summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Lee <anwlee@google.com>2015-09-04 14:00:47 -0700
committerAndrew Lee <anwlee@google.com>2015-09-09 11:04:21 -0700
commitf4e59f5e600e768db2e36f379fd95444a0d6f802 (patch)
treeff05b07e824ea343e230df1a74b06e0f8cdd243f
parent2d3b34d2392f9a4e8a5c87d8148a0892659a7df6 (diff)
Fuzzy match phone number for contact lookup.
In some countries, it appears that the country code received is not always accurate to what we would expect (carrier kerfluffery?), so don't do a lookup with the normalized phone number. This is consistent with the logic we have been using for InCallUi. Bug: 23822088 Change-Id: I2c7ede596cbb8a2e5c4a3a35d04ca78e62767bcc
-rw-r--r--src/com/android/dialer/calllog/ContactInfoHelper.java71
1 files changed, 19 insertions, 52 deletions
diff --git a/src/com/android/dialer/calllog/ContactInfoHelper.java b/src/com/android/dialer/calllog/ContactInfoHelper.java
index 2e07a03b1..2f97bc569 100644
--- a/src/com/android/dialer/calllog/ContactInfoHelper.java
+++ b/src/com/android/dialer/calllog/ContactInfoHelper.java
@@ -75,30 +75,22 @@ public class ContactInfoHelper {
if (TextUtils.isEmpty(number)) {
return null;
}
- final ContactInfo info;
- // Determine the contact info.
+ ContactInfo info;
+
if (PhoneNumberHelper.isUriNumber(number)) {
- // This "number" is really a SIP address.
- ContactInfo sipInfo = queryContactInfoForSipAddress(number);
- if (sipInfo == null || sipInfo == ContactInfo.EMPTY) {
- // Check whether the "username" part of the SIP address is
- // actually the phone number of a contact.
+ // The number is a SIP address..
+ info = lookupContactFromUri(getContactInfoLookupUri(number));
+ if (info == null || info == ContactInfo.EMPTY) {
+ // If lookup failed, check if the "username" of the SIP address is a phone number.
String username = PhoneNumberHelper.getUsernameFromUriNumber(number);
if (PhoneNumberUtils.isGlobalPhoneNumber(username)) {
- sipInfo = queryContactInfoForPhoneNumber(username, countryIso);
+ info = queryContactInfoForPhoneNumber(username, countryIso);
}
}
- info = sipInfo;
} else {
// Look for a contact that has the given phone number.
- ContactInfo phoneInfo = queryContactInfoForPhoneNumber(number, countryIso);
-
- if (phoneInfo == null || phoneInfo == ContactInfo.EMPTY) {
- // Check whether the phone number has been saved as an "Internet call" number.
- phoneInfo = queryContactInfoForSipAddress(number);
- }
- info = phoneInfo;
+ info = queryContactInfoForPhoneNumber(number, countryIso);
}
final ContactInfo updatedInfo;
@@ -201,28 +193,6 @@ public class ContactInfoHelper {
}
/**
- * Determines the contact information for the given SIP address.
- * <p>
- * It returns the contact info if found.
- * <p>
- * If no contact corresponds to the given SIP address, returns {@link ContactInfo#EMPTY}.
- * <p>
- * If the lookup fails for some other reason, it returns null.
- */
- private ContactInfo queryContactInfoForSipAddress(String sipAddress) {
- if (TextUtils.isEmpty(sipAddress)) {
- return null;
- }
- final ContactInfo info;
-
- // "contactNumber" is a SIP address, so use the PhoneLookup table with the SIP parameter.
- Uri.Builder uriBuilder = PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI.buildUpon();
- uriBuilder.appendPath(Uri.encode(sipAddress));
- uriBuilder.appendQueryParameter(PhoneLookup.QUERY_PARAMETER_SIP_ADDRESS, "1");
- return lookupContactFromUri(uriBuilder.build());
- }
-
- /**
* Determines the contact information for the given phone number.
* <p>
* It returns the contact info if found.
@@ -235,21 +205,8 @@ public class ContactInfoHelper {
if (TextUtils.isEmpty(number)) {
return null;
}
- String contactNumber = number;
- if (!TextUtils.isEmpty(countryIso)) {
- // Normalize the number: this is needed because the PhoneLookup query below does not
- // accept a country code as an input.
- String numberE164 = PhoneNumberUtils.formatNumberToE164(number, countryIso);
- if (!TextUtils.isEmpty(numberE164)) {
- // Only use it if the number could be formatted to E164.
- contactNumber = numberE164;
- }
- }
- // The "contactNumber" is a regular phone number, so use the PhoneLookup table.
- Uri uri = Uri.withAppendedPath(PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI,
- Uri.encode(contactNumber));
- ContactInfo info = lookupContactFromUri(uri);
+ ContactInfo info = lookupContactFromUri(getContactInfoLookupUri(number));
if (info != null && info != ContactInfo.EMPTY) {
info.formattedNumber = formatPhoneNumber(number, null, countryIso);
} else if (mCachedNumberLookupService != null) {
@@ -393,6 +350,16 @@ public class ContactInfoHelper {
}
}
+ public static Uri getContactInfoLookupUri(String number) {
+ // Get URI for the number in the PhoneLookup table, with a parameter to indicate whether
+ // the number is a SIP number.
+ return PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI.buildUpon()
+ .appendPath(Uri.encode(number))
+ .appendQueryParameter(PhoneLookup.QUERY_PARAMETER_SIP_ADDRESS,
+ String.valueOf(PhoneNumberHelper.isUriNumber(number)))
+ .build();
+ }
+
/**
* Returns the contact information stored in an entry of the call log.
*