Search in sources :

Example 46 with JobInfo

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());
}
Also used : JobStatus(com.android.server.job.controllers.JobStatus) PersistableBundle(android.os.PersistableBundle) JobInfo(android.app.job.JobInfo) JobSet(com.android.server.job.JobStore.JobSet) Builder(android.app.job.JobInfo.Builder) Builder(android.app.job.JobInfo.Builder)

Example 47 with JobInfo

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);
}
Also used : JobInfo(android.app.job.JobInfo) Event(com.android.server.job.MockPriorityJobService.TestEnvironment.Event)

Example 48 with JobInfo

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));
}
Also used : JobInfo(android.app.job.JobInfo) Test(org.junit.Test)

Example 49 with JobInfo

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()));
}
Also used : PersistableBundle(android.os.PersistableBundle) JobInfo(android.app.job.JobInfo) Test(org.junit.Test)

Example 50 with JobInfo

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;
}
Also used : JobInfo(android.app.job.JobInfo) JobParameters(android.app.job.JobParameters) NonNull(android.support.annotation.NonNull)

Aggregations

JobInfo (android.app.job.JobInfo)66 JobStatus (com.android.server.job.controllers.JobStatus)22 JobScheduler (android.app.job.JobScheduler)13 Builder (android.app.job.JobInfo.Builder)12 JobSet (com.android.server.job.JobStore.JobSet)12 ArrayList (java.util.ArrayList)10 ComponentName (android.content.ComponentName)8 Event (com.android.server.job.MockPriorityJobService.TestEnvironment.Event)8 Test (org.junit.Test)7 PersistableBundle (android.os.PersistableBundle)6 NotificationManager (android.app.NotificationManager)5 JobSchedulerInternal (com.android.server.job.JobSchedulerInternal)5 StateController (com.android.server.job.controllers.StateController)5 JobParameters (android.app.job.JobParameters)1 ConnectivityManager (android.net.ConnectivityManager)1 NonNull (android.support.annotation.NonNull)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1