diff options
author | Jeff Sharkey <jsharkey@android.com> | 2017-09-28 14:41:38 -0600 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2017-09-28 14:41:40 -0600 |
commit | b02470a0886c0466ec3fe201672dcfd0b3492155 (patch) | |
tree | 14c416e284bcee6cfe50e94a967156d7081e02f6 /src/com/android/providers/downloads/DownloadJobService.java | |
parent | 87cd054358967b8d2670f15d2ecd1a27222f072d (diff) | |
download | android_packages_providers_DownloadProvider-b02470a0886c0466ec3fe201672dcfd0b3492155.tar.gz android_packages_providers_DownloadProvider-b02470a0886c0466ec3fe201672dcfd0b3492155.tar.bz2 android_packages_providers_DownloadProvider-b02470a0886c0466ec3fe201672dcfd0b3492155.zip |
Prevent duplicate jobs for same download.
Before this CL, we could have started duplicate jobs for the same
download ID in parallel. Now, we ignore duplicate jobs for the same
download. This requires us to only reschedule a job after removing
it from mActiveThreads, so slight refactoring there.
Test: bit DownloadProviderTests:*
Bug: 36227864
Change-Id: I3103480859c5eb9488817165187c5dae05b2d843
Diffstat (limited to 'src/com/android/providers/downloads/DownloadJobService.java')
-rw-r--r-- | src/com/android/providers/downloads/DownloadJobService.java | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/com/android/providers/downloads/DownloadJobService.java b/src/com/android/providers/downloads/DownloadJobService.java index 0ce4266a..d09738c2 100644 --- a/src/com/android/providers/downloads/DownloadJobService.java +++ b/src/com/android/providers/downloads/DownloadJobService.java @@ -66,6 +66,10 @@ public class DownloadJobService extends JobService { final DownloadThread thread; synchronized (mActiveThreads) { + if (mActiveThreads.indexOfKey(id) >= 0) { + Log.w(TAG, "Odd, already running download " + id); + return false; + } thread = new DownloadThread(this, params, info); mActiveThreads.put(id, thread); } @@ -93,14 +97,20 @@ public class DownloadJobService extends JobService { } public void jobFinishedInternal(JobParameters params, boolean needsReschedule) { + final int id = params.getJobId(); + synchronized (mActiveThreads) { mActiveThreads.remove(params.getJobId()); } + if (needsReschedule) { + Helpers.scheduleJob(this, DownloadInfo.queryDownloadInfo(this, id)); + } // Update notifications one last time while job is protecting us mObserver.onChange(false); - jobFinished(params, needsReschedule); + // We do our own rescheduling above + jobFinished(params, false); } private ContentObserver mObserver = new ContentObserver(Helpers.getAsyncHandler()) { |