3
0
Fork 0

Merge "Rename legacy cache keys" into main

This commit is contained in:
Lee Shombert 2024-09-19 16:44:33 +00:00 committed by Android (Google) Code Review
commit ee2b55244d
7 changed files with 60 additions and 9 deletions

View File

@ -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>(

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -1796,7 +1796,8 @@ public final class PermissionManager {
}
/** @hide */
public static final String CACHE_KEY_PACKAGE_INFO = "cache_key.package_info";
public static final String CACHE_KEY_PACKAGE_INFO =
PropertyInvalidatedCache.createSystemCacheKey("package_info");
/** @hide */
private static final PropertyInvalidatedCache<PermissionQuery, Integer> sPermissionCache =

View File

@ -451,7 +451,7 @@ public class LocationManager {
private static final long MAX_SINGLE_LOCATION_TIMEOUT_MS = 30 * 1000;
private static final String CACHE_KEY_LOCATION_ENABLED_PROPERTY =
"cache_key.location_enabled";
PropertyInvalidatedCache.createSystemCacheKey("location_enabled");
static ILocationManager getService() throws RemoteException {
try {