@Test public void testJobFinishedSuccess() { JobInfo job = JobCreator.create(application).setRequiresCharging(true).build(); JobStatus jobStatus = JobStatus.createFromJobInfo(job, noopScheduler.getTag()); jobStore.add(jobStatus); jobScheduler.onJobCompleted(job.getId(), false); assertJobSchedulerContains(); }
@RestrictTo(RestrictTo.Scope.LIBRARY) public void onJobCompleted(int jobId, boolean needsReschedule) { synchronized (JobStore.LOCK) { JobStatus jobStatus = jobStore.getJob(jobId); if (jobStatus != null) { jobStore.remove(jobId); if (needsReschedule) { jobStore.add(getRescheduleJobForFailure(jobStatus)); } else if (jobStatus.isPeriodic()) { jobStore.add(getRescheduleJobForPeriodic(jobStatus)); } getSchedulerForTag(context, jobStatus.getSchedulerTag()).onJobCompleted(jobId, needsReschedule); } } }
JobScheduler { @RestrictTo(RestrictTo.Scope.LIBRARY) public void onJobCompleted(int jobId, boolean needsReschedule) { synchronized (JobStore.LOCK) { JobStatus jobStatus = jobStore.getJob(jobId); if (jobStatus != null) { jobStore.remove(jobId); if (needsReschedule) { jobStore.add(getRescheduleJobForFailure(jobStatus)); } else if (jobStatus.isPeriodic()) { jobStore.add(getRescheduleJobForPeriodic(jobStatus)); } getSchedulerForTag(context, jobStatus.getSchedulerTag()).onJobCompleted(jobId, needsReschedule); } } } }
JobScheduler { @RestrictTo(RestrictTo.Scope.LIBRARY) public void onJobCompleted(int jobId, boolean needsReschedule) { synchronized (JobStore.LOCK) { JobStatus jobStatus = jobStore.getJob(jobId); if (jobStatus != null) { jobStore.remove(jobId); if (needsReschedule) { jobStore.add(getRescheduleJobForFailure(jobStatus)); } else if (jobStatus.isPeriodic()) { jobStore.add(getRescheduleJobForPeriodic(jobStatus)); } getSchedulerForTag(context, jobStatus.getSchedulerTag()).onJobCompleted(jobId, needsReschedule); } } } private  JobScheduler(Context context); }
JobScheduler { @RestrictTo(RestrictTo.Scope.LIBRARY) public void onJobCompleted(int jobId, boolean needsReschedule) { synchronized (JobStore.LOCK) { JobStatus jobStatus = jobStore.getJob(jobId); if (jobStatus != null) { jobStore.remove(jobId); if (needsReschedule) { jobStore.add(getRescheduleJobForFailure(jobStatus)); } else if (jobStatus.isPeriodic()) { jobStore.add(getRescheduleJobForPeriodic(jobStatus)); } getSchedulerForTag(context, jobStatus.getSchedulerTag()).onJobCompleted(jobId, needsReschedule); } } } 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 { @RestrictTo(RestrictTo.Scope.LIBRARY) public void onJobCompleted(int jobId, boolean needsReschedule) { synchronized (JobStore.LOCK) { JobStatus jobStatus = jobStore.getJob(jobId); if (jobStatus != null) { jobStore.remove(jobId); if (needsReschedule) { jobStore.add(getRescheduleJobForFailure(jobStatus)); } else if (jobStatus.isPeriodic()) { jobStore.add(getRescheduleJobForPeriodic(jobStatus)); } getSchedulerForTag(context, jobStatus.getSchedulerTag()).onJobCompleted(jobId, needsReschedule); } } } 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; }