From fd3b0b927326b130c0c13cb795f7588257944251 Mon Sep 17 00:00:00 2001 From: Chandru S Date: Mon, 23 Jan 2023 16:52:20 -0800 Subject: [PATCH] Prevent face auth from running again after a successful unlock when assistant is active. Fixes: 264952680 Test: atest KeyguardUpdateMonitorTest Test: manually, 1. Enable face & fp unlock 2. Enable AoD 3. Enable assistant with voice trigger 4. Hold phone in front of your face 5. Go to AoD by pressing the power button 6. Trigger assistant by saying "Ok Google" 7. Assistant should open up on lockscreen. 8. Say "setup an alarm" 9. Face unlock should be triggered and device should be unlocked in the bg with keyguard being dismissed. 10. Specify the time for the alarm verbally 11. Once the alarm is set, tap the alarm on the assistant window 12. Face unlock should not be triggered momentarily while assistant is dismissed. Change-Id: Ie3eefc17bc81b2057f318ad53159f5c9b823721b --- .../android/keyguard/KeyguardUpdateMonitor.java | 7 ++++++- .../logging/KeyguardUpdateMonitorLogger.kt | 16 ++++++++++++++++ .../keyguard/KeyguardUpdateMonitorTest.java | 14 +++++++++++++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java index a9695dd62ba48..3581be4b52df3 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java @@ -1537,6 +1537,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab @VisibleForTesting void setAssistantVisible(boolean assistantVisible) { mAssistantVisible = assistantVisible; + mLogger.logAssistantVisible(mAssistantVisible); updateBiometricListeningState(BIOMETRIC_ACTION_UPDATE, FACE_AUTH_UPDATED_ASSISTANT_VISIBILITY_CHANGED); if (mAssistantVisible) { @@ -2678,7 +2679,10 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab private boolean shouldListenForFaceAssistant() { BiometricAuthenticated face = mUserFaceAuthenticated.get(getCurrentUser()); - return mAssistantVisible && mKeyguardOccluded + return mAssistantVisible + // There can be intermediate states where mKeyguardShowing is false but + // mKeyguardOccluded is true, we don't want to run face auth in such a scenario. + && (mKeyguardShowing && mKeyguardOccluded) && !(face != null && face.mAuthenticated) && !mUserHasTrust.get(getCurrentUser(), false); } @@ -3679,6 +3683,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab if (info == null) { return; } + mLogger.logTaskStackChangedForAssistant(info.visible); mHandler.sendMessage(mHandler.obtainMessage(MSG_ASSISTANT_STACK_CHANGED, info.visible)); } catch (RemoteException e) { diff --git a/packages/SystemUI/src/com/android/keyguard/logging/KeyguardUpdateMonitorLogger.kt b/packages/SystemUI/src/com/android/keyguard/logging/KeyguardUpdateMonitorLogger.kt index 5b4245595be95..201a1d9507484 100644 --- a/packages/SystemUI/src/com/android/keyguard/logging/KeyguardUpdateMonitorLogger.kt +++ b/packages/SystemUI/src/com/android/keyguard/logging/KeyguardUpdateMonitorLogger.kt @@ -431,4 +431,20 @@ class KeyguardUpdateMonitorLogger @Inject constructor( str1 = PowerManager.wakeReasonToString(pmWakeReason) }, { "Skip updating face listening state on wakeup from $str1"}) } + + fun logTaskStackChangedForAssistant(assistantVisible: Boolean) { + logBuffer.log(TAG, VERBOSE, { + bool1 = assistantVisible + }, { + "TaskStackChanged for ACTIVITY_TYPE_ASSISTANT, assistant visible: $bool1" + }) + } + + fun logAssistantVisible(assistantVisible: Boolean) { + logBuffer.log(TAG, VERBOSE, { + bool1 = assistantVisible + }, { + "Updating mAssistantVisible to new value: $bool1" + }) + } } diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java index df6752a2b69dc..86cd022fafd84 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java @@ -95,7 +95,6 @@ import android.os.PowerManager; import android.os.RemoteException; import android.os.UserHandle; import android.os.UserManager; -import android.provider.Settings; import android.service.dreams.IDreamManager; import android.service.trust.TrustAgentService; import android.telephony.ServiceState; @@ -833,6 +832,19 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { verify(mFaceManager).authenticate(any(), any(), any(), any(), anyInt(), anyBoolean()); } + @Test + public void doesNotTryToAuthenticateWhenKeyguardIsNotShowingButOccluded_whenAssistant() { + mKeyguardUpdateMonitor.setKeyguardShowing(false, true); + mKeyguardUpdateMonitor.setAssistantVisible(true); + + verify(mFaceManager, never()).authenticate(any(), + any(), + any(), + any(), + anyInt(), + anyBoolean()); + } + @Test public void testTriesToAuthenticate_whenTrustOnAgentKeyguard_ifBypass() { mKeyguardUpdateMonitor.dispatchStartedWakingUp(PowerManager.WAKE_REASON_POWER_BUTTON);