@Test public void testCancelAll() { JobInfo job = JobCreator.create(application).setMinimumLatency(TimeUnit.HOURS.toMillis(1)).build(); jobScheduler.schedule(job); JobInfo job2 = JobCreator.create(application).setMinimumLatency(TimeUnit.HOURS.toMillis(1)).build(); jobScheduler.schedule(job2); JobInfo job3 = JobCreator.create(application).setMinimumLatency(TimeUnit.HOURS.toMillis(1)).build(); jobScheduler.schedule(job3); assertJobSchedulerContains(job.getId(), job2.getId(), job3.getId()); jobScheduler.cancelAll(); assertJobSchedulerContains(); }
public void cancelAll() { synchronized (JobStore.LOCK) { Set<String> tags = new HashSet<>(); for (JobStatus jobStatus : jobStore.getJobs()) { tags.add(jobStatus.getSchedulerTag()); } jobStore.clear(); for (String tag : tags) { getSchedulerForTag(context, tag).cancelAll(); } } }
JobScheduler { public void cancelAll() { synchronized (JobStore.LOCK) { Set<String> tags = new HashSet<>(); for (JobStatus jobStatus : jobStore.getJobs()) { tags.add(jobStatus.getSchedulerTag()); } jobStore.clear(); for (String tag : tags) { getSchedulerForTag(context, tag).cancelAll(); } } } }
JobScheduler { public void cancelAll() { synchronized (JobStore.LOCK) { Set<String> tags = new HashSet<>(); for (JobStatus jobStatus : jobStore.getJobs()) { tags.add(jobStatus.getSchedulerTag()); } jobStore.clear(); for (String tag : tags) { getSchedulerForTag(context, tag).cancelAll(); } } } private  JobScheduler(Context context); }
JobScheduler { public void cancelAll() { synchronized (JobStore.LOCK) { Set<String> tags = new HashSet<>(); for (JobStatus jobStatus : jobStore.getJobs()) { tags.add(jobStatus.getSchedulerTag()); } jobStore.clear(); for (String tag : tags) { getSchedulerForTag(context, tag).cancelAll(); } } } private  JobScheduler(Context context); static synchronized JobScheduler get(Context context); int schedule(JobInfo job); void cancel(int jobId); void cancelAll(); @NonNull List<JobInfo> getAllPendingJobs(); @Nullable JobInfo getPendingJob(int jobId); @RestrictTo(RestrictTo.Scope.LIBRARY) void onJobCompleted(int jobId, boolean needsReschedule); @RestrictTo(RestrictTo.Scope.LIBRARY) List<JobStatus> getJobsByScheduler(String scheduler); @RestrictTo(RestrictTo.Scope.LIBRARY) JobStatus getJob(int jobId); @RestrictTo(RestrictTo.Scope.LIBRARY) void addJob(JobStatus jobStatus); @RestrictTo(RestrictTo.Scope.LIBRARY) void removeJob(int jobId); }
JobScheduler { public void cancelAll() { synchronized (JobStore.LOCK) { Set<String> tags = new HashSet<>(); for (JobStatus jobStatus : jobStore.getJobs()) { tags.add(jobStatus.getSchedulerTag()); } jobStore.clear(); for (String tag : tags) { getSchedulerForTag(context, tag).cancelAll(); } } } private  JobScheduler(Context context); static synchronized JobScheduler get(Context context); int schedule(JobInfo job); void cancel(int jobId); void cancelAll(); @NonNull List<JobInfo> getAllPendingJobs(); @Nullable JobInfo getPendingJob(int jobId); @RestrictTo(RestrictTo.Scope.LIBRARY) void onJobCompleted(int jobId, boolean needsReschedule); @RestrictTo(RestrictTo.Scope.LIBRARY) List<JobStatus> getJobsByScheduler(String scheduler); @RestrictTo(RestrictTo.Scope.LIBRARY) JobStatus getJob(int jobId); @RestrictTo(RestrictTo.Scope.LIBRARY) void addJob(JobStatus jobStatus); @RestrictTo(RestrictTo.Scope.LIBRARY) void removeJob(int jobId); static final int RESULT_FAILURE; static final int RESULT_SUCCESS; }