diff --git a/services/core/java/com/android/server/pm/AppsFilterImpl.java b/services/core/java/com/android/server/pm/AppsFilterImpl.java index dff7100e90e33..c447880e75e9b 100644 --- a/services/core/java/com/android/server/pm/AppsFilterImpl.java +++ b/services/core/java/com/android/server/pm/AppsFilterImpl.java @@ -61,6 +61,7 @@ import com.android.server.pm.pkg.component.ParsedInstrumentation; import com.android.server.pm.pkg.component.ParsedIntentInfo; import com.android.server.pm.pkg.component.ParsedMainComponent; import com.android.server.pm.pkg.component.ParsedProvider; +import com.android.server.pm.snapshot.PackageDataSnapshot; import com.android.server.utils.Snappable; import com.android.server.utils.SnapshotCache; import com.android.server.utils.Watchable; @@ -179,7 +180,6 @@ public class AppsFilterImpl implements AppsFilterSnapshot, Watchable, Snappable private final boolean mSystemAppsQueryable; private final FeatureConfig mFeatureConfig; private final OverlayReferenceMapper mOverlayReferenceMapper; - private final StateProvider mStateProvider; private SigningDetails mSystemSigningDetails; @GuardedBy("mLock") @@ -192,7 +192,8 @@ public class AppsFilterImpl implements AppsFilterSnapshot, Watchable, Snappable /** * This structure maps uid -> uid and indicates whether access from the first should be * filtered to the second. It's essentially a cache of the - * {@link #shouldFilterApplicationInternal(int, Object, PackageStateInternal, int)} call. + * {@link #shouldFilterApplicationInternal(PackageDataSnapshot, int, Object, + * PackageStateInternal, int)} call. * NOTE: It can only be relied upon after the system is ready to avoid unnecessary update on * initial scam and is empty until {@link #mSystemReady} is true. */ @@ -282,8 +283,7 @@ public class AppsFilterImpl implements AppsFilterSnapshot, Watchable, Snappable } @VisibleForTesting(visibility = PRIVATE) - AppsFilterImpl(StateProvider stateProvider, - FeatureConfig featureConfig, + AppsFilterImpl(FeatureConfig featureConfig, String[] forceQueryableList, boolean systemAppsQueryable, @Nullable OverlayReferenceMapper.Provider overlayProvider, @@ -293,7 +293,6 @@ public class AppsFilterImpl implements AppsFilterSnapshot, Watchable, Snappable mSystemAppsQueryable = systemAppsQueryable; mOverlayReferenceMapper = new OverlayReferenceMapper(true /*deferRebuild*/, overlayProvider); - mStateProvider = stateProvider; mBackgroundExecutor = backgroundExecutor; mShouldFilterCache = new WatchedSparseBooleanMatrix(); mShouldFilterCacheSnapshot = new SnapshotCache.Auto<>( @@ -352,7 +351,6 @@ public class AppsFilterImpl implements AppsFilterSnapshot, Watchable, Snappable mSystemAppsQueryable = orig.mSystemAppsQueryable; mFeatureConfig = orig.mFeatureConfig; mOverlayReferenceMapper = orig.mOverlayReferenceMapper; - mStateProvider = orig.mStateProvider; mSystemSigningDetails = orig.mSystemSigningDetails; synchronized (orig.mCacheLock) { mShouldFilterCache = orig.mShouldFilterCacheSnapshot.snapshot(); @@ -361,7 +359,7 @@ public class AppsFilterImpl implements AppsFilterSnapshot, Watchable, Snappable mBackgroundExecutor = null; mSnapshot = new SnapshotCache.Sealed<>(); - mSystemReady = true; + mSystemReady = orig.mSystemReady; } /** @@ -373,23 +371,6 @@ public class AppsFilterImpl implements AppsFilterSnapshot, Watchable, Snappable return mSnapshot.snapshot(); } - /** - * Provides system state to AppsFilter via {@link CurrentStateCallback} after properly guarding - * the data with the package lock. - * - * Don't call {@link #runWithState} with {@link #mCacheLock} held. - */ - @VisibleForTesting(visibility = PRIVATE) - public interface StateProvider { - void runWithState(CurrentStateCallback callback); - - interface CurrentStateCallback { - void currentState(ArrayMap settings, - Collection sharedUserSettings, - UserInfo[] users); - } - } - @VisibleForTesting(visibility = PRIVATE) public interface FeatureConfig { @@ -517,12 +498,13 @@ public class AppsFilterImpl implements AppsFilterSnapshot, Watchable, Snappable @Override public void onCompatChange(String packageName) { - AndroidPackage pkg = mPmInternal.getPackage(packageName); + PackageDataSnapshot snapshot = mPmInternal.snapshot(); + AndroidPackage pkg = snapshot.getPackage(packageName); if (pkg == null) { return; } updateEnabledState(pkg); - mAppsFilter.updateShouldFilterCacheForPackage(packageName); + mAppsFilter.updateShouldFilterCacheForPackage(snapshot, packageName); } private void updateEnabledState(@NonNull AndroidPackage pkg) { @@ -574,14 +556,7 @@ public class AppsFilterImpl implements AppsFilterSnapshot, Watchable, Snappable forcedQueryablePackageNames[i] = forcedQueryablePackageNames[i].intern(); } } - final StateProvider stateProvider = command -> { - synchronized (injector.getLock()) { - command.currentState(injector.getSettings().getPackagesLocked().untrackedStorage(), - injector.getSettings().getAllSharedUsersLPw(), - injector.getUserManagerInternal().getUserInfos()); - } - }; - AppsFilterImpl appsFilter = new AppsFilterImpl(stateProvider, featureConfig, + AppsFilterImpl appsFilter = new AppsFilterImpl(featureConfig, forcedQueryablePackageNames, forceSystemAppsQueryable, null, injector.getBackgroundExecutor()); featureConfig.setAppsFilter(appsFilter); @@ -754,12 +729,11 @@ public class AppsFilterImpl implements AppsFilterSnapshot, Watchable, Snappable return changed; } - public void onSystemReady() { + public void onSystemReady(PackageManagerInternal pmInternal) { mOverlayReferenceMapper.rebuildIfDeferred(); mFeatureConfig.onSystemReady(); - updateEntireShouldFilterCacheAsync(); - onChanged(); + updateEntireShouldFilterCacheAsync(pmInternal); mSystemReady = true; } @@ -769,39 +743,41 @@ public class AppsFilterImpl implements AppsFilterSnapshot, Watchable, Snappable * @param newPkgSetting the new setting being added * @param isReplace if the package is being replaced and may need extra cleanup. */ - public void addPackage(PackageStateInternal newPkgSetting, boolean isReplace) { + public void addPackage(PackageDataSnapshot snapshot, PackageStateInternal newPkgSetting, + boolean isReplace) { if (DEBUG_TRACING) { Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "filter.addPackage"); } try { if (isReplace) { // let's first remove any prior rules for this package - removePackage(newPkgSetting, true /*isReplace*/); + removePackage(snapshot, newPkgSetting, true /*isReplace*/); } - mStateProvider.runWithState((settings, sharedUserSettings, users) -> { - ArraySet additionalChangedPackages = - addPackageInternal(newPkgSetting, settings); - if (mSystemReady) { - updateShouldFilterCacheForPackage(null, newPkgSetting, + final ArrayMap settings = + snapshot.getPackageStates(); + final UserInfo[] users = snapshot.getUserInfos(); + final ArraySet additionalChangedPackages = + addPackageInternal(newPkgSetting, settings); + if (mSystemReady) { + synchronized (mCacheLock) { + updateShouldFilterCacheForPackage(snapshot, null, newPkgSetting, settings, users, USER_ALL, settings.size()); if (additionalChangedPackages != null) { for (int index = 0; index < additionalChangedPackages.size(); index++) { String changedPackage = additionalChangedPackages.valueAt(index); - PackageStateInternal changedPkgSetting = - settings.get(changedPackage); + PackageStateInternal changedPkgSetting = settings.get(changedPackage); if (changedPkgSetting == null) { // It's possible for the overlay mapper to know that an actor // package changed via an explicit reference, even if the actor // isn't installed, so skip if that's the case. continue; } - - updateShouldFilterCacheForPackage(null, changedPkgSetting, + updateShouldFilterCacheForPackage(snapshot, null, changedPkgSetting, settings, users, USER_ALL, settings.size()); } } - } // else, rebuild entire cache when system is ready - }); + } + } // else, rebuild entire cache when system is ready } finally { onChanged(); if (DEBUG_TRACING) { @@ -941,30 +917,32 @@ public class AppsFilterImpl implements AppsFilterSnapshot, Watchable, Snappable } } - private void updateEntireShouldFilterCache() { - updateEntireShouldFilterCache(USER_ALL); + private void updateEntireShouldFilterCache(PackageDataSnapshot snapshot) { + updateEntireShouldFilterCache(snapshot, USER_ALL); } - private void updateEntireShouldFilterCache(int subjectUserId) { - mStateProvider.runWithState((settings, sharedUserSettings, users) -> { - int userId = USER_NULL; - for (int u = 0; u < users.length; u++) { - if (subjectUserId == users[u].id) { - userId = subjectUserId; - break; - } + private void updateEntireShouldFilterCache(PackageDataSnapshot snapshot, int subjectUserId) { + final ArrayMap settings = + snapshot.getPackageStates(); + final UserInfo[] users = snapshot.getUserInfos(); + int userId = USER_NULL; + for (int u = 0; u < users.length; u++) { + if (subjectUserId == users[u].id) { + userId = subjectUserId; + break; } - if (userId == USER_NULL) { - Slog.e(TAG, "We encountered a new user that isn't a member of known users, " - + "updating the whole cache"); - userId = USER_ALL; - } - updateEntireShouldFilterCacheInner(settings, users, userId); - }); + } + if (userId == USER_NULL) { + Slog.e(TAG, "We encountered a new user that isn't a member of known users, " + + "updating the whole cache"); + userId = USER_ALL; + } + updateEntireShouldFilterCacheInner(snapshot, settings, users, userId); + onChanged(); } - private void updateEntireShouldFilterCacheInner( + private void updateEntireShouldFilterCacheInner(PackageDataSnapshot snapshot, ArrayMap settings, UserInfo[] users, int subjectUserId) { @@ -973,67 +951,42 @@ public class AppsFilterImpl implements AppsFilterSnapshot, Watchable, Snappable mShouldFilterCache.clear(); } mShouldFilterCache.setCapacity(users.length * settings.size()); - } - for (int i = settings.size() - 1; i >= 0; i--) { - updateShouldFilterCacheForPackage( - null /*skipPackage*/, settings.valueAt(i), settings, users, - subjectUserId, i); + for (int i = settings.size() - 1; i >= 0; i--) { + updateShouldFilterCacheForPackage(snapshot, + null /*skipPackage*/, settings.valueAt(i), settings, users, + subjectUserId, i); + } } } - private void updateEntireShouldFilterCacheAsync() { + private void updateEntireShouldFilterCacheAsync(PackageManagerInternal pmInternal) { mBackgroundExecutor.execute(() -> { - final ArrayMap settingsCopy = new ArrayMap<>(); - final Collection sharedUserSettingsCopy = new ArraySet<>(); final ArrayMap packagesCache = new ArrayMap<>(); final UserInfo[][] usersRef = new UserInfo[1][]; - mStateProvider.runWithState((settings, sharedUserSettings, users) -> { - packagesCache.ensureCapacity(settings.size()); - settingsCopy.putAll(settings); - usersRef[0] = users; - // store away the references to the immutable packages, since settings are retained - // during updates. - for (int i = 0, max = settings.size(); i < max; i++) { - final AndroidPackage pkg = settings.valueAt(i).getPkg(); - packagesCache.put(settings.keyAt(i), pkg); - } - sharedUserSettingsCopy.addAll(sharedUserSettings); - }); + final PackageDataSnapshot snapshot = pmInternal.snapshot(); + final ArrayMap settings = + snapshot.getPackageStates(); + final UserInfo[] users = snapshot.getUserInfos(); - boolean[] changed = new boolean[1]; - // We have a cache, let's make sure the world hasn't changed out from under us. - mStateProvider.runWithState((settings, sharedUserSettings, users) -> { - if (settings.size() != settingsCopy.size()) { - changed[0] = true; - return; - } - for (int i = 0, max = settings.size(); i < max; i++) { - final AndroidPackage pkg = settings.valueAt(i).getPkg(); - if (!Objects.equals(pkg, packagesCache.get(settings.keyAt(i)))) { - changed[0] = true; - return; - } - } - }); - if (changed[0]) { - // Something has changed, just update the cache inline with the lock held - updateEntireShouldFilterCache(); - if (DEBUG_LOGGING) { - Slog.i(TAG, "Rebuilding cache with lock due to package change."); - } - } else { - updateEntireShouldFilterCacheInner(settingsCopy, - usersRef[0], USER_ALL); - onChanged(); + packagesCache.ensureCapacity(settings.size()); + usersRef[0] = users; + // store away the references to the immutable packages, since settings are retained + // during updates. + for (int i = 0, max = settings.size(); i < max; i++) { + final AndroidPackage pkg = settings.valueAt(i).getPkg(); + packagesCache.put(settings.keyAt(i), pkg); } + + updateEntireShouldFilterCacheInner(snapshot, settings, usersRef[0], USER_ALL); + onChanged(); }); } - public void onUserCreated(int newUserId) { + public void onUserCreated(PackageDataSnapshot snapshot, int newUserId) { if (!mSystemReady) { return; } - updateEntireShouldFilterCache(newUserId); + updateEntireShouldFilterCache(snapshot, newUserId); } public void onUserDeleted(@UserIdInt int userId) { @@ -1044,19 +997,24 @@ public class AppsFilterImpl implements AppsFilterSnapshot, Watchable, Snappable onChanged(); } - private void updateShouldFilterCacheForPackage(String packageName) { - mStateProvider.runWithState((settings, sharedUserSettings, users) -> { - if (!mSystemReady) { - return; - } - updateShouldFilterCacheForPackage(null /* skipPackage */, + private void updateShouldFilterCacheForPackage(PackageDataSnapshot snapshot, + String packageName) { + if (!mSystemReady) { + return; + } + final ArrayMap settings = + snapshot.getPackageStates(); + final UserInfo[] users = snapshot.getUserInfos(); + synchronized (mCacheLock) { + updateShouldFilterCacheForPackage(snapshot, null /* skipPackage */, settings.get(packageName), settings, users, USER_ALL, settings.size() /*maxIndex*/); - }); + } onChanged(); } - private void updateShouldFilterCacheForPackage( + @GuardedBy("mCacheLock") + private void updateShouldFilterCacheForPackage(PackageDataSnapshot snapshot, @Nullable String skipPackageName, PackageStateInternal subjectSetting, ArrayMap allSettings, UserInfo[] allUsers, int subjectUserId, int maxIndex) { @@ -1072,31 +1030,30 @@ public class AppsFilterImpl implements AppsFilterSnapshot, Watchable, Snappable } if (subjectUserId == USER_ALL) { for (int su = 0; su < allUsers.length; su++) { - updateShouldFilterCacheForUser(subjectSetting, allUsers, otherSetting, + updateShouldFilterCacheForUser(snapshot, subjectSetting, allUsers, otherSetting, allUsers[su].id); } } else { - updateShouldFilterCacheForUser(subjectSetting, allUsers, otherSetting, + updateShouldFilterCacheForUser(snapshot, subjectSetting, allUsers, otherSetting, subjectUserId); } } } - private void updateShouldFilterCacheForUser( + @GuardedBy("mCacheLock") + private void updateShouldFilterCacheForUser(PackageDataSnapshot snapshot, PackageStateInternal subjectSetting, UserInfo[] allUsers, PackageStateInternal otherSetting, int subjectUserId) { for (int ou = 0; ou < allUsers.length; ou++) { int otherUser = allUsers[ou].id; int subjectUid = UserHandle.getUid(subjectUserId, subjectSetting.getAppId()); int otherUid = UserHandle.getUid(otherUser, otherSetting.getAppId()); - final boolean shouldFilterSubjectToOther = shouldFilterApplicationInternal( + final boolean shouldFilterSubjectToOther = shouldFilterApplicationInternal(snapshot, subjectUid, subjectSetting, otherSetting, otherUser); - final boolean shouldFilterOtherToSubject = shouldFilterApplicationInternal( + final boolean shouldFilterOtherToSubject = shouldFilterApplicationInternal(snapshot, otherUid, otherSetting, subjectSetting, subjectUserId); - synchronized (mCacheLock) { - mShouldFilterCache.put(subjectUid, otherUid, shouldFilterSubjectToOther); - mShouldFilterCache.put(otherUid, subjectUid, shouldFilterOtherToSubject); - } + mShouldFilterCache.put(subjectUid, otherUid, shouldFilterSubjectToOther); + mShouldFilterCache.put(otherUid, subjectUid, shouldFilterOtherToSubject); } } @@ -1182,11 +1139,13 @@ public class AppsFilterImpl implements AppsFilterSnapshot, Watchable, Snappable } /** - * See {@link AppsFilterSnapshot#getVisibilityAllowList(PackageStateInternal, int[], ArrayMap)} + * See {@link AppsFilterSnapshot#getVisibilityAllowList(PackageDataSnapshot, + * PackageStateInternal, int[], ArrayMap)} */ @Override @Nullable - public SparseArray getVisibilityAllowList(PackageStateInternal setting, int[] users, + public SparseArray getVisibilityAllowList(PackageDataSnapshot snapshot, + PackageStateInternal setting, int[] users, ArrayMap existingSettings) { synchronized (mLock) { if (mForceQueryable.contains(setting.getAppId())) { @@ -1211,7 +1170,8 @@ public class AppsFilterImpl implements AppsFilterSnapshot, Watchable, Snappable continue; } final int existingUid = UserHandle.getUid(userId, existingAppId); - if (!shouldFilterApplication(existingUid, existingSetting, setting, userId)) { + if (!shouldFilterApplication(snapshot, existingUid, existingSetting, setting, + userId)) { if (buffer == null) { buffer = new int[appIds.length]; } @@ -1232,19 +1192,21 @@ public class AppsFilterImpl implements AppsFilterSnapshot, Watchable, Snappable */ @VisibleForTesting(visibility = PRIVATE) @Nullable - SparseArray getVisibilityAllowList(PackageStateInternal setting, int[] users, + SparseArray getVisibilityAllowList(PackageDataSnapshot snapshot, + PackageStateInternal setting, int[] users, WatchedArrayMap existingSettings) { - return getVisibilityAllowList(setting, users, existingSettings.untrackedStorage()); + return getVisibilityAllowList(snapshot, setting, users, + existingSettings.untrackedStorage()); } /** - * Equivalent to calling {@link #addPackage(PackageStateInternal, boolean)} with - * {@code isReplace} equal to {@code false}. + * Equivalent to calling {@link #addPackage(PackageDataSnapshot, PackageStateInternal, boolean)} + * with {@code isReplace} equal to {@code false}. * - * @see AppsFilterImpl#addPackage(PackageStateInternal, boolean) + * @see AppsFilterImpl#addPackage(PackageDataSnapshot, PackageStateInternal, boolean) */ - public void addPackage(PackageStateInternal newPkgSetting) { - addPackage(newPkgSetting, false /* isReplace */); + public void addPackage(PackageDataSnapshot snapshot, PackageStateInternal newPkgSetting) { + addPackage(snapshot, newPkgSetting, false /* isReplace */); } /** @@ -1253,119 +1215,122 @@ public class AppsFilterImpl implements AppsFilterSnapshot, Watchable, Snappable * @param setting the setting of the package being removed. * @param isReplace if the package is being replaced. */ - public void removePackage(PackageStateInternal setting, boolean isReplace) { - mStateProvider.runWithState((settings, sharedUserSettings, users) -> { - final ArraySet additionalChangedPackages; - final int userCount = users.length; - synchronized (mLock) { - for (int u = 0; u < userCount; u++) { - final int userId = users[u].id; - final int removingUid = UserHandle.getUid(userId, setting.getAppId()); - mImplicitlyQueryable.remove(removingUid); - for (int i = mImplicitlyQueryable.size() - 1; i >= 0; i--) { - mImplicitlyQueryable.remove(mImplicitlyQueryable.keyAt(i), - removingUid); - } - - if (isReplace) { - continue; - } - - mRetainedImplicitlyQueryable.remove(removingUid); - for (int i = mRetainedImplicitlyQueryable.size() - 1; i >= 0; i--) { - mRetainedImplicitlyQueryable.remove( - mRetainedImplicitlyQueryable.keyAt(i), removingUid); - } + public void removePackage(PackageDataSnapshot snapshot, PackageStateInternal setting, + boolean isReplace) { + final ArraySet additionalChangedPackages; + final ArrayMap settings = + snapshot.getPackageStates(); + final UserInfo[] users = snapshot.getUserInfos(); + final Collection sharedUserSettings = snapshot.getAllSharedUsers(); + final int userCount = users.length; + synchronized (mLock) { + for (int u = 0; u < userCount; u++) { + final int userId = users[u].id; + final int removingUid = UserHandle.getUid(userId, setting.getAppId()); + mImplicitlyQueryable.remove(removingUid); + for (int i = mImplicitlyQueryable.size() - 1; i >= 0; i--) { + mImplicitlyQueryable.remove(mImplicitlyQueryable.keyAt(i), + removingUid); } - if (!mQueriesViaComponentRequireRecompute) { - mQueriesViaComponent.remove(setting.getAppId()); - for (int i = mQueriesViaComponent.size() - 1; i >= 0; i--) { - mQueriesViaComponent.remove(mQueriesViaComponent.keyAt(i), - setting.getAppId()); - } - } - mQueriesViaPackage.remove(setting.getAppId()); - for (int i = mQueriesViaPackage.size() - 1; i >= 0; i--) { - mQueriesViaPackage.remove(mQueriesViaPackage.keyAt(i), - setting.getAppId()); - } - mQueryableViaUsesLibrary.remove(setting.getAppId()); - for (int i = mQueryableViaUsesLibrary.size() - 1; i >= 0; i--) { - mQueryableViaUsesLibrary.remove(mQueryableViaUsesLibrary.keyAt(i), - setting.getAppId()); + if (isReplace) { + continue; } - mForceQueryable.remove(setting.getAppId()); - - if (setting.getPkg() != null - && !setting.getPkg().getProtectedBroadcasts().isEmpty()) { - final String removingPackageName = setting.getPkg().getPackageName(); - final ArrayList protectedBroadcasts = new ArrayList<>(); - protectedBroadcasts.addAll(mProtectedBroadcasts.untrackedStorage()); - collectProtectedBroadcasts(settings, removingPackageName); - if (!mProtectedBroadcasts.containsAll(protectedBroadcasts)) { - mQueriesViaComponentRequireRecompute = true; - } + mRetainedImplicitlyQueryable.remove(removingUid); + for (int i = mRetainedImplicitlyQueryable.size() - 1; i >= 0; i--) { + mRetainedImplicitlyQueryable.remove( + mRetainedImplicitlyQueryable.keyAt(i), removingUid); } } - additionalChangedPackages = mOverlayReferenceMapper.removePkg(setting.getPackageName()); - mFeatureConfig.updatePackageState(setting, true /*removed*/); - - // After removing all traces of the package, if it's part of a shared user, - // re-add other - // shared user members to re-establish visibility between them and other - // packages. - // NOTE: this must come after all removals from data structures but before we - // update the - // cache - if (setting.hasSharedUser()) { - final ArraySet sharedUserPackages = - getSharedUserPackages(setting.getSharedUserAppId(), sharedUserSettings); - for (int i = sharedUserPackages.size() - 1; i >= 0; i--) { - if (sharedUserPackages.valueAt(i) == setting) { - continue; - } - addPackageInternal( - sharedUserPackages.valueAt(i), settings); + if (!mQueriesViaComponentRequireRecompute) { + mQueriesViaComponent.remove(setting.getAppId()); + for (int i = mQueriesViaComponent.size() - 1; i >= 0; i--) { + mQueriesViaComponent.remove(mQueriesViaComponent.keyAt(i), + setting.getAppId()); } } + mQueriesViaPackage.remove(setting.getAppId()); + for (int i = mQueriesViaPackage.size() - 1; i >= 0; i--) { + mQueriesViaPackage.remove(mQueriesViaPackage.keyAt(i), + setting.getAppId()); + } + mQueryableViaUsesLibrary.remove(setting.getAppId()); + for (int i = mQueryableViaUsesLibrary.size() - 1; i >= 0; i--) { + mQueryableViaUsesLibrary.remove(mQueryableViaUsesLibrary.keyAt(i), + setting.getAppId()); + } - removeAppIdFromVisibilityCache(setting.getAppId()); - if (mSystemReady && setting.hasSharedUser()) { - final ArraySet sharedUserPackages = - getSharedUserPackages(setting.getSharedUserAppId(), sharedUserSettings); - for (int i = sharedUserPackages.size() - 1; i >= 0; i--) { - PackageStateInternal siblingSetting = - sharedUserPackages.valueAt(i); - if (siblingSetting == setting) { - continue; - } - updateShouldFilterCacheForPackage( + mForceQueryable.remove(setting.getAppId()); + + if (setting.getPkg() != null + && !setting.getPkg().getProtectedBroadcasts().isEmpty()) { + final String removingPackageName = setting.getPkg().getPackageName(); + final ArrayList protectedBroadcasts = new ArrayList<>(); + protectedBroadcasts.addAll(mProtectedBroadcasts.untrackedStorage()); + collectProtectedBroadcasts(settings, removingPackageName); + if (!mProtectedBroadcasts.containsAll(protectedBroadcasts)) { + mQueriesViaComponentRequireRecompute = true; + } + } + } + + additionalChangedPackages = mOverlayReferenceMapper.removePkg(setting.getPackageName()); + mFeatureConfig.updatePackageState(setting, true /*removed*/); + + // After removing all traces of the package, if it's part of a shared user, re-add other + // shared user members to re-establish visibility between them and other packages. + // NOTE: this must come after all removals from data structures but before we update the + // cache + if (setting.hasSharedUser()) { + final ArraySet sharedUserPackages = + getSharedUserPackages(setting.getSharedUserAppId(), sharedUserSettings); + for (int i = sharedUserPackages.size() - 1; i >= 0; i--) { + if (sharedUserPackages.valueAt(i) == setting) { + continue; + } + addPackageInternal( + sharedUserPackages.valueAt(i), settings); + } + } + + removeAppIdFromVisibilityCache(setting.getAppId()); + if (mSystemReady && setting.hasSharedUser()) { + final ArraySet sharedUserPackages = + getSharedUserPackages(setting.getSharedUserAppId(), sharedUserSettings); + for (int i = sharedUserPackages.size() - 1; i >= 0; i--) { + PackageStateInternal siblingSetting = + sharedUserPackages.valueAt(i); + if (siblingSetting == setting) { + continue; + } + synchronized (mCacheLock) { + updateShouldFilterCacheForPackage(snapshot, setting.getPackageName(), siblingSetting, settings, users, USER_ALL, settings.size()); } } + } - if (mSystemReady) { - if (additionalChangedPackages != null) { - for (int index = 0; index < additionalChangedPackages.size(); index++) { - String changedPackage = additionalChangedPackages.valueAt(index); - PackageStateInternal changedPkgSetting = settings.get(changedPackage); - if (changedPkgSetting == null) { - // It's possible for the overlay mapper to know that an actor - // package changed via an explicit reference, even if the actor - // isn't installed, so skip if that's the case. - continue; - } - - updateShouldFilterCacheForPackage(null, changedPkgSetting, + if (mSystemReady) { + if (additionalChangedPackages != null) { + for (int index = 0; index < additionalChangedPackages.size(); index++) { + String changedPackage = additionalChangedPackages.valueAt(index); + PackageStateInternal changedPkgSetting = settings.get(changedPackage); + if (changedPkgSetting == null) { + // It's possible for the overlay mapper to know that an actor + // package changed via an explicit reference, even if the actor + // isn't installed, so skip if that's the case. + continue; + } + synchronized (mCacheLock) { + updateShouldFilterCacheForPackage(snapshot, null, changedPkgSetting, settings, users, USER_ALL, settings.size()); } } } - }); + } onChanged(); } @@ -1382,12 +1347,12 @@ public class AppsFilterImpl implements AppsFilterSnapshot, Watchable, Snappable /** * See - * {@link AppsFilterSnapshot#shouldFilterApplication(int, Object, PackageStateInternal, - * int)} + * {@link AppsFilterSnapshot#shouldFilterApplication(PackageDataSnapshot, int, Object, + * PackageStateInternal, int)} */ @Override - public boolean shouldFilterApplication(int callingUid, @Nullable Object callingSetting, - PackageStateInternal targetPkgSetting, int userId) { + public boolean shouldFilterApplication(PackageDataSnapshot snapshot, int callingUid, + @Nullable Object callingSetting, PackageStateInternal targetPkgSetting, int userId) { if (DEBUG_TRACING) { Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "shouldFilterApplication"); } @@ -1405,7 +1370,7 @@ public class AppsFilterImpl implements AppsFilterSnapshot, Watchable, Snappable return false; } } else { - if (!shouldFilterApplicationInternal( + if (!shouldFilterApplicationInternal(snapshot, callingUid, callingSetting, targetPkgSetting, userId)) { return false; } @@ -1440,8 +1405,8 @@ public class AppsFilterImpl implements AppsFilterSnapshot, Watchable, Snappable } } - private boolean shouldFilterApplicationInternal(int callingUid, Object callingSetting, - PackageStateInternal targetPkgSetting, int targetUserId) { + private boolean shouldFilterApplicationInternal(PackageDataSnapshot snapshot, int callingUid, + Object callingSetting, PackageStateInternal targetPkgSetting, int targetUserId) { if (DEBUG_TRACING) { Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "shouldFilterApplicationInternal"); } @@ -1467,9 +1432,8 @@ public class AppsFilterImpl implements AppsFilterSnapshot, Watchable, Snappable final PackageStateInternal packageState = (PackageStateInternal) callingSetting; if (packageState.hasSharedUser()) { callingPkgSetting = null; - mStateProvider.runWithState((settings, sharedUserSettings, users) -> - callingSharedPkgSettings.addAll(getSharedUserPackages( - packageState.getSharedUserAppId(), sharedUserSettings))); + callingSharedPkgSettings.addAll(getSharedUserPackages( + packageState.getSharedUserAppId(), snapshot.getAllSharedUsers())); } else { callingPkgSetting = packageState; @@ -1600,11 +1564,7 @@ public class AppsFilterImpl implements AppsFilterSnapshot, Watchable, Snappable Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "mQueriesViaComponent"); } if (mQueriesViaComponentRequireRecompute) { - final ArrayMap settingsCopy = new ArrayMap<>(); - mStateProvider.runWithState((settings, sharedUserSettings, users) -> { - settingsCopy.putAll(settings); - }); - recomputeComponentVisibility(settingsCopy); + recomputeComponentVisibility(snapshot.getPackageStates()); onChanged(); } synchronized (mLock) { diff --git a/services/core/java/com/android/server/pm/AppsFilterSnapshot.java b/services/core/java/com/android/server/pm/AppsFilterSnapshot.java index cb8c649ded00b..de037f3ba8897 100644 --- a/services/core/java/com/android/server/pm/AppsFilterSnapshot.java +++ b/services/core/java/com/android/server/pm/AppsFilterSnapshot.java @@ -25,6 +25,7 @@ import android.util.SparseArray; import com.android.internal.util.function.QuadFunction; import com.android.server.pm.parsing.pkg.AndroidPackage; import com.android.server.pm.pkg.PackageStateInternal; +import com.android.server.pm.snapshot.PackageDataSnapshot; import java.io.PrintWriter; @@ -40,27 +41,30 @@ public interface AppsFilterSnapshot { * If the setting is visible to all UIDs, null is returned. If an app is not visible to any * applications, the int array will be empty. * + * @param snapshot the snapshot of the computer that contains all package information * @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 allow list should be * applied. */ - SparseArray getVisibilityAllowList(PackageStateInternal setting, int[] users, + SparseArray getVisibilityAllowList(PackageDataSnapshot snapshot, + PackageStateInternal setting, int[] users, ArrayMap existingSettings); /** * Returns true if the calling package should not be able to see the target package, false if no * filtering should be done. * + * @param snapshot the snapshot of the computer that contains all package information * @param callingUid the uid of the caller attempting to access a package * @param callingSetting the setting attempting to access a package or null if it could not be * found * @param targetPkgSetting the package being accessed * @param userId the user in which this access is being attempted */ - boolean shouldFilterApplication(int callingUid, @Nullable Object callingSetting, - PackageStateInternal targetPkgSetting, int userId); + boolean shouldFilterApplication(PackageDataSnapshot snapshot, int callingUid, + @Nullable Object callingSetting, PackageStateInternal targetPkgSetting, int userId); /** * Returns whether the querying package is allowed to see the target package. diff --git a/services/core/java/com/android/server/pm/Computer.java b/services/core/java/com/android/server/pm/Computer.java index c259797942a71..db48a1f630992 100644 --- a/services/core/java/com/android/server/pm/Computer.java +++ b/services/core/java/com/android/server/pm/Computer.java @@ -59,6 +59,7 @@ import com.android.server.utils.WatchedLongSparseArray; import java.io.FileDescriptor; import java.io.PrintWriter; +import java.util.Collection; import java.util.List; import java.util.Set; @@ -128,6 +129,7 @@ public interface Computer extends PackageDataSnapshot { */ ActivityInfo getActivityInfoInternal(ComponentName component, long flags, int filterCallingUid, int userId); + @Override AndroidPackage getPackage(String packageName); AndroidPackage getPackage(int uid); ApplicationInfo generateApplicationInfoFromSettings(String packageName, long flags, @@ -289,6 +291,7 @@ public interface Computer extends PackageDataSnapshot { PreferredIntentResolver getPreferredActivities(@UserIdInt int userId); @NonNull + @Override ArrayMap getPackageStates(); @Nullable @@ -602,4 +605,12 @@ public interface Computer extends PackageDataSnapshot { @NonNull List getVolumePackages(@NonNull String volumeUuid); + + @Override + @NonNull + UserInfo[] getUserInfos(); + + @Override + @NonNull + Collection getAllSharedUsers(); } diff --git a/services/core/java/com/android/server/pm/ComputerEngine.java b/services/core/java/com/android/server/pm/ComputerEngine.java index 80d61b593fd24..bf9f4fa8a2114 100644 --- a/services/core/java/com/android/server/pm/ComputerEngine.java +++ b/services/core/java/com/android/server/pm/ComputerEngine.java @@ -1348,7 +1348,7 @@ public class ComputerEngine implements Computer { PackageStateInternal resolvedSetting = getPackageStateInternal(info.activityInfo.packageName, 0); if (resolveForStart - || !mAppsFilter.shouldFilterApplication( + || !mAppsFilter.shouldFilterApplication(this, filterCallingUid, callingSetting, resolvedSetting, userId)) { continue; } @@ -1382,7 +1382,7 @@ public class ComputerEngine implements Computer { mSettings.getSettingBase(UserHandle.getAppId(filterCallingUid)); PackageStateInternal resolvedSetting = getPackageStateInternal(info.serviceInfo.packageName, 0); - if (!mAppsFilter.shouldFilterApplication( + if (!mAppsFilter.shouldFilterApplication(this, filterCallingUid, callingSetting, resolvedSetting, userId)) { continue; } @@ -2730,7 +2730,7 @@ public class ComputerEngine implements Computer { } int appId = UserHandle.getAppId(callingUid); final SettingBase callingPs = mSettings.getSettingBase(appId); - return mAppsFilter.shouldFilterApplication(callingUid, callingPs, ps, userId); + return mAppsFilter.shouldFilterApplication(this, callingUid, callingPs, ps, userId); } /** @@ -5036,7 +5036,7 @@ public class ComputerEngine implements Computer { if (setting == null) { return null; } - return mAppsFilter.getVisibilityAllowList(setting, userIds, getPackageStates()); + return mAppsFilter.getVisibilityAllowList(this, setting, userIds, getPackageStates()); } @Nullable @@ -5323,7 +5323,7 @@ public class ComputerEngine implements Computer { if (ps == null) { return null; } - final SparseArray visibilityAllowList = mAppsFilter.getVisibilityAllowList(ps, + final SparseArray visibilityAllowList = mAppsFilter.getVisibilityAllowList(this, ps, new int[]{userId}, getPackageStates()); return visibilityAllowList != null ? visibilityAllowList.get(userId) : null; } @@ -5823,4 +5823,16 @@ public class ComputerEngine implements Computer { public List getVolumePackages(@NonNull String volumeUuid) { return mSettings.getVolumePackages(volumeUuid); } + + @Override + @NonNull + public Collection getAllSharedUsers() { + return mSettings.getAllSharedUsers(); + } + + @Override + @NonNull + public UserInfo[] getUserInfos() { + return mInjector.getUserManagerInternal().getUserInfos(); + } } diff --git a/services/core/java/com/android/server/pm/DeletePackageHelper.java b/services/core/java/com/android/server/pm/DeletePackageHelper.java index d3d291ea52ac8..cb38d522f3bdd 100644 --- a/services/core/java/com/android/server/pm/DeletePackageHelper.java +++ b/services/core/java/com/android/server/pm/DeletePackageHelper.java @@ -543,8 +543,9 @@ final class DeletePackageHelper { synchronized (mPm.mLock) { if (outInfo != null) { outInfo.mUid = ps.getAppId(); - outInfo.mBroadcastAllowList = mPm.mAppsFilter.getVisibilityAllowList(ps, - allUserHandles, mPm.mSettings.getPackagesLocked()); + outInfo.mBroadcastAllowList = mPm.mAppsFilter.getVisibilityAllowList( + mPm.snapshotComputer(), ps, allUserHandles, + mPm.mSettings.getPackagesLocked()); } } diff --git a/services/core/java/com/android/server/pm/InstallPackageHelper.java b/services/core/java/com/android/server/pm/InstallPackageHelper.java index bbdb7ebfe8870..8bd1da9fbe9b2 100644 --- a/services/core/java/com/android/server/pm/InstallPackageHelper.java +++ b/services/core/java/com/android/server/pm/InstallPackageHelper.java @@ -464,9 +464,9 @@ final class InstallPackageHelper { KeySetManagerService ksms = mPm.mSettings.getKeySetManagerService(); ksms.addScannedPackageLPw(pkg); - mPm.mComponentResolver.addAllComponents(pkg, chatty, mPm.mSetupWizardPackage, - mPm.snapshotComputer()); - mPm.mAppsFilter.addPackage(pkgSetting, isReplace); + final Computer snapshot = mPm.snapshotComputer(); + mPm.mComponentResolver.addAllComponents(pkg, chatty, mPm.mSetupWizardPackage, snapshot); + mPm.mAppsFilter.addPackage(snapshot, pkgSetting, isReplace); mPm.addAllPackageProperties(pkg); if (oldPkgSetting == null || oldPkgSetting.getPkg() == null) { @@ -1916,7 +1916,7 @@ final class InstallPackageHelper { .setLastUpdateTime(System.currentTimeMillis()); res.mRemovedInfo.mBroadcastAllowList = mPm.mAppsFilter.getVisibilityAllowList( - reconciledPkg.mPkgSetting, request.mAllUsers, + mPm.snapshotComputer(), reconciledPkg.mPkgSetting, request.mAllUsers, mPm.mSettings.getPackagesLocked()); if (reconciledPkg.mPrepareResult.mSystem) { // Remove existing system package @@ -2712,9 +2712,9 @@ final class InstallPackageHelper { // Send to all running apps. final SparseArray newBroadcastAllowList; synchronized (mPm.mLock) { - newBroadcastAllowList = mPm.mAppsFilter.getVisibilityAllowList( - mPm.snapshotComputer() - .getPackageStateInternal(packageName, Process.SYSTEM_UID), + final Computer snapshot = mPm.snapshotComputer(); + newBroadcastAllowList = mPm.mAppsFilter.getVisibilityAllowList(snapshot, + snapshot.getPackageStateInternal(packageName, Process.SYSTEM_UID), updateUserIds, mPm.mSettings.getPackagesLocked()); } mPm.sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED, packageName, diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index 7fd28f678aedd..551d8d0d54d75 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -2992,7 +2992,7 @@ public class PackageManagerService implements PackageSender, TestUtilityService if (ArrayUtils.isEmpty(userIds) && ArrayUtils.isEmpty(instantUserIds)) { return; } - SparseArray broadcastAllowList = mAppsFilter.getVisibilityAllowList( + SparseArray broadcastAllowList = mAppsFilter.getVisibilityAllowList(snapshot, snapshot.getPackageStateInternal(packageName, Process.SYSTEM_UID), userIds, snapshot.getPackageStates()); mHandler.post(() -> mBroadcastHelper.sendPackageAddedForNewUsers( @@ -4013,7 +4013,7 @@ public class PackageManagerService implements PackageSender, TestUtilityService .getUriFor(Secure.INSTANT_APPS_ENABLED), false, co, UserHandle.USER_ALL); co.onChange(true); - mAppsFilter.onSystemReady(); + mAppsFilter.onSystemReady(LocalServices.getService(PackageManagerInternal.class)); // Disable any carrier apps. We do this very early in boot to prevent the apps from being // disabled after already being started. @@ -4226,7 +4226,7 @@ public class PackageManagerService implements PackageSender, TestUtilityService synchronized (mLock) { scheduleWritePackageRestrictions(userId); scheduleWritePackageListLocked(userId); - mAppsFilter.onUserCreated(userId); + mAppsFilter.onUserCreated(snapshotComputer(), userId); } } @@ -5751,7 +5751,7 @@ public class PackageManagerService implements PackageSender, TestUtilityService targetPackageState = snapshotComputer().getPackageStateInternal(targetPackage); mSettings.addInstallerPackageNames(targetPackageState.getInstallSource()); } - mAppsFilter.addPackage(targetPackageState); + mAppsFilter.addPackage(snapshotComputer(), targetPackageState); scheduleWriteSettings(); } } diff --git a/services/core/java/com/android/server/pm/RemovePackageHelper.java b/services/core/java/com/android/server/pm/RemovePackageHelper.java index baa3a9d85b0a1..65d3430fe474f 100644 --- a/services/core/java/com/android/server/pm/RemovePackageHelper.java +++ b/services/core/java/com/android/server/pm/RemovePackageHelper.java @@ -274,8 +274,9 @@ final class RemovePackageHelper { synchronized (mPm.mLock) { mPm.mDomainVerificationManager.clearPackage(deletedPs.getPackageName()); mPm.mSettings.getKeySetManagerService().removeAppKeySetDataLPw(packageName); - mPm.mAppsFilter.removePackage(mPm.snapshotComputer() - .getPackageStateInternal(packageName), false /* isReplace */); + final Computer snapshot = mPm.snapshotComputer(); + mPm.mAppsFilter.removePackage(snapshot, + snapshot.getPackageStateInternal(packageName), false /* isReplace */); removedAppId = mPm.mSettings.removePackageLPw(packageName); if (outInfo != null) { outInfo.mRemovedAppId = removedAppId; diff --git a/services/core/java/com/android/server/pm/SuspendPackageHelper.java b/services/core/java/com/android/server/pm/SuspendPackageHelper.java index 860c54c31bb2e..29c926c5f7904 100644 --- a/services/core/java/com/android/server/pm/SuspendPackageHelper.java +++ b/services/core/java/com/android/server/pm/SuspendPackageHelper.java @@ -598,7 +598,7 @@ public final class SuspendPackageHelper { final String pkgName = pkgList[i]; final int uid = uidList[i]; SparseArray allowList = mInjector.getAppsFilter().getVisibilityAllowList( - snapshot.getPackageStateInternal(pkgName, SYSTEM_UID), + snapshot, snapshot.getPackageStateInternal(pkgName, SYSTEM_UID), userIds, snapshot.getPackageStates()); if (allowList == null) { allowList = new SparseArray<>(0); diff --git a/services/core/java/com/android/server/pm/snapshot/PackageDataSnapshot.java b/services/core/java/com/android/server/pm/snapshot/PackageDataSnapshot.java index b09144568eb4e..e1e22222ae3ed 100644 --- a/services/core/java/com/android/server/pm/snapshot/PackageDataSnapshot.java +++ b/services/core/java/com/android/server/pm/snapshot/PackageDataSnapshot.java @@ -16,5 +16,22 @@ package com.android.server.pm.snapshot; +import android.annotation.NonNull; +import android.content.pm.UserInfo; +import android.util.ArrayMap; + +import com.android.server.pm.SharedUserSetting; +import com.android.server.pm.parsing.pkg.AndroidPackage; +import com.android.server.pm.pkg.PackageStateInternal; + +import java.util.Collection; + public interface PackageDataSnapshot { + @NonNull + ArrayMap getPackageStates(); + @NonNull + UserInfo[] getUserInfos(); + @NonNull + Collection getAllSharedUsers(); + AndroidPackage getPackage(String packageName); } diff --git a/services/tests/PackageManagerComponentOverrideTests/src/com/android/server/pm/test/override/PackageManagerComponentLabelIconOverrideTest.kt b/services/tests/PackageManagerComponentOverrideTests/src/com/android/server/pm/test/override/PackageManagerComponentLabelIconOverrideTest.kt index 7b152247eb9cc..9c0f713643541 100644 --- a/services/tests/PackageManagerComponentOverrideTests/src/com/android/server/pm/test/override/PackageManagerComponentLabelIconOverrideTest.kt +++ b/services/tests/PackageManagerComponentOverrideTests/src/com/android/server/pm/test/override/PackageManagerComponentLabelIconOverrideTest.kt @@ -30,6 +30,7 @@ import com.android.server.pm.parsing.pkg.AndroidPackage import com.android.server.pm.parsing.pkg.PackageImpl import com.android.server.pm.parsing.pkg.ParsedPackage import com.android.server.pm.resolution.ComponentResolver +import com.android.server.pm.snapshot.PackageDataSnapshot import com.android.server.pm.test.override.PackageManagerComponentLabelIconOverrideTest.Companion.Params.AppType import com.android.server.testutils.TestHandler import com.android.server.testutils.mock @@ -361,8 +362,8 @@ class PackageManagerComponentLabelIconOverrideTest { whenever(this.isCallerRecents(anyInt())) { false } } val mockAppsFilter: AppsFilterImpl = mockThrowOnUnmocked { - whenever(this.shouldFilterApplication(anyInt(), any(), - any(), anyInt())) { false } + whenever(this.shouldFilterApplication(any(), anyInt(), + any(), any(), anyInt())) { false } whenever(this.snapshot()) { this@mockThrowOnUnmocked } whenever(registerObserver(any())).thenCallRealMethod() } diff --git a/services/tests/mockingservicestests/src/com/android/server/pm/MockSystem.kt b/services/tests/mockingservicestests/src/com/android/server/pm/MockSystem.kt index 353c8e22cceb7..55745cd254a4b 100644 --- a/services/tests/mockingservicestests/src/com/android/server/pm/MockSystem.kt +++ b/services/tests/mockingservicestests/src/com/android/server/pm/MockSystem.kt @@ -69,6 +69,7 @@ import com.android.server.pm.permission.PermissionManagerServiceInternal import com.android.server.pm.pkg.parsing.ParsingPackage import com.android.server.pm.pkg.parsing.ParsingPackageUtils import com.android.server.pm.resolution.ComponentResolver +import com.android.server.pm.snapshot.PackageDataSnapshot import com.android.server.pm.verify.domain.DomainVerificationManagerInternal import com.android.server.sdksandbox.SdkSandboxManagerLocal import com.android.server.testutils.TestHandler @@ -329,7 +330,7 @@ class MockSystem(withSession: (StaticMockitoSessionBuilder) -> Unit = {}) { } whenever(mocks.injector.sharedLibrariesImpl) { mSharedLibraries } // everything visible by default - whenever(mocks.appsFilter.shouldFilterApplication( + whenever(mocks.appsFilter.shouldFilterApplication(any(PackageDataSnapshot::class.java), anyInt(), nullable(), nullable(), anyInt())) { false } val displayManager: DisplayManager = mock() diff --git a/services/tests/mockingservicestests/src/com/android/server/pm/SuspendPackageHelperTest.kt b/services/tests/mockingservicestests/src/com/android/server/pm/SuspendPackageHelperTest.kt index 3ba9ca591fb34..b9d6b2ccd3063 100644 --- a/services/tests/mockingservicestests/src/com/android/server/pm/SuspendPackageHelperTest.kt +++ b/services/tests/mockingservicestests/src/com/android/server/pm/SuspendPackageHelperTest.kt @@ -23,6 +23,7 @@ import android.os.PersistableBundle import android.util.ArrayMap import android.util.SparseArray import com.android.server.pm.pkg.PackageStateInternal +import com.android.server.pm.snapshot.PackageDataSnapshot import com.android.server.testutils.any import com.android.server.testutils.eq import com.android.server.testutils.nullable @@ -389,6 +390,7 @@ class SuspendPackageHelperTest : PackageHelperTestBase() { private fun mockAllowList(pkgSetting: PackageStateInternal, list: SparseArray?) { whenever(rule.mocks().appsFilter.getVisibilityAllowList( + any(PackageDataSnapshot::class.java), argThat { it?.packageName == pkgSetting.packageName }, any(IntArray::class.java), any() as ArrayMap )) diff --git a/services/tests/servicestests/src/com/android/server/pm/AppsFilterImplTest.java b/services/tests/servicestests/src/com/android/server/pm/AppsFilterImplTest.java index 3be2aacc75cb1..c43e6ab6658af 100644 --- a/services/tests/servicestests/src/com/android/server/pm/AppsFilterImplTest.java +++ b/services/tests/servicestests/src/com/android/server/pm/AppsFilterImplTest.java @@ -30,6 +30,7 @@ import android.annotation.Nullable; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManagerInternal; import android.content.pm.Signature; import android.content.pm.SigningDetails; import android.content.pm.UserInfo; @@ -53,6 +54,7 @@ import com.android.server.pm.pkg.component.ParsedInstrumentationImpl; import com.android.server.pm.pkg.component.ParsedIntentInfoImpl; import com.android.server.pm.pkg.component.ParsedProviderImpl; import com.android.server.pm.pkg.parsing.ParsingPackage; +import com.android.server.pm.snapshot.PackageDataSnapshot; import com.android.server.utils.WatchableTester; import org.junit.Before; @@ -99,9 +101,11 @@ public class AppsFilterImplTest { @Mock AppsFilterImpl.FeatureConfig mFeatureConfigMock; @Mock - AppsFilterImpl.StateProvider mStateProvider; + PackageDataSnapshot mSnapshot; @Mock Executor mMockExecutor; + @Mock + PackageManagerInternal mPmInternal; private ArrayMap mExisting = new ArrayMap<>(); private Collection mSharedUserSettings = new ArraySet<>(); @@ -201,12 +205,10 @@ public class AppsFilterImplTest { mExisting = new ArrayMap<>(); MockitoAnnotations.initMocks(this); - doAnswer(invocation -> { - ((AppsFilterImpl.StateProvider.CurrentStateCallback) invocation.getArgument(0)) - .currentState(mExisting, mSharedUserSettings, USER_INFO_LIST); - return new Object(); - }).when(mStateProvider) - .runWithState(any(AppsFilterImpl.StateProvider.CurrentStateCallback.class)); + when(mSnapshot.getPackageStates()).thenAnswer(x -> mExisting); + when(mSnapshot.getAllSharedUsers()).thenReturn(mSharedUserSettings); + when(mSnapshot.getUserInfos()).thenReturn(USER_INFO_LIST); + when(mPmInternal.snapshot()).thenReturn(mSnapshot); doAnswer(invocation -> { ((Runnable) invocation.getArgument(0)).run(); @@ -223,11 +225,11 @@ public class AppsFilterImplTest { @Test public void testSystemReadyPropogates() throws Exception { final AppsFilterImpl appsFilter = - new AppsFilterImpl(mStateProvider, mFeatureConfigMock, new String[]{}, false, null, + new AppsFilterImpl(mFeatureConfigMock, new String[]{}, false, null, mMockExecutor); final WatchableTester watcher = new WatchableTester(appsFilter, "onChange"); watcher.register(); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); watcher.verifyChangeReported("systemReady"); verify(mFeatureConfigMock).onSystemReady(); } @@ -235,13 +237,13 @@ public class AppsFilterImplTest { @Test public void testQueriesAction_FilterMatches() throws Exception { final AppsFilterImpl appsFilter = - new AppsFilterImpl(mStateProvider, mFeatureConfigMock, new String[]{}, false, null, + new AppsFilterImpl(mFeatureConfigMock, new String[]{}, false, null, mMockExecutor); final WatchableTester watcher = new WatchableTester(appsFilter, "onChange"); watcher.register(); simulateAddBasicAndroid(appsFilter); watcher.verifyChangeReported("addBasicAndroid"); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); watcher.verifyChangeReported("systemReady"); PackageSetting target = simulateAddPackage(appsFilter, @@ -251,14 +253,16 @@ public class AppsFilterImplTest { pkg("com.some.other.package", new Intent("TEST_ACTION")), DUMMY_CALLING_APPID); watcher.verifyChangeReported("add package"); - assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target, - SYSTEM_USER)); + assertFalse( + appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, calling, target, + SYSTEM_USER)); watcher.verifyNoChangeReported("shouldFilterAplication"); } + @Test public void testQueriesProtectedAction_FilterDoesNotMatch() throws Exception { final AppsFilterImpl appsFilter = - new AppsFilterImpl(mStateProvider, mFeatureConfigMock, new String[]{}, false, null, + new AppsFilterImpl(mFeatureConfigMock, new String[]{}, false, null, mMockExecutor); final WatchableTester watcher = new WatchableTester(appsFilter, "onChange"); watcher.register(); @@ -271,7 +275,7 @@ public class AppsFilterImplTest { simulateAddPackage(appsFilter, android, 1000, b -> b.setSigningDetails(frameworkSigningDetails)); watcher.verifyChangeReported("addPackage"); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); watcher.verifyChangeReported("systemReady"); final int activityUid = DUMMY_TARGET_APPID; @@ -292,14 +296,14 @@ public class AppsFilterImplTest { pkg("com.calling.wildcard", new Intent("*")), wildcardUid); watcher.verifyChangeReported("addPackage"); - assertFalse(appsFilter.shouldFilterApplication(callingUid, calling, targetActivity, - SYSTEM_USER)); - assertTrue(appsFilter.shouldFilterApplication(callingUid, calling, targetReceiver, - SYSTEM_USER)); + assertFalse(appsFilter.shouldFilterApplication(mSnapshot, callingUid, calling, + targetActivity, SYSTEM_USER)); + assertTrue(appsFilter.shouldFilterApplication(mSnapshot, callingUid, calling, + targetReceiver, SYSTEM_USER)); - assertFalse(appsFilter.shouldFilterApplication( + assertFalse(appsFilter.shouldFilterApplication(mSnapshot, wildcardUid, callingWildCard, targetActivity, SYSTEM_USER)); - assertTrue(appsFilter.shouldFilterApplication( + assertTrue(appsFilter.shouldFilterApplication(mSnapshot, wildcardUid, callingWildCard, targetReceiver, SYSTEM_USER)); watcher.verifyNoChangeReported("shouldFilterApplication"); } @@ -307,13 +311,13 @@ public class AppsFilterImplTest { @Test public void testQueriesProvider_FilterMatches() throws Exception { final AppsFilterImpl appsFilter = - new AppsFilterImpl(mStateProvider, mFeatureConfigMock, new String[]{}, false, null, + new AppsFilterImpl(mFeatureConfigMock, new String[]{}, false, null, mMockExecutor); final WatchableTester watcher = new WatchableTester(appsFilter, "onChange"); watcher.register(); simulateAddBasicAndroid(appsFilter); watcher.verifyChangeReported("addPackage"); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); watcher.verifyChangeReported("systemReady"); PackageSetting target = simulateAddPackage(appsFilter, @@ -324,19 +328,19 @@ public class AppsFilterImplTest { DUMMY_CALLING_APPID); watcher.verifyChangeReported("addPackage"); - assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target, - SYSTEM_USER)); + assertFalse(appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, calling, + target, SYSTEM_USER)); watcher.verifyNoChangeReported("shouldFilterApplication"); } @Test public void testOnUserUpdated_FilterMatches() throws Exception { final AppsFilterImpl appsFilter = - new AppsFilterImpl(mStateProvider, mFeatureConfigMock, new String[]{}, false, null, + new AppsFilterImpl(mFeatureConfigMock, new String[]{}, false, null, mMockExecutor); simulateAddBasicAndroid(appsFilter); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); PackageSetting target = simulateAddPackage(appsFilter, pkgWithProvider("com.some.package", "com.some.authority"), DUMMY_TARGET_APPID); @@ -346,41 +350,31 @@ public class AppsFilterImplTest { for (int subjectUserId : USER_ARRAY) { for (int otherUserId : USER_ARRAY) { - assertFalse(appsFilter.shouldFilterApplication( + assertFalse(appsFilter.shouldFilterApplication(mSnapshot, UserHandle.getUid(DUMMY_CALLING_APPID, subjectUserId), calling, target, otherUserId)); } } // adds new user - doAnswer(invocation -> { - ((AppsFilterImpl.StateProvider.CurrentStateCallback) invocation.getArgument(0)) - .currentState(mExisting, mSharedUserSettings, USER_INFO_LIST_WITH_ADDED); - return new Object(); - }).when(mStateProvider) - .runWithState(any(AppsFilterImpl.StateProvider.CurrentStateCallback.class)); - appsFilter.onUserCreated(ADDED_USER); + when(mSnapshot.getUserInfos()).thenReturn(USER_INFO_LIST_WITH_ADDED); + appsFilter.onUserCreated(mSnapshot, ADDED_USER); for (int subjectUserId : USER_ARRAY_WITH_ADDED) { for (int otherUserId : USER_ARRAY_WITH_ADDED) { - assertFalse(appsFilter.shouldFilterApplication( + assertFalse(appsFilter.shouldFilterApplication(mSnapshot, UserHandle.getUid(DUMMY_CALLING_APPID, subjectUserId), calling, target, otherUserId)); } } // delete user - doAnswer(invocation -> { - ((AppsFilterImpl.StateProvider.CurrentStateCallback) invocation.getArgument(0)) - .currentState(mExisting, mSharedUserSettings, USER_INFO_LIST); - return new Object(); - }).when(mStateProvider) - .runWithState(any(AppsFilterImpl.StateProvider.CurrentStateCallback.class)); + when(mSnapshot.getUserInfos()).thenReturn(USER_INFO_LIST); appsFilter.onUserDeleted(ADDED_USER); for (int subjectUserId : USER_ARRAY) { for (int otherUserId : USER_ARRAY) { - assertFalse(appsFilter.shouldFilterApplication( + assertFalse(appsFilter.shouldFilterApplication(mSnapshot, UserHandle.getUid(DUMMY_CALLING_APPID, subjectUserId), calling, target, otherUserId)); } @@ -390,13 +384,13 @@ public class AppsFilterImplTest { @Test public void testQueriesDifferentProvider_Filters() throws Exception { final AppsFilterImpl appsFilter = - new AppsFilterImpl(mStateProvider, mFeatureConfigMock, new String[]{}, false, null, + new AppsFilterImpl(mFeatureConfigMock, new String[]{}, false, null, mMockExecutor); final WatchableTester watcher = new WatchableTester(appsFilter, "onChange"); watcher.register(); simulateAddBasicAndroid(appsFilter); watcher.verifyChangeReported("addPackage"); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); watcher.verifyChangeReported("systemReady"); PackageSetting target = simulateAddPackage(appsFilter, @@ -407,18 +401,18 @@ public class AppsFilterImplTest { DUMMY_CALLING_APPID); watcher.verifyChangeReported("addPackage"); - assertTrue(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target, - SYSTEM_USER)); + assertTrue(appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, calling, + target, SYSTEM_USER)); watcher.verifyNoChangeReported("shouldFilterApplication"); } @Test public void testQueriesProviderWithSemiColon_FilterMatches() throws Exception { final AppsFilterImpl appsFilter = - new AppsFilterImpl(mStateProvider, mFeatureConfigMock, new String[]{}, false, null, + new AppsFilterImpl(mFeatureConfigMock, new String[]{}, false, null, mMockExecutor); simulateAddBasicAndroid(appsFilter); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); PackageSetting target = simulateAddPackage(appsFilter, pkgWithProvider("com.some.package", "com.some.authority;com.some.other.authority"), @@ -427,34 +421,34 @@ public class AppsFilterImplTest { pkgQueriesProvider("com.some.other.package", "com.some.authority"), DUMMY_CALLING_APPID); - assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target, - SYSTEM_USER)); + assertFalse(appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, calling, + target, SYSTEM_USER)); } @Test public void testQueriesAction_NoMatchingAction_Filters() throws Exception { final AppsFilterImpl appsFilter = - new AppsFilterImpl(mStateProvider, mFeatureConfigMock, new String[]{}, false, null, + new AppsFilterImpl(mFeatureConfigMock, new String[]{}, false, null, mMockExecutor); simulateAddBasicAndroid(appsFilter); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package"), DUMMY_TARGET_APPID); PackageSetting calling = simulateAddPackage(appsFilter, pkg("com.some.other.package", new Intent("TEST_ACTION")), DUMMY_CALLING_APPID); - assertTrue(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target, - SYSTEM_USER)); + assertTrue(appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, calling, + target, SYSTEM_USER)); } @Test public void testQueriesAction_NoMatchingActionFilterLowSdk_DoesntFilter() throws Exception { final AppsFilterImpl appsFilter = - new AppsFilterImpl(mStateProvider, mFeatureConfigMock, new String[]{}, false, null, + new AppsFilterImpl(mFeatureConfigMock, new String[]{}, false, null, mMockExecutor); simulateAddBasicAndroid(appsFilter); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package"), DUMMY_TARGET_APPID); @@ -465,35 +459,37 @@ public class AppsFilterImplTest { DUMMY_CALLING_APPID); - assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target, - SYSTEM_USER)); + assertFalse( + appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, calling, target, + SYSTEM_USER)); } @Test public void testNoQueries_Filters() throws Exception { final AppsFilterImpl appsFilter = - new AppsFilterImpl(mStateProvider, mFeatureConfigMock, new String[]{}, false, null, + new AppsFilterImpl(mFeatureConfigMock, new String[]{}, false, null, mMockExecutor); simulateAddBasicAndroid(appsFilter); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package"), DUMMY_TARGET_APPID); PackageSetting calling = simulateAddPackage(appsFilter, pkg("com.some.other.package"), DUMMY_CALLING_APPID); - assertTrue(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target, - SYSTEM_USER)); + assertTrue( + appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, calling, target, + SYSTEM_USER)); } @Test public void testNoUsesLibrary_Filters() throws Exception { - final AppsFilterImpl appsFilter = new AppsFilterImpl(mStateProvider, mFeatureConfigMock, + final AppsFilterImpl appsFilter = new AppsFilterImpl(mFeatureConfigMock, new String[]{}, /* systemAppsQueryable */ false, /* overlayProvider */ null, mMockExecutor); simulateAddBasicAndroid(appsFilter); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); final Signature mockSignature = Mockito.mock(Signature.class); final SigningDetails mockSigningDetails = new SigningDetails( @@ -508,18 +504,19 @@ public class AppsFilterImplTest { final PackageSetting calling = simulateAddPackage(appsFilter, pkg("com.some.other.package"), DUMMY_CALLING_APPID); - assertTrue(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target, - SYSTEM_USER)); + assertTrue( + appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, calling, target, + SYSTEM_USER)); } @Test public void testUsesLibrary_DoesntFilter() throws Exception { - final AppsFilterImpl appsFilter = new AppsFilterImpl(mStateProvider, mFeatureConfigMock, + final AppsFilterImpl appsFilter = new AppsFilterImpl(mFeatureConfigMock, new String[]{}, /* systemAppsQueryable */ false, /* overlayProvider */ null, mMockExecutor); simulateAddBasicAndroid(appsFilter); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); final Signature mockSignature = Mockito.mock(Signature.class); final SigningDetails mockSigningDetails = new SigningDetails( @@ -535,18 +532,19 @@ public class AppsFilterImplTest { pkg("com.some.other.package").addUsesLibrary("com.some.shared_library"), DUMMY_CALLING_APPID); - assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target, - SYSTEM_USER)); + assertFalse( + appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, calling, target, + SYSTEM_USER)); } @Test public void testUsesOptionalLibrary_DoesntFilter() throws Exception { - final AppsFilterImpl appsFilter = new AppsFilterImpl(mStateProvider, mFeatureConfigMock, + final AppsFilterImpl appsFilter = new AppsFilterImpl(mFeatureConfigMock, new String[]{}, /* systemAppsQueryable */ false, /* overlayProvider */ null, mMockExecutor); simulateAddBasicAndroid(appsFilter); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); final Signature mockSignature = Mockito.mock(Signature.class); final SigningDetails mockSigningDetails = new SigningDetails( @@ -562,18 +560,19 @@ public class AppsFilterImplTest { pkg("com.some.other.package").addUsesOptionalLibrary("com.some.shared_library"), DUMMY_CALLING_APPID); - assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target, - SYSTEM_USER)); + assertFalse( + appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, calling, target, + SYSTEM_USER)); } @Test public void testUsesLibrary_ShareUid_DoesntFilter() throws Exception { - final AppsFilterImpl appsFilter = new AppsFilterImpl(mStateProvider, mFeatureConfigMock, + final AppsFilterImpl appsFilter = new AppsFilterImpl(mFeatureConfigMock, new String[]{}, /* systemAppsQueryable */ false, /* overlayProvider */ null, mMockExecutor); simulateAddBasicAndroid(appsFilter); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); final Signature mockSignature = Mockito.mock(Signature.class); final SigningDetails mockSigningDetails = new SigningDetails( @@ -589,22 +588,23 @@ public class AppsFilterImplTest { pkg("com.some.other.package_a").setSharedUserId("com.some.uid"), DUMMY_CALLING_APPID); simulateAddPackage(appsFilter, pkg("com.some.other.package_b") - .setSharedUserId("com.some.uid").addUsesLibrary("com.some.shared_library"), + .setSharedUserId("com.some.uid").addUsesLibrary("com.some.shared_library"), DUMMY_CALLING_APPID); // Although package_a doesn't use library, it should be granted visibility. It's because // package_a shares userId with package_b, and package_b uses that shared library. - assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target, - SYSTEM_USER)); + assertFalse( + appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, calling, target, + SYSTEM_USER)); } @Test public void testForceQueryable_SystemDoesntFilter() throws Exception { final AppsFilterImpl appsFilter = - new AppsFilterImpl(mStateProvider, mFeatureConfigMock, new String[]{}, false, null, + new AppsFilterImpl(mFeatureConfigMock, new String[]{}, false, null, mMockExecutor); simulateAddBasicAndroid(appsFilter); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package").setForceQueryable(true), DUMMY_TARGET_APPID, @@ -612,36 +612,38 @@ public class AppsFilterImplTest { PackageSetting calling = simulateAddPackage(appsFilter, pkg("com.some.other.package"), DUMMY_CALLING_APPID); - assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target, - SYSTEM_USER)); + assertFalse( + appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, calling, target, + SYSTEM_USER)); } @Test public void testForceQueryable_NonSystemFilters() throws Exception { final AppsFilterImpl appsFilter = - new AppsFilterImpl(mStateProvider, mFeatureConfigMock, new String[]{}, false, null, + new AppsFilterImpl(mFeatureConfigMock, new String[]{}, false, null, mMockExecutor); simulateAddBasicAndroid(appsFilter); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package").setForceQueryable(true), DUMMY_TARGET_APPID); PackageSetting calling = simulateAddPackage(appsFilter, pkg("com.some.other.package"), DUMMY_CALLING_APPID); - assertTrue(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target, - SYSTEM_USER)); + assertTrue( + appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, calling, target, + SYSTEM_USER)); } @Test public void testForceQueryableByDevice_SystemCaller_DoesntFilter() throws Exception { final AppsFilterImpl appsFilter = - new AppsFilterImpl(mStateProvider, mFeatureConfigMock, + new AppsFilterImpl(mFeatureConfigMock, new String[]{"com.some.package"}, false, null, mMockExecutor); simulateAddBasicAndroid(appsFilter); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package"), DUMMY_TARGET_APPID, @@ -649,17 +651,18 @@ public class AppsFilterImplTest { PackageSetting calling = simulateAddPackage(appsFilter, pkg("com.some.other.package"), DUMMY_CALLING_APPID); - assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target, - SYSTEM_USER)); + assertFalse( + appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, calling, target, + SYSTEM_USER)); } @Test public void testSystemSignedTarget_DoesntFilter() throws CertificateException { final AppsFilterImpl appsFilter = - new AppsFilterImpl(mStateProvider, mFeatureConfigMock, new String[]{}, false, null, + new AppsFilterImpl(mFeatureConfigMock, new String[]{}, false, null, mMockExecutor); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); final Signature frameworkSignature = Mockito.mock(Signature.class); final SigningDetails frameworkSigningDetails = @@ -679,36 +682,38 @@ public class AppsFilterImplTest { pkg("com.some.other.package"), DUMMY_CALLING_APPID, b -> b.setSigningDetails(otherSigningDetails)); - assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target, - SYSTEM_USER)); + assertFalse( + appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, calling, target, + SYSTEM_USER)); } @Test public void testForceQueryableByDevice_NonSystemCaller_Filters() throws Exception { final AppsFilterImpl appsFilter = - new AppsFilterImpl(mStateProvider, mFeatureConfigMock, + new AppsFilterImpl(mFeatureConfigMock, new String[]{"com.some.package"}, false, null, mMockExecutor); simulateAddBasicAndroid(appsFilter); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package"), DUMMY_TARGET_APPID); PackageSetting calling = simulateAddPackage(appsFilter, pkg("com.some.other.package"), DUMMY_CALLING_APPID); - assertTrue(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target, - SYSTEM_USER)); + assertTrue( + appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, calling, target, + SYSTEM_USER)); } @Test public void testSystemQueryable_DoesntFilter() throws Exception { final AppsFilterImpl appsFilter = - new AppsFilterImpl(mStateProvider, mFeatureConfigMock, new String[]{}, + new AppsFilterImpl(mFeatureConfigMock, new String[]{}, true /* system force queryable */, null, mMockExecutor); simulateAddBasicAndroid(appsFilter); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package"), DUMMY_TARGET_APPID, @@ -716,25 +721,27 @@ public class AppsFilterImplTest { PackageSetting calling = simulateAddPackage(appsFilter, pkg("com.some.other.package"), DUMMY_CALLING_APPID); - assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target, - SYSTEM_USER)); + assertFalse( + appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, calling, target, + SYSTEM_USER)); } @Test public void testQueriesPackage_DoesntFilter() throws Exception { final AppsFilterImpl appsFilter = - new AppsFilterImpl(mStateProvider, mFeatureConfigMock, new String[]{}, false, null, + new AppsFilterImpl(mFeatureConfigMock, new String[]{}, false, null, mMockExecutor); simulateAddBasicAndroid(appsFilter); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package"), DUMMY_TARGET_APPID); PackageSetting calling = simulateAddPackage(appsFilter, pkg("com.some.other.package", "com.some.package"), DUMMY_CALLING_APPID); - assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target, - SYSTEM_USER)); + assertFalse( + appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, calling, target, + SYSTEM_USER)); } @Test @@ -742,49 +749,52 @@ public class AppsFilterImplTest { when(mFeatureConfigMock.packageIsEnabled(any(AndroidPackage.class))) .thenReturn(false); final AppsFilterImpl appsFilter = - new AppsFilterImpl(mStateProvider, mFeatureConfigMock, new String[]{}, false, null, + new AppsFilterImpl(mFeatureConfigMock, new String[]{}, false, null, mMockExecutor); simulateAddBasicAndroid(appsFilter); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); PackageSetting target = simulateAddPackage( appsFilter, pkg("com.some.package"), DUMMY_TARGET_APPID); PackageSetting calling = simulateAddPackage( appsFilter, pkg("com.some.other.package"), DUMMY_CALLING_APPID); - assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target, - SYSTEM_USER)); + assertFalse( + appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, calling, target, + SYSTEM_USER)); } @Test public void testSystemUid_DoesntFilter() throws Exception { final AppsFilterImpl appsFilter = - new AppsFilterImpl(mStateProvider, mFeatureConfigMock, new String[]{}, false, null, + new AppsFilterImpl(mFeatureConfigMock, new String[]{}, false, null, mMockExecutor); simulateAddBasicAndroid(appsFilter); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package"), DUMMY_TARGET_APPID); - assertFalse(appsFilter.shouldFilterApplication(SYSTEM_USER, null, target, SYSTEM_USER)); - assertFalse(appsFilter.shouldFilterApplication(Process.FIRST_APPLICATION_UID - 1, - null, target, SYSTEM_USER)); + assertFalse(appsFilter.shouldFilterApplication(mSnapshot, SYSTEM_USER, null, target, + SYSTEM_USER)); + assertFalse(appsFilter.shouldFilterApplication(mSnapshot, + Process.FIRST_APPLICATION_UID - 1, null, target, SYSTEM_USER)); } @Test public void testSystemUidSecondaryUser_DoesntFilter() throws Exception { final AppsFilterImpl appsFilter = - new AppsFilterImpl(mStateProvider, mFeatureConfigMock, new String[]{}, false, null, + new AppsFilterImpl(mFeatureConfigMock, new String[]{}, false, null, mMockExecutor); simulateAddBasicAndroid(appsFilter); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package"), DUMMY_TARGET_APPID); - assertFalse(appsFilter.shouldFilterApplication(0, null, target, SECONDARY_USER)); - assertFalse(appsFilter.shouldFilterApplication( + assertFalse(appsFilter.shouldFilterApplication(mSnapshot, 0, null, target, + SECONDARY_USER)); + assertFalse(appsFilter.shouldFilterApplication(mSnapshot, UserHandle.getUid(SECONDARY_USER, Process.FIRST_APPLICATION_UID - 1), null, target, SECONDARY_USER)); } @@ -792,25 +802,25 @@ public class AppsFilterImplTest { @Test public void testNonSystemUid_NoCallingSetting_Filters() throws Exception { final AppsFilterImpl appsFilter = - new AppsFilterImpl(mStateProvider, mFeatureConfigMock, new String[]{}, false, null, + new AppsFilterImpl(mFeatureConfigMock, new String[]{}, false, null, mMockExecutor); simulateAddBasicAndroid(appsFilter); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package"), DUMMY_TARGET_APPID); - assertTrue(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, null, target, + assertTrue(appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, null, target, SYSTEM_USER)); } @Test public void testNoTargetPackage_filters() throws Exception { final AppsFilterImpl appsFilter = - new AppsFilterImpl(mStateProvider, mFeatureConfigMock, new String[]{}, false, null, + new AppsFilterImpl(mFeatureConfigMock, new String[]{}, false, null, mMockExecutor); simulateAddBasicAndroid(appsFilter); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); PackageSetting target = new PackageSettingBuilder() .setAppId(DUMMY_TARGET_APPID) @@ -821,8 +831,9 @@ public class AppsFilterImplTest { PackageSetting calling = simulateAddPackage(appsFilter, pkg("com.some.other.package", new Intent("TEST_ACTION")), DUMMY_CALLING_APPID); - assertTrue(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target, - SYSTEM_USER)); + assertTrue( + appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, calling, target, + SYSTEM_USER)); } @Test @@ -838,7 +849,6 @@ public class AppsFilterImplTest { ParsingPackage actor = pkg("com.some.package.actor"); final AppsFilterImpl appsFilter = new AppsFilterImpl( - mStateProvider, mFeatureConfigMock, new String[]{}, false, @@ -868,7 +878,7 @@ public class AppsFilterImplTest { }, mMockExecutor); simulateAddBasicAndroid(appsFilter); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); // Packages must be added in actor -> overlay -> target order so that the implicit // visibility of the actor into the overlay can be tested @@ -878,33 +888,33 @@ public class AppsFilterImplTest { simulateAddPackage(appsFilter, overlay, DUMMY_OVERLAY_APPID); // Actor can not see overlay (yet) - assertTrue(appsFilter.shouldFilterApplication(DUMMY_ACTOR_APPID, actorSetting, + assertTrue(appsFilter.shouldFilterApplication(mSnapshot, DUMMY_ACTOR_APPID, actorSetting, overlaySetting, SYSTEM_USER)); PackageSetting targetSetting = simulateAddPackage(appsFilter, target, DUMMY_TARGET_APPID); // Actor can see both target and overlay - assertFalse(appsFilter.shouldFilterApplication(DUMMY_ACTOR_APPID, actorSetting, + assertFalse(appsFilter.shouldFilterApplication(mSnapshot, DUMMY_ACTOR_APPID, actorSetting, targetSetting, SYSTEM_USER)); - assertFalse(appsFilter.shouldFilterApplication(DUMMY_ACTOR_APPID, actorSetting, + assertFalse(appsFilter.shouldFilterApplication(mSnapshot, DUMMY_ACTOR_APPID, actorSetting, overlaySetting, SYSTEM_USER)); // But target/overlay can't see each other - assertTrue(appsFilter.shouldFilterApplication(DUMMY_TARGET_APPID, targetSetting, + assertTrue(appsFilter.shouldFilterApplication(mSnapshot, DUMMY_TARGET_APPID, targetSetting, overlaySetting, SYSTEM_USER)); - assertTrue(appsFilter.shouldFilterApplication(DUMMY_OVERLAY_APPID, overlaySetting, - targetSetting, SYSTEM_USER)); + assertTrue(appsFilter.shouldFilterApplication(mSnapshot, DUMMY_OVERLAY_APPID, + overlaySetting, targetSetting, SYSTEM_USER)); // And can't see the actor - assertTrue(appsFilter.shouldFilterApplication(DUMMY_TARGET_APPID, targetSetting, - actorSetting, SYSTEM_USER)); - assertTrue(appsFilter.shouldFilterApplication(DUMMY_OVERLAY_APPID, overlaySetting, + assertTrue(appsFilter.shouldFilterApplication(mSnapshot, DUMMY_TARGET_APPID, targetSetting, actorSetting, SYSTEM_USER)); + assertTrue(appsFilter.shouldFilterApplication(mSnapshot, DUMMY_OVERLAY_APPID, + overlaySetting, actorSetting, SYSTEM_USER)); - appsFilter.removePackage(targetSetting, false /* isReplace */); + appsFilter.removePackage(mSnapshot, targetSetting, false /* isReplace */); // Actor loses visibility to the overlay via removal of the target - assertTrue(appsFilter.shouldFilterApplication(DUMMY_ACTOR_APPID, actorSetting, + assertTrue(appsFilter.shouldFilterApplication(mSnapshot, DUMMY_ACTOR_APPID, actorSetting, overlaySetting, SYSTEM_USER)); } @@ -928,7 +938,6 @@ public class AppsFilterImplTest { null /*settingBuilder*/); final AppsFilterImpl appsFilter = new AppsFilterImpl( - mStateProvider, mFeatureConfigMock, new String[]{}, false, @@ -959,7 +968,7 @@ public class AppsFilterImplTest { }, mMockExecutor); simulateAddBasicAndroid(appsFilter); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); PackageSetting targetSetting = simulateAddPackage(appsFilter, target, DUMMY_TARGET_APPID); SharedUserSetting actorSharedSetting = new SharedUserSetting("actorSharedUser", @@ -971,19 +980,19 @@ public class AppsFilterImplTest { simulateAddPackage(ps2, appsFilter, actorSharedSetting); // actorTwo can see both target and overlay - assertFalse(appsFilter.shouldFilterApplication(DUMMY_ACTOR_APPID, actorSharedSetting, - targetSetting, SYSTEM_USER)); - assertFalse(appsFilter.shouldFilterApplication(DUMMY_ACTOR_APPID, actorSharedSetting, - overlaySetting, SYSTEM_USER)); + assertFalse(appsFilter.shouldFilterApplication(mSnapshot, DUMMY_ACTOR_APPID, + actorSharedSetting, targetSetting, SYSTEM_USER)); + assertFalse(appsFilter.shouldFilterApplication(mSnapshot, DUMMY_ACTOR_APPID, + actorSharedSetting, overlaySetting, SYSTEM_USER)); } @Test public void testInitiatingApp_DoesntFilter() throws Exception { final AppsFilterImpl appsFilter = - new AppsFilterImpl(mStateProvider, mFeatureConfigMock, new String[]{}, false, null, + new AppsFilterImpl(mFeatureConfigMock, new String[]{}, false, null, mMockExecutor); simulateAddBasicAndroid(appsFilter); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package"), DUMMY_TARGET_APPID); @@ -991,17 +1000,18 @@ public class AppsFilterImplTest { DUMMY_CALLING_APPID, withInstallSource(target.getPackageName(), null, null, null, false)); - assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target, - SYSTEM_USER)); + assertFalse( + appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, calling, target, + SYSTEM_USER)); } @Test public void testUninstalledInitiatingApp_Filters() throws Exception { final AppsFilterImpl appsFilter = - new AppsFilterImpl(mStateProvider, mFeatureConfigMock, new String[]{}, false, null, + new AppsFilterImpl(mFeatureConfigMock, new String[]{}, false, null, mMockExecutor); simulateAddBasicAndroid(appsFilter); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package"), DUMMY_TARGET_APPID); @@ -1009,20 +1019,21 @@ public class AppsFilterImplTest { DUMMY_CALLING_APPID, withInstallSource(target.getPackageName(), null, null, null, true)); - assertTrue(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target, - SYSTEM_USER)); + assertTrue( + appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, calling, target, + SYSTEM_USER)); } @Test public void testOriginatingApp_Filters() throws Exception { final AppsFilterImpl appsFilter = - new AppsFilterImpl(mStateProvider, mFeatureConfigMock, new String[]{}, false, null, + new AppsFilterImpl(mFeatureConfigMock, new String[]{}, false, null, mMockExecutor); final WatchableTester watcher = new WatchableTester(appsFilter, "onChange"); watcher.register(); simulateAddBasicAndroid(appsFilter); watcher.verifyChangeReported("addBasicAndroid"); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); watcher.verifyChangeReported("systemReady"); PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package"), @@ -1033,21 +1044,22 @@ public class AppsFilterImplTest { false)); watcher.verifyChangeReported("add package"); - assertTrue(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target, - SYSTEM_USER)); + assertTrue( + appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, calling, target, + SYSTEM_USER)); watcher.verifyNoChangeReported("shouldFilterAplication"); } @Test public void testInstallingApp_DoesntFilter() throws Exception { final AppsFilterImpl appsFilter = - new AppsFilterImpl(mStateProvider, mFeatureConfigMock, new String[]{}, false, null, + new AppsFilterImpl(mFeatureConfigMock, new String[]{}, false, null, mMockExecutor); final WatchableTester watcher = new WatchableTester(appsFilter, "onChange"); watcher.register(); simulateAddBasicAndroid(appsFilter); watcher.verifyChangeReported("addBasicAndroid"); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); watcher.verifyChangeReported("systemReady"); PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package"), @@ -1058,21 +1070,22 @@ public class AppsFilterImplTest { false)); watcher.verifyChangeReported("add package"); - assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target, - SYSTEM_USER)); + assertFalse( + appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, calling, target, + SYSTEM_USER)); watcher.verifyNoChangeReported("shouldFilterAplication"); } @Test public void testInstrumentation_DoesntFilter() throws Exception { final AppsFilterImpl appsFilter = - new AppsFilterImpl(mStateProvider, mFeatureConfigMock, new String[]{}, false, null, + new AppsFilterImpl(mFeatureConfigMock, new String[]{}, false, null, mMockExecutor); final WatchableTester watcher = new WatchableTester(appsFilter, "onChange"); watcher.register(); simulateAddBasicAndroid(appsFilter); watcher.verifyChangeReported("addBasicAndroid"); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); watcher.verifyChangeReported("systemReady"); PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package"), @@ -1084,24 +1097,24 @@ public class AppsFilterImplTest { watcher.verifyChangeReported("add package"); assertFalse( - appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, instrumentation, target, - SYSTEM_USER)); + appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, instrumentation, + target, SYSTEM_USER)); assertFalse( - appsFilter.shouldFilterApplication(DUMMY_TARGET_APPID, target, instrumentation, - SYSTEM_USER)); + appsFilter.shouldFilterApplication(mSnapshot, DUMMY_TARGET_APPID, target, + instrumentation, SYSTEM_USER)); watcher.verifyNoChangeReported("shouldFilterAplication"); } @Test public void testWhoCanSee() throws Exception { final AppsFilterImpl appsFilter = - new AppsFilterImpl(mStateProvider, mFeatureConfigMock, new String[]{}, false, null, + new AppsFilterImpl(mFeatureConfigMock, new String[]{}, false, null, mMockExecutor); final WatchableTester watcher = new WatchableTester(appsFilter, "onChange"); watcher.register(); simulateAddBasicAndroid(appsFilter); watcher.verifyChangeReported("addBasicAndroid"); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); watcher.verifyChangeReported("systemReady"); final int systemAppId = Process.FIRST_APPLICATION_UID - 1; @@ -1123,14 +1136,14 @@ public class AppsFilterImplTest { watcher.verifyChangeReported("add package"); final SparseArray systemFilter = - appsFilter.getVisibilityAllowList(system, USER_ARRAY, mExisting); + appsFilter.getVisibilityAllowList(mSnapshot, system, USER_ARRAY, mExisting); watcher.verifyNoChangeReported("getVisibility"); assertThat(toList(systemFilter.get(SYSTEM_USER)), contains(seesNothingAppId, hasProviderAppId, queriesProviderAppId)); watcher.verifyNoChangeReported("getVisibility"); final SparseArray seesNothingFilter = - appsFilter.getVisibilityAllowList(seesNothing, USER_ARRAY, mExisting); + appsFilter.getVisibilityAllowList(mSnapshot, seesNothing, USER_ARRAY, mExisting); watcher.verifyNoChangeReported("getVisibility"); assertThat(toList(seesNothingFilter.get(SYSTEM_USER)), contains(seesNothingAppId)); @@ -1140,12 +1153,13 @@ public class AppsFilterImplTest { watcher.verifyNoChangeReported("getVisibility"); final SparseArray hasProviderFilter = - appsFilter.getVisibilityAllowList(hasProvider, USER_ARRAY, mExisting); + appsFilter.getVisibilityAllowList(mSnapshot, hasProvider, USER_ARRAY, mExisting); assertThat(toList(hasProviderFilter.get(SYSTEM_USER)), contains(hasProviderAppId, queriesProviderAppId)); SparseArray queriesProviderFilter = - appsFilter.getVisibilityAllowList(queriesProvider, USER_ARRAY, mExisting); + appsFilter.getVisibilityAllowList(mSnapshot, queriesProvider, USER_ARRAY, + mExisting); watcher.verifyNoChangeReported("getVisibility"); assertThat(toList(queriesProviderFilter.get(SYSTEM_USER)), contains(queriesProviderAppId)); @@ -1158,7 +1172,8 @@ public class AppsFilterImplTest { // ensure implicit access is included in the filter queriesProviderFilter = - appsFilter.getVisibilityAllowList(queriesProvider, USER_ARRAY, mExisting); + appsFilter.getVisibilityAllowList(mSnapshot, queriesProvider, USER_ARRAY, + mExisting); watcher.verifyNoChangeReported("getVisibility"); assertThat(toList(queriesProviderFilter.get(SYSTEM_USER)), contains(hasProviderAppId, queriesProviderAppId)); @@ -1168,13 +1183,13 @@ public class AppsFilterImplTest { @Test public void testOnChangeReport() throws Exception { final AppsFilterImpl appsFilter = - new AppsFilterImpl(mStateProvider, mFeatureConfigMock, new String[]{}, false, null, + new AppsFilterImpl(mFeatureConfigMock, new String[]{}, false, null, mMockExecutor); final WatchableTester watcher = new WatchableTester(appsFilter, "onChange"); watcher.register(); simulateAddBasicAndroid(appsFilter); watcher.verifyChangeReported("addBasic"); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); watcher.verifyChangeReported("systemReady"); final int systemAppId = Process.FIRST_APPLICATION_UID - 1; @@ -1196,13 +1211,13 @@ public class AppsFilterImplTest { watcher.verifyChangeReported("addPackage"); final SparseArray systemFilter = - appsFilter.getVisibilityAllowList(system, USER_ARRAY, mExisting); + appsFilter.getVisibilityAllowList(mSnapshot, system, USER_ARRAY, mExisting); assertThat(toList(systemFilter.get(SYSTEM_USER)), contains(seesNothingAppId, hasProviderAppId, queriesProviderAppId)); watcher.verifyNoChangeReported("get"); final SparseArray seesNothingFilter = - appsFilter.getVisibilityAllowList(seesNothing, USER_ARRAY, mExisting); + appsFilter.getVisibilityAllowList(mSnapshot, seesNothing, USER_ARRAY, mExisting); assertThat(toList(seesNothingFilter.get(SYSTEM_USER)), contains(seesNothingAppId)); assertThat(toList(seesNothingFilter.get(SECONDARY_USER)), @@ -1210,13 +1225,14 @@ public class AppsFilterImplTest { watcher.verifyNoChangeReported("get"); final SparseArray hasProviderFilter = - appsFilter.getVisibilityAllowList(hasProvider, USER_ARRAY, mExisting); + appsFilter.getVisibilityAllowList(mSnapshot, hasProvider, USER_ARRAY, mExisting); assertThat(toList(hasProviderFilter.get(SYSTEM_USER)), contains(hasProviderAppId, queriesProviderAppId)); watcher.verifyNoChangeReported("get"); SparseArray queriesProviderFilter = - appsFilter.getVisibilityAllowList(queriesProvider, USER_ARRAY, mExisting); + appsFilter.getVisibilityAllowList(mSnapshot, queriesProvider, USER_ARRAY, + mExisting); assertThat(toList(queriesProviderFilter.get(SYSTEM_USER)), contains(queriesProviderAppId)); watcher.verifyNoChangeReported("get"); @@ -1228,23 +1244,24 @@ public class AppsFilterImplTest { // ensure implicit access is included in the filter queriesProviderFilter = - appsFilter.getVisibilityAllowList(queriesProvider, USER_ARRAY, mExisting); + appsFilter.getVisibilityAllowList(mSnapshot, queriesProvider, USER_ARRAY, + mExisting); assertThat(toList(queriesProviderFilter.get(SYSTEM_USER)), contains(hasProviderAppId, queriesProviderAppId)); watcher.verifyNoChangeReported("get"); // remove a package - appsFilter.removePackage(seesNothing, false /* isReplace */); + appsFilter.removePackage(mSnapshot, seesNothing, false /* isReplace */); watcher.verifyChangeReported("removePackage"); } @Test public void testOnChangeReportedFilter() throws Exception { final AppsFilterImpl appsFilter = - new AppsFilterImpl(mStateProvider, mFeatureConfigMock, new String[]{}, false, null, + new AppsFilterImpl(mFeatureConfigMock, new String[]{}, false, null, mMockExecutor); simulateAddBasicAndroid(appsFilter); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); final WatchableTester watcher = new WatchableTester(appsFilter, "onChange filter"); watcher.register(); @@ -1256,21 +1273,21 @@ public class AppsFilterImplTest { watcher.verifyChangeReported("addPackage"); assertFalse( - appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, instrumentation, target, - SYSTEM_USER)); + appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, instrumentation, + target, SYSTEM_USER)); assertFalse( - appsFilter.shouldFilterApplication(DUMMY_TARGET_APPID, target, instrumentation, - SYSTEM_USER)); + appsFilter.shouldFilterApplication(mSnapshot, DUMMY_TARGET_APPID, target, + instrumentation, SYSTEM_USER)); watcher.verifyNoChangeReported("shouldFilterApplication"); } @Test public void testAppsFilterRead() throws Exception { final AppsFilterImpl appsFilter = - new AppsFilterImpl(mStateProvider, mFeatureConfigMock, new String[]{}, false, null, + new AppsFilterImpl(mFeatureConfigMock, new String[]{}, false, null, mMockExecutor); simulateAddBasicAndroid(appsFilter); - appsFilter.onSystemReady(); + appsFilter.onSystemReady(mPmInternal); PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package"), DUMMY_TARGET_APPID); @@ -1288,25 +1305,29 @@ public class AppsFilterImplTest { AppsFilterSnapshot snapshot = appsFilter.snapshot(); assertFalse( - snapshot.shouldFilterApplication(DUMMY_CALLING_APPID, instrumentation, target, + snapshot.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, instrumentation, + target, SYSTEM_USER)); assertFalse( - snapshot.shouldFilterApplication(DUMMY_TARGET_APPID, target, instrumentation, + snapshot.shouldFilterApplication(mSnapshot, DUMMY_TARGET_APPID, target, + instrumentation, SYSTEM_USER)); SparseArray queriesProviderFilter = - snapshot.getVisibilityAllowList(queriesProvider, USER_ARRAY, mExisting); + snapshot.getVisibilityAllowList(mSnapshot, queriesProvider, USER_ARRAY, mExisting); assertThat(toList(queriesProviderFilter.get(SYSTEM_USER)), contains(queriesProviderAppId)); assertTrue(snapshot.canQueryPackage(instrumentation.getPkg(), target.getPackageName())); // New changes don't affect the snapshot - appsFilter.removePackage(target, false); + appsFilter.removePackage(mSnapshot, target, false); assertTrue( - appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, instrumentation, target, + appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, instrumentation, + target, SYSTEM_USER)); assertFalse( - snapshot.shouldFilterApplication(DUMMY_CALLING_APPID, instrumentation, target, + snapshot.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, instrumentation, + target, SYSTEM_USER)); } @@ -1343,7 +1364,7 @@ public class AppsFilterImplTest { } private PackageSetting simulateAddPackage(AppsFilterImpl filter, - ParsingPackage newPkgBuilder, int appId, @Nullable WithSettingBuilder action, + ParsingPackage newPkgBuilder, int appId, @Nullable WithSettingBuilder action, @Nullable SharedUserSetting sharedUserSetting) { final PackageSetting setting = getPackageSettingFromParsingPackage(newPkgBuilder, appId, action); @@ -1373,7 +1394,7 @@ public class AppsFilterImplTest { setting.setSharedUserAppId(sharedUserSetting.mAppId); mSharedUserSettings.add(sharedUserSetting); } - filter.addPackage(setting); + filter.addPackage(mSnapshot, setting); } private WithSettingBuilder withInstallSource(String initiatingPackageName,