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 --- .../consolidator/PhoneLookupInfoConsolidator.java | 22 +++++++++++ .../dialer/phonelookup/cp2/Cp2Projections.java | 45 +++++++++++++--------- .../dialer/phonelookup/phone_lookup_info.proto | 17 +++++--- 3 files changed, 60 insertions(+), 24 deletions(-) (limited to 'java/com/android/dialer/phonelookup') 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