From 3bf84127cd907af57524cce9db4ad02455cd0495 Mon Sep 17 00:00:00 2001 From: linyuh Date: Sun, 8 Apr 2018 23:28:26 -0700 Subject: Have PhoneLookup read carrier presence data from CP2. Bug: 70988687 Test: Cp2DefaultDirectoryPhoneLookupTest, PhoneLookupInfoConsolidatorTest PiperOrigin-RevId: 192085574 Change-Id: I4512c9e2e9e14340fa3aa9b2d7d6aaea6344bba6 --- .../consolidator/PhoneLookupInfoConsolidator.java | 18 ++++++++++++++++++ .../android/dialer/phonelookup/cp2/Cp2Projections.java | 16 ++++++++++++++-- .../android/dialer/phonelookup/phone_lookup_info.proto | 11 ++++++++++- 3 files changed, 42 insertions(+), 3 deletions(-) (limited to 'java') diff --git a/java/com/android/dialer/phonelookup/consolidator/PhoneLookupInfoConsolidator.java b/java/com/android/dialer/phonelookup/consolidator/PhoneLookupInfoConsolidator.java index 4b994e725..c3824dc49 100644 --- a/java/com/android/dialer/phonelookup/consolidator/PhoneLookupInfoConsolidator.java +++ b/java/com/android/dialer/phonelookup/consolidator/PhoneLookupInfoConsolidator.java @@ -321,6 +321,24 @@ public final class PhoneLookupInfoConsolidator { } } + /** + * The {@link PhoneLookupInfo} passed to the constructor is associated with a number. This method + * returns whether the number can be reached via carrier video calls. + */ + public boolean canSupportCarrierVideoCall() { + switch (nameSource) { + case NameSource.CP2_DEFAULT_DIRECTORY: + return Assert.isNotNull(firstDefaultCp2Contact).getCanSupportCarrierVideoCall(); + case NameSource.CP2_EXTENDED_DIRECTORY: + case NameSource.PEOPLE_API: + case NameSource.NONE: + return false; + default: + throw Assert.createUnsupportedOperationFailException( + String.format("Unsupported name source: %s", nameSource)); + } + } + /** * Arbitrarily select the first CP2 contact in the default directory. In the future, it may make * sense to display contact information from all contacts with the same number (for example show diff --git a/java/com/android/dialer/phonelookup/cp2/Cp2Projections.java b/java/com/android/dialer/phonelookup/cp2/Cp2Projections.java index 5a211eddc..377091264 100644 --- a/java/com/android/dialer/phonelookup/cp2/Cp2Projections.java +++ b/java/com/android/dialer/phonelookup/cp2/Cp2Projections.java @@ -41,7 +41,8 @@ final class Cp2Projections { Phone.LABEL, // 5 Phone.NORMALIZED_NUMBER, // 6 Phone.CONTACT_ID, // 7 - Phone.LOOKUP_KEY // 8 + Phone.LOOKUP_KEY, // 8 + Phone.CARRIER_PRESENCE }; // Projection for performing lookups using the PHONE_LOOKUP table @@ -58,7 +59,8 @@ final class Cp2Projections { PhoneLookup.LOOKUP_KEY // 8 }; - // The following indexes should match both PHONE_PROJECTION and PHONE_LOOKUP_PROJECTION above. + // The following indexes should match the common columns in + // PHONE_PROJECTION and PHONE_LOOKUP_PROJECTION above. private static final int CP2_INFO_NAME_INDEX = 0; private static final int CP2_INFO_PHOTO_THUMBNAIL_URI_INDEX = 1; private static final int CP2_INFO_PHOTO_URI_INDEX = 2; @@ -116,6 +118,16 @@ final class Cp2Projections { if (!TextUtils.isEmpty(lookupKey)) { infoBuilder.setLookupUri(Contacts.getLookupUri(contactId, lookupKey).toString()); } + + // Only PHONE_PROJECTION has a column containing carrier presence info. + int carrierPresenceColumn = cursor.getColumnIndex(Phone.CARRIER_PRESENCE); + if (carrierPresenceColumn != -1) { + int carrierPresenceInfo = cursor.getInt(carrierPresenceColumn); + infoBuilder.setCanSupportCarrierVideoCall( + (carrierPresenceInfo & Phone.CARRIER_PRESENCE_VT_CAPABLE) + == Phone.CARRIER_PRESENCE_VT_CAPABLE); + } + return infoBuilder.build(); } diff --git a/java/com/android/dialer/phonelookup/phone_lookup_info.proto b/java/com/android/dialer/phonelookup/phone_lookup_info.proto index 5fa33d4d4..96121885f 100644 --- a/java/com/android/dialer/phonelookup/phone_lookup_info.proto +++ b/java/com/android/dialer/phonelookup/phone_lookup_info.proto @@ -18,7 +18,7 @@ message PhoneLookupInfo { // Information about a PhoneNumber retrieved from CP2. message Cp2Info { // Information about a single contact. - // Next ID: 8 + // Next ID: 9 message Cp2ContactInfo { // For a contact in the default directory: // android.provider.ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME_PRIMARY @@ -65,6 +65,15 @@ message PhoneLookupInfo { // constructed based on // android.provider.ContactsContract.PhoneLookup.LOOKUP_KEY optional string lookup_uri = 7; + + // For a contact in the default directory: + // value set based on + // android.provider.ContactsContract.CommonDataKinds.Phone.CARRIER_PRESENCE + // For a contact in other directories: always false. + // This is because we lookup contacts in other directories via + // android.provider.ContactsContract.PhoneLookup, to which carrier + // presence info is not directly accessible. + optional bool can_support_carrier_video_call = 8; } // Repeated because one phone number can be associated with multiple CP2 // contacts. -- cgit v1.2.3