diff --git a/services/core/java/com/android/server/biometrics/sensors/fingerprint/aidl/FingerprintAuthenticationClient.java b/services/core/java/com/android/server/biometrics/sensors/fingerprint/aidl/FingerprintAuthenticationClient.java index 9aecf783a881d..05e83da6a107e 100644 --- a/services/core/java/com/android/server/biometrics/sensors/fingerprint/aidl/FingerprintAuthenticationClient.java +++ b/services/core/java/com/android/server/biometrics/sensors/fingerprint/aidl/FingerprintAuthenticationClient.java @@ -92,6 +92,7 @@ class FingerprintAuthenticationClient extends AuthenticationClient private long mSideFpsLastAcquireStartTime; private Runnable mAuthSuccessRunnable; private final Clock mClock; + private boolean mDidFinishSfps; FingerprintAuthenticationClient( @NonNull Context context, @@ -197,8 +198,9 @@ class FingerprintAuthenticationClient extends AuthenticationClient @Override protected void handleLifecycleAfterAuth(boolean authenticated) { - if (authenticated) { + if (authenticated && !mDidFinishSfps) { mCallback.onClientFinished(this, true /* success */); + mDidFinishSfps = true; } } @@ -490,11 +492,16 @@ class FingerprintAuthenticationClient extends AuthenticationClient if (mSensorProps.isAnySidefpsType()) { Slog.i(TAG, "(sideFPS): onPowerPressed"); mHandler.post(() -> { + if (mDidFinishSfps) { + return; + } Slog.i(TAG, "(sideFPS): finishing auth"); // Ignore auths after a power has been detected mHandler.removeMessages(MESSAGE_AUTH_SUCCESS); // Do not call onError() as that will send an additional callback to coex. + mDidFinishSfps = true; onErrorInternal(BiometricConstants.BIOMETRIC_ERROR_POWER_PRESSED, 0, true); + stopHalOperation(); mSensorOverlays.hide(getSensorId()); }); } diff --git a/services/tests/servicestests/src/com/android/server/biometrics/sensors/fingerprint/aidl/FingerprintAuthenticationClientTest.java b/services/tests/servicestests/src/com/android/server/biometrics/sensors/fingerprint/aidl/FingerprintAuthenticationClientTest.java index cd4af0a581f81..666d4010e9214 100644 --- a/services/tests/servicestests/src/com/android/server/biometrics/sensors/fingerprint/aidl/FingerprintAuthenticationClientTest.java +++ b/services/tests/servicestests/src/com/android/server/biometrics/sensors/fingerprint/aidl/FingerprintAuthenticationClientTest.java @@ -372,6 +372,7 @@ public class FingerprintAuthenticationClientTest { @Test public void fingerprintPowerIgnoresAuthInWindow() throws Exception { when(mSensorProps.isAnySidefpsType()).thenReturn(true); + when(mHal.authenticate(anyLong())).thenReturn(mCancellationSignal); final FingerprintAuthenticationClient client = createClient(1); client.start(mCallback); @@ -382,11 +383,13 @@ public class FingerprintAuthenticationClientTest { mLooper.dispatchAll(); verify(mCallback).onClientFinished(any(), eq(false)); + verify(mCancellationSignal).cancel(); } @Test public void fingerprintAuthIgnoredWaitingForPower() throws Exception { when(mSensorProps.isAnySidefpsType()).thenReturn(true); + when(mHal.authenticate(anyLong())).thenReturn(mCancellationSignal); final FingerprintAuthenticationClient client = createClient(1); client.start(mCallback); @@ -397,11 +400,13 @@ public class FingerprintAuthenticationClientTest { mLooper.dispatchAll(); verify(mCallback).onClientFinished(any(), eq(false)); + verify(mCancellationSignal).cancel(); } @Test - public void fingerprintAuthSucceedsAfterPowerWindow() throws Exception { + public void fingerprintAuthFailsWhenAuthAfterPower() throws Exception { when(mSensorProps.isAnySidefpsType()).thenReturn(true); + when(mHal.authenticate(anyLong())).thenReturn(mCancellationSignal); final FingerprintAuthenticationClient client = createClient(1); client.start(mCallback); @@ -415,7 +420,9 @@ public class FingerprintAuthenticationClientTest { mLooper.moveTimeForward(1000); mLooper.dispatchAll(); - verify(mCallback).onClientFinished(any(), eq(true)); + verify(mCallback, never()).onClientFinished(any(), eq(true)); + verify(mCallback).onClientFinished(any(), eq(false)); + when(mHal.authenticateWithContext(anyLong(), any())).thenReturn(mCancellationSignal); } @Test