Search in sources :

Example 31 with JobStatus

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

the class JobSchedulerService method noteJobsNonpending.

void noteJobsNonpending(List<JobStatus> jobs) {
    for (int i = jobs.size() - 1; i >= 0; i--) {
        JobStatus job = jobs.get(i);
        mJobPackageTracker.noteNonpending(job);
    }
}
Also used : JobStatus(com.android.server.job.controllers.JobStatus)

Example 32 with JobStatus

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

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

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

the class JobSchedulerService method noteJobsNonpending.

void noteJobsNonpending(List<JobStatus> jobs) {
    for (int i = jobs.size() - 1; i >= 0; i--) {
        JobStatus job = jobs.get(i);
        mJobPackageTracker.noteNonpending(job);
    }
}
Also used : JobStatus(com.android.server.job.controllers.JobStatus)

Example 34 with JobStatus

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

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

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

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