diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2017-08-31 16:17:04 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-08-31 16:17:04 +0000 |
commit | c39ea3c55fac807c0b98aabdf56c70dc8a49036c (patch) | |
tree | e282668a9587cf6c1ec7b604dea860400c75c6c7 /java/com/android/dialer/oem/CequintCallerIdManager.java | |
parent | 68038172793ee0e2ab3e2e56ddfbeb82879d1f58 (diff) | |
parent | 2ca4318cc1ee57dda907ba2069bd61d162b1baef (diff) |
Merge "Update Dialer source to latest internal Google revision."
Diffstat (limited to 'java/com/android/dialer/oem/CequintCallerIdManager.java')
-rw-r--r-- | java/com/android/dialer/oem/CequintCallerIdManager.java | 100 |
1 files changed, 28 insertions, 72 deletions
diff --git a/java/com/android/dialer/oem/CequintCallerIdManager.java b/java/com/android/dialer/oem/CequintCallerIdManager.java index 095ee4e66..7b6ddbc3a 100644 --- a/java/com/android/dialer/oem/CequintCallerIdManager.java +++ b/java/com/android/dialer/oem/CequintCallerIdManager.java @@ -18,7 +18,6 @@ package com.android.dialer.oem; import android.annotation.TargetApi; import android.content.Context; import android.content.pm.PackageManager; -import android.database.ContentObserver; import android.database.Cursor; import android.net.Uri; import android.os.Build.VERSION_CODES; @@ -29,9 +28,8 @@ import android.support.annotation.WorkerThread; import android.telephony.PhoneNumberUtils; import android.text.TextUtils; import com.android.dialer.common.Assert; -import com.android.dialer.common.ConfigProviderBindings; import com.android.dialer.common.LogUtil; -import com.android.dialer.util.PermissionsUtil; +import com.android.dialer.configprovider.ConfigProviderBindings; import java.util.concurrent.ConcurrentHashMap; /** @@ -73,17 +71,12 @@ public class CequintCallerIdManager { private static final String IMAGE = "cid_pLogo"; private static final String DISPLAY_NAME = "cid_pDisplayName"; - // TODO: Revisit it and maybe remove it if it's not necessary. - private static final ConcurrentHashMap<String, CequintCallerIdContact> callLogCache = - new ConcurrentHashMap<>(); - private static final ConcurrentHashMap<String, CequintCallerIdContact> incallIncomingCallCache = - new ConcurrentHashMap<>(); - private static final ConcurrentHashMap<String, CequintCallerIdContact> incallOutgoingCallCache = - new ConcurrentHashMap<>(); - private static boolean hasRegisteredContentObserver; private static boolean hasAlreadyCheckedCequintCallerIdPackage; private static boolean isCequintCallerIdEnabled; + // TODO(wangqi): Revisit it and maybe remove it if it's not necessary. + private final ConcurrentHashMap<String, CequintCallerIdContact> callLogCache; + /** Cequint caller id contact information. */ public static class CequintCallerIdContact { public final String name; @@ -117,27 +110,8 @@ public class CequintCallerIdManager { return isCequintCallerIdEnabled; } - @WorkerThread - @Nullable - public static CequintCallerIdContact getCequintCallerIdContact(Context context, String number) { - Assert.isWorkerThread(); - LogUtil.d( - "CequintCallerIdManager.getCequintCallerIdContact", - "number: %s", - LogUtil.sanitizePhoneNumber(number)); - if (callLogCache.containsKey(number)) { - return callLogCache.get(number); - } - CequintCallerIdContact cequintCallerIdContact = - lookup( - context, - CONTENT_URI, - PhoneNumberUtils.stripSeparators(number), - new String[] {"system"}); - if (cequintCallerIdContact != null) { - callLogCache.put(number, cequintCallerIdContact); - } - return cequintCallerIdContact; + public static CequintCallerIdManager createInstanceForCallLog() { + return new CequintCallerIdManager(); } @WorkerThread @@ -151,12 +125,6 @@ public class CequintCallerIdManager { LogUtil.sanitizePhoneNumber(number), LogUtil.sanitizePii(cnapName), isIncoming); - registerContentObserver(context); - if (isIncoming && incallIncomingCallCache.containsKey(number)) { - return incallIncomingCallCache.get(number); - } else if (!isIncoming && incallOutgoingCallCache.containsKey(number)) { - return incallOutgoingCallCache.get(number); - } int flag = 0; if (isIncoming) { flag |= CALLER_ID_LOOKUP_INCOMING_CALL; @@ -165,14 +133,28 @@ public class CequintCallerIdManager { flag |= CALLER_ID_LOOKUP_USER_PROVIDED_CID; } String[] flags = {cnapName, String.valueOf(flag)}; + return lookup(context, CONTENT_URI_FOR_INCALL, number, flags); + } + + @WorkerThread + @Nullable + public CequintCallerIdContact getCequintCallerIdContact(Context context, String number) { + Assert.isWorkerThread(); + LogUtil.d( + "CequintCallerIdManager.getCequintCallerIdContact", + "number: %s", + LogUtil.sanitizePhoneNumber(number)); + if (callLogCache.containsKey(number)) { + return callLogCache.get(number); + } CequintCallerIdContact cequintCallerIdContact = - lookup(context, CONTENT_URI_FOR_INCALL, number, flags); + lookup( + context, + CONTENT_URI, + PhoneNumberUtils.stripSeparators(number), + new String[] {"system"}); if (cequintCallerIdContact != null) { - if (isIncoming) { - incallIncomingCallCache.put(number, cequintCallerIdContact); - } else { - incallOutgoingCallCache.put(number, cequintCallerIdContact); - } + callLogCache.put(number, cequintCallerIdContact); } return cequintCallerIdContact; } @@ -285,33 +267,7 @@ public class CequintCallerIdManager { return geoDescription; } - private static synchronized void registerContentObserver(Context context) { - if (!PermissionsUtil.hasCequintPermissions(context)) { - LogUtil.i("CequintCallerIdManager.registerContentObserver", "no cequint permissions"); - return; - } - - if (hasRegisteredContentObserver) { - return; - } - ContentObserver contentObserver = - new ContentObserver(null) { - @Override - public void onChange(boolean selfChange) { - invalidateCache(); - } - }; - - context - .getContentResolver() - .registerContentObserver(CONTENT_URI_FOR_INCALL, true, contentObserver); - hasRegisteredContentObserver = true; - } - - private static void invalidateCache() { - incallIncomingCallCache.clear(); - incallOutgoingCallCache.clear(); + private CequintCallerIdManager() { + callLogCache = new ConcurrentHashMap<>(); } - - private CequintCallerIdManager() {} } |