@Test(expected = IllegalStateException.class) public void testScheduleHasUpperLimit() { for (int i = 0; i <= JobScheduler.MAX_JOBS + 1; i++) { jobScheduler.schedule( JobCreator.create(application, 2000).setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY).build()); } }
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; }