Merge "Use CONTENT_URI_WITH_VOICEMAIL for SystemCallLogDataSource"
am: 5fb96c9646

Change-Id: I79f55ac7c3eefccbdd9334e53185d7ed82978115
diff --git a/java/com/android/dialer/calllog/database/AnnotatedCallLogContentProvider.java b/java/com/android/dialer/calllog/database/AnnotatedCallLogContentProvider.java
index 9a3d2e2..39a8065 100644
--- a/java/com/android/dialer/calllog/database/AnnotatedCallLogContentProvider.java
+++ b/java/com/android/dialer/calllog/database/AnnotatedCallLogContentProvider.java
@@ -29,6 +29,7 @@
 import android.database.sqlite.SQLiteQueryBuilder;
 import android.net.Uri;
 import android.os.Build;
+import android.provider.CallLog.Calls;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import com.android.dialer.calllog.database.contract.AnnotatedCallLogContract;
@@ -121,7 +122,13 @@
         Assert.checkArgument(sortOrder == null, "sort order not supported for coalesced call log");
         try (Cursor allAnnotatedCallLogRows =
             queryBuilder.query(
-                db, null, null, null, null, null, AnnotatedCallLog.TIMESTAMP + " DESC")) {
+                db,
+                null,
+                String.format("%s != ?", CoalescedAnnotatedCallLog.CALL_TYPE),
+                new String[] {Integer.toString(Calls.VOICEMAIL_TYPE)},
+                null,
+                null,
+                AnnotatedCallLog.TIMESTAMP + " DESC")) {
           Cursor coalescedRows = coalescer.coalesce(allAnnotatedCallLogRows);
           coalescedRows.setNotificationUri(
               getContext().getContentResolver(), CoalescedAnnotatedCallLog.CONTENT_URI);
diff --git a/java/com/android/dialer/calllog/datasources/systemcalllog/SystemCallLogDataSource.java b/java/com/android/dialer/calllog/datasources/systemcalllog/SystemCallLogDataSource.java
index 0a965f6..681a86d 100644
--- a/java/com/android/dialer/calllog/datasources/systemcalllog/SystemCallLogDataSource.java
+++ b/java/com/android/dialer/calllog/datasources/systemcalllog/SystemCallLogDataSource.java
@@ -88,7 +88,7 @@
     appContext
         .getContentResolver()
         .registerContentObserver(
-            CallLog.Calls.CONTENT_URI,
+            CallLog.Calls.CONTENT_URI_WITH_VOICEMAIL,
             true,
             new CallLogObserver(
                 ThreadUtil.getUiThreadHandler(), appContext, contentObserverCallbacks));
@@ -152,6 +152,9 @@
   @Override
   public ContentValues coalesce(List<ContentValues> individualRowsSortedByTimestampDesc) {
     // TODO(zachh): Complete implementation.
+
+    assertNoVoicemailsInRows(individualRowsSortedByTimestampDesc);
+
     return new RowCombiner(individualRowsSortedByTimestampDesc)
         .useMostRecentLong(AnnotatedCallLog.TIMESTAMP)
         .useMostRecentLong(AnnotatedCallLog.NEW)
@@ -174,6 +177,15 @@
         .combine();
   }
 
+  private void assertNoVoicemailsInRows(List<ContentValues> individualRowsSortedByTimestampDesc) {
+    for (ContentValues contentValue : individualRowsSortedByTimestampDesc) {
+      if (contentValue.getAsLong(AnnotatedCallLog.CALL_TYPE) != null) {
+        Assert.checkArgument(
+            contentValue.getAsLong(AnnotatedCallLog.CALL_TYPE) != Calls.VOICEMAIL_TYPE);
+      }
+    }
+  }
+
   @TargetApi(Build.VERSION_CODES.M) // Uses try-with-resources
   private void handleInsertsAndUpdates(
       Context appContext, CallLogMutations mutations, Set<Long> existingAnnotatedCallLogIds) {
@@ -189,7 +201,7 @@
         appContext
             .getContentResolver()
             .query(
-                Calls.CONTENT_URI, // Excludes voicemail
+                Calls.CONTENT_URI_WITH_VOICEMAIL,
                 new String[] {
                   Calls._ID,
                   Calls.DATE,
@@ -414,7 +426,12 @@
     try (Cursor cursor =
         appContext
             .getContentResolver()
-            .query(Calls.CONTENT_URI, new String[] {Calls._ID}, whereClause, whereArgs, null)) {
+            .query(
+                Calls.CONTENT_URI_WITH_VOICEMAIL,
+                new String[] {Calls._ID},
+                whereClause,
+                whereArgs,
+                null)) {
 
       if (cursor == null) {
         LogUtil.e("SystemCallLogDataSource.getIdsFromSystemCallLog", "null cursor");