Merge "Correct the PropertyInvalidatedCache module definition" into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
9331216cd1
@@ -55,12 +55,13 @@ package android.app {
|
||||
}
|
||||
|
||||
public class PropertyInvalidatedCache<Query, Result> {
|
||||
ctor public PropertyInvalidatedCache(int, int, @NonNull String, @NonNull String, @NonNull android.app.PropertyInvalidatedCache.QueryHandler<Query,Result>);
|
||||
ctor public PropertyInvalidatedCache(int, @NonNull String, @NonNull String, @NonNull String, @NonNull android.app.PropertyInvalidatedCache.QueryHandler<Query,Result>);
|
||||
method public final void disableForCurrentProcess();
|
||||
method public final void invalidateCache();
|
||||
method public static void invalidateCache(int, @NonNull String);
|
||||
method public static void invalidateCache(@NonNull String, @NonNull String);
|
||||
method @Nullable public final Result query(@NonNull Query);
|
||||
field public static final int MODULE_BLUETOOTH = 2; // 0x2
|
||||
field public static final String MODULE_BLUETOOTH = "bluetooth";
|
||||
field public static final String MODULE_TELEPHONY = "telephony";
|
||||
}
|
||||
|
||||
public abstract static class PropertyInvalidatedCache.QueryHandler<Q, R> {
|
||||
|
||||
@@ -372,8 +372,8 @@ package android.app {
|
||||
}
|
||||
|
||||
public class PropertyInvalidatedCache<Query, Result> {
|
||||
ctor public PropertyInvalidatedCache(int, int, @NonNull String, @NonNull String, @NonNull android.app.PropertyInvalidatedCache.QueryHandler<Query,Result>);
|
||||
method @NonNull public static String createPropertyName(int, @NonNull String);
|
||||
ctor public PropertyInvalidatedCache(int, @NonNull String, @NonNull String, @NonNull String, @NonNull android.app.PropertyInvalidatedCache.QueryHandler<Query,Result>);
|
||||
method @NonNull public static String createPropertyName(@NonNull String, @NonNull String);
|
||||
method public final void disableForCurrentProcess();
|
||||
method public static void disableForTestMode();
|
||||
method public final void disableInstance();
|
||||
@@ -381,14 +381,15 @@ package android.app {
|
||||
method public final void forgetDisableLocal();
|
||||
method public boolean getDisabledState();
|
||||
method public final void invalidateCache();
|
||||
method public static void invalidateCache(int, @NonNull String);
|
||||
method public static void invalidateCache(@NonNull String, @NonNull String);
|
||||
method public final boolean isDisabled();
|
||||
method @Nullable public final Result query(@NonNull Query);
|
||||
method public static void setTestMode(boolean);
|
||||
method public void testPropertyName();
|
||||
field public static final int MODULE_BLUETOOTH = 2; // 0x2
|
||||
field public static final int MODULE_SYSTEM = 1; // 0x1
|
||||
field public static final int MODULE_TEST = 0; // 0x0
|
||||
field public static final String MODULE_BLUETOOTH = "bluetooth";
|
||||
field public static final String MODULE_SYSTEM = "system_server";
|
||||
field public static final String MODULE_TELEPHONY = "telephony";
|
||||
field public static final String MODULE_TEST = "test";
|
||||
}
|
||||
|
||||
public abstract static class PropertyInvalidatedCache.QueryHandler<Q, R> {
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package android.app;
|
||||
|
||||
import android.annotation.IntDef;
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.SystemApi;
|
||||
@@ -265,13 +264,6 @@ public class PropertyInvalidatedCache<Query, Result> {
|
||||
* the permissions granted to the processes that contain the corresponding caches.
|
||||
* @hide
|
||||
*/
|
||||
@IntDef(prefix = { "MODULE_" }, value = {
|
||||
MODULE_TEST,
|
||||
MODULE_SYSTEM,
|
||||
MODULE_BLUETOOTH
|
||||
})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface Module {}
|
||||
|
||||
/**
|
||||
* The module used for unit tests and cts tests. It is expected that no process in
|
||||
@@ -279,7 +271,7 @@ public class PropertyInvalidatedCache<Query, Result> {
|
||||
* @hide
|
||||
*/
|
||||
@TestApi
|
||||
public static final int MODULE_TEST = 0;
|
||||
public static final String MODULE_TEST = "test";
|
||||
|
||||
/**
|
||||
* The module used for system server/framework caches. This is not visible outside
|
||||
@@ -287,7 +279,7 @@ public class PropertyInvalidatedCache<Query, Result> {
|
||||
* @hide
|
||||
*/
|
||||
@TestApi
|
||||
public static final int MODULE_SYSTEM = 1;
|
||||
public static final String MODULE_SYSTEM = "system_server";
|
||||
|
||||
/**
|
||||
* The module used for bluetooth caches.
|
||||
@@ -295,11 +287,12 @@ public class PropertyInvalidatedCache<Query, Result> {
|
||||
*/
|
||||
@SystemApi(client=SystemApi.Client.MODULE_LIBRARIES)
|
||||
@TestApi
|
||||
public static final int MODULE_BLUETOOTH = 2;
|
||||
public static final String MODULE_BLUETOOTH = "bluetooth";
|
||||
|
||||
// A static array mapping module constants to strings.
|
||||
private final static String[] sModuleNames =
|
||||
{ "test", "system_server", "bluetooth" };
|
||||
/**
|
||||
* The module used for telephony caches.
|
||||
*/
|
||||
public static final String MODULE_TELEPHONY = "telephony";
|
||||
|
||||
/**
|
||||
* Construct a system property that matches the rules described above. The module is
|
||||
@@ -315,7 +308,8 @@ public class PropertyInvalidatedCache<Query, Result> {
|
||||
* @hide
|
||||
*/
|
||||
@TestApi
|
||||
public static @NonNull String createPropertyName(@Module int module, @NonNull String apiName) {
|
||||
public static @NonNull String createPropertyName(@NonNull String module,
|
||||
@NonNull String apiName) {
|
||||
char[] api = apiName.toCharArray();
|
||||
int upper = 0;
|
||||
for (int i = 0; i < api.length; i++) {
|
||||
@@ -338,14 +332,7 @@ public class PropertyInvalidatedCache<Query, Result> {
|
||||
}
|
||||
}
|
||||
|
||||
String moduleName = null;
|
||||
try {
|
||||
moduleName = sModuleNames[module];
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
throw new IllegalArgumentException("invalid module " + module);
|
||||
}
|
||||
|
||||
return "cache_key." + moduleName + "." + new String(suffix);
|
||||
return "cache_key." + module + "." + new String(suffix);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -548,7 +535,7 @@ public class PropertyInvalidatedCache<Query, Result> {
|
||||
*/
|
||||
@SystemApi(client=SystemApi.Client.MODULE_LIBRARIES)
|
||||
@TestApi
|
||||
public PropertyInvalidatedCache(int maxEntries, @Module int module, @NonNull String api,
|
||||
public PropertyInvalidatedCache(int maxEntries, @NonNull String module, @NonNull String api,
|
||||
@NonNull String cacheName, @NonNull QueryHandler<Query, Result> computer) {
|
||||
mPropertyName = createPropertyName(module, api);
|
||||
mCacheName = cacheName;
|
||||
@@ -989,7 +976,7 @@ public class PropertyInvalidatedCache<Query, Result> {
|
||||
*/
|
||||
@SystemApi(client=SystemApi.Client.MODULE_LIBRARIES)
|
||||
@TestApi
|
||||
public static void invalidateCache(@Module int module, @NonNull String api) {
|
||||
public static void invalidateCache(@NonNull String module, @NonNull String api) {
|
||||
invalidateCache(createPropertyName(module, api));
|
||||
}
|
||||
|
||||
@@ -1211,8 +1198,10 @@ public class PropertyInvalidatedCache<Query, Result> {
|
||||
getHandlerLocked().sendEmptyMessageAtTime(0, mUncorkDeadlineMs);
|
||||
PropertyInvalidatedCache.corkInvalidations(mPropertyName);
|
||||
} else {
|
||||
final long count = sCorkedInvalidates.getOrDefault(mPropertyName, (long) 0);
|
||||
sCorkedInvalidates.put(mPropertyName, count + 1);
|
||||
synchronized (sCorkLock) {
|
||||
final long count = sCorkedInvalidates.getOrDefault(mPropertyName, (long) 0);
|
||||
sCorkedInvalidates.put(mPropertyName, count + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1341,7 +1330,7 @@ public class PropertyInvalidatedCache<Query, Result> {
|
||||
}
|
||||
}
|
||||
|
||||
private void dumpContents(PrintWriter pw, String[] args) {
|
||||
private void dumpContents(PrintWriter pw) {
|
||||
long invalidateCount;
|
||||
long corkedInvalidates;
|
||||
synchronized (sCorkLock) {
|
||||
@@ -1418,7 +1407,7 @@ public class PropertyInvalidatedCache<Query, Result> {
|
||||
|
||||
for (int i = 0; i < activeCaches.size(); i++) {
|
||||
PropertyInvalidatedCache currentCache = activeCaches.get(i);
|
||||
currentCache.dumpContents(pw, args);
|
||||
currentCache.dumpContents(pw);
|
||||
pw.flush();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.junit.Test;
|
||||
public class PropertyInvalidatedCacheTests {
|
||||
|
||||
// Configuration for creating caches
|
||||
private static final int MODULE = PropertyInvalidatedCache.MODULE_TEST;
|
||||
private static final String MODULE = PropertyInvalidatedCache.MODULE_TEST;
|
||||
private static final String API = "testApi";
|
||||
|
||||
// This class is a proxy for binder calls. It contains a counter that increments
|
||||
@@ -214,13 +214,13 @@ public class PropertyInvalidatedCacheTests {
|
||||
this(MODULE, API);
|
||||
}
|
||||
|
||||
TestCache(int module, String api) {
|
||||
TestCache(String module, String api) {
|
||||
this(module, api, new TestQuery());
|
||||
setTestMode(true);
|
||||
testPropertyName();
|
||||
}
|
||||
|
||||
TestCache(int module, String api, TestQuery query) {
|
||||
TestCache(String module, String api, TestQuery query) {
|
||||
super(4, module, api, api, query);
|
||||
mQuery = query;
|
||||
setTestMode(true);
|
||||
@@ -364,15 +364,6 @@ public class PropertyInvalidatedCacheTests {
|
||||
n1 = PropertyInvalidatedCache.createPropertyName(
|
||||
PropertyInvalidatedCache.MODULE_SYSTEM, "get_package_info");
|
||||
assertEquals(n1, "cache_key.system_server.get_package_info");
|
||||
try {
|
||||
n1 = PropertyInvalidatedCache.createPropertyName(
|
||||
PropertyInvalidatedCache.MODULE_SYSTEM - 1, "get package_info");
|
||||
// n1 is an invalid api name.
|
||||
assertEquals(false, true);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// An exception is expected here.
|
||||
}
|
||||
|
||||
n1 = PropertyInvalidatedCache.createPropertyName(
|
||||
PropertyInvalidatedCache.MODULE_BLUETOOTH, "getState");
|
||||
assertEquals(n1, "cache_key.bluetooth.get_state");
|
||||
|
||||
Reference in New Issue
Block a user