mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 02:17:41 +00:00 
			
		
		
		
	Default policy for singleton available in OwnCloudManagerFactory made configurable
This commit is contained in:
		
							parent
							
								
									9be1323745
								
							
						
					
					
						commit
						7e2ec10442
					
				| @ -57,6 +57,9 @@ public class OwnCloudAccount { | ||||
|     	mSavedAccountName = savedAccount.name; | ||||
|         mBaseUri = Uri.parse(AccountUtils.getBaseUrlForAccount(context, savedAccount)); | ||||
|         mCredentials = AccountUtils.getCredentialsForAccount(context, savedAccount); | ||||
|         if (mCredentials == null) { | ||||
|         	mCredentials = OwnCloudCredentialsFactory.getAnonymousCredentials(); | ||||
|         } | ||||
|     } | ||||
|      | ||||
|      | ||||
|  | ||||
| @ -7,12 +7,12 @@ public class OwnCloudClientManagerFactory { | ||||
| 		SINGLE_SESSION_PER_ACCOUNT | ||||
| 	} | ||||
| 	 | ||||
| 	public final static Policy DEFAULT_POLICY = Policy.ALWAYS_NEW_CLIENT; | ||||
| 	public static Policy sDefaultPolicy = Policy.ALWAYS_NEW_CLIENT; | ||||
| 	 | ||||
| 	private static OwnCloudClientManager mDefaultSingleton; | ||||
| 	private static OwnCloudClientManager sDefaultSingleton; | ||||
| 
 | ||||
| 	public static OwnCloudClientManager newDefaultOwnCloudClientManager() { | ||||
| 		return newOwnCloudClientManager(DEFAULT_POLICY); | ||||
| 		return newOwnCloudClientManager(sDefaultPolicy); | ||||
| 	} | ||||
| 	 | ||||
| 	public static OwnCloudClientManager newOwnCloudClientManager(Policy policy) { | ||||
| @ -29,10 +29,32 @@ public class OwnCloudClientManagerFactory { | ||||
| 	} | ||||
| 	 | ||||
|     public static OwnCloudClientManager getDefaultSingleton() { | ||||
|     	if (mDefaultSingleton == null) { | ||||
|     		mDefaultSingleton = newDefaultOwnCloudClientManager(); | ||||
|     	if (sDefaultSingleton == null) { | ||||
|     		sDefaultSingleton = newDefaultOwnCloudClientManager(); | ||||
|     	} | ||||
|     	return mDefaultSingleton; | ||||
|     	return sDefaultSingleton; | ||||
|     } | ||||
|      | ||||
|     public static void setDefaultPolicy(Policy policy) { | ||||
|     	if (defaultSingletonMustBeUpdated(policy)) { | ||||
|     		sDefaultSingleton = null; | ||||
|     	} | ||||
|     	sDefaultPolicy = policy; | ||||
|     } | ||||
| 
 | ||||
| 	private static boolean defaultSingletonMustBeUpdated(Policy policy) { | ||||
| 		if (sDefaultSingleton == null) { | ||||
| 			return false; | ||||
| 		} | ||||
| 		if (policy == Policy.ALWAYS_NEW_CLIENT &&  | ||||
| 				!(sDefaultSingleton instanceof SimpleFactoryManager)) { | ||||
| 			return true; | ||||
| 		} | ||||
| 		if (policy == Policy.SINGLE_SESSION_PER_ACCOUNT &&  | ||||
| 				!(sDefaultSingleton instanceof SingleSessionManager)) { | ||||
| 			return true; | ||||
| 		} | ||||
| 		return false; | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -99,6 +99,7 @@ public class SingleSessionManager implements OwnCloudClientManager { | ||||
|     	} else { | ||||
|     		Log.d(TAG, "    reusing client {" + accountName + ", " + client.hashCode() + "}"); | ||||
|     		reusingKnown = true; | ||||
|     		keepCredentialsUpdated(account, client); | ||||
|     	} | ||||
|     	 | ||||
|     	if (client == null) { | ||||
| @ -191,6 +192,15 @@ public class SingleSessionManager implements OwnCloudClientManager { | ||||
|     } | ||||
|     */ | ||||
|      | ||||
| 	private void keepCredentialsUpdated(OwnCloudAccount account, OwnCloudClient reusedClient) { | ||||
| 		OwnCloudCredentials recentCredentials = account.getCredentials(); | ||||
| 		if (!recentCredentials.getAuthToken().equals( | ||||
| 				reusedClient.getCredentials().getAuthToken())) { | ||||
| 			reusedClient.setCredentials(recentCredentials); | ||||
| 		} | ||||
| 		 | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
|     public synchronized OwnCloudClient removeClientFor(Account savedAccount, Context context)  | ||||
|     		throws AccountNotFoundException, OperationCanceledException, AuthenticatorException, IOException { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user