@Override public int schedule(JobInfo job) throws RemoteException { int vuid = VBinder.getCallingUid(); int id = job.getId(); ComponentName service = job.getService(); JobId jobId = new JobId(vuid, service.getPackageName(), id); JobConfig config = mJobStore.get(jobId); if (config == null) { config = new JobConfig(mGlobalJobId++, service.getClassName(), job.getExtras()); mJobStore.put(jobId, config); } else { config.serviceName = service.getClassName(); config.extras = job.getExtras(); } saveJobs(); mirror.android.app.job.JobInfo.jobId.set(job, config.virtualJobId); mirror.android.app.job.JobInfo.service.set(job, mJobProxyComponent); return mScheduler.schedule(job); }
@NonNull private JobParameters prepareJobParameters(SchedulerConstraint constraint) { JobInfo info = schedule(constraint); JobParameters params = mock(JobParameters.class); when(params.getExtras()).thenReturn(info.getExtras()); when(params.getJobId()).thenReturn(info.getId()); return params; }
@Test public void bundleNullDeadline() throws Exception { SchedulerConstraint constraint = mock(SchedulerConstraint.class); when(constraint.getNetworkStatus()).thenReturn(NetworkUtil.METERED); when(constraint.getUuid()).thenReturn("abc"); when(constraint.getDelayInMs()).thenReturn(345L); when(constraint.getOverrideDeadlineInMs()).thenReturn(null); JobInfo jobInfo = schedule(constraint); PersistableBundle extras = jobInfo.getExtras(); SchedulerConstraint fromBundle = FrameworkScheduler.fromBundle(extras); assertThat(fromBundle.getNetworkStatus(), is(NetworkUtil.METERED)); assertThat(fromBundle.getUuid(), is("abc")); assertThat(fromBundle.getDelayInMs(), is(345L)); assertThat(fromBundle.getOverrideDeadlineInMs(), is(nullValue())); }
@Test public void bundle() throws Exception { SchedulerConstraint constraint = mock(SchedulerConstraint.class); when(constraint.getNetworkStatus()).thenReturn(NetworkUtil.METERED); when(constraint.getUuid()).thenReturn("abc"); when(constraint.getDelayInMs()).thenReturn(345L); when(constraint.getOverrideDeadlineInMs()).thenReturn(235L); JobInfo jobInfo = schedule(constraint); PersistableBundle extras = jobInfo.getExtras(); SchedulerConstraint fromBundle = FrameworkScheduler.fromBundle(extras); assertThat(fromBundle.getNetworkStatus(), is(NetworkUtil.METERED)); assertThat(fromBundle.getUuid(), is("abc")); assertThat(fromBundle.getDelayInMs(), is(345L)); assertThat(fromBundle.getOverrideDeadlineInMs(), is(235L)); }
@Override public int schedule(JobInfo job) { int vuid = VBinder.getCallingUid(); int id = job.getId(); ComponentName service = job.getService(); JobId jobId = new JobId(vuid, service.getPackageName(), id); JobConfig config = mJobStore.get(jobId); if (config == null) { config = new JobConfig(mGlobalJobId++, service.getClassName(), job.getExtras()); mJobStore.put(jobId, config); } else { config.serviceName = service.getClassName(); config.extras = job.getExtras(); } saveJobs(); mirror.android.app.job.JobInfo.jobId.set(job, config.virtualJobId); mirror.android.app.job.JobInfo.service.set(job, mJobProxyComponent); return mScheduler.schedule(job); }
@Override public int schedule(JobInfo job) throws RemoteException { int vuid = VBinder.getCallingUid(); int id = job.getId(); ComponentName service = job.getService(); JobId jobId = new JobId(vuid, service.getPackageName(), id); JobConfig config = mJobStore.get(jobId); if (config == null) { config = new JobConfig(mGlobalJobId++, service.getClassName(), job.getExtras()); mJobStore.put(jobId, config); } else { config.serviceName = service.getClassName(); config.extras = job.getExtras(); } saveJobs(); mirror.android.app.job.JobInfo.jobId.set(job, config.virtualJobId); mirror.android.app.job.JobInfo.service.set(job, mJobProxyComponent); return mScheduler.schedule(job); }
private void assertNativeJobInfoMatchesJobInfo(android.app.job.JobInfo nativeJob, JobInfo job) { assertEquals(nativeJob.getId(), job.getId()); assertEquals(new PersistableBundle(nativeJob.getExtras()).toMap(10), job.getExtras().toMap(10)); assertEquals(nativeJob.getService(), new ComponentName(context, JobSchedulerJobService.class)); assertEquals(nativeJob.isRequireCharging(), job.isRequireCharging()); assertEquals(nativeJob.isRequireDeviceIdle(), job.isRequireDeviceIdle()); assertEquals(nativeJob.getNetworkType(), job.getNetworkType()); assertEquals(nativeJob.getMinLatencyMillis(), job.getMinLatencyMillis()); assertEquals(nativeJob.getMaxExecutionDelayMillis(), job.getMaxExecutionDelayMillis()); assertEquals(nativeJob.isPeriodic(), job.isPeriodic()); assertEquals(nativeJob.isPersisted(), job.isPersisted()); assertEquals(nativeJob.getInitialBackoffMillis(), job.getInitialBackoffMillis()); assertEquals(nativeJob.getBackoffPolicy(), job.getBackoffPolicy()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { assertEquals(nativeJob.getFlexMillis(), job.getFlexMillis()); assertArrayEquals(getUris(nativeJob.getTriggerContentUris()), getUris(job.getTriggerContentUris())); assertEquals(nativeJob.getTriggerContentUpdateDelay(), job.getTriggerContentUpdateDelay()); assertEquals(nativeJob.getTriggerContentMaxDelay(), job.getTriggerContentMaxDelay()); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { assertEquals( BundleUtils.toMap(nativeJob.getTransientExtras(), 10), BundleUtils.toMap(job.getTransientExtras(), 10)); assertEquals(nativeJob.isRequireBatteryNotLow(), job.isRequireBatteryNotLow()); assertEquals(nativeJob.isRequireStorageNotLow(), job.isRequireBatteryNotLow()); } }