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

Commit a45a83a4 authored by Lee Shombert's avatar Lee Shombert Committed by Android (Google) Code Review
Browse files

Merge "Make selected PIC caches non-isolating" into main

parents 5e4b83bc 1f1ae1df
Loading
Loading
Loading
Loading
+12 −30
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package android.app;
package android.app;


import static android.app.PropertyInvalidatedCache.MODULE_SYSTEM;
import static android.app.PropertyInvalidatedCache.createSystemCacheKey;
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_COLORED;
import static android.app.admin.DevicePolicyResources.Drawables.Style.SOLID_NOT_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);
        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.
     * Identifies a single hasSystemFeature query.
     */
     */
    @Immutable
    private record HasSystemFeatureQuery(String name, int version) {}
    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;
        }
    }


    // Make this cache relatively large.  There are many system features and
    // Make this cache relatively large.  There are many system features and
    // none are ever invalidated.  MPTS tests suggests that the cache should
    // none are ever invalidated.  MPTS tests suggests that the cache should
    // hold at least 150 entries.
    // hold at least 150 entries.
    private final static PropertyInvalidatedCache<HasSystemFeatureQuery, Boolean>
    private final static PropertyInvalidatedCache<HasSystemFeatureQuery, Boolean>
            mHasSystemFeatureCache =
            mHasSystemFeatureCache = new PropertyInvalidatedCache<>(
            new PropertyInvalidatedCache<HasSystemFeatureQuery, Boolean>(
                new PropertyInvalidatedCache.Args(MODULE_SYSTEM)
                256, createSystemCacheKey("has_system_feature")) {
                .api(HAS_SYSTEM_FEATURE_API).maxEntries(256).isolateUids(false),
                HAS_SYSTEM_FEATURE_API, null) {

                @Override
                @Override
                public Boolean recompute(HasSystemFeatureQuery query) {
                public Boolean recompute(HasSystemFeatureQuery query) {
                    try {
                    try {
+9 −7
Original line number Original line 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
    // 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.
    // zero then the client never tried to use the cache.  If invalidations and corks are also
    private boolean isActive() {
    // zero then the server never tried to use the cache.
    private boolean isActive(NonceHandler.Stats stats) {
        synchronized (mLock) {
        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();
        NonceHandler.Stats stats = mNonce.getStats();


        synchronized (mLock) {
        synchronized (mLock) {
            if (brief && !isActive()) {
            if (brief && !isActive(stats)) {
                return;
                return;
            }
            }


            pw.println(formatSimple("  Cache Name: %s", cacheName()));
            pw.println(formatSimple("  Cache Name: %s", cacheName()));
            pw.println(formatSimple("    Property: %s", mPropertyName));
            pw.println(formatSimple("    Property: %s", mPropertyName));
            pw.println(formatSimple(
            pw.println(formatSimple(
                "    Hits: %d, Misses: %d, Skips: %d, Clears: %d, Uids: %d",
                "    Hits: %d, Misses: %d, Skips: %d, Clears: %d",
                mHits, mMisses, getSkipsLocked(), mClears, mCache.size()));
                mHits, mMisses, getSkipsLocked(), mClears));


            // Print all the skip reasons.
            // Print all the skip reasons.
            pw.format("    Skip-%s: %d", sNonceName[0], mSkips[0]);
            pw.format("    Skip-%s: %d", sNonceName[0], mSkips[0]);
@@ -1986,7 +1988,7 @@ public class PropertyInvalidatedCache<Query, Result> {
            pw.println();
            pw.println();


            pw.println(formatSimple(
            pw.println(formatSimple(
                "    Nonce: 0x%016x, Invalidates: %d, CorkedInvalidates: %d",
                "    Nonce: 0x%016x, Invalidates: %d, Corked: %d",
                mLastSeenNonce, stats.invalidated, stats.corkedInvalidates));
                mLastSeenNonce, stats.invalidated, stats.corkedInvalidates));
            pw.println(formatSimple(
            pw.println(formatSimple(
                "    Current Size: %d, Max Size: %d, HW Mark: %d, Overflows: %d",
                "    Current Size: %d, Max Size: %d, HW Mark: %d, Overflows: %d",
+10 −8
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
package android.hardware.display;
package android.hardware.display;




import static android.app.PropertyInvalidatedCache.MODULE_SYSTEM;
import static android.hardware.display.DisplayManager.EventFlag;
import static android.hardware.display.DisplayManager.EventFlag;
import static android.Manifest.permission.MANAGE_DISPLAYS;
import static android.Manifest.permission.MANAGE_DISPLAYS;
import static android.view.Display.HdrCapabilities.HdrType;
import static android.view.Display.HdrCapabilities.HdrType;
@@ -188,9 +189,11 @@ public final class DisplayManagerGlobal {
    }
    }


    private PropertyInvalidatedCache<Integer, DisplayInfo> mDisplayCache =
    private PropertyInvalidatedCache<Integer, DisplayInfo> mDisplayCache =
            new PropertyInvalidatedCache<Integer, DisplayInfo>(
            new PropertyInvalidatedCache<>(
                8, // size of display cache
                new PropertyInvalidatedCache.Args(MODULE_SYSTEM)
                CACHE_KEY_DISPLAY_INFO_PROPERTY) {
                .maxEntries(8).api(CACHE_KEY_DISPLAY_INFO_API).isolateUids(false),
                CACHE_KEY_DISPLAY_INFO_API, null) {

                @Override
                @Override
                public DisplayInfo recompute(Integer id) {
                public DisplayInfo recompute(Integer id) {
                    try {
                    try {
@@ -1514,18 +1517,17 @@ public final class DisplayManagerGlobal {
    }
    }


    /**
    /**
     * Name of the property containing a unique token which changes every time we update the
     * The API portion of the key that identifies the unique PropertyInvalidatedCache token which
     * system's display configuration.
     * changes every time we update the system's display configuration.
     */
     */
    public static final String CACHE_KEY_DISPLAY_INFO_PROPERTY =
    private static final String CACHE_KEY_DISPLAY_INFO_API = "display_info";
            PropertyInvalidatedCache.createSystemCacheKey("display_info");


    /**
    /**
     * Invalidates the contents of the display info cache for all applications. Can only
     * Invalidates the contents of the display info cache for all applications. Can only
     * be called by system_server.
     * be called by system_server.
     */
     */
    public static void invalidateLocalDisplayInfoCaches() {
    public static void invalidateLocalDisplayInfoCaches() {
        PropertyInvalidatedCache.invalidateCache(CACHE_KEY_DISPLAY_INFO_PROPERTY);
        PropertyInvalidatedCache.invalidateCache(MODULE_SYSTEM, CACHE_KEY_DISPLAY_INFO_API);
    }
    }


    /**
    /**