Skip to content

Commit 6d86e54

Browse files
Sandeep KuntaPMS22
authored andcommitted
Optimize IncallUI delay for voice calls
In current implementation detectCountry method is called from telephony as many times as 34 for one MO voice call, causing increasing delay to appear incallui for user. This fix ensures that there is only one call to detectCountry method per one voice call thus optimizing delay. CRs-Fixed: 803069 Change-Id: Ia6e832476c7f7be2750f1c2d9a4c83f728c2131e Signed-off-by: Sujit Roy <kumarsujitroy@gmail.com>
1 parent 3fca9af commit 6d86e54

1 file changed

Lines changed: 27 additions & 6 deletions

File tree

telephony/java/android/telephony/PhoneNumberUtils.java

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import android.content.Context;
2727
import android.content.Intent;
2828
import android.database.Cursor;
29+
import android.location.Country;
2930
import android.location.CountryDetector;
3031
import android.net.Uri;
3132
import android.os.PersistableBundle;
@@ -108,6 +109,7 @@ public class PhoneNumberUtils {
108109
private static final String BCD_EF_ADN_EXTENDED = "*#,N;";
109110
private static final String BCD_CALLED_PARTY_EXTENDED = "*#abc";
110111

112+
private static Country sCountryDetector = null;
111113
/*
112114
* global-phone-number = ["+"] 1*( DIGIT / written-sep )
113115
* written-sep = ("-"/".")
@@ -2177,12 +2179,9 @@ private static boolean isLocalEmergencyNumberInternal(String number,
21772179
private static boolean isLocalEmergencyNumberInternal(int subId, String number,
21782180
Context context,
21792181
boolean useExactMatch) {
2180-
String countryIso;
2181-
CountryDetector detector = (CountryDetector) context.getSystemService(
2182-
Context.COUNTRY_DETECTOR);
2183-
if (detector != null && detector.detectCountry() != null) {
2184-
countryIso = detector.detectCountry().getCountryIso();
2185-
} else {
2182+
String countryIso = getCountryIso(context);
2183+
Rlog.w(LOG_TAG, "isLocalEmergencyNumberInternal" + countryIso);
2184+
if (countryIso == null) {
21862185
Locale locale = context.getResources().getConfiguration().locale;
21872186
countryIso = locale.getCountry();
21882187
Rlog.w(LOG_TAG, "No CountryDetector; falling back to countryIso based on locale: "
@@ -2191,6 +2190,28 @@ private static boolean isLocalEmergencyNumberInternal(int subId, String number,
21912190
return isEmergencyNumberInternal(subId, number, countryIso, useExactMatch);
21922191
}
21932192

2193+
private static String getCountryIso(Context context) {
2194+
Rlog.w(LOG_TAG, "getCountryIso " + sCountryDetector);
2195+
if (sCountryDetector == null) {
2196+
CountryDetector detector = (CountryDetector) context.getSystemService(
2197+
Context.COUNTRY_DETECTOR);
2198+
if (detector != null) {
2199+
sCountryDetector = detector.detectCountry();
2200+
}
2201+
}
2202+
2203+
if (sCountryDetector == null) {
2204+
return null;
2205+
} else {
2206+
return sCountryDetector.getCountryIso();
2207+
}
2208+
}
2209+
2210+
/** @hide */
2211+
public static void resetCountryDetectorInfo() {
2212+
sCountryDetector = null;
2213+
}
2214+
21942215
/**
21952216
* isVoiceMailNumber: checks a given number against the voicemail
21962217
* number provided by the RIL and SIM card. The caller must have

0 commit comments

Comments
 (0)