summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/oem
diff options
context:
space:
mode:
authorlinyuh <linyuh@google.com>2018-04-26 20:21:01 -0700
committerCopybara-Service <copybara-piper@google.com>2018-04-26 20:39:04 -0700
commitfa3cd3bfb14f4b8ac65c0ee6757bc78b40a73573 (patch)
tree103f1b46b7e581ccd2be82860b19fc3562bdb3c2 /java/com/android/dialer/oem
parentc87f1fbc35dcb19ed598008a88997e6547a1caca (diff)
Implement CequintPhoneLookup
Bug: 70989584 Test: CequintPhoneLookupTest PiperOrigin-RevId: 194493484 Change-Id: I59f9b334f0a218e7ba1c34948db4ddbf11490df3
Diffstat (limited to 'java/com/android/dialer/oem')
-rw-r--r--java/com/android/dialer/oem/CequintCallerIdManager.java113
1 files changed, 69 insertions, 44 deletions
diff --git a/java/com/android/dialer/oem/CequintCallerIdManager.java b/java/com/android/dialer/oem/CequintCallerIdManager.java
index 55cafc15e..53f5352b2 100644
--- a/java/com/android/dialer/oem/CequintCallerIdManager.java
+++ b/java/com/android/dialer/oem/CequintCallerIdManager.java
@@ -24,6 +24,7 @@ import android.os.Build.VERSION_CODES;
import android.support.annotation.AnyThread;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
+import android.support.annotation.VisibleForTesting;
import android.support.annotation.WorkerThread;
import android.telephony.PhoneNumberUtils;
import android.text.TextUtils;
@@ -45,7 +46,8 @@ import java.util.concurrent.ConcurrentHashMap;
@TargetApi(VERSION_CODES.N)
public class CequintCallerIdManager {
- private static final String CONFIG_CALLER_ID_ENABLED = "config_caller_id_enabled";
+ @VisibleForTesting
+ public static final String CONFIG_CALLER_ID_ENABLED = "config_caller_id_enabled";
private static final int CALLER_ID_LOOKUP_USER_PROVIDED_CID = 0x0001;
private static final int CALLER_ID_LOOKUP_SYSTEM_PROVIDED_CID = 0x0002;
@@ -53,36 +55,43 @@ public class CequintCallerIdManager {
private static final String[] EMPTY_PROJECTION = new String[] {};
- // Column names in Cequint provider.
- private static final String CITY_NAME = "cid_pCityName";
- private static final String STATE_NAME = "cid_pStateName";
- private static final String STATE_ABBR = "cid_pStateAbbr";
- private static final String COUNTRY_NAME = "cid_pCountryName";
- private static final String COMPANY = "cid_pCompany";
- private static final String NAME = "cid_pName";
- private static final String FIRST_NAME = "cid_pFirstName";
- private static final String LAST_NAME = "cid_pLastName";
- private static final String IMAGE = "cid_pLogo";
- private static final String DISPLAY_NAME = "cid_pDisplayName";
+ /** Column names in Cequint content provider. */
+ @VisibleForTesting
+ public static final class CequintColumnNames {
+ public static final String CITY_NAME = "cid_pCityName";
+ public static final String STATE_NAME = "cid_pStateName";
+ public static final String STATE_ABBR = "cid_pStateAbbr";
+ public static final String COUNTRY_NAME = "cid_pCountryName";
+ public static final String COMPANY = "cid_pCompany";
+ public static final String NAME = "cid_pName";
+ public static final String FIRST_NAME = "cid_pFirstName";
+ public static final String LAST_NAME = "cid_pLastName";
+ public static final String PHOTO_URI = "cid_pLogo";
+ public static final String DISPLAY_NAME = "cid_pDisplayName";
+ }
private static boolean hasAlreadyCheckedCequintCallerIdPackage;
private static String cequintProviderAuthority;
- // TODO(wangqi): Revisit it and maybe remove it if it's not necessary.
- private final ConcurrentHashMap<String, CequintCallerIdContact> callLogCache;
+ // TODO(a bug): Revisit it and maybe remove it if it's not necessary.
+ private final ConcurrentHashMap<String, CequintCallerIdContact> callLogCache =
+ new ConcurrentHashMap<>();
/** Cequint caller ID contact information. */
@AutoValue
public abstract static class CequintCallerIdContact {
+ @Nullable
public abstract String name();
/**
* Description of the geolocation (e.g., "Mountain View, CA"), which is for display purpose
* only.
*/
+ @Nullable
public abstract String geolocation();
+ @Nullable
public abstract String photoUri();
static Builder builder() {
@@ -91,11 +100,11 @@ public class CequintCallerIdManager {
@AutoValue.Builder
abstract static class Builder {
- abstract Builder setName(String name);
+ abstract Builder setName(@Nullable String name);
- abstract Builder setGeolocation(String geolocation);
+ abstract Builder setGeolocation(@Nullable String geolocation);
- abstract Builder setPhotoUri(String photoUri);
+ abstract Builder setPhotoUri(@Nullable String photoUri);
abstract CequintCallerIdContact build();
}
@@ -125,17 +134,14 @@ public class CequintCallerIdManager {
return cequintProviderAuthority != null;
}
- public static CequintCallerIdManager createInstanceForCallLog() {
- return new CequintCallerIdManager();
- }
-
+ /** Returns a {@link CequintCallerIdContact} for a call. */
@WorkerThread
@Nullable
- public static CequintCallerIdContact getCequintCallerIdContactForInCall(
+ public static CequintCallerIdContact getCequintCallerIdContactForCall(
Context context, String number, String cnapName, boolean isIncoming) {
Assert.isWorkerThread();
LogUtil.d(
- "CequintCallerIdManager.getCequintCallerIdContactForInCall",
+ "CequintCallerIdManager.getCequintCallerIdContactForCall",
"number: %s, cnapName: %s, isIncoming: %b",
LogUtil.sanitizePhoneNumber(number),
LogUtil.sanitizePii(cnapName),
@@ -151,29 +157,51 @@ public class CequintCallerIdManager {
return lookup(context, getIncallLookupUri(), number, flags);
}
+ /**
+ * Returns a cached {@link CequintCallerIdContact} associated with the provided number. If no
+ * contact can be found in the cache, look up the number using the Cequint content provider.
+ *
+ * @deprecated This method is for the old call log only. New code should use {@link
+ * #getCequintCallerIdContactForNumber(Context, String)}.
+ */
+ @Deprecated
@WorkerThread
@Nullable
- public CequintCallerIdContact getCequintCallerIdContact(Context context, String number) {
+ public CequintCallerIdContact getCachedCequintCallerIdContact(Context context, String number) {
Assert.isWorkerThread();
LogUtil.d(
- "CequintCallerIdManager.getCequintCallerIdContact",
+ "CequintCallerIdManager.getCachedCequintCallerIdContact",
"number: %s",
LogUtil.sanitizePhoneNumber(number));
if (callLogCache.containsKey(number)) {
return callLogCache.get(number);
}
CequintCallerIdContact cequintCallerIdContact =
- lookup(
- context,
- getLookupUri(),
- PhoneNumberUtils.stripSeparators(number),
- new String[] {"system"});
+ getCequintCallerIdContactForNumber(context, number);
if (cequintCallerIdContact != null) {
callLogCache.put(number, cequintCallerIdContact);
}
return cequintCallerIdContact;
}
+ /**
+ * Returns a {@link CequintCallerIdContact} associated with the provided number by looking it up
+ * using the Cequint content provider.
+ */
+ @WorkerThread
+ @Nullable
+ public static CequintCallerIdContact getCequintCallerIdContactForNumber(
+ Context context, String number) {
+ Assert.isWorkerThread();
+ LogUtil.d(
+ "CequintCallerIdManager.getCequintCallerIdContactForNumber",
+ "number: %s",
+ LogUtil.sanitizePhoneNumber(number));
+
+ return lookup(
+ context, getLookupUri(), PhoneNumberUtils.stripSeparators(number), new String[] {"system"});
+ }
+
@WorkerThread
@Nullable
private static CequintCallerIdContact lookup(
@@ -185,16 +213,17 @@ public class CequintCallerIdManager {
try (Cursor cursor =
context.getContentResolver().query(uri, EMPTY_PROJECTION, number, flags, null)) {
if (cursor != null && cursor.moveToFirst()) {
- String city = getString(cursor, cursor.getColumnIndex(CITY_NAME));
- String state = getString(cursor, cursor.getColumnIndex(STATE_NAME));
- String stateAbbr = getString(cursor, cursor.getColumnIndex(STATE_ABBR));
- String country = getString(cursor, cursor.getColumnIndex(COUNTRY_NAME));
- String company = getString(cursor, cursor.getColumnIndex(COMPANY));
- String name = getString(cursor, cursor.getColumnIndex(NAME));
- String firstName = getString(cursor, cursor.getColumnIndex(FIRST_NAME));
- String lastName = getString(cursor, cursor.getColumnIndex(LAST_NAME));
- String photoUri = getString(cursor, cursor.getColumnIndex(IMAGE));
- String displayName = getString(cursor, cursor.getColumnIndex(DISPLAY_NAME));
+ String city = getString(cursor, cursor.getColumnIndex(CequintColumnNames.CITY_NAME));
+ String state = getString(cursor, cursor.getColumnIndex(CequintColumnNames.STATE_NAME));
+ String stateAbbr = getString(cursor, cursor.getColumnIndex(CequintColumnNames.STATE_ABBR));
+ String country = getString(cursor, cursor.getColumnIndex(CequintColumnNames.COUNTRY_NAME));
+ String company = getString(cursor, cursor.getColumnIndex(CequintColumnNames.COMPANY));
+ String name = getString(cursor, cursor.getColumnIndex(CequintColumnNames.NAME));
+ String firstName = getString(cursor, cursor.getColumnIndex(CequintColumnNames.FIRST_NAME));
+ String lastName = getString(cursor, cursor.getColumnIndex(CequintColumnNames.LAST_NAME));
+ String photoUri = getString(cursor, cursor.getColumnIndex(CequintColumnNames.PHOTO_URI));
+ String displayName =
+ getString(cursor, cursor.getColumnIndex(CequintColumnNames.DISPLAY_NAME));
String contactName =
TextUtils.isEmpty(displayName)
@@ -293,8 +322,4 @@ public class CequintCallerIdManager {
private static Uri getIncallLookupUri() {
return Uri.parse("content://" + cequintProviderAuthority + "/incalllookup");
}
-
- private CequintCallerIdManager() {
- callLogCache = new ConcurrentHashMap<>();
- }
}