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

Commit 397b88fc authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add check for NPE in AuthenticationClient" into udc-qpr-dev am: 35759b88 am: d0e2ed05

parents 95085c4e d0e2ed05
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -283,7 +283,11 @@ public abstract class AuthenticationClient<T, O extends AuthenticateOptions>
                }

                try {
                    if (listener != null) {
                        listener.onAuthenticationFailed(getSensorId());
                    } else {
                        Slog.e(TAG, "Received failed auth, but client was not listening");
                    }
                } catch (RemoteException e) {
                    Slog.e(TAG, "Unable to notify listener", e);
                    mCallback.onClientFinished(this, false);
+40 −3
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import static org.mockito.Mockito.when;
import android.app.ActivityManager;
import android.app.ActivityTaskManager;
import android.content.ComponentName;
import android.hardware.biometrics.BiometricManager;
import android.hardware.biometrics.common.AuthenticateReason;
import android.hardware.biometrics.common.ICancellationSignal;
import android.hardware.biometrics.common.OperationContext;
@@ -109,6 +110,8 @@ public class FaceAuthenticationClientTest {
    private ICancellationSignal mCancellationSignal;
    @Mock
    private AuthSessionCoordinator mAuthSessionCoordinator;
    @Mock
    private BiometricManager mBiometricManager;
    @Captor
    private ArgumentCaptor<OperationContextExt> mOperationContextCaptor;
    @Captor
@@ -119,6 +122,7 @@ public class FaceAuthenticationClientTest {

    @Before
    public void setup() {
        mContext.addMockSystemService(BiometricManager.class, mBiometricManager);
        when(mBiometricContext.updateContext(any(), anyBoolean())).thenAnswer(
                i -> i.getArgument(0));
        when(mBiometricContext.getAuthSessionCoordinator()).thenReturn(mAuthSessionCoordinator);
@@ -212,11 +216,44 @@ public class FaceAuthenticationClientTest {
                .onError(anyInt(), anyInt(), eq(BIOMETRIC_ERROR_CANCELED), anyInt());
    }

    @Test
    public void testOnAuthenticatedFalseWhenListenerIsNull() throws RemoteException {
        final FaceAuthenticationClient client = createClientWithNullListener();
        client.start(mCallback);
        client.onAuthenticated(new Face("friendly", 1 /* faceId */, 2 /* deviceId */),
                false /* authenticated */, new ArrayList<>());

        verify(mCallback).onClientFinished(client, true);
    }

    @Test
    public void testOnAuthenticatedTrueWhenListenerIsNull() throws RemoteException {
        final FaceAuthenticationClient client = createClientWithNullListener();
        client.start(mCallback);
        client.onAuthenticated(new Face("friendly", 1 /* faceId */, 2 /* deviceId */),
                true /* authenticated */, new ArrayList<>());

        verify(mCallback).onClientFinished(client, true);
    }

    private FaceAuthenticationClient createClient() throws RemoteException {
        return createClient(2 /* version */);
        return createClient(2 /* version */, mClientMonitorCallbackConverter,
                false /* allowBackgroundAuthentication */);
    }

    private FaceAuthenticationClient createClientWithNullListener() throws RemoteException {
        return createClient(2 /* version */, null /* listener */,
                true /* allowBackgroundAuthentication */);
    }

    private FaceAuthenticationClient createClient(int version) throws RemoteException {
        return createClient(version, mClientMonitorCallbackConverter,
                false /* allowBackgroundAuthentication */);
    }

    private FaceAuthenticationClient createClient(int version,
            ClientMonitorCallbackConverter listener,
            boolean allowBackgroundAuthentication) throws RemoteException {
        when(mHal.getInterfaceVersion()).thenReturn(version);

        final AidlSession aidl = new AidlSession(version, mHal, USER_ID, mHalSessionCallback);
@@ -229,11 +266,11 @@ public class FaceAuthenticationClientTest {
                        FaceAuthenticateOptions.AUTHENTICATE_REASON_ASSISTANT_VISIBLE)
                .build();
        return new FaceAuthenticationClient(mContext, () -> aidl, mToken,
                2 /* requestId */, mClientMonitorCallbackConverter, OP_ID,
                2 /* requestId */, listener, OP_ID,
                false /* restricted */, options, 4 /* cookie */,
                false /* requireConfirmation */,
                mBiometricLogger, mBiometricContext, true /* isStrongBiometric */,
                mUsageStats, null /* mLockoutCache */, false /* allowBackgroundAuthentication */,
                mUsageStats, null /* mLockoutCache */, allowBackgroundAuthentication,
                null /* sensorPrivacyManager */, 0 /* biometricStrength */) {
            @Override
            protected ActivityTaskManager getActivityTaskManager() {
+34 −6
Original line number Diff line number Diff line
@@ -392,7 +392,6 @@ public class FingerprintAuthenticationClientTest {
        final ActivityManager.RunningTaskInfo topTask = new ActivityManager.RunningTaskInfo();
        topTask.topActivity = new ComponentName("other", "thing");
        when(mActivityTaskManager.getTasks(anyInt())).thenReturn(List.of(topTask));
        when(mHal.authenticateWithContext(anyLong(), any())).thenReturn(mCancellationSignal);

        final FingerprintAuthenticationClient client = createClientWithoutBackgroundAuth();
        client.start(mCallback);
@@ -406,21 +405,50 @@ public class FingerprintAuthenticationClientTest {
                .onError(anyInt(), anyInt(), eq(BIOMETRIC_ERROR_CANCELED), anyInt());
    }

    @Test
    public void testOnAuthenticatedFalseWhenListenerIsNull() throws RemoteException {
        final FingerprintAuthenticationClient client = createClientWithNullListener();
        client.start(mCallback);
        client.onAuthenticated(new Fingerprint("friendly", 1 /* fingerId */,
                        2 /* deviceId */), false /* authenticated */, new ArrayList<>());

        verify(mCallback, never()).onClientFinished(eq(client), anyBoolean());
    }

    @Test
    public void testOnAuthenticatedTrueWhenListenerIsNull() throws RemoteException {
        final FingerprintAuthenticationClient client = createClientWithNullListener();
        client.start(mCallback);
        client.onAuthenticated(new Fingerprint("friendly", 1 /* fingerId */,
                2 /* deviceId */), true /* authenticated */, new ArrayList<>());

        verify(mCallback).onClientFinished(client, true);
    }

    private FingerprintAuthenticationClient createClient() throws RemoteException {
        return createClient(100 /* version */, true /* allowBackgroundAuthentication */);
        return createClient(100 /* version */, true /* allowBackgroundAuthentication */,
                mClientMonitorCallbackConverter);
    }

    private FingerprintAuthenticationClient createClientWithoutBackgroundAuth()
            throws RemoteException {
        return createClient(100 /* version */, false /* allowBackgroundAuthentication */);
        return createClient(100 /* version */, false /* allowBackgroundAuthentication */,
                mClientMonitorCallbackConverter);
    }

    private FingerprintAuthenticationClient createClient(int version) throws RemoteException {
        return createClient(version, true /* allowBackgroundAuthentication */);
        return createClient(version, true /* allowBackgroundAuthentication */,
                mClientMonitorCallbackConverter);
    }

    private FingerprintAuthenticationClient createClientWithNullListener() throws RemoteException {
        return createClient(100 /* version */, true /* allowBackgroundAuthentication */,
                null /* listener */);
    }

    private FingerprintAuthenticationClient createClient(int version,
            boolean allowBackgroundAuthentication) throws RemoteException {
            boolean allowBackgroundAuthentication, ClientMonitorCallbackConverter listener)
            throws RemoteException {
        when(mHal.getInterfaceVersion()).thenReturn(version);

        final AidlSession aidl = new AidlSession(version, mHal, USER_ID, mHalSessionCallback);
@@ -430,7 +458,7 @@ public class FingerprintAuthenticationClientTest {
                .setSensorId(9)
                .build();
        return new FingerprintAuthenticationClient(mContext, () -> aidl, mToken,
                REQUEST_ID, mClientMonitorCallbackConverter, OP_ID,
                REQUEST_ID, listener, OP_ID,
                false /* restricted */, options, 4 /* cookie */,
                false /* requireConfirmation */,
                mBiometricLogger, mBiometricContext,