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

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

Rename legacy cache keys

This CL renames legacy PropertyInvalidatedCache keys to match the new
naming convention, which is "cache_key.<module>.<name>", where the
module is one of "system_server", "telephony", or "bluetooth".  The
rename is entirely in the framework.  There is no backcompat issue.

Invalid cache keys are logged, unless the flag is true, in which case
a fatal exception is thrown.

Tested with a special image that removed the SELinux policies that
permitted the legacy property names to work.  Booted the image and
verified no selinux violations in logcat.  This means no caches were
using the legacy properties.

Test: booted the image and verified that no caches with non-standard
   names existed in the system.  Verification used the output of
   `dumpsys cacheinfo`.

Flag: EXEMPT refactor
Bug: 366552454
Change-Id: Icfc43980def04c8aefaa4097a38eabbc7ca3b054
parent feaa25f8
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.app;

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;
import static android.app.admin.DevicePolicyResources.Drawables.WORK_PROFILE_ICON;
@@ -817,7 +818,7 @@ public class ApplicationPackageManager extends PackageManager {
    private final static PropertyInvalidatedCache<HasSystemFeatureQuery, Boolean>
            mHasSystemFeatureCache =
            new PropertyInvalidatedCache<HasSystemFeatureQuery, Boolean>(
                256, "cache_key.has_system_feature") {
                256, createSystemCacheKey("has_system_feature")) {
                @Override
                public Boolean recompute(HasSystemFeatureQuery query) {
                    try {
@@ -1127,7 +1128,7 @@ public class ApplicationPackageManager extends PackageManager {
    }

    private static final String CACHE_KEY_PACKAGES_FOR_UID_PROPERTY =
            "cache_key.get_packages_for_uid";
            createSystemCacheKey("get_packages_for_uid");
    private static final PropertyInvalidatedCache<Integer, GetPackagesForUidResult>
            mGetPackagesForUidCache =
            new PropertyInvalidatedCache<Integer, GetPackagesForUidResult>(
+47 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.app;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.TestApi;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
@@ -282,6 +283,12 @@ public class PropertyInvalidatedCache<Query, Result> {
     * @hide
     */

    /**
     * The well-known key prefix.
     * @hide
     */
    private static final String CACHE_KEY_PREFIX = "cache_key";

    /**
     * The module used for unit tests and cts tests.  It is expected that no process in
     * the system has permissions to write properties with this module.
@@ -366,7 +373,44 @@ public class PropertyInvalidatedCache<Query, Result> {
            }
        }

        return "cache_key." + module + "." + new String(suffix);
        return CACHE_KEY_PREFIX + "." + module + "." + new String(suffix);
    }

    /**
     * All legal keys start with one of the following strings.
     */
    private static final String[] sValidKeyPrefix = {
        CACHE_KEY_PREFIX + "." + MODULE_SYSTEM + ".",
        CACHE_KEY_PREFIX + "." + MODULE_BLUETOOTH + ".",
        CACHE_KEY_PREFIX + "." + MODULE_TELEPHONY + ".",
        CACHE_KEY_PREFIX + "." + MODULE_TEST + ".",
    };

    /**
     * Verify that the property name conforms to the standard.  Log a warning if this is not true.
     * Note that this is done once in the cache constructor; it does not have to be very fast.
     */
    private void validateCacheKey(String name) {
        if (Build.IS_USER) {
            // Do not bother checking keys in user builds.  The keys will have been tested in
            // eng/userdebug builds already.
            return;
        }
        for (int i = 0; i < sValidKeyPrefix.length; i++) {
            if (name.startsWith(sValidKeyPrefix[i])) return;
        }
        Log.w(TAG, "invalid cache name: " + name);
    }

    /**
     * Create a cache key for the system module.  The parameter is the API name.  This reduces
     * some of the boilerplate in system caches.  It is not needed in other modules because other
     * modules must use the {@link IpcDataCache} interfaces.
     * @hide
     */
    @NonNull
    public static String createSystemCacheKey(@NonNull String api) {
        return createPropertyName(MODULE_SYSTEM, api);
    }

    /**
@@ -561,6 +605,7 @@ public class PropertyInvalidatedCache<Query, Result> {
    public PropertyInvalidatedCache(int maxEntries, @NonNull String propertyName,
            @NonNull String cacheName) {
        mPropertyName = propertyName;
        validateCacheKey(mPropertyName);
        mCacheName = cacheName;
        mMaxEntries = maxEntries;
        mComputer = new DefaultComputer<>(this);
@@ -584,6 +629,7 @@ public class PropertyInvalidatedCache<Query, Result> {
    public PropertyInvalidatedCache(int maxEntries, @NonNull String module, @NonNull String api,
            @NonNull String cacheName, @NonNull QueryHandler<Query, Result> computer) {
        mPropertyName = createPropertyName(module, api);
        validateCacheKey(mPropertyName);
        mCacheName = cacheName;
        mMaxEntries = maxEntries;
        mComputer = computer;
+3 −1
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.app.compat;

import static android.app.PropertyInvalidatedCache.createSystemCacheKey;

import android.annotation.NonNull;
import android.app.PropertyInvalidatedCache;
import android.content.Context;
@@ -31,7 +33,7 @@ import com.android.internal.compat.IPlatformCompat;
 */
public final class ChangeIdStateCache
        extends PropertyInvalidatedCache<ChangeIdStateQuery, Boolean> {
    private static final String CACHE_KEY = "cache_key.is_compat_change_enabled";
    private static final String CACHE_KEY = createSystemCacheKey("is_compat_change_enabled");
    private static final int MAX_ENTRIES = 2048;
    private static boolean sDisabled = false;
    private volatile IPlatformCompat mPlatformCompat;
+1 −1
Original line number Diff line number Diff line
@@ -1445,7 +1445,7 @@ public final class DisplayManagerGlobal {
     * system's display configuration.
     */
    public static final String CACHE_KEY_DISPLAY_INFO_PROPERTY =
            "cache_key.display_info";
            PropertyInvalidatedCache.createSystemCacheKey("display_info");

    /**
     * Invalidates the contents of the display info cache for all applications. Can only
+3 −2
Original line number Diff line number Diff line
@@ -1144,9 +1144,10 @@ public final class PowerManager {
    }

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

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

    private static final int MAX_CACHE_ENTRIES = 1;

Loading