diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java index ccfb8ebf..6f5bca83 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java @@ -1,5 +1,5 @@ /* ownCloud Android Library is available under MIT license - * Copyright (C) 2019 ownCloud GmbH. + * Copyright (C) 2020 ownCloud GmbH. * Copyright (C) 2012 Bartek Przybylski * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -53,9 +53,8 @@ import static com.owncloud.android.lib.common.http.HttpConstants.OC_X_REQUEST_ID public class OwnCloudClient extends HttpClient { public static final String WEBDAV_FILES_PATH_4_0 = "/remote.php/dav/files/"; - public static final String WEBDAV_UPLOADS_PATH_4_0 = "/remote.php/dav/uploads/"; + private static final String WEBDAV_UPLOADS_PATH_4_0 = "/remote.php/dav/uploads/"; public static final String STATUS_PATH = "/status.php"; - public static final String FILES_WEB_PATH = "/index.php/apps/files"; private static final int MAX_REDIRECTIONS_COUNT = 3; private static final int MAX_REPEAT_COUNT_WITH_FRESH_CREDENTIALS = 1; @@ -68,13 +67,8 @@ public class OwnCloudClient extends HttpClient { private OwnCloudVersion mVersion = null; private OwnCloudAccount mAccount; - /** - * {@link @OwnCloudClientManager} holding a reference to this object and delivering it to callers; might be - * NULL - */ - private OwnCloudClientManager mOwnCloudClientManager = null; + private SingleSessionManager mSingleSessionManager = null; - private String mRedirectedLocation; private boolean mFollowRedirects; public OwnCloudClient(Uri baseUri) { @@ -97,7 +91,7 @@ public class OwnCloudClient extends HttpClient { mCredentials.applyTo(this); } - public void applyCredentials() { + void applyCredentials() { mCredentials.applyTo(this); } @@ -127,9 +121,6 @@ public class OwnCloudClient extends HttpClient { private void checkFirstRedirection(HttpBaseMethod method) { final String location = method.getResponseHeader(HttpConstants.LOCATION_HEADER_LOWER); - if (location != null && !location.isEmpty()) { - mRedirectedLocation = location; - } } private int executeRedirectedHttpMethod(HttpBaseMethod method) throws Exception { @@ -360,10 +351,10 @@ public class OwnCloudClient extends HttpClient { } } - if (!credentialsWereRefreshed && mOwnCloudClientManager != null) { + if (!credentialsWereRefreshed && mSingleSessionManager != null) { // if credentials are not refreshed, client must be removed // from the OwnCloudClientManager to prevent it is reused once and again - mOwnCloudClientManager.removeClientFor(mAccount); + mSingleSessionManager.removeClientFor(mAccount); } } // else: onExecute will finish with status 401 @@ -395,7 +386,7 @@ public class OwnCloudClient extends HttpClient { /** * Invalidates credentials stored for the given account in the system {@link AccountManager} and in - * current {@link OwnCloudClientManagerFactory#getDefaultSingleton()} instance. + * current {@link SingleSessionManager#getDefaultSingleton()} instance. *
* {@link #shouldInvalidateAccountCredentials(int)} should be called first. * @@ -411,10 +402,6 @@ public class OwnCloudClient extends HttpClient { return true; } - void setOwnCloudClientManager(OwnCloudClientManager clientManager) { - mOwnCloudClientManager = clientManager; - } - public boolean followRedirects() { return mFollowRedirects; } @@ -422,4 +409,4 @@ public class OwnCloudClient extends HttpClient { public void setFollowRedirects(boolean followRedirects) { this.mFollowRedirects = followRedirects; } -} \ No newline at end of file +} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientManager.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientManager.java deleted file mode 100644 index fe793863..00000000 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientManager.java +++ /dev/null @@ -1,52 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * Copyright (C) 2019 ownCloud GmbH. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -package com.owncloud.android.lib.common; - -import android.accounts.AuthenticatorException; -import android.accounts.OperationCanceledException; -import android.content.Context; - -import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException; - -import java.io.IOException; - -/** - * Manager to create and reuse OwnCloudClient instances to access remote OC servers. - * - * @author David A. Velasco - * @author masensio - * @author Christian Schabesberger - */ - -public interface OwnCloudClientManager { - - OwnCloudClient getClientFor(OwnCloudAccount account, Context context) throws AccountNotFoundException, - OperationCanceledException, AuthenticatorException, IOException; - - OwnCloudClient removeClientFor(OwnCloudAccount account); - - void saveAllClients(Context context, String accountType) throws AccountNotFoundException, AuthenticatorException, IOException, - OperationCanceledException; -} \ No newline at end of file diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientManagerFactory.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientManagerFactory.java deleted file mode 100644 index 31383d3d..00000000 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientManagerFactory.java +++ /dev/null @@ -1,85 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * Copyright (C) 2019 ownCloud GmbH. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ -package com.owncloud.android.lib.common; - -public class OwnCloudClientManagerFactory { - - private static Policy sDefaultPolicy = Policy.NEW_CLIENT; - private static OwnCloudClientManager sDefaultSingleton; - private static String sUserAgent; - - private static OwnCloudClientManager newDefaultOwnCloudClientManager() { - return newOwnCloudClientManager(sDefaultPolicy); - } - - private static OwnCloudClientManager newOwnCloudClientManager(Policy policy) { - switch (policy) { - case NEW_CLIENT: - return new SimpleFactoryManager(); - - case SINGLE_SESSION_PER_ACCOUNT: - return new SingleSessionManager(); - - default: - throw new IllegalArgumentException("Unknown policy"); - } - } - - public static OwnCloudClientManager getDefaultSingleton() { - if (sDefaultSingleton == null) { - sDefaultSingleton = newDefaultOwnCloudClientManager(); - } - return sDefaultSingleton; - } - - public static void setDefaultPolicy(Policy policy) { - if (policy == null) { - throw new IllegalArgumentException("Default policy cannot be NULL"); - } - if (defaultSingletonMustBeUpdated(policy)) { - sDefaultSingleton = null; - } - sDefaultPolicy = policy; - } - - public static String getUserAgent() { - return sUserAgent; - } - - public static void setUserAgent(String userAgent) { - sUserAgent = userAgent; - } - - private static boolean defaultSingletonMustBeUpdated(Policy policy) { - if (sDefaultSingleton == null) { - return false; - } - return policy == Policy.NEW_CLIENT && !(sDefaultSingleton instanceof SimpleFactoryManager); - } - - public enum Policy { - NEW_CLIENT, - SINGLE_SESSION_PER_ACCOUNT - } -} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/SimpleFactoryManager.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/SimpleFactoryManager.java deleted file mode 100644 index 4d5ebfa3..00000000 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/SimpleFactoryManager.java +++ /dev/null @@ -1,72 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * Copyright (C) 2016 ownCloud GmbH. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -package com.owncloud.android.lib.common; - -import android.accounts.AuthenticatorException; -import android.accounts.OperationCanceledException; -import android.content.Context; - -import com.owncloud.android.lib.common.accounts.AccountUtils; -import timber.log.Timber; - -import java.io.IOException; - -public class SimpleFactoryManager implements OwnCloudClientManager { - - @Override - public OwnCloudClient getClientFor(OwnCloudAccount account, Context context) throws - OperationCanceledException, AuthenticatorException, IOException { - - Timber.d("getClientFor(OwnCloudAccount ... : "); - - OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient( - account.getBaseUri(), - context.getApplicationContext(), - true); - - Timber.v("new client {" + (account.getName() != null ? account.getName() : - AccountUtils.buildAccountName(account.getBaseUri(), "")) + ", " + client.hashCode() + "}"); - - if (account.getCredentials() == null) { - account.loadCredentials(context); - } - client.setCredentials(account.getCredentials()); - client.setAccount(account); - client.setContext(context); - client.setOwnCloudClientManager(this); - return client; - } - - @Override - public OwnCloudClient removeClientFor(OwnCloudAccount account) { - // nothing to do - not taking care of tracking instances! - return null; - } - - @Override - public void saveAllClients(Context context, String accountType) { - // nothing to do - not taking care of tracking instances! - } -} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/SingleSessionManager.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/SingleSessionManager.java index e4b190a4..f448e45b 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/SingleSessionManager.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/SingleSessionManager.java @@ -1,5 +1,5 @@ /* ownCloud Android Library is available under MIT license - * Copyright (C) 2019 ownCloud GmbH. + * Copyright (C) 2020 ownCloud GmbH. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -41,23 +41,35 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; /** - * Implementation of {@link OwnCloudClientManager} - *
- * TODO check multithreading safety
- *
* @author David A. Velasco
* @author masensio
* @author Christian Schabesberger
* @author David González Verdugo
*/
-public class SingleSessionManager implements OwnCloudClientManager {
+public class SingleSessionManager {
+
+ private static SingleSessionManager sDefaultSingleton;
+ private static String sUserAgent;
private ConcurrentMap