@Test public void testSchedule() { JobInfo job = JobCreator.create(application).setRequiresCharging(true).build(); jobScheduler.schedule(job); assertJobSchedulerContains(job.getId()); JobInfo job2 = JobCreator.create(application).setRequiresCharging(true).build(); jobScheduler.schedule(job2); assertJobSchedulerContains(job.getId(), job2.getId()); jobScheduler.schedule(job); assertJobSchedulerContains(job.getId(), job2.getId()); }
public int schedule(JobInfo job) { synchronized (JobStore.LOCK) { if (jobStore.size() > MAX_JOBS) { throw new IllegalStateException("Apps may not schedule more than " + MAX_JOBS + " distinct jobs"); } Scheduler scheduler = getSchedulerForJob(context, job); jobStore.add(JobStatus.createFromJobInfo(job, scheduler.getTag())); return scheduler.schedule(job); } }
JobScheduler { public int schedule(JobInfo job) { synchronized (JobStore.LOCK) { if (jobStore.size() > MAX_JOBS) { throw new IllegalStateException("Apps may not schedule more than " + MAX_JOBS + " distinct jobs"); } Scheduler scheduler = getSchedulerForJob(context, job); jobStore.add(JobStatus.createFromJobInfo(job, scheduler.getTag())); return scheduler.schedule(job); } } }
JobScheduler { public int schedule(JobInfo job) { synchronized (JobStore.LOCK) { if (jobStore.size() > MAX_JOBS) { throw new IllegalStateException("Apps may not schedule more than " + MAX_JOBS + " distinct jobs"); } Scheduler scheduler = getSchedulerForJob(context, job); jobStore.add(JobStatus.createFromJobInfo(job, scheduler.getTag())); return scheduler.schedule(job); } } private  JobScheduler(Context context); }
JobScheduler { public int schedule(JobInfo job) { synchronized (JobStore.LOCK) { if (jobStore.size() > MAX_JOBS) { throw new IllegalStateException("Apps may not schedule more than " + MAX_JOBS + " distinct jobs"); } Scheduler scheduler = getSchedulerForJob(context, job); jobStore.add(JobStatus.createFromJobInfo(job, scheduler.getTag())); return scheduler.schedule(job); } } 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 int schedule(JobInfo job) { synchronized (JobStore.LOCK) { if (jobStore.size() > MAX_JOBS) { throw new IllegalStateException("Apps may not schedule more than " + MAX_JOBS + " distinct jobs"); } Scheduler scheduler = getSchedulerForJob(context, job); jobStore.add(JobStatus.createFromJobInfo(job, scheduler.getTag())); return scheduler.schedule(job); } } 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; }