Loading apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java +29 −26 Original line number Original line Diff line number Diff line Loading @@ -141,6 +141,7 @@ import java.util.function.Predicate; * * * Note on locking: Any operations that manipulate {@link #mJobs} need to lock on that object. * Note on locking: Any operations that manipulate {@link #mJobs} need to lock on that object. * Any function with the suffix 'Locked' also needs to lock on {@link #mJobs}. * Any function with the suffix 'Locked' also needs to lock on {@link #mJobs}. * * @hide * @hide */ */ public class JobSchedulerService extends com.android.server.SystemService public class JobSchedulerService extends com.android.server.SystemService Loading Loading @@ -744,7 +745,8 @@ public class JobSchedulerService extends com.android.server.SystemService try { try { final int userId = UserHandle.getUserId(pkgUid); final int userId = UserHandle.getUserId(pkgUid); IPackageManager pm = AppGlobals.getPackageManager(); IPackageManager pm = AppGlobals.getPackageManager(); final int state = pm.getApplicationEnabledSetting(pkgName, userId); final int state = pm.getApplicationEnabledSetting(pkgName, userId); if (state == COMPONENT_ENABLED_STATE_DISABLED if (state == COMPONENT_ENABLED_STATE_DISABLED || state == COMPONENT_ENABLED_STATE_DISABLED_USER) { || state == COMPONENT_ENABLED_STATE_DISABLED_USER) { if (DEBUG) { if (DEBUG) { Loading Loading @@ -798,16 +800,15 @@ public class JobSchedulerService extends com.android.server.SystemService } } } } } else if (Intent.ACTION_PACKAGE_FULLY_REMOVED.equals(action)) { } else if (Intent.ACTION_PACKAGE_FULLY_REMOVED.equals(action)) { int uidRemoved = intent.getIntExtra(Intent.EXTRA_UID, -1); if (DEBUG) { if (DEBUG) { Slog.d(TAG, "Removing jobs for uid: " + uidRemoved); Slog.d(TAG, "Removing jobs for " + pkgName + " (uid=" + pkgUid + ")"); } } synchronized (mLock) { synchronized (mLock) { mUidToPackageCache.remove(uidRemoved); mUidToPackageCache.remove(pkgUid); // There's no guarantee that the process has been stopped by the time we // There's no guarantee that the process has been stopped by the time we // get here, but since this is generally a user-initiated action, it should // get here, but since this is generally a user-initiated action, it should // be fine to just put USER instead of UNINSTALL or DISABLED. // be fine to just put USER instead of UNINSTALL or DISABLED. cancelJobsForPackageAndUidLocked(pkgName, uidRemoved, cancelJobsForPackageAndUidLocked(pkgName, pkgUid, JobParameters.STOP_REASON_USER, JobParameters.STOP_REASON_USER, JobParameters.INTERNAL_STOP_REASON_UNINSTALL, "app uninstalled"); JobParameters.INTERNAL_STOP_REASON_UNINSTALL, "app uninstalled"); for (int c = 0; c < mControllers.size(); ++c) { for (int c = 0; c < mControllers.size(); ++c) { Loading Loading @@ -1601,6 +1602,7 @@ public class JobSchedulerService extends com.android.server.SystemService /** /** * Called when we want to remove a JobStatus object that we've finished executing. * Called when we want to remove a JobStatus object that we've finished executing. * * @return true if the job was removed. * @return true if the job was removed. */ */ private boolean stopTrackingJobLocked(JobStatus jobStatus, JobStatus incomingJob, private boolean stopTrackingJobLocked(JobStatus jobStatus, JobStatus incomingJob, Loading Loading @@ -1655,7 +1657,6 @@ public class JobSchedulerService extends com.android.server.SystemService * @param failureToReschedule Provided job status that we will reschedule. * @param failureToReschedule Provided job status that we will reschedule. * @return A newly instantiated JobStatus with the same constraints as the last job except * @return A newly instantiated JobStatus with the same constraints as the last job except * with adjusted timing constraints. * with adjusted timing constraints. * * @see #maybeQueueReadyJobsForExecutionLocked * @see #maybeQueueReadyJobsForExecutionLocked */ */ @VisibleForTesting @VisibleForTesting Loading Loading @@ -2116,6 +2117,7 @@ public class JobSchedulerService extends com.android.server.SystemService newReadyJobs.clear(); newReadyJobs.clear(); } } } } private final ReadyJobQueueFunctor mReadyQueueFunctor = new ReadyJobQueueFunctor(); private final ReadyJobQueueFunctor mReadyQueueFunctor = new ReadyJobQueueFunctor(); /** /** Loading Loading @@ -2208,6 +2210,7 @@ public class JobSchedulerService extends com.android.server.SystemService runnableJobs.clear(); runnableJobs.clear(); } } } } private final MaybeReadyJobQueueFunctor mMaybeQueueFunctor = new MaybeReadyJobQueueFunctor(); private final MaybeReadyJobQueueFunctor mMaybeQueueFunctor = new MaybeReadyJobQueueFunctor(); private void maybeQueueReadyJobsForExecutionLocked() { private void maybeQueueReadyJobsForExecutionLocked() { Loading Loading @@ -2599,7 +2602,8 @@ public class JobSchedulerService extends com.android.server.SystemService * Binder stub trampoline implementation * Binder stub trampoline implementation */ */ final class JobSchedulerStub extends IJobScheduler.Stub { final class JobSchedulerStub extends IJobScheduler.Stub { /** Cache determination of whether a given app can persist jobs /** * Cache determination of whether a given app can persist jobs * key is uid of the calling app; value is undetermined/true/false * key is uid of the calling app; value is undetermined/true/false */ */ private final SparseArray<Boolean> mPersistCache = new SparseArray<Boolean>(); private final SparseArray<Boolean> mPersistCache = new SparseArray<Boolean>(); Loading Loading @@ -2880,8 +2884,7 @@ public class JobSchedulerService extends com.android.server.SystemService public List<JobInfo> getStartedJobs() { public List<JobInfo> getStartedJobs() { final int uid = Binder.getCallingUid(); final int uid = Binder.getCallingUid(); if (uid != Process.SYSTEM_UID) { if (uid != Process.SYSTEM_UID) { throw new SecurityException( throw new SecurityException("getStartedJobs() is system internal use only."); "getStartedJobs() is system internal use only."); } } final ArrayList<JobInfo> runningJobs; final ArrayList<JobInfo> runningJobs; Loading Loading @@ -2909,8 +2912,7 @@ public class JobSchedulerService extends com.android.server.SystemService public ParceledListSlice<JobSnapshot> getAllJobSnapshots() { public ParceledListSlice<JobSnapshot> getAllJobSnapshots() { final int uid = Binder.getCallingUid(); final int uid = Binder.getCallingUid(); if (uid != Process.SYSTEM_UID) { if (uid != Process.SYSTEM_UID) { throw new SecurityException( throw new SecurityException("getAllJobSnapshots() is system internal use only."); "getAllJobSnapshots() is system internal use only."); } } synchronized (mLock) { synchronized (mLock) { final ArrayList<JobSnapshot> snapshots = new ArrayList<>(mJobs.size()); final ArrayList<JobSnapshot> snapshots = new ArrayList<>(mJobs.size()); Loading Loading @@ -3514,7 +3516,8 @@ public class JobSchedulerService extends com.android.server.SystemService continue; continue; } } job.dump(proto, JobSchedulerServiceDumpProto.RegisteredJob.DUMP, true, nowElapsed); job.dump(proto, JobSchedulerServiceDumpProto.RegisteredJob.DUMP, true, nowElapsed); proto.write( proto.write( JobSchedulerServiceDumpProto.RegisteredJob.IS_JOB_READY_TO_BE_EXECUTED, JobSchedulerServiceDumpProto.RegisteredJob.IS_JOB_READY_TO_BE_EXECUTED, Loading Loading
apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java +29 −26 Original line number Original line Diff line number Diff line Loading @@ -141,6 +141,7 @@ import java.util.function.Predicate; * * * Note on locking: Any operations that manipulate {@link #mJobs} need to lock on that object. * Note on locking: Any operations that manipulate {@link #mJobs} need to lock on that object. * Any function with the suffix 'Locked' also needs to lock on {@link #mJobs}. * Any function with the suffix 'Locked' also needs to lock on {@link #mJobs}. * * @hide * @hide */ */ public class JobSchedulerService extends com.android.server.SystemService public class JobSchedulerService extends com.android.server.SystemService Loading Loading @@ -744,7 +745,8 @@ public class JobSchedulerService extends com.android.server.SystemService try { try { final int userId = UserHandle.getUserId(pkgUid); final int userId = UserHandle.getUserId(pkgUid); IPackageManager pm = AppGlobals.getPackageManager(); IPackageManager pm = AppGlobals.getPackageManager(); final int state = pm.getApplicationEnabledSetting(pkgName, userId); final int state = pm.getApplicationEnabledSetting(pkgName, userId); if (state == COMPONENT_ENABLED_STATE_DISABLED if (state == COMPONENT_ENABLED_STATE_DISABLED || state == COMPONENT_ENABLED_STATE_DISABLED_USER) { || state == COMPONENT_ENABLED_STATE_DISABLED_USER) { if (DEBUG) { if (DEBUG) { Loading Loading @@ -798,16 +800,15 @@ public class JobSchedulerService extends com.android.server.SystemService } } } } } else if (Intent.ACTION_PACKAGE_FULLY_REMOVED.equals(action)) { } else if (Intent.ACTION_PACKAGE_FULLY_REMOVED.equals(action)) { int uidRemoved = intent.getIntExtra(Intent.EXTRA_UID, -1); if (DEBUG) { if (DEBUG) { Slog.d(TAG, "Removing jobs for uid: " + uidRemoved); Slog.d(TAG, "Removing jobs for " + pkgName + " (uid=" + pkgUid + ")"); } } synchronized (mLock) { synchronized (mLock) { mUidToPackageCache.remove(uidRemoved); mUidToPackageCache.remove(pkgUid); // There's no guarantee that the process has been stopped by the time we // There's no guarantee that the process has been stopped by the time we // get here, but since this is generally a user-initiated action, it should // get here, but since this is generally a user-initiated action, it should // be fine to just put USER instead of UNINSTALL or DISABLED. // be fine to just put USER instead of UNINSTALL or DISABLED. cancelJobsForPackageAndUidLocked(pkgName, uidRemoved, cancelJobsForPackageAndUidLocked(pkgName, pkgUid, JobParameters.STOP_REASON_USER, JobParameters.STOP_REASON_USER, JobParameters.INTERNAL_STOP_REASON_UNINSTALL, "app uninstalled"); JobParameters.INTERNAL_STOP_REASON_UNINSTALL, "app uninstalled"); for (int c = 0; c < mControllers.size(); ++c) { for (int c = 0; c < mControllers.size(); ++c) { Loading Loading @@ -1601,6 +1602,7 @@ public class JobSchedulerService extends com.android.server.SystemService /** /** * Called when we want to remove a JobStatus object that we've finished executing. * Called when we want to remove a JobStatus object that we've finished executing. * * @return true if the job was removed. * @return true if the job was removed. */ */ private boolean stopTrackingJobLocked(JobStatus jobStatus, JobStatus incomingJob, private boolean stopTrackingJobLocked(JobStatus jobStatus, JobStatus incomingJob, Loading Loading @@ -1655,7 +1657,6 @@ public class JobSchedulerService extends com.android.server.SystemService * @param failureToReschedule Provided job status that we will reschedule. * @param failureToReschedule Provided job status that we will reschedule. * @return A newly instantiated JobStatus with the same constraints as the last job except * @return A newly instantiated JobStatus with the same constraints as the last job except * with adjusted timing constraints. * with adjusted timing constraints. * * @see #maybeQueueReadyJobsForExecutionLocked * @see #maybeQueueReadyJobsForExecutionLocked */ */ @VisibleForTesting @VisibleForTesting Loading Loading @@ -2116,6 +2117,7 @@ public class JobSchedulerService extends com.android.server.SystemService newReadyJobs.clear(); newReadyJobs.clear(); } } } } private final ReadyJobQueueFunctor mReadyQueueFunctor = new ReadyJobQueueFunctor(); private final ReadyJobQueueFunctor mReadyQueueFunctor = new ReadyJobQueueFunctor(); /** /** Loading Loading @@ -2208,6 +2210,7 @@ public class JobSchedulerService extends com.android.server.SystemService runnableJobs.clear(); runnableJobs.clear(); } } } } private final MaybeReadyJobQueueFunctor mMaybeQueueFunctor = new MaybeReadyJobQueueFunctor(); private final MaybeReadyJobQueueFunctor mMaybeQueueFunctor = new MaybeReadyJobQueueFunctor(); private void maybeQueueReadyJobsForExecutionLocked() { private void maybeQueueReadyJobsForExecutionLocked() { Loading Loading @@ -2599,7 +2602,8 @@ public class JobSchedulerService extends com.android.server.SystemService * Binder stub trampoline implementation * Binder stub trampoline implementation */ */ final class JobSchedulerStub extends IJobScheduler.Stub { final class JobSchedulerStub extends IJobScheduler.Stub { /** Cache determination of whether a given app can persist jobs /** * Cache determination of whether a given app can persist jobs * key is uid of the calling app; value is undetermined/true/false * key is uid of the calling app; value is undetermined/true/false */ */ private final SparseArray<Boolean> mPersistCache = new SparseArray<Boolean>(); private final SparseArray<Boolean> mPersistCache = new SparseArray<Boolean>(); Loading Loading @@ -2880,8 +2884,7 @@ public class JobSchedulerService extends com.android.server.SystemService public List<JobInfo> getStartedJobs() { public List<JobInfo> getStartedJobs() { final int uid = Binder.getCallingUid(); final int uid = Binder.getCallingUid(); if (uid != Process.SYSTEM_UID) { if (uid != Process.SYSTEM_UID) { throw new SecurityException( throw new SecurityException("getStartedJobs() is system internal use only."); "getStartedJobs() is system internal use only."); } } final ArrayList<JobInfo> runningJobs; final ArrayList<JobInfo> runningJobs; Loading Loading @@ -2909,8 +2912,7 @@ public class JobSchedulerService extends com.android.server.SystemService public ParceledListSlice<JobSnapshot> getAllJobSnapshots() { public ParceledListSlice<JobSnapshot> getAllJobSnapshots() { final int uid = Binder.getCallingUid(); final int uid = Binder.getCallingUid(); if (uid != Process.SYSTEM_UID) { if (uid != Process.SYSTEM_UID) { throw new SecurityException( throw new SecurityException("getAllJobSnapshots() is system internal use only."); "getAllJobSnapshots() is system internal use only."); } } synchronized (mLock) { synchronized (mLock) { final ArrayList<JobSnapshot> snapshots = new ArrayList<>(mJobs.size()); final ArrayList<JobSnapshot> snapshots = new ArrayList<>(mJobs.size()); Loading Loading @@ -3514,7 +3516,8 @@ public class JobSchedulerService extends com.android.server.SystemService continue; continue; } } job.dump(proto, JobSchedulerServiceDumpProto.RegisteredJob.DUMP, true, nowElapsed); job.dump(proto, JobSchedulerServiceDumpProto.RegisteredJob.DUMP, true, nowElapsed); proto.write( proto.write( JobSchedulerServiceDumpProto.RegisteredJob.IS_JOB_READY_TO_BE_EXECUTED, JobSchedulerServiceDumpProto.RegisteredJob.IS_JOB_READY_TO_BE_EXECUTED, Loading