Loading java/com/android/dialer/phonelookup/cp2/Cp2PhoneLookup.java +33 −9 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ import android.database.Cursor; import android.provider.ContactsContract.CommonDataKinds.Phone; import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.DeletedContacts; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.util.ArrayMap; import android.support.v4.util.ArraySet; Loading @@ -39,6 +38,7 @@ import com.android.dialer.phonelookup.PhoneLookupInfo.Cp2Info; import com.android.dialer.phonelookup.PhoneLookupInfo.Cp2Info.Cp2ContactInfo; import com.android.dialer.phonenumberproto.DialerPhoneNumberUtil; import com.android.dialer.storage.Unencrypted; import com.android.dialer.telecom.TelecomCallUtil; import com.google.common.base.Optional; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; Loading Loading @@ -96,9 +96,32 @@ public final class Cp2PhoneLookup implements PhoneLookup { } @Override public ListenableFuture<PhoneLookupInfo> lookup(@NonNull Call call) { // TODO(zachh): Implementation. return backgroundExecutorService.submit(PhoneLookupInfo::getDefaultInstance); public ListenableFuture<PhoneLookupInfo> lookup(Call call) { return backgroundExecutorService.submit(() -> lookupInternal(call)); } private PhoneLookupInfo lookupInternal(Call call) { String rawNumber = TelecomCallUtil.getNumber(call); if (TextUtils.isEmpty(rawNumber)) { return PhoneLookupInfo.getDefaultInstance(); } Optional<String> e164 = TelecomCallUtil.getE164Number(appContext, call); Set<Cp2ContactInfo> cp2ContactInfos = new ArraySet<>(); try (Cursor cursor = e164.isPresent() ? queryPhoneTableBasedOnE164(CP2_INFO_PROJECTION, ImmutableSet.of(e164.get())) : queryPhoneTableBasedOnRawNumber(CP2_INFO_PROJECTION, ImmutableSet.of(rawNumber))) { if (cursor == null) { LogUtil.w("Cp2PhoneLookup.lookupInternal", "null cursor"); return PhoneLookupInfo.getDefaultInstance(); } while (cursor.moveToNext()) { cp2ContactInfos.add(buildCp2ContactInfoFromPhoneCursor(appContext, cursor)); } } return PhoneLookupInfo.newBuilder() .setCp2Info(Cp2Info.newBuilder().addAllCp2ContactInfo(cp2ContactInfos)) .build(); } @Override Loading Loading @@ -226,10 +249,11 @@ public final class Cp2PhoneLookup implements PhoneLookup { public ListenableFuture<ImmutableMap<DialerPhoneNumber, PhoneLookupInfo>> getMostRecentPhoneLookupInfo( ImmutableMap<DialerPhoneNumber, PhoneLookupInfo> existingInfoMap) { return backgroundExecutorService.submit(() -> bulkUpdateInternal(existingInfoMap)); return backgroundExecutorService.submit( () -> getMostRecentPhoneLookupInfoInternal(existingInfoMap)); } private ImmutableMap<DialerPhoneNumber, PhoneLookupInfo> bulkUpdateInternal( private ImmutableMap<DialerPhoneNumber, PhoneLookupInfo> getMostRecentPhoneLookupInfoInternal( ImmutableMap<DialerPhoneNumber, PhoneLookupInfo> existingInfoMap) { currentLastTimestampProcessed = null; long lastModified = sharedPreferences.getLong(PREF_LAST_TIMESTAMP_PROCESSED, 0L); Loading Loading @@ -381,7 +405,7 @@ public final class Cp2PhoneLookup implements PhoneLookup { String e164Number = cursor.getString(CP2_INFO_NORMALIZED_NUMBER_INDEX); Set<DialerPhoneNumber> dialerPhoneNumbers = partitionedNumbers.dialerPhoneNumbersForE164(e164Number); Cp2ContactInfo info = buildCp2ContactInfoFromUpdatedContactsCursor(appContext, cursor); Cp2ContactInfo info = buildCp2ContactInfoFromPhoneCursor(appContext, cursor); addInfo(map, dialerPhoneNumbers, info); } } Loading @@ -398,7 +422,7 @@ public final class Cp2PhoneLookup implements PhoneLookup { String unformattableNumber = cursor.getString(CP2_INFO_NUMBER_INDEX); Set<DialerPhoneNumber> dialerPhoneNumbers = partitionedNumbers.dialerPhoneNumbersForUnformattable(unformattableNumber); Cp2ContactInfo info = buildCp2ContactInfoFromUpdatedContactsCursor(appContext, cursor); Cp2ContactInfo info = buildCp2ContactInfoFromPhoneCursor(appContext, cursor); addInfo(map, dialerPhoneNumbers, info); } } Loading Loading @@ -453,7 +477,7 @@ public final class Cp2PhoneLookup implements PhoneLookup { * @param cursor with projection {@link #CP2_INFO_PROJECTION}. * @return new {@link Cp2ContactInfo} based on current row of {@code cursor}. */ private static Cp2ContactInfo buildCp2ContactInfoFromUpdatedContactsCursor( private static Cp2ContactInfo buildCp2ContactInfoFromPhoneCursor( Context appContext, Cursor cursor) { String displayName = cursor.getString(CP2_INFO_NAME_INDEX); String photoUri = cursor.getString(CP2_INFO_PHOTO_URI_INDEX); Loading java/com/android/dialer/telecom/TelecomCallUtil.java +31 −15 Original line number Diff line number Diff line Loading @@ -72,13 +72,37 @@ public class TelecomCallUtil { } /** * Normalizes the number of the {@code call} to E.164. If the country code is missing in the * number the SIM's country will be used. Only removes non-dialable digits if the country code is * missing. * Normalizes the number of the {@code call} to E.164. The country of the SIM associated with the * call is used to determine the country. * * <p>If the number cannot be formatted (because for example the country cannot be determined), * returns the number with non-dialable digits removed. */ @WorkerThread public static Optional<String> getNormalizedNumber(Context appContext, Call call) { Assert.isWorkerThread(); Optional<String> e164 = getE164Number(appContext, call); if (e164.isPresent()) { return e164; } String rawNumber = getNumber(call); if (TextUtils.isEmpty(rawNumber)) { return Optional.absent(); } return Optional.of(PhoneNumberUtils.normalizeNumber(rawNumber)); } /** * Formats the number of the {@code call} to E.164. The country of the SIM associated with the * call is used to determine the country. * * <p>If the number cannot be formatted (because for example the country cannot be determined), * returns {@link Optional#absent()}. */ @WorkerThread public static Optional<String> getE164Number(Context appContext, Call call) { Assert.isWorkerThread(); PhoneAccountHandle phoneAccountHandle = call.getDetails().getAccountHandle(); Optional<SubscriptionInfo> subscriptionInfo = TelecomUtil.getSubscriptionInfo(appContext, phoneAccountHandle); Loading @@ -86,21 +110,13 @@ public class TelecomCallUtil { if (TextUtils.isEmpty(rawNumber)) { return Optional.absent(); } String normalizedNumber = PhoneNumberUtils.normalizeNumber(rawNumber); if (TextUtils.isEmpty(normalizedNumber)) { return Optional.absent(); } String countryCode = subscriptionInfo.isPresent() ? subscriptionInfo.get().getCountryIso() : null; if (countryCode == null) { LogUtil.w( "PhoneLookupHistoryRecorder.getNormalizedNumber", "couldn't find a country code for call"); return Optional.of(normalizedNumber); LogUtil.w("TelecomCallUtil.getE164Number", "couldn't find a country code for call"); return Optional.absent(); } String e164Number = PhoneNumberUtils.formatNumberToE164(rawNumber, countryCode.toUpperCase(Locale.US)); return e164Number == null ? Optional.of(normalizedNumber) : Optional.of(e164Number); return Optional.fromNullable( PhoneNumberUtils.formatNumberToE164(rawNumber, countryCode.toUpperCase(Locale.US))); } } Loading
java/com/android/dialer/phonelookup/cp2/Cp2PhoneLookup.java +33 −9 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ import android.database.Cursor; import android.provider.ContactsContract.CommonDataKinds.Phone; import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.DeletedContacts; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.util.ArrayMap; import android.support.v4.util.ArraySet; Loading @@ -39,6 +38,7 @@ import com.android.dialer.phonelookup.PhoneLookupInfo.Cp2Info; import com.android.dialer.phonelookup.PhoneLookupInfo.Cp2Info.Cp2ContactInfo; import com.android.dialer.phonenumberproto.DialerPhoneNumberUtil; import com.android.dialer.storage.Unencrypted; import com.android.dialer.telecom.TelecomCallUtil; import com.google.common.base.Optional; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; Loading Loading @@ -96,9 +96,32 @@ public final class Cp2PhoneLookup implements PhoneLookup { } @Override public ListenableFuture<PhoneLookupInfo> lookup(@NonNull Call call) { // TODO(zachh): Implementation. return backgroundExecutorService.submit(PhoneLookupInfo::getDefaultInstance); public ListenableFuture<PhoneLookupInfo> lookup(Call call) { return backgroundExecutorService.submit(() -> lookupInternal(call)); } private PhoneLookupInfo lookupInternal(Call call) { String rawNumber = TelecomCallUtil.getNumber(call); if (TextUtils.isEmpty(rawNumber)) { return PhoneLookupInfo.getDefaultInstance(); } Optional<String> e164 = TelecomCallUtil.getE164Number(appContext, call); Set<Cp2ContactInfo> cp2ContactInfos = new ArraySet<>(); try (Cursor cursor = e164.isPresent() ? queryPhoneTableBasedOnE164(CP2_INFO_PROJECTION, ImmutableSet.of(e164.get())) : queryPhoneTableBasedOnRawNumber(CP2_INFO_PROJECTION, ImmutableSet.of(rawNumber))) { if (cursor == null) { LogUtil.w("Cp2PhoneLookup.lookupInternal", "null cursor"); return PhoneLookupInfo.getDefaultInstance(); } while (cursor.moveToNext()) { cp2ContactInfos.add(buildCp2ContactInfoFromPhoneCursor(appContext, cursor)); } } return PhoneLookupInfo.newBuilder() .setCp2Info(Cp2Info.newBuilder().addAllCp2ContactInfo(cp2ContactInfos)) .build(); } @Override Loading Loading @@ -226,10 +249,11 @@ public final class Cp2PhoneLookup implements PhoneLookup { public ListenableFuture<ImmutableMap<DialerPhoneNumber, PhoneLookupInfo>> getMostRecentPhoneLookupInfo( ImmutableMap<DialerPhoneNumber, PhoneLookupInfo> existingInfoMap) { return backgroundExecutorService.submit(() -> bulkUpdateInternal(existingInfoMap)); return backgroundExecutorService.submit( () -> getMostRecentPhoneLookupInfoInternal(existingInfoMap)); } private ImmutableMap<DialerPhoneNumber, PhoneLookupInfo> bulkUpdateInternal( private ImmutableMap<DialerPhoneNumber, PhoneLookupInfo> getMostRecentPhoneLookupInfoInternal( ImmutableMap<DialerPhoneNumber, PhoneLookupInfo> existingInfoMap) { currentLastTimestampProcessed = null; long lastModified = sharedPreferences.getLong(PREF_LAST_TIMESTAMP_PROCESSED, 0L); Loading Loading @@ -381,7 +405,7 @@ public final class Cp2PhoneLookup implements PhoneLookup { String e164Number = cursor.getString(CP2_INFO_NORMALIZED_NUMBER_INDEX); Set<DialerPhoneNumber> dialerPhoneNumbers = partitionedNumbers.dialerPhoneNumbersForE164(e164Number); Cp2ContactInfo info = buildCp2ContactInfoFromUpdatedContactsCursor(appContext, cursor); Cp2ContactInfo info = buildCp2ContactInfoFromPhoneCursor(appContext, cursor); addInfo(map, dialerPhoneNumbers, info); } } Loading @@ -398,7 +422,7 @@ public final class Cp2PhoneLookup implements PhoneLookup { String unformattableNumber = cursor.getString(CP2_INFO_NUMBER_INDEX); Set<DialerPhoneNumber> dialerPhoneNumbers = partitionedNumbers.dialerPhoneNumbersForUnformattable(unformattableNumber); Cp2ContactInfo info = buildCp2ContactInfoFromUpdatedContactsCursor(appContext, cursor); Cp2ContactInfo info = buildCp2ContactInfoFromPhoneCursor(appContext, cursor); addInfo(map, dialerPhoneNumbers, info); } } Loading Loading @@ -453,7 +477,7 @@ public final class Cp2PhoneLookup implements PhoneLookup { * @param cursor with projection {@link #CP2_INFO_PROJECTION}. * @return new {@link Cp2ContactInfo} based on current row of {@code cursor}. */ private static Cp2ContactInfo buildCp2ContactInfoFromUpdatedContactsCursor( private static Cp2ContactInfo buildCp2ContactInfoFromPhoneCursor( Context appContext, Cursor cursor) { String displayName = cursor.getString(CP2_INFO_NAME_INDEX); String photoUri = cursor.getString(CP2_INFO_PHOTO_URI_INDEX); Loading
java/com/android/dialer/telecom/TelecomCallUtil.java +31 −15 Original line number Diff line number Diff line Loading @@ -72,13 +72,37 @@ public class TelecomCallUtil { } /** * Normalizes the number of the {@code call} to E.164. If the country code is missing in the * number the SIM's country will be used. Only removes non-dialable digits if the country code is * missing. * Normalizes the number of the {@code call} to E.164. The country of the SIM associated with the * call is used to determine the country. * * <p>If the number cannot be formatted (because for example the country cannot be determined), * returns the number with non-dialable digits removed. */ @WorkerThread public static Optional<String> getNormalizedNumber(Context appContext, Call call) { Assert.isWorkerThread(); Optional<String> e164 = getE164Number(appContext, call); if (e164.isPresent()) { return e164; } String rawNumber = getNumber(call); if (TextUtils.isEmpty(rawNumber)) { return Optional.absent(); } return Optional.of(PhoneNumberUtils.normalizeNumber(rawNumber)); } /** * Formats the number of the {@code call} to E.164. The country of the SIM associated with the * call is used to determine the country. * * <p>If the number cannot be formatted (because for example the country cannot be determined), * returns {@link Optional#absent()}. */ @WorkerThread public static Optional<String> getE164Number(Context appContext, Call call) { Assert.isWorkerThread(); PhoneAccountHandle phoneAccountHandle = call.getDetails().getAccountHandle(); Optional<SubscriptionInfo> subscriptionInfo = TelecomUtil.getSubscriptionInfo(appContext, phoneAccountHandle); Loading @@ -86,21 +110,13 @@ public class TelecomCallUtil { if (TextUtils.isEmpty(rawNumber)) { return Optional.absent(); } String normalizedNumber = PhoneNumberUtils.normalizeNumber(rawNumber); if (TextUtils.isEmpty(normalizedNumber)) { return Optional.absent(); } String countryCode = subscriptionInfo.isPresent() ? subscriptionInfo.get().getCountryIso() : null; if (countryCode == null) { LogUtil.w( "PhoneLookupHistoryRecorder.getNormalizedNumber", "couldn't find a country code for call"); return Optional.of(normalizedNumber); LogUtil.w("TelecomCallUtil.getE164Number", "couldn't find a country code for call"); return Optional.absent(); } String e164Number = PhoneNumberUtils.formatNumberToE164(rawNumber, countryCode.toUpperCase(Locale.US)); return e164Number == null ? Optional.of(normalizedNumber) : Optional.of(e164Number); return Optional.fromNullable( PhoneNumberUtils.formatNumberToE164(rawNumber, countryCode.toUpperCase(Locale.US))); } }