summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/phonenumberutil
diff options
context:
space:
mode:
authorlinyuh <linyuh@google.com>2017-12-12 13:43:26 -0800
committerCopybara-Service <copybara-piper@google.com>2017-12-12 14:34:20 -0800
commit75d67f5d83bdb28c6254cf064d09ac24fc9ae928 (patch)
tree85148446a15528867fba0d7353b024081d9e0a5a /java/com/android/dialer/phonenumberutil
parent02ca4c8b2ec7faabb7a74278d240842a1351264a (diff)
BEGIN_PUBLIC
Automated rollback of changelist 172683494 Bug: 30225112 Test: None PiperOrigin-RevId: 178807986 Change-Id: I45978ea4daab71985ac93c3c3a0439fdd8e873d5
Diffstat (limited to 'java/com/android/dialer/phonenumberutil')
-rw-r--r--java/com/android/dialer/phonenumberutil/PhoneNumberHelper.java76
1 files changed, 28 insertions, 48 deletions
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)}.
- *
- * <p>The two phone numbers are considered "identical enough" if
- *
- * <ul>
- * <li>their corresponding raw numbers are both global phone numbers (i.e., they can be accepted
- * by {@link PhoneNumberUtils#isGlobalPhoneNumber(String)}) and {@link
- * PhoneNumberUtils#compare(String, String)} deems them as "identical enough"; OR
- * <li>at least one of the raw numbers is not a global phone number and the two raw numbers are
- * exactly the same.
- * </ul>
- *
- * 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.
- *
- * <p>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.
*
* <p>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.
*
* <p>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.
+ *
+ * <p>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.
+ *
+ * <p>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.
+ *
+ * <p>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;