@Test public void verifyAlarmIsCanceledAfterStart() throws Exception { assumeTrue(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP); JobConfig.forceApi(JobApi.V_21); int jobId = scheduleJob(); final Intent intent = PlatformAlarmServiceExact.createIntent(context(), jobId, null); PendingIntent pendingIntent = PendingIntent.getService(context(), jobId, intent, PendingIntent.FLAG_NO_CREATE); assertThat(pendingIntent).isNotNull(); boolean started = TransientBundleCompat.startWithTransientBundle(context(), mJobManagerRule.getManager().getJobRequest(jobId)); assertThat(started).isTrue(); pendingIntent = PendingIntent.getService(context(), jobId, intent, PendingIntent.FLAG_NO_CREATE); assertThat(pendingIntent).isNull(); }
@Test public void verifyAlarmNotCanceledForPeriodicAfterStart() throws Exception { assumeTrue(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP); JobConfig.forceApi(JobApi.V_21); Bundle extras = new Bundle(); extras.putString("key", "value"); int jobId = new JobRequest.Builder("tag") .setPeriodic(TimeUnit.DAYS.toMillis(1)) .setTransientExtras(extras) .build() .schedule(); assertThat(mJobManagerRule.getAllPendingJobsFromScheduler()).isNotNull().isNotEmpty(); JobRequest request = mJobManagerRule.getManager().getJobRequest(jobId); assertThat(request.isTransient()).isTrue(); final Intent intent = PlatformAlarmServiceExact.createIntent(context(), jobId, null); PendingIntent pendingIntent = PendingIntent.getService(context(), jobId, intent, PendingIntent.FLAG_NO_CREATE); assertThat(pendingIntent).isNotNull(); boolean started = TransientBundleCompat.startWithTransientBundle(context(), request); assertThat(started).isTrue(); pendingIntent = PendingIntent.getService(context(), jobId, intent, PendingIntent.FLAG_NO_CREATE); assertThat(pendingIntent).isNotNull(); }
@Test public void verifyAlarmIsCanceled() throws Exception { assumeTrue(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP); JobConfig.forceApi(JobApi.V_21); int jobId = scheduleJob(); final Intent intent = PlatformAlarmServiceExact.createIntent(context(), jobId, null); PendingIntent pendingIntent = PendingIntent.getService(context(), jobId, intent, PendingIntent.FLAG_NO_CREATE); assertThat(pendingIntent).isNotNull(); mJobManagerRule.getManager().cancel(jobId); pendingIntent = PendingIntent.getService(context(), jobId, intent, PendingIntent.FLAG_NO_CREATE); assertThat(pendingIntent).isNull(); }
@Test public void verifyNativeImplementationIsUsedWithO() throws Exception { // ignore test if not supported assumeTrue(JobApi.V_26.isSupported(InstrumentationRegistry.getTargetContext())); JobConfig.forceApi(JobApi.V_26); int jobId = scheduleJob(); final Intent intent = PlatformAlarmServiceExact.createIntent(context(), jobId, null); PendingIntent pendingIntent = PendingIntent.getService(context(), jobId, intent, PendingIntent.FLAG_NO_CREATE); assertThat(pendingIntent).isNull(); }