mirror of
https://github.com/owncloud/android-library.git
synced 2026-08-20 12:52:53 +00:00
Get rid of conditions for <10 servers
This commit is contained in:
-62
@@ -1,62 +0,0 @@
|
||||
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 com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Dynamic implementation of {@link OwnCloudClientManager}.
|
||||
*
|
||||
* Wraps instances of {@link SingleSessionManager} and {@link SimpleFactoryManager} and delegates on one
|
||||
* or the other depending on the known version of the server corresponding to the {@link OwnCloudAccount}
|
||||
*
|
||||
* @author David A. Velasco
|
||||
*/
|
||||
|
||||
public class DynamicSessionManager implements OwnCloudClientManager {
|
||||
|
||||
private SimpleFactoryManager mSimpleFactoryManager = new SimpleFactoryManager();
|
||||
|
||||
private SingleSessionManager mSingleSessionManager = new SingleSessionManager();
|
||||
|
||||
@Override
|
||||
public OwnCloudClient getClientFor(OwnCloudAccount account, Context context)
|
||||
throws OperationCanceledException, AuthenticatorException, IOException {
|
||||
|
||||
OwnCloudVersion ownCloudVersion = null;
|
||||
if (account.getSavedAccount() != null) {
|
||||
ownCloudVersion = AccountUtils.getServerVersionForAccount(
|
||||
account.getSavedAccount(), context
|
||||
);
|
||||
}
|
||||
|
||||
if (ownCloudVersion != null && ownCloudVersion.isSessionMonitoringSupported()) {
|
||||
return mSingleSessionManager.getClientFor(account, context);
|
||||
} else {
|
||||
return mSimpleFactoryManager.getClientFor(account, context);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public OwnCloudClient removeClientFor(OwnCloudAccount account) {
|
||||
OwnCloudClient clientRemovedFromFactoryManager = mSimpleFactoryManager.removeClientFor(account);
|
||||
OwnCloudClient clientRemovedFromSingleSessionManager = mSingleSessionManager.removeClientFor(account);
|
||||
if (clientRemovedFromSingleSessionManager != null) {
|
||||
return clientRemovedFromSingleSessionManager;
|
||||
} else {
|
||||
return clientRemovedFromFactoryManager;
|
||||
}
|
||||
// clientRemoved and clientRemoved2 should not be != null at the same time
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveAllClients(Context context, String accountType) {
|
||||
mSimpleFactoryManager.saveAllClients(context, accountType);
|
||||
mSingleSessionManager.saveAllClients(context, accountType);
|
||||
}
|
||||
}
|
||||
+5
-9
@@ -29,17 +29,17 @@ public class OwnCloudClientManagerFactory {
|
||||
private static OwnCloudClientManager sDefaultSingleton;
|
||||
private static String sUserAgent;
|
||||
|
||||
public static OwnCloudClientManager newDefaultOwnCloudClientManager() {
|
||||
private static OwnCloudClientManager newDefaultOwnCloudClientManager() {
|
||||
return newOwnCloudClientManager(sDefaultPolicy);
|
||||
}
|
||||
|
||||
public static OwnCloudClientManager newOwnCloudClientManager(Policy policy) {
|
||||
private static OwnCloudClientManager newOwnCloudClientManager(Policy policy) {
|
||||
switch (policy) {
|
||||
case ALWAYS_NEW_CLIENT:
|
||||
return new SimpleFactoryManager();
|
||||
|
||||
case SINGLE_SESSION_PER_ACCOUNT_IF_SERVER_SUPPORTS_SERVER_MONITORING:
|
||||
return new DynamicSessionManager();
|
||||
case SINGLE_SESSION_PER_ACCOUNT:
|
||||
return new SingleSessionManager();
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown policy");
|
||||
@@ -53,10 +53,6 @@ public class OwnCloudClientManagerFactory {
|
||||
return sDefaultSingleton;
|
||||
}
|
||||
|
||||
public static Policy getDefaultPolicy() {
|
||||
return sDefaultPolicy;
|
||||
}
|
||||
|
||||
public static void setDefaultPolicy(Policy policy) {
|
||||
if (policy == null) {
|
||||
throw new IllegalArgumentException("Default policy cannot be NULL");
|
||||
@@ -84,6 +80,6 @@ public class OwnCloudClientManagerFactory {
|
||||
|
||||
public enum Policy {
|
||||
ALWAYS_NEW_CLIENT,
|
||||
SINGLE_SESSION_PER_ACCOUNT_IF_SERVER_SUPPORTS_SERVER_MONITORING
|
||||
SINGLE_SESSION_PER_ACCOUNT
|
||||
}
|
||||
}
|
||||
|
||||
+2
-6
@@ -143,7 +143,6 @@ public class AccountUtils {
|
||||
boolean isOauth2 = supportsOAuth2 != null && supportsOAuth2.equals("TRUE");
|
||||
|
||||
String username = AccountUtils.getUsernameForAccount(account);
|
||||
OwnCloudVersion version = new OwnCloudVersion(am.getUserData(account, Constants.KEY_OC_VERSION));
|
||||
|
||||
if (isOauth2) {
|
||||
String accessToken = am.blockingGetAuthToken(
|
||||
@@ -152,7 +151,6 @@ public class AccountUtils {
|
||||
false);
|
||||
|
||||
credentials = OwnCloudCredentialsFactory.newBearerCredentials(username, accessToken);
|
||||
|
||||
} else {
|
||||
String password = am.blockingGetAuthToken(
|
||||
account,
|
||||
@@ -161,8 +159,7 @@ public class AccountUtils {
|
||||
|
||||
credentials = OwnCloudCredentialsFactory.newBasicCredentials(
|
||||
username,
|
||||
password,
|
||||
version.isPreemptiveAuthenticationPreferred()
|
||||
password
|
||||
);
|
||||
}
|
||||
|
||||
@@ -201,9 +198,8 @@ public class AccountUtils {
|
||||
if (url.contains("://")) {
|
||||
url = url.substring(serverBaseUrl.toString().indexOf("://") + 3);
|
||||
}
|
||||
String accountName = username + "@" + url;
|
||||
|
||||
return accountName;
|
||||
return username + "@" + url;
|
||||
}
|
||||
|
||||
public static void saveClient(OwnCloudClient client, Account savedAccount, Context context) {
|
||||
|
||||
-6
@@ -38,12 +38,6 @@ public class OwnCloudCredentialsFactory {
|
||||
return new OwnCloudBasicCredentials(username, password);
|
||||
}
|
||||
|
||||
public static OwnCloudCredentials newBasicCredentials(
|
||||
String username, String password, boolean preemptiveMode
|
||||
) {
|
||||
return new OwnCloudBasicCredentials(username, password, preemptiveMode);
|
||||
}
|
||||
|
||||
public static OwnCloudCredentials newBearerCredentials(String username, String authToken) {
|
||||
return new OwnCloudBearerCredentials(username, authToken);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user