Search in sources :

Example 1 with NumberAttributes

use of com.android.dialer.NumberAttributes in project android_packages_apps_Dialer by LineageOS.

the class CallLogCacheUpdater method updateCacheInternal.

private void updateCacheInternal(CallLogMutations mutations) {
    ArrayList<ContentProviderOperation> operations = new ArrayList<>();
    Stream.concat(mutations.getInserts().entrySet().stream(), mutations.getUpdates().entrySet().stream()).limit(CACHE_UPDATE_LIMIT).forEach(entry -> {
        ContentValues values = entry.getValue();
        if (!values.containsKey(AnnotatedCallLog.NUMBER_ATTRIBUTES) || !values.containsKey(AnnotatedCallLog.NUMBER)) {
            return;
        }
        DialerPhoneNumber dialerPhoneNumber = ProtoParsers.getTrusted(values, AnnotatedCallLog.NUMBER, DialerPhoneNumber.getDefaultInstance());
        NumberAttributes numberAttributes = ProtoParsers.getTrusted(values, AnnotatedCallLog.NUMBER_ATTRIBUTES, NumberAttributes.getDefaultInstance());
        operations.add(ContentProviderOperation.newUpdate(ContentUris.withAppendedId(Calls.CONTENT_URI, entry.getKey())).withValue(Calls.CACHED_FORMATTED_NUMBER, values.getAsString(AnnotatedCallLog.FORMATTED_NUMBER)).withValue(Calls.CACHED_LOOKUP_URI, numberAttributes.getLookupUri()).withValue(Calls.CACHED_NAME, numberAttributes.getName()).withValue(Calls.CACHED_NORMALIZED_NUMBER, dialerPhoneNumber.getNormalizedNumber()).withValue(Calls.CACHED_NUMBER_LABEL, numberAttributes.getNumberTypeLabel()).withValue(Calls.CACHED_NUMBER_TYPE, Phone.TYPE_CUSTOM).withValue(Calls.CACHED_PHOTO_ID, numberAttributes.getPhotoId()).withValue(Calls.CACHED_PHOTO_URI, numberAttributes.getPhotoUri()).withSelection(Calls.CACHED_NAME + " IS NOT ?", new String[] { numberAttributes.getName() }).build());
    });
    try {
        int count = Arrays.stream(appContext.getContentResolver().applyBatch(CallLog.AUTHORITY, operations)).mapToInt(result -> result.count).sum();
        LogUtil.i("CallLogCacheUpdater.updateCache", "updated %d rows", count);
    } catch (OperationApplicationException | RemoteException e) {
        throw new IllegalStateException(e);
    }
}
Also used : ContentValues(android.content.ContentValues) ContentProviderOperation(android.content.ContentProviderOperation) NumberAttributes(com.android.dialer.NumberAttributes) Context(android.content.Context) LogUtil(com.android.dialer.common.LogUtil) Arrays(java.util.Arrays) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) AnnotatedCallLog(com.android.dialer.calllog.database.contract.AnnotatedCallLogContract.AnnotatedCallLog) RemoteException(android.os.RemoteException) CallLogMutations(com.android.dialer.calllog.datasources.CallLogMutations) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) VisibleForTesting(android.support.annotation.VisibleForTesting) BackgroundExecutor(com.android.dialer.common.concurrent.Annotations.BackgroundExecutor) ProtoParsers(com.android.dialer.protos.ProtoParsers) ApplicationContext(com.android.dialer.inject.ApplicationContext) CallLog(android.provider.CallLog) Phone(android.provider.ContactsContract.CommonDataKinds.Phone) DialerPhoneNumber(com.android.dialer.DialerPhoneNumber) OperationApplicationException(android.content.OperationApplicationException) Futures(com.google.common.util.concurrent.Futures) Stream(java.util.stream.Stream) Calls(android.provider.CallLog.Calls) ContentValues(android.content.ContentValues) ContentUris(android.content.ContentUris) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) ContentProviderOperation(android.content.ContentProviderOperation) ArrayList(java.util.ArrayList) DialerPhoneNumber(com.android.dialer.DialerPhoneNumber) RemoteException(android.os.RemoteException) NumberAttributes(com.android.dialer.NumberAttributes) OperationApplicationException(android.content.OperationApplicationException)

Example 2 with NumberAttributes

use of com.android.dialer.NumberAttributes in project android_packages_apps_Dialer by LineageOS.

the class VoicemailCursorLoader method toVoicemailEntry.

/**
 * Creates a new {@link VoicemailEntry} from the provided cursor using the current position.
 */
static VoicemailEntry toVoicemailEntry(Cursor cursor) {
    DialerPhoneNumber number;
    try {
        number = DialerPhoneNumber.parseFrom(cursor.getBlob(NUMBER));
    } catch (InvalidProtocolBufferException e) {
        throw new IllegalStateException("Couldn't parse DialerPhoneNumber bytes");
    }
    NumberAttributes numberAttributes;
    try {
        numberAttributes = NumberAttributes.parseFrom(cursor.getBlob(NUMBER_ATTRIBUTES));
    } catch (InvalidProtocolBufferException e) {
        throw new IllegalStateException("Couldn't parse NumberAttributes bytes");
    }
    // Voicemail numbers should always be valid so the CP2 information should never be incomplete,
    // and there should be no need to query PhoneLookup at render time.
    Assert.checkArgument(!numberAttributes.getIsCp2InfoIncomplete(), "CP2 info incomplete for number: %s", LogUtil.sanitizePii(number.getNormalizedNumber()));
    VoicemailEntry.Builder voicemailEntryBuilder = VoicemailEntry.newBuilder().setId(cursor.getInt(ID)).setTimestamp(cursor.getLong(TIMESTAMP)).setNumber(number).setDuration(cursor.getLong(DURATION)).setCallType(cursor.getInt(CALL_TYPE)).setIsRead(cursor.getInt(IS_READ)).setNumberAttributes(numberAttributes).setTranscriptionState(cursor.getInt(TRANSCRIPTION_STATE));
    String formattedNumber = cursor.getString(FORMATTED_NUMBER);
    if (!TextUtils.isEmpty(formattedNumber)) {
        voicemailEntryBuilder.setFormattedNumber(formattedNumber);
    }
    String geocodedLocation = cursor.getString(GEOCODED_LOCATION);
    if (!TextUtils.isEmpty(geocodedLocation)) {
        voicemailEntryBuilder.setGeocodedLocation(geocodedLocation);
    }
    String transcription = cursor.getString(TRANSCRIPTION);
    if (!TextUtils.isEmpty(transcription)) {
        voicemailEntryBuilder.setTranscription(transcription);
    }
    String voicemailUri = cursor.getString(VOICEMAIL_URI);
    if (!TextUtils.isEmpty(voicemailUri)) {
        voicemailEntryBuilder.setVoicemailUri(voicemailUri);
    }
    String phoneAccountComponentName = cursor.getString(PHONE_ACCOUNT_COMPONENT_NAME);
    if (!TextUtils.isEmpty(phoneAccountComponentName)) {
        voicemailEntryBuilder.setPhoneAccountComponentName(phoneAccountComponentName);
    }
    String phoneAccountId = cursor.getString(PHONE_ACCOUNT_ID);
    if (!TextUtils.isEmpty(phoneAccountId)) {
        voicemailEntryBuilder.setPhoneAccountId(phoneAccountId);
    }
    return voicemailEntryBuilder.build();
}
Also used : VoicemailEntry(com.android.dialer.voicemail.model.VoicemailEntry) DialerPhoneNumber(com.android.dialer.DialerPhoneNumber) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) NumberAttributes(com.android.dialer.NumberAttributes)

Aggregations

DialerPhoneNumber (com.android.dialer.DialerPhoneNumber)2 NumberAttributes (com.android.dialer.NumberAttributes)2 ContentProviderOperation (android.content.ContentProviderOperation)1 ContentUris (android.content.ContentUris)1 ContentValues (android.content.ContentValues)1 Context (android.content.Context)1 OperationApplicationException (android.content.OperationApplicationException)1 RemoteException (android.os.RemoteException)1 CallLog (android.provider.CallLog)1 Calls (android.provider.CallLog.Calls)1 Phone (android.provider.ContactsContract.CommonDataKinds.Phone)1 VisibleForTesting (android.support.annotation.VisibleForTesting)1 AnnotatedCallLog (com.android.dialer.calllog.database.contract.AnnotatedCallLogContract.AnnotatedCallLog)1 CallLogMutations (com.android.dialer.calllog.datasources.CallLogMutations)1 LogUtil (com.android.dialer.common.LogUtil)1 BackgroundExecutor (com.android.dialer.common.concurrent.Annotations.BackgroundExecutor)1 ApplicationContext (com.android.dialer.inject.ApplicationContext)1 ProtoParsers (com.android.dialer.protos.ProtoParsers)1 VoicemailEntry (com.android.dialer.voicemail.model.VoicemailEntry)1 Futures (com.google.common.util.concurrent.Futures)1