diff options
3 files changed, 31 insertions, 45 deletions
diff --git a/core/java/android/app/ApplicationPackageManager.java b/core/java/android/app/ApplicationPackageManager.java index fb5a12b49921..6c6fb426d6b6 100644 --- a/core/java/android/app/ApplicationPackageManager.java +++ b/core/java/android/app/ApplicationPackageManager.java @@ -16,6 +16,7 @@ package android.app; +import static android.app.PropertyInvalidatedCache.MODULE_SYSTEM; import static android.app.PropertyInvalidatedCache.createSystemCacheKey; import static android.app.admin.DevicePolicyResources.Drawables.Style.SOLID_COLORED; import static android.app.admin.DevicePolicyResources.Drawables.Style.SOLID_NOT_COLORED; @@ -783,43 +784,24 @@ public class ApplicationPackageManager extends PackageManager { } /** + * The API and cache name for hasSystemFeature. + */ + private static final String HAS_SYSTEM_FEATURE_API = "has_system_feature"; + + /** * Identifies a single hasSystemFeature query. */ - @Immutable - private static final class HasSystemFeatureQuery { - public final String name; - public final int version; - public HasSystemFeatureQuery(String n, int v) { - name = n; - version = v; - } - @Override - public String toString() { - return String.format("HasSystemFeatureQuery(name=\"%s\", version=%d)", - name, version); - } - @Override - public boolean equals(@Nullable Object o) { - if (o instanceof HasSystemFeatureQuery) { - HasSystemFeatureQuery r = (HasSystemFeatureQuery) o; - return Objects.equals(name, r.name) && version == r.version; - } else { - return false; - } - } - @Override - public int hashCode() { - return Objects.hashCode(name) * 13 + version; - } - } + private record HasSystemFeatureQuery(String name, int version) {} // Make this cache relatively large. There are many system features and // none are ever invalidated. MPTS tests suggests that the cache should // hold at least 150 entries. private final static PropertyInvalidatedCache<HasSystemFeatureQuery, Boolean> - mHasSystemFeatureCache = - new PropertyInvalidatedCache<HasSystemFeatureQuery, Boolean>( - 256, createSystemCacheKey("has_system_feature")) { + mHasSystemFeatureCache = new PropertyInvalidatedCache<>( + new PropertyInvalidatedCache.Args(MODULE_SYSTEM) + .api(HAS_SYSTEM_FEATURE_API).maxEntries(256).isolateUids(false), + HAS_SYSTEM_FEATURE_API, null) { + @Override public Boolean recompute(HasSystemFeatureQuery query) { try { diff --git a/core/java/android/app/PropertyInvalidatedCache.java b/core/java/android/app/PropertyInvalidatedCache.java index 1dc774285a32..675152fbbbb6 100644 --- a/core/java/android/app/PropertyInvalidatedCache.java +++ b/core/java/android/app/PropertyInvalidatedCache.java @@ -1947,10 +1947,12 @@ public class PropertyInvalidatedCache<Query, Result> { } // Return true if this cache has had any activity. If the hits, misses, and skips are all - // zero then the client never tried to use the cache. - private boolean isActive() { + // zero then the client never tried to use the cache. If invalidations and corks are also + // zero then the server never tried to use the cache. + private boolean isActive(NonceHandler.Stats stats) { synchronized (mLock) { - return mHits + mMisses + getSkipsLocked() > 0; + return mHits + mMisses + getSkipsLocked() + + stats.invalidated + stats.corkedInvalidates > 0; } } @@ -1968,15 +1970,15 @@ public class PropertyInvalidatedCache<Query, Result> { NonceHandler.Stats stats = mNonce.getStats(); synchronized (mLock) { - if (brief && !isActive()) { + if (brief && !isActive(stats)) { return; } pw.println(formatSimple(" Cache Name: %s", cacheName())); pw.println(formatSimple(" Property: %s", mPropertyName)); pw.println(formatSimple( - " Hits: %d, Misses: %d, Skips: %d, Clears: %d, Uids: %d", - mHits, mMisses, getSkipsLocked(), mClears, mCache.size())); + " Hits: %d, Misses: %d, Skips: %d, Clears: %d", + mHits, mMisses, getSkipsLocked(), mClears)); // Print all the skip reasons. pw.format(" Skip-%s: %d", sNonceName[0], mSkips[0]); @@ -1986,7 +1988,7 @@ public class PropertyInvalidatedCache<Query, Result> { pw.println(); pw.println(formatSimple( - " Nonce: 0x%016x, Invalidates: %d, CorkedInvalidates: %d", + " Nonce: 0x%016x, Invalidates: %d, Corked: %d", mLastSeenNonce, stats.invalidated, stats.corkedInvalidates)); pw.println(formatSimple( " Current Size: %d, Max Size: %d, HW Mark: %d, Overflows: %d", diff --git a/core/java/android/hardware/display/DisplayManagerGlobal.java b/core/java/android/hardware/display/DisplayManagerGlobal.java index 03b44f63e3b7..8872145b18dd 100644 --- a/core/java/android/hardware/display/DisplayManagerGlobal.java +++ b/core/java/android/hardware/display/DisplayManagerGlobal.java @@ -17,6 +17,7 @@ package android.hardware.display; +import static android.app.PropertyInvalidatedCache.MODULE_SYSTEM; import static android.hardware.display.DisplayManager.EventFlag; import static android.Manifest.permission.MANAGE_DISPLAYS; import static android.view.Display.HdrCapabilities.HdrType; @@ -179,9 +180,11 @@ public final class DisplayManagerGlobal { } private PropertyInvalidatedCache<Integer, DisplayInfo> mDisplayCache = - new PropertyInvalidatedCache<Integer, DisplayInfo>( - 8, // size of display cache - CACHE_KEY_DISPLAY_INFO_PROPERTY) { + new PropertyInvalidatedCache<>( + new PropertyInvalidatedCache.Args(MODULE_SYSTEM) + .maxEntries(8).api(CACHE_KEY_DISPLAY_INFO_API).isolateUids(false), + CACHE_KEY_DISPLAY_INFO_API, null) { + @Override public DisplayInfo recompute(Integer id) { try { @@ -1493,18 +1496,17 @@ public final class DisplayManagerGlobal { } /** - * Name of the property containing a unique token which changes every time we update the - * system's display configuration. + * The API portion of the key that identifies the unique PropertyInvalidatedCache token which + * changes every time we update the system's display configuration. */ - public static final String CACHE_KEY_DISPLAY_INFO_PROPERTY = - PropertyInvalidatedCache.createSystemCacheKey("display_info"); + private static final String CACHE_KEY_DISPLAY_INFO_API = "display_info"; /** * Invalidates the contents of the display info cache for all applications. Can only * be called by system_server. */ public static void invalidateLocalDisplayInfoCaches() { - PropertyInvalidatedCache.invalidateCache(CACHE_KEY_DISPLAY_INFO_PROPERTY); + PropertyInvalidatedCache.invalidateCache(MODULE_SYSTEM, CACHE_KEY_DISPLAY_INFO_API); } /** |