Search in sources :

Example 6 with JobInfo

use of android.app.job.JobInfo in project platform_frameworks_base by android.

the class JobStoreTest method testMaybeWriteStatusToDisk.

public void testMaybeWriteStatusToDisk() throws Exception {
    int taskId = 5;
    // 20s
    long runByMillis = 20000L;
    // 2s
    long runFromMillis = 2000L;
    // 10s
    long initialBackoff = 10000L;
    final JobInfo task = new Builder(taskId, mComponent).setRequiresCharging(true).setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY).setBackoffCriteria(initialBackoff, JobInfo.BACKOFF_POLICY_EXPONENTIAL).setOverrideDeadline(runByMillis).setMinimumLatency(runFromMillis).setPersisted(true).build();
    final JobStatus ts = JobStatus.createFromJobInfo(task, SOME_UID, null, -1, null);
    mTaskStoreUnderTest.add(ts);
    Thread.sleep(IO_WAIT);
    // Manually load tasks from xml file.
    final JobSet jobStatusSet = new JobSet();
    mTaskStoreUnderTest.readJobMapFromDisk(jobStatusSet);
    assertEquals("Didn't get expected number of persisted tasks.", 1, jobStatusSet.size());
    final JobStatus loadedTaskStatus = jobStatusSet.getAllJobs().get(0);
    assertTasksEqual(task, loadedTaskStatus.getJob());
    assertTrue("JobStore#contains invalid.", mTaskStoreUnderTest.containsJob(ts));
    assertEquals("Different uids.", SOME_UID, loadedTaskStatus.getUid());
    compareTimestampsSubjectToIoLatency("Early run-times not the same after read.", ts.getEarliestRunTime(), loadedTaskStatus.getEarliestRunTime());
    compareTimestampsSubjectToIoLatency("Late run-times not the same after read.", ts.getLatestRunTimeElapsed(), loadedTaskStatus.getLatestRunTimeElapsed());
}
Also used : JobStatus(com.android.server.job.controllers.JobStatus) JobInfo(android.app.job.JobInfo) JobSet(com.android.server.job.JobStore.JobSet) Builder(android.app.job.JobInfo.Builder)

Example 7 with JobInfo

use of android.app.job.JobInfo in project platform_frameworks_base by android.

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 8 with JobInfo

use of android.app.job.JobInfo in project platform_frameworks_base by android.

the class PrioritySchedulingTest method testLowerPriorityJobPreempted.

public void testLowerPriorityJobPreempted() throws Exception {
    JobInfo job1 = new JobInfo.Builder(111, kJobServiceComponent).setPriority(1).setOverrideDeadline(7000L).build();
    JobInfo job2 = new JobInfo.Builder(222, kJobServiceComponent).setPriority(1).setOverrideDeadline(7000L).build();
    JobInfo job3 = new JobInfo.Builder(333, kJobServiceComponent).setPriority(1).setOverrideDeadline(7000L).build();
    JobInfo job4 = new JobInfo.Builder(444, kJobServiceComponent).setPriority(2).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 lower priority jobs
    Thread.sleep(10000);
    Event job4Execution = new Event(TestEnvironment.EVENT_START_JOB, 444);
    ArrayList<Event> executedEvents = kTestEnvironment.getExecutedEvents();
    boolean wasJob4Executed = executedEvents.contains(job4Execution);
    boolean wasSomeJobPreempted = false;
    for (Event event : executedEvents) {
        if (event.event == TestEnvironment.EVENT_PREEMPT_JOB) {
            wasSomeJobPreempted = true;
            break;
        }
    }
    assertTrue("No job was preempted.", wasSomeJobPreempted);
    assertTrue("Lower priority jobs were not preempted.", wasJob4Executed);
}
Also used : JobInfo(android.app.job.JobInfo) Event(com.android.server.job.MockPriorityJobService.TestEnvironment.Event)

Example 9 with JobInfo

use of android.app.job.JobInfo in project platform_frameworks_base by android.

the class JobSchedulerService method getPendingJobs.

public List<JobInfo> getPendingJobs(int uid) {
    synchronized (mLock) {
        List<JobStatus> jobs = mJobs.getJobsByUid(uid);
        ArrayList<JobInfo> outList = new ArrayList<JobInfo>(jobs.size());
        for (int i = jobs.size() - 1; i >= 0; i--) {
            JobStatus job = jobs.get(i);
            outList.add(job.getJob());
        }
        return outList;
    }
}
Also used : JobStatus(com.android.server.job.controllers.JobStatus) JobInfo(android.app.job.JobInfo) ArrayList(java.util.ArrayList)

Example 10 with JobInfo

use of android.app.job.JobInfo in project android-priority-jobqueue by yigit.

the class FrameworkSchedulerTest method deadlineAndDelay.

@Test
public void deadlineAndDelay() {
    SchedulerConstraint constraint = mock(SchedulerConstraint.class);
    when(constraint.getNetworkStatus()).thenReturn(NetworkUtil.DISCONNECTED);
    when(constraint.getOverrideDeadlineInMs()).thenReturn(255L);
    when(constraint.getDelayInMs()).thenReturn(133L);
    JobInfo jobInfo = schedule(constraint);
    assertThat(jobInfo.isPersisted(), is(true));
    assertThat(jobInfo.getId(), is(1));
    assertThat(jobInfo.getMinLatencyMillis(), is(133L));
    assertThat(jobInfo.getMaxExecutionDelayMillis(), is(255L));
}
Also used : JobInfo(android.app.job.JobInfo) Test(org.junit.Test)

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