Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 096b7d4a authored by Grace Jia's avatar Grace Jia Committed by Gerrit Code Review
Browse files

Merge "Add new phone number match method."

parents ee022003 6194382d
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -40497,12 +40497,13 @@ package android.telephony {
  public class PhoneNumberUtils {
    ctor public PhoneNumberUtils();
    method public static void addTtsSpan(android.text.Spannable, int, int);
    method public static boolean areSamePhoneNumber(@NonNull String, @NonNull String, @NonNull String);
    method @Deprecated public static String calledPartyBCDFragmentToString(byte[], int, int);
    method public static String calledPartyBCDFragmentToString(byte[], int, int, int);
    method @Deprecated public static String calledPartyBCDToString(byte[], int, int);
    method public static String calledPartyBCDToString(byte[], int, int, int);
    method public static boolean compare(String, String);
    method public static boolean compare(android.content.Context, String, String);
    method @Deprecated public static boolean compare(String, String);
    method @Deprecated public static boolean compare(android.content.Context, String, String);
    method public static String convertKeypadLettersToDigits(String);
    method public static android.text.style.TtsSpan createTtsSpan(String);
    method public static CharSequence createTtsSpannable(CharSequence);
+48 −1
Original line number Diff line number Diff line
@@ -478,7 +478,9 @@ public class PhoneNumberUtils {

    /**
     * Compare phone numbers a and b, return true if they're identical enough for caller ID purposes.
     * @deprecated use {@link #areSamePhoneNumber(String, String, String)} instead
     */
    @Deprecated
    public static boolean compare(String a, String b) {
        // We've used loose comparation at least Eclair, which may change in the future.

@@ -489,7 +491,9 @@ public class PhoneNumberUtils {
     * Compare phone numbers a and b, and return true if they're identical
     * enough for caller ID purposes. Checks a resource to determine whether
     * to use a strict or loose comparison algorithm.
     * @deprecated use {@link #areSamePhoneNumber(String, String, String)} instead
     */
    @Deprecated
    public static boolean compare(Context context, String a, String b) {
        boolean useStrict = context.getResources().getBoolean(
               com.android.internal.R.bool.config_use_strict_phone_number_comparation);
@@ -3254,4 +3258,47 @@ public class PhoneNumberUtils {
        }
        return number;
    }

    /**
     * Determines if two phone numbers are the same.
     * <p>
     * Matching is based on <a href="https://github.com/google/libphonenumber>libphonenumber</a>.
     * Unlike {@link #compare(String, String)}, matching takes into account national
     * dialing plans rather than simply matching the last 7 digits of the two phone numbers. As a
     * result, it is expected that some numbers which would match using the previous method will no
     * longer match using this new approach.
     *
     * @param number1
     * @param number2
     * @param defaultCountryIso The lowercase two letter ISO 3166-1 country code. Used when parsing
     *                          the phone numbers where it is not possible to determine the country
     *                          associated with a phone number based on the number alone. It
     *                          is recommended to pass in
     *                          {@link TelephonyManager#getNetworkCountryIso()}.
     * @return True if the two given phone number are same.
     */
    public static boolean areSamePhoneNumber(@NonNull String number1,
            @NonNull String number2, @NonNull String defaultCountryIso) {
        PhoneNumberUtil util = PhoneNumberUtil.getInstance();
        PhoneNumber n1;
        PhoneNumber n2;
        defaultCountryIso = defaultCountryIso.toUpperCase();
        try {
            n1 = util.parseAndKeepRawInput(number1, defaultCountryIso);
            n2 = util.parseAndKeepRawInput(number2, defaultCountryIso);
        } catch (NumberParseException e) {
            return false;
        }

        PhoneNumberUtil.MatchType matchType = util.isNumberMatch(n1, n2);
        if (matchType == PhoneNumberUtil.MatchType.EXACT_MATCH
                || matchType == PhoneNumberUtil.MatchType.NSN_MATCH) {
            return true;
        } else if (matchType == PhoneNumberUtil.MatchType.SHORT_NSN_MATCH) {
            return (n1.getNationalNumber() == n2.getNationalNumber()
                    && n1.getCountryCode() == n2.getCountryCode());
        } else {
            return false;
        }
    }
}