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

Commit 95d30241 authored by Kevin Chyn's avatar Kevin Chyn
Browse files

Update IBiometricSensorReceiver with sensorId

We should first remove halDeviceId since it's not used and adds
confusion.

Bug: 149067920
Test: atest com.android.server.biometrics
Test: enroll, auth (lockscreen), remove on fingerprint/face devices
Test: BiometricPromptDemo on fingerprint/face devices

Change-Id: Ic57ed3307225ae2653f8f83308a4119346428c26
parent e6bdee20
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -24,10 +24,10 @@ oneway interface IBiometricSensorReceiver {
    // the auth token must be submitted into KeyStore.
    void onAuthenticationSucceeded(int sensorId, in byte[] token);
    // Notify BiometricService authentication was rejected.
    void onAuthenticationFailed();
    void onAuthenticationFailed(int sensorId);
    // Notify BiometricService than an error has occured. Forward to the correct receiver depending
    // on the cookie.
    void onError(int cookie, int modality, int error, int vendorCode);
    void onError(int sensorId, int cookie, int error, int vendorCode);
    // Notifies that a biometric has been acquired.
    void onAcquired(int acquiredInfo, String message);
    void onAcquired(int sensorId, int acquiredInfo, String message);
}
+17 −6
Original line number Diff line number Diff line
@@ -296,8 +296,8 @@ final class AuthSession {
    /**
     * @return true if this AuthSession is finished, e.g. should be set to null.
     */
    boolean onErrorReceived(int cookie, @BiometricAuthenticator.Modality int modality,
            int error, int vendorCode) throws RemoteException {
    boolean onErrorReceived(int sensorId, int cookie, @BiometricConstants.Errors int error,
            int vendorCode) throws RemoteException {

        if (!containsCookie(cookie)) {
            Slog.e(TAG, "Unknown/expired cookie: " + cookie);
@@ -315,6 +315,8 @@ final class AuthSession {
        mErrorEscrow = error;
        mVendorCodeEscrow = vendorCode;

        final @BiometricAuthenticator.Modality int modality = sensorIdToModality(sensorId);

        switch (mState) {
            case STATE_AUTH_CALLED: {
                // If any error is received while preparing the auth session (lockout, etc),
@@ -386,7 +388,7 @@ final class AuthSession {
        return false;
    }

    void onAcquired(int acquiredInfo, String message) {
    void onAcquired(int sensorId, int acquiredInfo, String message) {
        if (message == null) {
            Slog.w(TAG, "Ignoring null message: " + acquiredInfo);
            return;
@@ -471,10 +473,9 @@ final class AuthSession {
        }
    }

    void onAuthenticationTimedOut(@BiometricAuthenticator.Modality int modality, int error,
            int vendorCode) {
    void onAuthenticationTimedOut(int sensorId, int cookie, int error, int vendorCode) {
        try {
            mStatusBarService.onBiometricError(modality, error, vendorCode);
            mStatusBarService.onBiometricError(sensorIdToModality(sensorId), error, vendorCode);
            mState = STATE_AUTH_PAUSED;
        } catch (RemoteException e) {
            Slog.e(TAG, "RemoteException", e);
@@ -695,6 +696,16 @@ final class AuthSession {
        return modality;
    }

    private @BiometricAuthenticator.Modality int sensorIdToModality(int sensorId) {
        for (BiometricSensor sensor : mPreAuthInfo.eligibleSensors) {
            if (sensorId == sensor.id) {
                return sensor.modality;
            }
        }
        Slog.e(TAG, "Unknown sensor: " + sensorId);
        return TYPE_NONE;
    }

    @Override
    public String toString() {
        return "State: " + mState
+1 −1
Original line number Diff line number Diff line
@@ -219,7 +219,7 @@ public abstract class AuthenticationClient extends ClientMonitor {
                    // will show briefly and be replaced by "device locked out" message.
                    if (listener != null) {
                        if (isBiometricPrompt()) {
                            listener.onAuthenticationFailedInternal();
                            listener.onAuthenticationFailedInternal(getSensorId());
                        } else {
                            listener.onAuthenticationFailed();
                        }
+34 −27
Original line number Diff line number Diff line
@@ -137,8 +137,8 @@ public class BiometricService extends SystemService {
                case MSG_ON_ERROR: {
                    SomeArgs args = (SomeArgs) msg.obj;
                    handleOnError(
                            args.argi1 /* cookie */,
                            args.argi2 /* modality */,
                            args.argi1 /* sensorId */,
                            args.argi2 /* cookie */,
                            args.argi3 /* error */,
                            args.argi4 /* vendorCode */);
                    args.recycle();
@@ -148,7 +148,8 @@ public class BiometricService extends SystemService {
                case MSG_ON_ACQUIRED: {
                    SomeArgs args = (SomeArgs) msg.obj;
                    handleOnAcquired(
                            args.argi1 /* acquiredInfo */,
                            args.argi1 /* sensorId */,
                            args.argi2 /* acquiredInfo */,
                            (String) args.arg1 /* message */);
                    args.recycle();
                    break;
@@ -196,9 +197,10 @@ public class BiometricService extends SystemService {
                case MSG_ON_AUTHENTICATION_TIMED_OUT: {
                    SomeArgs args = (SomeArgs) msg.obj;
                    handleAuthenticationTimedOut(
                            args.argi1 /* modality */,
                            args.argi2 /* error */,
                            args.argi3 /* vendorCode */);
                            args.argi1 /* sensorId */,
                            args.argi2 /* cookie */,
                            args.argi3 /* error */,
                            args.argi4 /* vendorCode */);
                    args.recycle();
                    break;
                }
@@ -373,8 +375,7 @@ public class BiometricService extends SystemService {
    @VisibleForTesting
    final IBiometricSensorReceiver mBiometricSensorReceiver = new IBiometricSensorReceiver.Stub() {
        @Override
        public void onAuthenticationSucceeded(int sensorId,
                byte[] token) {
        public void onAuthenticationSucceeded(int sensorId, byte[] token) {
            SomeArgs args = SomeArgs.obtain();
            args.argi1 = sensorId;
            args.arg1 = token;
@@ -382,27 +383,28 @@ public class BiometricService extends SystemService {
        }

        @Override
        public void onAuthenticationFailed() {
        public void onAuthenticationFailed(int sensorId) {
            Slog.v(TAG, "onAuthenticationFailed");
            mHandler.obtainMessage(MSG_ON_AUTHENTICATION_REJECTED).sendToTarget();
        }

        @Override
        public void onError(int cookie, @BiometricAuthenticator.Modality int modality,
                @BiometricConstants.Errors int error, int vendorCode) {
        public void onError(int sensorId, int cookie, @BiometricConstants.Errors int error,
                int vendorCode) {
            // Determine if error is hard or soft error. Certain errors (such as TIMEOUT) are
            // soft errors and we should allow the user to try authenticating again instead of
            // dismissing BiometricPrompt.
            if (error == BiometricConstants.BIOMETRIC_ERROR_TIMEOUT) {
                SomeArgs args = SomeArgs.obtain();
                args.argi1 = modality;
                args.argi2 = error;
                args.argi3 = vendorCode;
                args.argi1 = sensorId;
                args.argi2 = cookie;
                args.argi3 = error;
                args.argi4 = vendorCode;
                mHandler.obtainMessage(MSG_ON_AUTHENTICATION_TIMED_OUT, args).sendToTarget();
            } else {
                SomeArgs args = SomeArgs.obtain();
                args.argi1 = cookie;
                args.argi2 = modality;
                args.argi1 = sensorId;
                args.argi2 = cookie;
                args.argi3 = error;
                args.argi4 = vendorCode;
                mHandler.obtainMessage(MSG_ON_ERROR, args).sendToTarget();
@@ -410,9 +412,10 @@ public class BiometricService extends SystemService {
        }

        @Override
        public void onAcquired(int acquiredInfo, String message) {
        public void onAcquired(int sensorId, int acquiredInfo, String message) {
            SomeArgs args = SomeArgs.obtain();
            args.argi1 = acquiredInfo;
            args.argi1 = sensorId;
            args.argi2 = acquiredInfo;
            args.arg1 = message;
            mHandler.obtainMessage(MSG_ON_ACQUIRED, args).sendToTarget();
        }
@@ -865,8 +868,9 @@ public class BiometricService extends SystemService {
        mCurrentAuthSession.onAuthenticationRejected();
    }

    private void handleAuthenticationTimedOut(int modality, int error, int vendorCode) {
        Slog.v(TAG, "handleAuthenticationTimedOut(), modality: " + modality
    private void handleAuthenticationTimedOut(int sensorId, int cookie, int error, int vendorCode) {
        Slog.v(TAG, "handleAuthenticationTimedOut(), sensorId: " + sensorId
                + ", cookie: " + cookie
                + ", error: " + error
                + ", vendorCode: " + vendorCode);
        // Should never happen, log this to catch bad HAL behavior (e.g. auth succeeded
@@ -876,12 +880,15 @@ public class BiometricService extends SystemService {
            return;
        }

        mCurrentAuthSession.onAuthenticationTimedOut(modality, error, vendorCode);
        mCurrentAuthSession.onAuthenticationTimedOut(sensorId, cookie, error, vendorCode);
    }

    private void handleOnError(int cookie, @BiometricAuthenticator.Modality int modality,
            @BiometricConstants.Errors int error, int vendorCode) {
        Slog.d(TAG, "handleOnError: " + error + " cookie: " + cookie);
    private void handleOnError(int sensorId, int cookie, @BiometricConstants.Errors int error,
            int vendorCode) {
        Slog.d(TAG, "handleOnError() sensorId: " + sensorId
                + ", cookie: " + cookie
                + ", error: " + error
                + ", vendorCode: " + vendorCode);

        if (mCurrentAuthSession == null) {
            Slog.e(TAG, "handleOnError: AuthSession is null");
@@ -890,7 +897,7 @@ public class BiometricService extends SystemService {

        try {
            final boolean finished = mCurrentAuthSession
                    .onErrorReceived(cookie, modality, error, vendorCode);
                    .onErrorReceived(sensorId, cookie, error, vendorCode);
            if (finished) {
                Slog.d(TAG, "handleOnError: AuthSession finished");
                mCurrentAuthSession = null;
@@ -900,7 +907,7 @@ public class BiometricService extends SystemService {
        }
    }

    private void handleOnAcquired(int acquiredInfo, String message) {
    private void handleOnAcquired(int sensorId, int acquiredInfo, String message) {
        // Should never happen, log this to catch bad HAL behavior (e.g. auth succeeded
        // after user dismissed/canceled dialog).
        if (mCurrentAuthSession == null) {
@@ -908,7 +915,7 @@ public class BiometricService extends SystemService {
            return;
        }

        mCurrentAuthSession.onAcquired(acquiredInfo, message);
        mCurrentAuthSession.onAcquired(sensorId, acquiredInfo, message);
    }

    private void handleOnDismissed(@BiometricPrompt.DismissedReason int reason,
+6 −6
Original line number Diff line number Diff line
@@ -421,7 +421,7 @@ public abstract class BiometricServiceBase extends SystemService
        default void onEnrollResult(BiometricAuthenticator.Identifier identifier,
                int remaining) throws RemoteException {};

        void onAcquired(int acquiredInfo, int vendorCode) throws RemoteException;
        void onAcquired(int sensorId, int acquiredInfo, int vendorCode) throws RemoteException;

        default void onAuthenticationSucceeded(BiometricAuthenticator.Identifier biometric,
                int userId) throws RemoteException {
@@ -437,7 +437,7 @@ public abstract class BiometricServiceBase extends SystemService
            throw new UnsupportedOperationException("Stub!");
        }

        default void onAuthenticationFailedInternal()
        default void onAuthenticationFailedInternal(int sensorId)
                throws RemoteException {
            throw new UnsupportedOperationException("Stub!");
        }
@@ -474,10 +474,10 @@ public abstract class BiometricServiceBase extends SystemService
        }

        @Override
        public void onAuthenticationFailedInternal()
        public void onAuthenticationFailedInternal(int sensorId)
                throws RemoteException {
            if (getWrapperReceiver() != null) {
                getWrapperReceiver().onAuthenticationFailed();
                getWrapperReceiver().onAuthenticationFailed(sensorId);
            }
        }
    }
@@ -715,9 +715,9 @@ public abstract class BiometricServiceBase extends SystemService
     * Callback handlers from the daemon. The caller must put this on a handler.
     */

    protected void handleAcquired(long deviceId, int acquiredInfo, int vendorCode) {
    protected void handleAcquired(int sensorId, int acquiredInfo, int vendorCode) {
        ClientMonitor client = mCurrentClient;
        if (client != null && client.onAcquired(acquiredInfo, vendorCode)) {
        if (client != null && client.onAcquired(sensorId, acquiredInfo, vendorCode)) {
            removeClient(client);
        }
        if (mPerformanceStats != null && getLockoutMode() == AuthenticationClient.LOCKOUT_NONE
Loading