summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/phonelookup
diff options
context:
space:
mode:
authorzachh <zachh@google.com>2017-12-15 17:42:12 -0800
committerCopybara-Service <copybara-piper@google.com>2017-12-15 17:50:58 -0800
commitba44ee32b2d99e5ddc67f7037a519f305279cb85 (patch)
treeda873a5ce24d3cb14b5c466163f64407a4712eb4 /java/com/android/dialer/phonelookup
parent1f9a42626218934ec68926b5553ff387c5f0bf21 (diff)
Support empty PhoneLookupInfo in Cp2PhoneLookup.
This is necessary to support the case when the user has just upgraded to the new UI and there is no PhoneLookupHistory data yet, or they have cleared their data. Bug: 70570635 Test: unit and manual PiperOrigin-RevId: 179261139 Change-Id: I1e521d2e86bd3f8643c5c0bb537a52c41f1ceb6d
Diffstat (limited to 'java/com/android/dialer/phonelookup')
-rw-r--r--java/com/android/dialer/phonelookup/cp2/Cp2PhoneLookup.java47
-rw-r--r--java/com/android/dialer/phonelookup/phone_lookup_info.proto5
2 files changed, 25 insertions, 27 deletions
diff --git a/java/com/android/dialer/phonelookup/cp2/Cp2PhoneLookup.java b/java/com/android/dialer/phonelookup/cp2/Cp2PhoneLookup.java
index 501b0884d..fce6bbaf6 100644
--- a/java/com/android/dialer/phonelookup/cp2/Cp2PhoneLookup.java
+++ b/java/com/android/dialer/phonelookup/cp2/Cp2PhoneLookup.java
@@ -47,7 +47,6 @@ import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.i18n.phonenumbers.PhoneNumberUtil;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Objects;
import java.util.Set;
import javax.inject.Inject;
@@ -99,7 +98,6 @@ public final class Cp2PhoneLookup implements PhoneLookup {
@Override
public ListenableFuture<PhoneLookupInfo> lookup(@NonNull Call call) {
// TODO(zachh): Implementation.
- // TODO(zachh): Note: Should write empty Cp2Info even when no contact found.
return backgroundExecutorService.submit(PhoneLookupInfo::getDefaultInstance);
}
@@ -264,11 +262,9 @@ public final class Cp2PhoneLookup implements PhoneLookup {
infoBuilder.setCp2Info(
Cp2Info.newBuilder().addAllCp2ContactInfo(updatedContacts.get(dialerPhoneNumber)));
- // If it was deleted and not added to a new contact, replace the Cp2ContactInfo list with
- // the default instance of Cp2ContactInfo
+ // If it was deleted and not added to a new contact, clear all the CP2 information.
} else if (deletedPhoneNumbers.contains(dialerPhoneNumber)) {
- infoBuilder.setCp2Info(
- Cp2Info.newBuilder().addCp2ContactInfo(Cp2ContactInfo.getDefaultInstance()));
+ infoBuilder.clearCp2Info();
}
// If the DialerPhoneNumber didn't change, add the unchanged existing info.
@@ -319,25 +315,26 @@ public final class Cp2PhoneLookup implements PhoneLookup {
continue;
}
- // Note: Methods in this class must always set at least one Cp2Info, setting it to
- // getDefaultInstance() if there is no information for the contact.
- Assert.checkState(
- existingInfo.getCp2Info().getCp2ContactInfoCount() > 0, "existing info has no cp2 infos");
-
- // For each Cp2ContactInfo for each existing DialerPhoneNumber...
- // Store the contact id if it exist, else automatically add the DialerPhoneNumber to our
- // set of DialerPhoneNumbers we want to update.
- for (Cp2ContactInfo cp2ContactInfo : existingInfo.getCp2Info().getCp2ContactInfoList()) {
- if (Objects.equals(cp2ContactInfo, Cp2ContactInfo.getDefaultInstance())) {
- // If the number doesn't have any Cp2ContactInfo set to it, for various reasons, we need
- // to look up the number to check if any exists.
- // The various reasons this might happen are:
- // - An existing contact that wasn't in the call log is now in the call log.
- // - A number was in the call log before but has now been added to a contact.
- // - A number is in the call log, but isn't associated with any contact.
- updatedNumbers.add(dialerPhoneNumber);
- } else {
- contactIds.add(cp2ContactInfo.getContactId());
+ /// When the PhoneLookupHistory contains no information for a number, because for example the
+ // user just upgraded to the new UI, or cleared data, we need to check for updated info.
+ if (existingInfo.getCp2Info().getCp2ContactInfoCount() == 0) {
+ updatedNumbers.add(dialerPhoneNumber);
+ } else {
+ // For each Cp2ContactInfo for each existing DialerPhoneNumber...
+ // Store the contact id if it exist, else automatically add the DialerPhoneNumber to our
+ // set of DialerPhoneNumbers we want to update.
+ for (Cp2ContactInfo cp2ContactInfo : existingInfo.getCp2Info().getCp2ContactInfoList()) {
+ long existingContactId = cp2ContactInfo.getContactId();
+ if (existingContactId == 0) {
+ // If the number doesn't have a contact id, for various reasons, we need to look up the
+ // number to check if any exists. The various reasons this might happen are:
+ // - An existing contact that wasn't in the call log is now in the call log.
+ // - A number was in the call log before but has now been added to a contact.
+ // - A number is in the call log, but isn't associated with any contact.
+ updatedNumbers.add(dialerPhoneNumber);
+ } else {
+ contactIds.add(cp2ContactInfo.getContactId());
+ }
}
}
}
diff --git a/java/com/android/dialer/phonelookup/phone_lookup_info.proto b/java/com/android/dialer/phonelookup/phone_lookup_info.proto
index 4e62d67c1..c42faf49d 100644
--- a/java/com/android/dialer/phonelookup/phone_lookup_info.proto
+++ b/java/com/android/dialer/phonelookup/phone_lookup_info.proto
@@ -39,8 +39,9 @@ message PhoneLookupInfo {
optional string lookup_uri = 6;
}
// Repeated because one phone number can be associated with multiple CP2
- // contacts. If no contact is found for a number, this will contain exactly
- // one element which is the default Cp2ContactInfo instance.
+ // contacts.
+ //
+ // Empty if there is no CP2 contact information for the number.
repeated Cp2ContactInfo cp2_contact_info = 1;
}
optional Cp2Info cp2_info = 1;