- String currentAccountVersion = accountMgr.getUserData(currentAccount, Constants.KEY_OC_ACCOUNT_VERSION);\r
-\r
- if (currentAccountVersion == null) {\r
- Log_OC.i(TAG, "Upgrading accounts to account version #" + ACCOUNT_VERSION);\r
- Account[] ocAccounts = accountMgr.getAccountsByType(MainApp.getAccountType());\r
- String serverUrl, username, newAccountName, password;\r
- Account newAccount;\r
- for (Account account : ocAccounts) {\r
- // build new account name\r
- serverUrl = accountMgr.getUserData(account, Constants.KEY_OC_BASE_URL);\r
- username = account.name.substring(0, account.name.lastIndexOf('@'));\r
- newAccountName = com.owncloud.android.lib.common.accounts.AccountUtils.\r
- buildAccountName(Uri.parse(serverUrl), username);\r
-\r
- // migrate to a new account, if needed\r
- if (!newAccountName.equals(account.name)) {\r
- Log_OC.d(TAG, "Upgrading " + account.name + " to " + newAccountName );\r
-\r
- // create the new account\r
- newAccount = new Account(newAccountName, MainApp.getAccountType());\r
- password = accountMgr.getPassword(account);\r
- accountMgr.addAccountExplicitly(newAccount, (password != null) ? password : "", null);\r
-\r
- // copy base URL\r
- accountMgr.setUserData(newAccount, Constants.KEY_OC_BASE_URL, serverUrl);\r
-\r
- // copy server version\r
- accountMgr.setUserData(\r
- newAccount,\r
- Constants.KEY_OC_VERSION,\r
- accountMgr.getUserData(account, Constants.KEY_OC_VERSION)\r
- );\r
-\r
- // copy cookies\r
- accountMgr.setUserData(\r
- newAccount,\r
- Constants.KEY_COOKIES,\r
- accountMgr.getUserData(account, Constants.KEY_COOKIES)\r
- );\r
-\r
- // copy type of authentication\r
- String isSamlStr = accountMgr.getUserData(account, Constants.KEY_SUPPORTS_SAML_WEB_SSO);\r
- boolean isSaml = "TRUE".equals(isSamlStr);\r
- if (isSaml) {\r
- accountMgr.setUserData(newAccount, Constants.KEY_SUPPORTS_SAML_WEB_SSO, "TRUE");\r
- }\r
-\r
- String isOauthStr = accountMgr.getUserData(account, Constants.KEY_SUPPORTS_OAUTH2);\r
- boolean isOAuth = "TRUE".equals(isOauthStr);\r
- if (isOAuth) {\r
- accountMgr.setUserData(newAccount, Constants.KEY_SUPPORTS_OAUTH2, "TRUE");\r
- }\r
+ if ( currentAccount != null ) {\r
+ String currentAccountVersion = accountMgr.getUserData(currentAccount, Constants.KEY_OC_ACCOUNT_VERSION);\r
+\r
+ if (currentAccountVersion == null) {\r
+ Log_OC.i(TAG, "Upgrading accounts to account version #" + ACCOUNT_VERSION);\r
+ Account[] ocAccounts = accountMgr.getAccountsByType(MainApp.getAccountType());\r
+ String serverUrl, username, newAccountName, password;\r
+ Account newAccount;\r
+ for (Account account : ocAccounts) {\r
+ // build new account name\r
+ serverUrl = accountMgr.getUserData(account, Constants.KEY_OC_BASE_URL);\r
+ username = account.name.substring(0, account.name.lastIndexOf('@'));\r
+ newAccountName = com.owncloud.android.lib.common.accounts.AccountUtils.\r
+ buildAccountName(Uri.parse(serverUrl), username);\r
+\r
+ // migrate to a new account, if needed\r
+ if (!newAccountName.equals(account.name)) {\r
+ Log_OC.d(TAG, "Upgrading " + account.name + " to " + newAccountName);\r
+\r
+ // create the new account\r
+ newAccount = new Account(newAccountName, MainApp.getAccountType());\r
+ password = accountMgr.getPassword(account);\r
+ accountMgr.addAccountExplicitly(newAccount, (password != null) ? password : "", null);\r
+\r
+ // copy base URL\r
+ accountMgr.setUserData(newAccount, Constants.KEY_OC_BASE_URL, serverUrl);\r
+\r
+ // copy server version\r
+ accountMgr.setUserData(\r
+ newAccount,\r
+ Constants.KEY_OC_VERSION,\r
+ accountMgr.getUserData(account, Constants.KEY_OC_VERSION)\r
+ );\r
+\r
+ // copy cookies\r
+ accountMgr.setUserData(\r
+ newAccount,\r
+ Constants.KEY_COOKIES,\r
+ accountMgr.getUserData(account, Constants.KEY_COOKIES)\r
+ );\r
+\r
+ // copy type of authentication\r
+ String isSamlStr = accountMgr.getUserData(account, Constants.KEY_SUPPORTS_SAML_WEB_SSO);\r
+ boolean isSaml = "TRUE".equals(isSamlStr);\r
+ if (isSaml) {\r
+ accountMgr.setUserData(newAccount, Constants.KEY_SUPPORTS_SAML_WEB_SSO, "TRUE");\r
+ }\r
+\r
+ String isOauthStr = accountMgr.getUserData(account, Constants.KEY_SUPPORTS_OAUTH2);\r
+ boolean isOAuth = "TRUE".equals(isOauthStr);\r
+ if (isOAuth) {\r
+ accountMgr.setUserData(newAccount, Constants.KEY_SUPPORTS_OAUTH2, "TRUE");\r
+ }\r