Search in sources :

Example 96 with JobStatus

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

the class JobSchedulerService method printPendingQueue.

private String printPendingQueue() {
    StringBuilder s = new StringBuilder("Pending queue: ");
    Iterator<JobStatus> it = mPendingJobs.iterator();
    while (it.hasNext()) {
        JobStatus js = it.next();
        s.append("(").append(js.getJob().getId()).append(", ").append(js.getUid()).append(") ");
    }
    return s.toString();
}
Also used : JobStatus(com.android.server.job.controllers.JobStatus)

Example 97 with JobStatus

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

the class JobSchedulerService method onBootPhase.

@Override
public void onBootPhase(int phase) {
    if (PHASE_SYSTEM_SERVICES_READY == phase) {
        mConstants.start(getContext().getContentResolver());
        // Register br for package removals and user removals.
        final IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
        filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
        filter.addAction(Intent.ACTION_PACKAGE_RESTARTED);
        filter.addAction(Intent.ACTION_QUERY_PACKAGE_RESTART);
        filter.addDataScheme("package");
        getContext().registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, filter, null, null);
        final IntentFilter userFilter = new IntentFilter(Intent.ACTION_USER_REMOVED);
        getContext().registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, userFilter, null, null);
        mPowerManager = (PowerManager) getContext().getSystemService(Context.POWER_SERVICE);
        try {
            ActivityManagerNative.getDefault().registerUidObserver(mUidObserver, ActivityManager.UID_OBSERVER_PROCSTATE | ActivityManager.UID_OBSERVER_GONE | ActivityManager.UID_OBSERVER_IDLE);
        } catch (RemoteException e) {
        // ignored; both services live in system_server
        }
    } else if (phase == PHASE_THIRD_PARTY_APPS_CAN_START) {
        synchronized (mLock) {
            // Let's go!
            mReadyToRock = true;
            mBatteryStats = IBatteryStats.Stub.asInterface(ServiceManager.getService(BatteryStats.SERVICE_NAME));
            mLocalDeviceIdleController = LocalServices.getService(DeviceIdleController.LocalService.class);
            // Create the "runners".
            for (int i = 0; i < MAX_JOB_CONTEXTS_COUNT; i++) {
                mActiveServices.add(new JobServiceContext(this, mBatteryStats, mJobPackageTracker, getContext().getMainLooper()));
            }
            // Attach jobs to their controllers.
            mJobs.forEachJob(new JobStatusFunctor() {

                @Override
                public void process(JobStatus job) {
                    for (int controller = 0; controller < mControllers.size(); controller++) {
                        final StateController sc = mControllers.get(controller);
                        sc.maybeStartTrackingJobLocked(job, null);
                    }
                }
            });
            // GO GO GO!
            mHandler.obtainMessage(MSG_CHECK_JOB).sendToTarget();
        }
    }
}
Also used : JobStatus(com.android.server.job.controllers.JobStatus) IntentFilter(android.content.IntentFilter) DeviceIdleController(com.android.server.DeviceIdleController) JobStatusFunctor(com.android.server.job.JobStore.JobStatusFunctor) RemoteException(android.os.RemoteException) StateController(com.android.server.job.controllers.StateController)

Example 98 with JobStatus

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

the class JobSchedulerService method executeRunCommand.

// Shell command infrastructure: run the given job immediately
int executeRunCommand(String pkgName, int userId, int jobId, boolean force) {
    if (DEBUG) {
        Slog.v(TAG, "executeRunCommand(): " + pkgName + "/" + userId + " " + jobId + " f=" + force);
    }
    try {
        final int uid = AppGlobals.getPackageManager().getPackageUid(pkgName, 0, userId);
        if (uid < 0) {
            return JobSchedulerShellCommand.CMD_ERR_NO_PACKAGE;
        }
        synchronized (mLock) {
            final JobStatus js = mJobs.getJobByUidAndJobId(uid, jobId);
            if (js == null) {
                return JobSchedulerShellCommand.CMD_ERR_NO_JOB;
            }
            js.overrideState = (force) ? JobStatus.OVERRIDE_FULL : JobStatus.OVERRIDE_SOFT;
            if (!js.isConstraintsSatisfied()) {
                js.overrideState = 0;
                return JobSchedulerShellCommand.CMD_ERR_CONSTRAINTS;
            }
            mHandler.obtainMessage(MSG_CHECK_JOB_GREEDY).sendToTarget();
        }
    } catch (RemoteException e) {
    // can't happen
    }
    return 0;
}
Also used : JobStatus(com.android.server.job.controllers.JobStatus) RemoteException(android.os.RemoteException)

Example 99 with JobStatus

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

the class JobSchedulerService method cancelJobsForUid.

/**
     * Entry point from client to cancel all jobs originating from their uid.
     * This will remove the job from the master list, and cancel the job if it was staged for
     * execution or being executed.
     * @param uid Uid to check against for removal of a job.
     * @param forceAll If true, all jobs for the uid will be canceled; if false, only those
     * whose apps are stopped.
     */
public void cancelJobsForUid(int uid, boolean forceAll) {
    List<JobStatus> jobsForUid;
    synchronized (mLock) {
        jobsForUid = mJobs.getJobsByUid(uid);
    }
    for (int i = 0; i < jobsForUid.size(); i++) {
        JobStatus toRemove = jobsForUid.get(i);
        if (!forceAll) {
            String packageName = toRemove.getServiceComponent().getPackageName();
            try {
                if (ActivityManagerNative.getDefault().getAppStartMode(uid, packageName) != ActivityManager.APP_START_MODE_DISABLED) {
                    continue;
                }
            } catch (RemoteException e) {
            }
        }
        cancelJobImpl(toRemove, null);
    }
}
Also used : JobStatus(com.android.server.job.controllers.JobStatus) RemoteException(android.os.RemoteException)

Example 100 with JobStatus

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

the class JobSchedulerService method stopJobOnServiceContextLocked.

private boolean stopJobOnServiceContextLocked(JobStatus job, int reason) {
    for (int i = 0; i < mActiveServices.size(); i++) {
        JobServiceContext jsc = mActiveServices.get(i);
        final JobStatus executing = jsc.getRunningJob();
        if (executing != null && executing.matches(job.getUid(), job.getJobId())) {
            jsc.cancelExecutingJob(reason);
            return true;
        }
    }
    return false;
}
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