Filter only '/' character in user input when version of server is 8.1 or later
[pub/Android/ownCloud.git] / src / com / owncloud / android / authentication / AccountUtils.java
index a22164f..1e67aa6 100644 (file)
@@ -167,82 +167,84 @@ public class AccountUtils {
         Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(context);\r
         AccountManager accountMgr = AccountManager.get(context);\r
 \r
         Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(context);\r
         AccountManager accountMgr = AccountManager.get(context);\r
 \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
+        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
                     /* TODO - study if it's possible to run this method in a background thread to copy the authToken\r
                     if (isOAuth || isSaml) {\r
                         accountMgr.setAuthToken(newAccount, mAuthTokenType, mAuthToken);\r
                     }\r
                     */\r
 \r
                     /* TODO - study if it's possible to run this method in a background thread to copy the authToken\r
                     if (isOAuth || isSaml) {\r
                         accountMgr.setAuthToken(newAccount, mAuthTokenType, mAuthToken);\r
                     }\r
                     */\r
 \r
-                    // don't forget the account saved in preferences as the current one\r
-                    if (currentAccount != null && currentAccount.name.equals(account.name)) {\r
-                        AccountUtils.setCurrentOwnCloudAccount(context, newAccountName);\r
-                    }\r
+                        // don't forget the account saved in preferences as the current one\r
+                        if (currentAccount != null && currentAccount.name.equals(account.name)) {\r
+                            AccountUtils.setCurrentOwnCloudAccount(context, newAccountName);\r
+                        }\r
 \r
 \r
-                    // remove the old account\r
-                    accountMgr.removeAccount(account, null, null);  // will assume it succeeds, not a big deal otherwise\r
+                        // remove the old account\r
+                        accountMgr.removeAccount(account, null, null);  // will assume it succeeds, not a big deal otherwise\r
 \r
 \r
-                } else {\r
-                    // servers which base URL is in the root of their domain need no change\r
-                    Log_OC.d(TAG, account.name + " needs no upgrade ");\r
-                    newAccount = account;\r
-                }\r
+                    } else {\r
+                        // servers which base URL is in the root of their domain need no change\r
+                        Log_OC.d(TAG, account.name + " needs no upgrade ");\r
+                        newAccount = account;\r
+                    }\r
 \r
 \r
-                // at least, upgrade account version\r
-                Log_OC.d(TAG, "Setting version " + ACCOUNT_VERSION + " to " + newAccountName);\r
-                accountMgr.setUserData(newAccount, Constants.KEY_OC_ACCOUNT_VERSION, Integer.toString(ACCOUNT_VERSION));\r
+                    // at least, upgrade account version\r
+                    Log_OC.d(TAG, "Setting version " + ACCOUNT_VERSION + " to " + newAccountName);\r
+                    accountMgr.setUserData(newAccount, Constants.KEY_OC_ACCOUNT_VERSION, Integer.toString(ACCOUNT_VERSION));\r
 \r
 \r
+                }\r
             }\r
         }\r
     }\r
             }\r
         }\r
     }\r