use of com.android.dialer.DialerPhoneNumber 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.DialerPhoneNumber in project android_packages_apps_Dialer by LineageOS.
the class Cp2DefaultDirectoryPhoneLookup method findUnprocessableNumbers.
private ArraySet<DialerPhoneNumber> findUnprocessableNumbers(ImmutableMap<DialerPhoneNumber, Cp2Info> existingInfoMap) {
ArraySet<DialerPhoneNumber> unprocessableNumbers = new ArraySet<>();
PartitionedNumbers partitionedNumbers = new PartitionedNumbers(existingInfoMap.keySet());
int invalidNumberCount = partitionedNumbers.invalidNumbers().size();
Logger.get(appContext).logAnnotatedCallLogMetrics(invalidNumberCount);
if (invalidNumberCount > getMaxSupportedInvalidNumbers()) {
for (String invalidNumber : partitionedNumbers.invalidNumbers()) {
unprocessableNumbers.addAll(partitionedNumbers.dialerPhoneNumbersForInvalid(invalidNumber));
}
}
return unprocessableNumbers;
}
use of com.android.dialer.DialerPhoneNumber 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);
}
}
use of com.android.dialer.DialerPhoneNumber in project android_packages_apps_Dialer by LineageOS.
the class VoicemailCursorLoader method toVoicemailEntry.
/**
* Creates a new {@link VoicemailEntry} from the provided cursor using the current position.
*/
static VoicemailEntry toVoicemailEntry(Cursor cursor) {
DialerPhoneNumber number;
try {
number = DialerPhoneNumber.parseFrom(cursor.getBlob(NUMBER));
} catch (InvalidProtocolBufferException e) {
throw new IllegalStateException("Couldn't parse DialerPhoneNumber bytes");
}
NumberAttributes numberAttributes;
try {
numberAttributes = NumberAttributes.parseFrom(cursor.getBlob(NUMBER_ATTRIBUTES));
} catch (InvalidProtocolBufferException e) {
throw new IllegalStateException("Couldn't parse NumberAttributes bytes");
}
// Voicemail numbers should always be valid so the CP2 information should never be incomplete,
// and there should be no need to query PhoneLookup at render time.
Assert.checkArgument(!numberAttributes.getIsCp2InfoIncomplete(), "CP2 info incomplete for number: %s", LogUtil.sanitizePii(number.getNormalizedNumber()));
VoicemailEntry.Builder voicemailEntryBuilder = VoicemailEntry.newBuilder().setId(cursor.getInt(ID)).setTimestamp(cursor.getLong(TIMESTAMP)).setNumber(number).setDuration(cursor.getLong(DURATION)).setCallType(cursor.getInt(CALL_TYPE)).setIsRead(cursor.getInt(IS_READ)).setNumberAttributes(numberAttributes).setTranscriptionState(cursor.getInt(TRANSCRIPTION_STATE));
String formattedNumber = cursor.getString(FORMATTED_NUMBER);
if (!TextUtils.isEmpty(formattedNumber)) {
voicemailEntryBuilder.setFormattedNumber(formattedNumber);
}
String geocodedLocation = cursor.getString(GEOCODED_LOCATION);
if (!TextUtils.isEmpty(geocodedLocation)) {
voicemailEntryBuilder.setGeocodedLocation(geocodedLocation);
}
String transcription = cursor.getString(TRANSCRIPTION);
if (!TextUtils.isEmpty(transcription)) {
voicemailEntryBuilder.setTranscription(transcription);
}
String voicemailUri = cursor.getString(VOICEMAIL_URI);
if (!TextUtils.isEmpty(voicemailUri)) {
voicemailEntryBuilder.setVoicemailUri(voicemailUri);
}
String phoneAccountComponentName = cursor.getString(PHONE_ACCOUNT_COMPONENT_NAME);
if (!TextUtils.isEmpty(phoneAccountComponentName)) {
voicemailEntryBuilder.setPhoneAccountComponentName(phoneAccountComponentName);
}
String phoneAccountId = cursor.getString(PHONE_ACCOUNT_ID);
if (!TextUtils.isEmpty(phoneAccountId)) {
voicemailEntryBuilder.setPhoneAccountId(phoneAccountId);
}
return voicemailEntryBuilder.build();
}
use of com.android.dialer.DialerPhoneNumber in project android_packages_apps_Dialer by LineageOS.
the class DialerPhoneNumberUtil method parse.
/**
* Parses the provided raw phone number into a {@link DialerPhoneNumber}.
*
* @see PhoneNumberUtil#parse(CharSequence, String)
*/
@WorkerThread
public DialerPhoneNumber parse(@Nullable String numberToParse, @Nullable String defaultRegion) {
Assert.isWorkerThread();
DialerPhoneNumber.Builder dialerPhoneNumber = DialerPhoneNumber.newBuilder();
if (defaultRegion != null) {
dialerPhoneNumber.setCountryIso(defaultRegion);
}
// Numbers can be null or empty for incoming "unknown" calls.
if (numberToParse == null) {
return dialerPhoneNumber.build();
}
// of a service number and the "*" can appear at the beginning (see a bug).
if (isServiceNumber(numberToParse)) {
return dialerPhoneNumber.setNormalizedNumber(numberToParse).build();
}
String postDialPortion = PhoneNumberUtils.extractPostDialPortion(numberToParse);
if (!postDialPortion.isEmpty()) {
dialerPhoneNumber.setPostDialPortion(postDialPortion);
}
String networkPortion = PhoneNumberUtils.extractNetworkPortion(numberToParse);
try {
PhoneNumber phoneNumber = phoneNumberUtil.parse(networkPortion, defaultRegion);
if (phoneNumberUtil.isValidNumber(phoneNumber)) {
String validNumber = phoneNumberUtil.format(phoneNumber, PhoneNumberFormat.E164);
if (TextUtils.isEmpty(validNumber)) {
throw new IllegalStateException("e164 number should not be empty: " + LogUtil.sanitizePii(numberToParse));
}
// The E164 representation doesn't contain post-dial digits, but we need to preserve them.
if (!postDialPortion.isEmpty()) {
validNumber += postDialPortion;
}
return dialerPhoneNumber.setNormalizedNumber(validNumber).setIsValid(true).build();
}
} catch (NumberParseException e) {
// fall through
}
return dialerPhoneNumber.setNormalizedNumber(networkPortion + postDialPortion).build();
}
Aggregations