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

Commit 87f9744c authored by Ale Nijamkin's avatar Ale Nijamkin Committed by Android (Google) Code Review
Browse files

Merge "[flexiglass] Fixes DeviceEntryHapticsInteractorTest" into main

parents 75518118 a3c8e1d9
Loading
Loading
Loading
Loading
+48 −46
Original line number Original line Diff line number Diff line
@@ -45,7 +45,11 @@ import com.android.systemui.keyguard.shared.model.BiometricUnlockMode
import com.android.systemui.keyguard.shared.model.BiometricUnlockSource
import com.android.systemui.keyguard.shared.model.BiometricUnlockSource
import com.android.systemui.keyguard.shared.model.FailFingerprintAuthenticationStatus
import com.android.systemui.keyguard.shared.model.FailFingerprintAuthenticationStatus
import com.android.systemui.keyguard.shared.model.SuccessFingerprintAuthenticationStatus
import com.android.systemui.keyguard.shared.model.SuccessFingerprintAuthenticationStatus
import com.android.systemui.kosmos.testScope
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.advanceTimeBy
import com.android.systemui.kosmos.collectLastValue
import com.android.systemui.kosmos.runCurrent
import com.android.systemui.kosmos.runTest
import com.android.systemui.power.data.repository.powerRepository
import com.android.systemui.power.data.repository.powerRepository
import com.android.systemui.power.shared.model.WakeSleepReason
import com.android.systemui.power.shared.model.WakeSleepReason
import com.android.systemui.power.shared.model.WakefulnessState
import com.android.systemui.power.shared.model.WakefulnessState
@@ -58,7 +62,6 @@ import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.advanceTimeBy
import kotlinx.coroutines.test.advanceTimeBy
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.test.runTest
@@ -72,9 +75,6 @@ import org.mockito.kotlin.whenever
@RunWith(AndroidJUnit4::class)
@RunWith(AndroidJUnit4::class)
class DeviceEntryHapticsInteractorTest : SysuiTestCase() {
class DeviceEntryHapticsInteractorTest : SysuiTestCase() {
    private val kosmos = testKosmos()
    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope

    private lateinit var underTest: DeviceEntryHapticsInteractor


    @Before
    @Before
    fun setup() {
    fun setup() {
@@ -98,14 +98,14 @@ class DeviceEntryHapticsInteractorTest : SysuiTestCase() {
            kosmos.keyguardBouncerRepository.setAlternateVisible(false)
            kosmos.keyguardBouncerRepository.setAlternateVisible(false)
            kosmos.sceneInteractor.changeScene(Scenes.Lockscreen, "reason")
            kosmos.sceneInteractor.changeScene(Scenes.Lockscreen, "reason")
        }
        }
        underTest = kosmos.deviceEntryHapticsInteractor
    }
    }


    @DisableSceneContainer
    @DisableSceneContainer
    @Test
    @Test
    fun nonPowerButtonFPS_vibrateSuccess() =
    fun nonPowerButtonFPS_vibrateSuccess() =
        testScope.runTest {
        kosmos.runTest {
            val playSuccessHaptic by collectLastValue(underTest.playSuccessHapticOnDeviceEntry)
            val playSuccessHaptic by
                collectLastValue(deviceEntryHapticsInteractor.playSuccessHapticOnDeviceEntry)
            enrollFingerprint(FingerprintSensorType.UDFPS_ULTRASONIC)
            enrollFingerprint(FingerprintSensorType.UDFPS_ULTRASONIC)
            runCurrent()
            runCurrent()
            enterDeviceFromFingerprintUnlockLegacy()
            enterDeviceFromFingerprintUnlockLegacy()
@@ -115,8 +115,9 @@ class DeviceEntryHapticsInteractorTest : SysuiTestCase() {
    @DisableSceneContainer
    @DisableSceneContainer
    @Test
    @Test
    fun powerButtonFPS_vibrateSuccess() =
    fun powerButtonFPS_vibrateSuccess() =
        testScope.runTest {
        kosmos.runTest {
            val playSuccessHaptic by collectLastValue(underTest.playSuccessHapticOnDeviceEntry)
            val playSuccessHaptic by
                collectLastValue(deviceEntryHapticsInteractor.playSuccessHapticOnDeviceEntry)
            enrollFingerprint(FingerprintSensorType.POWER_BUTTON)
            enrollFingerprint(FingerprintSensorType.POWER_BUTTON)
            kosmos.fakeKeyEventRepository.setPowerButtonDown(false)
            kosmos.fakeKeyEventRepository.setPowerButtonDown(false)


@@ -132,8 +133,9 @@ class DeviceEntryHapticsInteractorTest : SysuiTestCase() {
    @DisableSceneContainer
    @DisableSceneContainer
    @Test
    @Test
    fun powerButtonFPS_powerDown_doNotVibrateSuccess() =
    fun powerButtonFPS_powerDown_doNotVibrateSuccess() =
        testScope.runTest {
        kosmos.runTest {
            val playSuccessHaptic by collectLastValue(underTest.playSuccessHapticOnDeviceEntry)
            val playSuccessHaptic by
                collectLastValue(deviceEntryHapticsInteractor.playSuccessHapticOnDeviceEntry)
            enrollFingerprint(FingerprintSensorType.POWER_BUTTON)
            enrollFingerprint(FingerprintSensorType.POWER_BUTTON)
            kosmos.fakeKeyEventRepository.setPowerButtonDown(true) // power button is currently DOWN
            kosmos.fakeKeyEventRepository.setPowerButtonDown(true) // power button is currently DOWN


@@ -149,8 +151,9 @@ class DeviceEntryHapticsInteractorTest : SysuiTestCase() {
    @DisableSceneContainer
    @DisableSceneContainer
    @Test
    @Test
    fun powerButtonFPS_powerButtonRecentlyPressed_doNotVibrateSuccess() =
    fun powerButtonFPS_powerButtonRecentlyPressed_doNotVibrateSuccess() =
        testScope.runTest {
        kosmos.runTest {
            val playSuccessHaptic by collectLastValue(underTest.playSuccessHapticOnDeviceEntry)
            val playSuccessHaptic by
                collectLastValue(deviceEntryHapticsInteractor.playSuccessHapticOnDeviceEntry)
            enrollFingerprint(FingerprintSensorType.POWER_BUTTON)
            enrollFingerprint(FingerprintSensorType.POWER_BUTTON)
            kosmos.fakeKeyEventRepository.setPowerButtonDown(false)
            kosmos.fakeKeyEventRepository.setPowerButtonDown(false)


@@ -165,8 +168,8 @@ class DeviceEntryHapticsInteractorTest : SysuiTestCase() {


    @Test
    @Test
    fun nonPowerButtonFPS_vibrateError() =
    fun nonPowerButtonFPS_vibrateError() =
        testScope.runTest {
        kosmos.runTest {
            val playErrorHaptic by collectLastValue(underTest.playErrorHaptic)
            val playErrorHaptic by collectLastValue(deviceEntryHapticsInteractor.playErrorHaptic)
            enrollFingerprint(FingerprintSensorType.UDFPS_ULTRASONIC)
            enrollFingerprint(FingerprintSensorType.UDFPS_ULTRASONIC)
            runCurrent()
            runCurrent()
            fingerprintFailure()
            fingerprintFailure()
@@ -175,8 +178,8 @@ class DeviceEntryHapticsInteractorTest : SysuiTestCase() {


    @Test
    @Test
    fun nonPowerButtonFPS_coExFaceFailure_doNotVibrateError() =
    fun nonPowerButtonFPS_coExFaceFailure_doNotVibrateError() =
        testScope.runTest {
        kosmos.runTest {
            val playErrorHaptic by collectLastValue(underTest.playErrorHaptic)
            val playErrorHaptic by collectLastValue(deviceEntryHapticsInteractor.playErrorHaptic)
            enrollFingerprint(FingerprintSensorType.UDFPS_ULTRASONIC)
            enrollFingerprint(FingerprintSensorType.UDFPS_ULTRASONIC)
            enrollFace()
            enrollFace()
            runCurrent()
            runCurrent()
@@ -186,8 +189,8 @@ class DeviceEntryHapticsInteractorTest : SysuiTestCase() {


    @Test
    @Test
    fun powerButtonFPS_vibrateError() =
    fun powerButtonFPS_vibrateError() =
        testScope.runTest {
        kosmos.runTest {
            val playErrorHaptic by collectLastValue(underTest.playErrorHaptic)
            val playErrorHaptic by collectLastValue(deviceEntryHapticsInteractor.playErrorHaptic)
            enrollFingerprint(FingerprintSensorType.POWER_BUTTON)
            enrollFingerprint(FingerprintSensorType.POWER_BUTTON)
            runCurrent()
            runCurrent()
            fingerprintFailure()
            fingerprintFailure()
@@ -196,8 +199,8 @@ class DeviceEntryHapticsInteractorTest : SysuiTestCase() {


    @Test
    @Test
    fun powerButtonFPS_powerDown_doNotVibrateError() =
    fun powerButtonFPS_powerDown_doNotVibrateError() =
        testScope.runTest {
        kosmos.runTest {
            val playErrorHaptic by collectLastValue(underTest.playErrorHaptic)
            val playErrorHaptic by collectLastValue(deviceEntryHapticsInteractor.playErrorHaptic)
            enrollFingerprint(FingerprintSensorType.POWER_BUTTON)
            enrollFingerprint(FingerprintSensorType.POWER_BUTTON)
            kosmos.fakeKeyEventRepository.setPowerButtonDown(true)
            kosmos.fakeKeyEventRepository.setPowerButtonDown(true)
            runCurrent()
            runCurrent()
@@ -208,10 +211,10 @@ class DeviceEntryHapticsInteractorTest : SysuiTestCase() {
    @EnableSceneContainer
    @EnableSceneContainer
    @Test
    @Test
    fun playSuccessHaptic_onDeviceEntryFromUdfps() =
    fun playSuccessHaptic_onDeviceEntryFromUdfps() =
        testScope.runTest {
        kosmos.runTest {
            kosmos.configureKeyguardBypass(isBypassAvailable = false)
            kosmos.configureKeyguardBypass(isBypassAvailable = false)
            underTest = kosmos.deviceEntryHapticsInteractor
            val playSuccessHaptic by
            val playSuccessHaptic by collectLastValue(underTest.playSuccessHapticOnDeviceEntry)
                collectLastValue(deviceEntryHapticsInteractor.playSuccessHapticOnDeviceEntry)
            enrollFingerprint(FingerprintSensorType.UDFPS_ULTRASONIC)
            enrollFingerprint(FingerprintSensorType.UDFPS_ULTRASONIC)
            runCurrent()
            runCurrent()
            configureDeviceEntryFromBiometricSource(isFpUnlock = true)
            configureDeviceEntryFromBiometricSource(isFpUnlock = true)
@@ -222,10 +225,10 @@ class DeviceEntryHapticsInteractorTest : SysuiTestCase() {
    @EnableSceneContainer
    @EnableSceneContainer
    @Test
    @Test
    fun playSuccessHaptic_onDeviceEntryFromSfps() =
    fun playSuccessHaptic_onDeviceEntryFromSfps() =
        testScope.runTest {
        kosmos.runTest {
            kosmos.configureKeyguardBypass(isBypassAvailable = false)
            kosmos.configureKeyguardBypass(isBypassAvailable = false)
            underTest = kosmos.deviceEntryHapticsInteractor
            val playSuccessHaptic by
            val playSuccessHaptic by collectLastValue(underTest.playSuccessHapticOnDeviceEntry)
                collectLastValue(deviceEntryHapticsInteractor.playSuccessHapticOnDeviceEntry)
            enrollFingerprint(FingerprintSensorType.POWER_BUTTON)
            enrollFingerprint(FingerprintSensorType.POWER_BUTTON)
            kosmos.fakeKeyEventRepository.setPowerButtonDown(false)
            kosmos.fakeKeyEventRepository.setPowerButtonDown(false)


@@ -242,11 +245,11 @@ class DeviceEntryHapticsInteractorTest : SysuiTestCase() {
    @EnableSceneContainer
    @EnableSceneContainer
    @Test
    @Test
    fun playSuccessHaptic_onDeviceEntryFromFaceAuth() =
    fun playSuccessHaptic_onDeviceEntryFromFaceAuth() =
        testScope.runTest {
        kosmos.runTest {
            enrollFace()
            enrollFace()
            kosmos.configureKeyguardBypass(isBypassAvailable = true)
            kosmos.configureKeyguardBypass(isBypassAvailable = true)
            underTest = kosmos.deviceEntryHapticsInteractor
            val playSuccessHaptic by
            val playSuccessHaptic by collectLastValue(underTest.playSuccessHapticOnDeviceEntry)
                collectLastValue(deviceEntryHapticsInteractor.playSuccessHapticOnDeviceEntry)
            configureDeviceEntryFromBiometricSource(isFaceUnlock = true)
            configureDeviceEntryFromBiometricSource(isFaceUnlock = true)
            verifyDeviceEntryFromFaceAuth()
            verifyDeviceEntryFromFaceAuth()
            assertThat(playSuccessHaptic).isNotNull()
            assertThat(playSuccessHaptic).isNotNull()
@@ -256,9 +259,9 @@ class DeviceEntryHapticsInteractorTest : SysuiTestCase() {
    @EnableSceneContainer
    @EnableSceneContainer
    @Test
    @Test
    fun skipSuccessHaptic_onFaceAuthSuccess_whenBypassDisabled() =
    fun skipSuccessHaptic_onFaceAuthSuccess_whenBypassDisabled() =
        testScope.runTest {
        kosmos.runTest {
            underTest = kosmos.deviceEntryHapticsInteractor
            val playSuccessHaptic by
            val playSuccessHaptic by collectLastValue(underTest.playSuccessHapticOnDeviceEntry)
                collectLastValue(deviceEntryHapticsInteractor.playSuccessHapticOnDeviceEntry)


            enrollFace()
            enrollFace()
            kosmos.configureKeyguardBypass(isBypassAvailable = false)
            kosmos.configureKeyguardBypass(isBypassAvailable = false)
@@ -272,10 +275,10 @@ class DeviceEntryHapticsInteractorTest : SysuiTestCase() {
    @EnableSceneContainer
    @EnableSceneContainer
    @Test
    @Test
    fun skipSuccessHaptic_onDeviceEntryFromSfps_whenPowerDown() =
    fun skipSuccessHaptic_onDeviceEntryFromSfps_whenPowerDown() =
        testScope.runTest {
        kosmos.runTest {
            kosmos.configureKeyguardBypass(isBypassAvailable = false)
            kosmos.configureKeyguardBypass(isBypassAvailable = false)
            underTest = kosmos.deviceEntryHapticsInteractor
            val playSuccessHaptic by
            val playSuccessHaptic by collectLastValue(underTest.playSuccessHapticOnDeviceEntry)
                collectLastValue(deviceEntryHapticsInteractor.playSuccessHapticOnDeviceEntry)
            enrollFingerprint(FingerprintSensorType.POWER_BUTTON)
            enrollFingerprint(FingerprintSensorType.POWER_BUTTON)
            // power button is currently DOWN
            // power button is currently DOWN
            kosmos.fakeKeyEventRepository.setPowerButtonDown(true)
            kosmos.fakeKeyEventRepository.setPowerButtonDown(true)
@@ -293,10 +296,10 @@ class DeviceEntryHapticsInteractorTest : SysuiTestCase() {
    @EnableSceneContainer
    @EnableSceneContainer
    @Test
    @Test
    fun skipSuccessHaptic_onDeviceEntryFromSfps_whenPowerButtonRecentlyPressed() =
    fun skipSuccessHaptic_onDeviceEntryFromSfps_whenPowerButtonRecentlyPressed() =
        testScope.runTest {
        kosmos.runTest {
            kosmos.configureKeyguardBypass(isBypassAvailable = false)
            kosmos.configureKeyguardBypass(isBypassAvailable = false)
            underTest = kosmos.deviceEntryHapticsInteractor
            val playSuccessHaptic by
            val playSuccessHaptic by collectLastValue(underTest.playSuccessHapticOnDeviceEntry)
                collectLastValue(deviceEntryHapticsInteractor.playSuccessHapticOnDeviceEntry)
            enrollFingerprint(FingerprintSensorType.POWER_BUTTON)
            enrollFingerprint(FingerprintSensorType.POWER_BUTTON)
            kosmos.fakeKeyEventRepository.setPowerButtonDown(false)
            kosmos.fakeKeyEventRepository.setPowerButtonDown(false)


@@ -313,9 +316,9 @@ class DeviceEntryHapticsInteractorTest : SysuiTestCase() {
    @OptIn(ExperimentalCoroutinesApi::class)
    @OptIn(ExperimentalCoroutinesApi::class)
    @Test
    @Test
    fun playSuccessHaptic_onDeviceEntry_fromDeviceEntryIcon() =
    fun playSuccessHaptic_onDeviceEntry_fromDeviceEntryIcon() =
        testScope.runTest {
        kosmos.runTest {
            underTest = kosmos.deviceEntryHapticsInteractor
            val playSuccessHaptic by
            val playSuccessHaptic by collectLastValue(underTest.playSuccessHapticOnDeviceEntry)
                collectLastValue(deviceEntryHapticsInteractor.playSuccessHapticOnDeviceEntry)


            kosmos.fakeKeyguardRepository.setKeyguardDismissible(true)
            kosmos.fakeKeyguardRepository.setKeyguardDismissible(true)
            runCurrent()
            runCurrent()
@@ -353,17 +356,16 @@ class DeviceEntryHapticsInteractorTest : SysuiTestCase() {
                )
                )
            }
            }
        }
        }
        underTest = kosmos.deviceEntryHapticsInteractor
    }
    }


    private fun TestScope.verifyDeviceEntryFromFingerprintAuth() {
    private fun Kosmos.verifyDeviceEntryFromFingerprintAuth() {
        val deviceEntryFromBiometricSource by
        val deviceEntryFromBiometricSource by
            collectLastValue(kosmos.deviceEntrySourceInteractor.deviceEntryFromBiometricSource)
            collectLastValue(kosmos.deviceEntrySourceInteractor.deviceEntryFromBiometricSource)
        assertThat(deviceEntryFromBiometricSource)
        assertThat(deviceEntryFromBiometricSource)
            .isEqualTo(BiometricUnlockSource.FINGERPRINT_SENSOR)
            .isEqualTo(BiometricUnlockSource.FINGERPRINT_SENSOR)
    }
    }


    private fun TestScope.verifyDeviceEntryFromFaceAuth() {
    private fun Kosmos.verifyDeviceEntryFromFaceAuth() {
        val deviceEntryFromBiometricSource by
        val deviceEntryFromBiometricSource by
            collectLastValue(kosmos.deviceEntrySourceInteractor.deviceEntryFromBiometricSource)
            collectLastValue(kosmos.deviceEntrySourceInteractor.deviceEntryFromBiometricSource)
        assertThat(deviceEntryFromBiometricSource).isEqualTo(BiometricUnlockSource.FACE_SENSOR)
        assertThat(deviceEntryFromBiometricSource).isEqualTo(BiometricUnlockSource.FACE_SENSOR)