From e3b74d22b4e92009433e07f29973f53fb90613e1 Mon Sep 17 00:00:00 2001 From: zachh Date: Fri, 15 Dec 2017 23:50:27 -0800 Subject: Implemented Cp2PhoneLookup#lookup. Bug: 34672501 Test: unit PiperOrigin-RevId: 179278530 Change-Id: If629aa2c31efad790c8c70e8066dc9a5612d1fc3 --- .../android/dialer/telecom/TelecomCallUtil.java | 46 +++++++++++++++------- 1 file changed, 31 insertions(+), 15 deletions(-) (limited to 'java/com/android/dialer/telecom') diff --git a/java/com/android/dialer/telecom/TelecomCallUtil.java b/java/com/android/dialer/telecom/TelecomCallUtil.java index acec49851..b877a7392 100644 --- a/java/com/android/dialer/telecom/TelecomCallUtil.java +++ b/java/com/android/dialer/telecom/TelecomCallUtil.java @@ -72,13 +72,37 @@ public class TelecomCallUtil { } /** - * Normalizes the number of the {@code call} to E.164. If the country code is missing in the - * number the SIM's country will be used. Only removes non-dialable digits if the country code is - * missing. + * Normalizes the number of the {@code call} to E.164. The country of the SIM associated with the + * call is used to determine the country. + * + *

If the number cannot be formatted (because for example the country cannot be determined), + * returns the number with non-dialable digits removed. */ @WorkerThread public static Optional getNormalizedNumber(Context appContext, Call call) { Assert.isWorkerThread(); + + Optional e164 = getE164Number(appContext, call); + if (e164.isPresent()) { + return e164; + } + String rawNumber = getNumber(call); + if (TextUtils.isEmpty(rawNumber)) { + return Optional.absent(); + } + return Optional.of(PhoneNumberUtils.normalizeNumber(rawNumber)); + } + + /** + * Formats the number of the {@code call} to E.164. The country of the SIM associated with the + * call is used to determine the country. + * + *

If the number cannot be formatted (because for example the country cannot be determined), + * returns {@link Optional#absent()}. + */ + @WorkerThread + public static Optional getE164Number(Context appContext, Call call) { + Assert.isWorkerThread(); PhoneAccountHandle phoneAccountHandle = call.getDetails().getAccountHandle(); Optional subscriptionInfo = TelecomUtil.getSubscriptionInfo(appContext, phoneAccountHandle); @@ -86,21 +110,13 @@ public class TelecomCallUtil { if (TextUtils.isEmpty(rawNumber)) { return Optional.absent(); } - String normalizedNumber = PhoneNumberUtils.normalizeNumber(rawNumber); - if (TextUtils.isEmpty(normalizedNumber)) { - return Optional.absent(); - } String countryCode = subscriptionInfo.isPresent() ? subscriptionInfo.get().getCountryIso() : null; if (countryCode == null) { - LogUtil.w( - "PhoneLookupHistoryRecorder.getNormalizedNumber", - "couldn't find a country code for call"); - return Optional.of(normalizedNumber); + LogUtil.w("TelecomCallUtil.getE164Number", "couldn't find a country code for call"); + return Optional.absent(); } - - String e164Number = - PhoneNumberUtils.formatNumberToE164(rawNumber, countryCode.toUpperCase(Locale.US)); - return e164Number == null ? Optional.of(normalizedNumber) : Optional.of(e164Number); + return Optional.fromNullable( + PhoneNumberUtils.formatNumberToE164(rawNumber, countryCode.toUpperCase(Locale.US))); } } -- cgit v1.2.3