Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 50ebc36b authored by Kweku Adams's avatar Kweku Adams
Browse files

Enforce RECEIVE_BOOT_COMPLETED permission.

Make sure apps have the RECEIVE_BOOT_COMPLETED permission when calling
enqueue().

Bug: 255352252
Test: atest CtsJobSchedulerTestCases
Change-Id: I6a12215a5d069c06821bffa8bc5a91b40d043678
parent db63d9a6
Loading
Loading
Loading
Loading
+8 −9
Original line number Original line Diff line number Diff line
@@ -3743,7 +3743,7 @@ public class JobSchedulerService extends com.android.server.SystemService
        // Enforce that only the app itself (or shared uid participant) can schedule a
        // Enforce that only the app itself (or shared uid participant) can schedule a
        // job that runs one of the app's services, as well as verifying that the
        // job that runs one of the app's services, as well as verifying that the
        // named service properly requires the BIND_JOB_SERVICE permission
        // named service properly requires the BIND_JOB_SERVICE permission
        private void enforceValidJobRequest(int uid, JobInfo job) {
        private void enforceValidJobRequest(int uid, int pid, JobInfo job) {
            final PackageManager pm = getContext()
            final PackageManager pm = getContext()
                    .createContextAsUser(UserHandle.getUserHandleForUid(uid), 0)
                    .createContextAsUser(UserHandle.getUserHandleForUid(uid), 0)
                    .getPackageManager();
                    .getPackageManager();
@@ -3767,6 +3767,10 @@ public class JobSchedulerService extends com.android.server.SystemService
                throw new IllegalArgumentException(
                throw new IllegalArgumentException(
                        "Tried to schedule job for non-existent component: " + service);
                        "Tried to schedule job for non-existent component: " + service);
            }
            }
            if (job.isPersisted() && !canPersistJobs(pid, uid)) {
                throw new IllegalArgumentException("Requested job cannot be persisted without"
                        + " holding android.permission.RECEIVE_BOOT_COMPLETED permission");
            }
        }
        }


        private boolean canPersistJobs(int pid, int uid) {
        private boolean canPersistJobs(int pid, int uid) {
@@ -3895,13 +3899,7 @@ public class JobSchedulerService extends com.android.server.SystemService
            final int uid = Binder.getCallingUid();
            final int uid = Binder.getCallingUid();
            final int userId = UserHandle.getUserId(uid);
            final int userId = UserHandle.getUserId(uid);


            enforceValidJobRequest(uid, job);
            enforceValidJobRequest(uid, pid, job);
            if (job.isPersisted()) {
                if (!canPersistJobs(pid, uid)) {
                    throw new IllegalArgumentException("Error: requested job be persisted without"
                            + " holding RECEIVE_BOOT_COMPLETED permission.");
                }
            }


            final int result = validateJob(job, uid, -1, null, null);
            final int result = validateJob(job, uid, -1, null, null);
            if (result != JobScheduler.RESULT_SUCCESS) {
            if (result != JobScheduler.RESULT_SUCCESS) {
@@ -3928,9 +3926,10 @@ public class JobSchedulerService extends com.android.server.SystemService
                Slog.d(TAG, "Enqueueing job: " + job.toString() + " work: " + work);
                Slog.d(TAG, "Enqueueing job: " + job.toString() + " work: " + work);
            }
            }
            final int uid = Binder.getCallingUid();
            final int uid = Binder.getCallingUid();
            final int pid = Binder.getCallingPid();
            final int userId = UserHandle.getUserId(uid);
            final int userId = UserHandle.getUserId(uid);


            enforceValidJobRequest(uid, job);
            enforceValidJobRequest(uid, pid, job);
            if (work == null) {
            if (work == null) {
                throw new NullPointerException("work is null");
                throw new NullPointerException("work is null");
            }
            }