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
This commit is contained in:
Kweku Adams
2018-12-07 18:33:39 -08:00
parent 96dc163894
commit 8bd5edc4d6

View File

@@ -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,