Search in sources :

Example 6 with Cp2ContactInfo

use of com.android.dialer.phonelookup.PhoneLookupInfo.Cp2Info.Cp2ContactInfo in project android_packages_apps_Dialer by LineageOS.

the class Cp2DefaultDirectoryPhoneLookup method findNumbersToUpdate.

private ListenableFuture<Set<DialerPhoneNumber>> findNumbersToUpdate(Map<DialerPhoneNumber, Cp2Info> existingInfoMap, long lastModified, Set<DialerPhoneNumber> deletedPhoneNumbers) {
    return backgroundExecutorService.submit(() -> {
        Set<DialerPhoneNumber> updatedNumbers = new ArraySet<>();
        Set<Long> contactIds = new ArraySet<>();
        for (Entry<DialerPhoneNumber, Cp2Info> entry : existingInfoMap.entrySet()) {
            DialerPhoneNumber dialerPhoneNumber = entry.getKey();
            Cp2Info existingInfo = entry.getValue();
            // If the number was deleted, we need to check if it was added to a new contact.
            if (deletedPhoneNumbers.contains(dialerPhoneNumber)) {
                updatedNumbers.add(dialerPhoneNumber);
                continue;
            }
            // updated info.
            if (existingInfo.getCp2ContactInfoCount() == 0) {
                updatedNumbers.add(dialerPhoneNumber);
            } else {
                // our set of DialerPhoneNumbers we want to update.
                for (Cp2ContactInfo cp2ContactInfo : existingInfo.getCp2ContactInfoList()) {
                    long existingContactId = cp2ContactInfo.getContactId();
                    if (existingContactId == 0) {
                        // If the number doesn't have a contact id, for various reasons, we need to look
                        // up the number to check if any exists. The various reasons this might happen
                        // are:
                        // - An existing contact that wasn't in the call log is now in the call log.
                        // - A number was in the call log before but has now been added to a contact.
                        // - A number is in the call log, but isn't associated with any contact.
                        updatedNumbers.add(dialerPhoneNumber);
                    } else {
                        contactIds.add(cp2ContactInfo.getContactId());
                    }
                }
            }
        }
        // is in our set of contact IDs we build above.
        if (!contactIds.isEmpty()) {
            try (Cursor cursor = queryContactsTableForContacts(contactIds, lastModified)) {
                int contactIdIndex = cursor.getColumnIndex(Contacts._ID);
                int lastUpdatedIndex = cursor.getColumnIndex(Contacts.CONTACT_LAST_UPDATED_TIMESTAMP);
                cursor.moveToPosition(-1);
                while (cursor.moveToNext()) {
                    // Find the DialerPhoneNumber for each contact id and add it to our updated numbers
                    // set. These, along with our number not associated with any Cp2ContactInfo need to
                    // be updated.
                    long contactId = cursor.getLong(contactIdIndex);
                    updatedNumbers.addAll(findDialerPhoneNumbersContainingContactId(existingInfoMap, contactId));
                    long lastUpdatedTimestamp = cursor.getLong(lastUpdatedIndex);
                    if (currentLastTimestampProcessed == null || currentLastTimestampProcessed < lastUpdatedTimestamp) {
                        currentLastTimestampProcessed = lastUpdatedTimestamp;
                    }
                }
            }
        }
        return updatedNumbers;
    });
}
Also used : Cp2Info(com.android.dialer.phonelookup.PhoneLookupInfo.Cp2Info) ArraySet(android.support.v4.util.ArraySet) DialerPhoneNumber(com.android.dialer.DialerPhoneNumber) Cp2ContactInfo(com.android.dialer.phonelookup.PhoneLookupInfo.Cp2Info.Cp2ContactInfo) Cursor(android.database.Cursor)

Example 7 with Cp2ContactInfo

use of com.android.dialer.phonelookup.PhoneLookupInfo.Cp2Info.Cp2ContactInfo in project android_packages_apps_Dialer by LineageOS.

the class Cp2DefaultDirectoryPhoneLookup method addInfo.

/**
 * Adds the {@code cp2ContactInfo} to the entries for all specified {@code dialerPhoneNumbers} in
 * the {@code map}.
 */
private static void addInfo(Map<DialerPhoneNumber, Set<Cp2ContactInfo>> map, Set<DialerPhoneNumber> dialerPhoneNumbers, Set<Cp2ContactInfo> cp2ContactInfos) {
    for (DialerPhoneNumber dialerPhoneNumber : dialerPhoneNumbers) {
        Set<Cp2ContactInfo> existingInfos = map.get(dialerPhoneNumber);
        if (existingInfos == null) {
            existingInfos = new ArraySet<>();
            map.put(dialerPhoneNumber, existingInfos);
        }
        existingInfos.addAll(cp2ContactInfos);
    }
}
Also used : DialerPhoneNumber(com.android.dialer.DialerPhoneNumber) Cp2ContactInfo(com.android.dialer.phonelookup.PhoneLookupInfo.Cp2Info.Cp2ContactInfo)

Aggregations

Cp2ContactInfo (com.android.dialer.phonelookup.PhoneLookupInfo.Cp2Info.Cp2ContactInfo)7 ArraySet (android.support.v4.util.ArraySet)6 DialerPhoneNumber (com.android.dialer.DialerPhoneNumber)5 Cursor (android.database.Cursor)4 ArrayMap (android.support.v4.util.ArrayMap)3 Cp2Info (com.android.dialer.phonelookup.PhoneLookupInfo.Cp2Info)3 PartitionedNumbers (com.android.dialer.phonenumberproto.PartitionedNumbers)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 Set (java.util.Set)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Context (android.content.Context)1 SharedPreferences (android.content.SharedPreferences)1 Uri (android.net.Uri)1 ContactsContract (android.provider.ContactsContract)1 Phone (android.provider.ContactsContract.CommonDataKinds.Phone)1