summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/phonenumberutil
diff options
context:
space:
mode:
authorwangqi <wangqi@google.com>2017-09-21 09:37:40 -0700
committerEric Erfanian <erfanian@google.com>2017-09-22 15:59:39 +0000
commit1420a22d5dc0d87f8634980b729a3511e42b6493 (patch)
treee82dd12010685713517e7b4737b999839880e843 /java/com/android/dialer/phonenumberutil
parent3f4a31982fc815b1620671f16f7d45a8d2c07988 (diff)
Better handling country iso when getting geo location of phone number.
1. Use existing country iso info instead of guessing current country iso from sim and locale for blocked number. 2. Use country iso of current sim instead of default sim for incall location info. This fixes bug in multi sim device when default sim is out of service and making call with the other sim. Bug: 65399976 Test: manual PiperOrigin-RevId: 169554641 Change-Id: I416d7e2d6bc3c872bfec3eda4005a5a1684f0e40
Diffstat (limited to 'java/com/android/dialer/phonenumberutil')
-rw-r--r--java/com/android/dialer/phonenumberutil/PhoneNumberHelper.java31
1 files changed, 18 insertions, 13 deletions
diff --git a/java/com/android/dialer/phonenumberutil/PhoneNumberHelper.java b/java/com/android/dialer/phonenumberutil/PhoneNumberHelper.java
index 1189a9b24..b25e4d7fe 100644
--- a/java/com/android/dialer/phonenumberutil/PhoneNumberHelper.java
+++ b/java/com/android/dialer/phonenumberutil/PhoneNumberHelper.java
@@ -24,11 +24,12 @@ import android.telephony.PhoneNumberUtils;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import com.android.dialer.common.LogUtil;
+import com.android.dialer.compat.CompatUtils;
+import com.android.dialer.compat.telephony.TelephonyManagerCompat;
import com.android.dialer.phonenumbergeoutil.PhoneNumberGeoUtilComponent;
import com.android.dialer.telecom.TelecomUtil;
import java.util.Arrays;
import java.util.HashSet;
-import java.util.Locale;
import java.util.Set;
public class PhoneNumberHelper {
@@ -92,27 +93,33 @@ public class PhoneNumberHelper {
}
/**
+ * @param countryIso Country ISO used if there is no country code in the number, may be null
+ * otherwise.
* @return a geographical description string for the specified number.
*/
- public static String getGeoDescription(Context context, String number) {
+ public static String getGeoDescription(
+ Context context, String number, @Nullable String countryIso) {
return PhoneNumberGeoUtilComponent.get(context)
.getPhoneNumberGeoUtil()
- .getGeoDescription(context, number);
+ .getGeoDescription(context, number, countryIso);
}
/**
+ * @param phoneAccountHandle {@code PhonAccountHandle} used to get current network country ISO.
+ * May be null if no account is in use or selected, in which case default account will be
+ * used.
* @return The ISO 3166-1 two letters country code of the country the user is in based on the
* network location. If the network location does not exist, fall back to the locale setting.
*/
- public static String getCurrentCountryIso(Context context, Locale locale) {
+ public static String getCurrentCountryIso(
+ Context context, @Nullable PhoneAccountHandle phoneAccountHandle) {
// Without framework function calls, this seems to be the most accurate location service
// we can rely on.
- final TelephonyManager telephonyManager =
- (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
-
- String countryIso = telephonyManager.getNetworkCountryIso();
+ String countryIso =
+ TelephonyManagerCompat.getNetworkCountryIsoForPhoneAccountHandle(
+ context, phoneAccountHandle);
if (TextUtils.isEmpty(countryIso)) {
- countryIso = locale.getCountry();
+ countryIso = CompatUtils.getLocale(context).getCountry();
LogUtil.i(
"PhoneNumberHelper.getCurrentCountryIso",
"No CountryDetector; falling back to countryIso based on locale: " + countryIso);
@@ -126,14 +133,12 @@ public class PhoneNumberHelper {
* @return Formatted phone number. e.g. 1-123-456-7890. Returns the original number if formatting
* failed.
*/
- public static String formatNumber(@Nullable String number, Context context) {
+ public static String formatNumber(@Nullable String number, String countryIso) {
// The number can be null e.g. schema is voicemail and uri content is empty.
if (number == null) {
return null;
}
- String formattedNumber =
- PhoneNumberUtils.formatNumber(
- number, PhoneNumberHelper.getCurrentCountryIso(context, Locale.getDefault()));
+ String formattedNumber = PhoneNumberUtils.formatNumber(number, countryIso);
return formattedNumber != null ? formattedNumber : number;
}