diff options
6 files changed, 32 insertions, 82 deletions
diff --git a/core/java/android/hardware/biometrics/BiometricManager.java b/core/java/android/hardware/biometrics/BiometricManager.java index a539ff1a7f25..fdd8b04921f5 100644 --- a/core/java/android/hardware/biometrics/BiometricManager.java +++ b/core/java/android/hardware/biometrics/BiometricManager.java @@ -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) { diff --git a/core/java/android/hardware/biometrics/BiometricTestSession.java b/core/java/android/hardware/biometrics/BiometricTestSession.java index 8bd352888de1..027d1015a4b5 100644 --- a/core/java/android/hardware/biometrics/BiometricTestSession.java +++ b/core/java/android/hardware/biometrics/BiometricTestSession.java @@ -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(); } @@ -200,12 +175,10 @@ public class BiometricTestSession implements AutoCloseable { /** * Simulates an acquired message from the HAL. * - * @param userId User that this command applies to. + * @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) { @@ -219,12 +192,10 @@ public class BiometricTestSession implements AutoCloseable { /** * Simulates an error message from the HAL. * - * @param userId User that this command applies to. + * @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); - } - } + mUsersCleaningUp.add(userId); + 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()) { diff --git a/core/java/android/hardware/biometrics/ITestSession.aidl b/core/java/android/hardware/biometrics/ITestSession.aidl index bd99606808b7..df9f504a2c05 100644 --- a/core/java/android/hardware/biometrics/ITestSession.aidl +++ b/core/java/android/hardware/biometrics/ITestSession.aidl @@ -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(); } diff --git a/core/java/android/hardware/fingerprint/FingerprintManager.java b/core/java/android/hardware/fingerprint/FingerprintManager.java index 7f1cac08b430..903e91646332 100644 --- a/core/java/android/hardware/fingerprint/FingerprintManager.java +++ b/core/java/android/hardware/fingerprint/FingerprintManager.java @@ -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) { diff --git a/services/core/java/com/android/server/biometrics/sensors/face/aidl/BiometricTestSessionImpl.java b/services/core/java/com/android/server/biometrics/sensors/face/aidl/BiometricTestSessionImpl.java index dca14914a572..0fdd57d64d8d 100644 --- a/services/core/java/com/android/server/biometrics/sensors/face/aidl/BiometricTestSessionImpl.java +++ b/services/core/java/com/android/server/biometrics/sensors/face/aidl/BiometricTestSessionImpl.java @@ -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; - } } diff --git a/services/core/java/com/android/server/biometrics/sensors/fingerprint/aidl/BiometricTestSessionImpl.java b/services/core/java/com/android/server/biometrics/sensors/fingerprint/aidl/BiometricTestSessionImpl.java index caa2c1c34ff7..8dc560b0e0b5 100644 --- a/services/core/java/com/android/server/biometrics/sensors/fingerprint/aidl/BiometricTestSessionImpl.java +++ b/services/core/java/com/android/server/biometrics/sensors/fingerprint/aidl/BiometricTestSessionImpl.java @@ -293,11 +293,4 @@ class BiometricTestSessionImpl extends ITestSession.Stub { } }); } - - @android.annotation.EnforcePermission(android.Manifest.permission.TEST_BIOMETRIC) - @Override - public int getSensorId() { - super.getSensorId_enforcePermission(); - return mSensorId; - } }
\ No newline at end of file |