public List<JobInfo> getAllPendingJobsFromScheduler() { JobScheduler jobScheduler = getJobScheduler(); ArrayList<JobInfo> jobs = new ArrayList<>(jobScheduler.getAllPendingJobs()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { Iterator<JobInfo> iterator = jobs.iterator(); while (iterator.hasNext()) { if (iterator.next().getId() == JobIdsInternal.JOB_ID_JOB_RESCHEDULE_SERVICE) { iterator.remove(); } } } return jobs; } }
@Before public void prepare() { mManager = mJobManagerRule.getManager(); }
@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(); }
private void waitForJobRescheduleService() throws InterruptedException { new JobRescheduleService().rescheduleJobs(mJobManagerRule.getManager()); } }
@Override protected void after() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { getJobScheduler().cancelAll(); } mManager.cancelAll(); mManager.destroy(); getJobScheduler().cancelAll(); JobConfig.reset(); }
@Before public void prepare() { mManager = mJobManagerRule.getManager(); mManager.addJobCreator(new TestJobCreator()); mLatch = new CountDownLatch(1); }
@Before public void prepare() { mManager = mJobManagerRule.getManager(); mManager.addJobCreator(new TestJobCreator()); }
@Before public void prepare() { mManager = mJobManagerRule.getManager(); mManager.addJobCreator(new TestJobCreator()); }
@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 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(); }