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