Search in sources :

Example 6 with JobSet

use of com.android.server.job.JobStore.JobSet in project android_frameworks_base by DirtyUnicorns.

the class JobStoreTest method testNonPersistedTaskIsNotPersisted.

/**
     * Test that non persisted job is not written to disk.
     */
public void testNonPersistedTaskIsNotPersisted() throws Exception {
    JobInfo.Builder b = new Builder(42, mComponent).setOverrideDeadline(10000).setPersisted(false);
    JobStatus jsNonPersisted = JobStatus.createFromJobInfo(b.build(), SOME_UID, null, -1, null);
    mTaskStoreUnderTest.add(jsNonPersisted);
    b = new Builder(43, mComponent).setOverrideDeadline(10000).setPersisted(true);
    JobStatus jsPersisted = JobStatus.createFromJobInfo(b.build(), SOME_UID, null, -1, null);
    mTaskStoreUnderTest.add(jsPersisted);
    Thread.sleep(IO_WAIT);
    final JobSet jobStatusSet = new JobSet();
    mTaskStoreUnderTest.readJobMapFromDisk(jobStatusSet);
    assertEquals("Job count is incorrect.", 1, jobStatusSet.size());
    JobStatus jobStatus = jobStatusSet.getAllJobs().iterator().next();
    assertEquals("Wrong job persisted.", 43, jobStatus.getJobId());
}
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) Builder(android.app.job.JobInfo.Builder)

Example 7 with JobSet

use of com.android.server.job.JobStore.JobSet in project android_frameworks_base by DirtyUnicorns.

the class JobStoreTest method testWritingTaskWithSourcePackage.

public void testWritingTaskWithSourcePackage() throws Exception {
    JobInfo.Builder b = new Builder(8, mComponent).setRequiresDeviceIdle(true).setPeriodic(10000L).setRequiresCharging(true).setPersisted(true);
    JobStatus taskStatus = JobStatus.createFromJobInfo(b.build(), SOME_UID, "com.google.android.gms", 0, 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();
    assertEquals("Source package not equal.", loaded.getSourcePackageName(), taskStatus.getSourcePackageName());
    assertEquals("Source user not equal.", loaded.getSourceUserId(), taskStatus.getSourceUserId());
}
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) Builder(android.app.job.JobInfo.Builder)

Example 8 with JobSet

use of com.android.server.job.JobStore.JobSet in project android_frameworks_base by DirtyUnicorns.

the class JobStoreTest method testWritingTwoFilesToDisk.

public void testWritingTwoFilesToDisk() throws Exception {
    final JobInfo task1 = new Builder(8, mComponent).setRequiresDeviceIdle(true).setPeriodic(10000L).setRequiresCharging(true).setPersisted(true).build();
    final JobInfo task2 = new Builder(12, mComponent).setMinimumLatency(5000L).setBackoffCriteria(15000L, JobInfo.BACKOFF_POLICY_LINEAR).setOverrideDeadline(30000L).setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED).setPersisted(true).build();
    final JobStatus taskStatus1 = JobStatus.createFromJobInfo(task1, SOME_UID, null, -1, null);
    final JobStatus taskStatus2 = JobStatus.createFromJobInfo(task2, SOME_UID, null, -1, null);
    mTaskStoreUnderTest.add(taskStatus1);
    mTaskStoreUnderTest.add(taskStatus2);
    Thread.sleep(IO_WAIT);
    final JobSet jobStatusSet = new JobSet();
    mTaskStoreUnderTest.readJobMapFromDisk(jobStatusSet);
    assertEquals("Incorrect # of persisted tasks.", 2, jobStatusSet.size());
    Iterator<JobStatus> it = jobStatusSet.getAllJobs().iterator();
    JobStatus loaded1 = it.next();
    JobStatus loaded2 = it.next();
    // Reverse them so we know which comparison to make.
    if (loaded1.getJobId() != 8) {
        JobStatus tmp = loaded1;
        loaded1 = loaded2;
        loaded2 = tmp;
    }
    assertTasksEqual(task1, loaded1.getJob());
    assertTasksEqual(task2, loaded2.getJob());
    assertTrue("JobStore#contains invalid.", mTaskStoreUnderTest.containsJob(taskStatus1));
    assertTrue("JobStore#contains invalid.", mTaskStoreUnderTest.containsJob(taskStatus2));
    // Check that the loaded task has the correct runtimes.
    compareTimestampsSubjectToIoLatency("Early run-times not the same after read.", taskStatus1.getEarliestRunTime(), loaded1.getEarliestRunTime());
    compareTimestampsSubjectToIoLatency("Late run-times not the same after read.", taskStatus1.getLatestRunTimeElapsed(), loaded1.getLatestRunTimeElapsed());
    compareTimestampsSubjectToIoLatency("Early run-times not the same after read.", taskStatus2.getEarliestRunTime(), loaded2.getEarliestRunTime());
    compareTimestampsSubjectToIoLatency("Late run-times not the same after read.", taskStatus2.getLatestRunTimeElapsed(), loaded2.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 9 with JobSet

use of com.android.server.job.JobStore.JobSet in project platform_frameworks_base by android.

the class JobStoreTest method testPriorityPersisted.

public void testPriorityPersisted() throws Exception {
    JobInfo.Builder b = new Builder(92, mComponent).setOverrideDeadline(5000).setPriority(42).setPersisted(true);
    final JobStatus js = JobStatus.createFromJobInfo(b.build(), SOME_UID, null, -1, null);
    mTaskStoreUnderTest.add(js);
    Thread.sleep(IO_WAIT);
    final JobSet jobStatusSet = new JobSet();
    mTaskStoreUnderTest.readJobMapFromDisk(jobStatusSet);
    JobStatus loaded = jobStatusSet.getAllJobs().iterator().next();
    assertEquals("Priority not correctly persisted.", 42, loaded.getPriority());
}
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) Builder(android.app.job.JobInfo.Builder)

Example 10 with JobSet

use of com.android.server.job.JobStore.JobSet in project platform_frameworks_base by android.

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)

Aggregations

JobInfo (android.app.job.JobInfo)32 Builder (android.app.job.JobInfo.Builder)32 JobSet (com.android.server.job.JobStore.JobSet)32 JobStatus (com.android.server.job.controllers.JobStatus)32 PersistableBundle (android.os.PersistableBundle)4