From 151a5e408a4b4f140fd11e89b8fb5f9090530b13 Mon Sep 17 00:00:00 2001 From: Chandru S Date: Mon, 23 Jan 2023 19:01:20 -0800 Subject: [PATCH] Reset mAssistantVisible state whenever device starts going to sleep Fixes: 266501461 Test: atest KeyguardUpdateMonitorTest Test: manual 1. Enable AoD 2. Enable face & fp 3. Enable voice assistant 4. Keep the device away from face 5. Go to AoD 6. Trigger assistant with "Ok Google" 7. Once device wakes up and assistant is listening, say "set an alarm" 8. Face auth will trigger, but don't unlock the device. 9. Wait until face auth stops 10. Press power button to go to AoD while assistant is visisble 11. Face auth shouldn't run after the devices goes into AoD Change-Id: Idffe08420baec1eb05b6b3f81d0381bb3cddf193 --- .../keyguard/KeyguardUpdateMonitor.java | 8 +++++- .../keyguard/KeyguardUpdateMonitorTest.java | 26 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java index 3581be4b52df3..063daa67556c5 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java @@ -1945,6 +1945,11 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } } mGoingToSleep = true; + // Resetting assistant visibility state as the device is going to sleep now. + // TaskStackChangeListener gets triggered a little late when we transition to AoD, + // which results in face auth running once on AoD. + mAssistantVisible = false; + mLogger.d("Started going to sleep, mGoingToSleep=true, mAssistantVisible=false"); updateBiometricListeningState(BIOMETRIC_ACTION_UPDATE, FACE_AUTH_UPDATED_GOING_TO_SLEEP); } @@ -3342,7 +3347,8 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab /** * Handle {@link #MSG_KEYGUARD_RESET} */ - private void handleKeyguardReset() { + @VisibleForTesting + protected void handleKeyguardReset() { mLogger.d("handleKeyguardReset"); updateBiometricListeningState(BIOMETRIC_ACTION_UPDATE, FACE_AUTH_UPDATED_KEYGUARD_RESET); diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java index 86cd022fafd84..0253262989fd9 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java @@ -857,6 +857,32 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { verify(mFaceManager).authenticate(any(), any(), any(), any(), anyInt(), anyBoolean()); } + @Test + public void faceUnlockDoesNotRunWhenDeviceIsGoingToSleepWithAssistantVisible() { + mKeyguardUpdateMonitor.setKeyguardShowing(true, true); + mKeyguardUpdateMonitor.setAssistantVisible(true); + + verify(mFaceManager).authenticate(any(), any(), any(), any(), anyInt(), anyBoolean()); + mTestableLooper.processAllMessages(); + clearInvocations(mFaceManager); + + // Device going to sleep while assistant is visible + mKeyguardUpdateMonitor.handleStartedGoingToSleep(0); + mKeyguardUpdateMonitor.handleFinishedGoingToSleep(0); + mTestableLooper.moveTimeForward(DEFAULT_CANCEL_SIGNAL_TIMEOUT); + mTestableLooper.processAllMessages(); + + mKeyguardUpdateMonitor.handleKeyguardReset(); + + assertThat(mKeyguardUpdateMonitor.isFaceDetectionRunning()).isFalse(); + verify(mFaceManager, never()).authenticate(any(), + any(), + any(), + any(), + anyInt(), + anyBoolean()); + } + @Test public void testIgnoresAuth_whenTrustAgentOnKeyguard_withoutBypass() { mKeyguardUpdateMonitor.dispatchStartedWakingUp(PowerManager.WAKE_REASON_POWER_BUTTON);