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

Commit 8ba50e5c authored by bsears's avatar bsears Committed by Android (Google) Code Review
Browse files

Merge "Revert "Fix enrollment cancelation race conditions.""

parents 3dac8545 f4dc031e
Loading
Loading
Loading
Loading
+22 −27
Original line number Original line Diff line number Diff line
@@ -306,21 +306,22 @@ public class FaceManager implements BiometricAuthenticator, BiometricFaceConstan
            throw new IllegalArgumentException("Must supply an enrollment callback");
            throw new IllegalArgumentException("Must supply an enrollment callback");
        }
        }


        if (cancel != null && cancel.isCanceled()) {
        if (cancel != null) {
            if (cancel.isCanceled()) {
                Slog.w(TAG, "enrollment already canceled");
                Slog.w(TAG, "enrollment already canceled");
                return;
                return;
            } else {
                cancel.setOnCancelListener(new OnEnrollCancelListener());
            }
        }
        }


        if (mService != null) {
        if (mService != null) {
            try {
            try {
                mEnrollmentCallback = callback;
                mEnrollmentCallback = callback;
                Trace.beginSection("FaceManager#enroll");
                Trace.beginSection("FaceManager#enroll");
                final long enrollId = mService.enroll(userId, mToken, hardwareAuthToken,
                mService.enroll(userId, mToken, hardwareAuthToken, mServiceReceiver,
                        mServiceReceiver, mContext.getOpPackageName(), disabledFeatures,
                        mContext.getOpPackageName(), disabledFeatures, previewSurface,
                        previewSurface, debugConsent);
                        debugConsent);
                if (cancel != null) {
                    cancel.setOnCancelListener(new OnEnrollCancelListener(enrollId));
                }
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                Slog.w(TAG, "Remote exception in enroll: ", e);
                Slog.w(TAG, "Remote exception in enroll: ", e);
                // Though this may not be a hardware issue, it will cause apps to give up or
                // Though this may not be a hardware issue, it will cause apps to give up or
@@ -358,20 +359,21 @@ public class FaceManager implements BiometricAuthenticator, BiometricFaceConstan
            throw new IllegalArgumentException("Must supply an enrollment callback");
            throw new IllegalArgumentException("Must supply an enrollment callback");
        }
        }


        if (cancel != null && cancel.isCanceled()) {
        if (cancel != null) {
            if (cancel.isCanceled()) {
                Slog.w(TAG, "enrollRemotely is already canceled.");
                Slog.w(TAG, "enrollRemotely is already canceled.");
                return;
                return;
            } else {
                cancel.setOnCancelListener(new OnEnrollCancelListener());
            }
        }
        }


        if (mService != null) {
        if (mService != null) {
            try {
            try {
                mEnrollmentCallback = callback;
                mEnrollmentCallback = callback;
                Trace.beginSection("FaceManager#enrollRemotely");
                Trace.beginSection("FaceManager#enrollRemotely");
                final long enrolId = mService.enrollRemotely(userId, mToken, hardwareAuthToken,
                mService.enrollRemotely(userId, mToken, hardwareAuthToken, mServiceReceiver,
                        mServiceReceiver, mContext.getOpPackageName(), disabledFeatures);
                        mContext.getOpPackageName(), disabledFeatures);
                if (cancel != null) {
                    cancel.setOnCancelListener(new OnEnrollCancelListener(enrolId));
                }
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                Slog.w(TAG, "Remote exception in enrollRemotely: ", e);
                Slog.w(TAG, "Remote exception in enrollRemotely: ", e);
                // Though this may not be a hardware issue, it will cause apps to give up or
                // Though this may not be a hardware issue, it will cause apps to give up or
@@ -711,10 +713,10 @@ public class FaceManager implements BiometricAuthenticator, BiometricFaceConstan
        }
        }
    }
    }


    private void cancelEnrollment(long requestId) {
    private void cancelEnrollment() {
        if (mService != null) {
        if (mService != null) {
            try {
            try {
                mService.cancelEnrollment(mToken, requestId);
                mService.cancelEnrollment(mToken);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
                throw e.rethrowFromSystemServer();
            }
            }
@@ -1098,16 +1100,9 @@ public class FaceManager implements BiometricAuthenticator, BiometricFaceConstan
    }
    }


    private class OnEnrollCancelListener implements OnCancelListener {
    private class OnEnrollCancelListener implements OnCancelListener {
        private final long mAuthRequestId;

        private OnEnrollCancelListener(long id) {
            mAuthRequestId = id;
        }

        @Override
        @Override
        public void onCancel() {
        public void onCancel() {
            Slog.d(TAG, "Cancel face enrollment requested for: " + mAuthRequestId);
            cancelEnrollment();
            cancelEnrollment(mAuthRequestId);
        }
        }
    }
    }


+4 −5
Original line number Original line Diff line number Diff line
@@ -76,16 +76,15 @@ interface IFaceService {
    void cancelAuthenticationFromService(int sensorId, IBinder token, String opPackageName, long requestId);
    void cancelAuthenticationFromService(int sensorId, IBinder token, String opPackageName, long requestId);


    // Start face enrollment
    // Start face enrollment
    long enroll(int userId, IBinder token, in byte [] hardwareAuthToken, IFaceServiceReceiver receiver,
    void enroll(int userId, IBinder token, in byte [] hardwareAuthToken, IFaceServiceReceiver receiver,
            String opPackageName, in int [] disabledFeatures,
            String opPackageName, in int [] disabledFeatures, in Surface previewSurface, boolean debugConsent);
            in Surface previewSurface, boolean debugConsent);


    // Start remote face enrollment
    // Start remote face enrollment
    long enrollRemotely(int userId, IBinder token, in byte [] hardwareAuthToken, IFaceServiceReceiver receiver,
    void enrollRemotely(int userId, IBinder token, in byte [] hardwareAuthToken, IFaceServiceReceiver receiver,
            String opPackageName, in int [] disabledFeatures);
            String opPackageName, in int [] disabledFeatures);


    // Cancel enrollment in progress
    // Cancel enrollment in progress
    void cancelEnrollment(IBinder token, long requestId);
    void cancelEnrollment(IBinder token);


    // Removes the specified face enrollment for the specified userId.
    // Removes the specified face enrollment for the specified userId.
    void remove(IBinder token, int faceId, int userId, IFaceServiceReceiver receiver,
    void remove(IBinder token, int faceId, int userId, IFaceServiceReceiver receiver,
+12 −18
Original line number Original line Diff line number Diff line
@@ -183,16 +183,9 @@ public class FingerprintManager implements BiometricAuthenticator, BiometricFing
    }
    }


    private class OnEnrollCancelListener implements OnCancelListener {
    private class OnEnrollCancelListener implements OnCancelListener {
        private final long mAuthRequestId;

        private OnEnrollCancelListener(long id) {
            mAuthRequestId = id;
        }

        @Override
        @Override
        public void onCancel() {
        public void onCancel() {
            Slog.d(TAG, "Cancel fingerprint enrollment requested for: " + mAuthRequestId);
            cancelEnrollment();
            cancelEnrollment(mAuthRequestId);
        }
        }
    }
    }


@@ -653,19 +646,20 @@ public class FingerprintManager implements BiometricAuthenticator, BiometricFing
            throw new IllegalArgumentException("Must supply an enrollment callback");
            throw new IllegalArgumentException("Must supply an enrollment callback");
        }
        }


        if (cancel != null && cancel.isCanceled()) {
        if (cancel != null) {
            if (cancel.isCanceled()) {
                Slog.w(TAG, "enrollment already canceled");
                Slog.w(TAG, "enrollment already canceled");
                return;
                return;
            } else {
                cancel.setOnCancelListener(new OnEnrollCancelListener());
            }
        }
        }


        if (mService != null) {
        if (mService != null) {
            try {
            try {
                mEnrollmentCallback = callback;
                mEnrollmentCallback = callback;
                final long enrollId = mService.enroll(mToken, hardwareAuthToken, userId,
                mService.enroll(mToken, hardwareAuthToken, userId, mServiceReceiver,
                        mServiceReceiver, mContext.getOpPackageName(), enrollReason);
                        mContext.getOpPackageName(), enrollReason);
                if (cancel != null) {
                    cancel.setOnCancelListener(new OnEnrollCancelListener(enrollId));
                }
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                Slog.w(TAG, "Remote exception in enroll: ", e);
                Slog.w(TAG, "Remote exception in enroll: ", e);
                // Though this may not be a hardware issue, it will cause apps to give up or try
                // Though this may not be a hardware issue, it will cause apps to give up or try
@@ -1308,9 +1302,9 @@ public class FingerprintManager implements BiometricAuthenticator, BiometricFing
        return allSensors.isEmpty() ? null : allSensors.get(0);
        return allSensors.isEmpty() ? null : allSensors.get(0);
    }
    }


    private void cancelEnrollment(long requestId) {
    private void cancelEnrollment() {
        if (mService != null) try {
        if (mService != null) try {
            mService.cancelEnrollment(mToken, requestId);
            mService.cancelEnrollment(mToken);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
+2 −2
Original line number Original line Diff line number Diff line
@@ -84,11 +84,11 @@ interface IFingerprintService {
    void cancelAuthenticationFromService(int sensorId, IBinder token, String opPackageName, long requestId);
    void cancelAuthenticationFromService(int sensorId, IBinder token, String opPackageName, long requestId);


    // Start fingerprint enrollment
    // Start fingerprint enrollment
    long enroll(IBinder token, in byte [] hardwareAuthToken, int userId, IFingerprintServiceReceiver receiver,
    void enroll(IBinder token, in byte [] hardwareAuthToken, int userId, IFingerprintServiceReceiver receiver,
            String opPackageName, int enrollReason);
            String opPackageName, int enrollReason);


    // Cancel enrollment in progress
    // Cancel enrollment in progress
    void cancelEnrollment(IBinder token, long requestId);
    void cancelEnrollment(IBinder token);


    // Any errors resulting from this call will be returned to the listener
    // Any errors resulting from this call will be returned to the listener
    void remove(IBinder token, int fingerId, int userId, IFingerprintServiceReceiver receiver,
    void remove(IBinder token, int fingerId, int userId, IFingerprintServiceReceiver receiver,
+2 −4
Original line number Original line Diff line number Diff line
@@ -16,8 +16,6 @@


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


import static com.android.internal.annotations.VisibleForTesting.Visibility;

import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.content.Context;
import android.content.Context;
@@ -50,6 +48,7 @@ public abstract class BaseClientMonitor extends LoggableMonitor
     * Interface that ClientMonitor holders should use to receive callbacks.
     * Interface that ClientMonitor holders should use to receive callbacks.
     */
     */
    public interface Callback {
    public interface Callback {

        /**
        /**
         * Invoked when the ClientMonitor operation has been started (e.g. reached the head of
         * Invoked when the ClientMonitor operation has been started (e.g. reached the head of
         * the queue and becomes the current operation).
         * the queue and becomes the current operation).
@@ -204,8 +203,7 @@ public abstract class BaseClientMonitor extends LoggableMonitor
    }
    }


    /** Signals this operation has completed its lifecycle and should no longer be used. */
    /** Signals this operation has completed its lifecycle and should no longer be used. */
    @VisibleForTesting(visibility = Visibility.PACKAGE)
    void destroy() {
    public void destroy() {
        mAlreadyDone = true;
        mAlreadyDone = true;
        if (mToken != null) {
        if (mToken != null) {
            try {
            try {
Loading