projects
/
pub
/
Android
/
ownCloud.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
2058391
)
Try to cancel transfers when an account is deleted outside of the app: Done
author
masensio
<masensio@solidgear.es>
Thu, 19 Feb 2015 11:50:53 +0000
(12:50 +0100)
committer
masensio
<masensio@solidgear.es>
Thu, 19 Feb 2015 11:50:53 +0000
(12:50 +0100)
src/com/owncloud/android/files/services/FileDownloader.java
patch
|
blob
|
blame
|
history
src/com/owncloud/android/files/services/FileUploader.java
patch
|
blob
|
blame
|
history
src/com/owncloud/android/ui/activity/FileActivity.java
patch
|
blob
|
blame
|
history
diff --git
a/src/com/owncloud/android/files/services/FileDownloader.java
b/src/com/owncloud/android/files/services/FileDownloader.java
index
4ae3325
..
efe271d
100644
(file)
--- a/
src/com/owncloud/android/files/services/FileDownloader.java
+++ b/
src/com/owncloud/android/files/services/FileDownloader.java
@@
-235,7
+235,8
@@
public class FileDownloader extends Service implements OnDatatransferProgressLis
);
Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
"Removing download of " + file.getRemotePath());*/
);
Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
"Removing download of " + file.getRemotePath());*/
- Pair<DownloadFileOperation, String> removeResult = mPendingDownloads.remove(account, file.getRemotePath());
+ Pair<DownloadFileOperation, String> removeResult =
+ mPendingDownloads.remove(account, file.getRemotePath());
DownloadFileOperation download = removeResult.first;
if (download != null) {
/*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
DownloadFileOperation download = removeResult.first;
if (download != null) {
/*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
@@
-352,6
+353,17
@@
public class FileDownloader extends Service implements OnDatatransferProgressLis
boundListener.onTransferProgress(progressRate, totalTransferredSoFar, totalToTransfer, fileName);
}
}
boundListener.onTransferProgress(progressRate, totalTransferredSoFar, totalToTransfer, fileName);
}
}
+
+ /**
+ * Review downloads and cancel it if its account doesn't exist
+ */
+ public void reviewDownloads() {
+ if (mCurrentDownload != null &&
+ !AccountUtils.exists(mCurrentDownload.getAccount(), getApplicationContext())) {
+ mCurrentDownload.cancel();
+ }
+ // The rest of downloads are cancelled when they try to start
+ }
}
}
diff --git
a/src/com/owncloud/android/files/services/FileUploader.java
b/src/com/owncloud/android/files/services/FileUploader.java
index
b076d6f
..
3ce1aac
100644
(file)
--- a/
src/com/owncloud/android/files/services/FileUploader.java
+++ b/
src/com/owncloud/android/files/services/FileUploader.java
@@
-459,6
+459,16
@@
public class FileUploader extends Service implements OnDatatransferProgressListe
}
}
}
}
+ /**
+ * Review uploads and cancel it if its account doesn't exist
+ */
+ public void reviewUploads() {
+ if (mCurrentUpload != null &&
+ !AccountUtils.exists(mCurrentUpload.getAccount(), getApplicationContext())) {
+ mCurrentUpload.cancel();
+ }
+ // The rest of uploads are cancelled when they try to start
+ }
}
/**
}
/**
diff --git
a/src/com/owncloud/android/ui/activity/FileActivity.java
b/src/com/owncloud/android/ui/activity/FileActivity.java
index
4f0e5bc
..
578c596
100644
(file)
--- a/
src/com/owncloud/android/ui/activity/FileActivity.java
+++ b/
src/com/owncloud/android/ui/activity/FileActivity.java
@@
-23,6
+23,7
@@
import android.accounts.AccountManager;
import android.accounts.AccountManagerCallback;
import android.accounts.AccountManagerFuture;
import android.accounts.AuthenticatorException;
import android.accounts.AccountManagerCallback;
import android.accounts.AccountManagerFuture;
import android.accounts.AuthenticatorException;
+import android.accounts.OnAccountsUpdateListener;
import android.accounts.OperationCanceledException;
import android.content.ComponentName;
import android.content.Context;
import android.accounts.OperationCanceledException;
import android.content.ComponentName;
import android.content.Context;
@@
-68,8
+69,8
@@
import com.owncloud.android.utils.ErrorMessageAdapter;
*
* @author David A. Velasco
*/
*
* @author David A. Velasco
*/
-public class FileActivity extends SherlockFragmentActivity
-
implements OnRemoteOperationListener, ComponentsGett
er {
+public class FileActivity extends SherlockFragmentActivity
+
implements OnRemoteOperationListener, ComponentsGetter, OnAccountsUpdateListen
er {
public static final String EXTRA_FILE = "com.owncloud.android.ui.activity.FILE";
public static final String EXTRA_ACCOUNT = "com.owncloud.android.ui.activity.ACCOUNT";
public static final String EXTRA_FILE = "com.owncloud.android.ui.activity.FILE";
public static final String EXTRA_ACCOUNT = "com.owncloud.android.ui.activity.ACCOUNT";
@@
-79,7
+80,7
@@
implements OnRemoteOperationListener, ComponentsGetter {
public static final String TAG = FileActivity.class.getSimpleName();
private static final String DIALOG_WAIT_TAG = "DIALOG_WAIT";
public static final String TAG = FileActivity.class.getSimpleName();
private static final String DIALOG_WAIT_TAG = "DIALOG_WAIT";
- private static final String KEY_WAITING_FOR_OP_ID = "WAITING_FOR_OP_ID";
;
+ private static final String KEY_WAITING_FOR_OP_ID = "WAITING_FOR_OP_ID";
protected static final long DELAY_TO_REQUEST_OPERATION_ON_ACTIVITY_RESULTS = 200;
protected static final long DELAY_TO_REQUEST_OPERATION_ON_ACTIVITY_RESULTS = 200;
@@
-158,6
+159,10
@@
implements OnRemoteOperationListener, ComponentsGetter {
if (mUploadServiceConnection != null) {
bindService(new Intent(this, FileUploader.class), mUploadServiceConnection, Context.BIND_AUTO_CREATE);
}
if (mUploadServiceConnection != null) {
bindService(new Intent(this, FileUploader.class), mUploadServiceConnection, Context.BIND_AUTO_CREATE);
}
+
+ // add AccountsUpdatedListener
+ AccountManager am = AccountManager.get(getApplicationContext());
+ am.addOnAccountsUpdatedListener(this, null, false);
}
}
@@
-221,6
+226,11
@@
implements OnRemoteOperationListener, ComponentsGetter {
unbindService(mUploadServiceConnection);
mUploadServiceConnection = null;
}
unbindService(mUploadServiceConnection);
mUploadServiceConnection = null;
}
+
+ // remove AccountsUpdatedListener
+ AccountManager am = AccountManager.get(getApplicationContext());
+ am.removeOnAccountsUpdatedListener(this);
+
super.onDestroy();
}
super.onDestroy();
}
@@
-256,8
+266,6
@@
implements OnRemoteOperationListener, ComponentsGetter {
* to create a new ownCloud {@link Account}.
*
* POSTCONDITION: updates {@link #mAccountWasSet} and {@link #mAccountWasRestored}.
* to create a new ownCloud {@link Account}.
*
* POSTCONDITION: updates {@link #mAccountWasSet} and {@link #mAccountWasRestored}.
- *
- * @return 'True' if the checked {@link Account} was valid.
*/
private void swapToDefaultAccount() {
// default to the most recently used account
*/
private void swapToDefaultAccount() {
// default to the most recently used account
@@
-289,6
+297,7
@@
implements OnRemoteOperationListener, ComponentsGetter {
this,
new AccountCreationCallback(),
null);
this,
new AccountCreationCallback(),
null);
+ am.addOnAccountsUpdatedListener(this, null, true);
}
}
@@
-356,7
+365,15
@@
implements OnRemoteOperationListener, ComponentsGetter {
protected ServiceConnection newTransferenceServiceConnection() {
return null;
}
protected ServiceConnection newTransferenceServiceConnection() {
return null;
}
-
+
+ @Override
+ public void onAccountsUpdated(Account[] accounts) {
+ // detect a change in the list of accounts
+ Log_OC.d(TAG, "onAccountsUpdated");
+ mDownloaderBinder.reviewDownloads();
+ mUploaderBinder.reviewUploads();
+ }
+
/**
* Helper class handling a callback from the {@link AccountManager} after the creation of
/**
* Helper class handling a callback from the {@link AccountManager} after the creation of