X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/20583912301fc6b0ec069ebfeeba50d52d435183..cb175f29949dbac17a3870a71ecff60df5c9bdc4:/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 4ae3325d..a126028b 100644 --- a/src/com/owncloud/android/files/services/FileDownloader.java +++ b/src/com/owncloud/android/files/services/FileDownloader.java @@ -111,15 +111,31 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis @Override public void onCreate() { super.onCreate(); + Log_OC.d(TAG, "Creating service"); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - HandlerThread thread = new HandlerThread("FileDownloaderThread", - Process.THREAD_PRIORITY_BACKGROUND); + HandlerThread thread = new HandlerThread("FileDownloaderThread", Process.THREAD_PRIORITY_BACKGROUND); thread.start(); mServiceLooper = thread.getLooper(); mServiceHandler = new ServiceHandler(mServiceLooper, this); mBinder = new FileDownloaderBinder(); } + + /** + * Service clean up + */ + @Override + public void onDestroy() { + Log_OC.v(TAG, "Destroying service" ); + mBinder = null; + mServiceHandler = null; + mServiceLooper.quit(); + mServiceLooper = null; + mNotificationManager = null; + super.onDestroy(); + } + + /** * Entry point to add one or several files to the queue of downloads. * @@ -128,6 +144,8 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis */ @Override public int onStartCommand(Intent intent, int flags, int startId) { + Log_OC.d(TAG, "Starting command with id " + startId); + if ( !intent.hasExtra(EXTRA_ACCOUNT) || !intent.hasExtra(EXTRA_FILE) ) { @@ -235,7 +253,8 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis ); Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(), "Removing download of " + file.getRemotePath());*/ - Pair removeResult = mPendingDownloads.remove(account, file.getRemotePath()); + Pair removeResult = + mPendingDownloads.remove(account, file.getRemotePath()); DownloadFileOperation download = removeResult.first; if (download != null) { /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(), @@ -352,6 +371,17 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis 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 + } } @@ -379,11 +409,10 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis Iterator it = requestedDownloads.iterator(); while (it.hasNext()) { String next = it.next(); - /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(), - "Handling download file " + next);*/ mService.downloadFile(next); } } + Log_OC.d(TAG, "Stopping after command with id " + msg.arg1); mService.stopSelf(msg.arg1); } }