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

Commit 40c2f1a3 authored by Joe Bolinger's avatar Joe Bolinger
Browse files

Use new context HAL methods for all biometric operations.

Bug: 204584403
Bug: 204585936
Test: manual (via BP test app)
Test: atest com.android.server.biometrics.sensors
Change-Id: I653cc16595ffbc3346ad5009b4b742cd14aecc12
parent 82a7c8e5
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -54,11 +54,6 @@ public abstract class AcquisitionClient<T> extends HalClientMonitor<T> implement
    private boolean mShouldSendErrorToClient = true;
    private boolean mAlreadyCancelled;

    /**
     * Stops the HAL operation specific to the ClientMonitor subclass.
     */
    protected abstract void stopHalOperation();

    public AcquisitionClient(@NonNull Context context, @NonNull Supplier<T> lazyDaemon,
            @NonNull IBinder token, @NonNull ClientMonitorCallbackConverter listener, int userId,
            @NonNull String owner, int cookie, int sensorId, boolean shouldVibrate,
@@ -69,6 +64,11 @@ public abstract class AcquisitionClient<T> extends HalClientMonitor<T> implement
        mShouldVibrate = shouldVibrate;
    }

    /**
     * Stops the HAL operation specific to the ClientMonitor subclass.
     */
    protected abstract void stopHalOperation();

    @Override
    public void unableToStart() {
        try {
+16 −16
Original line number Diff line number Diff line
@@ -90,22 +90,6 @@ public abstract class AuthenticationClient<T> extends AcquisitionClient<T>
    //  the state. We should think of a way to improve this in the future.
    protected @State int mState = STATE_NEW;

    /**
     * Handles lifecycle, e.g. {@link BiometricScheduler},
     * {@link ClientMonitorCallback} after authentication
     * results are known. Note that this happens asynchronously from (but shortly after)
     * {@link #onAuthenticated(BiometricAuthenticator.Identifier, boolean, ArrayList)} and allows
     * {@link CoexCoordinator} a chance to invoke/delay this event.
     * @param authenticated
     */
    protected abstract void handleLifecycleAfterAuth(boolean authenticated);

    /**
     * @return true if a user was detected (i.e. face was found, fingerprint sensor was touched.
     *         etc)
     */
    public abstract boolean wasUserDetected();

    public AuthenticationClient(@NonNull Context context, @NonNull Supplier<T> lazyDaemon,
            @NonNull IBinder token, @NonNull ClientMonitorCallbackConverter listener,
            int targetUserId, long operationId, boolean restricted, @NonNull String owner,
@@ -475,6 +459,22 @@ public abstract class AuthenticationClient<T> extends AcquisitionClient<T>
        }
    }

    /**
     * Handles lifecycle, e.g. {@link BiometricScheduler},
     * {@link com.android.server.biometrics.sensors.BaseClientMonitor.Callback} after authentication
     * results are known. Note that this happens asynchronously from (but shortly after)
     * {@link #onAuthenticated(BiometricAuthenticator.Identifier, boolean, ArrayList)} and allows
     * {@link CoexCoordinator} a chance to invoke/delay this event.
     * @param authenticated
     */
    protected abstract void handleLifecycleAfterAuth(boolean authenticated);

    /**
     * @return true if a user was detected (i.e. face was found, fingerprint sensor was touched.
     *         etc)
     */
    public abstract boolean wasUserDetected();

    public @State int getState() {
        return mState;
    }
+13 −13
Original line number Diff line number Diff line
@@ -30,18 +30,6 @@ import java.util.function.Supplier;
 */
public abstract class HalClientMonitor<T> extends BaseClientMonitor {
    
    /**
     * Starts the HAL operation specific to the ClientMonitor subclass.
     */
    protected abstract void startHalOperation();

    /**
     * Invoked if the scheduler is unable to start the ClientMonitor (for example the HAL is null).
     * If such a problem is detected, the scheduler will not invoke
     * {@link #start(ClientMonitorCallback)}.
     */
    public abstract void unableToStart();

    @NonNull
    protected final Supplier<T> mLazyDaemon;

@@ -71,4 +59,16 @@ public abstract class HalClientMonitor<T> extends BaseClientMonitor {
    public T getFreshDaemon() {
        return mLazyDaemon.get();
    }

    /**
     * Starts the HAL operation specific to the ClientMonitor subclass.
     */
    protected abstract void startHalOperation();

    /**
     * Invoked if the scheduler is unable to start the ClientMonitor (for example the HAL is null).
     * If such a problem is detected, the scheduler will not invoke
     * {@link #start(ClientMonitorCallback)}.
     */
    public abstract void unableToStart();
}
+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ public abstract class StartUserClient<T, U> extends HalClientMonitor<T> {
     * @param <U> New user object.
     */
    public interface UserStartedCallback<U> {
        void onUserStarted(int newUserId, U newUser);
        void onUserStarted(int newUserId, U newUser, int halInterfaceVersion);
    }

    @NonNull @VisibleForTesting
+66 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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 com.android.server.biometrics.sensors.face.aidl;

import android.annotation.NonNull;
import android.hardware.biometrics.face.ISession;

import static com.android.server.biometrics.sensors.face.aidl.Sensor.HalSessionCallback;

/**
 * A holder for an AIDL {@link ISession} with additional metadata about the current user
 * and the backend.
 */
public class AidlSession {

    private final int mHalInterfaceVersion;
    @NonNull
    private final ISession mSession;
    private final int mUserId;
    @NonNull private final HalSessionCallback mHalSessionCallback;

    public AidlSession(int halInterfaceVersion, @NonNull ISession session, int userId,
            HalSessionCallback halSessionCallback) {
        mHalInterfaceVersion = halInterfaceVersion;
        mSession = session;
        mUserId = userId;
        mHalSessionCallback = halSessionCallback;
    }

    /** The underlying {@link ISession}. */
    @NonNull public ISession getSession() {
        return mSession;
    }

    /** The user id associated with the session. */
    public int getUserId() {
        return mUserId;
    }

    /** The HAL callback, which should only be used in tests {@See BiometricTestSessionImpl}. */
    HalSessionCallback getHalSessionCallback() {
        return mHalSessionCallback;
    }

    /**
     * If this backend implements the *WithContext methods for enroll, authenticate, and
     * detectInteraction. These variants should always be called if they are available.
     */
    public boolean hasContextMethods() {
        return mHalInterfaceVersion >= 2;
    }
}
Loading