From 0c852330af5f9ccb27dea3139c5becb15622afaf Mon Sep 17 00:00:00 2001 From: Chandru S Date: Fri, 23 Jun 2023 11:52:45 -0700 Subject: [PATCH] Allow face auth to run even when secure camera is launched if primary bouncer is also visible Test: atest DeviceEntryFaceAuthRepositoryTest Fixes: 285521712 Change-Id: I1af59924054ed3f01a43774cf306b39b300ab8df --- .../DeviceEntryFaceAuthRepository.kt | 19 +++++++++------ .../DeviceEntryFaceAuthRepositoryTest.kt | 23 +++++++++++++++++++ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepository.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepository.kt index 197929cb638c0..82c5fb1f24e70 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepository.kt @@ -317,13 +317,14 @@ constructor( tableLogBuffer ), logAndObserve( - combine( - keyguardInteractor.isSecureCameraActive, - alternateBouncerInteractor.isVisible - ) { a, b -> - !a || b - }, - "secureCameraNotActiveOrAltBouncerIsShowing", + keyguardInteractor.isSecureCameraActive + .isFalse() + .or( + alternateBouncerInteractor.isVisible.or( + keyguardInteractor.primaryBouncerShowing + ) + ), + "secureCameraNotActiveOrAnyBouncerIsShowing", tableLogBuffer ), logAndObserve( @@ -640,6 +641,10 @@ constructor( private fun and(flow: Flow, anotherFlow: Flow) = flow.combine(anotherFlow) { a, b -> a && b } +/** Combine two boolean flows by or-ing both of them */ +private fun Flow.or(anotherFlow: Flow) = + this.combine(anotherFlow) { a, b -> a || b } + /** "Not" the given flow. The return [Flow] will be true when [this] flow is false. */ private fun Flow.isFalse(): Flow { return this.map { !it } diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepositoryTest.kt index 9eef793057aa3..86684696a88e2 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepositoryTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepositoryTest.kt @@ -572,6 +572,29 @@ class DeviceEntryFaceAuthRepositoryTest : SysuiTestCase() { } } + @Test + fun authenticateRunsWhenSecureCameraIsActiveIfBouncerIsShowing() = + testScope.runTest { + initCollectors() + allPreconditionsToRunFaceAuthAreTrue() + bouncerRepository.setAlternateVisible(false) + bouncerRepository.setPrimaryShow(false) + + assertThat(canFaceAuthRun()).isTrue() + + // launch secure camera + fakeCommandQueue.doForEachCallback { + it.onCameraLaunchGestureDetected(CAMERA_LAUNCH_SOURCE_POWER_DOUBLE_TAP) + } + keyguardRepository.setKeyguardOccluded(true) + runCurrent() + assertThat(canFaceAuthRun()).isFalse() + + // but bouncer is shown after that. + bouncerRepository.setPrimaryShow(true) + assertThat(canFaceAuthRun()).isTrue() + } + @Test fun authenticateDoesNotRunOnUnsupportedPosture() = testScope.runTest {