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

Commit fd84288d authored by Hao Dong's avatar Hao Dong Committed by Android (Google) Code Review
Browse files

Revert "Set all sensors to enable test hal when one of them crea..."

Revert submission 28905822-cherrypicker-L87000030005908347:N77200030093575194

Reason for revert: Android OEMs are not required to pick up MPRs or QPRs

Reverted changes: /q/submissionid:28905822-cherrypicker-L87000030005908347:N77200030093575194

Change-Id: I50743fc6e82a312cbc692cbcfeb2738c9c82b6f3
parent 18209ec5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -399,7 +399,7 @@ public class BiometricManager {
    @RequiresPermission(TEST_BIOMETRIC)
    public BiometricTestSession createTestSession(int sensorId) {
        try {
            return new BiometricTestSession(mContext, getSensorProperties(), sensorId,
            return new BiometricTestSession(mContext, sensorId,
                    (context, sensorId1, callback) -> mService
                            .createTestSession(sensorId1, callback, context.getOpPackageName()));
        } catch (RemoteException e) {
+30 −62
Original line number Diff line number Diff line
@@ -27,15 +27,12 @@ import android.os.RemoteException;
import android.util.ArraySet;
import android.util.Log;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * Common set of interfaces to test biometric-related APIs, including {@link BiometricPrompt} and
 * {@link android.hardware.fingerprint.FingerprintManager}.
 *
 * @hide
 */
@TestApi
@@ -51,29 +48,21 @@ public class BiometricTestSession implements AutoCloseable {
                @NonNull ITestSessionCallback callback) throws RemoteException;
    }

    private final Context mContext;
    private final int mSensorId;
    private final List<ITestSession> mTestSessionsForAllSensors = new ArrayList<>();
    private ITestSession mTestSession;
    private final ITestSession mTestSession;

    // Keep track of users that were tested, which need to be cleaned up when finishing.
    @NonNull
    private final ArraySet<Integer> mTestedUsers;
    @NonNull private final ArraySet<Integer> mTestedUsers;

    // Track the users currently cleaning up, and provide a latch that gets notified when all
    // users have finished cleaning up. This is an imperfect system, as there can technically be
    // multiple cleanups per user. Theoretically we should track the cleanup's BaseClientMonitor's
    // unique ID, but it's complicated to plumb it through. This should be fine for now.
    @Nullable
    private CountDownLatch mCloseLatch;
    @NonNull
    private final ArraySet<Integer> mUsersCleaningUp;

    private class TestSessionCallbackIml extends ITestSessionCallback.Stub {
        private final int mSensorId;
        private TestSessionCallbackIml(int sensorId) {
            mSensorId = sensorId;
        }
    @Nullable private CountDownLatch mCloseLatch;
    @NonNull private final ArraySet<Integer> mUsersCleaningUp;

    private final ITestSessionCallback mCallback = new ITestSessionCallback.Stub() {
        @Override
        public void onCleanupStarted(int userId) {
            Log.d(getTag(), "onCleanupStarted, sensor: " + mSensorId + ", userId: " + userId);
@@ -87,30 +76,19 @@ public class BiometricTestSession implements AutoCloseable {
            mUsersCleaningUp.remove(userId);

            if (mUsersCleaningUp.isEmpty() && mCloseLatch != null) {
                Log.d(getTag(), "counting down");
                mCloseLatch.countDown();
            }
        }
    }
    };

    /**
     * @hide
     */
    public BiometricTestSession(@NonNull Context context, List<SensorProperties> sensors,
            int sensorId, @NonNull TestSessionProvider testSessionProvider) throws RemoteException {
    public BiometricTestSession(@NonNull Context context, int sensorId,
            @NonNull TestSessionProvider testSessionProvider) throws RemoteException {
        mContext = context;
        mSensorId = sensorId;
        // When any of the sensors should create the test session, all the other sensors should
        // set test hal enabled too.
        for (SensorProperties sensor : sensors) {
            final int id = sensor.getSensorId();
            final ITestSession session = testSessionProvider.createTestSession(context, id,
                    new TestSessionCallbackIml(id));
            mTestSessionsForAllSensors.add(session);
            if (id == sensorId) {
                mTestSession = session;
            }
        }

        mTestSession = testSessionProvider.createTestSession(context, sensorId, mCallback);
        mTestedUsers = new ArraySet<>();
        mUsersCleaningUp = new ArraySet<>();
        setTestHalEnabled(true);
@@ -129,11 +107,8 @@ public class BiometricTestSession implements AutoCloseable {
    @RequiresPermission(TEST_BIOMETRIC)
    private void setTestHalEnabled(boolean enabled) {
        try {
            for (ITestSession session : mTestSessionsForAllSensors) {
                Log.w(getTag(), "setTestHalEnabled, sensor: " + session.getSensorId() + " enabled: "
                        + enabled);
                session.setTestHalEnabled(enabled);
            }
            Log.w(getTag(), "setTestHalEnabled, sensor: " + mSensorId + " enabled: " + enabled);
            mTestSession.setTestHalEnabled(enabled);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -202,10 +177,8 @@ public class BiometricTestSession implements AutoCloseable {
     *
     * @param userId User that this command applies to.
     * @param acquireInfo See
     *                    {@link
     *                    BiometricPrompt.AuthenticationCallback#onAuthenticationAcquired(int)} and
     *                    {@link
     *                    FingerprintManager.AuthenticationCallback#onAuthenticationAcquired(int)}
     * {@link BiometricPrompt.AuthenticationCallback#onAuthenticationAcquired(int)} and
     * {@link FingerprintManager.AuthenticationCallback#onAuthenticationAcquired(int)}
     */
    @RequiresPermission(TEST_BIOMETRIC)
    public void notifyAcquired(int userId, int acquireInfo) {
@@ -221,10 +194,8 @@ public class BiometricTestSession implements AutoCloseable {
     *
     * @param userId User that this command applies to.
     * @param errorCode See
     *                  {@link BiometricPrompt.AuthenticationCallback#onAuthenticationError(int,
     *                  CharSequence)} and
     *                  {@link FingerprintManager.AuthenticationCallback#onAuthenticationError(int,
     *                  CharSequence)}
     * {@link BiometricPrompt.AuthenticationCallback#onAuthenticationError(int, CharSequence)} and
     * {@link FingerprintManager.AuthenticationCallback#onAuthenticationError(int, CharSequence)}
     */
    @RequiresPermission(TEST_BIOMETRIC)
    public void notifyError(int userId, int errorCode) {
@@ -249,20 +220,8 @@ public class BiometricTestSession implements AutoCloseable {
                Log.w(getTag(), "Cleanup already in progress for user: " + userId);
            }

            for (ITestSession session : mTestSessionsForAllSensors) {
            mUsersCleaningUp.add(userId);
                Log.d(getTag(), "cleanupInternalState for sensor: " + session.getSensorId());
                mCloseLatch = new CountDownLatch(1);
                session.cleanupInternalState(userId);

                try {
                    Log.d(getTag(), "Awaiting latch...");
                    mCloseLatch.await(3, TimeUnit.SECONDS);
                    Log.d(getTag(), "Finished awaiting");
                } catch (InterruptedException e) {
                    Log.e(getTag(), "Latch interrupted", e);
                }
            }
            mTestSession.cleanupInternalState(userId);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -275,9 +234,18 @@ public class BiometricTestSession implements AutoCloseable {
        // Cleanup can be performed using the test HAL, since it always responds to enumerate with
        // zero enrollments.
        if (!mTestedUsers.isEmpty()) {
            mCloseLatch = new CountDownLatch(1);
            for (int user : mTestedUsers) {
                cleanupInternalState(user);
            }

            try {
                Log.d(getTag(), "Awaiting latch...");
                mCloseLatch.await(3, TimeUnit.SECONDS);
                Log.d(getTag(), "Finished awaiting");
            } catch (InterruptedException e) {
                Log.e(getTag(), "Latch interrupted", e);
            }
        }

        if (!mUsersCleaningUp.isEmpty()) {
+0 −4
Original line number Diff line number Diff line
@@ -59,8 +59,4 @@ interface ITestSession {
    // HAL is disabled (e.g. to clean up after a test).
    @EnforcePermission("TEST_BIOMETRIC")
    void cleanupInternalState(int userId);

    // Get the sensor id of the current test session.
    @EnforcePermission("TEST_BIOMETRIC")
    int getSensorId();
}
+1 −1
Original line number Diff line number Diff line
@@ -172,7 +172,7 @@ public class FingerprintManager implements BiometricAuthenticator, BiometricFing
    @RequiresPermission(TEST_BIOMETRIC)
    public BiometricTestSession createTestSession(int sensorId) {
        try {
            return new BiometricTestSession(mContext, getSensorProperties(), sensorId,
            return new BiometricTestSession(mContext, sensorId,
                    (context, sensorId1, callback) -> mService
                            .createTestSession(sensorId1, callback, context.getOpPackageName()));
        } catch (RemoteException e) {
+0 −7
Original line number Diff line number Diff line
@@ -264,11 +264,4 @@ public class BiometricTestSessionImpl extends ITestSession.Stub {
            }
        });
    }

    @android.annotation.EnforcePermission(android.Manifest.permission.TEST_BIOMETRIC)
    @Override
    public int getSensorId() {
        super.getSensorId_enforcePermission();
        return mSensorId;
    }
}
Loading