Fix flaky tests
Test: atest FingerprintProviderTest Test: atest FaceProviderTest Bug: 285787206 Change-Id: I6546759ae1288abff967a4f624a90f3800687d5a
This commit is contained in:
@@ -149,6 +149,17 @@ public class FaceProvider implements IBinder.DeathRecipient, ServiceProvider {
|
||||
@NonNull String halInstanceName,
|
||||
@NonNull LockoutResetDispatcher lockoutResetDispatcher,
|
||||
@NonNull BiometricContext biometricContext) {
|
||||
this(context, biometricStateCallback, props, halInstanceName, lockoutResetDispatcher,
|
||||
biometricContext, null /* daemon */);
|
||||
}
|
||||
|
||||
@VisibleForTesting FaceProvider(@NonNull Context context,
|
||||
@NonNull BiometricStateCallback biometricStateCallback,
|
||||
@NonNull SensorProps[] props,
|
||||
@NonNull String halInstanceName,
|
||||
@NonNull LockoutResetDispatcher lockoutResetDispatcher,
|
||||
@NonNull BiometricContext biometricContext,
|
||||
IFace daemon) {
|
||||
mContext = context;
|
||||
mBiometricStateCallback = biometricStateCallback;
|
||||
mHalInstanceName = halInstanceName;
|
||||
@@ -160,6 +171,7 @@ public class FaceProvider implements IBinder.DeathRecipient, ServiceProvider {
|
||||
mTaskStackListener = new BiometricTaskStackListener();
|
||||
mBiometricContext = biometricContext;
|
||||
mAuthSessionCoordinator = mBiometricContext.getAuthSessionCoordinator();
|
||||
mDaemon = daemon;
|
||||
|
||||
for (SensorProps prop : props) {
|
||||
final int sensorId = prop.commonProps.sensorId;
|
||||
|
||||
@@ -160,6 +160,17 @@ public class FingerprintProvider implements IBinder.DeathRecipient, ServiceProvi
|
||||
@NonNull LockoutResetDispatcher lockoutResetDispatcher,
|
||||
@NonNull GestureAvailabilityDispatcher gestureAvailabilityDispatcher,
|
||||
@NonNull BiometricContext biometricContext) {
|
||||
this(context, biometricStateCallback, props, halInstanceName, lockoutResetDispatcher,
|
||||
gestureAvailabilityDispatcher, biometricContext, null /* daemon */);
|
||||
}
|
||||
|
||||
@VisibleForTesting FingerprintProvider(@NonNull Context context,
|
||||
@NonNull BiometricStateCallback biometricStateCallback,
|
||||
@NonNull SensorProps[] props, @NonNull String halInstanceName,
|
||||
@NonNull LockoutResetDispatcher lockoutResetDispatcher,
|
||||
@NonNull GestureAvailabilityDispatcher gestureAvailabilityDispatcher,
|
||||
@NonNull BiometricContext biometricContext,
|
||||
IFingerprint daemon) {
|
||||
mContext = context;
|
||||
mBiometricStateCallback = biometricStateCallback;
|
||||
mHalInstanceName = halInstanceName;
|
||||
@@ -170,6 +181,7 @@ public class FingerprintProvider implements IBinder.DeathRecipient, ServiceProvi
|
||||
mTaskStackListener = new BiometricTaskStackListener();
|
||||
mBiometricContext = biometricContext;
|
||||
mAuthSessionCoordinator = mBiometricContext.getAuthSessionCoordinator();
|
||||
mDaemon = daemon;
|
||||
|
||||
final List<SensorLocationInternal> workaroundLocations = getWorkaroundSensorProps(context);
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.platform.test.annotations.Presubmit;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
@@ -73,7 +72,7 @@ public class FaceProviderTest {
|
||||
|
||||
private SensorProps[] mSensorProps;
|
||||
private LockoutResetDispatcher mLockoutResetDispatcher;
|
||||
private TestableFaceProvider mFaceProvider;
|
||||
private FaceProvider mFaceProvider;
|
||||
|
||||
private static void waitForIdle() {
|
||||
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
|
||||
@@ -98,8 +97,9 @@ public class FaceProviderTest {
|
||||
|
||||
mLockoutResetDispatcher = new LockoutResetDispatcher(mContext);
|
||||
|
||||
mFaceProvider = new TestableFaceProvider(mDaemon, mContext, mBiometricStateCallback,
|
||||
mSensorProps, TAG, mLockoutResetDispatcher, mBiometricContext);
|
||||
mFaceProvider = new FaceProvider(mContext, mBiometricStateCallback,
|
||||
mSensorProps, TAG, mLockoutResetDispatcher, mBiometricContext,
|
||||
mDaemon);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -130,6 +130,7 @@ public class FaceProviderTest {
|
||||
for (SensorProps prop : mSensorProps) {
|
||||
final BiometricScheduler scheduler =
|
||||
mFaceProvider.mFaceSensors.get(prop.commonProps.sensorId).getScheduler();
|
||||
scheduler.reset();
|
||||
for (int i = 0; i < numFakeOperations; i++) {
|
||||
final HalClientMonitor testMonitor = mock(HalClientMonitor.class);
|
||||
when(testMonitor.getFreshDaemon()).thenReturn(new Object());
|
||||
@@ -142,7 +143,7 @@ public class FaceProviderTest {
|
||||
for (SensorProps prop : mSensorProps) {
|
||||
final BiometricScheduler scheduler =
|
||||
mFaceProvider.mFaceSensors.get(prop.commonProps.sensorId).getScheduler();
|
||||
assertEquals(numFakeOperations, scheduler.getCurrentPendingCount());
|
||||
assertEquals(numFakeOperations - 1, scheduler.getCurrentPendingCount());
|
||||
assertNotNull(scheduler.getCurrentClient());
|
||||
}
|
||||
|
||||
@@ -159,25 +160,4 @@ public class FaceProviderTest {
|
||||
assertEquals(0, scheduler.getCurrentPendingCount());
|
||||
}
|
||||
}
|
||||
|
||||
private static class TestableFaceProvider extends FaceProvider {
|
||||
private final IFace mDaemon;
|
||||
|
||||
TestableFaceProvider(@NonNull IFace daemon,
|
||||
@NonNull Context context,
|
||||
@NonNull BiometricStateCallback biometricStateCallback,
|
||||
@NonNull SensorProps[] props,
|
||||
@NonNull String halInstanceName,
|
||||
@NonNull LockoutResetDispatcher lockoutResetDispatcher,
|
||||
@NonNull BiometricContext biometricContext) {
|
||||
super(context, biometricStateCallback, props, halInstanceName, lockoutResetDispatcher,
|
||||
biometricContext);
|
||||
mDaemon = daemon;
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized IFace getHalInstance() {
|
||||
return mDaemon;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.platform.test.annotations.Presubmit;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
@@ -81,7 +80,7 @@ public class FingerprintProviderTest {
|
||||
|
||||
private SensorProps[] mSensorProps;
|
||||
private LockoutResetDispatcher mLockoutResetDispatcher;
|
||||
private TestableFingerprintProvider mFingerprintProvider;
|
||||
private FingerprintProvider mFingerprintProvider;
|
||||
|
||||
private static void waitForIdle() {
|
||||
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
|
||||
@@ -110,17 +109,13 @@ public class FingerprintProviderTest {
|
||||
|
||||
mLockoutResetDispatcher = new LockoutResetDispatcher(mContext);
|
||||
|
||||
mFingerprintProvider = new TestableFingerprintProvider(mDaemon, mContext,
|
||||
mFingerprintProvider = new FingerprintProvider(mContext,
|
||||
mBiometricStateCallback, mSensorProps, TAG, mLockoutResetDispatcher,
|
||||
mGestureAvailabilityDispatcher, mBiometricContext);
|
||||
mGestureAvailabilityDispatcher, mBiometricContext, mDaemon);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddingSensors() {
|
||||
mFingerprintProvider = new TestableFingerprintProvider(mDaemon, mContext,
|
||||
mBiometricStateCallback, mSensorProps, TAG, mLockoutResetDispatcher,
|
||||
mGestureAvailabilityDispatcher, mBiometricContext);
|
||||
|
||||
waitForIdle();
|
||||
|
||||
for (SensorProps prop : mSensorProps) {
|
||||
@@ -147,6 +142,7 @@ public class FingerprintProviderTest {
|
||||
final BiometricScheduler scheduler =
|
||||
mFingerprintProvider.mFingerprintSensors.get(prop.commonProps.sensorId)
|
||||
.getScheduler();
|
||||
scheduler.reset();
|
||||
for (int i = 0; i < numFakeOperations; i++) {
|
||||
final HalClientMonitor testMonitor = mock(HalClientMonitor.class);
|
||||
when(testMonitor.getFreshDaemon()).thenReturn(new Object());
|
||||
@@ -160,7 +156,7 @@ public class FingerprintProviderTest {
|
||||
final BiometricScheduler scheduler =
|
||||
mFingerprintProvider.mFingerprintSensors.get(prop.commonProps.sensorId)
|
||||
.getScheduler();
|
||||
assertEquals(numFakeOperations, scheduler.getCurrentPendingCount());
|
||||
assertEquals(numFakeOperations - 1, scheduler.getCurrentPendingCount());
|
||||
assertNotNull(scheduler.getCurrentClient());
|
||||
}
|
||||
|
||||
@@ -178,26 +174,4 @@ public class FingerprintProviderTest {
|
||||
assertEquals(0, scheduler.getCurrentPendingCount());
|
||||
}
|
||||
}
|
||||
|
||||
private static class TestableFingerprintProvider extends FingerprintProvider {
|
||||
private final IFingerprint mDaemon;
|
||||
|
||||
TestableFingerprintProvider(@NonNull IFingerprint daemon,
|
||||
@NonNull Context context,
|
||||
@NonNull BiometricStateCallback biometricStateCallback,
|
||||
@NonNull SensorProps[] props,
|
||||
@NonNull String halInstanceName,
|
||||
@NonNull LockoutResetDispatcher lockoutResetDispatcher,
|
||||
@NonNull GestureAvailabilityDispatcher gestureAvailabilityDispatcher,
|
||||
@NonNull BiometricContext biometricContext) {
|
||||
super(context, biometricStateCallback, props, halInstanceName, lockoutResetDispatcher,
|
||||
gestureAvailabilityDispatcher, biometricContext);
|
||||
mDaemon = daemon;
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized IFingerprint getHalInstance() {
|
||||
return mDaemon;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user