Search in sources :

Example 1 with JobStatus

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

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

Example 3 with JobStatus

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

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

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

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

the class JobSchedulerService method assignJobsToContextsLocked.

/**
     * Takes jobs from pending queue and runs them on available contexts.
     * If no contexts are available, preempts lower priority jobs to
     * run higher priority ones.
     * Lock on mJobs before calling this function.
     */
private void assignJobsToContextsLocked() {
    if (DEBUG) {
        Slog.d(TAG, printPendingQueue());
    }
    int memLevel;
    try {
        memLevel = ActivityManagerNative.getDefault().getMemoryTrimLevel();
    } catch (RemoteException e) {
        memLevel = ProcessStats.ADJ_MEM_FACTOR_NORMAL;
    }
    switch(memLevel) {
        case ProcessStats.ADJ_MEM_FACTOR_MODERATE:
            mMaxActiveJobs = mConstants.BG_MODERATE_JOB_COUNT;
            break;
        case ProcessStats.ADJ_MEM_FACTOR_LOW:
            mMaxActiveJobs = mConstants.BG_LOW_JOB_COUNT;
            break;
        case ProcessStats.ADJ_MEM_FACTOR_CRITICAL:
            mMaxActiveJobs = mConstants.BG_CRITICAL_JOB_COUNT;
            break;
        default:
            mMaxActiveJobs = mConstants.BG_NORMAL_JOB_COUNT;
            break;
    }
    JobStatus[] contextIdToJobMap = mTmpAssignContextIdToJobMap;
    boolean[] act = mTmpAssignAct;
    int[] preferredUidForContext = mTmpAssignPreferredUidForContext;
    int numActive = 0;
    int numForeground = 0;
    for (int i = 0; i < MAX_JOB_CONTEXTS_COUNT; i++) {
        final JobServiceContext js = mActiveServices.get(i);
        final JobStatus status = js.getRunningJob();
        if ((contextIdToJobMap[i] = status) != null) {
            numActive++;
            if (status.lastEvaluatedPriority >= JobInfo.PRIORITY_TOP_APP) {
                numForeground++;
            }
        }
        act[i] = false;
        preferredUidForContext[i] = js.getPreferredUid();
    }
    if (DEBUG) {
        Slog.d(TAG, printContextIdToJobMap(contextIdToJobMap, "running jobs initial"));
    }
    for (int i = 0; i < mPendingJobs.size(); i++) {
        JobStatus nextPending = mPendingJobs.get(i);
        // If job is already running, go to next job.
        int jobRunningContext = findJobContextIdFromMap(nextPending, contextIdToJobMap);
        if (jobRunningContext != -1) {
            continue;
        }
        final int priority = evaluateJobPriorityLocked(nextPending);
        nextPending.lastEvaluatedPriority = priority;
        // Find a context for nextPending. The context should be available OR
        // it should have lowest priority among all running jobs
        // (sharing the same Uid as nextPending)
        int minPriority = Integer.MAX_VALUE;
        int minPriorityContextId = -1;
        for (int j = 0; j < MAX_JOB_CONTEXTS_COUNT; j++) {
            JobStatus job = contextIdToJobMap[j];
            int preferredUid = preferredUidForContext[j];
            if (job == null) {
                if ((numActive < mMaxActiveJobs || (priority >= JobInfo.PRIORITY_TOP_APP && numForeground < mConstants.FG_JOB_COUNT)) && (preferredUid == nextPending.getUid() || preferredUid == JobServiceContext.NO_PREFERRED_UID)) {
                    // This slot is free, and we haven't yet hit the limit on
                    // concurrent jobs...  we can just throw the job in to here.
                    minPriorityContextId = j;
                    break;
                }
                // concurrent jobs.
                continue;
            }
            if (job.getUid() != nextPending.getUid()) {
                continue;
            }
            if (evaluateJobPriorityLocked(job) >= nextPending.lastEvaluatedPriority) {
                continue;
            }
            if (minPriority > nextPending.lastEvaluatedPriority) {
                minPriority = nextPending.lastEvaluatedPriority;
                minPriorityContextId = j;
            }
        }
        if (minPriorityContextId != -1) {
            contextIdToJobMap[minPriorityContextId] = nextPending;
            act[minPriorityContextId] = true;
            numActive++;
            if (priority >= JobInfo.PRIORITY_TOP_APP) {
                numForeground++;
            }
        }
    }
    if (DEBUG) {
        Slog.d(TAG, printContextIdToJobMap(contextIdToJobMap, "running jobs final"));
    }
    mJobPackageTracker.noteConcurrency(numActive, numForeground);
    for (int i = 0; i < MAX_JOB_CONTEXTS_COUNT; i++) {
        boolean preservePreferredUid = false;
        if (act[i]) {
            JobStatus js = mActiveServices.get(i).getRunningJob();
            if (js != null) {
                if (DEBUG) {
                    Slog.d(TAG, "preempting job: " + mActiveServices.get(i).getRunningJob());
                }
                // preferredUid will be set to uid of currently running job.
                mActiveServices.get(i).preemptExecutingJob();
                preservePreferredUid = true;
            } else {
                final JobStatus pendingJob = contextIdToJobMap[i];
                if (DEBUG) {
                    Slog.d(TAG, "About to run job on context " + String.valueOf(i) + ", job: " + pendingJob);
                }
                for (int ic = 0; ic < mControllers.size(); ic++) {
                    mControllers.get(ic).prepareForExecutionLocked(pendingJob);
                }
                if (!mActiveServices.get(i).executeRunnableJob(pendingJob)) {
                    Slog.d(TAG, "Error executing " + pendingJob);
                }
                if (mPendingJobs.remove(pendingJob)) {
                    mJobPackageTracker.noteNonpending(pendingJob);
                }
            }
        }
        if (!preservePreferredUid) {
            mActiveServices.get(i).clearPreferredUid();
        }
    }
}
Also used : JobStatus(com.android.server.job.controllers.JobStatus) RemoteException(android.os.RemoteException)

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