diff --git a/services/core/java/com/android/server/pm/AppsFilterBase.java b/services/core/java/com/android/server/pm/AppsFilterBase.java index 7004c73631224..e7bcb0aa13c8b 100644 --- a/services/core/java/com/android/server/pm/AppsFilterBase.java +++ b/services/core/java/com/android/server/pm/AppsFilterBase.java @@ -173,7 +173,7 @@ public abstract class AppsFilterBase implements AppsFilterSnapshot { * {@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. + * initial scam and is empty until {@link #mCacheReady} is true. */ @NonNull @Watched @@ -181,7 +181,7 @@ public abstract class AppsFilterBase implements AppsFilterSnapshot { @NonNull protected SnapshotCache mShouldFilterCacheSnapshot; - protected volatile boolean mSystemReady = false; + protected volatile boolean mCacheReady = false; protected boolean isForceQueryable(int callingAppId) { return mForceQueryable.contains(callingAppId); @@ -312,7 +312,7 @@ public abstract class AppsFilterBase implements AppsFilterSnapshot { || callingAppId == targetPkgSetting.getAppId()) { return false; } - if (mSystemReady) { // use cache + if (mCacheReady) { // use cache if (!shouldFilterApplicationUsingCache(callingUid, targetPkgSetting.getAppId(), userId)) { diff --git a/services/core/java/com/android/server/pm/AppsFilterImpl.java b/services/core/java/com/android/server/pm/AppsFilterImpl.java index 952711db17358..c817e24d3b821 100644 --- a/services/core/java/com/android/server/pm/AppsFilterImpl.java +++ b/services/core/java/com/android/server/pm/AppsFilterImpl.java @@ -404,7 +404,8 @@ public final class AppsFilterImpl extends AppsFilterLocked implements Watchable, + recipientUid + " -> " + visibleUid); } - if (mSystemReady) { + // TODO(b/231528435): invalidate cache instead of locking. + if (true/*mCacheReady*/) { synchronized (mCacheLock) { // update the cache in a one-off manner since we've got all the information we // need. @@ -420,7 +421,6 @@ public final class AppsFilterImpl extends AppsFilterLocked implements Watchable, mFeatureConfig.onSystemReady(); updateEntireShouldFilterCacheAsync(pmInternal); - mSystemReady = true; } /** @@ -444,7 +444,8 @@ public final class AppsFilterImpl extends AppsFilterLocked implements Watchable, final UserInfo[] users = snapshot.getUserInfos(); final ArraySet additionalChangedPackages = addPackageInternal(newPkgSetting, settings); - if (mSystemReady) { + // TODO(b/231528435): invalidate cache instead of locking. + if (true/*mCacheReady*/) { synchronized (mCacheLock) { updateShouldFilterCacheForPackage(snapshot, null, newPkgSetting, settings, users, USER_ALL, settings.size()); @@ -586,7 +587,7 @@ public final class AppsFilterImpl extends AppsFilterLocked implements Watchable, } private void removeAppIdFromVisibilityCache(int appId) { - if (!mSystemReady) { + if (!mCacheReady) { return; } synchronized (mCacheLock) { @@ -661,18 +662,20 @@ public final class AppsFilterImpl extends AppsFilterLocked implements Watchable, updateEntireShouldFilterCacheInner(snapshot, settings, usersRef[0], USER_ALL); onChanged(); + + mCacheReady = true; }); } public void onUserCreated(PackageDataSnapshot snapshot, int newUserId) { - if (!mSystemReady) { + if (!mCacheReady) { return; } updateEntireShouldFilterCache(snapshot, newUserId); } public void onUserDeleted(@UserIdInt int userId) { - if (!mSystemReady) { + if (!mCacheReady) { return; } removeShouldFilterCacheForUser(userId); @@ -681,7 +684,7 @@ public final class AppsFilterImpl extends AppsFilterLocked implements Watchable, private void updateShouldFilterCacheForPackage(PackageDataSnapshot snapshot, String packageName) { - if (!mSystemReady) { + if (!mCacheReady) { return; } final ArrayMap settings = @@ -930,7 +933,8 @@ public final class AppsFilterImpl extends AppsFilterLocked implements Watchable, } removeAppIdFromVisibilityCache(setting.getAppId()); - if (mSystemReady && setting.hasSharedUser()) { + // TODO(b/231528435): invalidate cache instead of locking. + if (/*mCacheReady && */setting.hasSharedUser()) { final ArraySet sharedUserPackages = getSharedUserPackages(setting.getSharedUserAppId(), sharedUserSettings); for (int i = sharedUserPackages.size() - 1; i >= 0; i--) { @@ -947,7 +951,8 @@ public final class AppsFilterImpl extends AppsFilterLocked implements Watchable, } } - if (mSystemReady) { + // TODO(b/231528435): invalidate cache instead of locking. + if (true/*mCacheReady*/) { if (additionalChangedPackages != null) { for (int index = 0; index < additionalChangedPackages.size(); index++) { String changedPackage = additionalChangedPackages.valueAt(index); diff --git a/services/core/java/com/android/server/pm/AppsFilterLocked.java b/services/core/java/com/android/server/pm/AppsFilterLocked.java index e8e6cd9e8edbb..b85bd8fbaa876 100644 --- a/services/core/java/com/android/server/pm/AppsFilterLocked.java +++ b/services/core/java/com/android/server/pm/AppsFilterLocked.java @@ -32,7 +32,7 @@ abstract class AppsFilterLocked extends AppsFilterBase { /** * Guards the access for {@link AppsFilterBase#mShouldFilterCache}; */ - protected Object mCacheLock = new Object(); + protected final Object mCacheLock = new Object(); @Override protected boolean isForceQueryable(int appId) { diff --git a/services/core/java/com/android/server/pm/AppsFilterSnapshotImpl.java b/services/core/java/com/android/server/pm/AppsFilterSnapshotImpl.java index c12aa6d485a4d..39b63415e42eb 100644 --- a/services/core/java/com/android/server/pm/AppsFilterSnapshotImpl.java +++ b/services/core/java/com/android/server/pm/AppsFilterSnapshotImpl.java @@ -17,6 +17,7 @@ package com.android.server.pm; import com.android.server.utils.SnapshotCache; +import com.android.server.utils.WatchedSparseBooleanMatrix; import java.util.Arrays; @@ -49,12 +50,18 @@ public final class AppsFilterSnapshotImpl extends AppsFilterBase { mFeatureConfig = orig.mFeatureConfig.snapshot(); mOverlayReferenceMapper = orig.mOverlayReferenceMapper; mSystemSigningDetails = orig.mSystemSigningDetails; - synchronized (orig.mCacheLock) { - mShouldFilterCache = orig.mShouldFilterCacheSnapshot.snapshot(); - mShouldFilterCacheSnapshot = new SnapshotCache.Sealed<>(); + + mCacheReady = orig.mCacheReady; + if (mCacheReady) { + synchronized (orig.mCacheLock) { + mShouldFilterCache = orig.mShouldFilterCacheSnapshot.snapshot(); + } + } else { + // cache is not ready, use an empty cache for the snapshot + mShouldFilterCache = new WatchedSparseBooleanMatrix(); } + mShouldFilterCacheSnapshot = new SnapshotCache.Sealed<>(); mBackgroundExecutor = null; - mSystemReady = orig.mSystemReady; } }