Loading core/java/android/app/ActivityManagerInternal.java +1 −1 Original line number Diff line number Diff line Loading @@ -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. Loading services/core/java/com/android/server/am/ActivityManagerService.java +12 −12 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); } } Loading Loading @@ -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); Loading @@ -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. Loading Loading @@ -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) { Loading Loading @@ -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); } } Loading Loading @@ -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); Loading @@ -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); } services/core/java/com/android/server/pm/AppsFilter.java +10 −10 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -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; Loading @@ -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; } Loading @@ -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; } Loading services/core/java/com/android/server/pm/PackageManagerService.java +19 −19 Original line number Diff line number Diff line Loading @@ -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, Loading Loading @@ -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*/, Loading Loading @@ -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(); Loading @@ -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); Loading Loading @@ -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); Loading Loading @@ -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)); } } Loading Loading @@ -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)) { Loading Loading @@ -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 Loading Loading @@ -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; Loading @@ -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) { Loading Loading @@ -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*/, Loading @@ -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); } } Loading @@ -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); } } Loading Loading @@ -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 services/tests/servicestests/src/com/android/server/pm/AppsFilterTest.java +5 −8 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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) Loading Loading @@ -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)); Loading @@ -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)); } Loading Loading
core/java/android/app/ActivityManagerInternal.java +1 −1 Original line number Diff line number Diff line Loading @@ -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. Loading
services/core/java/com/android/server/am/ActivityManagerService.java +12 −12 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); } } Loading Loading @@ -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); Loading @@ -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. Loading Loading @@ -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) { Loading Loading @@ -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); } } Loading Loading @@ -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); Loading @@ -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); }
services/core/java/com/android/server/pm/AppsFilter.java +10 −10 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -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; Loading @@ -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; } Loading @@ -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; } Loading
services/core/java/com/android/server/pm/PackageManagerService.java +19 −19 Original line number Diff line number Diff line Loading @@ -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, Loading Loading @@ -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*/, Loading Loading @@ -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(); Loading @@ -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); Loading Loading @@ -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); Loading Loading @@ -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)); } } Loading Loading @@ -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)) { Loading Loading @@ -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 Loading Loading @@ -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; Loading @@ -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) { Loading Loading @@ -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*/, Loading @@ -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); } } Loading @@ -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); } } Loading Loading @@ -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
services/tests/servicestests/src/com/android/server/pm/AppsFilterTest.java +5 −8 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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) Loading Loading @@ -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)); Loading @@ -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)); } Loading