From e72ba25fe58d02b77e735c273f97d6553ec69a2c Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Thu, 5 May 2016 11:10:05 +1000 Subject: [PATCH] Call stopService to ensure notification goes away. Always show download notifications. Addresses a bug found in MR !273 whereby removing `stopForeground` results in a persistent "Downloading ..." notification even though it was cancelled. In the process of doing this, it also addresses / Fixes #621 by ensuring that all downloads of apks are done in a foreground service, regardless of the preference used for foreground updater service updating. --- .../fdroid/fdroid/net/DownloaderService.java | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java b/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java index 0f53a4693..ce1b05c3f 100644 --- a/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java +++ b/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java @@ -43,7 +43,6 @@ import android.util.Log; import org.fdroid.fdroid.AppDetails; import org.fdroid.fdroid.FDroid; -import org.fdroid.fdroid.Preferences; import org.fdroid.fdroid.R; import org.fdroid.fdroid.Utils; import org.fdroid.fdroid.data.App; @@ -260,10 +259,8 @@ public class DownloaderService extends Service { final String packageName = intent.getStringExtra(EXTRA_PACKAGE_NAME); sendBroadcast(uri, Downloader.ACTION_STARTED, localFile); - if (Preferences.get().isUpdateNotificationEnabled()) { - Notification notification = createNotification(intent.getDataString(), intent.getStringExtra(EXTRA_PACKAGE_NAME)).build(); - startForeground(NOTIFY_DOWNLOADING, notification); - } + Notification notification = createNotification(intent.getDataString(), packageName).build(); + startForeground(NOTIFY_DOWNLOADING, notification); try { downloader = DownloaderFactory.create(this, uri, localFile); @@ -276,13 +273,11 @@ public class DownloaderService extends Service { intent.putExtra(Downloader.EXTRA_TOTAL_BYTES, totalBytes); localBroadcastManager.sendBroadcast(intent); - if (Preferences.get().isUpdateNotificationEnabled()) { - NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - Notification notification = createNotification(uri.toString(), packageName) - .setProgress(totalBytes, bytesRead, false) - .build(); - nm.notify(NOTIFY_DOWNLOADING, notification); - } + NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + Notification notification = createNotification(uri.toString(), packageName) + .setProgress(totalBytes, bytesRead, false) + .build(); + nm.notify(NOTIFY_DOWNLOADING, notification); } }); downloader.download(); @@ -298,6 +293,7 @@ public class DownloaderService extends Service { if (downloader != null) { downloader.close(); } + stopForeground(true); } downloader = null; }