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

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

Merge changes I14e4cc5c,I2875765b

* changes:
  Fix cross user package visibility leakage for PackageManager (1/n)
  Add filtering uninstalled package flag to the shouldFilterApplication
parents 16244ee4 f5f55f41
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -215,6 +215,9 @@ public interface Computer extends PackageDataSnapshot {
    boolean isInstantApp(String packageName, int userId);
    boolean isInstantAppInternal(String packageName, @UserIdInt int userId, int callingUid);
    boolean isSameProfileGroup(@UserIdInt int callerUserId, @UserIdInt int userId);
    boolean shouldFilterApplication(@Nullable PackageStateInternal ps, int callingUid,
            @Nullable ComponentName component, @PackageManager.ComponentType int componentType,
            int userId, boolean filterUninstall);
    boolean shouldFilterApplication(@Nullable PackageStateInternal ps, int callingUid,
            @Nullable ComponentName component, @PackageManager.ComponentType int componentType,
            int userId);
@@ -222,6 +225,8 @@ public interface Computer extends PackageDataSnapshot {
            int userId);
    boolean shouldFilterApplication(@NonNull SharedUserSetting sus, int callingUid,
            int userId);
    boolean shouldFilterApplicationIncludingUninstalled(@Nullable PackageStateInternal ps,
            int callingUid, int userId);
    int checkUidPermission(String permName, int uid);
    int getPackageUidInternal(String packageName, long flags, int userId, int callingUid);
    long updateFlagsForApplication(long flags, int userId);
+37 −13
Original line number Diff line number Diff line
@@ -2677,7 +2677,7 @@ public class ComputerEngine implements Computer {
     */
    public final boolean shouldFilterApplication(@Nullable PackageStateInternal ps,
            int callingUid, @Nullable ComponentName component,
            @PackageManager.ComponentType int componentType, int userId) {
            @PackageManager.ComponentType int componentType, int userId, boolean filterUninstall) {
        if (Process.isSdkSandboxUid(callingUid)) {
            int clientAppUid = Process.getAppUidForSdkSandboxUid(callingUid);
            // SDK sandbox should be able to see it's client app
@@ -2691,9 +2691,11 @@ public class ComputerEngine implements Computer {
        }
        final String instantAppPkgName = getInstantAppPackageName(callingUid);
        final boolean callerIsInstantApp = instantAppPkgName != null;
        if (ps == null) {
            // pretend the application exists, but, needs to be filtered
            return callerIsInstantApp;
        if (ps == null
                || (filterUninstall && !ps.getUserStateOrDefault(userId).isInstalled())) {
            // If caller is instant app and ps is null, pretend the application exists,
            // but, needs to be filtered
            return (callerIsInstantApp || filterUninstall);
        }
        // if the target and caller are the same application, don't filter
        if (isCallerSameApp(ps.getPackageName(), callingUid)) {
@@ -2738,15 +2740,26 @@ public class ComputerEngine implements Computer {
    }

    /**
     * @see #shouldFilterApplication(PackageStateInternal, int, ComponentName, int, int)
     * @see #shouldFilterApplication(PackageStateInternal, int, ComponentName, int, int, boolean)
     */
    public final boolean shouldFilterApplication(@Nullable PackageStateInternal ps,
            int callingUid, @Nullable ComponentName component,
            @PackageManager.ComponentType int componentType, int userId) {
        return shouldFilterApplication(
                ps, callingUid, component, componentType, userId, false /* filterUninstall */);
    }

    /**
     * @see #shouldFilterApplication(PackageStateInternal, int, ComponentName, int, int, boolean)
     */
    public final boolean shouldFilterApplication(
            @Nullable PackageStateInternal ps, int callingUid, int userId) {
        return shouldFilterApplication(ps, callingUid, null, TYPE_UNKNOWN, userId);
        return shouldFilterApplication(
                ps, callingUid, null, TYPE_UNKNOWN, userId, false /* filterUninstall */);
    }

    /**
     * @see #shouldFilterApplication(PackageStateInternal, int, ComponentName, int, int)
     * @see #shouldFilterApplication(PackageStateInternal, int, ComponentName, int, int, boolean)
     */
    public final boolean shouldFilterApplication(@NonNull SharedUserSetting sus,
            int callingUid, int userId) {
@@ -2754,12 +2767,21 @@ public class ComputerEngine implements Computer {
        final ArraySet<PackageStateInternal> packageStates =
                (ArraySet<PackageStateInternal>) sus.getPackageStates();
        for (int index = packageStates.size() - 1; index >= 0 && filterApp; index--) {
            filterApp &= shouldFilterApplication(packageStates.valueAt(index),
                    callingUid, /* component */ null, TYPE_UNKNOWN, userId);
            filterApp &= shouldFilterApplication(packageStates.valueAt(index), callingUid,
                    null /* component */, TYPE_UNKNOWN, userId, false /* filterUninstall */);
        }
        return filterApp;
    }

    /**
     * @see #shouldFilterApplication(PackageStateInternal, int, ComponentName, int, int, boolean)
     */
    public final boolean shouldFilterApplicationIncludingUninstalled(
            @Nullable PackageStateInternal ps, int callingUid, int userId) {
        return shouldFilterApplication(
                ps, callingUid, null, TYPE_UNKNOWN, userId, true /* filterUninstall */);
    }

    /**
     * Verification statuses are ordered from the worse to the best, except for
     * INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_NEVER, which is the worse.
@@ -5264,9 +5286,10 @@ public class ComputerEngine implements Computer {
            return false;
        }
        final AndroidPackage pkg = mPackages.get(packageName);
        final int callingUserId = UserHandle.getUserId(callingUid);
        if (pkg == null
                || shouldFilterApplication(getPackageStateInternal(pkg.getPackageName()),
                callingUid, UserHandle.getUserId(callingUid))) {
                || shouldFilterApplicationIncludingUninstalled(
                        getPackageStateInternal(pkg.getPackageName()), callingUid, callingUserId)) {
            Slog.w(TAG, "KeySet requested for unknown package: " + packageName);
            throw new IllegalArgumentException("Unknown package: " + packageName);
        }
@@ -5288,9 +5311,10 @@ public class ComputerEngine implements Computer {
            return false;
        }
        final AndroidPackage pkg = mPackages.get(packageName);
        final int callingUserId = UserHandle.getUserId(callingUid);
        if (pkg == null
                || shouldFilterApplication(getPackageStateInternal(pkg.getPackageName()),
                callingUid, UserHandle.getUserId(callingUid))) {
                || shouldFilterApplicationIncludingUninstalled(
                        getPackageStateInternal(pkg.getPackageName()), callingUid, callingUserId)) {
            Slog.w(TAG, "KeySet requested for unknown package: " + packageName);
            throw new IllegalArgumentException("Unknown package: " + packageName);
        }
+2 −3
Original line number Diff line number Diff line
@@ -6636,9 +6636,8 @@ public class PackageManagerService implements PackageSender, TestUtilityService
            @UserIdInt int userId) {
        PackageStateInternal packageState =
                computer.getPackageStateInternal(packageName, callingUid);
        if (packageState == null
                || computer.shouldFilterApplication(packageState, callingUid, userId)
                || !packageState.getUserStateOrDefault(userId).isInstalled()) {
        if (computer.shouldFilterApplicationIncludingUninstalled(
                packageState, callingUid, userId)) {
            return null;
        } else {
            return packageState;
+1 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ android_test {
        "compatibility-device-util-axt",
        "androidx.test.runner",
        "truth-prebuilt",
        "Harrier",
    ],
    platform_apis: true,
    test_suites: ["device-tests"],
+9 −1
Original line number Diff line number Diff line
@@ -16,8 +16,16 @@
  -->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          package="com.android.server.pm.test.appenumeration">

    <queries>
        <package android:name="com.android.appenumeration.crossuserpackagevisibility" />
    </queries>

    <!-- It's merged from Harrier library. Remove it since this test should not hold it. -->
    <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" tools:node="remove" />

    <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
                     android:targetPackage="com.android.server.pm.test.appenumeration"
                     android:label="Package Manager Service Tests for app enumeration">
Loading