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

Commit f50d2a29 authored by Lee Shombert's avatar Lee Shombert
Browse files

Make power caches non-isolating

The following two caches are no longer uid-isolating:
 * is_power_save_mode
 * is_interactive

The cache constructors have been reflowed slightly to match the latest
non-deprecated apis.

Flag: EXEMPT bug-fix
Bug: 379098894
Test: presubmit
Change-Id: I9219e15a1e11cf1cfc3a74341661d54c92d1e6f7
parent 393eb6f7
Loading
Loading
Loading
Loading
+18 −10
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.os;

import static android.app.PropertyInvalidatedCache.MODULE_SYSTEM;

import android.Manifest.permission;
import android.annotation.CallbackExecutor;
import android.annotation.CurrentTimeMillisLong;
@@ -1186,17 +1188,23 @@ public final class PowerManager {
        }
    }

    private static final String CACHE_KEY_IS_POWER_SAVE_MODE_PROPERTY =
            PropertyInvalidatedCache.createSystemCacheKey("is_power_save_mode");
    private static final String CACHE_KEY_IS_POWER_SAVE_MODE_API = "is_power_save_mode";

    private static final String CACHE_KEY_IS_INTERACTIVE_PROPERTY =
            PropertyInvalidatedCache.createSystemCacheKey("is_interactive");
    private static final String CACHE_KEY_IS_INTERACTIVE_API = "is_interactive";

    private static final int MAX_CACHE_ENTRIES = 1;

    private static PropertyInvalidatedCache.Args getCacheArgs(String api) {
        return new PropertyInvalidatedCache.Args(MODULE_SYSTEM)
                .maxEntries(MAX_CACHE_ENTRIES)
                .isolateUids(false)
                .cacheNulls(false)
                .api(api);
    }

    private final PropertyInvalidatedCache<Void, Boolean> mPowerSaveModeCache =
            new PropertyInvalidatedCache<Void, Boolean>(MAX_CACHE_ENTRIES,
                CACHE_KEY_IS_POWER_SAVE_MODE_PROPERTY) {
            new PropertyInvalidatedCache<>(getCacheArgs(CACHE_KEY_IS_POWER_SAVE_MODE_API),
                    CACHE_KEY_IS_POWER_SAVE_MODE_API, null) {
                @Override
                public Boolean recompute(Void query) {
                    try {
@@ -1208,8 +1216,8 @@ public final class PowerManager {
            };

    private final PropertyInvalidatedCache<Integer, Boolean> mInteractiveCache =
            new PropertyInvalidatedCache<Integer, Boolean>(MAX_CACHE_ENTRIES,
                CACHE_KEY_IS_INTERACTIVE_PROPERTY) {
            new PropertyInvalidatedCache<>(getCacheArgs(CACHE_KEY_IS_INTERACTIVE_API),
                    CACHE_KEY_IS_INTERACTIVE_API, null) {
                @Override
                public Boolean recompute(Integer displayId) {
                    try {
@@ -4322,13 +4330,13 @@ public final class PowerManager {
     * @hide
     */
    public static void invalidatePowerSaveModeCaches() {
        PropertyInvalidatedCache.invalidateCache(CACHE_KEY_IS_POWER_SAVE_MODE_PROPERTY);
        PropertyInvalidatedCache.invalidateCache(MODULE_SYSTEM, CACHE_KEY_IS_POWER_SAVE_MODE_API);
    }

    /**
     * @hide
     */
    public static void invalidateIsInteractiveCaches() {
        PropertyInvalidatedCache.invalidateCache(CACHE_KEY_IS_INTERACTIVE_PROPERTY);
        PropertyInvalidatedCache.invalidateCache(MODULE_SYSTEM, CACHE_KEY_IS_INTERACTIVE_API);
    }
}