Added the min match system config for loose phone numbers comparison

Specific min match is required for each country.

Test: atest PhoneNumberUtilsTest

Change-Id: I7f9e9ad824d44f2ebf8367beb6ec337e3eb3a8ad
Merged-In: I7f9e9ad824d44f2ebf8367beb6ec337e3eb3a8ad
Signed-off-by: Taesu Lee <taesu82.lee@samsung.com>
Bug:134246556
(cherry picked from commit d65aafc748)
This commit is contained in:
Taesu Lee
2019-05-28 19:05:06 +09:00
committed by Hui Yu
parent 6bbd7c4cc6
commit b89c2984bb
4 changed files with 45 additions and 26 deletions

View File

@@ -2845,6 +2845,11 @@ package android.telephony {
method @NonNull public android.telephony.NetworkRegistrationInfo.Builder setTransportType(int); 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 { public class ServiceState implements android.os.Parcelable {
method public void addNetworkRegistrationInfo(android.telephony.NetworkRegistrationInfo); method public void addNetworkRegistrationInfo(android.telephony.NetworkRegistrationInfo);
method public void setCdmaSystemAndNetworkId(int, int); method public void setCdmaSystemAndNetworkId(int, int);

View File

@@ -1285,6 +1285,9 @@
<!-- Whether to use the strict phone number matcher in Kazakhstan. --> <!-- Whether to use the strict phone number matcher in Kazakhstan. -->
<bool name="config_use_strict_phone_number_comparation_for_kazakhstan">true</bool> <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. <!-- Display low battery warning when battery level dips to this value.
Also, the battery stats are flushed to disk when we hit this level. --> Also, the battery stats are flushed to disk when we hit this level. -->
<integer name="config_criticalBatteryWarningLevel">5</integer> <integer name="config_criticalBatteryWarningLevel">5</integer>

View File

@@ -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" />
<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_russia" />
<java-symbol type="bool" name="config_use_strict_phone_number_comparation_for_kazakhstan" /> <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_single_volume" />
<java-symbol type="bool" name="config_voice_capable" /> <java-symbol type="bool" name="config_voice_capable" />
<java-symbol type="bool" name="config_requireCallCapableAccountForHandle" /> <java-symbol type="bool" name="config_requireCallCapableAccountForHandle" />

View File

@@ -22,9 +22,11 @@ import com.android.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat;
import com.android.i18n.phonenumbers.Phonenumber.PhoneNumber; import com.android.i18n.phonenumbers.Phonenumber.PhoneNumber;
import android.annotation.IntDef; import android.annotation.IntDef;
import android.annotation.TestApi;
import android.annotation.UnsupportedAppUsage; import android.annotation.UnsupportedAppUsage;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.res.Resources;
import android.database.Cursor; import android.database.Cursor;
import android.location.CountryDetector; import android.location.CountryDetector;
import android.net.Uri; import android.net.Uri;
@@ -164,6 +166,33 @@ public class PhoneNumberUtils {
return c == 'w'||c == 'W'; 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 */ /** Returns true if ch is not dialable or alpha char */
private static boolean isSeparator(char ch) { private static boolean isSeparator(char ch) {
@@ -475,7 +504,7 @@ public class PhoneNumberUtils {
* enough for caller ID purposes. * enough for caller ID purposes.
* *
* - Compares from right to left * - Compares from right to left
* - requires MIN_MATCH (7) characters to match * - requires minimum characters to match
* - handles common trunk prefixes and international prefixes * - handles common trunk prefixes and international prefixes
* (basically, everything except the Russian trunk prefix) * (basically, everything except the Russian trunk prefix)
* *
@@ -491,6 +520,7 @@ public class PhoneNumberUtils {
int matched; int matched;
int numNonDialableCharsInA = 0; int numNonDialableCharsInA = 0;
int numNonDialableCharsInB = 0; int numNonDialableCharsInB = 0;
int minMatch = getMinMatch();
if (a == null || b == null) return a == b; 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 effectiveALen = a.length() - numNonDialableCharsInA;
int effectiveBLen = b.length() - numNonDialableCharsInB; 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) // treat them as equal (i.e. 404-04 and 40404)
if (effectiveALen == effectiveBLen && effectiveALen == matched) { if (effectiveALen == effectiveBLen && effectiveALen == matched) {
return true; return true;
@@ -545,7 +575,7 @@ public class PhoneNumberUtils {
} }
// At least one string has matched completely; // At least one string has matched completely;
if (matched >= MIN_MATCH && (ia < 0 || ib < 0)) { if (matched >= minMatch && (ia < 0 || ib < 0)) {
return true; 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 * in *reversed* order
* *
* This can be used to do a database lookup against the column * This can be used to do a database lookup against the column
@@ -747,7 +777,7 @@ public class PhoneNumberUtils {
public static String public static String
toCallerIDMinMatch(String phoneNumber) { toCallerIDMinMatch(String phoneNumber) {
String np = extractNetworkPortionAlt(phoneNumber); String np = extractNetworkPortionAlt(phoneNumber);
return internalGetStrippedReversed(np, MIN_MATCH); return internalGetStrippedReversed(np, getMinMatch());
} }
/** /**
@@ -1709,26 +1739,6 @@ public class PhoneNumberUtils {
return normalizedDigits.toString(); 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 * Checks a given number against the list of
* emergency numbers provided by the RIL and SIM card. * emergency numbers provided by the RIL and SIM card.