summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/calllog/ui/RealtimeRowProcessor.java
diff options
context:
space:
mode:
authorzachh <zachh@google.com>2018-01-22 14:43:03 -0800
committerCopybara-Service <copybara-piper@google.com>2018-01-22 16:11:07 -0800
commit05838b54c2ba81e74e205141c436ad8e9900b933 (patch)
tree5d47efb6820dfa5ba605de5f425be6165e977c10 /java/com/android/dialer/calllog/ui/RealtimeRowProcessor.java
parent861d8cd2dc75f80e5a6480145bbe29a1f5156acf (diff)
Changed PhoneLookup#lookup to accept a DialerPhoneNumber.
There's a problem with the existing implementation of RealtimeRowProcessor; when CP2 information is not present, data from other sources can potentially be erased. This CL fixes the problem by fetching the latest data from all sources, instead of just CP2. This requires being able to fetch PhoneLookup info without a Call, using only a number, so I changed PhoneLookup#lookup to accept a DialerPhoneNumber rather than a Call. (The reason that it accepted a Call was to support CNAP so we'll need a revised solution for that later.) There is a potential concern with performance in RealtimeRowProcessor due to performing a full [Composite]PhoneLookup vs. a CP2 lookup, because the full lookup includes network requests. However, it's anticipated that the real time lookups will very rarely have changes to apply so this might be OK as-is. If not, a mitigation strategy could be improving the performance of CompositePhoneLookup#lookup by short-circutiing slower sources when faster, higher priority sources have already completed. A follow-up CL will write the result of RealtimeRowProcessor queries to PhoneLookupHistory to further reduce how frequently real time updates need to be applied. Bug: 72229553 Test: existing unit PiperOrigin-RevId: 182839130 Change-Id: I8cb26827b4f4dc4702fb416234c8938179cd5ac5
Diffstat (limited to 'java/com/android/dialer/calllog/ui/RealtimeRowProcessor.java')
-rw-r--r--java/com/android/dialer/calllog/ui/RealtimeRowProcessor.java33
1 files changed, 16 insertions, 17 deletions
diff --git a/java/com/android/dialer/calllog/ui/RealtimeRowProcessor.java b/java/com/android/dialer/calllog/ui/RealtimeRowProcessor.java
index 57ad9657c..9e58e53ad 100644
--- a/java/com/android/dialer/calllog/ui/RealtimeRowProcessor.java
+++ b/java/com/android/dialer/calllog/ui/RealtimeRowProcessor.java
@@ -25,10 +25,9 @@ import com.android.dialer.calllog.model.CoalescedRow;
import com.android.dialer.common.Assert;
import com.android.dialer.common.concurrent.Annotations.Ui;
import com.android.dialer.inject.ApplicationContext;
+import com.android.dialer.phonelookup.PhoneLookup;
import com.android.dialer.phonelookup.PhoneLookupInfo;
-import com.android.dialer.phonelookup.PhoneLookupInfo.Cp2Info;
import com.android.dialer.phonelookup.consolidator.PhoneLookupInfoConsolidator;
-import com.android.dialer.phonelookup.cp2.Cp2LocalPhoneLookup;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
@@ -49,19 +48,19 @@ import javax.inject.Inject;
public final class RealtimeRowProcessor {
private final Context appContext;
- private final Cp2LocalPhoneLookup cp2LocalPhoneLookup;
+ private final PhoneLookup<PhoneLookupInfo> phoneLookup;
private final ListeningExecutorService uiExecutor;
- private final Map<DialerPhoneNumber, Cp2Info> cache = new ArrayMap<>();
+ private final Map<DialerPhoneNumber, PhoneLookupInfo> cache = new ArrayMap<>();
@Inject
RealtimeRowProcessor(
@ApplicationContext Context appContext,
@Ui ListeningExecutorService uiExecutor,
- Cp2LocalPhoneLookup cp2LocalPhoneLookup) {
+ PhoneLookup<PhoneLookupInfo> phoneLookup) {
this.appContext = appContext;
this.uiExecutor = uiExecutor;
- this.cp2LocalPhoneLookup = cp2LocalPhoneLookup;
+ this.phoneLookup = phoneLookup;
}
/**
@@ -75,17 +74,17 @@ public final class RealtimeRowProcessor {
return Futures.immediateFuture(row);
}
- Cp2Info cachedCp2Info = cache.get(row.number());
- if (cachedCp2Info != null) {
- return Futures.immediateFuture(applyCp2LocalInfoToRow(cachedCp2Info, row));
+ PhoneLookupInfo cachedPhoneLookupInfo = cache.get(row.number());
+ if (cachedPhoneLookupInfo != null) {
+ return Futures.immediateFuture(applyPhoneLookupInfoToRow(cachedPhoneLookupInfo, row));
}
- ListenableFuture<Cp2Info> cp2InfoFuture = cp2LocalPhoneLookup.lookupByNumber(row.number());
+ ListenableFuture<PhoneLookupInfo> phoneLookupInfoFuture = phoneLookup.lookup(row.number());
return Futures.transform(
- cp2InfoFuture,
- cp2Info -> {
- cache.put(row.number(), cp2Info);
- return applyCp2LocalInfoToRow(cp2Info, row);
+ phoneLookupInfoFuture,
+ phoneLookupInfo -> {
+ cache.put(row.number(), phoneLookupInfo);
+ return applyPhoneLookupInfoToRow(phoneLookupInfo, row);
},
uiExecutor /* ensures the cache is updated on a single thread */);
}
@@ -97,13 +96,13 @@ public final class RealtimeRowProcessor {
cache.clear();
}
- private CoalescedRow applyCp2LocalInfoToRow(Cp2Info cp2Info, CoalescedRow row) {
- PhoneLookupInfo phoneLookupInfo = PhoneLookupInfo.newBuilder().setCp2LocalInfo(cp2Info).build();
+ private CoalescedRow applyPhoneLookupInfoToRow(
+ PhoneLookupInfo phoneLookupInfo, CoalescedRow row) {
PhoneLookupInfoConsolidator phoneLookupInfoConsolidator =
new PhoneLookupInfoConsolidator(appContext, phoneLookupInfo);
- // It is safe to overwrite any existing data because CP2 always has highest priority.
return row.toBuilder()
.setNumberAttributes(
+ // TODO(zachh): Put this in a common location.
NumberAttributes.newBuilder()
.setName(phoneLookupInfoConsolidator.getName())
.setPhotoUri(phoneLookupInfoConsolidator.getPhotoUri())