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

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

Merge changes from topic "pm_cross_user_package_visibility_8"

* changes:
  Fix cross user package visibility leakage for activitySupportsIntent
  Fix cross user package visibility leakage for PackageManager (8/n)
  Add a user id parameter to getProperty API
parents 229f7fbe 0df1d5a2
Loading
Loading
Loading
Loading
+12 −11
Original line number Diff line number Diff line
@@ -3716,15 +3716,7 @@ public class ApplicationPackageManager extends PackageManager {
            throws NameNotFoundException {
        Objects.requireNonNull(packageName);
        Objects.requireNonNull(propertyName);
        try {
            final Property property = mPM.getProperty(propertyName, packageName, null);
            if (property == null) {
                throw new NameNotFoundException();
            }
            return property;
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
        }
        return getPropertyAsUser(propertyName, packageName, null /* className */, getUserId());
    }

    @Override
@@ -3732,9 +3724,18 @@ public class ApplicationPackageManager extends PackageManager {
            throws NameNotFoundException {
        Objects.requireNonNull(component);
        Objects.requireNonNull(propertyName);
        return getPropertyAsUser(propertyName,
                component.getPackageName(), component.getClassName(), getUserId());
    }

    @Override
    public Property getPropertyAsUser(@NonNull String propertyName, @NonNull String packageName,
            @Nullable String className, int userId) throws NameNotFoundException {
        Objects.requireNonNull(packageName);
        Objects.requireNonNull(propertyName);
        try {
            final Property property = mPM.getProperty(
                    propertyName, component.getPackageName(), component.getClassName());
            final Property property = mPM.getPropertyAsUser(propertyName,
                    packageName, className, userId);
            if (property == null) {
                throw new NameNotFoundException();
            }
+4 −3
Original line number Diff line number Diff line
@@ -89,8 +89,8 @@ interface IPackageManager {

    ActivityInfo getActivityInfo(in ComponentName className, long flags, int userId);

    boolean activitySupportsIntent(in ComponentName className, in Intent intent,
            String resolvedType);
    boolean activitySupportsIntentAsUser(in ComponentName className, in Intent intent,
            String resolvedType, int userId);

    ActivityInfo getReceiverInfo(in ComponentName className, long flags, int userId);

@@ -795,7 +795,8 @@ interface IPackageManager {

    void holdLock(in IBinder token, in int durationMs);

    PackageManager.Property getProperty(String propertyName, String packageName, String className);
    PackageManager.Property getPropertyAsUser(String propertyName, String packageName,
            String className, int userId);
    ParceledListSlice queryProperty(String propertyName, int componentType);

    void setKeepUninstalledPackages(in List<String> packageList);
+15 −0
Original line number Diff line number Diff line
@@ -10224,6 +10224,21 @@ public abstract class PackageManager {
                "getProperty not implemented in subclass");
    }

    /**
     * If the provided className is {@code null}, returns the property defined on the application.
     * Otherwise, returns the property defined on the component.
     *
     * @throws NameNotFoundException if the given package is not installed on the calling user or
     * component does not exist or if the given property is not defined within the manifest.
     * @hide
     */
    @NonNull
    public Property getPropertyAsUser(@NonNull String propertyName, @NonNull String packageName,
            @Nullable String className, int userId) throws NameNotFoundException {
        throw new UnsupportedOperationException(
                "getPropertyAsUser not implemented in subclass");
    }

    /**
     * Returns the property definition for all &lt;application&gt; tags.
     * <p>If the property is not defined with any &lt;application&gt; tag,
+3 −2
Original line number Diff line number Diff line
@@ -189,8 +189,9 @@ public class BackupEligibilityRules {
                boolean isDebuggable = (app.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
                if (UserHandle.isCore(app.uid) || isPrivileged) {
                    try {
                        return mPackageManager.getProperty(PackageManager.PROPERTY_ALLOW_ADB_BACKUP,
                                packageName).getBoolean();
                        return mPackageManager.getPropertyAsUser(
                                PackageManager.PROPERTY_ALLOW_ADB_BACKUP, packageName,
                                null /* className */, mUserId).getBoolean();
                    } catch (PackageManager.NameNotFoundException e) {
                        Slog.w(TAG, "Failed to read allowAdbBackup property for + "
                                + packageName);
+4 −3
Original line number Diff line number Diff line
@@ -110,7 +110,7 @@ final class PackageUtils {

            final ComponentName componentName = service.getComponentName();

            if (isPrimaryCompanionDeviceService(pm, componentName)) {
            if (isPrimaryCompanionDeviceService(pm, componentName, userId)) {
                // "Primary" service should be at the head of the list.
                services.add(0, componentName);
            } else {
@@ -122,9 +122,10 @@ final class PackageUtils {
    }

    private static boolean isPrimaryCompanionDeviceService(@NonNull PackageManager pm,
            @NonNull ComponentName componentName) {
            @NonNull ComponentName componentName, @UserIdInt int userId) {
        try {
            return pm.getProperty(PROPERTY_PRIMARY_TAG, componentName).getBoolean();
            return pm.getPropertyAsUser(PROPERTY_PRIMARY_TAG, componentName.getPackageName(),
                    componentName.getClassName(), userId).getBoolean();
        } catch (PackageManager.NameNotFoundException e) {
            return false;
        }
Loading