From 05838b54c2ba81e74e205141c436ad8e9900b933 Mon Sep 17 00:00:00 2001 From: zachh Date: Mon, 22 Jan 2018 14:43:03 -0800 Subject: 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 --- .../incallui/PhoneLookupHistoryRecorder.java | 34 ++++++++++++++++++---- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'java/com/android/incallui') 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 future = - PhoneLookupComponent.get(appContext).phoneLookup().lookup(call); + + ListeningExecutorService backgroundExecutor = + DialerExecutorComponent.get(appContext).backgroundExecutor(); + + ListenableFuture numberFuture = + backgroundExecutor.submit( + () -> { + DialerPhoneNumberUtil dialerPhoneNumberUtil = + new DialerPhoneNumberUtil(PhoneNumberUtil.getInstance()); + return dialerPhoneNumberUtil.parse( + TelecomCallUtil.getNumber(call), + TelecomCallUtil.getCountryCode(appContext, call).orNull()); + }); + + ListenableFuture infoFuture = + Futures.transformAsync( + numberFuture, + dialerPhoneNumber -> + PhoneLookupComponent.get(appContext).phoneLookup().lookup(dialerPhoneNumber), + MoreExecutors.directExecutor()); + Futures.addCallback( - future, + infoFuture, new FutureCallback() { @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); } } -- cgit v1.2.3