summaryrefslogtreecommitdiff
path: root/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'java/com')
-rw-r--r--java/com/android/contacts/common/list/PhoneNumberListAdapter.java6
-rw-r--r--java/com/android/dialer/app/filterednumber/NumbersAdapter.java6
-rw-r--r--java/com/android/dialer/compat/telephony/TelephonyManagerCompat.java30
-rw-r--r--java/com/android/dialer/phonenumbergeoutil/PhoneNumberGeoUtil.java3
-rw-r--r--java/com/android/dialer/phonenumbergeoutil/impl/PhoneNumberGeoUtilImpl.java4
-rw-r--r--java/com/android/dialer/phonenumbergeoutil/stub/PhoneNumberGeoUtilStub.java2
-rw-r--r--java/com/android/dialer/phonenumberutil/PhoneNumberHelper.java31
-rw-r--r--java/com/android/incallui/CallerInfo.java4
-rw-r--r--java/com/android/incallui/CallerInfoAsyncQuery.java3
-rw-r--r--java/com/android/incallui/CallerInfoUtils.java3
-rw-r--r--java/com/android/incallui/ContactInfoCache.java6
11 files changed, 71 insertions, 27 deletions
diff --git a/java/com/android/contacts/common/list/PhoneNumberListAdapter.java b/java/com/android/contacts/common/list/PhoneNumberListAdapter.java
index 71d9dad5f..741e606ac 100644
--- a/java/com/android/contacts/common/list/PhoneNumberListAdapter.java
+++ b/java/com/android/contacts/common/list/PhoneNumberListAdapter.java
@@ -381,7 +381,11 @@ public class PhoneNumberListAdapter extends ContactEntryListAdapter {
text = phoneLabel;
} else {
final String phoneNumber = cursor.getString(PhoneQuery.PHONE_NUMBER);
- text = PhoneNumberHelper.getGeoDescription(mContext, phoneNumber);
+ text =
+ PhoneNumberHelper.getGeoDescription(
+ mContext,
+ phoneNumber,
+ PhoneNumberHelper.getCurrentCountryIso(mContext, null /* PhoneAccountHandle */));
}
}
view.setPhoneNumber(text);
diff --git a/java/com/android/dialer/app/filterednumber/NumbersAdapter.java b/java/com/android/dialer/app/filterednumber/NumbersAdapter.java
index 938a78479..bdd6dcee8 100644
--- a/java/com/android/dialer/app/filterednumber/NumbersAdapter.java
+++ b/java/com/android/dialer/app/filterednumber/NumbersAdapter.java
@@ -72,7 +72,7 @@ public class NumbersAdapter extends SimpleCursorAdapter {
info = new ContactInfo();
info.number = number;
}
- final CharSequence locationOrType = getNumberTypeOrLocation(info);
+ final CharSequence locationOrType = getNumberTypeOrLocation(info, countryIso);
final String displayNumber = getDisplayNumber(info);
final String displayNumberStr =
mBidiFormatter.unicodeWrap(displayNumber, TextDirectionHeuristics.LTR);
@@ -121,12 +121,12 @@ public class NumbersAdapter extends SimpleCursorAdapter {
}
}
- private CharSequence getNumberTypeOrLocation(ContactInfo info) {
+ private CharSequence getNumberTypeOrLocation(ContactInfo info, String countryIso) {
if (!TextUtils.isEmpty(info.name)) {
return ContactsContract.CommonDataKinds.Phone.getTypeLabel(
mContext.getResources(), info.type, info.label);
} else {
- return PhoneNumberHelper.getGeoDescription(mContext, info.number);
+ return PhoneNumberHelper.getGeoDescription(mContext, info.number, countryIso);
}
}
diff --git a/java/com/android/dialer/compat/telephony/TelephonyManagerCompat.java b/java/com/android/dialer/compat/telephony/TelephonyManagerCompat.java
index db1dd4ac4..ecd36d359 100644
--- a/java/com/android/dialer/compat/telephony/TelephonyManagerCompat.java
+++ b/java/com/android/dialer/compat/telephony/TelephonyManagerCompat.java
@@ -198,4 +198,34 @@ public class TelephonyManagerCompat {
context.sendBroadcast(intent);
}
}
+
+ /**
+ * Returns network country iso for given {@code PhoneAccountHandle} for O+ devices and country iso
+ * for default sim for pre-O devices.
+ */
+ public static String getNetworkCountryIsoForPhoneAccountHandle(
+ Context context, @Nullable PhoneAccountHandle phoneAccountHandle) {
+ return getTelephonyManagerForPhoneAccountHandle(context, phoneAccountHandle)
+ .getNetworkCountryIso();
+ }
+
+ /**
+ * Returns TelephonyManager for given {@code PhoneAccountHandle} for O+ devices and default {@code
+ * TelephonyManager} for pre-O devices.
+ */
+ public static TelephonyManager getTelephonyManagerForPhoneAccountHandle(
+ Context context, @Nullable PhoneAccountHandle phoneAccountHandle) {
+ TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class);
+ if (phoneAccountHandle == null) {
+ return telephonyManager;
+ }
+ if (VERSION.SDK_INT >= VERSION_CODES.O) {
+ TelephonyManager telephonyManagerForPhoneAccount =
+ telephonyManager.createForPhoneAccountHandle(phoneAccountHandle);
+ if (telephonyManagerForPhoneAccount != null) {
+ return telephonyManagerForPhoneAccount;
+ }
+ }
+ return telephonyManager;
+ }
}
diff --git a/java/com/android/dialer/phonenumbergeoutil/PhoneNumberGeoUtil.java b/java/com/android/dialer/phonenumbergeoutil/PhoneNumberGeoUtil.java
index 2005abc68..7e4559828 100644
--- a/java/com/android/dialer/phonenumbergeoutil/PhoneNumberGeoUtil.java
+++ b/java/com/android/dialer/phonenumbergeoutil/PhoneNumberGeoUtil.java
@@ -20,5 +20,6 @@ import android.content.Context;
/** Interface for getting geo information for phone number. */
public interface PhoneNumberGeoUtil {
- String getGeoDescription(Context context, String number);
+ /** Returns geo location information for a phone number, e.g. California. */
+ String getGeoDescription(Context context, String number, String countryIso);
}
diff --git a/java/com/android/dialer/phonenumbergeoutil/impl/PhoneNumberGeoUtilImpl.java b/java/com/android/dialer/phonenumbergeoutil/impl/PhoneNumberGeoUtilImpl.java
index 32f65927d..fb28ed588 100644
--- a/java/com/android/dialer/phonenumbergeoutil/impl/PhoneNumberGeoUtilImpl.java
+++ b/java/com/android/dialer/phonenumbergeoutil/impl/PhoneNumberGeoUtilImpl.java
@@ -21,7 +21,6 @@ import android.text.TextUtils;
import com.android.dialer.common.LogUtil;
import com.android.dialer.compat.CompatUtils;
import com.android.dialer.phonenumbergeoutil.PhoneNumberGeoUtil;
-import com.android.dialer.phonenumberutil.PhoneNumberHelper;
import com.google.i18n.phonenumbers.NumberParseException;
import com.google.i18n.phonenumbers.PhoneNumberUtil;
import com.google.i18n.phonenumbers.Phonenumber;
@@ -36,7 +35,7 @@ public class PhoneNumberGeoUtilImpl implements PhoneNumberGeoUtil {
public PhoneNumberGeoUtilImpl() {}
@Override
- public String getGeoDescription(Context context, String number) {
+ public String getGeoDescription(Context context, String number, String countryIso) {
LogUtil.v("PhoneNumberGeoUtilImpl.getGeoDescription", "" + LogUtil.sanitizePii(number));
if (TextUtils.isEmpty(number)) {
@@ -47,7 +46,6 @@ public class PhoneNumberGeoUtilImpl implements PhoneNumberGeoUtil {
PhoneNumberOfflineGeocoder geocoder = PhoneNumberOfflineGeocoder.getInstance();
Locale locale = CompatUtils.getLocale(context);
- String countryIso = PhoneNumberHelper.getCurrentCountryIso(context, locale);
Phonenumber.PhoneNumber pn = null;
try {
LogUtil.v(
diff --git a/java/com/android/dialer/phonenumbergeoutil/stub/PhoneNumberGeoUtilStub.java b/java/com/android/dialer/phonenumbergeoutil/stub/PhoneNumberGeoUtilStub.java
index 4c5b3b0b3..06cd13760 100644
--- a/java/com/android/dialer/phonenumbergeoutil/stub/PhoneNumberGeoUtilStub.java
+++ b/java/com/android/dialer/phonenumbergeoutil/stub/PhoneNumberGeoUtilStub.java
@@ -26,7 +26,7 @@ public final class PhoneNumberGeoUtilStub implements PhoneNumberGeoUtil {
public PhoneNumberGeoUtilStub() {}
@Override
- public String getGeoDescription(Context context, String number) {
+ public String getGeoDescription(Context context, String number, String countryIso) {
return null;
}
}
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;
}
diff --git a/java/com/android/incallui/CallerInfo.java b/java/com/android/incallui/CallerInfo.java
index e552d7cd9..cc1a60a5b 100644
--- a/java/com/android/incallui/CallerInfo.java
+++ b/java/com/android/incallui/CallerInfo.java
@@ -162,6 +162,8 @@ public class CallerInfo {
*/
public String callSubject;
+ public String countryIso;
+
private boolean mIsEmergency;
private boolean mIsVoiceMail;
@@ -522,7 +524,7 @@ public class CallerInfo {
*/
public void updateGeoDescription(Context context, String fallbackNumber) {
String number = TextUtils.isEmpty(phoneNumber) ? fallbackNumber : phoneNumber;
- geoDescription = PhoneNumberHelper.getGeoDescription(context, number);
+ geoDescription = PhoneNumberHelper.getGeoDescription(context, number, countryIso);
}
/** @return a string debug representation of this instance. */
diff --git a/java/com/android/incallui/CallerInfoAsyncQuery.java b/java/com/android/incallui/CallerInfoAsyncQuery.java
index 858d0f4b7..86b1b7f22 100644
--- a/java/com/android/incallui/CallerInfoAsyncQuery.java
+++ b/java/com/android/incallui/CallerInfoAsyncQuery.java
@@ -162,6 +162,7 @@ public class CallerInfoAsyncQuery {
cw.listener = listener;
cw.cookie = cookie;
cw.number = info.phoneNumber;
+ cw.countryIso = info.countryIso;
// check to see if these are recognized numbers, and use shortcuts if we can.
if (PhoneNumberUtils.isLocalEmergencyNumber(context, info.phoneNumber)) {
@@ -268,6 +269,7 @@ public class CallerInfoAsyncQuery {
public Object cookie;
public int event;
public String number;
+ public String countryIso;
}
/* Directory lookup related code - END */
@@ -493,6 +495,7 @@ public class CallerInfoAsyncQuery {
mCallerInfo = newCallerInfo;
Log.d(this, "#####async contact look up with numeric username" + mCallerInfo);
}
+ mCallerInfo.countryIso = cw.countryIso;
// Final step: look up the geocoded description.
if (ENABLE_UNKNOWN_NUMBER_GEO_DESCRIPTION) {
diff --git a/java/com/android/incallui/CallerInfoUtils.java b/java/com/android/incallui/CallerInfoUtils.java
index 8f2310760..bf586f504 100644
--- a/java/com/android/incallui/CallerInfoUtils.java
+++ b/java/com/android/incallui/CallerInfoUtils.java
@@ -70,7 +70,7 @@ public class CallerInfoUtils {
"CallerInfoUtils.getCallerInfoForCall",
"Actually starting CallerInfoAsyncQuery.startQuery()...");
- //noinspection MissingPermission
+ // noinspection MissingPermission
CallerInfoAsyncQuery.startQuery(QUERY_TOKEN, context, info, listener, cookie);
} else {
LogUtil.w(
@@ -93,6 +93,7 @@ public class CallerInfoUtils {
info.namePresentation = call.getCnapNamePresentation();
info.callSubject = call.getCallSubject();
info.contactExists = false;
+ info.countryIso = PhoneNumberHelper.getCurrentCountryIso(context, call.getAccountHandle());
String number = call.getNumber();
if (!TextUtils.isEmpty(number)) {
diff --git a/java/com/android/incallui/ContactInfoCache.java b/java/com/android/incallui/ContactInfoCache.java
index 7bac6d329..39c4c2fda 100644
--- a/java/com/android/incallui/ContactInfoCache.java
+++ b/java/com/android/incallui/ContactInfoCache.java
@@ -211,7 +211,7 @@ public class ContactInfoCache implements OnImageLoadCompleteListener {
// No name, but we do have a valid CNAP name, so use that.
displayName = info.cnapName;
info.name = info.cnapName;
- displayNumber = PhoneNumberHelper.formatNumber(number, context);
+ displayNumber = PhoneNumberHelper.formatNumber(number, info.countryIso);
Log.d(
TAG,
" ==> cnapName available: displayName '"
@@ -224,7 +224,7 @@ public class ContactInfoCache implements OnImageLoadCompleteListener {
// case when an incoming call doesn't match any contact,
// or if you manually dial an outgoing number using the
// dialpad.
- displayNumber = PhoneNumberHelper.formatNumber(number, context);
+ displayNumber = PhoneNumberHelper.formatNumber(number, info.countryIso);
Log.d(
TAG,
@@ -249,7 +249,7 @@ public class ContactInfoCache implements OnImageLoadCompleteListener {
// later determine whether to use the name or nameAlternative when presenting
displayName = info.name;
cce.nameAlternative = info.nameAlternative;
- displayNumber = PhoneNumberHelper.formatNumber(number, context);
+ displayNumber = PhoneNumberHelper.formatNumber(number, info.countryIso);
label = info.phoneLabel;
Log.d(
TAG,