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

Commit 995bf23e authored by Rhed Jao's avatar Rhed Jao Committed by Android (Google) Code Review
Browse files

Merge "Fix cross user package visibility leakage for PackageManager (5/n)"

parents 189b3a93 fa0139d5
Loading
Loading
Loading
Loading
+6 −4
Original line number Original line Diff line number Diff line
@@ -2691,8 +2691,10 @@ public class ComputerEngine implements Computer {
        }
        }
        final String instantAppPkgName = getInstantAppPackageName(callingUid);
        final String instantAppPkgName = getInstantAppPackageName(callingUid);
        final boolean callerIsInstantApp = instantAppPkgName != null;
        final boolean callerIsInstantApp = instantAppPkgName != null;
        if (ps == null
        // Don't treat hiddenUntilInstalled as an uninstalled state, phone app needs to access
                || (filterUninstall && !ps.getUserStateOrDefault(userId).isInstalled())) {
        // these hidden application details to customize carrier apps.
        if (ps == null || (filterUninstall && !ps.isHiddenUntilInstalled()
                && !ps.getUserStateOrDefault(userId).isInstalled())) {
            // If caller is instant app and ps is null, pretend the application exists,
            // If caller is instant app and ps is null, pretend the application exists,
            // but, needs to be filtered
            // but, needs to be filtered
            return (callerIsInstantApp || filterUninstall);
            return (callerIsInstantApp || filterUninstall);
@@ -5175,7 +5177,7 @@ public class ComputerEngine implements Computer {
        enforceCrossUserPermission(callingUid, userId, false /* requireFullPermission */,
        enforceCrossUserPermission(callingUid, userId, false /* requireFullPermission */,
                false /* checkShell */, "get enabled");
                false /* checkShell */, "get enabled");
        try {
        try {
            if (shouldFilterApplication(
            if (shouldFilterApplicationIncludingUninstalled(
                    mSettings.getPackage(packageName), callingUid, userId)) {
                    mSettings.getPackage(packageName), callingUid, userId)) {
                throw new PackageManager.NameNotFoundException(packageName);
                throw new PackageManager.NameNotFoundException(packageName);
            }
            }
@@ -5204,7 +5206,7 @@ public class ComputerEngine implements Computer {
        try {
        try {
            if (shouldFilterApplication(
            if (shouldFilterApplication(
                    mSettings.getPackage(component.getPackageName()), callingUid,
                    mSettings.getPackage(component.getPackageName()), callingUid,
                    component, TYPE_UNKNOWN, userId)) {
                    component, TYPE_UNKNOWN, userId, true /* filterUninstall */)) {
                throw new PackageManager.NameNotFoundException(component.getPackageName());
                throw new PackageManager.NameNotFoundException(component.getPackageName());
            }
            }
            return mSettings.getComponentEnabledSetting(component, userId);
            return mSettings.getComponentEnabledSetting(component, userId);
+14 −15
Original line number Original line Diff line number Diff line
@@ -3653,27 +3653,26 @@ public class PackageManagerService implements PackageSender, TestUtilityService
                        snapshot.getPackagesForUid(callingUid), packageName);
                        snapshot.getPackagesForUid(callingUid), packageName);
                final PackageSetting pkgSetting = mSettings.getPackageLPr(packageName);
                final PackageSetting pkgSetting = mSettings.getPackageLPr(packageName);
                // Limit who can change which apps
                // Limit who can change which apps
                if (!isCallerTargetApp) {
                if (!isCallerTargetApp && !allowedByPermission) {
                    // Don't allow apps that don't have permission to modify other apps
                    // Don't allow apps that don't have permission to modify other apps
                    if (!allowedByPermission
                            || snapshot.shouldFilterApplication(pkgSetting, callingUid, userId)) {
                    throw new SecurityException("Attempt to change component state; "
                    throw new SecurityException("Attempt to change component state; "
                            + "pid=" + Binder.getCallingPid()
                            + "pid=" + Binder.getCallingPid()
                            + ", uid=" + callingUid
                            + ", uid=" + callingUid
                            + (!setting.isComponent() ? ", package=" + packageName
                            + (!setting.isComponent() ? ", package=" + packageName
                            : ", component=" + setting.getComponentName()));
                            : ", component=" + setting.getComponentName()));
                }
                }
                    // Don't allow changing protected packages.
                if (pkgSetting == null || snapshot.shouldFilterApplicationIncludingUninstalled(
                    if (mProtectedPackages.isPackageStateProtected(userId, packageName)) {
                        pkgSetting, callingUid, userId)) {
                        throw new SecurityException(
                                "Cannot disable a protected package: " + packageName);
                    }
                }
                if (pkgSetting == null) {
                    throw new IllegalArgumentException(setting.isComponent()
                    throw new IllegalArgumentException(setting.isComponent()
                            ? "Unknown component: " + setting.getComponentName()
                            ? "Unknown component: " + setting.getComponentName()
                            : "Unknown package: " + packageName);
                            : "Unknown package: " + packageName);
                }
                }
                // Don't allow changing protected packages.
                if (!isCallerTargetApp
                        && mProtectedPackages.isPackageStateProtected(userId, packageName)) {
                    throw new SecurityException(
                            "Cannot disable a protected package: " + packageName);
                }
                if (callingUid == Process.SHELL_UID
                if (callingUid == Process.SHELL_UID
                        && (pkgSetting.getFlags() & ApplicationInfo.FLAG_TEST_ONLY) == 0) {
                        && (pkgSetting.getFlags() & ApplicationInfo.FLAG_TEST_ONLY) == 0) {
                    // Shell can only change whole packages between ENABLED and DISABLED_USER states
                    // Shell can only change whole packages between ENABLED and DISABLED_USER states