diff options
Diffstat (limited to 'java/com/android/dialer/phonenumberproto/PartitionedNumbers.java')
-rw-r--r-- | java/com/android/dialer/phonenumberproto/PartitionedNumbers.java | 35 |
1 files changed, 14 insertions, 21 deletions
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. + * + * <p>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<String, ImmutableSet<DialerPhoneNumber>> @@ -40,29 +40,27 @@ public final class PartitionedNumbers { private final ImmutableMap<String, ImmutableSet<DialerPhoneNumber>> invalidNumbersToDialerPhoneNumbers; + /** + * Divides a set of {@link DialerPhoneNumber DialerPhoneNumbers} according to those that are valid + * according to libphonenumber, and those that are not. + * + * <p>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<DialerPhoneNumber> dialerPhoneNumbers) { Assert.isWorkerThread(); - DialerPhoneNumberUtil dialerPhoneNumberUtil = - new DialerPhoneNumberUtil(PhoneNumberUtil.getInstance()); Map<String, Set<DialerPhoneNumber>> e164MapBuilder = new ArrayMap<>(); Map<String, Set<DialerPhoneNumber>> invalidMapBuilder = new ArrayMap<>(); for (DialerPhoneNumber dialerPhoneNumber : dialerPhoneNumbers) { - Optional<String> 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<DialerPhoneNumber> 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<String> invalidNumbers() { |