/** * Returns the time when this job was scheduled. * <br> * <br> * <b>Note</b> that this value is only useful for non-periodic jobs. The time for periodic * jobs is inconsistent. Sometimes it will return the value when the periodic job was scheduled * for the first time and sometimes it will be updated after each period. The reason for this * limitation is the flex parameter, which was backported to older Android versions. You can * only rely on this value during the first interval of the periodic job. * * @return The time when the job was scheduled. */ public long getScheduledAt() { return mRequest.getScheduledAt(); }
@Test public void testSameIdAfterCancel() { JobRequest request = DummyJobs.createOneOff(); int jobId = request.getJobId(); assertThat(request.getScheduledAt()).isEqualTo(0L); manager().schedule(request); assertThat(request.getScheduledAt()).isGreaterThan(0L); JobRequest requestNew = request.cancelAndEdit().build(); assertThat(request.getScheduledAt()).isEqualTo(0L); int newId = requestNew.schedule(); assertThat(newId).isEqualTo(jobId); assertThat(request.getScheduledAt()).isEqualTo(0L); assertThat(requestNew.getScheduledAt()).isGreaterThan(0L); }
@NonNull public Job.Result executeJobRequest(@NonNull JobRequest request, @Nullable Bundle transientExtras) { long waited = System.currentTimeMillis() - request.getScheduledAt(); String timeWindow; if (request.isPeriodic()) {
@Test public void testUpdateDoesNotCrash() { JobRequest request = DummyJobs.createOneOff(); int jobId = request.schedule(); assertThat(request.getScheduledAt()).isGreaterThan(0L); assertThat(request.getFailureCount()).isEqualTo(0); assertThat(request.getLastRun()).isEqualTo(0); SQLiteDatabase database = mock(SQLiteDatabase.class); when(database.update(anyString(), any(ContentValues.class), nullable(String.class), any(String[].class))).thenThrow(SQLException.class); manager().getJobStorage().injectDatabase(database); request.updateStats(true, true); // updates the database value, but fails in this case assertThat(request.getFailureCount()).isEqualTo(1); // in memory value was updated, keep that assertThat(request.getLastRun()).isGreaterThan(0); // kinda hacky, this removes the request from the cache, but doesn't delete it in the database, // because we're using the mock at the moment manager().getJobStorage().remove(request); manager().getJobStorage().injectDatabase(null); // reset request = manager().getJobRequest(jobId); assertThat(request.getFailureCount()).isEqualTo(0); assertThat(request.getLastRun()).isEqualTo(0); }
if (request.getScheduledAt() > 0) { return;
/** * Returns the time when this job was scheduled. * <br> * <br> * <b>Note</b> that this value is only useful for non-periodic jobs. The time for periodic * jobs is inconsistent. Sometimes it will return the value when the periodic job was scheduled * for the first time and sometimes it will be updated after each period. The reason for this * limitation is the flex parameter, which was backported to older Android versions. You can * only rely on this value during the first interval of the periodic job. * * @return The time when the job was scheduled. */ public long getScheduledAt() { return mRequest.getScheduledAt(); }
@NonNull public Job.Result executeJobRequest(@NonNull JobRequest request, @Nullable Bundle transientExtras) { long waited = System.currentTimeMillis() - request.getScheduledAt(); String timeWindow; if (request.isPeriodic()) {
if (request.getScheduledAt() > 0) { return;