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