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

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

Merge "Notify caller onError when aborting operation." into sc-dev am: d2a11001

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14924641

Change-Id: I45649c54004d28ac669fe82c6cb67b9516ec0d9b
parents 8b5facf7 d2a11001
Loading
Loading
Loading
Loading
+19 −7
Original line number Original line Diff line number Diff line
@@ -27,6 +27,8 @@ import static android.Manifest.permission.USE_FINGERPRINT;
import static android.hardware.biometrics.BiometricAuthenticator.TYPE_FACE;
import static android.hardware.biometrics.BiometricAuthenticator.TYPE_FACE;
import static android.hardware.biometrics.BiometricAuthenticator.TYPE_FINGERPRINT;
import static android.hardware.biometrics.BiometricAuthenticator.TYPE_FINGERPRINT;
import static android.hardware.biometrics.BiometricAuthenticator.TYPE_IRIS;
import static android.hardware.biometrics.BiometricAuthenticator.TYPE_IRIS;
import static android.hardware.biometrics.BiometricAuthenticator.TYPE_NONE;
import static android.hardware.biometrics.BiometricConstants.BIOMETRIC_ERROR_CANCELED;
import static android.hardware.biometrics.BiometricManager.Authenticators;
import static android.hardware.biometrics.BiometricManager.Authenticators;


import android.annotation.NonNull;
import android.annotation.NonNull;
@@ -76,7 +78,6 @@ import java.util.List;
 */
 */
public class AuthService extends SystemService {
public class AuthService extends SystemService {
    private static final String TAG = "AuthService";
    private static final String TAG = "AuthService";
    private static final boolean DEBUG = false;
    private static final String SETTING_HIDL_DISABLED =
    private static final String SETTING_HIDL_DISABLED =
            "com.android.server.biometrics.AuthService.hidlDisabled";
            "com.android.server.biometrics.AuthService.hidlDisabled";
    private static final int DEFAULT_HIDL_DISABLED = 0;
    private static final int DEFAULT_HIDL_DISABLED = 0;
@@ -208,7 +209,6 @@ public class AuthService extends SystemService {
        public void authenticate(IBinder token, long sessionId, int userId,
        public void authenticate(IBinder token, long sessionId, int userId,
                IBiometricServiceReceiver receiver, String opPackageName, PromptInfo promptInfo)
                IBiometricServiceReceiver receiver, String opPackageName, PromptInfo promptInfo)
                throws RemoteException {
                throws RemoteException {

            // Only allow internal clients to authenticate with a different userId.
            // Only allow internal clients to authenticate with a different userId.
            final int callingUserId = UserHandle.getCallingUserId();
            final int callingUserId = UserHandle.getCallingUserId();
            final int callingUid = Binder.getCallingUid();
            final int callingUid = Binder.getCallingUid();
@@ -222,17 +222,18 @@ public class AuthService extends SystemService {
            }
            }


            if (!checkAppOps(callingUid, opPackageName, "authenticate()")) {
            if (!checkAppOps(callingUid, opPackageName, "authenticate()")) {
                Slog.e(TAG, "Denied by app ops: " + opPackageName);
                authenticateFastFail("Denied by app ops: " + opPackageName, receiver);
                return;
                return;
            }
            }


            if (!Utils.isForeground(callingUid, callingPid)) {
            if (token == null || receiver == null || opPackageName == null || promptInfo == null) {
                Slog.e(TAG, "Caller is not foreground: " + opPackageName);
                authenticateFastFail(
                        "Unable to authenticate, one or more null arguments", receiver);
                return;
                return;
            }
            }


            if (token == null || receiver == null || opPackageName == null || promptInfo == null) {
            if (!Utils.isForeground(callingUid, callingPid)) {
                Slog.e(TAG, "Unable to authenticate, one or more null arguments");
                authenticateFastFail("Caller is not foreground: " + opPackageName, receiver);
                return;
                return;
            }
            }


@@ -257,6 +258,17 @@ public class AuthService extends SystemService {
            }
            }
        }
        }


        private void authenticateFastFail(String message, IBiometricServiceReceiver receiver) {
            // notify caller in cases where authentication is aborted before calling into
            // IBiometricService without raising an exception
            Slog.e(TAG, message);
            try {
                receiver.onError(TYPE_NONE, BIOMETRIC_ERROR_CANCELED, 0 /*vendorCode */);
            } catch (RemoteException e) {
                Slog.e(TAG, "authenticateFastFail failed to notify caller", e);
            }
        }

        @Override
        @Override
        public void cancelAuthentication(IBinder token, String opPackageName)
        public void cancelAuthentication(IBinder token, String opPackageName)
                throws RemoteException {
                throws RemoteException {
+23 −1
Original line number Original line Diff line number Diff line
@@ -16,6 +16,8 @@


package com.android.server.biometrics;
package com.android.server.biometrics;


import static android.hardware.biometrics.BiometricAuthenticator.TYPE_NONE;
import static android.hardware.biometrics.BiometricConstants.BIOMETRIC_ERROR_CANCELED;
import static android.hardware.biometrics.BiometricConstants.BIOMETRIC_SUCCESS;
import static android.hardware.biometrics.BiometricConstants.BIOMETRIC_SUCCESS;


import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertEquals;
@@ -234,6 +236,27 @@ public class AuthServiceTest {
                eq(mReceiver),
                eq(mReceiver),
                eq(TEST_OP_PACKAGE_NAME),
                eq(TEST_OP_PACKAGE_NAME),
                eq(promptInfo));
                eq(promptInfo));
        verify(mReceiver).onError(eq(TYPE_NONE), eq(BIOMETRIC_ERROR_CANCELED), anyInt());
    }

    @Test
    public void testAuthenticate_missingRequiredParam() throws Exception {
        mAuthService = new AuthService(mContext, mInjector);
        mAuthService.onStart();

        final PromptInfo promptInfo = new PromptInfo();
        final long sessionId = 0;
        final int userId = 0;

        mAuthService.mImpl.authenticate(
                null /* token */,
                sessionId,
                userId,
                mReceiver,
                TEST_OP_PACKAGE_NAME,
                promptInfo);
        waitForIdle();
        verify(mReceiver).onError(eq(TYPE_NONE), eq(BIOMETRIC_ERROR_CANCELED), anyInt());
    }
    }


    @Test
    @Test
@@ -259,7 +282,6 @@ public class AuthServiceTest {
                eq(authenticators));
                eq(authenticators));
    }
    }



    @Test
    @Test
    public void testHasEnrolledBiometrics_callsBiometricServiceHasEnrolledBiometrics() throws
    public void testHasEnrolledBiometrics_callsBiometricServiceHasEnrolledBiometrics() throws
            Exception {
            Exception {