From 2d5167b475d64b4bad0f0cde2508bca55c4b7643 Mon Sep 17 00:00:00 2001 From: linyuh Date: Thu, 14 Dec 2017 12:34:31 -0800 Subject: Take into consideration special characters when we do contact match. Bug: 30225112 Test: CallLogGroupBuilderTest, PhoneNumberHelperTest, CallerInfoTest, and Manual (see demo) PiperOrigin-RevId: 179080046 Change-Id: I8e451a6c197a6c3df4260e58d0276a5dc5b9515a --- java/com/android/incallui/CallerInfo.java | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'java/com/android/incallui') diff --git a/java/com/android/incallui/CallerInfo.java b/java/com/android/incallui/CallerInfo.java index 5c43b4f39..d3b12c158 100644 --- a/java/com/android/incallui/CallerInfo.java +++ b/java/com/android/incallui/CallerInfo.java @@ -223,16 +223,26 @@ public class CallerInfo { long contactId = 0L; int columnIndex; - // Look for the name - columnIndex = cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME); + // Look for the number + columnIndex = cursor.getColumnIndex(PhoneLookup.NUMBER); if (columnIndex != -1) { - info.name = normalize(cursor.getString(columnIndex)); + // The Contacts provider ignores special characters in phone numbers when searching for a + // contact. For example, number "123" is considered a match with a contact with number "#123". + // We need to check whether the result contains a number that truly matches the query and move + // the cursor to that position before filling in the fields in CallerInfo. + boolean hasNumberMatch = + PhoneNumberHelper.updateCursorToMatchContactLookupUri(cursor, columnIndex, contactRef); + if (hasNumberMatch) { + info.phoneNumber = cursor.getString(columnIndex); + } else { + return info; + } } - // Look for the number - columnIndex = cursor.getColumnIndex(PhoneLookup.NUMBER); + // Look for the name + columnIndex = cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME); if (columnIndex != -1) { - info.phoneNumber = cursor.getString(columnIndex); + info.name = normalize(cursor.getString(columnIndex)); } // Look for the normalized number -- cgit v1.2.3