summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzachh <zachh@google.com>2018-04-17 18:05:25 -0700
committerCopybara-Service <copybara-piper@google.com>2018-04-17 18:25:49 -0700
commit9e73256fa20b95dd05bf9b46fe43ad96c3823178 (patch)
treeb3c906e6253b82c88de50ad57825019649ed3e7c
parent882c5bc1909eea75ac407120a1c3d36348372afd (diff)
Improved support for short codes in Coalescer.
Use ShortNumberInfo to identify shortcodes and apply more basic matching for them; without this short codes like '5555' and '55555' would match due to being a SHORT_NSN_MATCH even though they should not match. Also removed the PhoneNumberUtil argument from DialerPhoneNumberUtil's constructor as it was always PhoneNumberUtil.getInstance(). (This allowed me to do a similar thing for ShortNumberInfo.getInstance()). TEST=unit Bug: 71586485 Test: unit PiperOrigin-RevId: 193288929 Change-Id: Ia16c78e7eee5e0912d3913660952b9ee32713731
-rw-r--r--java/com/android/dialer/calllog/database/Coalescer.java4
-rw-r--r--java/com/android/dialer/calllog/datasources/systemcalllog/SystemCallLogDataSource.java4
-rw-r--r--java/com/android/dialer/commandline/impl/BlockingCommand.java4
-rw-r--r--java/com/android/dialer/phonenumberproto/DialerPhoneNumberUtil.java14
-rw-r--r--java/com/android/incallui/PhoneLookupHistoryRecorder.java4
5 files changed, 16 insertions, 14 deletions
diff --git a/java/com/android/dialer/calllog/database/Coalescer.java b/java/com/android/dialer/calllog/database/Coalescer.java
index 5fdf0dfd9..8a16be2da 100644
--- a/java/com/android/dialer/calllog/database/Coalescer.java
+++ b/java/com/android/dialer/calllog/database/Coalescer.java
@@ -33,7 +33,6 @@ import com.android.dialer.compat.telephony.TelephonyManagerCompat;
import com.android.dialer.phonenumberproto.DialerPhoneNumberUtil;
import com.android.dialer.telecom.TelecomUtil;
import com.google.common.base.Preconditions;
-import com.google.i18n.phonenumbers.PhoneNumberUtil;
import com.google.protobuf.InvalidProtocolBufferException;
import java.util.ArrayList;
import java.util.List;
@@ -73,8 +72,7 @@ public class Coalescer {
// Note: This method relies on rowsShouldBeCombined to determine which rows should be combined,
// but delegates to data sources to actually aggregate column values.
- DialerPhoneNumberUtil dialerPhoneNumberUtil =
- new DialerPhoneNumberUtil(PhoneNumberUtil.getInstance());
+ DialerPhoneNumberUtil dialerPhoneNumberUtil = new DialerPhoneNumberUtil();
MatrixCursor allCoalescedRowsMatrixCursor =
new MatrixCursor(
diff --git a/java/com/android/dialer/calllog/datasources/systemcalllog/SystemCallLogDataSource.java b/java/com/android/dialer/calllog/datasources/systemcalllog/SystemCallLogDataSource.java
index 99c3c9d0c..661b2495b 100644
--- a/java/com/android/dialer/calllog/datasources/systemcalllog/SystemCallLogDataSource.java
+++ b/java/com/android/dialer/calllog/datasources/systemcalllog/SystemCallLogDataSource.java
@@ -57,7 +57,6 @@ import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
-import com.google.i18n.phonenumbers.PhoneNumberUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -251,8 +250,7 @@ public class SystemCallLogDataSource implements CallLogDataSource {
Context appContext, CallLogMutations mutations, Set<Long> existingAnnotatedCallLogIds) {
long previousTimestampProcessed = sharedPreferences.getLong(PREF_LAST_TIMESTAMP_PROCESSED, 0L);
- DialerPhoneNumberUtil dialerPhoneNumberUtil =
- new DialerPhoneNumberUtil(PhoneNumberUtil.getInstance());
+ DialerPhoneNumberUtil dialerPhoneNumberUtil = new DialerPhoneNumberUtil();
// TODO(zachh): Really should be getting last 1000 by timestamp, not by last modified.
try (Cursor cursor =
diff --git a/java/com/android/dialer/commandline/impl/BlockingCommand.java b/java/com/android/dialer/commandline/impl/BlockingCommand.java
index c8f893422..f06e240ae 100644
--- a/java/com/android/dialer/commandline/impl/BlockingCommand.java
+++ b/java/com/android/dialer/commandline/impl/BlockingCommand.java
@@ -32,7 +32,6 @@ import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
-import com.google.i18n.phonenumbers.PhoneNumberUtil;
import javax.inject.Inject;
/** Block or unblock a number. */
@@ -88,8 +87,7 @@ public class BlockingCommand implements Command {
if ("isblocked".equals(command)) {
String number = args.getPositionals().get(1);
ListenableFuture<DialerPhoneNumber> dialerPhoneNumberFuture =
- executorService.submit(
- () -> new DialerPhoneNumberUtil(PhoneNumberUtil.getInstance()).parse(number, null));
+ executorService.submit(() -> new DialerPhoneNumberUtil().parse(number, null));
ListenableFuture<PhoneLookupInfo> lookupFuture =
Futures.transformAsync(
diff --git a/java/com/android/dialer/phonenumberproto/DialerPhoneNumberUtil.java b/java/com/android/dialer/phonenumberproto/DialerPhoneNumberUtil.java
index a5b9520fd..d8079efe3 100644
--- a/java/com/android/dialer/phonenumberproto/DialerPhoneNumberUtil.java
+++ b/java/com/android/dialer/phonenumberproto/DialerPhoneNumberUtil.java
@@ -29,6 +29,7 @@ import com.google.i18n.phonenumbers.PhoneNumberUtil;
import com.google.i18n.phonenumbers.PhoneNumberUtil.MatchType;
import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat;
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
+import com.google.i18n.phonenumbers.ShortNumberInfo;
/**
* Wrapper for selected methods in {@link PhoneNumberUtil} which uses the {@link DialerPhoneNumber}
@@ -38,11 +39,13 @@ import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
*/
public class DialerPhoneNumberUtil {
private final PhoneNumberUtil phoneNumberUtil;
+ private final ShortNumberInfo shortNumberInfo;
@WorkerThread
- public DialerPhoneNumberUtil(@NonNull PhoneNumberUtil phoneNumberUtil) {
+ public DialerPhoneNumberUtil() {
Assert.isWorkerThread();
- this.phoneNumberUtil = Assert.isNotNull(phoneNumberUtil);
+ this.phoneNumberUtil = PhoneNumberUtil.getInstance();
+ this.shortNumberInfo = ShortNumberInfo.getInstance();
}
/**
@@ -159,6 +162,13 @@ public class DialerPhoneNumberUtil {
return firstNumberIn.getNormalizedNumber().equals(secondNumberIn.getNormalizedNumber());
}
+ // Both numbers are parseable, first check for short codes to so that a number like "5555"
+ // doesn't match "55555" (due to those being a SHORT_NSN_MATCH below).
+ if (shortNumberInfo.isPossibleShortNumber(phoneNumber1)
+ || shortNumberInfo.isPossibleShortNumber(phoneNumber2)) {
+ return firstNumberIn.getNormalizedNumber().equals(secondNumberIn.getNormalizedNumber());
+ }
+
// Both numbers are parseable, use more sophisticated libphonenumber matching.
MatchType matchType = phoneNumberUtil.isNumberMatch(phoneNumber1, phoneNumber2);
diff --git a/java/com/android/incallui/PhoneLookupHistoryRecorder.java b/java/com/android/incallui/PhoneLookupHistoryRecorder.java
index 2b8075878..4f4137049 100644
--- a/java/com/android/incallui/PhoneLookupHistoryRecorder.java
+++ b/java/com/android/incallui/PhoneLookupHistoryRecorder.java
@@ -36,7 +36,6 @@ import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
-import com.google.i18n.phonenumbers.PhoneNumberUtil;
/**
* Fetches the current {@link PhoneLookupInfo} for the provided call and writes it to the
@@ -59,8 +58,7 @@ final class PhoneLookupHistoryRecorder {
ListenableFuture<DialerPhoneNumber> numberFuture =
backgroundExecutor.submit(
() -> {
- DialerPhoneNumberUtil dialerPhoneNumberUtil =
- new DialerPhoneNumberUtil(PhoneNumberUtil.getInstance());
+ DialerPhoneNumberUtil dialerPhoneNumberUtil = new DialerPhoneNumberUtil();
return dialerPhoneNumberUtil.parse(
TelecomCallUtil.getNumber(call), GeoUtil.getCurrentCountryIso(appContext));
});