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

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

Modify PropertyInvalidatedCache debugging

Bug: 140788621

There is no change in behavior unless DEBUG or VERIFY are true.
1. Do not log queries to a disabled cache.
2. If verification fails, log the failure and return the correct
   value.  This allows the system to continue running for further
   debug.

Test: Boot the phone with a test image that sets DEBUG and VERIFY
true.  Verified that there are limited messages about a disabled
cache (especially for the package_info cache).  Force verification
failures by removing cache invalidation from UserManager.  Verify
that the cache failures are logged but the system runs normally.

Change-Id: I80c604867a6d879c74ff8f8e8a0be0ac110c6581
parent 7d147cbe
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -296,12 +296,14 @@ public abstract class PropertyInvalidatedCache<Query, Result> {
        for (;;) {
            if (currentNonce == NONCE_DISABLED || currentNonce == NONCE_UNSET) {
                if (DEBUG) {
                    Log.d(TAG,
                            String.format("cache %s %s for %s",
                    if (!mDisabled) {
                        Log.d(TAG, String.format(
                            "cache %s %s for %s",
                            cacheName(),
                            currentNonce == NONCE_DISABLED ? "disabled" : "unset",
                            queryToString(query)));
                    }
                }
                return recompute(query);
            }
            final Result cachedResult;
@@ -450,8 +452,12 @@ public abstract class PropertyInvalidatedCache<Query, Result> {
            Result resultToCompare = recompute(query);
            boolean nonceChanged = (getCurrentNonce() != mLastSeenNonce);
            if (!nonceChanged && !debugCompareQueryResults(proposedResult, resultToCompare)) {
                throw new AssertionError("cache returned out of date response for " + query);
                Log.e(TAG, String.format(
                    "cache %s inconsistent for %s",
                    cacheName(), queryToString(query)));
            }
            // Always return the "true" result in verification mode.
            return resultToCompare;
        }
        return proposedResult;
    }