summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormaxwelb <maxwelb@google.com>2017-07-19 16:25:50 -0700
committerEric Erfanian <erfanian@google.com>2017-07-25 16:43:24 +0000
commit37768b95c107421320b7fba30bb81158b8215e2f (patch)
treede16bae5490130a13a74a00a59259ee7c58ae008
parent0c408e0e3c82bff80871c3a3f2de5d37bc398a42 (diff)
Fix non-normalized number bug with FuzzyPhoneNumberMatcher
This CL fixes a bug with the FuzzyPhoneNumberMatcher implementation. The logic should be that if the last 7 digits of two numbers match, we treat them as the same. The issue was that if we found digits that didn't match between the number, we reported them as not matching, even if they had 7 digits in common. This CL also makes some quality of life changes: - Renames FuzzyNumberMatcher to FuzzyPhoneNumberMatcher to match the class name. - Abstracts the logic of the FuzzyPhoneNumberMatcher into another well named method, so it's more clear how the code works. While I didn't check too carefully, I believe this will also help out issues with capability flakiness in: - b/62609419 | maxwelb | RCS very unstable when on cellular. Bug: 63564400,62609419 Test: FuzzyPhoneNumberMatcherTest PiperOrigin-RevId: 162552340 Change-Id: Ie091d985a34a16000750f6050bde6bb0ea7da4e5
-rw-r--r--java/com/android/dialer/enrichedcall/FuzzyPhoneNumberMatcher.java31
1 files changed, 20 insertions, 11 deletions
diff --git a/java/com/android/dialer/enrichedcall/FuzzyPhoneNumberMatcher.java b/java/com/android/dialer/enrichedcall/FuzzyPhoneNumberMatcher.java
index 27dc0e90c..6f4d97521 100644
--- a/java/com/android/dialer/enrichedcall/FuzzyPhoneNumberMatcher.java
+++ b/java/com/android/dialer/enrichedcall/FuzzyPhoneNumberMatcher.java
@@ -29,25 +29,34 @@ public class FuzzyPhoneNumberMatcher {
* too slow, so character by character matching is used instead.
*/
public static boolean matches(@NonNull String lhs, @NonNull String rhs) {
- int aIndex = lhs.length() - 1;
- int bIndex = rhs.length() - 1;
+ return lastSevenDigitsCharacterByCharacterMatches(lhs, rhs);
+ }
+
+ /**
+ * This strategy examines the numbers character by character starting from the end. If the last
+ * {@link #REQUIRED_MATCHED_DIGITS} match, it returns {@code true}.
+ */
+ private static boolean lastSevenDigitsCharacterByCharacterMatches(
+ @NonNull String lhs, @NonNull String rhs) {
+ int lhsIndex = lhs.length() - 1;
+ int rhsIndex = rhs.length() - 1;
int matchedDigits = 0;
- while (aIndex >= 0 && bIndex >= 0) {
- if (!Character.isDigit(lhs.charAt(aIndex))) {
- --aIndex;
+ while (lhsIndex >= 0 && rhsIndex >= 0) {
+ if (!Character.isDigit(lhs.charAt(lhsIndex))) {
+ --lhsIndex;
continue;
}
- if (!Character.isDigit(rhs.charAt(bIndex))) {
- --bIndex;
+ if (!Character.isDigit(rhs.charAt(rhsIndex))) {
+ --rhsIndex;
continue;
}
- if (lhs.charAt(aIndex) != rhs.charAt(bIndex)) {
- return false;
+ if (lhs.charAt(lhsIndex) != rhs.charAt(rhsIndex)) {
+ break;
}
- --aIndex;
- --bIndex;
+ --lhsIndex;
+ --rhsIndex;
++matchedDigits;
}