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

Commit 08544604 authored by Rhed Jao's avatar Rhed Jao
Browse files

Fix cross user package visibility leakage for PackageManager (8/n)

Fix APIs:
- PackageManager#getApplicationHiddenSettingAsUser
- PackageManager#getInstallReason
- PackageManager#setDistractingPackageRestrictions
- PackageManager#movePackage
- PackageManager#setPackageStoppedState
- PackageManager#queryProperty
- PackageManager#setInstallerPackageName
- PackageManager#setPackagesSuspended
- IPackageManager#getBlockUninstallForUser

Bug: 229684723
Test: atest CrossUserPackageVisibilityTests
Change-Id: I8d9f93041ec2a283ecdef38ea23d104201db9f77
parent 04c59bf4
Loading
Loading
Loading
Loading
+9 −11
Original line number Diff line number Diff line
@@ -5011,7 +5011,7 @@ public class ComputerEngine implements Computer {
            if (ps == null) {
                return true;
            }
            if (shouldFilterApplication(ps, callingUid, userId)) {
            if (shouldFilterApplicationIncludingUninstalled(ps, callingUid, userId)) {
                return true;
            }
            return ps.getUserStateOrDefault(userId).isHidden();
@@ -5076,7 +5076,8 @@ public class ComputerEngine implements Computer {
    @Override
    public boolean getBlockUninstallForUser(@NonNull String packageName, @UserIdInt int userId) {
        final PackageStateInternal ps = mSettings.getPackage(packageName);
            if (ps == null || shouldFilterApplication(ps, Binder.getCallingUid(), userId)) {
        final int callingUid = Binder.getCallingUid();
        if (ps == null || shouldFilterApplicationIncludingUninstalled(ps, callingUid, userId)) {
            return false;
        }
        return mSettings.getBlockUninstall(userId, packageName);
@@ -5471,14 +5472,11 @@ public class ComputerEngine implements Computer {
        enforceCrossUserPermission(callingUid, userId, true /* requireFullPermission */,
                false /* checkShell */, "get install reason");
        final PackageStateInternal ps = mSettings.getPackage(packageName);
        if (shouldFilterApplication(ps, callingUid, userId)) {
        if (ps == null || shouldFilterApplicationIncludingUninstalled(ps, callingUid, userId)) {
            return PackageManager.INSTALL_REASON_UNKNOWN;
        }
        if (ps != null) {
        return ps.getUserStateOrDefault(userId).getInstallReason();
    }
        return PackageManager.INSTALL_REASON_UNKNOWN;
    }

    @Override
    public boolean canPackageQuery(@NonNull String sourcePackageName,
+3 −3
Original line number Diff line number Diff line
@@ -93,9 +93,9 @@ public final class DistractingPackageHelper {
        for (int i = 0; i < packageNames.length; i++) {
            final String packageName = packageNames[i];
            final PackageStateInternal packageState =
                    snapshot.getPackageStateInternal(packageName);
            if (packageState == null
                    || snapshot.shouldFilterApplication(packageState, callingUid, userId)) {
                    snapshot.getPackageStateForInstalledAndFiltered(
                            packageName, callingUid, userId);
            if (packageState == null) {
                Slog.w(PackageManagerService.TAG,
                        "Could not find package setting for package: " + packageName
                                + ". Skipping...");
+3 −4
Original line number Diff line number Diff line
@@ -80,10 +80,9 @@ public final class MovePackageHelper {
        final PackageManager pm = mPm.mContext.getPackageManager();

        Computer snapshot = mPm.snapshotComputer();
        final PackageStateInternal packageState = snapshot.getPackageStateInternal(packageName);
        if (packageState == null
                || packageState.getPkg() == null
                || snapshot.shouldFilterApplication(packageState, callingUid, user.getIdentifier())) {
        final PackageStateInternal packageState = snapshot.getPackageStateForInstalledAndFiltered(
                packageName, callingUid, user.getIdentifier());
        if (packageState == null || packageState.getPkg() == null) {
            throw new PackageManagerException(MOVE_FAILED_DOESNT_EXIST, "Missing package");
        }
        final AndroidPackage pkg = packageState.getPkg();
+13 −17
Original line number Diff line number Diff line
@@ -4378,12 +4378,11 @@ public class PackageManagerService implements PackageSender, TestUtilityService
                    true /* requireFullPermission */, true /* checkShell */, "stop package");

            final PackageStateInternal packageState =
                    snapshot.getPackageStateInternal(packageName);
                    snapshot.getPackageStateForInstalledAndFiltered(
                            packageName, callingUid, userId);
            final PackageUserState packageUserState = packageState == null
                    ? null : packageState.getUserStateOrDefault(userId);
            if (packageState != null
                    && !snapshot.shouldFilterApplication(packageState, callingUid, userId)
                    && packageUserState.isStopped() != stopped) {
            if (packageState != null && packageUserState.isStopped() != stopped) {
                boolean wasNotLaunched = packageUserState.isNotLaunched();
                commitPackageStateMutation(null, packageName, state -> {
                    PackageUserStateWrite userState = state.userState(userId);
@@ -5237,11 +5236,10 @@ public class PackageManagerService implements PackageSender, TestUtilityService
            final int callingUserId = UserHandle.getCallingUserId();
            final Computer snapshot = snapshotComputer();
            final List<PackageManager.Property> result =
                    mPackageProperty.queryProperty(propertyName, componentType, packageName -> {
                        final PackageStateInternal ps =
                                snapshot.getPackageStateInternal(packageName);
                        return snapshot.shouldFilterApplication(ps, callingUid, callingUserId);
                    });
                    mPackageProperty.queryProperty(propertyName, componentType,
                            packageName -> snapshot.getPackageStateForInstalledAndFiltered(
                                    packageName, callingUid, callingUserId) == null
                    );
            if (result == null) {
                return ParceledListSlice.emptyList();
            }
@@ -5600,19 +5598,17 @@ public class PackageManagerService implements PackageSender, TestUtilityService
                }

                PackageStateInternal targetPackageState =
                        snapshot.getPackageStateInternal(targetPackage);
                if (targetPackageState == null
                        || snapshot.shouldFilterApplication(targetPackageState, callingUid,
                        callingUserId)) {
                        snapshot.getPackageStateForInstalledAndFiltered(
                                targetPackage, callingUid, callingUserId);
                if (targetPackageState == null) {
                    throw new IllegalArgumentException("Unknown target package: " + targetPackage);
                }

                PackageStateInternal installerPackageState = null;
                if (installerPackageName != null) {
                    installerPackageState = snapshot.getPackageStateInternal(installerPackageName);
                    if (installerPackageState == null
                            || snapshot.shouldFilterApplication(
                            installerPackageState, callingUid, callingUserId)) {
                    installerPackageState = snapshot.getPackageStateForInstalledAndFiltered(
                            installerPackageName, callingUid, callingUserId);
                    if (installerPackageState == null) {
                        throw new IllegalArgumentException("Unknown installer package: "
                                + installerPackageName);
                    }
+3 −3
Original line number Diff line number Diff line
@@ -127,9 +127,9 @@ public final class SuspendPackageHelper {
                continue;
            }
            final PackageStateInternal packageState =
                    snapshot.getPackageStateInternal(packageName);
            if (packageState == null
                    || snapshot.shouldFilterApplication(packageState, callingUid, userId)) {
                    snapshot.getPackageStateForInstalledAndFiltered(
                            packageName, callingUid, userId);
            if (packageState == null) {
                Slog.w(TAG, "Could not find package setting for package: " + packageName
                        + ". Skipping suspending/un-suspending.");
                unmodifiablePackages.add(packageName);
Loading