Merge branch 'develop' into upgrading_account_manager
[pub/Android/ownCloud.git] / src / com / owncloud / android / authentication / AccountUtils.java
index 33c7e6a..bb2315d 100644 (file)
@@ -1,6 +1,8 @@
-/* ownCloud Android client application\r
+/**\r
+ *   ownCloud Android client application\r
+ *\r
  *   Copyright (C) 2012  Bartek Przybylski\r
- *   Copyright (C) 2012-2013 ownCloud Inc.\r
+ *   Copyright (C) 2015 ownCloud Inc.\r
  *\r
  *   This program is free software: you can redistribute it and/or modify\r
  *   it under the terms of the GNU General Public License version 2,\r
 \r
 package com.owncloud.android.authentication;\r
 \r
+import java.util.Locale;\r
+\r
 import com.owncloud.android.MainApp;\r
-import com.owncloud.android.oc_framework.accounts.AccountTypeUtils;\r
-import com.owncloud.android.oc_framework.utils.OwnCloudVersion;\r
+import com.owncloud.android.lib.common.accounts.AccountTypeUtils;\r
+import com.owncloud.android.lib.resources.status.OwnCloudVersion;\r
 \r
 import android.accounts.Account;\r
 import android.accounts.AccountManager;\r
@@ -29,13 +33,9 @@ import android.content.SharedPreferences;
 import android.preference.PreferenceManager;\r
 \r
 public class AccountUtils {\r
-    public static final String WEBDAV_PATH_1_2 = "/webdav/owncloud.php";\r
-    public static final String WEBDAV_PATH_2_0 = "/files/webdav.php";\r
-    public static final String WEBDAV_PATH_4_0 = "/remote.php/webdav";\r
+    public static final String WEBDAV_PATH_4_0_AND_LATER = "/remote.php/webdav";\r
     private static final String ODAV_PATH = "/remote.php/odav";\r
     private static final String SAML_SSO_PATH = "/remote.php/webdav";\r
-    public static final String CARDDAV_PATH_2_0 = "/apps/contacts/carddav.php";\r
-    public static final String CARDDAV_PATH_4_0 = "/remote/carddav.php";\r
     public static final String STATUS_PATH = "/status.php";\r
 \r
     /**\r
@@ -81,8 +81,18 @@ public class AccountUtils {
                 MainApp.getAccountType());\r
 \r
         if (account != null && account.name != null) {\r
-            for (Account ac : ocAccounts) {\r
-                if (ac.name.equals(account.name)) {\r
+            int lastAtPos = account.name.lastIndexOf("@");\r
+            String hostAndPort = account.name.substring(lastAtPos + 1);\r
+            String username = account.name.substring(0, lastAtPos);\r
+            String otherHostAndPort, otherUsername;\r
+            Locale currentLocale = context.getResources().getConfiguration().locale;\r
+            for (Account otherAccount : ocAccounts) {\r
+                lastAtPos = otherAccount.name.lastIndexOf("@");\r
+                otherHostAndPort = otherAccount.name.substring(lastAtPos + 1);\r
+                otherUsername = otherAccount.name.substring(0, lastAtPos);\r
+                if (otherHostAndPort.equals(hostAndPort) &&\r
+                        otherUsername.toLowerCase(currentLocale).\r
+                            equals(username.toLowerCase(currentLocale))) {\r
                     return true;\r
                 }\r
             }\r
@@ -91,19 +101,6 @@ public class AccountUtils {
     }\r
     \r
 \r
-    /**\r
-     * Checks, whether or not there are any ownCloud accounts setup.\r
-     * \r
-     * @return true, if there is at least one account.\r
-     */\r
-    public static boolean accountsAreSetup(Context context) {\r
-        AccountManager accMan = AccountManager.get(context);\r
-        Account[] accounts = accMan\r
-                .getAccountsByType(MainApp.getAccountType());\r
-        return accounts.length > 0;\r
-    }\r
-    \r
-    \r
     public static boolean setCurrentOwnCloudAccount(Context context, String accountName) {\r
         boolean result = false;\r
         if (accountName != null) {\r
@@ -131,8 +128,10 @@ public class AccountUtils {
      * according to its version and the authorization method used.\r
      * \r
      * @param   version         Version of ownCloud server.\r
-     * @param   authTokenType   Authorization token type, matching some of the AUTH_TOKEN_TYPE_* constants in {@link AccountAuthenticator}. \r
-     * @return                  WebDAV path for given OC version and authorization method, null if OC version is unknown.\r
+     * @param   authTokenType   Authorization token type, matching some of the AUTH_TOKEN_TYPE_* constants in\r
+     *                          {@link AccountAuthenticator}.\r
+     * @return                  WebDAV path for given OC version and authorization method, null if OC version\r
+     *                          is unknown; versions prior to ownCloud 4 are not supported anymore\r
      */\r
     public static String getWebdavPath(OwnCloudVersion version, String authTokenType) {\r
         if (version != null) {\r
@@ -142,13 +141,7 @@ public class AccountUtils {
             if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(authTokenType)) {\r
                 return SAML_SSO_PATH;\r
             }\r
-            if (version.compareTo(OwnCloudVersion.owncloud_v4) >= 0)\r
-                return WEBDAV_PATH_4_0;\r
-            if (version.compareTo(OwnCloudVersion.owncloud_v3) >= 0\r
-                    || version.compareTo(OwnCloudVersion.owncloud_v2) >= 0)\r
-                return WEBDAV_PATH_2_0;\r
-            if (version.compareTo(OwnCloudVersion.owncloud_v1) >= 0)\r
-                return WEBDAV_PATH_1_2;\r
+            return WEBDAV_PATH_4_0_AND_LATER;\r
         }\r
         return null;\r
     }\r