summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java15
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java14
2 files changed, 21 insertions, 8 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 40cc5f3f3..8c26a6d74 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
@@ -18,6 +18,7 @@ import androidx.annotation.VisibleForTesting;
import androidx.core.app.ServiceCompat;
import androidx.core.content.ContextCompat;
+import de.danoeh.antennapod.core.BuildConfig;
import de.danoeh.antennapod.core.R;
import de.danoeh.antennapod.core.feed.LocalFeedUpdater;
import de.danoeh.antennapod.core.storage.EpisodeCleanupAlgorithmFactory;
@@ -141,9 +142,6 @@ public class DownloadService extends Service {
}
public static void download(Context context, boolean cleanupMedia, DownloadRequest... requests) {
- if (requests.length > 100) {
- throw new IllegalArgumentException("Android silently drops intent payloads that are too large");
- }
ArrayList<DownloadRequest> requestsToSend = new ArrayList<>();
for (DownloadRequest request : requests) {
if (!isDownloadingFile(request.getSource())) {
@@ -152,7 +150,15 @@ public class DownloadService extends Service {
}
if (requestsToSend.isEmpty()) {
return;
+ } else if (requestsToSend.size() > 100) {
+ if (BuildConfig.DEBUG) {
+ throw new IllegalArgumentException("Android silently drops intent payloads that are too large");
+ } else {
+ Log.d(TAG, "Too many download requests. Dropping some to avoid Android dropping all.");
+ requestsToSend = new ArrayList<>(requestsToSend.subList(0, 100));
+ }
}
+
Intent launchIntent = new Intent(context, DownloadService.class);
launchIntent.putParcelableArrayListExtra(DownloadService.EXTRA_REQUESTS, requestsToSend);
if (cleanupMedia) {
@@ -521,6 +527,9 @@ public class DownloadService extends Service {
if (isDownloadingFile(request.getSource())) {
Log.d(TAG, "Skipped enqueueing request. Already running.");
return;
+ } else if (downloadHandleExecutor.isShutdown()) {
+ Log.d(TAG, "Skipped enqueueing request. Service is already shutting down.");
+ return;
}
Log.d(TAG, "Add new request: " + request.getSource());
if (request.getSource().startsWith(Feed.PREFIX_LOCAL_FOLDER)) {
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java
index f5677433f..96ac08c6d 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java
@@ -136,7 +136,9 @@ public class DownloadServiceNotification {
continue;
}
sb.append("• ").append(statuses.get(i).getTitle());
- sb.append(": ").append(context.getString(DownloadErrorLabel.from(statuses.get(i).getReason())));
+ if (statuses.get(i).getReason() != null) {
+ sb.append(": ").append(context.getString(DownloadErrorLabel.from(statuses.get(i).getReason())));
+ }
if (i != statuses.size() - 1) {
sb.append("\n");
}
@@ -153,16 +155,18 @@ public class DownloadServiceNotification {
public void updateReport(List<DownloadStatus> reportQueue, boolean showAutoDownloadReport) {
// check if report should be created
boolean createReport = false;
- int successfulDownloads = 0;
int failedDownloads = 0;
// a download report is created if at least one download has failed
// (excluding failed image downloads)
for (DownloadStatus status : reportQueue) {
+ if (status == null || status.isCancelled()) {
+ continue;
+ }
if (status.isSuccessful()) {
- successfulDownloads++;
- createReport |= showAutoDownloadReport && !status.isInitiatedByUser() && status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA;
- } else if (!status.isCancelled()) {
+ createReport |= showAutoDownloadReport && !status.isInitiatedByUser()
+ && status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA;
+ } else {
failedDownloads++;
createReport = true;
}