diff options
| author | Kevin Chyn <kchyn@google.com> | 2021-02-19 21:10:03 +0000 |
|---|---|---|
| committer | Kevin Chyn <kchyn@google.com> | 2021-02-19 13:45:45 -0800 |
| commit | 0d1b06e3d51955b29e52e5f97f07035001969bed (patch) | |
| tree | ff7e0ed1f3fd04099dfeabb019d74cc11c8133c1 /core/java/android | |
| parent | bd18a4681dfac0a10ead2cd9b3d5d2992b28b02f (diff) | |
Revert^2 "Try to ensure tests run sequentially"
c0dd229fc6afb78c18b6688f7b5034f6229b222d
Change-Id: I1d9366f0cbe4fb41cedfed987162ec15e7845530
Diffstat (limited to 'core/java/android')
10 files changed, 106 insertions, 17 deletions
diff --git a/core/java/android/hardware/biometrics/BiometricManager.java b/core/java/android/hardware/biometrics/BiometricManager.java index 4ca31050bd52..5b28e0035b09 100644 --- a/core/java/android/hardware/biometrics/BiometricManager.java +++ b/core/java/android/hardware/biometrics/BiometricManager.java @@ -237,7 +237,8 @@ public class BiometricManager { public BiometricTestSession createTestSession(int sensorId) { try { return new BiometricTestSession(mContext, sensorId, - mService.createTestSession(sensorId, mContext.getOpPackageName())); + (context, sensorId1, callback) -> mService + .createTestSession(sensorId1, callback, context.getOpPackageName())); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } diff --git a/core/java/android/hardware/biometrics/BiometricTestSession.java b/core/java/android/hardware/biometrics/BiometricTestSession.java index 1c3560882f1b..ff1a17e07c11 100644 --- a/core/java/android/hardware/biometrics/BiometricTestSession.java +++ b/core/java/android/hardware/biometrics/BiometricTestSession.java @@ -19,6 +19,7 @@ package android.hardware.biometrics; import static android.Manifest.permission.TEST_BIOMETRIC; import android.annotation.NonNull; +import android.annotation.Nullable; import android.annotation.RequiresPermission; import android.annotation.TestApi; import android.content.Context; @@ -27,6 +28,9 @@ import android.os.RemoteException; import android.util.ArraySet; import android.util.Log; +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}. @@ -36,22 +40,58 @@ import android.util.Log; public class BiometricTestSession implements AutoCloseable { private static final String TAG = "BiometricTestSession"; + /** + * @hide + */ + public interface TestSessionProvider { + @NonNull + ITestSession createTestSession(@NonNull Context context, int sensorId, + @NonNull ITestSessionCallback callback) throws RemoteException; + } + private final Context mContext; private final int mSensorId; private final ITestSession mTestSession; // Keep track of users that were tested, which need to be cleaned up when finishing. - 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 final ITestSessionCallback mCallback = new ITestSessionCallback.Stub() { + @Override + public void onCleanupStarted(int userId) { + Log.d(TAG, "onCleanupStarted, sensor: " + mSensorId + ", userId: " + userId); + } + + @Override + public void onCleanupFinished(int userId) { + Log.d(TAG, "onCleanupFinished, sensor: " + mSensorId + + ", userId: " + userId + + ", remaining users: " + mUsersCleaningUp.size()); + mUsersCleaningUp.remove(userId); + + if (mUsersCleaningUp.isEmpty() && mCloseLatch != null) { + mCloseLatch.countDown(); + } + } + }; /** * @hide */ public BiometricTestSession(@NonNull Context context, int sensorId, - @NonNull ITestSession testSession) { + @NonNull TestSessionProvider testSessionProvider) throws RemoteException { mContext = context; mSensorId = sensorId; - mTestSession = testSession; + mTestSession = testSessionProvider.createTestSession(context, sensorId, mCallback); mTestedUsers = new ArraySet<>(); + mUsersCleaningUp = new ArraySet<>(); setTestHalEnabled(true); } @@ -176,6 +216,11 @@ public class BiometricTestSession implements AutoCloseable { @RequiresPermission(TEST_BIOMETRIC) public void cleanupInternalState(int userId) { try { + if (mUsersCleaningUp.contains(userId)) { + Log.w(TAG, "Cleanup already in progress for user: " + userId); + } + + mUsersCleaningUp.add(userId); mTestSession.cleanupInternalState(userId); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); @@ -185,12 +230,24 @@ public class BiometricTestSession implements AutoCloseable { @Override @RequiresPermission(TEST_BIOMETRIC) public void close() { - // Disable the test HAL first, so that enumerate is run on the real HAL, which should have - // no enrollments. Test-only framework enrollments will be deleted. - setTestHalEnabled(false); - - for (int user : mTestedUsers) { - cleanupInternalState(user); + // 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(TAG, "Awaiting latch..."); + mCloseLatch.await(10, TimeUnit.SECONDS); + Log.d(TAG, "Finished awaiting"); + } catch (InterruptedException e) { + Log.e(TAG, "Latch interrupted", e); + } } + + // Disable the test HAL after the sensor becomes idle. + setTestHalEnabled(false); } } diff --git a/core/java/android/hardware/biometrics/IAuthService.aidl b/core/java/android/hardware/biometrics/IAuthService.aidl index 0dfd5dbf300e..d8c9dbc849a9 100644 --- a/core/java/android/hardware/biometrics/IAuthService.aidl +++ b/core/java/android/hardware/biometrics/IAuthService.aidl @@ -20,6 +20,7 @@ import android.hardware.biometrics.IBiometricEnabledOnKeyguardCallback; import android.hardware.biometrics.IBiometricServiceReceiver; import android.hardware.biometrics.IInvalidationCallback; import android.hardware.biometrics.ITestSession; +import android.hardware.biometrics.ITestSessionCallback; import android.hardware.biometrics.PromptInfo; import android.hardware.biometrics.SensorPropertiesInternal; @@ -32,7 +33,7 @@ import android.hardware.biometrics.SensorPropertiesInternal; */ interface IAuthService { // Creates a test session with the specified sensorId - ITestSession createTestSession(int sensorId, String opPackageName); + ITestSession createTestSession(int sensorId, ITestSessionCallback callback, String opPackageName); // Retrieve static sensor properties for all biometric sensors List<SensorPropertiesInternal> getSensorProperties(String opPackageName); diff --git a/core/java/android/hardware/biometrics/IBiometricAuthenticator.aidl b/core/java/android/hardware/biometrics/IBiometricAuthenticator.aidl index c854ac9847d8..7639c5dd4d16 100644 --- a/core/java/android/hardware/biometrics/IBiometricAuthenticator.aidl +++ b/core/java/android/hardware/biometrics/IBiometricAuthenticator.aidl @@ -20,6 +20,7 @@ import android.hardware.biometrics.IBiometricSensorReceiver; import android.hardware.biometrics.IBiometricServiceLockoutResetCallback; import android.hardware.biometrics.IInvalidationCallback; import android.hardware.biometrics.ITestSession; +import android.hardware.biometrics.ITestSessionCallback; import android.hardware.biometrics.SensorPropertiesInternal; import android.hardware.face.IFaceServiceReceiver; import android.hardware.face.Face; @@ -32,7 +33,7 @@ import android.hardware.face.Face; interface IBiometricAuthenticator { // Creates a test session - ITestSession createTestSession(String opPackageName); + ITestSession createTestSession(ITestSessionCallback callback, String opPackageName); // Retrieve static sensor properties SensorPropertiesInternal getSensorProperties(String opPackageName); diff --git a/core/java/android/hardware/biometrics/IBiometricService.aidl b/core/java/android/hardware/biometrics/IBiometricService.aidl index a14a910a9e50..24331863a05f 100644 --- a/core/java/android/hardware/biometrics/IBiometricService.aidl +++ b/core/java/android/hardware/biometrics/IBiometricService.aidl @@ -21,6 +21,7 @@ import android.hardware.biometrics.IBiometricServiceReceiver; import android.hardware.biometrics.IBiometricAuthenticator; import android.hardware.biometrics.IInvalidationCallback; import android.hardware.biometrics.ITestSession; +import android.hardware.biometrics.ITestSessionCallback; import android.hardware.biometrics.PromptInfo; import android.hardware.biometrics.SensorPropertiesInternal; @@ -30,7 +31,7 @@ import android.hardware.biometrics.SensorPropertiesInternal; */ interface IBiometricService { // Creates a test session with the specified sensorId - ITestSession createTestSession(int sensorId, String opPackageName); + ITestSession createTestSession(int sensorId, ITestSessionCallback callback, String opPackageName); // Retrieve static sensor properties for all biometric sensors List<SensorPropertiesInternal> getSensorProperties(String opPackageName); diff --git a/core/java/android/hardware/biometrics/ITestSession.aidl b/core/java/android/hardware/biometrics/ITestSession.aidl index fa7a62c53531..f8395a119c0b 100644 --- a/core/java/android/hardware/biometrics/ITestSession.aidl +++ b/core/java/android/hardware/biometrics/ITestSession.aidl @@ -18,7 +18,7 @@ package android.hardware.biometrics; import android.hardware.biometrics.SensorPropertiesInternal; /** - * A test service for FingerprintManager and BiometricPrompt. + * A test service for FingerprintManager and BiometricManager. * @hide */ interface ITestSession { diff --git a/core/java/android/hardware/biometrics/ITestSessionCallback.aidl b/core/java/android/hardware/biometrics/ITestSessionCallback.aidl new file mode 100644 index 000000000000..3d9517f29548 --- /dev/null +++ b/core/java/android/hardware/biometrics/ITestSessionCallback.aidl @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.hardware.biometrics; + +/** + * ITestSession callback for FingerprintManager and BiometricManager. + * @hide + */ +interface ITestSessionCallback { + void onCleanupStarted(int userId); + void onCleanupFinished(int userId); +} diff --git a/core/java/android/hardware/face/IFaceService.aidl b/core/java/android/hardware/face/IFaceService.aidl index a2e0b3b1cb41..6e7c701ef5ff 100644 --- a/core/java/android/hardware/face/IFaceService.aidl +++ b/core/java/android/hardware/face/IFaceService.aidl @@ -19,6 +19,7 @@ import android.hardware.biometrics.IBiometricSensorReceiver; import android.hardware.biometrics.IBiometricServiceLockoutResetCallback; import android.hardware.biometrics.IInvalidationCallback; import android.hardware.biometrics.ITestSession; +import android.hardware.biometrics.ITestSessionCallback; import android.hardware.face.IFaceServiceReceiver; import android.hardware.face.Face; import android.hardware.face.FaceSensorPropertiesInternal; @@ -32,7 +33,7 @@ import android.view.Surface; interface IFaceService { // Creates a test session with the specified sensorId - ITestSession createTestSession(int sensorId, String opPackageName); + ITestSession createTestSession(int sensorId, ITestSessionCallback callback, String opPackageName); // Requests a proto dump of the specified sensor byte[] dumpSensorServiceStateProto(int sensorId, boolean clearSchedulerBuffer); diff --git a/core/java/android/hardware/fingerprint/FingerprintManager.java b/core/java/android/hardware/fingerprint/FingerprintManager.java index 2e4063b6dec1..fc795d8a0488 100644 --- a/core/java/android/hardware/fingerprint/FingerprintManager.java +++ b/core/java/android/hardware/fingerprint/FingerprintManager.java @@ -168,7 +168,8 @@ public class FingerprintManager implements BiometricAuthenticator, BiometricFing public BiometricTestSession createTestSession(int sensorId) { try { return new BiometricTestSession(mContext, sensorId, - mService.createTestSession(sensorId, mContext.getOpPackageName())); + (context, sensorId1, callback) -> mService + .createTestSession(sensorId1, callback, context.getOpPackageName())); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } diff --git a/core/java/android/hardware/fingerprint/IFingerprintService.aidl b/core/java/android/hardware/fingerprint/IFingerprintService.aidl index 1694fef0f71b..054c0d0f6513 100644 --- a/core/java/android/hardware/fingerprint/IFingerprintService.aidl +++ b/core/java/android/hardware/fingerprint/IFingerprintService.aidl @@ -19,6 +19,7 @@ import android.hardware.biometrics.IBiometricSensorReceiver; import android.hardware.biometrics.IBiometricServiceLockoutResetCallback; import android.hardware.biometrics.IInvalidationCallback; import android.hardware.biometrics.ITestSession; +import android.hardware.biometrics.ITestSessionCallback; import android.hardware.fingerprint.IFingerprintClientActiveCallback; import android.hardware.fingerprint.IFingerprintServiceReceiver; import android.hardware.fingerprint.IUdfpsOverlayController; @@ -33,7 +34,7 @@ import java.util.List; interface IFingerprintService { // Creates a test session with the specified sensorId - ITestSession createTestSession(int sensorId, String opPackageName); + ITestSession createTestSession(int sensorId, ITestSessionCallback callback, String opPackageName); // Requests a proto dump of the specified sensor byte[] dumpSensorServiceStateProto(int sensorId, boolean clearSchedulerBuffer); |
