diff options
author | Sandeep Kunta <skunta@codeaurora.org> | 2015-03-12 18:56:30 +0530 |
---|---|---|
committer | Linux Build Service Account <lnxbuild@localhost> | 2015-10-06 03:28:22 -0600 |
commit | f654a16191c0daf0e5d6d2a2cd7eed5cd2d70b93 (patch) | |
tree | 3410f2bf8e17cb5e76b85a9e59a1a36cecf8bf23 | |
parent | a63e4f0488f1f82172d4f191958ff7867e6f4d47 (diff) | |
download | frameworks_base-f654a16191c0daf0e5d6d2a2cd7eed5cd2d70b93.zip frameworks_base-f654a16191c0daf0e5d6d2a2cd7eed5cd2d70b93.tar.gz frameworks_base-f654a16191c0daf0e5d6d2a2cd7eed5cd2d70b93.tar.bz2 |
Call DetectCountry only once per call
In current implementation detectCountry method is called from telephon
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.
Change-Id: Ia6e832476c7f7be2750f1c2d9a4c83f728c2131e
CRs-Fixed: 803069
-rw-r--r-- | telephony/java/android/telephony/PhoneNumberUtils.java | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/telephony/java/android/telephony/PhoneNumberUtils.java b/telephony/java/android/telephony/PhoneNumberUtils.java index 79146f3..c73b42c 100644 --- a/telephony/java/android/telephony/PhoneNumberUtils.java +++ b/telephony/java/android/telephony/PhoneNumberUtils.java @@ -25,6 +25,7 @@ import com.android.i18n.phonenumbers.ShortNumberUtil; 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.SystemProperties; @@ -77,6 +78,7 @@ public class PhoneNumberUtils static final String LOG_TAG = "PhoneNumberUtils"; private static final boolean DBG = false; + private static Country sCountryDetector = null; /* * global-phone-number = ["+"] 1*( DIGIT / written-sep ) * written-sep = ("-"/".") @@ -2043,12 +2045,9 @@ public class PhoneNumberUtils 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: " @@ -2057,6 +2056,28 @@ public class PhoneNumberUtils 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 |