From 31e83f3eb7e6ce06c7fb93b621f6086e7d5cd8c2 Mon Sep 17 00:00:00 2001 From: linyuh Date: Wed, 17 Jan 2018 10:39:26 -0800 Subject: Replace PhoneLookupSelector with PhoneLookupInfoConsolidator. PhoneLookupInfoConsolidator is designed for the following two purposes. (1) Different sub-messages in a PhoneLookupInfo proto can contain information for the same purpose. For example, all of cp2_local_info, cp2_remote_info, and people_api_info have the information for a contact's name. PhoneLookupInfoConsolidator defines the rules that determine which sub-message should be used to display the name in the UI. This is the same as PhoneLookupSelector. (2) Avoid mixing info from different sub-messages when we are supposed to stick with only one sub-message. For example, if a PhoneLookupInfo proto has both cp2_local_info and cp2_remote_info but only cp2_remote_info has a photo URI, PhoneLookupInfoConsolidator should return an *empty* photo URI as cp2_local_info has higher priority and we should not use cp2_remote_info's photo URI to display the contact's photo. This is what PhoneLookupSelector is unable to do. Bug: 71763594 Test: PhoneLookupInfoConsolidatorTest PiperOrigin-RevId: 182236013 Change-Id: If19cdc1a9e076f3ebc8f9e2901f050b519e273f2 --- .../phonelookup/PhoneLookupDataSource.java | 30 ++++++++++++---------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java') diff --git a/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java b/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java index b73c169b9..1d4a35a6c 100644 --- a/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java +++ b/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java @@ -37,11 +37,12 @@ import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; import com.android.dialer.common.concurrent.Annotations.BackgroundExecutor; import com.android.dialer.common.concurrent.Annotations.LightweightExecutor; +import com.android.dialer.inject.ApplicationContext; import com.android.dialer.phonelookup.PhoneLookup; import com.android.dialer.phonelookup.PhoneLookupInfo; +import com.android.dialer.phonelookup.consolidator.PhoneLookupInfoConsolidator; import com.android.dialer.phonelookup.database.contract.PhoneLookupHistoryContract; import com.android.dialer.phonelookup.database.contract.PhoneLookupHistoryContract.PhoneLookupHistory; -import com.android.dialer.phonelookup.selector.PhoneLookupSelector; import com.android.dialer.phonenumberproto.DialerPhoneNumberUtil; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -67,8 +68,8 @@ import javax.inject.Inject; public final class PhoneLookupDataSource implements CallLogDataSource, PhoneLookup.ContentObserverCallbacks { + private final Context appContext; private final PhoneLookup phoneLookup; - private final PhoneLookupSelector phoneLookupSelector; private final ListeningExecutorService backgroundExecutorService; private final ListeningExecutorService lightweightExecutorService; @@ -94,11 +95,11 @@ public final class PhoneLookupDataSource @Inject PhoneLookupDataSource( PhoneLookup phoneLookup, - PhoneLookupSelector phoneLookupSelector, + @ApplicationContext Context appContext, @BackgroundExecutor ListeningExecutorService backgroundExecutorService, @LightweightExecutor ListeningExecutorService lightweightExecutorService) { this.phoneLookup = phoneLookup; - this.phoneLookupSelector = phoneLookupSelector; + this.appContext = appContext; this.backgroundExecutorService = backgroundExecutorService; this.lightweightExecutorService = lightweightExecutorService; } @@ -579,19 +580,20 @@ public final class PhoneLookupDataSource } private void updateContentValues(ContentValues contentValues, PhoneLookupInfo phoneLookupInfo) { + PhoneLookupInfoConsolidator phoneLookupInfoConsolidator = + new PhoneLookupInfoConsolidator(appContext, phoneLookupInfo); contentValues.put( AnnotatedCallLog.NUMBER_ATTRIBUTES, NumberAttributes.newBuilder() - .setName(phoneLookupSelector.selectName(phoneLookupInfo)) - .setPhotoUri(phoneLookupSelector.selectPhotoUri(phoneLookupInfo)) - .setPhotoId(phoneLookupSelector.selectPhotoId(phoneLookupInfo)) - .setLookupUri(phoneLookupSelector.selectLookupUri(phoneLookupInfo)) - .setNumberTypeLabel(phoneLookupSelector.selectNumberLabel(phoneLookupInfo)) - .setIsBusiness(phoneLookupSelector.selectIsBusiness(phoneLookupInfo)) - .setIsVoicemail(phoneLookupSelector.selectIsVoicemail(phoneLookupInfo)) - .setCanReportAsInvalidNumber( - phoneLookupSelector.canReportAsInvalidNumber(phoneLookupInfo)) - .setIsCp2InfoIncomplete(phoneLookupSelector.selectIsCp2InfoIncomplete(phoneLookupInfo)) + .setName(phoneLookupInfoConsolidator.getName()) + .setPhotoUri(phoneLookupInfoConsolidator.getPhotoUri()) + .setPhotoId(phoneLookupInfoConsolidator.getPhotoId()) + .setLookupUri(phoneLookupInfoConsolidator.getLookupUri()) + .setNumberTypeLabel(phoneLookupInfoConsolidator.getNumberLabel()) + .setIsBusiness(phoneLookupInfoConsolidator.isBusiness()) + .setIsVoicemail(phoneLookupInfoConsolidator.isVoicemail()) + .setCanReportAsInvalidNumber(phoneLookupInfoConsolidator.canReportAsInvalidNumber()) + .setIsCp2InfoIncomplete(phoneLookupInfoConsolidator.isCp2LocalInfoIncomplete()) .build() .toByteArray()); } -- cgit v1.2.3