diff options
| -rw-r--r-- | api/test-current.txt | 5 | ||||
| -rw-r--r-- | core/res/res/values/config.xml | 3 | ||||
| -rw-r--r-- | core/res/res/values/symbols.xml | 1 | ||||
| -rw-r--r-- | telephony/java/android/telephony/PhoneNumberUtils.java | 62 |
4 files changed, 45 insertions, 26 deletions
diff --git a/api/test-current.txt b/api/test-current.txt index acc1b4a7cac6..e8e27cb93427 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -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); diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 9a642add609e..f92a58ad471e 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -1285,6 +1285,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> diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 0367c279a77e..414751169e96 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -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" /> diff --git a/telephony/java/android/telephony/PhoneNumberUtils.java b/telephony/java/android/telephony/PhoneNumberUtils.java index b75e51577fdb..f03a9dc0f963 100644 --- a/telephony/java/android/telephony/PhoneNumberUtils.java +++ b/telephony/java/android/telephony/PhoneNumberUtils.java @@ -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. |