Updated creation of OwnCloudClients for known OC Accounts so that all the operations to the same Account are done through the same OwnCloudClient instance

This commit is contained in:
David A. Velasco 2014-06-05 17:52:37 +02:00
parent c9e756b05b
commit 727be448c8
9 changed files with 73 additions and 27 deletions

@ -1 +1 @@
Subproject commit ba42f934fc861f6d5120690edd46ba2c502dd705
Subproject commit 1ef3a0176cc870d3cb26a77652b7ae9fd79584ce

View file

@ -34,14 +34,14 @@ import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.notifications.NotificationBuilderWithProgressBar;
import com.owncloud.android.notifications.NotificationDelayer;
import com.owncloud.android.operations.DownloadFileOperation;
import com.owncloud.android.lib.common.OwnCloudClientMap;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.resources.files.FileUtils;
import com.owncloud.android.operations.DownloadFileOperation;
import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.preview.PreviewImageActivity;
@ -347,8 +347,9 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
/// prepare client object to send the request to the ownCloud server
if (mDownloadClient == null || !mLastAccount.equals(mCurrentDownload.getAccount())) {
mLastAccount = mCurrentDownload.getAccount();
mStorageManager = new FileDataStorageManager(mLastAccount, getContentResolver());
mDownloadClient = OwnCloudClientFactory.createOwnCloudClient(mLastAccount, getApplicationContext());
mStorageManager =
new FileDataStorageManager(mLastAccount, getContentResolver());
mDownloadClient = OwnCloudClientMap.getClientFor(mLastAccount, this);
}
/// perform the download

View file

@ -48,8 +48,8 @@ import com.owncloud.android.lib.resources.files.FileUtils;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
import com.owncloud.android.lib.common.accounts.AccountUtils.Constants;
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientMap;
import com.owncloud.android.ui.activity.FailedUploadActivity;
import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.ui.activity.FileDisplayActivity;
@ -486,8 +486,9 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
/// prepare client object to send requests to the ownCloud server
if (mUploadClient == null || !mLastAccount.equals(mCurrentUpload.getAccount())) {
mLastAccount = mCurrentUpload.getAccount();
mStorageManager = new FileDataStorageManager(mLastAccount, getContentResolver());
mUploadClient = OwnCloudClientFactory.createOwnCloudClient(mLastAccount, getApplicationContext());
mStorageManager =
new FileDataStorageManager(mLastAccount, getContentResolver());
mUploadClient = OwnCloudClientMap.getClientFor(mLastAccount, this);
}
/// check the existence of the parent folder for the file to upload

View file

@ -97,6 +97,7 @@ public abstract class SyncOperation extends RemoteOperation {
* @param listenerHandler Handler associated to the thread where the methods of the listener objects must be called.
* @return Thread were the remote operation is executed.
*/
/*
public Thread execute(FileDataStorageManager storageManager, Context context, OnRemoteOperationListener listener, Handler listenerHandler, Activity callerActivity) {
if (storageManager == null) {
throw new IllegalArgumentException("Trying to execute a sync operation with a NULL storage manager");
@ -107,6 +108,7 @@ public abstract class SyncOperation extends RemoteOperation {
mStorageManager = storageManager;
return super.execute(storageManager.getAccount(), context, listener, listenerHandler, callerActivity);
}
*/
/**

View file

@ -25,8 +25,9 @@ import java.util.concurrent.ConcurrentMap;
import com.owncloud.android.R;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.OwnCloudClientMap;
import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
@ -453,8 +454,12 @@ public class OperationsService extends Service {
if (mLastTarget == null || !mLastTarget.equals(next.first)) {
mLastTarget = next.first;
if (mLastTarget.mAccount != null) {
mOwnCloudClient = OwnCloudClientFactory.createOwnCloudClient(mLastTarget.mAccount, getApplicationContext());
mStorageManager = new FileDataStorageManager(mLastTarget.mAccount, getContentResolver());
mOwnCloudClient =
OwnCloudClientMap.getClientFor(mLastTarget.mAccount, this);
mStorageManager =
new FileDataStorageManager(
mLastTarget.mAccount,
getContentResolver());
} else {
mOwnCloudClient = OwnCloudClientFactory.createOwnCloudClient(mLastTarget.mServerUrl, getApplicationContext(),
mLastTarget.mFollowRedirects); // this is not good enough

View file

@ -27,8 +27,8 @@ import org.apache.http.client.ClientProtocolException;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientMap;
import android.accounts.Account;
@ -102,7 +102,7 @@ public abstract class AbstractOwnCloudSyncAdapter extends
protected void initClientForCurrentAccount() throws OperationCanceledException, AuthenticatorException, IOException, AccountNotFoundException {
AccountUtils.constructFullURLForAccount(getContext(), account);
mClient = OwnCloudClientFactory.createOwnCloudClient(account, getContext());
mClient = OwnCloudClientMap.getClientFor(account, getContext());
}
protected OwnCloudClient getClient() {

View file

@ -464,7 +464,7 @@ implements OnRemoteOperationListener, ComponentsGetter {
}
}
private void requestCredentialsUpdate() {
protected void requestCredentialsUpdate() {
Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);
updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, getAccount());
updateAccountCredentials.putExtra(

View file

@ -19,8 +19,14 @@
package com.owncloud.android.ui.activity;
import java.io.File;
import java.io.IOException;
import org.apache.commons.httpclient.Credentials;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
@ -68,6 +74,11 @@ import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
import com.owncloud.android.operations.CreateFolderOperation;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientMap;
import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
import com.owncloud.android.lib.common.network.BearerCredentials;
import com.owncloud.android.lib.common.network.CertificateCombinedException;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
@ -918,10 +929,45 @@ FileFragment.ContainerActivity, OnNavigationListener, OnSslUntrustedCertListener
mSyncInProgress = (!FileSyncAdapter.EVENT_FULL_SYNC_END.equals(event) && !SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED.equals(event));
if (SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED.
equals(event) &&
/// TODO refactor and make common
synchResult != null && !synchResult.isSuccess() &&
(synchResult.getCode() == ResultCode.UNAUTHORIZED ||
synchResult.isIdPRedirection() ||
(synchResult.isException() && synchResult.getException()
instanceof AuthenticatorException))) {
OwnCloudClient client = OwnCloudClientMap.removeClientFor(getAccount());
if (client != null) {
Credentials cred = client.getCredentials();
String ssoSessionCookie = client.getSsoSessionCookie();
if (cred != null || ssoSessionCookie != null) {
boolean bearerAuthorization = (cred != null && cred instanceof BearerCredentials);
boolean samlBasedSsoAuthorization = (cred == null && ssoSessionCookie != null);
AccountManager am = AccountManager.get(context);
if (bearerAuthorization) {
am.invalidateAuthToken(getAccount().type,
((BearerCredentials)cred).getAccessToken());
} else if (samlBasedSsoAuthorization ) {
am.invalidateAuthToken(getAccount().type, ssoSessionCookie);
} else {
am.clearPassword(getAccount());
}
}
}
requestCredentialsUpdate();
}
removeStickyBroadcast(intent);
Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress);
setSupportProgressBarIndeterminateVisibility(mSyncInProgress /*|| mRefreshSharesInProgress*/);
}
removeStickyBroadcast(intent);
Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress);
setSupportProgressBarIndeterminateVisibility(mSyncInProgress /*|| mRefreshSharesInProgress*/);
}
@ -1478,7 +1524,7 @@ FileFragment.ContainerActivity, OnNavigationListener, OnSslUntrustedCertListener
getAccount(),
getApplicationContext()
);
synchFolderOp.execute(getAccount(), this, null, null, this);
synchFolderOp.execute(getAccount(), this, null, null);
setSupportProgressBarIndeterminateVisibility(true);
}

View file

@ -329,19 +329,10 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
public void uploadFiles() {
try {
//OwnCloudClient webdav = OwnCloudClientUtils.createOwnCloudClient(mAccount, getApplicationContext());
ArrayList<String> local = new ArrayList<String>();
ArrayList<String> remote = new ArrayList<String>();
/* TODO - mCreateDir can never be true at this moment; we will replace wdc.createDirectory by CreateFolderOperation when that is fixed
OwnCloudClient wdc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getApplicationContext());
// create last directory in path if necessary
if (mCreateDir) {
wdc.createDirectory(mUploadPath);
}
*/
// this checks the mimeType
for (Parcelable mStream : mStreamsToUpload) {