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

Commit 39747538 authored by Jackal Guo's avatar Jackal Guo
Browse files

Apply package visibility to PACKAGE_DATA_CLEARED

Intent ACTION_PACKAGE_DATA_CLEARED is sent without the allowlist so
it may potentially leakage the package information.

Bug: 191291133
Test: atest AppEnumerationTests
Change-Id: Ica10615db22c0bc0eb4fba550bc069031f18c9a9
parent c02e59a1
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -377,7 +377,7 @@ public abstract class ActivityManagerInternal {
            IIntentReceiver resultTo, int resultCode, String resultData, Bundle resultExtras,
            IIntentReceiver resultTo, int resultCode, String resultData, Bundle resultExtras,
            String requiredPermission, Bundle bOptions, boolean serialized, boolean sticky,
            String requiredPermission, Bundle bOptions, boolean serialized, boolean sticky,
            @UserIdInt int userId, boolean allowBackgroundActivityStarts,
            @UserIdInt int userId, boolean allowBackgroundActivityStarts,
            @Nullable IBinder backgroundActivityStartsToken);
            @Nullable IBinder backgroundActivityStartsToken, @Nullable int[] broadcastAllowList);


    public abstract ComponentName startServiceInPackage(int uid, Intent service,
    public abstract ComponentName startServiceInPackage(int uid, Intent service,
            String resolvedType, boolean fgRequired, String callingPackage,
            String resolvedType, boolean fgRequired, String callingPackage,
+15 −0
Original line number Original line Diff line number Diff line
@@ -39,6 +39,7 @@ import android.os.HandlerExecutor;
import android.os.IBinder;
import android.os.IBinder;
import android.os.Looper;
import android.os.Looper;
import android.os.PersistableBundle;
import android.os.PersistableBundle;
import android.os.Process;
import android.util.ArrayMap;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.ArraySet;
import android.util.SparseArray;
import android.util.SparseArray;
@@ -719,6 +720,20 @@ public abstract class PackageManagerInternal implements PackageSettingsSnapshotP
     */
     */
    public abstract boolean filterAppAccess(int uid, int callingUid);
    public abstract boolean filterAppAccess(int uid, int callingUid);


    /**
     * Fetches all app Ids that a given application is currently visible to the provided user.
     *
     * <p>
     * <strong>Note: </strong>This only includes UIDs >= {@link Process#FIRST_APPLICATION_UID}
     * as all other UIDs can already see all applications.
     * </p>
     *
     * If the app is visible to all UIDs, null is returned. If the app is not visible to any
     * applications, the int array will be empty.
     */
    @Nullable
    public abstract int[] getVisibilityAllowList(@NonNull String packageName, int userId);

    /** Returns whether the given package was signed by the platform */
    /** Returns whether the given package was signed by the platform */
    public abstract boolean isPlatformSigned(String pkg);
    public abstract boolean isPlatformSigned(String pkg);


+10 −7
Original line number Original line Diff line number Diff line
@@ -3536,15 +3536,17 @@ public class ActivityManagerService extends IActivityManager.Stub
                    intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
                    intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
                    intent.putExtra(Intent.EXTRA_UID, (appInfo != null) ? appInfo.uid : -1);
                    intent.putExtra(Intent.EXTRA_UID, (appInfo != null) ? appInfo.uid : -1);
                    intent.putExtra(Intent.EXTRA_USER_HANDLE, resolvedUserId);
                    intent.putExtra(Intent.EXTRA_USER_HANDLE, resolvedUserId);
                    final int[] visibilityAllowList =
                            mPackageManagerInt.getVisibilityAllowList(packageName, resolvedUserId);
                    if (isInstantApp) {
                    if (isInstantApp) {
                        intent.putExtra(Intent.EXTRA_PACKAGE_NAME, packageName);
                        intent.putExtra(Intent.EXTRA_PACKAGE_NAME, packageName);
                        broadcastIntentInPackage("android", null, SYSTEM_UID, uid, pid, intent,
                        broadcastIntentInPackage("android", null, SYSTEM_UID, uid, pid, intent,
                                null, null, 0, null, null, permission.ACCESS_INSTANT_APPS, null,
                                null, null, 0, null, null, permission.ACCESS_INSTANT_APPS, null,
                                false, false, resolvedUserId, false, null);
                                false, false, resolvedUserId, false, null, visibilityAllowList);
                    } else {
                    } else {
                        broadcastIntentInPackage("android", null, SYSTEM_UID, uid, pid, intent,
                        broadcastIntentInPackage("android", null, SYSTEM_UID, uid, pid, intent,
                                null, null, 0, null, null, null, null, false, false, resolvedUserId,
                                null, null, 0, null, null, null, null, false, false, resolvedUserId,
                                false, null);
                                false, null, visibilityAllowList);
                    }
                    }
                    if (observer != null) {
                    if (observer != null) {
@@ -13653,7 +13655,8 @@ public class ActivityManagerService extends IActivityManager.Stub
            IIntentReceiver resultTo, int resultCode, String resultData, Bundle resultExtras,
            IIntentReceiver resultTo, int resultCode, String resultData, Bundle resultExtras,
            String requiredPermission, Bundle bOptions, boolean serialized, boolean sticky,
            String requiredPermission, Bundle bOptions, boolean serialized, boolean sticky,
            int userId, boolean allowBackgroundActivityStarts,
            int userId, boolean allowBackgroundActivityStarts,
            @Nullable IBinder backgroundActivityStartsToken) {
            @Nullable IBinder backgroundActivityStartsToken,
            @Nullable int[] broadcastAllowList) {
        synchronized(this) {
        synchronized(this) {
            intent = verifyBroadcastLocked(intent);
            intent = verifyBroadcastLocked(intent);
@@ -13665,8 +13668,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                        resultTo, resultCode, resultData, resultExtras, requiredPermissions, null,
                        resultTo, resultCode, resultData, resultExtras, requiredPermissions, null,
                        OP_NONE, bOptions, serialized, sticky, -1, uid, realCallingUid,
                        OP_NONE, bOptions, serialized, sticky, -1, uid, realCallingUid,
                        realCallingPid, userId, allowBackgroundActivityStarts,
                        realCallingPid, userId, allowBackgroundActivityStarts,
                        backgroundActivityStartsToken,
                        backgroundActivityStartsToken, broadcastAllowList);
                        null /* broadcastAllowList */);
            } finally {
            } finally {
                Binder.restoreCallingIdentity(origId);
                Binder.restoreCallingIdentity(origId);
            }
            }
@@ -15851,13 +15853,14 @@ public class ActivityManagerService extends IActivityManager.Stub
                IIntentReceiver resultTo, int resultCode, String resultData, Bundle resultExtras,
                IIntentReceiver resultTo, int resultCode, String resultData, Bundle resultExtras,
                String requiredPermission, Bundle bOptions, boolean serialized, boolean sticky,
                String requiredPermission, Bundle bOptions, boolean serialized, boolean sticky,
                int userId, boolean allowBackgroundActivityStarts,
                int userId, boolean allowBackgroundActivityStarts,
                @Nullable IBinder backgroundActivityStartsToken) {
                @Nullable IBinder backgroundActivityStartsToken,
                @Nullable int[] broadcastAllowList) {
            synchronized (ActivityManagerService.this) {
            synchronized (ActivityManagerService.this) {
                return ActivityManagerService.this.broadcastIntentInPackage(packageName, featureId,
                return ActivityManagerService.this.broadcastIntentInPackage(packageName, featureId,
                        uid, realCallingUid, realCallingPid, intent, resolvedType, resultTo,
                        uid, realCallingUid, realCallingPid, intent, resolvedType, resultTo,
                        resultCode, resultData, resultExtras, requiredPermission, bOptions,
                        resultCode, resultData, resultExtras, requiredPermission, bOptions,
                        serialized, sticky, userId, allowBackgroundActivityStarts,
                        serialized, sticky, userId, allowBackgroundActivityStarts,
                        backgroundActivityStartsToken);
                        backgroundActivityStartsToken, broadcastAllowList);
            }
            }
        }
        }
+2 −1
Original line number Original line Diff line number Diff line
@@ -468,7 +468,8 @@ public final class PendingIntentRecord extends IIntentSender.Stub {
                                key.featureId, uid, callingUid, callingPid, finalIntent,
                                key.featureId, uid, callingUid, callingPid, finalIntent,
                                resolvedType, finishedReceiver, code, null, null,
                                resolvedType, finishedReceiver, code, null, null,
                                requiredPermission, options, (finishedReceiver != null), false,
                                requiredPermission, options, (finishedReceiver != null), false,
                                userId, allowedByToken || allowTrampoline, bgStartsToken);
                                userId, allowedByToken || allowTrampoline, bgStartsToken,
                                null /* broadcastAllowList */);
                        if (sent == ActivityManager.BROADCAST_SUCCESS) {
                        if (sent == ActivityManager.BROADCAST_SUCCESS) {
                            sendFinish = false;
                            sendFinish = false;
                        }
                        }
+17 −0
Original line number Original line Diff line number Diff line
@@ -27126,6 +27126,18 @@ public class PackageManagerService extends IPackageManager.Stub
        return mComputer.filterAppAccess(uid, callingUid);
        return mComputer.filterAppAccess(uid, callingUid);
    }
    }
    private int[] getVisibilityAllowList(@NonNull String packageName, int userId) {
        synchronized (mLock) {
            final PackageSetting ps = getPackageSettingInternal(packageName, Process.SYSTEM_UID);
            if (ps == null) {
                return null;
            }
            final SparseArray<int[]> visibilityAllowList = mAppsFilter.getVisibilityAllowList(ps,
                    new int[]{userId}, mSettings.getPackagesLocked());
            return visibilityAllowList != null ? visibilityAllowList.get(userId) : null;
        }
    }
    private class PackageManagerInternalImpl extends PackageManagerInternal {
    private class PackageManagerInternalImpl extends PackageManagerInternal {
        @Override
        @Override
        public List<ApplicationInfo> getInstalledApplications(int flags, int userId,
        public List<ApplicationInfo> getInstalledApplications(int flags, int userId,
@@ -27213,6 +27225,11 @@ public class PackageManagerService extends IPackageManager.Stub
            return PackageManagerService.this.filterAppAccess(uid, callingUid);
            return PackageManagerService.this.filterAppAccess(uid, callingUid);
        }
        }
        @Nullable
        public int[] getVisibilityAllowList(@NonNull String packageName, int userId) {
            return PackageManagerService.this.getVisibilityAllowList(packageName, userId);
        }
        @Override
        @Override
        public AndroidPackage getPackage(String packageName) {
        public AndroidPackage getPackage(String packageName) {
            return PackageManagerService.this.getPackage(packageName);
            return PackageManagerService.this.getPackage(packageName);