diff options
8 files changed, 306 insertions, 5 deletions
diff --git a/services/tests/servicestests/src/com/android/server/biometrics/sensors/UserAwareBiometricSchedulerTest.java b/services/tests/servicestests/src/com/android/server/biometrics/sensors/UserAwareBiometricSchedulerTest.java index 0815fe52e262..dd5d826b1739 100644 --- a/services/tests/servicestests/src/com/android/server/biometrics/sensors/UserAwareBiometricSchedulerTest.java +++ b/services/tests/servicestests/src/com/android/server/biometrics/sensors/UserAwareBiometricSchedulerTest.java @@ -33,6 +33,9 @@ import android.os.Handler; import android.os.IBinder; import android.os.UserHandle; import android.platform.test.annotations.Presubmit; +import android.platform.test.annotations.RequiresFlagsDisabled; +import android.platform.test.flag.junit.CheckFlagsRule; +import android.platform.test.flag.junit.DeviceFlagsValueProvider; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; @@ -40,6 +43,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.test.filters.SmallTest; +import com.android.server.biometrics.Flags; import com.android.server.biometrics.log.BiometricContext; import com.android.server.biometrics.log.BiometricLogger; @@ -66,6 +70,9 @@ public class UserAwareBiometricSchedulerTest { @Rule public final MockitoRule mockito = MockitoJUnit.rule(); + @Rule + public final CheckFlagsRule mCheckFlagsRule = + DeviceFlagsValueProvider.createCheckFlagsRule(); private Handler mHandler; private UserAwareBiometricScheduler mScheduler; @@ -122,6 +129,7 @@ public class UserAwareBiometricSchedulerTest { } @Test + @RequiresFlagsDisabled(Flags.FLAG_DE_HIDL) public void testScheduleOperation_whenNoUser() { mCurrentUserId = UserHandle.USER_NULL; @@ -183,6 +191,7 @@ public class UserAwareBiometricSchedulerTest { } @Test + @RequiresFlagsDisabled(Flags.FLAG_DE_HIDL) public void testScheduleOperation_whenSameUser() { mCurrentUserId = 10; @@ -199,6 +208,7 @@ public class UserAwareBiometricSchedulerTest { } @Test + @RequiresFlagsDisabled(Flags.FLAG_DE_HIDL) public void testScheduleOperation_whenDifferentUser() { mCurrentUserId = 10; @@ -219,6 +229,7 @@ public class UserAwareBiometricSchedulerTest { } @Test + @RequiresFlagsDisabled(Flags.FLAG_DE_HIDL) public void testStartUser_alwaysStartsNextOperation() { BaseClientMonitor nextClient = mock(BaseClientMonitor.class); when(nextClient.getTargetUserId()).thenReturn(10); @@ -246,6 +257,7 @@ public class UserAwareBiometricSchedulerTest { } @Test + @RequiresFlagsDisabled(Flags.FLAG_DE_HIDL) public void testStartUser_failsClearsStopUserClient() { // When a stop user client fails, check that mStopUserClient // is set to null to prevent the scheduler from getting stuck. diff --git a/services/tests/servicestests/src/com/android/server/biometrics/sensors/face/aidl/FaceAuthenticationClientTest.java b/services/tests/servicestests/src/com/android/server/biometrics/sensors/face/aidl/FaceAuthenticationClientTest.java index f8b5b04294cd..84c36848adbf 100644 --- a/services/tests/servicestests/src/com/android/server/biometrics/sensors/face/aidl/FaceAuthenticationClientTest.java +++ b/services/tests/servicestests/src/com/android/server/biometrics/sensors/face/aidl/FaceAuthenticationClientTest.java @@ -50,12 +50,17 @@ import android.os.IBinder; import android.os.PowerManager; import android.os.RemoteException; import android.platform.test.annotations.Presubmit; +import android.platform.test.annotations.RequiresFlagsDisabled; +import android.platform.test.annotations.RequiresFlagsEnabled; +import android.platform.test.flag.junit.CheckFlagsRule; +import android.platform.test.flag.junit.DeviceFlagsValueProvider; import android.platform.test.flag.junit.SetFlagsRule; import android.testing.TestableContext; import androidx.test.filters.SmallTest; import androidx.test.platform.app.InstrumentationRegistry; +import com.android.server.biometrics.Flags; import com.android.server.biometrics.log.BiometricContext; import com.android.server.biometrics.log.BiometricLogger; import com.android.server.biometrics.log.OperationContextExt; @@ -94,6 +99,9 @@ public class FaceAuthenticationClientTest { @Rule public final TestableContext mContext = new TestableContext( InstrumentationRegistry.getInstrumentation().getTargetContext(), null); + @Rule + public final CheckFlagsRule mCheckFlagsRule = + DeviceFlagsValueProvider.createCheckFlagsRule(); @Mock private ISession mHal; @@ -127,6 +135,8 @@ public class FaceAuthenticationClientTest { private ArgumentCaptor<OperationContextExt> mOperationContextCaptor; @Captor private ArgumentCaptor<Consumer<OperationContext>> mContextInjector; + @Captor + private ArgumentCaptor<Consumer<OperationContext>> mStartHalConsumerCaptor; @Rule public final MockitoRule mockito = MockitoJUnit.rule(); @@ -149,6 +159,7 @@ public class FaceAuthenticationClientTest { } @Test + @RequiresFlagsDisabled(Flags.FLAG_DE_HIDL) public void authWithContext_v2() throws RemoteException { final FaceAuthenticationClient client = createClient(2); client.start(mCallback); @@ -189,6 +200,7 @@ public class FaceAuthenticationClientTest { } @Test + @RequiresFlagsDisabled(Flags.FLAG_DE_HIDL) public void notifyHalWhenContextChanges() throws RemoteException { final FaceAuthenticationClient client = createClient(); client.start(mCallback); @@ -211,6 +223,36 @@ public class FaceAuthenticationClientTest { } @Test + @RequiresFlagsEnabled(Flags.FLAG_DE_HIDL) + public void subscribeContextAndStartHal() throws RemoteException { + final FaceAuthenticationClient client = createClient(); + client.start(mCallback); + + verify(mBiometricContext).subscribe(mOperationContextCaptor.capture(), + mStartHalConsumerCaptor.capture(), mContextInjector.capture(), any()); + + mStartHalConsumerCaptor.getValue().accept( + mOperationContextCaptor.getValue().toAidlContext()); + final ArgumentCaptor<OperationContext> captor = + ArgumentCaptor.forClass(OperationContext.class); + + verify(mHal).authenticateWithContext(eq(OP_ID), captor.capture()); + + OperationContext opContext = captor.getValue(); + + assertThat(opContext).isSameInstanceAs( + mOperationContextCaptor.getValue().toAidlContext()); + + mContextInjector.getValue().accept(opContext); + + verify(mHal).onContextChanged(same(opContext)); + + client.stopHalOperation(); + + verify(mBiometricContext).unsubscribe(same(mOperationContextCaptor.getValue())); + } + + @Test public void cancelsAuthWhenNotInForeground() throws Exception { final ActivityManager.RunningTaskInfo topTask = new ActivityManager.RunningTaskInfo(); topTask.topActivity = new ComponentName("other", "thing"); diff --git a/services/tests/servicestests/src/com/android/server/biometrics/sensors/face/aidl/FaceDetectClientTest.java b/services/tests/servicestests/src/com/android/server/biometrics/sensors/face/aidl/FaceDetectClientTest.java index fbf0e13c2ac9..e626f7307e7e 100644 --- a/services/tests/servicestests/src/com/android/server/biometrics/sensors/face/aidl/FaceDetectClientTest.java +++ b/services/tests/servicestests/src/com/android/server/biometrics/sensors/face/aidl/FaceDetectClientTest.java @@ -37,11 +37,16 @@ import android.os.PowerManager; import android.os.RemoteException; import android.os.Vibrator; import android.platform.test.annotations.Presubmit; +import android.platform.test.annotations.RequiresFlagsDisabled; +import android.platform.test.annotations.RequiresFlagsEnabled; +import android.platform.test.flag.junit.CheckFlagsRule; +import android.platform.test.flag.junit.DeviceFlagsValueProvider; import android.testing.TestableContext; import androidx.test.filters.SmallTest; import androidx.test.platform.app.InstrumentationRegistry; +import com.android.server.biometrics.Flags; import com.android.server.biometrics.log.BiometricContext; import com.android.server.biometrics.log.BiometricLogger; import com.android.server.biometrics.log.OperationContextExt; @@ -71,6 +76,9 @@ public class FaceDetectClientTest { @Rule public final TestableContext mContext = new TestableContext( InstrumentationRegistry.getInstrumentation().getTargetContext(), null); + @Rule + public final CheckFlagsRule mCheckFlagsRule = + DeviceFlagsValueProvider.createCheckFlagsRule(); @Mock private ISession mHal; @@ -91,6 +99,8 @@ public class FaceDetectClientTest { @Captor private ArgumentCaptor<OperationContextExt> mOperationContextCaptor; @Captor + private ArgumentCaptor<Consumer<OperationContext>> mStartHalCaptor; + @Captor private ArgumentCaptor<Consumer<OperationContext>> mContextInjector; @Rule @@ -114,6 +124,7 @@ public class FaceDetectClientTest { } @Test + @RequiresFlagsDisabled(Flags.FLAG_DE_HIDL) public void detectWithContext_v2() throws RemoteException { final FaceDetectClient client = createClient(2); client.start(mCallback); @@ -132,6 +143,7 @@ public class FaceDetectClientTest { } @Test + @RequiresFlagsDisabled(Flags.FLAG_DE_HIDL) public void notifyHalWhenContextChanges() throws RemoteException { final FaceDetectClient client = createClient(); client.start(mCallback); @@ -154,6 +166,35 @@ public class FaceDetectClientTest { } @Test + @RequiresFlagsEnabled(Flags.FLAG_DE_HIDL) + public void subscribeContextAndStartHal() throws RemoteException { + final FaceDetectClient client = createClient(); + client.start(mCallback); + + verify(mBiometricContext).subscribe(mOperationContextCaptor.capture(), + mStartHalCaptor.capture(), mContextInjector.capture(), any()); + + mStartHalCaptor.getValue().accept(mOperationContextCaptor.getValue().toAidlContext()); + final ArgumentCaptor<OperationContext> captor = + ArgumentCaptor.forClass(OperationContext.class); + + verify(mHal).detectInteractionWithContext(captor.capture()); + + OperationContext opContext = captor.getValue(); + + assertThat(opContext).isSameInstanceAs( + mOperationContextCaptor.getValue().toAidlContext()); + + mContextInjector.getValue().accept(opContext); + + verify(mHal).onContextChanged(same(opContext)); + + client.stopHalOperation(); + + verify(mBiometricContext).unsubscribe(same(mOperationContextCaptor.getValue())); + } + + @Test public void doesNotPlayHapticOnInteractionDetected() throws Exception { final FaceDetectClient client = createClient(); client.start(mCallback); diff --git a/services/tests/servicestests/src/com/android/server/biometrics/sensors/face/aidl/FaceEnrollClientTest.java b/services/tests/servicestests/src/com/android/server/biometrics/sensors/face/aidl/FaceEnrollClientTest.java index d662620407e8..43ed07a0bf76 100644 --- a/services/tests/servicestests/src/com/android/server/biometrics/sensors/face/aidl/FaceEnrollClientTest.java +++ b/services/tests/servicestests/src/com/android/server/biometrics/sensors/face/aidl/FaceEnrollClientTest.java @@ -28,17 +28,21 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.hardware.biometrics.common.OperationContext; -import android.hardware.biometrics.face.FaceEnrollOptions; import android.hardware.biometrics.face.ISession; import android.hardware.face.Face; import android.os.IBinder; import android.os.RemoteException; import android.platform.test.annotations.Presubmit; +import android.platform.test.annotations.RequiresFlagsDisabled; +import android.platform.test.annotations.RequiresFlagsEnabled; +import android.platform.test.flag.junit.CheckFlagsRule; +import android.platform.test.flag.junit.DeviceFlagsValueProvider; import android.testing.TestableContext; import androidx.test.filters.SmallTest; import androidx.test.platform.app.InstrumentationRegistry; +import com.android.server.biometrics.Flags; import com.android.server.biometrics.log.BiometricContext; import com.android.server.biometrics.log.BiometricLogger; import com.android.server.biometrics.log.OperationContextExt; @@ -68,6 +72,9 @@ public class FaceEnrollClientTest { @Rule public final TestableContext mContext = new TestableContext( InstrumentationRegistry.getInstrumentation().getTargetContext(), null); + @Rule + public final CheckFlagsRule mCheckFlagsRule = + DeviceFlagsValueProvider.createCheckFlagsRule(); @Mock private ISession mHal; @@ -89,6 +96,8 @@ public class FaceEnrollClientTest { private ArgumentCaptor<OperationContextExt> mOperationContextCaptor; @Captor private ArgumentCaptor<Consumer<OperationContext>> mContextInjector; + @Captor + private ArgumentCaptor<Consumer<OperationContext>> mStartHalConsumer; @Rule public final MockitoRule mockito = MockitoJUnit.rule(); @@ -109,6 +118,7 @@ public class FaceEnrollClientTest { } @Test + @RequiresFlagsDisabled(Flags.FLAG_DE_HIDL) public void enrollWithContext_v2() throws RemoteException { final FaceEnrollClient client = createClient(2); client.start(mCallback); @@ -123,6 +133,7 @@ public class FaceEnrollClientTest { } @Test + @RequiresFlagsDisabled(Flags.FLAG_DE_HIDL) public void notifyHalWhenContextChanges() throws RemoteException { final FaceEnrollClient client = createClient(3); client.start(mCallback); @@ -145,6 +156,37 @@ public class FaceEnrollClientTest { } @Test + @RequiresFlagsEnabled(Flags.FLAG_DE_HIDL) + public void subscribeContextAndStartHal() throws RemoteException { + final FaceEnrollClient client = createClient(3); + client.start(mCallback); + + verify(mBiometricContext).subscribe( + mOperationContextCaptor.capture(), mStartHalConsumer.capture(), + mContextInjector.capture(), any()); + + mStartHalConsumer.getValue().accept(mOperationContextCaptor.getValue().toAidlContext()); + final ArgumentCaptor<OperationContext> captor = + ArgumentCaptor.forClass(OperationContext.class); + + verify(mHal).enrollWithContext(any(), anyByte(), any(), any(), captor.capture()); + + OperationContext opContext = captor.getValue(); + + assertThat(opContext).isSameInstanceAs( + mOperationContextCaptor.getValue().toAidlContext()); + + mContextInjector.getValue().accept(opContext); + + verify(mHal).onContextChanged(same(opContext)); + + client.stopHalOperation(); + + verify(mBiometricContext).unsubscribe(same(mOperationContextCaptor.getValue())); + } + + @Test + @RequiresFlagsDisabled(Flags.FLAG_DE_HIDL) public void enrollWithFaceOptions() throws RemoteException { final FaceEnrollClient client = createClient(4); client.start(mCallback); @@ -152,6 +194,20 @@ public class FaceEnrollClientTest { verify(mHal).enrollWithOptions(any()); } + @Test + @RequiresFlagsEnabled(Flags.FLAG_DE_HIDL) + public void enrollWithFaceOptionsAfterSubscribingContext() throws RemoteException { + final FaceEnrollClient client = createClient(4); + client.start(mCallback); + + verify(mBiometricContext).subscribe(mOperationContextCaptor.capture(), + mStartHalConsumer.capture(), any(), any()); + + mStartHalConsumer.getValue().accept(mOperationContextCaptor.getValue().toAidlContext()); + + verify(mHal).enrollWithOptions(any()); + } + private FaceEnrollClient createClient() throws RemoteException { return createClient(200 /* version */); } diff --git a/services/tests/servicestests/src/com/android/server/biometrics/sensors/face/hidl/Face10Test.java b/services/tests/servicestests/src/com/android/server/biometrics/sensors/face/hidl/Face10Test.java index 78c1e08ba832..949d6ee800fa 100644 --- a/services/tests/servicestests/src/com/android/server/biometrics/sensors/face/hidl/Face10Test.java +++ b/services/tests/servicestests/src/com/android/server/biometrics/sensors/face/hidl/Face10Test.java @@ -38,11 +38,15 @@ import android.os.IBinder; import android.os.Looper; import android.os.UserManager; import android.platform.test.annotations.Presubmit; +import android.platform.test.annotations.RequiresFlagsDisabled; +import android.platform.test.flag.junit.CheckFlagsRule; +import android.platform.test.flag.junit.DeviceFlagsValueProvider; import androidx.test.InstrumentationRegistry; import androidx.test.filters.SmallTest; import com.android.internal.R; +import com.android.server.biometrics.Flags; import com.android.server.biometrics.log.BiometricContext; import com.android.server.biometrics.sensors.AuthenticationStateListeners; import com.android.server.biometrics.sensors.BiometricScheduler; @@ -50,6 +54,7 @@ import com.android.server.biometrics.sensors.BiometricStateCallback; import com.android.server.biometrics.sensors.LockoutResetDispatcher; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -70,6 +75,10 @@ public class Face10Test { private static final int USER_ID = 20; private static final float FRR_THRESHOLD = 0.2f; + @Rule + public final CheckFlagsRule mCheckFlagsRule = + DeviceFlagsValueProvider.createCheckFlagsRule(); + @Mock private Context mContext; @Mock @@ -145,6 +154,7 @@ public class Face10Test { } @Test + @RequiresFlagsDisabled(Flags.FLAG_DE_HIDL) public void scheduleGenerateChallenge_cachesResult() { final IFaceServiceReceiver[] mocks = IntStream.range(0, 3) .mapToObj(i -> mock(IFaceServiceReceiver.class)) @@ -163,6 +173,7 @@ public class Face10Test { } @Test + @RequiresFlagsDisabled(Flags.FLAG_DE_HIDL) public void scheduleRevokeChallenge_waitsUntilEmpty() { final long challenge = 22; final IFaceServiceReceiver[] mocks = IntStream.range(0, 3) @@ -182,6 +193,7 @@ public class Face10Test { } @Test + @RequiresFlagsDisabled(Flags.FLAG_DE_HIDL) public void scheduleRevokeChallenge_doesNotWaitForever() { mFace10.scheduleGenerateChallenge( SENSOR_ID, USER_ID, mBinder, mock(IFaceServiceReceiver.class), TAG); diff --git a/services/tests/servicestests/src/com/android/server/biometrics/sensors/fingerprint/aidl/FingerprintAuthenticationClientTest.java b/services/tests/servicestests/src/com/android/server/biometrics/sensors/fingerprint/aidl/FingerprintAuthenticationClientTest.java index 4ed6f74d30fa..f96d9e841eba 100644 --- a/services/tests/servicestests/src/com/android/server/biometrics/sensors/fingerprint/aidl/FingerprintAuthenticationClientTest.java +++ b/services/tests/servicestests/src/com/android/server/biometrics/sensors/fingerprint/aidl/FingerprintAuthenticationClientTest.java @@ -56,6 +56,7 @@ import android.os.IBinder; import android.os.RemoteException; import android.os.test.TestLooper; import android.platform.test.annotations.Presubmit; +import android.platform.test.annotations.RequiresFlagsDisabled; import android.platform.test.annotations.RequiresFlagsEnabled; import android.platform.test.flag.junit.CheckFlagsRule; import android.platform.test.flag.junit.DeviceFlagsValueProvider; @@ -158,6 +159,9 @@ public class FingerprintAuthenticationClientTest { private ArgumentCaptor<OperationContextExt> mOperationContextCaptor; @Captor private ArgumentCaptor<Consumer<OperationContext>> mContextInjector; + @Captor + private ArgumentCaptor<Consumer<OperationContext>> mStartHalConsumerCaptor; + private final TestLooper mLooper = new TestLooper(); @Before @@ -175,12 +179,19 @@ public class FingerprintAuthenticationClientTest { public void authNoContext_v1() throws RemoteException { final FingerprintAuthenticationClient client = createClient(1); client.start(mCallback); + if (Flags.deHidl()) { + verify(mBiometricContext).subscribe(mOperationContextCaptor.capture(), + mStartHalConsumerCaptor.capture(), mContextInjector.capture(), any()); + mStartHalConsumerCaptor.getValue().accept(mOperationContextCaptor + .getValue().toAidlContext()); + } verify(mHal).authenticate(eq(OP_ID)); verify(mHal, never()).authenticateWithContext(anyLong(), any()); } @Test + @RequiresFlagsDisabled(Flags.FLAG_DE_HIDL) public void authWithContext_v2() throws RemoteException { final FingerprintAuthenticationClient client = createClient(2); client.start(mCallback); @@ -262,15 +273,24 @@ public class FingerprintAuthenticationClientTest { public void luxProbeWhenAwake() throws RemoteException { when(mBiometricContext.isAwake()).thenReturn(false); when(mBiometricContext.isAod()).thenReturn(false); + final FingerprintAuthenticationClient client = createClient(); client.start(mCallback); + if (Flags.deHidl()) { + verify(mBiometricContext).subscribe(mOperationContextCaptor.capture(), + mStartHalConsumerCaptor.capture(), mContextInjector.capture(), any()); + mStartHalConsumerCaptor.getValue().accept(mOperationContextCaptor + .getValue().toAidlContext()); + } final ArgumentCaptor<OperationContext> captor = ArgumentCaptor.forClass(OperationContext.class); verify(mHal).authenticateWithContext(eq(OP_ID), captor.capture()); OperationContext opContext = captor.getValue(); - verify(mBiometricContext).subscribe( - mOperationContextCaptor.capture(), mContextInjector.capture()); + if (!Flags.deHidl()) { + verify(mBiometricContext).subscribe( + mOperationContextCaptor.capture(), mContextInjector.capture()); + } assertThat(mOperationContextCaptor.getValue().toAidlContext()) .isSameInstanceAs(opContext); @@ -305,6 +325,12 @@ public class FingerprintAuthenticationClientTest { when(mBiometricContext.isAod()).thenReturn(false); final FingerprintAuthenticationClient client = createClient(); client.start(mCallback); + if (Flags.deHidl()) { + verify(mBiometricContext).subscribe(mOperationContextCaptor.capture(), + mStartHalConsumerCaptor.capture(), mContextInjector.capture(), any()); + mStartHalConsumerCaptor.getValue().accept(mOperationContextCaptor + .getValue().toAidlContext()); + } verify(mLuxProbe, isAwake ? times(1) : never()).enable(); } @@ -315,13 +341,21 @@ public class FingerprintAuthenticationClientTest { when(mBiometricContext.isAod()).thenReturn(true); final FingerprintAuthenticationClient client = createClient(); client.start(mCallback); + if (Flags.deHidl()) { + verify(mBiometricContext).subscribe(mOperationContextCaptor.capture(), + mStartHalConsumerCaptor.capture(), mContextInjector.capture(), any()); + mStartHalConsumerCaptor.getValue().accept(mOperationContextCaptor + .getValue().toAidlContext()); + } final ArgumentCaptor<OperationContext> captor = ArgumentCaptor.forClass(OperationContext.class); verify(mHal).authenticateWithContext(eq(OP_ID), captor.capture()); OperationContext opContext = captor.getValue(); - verify(mBiometricContext).subscribe( - mOperationContextCaptor.capture(), mContextInjector.capture()); + if (!Flags.deHidl()) { + verify(mBiometricContext).subscribe( + mOperationContextCaptor.capture(), mContextInjector.capture()); + } assertThat(opContext).isSameInstanceAs( mOperationContextCaptor.getValue().toAidlContext()); @@ -345,6 +379,7 @@ public class FingerprintAuthenticationClientTest { } @Test + @RequiresFlagsDisabled(Flags.FLAG_DE_HIDL) public void notifyHalWhenContextChanges() throws RemoteException { final FingerprintAuthenticationClient client = createClient(); client.start(mCallback); @@ -367,6 +402,36 @@ public class FingerprintAuthenticationClientTest { } @Test + @RequiresFlagsEnabled(Flags.FLAG_DE_HIDL) + public void subscribeContextAndStartHal() throws RemoteException { + final FingerprintAuthenticationClient client = createClient(); + client.start(mCallback); + + verify(mBiometricContext).subscribe(mOperationContextCaptor.capture(), + mStartHalConsumerCaptor.capture(), mContextInjector.capture(), any()); + + mStartHalConsumerCaptor.getValue().accept(mOperationContextCaptor + .getValue().toAidlContext()); + final ArgumentCaptor<OperationContext> captor = + ArgumentCaptor.forClass(OperationContext.class); + + verify(mHal).authenticateWithContext(eq(OP_ID), captor.capture()); + + OperationContext opContext = captor.getValue(); + + assertThat(opContext).isSameInstanceAs( + mOperationContextCaptor.getValue().toAidlContext()); + + mContextInjector.getValue().accept(opContext); + + verify(mHal).onContextChanged(same(opContext)); + + client.stopHalOperation(); + + verify(mBiometricContext).unsubscribe(same(mOperationContextCaptor.getValue())); + } + + @Test public void showHideOverlay_cancel() throws RemoteException { showHideOverlay(c -> c.cancel()); } diff --git a/services/tests/servicestests/src/com/android/server/biometrics/sensors/fingerprint/aidl/FingerprintDetectClientTest.java b/services/tests/servicestests/src/com/android/server/biometrics/sensors/fingerprint/aidl/FingerprintDetectClientTest.java index a467c84845cd..9edb8dde182a 100644 --- a/services/tests/servicestests/src/com/android/server/biometrics/sensors/fingerprint/aidl/FingerprintDetectClientTest.java +++ b/services/tests/servicestests/src/com/android/server/biometrics/sensors/fingerprint/aidl/FingerprintDetectClientTest.java @@ -35,11 +35,16 @@ import android.hardware.fingerprint.IUdfpsOverlayController; import android.os.IBinder; import android.os.RemoteException; import android.platform.test.annotations.Presubmit; +import android.platform.test.annotations.RequiresFlagsDisabled; +import android.platform.test.annotations.RequiresFlagsEnabled; +import android.platform.test.flag.junit.CheckFlagsRule; +import android.platform.test.flag.junit.DeviceFlagsValueProvider; import android.testing.TestableContext; import androidx.test.filters.SmallTest; import androidx.test.platform.app.InstrumentationRegistry; +import com.android.server.biometrics.Flags; import com.android.server.biometrics.log.BiometricContext; import com.android.server.biometrics.log.BiometricLogger; import com.android.server.biometrics.log.OperationContextExt; @@ -67,6 +72,9 @@ public class FingerprintDetectClientTest { @Rule public final TestableContext mContext = new TestableContext( InstrumentationRegistry.getInstrumentation().getTargetContext(), null); + @Rule + public final CheckFlagsRule mCheckFlagsRule = + DeviceFlagsValueProvider.createCheckFlagsRule(); @Mock private ISession mHal; @@ -88,6 +96,8 @@ public class FingerprintDetectClientTest { private ArgumentCaptor<OperationContextExt> mOperationContextCaptor; @Captor private ArgumentCaptor<Consumer<OperationContext>> mContextInjector; + @Captor + private ArgumentCaptor<Consumer<OperationContext>> mStartHalConsumerCaptor; @Rule public final MockitoRule mockito = MockitoJUnit.rule(); @@ -109,6 +119,7 @@ public class FingerprintDetectClientTest { } @Test + @RequiresFlagsDisabled(Flags.FLAG_DE_HIDL) public void detectNoContext_v2() throws RemoteException { final FingerprintDetectClient client = createClient(2); @@ -127,6 +138,7 @@ public class FingerprintDetectClientTest { } @Test + @RequiresFlagsDisabled(Flags.FLAG_DE_HIDL) public void notifyHalWhenContextChanges() throws RemoteException { final FingerprintDetectClient client = createClient(); client.start(mCallback); @@ -149,6 +161,31 @@ public class FingerprintDetectClientTest { } @Test + @RequiresFlagsEnabled(Flags.FLAG_DE_HIDL) + public void subscribeContextAndStartHal() throws RemoteException { + final FingerprintDetectClient client = createClient(); + client.start(mCallback); + + verify(mBiometricContext).subscribe(mOperationContextCaptor.capture(), + mStartHalConsumerCaptor.capture(), mContextInjector.capture(), any()); + + mStartHalConsumerCaptor.getValue().accept( + mOperationContextCaptor.getValue().toAidlContext()); + final ArgumentCaptor<OperationContext> captor = + ArgumentCaptor.forClass(OperationContext.class); + verify(mHal).detectInteractionWithContext(captor.capture()); + OperationContext opContext = captor.getValue(); + + assertThat(opContext).isSameInstanceAs( + mOperationContextCaptor.getValue().toAidlContext()); + mContextInjector.getValue().accept(opContext); + verify(mHal).onContextChanged(same(opContext)); + + client.stopHalOperation(); + verify(mBiometricContext).unsubscribe(same(mOperationContextCaptor.getValue())); + } + + @Test public void testWhenListenerIsNull() { final AidlSession aidl = new AidlSession(0, mHal, USER_ID, mAidlResponseHandler); final FingerprintDetectClient client = new FingerprintDetectClient(mContext, () -> aidl, diff --git a/services/tests/servicestests/src/com/android/server/biometrics/sensors/fingerprint/aidl/FingerprintEnrollClientTest.java b/services/tests/servicestests/src/com/android/server/biometrics/sensors/fingerprint/aidl/FingerprintEnrollClientTest.java index e7d4a2e463f7..951c93935e30 100644 --- a/services/tests/servicestests/src/com/android/server/biometrics/sensors/fingerprint/aidl/FingerprintEnrollClientTest.java +++ b/services/tests/servicestests/src/com/android/server/biometrics/sensors/fingerprint/aidl/FingerprintEnrollClientTest.java @@ -40,12 +40,17 @@ import android.hardware.fingerprint.IUdfpsOverlayController; import android.os.IBinder; import android.os.RemoteException; import android.platform.test.annotations.Presubmit; +import android.platform.test.annotations.RequiresFlagsDisabled; +import android.platform.test.annotations.RequiresFlagsEnabled; +import android.platform.test.flag.junit.CheckFlagsRule; +import android.platform.test.flag.junit.DeviceFlagsValueProvider; import android.platform.test.flag.junit.SetFlagsRule; import android.testing.TestableContext; import androidx.test.filters.SmallTest; import androidx.test.platform.app.InstrumentationRegistry; +import com.android.server.biometrics.Flags; import com.android.server.biometrics.log.BiometricContext; import com.android.server.biometrics.log.BiometricLogger; import com.android.server.biometrics.log.CallbackWithProbe; @@ -73,6 +78,9 @@ import java.util.function.Consumer; public class FingerprintEnrollClientTest { @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); + @Rule + public final CheckFlagsRule mCheckFlagsRule = + DeviceFlagsValueProvider.createCheckFlagsRule(); private static final byte[] HAT = new byte[69]; private static final int USER_ID = 8; @@ -117,6 +125,8 @@ public class FingerprintEnrollClientTest { private ArgumentCaptor<OperationContextExt> mOperationContextCaptor; @Captor private ArgumentCaptor<Consumer<OperationContext>> mContextInjector; + @Captor + private ArgumentCaptor<Consumer<OperationContext>> mStartHalConsumerCaptor; @Rule public final MockitoRule mockito = MockitoJUnit.rule(); @@ -140,6 +150,7 @@ public class FingerprintEnrollClientTest { } @Test + @RequiresFlagsDisabled(Flags.FLAG_DE_HIDL) public void enrollWithContext_v2() throws RemoteException { final FingerprintEnrollClient client = createClient(2); @@ -236,6 +247,7 @@ public class FingerprintEnrollClientTest { } @Test + @RequiresFlagsDisabled(Flags.FLAG_DE_HIDL) public void notifyHalWhenContextChanges() throws RemoteException { final FingerprintEnrollClient client = createClient(); client.start(mCallback); @@ -257,6 +269,30 @@ public class FingerprintEnrollClientTest { } @Test + @RequiresFlagsEnabled(Flags.FLAG_DE_HIDL) + public void subscribeContextAndStartHal() throws RemoteException { + final FingerprintEnrollClient client = createClient(); + client.start(mCallback); + + verify(mBiometricContext).subscribe(mOperationContextCaptor.capture(), + mStartHalConsumerCaptor.capture(), mContextInjector.capture(), any()); + + mStartHalConsumerCaptor.getValue().accept( + mOperationContextCaptor.getValue().toAidlContext()); + final ArgumentCaptor<OperationContext> captor = + ArgumentCaptor.forClass(OperationContext.class); + verify(mHal).enrollWithContext(any(), captor.capture()); + OperationContext opContext = captor.getValue(); + + mContextInjector.getValue().accept( + mOperationContextCaptor.getValue().toAidlContext()); + verify(mHal).onContextChanged(same(opContext)); + + client.stopHalOperation(); + verify(mBiometricContext).unsubscribe(same(mOperationContextCaptor.getValue())); + } + + @Test public void showHideOverlay_cancel() throws RemoteException { showHideOverlay(c -> c.cancel()); } |