diff options
| author | 2011-11-20 14:46:27 +0100 | |
|---|---|---|
| committer | 2011-11-20 14:52:59 +0100 | |
| commit | ab971d3c26346cfd94a37e40591318bf3b3ae4fd (patch) | |
| tree | f6b05aa10b83d6f21b55a21d5c3499f17a5f6a56 | |
| parent | 711683cd96884690b9e834198e7c756bb23ab5ad (diff) | |
Add support for country specific emergency number handling.
Bug: 5247602, 5615428
Change-Id: I1bdfbc987f45e0f2ebbe68adaab215395c83ca35
| -rw-r--r-- | telephony/java/android/telephony/PhoneNumberUtils.java | 131 |
1 files changed, 61 insertions, 70 deletions
diff --git a/telephony/java/android/telephony/PhoneNumberUtils.java b/telephony/java/android/telephony/PhoneNumberUtils.java index 07afe3077ff2..5da3d97706bc 100644 --- a/telephony/java/android/telephony/PhoneNumberUtils.java +++ b/telephony/java/android/telephony/PhoneNumberUtils.java @@ -20,6 +20,7 @@ import com.android.i18n.phonenumbers.NumberParseException; import com.android.i18n.phonenumbers.PhoneNumberUtil; import com.android.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat; import com.android.i18n.phonenumbers.Phonenumber.PhoneNumber; +import com.android.i18n.phonenumbers.ShortNumberUtil; import android.content.Context; import android.content.Intent; @@ -1572,56 +1573,7 @@ public class PhoneNumberUtils * listed in the RIL / sim, otherwise return false. */ private static boolean isEmergencyNumberInternal(String number, boolean useExactMatch) { - // If the number passed in is null, just return false: - if (number == null) return false; - - // If the number passed in is a SIP address, return false, since the - // concept of "emergency numbers" is only meaningful for calls placed - // over the cell network. - // (Be sure to do this check *before* calling extractNetworkPortionAlt(), - // since the whole point of extractNetworkPortionAlt() is to filter out - // any non-dialable characters (which would turn 'abc911def@example.com' - // into '911', for example.)) - if (isUriNumber(number)) { - return false; - } - - // Strip the separators from the number before comparing it - // to the list. - number = extractNetworkPortionAlt(number); - - // retrieve the list of emergency numbers - // check read-write ecclist property first - String numbers = SystemProperties.get("ril.ecclist"); - if (TextUtils.isEmpty(numbers)) { - // then read-only ecclist property since old RIL only uses this - numbers = SystemProperties.get("ro.ril.ecclist"); - } - - if (!TextUtils.isEmpty(numbers)) { - // searches through the comma-separated list for a match, - // return true if one is found. - for (String emergencyNum : numbers.split(",")) { - if (useExactMatch) { - if (number.equals(emergencyNum)) { - return true; - } - } else { - if (number.startsWith(emergencyNum)) { - return true; - } - } - } - // no matches found against the list! - return false; - } - - // No ecclist system property, so use our own list. - if (useExactMatch) { - return (number.equals("112") || number.equals("911")); - } else { - return (number.startsWith("112") || number.startsWith("911")); - } + return isEmergencyNumberInternal(number, null, useExactMatch); } /** @@ -1684,28 +1636,67 @@ public class PhoneNumberUtils private static boolean isEmergencyNumberInternal(String number, String defaultCountryIso, boolean useExactMatch) { - PhoneNumberUtil util = PhoneNumberUtil.getInstance(); - try { - PhoneNumber pn = util.parse(number, defaultCountryIso); - // libphonenumber guarantees short numbers such as emergency numbers are classified as - // invalid. Therefore, if the number passes the validation test, we believe it is not an - // emergency number. - // TODO: Compare against a list of country-specific known emergency numbers instead, once - // that has been collected. - if (util.isValidNumber(pn)) { - return false; - } else if ("BR".equalsIgnoreCase(defaultCountryIso) && number.length() >= 8) { - // This is to prevent Brazilian local numbers which start with 911 being incorrectly - // classified as emergency numbers. 911 is not an emergency number in Brazil; it is also - // not possible to append additional digits to an emergency number to dial the number in - // Brazil - it won't connect. - // TODO: Clean this up once a list of country-specific known emergency numbers is - // collected. - return false; + // If the number passed in is null, just return false: + if (number == null) return false; + + // If the number passed in is a SIP address, return false, since the + // concept of "emergency numbers" is only meaningful for calls placed + // over the cell network. + // (Be sure to do this check *before* calling extractNetworkPortionAlt(), + // since the whole point of extractNetworkPortionAlt() is to filter out + // any non-dialable characters (which would turn 'abc911def@example.com' + // into '911', for example.)) + if (isUriNumber(number)) { + return false; + } + + // Strip the separators from the number before comparing it + // to the list. + number = extractNetworkPortionAlt(number); + + // retrieve the list of emergency numbers + // check read-write ecclist property first + String numbers = SystemProperties.get("ril.ecclist"); + if (TextUtils.isEmpty(numbers)) { + // then read-only ecclist property since old RIL only uses this + numbers = SystemProperties.get("ro.ril.ecclist"); + } + + if (!TextUtils.isEmpty(numbers)) { + // searches through the comma-separated list for a match, + // return true if one is found. + for (String emergencyNum : numbers.split(",")) { + // It is not possible to append additional digits to an emergency number to dial + // the number in Brazil - it won't connect. + if (useExactMatch || "BR".equalsIgnoreCase(defaultCountryIso)) { + if (number.equals(emergencyNum)) { + return true; + } + } else { + if (number.startsWith(emergencyNum)) { + return true; + } + } + } + // no matches found against the list! + return false; + } + + // No ecclist system property, so use our own list. + if (defaultCountryIso != null) { + ShortNumberUtil util = new ShortNumberUtil(); + if (useExactMatch) { + return util.isEmergencyNumber(number, defaultCountryIso); + } else { + return util.connectsToEmergencyNumber(number, defaultCountryIso); + } + } else { + if (useExactMatch) { + return (number.equals("112") || number.equals("911")); + } else { + return (number.startsWith("112") || number.startsWith("911")); } - } catch (NumberParseException e) { } - return isEmergencyNumberInternal(number, useExactMatch); } /** |