Update code to use location aware isEmergencyNumber.

Bug: 5247602
Change-Id: Ieeda4a17464795b3591db754bc991759609f88c2
This commit is contained in:
Shaopeng Jia
2011-09-14 17:36:18 +02:00
parent 09bd49a8a7
commit 6b7c3f8a1c
5 changed files with 33 additions and 9 deletions

View File

@@ -24,6 +24,7 @@ import com.android.i18n.phonenumbers.Phonenumber.PhoneNumber;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.location.CountryDetector;
import android.net.Uri;
import android.os.SystemProperties;
import android.provider.Contacts;
@@ -1572,6 +1573,32 @@ public class PhoneNumberUtils
return isEmergencyNumber(number);
}
/**
* Checks if a given number is an emergency number for the country that the user is in. The
* current country is determined using the CountryDetector.
*
* @param number the number to look up.
* @param context the specific context which the number should be checked against
* @return if a phone number is an emergency number for a local country, based on the
* CountryDetector.
* @see android.location.CountryDetector
* @hide
*/
public static boolean isLocalEmergencyNumber(String number, Context context) {
String countryIso;
CountryDetector detector = (CountryDetector) context.getSystemService(
Context.COUNTRY_DETECTOR);
if (detector != null) {
countryIso = detector.detectCountry().getCountryIso();
} else {
Locale locale = context.getResources().getConfiguration().locale;
countryIso = locale.getCountry();
Log.w(LOG_TAG, "No CountryDetector; falling back to countryIso based on locale: "
+ countryIso);
}
return isEmergencyNumber(number, countryIso);
}
/**
* isVoiceMailNumber: checks a given number against the voicemail
* number provided by the RIL and SIM card. The caller must have

View File

@@ -254,9 +254,7 @@ public class CallerInfo {
// Change the callerInfo number ONLY if it is an emergency number
// or if it is the voicemail number. If it is either, take a
// shortcut and skip the query.
Locale locale = context.getResources().getConfiguration().locale;
String countryIso = getCurrentCountryIso(context, locale);
if (PhoneNumberUtils.isEmergencyNumber(number, countryIso)) {
if (PhoneNumberUtils.isLocalEmergencyNumber(number, context)) {
return new CallerInfo().markAsEmergency(context);
} else if (PhoneNumberUtils.isVoiceMailNumber(number)) {
return new CallerInfo().markAsVoiceMail();

View File

@@ -403,9 +403,7 @@ public class CallerInfoAsyncQuery {
cw.number = number;
// check to see if these are recognized numbers, and use shortcuts if we can.
CountryDetector detector = (CountryDetector) context.getSystemService(
Context.COUNTRY_DETECTOR);
if (PhoneNumberUtils.isEmergencyNumber(number, detector.detectCountry().getCountryIso())) {
if (PhoneNumberUtils.isLocalEmergencyNumber(number, context)) {
cw.event = EVENT_EMERGENCY_NUMBER;
} else if (PhoneNumberUtils.isVoiceMailNumber(number)) {
cw.event = EVENT_VOICEMAIL_NUMBER;

View File

@@ -190,7 +190,8 @@ public final class CdmaCallTracker extends CallTracker {
String inEcm=SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE, "false");
boolean isPhoneInEcmMode = inEcm.equals("true");
boolean isEmergencyCall = PhoneNumberUtils.isEmergencyNumber(dialString);
boolean isEmergencyCall =
PhoneNumberUtils.isLocalEmergencyNumber(dialString, phone.getContext());
// Cancel Ecm timer if a second emergency call is originating in Ecm mode
if (isPhoneInEcmMode && isEmergencyCall) {
@@ -1059,7 +1060,7 @@ public final class CdmaCallTracker extends CallTracker {
* Disable data call when emergency call is connected
*/
private void disableDataCallInEmergencyCall(String dialString) {
if (PhoneNumberUtils.isEmergencyNumber(dialString)) {
if (PhoneNumberUtils.isLocalEmergencyNumber(dialString, phone.getContext())) {
if (Phone.DEBUG_PHONE) log("disableDataCallInEmergencyCall");
mIsInEmergencyCall = true;
phone.mDataConnectionTracker.setInternalDataEnabled(false);

View File

@@ -496,7 +496,7 @@ public final class GsmMmiCode extends Handler implements MmiCode {
return false;
}
if (PhoneNumberUtils.isEmergencyNumber(dialString)) {
if (PhoneNumberUtils.isLocalEmergencyNumber(dialString, phone.getContext())) {
return false;
} else {
return isShortCodeUSSD(dialString, phone);