From a240266106bf99780a48d86883499dbebd20fbda Mon Sep 17 00:00:00 2001 From: zachh Date: Fri, 12 Jan 2018 15:19:00 -0800 Subject: Cleaned up wording around "valid" and "formattable". We don't actually parition by "formattable", we parition by "valid". An invalid number like 456-7890 can be formatted to E164 ("+14567890") but what ParitionedNumbers actually does is parition by valid/invalid (and then converts the valid numbers to E164). Also added a new sharded test suite for phonenumberproto tests which had occasionally been timing out on TAP. Test: existing PiperOrigin-RevId: 181800443 Change-Id: Id64fc32c893025b0115dd350dd87e3277607f21c --- .../DialerBlockedNumberPhoneLookup.java | 9 +-- .../phonelookup/cp2/Cp2LocalPhoneLookup.java | 74 +++++++++++----------- 2 files changed, 41 insertions(+), 42 deletions(-) (limited to 'java/com/android/dialer/phonelookup') diff --git a/java/com/android/dialer/phonelookup/blockednumber/DialerBlockedNumberPhoneLookup.java b/java/com/android/dialer/phonelookup/blockednumber/DialerBlockedNumberPhoneLookup.java index 54df3995c..e6c15e8d9 100644 --- a/java/com/android/dialer/phonelookup/blockednumber/DialerBlockedNumberPhoneLookup.java +++ b/java/com/android/dialer/phonelookup/blockednumber/DialerBlockedNumberPhoneLookup.java @@ -134,7 +134,8 @@ public final class DialerBlockedNumberPhoneLookup implements PhoneLookup { if (TextUtils.isEmpty(rawNumber)) { return Cp2Info.getDefaultInstance(); } - Optional e164 = TelecomCallUtil.getE164Number(appContext, call); + Optional validE164 = TelecomCallUtil.getValidE164Number(appContext, call); Set cp2ContactInfos = new ArraySet<>(); // Note: It would make sense to use PHONE_LOOKUP for E164 numbers as well, but we use PHONE to // ensure consistency when the batch methods are used to update data. try (Cursor cursor = - e164.isPresent() + validE164.isPresent() ? queryPhoneTableBasedOnE164( - Cp2Projections.getProjectionForPhoneTable(), ImmutableSet.of(e164.get())) + Cp2Projections.getProjectionForPhoneTable(), ImmutableSet.of(validE164.get())) : queryPhoneLookup(Cp2Projections.getProjectionForPhoneLookupTable(), rawNumber)) { if (cursor == null) { LogUtil.w("Cp2LocalPhoneLookup.lookupInternal", "null cursor"); @@ -154,7 +154,7 @@ public final class Cp2LocalPhoneLookup implements PhoneLookup { @Override public ListenableFuture isDirty(ImmutableSet phoneNumbers) { PartitionedNumbers partitionedNumbers = new PartitionedNumbers(phoneNumbers); - if (partitionedNumbers.unformattableNumbers().size() > MAX_SUPPORTED_INVALID_NUMBERS) { + if (partitionedNumbers.invalidNumbers().size() > MAX_SUPPORTED_INVALID_NUMBERS) { // If there are N invalid numbers, we can't determine determine dirtiness without running N // queries; since running this many queries is not feasible for the (lightweight) isDirty // check, simply return true. The expectation is that this should rarely be the case as the @@ -239,15 +239,14 @@ public final class Cp2LocalPhoneLookup implements PhoneLookup { List>> queryFutures = new ArrayList<>(); - // First use the E164 numbers to query the NORMALIZED_NUMBER column. + // First use the valid E164 numbers to query the NORMALIZED_NUMBER column. queryFutures.add( queryPhoneTableForContactIdsBasedOnE164(partitionedNumbers.validE164Numbers())); // Then run a separate query for each invalid number. Separate queries are done to accomplish // loose matching which couldn't be accomplished with a batch query. - Assert.checkState( - partitionedNumbers.unformattableNumbers().size() <= MAX_SUPPORTED_INVALID_NUMBERS); - for (String invalidNumber : partitionedNumbers.unformattableNumbers()) { + Assert.checkState(partitionedNumbers.invalidNumbers().size() <= MAX_SUPPORTED_INVALID_NUMBERS); + for (String invalidNumber : partitionedNumbers.invalidNumbers()) { queryFutures.add(queryPhoneLookupTableForContactIdsBasedOnRawNumber(invalidNumber)); } return Futures.transform( @@ -527,10 +526,9 @@ public final class Cp2LocalPhoneLookup implements PhoneLookup { ImmutableMap existingInfoMap) { ArraySet unprocessableNumbers = new ArraySet<>(); PartitionedNumbers partitionedNumbers = new PartitionedNumbers(existingInfoMap.keySet()); - if (partitionedNumbers.unformattableNumbers().size() > MAX_SUPPORTED_INVALID_NUMBERS) { - for (String invalidNumber : partitionedNumbers.unformattableNumbers()) { - unprocessableNumbers.addAll( - partitionedNumbers.dialerPhoneNumbersForUnformattable(invalidNumber)); + if (partitionedNumbers.invalidNumbers().size() > MAX_SUPPORTED_INVALID_NUMBERS) { + for (String invalidNumber : partitionedNumbers.invalidNumbers()) { + unprocessableNumbers.addAll(partitionedNumbers.dialerPhoneNumbersForInvalid(invalidNumber)); } } return unprocessableNumbers; @@ -652,39 +650,39 @@ public final class Cp2LocalPhoneLookup implements PhoneLookup { return Futures.immediateFuture(new ArrayMap<>()); } - // Divide the numbers into those we can format to E164 and those we can't. Issue a single - // batch query for the E164 numbers against the PHONE table, and in parallel issue - // individual queries against PHONE_LOOKUP for each non-E164 number. + // Divide the numbers into those that are valid and those that are not. Issue a single + // batch query for the valid numbers against the PHONE table, and in parallel issue + // individual queries against PHONE_LOOKUP for each invalid number. // TODO(zachh): These queries are inefficient without a lastModified column to filter on. PartitionedNumbers partitionedNumbers = new PartitionedNumbers(ImmutableSet.copyOf(updatedNumbers)); - ListenableFuture>> e164Future = + ListenableFuture>> validNumbersFuture = batchQueryForValidNumbers(partitionedNumbers.validE164Numbers()); - List>> nonE164FuturesList = new ArrayList<>(); - for (String invalidNumber : partitionedNumbers.unformattableNumbers()) { - nonE164FuturesList.add(individualQueryForInvalidNumber(invalidNumber)); + List>> invalidNumbersFuturesList = new ArrayList<>(); + for (String invalidNumber : partitionedNumbers.invalidNumbers()) { + invalidNumbersFuturesList.add(individualQueryForInvalidNumber(invalidNumber)); } - ListenableFuture>> nonE164Future = - Futures.allAsList(nonE164FuturesList); + ListenableFuture>> invalidNumbersFuture = + Futures.allAsList(invalidNumbersFuturesList); Callable>> computeMap = () -> { // These get() calls are safe because we are using whenAllSucceed below. - Map> e164Result = e164Future.get(); - List> non164Results = nonE164Future.get(); + Map> validNumbersResult = validNumbersFuture.get(); + List> invalidNumbersResult = invalidNumbersFuture.get(); Map> map = new ArrayMap<>(); - // First update the map with the E164 results. - for (Entry> entry : e164Result.entrySet()) { - String e164Number = entry.getKey(); + // First update the map with the valid number results. + for (Entry> entry : validNumbersResult.entrySet()) { + String validNumber = entry.getKey(); Set cp2ContactInfos = entry.getValue(); Set dialerPhoneNumbers = - partitionedNumbers.dialerPhoneNumbersForE164(e164Number); + partitionedNumbers.dialerPhoneNumbersForValidE164(validNumber); addInfo(map, dialerPhoneNumbers, cp2ContactInfos); @@ -694,12 +692,12 @@ public final class Cp2LocalPhoneLookup implements PhoneLookup { updatedNumbers.removeAll(dialerPhoneNumbers); } - // Next update the map with the non-E164 results. + // Next update the map with the invalid results. int i = 0; - for (String unformattableNumber : partitionedNumbers.unformattableNumbers()) { - Set cp2Infos = non164Results.get(i++); + for (String invalidNumber : partitionedNumbers.invalidNumbers()) { + Set cp2Infos = invalidNumbersResult.get(i++); Set dialerPhoneNumbers = - partitionedNumbers.dialerPhoneNumbersForUnformattable(unformattableNumber); + partitionedNumbers.dialerPhoneNumbersForInvalid(invalidNumber); addInfo(map, dialerPhoneNumbers, cp2Infos); @@ -717,32 +715,32 @@ public final class Cp2LocalPhoneLookup implements PhoneLookup { } return map; }; - return Futures.whenAllSucceed(e164Future, nonE164Future) + return Futures.whenAllSucceed(validNumbersFuture, invalidNumbersFuture) .call(computeMap, lightweightExecutorService); }, lightweightExecutorService); } private ListenableFuture>> batchQueryForValidNumbers( - Set e164Numbers) { + Set validE164Numbers) { return backgroundExecutorService.submit( () -> { Map> cp2ContactInfosByNumber = new ArrayMap<>(); - if (e164Numbers.isEmpty()) { + if (validE164Numbers.isEmpty()) { return cp2ContactInfosByNumber; } try (Cursor cursor = queryPhoneTableBasedOnE164( - Cp2Projections.getProjectionForPhoneTable(), e164Numbers)) { + Cp2Projections.getProjectionForPhoneTable(), validE164Numbers)) { if (cursor == null) { LogUtil.w("Cp2LocalPhoneLookup.batchQueryForValidNumbers", "null cursor"); } else { while (cursor.moveToNext()) { - String e164Number = Cp2Projections.getNormalizedNumberFromCursor(cursor); - Set cp2ContactInfos = cp2ContactInfosByNumber.get(e164Number); + String validE164Number = Cp2Projections.getNormalizedNumberFromCursor(cursor); + Set cp2ContactInfos = cp2ContactInfosByNumber.get(validE164Number); if (cp2ContactInfos == null) { cp2ContactInfos = new ArraySet<>(); - cp2ContactInfosByNumber.put(e164Number, cp2ContactInfos); + cp2ContactInfosByNumber.put(validE164Number, cp2ContactInfos); } cp2ContactInfos.add( Cp2Projections.buildCp2ContactInfoFromCursor(appContext, cursor)); -- cgit v1.2.3