From: masensio Date: Wed, 18 Feb 2015 17:39:10 +0000 (+0100) Subject: Cancel downloads for deleted users X-Git-Tag: oc-android-1.7.1_signed^2~40^2~9 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/20583912301fc6b0ec069ebfeeba50d52d435183?ds=inline Cancel downloads for deleted users --- diff --git a/AndroidManifest.xml b/AndroidManifest.xml index fd92d3d6..b520d092 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -86,8 +86,6 @@ android:name=".ui.activity.Preferences" android:theme="@style/Theme.ownCloud" > - - removeResult = - mPendingDownloads.removePayload(mCurrentAccount, mCurrentDownload.getRemotePath()); + Pair removeResult = + mPendingDownloads.removePayload(mCurrentAccount, mCurrentDownload.getRemotePath()); - /// notify result - notifyDownloadResult(mCurrentDownload, downloadResult); + /// notify result + notifyDownloadResult(mCurrentDownload, downloadResult); - sendBroadcastDownloadFinished(mCurrentDownload, downloadResult, removeResult.second); - } + sendBroadcastDownloadFinished(mCurrentDownload, downloadResult, removeResult.second); + } + } else { + // Cancel the transfer + Log_OC.d(TAG, "Account " + mCurrentDownload.getAccount().toString() + " doesn't exist"); + cancelDownloadsForAccount(mCurrentDownload.getAccount()); + } } } @@ -609,4 +653,32 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis sendStickyBroadcast(added); } + /** + * Remove downloads of an account + * @param account + */ + private void cancelDownloadsForAccount(Account account){ + // Cancel pending downloads + ConcurrentMap downloadsAccount = mPendingDownloads.get(account); + Iterator it = downloadsAccount.keySet().iterator(); + Log_OC.d(TAG, "Number of pending downloads= " + downloadsAccount.size()); + while (it.hasNext()) { + String key = it.next(); + Log_OC.d(TAG, "download CANCELLED " + key); + if (key.startsWith(account.name)) { + DownloadFileOperation download; + synchronized (mPendingDownloads) { + download = mPendingDownloads.get(key); + if (download != null) { + String remotePath = download.getRemotePath(); + if (mPendingDownloads.contains(account, remotePath)) { + mPendingDownloads.remove(account, remotePath); + } + } + } + } + } + } + + } diff --git a/src/com/owncloud/android/files/services/FileUploader.java b/src/com/owncloud/android/files/services/FileUploader.java index c5b92171..b076d6f4 100644 --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/src/com/owncloud/android/files/services/FileUploader.java @@ -367,23 +367,19 @@ public class FileUploader extends Service implements OnDatatransferProgressListe if (mCurrentUpload != null) { Log_OC.d(TAG, "Current Upload Account= " + mCurrentUpload.getAccount().name); - if (mCurrentUpload.getAccount().name == account.name) { + if (mCurrentUpload.getAccount().name.equals(account.name)) { mCurrentUpload.cancel(); } } // Cancel pending uploads Iterator it = mPendingUploads.keySet().iterator(); - Log_OC.d(TAG, "Number of pending updloads= " + mPendingUploads.size()); + Log_OC.d(TAG, "Number of pending uploads= " + mPendingUploads.size()); while (it.hasNext()) { String key = it.next(); Log_OC.d(TAG, "mPendingUploads CANCELLED " + key); if (key.startsWith(account.name)) { - UploadFileOperation upload; synchronized (mPendingUploads) { - upload = mPendingUploads.remove(key); - } - if (upload != null) { - mCurrentUpload.cancel(); + mPendingUploads.remove(key); } } } diff --git a/src/com/owncloud/android/files/services/IndexedForest.java b/src/com/owncloud/android/files/services/IndexedForest.java index e2e9cb85..f3c38fdd 100644 --- a/src/com/owncloud/android/files/services/IndexedForest.java +++ b/src/com/owncloud/android/files/services/IndexedForest.java @@ -21,8 +21,11 @@ import android.accounts.Account; import android.util.Pair; import com.owncloud.android.datamodel.OCFile; +import com.owncloud.android.lib.common.utils.Log_OC; +import com.owncloud.android.operations.UploadFileOperation; import java.io.File; +import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.Set; @@ -210,6 +213,21 @@ public class IndexedForest { } + public ConcurrentMap> get(Account account){ + ConcurrentMap> accountMap = new ConcurrentHashMap>(); + Iterator it = mMap.keySet().iterator(); + while (it.hasNext()) { + String key = it.next(); + Log_OC.d("IndexedForest", "Number of pending downloads= " + mMap.size()); + if (key.startsWith(account.name)) { + synchronized (accountMap) { + accountMap.putIfAbsent(key, mMap.get(key)); + } + } + } + return accountMap; + } + /** * Builds a key to index files * diff --git a/src/com/owncloud/android/operations/DownloadFileOperation.java b/src/com/owncloud/android/operations/DownloadFileOperation.java index 0a5ff94c..f6bee5d4 100644 --- a/src/com/owncloud/android/operations/DownloadFileOperation.java +++ b/src/com/owncloud/android/operations/DownloadFileOperation.java @@ -177,5 +177,4 @@ public class DownloadFileOperation extends RemoteOperation { mDataTransferListeners.remove(listener); } } - } diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 086e10a9..3b796966 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -1892,10 +1892,6 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener { onTransferStateChanged(file, false, false); } - public void cancelUploadsForAnAccount(Account account) { - mUploaderBinder.cancel(account); - } - @Override public void onRefresh(boolean ignoreETag) { refreshList(ignoreETag); diff --git a/src/com/owncloud/android/ui/activity/Preferences.java b/src/com/owncloud/android/ui/activity/Preferences.java index b03cd961..3b98061e 100644 --- a/src/com/owncloud/android/ui/activity/Preferences.java +++ b/src/com/owncloud/android/ui/activity/Preferences.java @@ -65,6 +65,8 @@ import com.owncloud.android.services.OperationsService; import com.owncloud.android.ui.RadioButtonPreference; import com.owncloud.android.utils.DisplayUtils; +import java.io.File; + /** * An Activity that allows the user to change the application's settings. @@ -443,6 +445,7 @@ public class Preferences extends SherlockPreferenceActivity if (!AccountUtils.exists(account, MainApp.getAppContext())) { // Cancel tranfers mUploaderBinder.cancel(account); + mDownloaderBinder.cancel(account); } Account a = AccountUtils.getCurrentOwnCloudAccount(this);