use of android.app.job.JobInfo in project android_frameworks_base by DirtyUnicorns.
the class JobStoreTest method testWritingTaskWithExtras.
public void testWritingTaskWithExtras() throws Exception {
JobInfo.Builder b = new Builder(8, mComponent).setRequiresDeviceIdle(true).setPeriodic(10000L).setRequiresCharging(true).setPersisted(true);
PersistableBundle extras = new PersistableBundle();
extras.putDouble("hello", 3.2);
extras.putString("hi", "there");
extras.putInt("into", 3);
b.setExtras(extras);
final JobInfo task = b.build();
JobStatus taskStatus = JobStatus.createFromJobInfo(task, SOME_UID, null, -1, null);
mTaskStoreUnderTest.add(taskStatus);
Thread.sleep(IO_WAIT);
final JobSet jobStatusSet = new JobSet();
mTaskStoreUnderTest.readJobMapFromDisk(jobStatusSet);
assertEquals("Incorrect # of persisted tasks.", 1, jobStatusSet.size());
JobStatus loaded = jobStatusSet.getAllJobs().iterator().next();
assertTasksEqual(task, loaded.getJob());
}
use of android.app.job.JobInfo in project android_frameworks_base by DirtyUnicorns.
the class PrioritySchedulingTest method testHigherPriorityJobNotPreempted.
public void testHigherPriorityJobNotPreempted() throws Exception {
JobInfo job1 = new JobInfo.Builder(111, kJobServiceComponent).setPriority(2).setOverrideDeadline(7000L).build();
JobInfo job2 = new JobInfo.Builder(222, kJobServiceComponent).setPriority(2).setOverrideDeadline(7000L).build();
JobInfo job3 = new JobInfo.Builder(333, kJobServiceComponent).setPriority(2).setOverrideDeadline(7000L).build();
JobInfo job4 = new JobInfo.Builder(444, kJobServiceComponent).setPriority(1).setMinimumLatency(2000L).setOverrideDeadline(7000L).build();
mJobScheduler.schedule(job1);
mJobScheduler.schedule(job2);
mJobScheduler.schedule(job3);
mJobScheduler.schedule(job4);
// Wait for job 4 to preempt one of the higher priority jobs
Thread.sleep(10000);
Event job4Execution = new Event(TestEnvironment.EVENT_START_JOB, 444);
boolean wasJob4Executed = kTestEnvironment.getExecutedEvents().contains(job4Execution);
assertFalse("Higher priority job was preempted.", wasJob4Executed);
}
use of android.app.job.JobInfo in project android-priority-jobqueue by yigit.
the class FrameworkSchedulerTest method deadline.
@Test
public void deadline() {
SchedulerConstraint constraint = mock(SchedulerConstraint.class);
when(constraint.getNetworkStatus()).thenReturn(NetworkUtil.DISCONNECTED);
when(constraint.getOverrideDeadlineInMs()).thenReturn(255L);
JobInfo jobInfo = schedule(constraint);
assertThat(jobInfo.isPersisted(), is(true));
assertThat(jobInfo.getId(), is(1));
assertThat(jobInfo.getMinLatencyMillis(), is(0L));
assertThat(jobInfo.getMaxExecutionDelayMillis(), is(255L));
}
use of android.app.job.JobInfo in project android-priority-jobqueue by yigit.
the class FrameworkSchedulerTest method bundleNullDeadline.
@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()));
}
use of android.app.job.JobInfo in project android-priority-jobqueue by yigit.
the class FrameworkSchedulerTest method prepareJobParameters.
@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;
}
Aggregations