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

Commit d2ff7136 authored by Joe Bolinger's avatar Joe Bolinger Committed by Android (Google) Code Review
Browse files

Merge "Propagate wake reason and face auth reason from SysUI to HAL." into udc-dev

parents e97ef045 357c3656
Loading
Loading
Loading
Loading
+121 −1
Original line number Diff line number Diff line
@@ -20,8 +20,13 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Intent;
import android.hardware.biometrics.IBiometricContextListener;
import android.hardware.biometrics.common.AuthenticateReason;
import android.hardware.biometrics.common.OperationContext;
import android.hardware.biometrics.common.OperationReason;
import android.hardware.biometrics.common.WakeReason;
import android.hardware.face.FaceAuthenticateOptions;
import android.hardware.fingerprint.FingerprintAuthenticateOptions;
import android.os.PowerManager;
import android.view.Surface;

/**
@@ -50,12 +55,127 @@ public class OperationContextExt {
        mAidlContext = context;
    }

    /** Gets the subset of the context that can be shared with the HAL. */
    /**
     * Gets the subset of the context that can be shared with the HAL.
     *
     * When starting a new operation use methods like to update & fetch the context:
     * <ul>
     *     <li>{@link #toAidlContext(FaceAuthenticateOptions)}
     *     <li>{@link #toAidlContext(FingerprintAuthenticateOptions)}
     * </ul>
     *
     * Use this method for any subsequent calls to the HAL or for operations that do
     * not accept any options.
     *
     * @return the underlying AIDL context
     */
    @NonNull
    public OperationContext toAidlContext() {
        return mAidlContext;
    }

    /**
     * Gets the subset of the context that can be shared with the HAL and updates
     * it with the given options.
     *
     * @param options authenticate options
     * @return the underlying AIDL context
     */
    @NonNull
    public OperationContext toAidlContext(@NonNull FaceAuthenticateOptions options) {
        mAidlContext.authenticateReason = AuthenticateReason
                .faceAuthenticateReason(getAuthReason(options));
        mAidlContext.wakeReason = getWakeReason(options);

        return mAidlContext;
    }

    /**
     * Gets the subset of the context that can be shared with the HAL and updates
     * it with the given options.
     *
     * @param options authenticate options
     * @return the underlying AIDL context
     */
    @NonNull
    public OperationContext toAidlContext(@NonNull FingerprintAuthenticateOptions options) {
        mAidlContext.authenticateReason = AuthenticateReason
                .fingerprintAuthenticateReason(getAuthReason(options));
        mAidlContext.wakeReason = getWakeReason(options);

        return mAidlContext;
    }

    @AuthenticateReason.Face
    private int getAuthReason(@NonNull FaceAuthenticateOptions options) {
        switch (options.getAuthenticateReason()) {
            case FaceAuthenticateOptions.AUTHENTICATE_REASON_STARTED_WAKING_UP:
                return AuthenticateReason.Face.STARTED_WAKING_UP;
            case FaceAuthenticateOptions.AUTHENTICATE_REASON_PRIMARY_BOUNCER_SHOWN:
                return AuthenticateReason.Face.PRIMARY_BOUNCER_SHOWN;
            case FaceAuthenticateOptions.AUTHENTICATE_REASON_ASSISTANT_VISIBLE:
                return AuthenticateReason.Face.ASSISTANT_VISIBLE;
            case FaceAuthenticateOptions.AUTHENTICATE_REASON_ALTERNATE_BIOMETRIC_BOUNCER_SHOWN:
                return AuthenticateReason.Face.ALTERNATE_BIOMETRIC_BOUNCER_SHOWN;
            case FaceAuthenticateOptions.AUTHENTICATE_REASON_NOTIFICATION_PANEL_CLICKED:
                return AuthenticateReason.Face.NOTIFICATION_PANEL_CLICKED;
            case FaceAuthenticateOptions.AUTHENTICATE_REASON_OCCLUDING_APP_REQUESTED:
                return AuthenticateReason.Face.OCCLUDING_APP_REQUESTED;
            case FaceAuthenticateOptions.AUTHENTICATE_REASON_PICK_UP_GESTURE_TRIGGERED:
                return AuthenticateReason.Face.PICK_UP_GESTURE_TRIGGERED;
            case FaceAuthenticateOptions.AUTHENTICATE_REASON_QS_EXPANDED:
                return AuthenticateReason.Face.QS_EXPANDED;
            case FaceAuthenticateOptions.AUTHENTICATE_REASON_SWIPE_UP_ON_BOUNCER:
                return AuthenticateReason.Face.SWIPE_UP_ON_BOUNCER;
            case FaceAuthenticateOptions.AUTHENTICATE_REASON_UDFPS_POINTER_DOWN:
                return AuthenticateReason.Face.UDFPS_POINTER_DOWN;
            default:
                return AuthenticateReason.Face.UNKNOWN;
        }
    }

    @WakeReason
    private int getWakeReason(@NonNull FaceAuthenticateOptions options) {
        switch (options.getWakeReason()) {
            case PowerManager.WAKE_REASON_POWER_BUTTON:
                return WakeReason.POWER_BUTTON;
            case PowerManager.WAKE_REASON_GESTURE:
                return WakeReason.GESTURE;
            case PowerManager.WAKE_REASON_WAKE_KEY:
                return WakeReason.WAKE_KEY;
            case PowerManager.WAKE_REASON_WAKE_MOTION:
                return WakeReason.WAKE_MOTION;
            case PowerManager.WAKE_REASON_DISPLAY_GROUP_ADDED:
                return WakeReason.DISPLAY_GROUP_ADDED;
            case PowerManager.WAKE_REASON_TAP:
                return WakeReason.TAP;
            case PowerManager.WAKE_REASON_LIFT:
                return WakeReason.LIFT;
            case PowerManager.WAKE_REASON_BIOMETRIC:
                return WakeReason.BIOMETRIC;
            case PowerManager.WAKE_REASON_CAMERA_LAUNCH:
            case PowerManager.WAKE_REASON_HDMI:
            case PowerManager.WAKE_REASON_DISPLAY_GROUP_TURNED_ON:
            case PowerManager.WAKE_REASON_UNFOLD_DEVICE:
            case PowerManager.WAKE_REASON_DREAM_FINISHED:
            case PowerManager.WAKE_REASON_TILT:
            case PowerManager.WAKE_REASON_APPLICATION:
            case PowerManager.WAKE_REASON_PLUGGED_IN:
            default:
                return WakeReason.UNKNOWN;
        }
    }

    @AuthenticateReason.Fingerprint
    private int getAuthReason(@NonNull FingerprintAuthenticateOptions options) {
        return AuthenticateReason.Fingerprint.UNKNOWN;
    }

    @WakeReason
    private int getWakeReason(@NonNull FingerprintAuthenticateOptions options) {
        return WakeReason.UNKNOWN;
    }

    /** {@link OperationContext#id}. */
    public int getId() {
        return mAidlContext.id;
+7 −0
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ public abstract class AuthenticationClient<T, O extends AuthenticateOptions>
    @Nullable
    private final TaskStackListener mTaskStackListener;
    private final LockoutTracker mLockoutTracker;
    private final O mOptions;
    private final boolean mIsRestricted;
    private final boolean mAllowBackgroundAuthentication;
    // TODO: This is currently hard to maintain, as each AuthenticationClient subclass must update
@@ -110,6 +111,7 @@ public abstract class AuthenticationClient<T, O extends AuthenticateOptions>
        mAllowBackgroundAuthentication = allowBackgroundAuthentication;
        mShouldUseLockoutTracker = lockoutTracker != null;
        mSensorStrength = sensorStrength;
        mOptions = options;
    }

    @LockoutTracker.LockoutMode
@@ -151,6 +153,11 @@ public abstract class AuthenticationClient<T, O extends AuthenticateOptions>
        return Utils.isSettings(getContext(), getOwnerString());
    }

    /** The options requested at the start of the operation. */
    protected O getOptions() {
        return mOptions;
    }

    @Override
    protected boolean isCryptoOperation() {
        return mOperationId != 0;
+1 −1
Original line number Diff line number Diff line
@@ -166,7 +166,7 @@ class FaceAuthenticationClient extends AuthenticationClient<AidlSession, FaceAut

        if (session.hasContextMethods()) {
            return session.getSession().authenticateWithContext(
                    mOperationId, getOperationContext().toAidlContext());
                    mOperationId, getOperationContext().toAidlContext(getOptions()));
        } else {
            return session.getSession().authenticate(mOperationId);
        }
+3 −1
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ public class FaceDetectClient extends AcquisitionClient<AidlSession> implements
    private static final String TAG = "FaceDetectClient";

    private final boolean mIsStrongBiometric;
    private final FaceAuthenticateOptions mOptions;
    @Nullable private ICancellationSignal mCancellationSignal;
    @Nullable private SensorPrivacyManager mSensorPrivacyManager;

@@ -74,6 +75,7 @@ public class FaceDetectClient extends AcquisitionClient<AidlSession> implements
        setRequestId(requestId);
        mIsStrongBiometric = isStrongBiometric;
        mSensorPrivacyManager = sensorPrivacyManager;
        mOptions = options;
    }

    @Override
@@ -118,7 +120,7 @@ public class FaceDetectClient extends AcquisitionClient<AidlSession> implements

        if (session.hasContextMethods()) {
            return session.getSession().detectInteractionWithContext(
                    getOperationContext().toAidlContext());
                    getOperationContext().toAidlContext(mOptions));
        } else {
            return session.getSession().detectInteraction();
        }
+1 −1
Original line number Diff line number Diff line
@@ -285,7 +285,7 @@ class FingerprintAuthenticationClient

        if (session.hasContextMethods()) {
            return session.getSession().authenticateWithContext(
                    mOperationId, opContext.toAidlContext());
                    mOperationId, opContext.toAidlContext(getOptions()));
        } else {
            return session.getSession().authenticate(mOperationId);
        }
Loading