use of com.android.dialer.phonenumberproto.DialerPhoneNumberUtil in project android_packages_apps_Dialer by LineageOS.
the class PhoneLookup method lookup.
/**
* Returns a future containing a new info for the number associated with the provided call.
*
* <p>The returned message should contain populated data for the sub-message corresponding to this
* {@link PhoneLookup}. For example, the CP2 implementation returns a {@link
* PhoneLookupInfo.Cp2Info} sub-message.
*
* <p>The default implementation is for all {@link PhoneLookup} implementations that don't need
* info in the given call, i.e., it simply extracts the phone number from the call and delegates
* to {@link #lookup(DialerPhoneNumber)}.
*
* <p>However, for {@link PhoneLookup} implementations that need info in the call (such as one for
* CNAP), they should override this method.
*/
default ListenableFuture<T> lookup(Context appContext, Call call) {
ListeningExecutorService backgroundExecutor = DialerExecutorComponent.get(appContext).backgroundExecutor();
ListenableFuture<DialerPhoneNumber> numberFuture = backgroundExecutor.submit(() -> {
DialerPhoneNumberUtil dialerPhoneNumberUtil = new DialerPhoneNumberUtil();
return dialerPhoneNumberUtil.parse(TelecomCallUtil.getNumber(call), GeoUtil.getCurrentCountryIso(appContext));
});
return Futures.transformAsync(numberFuture, this::lookup, MoreExecutors.directExecutor());
}
use of com.android.dialer.phonenumberproto.DialerPhoneNumberUtil in project android_packages_apps_Dialer by LineageOS.
the class Coalescer method coalesce.
/**
* Reads the entire {@link AnnotatedCallLog} database into memory from the provided {@code
* allAnnotatedCallLog} parameter and then builds and returns a new {@link MatrixCursor} which is
* the result of combining adjacent rows which should be collapsed for display purposes.
*
* @param allAnnotatedCallLogRowsSortedByTimestampDesc all {@link AnnotatedCallLog} rows, sorted
* by timestamp descending
* @return a new {@link MatrixCursor} containing the {@link CoalescedAnnotatedCallLog} rows to
* display
*/
@WorkerThread
@NonNull
Cursor coalesce(@NonNull Cursor allAnnotatedCallLogRowsSortedByTimestampDesc) {
Assert.isWorkerThread();
// Note: This method relies on rowsShouldBeCombined to determine which rows should be combined,
// but delegates to data sources to actually aggregate column values.
DialerPhoneNumberUtil dialerPhoneNumberUtil = new DialerPhoneNumberUtil(PhoneNumberUtil.getInstance());
MatrixCursor allCoalescedRowsMatrixCursor = new MatrixCursor(CoalescedAnnotatedCallLog.ALL_COLUMNS, Assert.isNotNull(allAnnotatedCallLogRowsSortedByTimestampDesc).getCount());
if (allAnnotatedCallLogRowsSortedByTimestampDesc.moveToFirst()) {
int coalescedRowId = 0;
List<ContentValues> currentRowGroup = new ArrayList<>();
do {
ContentValues currentRow = cursorRowToContentValues(allAnnotatedCallLogRowsSortedByTimestampDesc);
if (currentRowGroup.isEmpty()) {
currentRowGroup.add(currentRow);
continue;
}
ContentValues previousRow = currentRowGroup.get(currentRowGroup.size() - 1);
if (!rowsShouldBeCombined(dialerPhoneNumberUtil, previousRow, currentRow)) {
ContentValues coalescedRow = coalesceRowsForAllDataSources(currentRowGroup);
coalescedRow.put(CoalescedAnnotatedCallLog.NUMBER_CALLS, currentRowGroup.size());
addContentValuesToMatrixCursor(coalescedRow, allCoalescedRowsMatrixCursor, coalescedRowId++);
currentRowGroup.clear();
}
currentRowGroup.add(currentRow);
} while (allAnnotatedCallLogRowsSortedByTimestampDesc.moveToNext());
// Deal with leftover rows.
ContentValues coalescedRow = coalesceRowsForAllDataSources(currentRowGroup);
coalescedRow.put(CoalescedAnnotatedCallLog.NUMBER_CALLS, currentRowGroup.size());
addContentValuesToMatrixCursor(coalescedRow, allCoalescedRowsMatrixCursor, coalescedRowId);
}
return allCoalescedRowsMatrixCursor;
}
use of com.android.dialer.phonenumberproto.DialerPhoneNumberUtil in project android_packages_apps_Dialer by LineageOS.
the class BlockingCommand method run.
@Override
public ListenableFuture<String> run(Arguments args) throws IllegalCommandLineArgumentException {
if (args.getPositionals().isEmpty()) {
return Futures.immediateFuture(getUsage());
}
String command = args.getPositionals().get(0);
if ("block".equals(command)) {
String number = args.getPositionals().get(1);
return Futures.transform(Blocking.block(appContext, ImmutableList.of(number), null), (unused) -> "blocked " + number, MoreExecutors.directExecutor());
}
if ("unblock".equals(command)) {
String number = args.getPositionals().get(1);
return Futures.transform(Blocking.unblock(appContext, ImmutableList.of(number), null), (unused) -> "unblocked " + number, MoreExecutors.directExecutor());
}
if ("isblocked".equals(command)) {
String number = args.getPositionals().get(1);
ListenableFuture<DialerPhoneNumber> dialerPhoneNumberFuture = executorService.submit(() -> new DialerPhoneNumberUtil().parse(number, null));
ListenableFuture<PhoneLookupInfo> lookupFuture = Futures.transformAsync(dialerPhoneNumberFuture, (dialerPhoneNumber) -> PhoneLookupComponent.get(appContext).compositePhoneLookup().lookup(dialerPhoneNumber), executorService);
return Futures.transform(lookupFuture, (info) -> new PhoneLookupInfoConsolidator(info).isBlocked() ? "true" : "false", MoreExecutors.directExecutor());
}
return Futures.immediateFuture(getUsage());
}
use of com.android.dialer.phonenumberproto.DialerPhoneNumberUtil in project android_packages_apps_Dialer by LineageOS.
the class SystemCallLogDataSource method handleInsertsAndUpdates.
private void handleInsertsAndUpdates(Context appContext, CallLogMutations mutations, Set<Long> existingAnnotatedCallLogIds) {
long previousTimestampProcessed = sharedPreferences.getLong(PREF_LAST_TIMESTAMP_PROCESSED, 0L);
DialerPhoneNumberUtil dialerPhoneNumberUtil = new DialerPhoneNumberUtil();
// TODO(zachh): Really should be getting last 1000 by timestamp, not by last modified.
try (Cursor cursor = appContext.getContentResolver().query(Calls.CONTENT_URI_WITH_VOICEMAIL, getProjection(), Calls.LAST_MODIFIED + " > ? AND " + Voicemails.DELETED + " = 0", new String[] { String.valueOf(previousTimestampProcessed) }, Calls.LAST_MODIFIED + " DESC LIMIT 1000")) {
if (cursor == null) {
LogUtil.e("SystemCallLogDataSource.handleInsertsAndUpdates", "null cursor");
return;
}
if (!cursor.moveToFirst()) {
LogUtil.i("SystemCallLogDataSource.handleInsertsAndUpdates", "no entries to insert/update");
return;
}
LogUtil.i("SystemCallLogDataSource.handleInsertsAndUpdates", "found %d entries to insert/update", cursor.getCount());
int idColumn = cursor.getColumnIndexOrThrow(Calls._ID);
int dateColumn = cursor.getColumnIndexOrThrow(Calls.DATE);
int lastModifiedColumn = cursor.getColumnIndexOrThrow(Calls.LAST_MODIFIED);
int numberColumn = cursor.getColumnIndexOrThrow(Calls.NUMBER);
int presentationColumn = cursor.getColumnIndexOrThrow(Calls.NUMBER_PRESENTATION);
int typeColumn = cursor.getColumnIndexOrThrow(Calls.TYPE);
int countryIsoColumn = cursor.getColumnIndexOrThrow(Calls.COUNTRY_ISO);
int durationsColumn = cursor.getColumnIndexOrThrow(Calls.DURATION);
int dataUsageColumn = cursor.getColumnIndexOrThrow(Calls.DATA_USAGE);
int transcriptionColumn = cursor.getColumnIndexOrThrow(Calls.TRANSCRIPTION);
int voicemailUriColumn = cursor.getColumnIndexOrThrow(Calls.VOICEMAIL_URI);
int isReadColumn = cursor.getColumnIndexOrThrow(Calls.IS_READ);
int newColumn = cursor.getColumnIndexOrThrow(Calls.NEW);
int geocodedLocationColumn = cursor.getColumnIndexOrThrow(Calls.GEOCODED_LOCATION);
int phoneAccountComponentColumn = cursor.getColumnIndexOrThrow(Calls.PHONE_ACCOUNT_COMPONENT_NAME);
int phoneAccountIdColumn = cursor.getColumnIndexOrThrow(Calls.PHONE_ACCOUNT_ID);
int featuresColumn = cursor.getColumnIndexOrThrow(Calls.FEATURES);
int postDialDigitsColumn = cursor.getColumnIndexOrThrow(Calls.POST_DIAL_DIGITS);
// The cursor orders by LAST_MODIFIED DESC, so the first result is the most recent timestamp
// processed.
lastTimestampProcessed = cursor.getLong(lastModifiedColumn);
do {
long id = cursor.getLong(idColumn);
long date = cursor.getLong(dateColumn);
String numberAsStr = cursor.getString(numberColumn);
int type;
if (cursor.isNull(typeColumn) || (type = cursor.getInt(typeColumn)) == 0) {
// CallLog.Calls#TYPE lists the allowed values, which are non-null and non-zero.
throw new IllegalStateException("call type is missing");
}
int presentation;
if (cursor.isNull(presentationColumn) || (presentation = cursor.getInt(presentationColumn)) == 0) {
// non-zero.
throw new IllegalStateException("presentation is missing");
}
String countryIso = cursor.getString(countryIsoColumn);
int duration = cursor.getInt(durationsColumn);
int dataUsage = cursor.getInt(dataUsageColumn);
String transcription = cursor.getString(transcriptionColumn);
String voicemailUri = cursor.getString(voicemailUriColumn);
int isRead = cursor.getInt(isReadColumn);
int isNew = cursor.getInt(newColumn);
String geocodedLocation = cursor.getString(geocodedLocationColumn);
String phoneAccountComponentName = cursor.getString(phoneAccountComponentColumn);
String phoneAccountId = cursor.getString(phoneAccountIdColumn);
int features = cursor.getInt(featuresColumn);
String postDialDigits = cursor.getString(postDialDigitsColumn);
// Exclude Duo audio calls.
if (isDuoAudioCall(phoneAccountComponentName, features)) {
continue;
}
ContentValues contentValues = new ContentValues();
contentValues.put(AnnotatedCallLog.TIMESTAMP, date);
if (!TextUtils.isEmpty(numberAsStr)) {
String numberWithPostDialDigits = postDialDigits == null ? numberAsStr : numberAsStr + postDialDigits;
DialerPhoneNumber dialerPhoneNumber = dialerPhoneNumberUtil.parse(numberWithPostDialDigits, countryIso);
contentValues.put(AnnotatedCallLog.NUMBER, dialerPhoneNumber.toByteArray());
String formattedNumber = PhoneNumberUtils.formatNumber(numberWithPostDialDigits, countryIso);
if (formattedNumber == null) {
formattedNumber = numberWithPostDialDigits;
}
contentValues.put(AnnotatedCallLog.FORMATTED_NUMBER, formattedNumber);
} else {
contentValues.put(AnnotatedCallLog.NUMBER, DialerPhoneNumber.getDefaultInstance().toByteArray());
}
contentValues.put(AnnotatedCallLog.NUMBER_PRESENTATION, presentation);
contentValues.put(AnnotatedCallLog.CALL_TYPE, type);
contentValues.put(AnnotatedCallLog.IS_READ, isRead);
contentValues.put(AnnotatedCallLog.NEW, isNew);
contentValues.put(AnnotatedCallLog.GEOCODED_LOCATION, geocodedLocation);
contentValues.put(AnnotatedCallLog.PHONE_ACCOUNT_COMPONENT_NAME, phoneAccountComponentName);
contentValues.put(AnnotatedCallLog.PHONE_ACCOUNT_ID, phoneAccountId);
contentValues.put(AnnotatedCallLog.FEATURES, features);
contentValues.put(AnnotatedCallLog.DURATION, duration);
contentValues.put(AnnotatedCallLog.DATA_USAGE, dataUsage);
contentValues.put(AnnotatedCallLog.TRANSCRIPTION, transcription);
contentValues.put(AnnotatedCallLog.VOICEMAIL_URI, voicemailUri);
contentValues.put(AnnotatedCallLog.CALL_MAPPING_ID, String.valueOf(date));
setTranscriptionState(cursor, contentValues);
if (existingAnnotatedCallLogIds.contains(id)) {
mutations.update(id, contentValues);
} else {
mutations.insert(id, contentValues);
}
} while (cursor.moveToNext());
}
}
use of com.android.dialer.phonenumberproto.DialerPhoneNumberUtil in project android_packages_apps_Dialer by LineageOS.
the class CequintPhoneLookup method lookup.
@Override
public ListenableFuture<CequintInfo> lookup(Context appContext, Call call) {
if (!CequintCallerIdManager.isCequintCallerIdEnabled(appContext)) {
return Futures.immediateFuture(CequintInfo.getDefaultInstance());
}
ListenableFuture<DialerPhoneNumber> dialerPhoneNumberFuture = backgroundExecutorService.submit(() -> {
DialerPhoneNumberUtil dialerPhoneNumberUtil = new DialerPhoneNumberUtil();
return dialerPhoneNumberUtil.parse(TelecomCallUtil.getNumber(call), GeoUtil.getCurrentCountryIso(appContext));
});
String callerDisplayName = call.getDetails().getCallerDisplayName();
boolean isIncomingCall = (call.getState() == Call.STATE_RINGING);
return Futures.transformAsync(dialerPhoneNumberFuture, dialerPhoneNumber -> backgroundExecutorService.submit(() -> buildCequintInfo(CequintCallerIdManager.getCequintCallerIdContactForCall(appContext, Assert.isNotNull(dialerPhoneNumber).getNormalizedNumber(), callerDisplayName, isIncomingCall))), lightweightExecutorService);
}
Aggregations