summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/phonenumberproto/PartitionedNumbers.java
diff options
context:
space:
mode:
authorzachh <zachh@google.com>2018-01-29 13:45:58 -0800
committerCopybara-Service <copybara-piper@google.com>2018-01-29 15:36:05 -0800
commit75a8d5170399b37d33bced7825a9f6d88a5ec233 (patch)
tree35a7e6ae0b6dbdae5ba84388a55853af78ac875f /java/com/android/dialer/phonenumberproto/PartitionedNumbers.java
parentadd7d143419d8ada612eb3e0bb2807b0e97dff35 (diff)
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
Diffstat (limited to 'java/com/android/dialer/phonenumberproto/PartitionedNumbers.java')
-rw-r--r--java/com/android/dialer/phonenumberproto/PartitionedNumbers.java35
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() {