summaryrefslogtreecommitdiff
path: root/core/java/android/app/PropertyInvalidatedCache.java
diff options
context:
space:
mode:
authorLee Shombert <shombert@google.com>2022-04-08 07:54:39 -0700
committerLee Shombert <shombert@google.com>2022-04-11 07:27:16 -0700
commit529a49ee3d6452f033cb43a57bf8c865e177e2b8 (patch)
treecc973441e72db07421a39aefafcf909ba6bafe01 /core/java/android/app/PropertyInvalidatedCache.java
parent9074b73ec7942c6515a2a1e519cd16d18dd9ce59 (diff)
Helper classes for IpcDataCache clients
Bug: 227653108 This adds a helper class that can reduce much of the boilerplate in code that uses IpcDataCache (or the internal-only variant, PropertyInvalidatedCache). See the changes to DevicePolicyManager for example usage. Two PropertyInvalidatedCaches APIs are exposed for testing. The method createPropertyName() is changed so that apis like "Foo" are converted to "foo", not "_foo". Unit tests for the new behavior are added to IpcDataCacheTest. This was manually tested by dumping the cache info from builds with and without this change. Special attention is paid to the DevicePolicyManager caches. The same caches were found (as identified by their key and api) and the caches were enabled/disabled the same. In the course of testing, multiple instances of DevicePolicyManager caches were observed. Cache performance is better if the caches are static; making them static will be addressed in b/228452829. Test: * atest FrameworksCoreTests:IpcDataCacheTest * atest FrameworksCoreTests:PropertyInvalidatedCacheTests * atest FrameworksServicesTests:DevicePolicyConstantsTest * atest FrameworksServicesTests:DevicePolicyEventLoggerTest * atest FrameworksServicesTests:DevicePolicyManagerServiceMigrationTest * atest FrameworksServicesTests:DevicePolicyManagerTest * atest FrameworksServicesTests:EnterpriseSpecificIdCalculatorTest * atest FrameworksServicesTests:OverlayPackagesProviderTest * atest FrameworksServicesTests:OwnersTest * atest FrameworksServicesTests:PolicyVersionUpgraderTest * atest FrameworksServicesTests:SecurityEventTest * atest FrameworksServicesTests:SystemUpdatePolicyTest * atest FrameworksServicesTests:TransferOwnershipMetadataManagerTest * atest MixedDeviceOwnerTest#testIsDeviceOrganizationOwnedWithManagedProfile * atest MixedDeviceOwnerTest#testSetKeyguardDisabledFeatures * atest MixedManagedProfileOwnerTest#testIsDeviceOrganizationOwnedWithManagedProfile * atest MixedManagedProfileOwnerTest#testNetworkLoggingDelegate * atest MixedManagedProfileOwnerTest#testSetKeyguardDisabledFeatures * atest OrgOwnedProfileOwnerTest#testIsDeviceOrganizationOwnedWithManagedProfile * atest OrgOwnedProfileOwnerTest#testNetworkLoggingDelegate * atest OrgOwnedProfileOwnerTest#testSetKeyguardDisabledFeatures * atest android.devicepolicy.cts.DevicePolicyManagerTest * atest android.devicepolicy.cts.NetworkLoggingTest * atest com.android.cts.devicepolicy.DeviceOwnerTest#testAdminActionBookkeeping Change-Id: I2f4fe4ed25db5fb3100334b9d2ce748ee928c10d
Diffstat (limited to 'core/java/android/app/PropertyInvalidatedCache.java')
-rw-r--r--core/java/android/app/PropertyInvalidatedCache.java21
1 files changed, 17 insertions, 4 deletions
diff --git a/core/java/android/app/PropertyInvalidatedCache.java b/core/java/android/app/PropertyInvalidatedCache.java
index df7bf7b94700..add891d40d95 100644
--- a/core/java/android/app/PropertyInvalidatedCache.java
+++ b/core/java/android/app/PropertyInvalidatedCache.java
@@ -313,6 +313,7 @@ public class PropertyInvalidatedCache<Query, Result> {
* one of the permitted values above. The API is a string that is a legal Java simple
* identifier. The api is modified to conform to the system property style guide by
* replacing every upper case letter with an underscore and the lower case equivalent.
+ * (An initial upper case letter is not prefixed with an underscore).
* There is no requirement that the apiName be the name of an actual API.
*
* Be aware that SystemProperties has a maximum length which is private to the
@@ -326,7 +327,7 @@ public class PropertyInvalidatedCache<Query, Result> {
@NonNull String apiName) {
char[] api = apiName.toCharArray();
int upper = 0;
- for (int i = 0; i < api.length; i++) {
+ for (int i = 1; i < api.length; i++) {
if (Character.isUpperCase(api[i])) {
upper++;
}
@@ -336,7 +337,9 @@ public class PropertyInvalidatedCache<Query, Result> {
for (int i = 0; i < api.length; i++) {
if (Character.isJavaIdentifierPart(api[i])) {
if (Character.isUpperCase(api[i])) {
- suffix[j++] = '_';
+ if (i > 0) {
+ suffix[j++] = '_';
+ }
suffix[j++] = Character.toLowerCase(api[i]);
} else {
suffix[j++] = api[i];
@@ -1286,13 +1289,23 @@ public class PropertyInvalidatedCache<Query, Result> {
}
/**
- * Return the name of the cache, to be used in debug messages.
+ * Return the name of the cache, to be used in debug messages. This is exposed
+ * primarily for testing.
+ * @hide
*/
- private final @NonNull String cacheName() {
+ public final @NonNull String cacheName() {
return mCacheName;
}
/**
+ * Return the property used by the cache. This is primarily for test purposes.
+ * @hide
+ */
+ public final @NonNull String propertyName() {
+ return mPropertyName;
+ }
+
+ /**
* Return the query as a string, to be used in debug messages. New clients should not
* override this, but should instead add the necessary toString() method to the Query
* class.