summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/phonenumbercache
diff options
context:
space:
mode:
authorlinyuh <linyuh@google.com>2017-10-17 13:31:27 -0700
committerEric Erfanian <erfanian@google.com>2017-10-17 22:45:59 +0000
commit6f78d935ff64f178e9fe8891082c18578d4e4b74 (patch)
tree8bb6b163a88cf321073913c2b0b7dad5ecbd854e /java/com/android/dialer/phonenumbercache
parent68cc4733e1619e1b6b7f6d5f52ab057cc48525bb (diff)
Stop showing partially matched numbers that are not global phone numbers.
When determining whether two phone numbers are identical enough for caller ID purposes, the Contacts Provider ignores special dialable characters such as '#', '*', '+', etc. This makes it possible for the cursor returned by the Contacts Provider to have multiple rows even when the URI asks for a specific number. For example, suppose the user has two contacts whose numbers are "#123" and "123", respectively. When the URI asks for number "123", both numbers will be returned. Therefore, the following strategy is employed to find a match. If the cursor points to a global phone number (i.e., a number that can be accepted by PhoneNumberUtils#isGlobalPhoneNumber(String)) and the lookup number in the URI is a PARTIAL match, the cursor is a match. If the cursor points to a number that is not a global phone number, the cursor is a match iff the lookup number in the URI is an EXACT match. There is no matched cursor in all other circumstances. UI demo: Suppose the user has a contact named "Service1" with number "#123". Before: Incall UI after the user dials "123": https://photos.app.goo.gl/xFWCD4qy2VR3YEuJ2 Call log UI after the call ends: https://photos.app.goo.gl/FT28GdTBy1dtANtI2 After: Incall UI after the user dials "123": https://photos.app.goo.gl/Io3BisQmsyfnvitV2 Call log UI after the call ends: https://photos.app.goo.gl/6GgRrmx75yUTga3B3 Bug: 30225112 Test: PhoneNumberHelperTest PiperOrigin-RevId: 172505648 Change-Id: Ida554313455ff9ce40432897681f89f58d64af04
Diffstat (limited to 'java/com/android/dialer/phonenumbercache')
-rw-r--r--java/com/android/dialer/phonenumbercache/ContactInfoHelper.java36
1 files changed, 18 insertions, 18 deletions
diff --git a/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java b/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java
index b680bd57d..f501792f9 100644
--- a/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java
+++ b/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java
@@ -337,30 +337,30 @@ public class ContactInfoHelper {
return ContactInfo.EMPTY;
}
- Cursor phoneLookupCursor = null;
- try {
- String[] projection = PhoneQuery.getPhoneLookupProjection(uri);
- phoneLookupCursor = mContext.getContentResolver().query(uri, projection, null, null, null);
- } catch (NullPointerException e) {
- LogUtil.e("ContactInfoHelper.lookupContactFromUri", "phone lookup", e);
- // Trap NPE from pre-N CP2
- return null;
- }
- if (phoneLookupCursor == null) {
- LogUtil.d("ContactInfoHelper.lookupContactFromUri", "phoneLookupCursor is null");
- return null;
- }
+ try (Cursor phoneLookupCursor =
+ mContext
+ .getContentResolver()
+ .query(uri, PhoneQuery.getPhoneLookupProjection(uri), null, null, null)) {
+ if (phoneLookupCursor == null) {
+ LogUtil.d("ContactInfoHelper.lookupContactFromUri", "phoneLookupCursor is null");
+ return null;
+ }
- try {
if (!phoneLookupCursor.moveToFirst()) {
return ContactInfo.EMPTY;
}
- String lookupKey = phoneLookupCursor.getString(PhoneQuery.LOOKUP_KEY);
- ContactInfo contactInfo = createPhoneLookupContactInfo(phoneLookupCursor, lookupKey);
+
+ Cursor matchedCursor =
+ PhoneNumberHelper.getCursorMatchForContactLookupUri(
+ phoneLookupCursor, PhoneQuery.MATCHED_NUMBER, uri);
+ if (matchedCursor == null) {
+ return ContactInfo.EMPTY;
+ }
+
+ String lookupKey = matchedCursor.getString(PhoneQuery.LOOKUP_KEY);
+ ContactInfo contactInfo = createPhoneLookupContactInfo(matchedCursor, lookupKey);
fillAdditionalContactInfo(mContext, contactInfo);
return contactInfo;
- } finally {
- phoneLookupCursor.close();
}
}