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

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

Merge changes from topic "altBouncer_rearDisplayMode" into main

* changes:
  Don't show sideFpsIndicator if requested while asleep
  Don't show the altBouncer in rearDisplay mode
parents ffba93cb 1a125b1d
Loading
Loading
Loading
Loading
+22 −1
Original line number Diff line number Diff line
@@ -37,6 +37,9 @@ import com.android.systemui.display.data.repository.displayRepository
import com.android.systemui.display.data.repository.displayStateRepository
import com.android.systemui.display.shared.model.DisplayRotation
import com.android.systemui.kosmos.testScope
import com.android.systemui.power.data.repository.fakePowerRepository
import com.android.systemui.power.shared.model.WakeSleepReason
import com.android.systemui.power.shared.model.WakefulnessState
import com.android.systemui.res.R
import com.android.systemui.testKosmos
import com.android.systemui.util.mockito.eq
@@ -90,6 +93,15 @@ class SideFpsOverlayViewBinderTest : SysuiTestCase() {
        }
    }

    @Test
    fun verifyIndicatorNotAdded_whenAsleep() {
        kosmos.testScope.runTest {
            setupTestConfiguration(asleep = true)
            updateSfpsIndicatorRequests(kosmos, mContext, primaryBouncerRequest = true)
            verify(kosmos.windowManager, never()).addView(any(), any())
        }
    }

    @Test
    fun verifyIndicatorShowAndHide_onPrimaryBouncerShowAndHide() {
        kosmos.testScope.runTest {
@@ -194,7 +206,10 @@ class SideFpsOverlayViewBinderTest : SysuiTestCase() {
        }
    }

    private suspend fun TestScope.setupTestConfiguration(isInRearDisplayMode: Boolean) {
    private suspend fun TestScope.setupTestConfiguration(
        isInRearDisplayMode: Boolean = false,
        asleep: Boolean = false,
    ) {
        kosmos.fingerprintPropertyRepository.setProperties(
            sensorId = 1,
            strength = SensorStrength.STRONG,
@@ -205,6 +220,12 @@ class SideFpsOverlayViewBinderTest : SysuiTestCase() {
        kosmos.displayStateRepository.setIsInRearDisplayMode(isInRearDisplayMode)
        kosmos.displayStateRepository.setCurrentRotation(DisplayRotation.ROTATION_0)
        kosmos.displayRepository.emitDisplayChangeEvent(0)
        kosmos.fakePowerRepository.updateWakefulness(
            if (asleep) WakefulnessState.ASLEEP else WakefulnessState.AWAKE,
            WakeSleepReason.POWER_BUTTON,
            WakeSleepReason.POWER_BUTTON,
            false,
        )
        kosmos.sideFpsOverlayViewBinder.start()
        runCurrent()
    }
+2 −63
Original line number Diff line number Diff line
@@ -18,23 +18,19 @@ package com.android.systemui.bouncer.domain.interactor

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.keyguard.keyguardUpdateMonitor
import com.android.systemui.SysuiTestCase
import com.android.systemui.authentication.data.repository.FakeAuthenticationRepository
import com.android.systemui.authentication.domain.interactor.authenticationInteractor
import com.android.systemui.biometrics.data.repository.fingerprintPropertyRepository
import com.android.systemui.bouncer.data.repository.keyguardBouncerRepository
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.deviceentry.domain.interactor.deviceUnlockedInteractor
import com.android.systemui.flags.DisableSceneContainer
import com.android.systemui.flags.EnableSceneContainer
import com.android.systemui.keyguard.data.repository.biometricSettingsRepository
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.scene.domain.interactor.sceneInteractor
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.statusbar.policy.keyguardStateController
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.flow.map
@@ -44,7 +40,6 @@ import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.whenever

@SmallTest
@RunWith(AndroidJUnit4::class)
@@ -62,7 +57,7 @@ class AlternateBouncerInteractorTest : SysuiTestCase() {
    @DisableSceneContainer
    fun canShowAlternateBouncer_false_dueToTransitionState() =
        kosmos.testScope.runTest {
            givenAlternateBouncerSupported()
            kosmos.givenAlternateBouncerSupported()
            val canShowAlternateBouncer by collectLastValue(underTest.canShowAlternateBouncer)
            kosmos.fakeKeyguardTransitionRepository.sendTransitionStep(
                from = KeyguardState.AOD,
@@ -76,7 +71,7 @@ class AlternateBouncerInteractorTest : SysuiTestCase() {
    @EnableSceneContainer
    fun canShowAlternateBouncer_false_dueToTransitionState_scene_container() =
        kosmos.testScope.runTest {
            givenAlternateBouncerSupported()
            kosmos.givenAlternateBouncerSupported()
            val canShowAlternateBouncer by collectLastValue(underTest.canShowAlternateBouncer)
            val isDeviceUnlocked by
                collectLastValue(
@@ -91,46 +86,6 @@ class AlternateBouncerInteractorTest : SysuiTestCase() {
            assertThat(canShowAlternateBouncer).isFalse()
        }

    @Test
    fun canShowAlternateBouncerForFingerprint_ifFingerprintIsNotUsuallyAllowed() {
        givenCanShowAlternateBouncer()
        kosmos.biometricSettingsRepository.setIsFingerprintAuthEnrolledAndEnabled(false)

        assertFalse(underTest.canShowAlternateBouncerForFingerprint())
    }

    @Test
    fun canShowAlternateBouncerForFingerprint_strongBiometricNotAllowed() {
        givenCanShowAlternateBouncer()
        kosmos.biometricSettingsRepository.setIsFingerprintAuthCurrentlyAllowed(false)

        assertFalse(underTest.canShowAlternateBouncerForFingerprint())
    }

    @Test
    fun canShowAlternateBouncerForFingerprint_fingerprintLockedOut() {
        givenCanShowAlternateBouncer()
        whenever(kosmos.keyguardUpdateMonitor.isFingerprintLockedOut).thenReturn(true)

        assertFalse(underTest.canShowAlternateBouncerForFingerprint())
    }

    @Test
    fun canShowAlternateBouncerForFingerprint_butCanDismissLockScreen() {
        givenCanShowAlternateBouncer()
        whenever(kosmos.keyguardStateController.isUnlocked).thenReturn(true)

        assertFalse(underTest.canShowAlternateBouncerForFingerprint())
    }

    @Test
    fun canShowAlternateBouncerForFingerprint_primaryBouncerShowing() {
        givenCanShowAlternateBouncer()
        kosmos.keyguardBouncerRepository.setPrimaryShow(true)

        assertFalse(underTest.canShowAlternateBouncerForFingerprint())
    }

    @Test
    fun hide_wasPreviouslyShowing() {
        kosmos.keyguardBouncerRepository.setAlternateVisible(true)
@@ -146,20 +101,4 @@ class AlternateBouncerInteractorTest : SysuiTestCase() {
        assertFalse(underTest.hide())
        assertFalse(kosmos.keyguardBouncerRepository.alternateBouncerVisible.value)
    }

    @Test
    fun canShowAlternateBouncerForFingerprint_rearFps() {
        givenCanShowAlternateBouncer()
        kosmos.fingerprintPropertyRepository.supportsRearFps() // does not support alternate bouncer

        assertFalse(underTest.canShowAlternateBouncerForFingerprint())
    }

    private fun givenAlternateBouncerSupported() {
        kosmos.givenAlternateBouncerSupported()
    }

    private fun givenCanShowAlternateBouncer() {
        kosmos.givenCanShowAlternateBouncer()
    }
}
+4 −4
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ import android.view.windowManager
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.bouncer.domain.interactor.givenCanShowAlternateBouncer
import com.android.systemui.bouncer.domain.interactor.givenAlternateBouncerSupported
import com.android.systemui.flags.DisableSceneContainer
import com.android.systemui.keyguard.data.repository.fakeKeyguardTransitionRepository
import com.android.systemui.keyguard.shared.model.KeyguardState
@@ -73,7 +73,7 @@ class AlternateBouncerViewBinderTest : SysuiTestCase() {
    @Test
    fun addViewToWindowManager() {
        testScope.runTest {
            kosmos.givenCanShowAlternateBouncer()
            kosmos.givenAlternateBouncerSupported()
            kosmos.fakeKeyguardTransitionRepository.sendTransitionSteps(
                from = KeyguardState.LOCKSCREEN,
                to = KeyguardState.ALTERNATE_BOUNCER,
@@ -86,7 +86,7 @@ class AlternateBouncerViewBinderTest : SysuiTestCase() {
    @Test
    fun viewRemovedImmediatelyIfAlreadyAttachedToWindow() {
        testScope.runTest {
            kosmos.givenCanShowAlternateBouncer()
            kosmos.givenAlternateBouncerSupported()
            kosmos.fakeKeyguardTransitionRepository.sendTransitionSteps(
                from = KeyguardState.LOCKSCREEN,
                to = KeyguardState.ALTERNATE_BOUNCER,
@@ -107,7 +107,7 @@ class AlternateBouncerViewBinderTest : SysuiTestCase() {
    @Test
    fun viewNotRemovedUntilAttachedToWindow() {
        testScope.runTest {
            kosmos.givenCanShowAlternateBouncer()
            kosmos.givenAlternateBouncerSupported()
            kosmos.fakeKeyguardTransitionRepository.sendTransitionSteps(
                from = KeyguardState.LOCKSCREEN,
                to = KeyguardState.ALTERNATE_BOUNCER,
+0 −2
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import com.android.systemui.SysuiTestCase
import com.android.systemui.authentication.data.repository.fakeAuthenticationRepository
import com.android.systemui.authentication.shared.model.AuthenticationMethodModel
import com.android.systemui.bouncer.domain.interactor.alternateBouncerInteractor
import com.android.systemui.bouncer.domain.interactor.givenCanShowAlternateBouncer
import com.android.systemui.deviceentry.domain.interactor.deviceUnlockedInteractor
import com.android.systemui.flags.DisableSceneContainer
import com.android.systemui.flags.EnableSceneContainer
@@ -277,7 +276,6 @@ class StatusBarStateControllerImplTest(flags: FlagsParameterization) : SysuiTest
            sceneInteractor.changeScene(toScene = Scenes.Lockscreen, loggingReason = "reason")
            assertThat(currentScene).isEqualTo(Scenes.Lockscreen)

            givenCanShowAlternateBouncer()
            alternateBouncerInteractor.forceShow()
            assertThat(alternateBouncerIsVisible).isTrue()

+37 −18
Original line number Diff line number Diff line
@@ -48,8 +48,8 @@ import com.android.systemui.display.domain.interactor.DisplayStateInteractor
import com.android.systemui.keyguard.domain.interactor.DeviceEntrySideFpsOverlayInteractor
import com.android.systemui.keyguard.ui.viewmodel.SideFpsProgressBarViewModel
import com.android.systemui.lifecycle.repeatWhenAttached
import com.android.systemui.power.domain.interactor.PowerInteractor
import com.android.systemui.res.R
import com.android.systemui.util.kotlin.sample
import dagger.Lazy
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
@@ -69,6 +69,7 @@ constructor(
    private val sideFpsProgressBarViewModel: Lazy<SideFpsProgressBarViewModel>,
    private val sfpsSensorInteractor: Lazy<SideFpsSensorInteractor>,
    private val windowManager: Lazy<WindowManager>,
    private val powerInteractor: Lazy<PowerInteractor>,
) : CoreStartable {
    private val pauseDelegate: AccessibilityDelegateCompat =
        object : AccessibilityDelegateCompat() {
@@ -132,34 +133,52 @@ constructor(
                            biometricStatusInteractor.get().sfpsAuthenticationReason,
                            deviceEntrySideFpsOverlayInteractor.get().showIndicatorForDeviceEntry,
                            sideFpsProgressBarViewModel.get().isVisible,
                            ::Triple,
                        )
                        .sample(displayStateInteractor.get().isInRearDisplayMode, ::Pair)
                        .collect { (combinedFlows, isInRearDisplayMode: Boolean) ->
                            val (
                            displayStateInteractor.get().isInRearDisplayMode,
                            powerInteractor.get().isAsleep,
                        ) {
                            systemServerAuthReason,
                            showIndicatorForDeviceEntry,
                                progressBarIsVisible) =
                                combinedFlows
                            progressBarIsVisible,
                            isInRearDisplayMode,
                            isAsleep ->
                            Log.d(
                                TAG,
                                "systemServerAuthReason = $systemServerAuthReason, " +
                                    "showIndicatorForDeviceEntry = " +
                                    "$showIndicatorForDeviceEntry, " +
                                    "progressBarIsVisible = $progressBarIsVisible",
                                    "progressBarIsVisible = $progressBarIsVisible, " +
                                    "isInRearDisplayMode = $isInRearDisplayMode " +
                                    "isAsleep = $isAsleep",
                            )
                            if (!isInRearDisplayMode) {
                                if (progressBarIsVisible) {
                            if (isInRearDisplayMode || progressBarIsVisible) {
                                hide()
                            } else if (systemServerAuthReason != NotRunning) {
                                if (isAsleep) {
                                    Log.e(
                                        TAG,
                                        "requesting SideFpsIndicator for " +
                                            "$systemServerAuthReason while asleep.",
                                    )
                                    hide()
                                } else {
                                    show()
                                }
                            } else if (showIndicatorForDeviceEntry) {
                                if (isAsleep) {
                                    Log.e(
                                        TAG,
                                        "requesting SideFpsIndicator for " +
                                            "DeviceEntry while asleep.",
                                    )
                                    hide()
                                } else {
                                    show()
                                }
                            } else {
                                hide()
                            }
                        }
                        }
                        .collect {}
                }
            }
        }
@@ -200,8 +219,8 @@ constructor(
    private fun hide() {
        if (overlayView != null) {
            val lottie = overlayView!!.requireViewById<LottieAnimationView>(R.id.sidefps_animation)
            lottie.pauseAnimation()
            lottie.removeAllLottieOnCompositionLoadedListener()
            lottie.pauseAnimation()
            Log.d(TAG, "hide(): removing overlayView $overlayView, setting to null")
            windowManager.get().removeView(overlayView)
            overlayView = null
Loading