summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/telecom
diff options
context:
space:
mode:
authorzachh <zachh@google.com>2017-12-15 23:50:27 -0800
committerCopybara-Service <copybara-piper@google.com>2017-12-15 23:51:37 -0800
commite3b74d22b4e92009433e07f29973f53fb90613e1 (patch)
tree1a7612102ab551b0a765bd35ef89f0f28e1922a6 /java/com/android/dialer/telecom
parent14690e983b0858d8ee4679adc54c1810a8ccddcc (diff)
Implemented Cp2PhoneLookup#lookup.
Bug: 34672501 Test: unit PiperOrigin-RevId: 179278530 Change-Id: If629aa2c31efad790c8c70e8066dc9a5612d1fc3
Diffstat (limited to 'java/com/android/dialer/telecom')
-rw-r--r--java/com/android/dialer/telecom/TelecomCallUtil.java46
1 files changed, 31 insertions, 15 deletions
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.
+ *
+ * <p>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<String> getNormalizedNumber(Context appContext, Call call) {
Assert.isWorkerThread();
+
+ Optional<String> 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.
+ *
+ * <p>If the number cannot be formatted (because for example the country cannot be determined),
+ * returns {@link Optional#absent()}.
+ */
+ @WorkerThread
+ public static Optional<String> getE164Number(Context appContext, Call call) {
+ Assert.isWorkerThread();
PhoneAccountHandle phoneAccountHandle = call.getDetails().getAccountHandle();
Optional<SubscriptionInfo> 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)));
}
}