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

Commit e1d3de09 authored by Joe Bolinger's avatar Joe Bolinger Committed by Automerger Merge Worker
Browse files

Merge "Add options to face and fingerprint manager internal APIs." into udc-dev am: b5104b15

parents 6456f3df b5104b15
Loading
Loading
Loading
Loading
+77 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.hardware.biometrics;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * Common authentication options that are exposed across all modalities.
 *
 * @hide
 */
public interface AuthenticateOptions  {

    /** The user id for this operation. */
    int getUserId();

    /** The sensor id for this operation. */
    int getSensorId();

    /** The state is unknown. */
    int DISPLAY_STATE_UNKNOWN = 0;

    /** The display is on and showing the lockscreen (or an occluding app). */
    int DISPLAY_STATE_LOCKSCREEN = 1;

    /** The display is off or dozing. */
    int DISPLAY_STATE_NO_UI = 2;

    /** The display is showing a screensaver (dreaming). */
    int DISPLAY_STATE_SCREENSAVER = 3;

    /** The display is dreaming with always on display. */
    int DISPLAY_STATE_AOD = 4;

    /** The doze state of the device. */
    @IntDef(prefix = "DISPLAY_STATE_", value = {
            DISPLAY_STATE_UNKNOWN,
            DISPLAY_STATE_LOCKSCREEN,
            DISPLAY_STATE_NO_UI,
            DISPLAY_STATE_SCREENSAVER,
            DISPLAY_STATE_AOD
    })
    @Retention(RetentionPolicy.SOURCE)
    @interface DisplayState {}

    /** The current doze state of the device. */
    @DisplayState
    int getDisplayState();

    /**
     * The package name for that operation that should be used for
     * {@link android.app.AppOpsManager} verification.
     */
    @NonNull String getOpPackageName();

    /** The attribution tag, if any. */
    @Nullable String getAttributionTag();
}
+19 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.hardware.face;

parcelable FaceAuthenticateOptions;
+624 −0

File added.

Preview size limit exceeded, changes collapsed.

+28 −11
Original line number Diff line number Diff line
@@ -194,18 +194,30 @@ public class FaceManager implements BiometricAuthenticator, BiometricFaceConstan
    }

    /**
     * Request authentication of a crypto object. This call operates the face recognition hardware
     * and starts capturing images. It terminates when
     * @deprecated use {@link #authenticate(CryptoObject, CancellationSignal, AuthenticationCallback, Handler, FaceAuthenticateOptions)}.
     */
    @Deprecated
    @RequiresPermission(USE_BIOMETRIC_INTERNAL)
    public void authenticate(@Nullable CryptoObject crypto, @Nullable CancellationSignal cancel,
            @NonNull AuthenticationCallback callback, @Nullable Handler handler, int userId) {
        authenticate(crypto, cancel, callback, handler, new FaceAuthenticateOptions.Builder()
                .setUserId(userId)
                .build());
    }

    /**
     * Request authentication. This call operates the face recognition hardware and starts capturing images.
     * It terminates when
     * {@link AuthenticationCallback#onAuthenticationError(int, CharSequence)} or
     * {@link AuthenticationCallback#onAuthenticationSucceeded(AuthenticationResult)} is called, at
     * which point the object is no longer valid. The operation can be canceled by using the
     * provided cancel object.
     *
     * @param crypto   object associated with the call or null if none required.
     * @param crypto   object associated with the call or null if none required
     * @param cancel   an object that can be used to cancel authentication
     * @param callback an object to receive authentication events
     * @param handler  an optional handler to handle callback events
     * @param userId   userId to authenticate for
     * @param options  additional options to customize this request
     * @throws IllegalArgumentException if the crypto operation is not supported or is not backed
     *                                  by
     *                                  <a href="{@docRoot}training/articles/keystore.html">Android
@@ -215,8 +227,8 @@ public class FaceManager implements BiometricAuthenticator, BiometricFaceConstan
     */
    @RequiresPermission(USE_BIOMETRIC_INTERNAL)
    public void authenticate(@Nullable CryptoObject crypto, @Nullable CancellationSignal cancel,
            @NonNull AuthenticationCallback callback, @Nullable Handler handler, int userId,
            boolean isKeyguardBypassEnabled) {
            @NonNull AuthenticationCallback callback, @Nullable Handler handler,
            @NonNull FaceAuthenticateOptions options) {
        if (callback == null) {
            throw new IllegalArgumentException("Must supply an authentication callback");
        }
@@ -226,6 +238,9 @@ public class FaceManager implements BiometricAuthenticator, BiometricFaceConstan
            return;
        }

        options.setOpPackageName(mContext.getOpPackageName());
        options.setAttributionTag(mContext.getAttributionTag());

        if (mService != null) {
            try {
                useHandler(handler);
@@ -233,8 +248,8 @@ public class FaceManager implements BiometricAuthenticator, BiometricFaceConstan
                mCryptoObject = crypto;
                final long operationId = crypto != null ? crypto.getOpId() : 0;
                Trace.beginSection("FaceManager#authenticate");
                final long authId = mService.authenticate(mToken, operationId, userId,
                        mServiceReceiver, mContext.getOpPackageName(), isKeyguardBypassEnabled);
                final long authId = mService.authenticate(
                        mToken, operationId, mServiceReceiver, options);
                if (cancel != null) {
                    cancel.setOnCancelListener(new OnAuthenticationCancelListener(authId));
                }
@@ -258,7 +273,7 @@ public class FaceManager implements BiometricAuthenticator, BiometricFaceConstan
     */
    @RequiresPermission(USE_BIOMETRIC_INTERNAL)
    public void detectFace(@NonNull CancellationSignal cancel,
            @NonNull FaceDetectionCallback callback, int userId) {
            @NonNull FaceDetectionCallback callback, @NonNull FaceAuthenticateOptions options) {
        if (mService == null) {
            return;
        }
@@ -268,11 +283,13 @@ public class FaceManager implements BiometricAuthenticator, BiometricFaceConstan
            return;
        }

        options.setOpPackageName(mContext.getOpPackageName());
        options.setAttributionTag(mContext.getAttributionTag());

        mFaceDetectionCallback = callback;

        try {
            final long authId = mService.detectFace(
                    mToken, userId, mServiceReceiver, mContext.getOpPackageName());
            final long authId = mService.detectFace(mToken, mServiceReceiver, options);
            cancel.setOnCancelListener(new OnFaceDetectionCancelListener(authId));
        } catch (RemoteException e) {
            Slog.w(TAG, "Remote exception when requesting finger detect", e);
+6 −5
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.hardware.biometrics.ITestSessionCallback;
import android.hardware.face.IFaceAuthenticatorsRegisteredCallback;
import android.hardware.face.IFaceServiceReceiver;
import android.hardware.face.Face;
import android.hardware.face.FaceAuthenticateOptions;
import android.hardware.face.FaceSensorPropertiesInternal;
import android.view.Surface;

@@ -52,14 +53,14 @@ interface IFaceService {

    // Authenticate with a face. A requestId is returned that can be used to cancel this operation.
    @EnforcePermission("USE_BIOMETRIC_INTERNAL")
    long authenticate(IBinder token, long operationId, int userId, IFaceServiceReceiver receiver,
            String opPackageName, boolean isKeyguardBypassEnabled);
    long authenticate(IBinder token, long operationId, IFaceServiceReceiver receiver,
            in FaceAuthenticateOptions options);

    // Uses the face hardware to detect for the presence of a face, without giving details
    // about accept/reject/lockout. A requestId is returned that can be used to cancel this
    // operation.
    @EnforcePermission("USE_BIOMETRIC_INTERNAL")
    long detectFace(IBinder token, int userId, IFaceServiceReceiver receiver, String opPackageName);
    long detectFace(IBinder token, IFaceServiceReceiver receiver, in FaceAuthenticateOptions options);

    // This method prepares the service to start authenticating, but doesn't start authentication.
    // This is protected by the MANAGE_BIOMETRIC signatuer permission. This method should only be
@@ -68,8 +69,8 @@ interface IFaceService {
    // startPreparedClient().
    @EnforcePermission("USE_BIOMETRIC_INTERNAL")
    void prepareForAuthentication(int sensorId, boolean requireConfirmation, IBinder token,
            long operationId, int userId, IBiometricSensorReceiver sensorReceiver,
            String opPackageName, long requestId, int cookie,
            long operationId, IBiometricSensorReceiver sensorReceiver,
            in FaceAuthenticateOptions options, long requestId, int cookie,
            boolean allowBackgroundAuthentication);

    // Starts authentication with the previously prepared client.
Loading