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

Commit 3e5c2f49 authored by Beverly's avatar Beverly
Browse files

Reset primary bouncer face message to default when face auth restarts

Only reset the primary bouncer message on face auth
restarting if the currently shown message was a face message.
We don't want to reset fingerprint messages.

Also, we don't reset fingerprint messages when
a new fingerprint auth begins; since fingerprint
is much faster, the messages may look flickery
if the message was rest each time fingerprint
is re-tried.

Test: atest BouncerMessageInteractorTest
Test: Authenticate from primary bouncer with a mask, see
mask covering message. Restart face auth on the bouncer
and observe the mask covering message is reset.
Fixes: 330248002
Flag: EXEMPT bugfix

Change-Id: I19e981f4c5226e4f3be7a30bef70ad09ace1da0d
parent 304bb603
Loading
Loading
Loading
Loading
+53 −0
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@
package com.android.systemui.bouncer.domain.interactor

import android.content.pm.UserInfo
import android.hardware.biometrics.BiometricFaceConstants
import android.hardware.biometrics.BiometricSourceType
import android.testing.TestableLooper
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
@@ -25,6 +27,7 @@ import com.android.keyguard.KeyguardSecurityModel
import com.android.keyguard.KeyguardSecurityModel.SecurityMode.PIN
import com.android.keyguard.KeyguardSecurityModel.SecurityMode.Pattern
import com.android.keyguard.KeyguardUpdateMonitor
import com.android.keyguard.KeyguardUpdateMonitorCallback
import com.android.systemui.Flags
import com.android.systemui.SysuiTestCase
import com.android.systemui.biometrics.data.repository.FaceSensorInfo
@@ -58,7 +61,9 @@ import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentCaptor
import org.mockito.ArgumentMatchers.eq
import org.mockito.Captor
import org.mockito.Mock
import org.mockito.Mockito.verify
import org.mockito.MockitoAnnotations
@@ -77,6 +82,8 @@ class BouncerMessageInteractorTest : SysuiTestCase() {
    @Mock private lateinit var securityModel: KeyguardSecurityModel
    @Mock private lateinit var countDownTimerUtil: CountDownTimerUtil
    @Mock private lateinit var systemPropertiesHelper: SystemPropertiesHelper
    @Captor
    private lateinit var keyguardUpdateMonitorCaptor: ArgumentCaptor<KeyguardUpdateMonitorCallback>

    private lateinit var underTest: BouncerMessageInteractor

@@ -206,6 +213,52 @@ class BouncerMessageInteractorTest : SysuiTestCase() {
            assertThat(bouncerMessage?.secondaryMessage?.message).isNull()
        }

    @Test
    fun resetMessageBackToDefault_faceAuthRestarts() =
        testScope.runTest {
            init()
            verify(updateMonitor).registerCallback(keyguardUpdateMonitorCaptor.capture())
            val bouncerMessage by collectLastValue(underTest.bouncerMessage)

            underTest.setFaceAcquisitionMessage("not empty")

            assertThat(primaryResMessage(bouncerMessage))
                .isEqualTo("Unlock with PIN or fingerprint")
            assertThat(bouncerMessage?.secondaryMessage?.message).isEqualTo("not empty")

            keyguardUpdateMonitorCaptor.value.onBiometricAcquired(
                BiometricSourceType.FACE,
                BiometricFaceConstants.FACE_ACQUIRED_START
            )

            assertThat(primaryResMessage(bouncerMessage))
                .isEqualTo("Unlock with PIN or fingerprint")
            assertThat(bouncerMessage?.secondaryMessage?.message).isNull()
        }

    @Test
    fun faceRestartDoesNotResetFingerprintMessage() =
        testScope.runTest {
            init()
            verify(updateMonitor).registerCallback(keyguardUpdateMonitorCaptor.capture())
            val bouncerMessage by collectLastValue(underTest.bouncerMessage)

            underTest.setFingerprintAcquisitionMessage("not empty")

            assertThat(primaryResMessage(bouncerMessage))
                .isEqualTo("Unlock with PIN or fingerprint")
            assertThat(bouncerMessage?.secondaryMessage?.message).isEqualTo("not empty")

            keyguardUpdateMonitorCaptor.value.onBiometricAcquired(
                BiometricSourceType.FACE,
                BiometricFaceConstants.FACE_ACQUIRED_START
            )

            assertThat(primaryResMessage(bouncerMessage))
                .isEqualTo("Unlock with PIN or fingerprint")
            assertThat(bouncerMessage?.secondaryMessage?.message).isEqualTo("not empty")
        }

    @Test
    fun setFingerprintMessage_propagateValue() =
        testScope.runTest {
+14 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.bouncer.data.repository

import android.hardware.biometrics.BiometricSourceType
import com.android.systemui.bouncer.shared.model.BouncerMessageModel
import com.android.systemui.dagger.SysUISingleton
import javax.inject.Inject
@@ -26,7 +27,12 @@ import kotlinx.coroutines.flow.MutableStateFlow
interface BouncerMessageRepository {
    val bouncerMessage: Flow<BouncerMessageModel>

    fun setMessage(message: BouncerMessageModel)
    fun setMessage(message: BouncerMessageModel, source: BiometricSourceType? = null)

    /**
     * Return the source of the current [bouncerMessage] if it was set from a biometric. Else, null.
     */
    fun getMessageSource(): BiometricSourceType?
}

@SysUISingleton
@@ -34,8 +40,14 @@ class BouncerMessageRepositoryImpl @Inject constructor() : BouncerMessageReposit

    private val _bouncerMessage = MutableStateFlow(BouncerMessageModel())
    override val bouncerMessage: Flow<BouncerMessageModel> = _bouncerMessage
    private var messageSource: BiometricSourceType? = null

    override fun setMessage(message: BouncerMessageModel) {
    override fun setMessage(message: BouncerMessageModel, source: BiometricSourceType?) {
        _bouncerMessage.value = message
        messageSource = source
    }

    override fun getMessageSource(): BiometricSourceType? {
        return messageSource
    }
}
+14 −5
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.bouncer.domain.interactor

import android.hardware.biometrics.BiometricFaceConstants
import android.hardware.biometrics.BiometricSourceType
import android.os.CountDownTimer
import com.android.keyguard.KeyguardSecurityModel
@@ -115,7 +116,8 @@ constructor(
                                    isFingerprintAuthCurrentlyAllowedOnBouncer.value
                                )
                                .toMessage()
                    }
                    },
                    biometricSourceType,
                )
            }

@@ -123,7 +125,12 @@ constructor(
                biometricSourceType: BiometricSourceType?,
                acquireInfo: Int
            ) {
                super.onBiometricAcquired(biometricSourceType, acquireInfo)
                if (
                    repository.getMessageSource() == BiometricSourceType.FACE &&
                        acquireInfo == BiometricFaceConstants.FACE_ACQUIRED_START
                ) {
                    repository.setMessage(defaultMessage)
                }
            }

            override fun onBiometricAuthenticated(
@@ -131,7 +138,7 @@ constructor(
                biometricSourceType: BiometricSourceType?,
                isStrongBiometric: Boolean
            ) {
                repository.setMessage(defaultMessage)
                repository.setMessage(defaultMessage, biometricSourceType)
            }
        }

@@ -291,7 +298,8 @@ constructor(
                currentSecurityMode,
                value,
                isFingerprintAuthCurrentlyAllowedOnBouncer.value
            )
            ),
            BiometricSourceType.FINGERPRINT,
        )
    }

@@ -302,7 +310,8 @@ constructor(
                currentSecurityMode,
                value,
                isFingerprintAuthCurrentlyAllowedOnBouncer.value
            )
            ),
            BiometricSourceType.FACE,
        )
    }