Search in sources :

Example 1 with PhoneLookup

use of com.android.dialer.phonelookup.PhoneLookup in project android_packages_apps_Dialer by LineageOS.

the class CompositePhoneLookup method getMostRecentInfo.

/**
 * Delegates to a set of dependent lookups and combines results.
 *
 * <p>Note: If any of the dependent lookups fails, the returned future will also fail. If any of
 * the dependent lookups does not complete, the returned future will also not complete.
 */
@SuppressWarnings("unchecked")
public ListenableFuture<ImmutableMap<DialerPhoneNumber, PhoneLookupInfo>> getMostRecentInfo(ImmutableMap<DialerPhoneNumber, PhoneLookupInfo> existingInfoMap) {
    return Futures.transformAsync(callLogState.isBuilt(), isBuilt -> {
        Preconditions.checkNotNull(isBuilt);
        List<ListenableFuture<ImmutableMap<DialerPhoneNumber, ?>>> futures = new ArrayList<>();
        for (PhoneLookup phoneLookup : phoneLookups) {
            futures.add(buildSubmapAndGetMostRecentInfo(existingInfoMap, phoneLookup, isBuilt));
        }
        ListenableFuture<ImmutableMap<DialerPhoneNumber, PhoneLookupInfo>> combinedFuture = Futures.transform(Futures.allAsList(futures), (allMaps) -> {
            Preconditions.checkNotNull(allMaps);
            ImmutableMap.Builder<DialerPhoneNumber, PhoneLookupInfo> combinedMap = ImmutableMap.builder();
            for (DialerPhoneNumber dialerPhoneNumber : existingInfoMap.keySet()) {
                PhoneLookupInfo.Builder combinedInfo = PhoneLookupInfo.newBuilder();
                for (int i = 0; i < allMaps.size(); i++) {
                    ImmutableMap<DialerPhoneNumber, ?> map = allMaps.get(i);
                    Object subInfo = map.get(dialerPhoneNumber);
                    if (subInfo == null) {
                        throw new IllegalStateException("A sublookup didn't return an info for number: " + LogUtil.sanitizePhoneNumber(dialerPhoneNumber.getNormalizedNumber()));
                    }
                    phoneLookups.get(i).setSubMessage(combinedInfo, subInfo);
                }
                combinedMap.put(dialerPhoneNumber, combinedInfo.build());
            }
            return combinedMap.build();
        }, lightweightExecutorService);
        String eventName = getMostRecentInfoEventName(getLoggingName(), isBuilt);
        futureTimer.applyTiming(combinedFuture, eventName);
        return combinedFuture;
    }, MoreExecutors.directExecutor());
}
Also used : PhoneLookupInfo(com.android.dialer.phonelookup.PhoneLookupInfo) ArrayList(java.util.ArrayList) ImmutableMap(com.google.common.collect.ImmutableMap) Builder(com.android.dialer.phonelookup.PhoneLookupInfo.Builder) DialerPhoneNumber(com.android.dialer.DialerPhoneNumber) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) PhoneLookup(com.android.dialer.phonelookup.PhoneLookup)

Example 2 with PhoneLookup

use of com.android.dialer.phonelookup.PhoneLookup in project android_packages_apps_Dialer by LineageOS.

the class CompositePhoneLookup method combineSubMessageFutures.

/**
 * Combines a list of sub-message futures into a future for {@link PhoneLookupInfo}.
 */
@SuppressWarnings({ "unchecked", "rawtype" })
private ListenableFuture<PhoneLookupInfo> combineSubMessageFutures(List<ListenableFuture<?>> subMessageFutures) {
    return Futures.transform(Futures.allAsList(subMessageFutures), subMessages -> {
        Preconditions.checkNotNull(subMessages);
        Builder mergedInfo = PhoneLookupInfo.newBuilder();
        for (int i = 0; i < subMessages.size(); i++) {
            PhoneLookup phoneLookup = phoneLookups.get(i);
            phoneLookup.setSubMessage(mergedInfo, subMessages.get(i));
        }
        return mergedInfo.build();
    }, lightweightExecutorService);
}
Also used : Builder(com.android.dialer.phonelookup.PhoneLookupInfo.Builder) PhoneLookup(com.android.dialer.phonelookup.PhoneLookup)

Aggregations

PhoneLookup (com.android.dialer.phonelookup.PhoneLookup)2 Builder (com.android.dialer.phonelookup.PhoneLookupInfo.Builder)2 DialerPhoneNumber (com.android.dialer.DialerPhoneNumber)1 PhoneLookupInfo (com.android.dialer.phonelookup.PhoneLookupInfo)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 ArrayList (java.util.ArrayList)1