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

Commit c7ed75f8 authored by András Kurucz's avatar András Kurucz Committed by Android (Google) Code Review
Browse files

Merge "[Flexiglass] Bind KeyguardStatusbarView to HeadsUp events" into main

parents 5844d3fb c7daf268
Loading
Loading
Loading
Loading
+118 −12
Original line number Diff line number Diff line
@@ -23,8 +23,14 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.keyguard.data.repository.FakeKeyguardTransitionRepository
import com.android.systemui.keyguard.data.repository.fakeDeviceEntryFaceAuthRepository
import com.android.systemui.keyguard.data.repository.fakeKeyguardTransitionRepository
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.kosmos.testScope
import com.android.systemui.shade.shadeTestUtil
import com.android.systemui.statusbar.notification.data.repository.FakeHeadsUpRowRepository
import com.android.systemui.statusbar.notification.data.repository.notificationsKeyguardViewStateRepository
import com.android.systemui.statusbar.notification.shared.NotificationsHeadsUpRefactor
import com.android.systemui.statusbar.notification.stack.data.repository.headsUpNotificationRepository
import com.android.systemui.statusbar.notification.stack.data.repository.setNotifications
@@ -41,9 +47,19 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
@EnableFlags(NotificationsHeadsUpRefactor.FLAG_NAME)
class HeadsUpNotificationInteractorTest : SysuiTestCase() {
    private val kosmos = testKosmos()
    private val kosmos =
        testKosmos().apply {
            fakeKeyguardTransitionRepository =
                FakeKeyguardTransitionRepository(initInLockscreen = false)
        }
    private val testScope = kosmos.testScope
    private val repository = kosmos.headsUpNotificationRepository
    private val faceAuthRepository by lazy { kosmos.fakeDeviceEntryFaceAuthRepository }
    private val headsUpRepository by lazy { kosmos.headsUpNotificationRepository }
    private val keyguardTransitionRepository by lazy { kosmos.fakeKeyguardTransitionRepository }
    private val keyguardViewStateRepository by lazy {
        kosmos.notificationsKeyguardViewStateRepository
    }
    private val shadeTestUtil by lazy { kosmos.shadeTestUtil }

    private val underTest = kosmos.headsUpNotificationInteractor

@@ -60,7 +76,7 @@ class HeadsUpNotificationInteractorTest : SysuiTestCase() {
        testScope.runTest {
            val hasPinnedRows by collectLastValue(underTest.hasPinnedRows)
            // WHEN no pinned rows are set
            repository.setNotifications(
            headsUpRepository.setNotifications(
                fakeHeadsUpRowRepository("key 0"),
                fakeHeadsUpRowRepository("key 1"),
                fakeHeadsUpRowRepository("key 2"),
@@ -76,7 +92,7 @@ class HeadsUpNotificationInteractorTest : SysuiTestCase() {
        testScope.runTest {
            val hasPinnedRows by collectLastValue(underTest.hasPinnedRows)
            // WHEN a pinned rows is set
            repository.setNotifications(
            headsUpRepository.setNotifications(
                fakeHeadsUpRowRepository("key 0", isPinned = true),
                fakeHeadsUpRowRepository("key 1"),
                fakeHeadsUpRowRepository("key 2"),
@@ -98,7 +114,7 @@ class HeadsUpNotificationInteractorTest : SysuiTestCase() {
                    fakeHeadsUpRowRepository("key 1"),
                    fakeHeadsUpRowRepository("key 2"),
                )
            repository.setNotifications(rows)
            headsUpRepository.setNotifications(rows)
            runCurrent()

            // WHEN a row gets pinned
@@ -120,7 +136,7 @@ class HeadsUpNotificationInteractorTest : SysuiTestCase() {
                    fakeHeadsUpRowRepository("key 1"),
                    fakeHeadsUpRowRepository("key 2"),
                )
            repository.setNotifications(rows)
            headsUpRepository.setNotifications(rows)
            runCurrent()

            // THEN that row gets unpinned
@@ -144,7 +160,7 @@ class HeadsUpNotificationInteractorTest : SysuiTestCase() {
        testScope.runTest {
            val pinnedHeadsUpRows by collectLastValue(underTest.pinnedHeadsUpRows)
            // WHEN no rows are pinned
            repository.setNotifications(
            headsUpRepository.setNotifications(
                fakeHeadsUpRowRepository("key 0"),
                fakeHeadsUpRowRepository("key 1"),
                fakeHeadsUpRowRepository("key 2"),
@@ -166,7 +182,7 @@ class HeadsUpNotificationInteractorTest : SysuiTestCase() {
                    fakeHeadsUpRowRepository("key 1", isPinned = true),
                    fakeHeadsUpRowRepository("key 2"),
                )
            repository.setNotifications(rows)
            headsUpRepository.setNotifications(rows)
            runCurrent()

            // THEN the unpinned rows are filtered
@@ -184,7 +200,7 @@ class HeadsUpNotificationInteractorTest : SysuiTestCase() {
                    fakeHeadsUpRowRepository("key 1", isPinned = true),
                    fakeHeadsUpRowRepository("key 2"),
                )
            repository.setNotifications(rows)
            headsUpRepository.setNotifications(rows)
            runCurrent()

            // WHEN all rows gets pinned
@@ -206,7 +222,7 @@ class HeadsUpNotificationInteractorTest : SysuiTestCase() {
                    fakeHeadsUpRowRepository("key 1", isPinned = true),
                    fakeHeadsUpRowRepository("key 2", isPinned = true),
                )
            repository.setNotifications(rows)
            headsUpRepository.setNotifications(rows)
            runCurrent()

            // THEN no rows are filtered
@@ -224,7 +240,7 @@ class HeadsUpNotificationInteractorTest : SysuiTestCase() {
                    fakeHeadsUpRowRepository("key 1", isPinned = true),
                    fakeHeadsUpRowRepository("key 2", isPinned = true),
                )
            repository.setNotifications(rows)
            headsUpRepository.setNotifications(rows)
            runCurrent()

            // WHEN a row gets unpinned
@@ -246,7 +262,7 @@ class HeadsUpNotificationInteractorTest : SysuiTestCase() {
                    fakeHeadsUpRowRepository("key 1"),
                    fakeHeadsUpRowRepository("key 2"),
                )
            repository.setNotifications(rows)
            headsUpRepository.setNotifications(rows)
            runCurrent()

            rows[0].isPinned.value = true
@@ -262,6 +278,96 @@ class HeadsUpNotificationInteractorTest : SysuiTestCase() {
            assertThat(pinnedHeadsUpRows).containsExactly(rows[0])
        }

    @Test
    fun showHeadsUpStatusBar_true() =
        testScope.runTest {
            val showHeadsUpStatusBar by collectLastValue(underTest.showHeadsUpStatusBar)

            // WHEN a row is pinned
            headsUpRepository.setNotifications(fakeHeadsUpRowRepository("key 0", isPinned = true))

            assertThat(showHeadsUpStatusBar).isTrue()
        }

    @Test
    fun showHeadsUpStatusBar_withoutPinnedNotifications_false() =
        testScope.runTest {
            val showHeadsUpStatusBar by collectLastValue(underTest.showHeadsUpStatusBar)

            // WHEN no row is pinned
            headsUpRepository.setNotifications(fakeHeadsUpRowRepository("key 0", isPinned = false))

            assertThat(showHeadsUpStatusBar).isFalse()
        }

    @Test
    fun showHeadsUpStatusBar_whenShadeExpanded_false() =
        testScope.runTest {
            val showHeadsUpStatusBar by collectLastValue(underTest.showHeadsUpStatusBar)

            // WHEN a row is pinned
            headsUpRepository.setNotifications(fakeHeadsUpRowRepository("key 0", isPinned = true))
            // AND the shade is expanded
            shadeTestUtil.setShadeExpansion(1.0f)

            assertThat(showHeadsUpStatusBar).isFalse()
        }

    @Test
    fun showHeadsUpStatusBar_notificationsAreHidden_false() =
        testScope.runTest {
            val showHeadsUpStatusBar by collectLastValue(underTest.showHeadsUpStatusBar)

            // WHEN a row is pinned
            headsUpRepository.setNotifications(fakeHeadsUpRowRepository("key 0", isPinned = true))
            // AND the notifications are hidden
            keyguardViewStateRepository.areNotificationsFullyHidden.value = true

            assertThat(showHeadsUpStatusBar).isFalse()
        }

    @Test
    fun showHeadsUpStatusBar_onLockScreen_false() =
        testScope.runTest {
            val showHeadsUpStatusBar by collectLastValue(underTest.showHeadsUpStatusBar)

            // WHEN a row is pinned
            headsUpRepository.setNotifications(fakeHeadsUpRowRepository("key 0", isPinned = true))
            // AND the lock screen is shown
            keyguardTransitionRepository.emitInitialStepsFromOff(to = KeyguardState.LOCKSCREEN)

            assertThat(showHeadsUpStatusBar).isFalse()
        }

    @Test
    fun showHeadsUpStatusBar_onByPassLockScreen_true() =
        testScope.runTest {
            val showHeadsUpStatusBar by collectLastValue(underTest.showHeadsUpStatusBar)

            // WHEN a row is pinned
            headsUpRepository.setNotifications(fakeHeadsUpRowRepository("key 0", isPinned = true))
            // AND the lock screen is shown
            keyguardTransitionRepository.emitInitialStepsFromOff(to = KeyguardState.LOCKSCREEN)
            // AND bypass is enabled
            faceAuthRepository.isBypassEnabled.value = true

            assertThat(showHeadsUpStatusBar).isTrue()
        }

    @Test
    fun showHeadsUpStatusBar_onByPassLockScreen_withoutNotifications_false() =
        testScope.runTest {
            val showHeadsUpStatusBar by collectLastValue(underTest.showHeadsUpStatusBar)

            // WHEN no pinned rows
            // AND the lock screen is shown
            keyguardTransitionRepository.emitInitialStepsFromOff(to = KeyguardState.LOCKSCREEN)
            // AND bypass is enabled
            faceAuthRepository.isBypassEnabled.value = true

            assertThat(showHeadsUpStatusBar).isFalse()
        }

    private fun fakeHeadsUpRowRepository(key: String, isPinned: Boolean = false) =
        FakeHeadsUpRowRepository(key = key, elementKey = Any()).apply {
            this.isPinned.value = isPinned
+7 −12
Original line number Diff line number Diff line
@@ -524,9 +524,9 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas
            // WHEN there are no pinned rows
            val rows =
                arrayListOf(
                    fakeHeadsUpRowRepository(key = "0"),
                    fakeHeadsUpRowRepository(key = "1"),
                    fakeHeadsUpRowRepository(key = "2"),
                    FakeHeadsUpRowRepository(key = "0"),
                    FakeHeadsUpRowRepository(key = "1"),
                    FakeHeadsUpRowRepository(key = "2"),
                )
            headsUpRepository.setNotifications(
                rows,
@@ -565,8 +565,8 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas
            val hasPinnedHeadsUpRow by collectLastValue(underTest.hasPinnedHeadsUpRow)

            headsUpRepository.setNotifications(
                fakeHeadsUpRowRepository(key = "0", isPinned = true),
                fakeHeadsUpRowRepository(key = "1")
                FakeHeadsUpRowRepository(key = "0", isPinned = true),
                FakeHeadsUpRowRepository(key = "1")
            )
            runCurrent()

@@ -580,8 +580,8 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas
            val hasPinnedHeadsUpRow by collectLastValue(underTest.hasPinnedHeadsUpRow)

            headsUpRepository.setNotifications(
                fakeHeadsUpRowRepository(key = "0"),
                fakeHeadsUpRowRepository(key = "1"),
                FakeHeadsUpRowRepository(key = "0"),
                FakeHeadsUpRowRepository(key = "1"),
            )
            runCurrent()

@@ -625,9 +625,4 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas

            assertThat(animationsEnabled).isFalse()
        }

    private fun fakeHeadsUpRowRepository(key: String, isPinned: Boolean = false) =
        FakeHeadsUpRowRepository(key = key, elementKey = Any()).apply {
            this.isPinned.value = isPinned
        }
}
+3 −0
Original line number Diff line number Diff line
@@ -36,6 +36,9 @@ interface DeviceEntryFaceAuthInteractor {

    val authenticated: Flow<Boolean>

    /** Whether bypass is enabled. If enabled, face unlock dismisses the lock screen. */
    val isBypassEnabled: Flow<Boolean>

    /** Can face auth be run right now */
    fun canFaceAuthRun(): Boolean

+2 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import com.android.systemui.deviceentry.shared.model.FaceDetectionStatus
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.flowOf

/**
 * Implementation of the interactor that noops all face auth operations.
@@ -35,6 +36,7 @@ class NoopDeviceEntryFaceAuthInteractor @Inject constructor() : DeviceEntryFaceA
    override val detectionStatus: Flow<FaceDetectionStatus> = emptyFlow()
    override val lockedOut: Flow<Boolean> = emptyFlow()
    override val authenticated: Flow<Boolean> = emptyFlow()
    override val isBypassEnabled: Flow<Boolean> = flowOf(false)

    override fun canFaceAuthRun(): Boolean = false

+1 −0
Original line number Diff line number Diff line
@@ -286,6 +286,7 @@ constructor(
    override val detectionStatus = repository.detectionStatus
    override val lockedOut: Flow<Boolean> = repository.isLockedOut
    override val authenticated: Flow<Boolean> = repository.isAuthenticated
    override val isBypassEnabled: Flow<Boolean> = repository.isBypassEnabled

    private fun runFaceAuth(uiEvent: FaceAuthUiEvent, fallbackToDetect: Boolean) {
        if (repository.isLockedOut.value) {
Loading