Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2c904ea5 authored by Kevin Chyn's avatar Kevin Chyn
Browse files

2/n: Update fingerprint vibration logic

1) adds "mShouldVibrate" as a property for AcquisitionClient.
   Philosophically, all clients that inherit this class should be able
   to decide if haptics occur in onAuthentication*
2) UDFPS AIDL enroll haptic occurs when ACQUIRED_GOOD is received
3) UDFPS AIDL auth haptic continues to happen when success/reject is
   known (documenting reason in the bug below)

Test: manual enroll+auth
Test: atest com.android.server.biometrics
Test: adb shell dumpsys vibrator_manager

Bug: 193089985

Change-Id: I8ae60f99d36a4f49985411001670df3ee108768f
parent 62e3e3ae
Loading
Loading
Loading
Loading
+16 −4
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.hardware.biometrics.BiometricConstants;
import android.media.AudioAttributes;
import android.os.IBinder;
import android.os.PowerManager;
import android.os.Process;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.VibrationEffect;
@@ -49,6 +50,8 @@ public abstract class AcquisitionClient<T> extends HalClientMonitor<T> implement
            VibrationEffect.get(VibrationEffect.EFFECT_DOUBLE_CLICK);

    private final PowerManager mPowerManager;
    // If haptics should occur when auth result (success/reject) is known
    protected final boolean mShouldVibrate;
    private boolean mShouldSendErrorToClient = true;
    private boolean mAlreadyCancelled;

@@ -59,11 +62,12 @@ public abstract class AcquisitionClient<T> extends HalClientMonitor<T> implement

    public AcquisitionClient(@NonNull Context context, @NonNull LazyDaemon<T> lazyDaemon,
            @NonNull IBinder token, @NonNull ClientMonitorCallbackConverter listener, int userId,
            @NonNull String owner, int cookie, int sensorId, int statsModality,
            int statsAction, int statsClient) {
            @NonNull String owner, int cookie, int sensorId, boolean shouldVibrate,
            int statsModality, int statsAction, int statsClient) {
        super(context, lazyDaemon, token, listener, userId, owner, cookie, sensorId, statsModality,
                statsAction, statsClient);
        mPowerManager = context.getSystemService(PowerManager.class);
        mShouldVibrate = shouldVibrate;
    }

    @Override
@@ -191,14 +195,22 @@ public abstract class AcquisitionClient<T> extends HalClientMonitor<T> implement
    protected final void vibrateSuccess() {
        Vibrator vibrator = getContext().getSystemService(Vibrator.class);
        if (vibrator != null) {
            vibrator.vibrate(SUCCESS_VIBRATION_EFFECT, VIBRATION_SONIFICATION_ATTRIBUTES);
            vibrator.vibrate(Process.myUid(),
                    getContext().getOpPackageName(),
                    SUCCESS_VIBRATION_EFFECT,
                    getClass().getSimpleName() + "::success",
                    VIBRATION_SONIFICATION_ATTRIBUTES);
        }
    }

    protected final void vibrateError() {
        Vibrator vibrator = getContext().getSystemService(Vibrator.class);
        if (vibrator != null) {
            vibrator.vibrate(ERROR_VIBRATION_EFFECT, VIBRATION_SONIFICATION_ATTRIBUTES);
            vibrator.vibrate(Process.myUid(),
                    getContext().getOpPackageName(),
                    ERROR_VIBRATION_EFFECT,
                    getClass().getSimpleName() + "::error",
                    VIBRATION_SONIFICATION_ATTRIBUTES);
        }
    }
}
+6 −4
Original line number Diff line number Diff line
@@ -68,9 +68,11 @@ public abstract class AuthenticationClient<T> extends AcquisitionClient<T>
            int targetUserId, long operationId, boolean restricted, @NonNull String owner,
            int cookie, boolean requireConfirmation, int sensorId, boolean isStrongBiometric,
            int statsModality, int statsClient, @Nullable TaskStackListener taskStackListener,
            @NonNull LockoutTracker lockoutTracker, boolean allowBackgroundAuthentication) {
            @NonNull LockoutTracker lockoutTracker, boolean allowBackgroundAuthentication,
            boolean shouldVibrate) {
        super(context, lazyDaemon, token, listener, targetUserId, owner, cookie, sensorId,
                statsModality, BiometricsProtoEnums.ACTION_AUTHENTICATE, statsClient);
                shouldVibrate, statsModality, BiometricsProtoEnums.ACTION_AUTHENTICATE,
                statsClient);
        mIsStrongBiometric = isStrongBiometric;
        mOperationId = operationId;
        mRequireConfirmation = requireConfirmation;
@@ -204,7 +206,7 @@ public abstract class AuthenticationClient<T> extends AcquisitionClient<T>

                mAlreadyDone = true;

                if (listener != null) {
                if (listener != null && mShouldVibrate) {
                    vibrateSuccess();
                }

@@ -250,7 +252,7 @@ public abstract class AuthenticationClient<T> extends AcquisitionClient<T>
                    Slog.w(TAG, "Client not listening");
                }
            } else {
                if (listener != null) {
                if (listener != null && mShouldVibrate) {
                    vibrateError();
                }

+2 −5
Original line number Diff line number Diff line
@@ -38,7 +38,6 @@ public abstract class EnrollClient<T> extends AcquisitionClient<T> {
    protected final byte[] mHardwareAuthToken;
    protected final int mTimeoutSec;
    protected final BiometricUtils mBiometricUtils;
    private final boolean mShouldVibrate;

    private long mEnrollmentStartTimeMs;

@@ -50,15 +49,13 @@ public abstract class EnrollClient<T> extends AcquisitionClient<T> {
    public EnrollClient(@NonNull Context context, @NonNull LazyDaemon<T> lazyDaemon,
            @NonNull IBinder token, @NonNull ClientMonitorCallbackConverter listener, int userId,
            @NonNull byte[] hardwareAuthToken, @NonNull String owner, @NonNull BiometricUtils utils,
            int timeoutSec, int statsModality, int sensorId,
            boolean shouldVibrate) {
            int timeoutSec, int statsModality, int sensorId, boolean shouldVibrate) {
        super(context, lazyDaemon, token, listener, userId, owner, 0 /* cookie */, sensorId,
                statsModality, BiometricsProtoEnums.ACTION_ENROLL,
                shouldVibrate, statsModality, BiometricsProtoEnums.ACTION_ENROLL,
                BiometricsProtoEnums.CLIENT_UNKNOWN);
        mBiometricUtils = utils;
        mHardwareAuthToken = Arrays.copyOf(hardwareAuthToken, hardwareAuthToken.length);
        mTimeoutSec = timeoutSec;
        mShouldVibrate = shouldVibrate;
    }

    public void onEnrollResult(BiometricAuthenticator.Identifier identifier, int remaining) {
+1 −1
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ class FaceAuthenticationClient extends AuthenticationClient<ISession> implements
        super(context, lazyDaemon, token, listener, targetUserId, operationId, restricted,
                owner, cookie, requireConfirmation, sensorId, isStrongBiometric,
                BiometricsProtoEnums.MODALITY_FACE, statsClient, null /* taskStackListener */,
                lockoutCache, allowBackgroundAuthentication);
                lockoutCache, allowBackgroundAuthentication, true /* shouldVibrate */);
        mUsageStats = usageStats;
        mLockoutCache = lockoutCache;
        mNotificationManager = context.getSystemService(NotificationManager.class);
+2 −2
Original line number Diff line number Diff line
@@ -46,8 +46,8 @@ public class FaceDetectClient extends AcquisitionClient<ISession> implements Det
            @NonNull IBinder token, @NonNull ClientMonitorCallbackConverter listener, int userId,
            @NonNull String owner, int sensorId, boolean isStrongBiometric, int statsClient) {
        super(context, lazyDaemon, token, listener, userId, owner, 0 /* cookie */, sensorId,
                BiometricsProtoEnums.MODALITY_FACE, BiometricsProtoEnums.ACTION_AUTHENTICATE,
                statsClient);
                true /* shouldVibrate */, BiometricsProtoEnums.MODALITY_FACE,
                BiometricsProtoEnums.ACTION_AUTHENTICATE, statsClient);
        mIsStrongBiometric = isStrongBiometric;
    }

Loading