Search in sources :

Example 86 with JobStatus

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

the class JobServiceContext method onServiceConnected.

/**
     * We acquire/release a wakelock on onServiceConnected/unbindService. This mirrors the work
     * we intend to send to the client - we stop sending work when the service is unbound so until
     * then we keep the wakelock.
     * @param name The concrete component name of the service that has been connected.
     * @param service The IBinder of the Service's communication channel,
     */
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
    JobStatus runningJob;
    synchronized (mLock) {
        // This isn't strictly necessary b/c the JobServiceHandler is running on the main
        // looper and at this point we can't get any binder callbacks from the client. Better
        // safe than sorry.
        runningJob = mRunningJob;
    }
    if (runningJob == null || !name.equals(runningJob.getServiceComponent())) {
        mCallbackHandler.obtainMessage(MSG_SHUTDOWN_EXECUTION).sendToTarget();
        return;
    }
    this.service = IJobService.Stub.asInterface(service);
    final PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, runningJob.getTag());
    wl.setWorkSource(new WorkSource(runningJob.getSourceUid()));
    wl.setReferenceCounted(false);
    wl.acquire();
    synchronized (mLock) {
        // explicitly fast-forward the release if we're in that situation.
        if (mWakeLock != null) {
            Slog.w(TAG, "Bound new job " + runningJob + " but live wakelock " + mWakeLock + " tag=" + mWakeLock.getTag());
            mWakeLock.release();
        }
        mWakeLock = wl;
    }
    mCallbackHandler.obtainMessage(MSG_SERVICE_BOUND).sendToTarget();
}
Also used : JobStatus(com.android.server.job.controllers.JobStatus) PowerManager(android.os.PowerManager) WorkSource(android.os.WorkSource)

Example 87 with JobStatus

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

the class JobStoreTest method testWritingTaskWithFlex.

public void testWritingTaskWithFlex() throws Exception {
    JobInfo.Builder b = new Builder(8, mComponent).setRequiresDeviceIdle(true).setPeriodic(5 * 60 * 60 * 1000, 1 * 60 * 60 * 1000).setRequiresCharging(true).setPersisted(true);
    JobStatus taskStatus = JobStatus.createFromJobInfo(b.build(), 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();
    assertEquals("Period not equal.", loaded.getJob().getIntervalMillis(), taskStatus.getJob().getIntervalMillis());
    assertEquals("Flex not equal.", loaded.getJob().getFlexMillis(), taskStatus.getJob().getFlexMillis());
}
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 88 with JobStatus

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

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

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

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

use of com.android.server.job.controllers.JobStatus 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)

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