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

Commit 1f1ae1df authored by Lee Shombert's avatar Lee Shombert
Browse files

Make selected PIC caches non-isolating

The cache for hasSystemFeature() and the cache for getDisplayInfo() do
not need to isolate data between UIDs.  This CL marks those caches as
non-isolating.   The getDisplayInfo() cache was named after the system
property; it is now named after the API.  This is a non-functional
change to assist reporting.

A bad field ("Uids") has been removed from `dumpsys cacheinfo`.

Flag: android.app.pic_isolate_cache_by_uid
Bug: 323574186
Test: * Tested with the flag enabled; verified that two caches do not
   isolate data by UID.
 * Manually verified that the dumpsys field is no longer present.
Change-Id: I01530875677d9b36b0477a5cfa08771e41e48844
parent 505b5d1c
Loading
Loading
Loading
Loading
+12 −30
Original line number Diff line number Diff line
@@ -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;
@@ -782,44 +783,25 @@ public class ApplicationPackageManager extends PackageManager {
        return hasSystemFeature(name, 0);
    }

    /**
     * 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 {
+9 −7
Original line number Diff line number Diff line
@@ -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",
+10 −8
Original line number Diff line number Diff line
@@ -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);
    }

    /**