Skip to content

Commit

Permalink
Optimize IncallUI delay for voice calls
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Sandeep Kunta authored and PMS22 committed Mar 28, 2020
1 parent 3fca9af commit 6d86e54
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions telephony/java/android/telephony/PhoneNumberUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.location.Country;
import android.location.CountryDetector;
import android.net.Uri;
import android.os.PersistableBundle;
Expand Down Expand Up @@ -108,6 +109,7 @@ public class PhoneNumberUtils {
private static final String BCD_EF_ADN_EXTENDED = "*#,N;";
private static final String BCD_CALLED_PARTY_EXTENDED = "*#abc";

private static Country sCountryDetector = null;
/*
* global-phone-number = ["+"] 1*( DIGIT / written-sep )
* written-sep = ("-"/".")
Expand Down Expand Up @@ -2177,12 +2179,9 @@ private static boolean isLocalEmergencyNumberInternal(String number,
private static boolean isLocalEmergencyNumberInternal(int subId, String number,
Context context,
boolean useExactMatch) {
String countryIso;
CountryDetector detector = (CountryDetector) context.getSystemService(
Context.COUNTRY_DETECTOR);
if (detector != null && detector.detectCountry() != null) {
countryIso = detector.detectCountry().getCountryIso();
} else {
String countryIso = getCountryIso(context);
Rlog.w(LOG_TAG, "isLocalEmergencyNumberInternal" + countryIso);
if (countryIso == null) {
Locale locale = context.getResources().getConfiguration().locale;
countryIso = locale.getCountry();
Rlog.w(LOG_TAG, "No CountryDetector; falling back to countryIso based on locale: "
Expand All @@ -2191,6 +2190,28 @@ private static boolean isLocalEmergencyNumberInternal(int subId, String number,
return isEmergencyNumberInternal(subId, number, countryIso, useExactMatch);
}

private static String getCountryIso(Context context) {
Rlog.w(LOG_TAG, "getCountryIso " + sCountryDetector);
if (sCountryDetector == null) {
CountryDetector detector = (CountryDetector) context.getSystemService(
Context.COUNTRY_DETECTOR);
if (detector != null) {
sCountryDetector = detector.detectCountry();
}
}

if (sCountryDetector == null) {
return null;
} else {
return sCountryDetector.getCountryIso();
}
}

/** @hide */
public static void resetCountryDetectorInfo() {
sCountryDetector = null;
}

/**
* isVoiceMailNumber: checks a given number against the voicemail
* number provided by the RIL and SIM card. The caller must have
Expand Down

0 comments on commit 6d86e54

Please sign in to comment.