From 18e23785eb89a9adfaeb09b636b793921ecdabdd Mon Sep 17 00:00:00 2001 From: linyuh Date: Thu, 4 Jan 2018 13:40:44 -0800 Subject: Add column CAN_REPORT_AS_INVALID_NUMBER to the annotated call log. This column is filled by PhoneLookupDataSource using PhoneLookupInfo#PeopleApiInfo. Bug: 70218437 Test: AnnotatedCallLogDatabaseHelperTest, PhoneLookupDataSourceTest, RowCombinerTest, CoalescedAnnotatedCallLogCursorLoaderTest, PhoneLookupSelectorTest PiperOrigin-RevId: 180839783 Change-Id: I8d5ddb940670724fd4bf6dd6a50dcf408f91da9d --- .../database/AnnotatedCallLogDatabaseHelper.java | 3 ++- .../contract/AnnotatedCallLogContract.java | 10 +++++++++- .../phonelookup/PhoneLookupDataSource.java | 4 ++++ .../calllog/datasources/util/RowCombiner.java | 7 +++++++ .../android/dialer/calllog/model/CoalescedRow.java | 5 +++++ .../ui/CoalescedAnnotatedCallLogCursorLoader.java | 4 +++- .../dialer/phonelookup/PhoneLookupSelector.java | 23 ++++++++++++++++++++++ 7 files changed, 53 insertions(+), 3 deletions(-) (limited to 'java') diff --git a/java/com/android/dialer/calllog/database/AnnotatedCallLogDatabaseHelper.java b/java/com/android/dialer/calllog/database/AnnotatedCallLogDatabaseHelper.java index 8c6d58634..68d4b95df 100644 --- a/java/com/android/dialer/calllog/database/AnnotatedCallLogDatabaseHelper.java +++ b/java/com/android/dialer/calllog/database/AnnotatedCallLogDatabaseHelper.java @@ -59,7 +59,8 @@ class AnnotatedCallLogDatabaseHelper extends SQLiteOpenHelper { + (AnnotatedCallLog.IS_VOICEMAIL + " integer, ") + (AnnotatedCallLog.TRANSCRIPTION + " integer, ") + (AnnotatedCallLog.VOICEMAIL_URI + " text, ") - + (AnnotatedCallLog.CALL_TYPE + " integer") + + (AnnotatedCallLog.CALL_TYPE + " integer, ") + + (AnnotatedCallLog.CAN_REPORT_AS_INVALID_NUMBER + " integer") + ");"; /** Deletes all but the first maxRows rows (by timestamp) to keep the table a manageable size. */ diff --git a/java/com/android/dialer/calllog/database/contract/AnnotatedCallLogContract.java b/java/com/android/dialer/calllog/database/contract/AnnotatedCallLogContract.java index 7071ab5c1..1b3e09095 100644 --- a/java/com/android/dialer/calllog/database/contract/AnnotatedCallLogContract.java +++ b/java/com/android/dialer/calllog/database/contract/AnnotatedCallLogContract.java @@ -178,6 +178,13 @@ public class AnnotatedCallLogContract { */ String CALL_TYPE = "call_type"; + /** + * True if the number can be reported as invalid. + * + *

TYPE: INTEGER (boolean) + */ + String CAN_REPORT_AS_INVALID_NUMBER = "can_report_as_invalid_number"; + String[] ALL_COMMON_COLUMNS = new String[] { _ID, @@ -199,7 +206,8 @@ public class AnnotatedCallLogContract { FEATURES, IS_BUSINESS, IS_VOICEMAIL, - CALL_TYPE + CALL_TYPE, + CAN_REPORT_AS_INVALID_NUMBER }; } diff --git a/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java b/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java index 56e909e84..214862793 100644 --- a/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java +++ b/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java @@ -268,6 +268,7 @@ public final class PhoneLookupDataSource implements CallLogDataSource { .useMostRecentString(AnnotatedCallLog.PHOTO_URI) .useMostRecentLong(AnnotatedCallLog.PHOTO_ID) .useMostRecentString(AnnotatedCallLog.LOOKUP_URI) + .useMostRecentInt(AnnotatedCallLog.CAN_REPORT_AS_INVALID_NUMBER) .combine(); } @@ -564,6 +565,9 @@ public final class PhoneLookupDataSource implements CallLogDataSource { AnnotatedCallLog.LOOKUP_URI, PhoneLookupSelector.selectLookupUri(phoneLookupInfo)); contentValues.put( AnnotatedCallLog.NUMBER_TYPE_LABEL, PhoneLookupSelector.selectNumberLabel(phoneLookupInfo)); + contentValues.put( + AnnotatedCallLog.CAN_REPORT_AS_INVALID_NUMBER, + PhoneLookupSelector.canReportAsInvalidNumber(phoneLookupInfo)); } private static Uri numberUri(String number) { diff --git a/java/com/android/dialer/calllog/datasources/util/RowCombiner.java b/java/com/android/dialer/calllog/datasources/util/RowCombiner.java index ebb1ba665..6e33db51e 100644 --- a/java/com/android/dialer/calllog/datasources/util/RowCombiner.java +++ b/java/com/android/dialer/calllog/datasources/util/RowCombiner.java @@ -31,6 +31,13 @@ public class RowCombiner { this.individualRowsSortedByTimestampDesc = individualRowsSortedByTimestampDesc; } + /** Use the most recent value for the specified column. */ + public RowCombiner useMostRecentInt(String columnName) { + combinedRow.put( + columnName, individualRowsSortedByTimestampDesc.get(0).getAsInteger(columnName)); + return this; + } + /** Use the most recent value for the specified column. */ public RowCombiner useMostRecentLong(String columnName) { combinedRow.put(columnName, individualRowsSortedByTimestampDesc.get(0).getAsLong(columnName)); diff --git a/java/com/android/dialer/calllog/model/CoalescedRow.java b/java/com/android/dialer/calllog/model/CoalescedRow.java index 5cc056872..1824ba146 100644 --- a/java/com/android/dialer/calllog/model/CoalescedRow.java +++ b/java/com/android/dialer/calllog/model/CoalescedRow.java @@ -39,6 +39,7 @@ public abstract class CoalescedRow { .setIsBusiness(false) .setIsVoicemail(false) .setCallType(0) + .setCanReportAsInvalidNumber(false) .setCoalescedIds(CoalescedIds.getDefaultInstance()); } @@ -92,6 +93,8 @@ public abstract class CoalescedRow { public abstract int callType(); + public abstract boolean canReportAsInvalidNumber(); + public abstract CoalescedIds coalescedIds(); /** Builder for {@link CoalescedRow}. */ @@ -139,6 +142,8 @@ public abstract class CoalescedRow { public abstract Builder setCallType(int callType); + public abstract Builder setCanReportAsInvalidNumber(boolean canReportAsInvalidNumber); + public abstract Builder setCoalescedIds(CoalescedIds coalescedIds); public abstract CoalescedRow build(); diff --git a/java/com/android/dialer/calllog/ui/CoalescedAnnotatedCallLogCursorLoader.java b/java/com/android/dialer/calllog/ui/CoalescedAnnotatedCallLogCursorLoader.java index 8aefb1a74..6d60bdda4 100644 --- a/java/com/android/dialer/calllog/ui/CoalescedAnnotatedCallLogCursorLoader.java +++ b/java/com/android/dialer/calllog/ui/CoalescedAnnotatedCallLogCursorLoader.java @@ -49,7 +49,8 @@ final class CoalescedAnnotatedCallLogCursorLoader extends CursorLoader { private static final int IS_BUSINESS = 17; private static final int IS_VOICEMAIL = 18; private static final int CALL_TYPE = 19; - private static final int COALESCED_IDS = 20; + private static final int CAN_REPORT_AS_INVALID_NUMBER = 20; + private static final int COALESCED_IDS = 21; CoalescedAnnotatedCallLogCursorLoader(Context context) { // CoalescedAnnotatedCallLog requires that PROJECTION be ALL_COLUMNS and the following params be @@ -100,6 +101,7 @@ final class CoalescedAnnotatedCallLogCursorLoader extends CursorLoader { .setIsBusiness(cursor.getInt(IS_BUSINESS) == 1) .setIsVoicemail(cursor.getInt(IS_VOICEMAIL) == 1) .setCallType(cursor.getInt(CALL_TYPE)) + .setCanReportAsInvalidNumber(cursor.getInt(CAN_REPORT_AS_INVALID_NUMBER) == 1) .setCoalescedIds(coalescedIds) .build(); } diff --git a/java/com/android/dialer/phonelookup/PhoneLookupSelector.java b/java/com/android/dialer/phonelookup/PhoneLookupSelector.java index 0fe989332..c933af728 100644 --- a/java/com/android/dialer/phonelookup/PhoneLookupSelector.java +++ b/java/com/android/dialer/phonelookup/PhoneLookupSelector.java @@ -18,6 +18,8 @@ package com.android.dialer.phonelookup; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.android.dialer.phonelookup.PhoneLookupInfo.Cp2Info.Cp2ContactInfo; +import com.android.dialer.phonelookup.PhoneLookupInfo.PeopleApiInfo; +import com.android.dialer.phonelookup.PhoneLookupInfo.PeopleApiInfo.InfoType; /** * Prioritizes information from a {@link PhoneLookupInfo}. @@ -106,6 +108,27 @@ public final class PhoneLookupSelector { return ""; } + /** + * Returns true if the number associated with the given {@link PhoneLookupInfo} can be reported as + * invalid. + * + *

As we currently report invalid numbers via the People API, only numbers from the People API + * can be reported as invalid. + */ + public static boolean canReportAsInvalidNumber(PhoneLookupInfo phoneLookupInfo) { + // The presence of Cp2ContactInfo means the number associated with the given PhoneLookupInfo + // matches that of a Cp2 (local) contact, and PeopleApiInfo will not be used to display + // information like name, photo, etc. We should not allow the user to report the number in this + // case as the info displayed is not from the People API. + if (phoneLookupInfo.getCp2Info().getCp2ContactInfoCount() > 0) { + return false; + } + + PeopleApiInfo peopleApiInfo = phoneLookupInfo.getPeopleApiInfo(); + return peopleApiInfo.getInfoType() != InfoType.UNKNOWN + && !peopleApiInfo.getPersonId().isEmpty(); + } + /** * Arbitrarily select the first contact. In the future, it may make sense to display contact * information from all contacts with the same number (for example show the name as "Mom, Dad" or -- cgit v1.2.3