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

Commit 89125443 authored by Tim Murray's avatar Tim Murray
Browse files

NotificationManagerService: check cache before checking contacts

In case a contact has been added to the cache before the future runs
its work, check the cache before querying the contact.

Test: atest com.android.server.notification.ValidateNotificationPeopleTest
Bug: 161866124
Change-Id: I9c59a934952e4dc3cce1f99e905603cd357b9dbc
parent abffa29b
Loading
Loading
Loading
Loading
+29 −18
Original line number Diff line number Diff line
@@ -523,7 +523,17 @@ public class ValidateNotificationPeople implements NotificationSignalExtractor {
            if (VERBOSE) Slog.i(TAG, "Executing: validation for: " + mKey);
            long timeStartMs = System.currentTimeMillis();
            for (final String handle: mPendingLookups) {
                final String cacheKey = getCacheKey(mContext.getUserId(), handle);
                LookupResult lookupResult = null;
                boolean cacheHit = false;
                synchronized (mPeopleCache) {
                    lookupResult = mPeopleCache.get(cacheKey);
                    if (lookupResult != null && !lookupResult.isExpired()) {
                        // The name wasn't already added to the cache, no need to retry
                        cacheHit = true;
                    }
                }
                if (!cacheHit) {
                    final Uri uri = Uri.parse(handle);
                    if ("tel".equals(uri.getScheme())) {
                        if (DEBUG) Slog.d(TAG, "checking telephone URI: " + handle);
@@ -540,11 +550,13 @@ public class ValidateNotificationPeople implements NotificationSignalExtractor {
                            Slog.w(TAG, "unsupported URI " + handle);
                        }
                    }
                }
                if (lookupResult != null) {
                    if (!cacheHit) {
                        synchronized (mPeopleCache) {
                        final String cacheKey = getCacheKey(mContext.getUserId(), handle);
                            mPeopleCache.put(cacheKey, lookupResult);
                        }
                    }
                    if (DEBUG) {
                        Slog.d(TAG, "lookup contactAffinity is " + lookupResult.getAffinity());
                    }
@@ -580,4 +592,3 @@ public class ValidateNotificationPeople implements NotificationSignalExtractor {
        }
    }
}