summaryrefslogtreecommitdiffstats
path: root/java/com/android/incallui/PhoneLookupHistoryRecorder.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/incallui/PhoneLookupHistoryRecorder.java
parent861d8cd2dc75f80e5a6480145bbe29a1f5156acf (diff)
downloadandroid_packages_apps_Dialer-05838b54c2ba81e74e205141c436ad8e9900b933.tar.gz
android_packages_apps_Dialer-05838b54c2ba81e74e205141c436ad8e9900b933.tar.bz2
android_packages_apps_Dialer-05838b54c2ba81e74e205141c436ad8e9900b933.zip
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/incallui/PhoneLookupHistoryRecorder.java')
-rw-r--r--java/com/android/incallui/PhoneLookupHistoryRecorder.java34
1 files changed, 29 insertions, 5 deletions
diff --git a/java/com/android/incallui/PhoneLookupHistoryRecorder.java b/java/com/android/incallui/PhoneLookupHistoryRecorder.java
index 8517deb65..abbf934f0 100644
--- a/java/com/android/incallui/PhoneLookupHistoryRecorder.java
+++ b/java/com/android/incallui/PhoneLookupHistoryRecorder.java
@@ -19,18 +19,23 @@ import android.content.ContentValues;
import android.content.Context;
import android.support.annotation.Nullable;
import android.telecom.Call;
+import com.android.dialer.DialerPhoneNumber;
import com.android.dialer.buildtype.BuildType;
import com.android.dialer.common.Assert;
import com.android.dialer.common.LogUtil;
-import com.android.dialer.common.concurrent.DialerExecutors;
+import com.android.dialer.common.concurrent.DialerExecutorComponent;
import com.android.dialer.phonelookup.PhoneLookupComponent;
import com.android.dialer.phonelookup.PhoneLookupInfo;
import com.android.dialer.phonelookup.database.contract.PhoneLookupHistoryContract.PhoneLookupHistory;
+import com.android.dialer.phonenumberproto.DialerPhoneNumberUtil;
import com.android.dialer.telecom.TelecomCallUtil;
import com.google.common.base.Optional;
import com.google.common.util.concurrent.FutureCallback;
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
@@ -46,10 +51,29 @@ final class PhoneLookupHistoryRecorder {
if (!(BuildType.get() == BuildType.BUGFOOD || LogUtil.isDebugEnabled())) {
return;
}
- ListenableFuture<PhoneLookupInfo> future =
- PhoneLookupComponent.get(appContext).phoneLookup().lookup(call);
+
+ ListeningExecutorService backgroundExecutor =
+ DialerExecutorComponent.get(appContext).backgroundExecutor();
+
+ ListenableFuture<DialerPhoneNumber> numberFuture =
+ backgroundExecutor.submit(
+ () -> {
+ DialerPhoneNumberUtil dialerPhoneNumberUtil =
+ new DialerPhoneNumberUtil(PhoneNumberUtil.getInstance());
+ return dialerPhoneNumberUtil.parse(
+ TelecomCallUtil.getNumber(call),
+ TelecomCallUtil.getCountryCode(appContext, call).orNull());
+ });
+
+ ListenableFuture<PhoneLookupInfo> infoFuture =
+ Futures.transformAsync(
+ numberFuture,
+ dialerPhoneNumber ->
+ PhoneLookupComponent.get(appContext).phoneLookup().lookup(dialerPhoneNumber),
+ MoreExecutors.directExecutor());
+
Futures.addCallback(
- future,
+ infoFuture,
new FutureCallback<PhoneLookupInfo>() {
@Override
public void onSuccess(@Nullable PhoneLookupInfo result) {
@@ -79,6 +103,6 @@ final class PhoneLookupHistoryRecorder {
"PhoneLookupHistoryRecorder.onFailure", "could not write PhoneLookupHistory", t);
}
},
- DialerExecutors.getLowPriorityThreadPool(appContext));
+ backgroundExecutor);
}
}