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

Commit 56d5b375 authored by Julia Reynolds's avatar Julia Reynolds Committed by Android (Google) Code Review
Browse files

Merge "Revert^2 "Convert ENR expansion NotificationEntry usages to EntryAdapter"" into main

parents abee523f d836731c
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -65,8 +65,8 @@ class BundleEntryTest : SysuiTestCase() {

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

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

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

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

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

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

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

import android.os.Build
import android.os.UserHandle
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
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.ListEntry
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.listbuilder.OnBeforeRenderListListener
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.util.mockito.any
import com.android.systemui.util.mockito.mock
@@ -55,23 +59,39 @@ class GroupExpansionManagerTest : SysuiTestCase() {

    private lateinit var underTest: GroupExpansionManagerImpl

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

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

    private val summary1 = notificationSummaryEntry("foo", 1)
    private val summary2 = notificationSummaryEntry("bar", 1)
    private val entries =
    private lateinit var summary1: NotificationEntry
    private lateinit var summary2: NotificationEntry
    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>(
                GroupEntryBuilder()
                    .setSummary(summary1)
                    .setChildren(
                        listOf(
                        notificationEntry("foo", 2),
                        notificationEntry("foo", 3),
                        notificationEntry("foo", 4)
                            notificationEntry("foo", 2, summary1.row),
                            notificationEntry("foo", 3, summary1.row),
                            notificationEntry("foo", 4, summary1.row)
                        )
                    )
                    .build(),
@@ -79,32 +99,18 @@ class GroupExpansionManagerTest : SysuiTestCase() {
                    .setSummary(summary2)
                    .setChildren(
                        listOf(
                        notificationEntry("bar", 2),
                        notificationEntry("bar", 3),
                        notificationEntry("bar", 4)
                            notificationEntry("bar", 2, summary2.row),
                            notificationEntry("bar", 3, summary2.row),
                            notificationEntry("bar", 4, summary2.row)
                        )
                    )
                    .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(summary2)).thenReturn(summary2)

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

        underTest = GroupExpansionManagerImpl(dumpManager, groupMembershipManager)
    }

@@ -221,4 +227,15 @@ class GroupExpansionManagerTest : SysuiTestCase() {
        verify(listener).onGroupExpansionChange(summary1.row, false)
        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 Diff line number Diff line
@@ -170,28 +170,7 @@ class GroupMembershipManagerTest : SysuiTestCase() {

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun isGroupRoot_topLevelEntry() {
        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() {
    fun isChildEntryAdapterInGroup_child() {
        val groupKey = "group"
        val summary =
            NotificationEntryBuilder()
@@ -201,19 +180,19 @@ class GroupMembershipManagerTest : SysuiTestCase() {
        val entry = NotificationEntryBuilder().setGroup(mContext, groupKey).build()
        GroupEntryBuilder().setKey(groupKey).setSummary(summary).addChild(entry).build()

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

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

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

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

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    fun getGroupRoot_child() {
    fun isGroupRoot_child() {
        val groupKey = "group"
        val summary =
            NotificationEntryBuilder()
@@ -237,6 +216,6 @@ class GroupMembershipManagerTest : SysuiTestCase() {
        val entry = NotificationEntryBuilder().setGroup(mContext, groupKey).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 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.VisualInterruptionType
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.visualInterruptionDecisionProvider
import com.android.systemui.statusbar.notificationLockscreenUserManager
@@ -293,6 +294,7 @@ class StatusBarNotificationPresenterTest : SysuiTestCase() {

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

            // When the user expands a sensitive Notification
            val row = createRow()
            val entry =
            val row = createRow(createNotificationEntry())
            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
            verify(kosmos.lockscreenShadeTransitionController)
@@ -317,6 +343,7 @@ class StatusBarNotificationPresenterTest : SysuiTestCase() {

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

            // When the user expands a sensitive Notification
            val entry =
                createRow().entry.apply {
                createRow(createNotificationEntry()).entry.apply {
                    setSensitive(/* sensitive= */ true, /* deviceSensitive= */ true)
                }
            underTest.onExpandClicked(entry, mock(), /* nowExpanded= */ true)
@@ -337,6 +364,29 @@ class StatusBarNotificationPresenterTest : SysuiTestCase() {
            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 {
        val initController: InitController = InitController()
        return StatusBarNotificationPresenter(
@@ -398,10 +448,13 @@ class StatusBarNotificationPresenterTest : SysuiTestCase() {
        interruptSuppressor = suppressorCaptor.lastValue
    }

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