diff options
Diffstat (limited to 'java/com/android/dialer/calllog/database')
-rw-r--r-- | java/com/android/dialer/calllog/database/Coalescer.java | 31 | ||||
-rw-r--r-- | java/com/android/dialer/calllog/database/contract/AnnotatedCallLogContract.java | 9 |
2 files changed, 31 insertions, 9 deletions
diff --git a/java/com/android/dialer/calllog/database/Coalescer.java b/java/com/android/dialer/calllog/database/Coalescer.java index a8a8f2f1d..71052b907 100644 --- a/java/com/android/dialer/calllog/database/Coalescer.java +++ b/java/com/android/dialer/calllog/database/Coalescer.java @@ -21,6 +21,7 @@ import android.database.MatrixCursor; import android.support.annotation.NonNull; import android.support.annotation.WorkerThread; import android.telecom.PhoneAccountHandle; +import com.android.dialer.CoalescedIds; import com.android.dialer.DialerPhoneNumber; import com.android.dialer.calllog.database.contract.AnnotatedCallLogContract.AnnotatedCallLog; import com.android.dialer.calllog.database.contract.AnnotatedCallLogContract.CoalescedAnnotatedCallLog; @@ -29,6 +30,7 @@ import com.android.dialer.calllog.datasources.DataSources; import com.android.dialer.calllogutils.PhoneAccountUtils; import com.android.dialer.common.Assert; import com.android.dialer.phonenumberproto.DialerPhoneNumberUtil; +import com.google.common.base.Preconditions; import com.google.i18n.phonenumbers.PhoneNumberUtil; import com.google.protobuf.InvalidProtocolBufferException; import java.util.ArrayList; @@ -40,11 +42,10 @@ import javax.inject.Inject; /** * Coalesces call log rows by combining some adjacent rows. * - * <p>Applies the business which logic which determines which adjacent rows should be coalasced, and - * then delegates to each data source to determine how individual columns should be aggregated. + * <p>Applies the logic that determines which adjacent rows should be coalesced, and then delegates + * to each data source to determine how individual columns should be aggregated. */ public class Coalescer { - private final DataSources dataSources; @Inject @@ -96,7 +97,9 @@ public class Coalescer { if (!rowsShouldBeCombined(dialerPhoneNumberUtil, previousRow, currentRow)) { ContentValues coalescedRow = coalesceRowsForAllDataSources(currentRowGroup); - coalescedRow.put(CoalescedAnnotatedCallLog.NUMBER_CALLS, currentRowGroup.size()); + coalescedRow.put( + CoalescedAnnotatedCallLog.COALESCED_IDS, + getCoalescedIds(currentRowGroup).toByteArray()); addContentValuesToMatrixCursor( coalescedRow, allCoalescedRowsMatrixCursor, coalescedRowId++); currentRowGroup.clear(); @@ -106,7 +109,8 @@ public class Coalescer { // Deal with leftover rows. ContentValues coalescedRow = coalesceRowsForAllDataSources(currentRowGroup); - coalescedRow.put(CoalescedAnnotatedCallLog.NUMBER_CALLS, currentRowGroup.size()); + coalescedRow.put( + CoalescedAnnotatedCallLog.COALESCED_IDS, getCoalescedIds(currentRowGroup).toByteArray()); addContentValuesToMatrixCursor(coalescedRow, allCoalescedRowsMatrixCursor, coalescedRowId); } return allCoalescedRowsMatrixCursor; @@ -185,6 +189,23 @@ public class Coalescer { } /** + * Build a {@link CoalescedIds} proto that contains IDs of the rows in {@link AnnotatedCallLog} + * that are coalesced into one row in {@link CoalescedAnnotatedCallLog}. + * + * @param individualRows {@link AnnotatedCallLog} rows sorted by timestamp descending + * @return A {@link CoalescedIds} proto containing IDs of {@code individualRows}. + */ + private CoalescedIds getCoalescedIds(List<ContentValues> individualRows) { + CoalescedIds.Builder coalescedIds = CoalescedIds.newBuilder(); + + for (ContentValues row : individualRows) { + coalescedIds.addCoalescedId(Preconditions.checkNotNull(row.getAsLong(AnnotatedCallLog._ID))); + } + + return coalescedIds.build(); + } + + /** * @param contentValues a {@link CoalescedAnnotatedCallLog} row * @param matrixCursor represents {@link CoalescedAnnotatedCallLog} */ diff --git a/java/com/android/dialer/calllog/database/contract/AnnotatedCallLogContract.java b/java/com/android/dialer/calllog/database/contract/AnnotatedCallLogContract.java index 9efe21487..c9c053cea 100644 --- a/java/com/android/dialer/calllog/database/contract/AnnotatedCallLogContract.java +++ b/java/com/android/dialer/calllog/database/contract/AnnotatedCallLogContract.java @@ -274,17 +274,18 @@ public class AnnotatedCallLogContract { "vnd.android.cursor.item/coalesced_annotated_call_log"; /** - * Number of AnnotatedCallLog rows represented by this CoalescedAnnotatedCallLog row. + * IDs of rows in {@link AnnotatedCallLog} that are coalesced into one row in {@link + * CoalescedAnnotatedCallLog}, encoded as a {@link com.android.dialer.CoalescedIds} proto. * - * <p>Type: INTEGER + * <p>Type: BLOB */ - public static final String NUMBER_CALLS = "number_calls"; + public static final String COALESCED_IDS = "coalesced_ids"; /** * Columns that are only in the {@link CoalescedAnnotatedCallLog} but not the {@link * AnnotatedCallLog}. */ - private static final String[] COLUMNS_ONLY_IN_COALESCED_CALL_LOG = new String[] {NUMBER_CALLS}; + private static final String[] COLUMNS_ONLY_IN_COALESCED_CALL_LOG = new String[] {COALESCED_IDS}; /** All columns in the {@link CoalescedAnnotatedCallLog}. */ public static final String[] ALL_COLUMNS = |