Search in sources :

Example 11 with PhoneLookupInfo

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();
        }
    });
}
Also used : PhoneLookupInfo(com.android.dialer.phonelookup.PhoneLookupInfo) Selection(com.android.dialer.common.database.Selection) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) Cursor(android.database.Cursor)

Example 12 with PhoneLookupInfo

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());
}
Also used : ContentValues(android.content.ContentValues) PhoneLookupInfo(com.android.dialer.phonelookup.PhoneLookupInfo) Optional(com.google.common.base.Optional)

Aggregations

PhoneLookupInfo (com.android.dialer.phonelookup.PhoneLookupInfo)12 ContentValues (android.content.ContentValues)6 DialerPhoneNumber (com.android.dialer.DialerPhoneNumber)5 ArrayList (java.util.ArrayList)5 Cursor (android.database.Cursor)4 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)4 ContentProviderOperation (android.content.ContentProviderOperation)3 MainThread (android.support.annotation.MainThread)3 PhoneLookup (com.android.dialer.phonelookup.PhoneLookup)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)3 Context (android.content.Context)2 WorkerThread (android.support.annotation.WorkerThread)2 TextUtils (android.text.TextUtils)2 Assert (com.android.dialer.common.Assert)2 LogUtil (com.android.dialer.common.LogUtil)2 BackgroundExecutor (com.android.dialer.common.concurrent.Annotations.BackgroundExecutor)2 LightweightExecutor (com.android.dialer.common.concurrent.Annotations.LightweightExecutor)2 ApplicationContext (com.android.dialer.inject.ApplicationContext)2 PhoneLookupHistory (com.android.dialer.phonelookup.database.contract.PhoneLookupHistoryContract.PhoneLookupHistory)2