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());
}
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);
}
Aggregations