|
|
|
|
@@ -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.
|
|
|
|
|
|