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
diff --git a/java/com/android/incallui/CallerInfo.java b/java/com/android/incallui/CallerInfo.java
index 5c43b4f..d3b12c1 100644
--- a/java/com/android/incallui/CallerInfo.java
+++ b/java/com/android/incallui/CallerInfo.java
@@ -223,18 +223,28 @@
long contactId = 0L;
int columnIndex;
+ // Look for the number
+ columnIndex = cursor.getColumnIndex(PhoneLookup.NUMBER);
+ if (columnIndex != -1) {
+ // 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 name
columnIndex = cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME);
if (columnIndex != -1) {
info.name = normalize(cursor.getString(columnIndex));
}
- // Look for the number
- columnIndex = cursor.getColumnIndex(PhoneLookup.NUMBER);
- if (columnIndex != -1) {
- info.phoneNumber = cursor.getString(columnIndex);
- }
-
// Look for the normalized number
columnIndex = cursor.getColumnIndex(PhoneLookup.NORMALIZED_NUMBER);
if (columnIndex != -1) {