Merge branch 'material_buttons' of https://github.com/owncloud/android into material_fab
[pub/Android/ownCloud.git] / src / com / owncloud / android / authentication / AccountUtils.java
index 9afa819..2f05a3e 100644 (file)
@@ -114,7 +114,7 @@ public class AccountUtils {
         if (accountName != null) {\r
             Account[] ocAccounts = AccountManager.get(context).getAccountsByType(\r
                     MainApp.getAccountType());\r
-            boolean found = false;\r
+            boolean found;\r
             for (Account account : ocAccounts) {\r
                 found = (account.name.equals(accountName));\r
                 if (found) {\r
@@ -220,19 +220,20 @@ public class AccountUtils {
                         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
+                        /* 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
+                        if (currentAccount.name.equals(account.name)) {\r
                             AccountUtils.setCurrentOwnCloudAccount(context, newAccountName);\r
                         }\r
 \r
                         // remove the old account\r
-                        accountMgr.removeAccount(account, null, null);  // will assume it succeeds, not a big deal otherwise\r
+                        accountMgr.removeAccount(account, null, null);\r
+                            // will assume it succeeds, not a big deal otherwise\r
 \r
                     } else {\r
                         // servers which base URL is in the root of their domain need no change\r
@@ -242,7 +243,9 @@ public class AccountUtils {
 \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
+                    accountMgr.setUserData(\r
+                            newAccount, Constants.KEY_OC_ACCOUNT_VERSION, Integer.toString(ACCOUNT_VERSION)\r
+                    );\r
 \r
                 }\r
             }\r
@@ -267,4 +270,34 @@ public class AccountUtils {
         return url;\r
     }\r
 \r
+    /**\r
+     * Access the version of the OC server corresponding to an account SAVED IN THE ACCOUNTMANAGER\r
+     *\r
+     * @param   account     ownCloud account\r
+     * @return              Version of the OC server corresponding to account, according to the data saved\r
+     *                      in the system AccountManager\r
+     */\r
+    public static OwnCloudVersion getServerVersion(Account account) {\r
+        OwnCloudVersion serverVersion = null;\r
+        if (account != null) {\r
+            AccountManager accountMgr = AccountManager.get(MainApp.getAppContext());\r
+            String serverVersionStr = accountMgr.getUserData(account, Constants.KEY_OC_VERSION);\r
+            if (serverVersionStr != null) {\r
+                serverVersion = new OwnCloudVersion(serverVersionStr);\r
+            }\r
+        }\r
+        return serverVersion;\r
+    }\r
+\r
+    public static boolean hasSearchUsersSupport(Account account){\r
+        OwnCloudVersion serverVersion = null;\r
+        if (account != null) {\r
+            AccountManager accountMgr = AccountManager.get(MainApp.getAppContext());\r
+            String serverVersionStr = accountMgr.getUserData(account, Constants.KEY_OC_VERSION);\r
+            if (serverVersionStr != null) {\r
+                serverVersion = new OwnCloudVersion(serverVersionStr);\r
+            }\r
+        }\r
+        return (serverVersion != null ? serverVersion.isSearchUsersSupported() : false);\r
+    }\r
 }\r