Search in sources :

Example 1 with DialerPhoneNumber

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);
}
Also used : DialerPhoneNumber(com.android.dialer.DialerPhoneNumber) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException)

Example 2 with DialerPhoneNumber

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;
}
Also used : ContentValues(android.content.ContentValues) DialerPhoneNumber(com.android.dialer.DialerPhoneNumber) RowCombiner(com.android.dialer.calllog.datasources.util.RowCombiner)

Example 3 with DialerPhoneNumber

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;
}
Also used : DialerPhoneNumber(com.android.dialer.DialerPhoneNumber) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException)

Example 4 with 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;
}
Also used : ArraySet(android.util.ArraySet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) ArraySet(android.util.ArraySet) DialerPhoneNumber(com.android.dialer.DialerPhoneNumber) ArrayMap(android.util.ArrayMap)

Example 5 with DialerPhoneNumber

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;
    }));
}
Also used : ContentProviderOperation(android.content.ContentProviderOperation) Assert(com.android.dialer.common.Assert) Context(android.content.Context) LogUtil(com.android.dialer.common.LogUtil) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) Arrays(java.util.Arrays) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) AnnotatedCallLog(com.android.dialer.calllog.database.contract.AnnotatedCallLogContract.AnnotatedCallLog) RemoteException(android.os.RemoteException) Callable(java.util.concurrent.Callable) CallLogDataSource(com.android.dialer.calllog.datasources.CallLogDataSource) CallLogMutations(com.android.dialer.calllog.datasources.CallLogMutations) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) BackgroundExecutor(com.android.dialer.common.concurrent.Annotations.BackgroundExecutor) PhoneLookup(com.android.dialer.phonelookup.PhoneLookup) CompositePhoneLookup(com.android.dialer.phonelookup.composite.CompositePhoneLookup) Map(java.util.Map) ArraySet(android.util.ArraySet) PhoneLookupHistoryDatabaseHelper(com.android.dialer.phonelookup.database.PhoneLookupHistoryDatabaseHelper) PhoneLookupHistory(com.android.dialer.phonelookup.database.contract.PhoneLookupHistoryContract.PhoneLookupHistory) MainThread(android.support.annotation.MainThread) ApplicationContext(com.android.dialer.inject.ApplicationContext) Cursor(android.database.Cursor) ArrayMap(android.util.ArrayMap) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) LightweightExecutor(com.android.dialer.common.concurrent.Annotations.LightweightExecutor) ImmutableSet(com.google.common.collect.ImmutableSet) PhoneLookupInfo(com.android.dialer.phonelookup.PhoneLookupInfo) PhoneLookupHistoryContract(com.android.dialer.phonelookup.database.contract.PhoneLookupHistoryContract) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) TextUtils(android.text.TextUtils) WorkerThread(android.support.annotation.WorkerThread) Maps(com.google.common.collect.Maps) DialerPhoneNumber(com.android.dialer.DialerPhoneNumber) OperationApplicationException(android.content.OperationApplicationException) Futures(com.google.common.util.concurrent.Futures) Entry(java.util.Map.Entry) NumberAttributesBuilder(com.android.dialer.calllogutils.NumberAttributesBuilder) ContentValues(android.content.ContentValues) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) PhoneLookupInfo(com.android.dialer.phonelookup.PhoneLookupInfo) DialerPhoneNumber(com.android.dialer.DialerPhoneNumber) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ArrayMap(android.util.ArrayMap) Cursor(android.database.Cursor)

Aggregations

DialerPhoneNumber (com.android.dialer.DialerPhoneNumber)26 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)8 ContentValues (android.content.ContentValues)7 Cursor (android.database.Cursor)7 ImmutableMap (com.google.common.collect.ImmutableMap)7 ArrayList (java.util.ArrayList)7 ArraySet (android.support.v4.util.ArraySet)6 PhoneLookupInfo (com.android.dialer.phonelookup.PhoneLookupInfo)6 Cp2ContactInfo (com.android.dialer.phonelookup.PhoneLookupInfo.Cp2Info.Cp2ContactInfo)6 ImmutableSet (com.google.common.collect.ImmutableSet)6 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)6 Set (java.util.Set)6 PartitionedNumbers (com.android.dialer.phonenumberproto.PartitionedNumbers)5 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)5 Context (android.content.Context)4 ArraySet (android.util.ArraySet)4 LogUtil (com.android.dialer.common.LogUtil)4 BackgroundExecutor (com.android.dialer.common.concurrent.Annotations.BackgroundExecutor)4 ApplicationContext (com.android.dialer.inject.ApplicationContext)4 PhoneLookup (com.android.dialer.phonelookup.PhoneLookup)4