use of com.android.dialer.DialerPhoneNumber in project android_packages_apps_Dialer by LineageOS.
the class Coalescer method rowsShouldBeCombined.
/**
* @param row1 a row from {@link AnnotatedCallLog}
* @param row2 a row from {@link AnnotatedCallLog}
*/
private static boolean rowsShouldBeCombined(DialerPhoneNumberUtil dialerPhoneNumberUtil, ContentValues row1, ContentValues row2) {
// TODO: Real implementation.
DialerPhoneNumber number1;
DialerPhoneNumber number2;
try {
number1 = DialerPhoneNumber.parseFrom(row1.getAsByteArray(AnnotatedCallLog.NUMBER));
number2 = DialerPhoneNumber.parseFrom(row2.getAsByteArray(AnnotatedCallLog.NUMBER));
} catch (InvalidProtocolBufferException e) {
throw Assert.createAssertionFailException("error parsing DialerPhoneNumber proto", e);
}
if (!number1.hasDialerInternalPhoneNumber() && !number2.hasDialerInternalPhoneNumber()) {
// Empty numbers should not be combined.
return false;
}
if (!number1.hasDialerInternalPhoneNumber() || !number2.hasDialerInternalPhoneNumber()) {
// An empty number should not be combined with a non-empty number.
return false;
}
return dialerPhoneNumberUtil.isExactMatch(number1, number2);
}
use of com.android.dialer.DialerPhoneNumber in project android_packages_apps_Dialer by LineageOS.
the class SystemCallLogDataSource method coalesce.
@Override
public ContentValues coalesce(List<ContentValues> individualRowsSortedByTimestampDesc) {
// TODO: Complete implementation.
ContentValues coalescedValues = new RowCombiner(individualRowsSortedByTimestampDesc).useMostRecentLong(AnnotatedCallLog.TIMESTAMP).combine();
// All phone numbers in the provided group should be equivalent (but could be formatted
// differently). Arbitrarily show the raw phone number of the most recent call.
DialerPhoneNumber mostRecentPhoneNumber = getMostRecentPhoneNumber(individualRowsSortedByTimestampDesc);
coalescedValues.put(CoalescedAnnotatedCallLog.FORMATTED_NUMBER, mostRecentPhoneNumber.getRawInput().getNumber());
return coalescedValues;
}
use of com.android.dialer.DialerPhoneNumber in project android_packages_apps_Dialer by LineageOS.
the class SystemCallLogDataSource method getMostRecentPhoneNumber.
private static DialerPhoneNumber getMostRecentPhoneNumber(List<ContentValues> individualRowsSortedByTimestampDesc) {
DialerPhoneNumber dialerPhoneNumber;
byte[] protoBytes = individualRowsSortedByTimestampDesc.get(0).getAsByteArray(AnnotatedCallLog.NUMBER);
try {
dialerPhoneNumber = DialerPhoneNumber.parseFrom(protoBytes);
} catch (InvalidProtocolBufferException e) {
throw Assert.createAssertionFailException("couldn't parse DialerPhoneNumber", e);
}
return dialerPhoneNumber;
}
use of com.android.dialer.DialerPhoneNumber in project android_packages_apps_Dialer by LineageOS.
the class PhoneLookupDataSource method computePhoneLookupHistoryRowsToDelete.
private Set<String> computePhoneLookupHistoryRowsToDelete(Map<DialerPhoneNumber, Set<Long>> annotatedCallLogIdsByNumber, CallLogMutations mutations) {
if (mutations.getDeletes().isEmpty()) {
return ImmutableSet.of();
}
// First convert the dialer phone numbers to normalized numbers; we need to combine entries
// because different DialerPhoneNumbers can map to the same normalized number.
Map<String, Set<Long>> idsByNormalizedNumber = new ArrayMap<>();
for (Entry<DialerPhoneNumber, Set<Long>> entry : annotatedCallLogIdsByNumber.entrySet()) {
DialerPhoneNumber dialerPhoneNumber = entry.getKey();
Set<Long> idsForDialerPhoneNumber = entry.getValue();
// Note: This loses country info when number is not valid.
String normalizedNumber = dialerPhoneNumber.getNormalizedNumber();
Set<Long> idsForNormalizedNumber = idsByNormalizedNumber.get(normalizedNumber);
if (idsForNormalizedNumber == null) {
idsForNormalizedNumber = new ArraySet<>();
idsByNormalizedNumber.put(normalizedNumber, idsForNormalizedNumber);
}
idsForNormalizedNumber.addAll(idsForDialerPhoneNumber);
}
// Now look through and remove all IDs that were scheduled for delete; after doing that, if
// there are no remaining IDs left for a normalized number, the number can be deleted from
// PhoneLookupHistory.
Set<String> normalizedNumbersToDelete = new ArraySet<>();
for (Entry<String, Set<Long>> entry : idsByNormalizedNumber.entrySet()) {
String normalizedNumber = entry.getKey();
Set<Long> idsForNormalizedNumber = entry.getValue();
idsForNormalizedNumber.removeAll(mutations.getDeletes());
if (idsForNormalizedNumber.isEmpty()) {
normalizedNumbersToDelete.add(normalizedNumber);
}
}
return normalizedNumbersToDelete;
}
use of com.android.dialer.DialerPhoneNumber in project android_packages_apps_Dialer by LineageOS.
the class PhoneLookupDataSource method queryPhoneLookupHistoryForNumbers.
/**
* Returned map must have same keys as {@code uniqueDialerPhoneNumbers}
*/
private ImmutableMap<DialerPhoneNumber, PhoneLookupInfo> queryPhoneLookupHistoryForNumbers(Context appContext, Set<DialerPhoneNumber> uniqueDialerPhoneNumbers) {
// Note: This loses country info when number is not valid.
Map<DialerPhoneNumber, String> dialerPhoneNumberToNormalizedNumbers = Maps.asMap(uniqueDialerPhoneNumbers, DialerPhoneNumber::getNormalizedNumber);
// Convert values to a set to remove any duplicates that are the result of two
// DialerPhoneNumbers mapping to the same normalized number.
String[] normalizedNumbers = dialerPhoneNumberToNormalizedNumbers.values().toArray(new String[] {});
String[] questionMarks = new String[normalizedNumbers.length];
Arrays.fill(questionMarks, "?");
String selection = PhoneLookupHistory.NORMALIZED_NUMBER + " in (" + TextUtils.join(",", questionMarks) + ")";
Map<String, PhoneLookupInfo> normalizedNumberToInfoMap = new ArrayMap<>();
try (Cursor cursor = appContext.getContentResolver().query(PhoneLookupHistory.CONTENT_URI, new String[] { PhoneLookupHistory.NORMALIZED_NUMBER, PhoneLookupHistory.PHONE_LOOKUP_INFO }, selection, normalizedNumbers, null)) {
if (cursor == null) {
LogUtil.e("PhoneLookupDataSource.queryPhoneLookupHistoryForNumbers", "null cursor");
} else if (cursor.moveToFirst()) {
int normalizedNumberColumn = cursor.getColumnIndexOrThrow(PhoneLookupHistory.NORMALIZED_NUMBER);
int phoneLookupInfoColumn = cursor.getColumnIndexOrThrow(PhoneLookupHistory.PHONE_LOOKUP_INFO);
do {
String normalizedNumber = cursor.getString(normalizedNumberColumn);
PhoneLookupInfo phoneLookupInfo;
try {
phoneLookupInfo = PhoneLookupInfo.parseFrom(cursor.getBlob(phoneLookupInfoColumn));
} catch (InvalidProtocolBufferException e) {
throw new IllegalStateException(e);
}
normalizedNumberToInfoMap.put(normalizedNumber, phoneLookupInfo);
} while (cursor.moveToNext());
}
}
// number instead of DialerPhoneNumber. Build and return a new map keyed by DialerPhoneNumber.
return ImmutableMap.copyOf(Maps.asMap(uniqueDialerPhoneNumbers, (dialerPhoneNumber) -> {
String normalizedNumber = dialerPhoneNumberToNormalizedNumbers.get(dialerPhoneNumber);
PhoneLookupInfo phoneLookupInfo = normalizedNumberToInfoMap.get(normalizedNumber);
// entry for a number. Just use an empty value for that case.
return phoneLookupInfo == null ? PhoneLookupInfo.getDefaultInstance() : phoneLookupInfo;
}));
}
Aggregations