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

Commit ee00e617 authored by Diya Bera's avatar Diya Bera Committed by Android (Google) Code Review
Browse files

Merge "Update BiometricContext#subscribe API" into main

parents 6feb0b98 d750153c
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -87,10 +87,30 @@ public interface BiometricContext {
     *
     * @param context context that will be modified when changed
     * @param consumer callback when the context is modified
     *
     * @deprecated instead use {@link BiometricContext#subscribe(OperationContextExt, Consumer,
     *                                                           Consumer, AuthenticateOptions)}
     * TODO (b/294161627): Delete this API once Flags.DE_HIDL is removed.
     */
    @Deprecated
    void subscribe(@NonNull OperationContextExt context,
            @NonNull Consumer<OperationContext> consumer);

    /**
     * Subscribe to context changes and start the HAL operation.
     *
     * Note that this method only notifies for properties that are visible to the HAL.
     *
     * @param context               context that will be modified when changed
     * @param startHalConsumer      callback to start HAL operation after subscription is done
     * @param updateContextConsumer callback when the context is modified
     * @param options               authentication options for updating the context
     */
    void subscribe(@NonNull OperationContextExt context,
            @NonNull Consumer<OperationContext> startHalConsumer,
            @NonNull Consumer<OperationContext> updateContextConsumer,
            @Nullable AuthenticateOptions options);

    /** Unsubscribe from context changes. */
    void unsubscribe(@NonNull OperationContextExt context);

+13 −0
Original line number Diff line number Diff line
@@ -237,6 +237,19 @@ public final class BiometricContextProvider implements BiometricContext {
        }
    }

    @Override
    public void subscribe(@NonNull OperationContextExt context,
            @NonNull Consumer<OperationContext> startHalConsumer,
            @NonNull Consumer<OperationContext> updateContextConsumer,
            @Nullable AuthenticateOptions options) {
        mSubscribers.put(updateContext(context, context.isCrypto()), updateContextConsumer);
        if (options != null) {
            startHalConsumer.accept(context.toAidlContext(options));
        } else {
            startHalConsumer.accept(context.toAidlContext());
        }
    }

    @Override
    public void unsubscribe(@NonNull OperationContextExt context) {
        mSubscribers.remove(context);
+18 −0
Original line number Diff line number Diff line
@@ -94,6 +94,24 @@ public class OperationContextExt {
        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 AuthenticateOptions options) {
        if (options instanceof FaceAuthenticateOptions) {
            return toAidlContext((FaceAuthenticateOptions) options);
        }
        if (options instanceof FingerprintAuthenticateOptions) {
            return toAidlContext((FingerprintAuthenticateOptions) options);
        }
        throw new IllegalStateException("Authenticate options are invalid.");
    }

    /**
     * Gets the subset of the context that can be shared with the HAL and updates
     * it with the given options.
+4 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.Context;
import android.hardware.biometrics.BiometricAuthenticator;
import android.os.IBinder;

import com.android.server.biometrics.Flags;
import com.android.server.biometrics.log.BiometricContext;
import com.android.server.biometrics.log.BiometricLogger;
import com.android.server.biometrics.log.OperationContextExt;
@@ -93,6 +94,9 @@ public abstract class HalClientMonitor<T> extends BaseClientMonitor {
    }

    protected OperationContextExt getOperationContext() {
        if (Flags.deHidl()) {
            return mOperationContext;
        }
        return getBiometricContext().updateContext(mOperationContext, isCryptoOperation());
    }

+33 −1
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.util.Slog;

import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.biometrics.Flags;
import com.android.server.biometrics.Utils;
import com.android.server.biometrics.log.BiometricContext;
import com.android.server.biometrics.log.BiometricLogger;
@@ -152,9 +153,13 @@ public class FaceAuthenticationClient
                onError(BiometricConstants.BIOMETRIC_ERROR_HW_UNAVAILABLE,
                        0 /* vendorCode */);
                mCallback.onClientFinished(this, false /* success */);
            } else {
                if (Flags.deHidl()) {
                    startAuthenticate();
                } else {
                    mCancellationSignal = doAuthenticate();
                }
            }
        } catch (RemoteException e) {
            Slog.e(TAG, "Remote exception when requesting auth", e);
            onError(BiometricFaceConstants.FACE_ERROR_HW_UNAVAILABLE, 0 /* vendorCode */);
@@ -182,6 +187,33 @@ public class FaceAuthenticationClient
        }
    }

    private void startAuthenticate() throws RemoteException {
        final AidlSession session = getFreshDaemon();

        if (session.hasContextMethods()) {
            final OperationContextExt opContext = getOperationContext();
            getBiometricContext().subscribe(opContext, ctx -> {
                try {
                    mCancellationSignal = session.getSession().authenticateWithContext(
                            mOperationId, ctx);
                } catch (RemoteException e) {
                    Slog.e(TAG, "Remote exception when requesting auth", e);
                    onError(BiometricFaceConstants.FACE_ERROR_HW_UNAVAILABLE,
                            0 /* vendorCode */);
                    mCallback.onClientFinished(this, false /* success */);
                }
            }, ctx -> {
                try {
                    session.getSession().onContextChanged(ctx);
                } catch (RemoteException e) {
                    Slog.e(TAG, "Unable to notify context changed", e);
                }
            }, getOptions());
        } else {
            mCancellationSignal = session.getSession().authenticate(mOperationId);
        }
    }

    @Override
    protected void stopHalOperation() {
        unsubscribeBiometricContext();
Loading