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

Commit ec9eb593 authored by Patrick Baumann's avatar Patrick Baumann Committed by Android (Google) Code Review
Browse files

Merge "Inclusive naming of app enumeration changes from R"

parents 241b0165 4bec7098
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -457,7 +457,7 @@ public abstract class ActivityManagerInternal {
    public abstract int broadcastIntent(Intent intent,
            IIntentReceiver resultTo,
            String[] requiredPermissions, boolean serialized,
            int userId, int[] appIdWhitelist);
            int userId, int[] appIdAllowList);

    /**
     * Add uid to the ActivityManagerService PendingStartActivityUids list.
+12 −12
Original line number Diff line number Diff line
@@ -14286,7 +14286,7 @@ public class ActivityManagerService extends IActivityManager.Stub
    }
    private List<ResolveInfo> collectReceiverComponents(Intent intent, String resolvedType,
            int callingUid, int[] users, int[] broadcastWhitelist) {
            int callingUid, int[] users, int[] broadcastAllowList) {
        // TODO: come back and remove this assumption to triage all broadcasts
        int pmFlags = STOCK_PM_FLAGS | MATCH_DEBUG_TRIAGED_MISSING;
@@ -14362,12 +14362,12 @@ public class ActivityManagerService extends IActivityManager.Stub
        } catch (RemoteException ex) {
            // pm is in same process, this will never happen.
        }
        if (receivers != null && broadcastWhitelist != null) {
        if (receivers != null && broadcastAllowList != null) {
            for (int i = receivers.size() - 1; i >= 0; i--) {
                final int receiverAppId = UserHandle.getAppId(
                        receivers.get(i).activityInfo.applicationInfo.uid);
                if (receiverAppId >= Process.FIRST_APPLICATION_UID
                        && Arrays.binarySearch(broadcastWhitelist, receiverAppId) < 0) {
                        && Arrays.binarySearch(broadcastAllowList, receiverAppId) < 0) {
                    receivers.remove(i);
                }
            }
@@ -14477,7 +14477,7 @@ public class ActivityManagerService extends IActivityManager.Stub
            boolean ordered, boolean sticky, int callingPid, int callingUid, int realCallingUid,
            int realCallingPid, int userId, boolean allowBackgroundActivityStarts,
            @Nullable IBinder backgroundActivityStartsToken,
            @Nullable int[] broadcastWhitelist) {
            @Nullable int[] broadcastAllowList) {
        intent = new Intent(intent);
        final boolean callerInstantApp = isInstantApp(callerApp, callerPackage, callingUid);
@@ -14486,10 +14486,10 @@ public class ActivityManagerService extends IActivityManager.Stub
            intent.setFlags(intent.getFlags() & ~Intent.FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS);
        }
        if (userId == UserHandle.USER_ALL && broadcastWhitelist != null) {
                Slog.e(TAG, "broadcastWhitelist only applies when sending to individual users. "
        if (userId == UserHandle.USER_ALL && broadcastAllowList != null) {
                Slog.e(TAG, "broadcastAllowList only applies when sending to individual users. "
                        + "Assuming restrictive whitelist.");
                broadcastWhitelist = new int[]{};
                broadcastAllowList = new int[]{};
        }
        // By default broadcasts do not go to stopped apps.
@@ -14981,7 +14981,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        if ((intent.getFlags()&Intent.FLAG_RECEIVER_REGISTERED_ONLY)
                 == 0) {
            receivers = collectReceiverComponents(
                    intent, resolvedType, callingUid, users, broadcastWhitelist);
                    intent, resolvedType, callingUid, users, broadcastAllowList);
        }
        if (intent.getComponent() == null) {
            if (userId == UserHandle.USER_ALL && callingUid == SHELL_UID) {
@@ -15011,13 +15011,13 @@ public class ActivityManagerService extends IActivityManager.Stub
        if (DEBUG_BROADCAST) Slog.v(TAG_BROADCAST, "Enqueueing broadcast: " + intent.getAction()
                + " replacePending=" + replacePending);
        if (registeredReceivers != null && broadcastWhitelist != null) {
        if (registeredReceivers != null && broadcastAllowList != null) {
            // if a uid whitelist was provided, remove anything in the application space that wasn't
            // in it.
            for (int i = registeredReceivers.size() - 1; i >= 0; i--) {
                final int owningAppId = UserHandle.getAppId(registeredReceivers.get(i).owningUid);
                if (owningAppId >= Process.FIRST_APPLICATION_UID
                        && Arrays.binarySearch(broadcastWhitelist, owningAppId) < 0) {
                        && Arrays.binarySearch(broadcastAllowList, owningAppId) < 0) {
                    registeredReceivers.remove(i);
                }
            }
@@ -17996,7 +17996,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        public int broadcastIntent(Intent intent,
                IIntentReceiver resultTo,
                String[] requiredPermissions,
                boolean serialized, int userId, int[] appIdWhitelist) {
                boolean serialized, int userId, int[] appIdAllowList) {
            synchronized (ActivityManagerService.this) {
                intent = verifyBroadcastLocked(intent);
@@ -18011,7 +18011,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                            null /*options*/, serialized, false /*sticky*/, callingPid, callingUid,
                            callingUid, callingPid, userId, false /*allowBackgroundStarts*/,
                            null /*tokenNeededForBackgroundActivityStarts*/,
                            appIdWhitelist);
                            appIdAllowList);
                } finally {
                    Binder.restoreCallingIdentity(origId);
                }
+10 −10
Original line number Diff line number Diff line
@@ -137,11 +137,11 @@ public class AppsFilter {
    @VisibleForTesting(visibility = PRIVATE)
    AppsFilter(StateProvider stateProvider,
            FeatureConfig featureConfig,
            String[] forceQueryableWhitelist,
            String[] forceQueryableList,
            boolean systemAppsQueryable,
            @Nullable OverlayReferenceMapper.Provider overlayProvider) {
        mFeatureConfig = featureConfig;
        mForceQueryableByDevicePackageNames = forceQueryableWhitelist;
        mForceQueryableByDevicePackageNames = forceQueryableList;
        mSystemAppsQueryable = systemAppsQueryable;
        mOverlayReferenceMapper = new OverlayReferenceMapper(true /*deferRebuild*/,
                overlayProvider);
@@ -746,11 +746,11 @@ public class AppsFilter {
     * @param users            the set of users that should be evaluated for this calculation
     * @param existingSettings the set of all package settings that currently exist on device
     * @return a SparseArray mapping userIds to a sorted int array of appIds that may view the
     * provided setting or null if the app is visible to all and no whitelist should be
     * provided setting or null if the app is visible to all and no allow list should be
     * applied.
     */
    @Nullable
    public SparseArray<int[]> getVisibilityWhitelist(PackageSetting setting, int[] users,
    public SparseArray<int[]> getVisibilityAllowList(PackageSetting setting, int[] users,
            ArrayMap<String, PackageSetting> existingSettings) {
        if (mForceQueryable.contains(setting.appId)) {
            return null;
@@ -761,14 +761,14 @@ public class AppsFilter {
            final int userId = users[u];
            int[] appIds = new int[existingSettings.size()];
            int[] buffer = null;
            int whitelistSize = 0;
            int allowListSize = 0;
            for (int i = existingSettings.size() - 1; i >= 0; i--) {
                final PackageSetting existingSetting = existingSettings.valueAt(i);
                final int existingAppId = existingSetting.appId;
                if (existingAppId < Process.FIRST_APPLICATION_UID) {
                    continue;
                }
                final int loc = Arrays.binarySearch(appIds, 0, whitelistSize, existingAppId);
                final int loc = Arrays.binarySearch(appIds, 0, allowListSize, existingAppId);
                if (loc >= 0) {
                    continue;
                }
@@ -778,13 +778,13 @@ public class AppsFilter {
                        buffer = new int[appIds.length];
                    }
                    final int insert = ~loc;
                    System.arraycopy(appIds, insert, buffer, 0, whitelistSize - insert);
                    System.arraycopy(appIds, insert, buffer, 0, allowListSize - insert);
                    appIds[insert] = existingAppId;
                    System.arraycopy(buffer, 0, appIds, insert + 1, whitelistSize - insert);
                    whitelistSize++;
                    System.arraycopy(buffer, 0, appIds, insert + 1, allowListSize - insert);
                    allowListSize++;
                }
            }
            result.put(userId, Arrays.copyOf(appIds, whitelistSize));
            result.put(userId, Arrays.copyOf(appIds, allowListSize));
        }
        return result;
    }
+19 −19
Original line number Diff line number Diff line
@@ -2213,17 +2213,17 @@ public class PackageManagerService extends IPackageManager.Stub
                }
                extras.putInt(PackageInstaller.EXTRA_DATA_LOADER_TYPE, dataLoaderType);
                // Send to all running apps.
                final SparseArray<int[]> newBroadcastWhitelist;
                final SparseArray<int[]> newBroadcastAllowList;
                synchronized (mLock) {
                    newBroadcastWhitelist = mAppsFilter.getVisibilityWhitelist(
                    newBroadcastAllowList = mAppsFilter.getVisibilityAllowList(
                            getPackageSettingInternal(res.name, Process.SYSTEM_UID),
                            updateUserIds, mSettings.mPackages);
                }
                sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED, packageName,
                        extras, 0 /*flags*/,
                        null /*targetPackage*/, null /*finishedReceiver*/,
                        updateUserIds, instantUserIds, newBroadcastWhitelist);
                        updateUserIds, instantUserIds, newBroadcastAllowList);
                if (installerPackageName != null) {
                    // Send to the installer, even if it's not running.
                    sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED, packageName,
@@ -2255,7 +2255,7 @@ public class PackageManagerService extends IPackageManager.Stub
                    sendPackageBroadcast(Intent.ACTION_PACKAGE_REPLACED,
                            packageName, extras, 0 /*flags*/,
                            null /*targetPackage*/, null /*finishedReceiver*/,
                            updateUserIds, instantUserIds, res.removedInfo.broadcastWhitelist);
                            updateUserIds, instantUserIds, res.removedInfo.broadcastAllowList);
                    if (installerPackageName != null) {
                        sendPackageBroadcast(Intent.ACTION_PACKAGE_REPLACED, packageName,
                                extras, 0 /*flags*/,
@@ -12670,7 +12670,7 @@ public class PackageManagerService extends IPackageManager.Stub
    public void sendPackageBroadcast(final String action, final String pkg, final Bundle extras,
            final int flags, final String targetPkg, final IIntentReceiver finishedReceiver,
            final int[] userIds, int[] instantUserIds,
            @Nullable SparseArray<int[]> broadcastWhitelist) {
            @Nullable SparseArray<int[]> broadcastAllowList) {
        mHandler.post(() -> {
            try {
                final IActivityManager am = ActivityManager.getService();
@@ -12682,7 +12682,7 @@ public class PackageManagerService extends IPackageManager.Stub
                    resolvedUserIds = userIds;
                }
                doSendBroadcast(am, action, pkg, extras, flags, targetPkg, finishedReceiver,
                        resolvedUserIds, false, broadcastWhitelist);
                        resolvedUserIds, false, broadcastAllowList);
                if (instantUserIds != null && instantUserIds != EMPTY_INT_ARRAY) {
                    doSendBroadcast(am, action, pkg, extras, flags, targetPkg, finishedReceiver,
                            instantUserIds, true, null);
@@ -12755,7 +12755,7 @@ public class PackageManagerService extends IPackageManager.Stub
     */
    private void doSendBroadcast(IActivityManager am, String action, String pkg, Bundle extras,
            int flags, String targetPkg, IIntentReceiver finishedReceiver,
            int[] userIds, boolean isInstantApp, @Nullable SparseArray<int[]> broadcastWhitelist) {
            int[] userIds, boolean isInstantApp, @Nullable SparseArray<int[]> broadcastAllowList) {
        for (int id : userIds) {
            final Intent intent = new Intent(action,
                    pkg != null ? Uri.fromParts(PACKAGE_SCHEME, pkg, null) : null);
@@ -12785,7 +12785,7 @@ public class PackageManagerService extends IPackageManager.Stub
            mInjector.getActivityManagerInternal().broadcastIntent(
                    intent, finishedReceiver, requiredPermissions,
                    finishedReceiver != null, id,
                    broadcastWhitelist == null ? null : broadcastWhitelist.get(id));
                    broadcastAllowList == null ? null : broadcastAllowList.get(id));
        }
    }
@@ -12925,7 +12925,7 @@ public class PackageManagerService extends IPackageManager.Stub
        sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED,
                packageName, extras, 0, null, null, userIds, instantUserIds,
                mAppsFilter.getVisibilityWhitelist(
                mAppsFilter.getVisibilityAllowList(
                        getPackageSettingInternal(packageName, Process.SYSTEM_UID),
                        userIds, mSettings.mPackages));
        if (sendBootCompleted && !ArrayUtils.isEmpty(userIds)) {
@@ -16758,7 +16758,7 @@ public class PackageManagerService extends IPackageManager.Stub
                reconciledPkg.pkgSetting.firstInstallTime = deletedPkgSetting.firstInstallTime;
                reconciledPkg.pkgSetting.lastUpdateTime = System.currentTimeMillis();
                res.removedInfo.broadcastWhitelist = mAppsFilter.getVisibilityWhitelist(
                res.removedInfo.broadcastAllowList = mAppsFilter.getVisibilityAllowList(
                                reconciledPkg.pkgSetting, request.mAllUsers, mSettings.mPackages);
                if (reconciledPkg.prepareResult.system) {
                    // Remove existing system package
@@ -18688,7 +18688,7 @@ public class PackageManagerService extends IPackageManager.Stub
        boolean isStaticSharedLib;
        // a two dimensional array mapping userId to the set of appIds that can receive notice
        // of package changes
        SparseArray<int[]> broadcastWhitelist;
        SparseArray<int[]> broadcastAllowList;
        // Clean up resources deleted packages.
        InstallArgs args = null;
@@ -18711,9 +18711,9 @@ public class PackageManagerService extends IPackageManager.Stub
            extras.putInt(Intent.EXTRA_UID, removedAppId >= 0 ? removedAppId : uid);
            extras.putBoolean(Intent.EXTRA_REPLACING, true);
            packageSender.sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED, removedPackage, extras,
                    0, null /*targetPackage*/, null, null, null, broadcastWhitelist);
                    0, null /*targetPackage*/, null, null, null, broadcastAllowList);
            packageSender.sendPackageBroadcast(Intent.ACTION_PACKAGE_REPLACED, removedPackage,
                    extras, 0, null /*targetPackage*/, null, null, null, broadcastWhitelist);
                    extras, 0, null /*targetPackage*/, null, null, null, broadcastAllowList);
            packageSender.sendPackageBroadcast(Intent.ACTION_MY_PACKAGE_REPLACED, null, null, 0,
                    removedPackage, null, null, null, null /* broadcastWhitelist */);
            if (installerPackageName != null) {
@@ -18745,7 +18745,7 @@ public class PackageManagerService extends IPackageManager.Stub
            if (removedPackage != null) {
                packageSender.sendPackageBroadcast(Intent.ACTION_PACKAGE_REMOVED,
                    removedPackage, extras, 0, null /*targetPackage*/, null,
                    broadcastUsers, instantUserIds, broadcastWhitelist);
                    broadcastUsers, instantUserIds, broadcastAllowList);
                if (installerPackageName != null) {
                    packageSender.sendPackageBroadcast(Intent.ACTION_PACKAGE_REMOVED,
                            removedPackage, extras, 0 /*flags*/,
@@ -18754,7 +18754,7 @@ public class PackageManagerService extends IPackageManager.Stub
                if (dataRemoved && !isRemovedPackageSystemUpdate) {
                    packageSender.sendPackageBroadcast(Intent.ACTION_PACKAGE_FULLY_REMOVED,
                            removedPackage, extras, Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND, null,
                            null, broadcastUsers, instantUserIds, broadcastWhitelist);
                            null, broadcastUsers, instantUserIds, broadcastAllowList);
                    packageSender.notifyPackageRemoved(removedPackage, removedUid);
                }
            }
@@ -18767,7 +18767,7 @@ public class PackageManagerService extends IPackageManager.Stub
                packageSender.sendPackageBroadcast(Intent.ACTION_UID_REMOVED,
                        null, extras, Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND,
                        null, null, broadcastUsers, instantUserIds, broadcastWhitelist);
                        null, null, broadcastUsers, instantUserIds, broadcastAllowList);
            }
        }
@@ -21265,17 +21265,17 @@ public class PackageManagerService extends IPackageManager.Stub
        final boolean isInstantApp = isInstantApp(packageName, userId);
        final int[] userIds = isInstantApp ? EMPTY_INT_ARRAY : new int[] { userId };
        final int[] instantUserIds = isInstantApp ? new int[] { userId } : EMPTY_INT_ARRAY;
        final SparseArray<int[]> broadcastWhitelist;
        final SparseArray<int[]> broadcastAllowList;
        synchronized (mLock) {
            PackageSetting setting = getPackageSettingInternal(packageName, Process.SYSTEM_UID);
            if (setting == null) {
                return;
            }
            broadcastWhitelist = isInstantApp ? null : mAppsFilter.getVisibilityWhitelist(setting,
            broadcastAllowList = isInstantApp ? null : mAppsFilter.getVisibilityAllowList(setting,
                    userIds, mSettings.mPackages);
        }
        sendPackageBroadcast(Intent.ACTION_PACKAGE_CHANGED,  packageName, extras, flags, null, null,
                userIds, instantUserIds, broadcastWhitelist);
                userIds, instantUserIds, broadcastAllowList);
    }
    @Override
+5 −8
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.server.pm;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
@@ -70,8 +69,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.IntFunction;
import java.util.stream.Collectors;

@Presubmit
@RunWith(JUnit4.class)
@@ -805,24 +802,24 @@ public class AppsFilterTest {
                queriesProviderAppId);

        final SparseArray<int[]> systemFilter =
                appsFilter.getVisibilityWhitelist(system, USER_ARRAY, mExisting);
                appsFilter.getVisibilityAllowList(system, USER_ARRAY, mExisting);
        assertThat(toList(systemFilter.get(SYSTEM_USER)),
                contains(seesNothingAppId, hasProviderAppId, queriesProviderAppId));

        final SparseArray<int[]> seesNothingFilter =
                appsFilter.getVisibilityWhitelist(seesNothing, USER_ARRAY, mExisting);
                appsFilter.getVisibilityAllowList(seesNothing, USER_ARRAY, mExisting);
        assertThat(toList(seesNothingFilter.get(SYSTEM_USER)),
                contains(seesNothingAppId));
        assertThat(toList(seesNothingFilter.get(SECONDARY_USER)),
                contains(seesNothingAppId));

        final SparseArray<int[]> hasProviderFilter =
                appsFilter.getVisibilityWhitelist(hasProvider, USER_ARRAY, mExisting);
                appsFilter.getVisibilityAllowList(hasProvider, USER_ARRAY, mExisting);
        assertThat(toList(hasProviderFilter.get(SYSTEM_USER)),
                contains(hasProviderAppId, queriesProviderAppId));

        SparseArray<int[]> queriesProviderFilter =
                appsFilter.getVisibilityWhitelist(queriesProvider, USER_ARRAY, mExisting);
                appsFilter.getVisibilityAllowList(queriesProvider, USER_ARRAY, mExisting);
        assertThat(toList(queriesProviderFilter.get(SYSTEM_USER)),
                contains(queriesProviderAppId));

@@ -831,7 +828,7 @@ public class AppsFilterTest {

        // ensure implicit access is included in the filter
        queriesProviderFilter =
                appsFilter.getVisibilityWhitelist(queriesProvider, USER_ARRAY, mExisting);
                appsFilter.getVisibilityAllowList(queriesProvider, USER_ARRAY, mExisting);
        assertThat(toList(queriesProviderFilter.get(SYSTEM_USER)),
                contains(hasProviderAppId, queriesProviderAppId));
    }