From 75d67f5d83bdb28c6254cf064d09ac24fc9ae928 Mon Sep 17 00:00:00 2001 From: linyuh Date: Tue, 12 Dec 2017 13:43:26 -0800 Subject: BEGIN_PUBLIC Automated rollback of changelist 172683494 Bug: 30225112 Test: None PiperOrigin-RevId: 178807986 Change-Id: I45978ea4daab71985ac93c3c3a0439fdd8e873d5 --- .../dialer/phonenumberutil/PhoneNumberHelper.java | 76 ++++++++-------------- 1 file changed, 28 insertions(+), 48 deletions(-) (limited to 'java/com/android/dialer/phonenumberutil') diff --git a/java/com/android/dialer/phonenumberutil/PhoneNumberHelper.java b/java/com/android/dialer/phonenumberutil/PhoneNumberHelper.java index 783e04d7b..e32ace59e 100644 --- a/java/com/android/dialer/phonenumberutil/PhoneNumberHelper.java +++ b/java/com/android/dialer/phonenumberutil/PhoneNumberHelper.java @@ -37,7 +37,6 @@ import com.android.dialer.phonenumbergeoutil.PhoneNumberGeoUtilComponent; import com.android.dialer.telecom.TelecomUtil; import java.util.Arrays; import java.util.HashSet; -import java.util.Objects; import java.util.Set; public class PhoneNumberHelper { @@ -54,46 +53,7 @@ public class PhoneNumberHelper { } /** - * Compare two phone numbers, return true if they're identical enough for caller ID purposes. This - * is an enhanced version of {@link PhoneNumberUtils#compare(String, String)}. - * - *

The two phone numbers are considered "identical enough" if - * - *

- * - * The raw number of a phone number is obtained by first translating any alphabetic letters - * ([A-Za-z]) into the equivalent numeric digits and then removing all separators. See {@link - * PhoneNumberUtils#convertKeypadLettersToDigits(String)} and {@link - * PhoneNumberUtils#stripSeparators(String)}. - */ - public static boolean compare(@Nullable String number1, @Nullable String number2) { - if (number1 == null || number2 == null) { - return Objects.equals(number1, number2); - } - - String rawNumber1 = - PhoneNumberUtils.stripSeparators(PhoneNumberUtils.convertKeypadLettersToDigits(number1)); - String rawNumber2 = - PhoneNumberUtils.stripSeparators(PhoneNumberUtils.convertKeypadLettersToDigits(number2)); - - return PhoneNumberUtils.isGlobalPhoneNumber(rawNumber1) - && PhoneNumberUtils.isGlobalPhoneNumber(rawNumber2) - ? PhoneNumberUtils.compare(rawNumber1, rawNumber2) - : rawNumber1.equals(rawNumber2); - } - - /** - * Find the cursor pointing to the row in which a number is identical enough to the number in a - * contact lookup URI. - * - *

See the description of {@link PhoneNumberHelper#compare(String, String)} for the definition - * of "identical enough". + * Find the cursor pointing to a number that matches the number in a contact lookup URI. * *

When determining whether two phone numbers are identical enough for caller ID purposes, the * Contacts Provider uses {@link PhoneNumberUtils#compare(String, String)}, which ignores special @@ -101,17 +61,25 @@ public class PhoneNumberHelper { * 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, - * {@link PhoneNumberHelper#compare(String, String)}, which is an enhanced version of {@link - * PhoneNumberUtils#compare(String, String)}, is employed to find a match. + * 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 {@link + * PhoneNumberUtils#isGlobalPhoneNumber(String)}) and the lookup number in the URI is a PARTIAL + * match, return the cursor. + * + *

If the cursor points to a number that is not a global phone number, return the cursor iff + * the lookup number in the URI is an EXACT match. + * + *

Return null in all other circumstances. * * @param cursor A cursor returned by the Contacts Provider. * @param columnIndexForNumber The index of the column where phone numbers are stored. It is the * caller's responsibility to pass the correct column index. * @param contactLookupUri A URI used to retrieve a contact via the Contacts Provider. It is the * caller's responsibility to ensure the URI is one that asks for a specific phone number. - * @return The cursor pointing to the row in which the number is considered a match by the - * description above or null if no such cursor can be found. + * @return The cursor considered as a match by the description above or null if no such cursor can + * be found. */ public static Cursor getCursorMatchForContactLookupUri( Cursor cursor, int columnIndexForNumber, Uri contactLookupUri) { @@ -131,10 +99,22 @@ public class PhoneNumberHelper { return null; } + boolean isMatchFound; do { - String existingContactNumber = cursor.getString(columnIndexForNumber); + // All undialable characters should be converted/removed before comparing the lookup number + // and the existing contact number. + String rawExistingContactNumber = + PhoneNumberUtils.stripSeparators( + PhoneNumberUtils.convertKeypadLettersToDigits( + cursor.getString(columnIndexForNumber))); + String rawQueryNumber = + PhoneNumberUtils.stripSeparators( + PhoneNumberUtils.convertKeypadLettersToDigits(lookupNumber)); - boolean isMatchFound = compare(existingContactNumber, lookupNumber); + isMatchFound = + PhoneNumberUtils.isGlobalPhoneNumber(rawExistingContactNumber) + ? rawExistingContactNumber.contains(rawQueryNumber) + : rawExistingContactNumber.equals(rawQueryNumber); if (isMatchFound) { return cursor; -- cgit v1.2.3