AlarmManagerDriver implements Driver, JobValidator { @Override public int schedule(@NonNull Job job) { if (LOCAL_LOGV) { Log.v(TAG, "AlarmManagerDriver: schedule " +job); } final JobTrigger trigger = job.getTrigger(); final long atTime = scheduleTime(trigger); if (atTime > 0) { alarmManager.set(RTC_WAKEUP, atTime, createPendingIntent(context, BackupType.fromName(job.getTag()))); return SCHEDULE_RESULT_SUCCESS; } else { Log.w(TAG, "unsupported trigger for job "+job); return SCHEDULE_RESULT_UNSUPPORTED_TRIGGER; } } AlarmManagerDriver(Context context); @Override int schedule(@NonNull Job job); @Override int cancel(@NonNull String tag); @Override int cancelAll(); @Override @NonNull JobValidator getValidator(); @Override boolean isAvailable(); @Override List<String> validate(JobParameters jobParameters); @Override List<String> validate(JobTrigger jobTrigger); @Override List<String> validate(RetryStrategy retryStrategy);  }
@Test public void testScheduleJobWithExecutionWindowTrigger() throws Exception { final Job job = jobBuilder() .setTrigger(Trigger.executionWindow(30, 30)) .build(); final int result = subject.schedule(job); assertThat(result).isEqualTo(SCHEDULE_RESULT_SUCCESS); assertAlarmScheduled("UNKNOWN"); }
@Test public void testScheduleJobWithExecutionWindowTriggerAndTag() throws Exception { final Job job = jobBuilder() .setTag("REGULAR") .setTrigger(Trigger.executionWindow(30, 30)) .build(); final int result = subject.schedule(job); assertThat(result).isEqualTo(SCHEDULE_RESULT_SUCCESS); assertAlarmScheduled("REGULAR"); }
@Test public void testScheduleJobWithoutTrigger() throws Exception { final Job job = jobBuilder().build(); final int result = subject.schedule(job); assertThat(result).isEqualTo(SCHEDULE_RESULT_SUCCESS); assertAlarmScheduled("UNKNOWN"); }
@Test public void testScheduleJobWithUnknownTrigger() throws Exception { final Job job = jobBuilder() .setTrigger(Trigger.contentUriTrigger(Collections.singletonList(new ObservedUri(Uri.parse("foo: .build(); final int result = subject.schedule(job); assertThat(result).isEqualTo(SCHEDULE_RESULT_UNSUPPORTED_TRIGGER); }