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

Commit 3da02e10 authored by yawanng's avatar yawanng Committed by android-build-team Robot
Browse files

Adds caller check to getAllPackages()

This change enforces that only system, root or shell may call
getAllPackages(), a hidden API that shares all package names regardless
of user, instant app or package visibility rules.

Bug: 174661955
Change-Id: I77460ae19a4d41151577646441f11e2eddbb741a
Merged-In: I77460ae19a4d41151577646441f11e2eddbb741a
(cherry picked from commit 8124efd5)
(cherry picked from commit cca5bf92)
parent 3eb43753
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -6515,6 +6515,11 @@ public class PackageManagerService extends IPackageManager.Stub
    @Override
    public List<String> getAllPackages() {
        final int callingUid = Binder.getCallingUid();
        // enforceSystemOrRootOrShell:
        if (callingUid != Process.SYSTEM_UID && callingUid != Process.ROOT_UID 
                && callingUid != Process.SHELL_UID) {
            throw new SecurityException("getAllPackages is limited to privileged callers");
        }        
        final int callingUserId = UserHandle.getUserId(callingUid);
        synchronized (mPackages) {
            if (canViewInstantApps(callingUid, callingUserId)) {