/*package*/ void updateStats(boolean incFailureCount, boolean updateLastRun) { ContentValues contentValues = new ContentValues(); if (incFailureCount) { mFailureCount++; contentValues.put(JobStorage.COLUMN_NUM_FAILURES, mFailureCount); } if (updateLastRun) { mLastRun = JobConfig.getClock().currentTimeMillis(); contentValues.put(JobStorage.COLUMN_LAST_RUN, mLastRun); } JobManager.instance().getJobStorage().update(this, contentValues); }
calendar.setTimeInMillis(JobConfig.getClock().currentTimeMillis());
protected long getTriggerAtMillis(JobRequest request) { if (JobConfig.isForceRtc()) { return JobConfig.getClock().currentTimeMillis() + Common.getAverageDelayMs(request); } else { return JobConfig.getClock().elapsedRealtime() + Common.getAverageDelayMs(request); } }
private void verifyScheduleInNextHour(Clock clock) { JobConfig.setClock(clock); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(clock.currentTimeMillis()); int hour = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); long start = TimeUnit.HOURS.toMillis(hour + 1) + TimeUnit.MINUTES.toMillis(minute); long end = start + TimeUnit.HOURS.toMillis(1); DailyJob.schedule(DummyJobs.createBuilder(DummyJobs.SuccessJob.class), start, end); assertThat(manager().getAllJobRequests()).hasSize(1); JobRequest request = manager().getAllJobRequests().iterator().next(); assertThat(request.getStartMs()).isEqualTo(TimeUnit.HOURS.toMillis(1)); assertThat(request.getEndMs()).isEqualTo(TimeUnit.HOURS.toMillis(2)); }
/** * Cancel this request if it has been scheduled. Note that if the job isn't periodic, then the * time passed since the job has been scheduled is subtracted from the time frame. For example * a job should run between 4 and 6 seconds from now. You cancel the scheduled job after 2 * seconds, then the job will run between 2 and 4 seconds after it's been scheduled again. * * @return A builder to modify the parameters. */ public Builder cancelAndEdit() { // create a temporary variable, because .cancel() will reset mScheduledAt long scheduledAt = mScheduledAt; JobManager.instance().cancel(getJobId()); Builder builder = new Builder(this.mBuilder); mStarted = false; if (!isPeriodic()) { long offset = JobConfig.getClock().currentTimeMillis() - scheduledAt; long minValue = 1L; // 1ms builder.setExecutionWindow(Math.max(minValue, getStartMs() - offset), Math.max(minValue, getEndMs() - offset)); } return builder; }
protected void plantOneOffFlexSupport(JobRequest request, AlarmManager alarmManager, PendingIntent pendingIntent) { long triggerAtMs = JobConfig.getClock().currentTimeMillis() + Common.getAverageDelayMsSupportFlex(request); alarmManager.set(AlarmManager.RTC, triggerAtMs, pendingIntent); mCat.d("Scheduled repeating alarm (flex support), %s, interval %s, flex %s", request, JobUtil.timeToString(request.getIntervalMs()), JobUtil.timeToString(request.getFlexMs())); }
private void verifyScheduleOverMidnight(Clock clock) { JobConfig.setClock(clock); long start = TimeUnit.HOURS.toMillis(24) - 1L; long end = 1L; DailyJob.schedule(DummyJobs.createBuilder(DummyJobs.SuccessJob.class), start, end); assertThat(manager().getAllJobRequests()).hasSize(1); JobRequest request = manager().getAllJobRequests().iterator().next(); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(clock.currentTimeMillis()); int hour = calendar.get(Calendar.HOUR_OF_DAY); long maxStart = TimeUnit.HOURS.toMillis(24 - hour); assertThat(request.getStartMs()).isLessThan(maxStart); assertThat(request.getEndMs()).isLessThan(maxStart + 3); }
boolean flexSupport = periodic && jobApi.isFlexSupport() && request.getFlexMs() < request.getIntervalMs(); request.setScheduledAt(JobConfig.getClock().currentTimeMillis()); request.setFlexSupport(flexSupport); getJobStorage().put(request);
/*package*/ void updateStats(boolean incFailureCount, boolean updateLastRun) { ContentValues contentValues = new ContentValues(); if (incFailureCount) { mFailureCount++; contentValues.put(JobStorage.COLUMN_NUM_FAILURES, mFailureCount); } if (updateLastRun) { mLastRun = JobConfig.getClock().currentTimeMillis(); contentValues.put(JobStorage.COLUMN_LAST_RUN, mLastRun); } JobManager.instance().getJobStorage().update(this, contentValues); }
calendar.setTimeInMillis(JobConfig.getClock().currentTimeMillis());
protected long getTriggerAtMillis(JobRequest request) { if (JobConfig.isForceRtc()) { return JobConfig.getClock().currentTimeMillis() + Common.getAverageDelayMs(request); } else { return JobConfig.getClock().elapsedRealtime() + Common.getAverageDelayMs(request); } }
/** * Cancel this request if it has been scheduled. Note that if the job isn't periodic, then the * time passed since the job has been scheduled is subtracted from the time frame. For example * a job should run between 4 and 6 seconds from now. You cancel the scheduled job after 2 * seconds, then the job will run between 2 and 4 seconds after it's been scheduled again. * * @return A builder to modify the parameters. */ public Builder cancelAndEdit() { // create a temporary variable, because .cancel() will reset mScheduledAt long scheduledAt = mScheduledAt; JobManager.instance().cancel(getJobId()); Builder builder = new Builder(this.mBuilder); mStarted = false; if (!isPeriodic()) { long offset = JobConfig.getClock().currentTimeMillis() - scheduledAt; long minValue = 1L; // 1ms builder.setExecutionWindow(Math.max(minValue, getStartMs() - offset), Math.max(minValue, getEndMs() - offset)); } return builder; }
protected void plantOneOffFlexSupport(JobRequest request, AlarmManager alarmManager, PendingIntent pendingIntent) { long triggerAtMs = JobConfig.getClock().currentTimeMillis() + Common.getAverageDelayMsSupportFlex(request); alarmManager.set(AlarmManager.RTC, triggerAtMs, pendingIntent); mCat.d("Scheduled repeating alarm (flex support), %s, interval %s, flex %s", request, JobUtil.timeToString(request.getIntervalMs()), JobUtil.timeToString(request.getFlexMs())); }
boolean flexSupport = periodic && jobApi.isFlexSupport() && request.getFlexMs() < request.getIntervalMs(); request.setScheduledAt(JobConfig.getClock().currentTimeMillis()); request.setFlexSupport(flexSupport); mJobStorage.put(request);