mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Move responsibility of saving cookies from OwnCloudClientManager#saveClient(Account, Context) to AccountUtils#saveClient(Account , Context)
This commit is contained in:
parent
e7a0e30a27
commit
44f5337a50
@ -51,10 +51,6 @@ public interface OwnCloudClientManager {
|
||||
public OwnCloudClient getClientFor(
|
||||
Uri serverBaseUri, OwnCloudCredentials credentials, Context context);
|
||||
|
||||
public void saveClient(Account savedAccount, Context context)
|
||||
throws AccountNotFoundException, AuthenticatorException,
|
||||
IOException, OperationCanceledException;
|
||||
|
||||
public void saveAllClients(Context context, String accountType)
|
||||
throws AccountNotFoundException, AuthenticatorException,
|
||||
IOException, OperationCanceledException;
|
||||
|
@ -36,11 +36,6 @@ public class SimpleFactoryManager implements OwnCloudClientManager {
|
||||
return client;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveClient(Account savedAccount, Context context) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveAllClients(Context context, String accountType) {
|
||||
// TODO Auto-generated method stub
|
||||
|
@ -28,21 +28,17 @@ import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.httpclient.Cookie;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.accounts.AuthenticatorException;
|
||||
import android.accounts.OperationCanceledException;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientFactory;
|
||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
|
||||
import com.owncloud.android.lib.common.accounts.AccountUtils.Constants;
|
||||
|
||||
/**
|
||||
* Implementation of {@link OwnCloudClientManager}
|
||||
@ -57,7 +53,7 @@ import com.owncloud.android.lib.common.accounts.AccountUtils.Constants;
|
||||
|
||||
public class SingleSessionManager implements OwnCloudClientManager {
|
||||
|
||||
private static final String TAG = SingleSessionManager.class.getSimpleName();
|
||||
//private static final String TAG = SingleSessionManager.class.getSimpleName();
|
||||
|
||||
private static OwnCloudClientManager mInstance = null;
|
||||
|
||||
@ -144,54 +140,36 @@ public class SingleSessionManager implements OwnCloudClientManager {
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized void saveClient(Account savedAccount, Context context)
|
||||
throws AccountNotFoundException, AuthenticatorException, IOException,
|
||||
public synchronized void saveAllClients(Context context, String accountType)
|
||||
throws AccountNotFoundException, AuthenticatorException, IOException,
|
||||
OperationCanceledException {
|
||||
|
||||
// Account Manager
|
||||
AccountManager ac = AccountManager.get(context.getApplicationContext());
|
||||
|
||||
if (savedAccount != null) {
|
||||
Uri serverBaseUri =
|
||||
Uri.parse(AccountUtils.getBaseUrlForAccount(context, savedAccount));
|
||||
|
||||
|
||||
// Get all accounts
|
||||
Account [] accounts = AccountManager.get(context.getApplicationContext())
|
||||
.getAccountsByType(accountType);
|
||||
|
||||
// Save cookies for all accounts
|
||||
for(Account account: accounts){
|
||||
|
||||
Uri serverBaseUri =
|
||||
Uri.parse(AccountUtils.getBaseUrlForAccount(context, account));
|
||||
|
||||
Map<OwnCloudCredentials, OwnCloudClient> clientsPerAccount =
|
||||
mClientsPerServer.get(serverBaseUri.toString());
|
||||
|
||||
if (clientsPerAccount != null) {
|
||||
OwnCloudCredentials credentials =
|
||||
AccountUtils.getCredentialsForAccount(context, savedAccount);
|
||||
|
||||
/// TODO - CRITERIA FOR MATCH OF KEYS!!!
|
||||
OwnCloudClient client = clientsPerAccount.get(credentials);
|
||||
|
||||
if (client != null) {
|
||||
String cookiesString = client.getCookiesString();
|
||||
if (cookiesString != "") {
|
||||
ac.setUserData(savedAccount, Constants.KEY_COOKIES, cookiesString);
|
||||
Log.d(TAG, "Saving Cookies: "+ cookiesString );
|
||||
}
|
||||
}
|
||||
OwnCloudCredentials credentials =
|
||||
AccountUtils.getCredentialsForAccount(context, account);
|
||||
|
||||
/// TODO - CRITERIA FOR MATCH OF KEYS!!!
|
||||
OwnCloudClient client = clientsPerAccount.get(credentials);
|
||||
if (client != null) {
|
||||
AccountUtils.saveClient(client, account, context.getApplicationContext());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void saveAllClients(Context context, String accountType)
|
||||
throws AccountNotFoundException, AuthenticatorException, IOException,
|
||||
OperationCanceledException {
|
||||
|
||||
// Get all accounts
|
||||
Account [] accounts = AccountManager.get(context.getApplicationContext())
|
||||
.getAccountsByType(accountType);
|
||||
|
||||
// Save cookies for all accounts
|
||||
for(Account account: accounts){
|
||||
saveClient(account, context.getApplicationContext());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -26,7 +26,7 @@
|
||||
package com.owncloud.android.lib.common.accounts;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.OwnCloudCredentials;
|
||||
import com.owncloud.android.lib.common.OwnCloudCredentialsFactory;
|
||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
||||
@ -37,6 +37,7 @@ import android.accounts.AccountsException;
|
||||
import android.accounts.AuthenticatorException;
|
||||
import android.accounts.OperationCanceledException;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
public class AccountUtils {
|
||||
public static final String WEBDAV_PATH_1_2 = "/webdav/owncloud.php";
|
||||
@ -186,7 +187,24 @@ public class AccountUtils {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void saveClient(OwnCloudClient client, Account savedAccount, Context context) {
|
||||
|
||||
// Account Manager
|
||||
AccountManager ac = AccountManager.get(context.getApplicationContext());
|
||||
|
||||
if (client != null) {
|
||||
String cookiesString = client.getCookiesString();
|
||||
if (cookiesString != "") {
|
||||
ac.setUserData(savedAccount, Constants.KEY_COOKIES, cookiesString);
|
||||
Log.d("AccountUtils", "Saving Cookies: "+ cookiesString );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static class AccountNotFoundException extends AccountsException {
|
||||
|
||||
/** Generated - should be refreshed every time the class changes!! */
|
||||
|
@ -30,6 +30,7 @@ import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientFactory;
|
||||
import com.owncloud.android.lib.common.OwnCloudCredentials;
|
||||
import com.owncloud.android.lib.common.SingleSessionManager;
|
||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||
|
||||
|
||||
@ -254,6 +255,8 @@ public abstract class RemoteOperation implements Runnable {
|
||||
mClient = SingleSessionManager.getInstance().
|
||||
getClientFor(mAccount, mContext);
|
||||
}
|
||||
// Save Client Cookies
|
||||
AccountUtils.saveClient(mClient, mAccount, mContext);
|
||||
} else {
|
||||
throw new IllegalStateException("Trying to run a remote operation asynchronously with no client instance or account");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user