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

Commit 05646522 authored by Diya Bera's avatar Diya Bera
Browse files

Add onDetectionError API

Bug: 298458691
Test: atest FaceManagerTest FingerprintManagerTest
Change-Id: Icfdb90c9ee819f913b97f1049e206bdb65a5201b
parent a10767e3
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -1074,6 +1074,14 @@ public class FaceManager implements BiometricAuthenticator, BiometricFaceConstan
     */
    public interface FaceDetectionCallback {
        void onFaceDetected(int sensorId, int userId, boolean isStrongBiometric);

        /**
         * An error has occurred with face detection.
         *
         * This callback signifies that this operation has been completed, and
         * no more callbacks should be expected.
         */
        default void onDetectionError(int errorMsgId) {}
    }

    /**
@@ -1373,6 +1381,9 @@ public class FaceManager implements BiometricAuthenticator, BiometricFaceConstan
        } else if (mRemovalCallback != null) {
            mRemovalCallback.onRemovalError(mRemovalFace, clientErrMsgId,
                    getErrorString(mContext, errMsgId, vendorCode));
        } else if (mFaceDetectionCallback != null) {
            mFaceDetectionCallback.onDetectionError(errMsgId);
            mFaceDetectionCallback = null;
        }
    }

+11 −0
Original line number Diff line number Diff line
@@ -462,6 +462,14 @@ public class FingerprintManager implements BiometricAuthenticator, BiometricFing
         * Invoked when a fingerprint has been detected.
         */
        void onFingerprintDetected(int sensorId, int userId, boolean isStrongBiometric);

        /**
         * An error has occurred with fingerprint detection.
         *
         * This callback signifies that this operation has been completed, and
         * no more callbacks should be expected.
         */
        default void onDetectionError(int errorMsgId) {}
    }

    /**
@@ -1484,6 +1492,9 @@ public class FingerprintManager implements BiometricAuthenticator, BiometricFing
                    ? mRemoveTracker.mSingleFingerprint : null;
            mRemovalCallback.onRemovalError(fp, clientErrMsgId,
                    getErrorString(mContext, errMsgId, vendorCode));
        } else if (mFingerprintDetectionCallback != null) {
            mFingerprintDetectionCallback.onDetectionError(errMsgId);
            mFingerprintDetectionCallback = null;
        }
    }

+19 −0
Original line number Diff line number Diff line
@@ -79,6 +79,8 @@ public class FaceManagerTest {
    private FaceManager.AuthenticationCallback mAuthCallback;
    @Mock
    private FaceManager.EnrollmentCallback mEnrollmentCallback;
    @Mock
    private FaceManager.FaceDetectionCallback mFaceDetectionCallback;

    @Captor
    private ArgumentCaptor<IFaceAuthenticatorsRegisteredCallback> mCaptor;
@@ -191,6 +193,23 @@ public class FaceManagerTest {
                any(), anyString(), any(), any(), anyBoolean());
    }

    @Test
    public void detectClient_onError() throws RemoteException {
        ArgumentCaptor<IFaceServiceReceiver> argumentCaptor =
                ArgumentCaptor.forClass(IFaceServiceReceiver.class);

        CancellationSignal cancellationSignal = new CancellationSignal();
        mFaceManager.detectFace(cancellationSignal, mFaceDetectionCallback,
                new FaceAuthenticateOptions.Builder().build());

        verify(mService).detectFace(any(), argumentCaptor.capture(), any());

        argumentCaptor.getValue().onError(5 /* error */, 0 /* vendorCode */);
        mLooper.dispatchAll();

        verify(mFaceDetectionCallback).onDetectionError(anyInt());
    }

    private void initializeProperties() throws RemoteException {
        verify(mService).addAuthenticatorsRegisteredCallback(mCaptor.capture());

+19 −0
Original line number Diff line number Diff line
@@ -74,6 +74,8 @@ public class FingerprintManagerTest {
    private FingerprintManager.AuthenticationCallback mAuthCallback;
    @Mock
    private FingerprintManager.EnrollmentCallback mEnrollCallback;
    @Mock
    private FingerprintManager.FingerprintDetectionCallback mFingerprintDetectionCallback;

    @Captor
    private ArgumentCaptor<IFingerprintAuthenticatorsRegisteredCallback> mCaptor;
@@ -166,4 +168,21 @@ public class FingerprintManagerTest {
                anyString());
        verify(mService, never()).enroll(any(), any(), anyInt(), any(), anyString(), anyInt());
    }

    @Test
    public void detectClient_onError() throws RemoteException {
        ArgumentCaptor<IFingerprintServiceReceiver> argumentCaptor =
                ArgumentCaptor.forClass(IFingerprintServiceReceiver.class);

        mFingerprintManager.detectFingerprint(new CancellationSignal(),
                mFingerprintDetectionCallback,
                new FingerprintAuthenticateOptions.Builder().build());

        verify(mService).detectFingerprint(any(), argumentCaptor.capture(), any());

        argumentCaptor.getValue().onError(5 /* error */, 0 /* vendorCode */);
        mLooper.dispatchAll();

        verify(mFingerprintDetectionCallback).onDetectionError(anyInt());
    }
}