From 0cece3898b0f26b0fb026415d4c8f928d16296a3 Mon Sep 17 00:00:00 2001 From: Lee Shombert Date: Tue, 4 Jan 2022 08:10:15 -0800 Subject: Prepare PropertyInvalidatedCache for SystemApi Bug: 152453213 Tag: #refactor This commit prepares PropertyInvalidatedCache to function as a system api. Specifically, the methods recompute() and bypass() which may be overridden by clients are now public (instead of protected). This forces an update to all existing clients, to accommodate the change in method visibility. Two small changes have been made as cleanup: 1. The awkwardly named debugCompareQueryResults() is now resultEquals(), which is more or less consistent with how other equality tests are named in Android. This name change affects two clients. 2. PackageManager has changed to use resultEquals() instead of maybeCheckConsistency(). This provides a simpler and more consistent use of the APIs. maybeCheckConsistency() has been made private. Test: atest PropertyInvalidatedCacheTests Change-Id: I4110f8e887a4fd8c784141e8892557a9d1b80a94 --- core/java/android/app/PropertyInvalidatedCache.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'core/java/android/app/PropertyInvalidatedCache.java') diff --git a/core/java/android/app/PropertyInvalidatedCache.java b/core/java/android/app/PropertyInvalidatedCache.java index ef4d7b1f42e2..978160c1c243 100644 --- a/core/java/android/app/PropertyInvalidatedCache.java +++ b/core/java/android/app/PropertyInvalidatedCache.java @@ -505,13 +505,13 @@ public abstract class PropertyInvalidatedCache { * block. If this function returns null, the result of the cache query is null. There is no * "negative cache" in the query: we don't cache null results at all. */ - protected abstract Result recompute(Query query); + public abstract Result recompute(Query query); /** * Return true if the query should bypass the cache. The default behavior is to * always use the cache but the method can be overridden for a specific class. */ - protected boolean bypass(Query query) { + public boolean bypass(Query query) { return false; } @@ -519,7 +519,7 @@ public abstract class PropertyInvalidatedCache { * Determines if a pair of responses are considered equal. Used to determine whether * a cache is inadvertently returning stale results when VERIFY is set to true. */ - protected boolean debugCompareQueryResults(Result cachedResult, Result fetchedResult) { + protected boolean resultEquals(Result cachedResult, Result fetchedResult) { // If a service crashes and returns a null result, the cached value remains valid. if (fetchedResult != null) { return Objects.equals(cachedResult, fetchedResult); @@ -990,11 +990,11 @@ public abstract class PropertyInvalidatedCache { } } - protected Result maybeCheckConsistency(Query query, Result proposedResult) { + private Result maybeCheckConsistency(Query query, Result proposedResult) { if (VERIFY) { Result resultToCompare = recompute(query); boolean nonceChanged = (getCurrentNonce() != mLastSeenNonce); - if (!nonceChanged && !debugCompareQueryResults(proposedResult, resultToCompare)) { + if (!nonceChanged && !resultEquals(proposedResult, resultToCompare)) { Log.e(TAG, TextUtils.formatSimple( "cache %s inconsistent for %s is %s should be %s", cacheName(), queryToString(query), -- cgit v1.2.3