Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d5797db4 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Show group counts for groups in bundles" into main

parents 60025d4d c08d0810
Loading
Loading
Loading
Loading
+27 −14
Original line number Diff line number Diff line
@@ -19,9 +19,10 @@ package com.android.systemui.statusbar.notification.collection.render
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.statusbar.notification.collection.BundleEntry
import com.android.systemui.statusbar.notification.collection.GroupEntry
import com.android.systemui.statusbar.notification.collection.GroupEntryBuilder
import com.android.systemui.statusbar.notification.collection.ListEntry
import com.android.systemui.statusbar.notification.collection.InternalNotificationsApi
import com.android.systemui.statusbar.notification.collection.NotificationEntry
import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder
import com.android.systemui.statusbar.notification.collection.PipelineEntry
@@ -29,6 +30,7 @@ import com.android.systemui.statusbar.notification.collection.ShadeListBuilder
import com.android.systemui.statusbar.notification.collection.listbuilder.OnAfterRenderEntryListener
import com.android.systemui.statusbar.notification.collection.listbuilder.OnAfterRenderGroupListener
import com.android.systemui.statusbar.notification.collection.listbuilder.OnAfterRenderListListener
import com.android.systemui.statusbar.notification.row.data.repository.TEST_BUNDLE_SPEC
import com.android.systemui.util.mockito.withArgCaptor
import org.junit.Before
import org.junit.Test
@@ -41,7 +43,6 @@ import org.mockito.kotlin.spy
import org.mockito.kotlin.times
import org.mockito.kotlin.verify
import org.mockito.kotlin.verifyNoMoreInteractions
import java.nio.channels.Pipe

@SmallTest
@RunWith(AndroidJUnit4::class)
@@ -82,7 +83,7 @@ class RenderStageManagerTest : SysuiTestCase() {
        setUpListeners()

        // WHEN a shade list is built
        onRenderListListener.onRenderList(listWith2Groups8Entries())
        onRenderListListener.onRenderList(listWith3Groups1Bundle10Entries())

        // VERIFY that no listeners are called
        verifyNoMoreInteractions(
@@ -98,7 +99,7 @@ class RenderStageManagerTest : SysuiTestCase() {
        setUpRenderer()

        // WHEN a shade list is built
        onRenderListListener.onRenderList(listWith2Groups8Entries())
        onRenderListListener.onRenderList(listWith3Groups1Bundle10Entries())

        // VERIFY that the renderer is not queried for group or row controllers
        inOrder(spyViewRenderer).apply {
@@ -117,13 +118,13 @@ class RenderStageManagerTest : SysuiTestCase() {
        setUpListeners()

        // WHEN a shade list is built
        onRenderListListener.onRenderList(listWith2Groups8Entries())
        onRenderListListener.onRenderList(listWith3Groups1Bundle10Entries())

        // VERIFY that the renderer is queried once per group/entry
        inOrder(spyViewRenderer).apply {
            verify(spyViewRenderer, times(1)).onRenderList(any())
            verify(spyViewRenderer, times(2)).getGroupController(any())
            verify(spyViewRenderer, times(8)).getRowController(any())
            verify(spyViewRenderer, times(3)).getGroupController(any())
            verify(spyViewRenderer, times(10)).getRowController(any())
            verify(spyViewRenderer, times(1)).onDispatchComplete()
            verifyNoMoreInteractions(spyViewRenderer)
        }
@@ -139,13 +140,13 @@ class RenderStageManagerTest : SysuiTestCase() {
        renderStageManager.addOnAfterRenderEntryListener(mock())

        // WHEN a shade list is built
        onRenderListListener.onRenderList(listWith2Groups8Entries())
        onRenderListListener.onRenderList(listWith3Groups1Bundle10Entries())

        // VERIFY that the renderer is queried once per group/entry
        inOrder(spyViewRenderer).apply {
            verify(spyViewRenderer, times(1)).onRenderList(any())
            verify(spyViewRenderer, times(2)).getGroupController(any())
            verify(spyViewRenderer, times(8)).getRowController(any())
            verify(spyViewRenderer, times(3)).getGroupController(any())
            verify(spyViewRenderer, times(10)).getRowController(any())
            verify(spyViewRenderer, times(1)).onDispatchComplete()
            verifyNoMoreInteractions(spyViewRenderer)
        }
@@ -158,12 +159,12 @@ class RenderStageManagerTest : SysuiTestCase() {
        setUpListeners()

        // WHEN a shade list is built
        onRenderListListener.onRenderList(listWith2Groups8Entries())
        onRenderListListener.onRenderList(listWith3Groups1Bundle10Entries())

        // VERIFY that the listeners are invoked once per group and once per entry
        verify(onAfterRenderListListener, times(1)).onAfterRenderList(any())
        verify(onAfterRenderGroupListener, times(2)).onAfterRenderGroup(any(), any())
        verify(onAfterRenderEntryListener, times(8)).onAfterRenderEntry(any(), any())
        verify(onAfterRenderGroupListener, times(3)).onAfterRenderGroup(any(), any())
        verify(onAfterRenderEntryListener, times(10)).onAfterRenderEntry(any(), any())
        verifyNoMoreInteractions(
            onAfterRenderListListener,
            onAfterRenderGroupListener,
@@ -191,12 +192,13 @@ class RenderStageManagerTest : SysuiTestCase() {
        )
    }

    private fun listWith2Groups8Entries() =
    private fun listWith3Groups1Bundle10Entries() =
        listOf(
            group(notif(1), notif(2), notif(3)),
            notif(4),
            group(notif(5), notif(6), notif(7)),
            notif(8),
            bundle(group(notif(9)), notif(10))
        )

    private class FakeNotifViewRenderer : NotifViewRenderer {
@@ -213,4 +215,15 @@ class RenderStageManagerTest : SysuiTestCase() {

    private fun group(summary: NotificationEntry, vararg children: NotificationEntry): GroupEntry =
        GroupEntryBuilder().setSummary(summary).setChildren(children.toList()).build()

    @OptIn(InternalNotificationsApi::class)
    private fun bundle(group: GroupEntry, vararg children: NotificationEntry) : BundleEntry {
        var bundle = BundleEntry(TEST_BUNDLE_SPEC)
        bundle.addChild(group)
        for (child in children) {
            bundle.addChild(child)
        }

        return bundle
    }
}
+26 −1
Original line number Diff line number Diff line
@@ -100,7 +100,7 @@ class RenderStageManager @Inject constructor() : PipelineDumpable {
            if (onAfterRenderGroupListeners.isEmpty()) {
                return
            }
            entries.asSequence().filterIsInstance<GroupEntry>().forEach { group ->
            entries.forEachGroupEntry { group ->
                val controller = viewRenderer.getGroupController(group)
                onAfterRenderGroupListeners.forEach { listener ->
                    listener.onAfterRenderGroup(group, controller)
@@ -154,4 +154,29 @@ class RenderStageManager @Inject constructor() : PipelineDumpable {
            }
        }
    }

    /**
     * Performs an action on all group entries, even if they are in a bundle
     */
    private inline fun List<PipelineEntry>.forEachGroupEntry(
        action: (GroupEntry) -> Unit
    ) {
        forEach { entry ->
            when (entry) {
                is GroupEntry -> {
                    action(entry)
                }
                is BundleEntry -> {
                    for (bundleChild in entry.children) {
                        if (bundleChild is GroupEntry) {
                            action(bundleChild)
                        }
                    }
                }
                else -> {
                    // Do nothing for leaf nodes
                }
            }
        }
    }
}