From 07c50f1e60407083113bacf7c39b8bda67523b2b Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Wed, 22 Jun 2016 11:48:04 -0600 Subject: Update notifications when no jobs are scheduled. When inserting an already-completed download, we don't schedule a job, leaving notifications stale until the next real download comes along. This change kicks off a notification update pass in these cases to ensure we reflect the internal state. Bug: 29548026 Change-Id: I6ff87d69d83c265738d5e035197204bbb63cfa81 --- src/com/android/providers/downloads/Helpers.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/com/android/providers/downloads') diff --git a/src/com/android/providers/downloads/Helpers.java b/src/com/android/providers/downloads/Helpers.java index d43e1022..e9549052 100644 --- a/src/com/android/providers/downloads/Helpers.java +++ b/src/com/android/providers/downloads/Helpers.java @@ -112,15 +112,21 @@ public class Helpers { } public static void scheduleJob(Context context, long downloadId) { - scheduleJob(context, DownloadInfo.queryDownloadInfo(context, downloadId)); + final boolean scheduled = scheduleJob(context, + DownloadInfo.queryDownloadInfo(context, downloadId)); + if (!scheduled) { + // If we didn't schedule a future job, kick off a notification + // update pass immediately + getDownloadNotifier(context).update(); + } } /** * Schedule (or reschedule) a job for the given {@link DownloadInfo} using * its current state to define job constraints. */ - public static void scheduleJob(Context context, DownloadInfo info) { - if (info == null) return; + public static boolean scheduleJob(Context context, DownloadInfo info) { + if (info == null) return false; final JobScheduler scheduler = context.getSystemService(JobScheduler.class); @@ -129,7 +135,7 @@ public class Helpers { scheduler.cancel(jobId); // Skip scheduling if download is paused or finished - if (!info.isReadyToSchedule()) return; + if (!info.isReadyToSchedule()) return false; final JobInfo.Builder builder = new JobInfo.Builder(jobId, new ComponentName(context, DownloadJobService.class)); @@ -166,6 +172,7 @@ public class Helpers { } scheduler.scheduleAsPackage(builder.build(), packageName, UserHandle.myUserId(), TAG); + return true; } /* -- cgit v1.2.3