use of com.android.dialer.phonelookup.PhoneLookupInfo in project android_packages_apps_Dialer by LineageOS.
the class CnapPhoneLookup method lookup.
/**
* CNAP info cannot be retrieved when all we have is a number. The best we can do is returning the
* existing info in {@link PhoneLookupHistory}.
*/
@Override
public ListenableFuture<CnapInfo> lookup(DialerPhoneNumber dialerPhoneNumber) {
return backgroundExecutorService.submit(() -> {
Selection selection = Selection.builder().and(Selection.column(PhoneLookupHistory.NORMALIZED_NUMBER).is("=", dialerPhoneNumber.getNormalizedNumber())).build();
try (Cursor cursor = appContext.getContentResolver().query(PhoneLookupHistory.CONTENT_URI, new String[] { PhoneLookupHistory.PHONE_LOOKUP_INFO }, selection.getSelection(), selection.getSelectionArgs(), /* sortOrder = */
null)) {
if (cursor == null) {
LogUtil.e("CnapPhoneLookup.lookup", "null cursor");
return CnapInfo.getDefaultInstance();
}
if (!cursor.moveToFirst()) {
LogUtil.i("CnapPhoneLookup.lookup", "empty cursor");
return CnapInfo.getDefaultInstance();
}
// At ths point, we expect only one row in the cursor as
// PhoneLookupHistory.NORMALIZED_NUMBER is the primary key of table PhoneLookupHistory.
Assert.checkState(cursor.getCount() == 1);
int phoneLookupInfoColumn = cursor.getColumnIndexOrThrow(PhoneLookupHistory.PHONE_LOOKUP_INFO);
PhoneLookupInfo phoneLookupInfo;
try {
phoneLookupInfo = PhoneLookupInfo.parseFrom(cursor.getBlob(phoneLookupInfoColumn));
} catch (InvalidProtocolBufferException e) {
throw new IllegalStateException(e);
}
return phoneLookupInfo.getCnapInfo();
}
});
}
use of com.android.dialer.phonelookup.PhoneLookupInfo in project android_packages_apps_Dialer by LineageOS.
the class PhoneLookupHistoryRecorder method recordPhoneLookupInfo.
/**
* If the call log framework is enabled, fetches the current {@link PhoneLookupInfo} for the
* provided call and writes it to the PhoneLookupHistory. Otherwise does nothing.
*/
static void recordPhoneLookupInfo(Context appContext, Call call) {
if (!CallLogConfigComponent.get(appContext).callLogConfig().isCallLogFrameworkEnabled()) {
return;
}
ListenableFuture<PhoneLookupInfo> infoFuture = PhoneLookupComponent.get(appContext).compositePhoneLookup().lookup(call);
Futures.addCallback(infoFuture, new FutureCallback<PhoneLookupInfo>() {
@Override
public void onSuccess(@Nullable PhoneLookupInfo result) {
Assert.checkArgument(result != null);
Optional<String> normalizedNumber = TelecomCallUtil.getNormalizedNumber(appContext, call);
if (!normalizedNumber.isPresent()) {
LogUtil.w("PhoneLookupHistoryRecorder.onSuccess", "couldn't get a number");
return;
}
ContentValues contentValues = new ContentValues();
contentValues.put(PhoneLookupHistory.PHONE_LOOKUP_INFO, result.toByteArray());
contentValues.put(PhoneLookupHistory.LAST_MODIFIED, System.currentTimeMillis());
appContext.getContentResolver().update(PhoneLookupHistory.contentUriForNumber(normalizedNumber.get()), contentValues, null, null);
}
@Override
public void onFailure(Throwable t) {
// TODO(zachh): Consider how to best handle this; take measures to repair call log?
LogUtil.w("PhoneLookupHistoryRecorder.onFailure", "could not write PhoneLookupHistory", t);
}
}, DialerExecutorComponent.get(appContext).backgroundExecutor());
}
Aggregations