From 096d5a68f89f106cb03ec3e59065c1c04ab41096 Mon Sep 17 00:00:00 2001 From: linyuh Date: Tue, 13 Feb 2018 09:59:39 -0800 Subject: Include both PHOTO_URI and PHOTO_THUMBNAIL_URI in Cp2Info. Bug: 73007132 Test: NumberAttributesConverterTest, PhoneLookupInfoConsolidatorTest PiperOrigin-RevId: 185545712 Change-Id: I228d8c4e1b6327e38057f73aad63bb7048704d49 --- .../phonelookup/PhoneLookupDataSource.java | 20 +--------- .../dialer/calllog/ui/RealtimeRowProcessor.java | 20 +--------- .../calllogutils/NumberAttributesConverter.java | 26 ++++++++++++- .../consolidator/PhoneLookupInfoConsolidator.java | 22 +++++++++++ .../dialer/phonelookup/cp2/Cp2Projections.java | 45 +++++++++++++--------- .../dialer/phonelookup/phone_lookup_info.proto | 17 +++++--- 6 files changed, 89 insertions(+), 61 deletions(-) diff --git a/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java b/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java index 52570c05e..8dec43759 100644 --- a/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java +++ b/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java @@ -28,18 +28,17 @@ import android.text.TextUtils; import android.util.ArrayMap; import android.util.ArraySet; import com.android.dialer.DialerPhoneNumber; -import com.android.dialer.NumberAttributes; import com.android.dialer.calllog.database.contract.AnnotatedCallLogContract.AnnotatedCallLog; import com.android.dialer.calllog.datasources.CallLogDataSource; import com.android.dialer.calllog.datasources.CallLogMutations; import com.android.dialer.calllog.datasources.util.RowCombiner; +import com.android.dialer.calllogutils.NumberAttributesConverter; 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.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.google.common.collect.ImmutableMap; @@ -573,23 +572,8 @@ public final class PhoneLookupDataSource } private void updateContentValues(ContentValues contentValues, PhoneLookupInfo phoneLookupInfo) { - PhoneLookupInfoConsolidator phoneLookupInfoConsolidator = - new PhoneLookupInfoConsolidator(phoneLookupInfo); contentValues.put( AnnotatedCallLog.NUMBER_ATTRIBUTES, - NumberAttributes.newBuilder() - .setName(phoneLookupInfoConsolidator.getName()) - .setPhotoUri(phoneLookupInfoConsolidator.getPhotoUri()) - .setPhotoId(phoneLookupInfoConsolidator.getPhotoId()) - .setLookupUri(phoneLookupInfoConsolidator.getLookupUri()) - .setNumberTypeLabel(phoneLookupInfoConsolidator.getNumberLabel()) - .setIsBusiness(phoneLookupInfoConsolidator.isBusiness()) - .setIsVoicemail(phoneLookupInfoConsolidator.isVoicemail()) - .setIsBlocked(phoneLookupInfoConsolidator.isBlocked()) - .setIsSpam(phoneLookupInfoConsolidator.isSpam()) - .setCanReportAsInvalidNumber(phoneLookupInfoConsolidator.canReportAsInvalidNumber()) - .setIsCp2InfoIncomplete(phoneLookupInfoConsolidator.isCp2LocalInfoIncomplete()) - .build() - .toByteArray()); + NumberAttributesConverter.fromPhoneLookupInfo(phoneLookupInfo).build().toByteArray()); } } diff --git a/java/com/android/dialer/calllog/ui/RealtimeRowProcessor.java b/java/com/android/dialer/calllog/ui/RealtimeRowProcessor.java index 5083a95c5..69c431953 100644 --- a/java/com/android/dialer/calllog/ui/RealtimeRowProcessor.java +++ b/java/com/android/dialer/calllog/ui/RealtimeRowProcessor.java @@ -23,8 +23,8 @@ import android.support.annotation.MainThread; import android.support.annotation.VisibleForTesting; import android.util.ArrayMap; import com.android.dialer.DialerPhoneNumber; -import com.android.dialer.NumberAttributes; import com.android.dialer.calllog.model.CoalescedRow; +import com.android.dialer.calllogutils.NumberAttributesConverter; import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; import com.android.dialer.common.concurrent.Annotations.BackgroundExecutor; @@ -33,7 +33,6 @@ import com.android.dialer.common.concurrent.ThreadUtil; 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.google.common.collect.ImmutableMap; @@ -198,23 +197,8 @@ public final class RealtimeRowProcessor { private CoalescedRow applyPhoneLookupInfoToRow( PhoneLookupInfo phoneLookupInfo, CoalescedRow row) { - PhoneLookupInfoConsolidator phoneLookupInfoConsolidator = - new PhoneLookupInfoConsolidator(phoneLookupInfo); return row.toBuilder() - .setNumberAttributes( - // TODO(zachh): Put this in a common location. - NumberAttributes.newBuilder() - .setName(phoneLookupInfoConsolidator.getName()) - .setPhotoUri(phoneLookupInfoConsolidator.getPhotoUri()) - .setPhotoId(phoneLookupInfoConsolidator.getPhotoId()) - .setLookupUri(phoneLookupInfoConsolidator.getLookupUri()) - .setNumberTypeLabel(phoneLookupInfoConsolidator.getNumberLabel()) - .setIsBusiness(phoneLookupInfoConsolidator.isBusiness()) - .setIsVoicemail(phoneLookupInfoConsolidator.isVoicemail()) - .setIsBlocked(phoneLookupInfoConsolidator.isBlocked()) - .setIsSpam(phoneLookupInfoConsolidator.isSpam()) - .setCanReportAsInvalidNumber(phoneLookupInfoConsolidator.canReportAsInvalidNumber()) - .build()) + .setNumberAttributes(NumberAttributesConverter.fromPhoneLookupInfo(phoneLookupInfo).build()) .build(); } } diff --git a/java/com/android/dialer/calllogutils/NumberAttributesConverter.java b/java/com/android/dialer/calllogutils/NumberAttributesConverter.java index bed1edd06..efd1d72c2 100644 --- a/java/com/android/dialer/calllogutils/NumberAttributesConverter.java +++ b/java/com/android/dialer/calllogutils/NumberAttributesConverter.java @@ -16,13 +16,16 @@ package com.android.dialer.calllogutils; +import android.text.TextUtils; import com.android.dialer.NumberAttributes; import com.android.dialer.glidephotomanager.PhotoInfo; +import com.android.dialer.phonelookup.PhoneLookupInfo; +import com.android.dialer.phonelookup.consolidator.PhoneLookupInfoConsolidator; /** Converts {@link NumberAttributes} to {@link PhotoInfo} */ public final class NumberAttributesConverter { - /** Converts to {@link PhotoInfo.Builder} */ + /** Converts {@link NumberAttributes} to {@link PhotoInfo.Builder} */ public static PhotoInfo.Builder toPhotoInfoBuilder(NumberAttributes numberAttributes) { return PhotoInfo.builder() .setName(numberAttributes.getName()) @@ -34,4 +37,25 @@ public final class NumberAttributesConverter { .setIsVoicemail(numberAttributes.getIsVoicemail()) .setIsBlocked(numberAttributes.getIsBlocked()); } + + /** Converts {@link PhoneLookupInfo} to {@link NumberAttributes.Builder} */ + public static NumberAttributes.Builder fromPhoneLookupInfo(PhoneLookupInfo phoneLookupInfo) { + PhoneLookupInfoConsolidator phoneLookupInfoConsolidator = + new PhoneLookupInfoConsolidator(phoneLookupInfo); + return NumberAttributes.newBuilder() + .setName(phoneLookupInfoConsolidator.getName()) + .setPhotoUri( + !TextUtils.isEmpty(phoneLookupInfoConsolidator.getPhotoThumbnailUri()) + ? phoneLookupInfoConsolidator.getPhotoThumbnailUri() + : phoneLookupInfoConsolidator.getPhotoUri()) + .setPhotoId(phoneLookupInfoConsolidator.getPhotoId()) + .setLookupUri(phoneLookupInfoConsolidator.getLookupUri()) + .setNumberTypeLabel(phoneLookupInfoConsolidator.getNumberLabel()) + .setIsBusiness(phoneLookupInfoConsolidator.isBusiness()) + .setIsVoicemail(phoneLookupInfoConsolidator.isVoicemail()) + .setIsBlocked(phoneLookupInfoConsolidator.isBlocked()) + .setIsSpam(phoneLookupInfoConsolidator.isSpam()) + .setCanReportAsInvalidNumber(phoneLookupInfoConsolidator.canReportAsInvalidNumber()) + .setIsCp2InfoIncomplete(phoneLookupInfoConsolidator.isCp2LocalInfoIncomplete()); + } } diff --git a/java/com/android/dialer/phonelookup/consolidator/PhoneLookupInfoConsolidator.java b/java/com/android/dialer/phonelookup/consolidator/PhoneLookupInfoConsolidator.java index ce4030d70..9c5411081 100644 --- a/java/com/android/dialer/phonelookup/consolidator/PhoneLookupInfoConsolidator.java +++ b/java/com/android/dialer/phonelookup/consolidator/PhoneLookupInfoConsolidator.java @@ -106,6 +106,28 @@ public final class PhoneLookupInfoConsolidator { } } + /** + * The {@link PhoneLookupInfo} passed to the constructor is associated with a number. This method + * returns the photo thumbnail URI associated with that number. + * + *

If no photo thumbnail URI can be obtained from the {@link PhoneLookupInfo}, an empty string + * will be returned. + */ + public String getPhotoThumbnailUri() { + switch (nameSource) { + case NameSource.CP2_LOCAL: + return Assert.isNotNull(firstCp2LocalContact).getPhotoThumbnailUri(); + case NameSource.CP2_REMOTE: + return Assert.isNotNull(firstCp2RemoteContact).getPhotoThumbnailUri(); + case NameSource.PEOPLE_API: + case NameSource.NONE: + return ""; + default: + throw Assert.createUnsupportedOperationFailException( + String.format("Unsupported name source: %s", nameSource)); + } + } + /** * The {@link PhoneLookupInfo} passed to the constructor is associated with a number. This method * returns the photo URI associated with that number. diff --git a/java/com/android/dialer/phonelookup/cp2/Cp2Projections.java b/java/com/android/dialer/phonelookup/cp2/Cp2Projections.java index e3929990e..5a211eddc 100644 --- a/java/com/android/dialer/phonelookup/cp2/Cp2Projections.java +++ b/java/com/android/dialer/phonelookup/cp2/Cp2Projections.java @@ -35,12 +35,13 @@ final class Cp2Projections { new String[] { Phone.DISPLAY_NAME_PRIMARY, // 0 Phone.PHOTO_THUMBNAIL_URI, // 1 - Phone.PHOTO_ID, // 2 - Phone.TYPE, // 3 - Phone.LABEL, // 4 - Phone.NORMALIZED_NUMBER, // 5 - Phone.CONTACT_ID, // 6 - Phone.LOOKUP_KEY // 7 + Phone.PHOTO_URI, // 2 + Phone.PHOTO_ID, // 3 + Phone.TYPE, // 4 + Phone.LABEL, // 5 + Phone.NORMALIZED_NUMBER, // 6 + Phone.CONTACT_ID, // 7 + Phone.LOOKUP_KEY // 8 }; // Projection for performing lookups using the PHONE_LOOKUP table @@ -48,23 +49,25 @@ final class Cp2Projections { new String[] { PhoneLookup.DISPLAY_NAME_PRIMARY, // 0 PhoneLookup.PHOTO_THUMBNAIL_URI, // 1 - PhoneLookup.PHOTO_ID, // 2 - PhoneLookup.TYPE, // 3 - PhoneLookup.LABEL, // 4 - PhoneLookup.NORMALIZED_NUMBER, // 5 - PhoneLookup.CONTACT_ID, // 6 - PhoneLookup.LOOKUP_KEY // 7 + PhoneLookup.PHOTO_URI, // 2 + PhoneLookup.PHOTO_ID, // 3 + PhoneLookup.TYPE, // 4 + PhoneLookup.LABEL, // 5 + PhoneLookup.NORMALIZED_NUMBER, // 6 + PhoneLookup.CONTACT_ID, // 7 + PhoneLookup.LOOKUP_KEY // 8 }; // The following indexes should match both PHONE_PROJECTION and PHONE_LOOKUP_PROJECTION above. private static final int CP2_INFO_NAME_INDEX = 0; - private static final int CP2_INFO_PHOTO_URI_INDEX = 1; - private static final int CP2_INFO_PHOTO_ID_INDEX = 2; - private static final int CP2_INFO_TYPE_INDEX = 3; - private static final int CP2_INFO_LABEL_INDEX = 4; - private static final int CP2_INFO_NORMALIZED_NUMBER_INDEX = 5; - private static final int CP2_INFO_CONTACT_ID_INDEX = 6; - private static final int CP2_INFO_LOOKUP_KEY_INDEX = 7; + private static final int CP2_INFO_PHOTO_THUMBNAIL_URI_INDEX = 1; + private static final int CP2_INFO_PHOTO_URI_INDEX = 2; + private static final int CP2_INFO_PHOTO_ID_INDEX = 3; + private static final int CP2_INFO_TYPE_INDEX = 4; + private static final int CP2_INFO_LABEL_INDEX = 5; + private static final int CP2_INFO_NORMALIZED_NUMBER_INDEX = 6; + private static final int CP2_INFO_CONTACT_ID_INDEX = 7; + private static final int CP2_INFO_LOOKUP_KEY_INDEX = 8; private Cp2Projections() {} @@ -82,6 +85,7 @@ final class Cp2Projections { */ static Cp2ContactInfo buildCp2ContactInfoFromCursor(Context appContext, Cursor cursor) { String displayName = cursor.getString(CP2_INFO_NAME_INDEX); + String photoThumbnailUri = cursor.getString(CP2_INFO_PHOTO_THUMBNAIL_URI_INDEX); String photoUri = cursor.getString(CP2_INFO_PHOTO_URI_INDEX); int photoId = cursor.getInt(CP2_INFO_PHOTO_ID_INDEX); int type = cursor.getInt(CP2_INFO_TYPE_INDEX); @@ -93,6 +97,9 @@ final class Cp2Projections { if (!TextUtils.isEmpty(displayName)) { infoBuilder.setName(displayName); } + if (!TextUtils.isEmpty(photoThumbnailUri)) { + infoBuilder.setPhotoThumbnailUri(photoThumbnailUri); + } if (!TextUtils.isEmpty(photoUri)) { infoBuilder.setPhotoUri(photoUri); } diff --git a/java/com/android/dialer/phonelookup/phone_lookup_info.proto b/java/com/android/dialer/phonelookup/phone_lookup_info.proto index e9cb9f8ad..dd6bf664c 100644 --- a/java/com/android/dialer/phonelookup/phone_lookup_info.proto +++ b/java/com/android/dialer/phonelookup/phone_lookup_info.proto @@ -19,6 +19,7 @@ message PhoneLookupInfo { message Cp2Info { // Information about a single contact, which can be a local contact or a // remote one. + // Next ID: 8 message Cp2ContactInfo { // For a local contact: // android.provider.ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME_PRIMARY @@ -30,13 +31,19 @@ message PhoneLookupInfo { // android.provider.ContactsContract.CommonDataKinds.Phone.PHOTO_THUMBNAIL_URI // For a remote contact: // android.provider.ContactsContract.PhoneLookup.PHOTO_THUMBNAIL_URI - optional string photo_uri = 2; + optional string photo_thumbnail_uri = 2; + + // For a local contact: + // android.provider.ContactsContract.CommonDataKinds.Phone.PHOTO_URI + // For a remote contact: + // android.provider.ContactsContract.PhoneLookup.PHOTO_URI + optional string photo_uri = 3; // For a local contact: // android.provider.ContactsContract.CommonDataKinds.Phone.PHOTO_ID // For a remote contact: // android.provider.ContactsContract.PhoneLookup.PHOTO_ID - optional fixed64 photo_id = 3; + optional fixed64 photo_id = 4; // For a local contact: // android.provider.ContactsContract.CommonDataKinds.Phone.LABEL @@ -44,13 +51,13 @@ message PhoneLookupInfo { // android.provider.ContactsContract.PhoneLookup.LABEL // // The value can be "Home", "Mobile", ect. - optional string label = 4; + optional string label = 5; // For a local contact: // android.provider.ContactsContract.CommonDataKinds.Phone.CONTACT_ID // For a remote contact: // android.provider.ContactsContract.PhoneLookup.CONTACT_ID - optional fixed64 contact_id = 5; + optional fixed64 contact_id = 6; // For a local contact: // constructed based on @@ -58,7 +65,7 @@ message PhoneLookupInfo { // For a remote contact: // constructed based on // android.provider.ContactsContract.PhoneLookup.LOOKUP_KEY - optional string lookup_uri = 6; + optional string lookup_uri = 7; } // Repeated because one phone number can be associated with multiple CP2 // contacts. -- cgit v1.2.3