Merge changes I67975ba1,I6a872757 into tm-qpr-dev

* changes:
  FP auth window starts with acquire
  Cleaned up side fps logic
This commit is contained in:
Joshua Mccloskey
2022-10-20 01:07:32 +00:00
committed by Android (Google) Code Review
4 changed files with 150 additions and 10 deletions

View File

@@ -3577,9 +3577,9 @@
config_sidefpsSkipWaitForPowerVendorAcquireMessage --> config_sidefpsSkipWaitForPowerVendorAcquireMessage -->
<integer name="config_sidefpsSkipWaitForPowerAcquireMessage">6</integer> <integer name="config_sidefpsSkipWaitForPowerAcquireMessage">6</integer>
<!-- This vendor acquired message that will cause the sidefpsKgPowerPress window to be skipped. <!-- This vendor acquired message will cause the sidefpsKgPowerPress window to be skipped
config_sidefpsSkipWaitForPowerOnFingerUp must be true and when config_sidefpsSkipWaitForPowerAcquireMessage == 6 (VENDOR) and the vendor acquire
config_sidefpsSkipWaitForPowerAcquireMessage must be BIOMETRIC_ACQUIRED_VENDOR == 6. --> message equals this constant -->
<integer name="config_sidefpsSkipWaitForPowerVendorAcquireMessage">2</integer> <integer name="config_sidefpsSkipWaitForPowerVendorAcquireMessage">2</integer>
<!-- This config is used to force VoiceInteractionService to start on certain low ram devices. <!-- This config is used to force VoiceInteractionService to start on certain low ram devices.

View File

@@ -16,6 +16,7 @@
package com.android.server.biometrics.sensors.fingerprint.aidl; package com.android.server.biometrics.sensors.fingerprint.aidl;
import static android.hardware.biometrics.BiometricFingerprintConstants.FINGERPRINT_ACQUIRED_START;
import static android.hardware.biometrics.BiometricFingerprintConstants.FINGERPRINT_ACQUIRED_VENDOR; import static android.hardware.biometrics.BiometricFingerprintConstants.FINGERPRINT_ACQUIRED_VENDOR;
import android.annotation.NonNull; import android.annotation.NonNull;
@@ -57,6 +58,7 @@ import com.android.server.biometrics.sensors.SensorOverlays;
import com.android.server.biometrics.sensors.fingerprint.PowerPressHandler; import com.android.server.biometrics.sensors.fingerprint.PowerPressHandler;
import com.android.server.biometrics.sensors.fingerprint.Udfps; import com.android.server.biometrics.sensors.fingerprint.Udfps;
import java.time.Clock;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.function.Supplier; import java.util.function.Supplier;
@@ -88,7 +90,9 @@ class FingerprintAuthenticationClient extends AuthenticationClient<AidlSession>
private long mWaitForAuthKeyguard; private long mWaitForAuthKeyguard;
private long mWaitForAuthBp; private long mWaitForAuthBp;
private long mIgnoreAuthFor; private long mIgnoreAuthFor;
private long mSideFpsLastAcquireStartTime;
private Runnable mAuthSuccessRunnable; private Runnable mAuthSuccessRunnable;
private final Clock mClock;
FingerprintAuthenticationClient( FingerprintAuthenticationClient(
@NonNull Context context, @NonNull Context context,
@@ -112,7 +116,8 @@ class FingerprintAuthenticationClient extends AuthenticationClient<AidlSession>
@Nullable ISidefpsController sidefpsController, @Nullable ISidefpsController sidefpsController,
boolean allowBackgroundAuthentication, boolean allowBackgroundAuthentication,
@NonNull FingerprintSensorPropertiesInternal sensorProps, @NonNull FingerprintSensorPropertiesInternal sensorProps,
@NonNull Handler handler) { @NonNull Handler handler,
@NonNull Clock clock) {
super( super(
context, context,
lazyDaemon, lazyDaemon,
@@ -154,6 +159,8 @@ class FingerprintAuthenticationClient extends AuthenticationClient<AidlSession>
mSkipWaitForPowerVendorAcquireMessage = mSkipWaitForPowerVendorAcquireMessage =
context.getResources().getInteger( context.getResources().getInteger(
R.integer.config_sidefpsSkipWaitForPowerVendorAcquireMessage); R.integer.config_sidefpsSkipWaitForPowerVendorAcquireMessage);
mSideFpsLastAcquireStartTime = -1;
mClock = clock;
if (mSensorProps.isAnySidefpsType()) { if (mSensorProps.isAnySidefpsType()) {
if (Build.isDebuggable()) { if (Build.isDebuggable()) {
@@ -235,8 +242,14 @@ class FingerprintAuthenticationClient extends AuthenticationClient<AidlSession>
return; return;
} }
delay = isKeyguard() ? mWaitForAuthKeyguard : mWaitForAuthBp; delay = isKeyguard() ? mWaitForAuthKeyguard : mWaitForAuthBp;
Slog.i(TAG, "(sideFPS) Auth succeeded, sideFps waiting for power for: "
+ delay + "ms"); if (mSideFpsLastAcquireStartTime != -1) {
delay = Math.max(0,
delay - (mClock.millis() - mSideFpsLastAcquireStartTime));
}
Slog.i(TAG, "(sideFPS) Auth succeeded, sideFps "
+ "waiting for power until: " + delay + "ms");
} }
if (mHandler.hasMessages(MESSAGE_FINGER_UP)) { if (mHandler.hasMessages(MESSAGE_FINGER_UP)) {
@@ -260,13 +273,15 @@ class FingerprintAuthenticationClient extends AuthenticationClient<AidlSession>
mSensorOverlays.ifUdfps(controller -> controller.onAcquired(getSensorId(), acquiredInfo)); mSensorOverlays.ifUdfps(controller -> controller.onAcquired(getSensorId(), acquiredInfo));
super.onAcquired(acquiredInfo, vendorCode); super.onAcquired(acquiredInfo, vendorCode);
if (mSensorProps.isAnySidefpsType()) { if (mSensorProps.isAnySidefpsType()) {
if (acquiredInfo == FINGERPRINT_ACQUIRED_START) {
mSideFpsLastAcquireStartTime = mClock.millis();
}
final boolean shouldLookForVendor = final boolean shouldLookForVendor =
mSkipWaitForPowerAcquireMessage == FINGERPRINT_ACQUIRED_VENDOR; mSkipWaitForPowerAcquireMessage == FINGERPRINT_ACQUIRED_VENDOR;
final boolean acquireMessageMatch = acquiredInfo == mSkipWaitForPowerAcquireMessage; final boolean acquireMessageMatch = acquiredInfo == mSkipWaitForPowerAcquireMessage;
final boolean vendorMessageMatch = vendorCode == mSkipWaitForPowerVendorAcquireMessage; final boolean vendorMessageMatch = vendorCode == mSkipWaitForPowerVendorAcquireMessage;
final boolean ignorePowerPress = final boolean ignorePowerPress =
(acquireMessageMatch && !shouldLookForVendor) || (shouldLookForVendor acquireMessageMatch && (!shouldLookForVendor || vendorMessageMatch);
&& acquireMessageMatch && vendorMessageMatch);
if (ignorePowerPress) { if (ignorePowerPress) {
Slog.d(TAG, "(sideFPS) onFingerUp"); Slog.d(TAG, "(sideFPS) onFingerUp");

View File

@@ -47,6 +47,7 @@ import android.os.IBinder;
import android.os.Looper; import android.os.Looper;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.ServiceManager; import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.UserManager; import android.os.UserManager;
import android.util.Slog; import android.util.Slog;
import android.util.SparseArray; import android.util.SparseArray;
@@ -447,7 +448,8 @@ public class FingerprintProvider implements IBinder.DeathRecipient, ServiceProvi
mBiometricContext, isStrongBiometric, mBiometricContext, isStrongBiometric,
mTaskStackListener, mSensors.get(sensorId).getLockoutCache(), mTaskStackListener, mSensors.get(sensorId).getLockoutCache(),
mUdfpsOverlayController, mSidefpsController, allowBackgroundAuthentication, mUdfpsOverlayController, mSidefpsController, allowBackgroundAuthentication,
mSensors.get(sensorId).getSensorProperties(), mHandler); mSensors.get(sensorId).getSensorProperties(), mHandler,
SystemClock.elapsedRealtimeClock());
scheduleForSensor(sensorId, client, mBiometricStateCallback); scheduleForSensor(sensorId, client, mBiometricStateCallback);
}); });
} }

View File

@@ -41,6 +41,7 @@ import android.hardware.biometrics.common.OperationContext;
import android.hardware.biometrics.fingerprint.ISession; import android.hardware.biometrics.fingerprint.ISession;
import android.hardware.biometrics.fingerprint.PointerContext; import android.hardware.biometrics.fingerprint.PointerContext;
import android.hardware.fingerprint.Fingerprint; import android.hardware.fingerprint.Fingerprint;
import android.hardware.fingerprint.FingerprintManager;
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal; import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
import android.hardware.fingerprint.ISidefpsController; import android.hardware.fingerprint.ISidefpsController;
import android.hardware.fingerprint.IUdfpsOverlayController; import android.hardware.fingerprint.IUdfpsOverlayController;
@@ -73,6 +74,7 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule; import org.mockito.junit.MockitoRule;
import java.time.Clock;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.Consumer; import java.util.function.Consumer;
@@ -128,6 +130,8 @@ public class FingerprintAuthenticationClientTest {
private ICancellationSignal mCancellationSignal; private ICancellationSignal mCancellationSignal;
@Mock @Mock
private Probe mLuxProbe; private Probe mLuxProbe;
@Mock
private Clock mClock;
@Captor @Captor
private ArgumentCaptor<OperationContext> mOperationContextCaptor; private ArgumentCaptor<OperationContext> mOperationContextCaptor;
@Captor @Captor
@@ -446,6 +450,52 @@ public class FingerprintAuthenticationClientTest {
verify(mCallback).onClientFinished(any(), eq(true)); verify(mCallback).onClientFinished(any(), eq(true));
} }
@Test
public void sideFingerprintSkipsWindowIfVendorMessageMatch() throws Exception {
when(mSensorProps.isAnySidefpsType()).thenReturn(true);
final int vendorAcquireMessage = 1234;
mContext.getOrCreateTestableResources().addOverride(
R.integer.config_sidefpsSkipWaitForPowerAcquireMessage,
FingerprintManager.FINGERPRINT_ACQUIRED_VENDOR);
mContext.getOrCreateTestableResources().addOverride(
R.integer.config_sidefpsSkipWaitForPowerVendorAcquireMessage,
vendorAcquireMessage);
final FingerprintAuthenticationClient client = createClient(1);
client.start(mCallback);
mLooper.dispatchAll();
client.onAuthenticated(new Fingerprint("friendly", 4 /* fingerId */, 5 /* deviceId */),
true /* authenticated */, new ArrayList<>());
client.onAcquired(FingerprintManager.FINGERPRINT_ACQUIRED_VENDOR, vendorAcquireMessage);
mLooper.dispatchAll();
verify(mCallback).onClientFinished(any(), eq(true));
}
@Test
public void sideFingerprintDoesNotSkipWindowOnVendorErrorMismatch() throws Exception {
when(mSensorProps.isAnySidefpsType()).thenReturn(true);
final int vendorAcquireMessage = 1234;
mContext.getOrCreateTestableResources().addOverride(
R.integer.config_sidefpsSkipWaitForPowerAcquireMessage,
FingerprintManager.FINGERPRINT_ACQUIRED_VENDOR);
mContext.getOrCreateTestableResources().addOverride(
R.integer.config_sidefpsSkipWaitForPowerVendorAcquireMessage,
vendorAcquireMessage);
final FingerprintAuthenticationClient client = createClient(1);
client.start(mCallback);
mLooper.dispatchAll();
client.onAuthenticated(new Fingerprint("friendly", 4 /* fingerId */, 5 /* deviceId */),
true /* authenticated */, new ArrayList<>());
client.onAcquired(FingerprintManager.FINGERPRINT_ACQUIRED_VENDOR, 1);
mLooper.dispatchAll();
verify(mCallback, never()).onClientFinished(any(), anyBoolean());
}
@Test @Test
public void sideFingerprintSendsAuthIfFingerUp() throws Exception { public void sideFingerprintSendsAuthIfFingerUp() throws Exception {
when(mSensorProps.isAnySidefpsType()).thenReturn(true); when(mSensorProps.isAnySidefpsType()).thenReturn(true);
@@ -493,6 +543,79 @@ public class FingerprintAuthenticationClientTest {
verify(mCallback).onClientFinished(any(), eq(true)); verify(mCallback).onClientFinished(any(), eq(true));
} }
@Test
public void sideFingerprintPowerWindowStartsOnAcquireStart() throws Exception {
final int powerWindow = 500;
final long authStart = 300;
when(mSensorProps.isAnySidefpsType()).thenReturn(true);
mContext.getOrCreateTestableResources().addOverride(
R.integer.config_sidefpsBpPowerPressWindow, powerWindow);
final FingerprintAuthenticationClient client = createClient(1);
client.start(mCallback);
// Acquire start occurs at time = 0ms
when(mClock.millis()).thenReturn(0L);
client.onAcquired(FingerprintManager.FINGERPRINT_ACQUIRED_START, 0 /* vendorCode */);
// Auth occurs at time = 300
when(mClock.millis()).thenReturn(authStart);
// At this point the delay should be 500 - (300 - 0) == 200 milliseconds.
client.onAuthenticated(new Fingerprint("friendly", 4 /* fingerId */, 5 /* deviceId */),
true /* authenticated */, new ArrayList<>());
mLooper.dispatchAll();
verify(mCallback, never()).onClientFinished(any(), anyBoolean());
// After waiting 200 milliseconds, auth should succeed.
mLooper.moveTimeForward(powerWindow - authStart);
mLooper.dispatchAll();
verify(mCallback).onClientFinished(any(), eq(true));
}
@Test
public void sideFingerprintPowerWindowStartsOnLastAcquireStart() throws Exception {
final int powerWindow = 500;
when(mSensorProps.isAnySidefpsType()).thenReturn(true);
mContext.getOrCreateTestableResources().addOverride(
R.integer.config_sidefpsBpPowerPressWindow, powerWindow);
final FingerprintAuthenticationClient client = createClient(1);
client.start(mCallback);
// Acquire start occurs at time = 0ms
when(mClock.millis()).thenReturn(0L);
client.onAcquired(FingerprintManager.FINGERPRINT_ACQUIRED_START, 0 /* vendorCode */);
// Auth reject occurs at time = 300ms
when(mClock.millis()).thenReturn(300L);
client.onAuthenticated(new Fingerprint("friendly", 4 /* fingerId */, 5 /* deviceId */),
false /* authenticated */, new ArrayList<>());
mLooper.dispatchAll();
mLooper.moveTimeForward(300);
mLooper.dispatchAll();
verify(mCallback, never()).onClientFinished(any(), anyBoolean());
when(mClock.millis()).thenReturn(1300L);
client.onAcquired(FingerprintManager.FINGERPRINT_ACQUIRED_START, 0 /* vendorCode */);
// If code is correct, the new acquired start timestamp should be used
// and the code should only have to wait 500 - (1500-1300)ms.
when(mClock.millis()).thenReturn(1500L);
client.onAuthenticated(new Fingerprint("friendly", 4 /* fingerId */, 5 /* deviceId */),
true /* authenticated */, new ArrayList<>());
mLooper.dispatchAll();
mLooper.moveTimeForward(299);
mLooper.dispatchAll();
verify(mCallback, never()).onClientFinished(any(), anyBoolean());
mLooper.moveTimeForward(1);
mLooper.dispatchAll();
verify(mCallback).onClientFinished(any(), eq(true));
}
private FingerprintAuthenticationClient createClient() throws RemoteException { private FingerprintAuthenticationClient createClient() throws RemoteException {
return createClient(100 /* version */, true /* allowBackgroundAuthentication */); return createClient(100 /* version */, true /* allowBackgroundAuthentication */);
} }
@@ -520,7 +643,7 @@ public class FingerprintAuthenticationClientTest {
null /* taskStackListener */, mLockoutCache, null /* taskStackListener */, mLockoutCache,
mUdfpsOverlayController, mSideFpsController, allowBackgroundAuthentication, mUdfpsOverlayController, mSideFpsController, allowBackgroundAuthentication,
mSensorProps, mSensorProps,
new Handler(mLooper.getLooper())) { new Handler(mLooper.getLooper()), mClock) {
@Override @Override
protected ActivityTaskManager getActivityTaskManager() { protected ActivityTaskManager getActivityTaskManager() {
return mActivityTaskManager; return mActivityTaskManager;