Skip to content

Commit bb132eb

Browse files
David BrownAndroid (Google) Code Review
authored andcommitted
Merge "Update code to use location aware isEmergencyNumber."
2 parents 9756734 + 6b7c3f8 commit bb132eb

5 files changed

Lines changed: 33 additions & 9 deletions

File tree

telephony/java/android/telephony/PhoneNumberUtils.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import android.content.Context;
2525
import android.content.Intent;
2626
import android.database.Cursor;
27+
import android.location.CountryDetector;
2728
import android.net.Uri;
2829
import android.os.SystemProperties;
2930
import android.provider.Contacts;
@@ -1572,6 +1573,32 @@ public static boolean isEmergencyNumber(String number, String defaultCountryIso)
15721573
return isEmergencyNumber(number);
15731574
}
15741575

1576+
/**
1577+
* Checks if a given number is an emergency number for the country that the user is in. The
1578+
* current country is determined using the CountryDetector.
1579+
*
1580+
* @param number the number to look up.
1581+
* @param context the specific context which the number should be checked against
1582+
* @return if a phone number is an emergency number for a local country, based on the
1583+
* CountryDetector.
1584+
* @see android.location.CountryDetector
1585+
* @hide
1586+
*/
1587+
public static boolean isLocalEmergencyNumber(String number, Context context) {
1588+
String countryIso;
1589+
CountryDetector detector = (CountryDetector) context.getSystemService(
1590+
Context.COUNTRY_DETECTOR);
1591+
if (detector != null) {
1592+
countryIso = detector.detectCountry().getCountryIso();
1593+
} else {
1594+
Locale locale = context.getResources().getConfiguration().locale;
1595+
countryIso = locale.getCountry();
1596+
Log.w(LOG_TAG, "No CountryDetector; falling back to countryIso based on locale: "
1597+
+ countryIso);
1598+
}
1599+
return isEmergencyNumber(number, countryIso);
1600+
}
1601+
15751602
/**
15761603
* isVoiceMailNumber: checks a given number against the voicemail
15771604
* number provided by the RIL and SIM card. The caller must have

telephony/java/com/android/internal/telephony/CallerInfo.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,7 @@ public static CallerInfo getCallerInfo(Context context, String number) {
254254
// Change the callerInfo number ONLY if it is an emergency number
255255
// or if it is the voicemail number. If it is either, take a
256256
// shortcut and skip the query.
257-
Locale locale = context.getResources().getConfiguration().locale;
258-
String countryIso = getCurrentCountryIso(context, locale);
259-
if (PhoneNumberUtils.isEmergencyNumber(number, countryIso)) {
257+
if (PhoneNumberUtils.isLocalEmergencyNumber(number, context)) {
260258
return new CallerInfo().markAsEmergency(context);
261259
} else if (PhoneNumberUtils.isVoiceMailNumber(number)) {
262260
return new CallerInfo().markAsVoiceMail();

telephony/java/com/android/internal/telephony/CallerInfoAsyncQuery.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,7 @@ public static CallerInfoAsyncQuery startQuery(int token, Context context, String
403403
cw.number = number;
404404

405405
// check to see if these are recognized numbers, and use shortcuts if we can.
406-
CountryDetector detector = (CountryDetector) context.getSystemService(
407-
Context.COUNTRY_DETECTOR);
408-
if (PhoneNumberUtils.isEmergencyNumber(number, detector.detectCountry().getCountryIso())) {
406+
if (PhoneNumberUtils.isLocalEmergencyNumber(number, context)) {
409407
cw.event = EVENT_EMERGENCY_NUMBER;
410408
} else if (PhoneNumberUtils.isVoiceMailNumber(number)) {
411409
cw.event = EVENT_VOICEMAIL_NUMBER;

telephony/java/com/android/internal/telephony/cdma/CdmaCallTracker.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ public void unregisterForCallWaiting(Handler h) {
190190

191191
String inEcm=SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE, "false");
192192
boolean isPhoneInEcmMode = inEcm.equals("true");
193-
boolean isEmergencyCall = PhoneNumberUtils.isEmergencyNumber(dialString);
193+
boolean isEmergencyCall =
194+
PhoneNumberUtils.isLocalEmergencyNumber(dialString, phone.getContext());
194195

195196
// Cancel Ecm timer if a second emergency call is originating in Ecm mode
196197
if (isPhoneInEcmMode && isEmergencyCall) {
@@ -1059,7 +1060,7 @@ private void handleEcmTimer(int action) {
10591060
* Disable data call when emergency call is connected
10601061
*/
10611062
private void disableDataCallInEmergencyCall(String dialString) {
1062-
if (PhoneNumberUtils.isEmergencyNumber(dialString)) {
1063+
if (PhoneNumberUtils.isLocalEmergencyNumber(dialString, phone.getContext())) {
10631064
if (Phone.DEBUG_PHONE) log("disableDataCallInEmergencyCall");
10641065
mIsInEmergencyCall = true;
10651066
phone.mDataConnectionTracker.setInternalDataEnabled(false);

telephony/java/com/android/internal/telephony/gsm/GsmMmiCode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ static private boolean isShortCode(String dialString, GSMPhone phone) {
496496
return false;
497497
}
498498

499-
if (PhoneNumberUtils.isEmergencyNumber(dialString)) {
499+
if (PhoneNumberUtils.isLocalEmergencyNumber(dialString, phone.getContext())) {
500500
return false;
501501
} else {
502502
return isShortCodeUSSD(dialString, phone);

0 commit comments

Comments
 (0)