Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Unified Diff: components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskSchedulerJobService.java

Issue 2906063004: [Android] Reimplementing BTSJobSerivce delegate to not overwrite tasks (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskSchedulerJobService.java
diff --git a/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskSchedulerJobService.java b/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskSchedulerJobService.java
index cf86dda2bc0c4cb72d8e0c89dc4cbd902943057e..4a19907d6a7fcb3c93f0fc3a3009998c2f7fca51 100644
--- a/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskSchedulerJobService.java
+++ b/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskSchedulerJobService.java
@@ -18,6 +18,7 @@ import org.chromium.base.Log;
import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting;
+import java.util.List;
/**
* An implementation of {@link BackgroundTaskSchedulerDelegate} that uses the system
* {@link JobScheduler} to schedule jobs.
@@ -141,8 +142,8 @@ class BackgroundTaskSchedulerJobService implements BackgroundTaskSchedulerDelega
JobScheduler jobScheduler =
(JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
- if (taskInfo.shouldUpdateCurrent()) {
- jobScheduler.cancel(taskInfo.getTaskId());
+ if (!taskInfo.shouldUpdateCurrent() && hasPendingJob(jobScheduler, taskInfo.getTaskId())) {
+ return true;
}
int result = jobScheduler.schedule(jobInfo);
@@ -156,4 +157,13 @@ class BackgroundTaskSchedulerJobService implements BackgroundTaskSchedulerDelega
(JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
jobScheduler.cancel(taskId);
}
+
+ private boolean hasPendingJob(JobScheduler jobScheduler, int jobId) {
+ List<JobInfo> pendingJobs = jobScheduler.getAllPendingJobs();
+ for (JobInfo pendingJob : pendingJobs) {
+ if (pendingJob.getId() == jobId) return true;
+ }
+
+ return false;
+ }
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698