|
24 | 24 | import android.accounts.AccountManager; |
25 | 25 | import android.content.Context; |
26 | 26 | import android.content.SharedPreferences; |
27 | | -import android.net.Uri; |
28 | 27 | import android.preference.PreferenceManager; |
29 | 28 |
|
30 | 29 | import com.owncloud.android.MainApp; |
31 | 30 | import com.owncloud.android.datamodel.ArbitraryDataProvider; |
32 | 31 | import com.owncloud.android.datamodel.FileDataStorageManager; |
33 | | -import com.owncloud.android.lib.common.OwnCloudAccount; |
34 | | -import com.owncloud.android.lib.common.OwnCloudClient; |
35 | | -import com.owncloud.android.lib.common.OwnCloudClientManagerFactory; |
36 | | -import com.owncloud.android.lib.common.UserInfo; |
37 | 32 | import com.owncloud.android.lib.common.accounts.AccountTypeUtils; |
38 | 33 | import com.owncloud.android.lib.common.accounts.AccountUtils.Constants; |
39 | 34 | import com.owncloud.android.lib.common.operations.RemoteOperationResult; |
40 | 35 | import com.owncloud.android.lib.common.utils.Log_OC; |
41 | 36 | import com.owncloud.android.lib.resources.status.OwnCloudVersion; |
42 | | -import com.owncloud.android.lib.resources.users.GetRemoteUserInfoOperation; |
43 | 37 | import com.owncloud.android.operations.GetCapabilitiesOperarion; |
44 | 38 | import com.owncloud.android.ui.activity.ManageAccountsActivity; |
45 | 39 |
|
@@ -228,126 +222,7 @@ public static String getWebdavPath(OwnCloudVersion version, String authTokenType |
228 | 222 | return null; |
229 | 223 | } |
230 | 224 |
|
231 | | - |
232 | | - /** |
233 | | - * Update the accounts in AccountManager to meet the current version of accounts expected by the app, if needed. |
234 | | - * |
235 | | - * Introduced to handle a change in the structure of stored account names needed to allow different OC servers |
236 | | - * in the same domain, but not in the same path. |
237 | | - * |
238 | | - * @param context Used to access the AccountManager. |
239 | | - */ |
240 | | - public static void updateAccountVersion(Context context) { |
241 | | - Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(context); |
242 | | - AccountManager accountMgr = AccountManager.get(context); |
243 | | - |
244 | | - if ( currentAccount != null ) { |
245 | | - String currentAccountVersion = accountMgr.getUserData(currentAccount, Constants.KEY_OC_ACCOUNT_VERSION); |
246 | | - |
247 | | - if (!String.valueOf(ACCOUNT_VERSION_WITH_PROPER_ID).equalsIgnoreCase(currentAccountVersion)) { |
248 | | - Log_OC.i(TAG, "Upgrading accounts to account version #" + ACCOUNT_VERSION_WITH_PROPER_ID); |
249 | | - Account[] ocAccounts = accountMgr.getAccountsByType(MainApp.getAccountType()); |
250 | | - String serverUrl; |
251 | | - String username; |
252 | | - String newAccountName; |
253 | | - String password; |
254 | | - Account newAccount; |
255 | | - for (Account account : ocAccounts) { |
256 | | - // build new account name |
257 | | - serverUrl = accountMgr.getUserData(account, Constants.KEY_OC_BASE_URL); |
258 | | - |
259 | | - // update user name |
260 | | - try { |
261 | | - OwnCloudAccount ocAccount = new OwnCloudAccount(account, context); |
262 | | - OwnCloudClient client = OwnCloudClientManagerFactory.getDefaultSingleton() |
263 | | - .getClientFor(ocAccount, context); |
264 | | - |
265 | | - GetRemoteUserInfoOperation remoteUserNameOperation = new GetRemoteUserInfoOperation(); |
266 | | - RemoteOperationResult result = remoteUserNameOperation.execute(client); |
267 | | - |
268 | | - if (result.isSuccess()) { |
269 | | - UserInfo userInfo = (UserInfo) result.getData().get(0); |
270 | | - username = userInfo.id; |
271 | | - } else { |
272 | | - // skip account, try it next time |
273 | | - Log_OC.e(TAG, "Error while getting username for account: " + account.name); |
274 | | - continue; |
275 | | - } |
276 | | - } catch (Exception e) { |
277 | | - Log_OC.e(TAG, "Error while getting username: " + e.getMessage()); |
278 | | - continue; |
279 | | - } |
280 | | - |
281 | | - newAccountName = com.owncloud.android.lib.common.accounts.AccountUtils. |
282 | | - buildAccountName(Uri.parse(serverUrl), username); |
283 | | - |
284 | | - // migrate to a new account, if needed |
285 | | - if (!newAccountName.equals(account.name)) { |
286 | | - Log_OC.d(TAG, "Upgrading " + account.name + " to " + newAccountName); |
287 | | - |
288 | | - // create the new account |
289 | | - newAccount = new Account(newAccountName, MainApp.getAccountType()); |
290 | | - password = accountMgr.getPassword(account); |
291 | | - accountMgr.addAccountExplicitly(newAccount, (password != null) ? password : "", null); |
292 | | - |
293 | | - // copy base URL |
294 | | - accountMgr.setUserData(newAccount, Constants.KEY_OC_BASE_URL, serverUrl); |
295 | | - |
296 | | - // copy server version |
297 | | - accountMgr.setUserData( |
298 | | - newAccount, |
299 | | - Constants.KEY_OC_VERSION, |
300 | | - accountMgr.getUserData(account, Constants.KEY_OC_VERSION) |
301 | | - ); |
302 | | - |
303 | | - // copy cookies |
304 | | - accountMgr.setUserData( |
305 | | - newAccount, |
306 | | - Constants.KEY_COOKIES, |
307 | | - accountMgr.getUserData(account, Constants.KEY_COOKIES) |
308 | | - ); |
309 | | - |
310 | | - // copy type of authentication |
311 | | - final String isSamlStr = accountMgr.getUserData(account, Constants.KEY_SUPPORTS_SAML_WEB_SSO); |
312 | | - if (Boolean.parseBoolean(isSamlStr)) { |
313 | | - accountMgr.setUserData(newAccount, Constants.KEY_SUPPORTS_SAML_WEB_SSO, "TRUE"); |
314 | | - } |
315 | | - |
316 | | - final String isOauthStr = accountMgr.getUserData(account, Constants.KEY_SUPPORTS_OAUTH2); |
317 | | - if (Boolean.parseBoolean(isOauthStr)) { |
318 | | - accountMgr.setUserData(newAccount, Constants.KEY_SUPPORTS_OAUTH2, "TRUE"); |
319 | | - } |
320 | | - /* TODO - study if it's possible to run this method in a background thread to copy the authToken |
321 | | - if (isOAuth || isSaml) { |
322 | | - accountMgr.setAuthToken(newAccount, mAuthTokenType, mAuthToken); |
323 | | - } |
324 | | - */ |
325 | | - |
326 | | - // don't forget the account saved in preferences as the current one |
327 | | - if (currentAccount.name.equals(account.name)) { |
328 | | - AccountUtils.setCurrentOwnCloudAccount(context, newAccountName); |
329 | | - } |
330 | | - |
331 | | - // remove the old account |
332 | | - accountMgr.removeAccount(account, null, null); |
333 | | - // will assume it succeeds, not a big deal otherwise |
334 | | - |
335 | | - } else { |
336 | | - // servers which base URL is in the root of their domain need no change |
337 | | - Log_OC.d(TAG, account.name + " needs no upgrade "); |
338 | | - newAccount = account; |
339 | | - } |
340 | | - |
341 | | - // at least, upgrade account version |
342 | | - Log_OC.d(TAG, "Setting version " + ACCOUNT_VERSION_WITH_PROPER_ID + " to " + newAccountName); |
343 | | - accountMgr.setUserData(newAccount, |
344 | | - Constants.KEY_OC_ACCOUNT_VERSION, Integer.toString(ACCOUNT_VERSION_WITH_PROPER_ID)); |
345 | | - } |
346 | | - } |
347 | | - } |
348 | | - } |
349 | | - |
350 | | - |
| 225 | + |
351 | 226 | public static String trimWebdavSuffix(String url) { |
352 | 227 | while(url.endsWith("/")) { |
353 | 228 | url = url.substring(0, url.length() - 1); |
|
0 commit comments