From ac069a79d2f0701d1ce0371a11e3d2ed63afc4de Mon Sep 17 00:00:00 2001 From: linyuh Date: Thu, 19 Apr 2018 16:23:10 -0700 Subject: Support extracting info from a Call in PhoneLookup Bug: 70988915 Test: CompositePhoneLookupTest, PhoneLookupTest PiperOrigin-RevId: 193592973 Change-Id: I27b6a63049117ce6d31e50aea9c56c14f01d0e1d --- .../android/dialer/phonelookup/PhoneLookup.java | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'java/com/android/dialer/phonelookup/PhoneLookup.java') diff --git a/java/com/android/dialer/phonelookup/PhoneLookup.java b/java/com/android/dialer/phonelookup/PhoneLookup.java index d11f023af..0b9cbf6eb 100644 --- a/java/com/android/dialer/phonelookup/PhoneLookup.java +++ b/java/com/android/dialer/phonelookup/PhoneLookup.java @@ -16,11 +16,20 @@ package com.android.dialer.phonelookup; +import android.content.Context; import android.support.annotation.MainThread; +import android.telecom.Call; import com.android.dialer.DialerPhoneNumber; +import com.android.dialer.common.concurrent.DialerExecutorComponent; +import com.android.dialer.location.GeoUtil; +import com.android.dialer.phonenumberproto.DialerPhoneNumberUtil; +import com.android.dialer.telecom.TelecomCallUtil; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +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; /** * Provides operations related to retrieving information about phone numbers. @@ -31,12 +40,45 @@ import com.google.common.util.concurrent.ListenableFuture; */ public interface PhoneLookup { + /** + * Returns a future containing a new info for the number associated with the provided call. + * + *

The returned message should contain populated data for the sub-message corresponding to this + * {@link PhoneLookup}. For example, the CP2 implementation returns a {@link + * PhoneLookupInfo.Cp2Info} sub-message. + * + *

The default implementation is for all {@link PhoneLookup} implementations that don't need + * info in the given call, i.e., it simply extracts the phone number from the call and delegates + * to {@link #lookup(DialerPhoneNumber)}. + * + *

However, for {@link PhoneLookup} implementations that need info in the call (such as one for + * CNAP), they should override this method. + */ + default ListenableFuture lookup(Context appContext, Call call) { + ListeningExecutorService backgroundExecutor = + DialerExecutorComponent.get(appContext).backgroundExecutor(); + + ListenableFuture numberFuture = + backgroundExecutor.submit( + () -> { + DialerPhoneNumberUtil dialerPhoneNumberUtil = new DialerPhoneNumberUtil(); + return dialerPhoneNumberUtil.parse( + TelecomCallUtil.getNumber(call), GeoUtil.getCurrentCountryIso(appContext)); + }); + + return Futures.transformAsync(numberFuture, this::lookup, MoreExecutors.directExecutor()); + } + /** * Returns a future containing a new info for the provided number. * *

The returned message should contain populated data for the sub-message corresponding to this * {@link PhoneLookup}. For example, the CP2 implementation returns a {@link * PhoneLookupInfo.Cp2Info} sub-message. + * + *

If the lookup can't be done without info in a {@link Call} (e.g., CNAP), this method is + * expected to return existing info saved during the most recent lookup for a call to/from the + * provided number ({@link #lookup(Context, Call)}). */ ListenableFuture lookup(DialerPhoneNumber dialerPhoneNumber); -- cgit v1.2.3