diff options
author | zachh <zachh@google.com> | 2018-01-09 17:29:06 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-01-09 18:27:41 -0800 |
commit | ff88f7bbe07fb3e267af49427adf1a91e3fc21e9 (patch) | |
tree | 34211b16307c159d1726bddc0ec2e2468f66981d /java/com/android/dialer/phonelookup | |
parent | 9f8d0676caa3a00849fa18def2996399ee1bc708 (diff) |
Added RealtimeRowProcessor.
This is for performing work inside of the call log's RecyclerView, when the view holder is bound. Most of the time, this should be a no-op but there are possible edge cases where the call log data cannot be updated efficiently through the standard batch mechanism.
One example of this is when there are too many invalid numbers in the call log; the CP2 information for invalid numbers cannot be efficiently batch updated so we fetch this information at display time. (Note that we do handle up to 5 invalid numbers in the batch update mechanism, but if there are more than that we fallback to this realtime processing.)
Test: unit, manual
PiperOrigin-RevId: 181400016
Change-Id: Iea6b380742e757b48d19f319fe46dc5fae837604
Diffstat (limited to 'java/com/android/dialer/phonelookup')
-rw-r--r-- | java/com/android/dialer/phonelookup/cp2/Cp2PhoneLookup.java | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/java/com/android/dialer/phonelookup/cp2/Cp2PhoneLookup.java b/java/com/android/dialer/phonelookup/cp2/Cp2PhoneLookup.java index 0d312cbbe..5ae0fb68a 100644 --- a/java/com/android/dialer/phonelookup/cp2/Cp2PhoneLookup.java +++ b/java/com/android/dialer/phonelookup/cp2/Cp2PhoneLookup.java @@ -40,6 +40,7 @@ import com.android.dialer.phonelookup.PhoneLookupInfo; import com.android.dialer.phonelookup.PhoneLookupInfo.Cp2Info; import com.android.dialer.phonelookup.PhoneLookupInfo.Cp2Info.Cp2ContactInfo; import com.android.dialer.phonelookup.database.contract.PhoneLookupHistoryContract.PhoneLookupHistory; +import com.android.dialer.phonenumberproto.DialerPhoneNumberUtil; import com.android.dialer.phonenumberproto.PartitionedNumbers; import com.android.dialer.storage.Unencrypted; import com.android.dialer.telecom.TelecomCallUtil; @@ -51,6 +52,7 @@ import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; +import com.google.i18n.phonenumbers.PhoneNumberUtil; import com.google.protobuf.InvalidProtocolBufferException; import java.util.ArrayList; import java.util.List; @@ -157,6 +159,34 @@ public final class Cp2PhoneLookup implements PhoneLookup<Cp2Info> { return Cp2Info.newBuilder().addAllCp2ContactInfo(cp2ContactInfos).build(); } + /** + * Queries ContactsContract.PhoneLookup for the {@link Cp2Info} associated with the provided + * {@link DialerPhoneNumber}. Returns {@link Cp2Info#getDefaultInstance()} if there is no + * information. + */ + public ListenableFuture<Cp2Info> lookupByNumber(DialerPhoneNumber dialerPhoneNumber) { + return backgroundExecutorService.submit( + () -> { + DialerPhoneNumberUtil dialerPhoneNumberUtil = + new DialerPhoneNumberUtil(PhoneNumberUtil.getInstance()); + String rawNumber = dialerPhoneNumberUtil.normalizeNumber(dialerPhoneNumber); + if (rawNumber.isEmpty()) { + return Cp2Info.getDefaultInstance(); + } + Set<Cp2ContactInfo> cp2ContactInfos = new ArraySet<>(); + try (Cursor cursor = queryPhoneLookup(PHONE_LOOKUP_PROJECTION, rawNumber)) { + if (cursor == null) { + LogUtil.w("Cp2PhoneLookup.lookup", "null cursor"); + return Cp2Info.getDefaultInstance(); + } + while (cursor.moveToNext()) { + cp2ContactInfos.add(buildCp2ContactInfoFromPhoneCursor(appContext, cursor)); + } + } + return Cp2Info.newBuilder().addAllCp2ContactInfo(cp2ContactInfos).build(); + }); + } + @Override public ListenableFuture<Boolean> isDirty(ImmutableSet<DialerPhoneNumber> phoneNumbers) { PartitionedNumbers partitionedNumbers = new PartitionedNumbers(phoneNumbers); |