Search in sources :

Example 51 with JobStatus

use of com.android.server.job.controllers.JobStatus in project android_frameworks_base by crdroidandroid.

the class JobSchedulerService method onJobCompleted.

// JobCompletedListener implementations.
/**
     * A job just finished executing. We fetch the
     * {@link com.android.server.job.controllers.JobStatus} from the store and depending on
     * whether we want to reschedule we readd it to the controllers.
     * @param jobStatus Completed job.
     * @param needsReschedule Whether the implementing class should reschedule this job.
     */
@Override
public void onJobCompleted(JobStatus jobStatus, boolean needsReschedule) {
    if (DEBUG) {
        Slog.d(TAG, "Completed " + jobStatus + ", reschedule=" + needsReschedule);
    }
    // shuts down before it is added back.
    if (!stopTrackingJob(jobStatus, null, !jobStatus.getJob().isPeriodic())) {
        if (DEBUG) {
            Slog.d(TAG, "Could not find job to remove. Was job removed while executing?");
        }
        // We still want to check for jobs to execute, because this job may have
        // scheduled a new job under the same job id, and now we can run it.
        mHandler.obtainMessage(MSG_CHECK_JOB_GREEDY).sendToTarget();
        return;
    }
    // that may cause ordering problems if the app removes jobStatus while in here.
    if (needsReschedule) {
        JobStatus rescheduled = getRescheduleJobForFailure(jobStatus);
        startTrackingJob(rescheduled, jobStatus);
    } else if (jobStatus.getJob().isPeriodic()) {
        JobStatus rescheduledPeriodic = getRescheduleJobForPeriodic(jobStatus);
        startTrackingJob(rescheduledPeriodic, jobStatus);
    }
    reportActive();
    mHandler.obtainMessage(MSG_CHECK_JOB_GREEDY).sendToTarget();
}
Also used : JobStatus(com.android.server.job.controllers.JobStatus)

Example 52 with JobStatus

use of com.android.server.job.controllers.JobStatus in project android_frameworks_base by crdroidandroid.

the class JobStoreTest method testMassivePeriodClampedOnRead.

public void testMassivePeriodClampedOnRead() throws Exception {
    // flex
    final long ONE_HOUR = 60 * 60 * 1000L;
    // period
    final long TWO_HOURS = 2 * ONE_HOUR;
    JobInfo.Builder b = new Builder(8, mComponent).setPeriodic(TWO_HOURS, ONE_HOUR).setPersisted(true);
    final long invalidLateRuntimeElapsedMillis = // > period+flex
    SystemClock.elapsedRealtime() + (TWO_HOURS * ONE_HOUR) + TWO_HOURS;
    final long invalidEarlyRuntimeElapsedMillis = // Early is (late - period).
    invalidLateRuntimeElapsedMillis - TWO_HOURS;
    final JobStatus js = new JobStatus(b.build(), SOME_UID, "somePackage", 0, /* sourceUserId */
    "someTag", invalidEarlyRuntimeElapsedMillis, invalidLateRuntimeElapsedMillis);
    mTaskStoreUnderTest.add(js);
    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();
    // Assert early runtime was clamped to be under now + period. We can do <= here b/c we'll
    // call SystemClock.elapsedRealtime after doing the disk i/o.
    final long newNowElapsed = SystemClock.elapsedRealtime();
    assertTrue("Early runtime wasn't correctly clamped.", loaded.getEarliestRunTime() <= newNowElapsed + TWO_HOURS);
    // Assert late runtime was clamped to be now + period + flex.
    assertTrue("Early runtime wasn't correctly clamped.", loaded.getEarliestRunTime() <= newNowElapsed + TWO_HOURS + ONE_HOUR);
}
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 53 with JobStatus

use of com.android.server.job.controllers.JobStatus in project android_frameworks_base by crdroidandroid.

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 54 with JobStatus

use of com.android.server.job.controllers.JobStatus in project android_frameworks_base by crdroidandroid.

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 55 with JobStatus

use of com.android.server.job.controllers.JobStatus in project android_frameworks_base by crdroidandroid.

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)

Aggregations

JobStatus (com.android.server.job.controllers.JobStatus)122 JobInfo (android.app.job.JobInfo)42 Builder (android.app.job.JobInfo.Builder)32 JobSet (com.android.server.job.JobStore.JobSet)32 RemoteException (android.os.RemoteException)25 StateController (com.android.server.job.controllers.StateController)10 IntentFilter (android.content.IntentFilter)5 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)5 PowerManager (android.os.PowerManager)5 WorkSource (android.os.WorkSource)5 DeviceIdleController (com.android.server.DeviceIdleController)5 JobStatusFunctor (com.android.server.job.JobStore.JobStatusFunctor)5 ArrayList (java.util.ArrayList)5 PersistableBundle (android.os.PersistableBundle)4