summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorLincoln Ramsay <a1291762@gmail.com>2021-02-25 23:13:48 +1000
committerLincoln Ramsay <a1291762@gmail.com>2021-02-28 09:34:25 +1000
commitfcbbaa40603a04ba809058327c8c9620f3798570 (patch)
tree5bedfb5bac5c61f334a79bfd6983a49523f9cd48 /core
parent1cd680a2af9bc7ae9717fac84109c25542e81f06 (diff)
downloadAntennaPod-fcbbaa40603a04ba809058327c8c9620f3798570.zip
Avoid stuck download notifications
Cancel the periodic updater before calling stopForeground so that the notification can't come back after it has been closed. Remove the workaround for API 30 slow notification closing because it can cause a stuck notification. However, in order to avoid misleading text being left on the notification if it closes slowly, ensure that the "0 downloads" text is written to the notification when shutting down. Fixes #4556
Diffstat (limited to 'core')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java26
1 files changed, 12 insertions, 14 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java
index 4a17fbbda..44b673a4d 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java
@@ -172,8 +172,7 @@ public class DownloadService extends Service {
setupNotificationUpdaterIfNecessary();
syncExecutor.execute(() -> onDownloadQueued(intent));
} else if (numberOfDownloads.get() == 0) {
- stopForeground(true);
- stopSelf();
+ shutdown();
} else {
Log.d(TAG, "onStartCommand: Unknown intent");
}
@@ -227,10 +226,6 @@ public class DownloadService extends Service {
}
unregisterReceiver(cancelDownloadReceiver);
- stopForeground(true);
- NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
- nm.cancel(R.id.notification_downloading);
-
// if this was the initial gpodder sync, i.e. we just synced the feeds successfully,
// it is now time to sync the episode actions
SyncService.sync(this);
@@ -550,14 +545,7 @@ public class DownloadService extends Service {
if (numberOfDownloads.get() <= 0 && DownloadRequester.getInstance().hasNoDownloads()) {
Log.d(TAG, "Attempting shutdown");
- stopForeground(true);
- stopSelf();
-
- // Trick to hide the notification more quickly when the service is stopped
- // Without this, the second-last update of the notification stays for 3 seconds after onDestroy returns
- notificationUpdater.run();
- NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
- nm.cancel(R.id.notification_downloading);
+ shutdown();
}
}
@@ -647,4 +635,14 @@ public class DownloadService extends Service {
new PostDownloaderTask(downloads), 1, 1, TimeUnit.SECONDS);
}
}
+
+ private void shutdown() {
+ // If the service was run for a very short time, the system may delay closing
+ // the notification. Set the notification text now so that a misleading message
+ // is not left on the notification.
+ notificationUpdater.run();
+ cancelNotificationUpdater();
+ stopForeground(true);
+ stopSelf();
+ }
}