/** * Specify that this job should recur with the provided interval and flex, not more than once per period. * The flex controls how close to the end of a period the job can run. For example, specifying an interval * of 60 seconds and a flex of 15 seconds will allow the scheduler to determine the best moment between * the 45th and 60th second at which to execute your job. * * <br> * <br> * * As default a job isn't periodic. It isn't allowed to specify a time window for a periodic job. * Instead you set an interval with this function. Since {@link Job.Result#RESCHEDULE} is ignored for * periodic jobs, setting a back-off criteria is illegal as well. * * @param intervalMs The job should run at most once every {@code intervalMs}. The minimum value is {@code 15min}. * @param flexMs How close to the end of the period the job should run. The minimum value is {@code 5min}. * @see #MIN_INTERVAL * @see #MIN_FLEX */ public Builder setPeriodic(long intervalMs, long flexMs) { mIntervalMs = JobPreconditions.checkArgumentInRange(intervalMs, getMinInterval(), Long.MAX_VALUE, "intervalMs"); mFlexMs = JobPreconditions.checkArgumentInRange(flexMs, getMinFlex(), mIntervalMs, "flexMs"); return this; }
@Test @Config(sdk = Build.VERSION_CODES.LOLLIPOP) public void verifyMinIntervalChanged() { assertThat(JobRequest.getMinInterval()).isEqualTo(JobRequest.MIN_INTERVAL); assertThat(JobRequest.getMinFlex()).isEqualTo(JobRequest.MIN_FLEX); JobConfig.setAllowSmallerIntervalsForMarshmallow(true); assertThat(JobRequest.getMinInterval()).isLessThan(JobRequest.MIN_INTERVAL); assertThat(JobRequest.getMinFlex()).isLessThan(JobRequest.MIN_FLEX); }
JobPreconditions.checkArgumentInRange(mFlexMs, getMinFlex(), mIntervalMs, "flexMs");
/** * Specify that this job should recur with the provided interval and flex, not more than once per period. * The flex controls how close to the end of a period the job can run. For example, specifying an interval * of 60 seconds and a flex of 15 seconds will allow the scheduler to determine the best moment between * the 45th and 60th second at which to execute your job. * * <br> * <br> * * As default a job isn't periodic. It isn't allowed to specify a time window for a periodic job. * Instead you set an interval with this function. Since {@link Job.Result#RESCHEDULE} is ignored for * periodic jobs, setting a back-off criteria is illegal as well. * * @param intervalMs The job should run at most once every {@code intervalMs}. The minimum value is {@code 15min}. * @param flexMs How close to the end of the period the job should run. The minimum value is {@code 5min}. * @see #MIN_INTERVAL * @see #MIN_FLEX */ public Builder setPeriodic(long intervalMs, long flexMs) { mIntervalMs = JobPreconditions.checkArgumentInRange(intervalMs, getMinInterval(), Long.MAX_VALUE, "intervalMs"); mFlexMs = JobPreconditions.checkArgumentInRange(flexMs, getMinFlex(), mIntervalMs, "flexMs"); return this; }
JobPreconditions.checkArgumentInRange(mFlexMs, getMinFlex(), mIntervalMs, "flexMs");