From 8bd5edc4d60558443d9bf8464392f0af0ff10c42 Mon Sep 17 00:00:00 2001 From: Kweku Adams Date: Fri, 7 Dec 2018 18:33:39 -0800 Subject: Checking a job's source user id to determine readiness. We should be checking the source user id to determine if a job is ready to run instead of the calling user id. The calling user id is primarily kept to validate who can schedule and cancel a job, but a job should only run if the source user is started. Bug: N/A Test: atest CtsJobSchedulerTestCases PrioritySchedulingTest Change-Id: Idc5ee44c2ce3c5cb5300f38e5eec81709afed3b8 --- .../android/server/job/JobSchedulerService.java | 24 +++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/services/core/java/com/android/server/job/JobSchedulerService.java b/services/core/java/com/android/server/job/JobSchedulerService.java index 1325f049e737..f86cbfa933ba 100644 --- a/services/core/java/com/android/server/job/JobSchedulerService.java +++ b/services/core/java/com/android/server/job/JobSchedulerService.java @@ -954,7 +954,9 @@ public class JobSchedulerService extends com.android.server.SystemService @Override public void onStartUser(int userHandle) { - mStartedUsers = ArrayUtils.appendInt(mStartedUsers, userHandle); + synchronized (mLock) { + mStartedUsers = ArrayUtils.appendInt(mStartedUsers, userHandle); + } // Let's kick any outstanding jobs for this user. mHandler.obtainMessage(MSG_CHECK_JOB).sendToTarget(); } @@ -967,7 +969,9 @@ public class JobSchedulerService extends com.android.server.SystemService @Override public void onStopUser(int userHandle) { - mStartedUsers = ArrayUtils.removeInt(mStartedUsers, userHandle); + synchronized (mLock) { + mStartedUsers = ArrayUtils.removeInt(mStartedUsers, userHandle); + } } /** @@ -2150,8 +2154,7 @@ public class JobSchedulerService extends com.android.server.SystemService final boolean jobExists = mJobs.containsJob(job); - final int userId = job.getUserId(); - final boolean userStarted = ArrayUtils.contains(mStartedUsers, userId); + final boolean userStarted = areUsersStartedLocked(job); if (DEBUG) { Slog.v(TAG, "isReadyToBeExecutedLocked: " + job.toShortString() @@ -2239,7 +2242,7 @@ public class JobSchedulerService extends com.android.server.SystemService try { componentPresent = (AppGlobals.getPackageManager().getServiceInfo( job.getServiceComponent(), PackageManager.MATCH_DEBUG_TRIAGED_MISSING, - userId) != null); + job.getUserId()) != null); } catch (RemoteException e) { throw e.rethrowAsRuntimeException(); } @@ -3052,6 +3055,13 @@ public class JobSchedulerService extends com.android.server.SystemService printed = true; pw.println("user-stopped"); } + if (!ArrayUtils.contains(mStartedUsers, js.getSourceUserId())) { + if (printed) { + pw.print(" "); + } + printed = true; + pw.println("source-user-stopped"); + } if (mBackingUpUids.indexOfKey(js.getSourceUid()) >= 0) { if (printed) { pw.print(" "); @@ -3203,7 +3213,7 @@ public class JobSchedulerService extends com.android.server.SystemService pw.print(" (job="); pw.print(job.isReady()); pw.print(" user="); - pw.print(ArrayUtils.contains(mStartedUsers, job.getUserId())); + pw.print(areUsersStartedLocked(job)); pw.print(" !pending="); pw.print(!mPendingJobs.contains(job)); pw.print(" !active="); @@ -3373,7 +3383,7 @@ public class JobSchedulerService extends com.android.server.SystemService proto.write(JobSchedulerServiceDumpProto.RegisteredJob.IS_JOB_READY, job.isReady()); proto.write(JobSchedulerServiceDumpProto.RegisteredJob.IS_USER_STARTED, - ArrayUtils.contains(mStartedUsers, job.getUserId())); + areUsersStartedLocked(job)); proto.write(JobSchedulerServiceDumpProto.RegisteredJob.IS_JOB_PENDING, mPendingJobs.contains(job)); proto.write(JobSchedulerServiceDumpProto.RegisteredJob.IS_JOB_CURRENTLY_ACTIVE, -- cgit v1.2.3-59-g8ed1b