mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Updated OwnCloudClientManager#removeClient for new type OWnCloudAccount
This commit is contained in:
parent
7e2ec10442
commit
5130a93ef5
@ -26,7 +26,6 @@ package com.owncloud.android.lib.common;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AuthenticatorException;
|
||||
import android.accounts.OperationCanceledException;
|
||||
import android.content.Context;
|
||||
@ -45,21 +44,10 @@ public interface OwnCloudClientManager {
|
||||
|
||||
public OwnCloudClient getClientFor(OwnCloudAccount account, Context context);
|
||||
|
||||
/*
|
||||
public OwnCloudClient getClientFor(Account savedAccount, Context context)
|
||||
throws AccountNotFoundException, AuthenticatorException,
|
||||
IOException, OperationCanceledException;
|
||||
|
||||
public OwnCloudClient getClientFor(
|
||||
Uri serverBaseUri, OwnCloudCredentials credentials, Context context);
|
||||
*/
|
||||
public OwnCloudClient removeClientFor(OwnCloudAccount account);
|
||||
|
||||
public void saveAllClients(Context context, String accountType)
|
||||
throws AccountNotFoundException, AuthenticatorException,
|
||||
IOException, OperationCanceledException;
|
||||
|
||||
public OwnCloudClient removeClientFor(Account account, Context context)
|
||||
throws AccountNotFoundException, AuthenticatorException,
|
||||
IOException, OperationCanceledException;
|
||||
|
||||
}
|
||||
|
@ -1,14 +1,34 @@
|
||||
/* ownCloud Android Library is available under MIT license
|
||||
* Copyright (C) 2014 ownCloud Inc.
|
||||
*
|
||||
* 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.Account;
|
||||
import android.accounts.AuthenticatorException;
|
||||
import android.accounts.OperationCanceledException;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||
|
||||
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
public class SimpleFactoryManager implements OwnCloudClientManager {
|
||||
|
||||
@ -22,51 +42,27 @@ public class SimpleFactoryManager implements OwnCloudClientManager {
|
||||
context.getApplicationContext(),
|
||||
true);
|
||||
|
||||
Log.d(TAG, " new client " + client.hashCode());
|
||||
Log.d(TAG, " new client {" +
|
||||
(account.getName() != null ?
|
||||
account.getName() :
|
||||
AccountUtils.buildAccountName(
|
||||
account.getBaseUri(),
|
||||
account.getCredentials().getAuthToken())) +
|
||||
", " + client.hashCode() + "}");
|
||||
|
||||
client.setCredentials(account.getCredentials());
|
||||
return client;
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public OwnCloudClient getClientFor(Account savedAccount, Context context)
|
||||
throws OperationCanceledException, AuthenticatorException, AccountNotFoundException,
|
||||
IOException {
|
||||
Log.d(TAG, "getClientFor(Account ... : ");
|
||||
|
||||
OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(
|
||||
savedAccount,
|
||||
context.getApplicationContext());
|
||||
|
||||
Log.d(TAG, " new client " + client.hashCode());
|
||||
return client;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OwnCloudClient getClientFor(Uri serverBaseUri, OwnCloudCredentials credentials,
|
||||
Context context) {
|
||||
Log.d(TAG, "getClientFor(Uri ... : ");
|
||||
|
||||
OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(
|
||||
serverBaseUri,
|
||||
context.getApplicationContext(),
|
||||
true);
|
||||
|
||||
client.setCredentials(credentials);
|
||||
Log.d(TAG, " new client " + client.hashCode());
|
||||
return client;
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void saveAllClients(Context context, String accountType) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public OwnCloudClient removeClientFor(Account account, Context context) {
|
||||
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!
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -46,16 +46,12 @@ import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundExce
|
||||
*
|
||||
* TODO check multithreading safety
|
||||
*
|
||||
* TODO better mapping?
|
||||
*
|
||||
* @author David A. Velasco
|
||||
* @author masensio
|
||||
*/
|
||||
|
||||
public class SingleSessionManager implements OwnCloudClientManager {
|
||||
|
||||
//private static final String TAG = SingleSessionManager.class.getSimpleName();
|
||||
|
||||
private static final String TAG = SingleSessionManager.class.getSimpleName();
|
||||
|
||||
private Map<String, Map<OwnCloudCredentials, OwnCloudClient>> mClientsPerServer =
|
||||
@ -130,96 +126,41 @@ public class SingleSessionManager implements OwnCloudClientManager {
|
||||
return client;
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public synchronized OwnCloudClient getClientFor(Account savedAccount, Context context)
|
||||
throws OperationCanceledException, AuthenticatorException, AccountNotFoundException,
|
||||
IOException {
|
||||
|
||||
Uri serverBaseUri =
|
||||
Uri.parse(AccountUtils.getBaseUrlForAccount(context, savedAccount));
|
||||
|
||||
OwnCloudCredentials credentials =
|
||||
AccountUtils.getCredentialsForAccount(context, savedAccount);
|
||||
|
||||
OwnCloudClient client = getClientFor(serverBaseUri, credentials, context);
|
||||
|
||||
// Restore Cookies ??
|
||||
AccountUtils.restoreCookies(savedAccount, client, context);
|
||||
|
||||
return client;
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
@Override
|
||||
public synchronized OwnCloudClient getClientFor(
|
||||
Uri serverBaseUri, OwnCloudCredentials credentials, Context context) {
|
||||
|
||||
Map<OwnCloudCredentials, OwnCloudClient> clientsPerAccount =
|
||||
mClientsPerServer.get(serverBaseUri.toString());
|
||||
|
||||
if (clientsPerAccount == null) {
|
||||
clientsPerAccount = new HashMap<OwnCloudCredentials, OwnCloudClient>();
|
||||
mClientsPerServer.put(
|
||||
serverBaseUri.toString(),
|
||||
clientsPerAccount);
|
||||
}
|
||||
|
||||
if (credentials == null) {
|
||||
credentials = OwnCloudCredentialsFactory.getAnonymousCredentials();
|
||||
}
|
||||
|
||||
/// TODO - CRITERIA FOR MATCH OF KEYS!!!
|
||||
OwnCloudClient client = clientsPerAccount.get(credentials);
|
||||
if (client == null) {
|
||||
client = OwnCloudClientFactory.createOwnCloudClient(
|
||||
serverBaseUri,
|
||||
context.getApplicationContext(),
|
||||
true);
|
||||
|
||||
// Restore Cookies
|
||||
String accountName = AccountUtils.buildAccountName(serverBaseUri, credentials.getUsername());
|
||||
AccountUtils.restoreCookies(accountName, client, context);
|
||||
|
||||
client.setCredentials(credentials);
|
||||
clientsPerAccount.put(credentials, client);
|
||||
|
||||
}
|
||||
|
||||
return client;
|
||||
}
|
||||
*/
|
||||
|
||||
private void keepCredentialsUpdated(OwnCloudAccount account, OwnCloudClient reusedClient) {
|
||||
OwnCloudCredentials recentCredentials = account.getCredentials();
|
||||
if (!recentCredentials.getAuthToken().equals(
|
||||
reusedClient.getCredentials().getAuthToken())) {
|
||||
reusedClient.setCredentials(recentCredentials);
|
||||
}
|
||||
@Override
|
||||
public OwnCloudClient removeClientFor(OwnCloudAccount account) {
|
||||
|
||||
if (account == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
OwnCloudClient client = null;
|
||||
String accountName = account.getName();
|
||||
if (accountName != null) {
|
||||
client = mClientsWithKnownUsername.remove(accountName);
|
||||
if (client != null) {
|
||||
Log.d(TAG, "Removed client {" + accountName + ", " + client.hashCode() + "}");
|
||||
return client;
|
||||
} else {
|
||||
Log.d(TAG, "No client tracked for {" + accountName + "}");
|
||||
}
|
||||
}
|
||||
|
||||
String sessionName = AccountUtils.buildAccountName(
|
||||
account.getBaseUri(),
|
||||
account.getCredentials().getAuthToken());
|
||||
client = mClientsWithUnknownUsername.remove(sessionName);
|
||||
if (client != null) {
|
||||
Log.d(TAG, "Removed client {" + sessionName + ", " + client.hashCode() + "}");
|
||||
return client;
|
||||
}
|
||||
Log.d(TAG, "No client tracked for {" + sessionName + "}");
|
||||
|
||||
Log.d(TAG, "No client removed");
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized OwnCloudClient removeClientFor(Account savedAccount, Context context)
|
||||
throws AccountNotFoundException, OperationCanceledException, AuthenticatorException, IOException {
|
||||
|
||||
Uri serverBaseUri =
|
||||
Uri.parse(AccountUtils.getBaseUrlForAccount(context, savedAccount));
|
||||
|
||||
Map<OwnCloudCredentials, OwnCloudClient> clientsPerAccount =
|
||||
mClientsPerServer.get(serverBaseUri.toString());
|
||||
|
||||
if (clientsPerAccount != null) {
|
||||
OwnCloudCredentials credentials =
|
||||
AccountUtils.getCredentialsForAccount(context, savedAccount);
|
||||
|
||||
return clientsPerAccount.remove(credentials);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized void saveAllClients(Context context, String accountType)
|
||||
@ -253,5 +194,14 @@ 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user