/*package*/ JobRequest getJobRequest(int jobId, boolean includeStarted) { JobRequest jobRequest = getJobStorage().get(jobId); if (!includeStarted && jobRequest != null && jobRequest.isStarted()) { return null; } else { return jobRequest; } }
private JobCallable(Job job) { mJob = job; Context context = mJob.getContext(); mWakeLock = WakeLockUtil.acquireWakeLock(context, "JobExecutor", WAKE_LOCK_TIMEOUT); }
/** * Cancel either the pending {@link JobRequest} or the running {@link Job}. * * @param jobId The unique ID of the {@link JobRequest} or running {@link Job}. * @return {@code true} if a request or job were found and canceled. */ public boolean cancel(int jobId) { // call both methods boolean result = cancelInner(getJobRequest(jobId, true)) | cancelInner(getJob(jobId)); JobProxy.Common.cleanUpOrphanedJob(mContext, jobId); // do this as well, just in case return result; }
@Test public void testStartNow() throws Exception { mJob = new TestJob(); new JobRequest.Builder("tag") .startNow() .setTransientExtras(createTransientBundle()) .build() .schedule(); mJob.verifyJob(3, TimeUnit.SECONDS); }
@Test public void testStartNow() throws Exception { mJob = new TestJob(PlatformAlarmService.class); new JobRequest.Builder("tag") .startNow() .build() .schedule(); mJob.verifyJob(3, TimeUnit.SECONDS); }
/** * @param jobId The unique ID of the pending {@link JobRequest}. * @return The {@link JobRequest} if it's pending or {@code null} otherwise. */ public JobRequest getJobRequest(int jobId) { JobRequest request = getJobRequest(jobId, false); if (request != null && request.isTransient() && !request.getJobApi().getProxy(mContext).isPlatformJobScheduled(request)) { getJobStorage().remove(request); return null; } else { return request; } }
public static long getEndMs(JobRequest request, boolean shiftEnd) { long endMs; if (request.getFailureCount() > 0) { endMs = request.getBackoffOffset(); } else { endMs = request.getEndMs(); } if (shiftEnd && request.requirementsEnforced() && request.hasRequirements()) { // move the end backwards if the API is smart with the requirements endMs = checkedMultiply(endMs, 100); } return endMs; }
/** * @return {@code false} if the {@link Job} requires the device to be idle and it isn't idle. Otherwise * always returns {@code true}. */ protected boolean isRequirementDeviceIdleMet() { return !(getParams().getRequest().requiresDeviceIdle() && !Device.isIdle(getContext())); }
/** * @return Whether the storage not low requirement is met. That's true either if it's not a requirement * or if the storage actually isn't low. */ protected boolean isRequirementStorageNotLowMet() { return !(getParams().getRequest().requiresStorageNotLow() && Device.isStorageLow()); }
@Before public void prepare() { mManager = mJobManagerRule.getManager(); mManager.addJobCreator(new TestJobCreator()); }
private void scheduleWithApi(JobRequest request, JobApi jobApi, boolean periodic, boolean flexSupport) { JobProxy proxy = getJobProxy(jobApi); if (periodic) { if (flexSupport) { proxy.plantPeriodicFlexSupport(request); } else { proxy.plantPeriodic(request); } } else { proxy.plantOneOff(request); } }
@SuppressWarnings("UnusedReturnValue") /*package*/ int rescheduleJobs(JobManager manager) { return rescheduleJobs(manager, manager.getAllJobRequests(null, true, true)); }
@Test public void testDatabaseUpgrade1to2to3to4to5to6() { Context context = RuntimeEnvironment.application; context.deleteDatabase(DATABASE_NAME); JobOpenHelper1 openHelper = new JobOpenHelper1(context); createDatabase(openHelper, false); createJobs(openHelper); createDatabase(new JobOpenHelper2(context), true); createDatabase(new JobOpenHelper3(context), true); createDatabase(new JobOpenHelper4(context), true); createDatabase(new JobOpenHelper5(context), true); checkJob(); }
@Override protected void after() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { getJobScheduler().cancelAll(); } mManager.cancelAll(); mManager.destroy(); getJobScheduler().cancelAll(); JobConfig.reset(); }
@Override public void run() { try { int jobId = schedule(baseBuilder, startMs, endMs); callback.onJobScheduled(jobId, baseBuilder.mTag, null); } catch (Exception e) { callback.onJobScheduled(JobRequest.JobScheduledCallback.JOB_ID_ERROR, baseBuilder.mTag, e); } } });
@Override public void delete(JobRequest request) { executeJob(request.getJobId(), Job.Result.SUCCESS); } });
private void waitForJobRescheduleService() throws InterruptedException { new JobRescheduleService().rescheduleJobs(mJobManagerRule.getManager()); } }