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

Commit 769529b3 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Convert ENR expansion NotificationEntry usages to EntryAdapter

And in doing so realized we don't actually need a getGroupRoot
method to get parent because the ENRs already have track who their
parent ENR is.

Test: GroupExpansionManagerTest
Test: GroupMembershipManagerTest
Test: StatusBarNotificationPresenterTest
Test: NotificationEntryTest
Test: BundleEntryTest
Test: HeadsUpManagerImplTest
Test: ExpandableNotificationRowTest
Bug: 395857098
Flag: com.android.systemui.notification_bundle_ui
Change-Id: I8d0dd0a37151d0bcc5533b2c2b8eedd790b310ee
parent 973f0b16
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -65,8 +65,8 @@ class BundleEntryTest : SysuiTestCase() {


    @Test
    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun getGroupRoot_adapter() {
    fun isGroupRoot_adapter() {
        assertThat(underTest.entryAdapter.groupRoot).isEqualTo(underTest.entryAdapter)
        assertThat(underTest.entryAdapter.isGroupRoot).isTrue()
    }
    }


    @Test
    @Test
+4 −4
Original line number Original line Diff line number Diff line
@@ -542,7 +542,7 @@ public class NotificationEntryTest extends SysuiTestCase {


    @Test
    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    public void getGroupRoot_adapter_groupSummary() {
    public void isGroupRoot_adapter_groupSummary() {
        ExpandableNotificationRow row = mock(ExpandableNotificationRow.class);
        ExpandableNotificationRow row = mock(ExpandableNotificationRow.class);
        Notification notification = new Notification.Builder(mContext, "")
        Notification notification = new Notification.Builder(mContext, "")
                .setSmallIcon(R.drawable.ic_person)
                .setSmallIcon(R.drawable.ic_person)
@@ -562,12 +562,12 @@ public class NotificationEntryTest extends SysuiTestCase {
                .build();
                .build();
        entry.setRow(row);
        entry.setRow(row);


        assertThat(entry.getEntryAdapter().getGroupRoot()).isNull();
        assertThat(entry.getEntryAdapter().isGroupRoot()).isFalse();
    }
    }


    @Test
    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    public void getGroupRoot_adapter_groupChild() {
    public void isGroupRoot_adapter_groupChild() {
        Notification notification = new Notification.Builder(mContext, "")
        Notification notification = new Notification.Builder(mContext, "")
                .setSmallIcon(R.drawable.ic_person)
                .setSmallIcon(R.drawable.ic_person)
                .setGroupSummary(true)
                .setGroupSummary(true)
@@ -591,7 +591,7 @@ public class NotificationEntryTest extends SysuiTestCase {
                .setParent(groupEntry.build())
                .setParent(groupEntry.build())
                .build();
                .build();


        assertThat(entry.getEntryAdapter().getGroupRoot()).isEqualTo(parent.getEntryAdapter());
        assertThat(entry.getEntryAdapter().isGroupRoot()).isFalse();
    }
    }


    @Test
    @Test
+54 −37
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.statusbar.notification.collection.render
package com.android.systemui.statusbar.notification.collection.render


import android.os.Build
import android.os.Build
import android.os.UserHandle
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.platform.test.annotations.EnableFlags
import android.platform.test.flag.junit.SetFlagsRule
import android.platform.test.flag.junit.SetFlagsRule
@@ -29,9 +30,12 @@ import com.android.systemui.statusbar.notification.collection.GroupEntry
import com.android.systemui.statusbar.notification.collection.GroupEntryBuilder
import com.android.systemui.statusbar.notification.collection.GroupEntryBuilder
import com.android.systemui.statusbar.notification.collection.ListEntry
import com.android.systemui.statusbar.notification.collection.ListEntry
import com.android.systemui.statusbar.notification.collection.NotifPipeline
import com.android.systemui.statusbar.notification.collection.NotifPipeline
import com.android.systemui.statusbar.notification.collection.NotificationEntry
import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder
import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder
import com.android.systemui.statusbar.notification.collection.listbuilder.OnBeforeRenderListListener
import com.android.systemui.statusbar.notification.collection.listbuilder.OnBeforeRenderListListener
import com.android.systemui.statusbar.notification.collection.render.GroupExpansionManager.OnGroupExpansionChangeListener
import com.android.systemui.statusbar.notification.collection.render.GroupExpansionManager.OnGroupExpansionChangeListener
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
import com.android.systemui.statusbar.notification.row.NotificationTestHelper
import com.android.systemui.statusbar.notification.shared.NotificationBundleUi
import com.android.systemui.statusbar.notification.shared.NotificationBundleUi
import com.android.systemui.util.mockito.any
import com.android.systemui.util.mockito.any
import com.android.systemui.util.mockito.mock
import com.android.systemui.util.mockito.mock
@@ -55,23 +59,39 @@ class GroupExpansionManagerTest : SysuiTestCase() {


    private lateinit var underTest: GroupExpansionManagerImpl
    private lateinit var underTest: GroupExpansionManagerImpl


    private lateinit var testHelper: NotificationTestHelper
    private val dumpManager: DumpManager = mock()
    private val dumpManager: DumpManager = mock()
    private val groupMembershipManager: GroupMembershipManager = mock()
    private val groupMembershipManager: GroupMembershipManager = mock()


    private val pipeline: NotifPipeline = mock()
    private val pipeline: NotifPipeline = mock()
    private lateinit var beforeRenderListListener: OnBeforeRenderListListener
    private lateinit var beforeRenderListListener: OnBeforeRenderListListener


    private val summary1 = notificationSummaryEntry("foo", 1)
    private lateinit var summary1: NotificationEntry
    private val summary2 = notificationSummaryEntry("bar", 1)
    private lateinit var summary2: NotificationEntry
    private val entries =
    private lateinit var entries: List<ListEntry>

    private fun notificationEntry(pkg: String, id: Int, parent: ExpandableNotificationRow?) =
        NotificationEntryBuilder().setPkg(pkg).setId(id).build().apply {
            row = testHelper.createRow().apply {
                setIsChildInGroup(true, parent)
            }
        }

    @Before
    fun setUp() {
        testHelper = NotificationTestHelper(mContext, mDependency)

        summary1 = testHelper.createRow().entry
        summary2 = testHelper.createRow().entry
        entries =
            listOf<ListEntry>(
            listOf<ListEntry>(
                GroupEntryBuilder()
                GroupEntryBuilder()
                    .setSummary(summary1)
                    .setSummary(summary1)
                    .setChildren(
                    .setChildren(
                        listOf(
                        listOf(
                        notificationEntry("foo", 2),
                            notificationEntry("foo", 2, summary1.row),
                        notificationEntry("foo", 3),
                            notificationEntry("foo", 3, summary1.row),
                        notificationEntry("foo", 4)
                            notificationEntry("foo", 4, summary1.row)
                        )
                        )
                    )
                    )
                    .build(),
                    .build(),
@@ -79,32 +99,18 @@ class GroupExpansionManagerTest : SysuiTestCase() {
                    .setSummary(summary2)
                    .setSummary(summary2)
                    .setChildren(
                    .setChildren(
                        listOf(
                        listOf(
                        notificationEntry("bar", 2),
                            notificationEntry("bar", 2, summary2.row),
                        notificationEntry("bar", 3),
                            notificationEntry("bar", 3, summary2.row),
                        notificationEntry("bar", 4)
                            notificationEntry("bar", 4, summary2.row)
                        )
                        )
                    )
                    )
                    .build(),
                    .build(),
            notificationEntry("baz", 1)
                notificationEntry("baz", 1, null)
            )
            )


    private fun notificationEntry(pkg: String, id: Int) =
        NotificationEntryBuilder().setPkg(pkg).setId(id).build().apply { row = mock() }

    private fun notificationSummaryEntry(pkg: String, id: Int) =
        NotificationEntryBuilder().setPkg(pkg).setId(id).setParent(GroupEntry.ROOT_ENTRY).build()
            .apply { row = mock() }

    @Before
    fun setUp() {
        whenever(groupMembershipManager.getGroupSummary(summary1)).thenReturn(summary1)
        whenever(groupMembershipManager.getGroupSummary(summary1)).thenReturn(summary1)
        whenever(groupMembershipManager.getGroupSummary(summary2)).thenReturn(summary2)
        whenever(groupMembershipManager.getGroupSummary(summary2)).thenReturn(summary2)


        whenever(groupMembershipManager.getGroupRoot(summary1.entryAdapter))
            .thenReturn(summary1.entryAdapter)
        whenever(groupMembershipManager.getGroupRoot(summary2.entryAdapter))
            .thenReturn(summary2.entryAdapter)

        underTest = GroupExpansionManagerImpl(dumpManager, groupMembershipManager)
        underTest = GroupExpansionManagerImpl(dumpManager, groupMembershipManager)
    }
    }


@@ -221,4 +227,15 @@ class GroupExpansionManagerTest : SysuiTestCase() {
        verify(listener).onGroupExpansionChange(summary1.row, false)
        verify(listener).onGroupExpansionChange(summary1.row, false)
        verifyNoMoreInteractions(listener)
        verifyNoMoreInteractions(listener)
    }
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun isGroupExpanded() {
        underTest.setGroupExpanded(summary1.entryAdapter, true)

        assertThat(underTest.isGroupExpanded(summary1.entryAdapter)).isTrue();
        assertThat(underTest.isGroupExpanded(
            (entries[0] as? GroupEntry)?.getChildren()?.get(0)?.entryAdapter))
            .isTrue();
    }
}
}
+8 −29
Original line number Original line Diff line number Diff line
@@ -170,28 +170,7 @@ class GroupMembershipManagerTest : SysuiTestCase() {


    @Test
    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun isGroupRoot_topLevelEntry() {
    fun isChildEntryAdapterInGroup_child() {
        val entry = NotificationEntryBuilder().setParent(GroupEntry.ROOT_ENTRY).build()
        assertThat(underTest.isGroupRoot(entry.entryAdapter)).isFalse()
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun isGroupRoot_summary() {
        val groupKey = "group"
        val summary =
            NotificationEntryBuilder()
                .setGroup(mContext, groupKey)
                .setGroupSummary(mContext, true)
                .build()
        GroupEntryBuilder().setKey(groupKey).setSummary(summary).build()

        assertThat(underTest.isGroupRoot(summary.entryAdapter)).isTrue()
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun isGroupRoot_child() {
        val groupKey = "group"
        val groupKey = "group"
        val summary =
        val summary =
            NotificationEntryBuilder()
            NotificationEntryBuilder()
@@ -201,19 +180,19 @@ class GroupMembershipManagerTest : SysuiTestCase() {
        val entry = NotificationEntryBuilder().setGroup(mContext, groupKey).build()
        val entry = NotificationEntryBuilder().setGroup(mContext, groupKey).build()
        GroupEntryBuilder().setKey(groupKey).setSummary(summary).addChild(entry).build()
        GroupEntryBuilder().setKey(groupKey).setSummary(summary).addChild(entry).build()


        assertThat(underTest.isGroupRoot(entry.entryAdapter)).isFalse()
        assertThat(underTest.isChildInGroup(entry.entryAdapter)).isTrue()
    }
    }


    @Test
    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun getGroupRoot_topLevelEntry() {
    fun isGroupRoot_topLevelEntry() {
        val entry = NotificationEntryBuilder().setParent(GroupEntry.ROOT_ENTRY).build()
        val entry = NotificationEntryBuilder().setParent(GroupEntry.ROOT_ENTRY).build()
        assertThat(underTest.getGroupRoot(entry.entryAdapter)).isNull()
        assertThat(underTest.isGroupRoot(entry.entryAdapter)).isFalse()
    }
    }


    @Test
    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun getGroupRoot_summary() {
    fun isGroupRoot_summary() {
        val groupKey = "group"
        val groupKey = "group"
        val summary =
        val summary =
            NotificationEntryBuilder()
            NotificationEntryBuilder()
@@ -222,12 +201,12 @@ class GroupMembershipManagerTest : SysuiTestCase() {
                .build()
                .build()
        GroupEntryBuilder().setKey(groupKey).setSummary(summary).build()
        GroupEntryBuilder().setKey(groupKey).setSummary(summary).build()


        assertThat(underTest.getGroupRoot(summary.entryAdapter)).isEqualTo(summary.entryAdapter)
        assertThat(underTest.isGroupRoot(summary.entryAdapter)).isTrue()
    }
    }


    @Test
    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun getGroupRoot_child() {
    fun isGroupRoot_child() {
        val groupKey = "group"
        val groupKey = "group"
        val summary =
        val summary =
            NotificationEntryBuilder()
            NotificationEntryBuilder()
@@ -237,6 +216,6 @@ class GroupMembershipManagerTest : SysuiTestCase() {
        val entry = NotificationEntryBuilder().setGroup(mContext, groupKey).build()
        val entry = NotificationEntryBuilder().setGroup(mContext, groupKey).build()
        GroupEntryBuilder().setKey(groupKey).setSummary(summary).addChild(entry).build()
        GroupEntryBuilder().setKey(groupKey).setSummary(summary).addChild(entry).build()


        assertThat(underTest.getGroupRoot(entry.entryAdapter)).isEqualTo(summary.entryAdapter)
        assertThat(underTest.isGroupRoot(entry.entryAdapter)).isFalse()
    }
    }
}
}
+61 −8
Original line number Original line Diff line number Diff line
@@ -54,6 +54,7 @@ import com.android.systemui.statusbar.notification.interruption.VisualInterrupti
import com.android.systemui.statusbar.notification.interruption.VisualInterruptionRefactor
import com.android.systemui.statusbar.notification.interruption.VisualInterruptionRefactor
import com.android.systemui.statusbar.notification.interruption.VisualInterruptionType
import com.android.systemui.statusbar.notification.interruption.VisualInterruptionType
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
import com.android.systemui.statusbar.notification.shared.NotificationBundleUi
import com.android.systemui.statusbar.notification.stack.notificationStackScrollLayoutController
import com.android.systemui.statusbar.notification.stack.notificationStackScrollLayoutController
import com.android.systemui.statusbar.notification.visualInterruptionDecisionProvider
import com.android.systemui.statusbar.notification.visualInterruptionDecisionProvider
import com.android.systemui.statusbar.notificationLockscreenUserManager
import com.android.systemui.statusbar.notificationLockscreenUserManager
@@ -293,6 +294,7 @@ class StatusBarNotificationPresenterTest : SysuiTestCase() {


    @Test
    @Test
    @EnableSceneContainer
    @EnableSceneContainer
    @DisableFlags(NotificationBundleUi.FLAG_NAME)
    fun testExpandSensitiveNotification_onLockScreen_opensShade() =
    fun testExpandSensitiveNotification_onLockScreen_opensShade() =
        kosmos.runTest {
        kosmos.runTest {
            // Given we are on the keyguard
            // Given we are on the keyguard
@@ -303,11 +305,35 @@ class StatusBarNotificationPresenterTest : SysuiTestCase() {
            )
            )


            // When the user expands a sensitive Notification
            // When the user expands a sensitive Notification
            val row = createRow()
            val row = createRow(createNotificationEntry())
            val entry =
            row.entry.apply { setSensitive(/* sensitive= */ true, /* deviceSensitive= */ true) }
            row.entry.apply { setSensitive(/* sensitive= */ true, /* deviceSensitive= */ true) }


            underTest.onExpandClicked(entry, mock(), /* nowExpanded= */ true)
            underTest.onExpandClicked(row.entry, mock(), /* nowExpanded= */ true)

            // Then we open the locked shade
            verify(kosmos.lockscreenShadeTransitionController)
                // Explicit parameters to avoid issues with Kotlin default arguments in Mockito
                .goToLockedShade(row, true)
        }

    @Test
    @EnableSceneContainer
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun testExpandSensitiveNotification_onLockScreen_opensShade_entryAdapter() =
        kosmos.runTest {
            // Given we are on the keyguard
            kosmos.sysuiStatusBarStateController.state = StatusBarState.KEYGUARD
            // And the device is locked
            kosmos.fakeAuthenticationRepository.setAuthenticationMethod(
                AuthenticationMethodModel.Pin
            )

            // When the user expands a sensitive Notification
            val entry = createNotificationEntry()
            val row = createRow(entry)
            entry.setSensitive(/* sensitive= */ true, /* deviceSensitive= */ true)

            underTest.onExpandClicked(row, row.entryAdapter, /* nowExpanded= */ true)


            // Then we open the locked shade
            // Then we open the locked shade
            verify(kosmos.lockscreenShadeTransitionController)
            verify(kosmos.lockscreenShadeTransitionController)
@@ -317,6 +343,7 @@ class StatusBarNotificationPresenterTest : SysuiTestCase() {


    @Test
    @Test
    @EnableSceneContainer
    @EnableSceneContainer
    @DisableFlags(NotificationBundleUi.FLAG_NAME)
    fun testExpandSensitiveNotification_onLockedShade_showsBouncer() =
    fun testExpandSensitiveNotification_onLockedShade_showsBouncer() =
        kosmos.runTest {
        kosmos.runTest {
            // Given we are on the locked shade
            // Given we are on the locked shade
@@ -328,7 +355,7 @@ class StatusBarNotificationPresenterTest : SysuiTestCase() {


            // When the user expands a sensitive Notification
            // When the user expands a sensitive Notification
            val entry =
            val entry =
                createRow().entry.apply {
                createRow(createNotificationEntry()).entry.apply {
                    setSensitive(/* sensitive= */ true, /* deviceSensitive= */ true)
                    setSensitive(/* sensitive= */ true, /* deviceSensitive= */ true)
                }
                }
            underTest.onExpandClicked(entry, mock(), /* nowExpanded= */ true)
            underTest.onExpandClicked(entry, mock(), /* nowExpanded= */ true)
@@ -337,6 +364,29 @@ class StatusBarNotificationPresenterTest : SysuiTestCase() {
            verify(kosmos.activityStarter).dismissKeyguardThenExecute(any(), eq(null), eq(false))
            verify(kosmos.activityStarter).dismissKeyguardThenExecute(any(), eq(null), eq(false))
        }
        }


    @Test
    @EnableSceneContainer
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun testExpandSensitiveNotification_onLockedShade_showsBouncer_entryAdapter() =
        kosmos.runTest {
            // Given we are on the locked shade
            kosmos.sysuiStatusBarStateController.state = StatusBarState.SHADE_LOCKED
            // And the device is locked
            kosmos.fakeAuthenticationRepository.setAuthenticationMethod(
                AuthenticationMethodModel.Pin
            )

            // When the user expands a sensitive Notification
            val entry = createNotificationEntry()
            val row = createRow(entry)
            entry.setSensitive(/* sensitive= */ true, /* deviceSensitive= */ true)

            underTest.onExpandClicked(row, row.entryAdapter, /* nowExpanded= */ true)

            // Then we show the bouncer
            verify(kosmos.activityStarter).dismissKeyguardThenExecute(any(), eq(null), eq(false))
        }

    private fun createPresenter(): StatusBarNotificationPresenter {
    private fun createPresenter(): StatusBarNotificationPresenter {
        val initController: InitController = InitController()
        val initController: InitController = InitController()
        return StatusBarNotificationPresenter(
        return StatusBarNotificationPresenter(
@@ -398,10 +448,13 @@ class StatusBarNotificationPresenterTest : SysuiTestCase() {
        interruptSuppressor = suppressorCaptor.lastValue
        interruptSuppressor = suppressorCaptor.lastValue
    }
    }


    private fun createRow(): ExpandableNotificationRow {
    private fun createRow(entry: NotificationEntry): ExpandableNotificationRow {
        val row: ExpandableNotificationRow = mock()
        val row: ExpandableNotificationRow = mock()
        val entry: NotificationEntry = createNotificationEntry()
        if (NotificationBundleUi.isEnabled) {
            whenever(row.entryAdapter).thenReturn(entry.entryAdapter)
        } else {
            whenever(row.entry).thenReturn(entry)
            whenever(row.entry).thenReturn(entry)
        }
        entry.row = row
        entry.row = row
        return row
        return row
    }
    }
Loading