X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/0f7ea542c9b657ba6ad335cd5003901b6ab35385..898957f9e758b12b418801754bb225d94e51317e:/src/com/owncloud/android/files/services/FileDownloader.java diff --git a/src/com/owncloud/android/files/services/FileDownloader.java b/src/com/owncloud/android/files/services/FileDownloader.java index 64eea6be..f5be6a76 100644 --- a/src/com/owncloud/android/files/services/FileDownloader.java +++ b/src/com/owncloud/android/files/services/FileDownloader.java @@ -1,4 +1,6 @@ -/* ownCloud Android client application +/** + * ownCloud Android client application + * * Copyright (C) 2012 Bartek Przybylski * Copyright (C) 2012-2015 ownCloud Inc. * @@ -25,7 +27,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Vector; -import java.util.concurrent.ConcurrentMap; import com.owncloud.android.R; import com.owncloud.android.authentication.AccountUtils; @@ -51,7 +52,9 @@ import com.owncloud.android.ui.preview.PreviewImageFragment; import com.owncloud.android.utils.ErrorMessageAdapter; import android.accounts.Account; +import android.accounts.AccountManager; import android.accounts.AccountsException; +import android.accounts.OnAccountsUpdateListener; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; @@ -66,7 +69,8 @@ import android.os.Process; import android.support.v4.app.NotificationCompat; import android.util.Pair; -public class FileDownloader extends Service implements OnDatatransferProgressListener { +public class FileDownloader extends Service + implements OnDatatransferProgressListener, OnAccountsUpdateListener { public static final String EXTRA_ACCOUNT = "ACCOUNT"; public static final String EXTRA_FILE = "FILE"; @@ -118,6 +122,10 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis mServiceLooper = thread.getLooper(); mServiceHandler = new ServiceHandler(mServiceLooper, this); mBinder = new FileDownloaderBinder(); + + // add AccountsUpdatedListener + AccountManager am = AccountManager.get(getApplicationContext()); + am.addOnAccountsUpdatedListener(this, null, false); } @@ -132,6 +140,11 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis mServiceLooper.quit(); mServiceLooper = null; mNotificationManager = null; + + // remove AccountsUpdatedListener + AccountManager am = AccountManager.get(getApplicationContext()); + am.removeOnAccountsUpdatedListener(this); + super.onDestroy(); } @@ -224,6 +237,16 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis return false; // not accepting rebinding (default behaviour) } + @Override + public void onAccountsUpdated(Account[] accounts) { + //review the current download and cancel it if its account doesn't exist + if (mCurrentDownload != null && + !AccountUtils.exists(mCurrentDownload.getAccount(), getApplicationContext())) { + mCurrentDownload.cancel(); + } + // The rest of downloads are cancelled when they try to start + } + /** * Binder to let client components to perform operations on the queue of downloads. @@ -667,7 +690,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis /** * Remove downloads of an account * - * @param account + * @param account Downloads account to remove */ private void cancelDownloadsForAccount(Account account) { // Cancel pending downloads