summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Lee <anwlee@google.com>2015-10-29 10:55:44 -0700
committerAndrew Lee <anwlee@google.com>2015-10-30 15:44:10 -0700
commitdfc69c43df7c46fb6f059c3ac7f61badd2a4b820 (patch)
tree5b955e3572a5a38a0c16b6184821e1ec9e99e210
parent72579fe971e0a0c3711438e8852d9659f48101c8 (diff)
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
-rw-r--r--src/com/android/dialer/calllog/CallLogAdapter.java14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/com/android/dialer/calllog/CallLogAdapter.java b/src/com/android/dialer/calllog/CallLogAdapter.java
index d846c654d..7999ee0f5 100644
--- a/src/com/android/dialer/calllog/CallLogAdapter.java
+++ b/src/com/android/dialer/calllog/CallLogAdapter.java
@@ -56,6 +56,7 @@ import com.android.dialer.voicemail.VoicemailPlaybackPresenter;
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 @@ public class CallLogAdapter extends GroupingListAdapter
}
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 @@ public class CallLogAdapter extends GroupingListAdapter
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 @@ public class CallLogAdapter extends GroupingListAdapter
CallTypeHelper callTypeHelper = new CallTypeHelper(resources);
mTelecomCallLogCache = new TelecomCallLogCache(mContext);
- mBlockedIdCache = new HashMap<>();
PhoneCallDetailsHelper phoneCallDetailsHelper =
new PhoneCallDetailsHelper(mContext, resources, mTelecomCallLogCache);
mCallLogListItemHelper =
@@ -516,7 +521,8 @@ public class CallLogAdapter extends GroupingListAdapter
// 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 @@ public class CallLogAdapter extends GroupingListAdapter
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();
}