summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/phonenumberproto
diff options
context:
space:
mode:
authorzachh <zachh@google.com>2018-01-08 14:13:07 -0800
committerCopybara-Service <copybara-piper@google.com>2018-01-08 17:12:35 -0800
commitc40c2d996479d926b174777d7186347e7776ccc5 (patch)
tree6afa7f36f322e3d300be2df58872721701b65ab6 /java/com/android/dialer/phonenumberproto
parentfdbf2a0d7124af3e3026acbe39873bd2deea13ed (diff)
Use ContactsContract.PhoneLookup for invalid numbers in Cp2PhoneLookup.
"Invalid" numbers are identified according to PhoneNumberUtil.isValidNumber. This is necessary to support loose matching for such numbers. However, ContactsContract.PhoneLookup only supports looking up individual numbers, which means that we cannot issue batch queries and must issue individiual queries for each invalid number. The hope is that these numbers won't appear frequently so performance should still be acceptable. However, as a failsafe, if there are more than 5 invalid numbers we just give up trying to bulk update the invalid numbers and signal that those numbers are INCOMPLETE so that the UI can query for their CP2 information on the fly (the UI will be updated in a future CL). It was necessary to convert much of the class to use futures to support parallelization of the queries. Bug: 71504246 Test: unit PiperOrigin-RevId: 181216674 Change-Id: I3bec477d305772b4ca3e46d0bd326cfebf9fa313
Diffstat (limited to 'java/com/android/dialer/phonenumberproto')
-rw-r--r--java/com/android/dialer/phonenumberproto/DialerPhoneNumberUtil.java26
1 files changed, 18 insertions, 8 deletions
diff --git a/java/com/android/dialer/phonenumberproto/DialerPhoneNumberUtil.java b/java/com/android/dialer/phonenumberproto/DialerPhoneNumberUtil.java
index d23b5a19d..8cb4557cb 100644
--- a/java/com/android/dialer/phonenumberproto/DialerPhoneNumberUtil.java
+++ b/java/com/android/dialer/phonenumberproto/DialerPhoneNumberUtil.java
@@ -20,6 +20,7 @@ import android.support.annotation.AnyThread;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.WorkerThread;
+import android.telephony.PhoneNumberUtils;
import com.android.dialer.DialerInternalPhoneNumber;
import com.android.dialer.DialerPhoneNumber;
import com.android.dialer.DialerPhoneNumber.RawInput;
@@ -128,29 +129,38 @@ public class DialerPhoneNumberUtil {
}
/**
- * Formats the provided number to e164 format or return raw number if number is unparseable.
+ * Formats the provided number to E164 format or return a normalized version of the raw number if
+ * the number is not valid according to {@link PhoneNumberUtil#isValidNumber(PhoneNumber)}.
*
- * @see PhoneNumberUtil#format(PhoneNumber, PhoneNumberFormat)
+ * @see #formatToE164(DialerPhoneNumber)
+ * @see PhoneNumberUtils#normalizeNumber(String)
*/
@WorkerThread
public String normalizeNumber(DialerPhoneNumber number) {
Assert.isWorkerThread();
- return formatToE164(number).or(number.getRawInput().getNumber());
+ return formatToE164(number)
+ .or(PhoneNumberUtils.normalizeNumber(number.getRawInput().getNumber()));
}
/**
- * Formats the provided number to e164 format if possible.
+ * If the provided number is "valid" (see {@link PhoneNumberUtil#isValidNumber(PhoneNumber)}),
+ * formats it to E.164. Otherwise, returns {@link Optional#absent()}.
+ *
+ * <p>This method is analogous to {@link PhoneNumberUtils#formatNumberToE164(String, String)} (but
+ * works with an already parsed {@link DialerPhoneNumber} object).
*
+ * @see PhoneNumberUtil#isValidNumber(PhoneNumber)
* @see PhoneNumberUtil#format(PhoneNumber, PhoneNumberFormat)
+ * @see PhoneNumberUtils#formatNumberToE164(String, String)
*/
@WorkerThread
public Optional<String> formatToE164(DialerPhoneNumber number) {
Assert.isWorkerThread();
if (number.hasDialerInternalPhoneNumber()) {
- return Optional.of(
- phoneNumberUtil.format(
- Converter.protoToPojo(number.getDialerInternalPhoneNumber()),
- PhoneNumberFormat.E164));
+ PhoneNumber phoneNumber = Converter.protoToPojo(number.getDialerInternalPhoneNumber());
+ if (phoneNumberUtil.isValidNumber(phoneNumber)) {
+ return Optional.fromNullable(phoneNumberUtil.format(phoneNumber, PhoneNumberFormat.E164));
+ }
}
return Optional.absent();
}