From 75a8d5170399b37d33bced7825a9f6d88a5ec233 Mon Sep 17 00:00:00 2001 From: zachh Date: Mon, 29 Jan 2018 13:45:58 -0800 Subject: Added is_valid and post_dial_portion fields to DialerPhoneNumber. These are frequently used attributes of numbers that we can compute once at parse-time. Also did some general cleanup of DialerPhoneNumberUtil: -Removed unused Future version of parse() -Remove formatToValidE164 now that the new fields are available -Inlined normalizeNumber() Bug: 72563861 Test: existing PiperOrigin-RevId: 183720128 Change-Id: I702dc265360e590439c5352c493ae8a858f36812 --- .../phonenumberproto/PartitionedNumbers.java | 35 +++++++++------------- 1 file changed, 14 insertions(+), 21 deletions(-) (limited to 'java/com/android/dialer/phonenumberproto/PartitionedNumbers.java') diff --git a/java/com/android/dialer/phonenumberproto/PartitionedNumbers.java b/java/com/android/dialer/phonenumberproto/PartitionedNumbers.java index dbf99365c..2c19c1232 100644 --- a/java/com/android/dialer/phonenumberproto/PartitionedNumbers.java +++ b/java/com/android/dialer/phonenumberproto/PartitionedNumbers.java @@ -20,19 +20,19 @@ import android.support.annotation.NonNull; import android.support.annotation.WorkerThread; import android.support.v4.util.ArrayMap; import android.support.v4.util.ArraySet; -import android.telephony.PhoneNumberUtils; import com.android.dialer.DialerPhoneNumber; import com.android.dialer.common.Assert; -import com.google.common.base.Optional; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.google.i18n.phonenumbers.PhoneNumberUtil; import java.util.Map; import java.util.Set; /** * Divides a set of {@link DialerPhoneNumber DialerPhoneNumbers} according to those that are valid * according to libphonenumber, and those that are not. + * + *

Numbers with post-dial portions are always considered invalid as most systems store E164 + * numbers which do not support post-dial portions. */ public final class PartitionedNumbers { private final ImmutableMap> @@ -40,29 +40,27 @@ public final class PartitionedNumbers { private final ImmutableMap> invalidNumbersToDialerPhoneNumbers; + /** + * Divides a set of {@link DialerPhoneNumber DialerPhoneNumbers} according to those that are valid + * according to libphonenumber, and those that are not. + * + *

Numbers with post-dial portions are always considered invalid as most systems store E164 + * numbers which do not support post-dial portions. + */ @WorkerThread public PartitionedNumbers(@NonNull ImmutableSet dialerPhoneNumbers) { Assert.isWorkerThread(); - DialerPhoneNumberUtil dialerPhoneNumberUtil = - new DialerPhoneNumberUtil(PhoneNumberUtil.getInstance()); Map> e164MapBuilder = new ArrayMap<>(); Map> invalidMapBuilder = new ArrayMap<>(); for (DialerPhoneNumber dialerPhoneNumber : dialerPhoneNumbers) { - Optional optValidE164 = dialerPhoneNumberUtil.formatToValidE164(dialerPhoneNumber); /* * Numbers with post-dial digits are considered valid and can be converted to E164, but their - * post dial digits are lost in the process. Similarly, if a contact's number has a post-dial - * digits, the normalized version of it stored in the contacts database does not include the - * post dial digits. - * - * A number with post-dial digits should not match a contact whose number does not have - * post-dial digits, which means that we cannot normalize such numbers for use in bulk lookup. - * Treat them as invalid which will cause them to be processed individually using - * ContactsContract.PHONE_LOOKUP. + * post dial digits are lost in the process. For example, the normalized version of a number + * with a post-dial portion in the contacts database is stored without the post-dial portion. */ - if (optValidE164.isPresent() && !hasPostDialDigits(dialerPhoneNumber)) { - String validE164 = optValidE164.get(); + if (dialerPhoneNumber.getIsValid() && dialerPhoneNumber.getPostDialPortion().isEmpty()) { + String validE164 = dialerPhoneNumber.getNormalizedNumber(); Set currentNumbers = e164MapBuilder.get(validE164); if (currentNumbers == null) { currentNumbers = new ArraySet<>(); @@ -84,11 +82,6 @@ public final class PartitionedNumbers { invalidNumbersToDialerPhoneNumbers = makeImmutable(invalidMapBuilder); } - private boolean hasPostDialDigits(DialerPhoneNumber dialerPhoneNumber) { - return !PhoneNumberUtils.extractPostDialPortion(dialerPhoneNumber.getNormalizedNumber()) - .isEmpty(); - } - /** Returns the set of invalid numbers from the original DialerPhoneNumbers */ @NonNull public ImmutableSet invalidNumbers() { -- cgit v1.2.3