Merge "Group blocked calls separately in call log." into ub-contactsdialer-a-dev
diff --git a/src/com/android/dialer/calllog/CallLogGroupBuilder.java b/src/com/android/dialer/calllog/CallLogGroupBuilder.java
index 4cf2d07..5eea096 100644
--- a/src/com/android/dialer/calllog/CallLogGroupBuilder.java
+++ b/src/com/android/dialer/calllog/CallLogGroupBuilder.java
@@ -24,6 +24,7 @@
 
 import com.android.contacts.common.util.DateUtils;
 import com.android.contacts.common.util.PhoneNumberHelper;
+import com.android.dialer.util.AppCompatConstants;
 
 import com.google.common.annotations.VisibleForTesting;
 
@@ -145,10 +146,11 @@
             final boolean isSameAccount = isSameAccount(
                     groupAccountComponentName, accountComponentName, groupAccountId, accountId);
 
-            // Group with the same number and account which are not voicemail.
-            if (isSameNumber && isSameAccount
-                    && (callType != Calls.VOICEMAIL_TYPE)
-                    && (groupCallType != Calls.VOICEMAIL_TYPE)) {
+            // Group with the same number and account. Never group voicemails. Only group blocked
+            // calls with other blocked calls.
+            if (isSameNumber && isSameAccount && areBothNotVoicemail(callType, groupCallType)
+                    && (areBothNotBlocked(callType, groupCallType)
+                            || areBothBlocked(callType, groupCallType))) {
                 // Increment the size of the group to include the current call, but do not create
                 // the group until finding a call that does not match.
                 groupSize++;
@@ -240,4 +242,19 @@
             return DAY_GROUP_OTHER;
         }
     }
+
+    private boolean areBothNotVoicemail(int callType, int groupCallType) {
+        return callType != AppCompatConstants.CALLS_VOICEMAIL_TYPE
+                && groupCallType != AppCompatConstants.CALLS_VOICEMAIL_TYPE;
+    }
+
+    private boolean areBothNotBlocked(int callType, int groupCallType) {
+        return callType != AppCompatConstants.CALLS_BLOCKED_TYPE
+                && groupCallType != AppCompatConstants.CALLS_BLOCKED_TYPE;
+    }
+
+    private boolean areBothBlocked(int callType, int groupCallType) {
+        return callType == AppCompatConstants.CALLS_BLOCKED_TYPE
+                && groupCallType == AppCompatConstants.CALLS_BLOCKED_TYPE;
+    }
 }
diff --git a/tests/src/com/android/dialer/calllog/CallLogGroupBuilderTest.java b/tests/src/com/android/dialer/calllog/CallLogGroupBuilderTest.java
index f5a9fe6..5d0b6be 100644
--- a/tests/src/com/android/dialer/calllog/CallLogGroupBuilderTest.java
+++ b/tests/src/com/android/dialer/calllog/CallLogGroupBuilderTest.java
@@ -95,7 +95,7 @@
         assertGroupIs(0, 3, mFakeGroupCreator.groups.get(0));
     }
 
-    public void testAddGroups_Voicemail() {
+    public void testGrouping_Voicemail() {
         // Does not group with other types of calls, include voicemail themselves.
         assertCallsAreNotGrouped(
                 AppCompatConstants.CALLS_VOICEMAIL_TYPE, AppCompatConstants.CALLS_MISSED_TYPE);
@@ -107,7 +107,7 @@
                 AppCompatConstants.CALLS_VOICEMAIL_TYPE, AppCompatConstants.CALLS_OUTGOING_TYPE);
     }
 
-    public void testAddGroups_Missed() {
+    public void testGrouping_Missed() {
         // Groups with one or more missed calls.
         assertCallsAreGrouped(
                 AppCompatConstants.CALLS_MISSED_TYPE, AppCompatConstants.CALLS_MISSED_TYPE);
@@ -124,7 +124,7 @@
                 AppCompatConstants.CALLS_MISSED_TYPE, AppCompatConstants.CALLS_OUTGOING_TYPE);
     }
 
-    public void testAddGroups_Incoming() {
+    public void testGrouping_Incoming() {
         // Groups with one or more incoming or outgoing.
         assertCallsAreGrouped(
                 AppCompatConstants.CALLS_INCOMING_TYPE, AppCompatConstants.CALLS_INCOMING_TYPE);
@@ -145,7 +145,7 @@
                 AppCompatConstants.CALLS_INCOMING_TYPE, AppCompatConstants.CALLS_VOICEMAIL_TYPE);
     }
 
-    public void testAddGroups_Outgoing() {
+    public void testGrouping_Outgoing() {
         // Groups with one or more incoming or outgoing.
         assertCallsAreGrouped(
                 AppCompatConstants.CALLS_OUTGOING_TYPE, AppCompatConstants.CALLS_INCOMING_TYPE);
@@ -166,20 +166,31 @@
                 AppCompatConstants.CALLS_INCOMING_TYPE, AppCompatConstants.CALLS_VOICEMAIL_TYPE);
     }
 
+    public void testGrouping_Blocked() {
+        assertCallsAreNotGrouped(
+                AppCompatConstants.CALLS_BLOCKED_TYPE, AppCompatConstants.CALLS_INCOMING_TYPE);
+        assertCallsAreNotGrouped(
+                AppCompatConstants.CALLS_BLOCKED_TYPE, AppCompatConstants.CALLS_OUTGOING_TYPE);
+        assertCallsAreNotGrouped(
+                AppCompatConstants.CALLS_BLOCKED_TYPE, AppCompatConstants.CALLS_MISSED_TYPE);
+
+    }
+
     public void testAddGroups_Mixed() {
         addMultipleCallLogEntries(TEST_NUMBER1,
-                AppCompatConstants.CALLS_VOICEMAIL_TYPE,   // Group 1:Stand-alone
+                AppCompatConstants.CALLS_VOICEMAIL_TYPE,   // Group 1: 0
                 AppCompatConstants.CALLS_INCOMING_TYPE,    // Group 2: 1-4
                 AppCompatConstants.CALLS_OUTGOING_TYPE,
                 AppCompatConstants.CALLS_MISSED_TYPE,
                 AppCompatConstants.CALLS_MISSED_TYPE,
-                AppCompatConstants.CALLS_VOICEMAIL_TYPE,   // Group 3: Stand-alone
-                AppCompatConstants.CALLS_INCOMING_TYPE,    // Group 4: Stand-alone
-                AppCompatConstants.CALLS_VOICEMAIL_TYPE,   // Group 5: Stand-alone
+                AppCompatConstants.CALLS_VOICEMAIL_TYPE,   // Group 3: 5
+                AppCompatConstants.CALLS_INCOMING_TYPE,    // Group 4: 6
+                AppCompatConstants.CALLS_VOICEMAIL_TYPE,   // Group 5: 7
                 AppCompatConstants.CALLS_MISSED_TYPE,      // Group 6: 8-10
                 AppCompatConstants.CALLS_MISSED_TYPE,
                 AppCompatConstants.CALLS_OUTGOING_TYPE);
         mBuilder.addGroups(mCursor);
+
         assertEquals(6, mFakeGroupCreator.groups.size());
         assertGroupIs(0, 1, mFakeGroupCreator.groups.get(0));
         assertGroupIs(1, 4, mFakeGroupCreator.groups.get(1));
@@ -189,6 +200,23 @@
         assertGroupIs(8, 3, mFakeGroupCreator.groups.get(5));
     }
 
+    public void testAddGroups_Blocked() {
+        addMultipleCallLogEntries(TEST_NUMBER1,
+                AppCompatConstants.CALLS_INCOMING_TYPE,     // Group 1: 0-1
+                AppCompatConstants.CALLS_OUTGOING_TYPE,
+                AppCompatConstants.CALLS_BLOCKED_TYPE,      // Group 2: 2
+                AppCompatConstants.CALLS_MISSED_TYPE,       // Group 3: 3
+                AppCompatConstants.CALLS_BLOCKED_TYPE,      // Group 4: 4-5
+                AppCompatConstants.CALLS_BLOCKED_TYPE);
+        mBuilder.addGroups(mCursor);
+
+        assertEquals(4, mFakeGroupCreator.groups.size());
+        assertGroupIs(0, 2, mFakeGroupCreator.groups.get(0));
+        assertGroupIs(2, 1, mFakeGroupCreator.groups.get(1));
+        assertGroupIs(3, 1, mFakeGroupCreator.groups.get(2));
+        assertGroupIs(4, 2, mFakeGroupCreator.groups.get(3));
+    }
+
     public void testEqualPhoneNumbers() {
         // Identical.
         assertTrue(mBuilder.equalNumbers("6505555555", "6505555555"));