Fix biometric context update problem.

Bug: b/288761850
Test: Check b/288761850
Change-Id: I890d102d10a3efa230e26e4e9753f9c66b71afdb
This commit is contained in:
Vincent Wang
2023-08-02 05:56:42 +00:00
parent fb4a3c341a
commit a7c50568f6
2 changed files with 15 additions and 0 deletions

View File

@@ -216,6 +216,10 @@ public final class BiometricContextProvider implements BiometricContext {
public void subscribe(@NonNull OperationContextExt context,
@NonNull Consumer<OperationContext> consumer) {
mSubscribers.put(context, consumer);
// TODO(b/294161627) Combine the getContext/subscribe APIs to avoid race
if (context.getDisplayState() != getDisplayState()) {
consumer.accept(context.update(this, context.isCrypto()).toAidlContext());
}
}
@Override

View File

@@ -251,6 +251,14 @@ public class BiometricContextProviderTest {
assertThat(actual).containsExactly(true, false, true, true, false, false).inOrder();
}
@Test
public void testSubscribesWithDifferentState() throws RemoteException {
final Consumer<OperationContext> nonEmptyConsumer = mock(Consumer.class);
mListener.onDisplayStateChanged(AuthenticateOptions.DISPLAY_STATE_AOD);
mProvider.subscribe(mOpContext, nonEmptyConsumer);
verify(nonEmptyConsumer).accept(same(mOpContext.toAidlContext()));
}
@Test
public void testUnsubscribes() throws RemoteException {
final Consumer<OperationContext> emptyConsumer = mock(Consumer.class);
@@ -259,6 +267,9 @@ public class BiometricContextProviderTest {
mListener.onDisplayStateChanged(AuthenticateOptions.DISPLAY_STATE_AOD);
//reset to unknown to avoid trigger accept when subscribe
mListener.onDisplayStateChanged(AuthenticateOptions.DISPLAY_STATE_UNKNOWN);
final Consumer<OperationContext> nonEmptyConsumer = mock(Consumer.class);
mProvider.subscribe(mOpContext, nonEmptyConsumer);
mListener.onDisplayStateChanged(AuthenticateOptions.DISPLAY_STATE_LOCKSCREEN);