Search in sources :

Example 36 with JobStatus

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

the class JobSchedulerService method scheduleAsPackage.

public int scheduleAsPackage(JobInfo job, int uId, String packageName, int userId, String tag) {
    JobStatus jobStatus = JobStatus.createFromJobInfo(job, uId, packageName, userId, tag);
    try {
        if (ActivityManagerNative.getDefault().getAppStartMode(uId, job.getService().getPackageName()) == ActivityManager.APP_START_MODE_DISABLED) {
            Slog.w(TAG, "Not scheduling job " + uId + ":" + job.toString() + " -- package not allowed to start");
            return JobScheduler.RESULT_FAILURE;
        }
    } catch (RemoteException e) {
    }
    if (DEBUG)
        Slog.d(TAG, "SCHEDULE: " + jobStatus.toShortString());
    JobStatus toCancel;
    synchronized (mLock) {
        // Jobs on behalf of others don't apply to the per-app job cap
        if (ENFORCE_MAX_JOBS && packageName == null) {
            if (mJobs.countJobsForUid(uId) > MAX_JOBS_PER_APP) {
                Slog.w(TAG, "Too many jobs for uid " + uId);
                throw new IllegalStateException("Apps may not schedule more than " + MAX_JOBS_PER_APP + " distinct jobs");
            }
        }
        toCancel = mJobs.getJobByUidAndJobId(uId, job.getId());
        if (toCancel != null) {
            cancelJobImpl(toCancel, jobStatus);
        }
        startTrackingJob(jobStatus, toCancel);
    }
    mHandler.obtainMessage(MSG_CHECK_JOB).sendToTarget();
    return JobScheduler.RESULT_SUCCESS;
}
Also used : JobStatus(com.android.server.job.controllers.JobStatus) RemoteException(android.os.RemoteException)

Example 37 with JobStatus

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

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

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

the class JobSchedulerService method cancelJobsForUser.

void cancelJobsForUser(int userHandle) {
    List<JobStatus> jobsForUser;
    synchronized (mLock) {
        jobsForUser = mJobs.getJobsByUser(userHandle);
    }
    for (int i = 0; i < jobsForUser.size(); i++) {
        JobStatus toRemove = jobsForUser.get(i);
        cancelJobImpl(toRemove, null);
    }
}
Also used : JobStatus(com.android.server.job.controllers.JobStatus)

Example 39 with JobStatus

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

the class JobSchedulerService method noteJobsPending.

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

Example 40 with JobStatus

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

the class JobSchedulerService method onDeviceIdleStateChanged.

@Override
public void onDeviceIdleStateChanged(boolean deviceIdle) {
    synchronized (mLock) {
        if (deviceIdle) {
            // except those using the idle exemption flag.
            for (int i = 0; i < mActiveServices.size(); i++) {
                JobServiceContext jsc = mActiveServices.get(i);
                final JobStatus executing = jsc.getRunningJob();
                if (executing != null && (executing.getFlags() & JobInfo.FLAG_WILL_BE_FOREGROUND) == 0) {
                    jsc.cancelExecutingJob(JobParameters.REASON_DEVICE_IDLE);
                }
            }
        } else {
            // When coming out of idle, allow thing to start back up.
            if (mReadyToRock) {
                if (mLocalDeviceIdleController != null) {
                    if (!mReportedActive) {
                        mReportedActive = true;
                        mLocalDeviceIdleController.setJobsActive(true);
                    }
                }
            }
            mHandler.obtainMessage(MSG_CHECK_JOB).sendToTarget();
        }
    }
}
Also used : JobStatus(com.android.server.job.controllers.JobStatus)

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