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