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

Commit 37dc6c3c authored by Taesu Lee's avatar Taesu Lee Committed by android-build-merger
Browse files

Merge "Merge "Added the min match system config for loose phone numbers...

Merge "Merge "Added the min match system config for loose phone numbers comparison" into qt-dev-plus-aosp am: 41f788ca" into qt-r1-dev-plus-aosp
am: 4c0e49b0

Change-Id: Ie95944ee03ed9544035cef25968e7cd870521111
parents 55ae4246 4c0e49b0
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -2847,6 +2847,11 @@ package android.telephony {
    method @NonNull public android.telephony.NetworkRegistrationInfo.Builder setTransportType(int);
  }

  public class PhoneNumberUtils {
    method public static int getMinMatchForTest();
    method public static void setMinMatchForTest(int);
  }

  public class ServiceState implements android.os.Parcelable {
    method public void addNetworkRegistrationInfo(android.telephony.NetworkRegistrationInfo);
    method public void setCdmaSystemAndNetworkId(int, int);
+3 −0
Original line number Diff line number Diff line
@@ -1301,6 +1301,9 @@
    <!-- Whether to use the strict phone number matcher in Kazakhstan. -->
    <bool name="config_use_strict_phone_number_comparation_for_kazakhstan">true</bool>

    <!-- The character count of the minimum match for comparison phone numbers -->
    <integer name="config_phonenumber_compare_min_match">7</integer>

    <!-- Display low battery warning when battery level dips to this value.
         Also, the battery stats are flushed to disk when we hit this level.  -->
    <integer name="config_criticalBatteryWarningLevel">5</integer>
+1 −0
Original line number Diff line number Diff line
@@ -320,6 +320,7 @@
  <java-symbol type="bool" name="config_use_strict_phone_number_comparation" />
  <java-symbol type="bool" name="config_use_strict_phone_number_comparation_for_russia" />
  <java-symbol type="bool" name="config_use_strict_phone_number_comparation_for_kazakhstan" />
  <java-symbol type="integer" name="config_phonenumber_compare_min_match" />
  <java-symbol type="bool" name="config_single_volume" />
  <java-symbol type="bool" name="config_voice_capable" />
  <java-symbol type="bool" name="config_requireCallCapableAccountForHandle" />
+36 −26
Original line number Diff line number Diff line
@@ -22,9 +22,11 @@ import com.android.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat;
import com.android.i18n.phonenumbers.Phonenumber.PhoneNumber;

import android.annotation.IntDef;
import android.annotation.TestApi;
import android.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.database.Cursor;
import android.location.CountryDetector;
import android.net.Uri;
@@ -164,6 +166,33 @@ public class PhoneNumberUtils {
        return c == 'w'||c == 'W';
    }

    private static int sMinMatch = 0;

    private static int getMinMatch() {
        if (sMinMatch == 0) {
            sMinMatch = Resources.getSystem().getInteger(
                    com.android.internal.R.integer.config_phonenumber_compare_min_match);
        }
        return sMinMatch;
    }

    /**
     * A Test API to get current sMinMatch.
     * @hide
     */
    @TestApi
    public static int getMinMatchForTest() {
        return getMinMatch();
    }

    /**
     * A Test API to set sMinMatch.
     * @hide
     */
    @TestApi
    public static void setMinMatchForTest(int minMatch) {
        sMinMatch = minMatch;
    }

    /** Returns true if ch is not dialable or alpha char */
    private static boolean isSeparator(char ch) {
@@ -475,7 +504,7 @@ public class PhoneNumberUtils {
     * enough for caller ID purposes.
     *
     * - Compares from right to left
     * - requires MIN_MATCH (7) characters to match
     * - requires minimum characters to match
     * - handles common trunk prefixes and international prefixes
     *   (basically, everything except the Russian trunk prefix)
     *
@@ -491,6 +520,7 @@ public class PhoneNumberUtils {
        int matched;
        int numNonDialableCharsInA = 0;
        int numNonDialableCharsInB = 0;
        int minMatch = getMinMatch();

        if (a == null || b == null) return a == b;

@@ -530,12 +560,12 @@ public class PhoneNumberUtils {
            }
        }

        if (matched < MIN_MATCH) {
        if (matched < minMatch) {
            int effectiveALen = a.length() - numNonDialableCharsInA;
            int effectiveBLen = b.length() - numNonDialableCharsInB;


            // if the number of dialable chars in a and b match, but the matched chars < MIN_MATCH,
            // if the number of dialable chars in a and b match, but the matched chars < minMatch,
            // treat them as equal (i.e. 404-04 and 40404)
            if (effectiveALen == effectiveBLen && effectiveALen == matched) {
                return true;
@@ -545,7 +575,7 @@ public class PhoneNumberUtils {
        }

        // At least one string has matched completely;
        if (matched >= MIN_MATCH && (ia < 0 || ib < 0)) {
        if (matched >= minMatch && (ia < 0 || ib < 0)) {
            return true;
        }

@@ -736,7 +766,7 @@ public class PhoneNumberUtils {
    }

    /**
     * Returns the rightmost MIN_MATCH (5) characters in the network portion
     * Returns the rightmost minimum matched characters in the network portion
     * in *reversed* order
     *
     * This can be used to do a database lookup against the column
@@ -747,7 +777,7 @@ public class PhoneNumberUtils {
    public static String
    toCallerIDMinMatch(String phoneNumber) {
        String np = extractNetworkPortionAlt(phoneNumber);
        return internalGetStrippedReversed(np, MIN_MATCH);
        return internalGetStrippedReversed(np, getMinMatch());
    }

    /**
@@ -1709,26 +1739,6 @@ public class PhoneNumberUtils {
        return normalizedDigits.toString();
    }

    // Three and four digit phone numbers for either special services,
    // or 3-6 digit addresses from the network (eg carrier-originated SMS messages) should
    // not match.
    //
    // This constant used to be 5, but SMS short codes has increased in length and
    // can be easily 6 digits now days. Most countries have SMS short code length between
    // 3 to 6 digits. The exceptions are
    //
    // Australia: Short codes are six or eight digits in length, starting with the prefix "19"
    //            followed by an additional four or six digits and two.
    // Czechia: Codes are seven digits in length for MO and five (not billed) or
    //            eight (billed) for MT direction
    //
    // see http://en.wikipedia.org/wiki/Short_code#Regional_differences for reference
    //
    // However, in order to loose match 650-555-1212 and 555-1212, we need to set the min match
    // to 7.
    @UnsupportedAppUsage
    static final int MIN_MATCH = 7;

    /**
     * Checks a given number against the list of
     * emergency numbers provided by the RIL and SIM card.