Change blocked id cache to static.

This "shares" the cache among multiple instances of call log
fragment. This allows "clearing" the cache to propagate changes
across all instances. This should also have the side benefit
of fewer lookups.

~ Change to use ConcurrentHashMap, since it can now be accessed by
multiple call log fragments.
~ Do a little footwork with conversion, since ConcurrentHashMap
does not accept null values.

Bug: 25369105
Change-Id: Id21d1f6a18017c8e0bca88e57f09c9b4b173b843
diff --git a/src/com/android/dialer/calllog/CallLogAdapter.java b/src/com/android/dialer/calllog/CallLogAdapter.java
index d846c65..7999ee0 100644
--- a/src/com/android/dialer/calllog/CallLogAdapter.java
+++ b/src/com/android/dialer/calllog/CallLogAdapter.java
@@ -56,6 +56,7 @@
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * Adapter class to fill in data for the Call Log.
@@ -71,6 +72,8 @@
     }
 
     private static final int NO_EXPANDED_LIST_ITEM = -1;
+    // ConcurrentHashMap doesn't store null values. Use this value for numbers which aren't blocked.
+    private static final int NOT_BLOCKED = -1;
 
     private static final int VOICEMAIL_PROMO_CARD_POSITION = 0;
 
@@ -91,7 +94,10 @@
     private final FilteredNumberAsyncQueryHandler mFilteredNumberAsyncQueryHandler;
 
     protected ContactInfoCache mContactInfoCache;
-    protected final Map<NumberWithCountryIso, Integer> mBlockedIdCache;
+    // Declaring static, since this can be shared across different instances, such as history and
+    // voicemail, so when the cache is cleared in one instance, it propagates across all instances.
+    private static final Map<NumberWithCountryIso, Integer> mBlockedIdCache =
+            new ConcurrentHashMap<>();
 
     private boolean mIsCallLogActivity;
 
@@ -257,7 +263,6 @@
         CallTypeHelper callTypeHelper = new CallTypeHelper(resources);
 
         mTelecomCallLogCache = new TelecomCallLogCache(mContext);
-        mBlockedIdCache = new HashMap<>();
         PhoneCallDetailsHelper phoneCallDetailsHelper =
                 new PhoneCallDetailsHelper(mContext, resources, mTelecomCallLogCache);
         mCallLogListItemHelper =
@@ -516,7 +521,8 @@
         // Update the photo, once we know whether the user's number is blocked or not.
         final NumberWithCountryIso blockedIdKey = new NumberWithCountryIso(number, countryIso);
         if (mBlockedIdCache.containsKey(blockedIdKey)) {
-            views.blockId = mBlockedIdCache.get(blockedIdKey);
+            int blockedId = mBlockedIdCache.get(blockedIdKey);
+            views.blockId = blockedId != NOT_BLOCKED ? blockedId : null;
             views.updatePhoto();
         } else {
             views.blockId = null;
@@ -524,7 +530,7 @@
                         new OnCheckBlockedListener() {
                     @Override
                     public void onCheckComplete(Integer id) {
-                        mBlockedIdCache.put(blockedIdKey, id);
+                        mBlockedIdCache.put(blockedIdKey, id != null ? id : NOT_BLOCKED);
                         views.blockId = id;
                         views.updatePhoto();
                     }