Merge "Mark cancel when client is interruptable" into udc-dev
This commit is contained in:
@@ -555,7 +555,7 @@ public class BiometricScheduler {
|
|||||||
for (BiometricSchedulerOperation pendingOperation : mPendingOperations) {
|
for (BiometricSchedulerOperation pendingOperation : mPendingOperations) {
|
||||||
Slog.d(getTag(), "[Watchdog cancelling pending] "
|
Slog.d(getTag(), "[Watchdog cancelling pending] "
|
||||||
+ pendingOperation.getClientMonitor());
|
+ pendingOperation.getClientMonitor());
|
||||||
pendingOperation.markCanceling();
|
pendingOperation.markCancelingForWatchdog();
|
||||||
}
|
}
|
||||||
Slog.d(getTag(), "[Watchdog cancelling current] "
|
Slog.d(getTag(), "[Watchdog cancelling current] "
|
||||||
+ mCurrentOperation.getClientMonitor());
|
+ mCurrentOperation.getClientMonitor());
|
||||||
|
|||||||
@@ -267,13 +267,17 @@ public class BiometricSchedulerOperation {
|
|||||||
|
|
||||||
/** Flags this operation as canceled, if possible, but does not cancel it until started. */
|
/** Flags this operation as canceled, if possible, but does not cancel it until started. */
|
||||||
public boolean markCanceling() {
|
public boolean markCanceling() {
|
||||||
if (mState == STATE_WAITING_IN_QUEUE) {
|
if (mState == STATE_WAITING_IN_QUEUE && isInterruptable()) {
|
||||||
mState = STATE_WAITING_IN_QUEUE_CANCELING;
|
mState = STATE_WAITING_IN_QUEUE_CANCELING;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting void markCancelingForWatchdog() {
|
||||||
|
mState = STATE_WAITING_IN_QUEUE_CANCELING;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancel the operation now.
|
* Cancel the operation now.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -62,18 +62,15 @@ public class BiometricSchedulerOperationTest {
|
|||||||
super(null, null, null, null, 0, null, 0, 0,
|
super(null, null, null, null, 0, null, 0, 0,
|
||||||
mock(BiometricLogger.class), mock(BiometricContext.class));
|
mock(BiometricLogger.class), mock(BiometricContext.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isInterruptable() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public final MockitoRule mockito = MockitoJUnit.rule();
|
public final MockitoRule mockito = MockitoJUnit.rule();
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private InterruptableMonitor<FakeHal> mClientMonitor;
|
private InterruptableMonitor<FakeHal> mInterruptableClientMonitor;
|
||||||
|
@Mock
|
||||||
|
private BaseClientMonitor mNonInterruptableClientMonitor;
|
||||||
@Mock
|
@Mock
|
||||||
private ClientMonitorCallback mClientCallback;
|
private ClientMonitorCallback mClientCallback;
|
||||||
@Mock
|
@Mock
|
||||||
@@ -84,149 +81,159 @@ public class BiometricSchedulerOperationTest {
|
|||||||
ArgumentCaptor<ClientMonitorCallback> mStartedCallbackCaptor;
|
ArgumentCaptor<ClientMonitorCallback> mStartedCallbackCaptor;
|
||||||
|
|
||||||
private Handler mHandler;
|
private Handler mHandler;
|
||||||
private BiometricSchedulerOperation mOperation;
|
private BiometricSchedulerOperation mInterruptableOperation;
|
||||||
|
private BiometricSchedulerOperation mNonInterruptableOperation;
|
||||||
private boolean mIsDebuggable;
|
private boolean mIsDebuggable;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
mHandler = new Handler(TestableLooper.get(this).getLooper());
|
mHandler = new Handler(TestableLooper.get(this).getLooper());
|
||||||
mIsDebuggable = false;
|
mIsDebuggable = false;
|
||||||
mOperation = new BiometricSchedulerOperation(mClientMonitor, mClientCallback,
|
mInterruptableOperation = new BiometricSchedulerOperation(mInterruptableClientMonitor,
|
||||||
() -> mIsDebuggable);
|
mClientCallback, () -> mIsDebuggable);
|
||||||
|
mNonInterruptableOperation = new BiometricSchedulerOperation(mNonInterruptableClientMonitor,
|
||||||
|
mClientCallback, () -> mIsDebuggable);
|
||||||
|
|
||||||
|
when(mInterruptableClientMonitor.isInterruptable()).thenReturn(true);
|
||||||
|
when(mNonInterruptableClientMonitor.isInterruptable()).thenReturn(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStartWithCookie() {
|
public void testStartWithCookie() {
|
||||||
final int cookie = 200;
|
final int cookie = 200;
|
||||||
when(mClientMonitor.getCookie()).thenReturn(cookie);
|
when(mInterruptableClientMonitor.getCookie()).thenReturn(cookie);
|
||||||
when(mClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
when(mInterruptableClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
||||||
|
|
||||||
assertThat(mOperation.isReadyToStart(mOnStartCallback)).isEqualTo(cookie);
|
assertThat(mInterruptableOperation.isReadyToStart(mOnStartCallback)).isEqualTo(cookie);
|
||||||
assertThat(mOperation.isStarted()).isFalse();
|
assertThat(mInterruptableOperation.isStarted()).isFalse();
|
||||||
assertThat(mOperation.isCanceling()).isFalse();
|
assertThat(mInterruptableOperation.isCanceling()).isFalse();
|
||||||
assertThat(mOperation.isFinished()).isFalse();
|
assertThat(mInterruptableOperation.isFinished()).isFalse();
|
||||||
verify(mClientMonitor).waitForCookie(any());
|
verify(mInterruptableClientMonitor).waitForCookie(any());
|
||||||
|
|
||||||
final boolean started = mOperation.startWithCookie(mOnStartCallback, cookie);
|
final boolean started = mInterruptableOperation.startWithCookie(mOnStartCallback, cookie);
|
||||||
|
|
||||||
assertThat(started).isTrue();
|
assertThat(started).isTrue();
|
||||||
verify(mClientMonitor).start(mStartedCallbackCaptor.capture());
|
verify(mInterruptableClientMonitor).start(mStartedCallbackCaptor.capture());
|
||||||
mStartedCallbackCaptor.getValue().onClientStarted(mClientMonitor);
|
mStartedCallbackCaptor.getValue().onClientStarted(mInterruptableClientMonitor);
|
||||||
assertThat(mOperation.isStarted()).isTrue();
|
assertThat(mInterruptableOperation.isStarted()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoStartWithoutCookie() {
|
public void testNoStartWithoutCookie() {
|
||||||
final int goodCookie = 20;
|
final int goodCookie = 20;
|
||||||
final int badCookie = 22;
|
final int badCookie = 22;
|
||||||
when(mClientMonitor.getCookie()).thenReturn(goodCookie);
|
when(mInterruptableClientMonitor.getCookie()).thenReturn(goodCookie);
|
||||||
when(mClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
when(mInterruptableClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
||||||
|
|
||||||
assertThat(mOperation.isReadyToStart(mOnStartCallback)).isEqualTo(goodCookie);
|
assertThat(mInterruptableOperation.isReadyToStart(mOnStartCallback)).isEqualTo(goodCookie);
|
||||||
final boolean started = mOperation.startWithCookie(mOnStartCallback, badCookie);
|
final boolean started = mInterruptableOperation.startWithCookie(mOnStartCallback,
|
||||||
|
badCookie);
|
||||||
|
|
||||||
assertThat(started).isFalse();
|
assertThat(started).isFalse();
|
||||||
assertThat(mOperation.isStarted()).isFalse();
|
assertThat(mInterruptableOperation.isStarted()).isFalse();
|
||||||
assertThat(mOperation.isCanceling()).isFalse();
|
assertThat(mInterruptableOperation.isCanceling()).isFalse();
|
||||||
assertThat(mOperation.isFinished()).isFalse();
|
assertThat(mInterruptableOperation.isFinished()).isFalse();
|
||||||
verify(mClientMonitor).waitForCookie(any());
|
verify(mInterruptableClientMonitor).waitForCookie(any());
|
||||||
verify(mClientMonitor, never()).start(any());
|
verify(mInterruptableClientMonitor, never()).start(any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSecondStartWithCookieCrashesWhenDebuggable() {
|
public void testSecondStartWithCookieCrashesWhenDebuggable() {
|
||||||
final int cookie = 5;
|
final int cookie = 5;
|
||||||
mIsDebuggable = true;
|
mIsDebuggable = true;
|
||||||
when(mClientMonitor.getCookie()).thenReturn(cookie);
|
when(mInterruptableClientMonitor.getCookie()).thenReturn(cookie);
|
||||||
when(mClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
when(mInterruptableClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
||||||
|
|
||||||
final boolean started = mOperation.startWithCookie(mOnStartCallback, cookie);
|
final boolean started = mInterruptableOperation.startWithCookie(mOnStartCallback, cookie);
|
||||||
assertThat(started).isTrue();
|
assertThat(started).isTrue();
|
||||||
|
|
||||||
assertThrows(IllegalStateException.class,
|
assertThrows(IllegalStateException.class,
|
||||||
() -> mOperation.startWithCookie(mOnStartCallback, cookie));
|
() -> mInterruptableOperation.startWithCookie(mOnStartCallback, cookie));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSecondStartWithCookieFailsNicelyWhenNotDebuggable() {
|
public void testSecondStartWithCookieFailsNicelyWhenNotDebuggable() {
|
||||||
final int cookie = 5;
|
final int cookie = 5;
|
||||||
mIsDebuggable = false;
|
mIsDebuggable = false;
|
||||||
when(mClientMonitor.getCookie()).thenReturn(cookie);
|
when(mInterruptableClientMonitor.getCookie()).thenReturn(cookie);
|
||||||
when(mClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
when(mInterruptableClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
||||||
|
|
||||||
final boolean started = mOperation.startWithCookie(mOnStartCallback, cookie);
|
final boolean started = mInterruptableOperation.startWithCookie(mOnStartCallback, cookie);
|
||||||
assertThat(started).isTrue();
|
assertThat(started).isTrue();
|
||||||
|
|
||||||
final boolean startedAgain = mOperation.startWithCookie(mOnStartCallback, cookie);
|
final boolean startedAgain = mInterruptableOperation.startWithCookie(mOnStartCallback,
|
||||||
|
cookie);
|
||||||
assertThat(startedAgain).isFalse();
|
assertThat(startedAgain).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void startsWhenReadyAndHalAvailable() {
|
public void startsWhenReadyAndHalAvailable() {
|
||||||
when(mClientMonitor.getCookie()).thenReturn(0);
|
when(mInterruptableClientMonitor.getCookie()).thenReturn(0);
|
||||||
when(mClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
when(mInterruptableClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
||||||
|
|
||||||
mOperation.start(mOnStartCallback);
|
mInterruptableOperation.start(mOnStartCallback);
|
||||||
verify(mClientMonitor).start(mStartedCallbackCaptor.capture());
|
verify(mInterruptableClientMonitor).start(mStartedCallbackCaptor.capture());
|
||||||
mStartedCallbackCaptor.getValue().onClientStarted(mClientMonitor);
|
mStartedCallbackCaptor.getValue().onClientStarted(mInterruptableClientMonitor);
|
||||||
|
|
||||||
assertThat(mOperation.isStarted()).isTrue();
|
assertThat(mInterruptableOperation.isStarted()).isTrue();
|
||||||
assertThat(mOperation.isCanceling()).isFalse();
|
assertThat(mInterruptableOperation.isCanceling()).isFalse();
|
||||||
assertThat(mOperation.isFinished()).isFalse();
|
assertThat(mInterruptableOperation.isFinished()).isFalse();
|
||||||
|
|
||||||
verify(mClientCallback).onClientStarted(eq(mClientMonitor));
|
verify(mClientCallback).onClientStarted(eq(mInterruptableClientMonitor));
|
||||||
verify(mOnStartCallback).onClientStarted(eq(mClientMonitor));
|
verify(mOnStartCallback).onClientStarted(eq(mInterruptableClientMonitor));
|
||||||
verify(mClientCallback, never()).onClientFinished(any(), anyBoolean());
|
verify(mClientCallback, never()).onClientFinished(any(), anyBoolean());
|
||||||
verify(mOnStartCallback, never()).onClientFinished(any(), anyBoolean());
|
verify(mOnStartCallback, never()).onClientFinished(any(), anyBoolean());
|
||||||
|
|
||||||
mStartedCallbackCaptor.getValue().onClientFinished(mClientMonitor, true);
|
mStartedCallbackCaptor.getValue().onClientFinished(mInterruptableClientMonitor,
|
||||||
|
true);
|
||||||
|
|
||||||
assertThat(mOperation.isFinished()).isTrue();
|
assertThat(mInterruptableOperation.isFinished()).isTrue();
|
||||||
assertThat(mOperation.isCanceling()).isFalse();
|
assertThat(mInterruptableOperation.isCanceling()).isFalse();
|
||||||
verify(mClientMonitor).destroy();
|
verify(mInterruptableClientMonitor).destroy();
|
||||||
verify(mOnStartCallback).onClientFinished(eq(mClientMonitor), eq(true));
|
verify(mOnStartCallback).onClientFinished(eq(mInterruptableClientMonitor), eq(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void startFailsWhenReadyButHalNotAvailable() {
|
public void startFailsWhenReadyButHalNotAvailable() {
|
||||||
when(mClientMonitor.getCookie()).thenReturn(0);
|
when(mInterruptableClientMonitor.getCookie()).thenReturn(0);
|
||||||
when(mClientMonitor.getFreshDaemon()).thenReturn(null);
|
when(mInterruptableClientMonitor.getFreshDaemon()).thenReturn(null);
|
||||||
|
|
||||||
mOperation.start(mOnStartCallback);
|
mInterruptableOperation.start(mOnStartCallback);
|
||||||
verify(mClientMonitor, never()).start(any());
|
verify(mInterruptableClientMonitor, never()).start(any());
|
||||||
|
|
||||||
assertThat(mOperation.isStarted()).isFalse();
|
assertThat(mInterruptableOperation.isStarted()).isFalse();
|
||||||
assertThat(mOperation.isCanceling()).isFalse();
|
assertThat(mInterruptableOperation.isCanceling()).isFalse();
|
||||||
assertThat(mOperation.isFinished()).isTrue();
|
assertThat(mInterruptableOperation.isFinished()).isTrue();
|
||||||
|
|
||||||
verify(mClientCallback, never()).onClientStarted(eq(mClientMonitor));
|
verify(mClientCallback, never()).onClientStarted(eq(mInterruptableClientMonitor));
|
||||||
verify(mOnStartCallback, never()).onClientStarted(eq(mClientMonitor));
|
verify(mOnStartCallback, never()).onClientStarted(eq(mInterruptableClientMonitor));
|
||||||
verify(mClientCallback).onClientFinished(eq(mClientMonitor), eq(false));
|
verify(mClientCallback).onClientFinished(eq(mInterruptableClientMonitor), eq(false));
|
||||||
verify(mOnStartCallback).onClientFinished(eq(mClientMonitor), eq(false));
|
verify(mOnStartCallback).onClientFinished(eq(mInterruptableClientMonitor), eq(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void secondStartCrashesWhenDebuggable() {
|
public void secondStartCrashesWhenDebuggable() {
|
||||||
mIsDebuggable = true;
|
mIsDebuggable = true;
|
||||||
when(mClientMonitor.getCookie()).thenReturn(0);
|
when(mInterruptableClientMonitor.getCookie()).thenReturn(0);
|
||||||
when(mClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
when(mInterruptableClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
||||||
|
|
||||||
final boolean started = mOperation.start(mOnStartCallback);
|
final boolean started = mInterruptableOperation.start(mOnStartCallback);
|
||||||
assertThat(started).isTrue();
|
assertThat(started).isTrue();
|
||||||
|
|
||||||
assertThrows(IllegalStateException.class, () -> mOperation.start(mOnStartCallback));
|
assertThrows(IllegalStateException.class, () -> mInterruptableOperation.start(
|
||||||
|
mOnStartCallback));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void secondStartFailsNicelyWhenNotDebuggable() {
|
public void secondStartFailsNicelyWhenNotDebuggable() {
|
||||||
mIsDebuggable = false;
|
mIsDebuggable = false;
|
||||||
when(mClientMonitor.getCookie()).thenReturn(0);
|
when(mInterruptableClientMonitor.getCookie()).thenReturn(0);
|
||||||
when(mClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
when(mInterruptableClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
||||||
|
|
||||||
final boolean started = mOperation.start(mOnStartCallback);
|
final boolean started = mInterruptableOperation.start(mOnStartCallback);
|
||||||
assertThat(started).isTrue();
|
assertThat(started).isTrue();
|
||||||
|
|
||||||
final boolean startedAgain = mOperation.start(mOnStartCallback);
|
final boolean startedAgain = mInterruptableOperation.start(mOnStartCallback);
|
||||||
assertThat(startedAgain).isFalse();
|
assertThat(startedAgain).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,77 +241,78 @@ public class BiometricSchedulerOperationTest {
|
|||||||
public void doesNotStartWithCookie() {
|
public void doesNotStartWithCookie() {
|
||||||
// This class only throws exceptions when debuggable.
|
// This class only throws exceptions when debuggable.
|
||||||
mIsDebuggable = true;
|
mIsDebuggable = true;
|
||||||
when(mClientMonitor.getCookie()).thenReturn(9);
|
when(mInterruptableClientMonitor.getCookie()).thenReturn(9);
|
||||||
assertThrows(IllegalStateException.class,
|
assertThrows(IllegalStateException.class,
|
||||||
() -> mOperation.start(mock(ClientMonitorCallback.class)));
|
() -> mInterruptableOperation.start(mock(ClientMonitorCallback.class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cannotRestart() {
|
public void cannotRestart() {
|
||||||
// This class only throws exceptions when debuggable.
|
// This class only throws exceptions when debuggable.
|
||||||
mIsDebuggable = true;
|
mIsDebuggable = true;
|
||||||
when(mClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
when(mInterruptableClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
||||||
|
|
||||||
mOperation.start(mOnStartCallback);
|
mInterruptableOperation.start(mOnStartCallback);
|
||||||
|
|
||||||
assertThrows(IllegalStateException.class,
|
assertThrows(IllegalStateException.class,
|
||||||
() -> mOperation.start(mock(ClientMonitorCallback.class)));
|
() -> mInterruptableOperation.start(mock(ClientMonitorCallback.class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void abortsNotRunning() {
|
public void abortsNotRunning() {
|
||||||
// This class only throws exceptions when debuggable.
|
// This class only throws exceptions when debuggable.
|
||||||
mIsDebuggable = true;
|
mIsDebuggable = true;
|
||||||
when(mClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
when(mInterruptableClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
||||||
|
|
||||||
mOperation.abort();
|
mInterruptableOperation.abort();
|
||||||
|
|
||||||
assertThat(mOperation.isFinished()).isTrue();
|
assertThat(mInterruptableOperation.isFinished()).isTrue();
|
||||||
verify(mClientMonitor).unableToStart();
|
verify(mInterruptableClientMonitor).unableToStart();
|
||||||
verify(mClientMonitor).destroy();
|
verify(mInterruptableClientMonitor).destroy();
|
||||||
assertThrows(IllegalStateException.class,
|
assertThrows(IllegalStateException.class,
|
||||||
() -> mOperation.start(mock(ClientMonitorCallback.class)));
|
() -> mInterruptableOperation.start(mock(ClientMonitorCallback.class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void abortCrashesWhenDebuggableIfOperationIsRunning() {
|
public void abortCrashesWhenDebuggableIfOperationIsRunning() {
|
||||||
mIsDebuggable = true;
|
mIsDebuggable = true;
|
||||||
when(mClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
when(mInterruptableClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
||||||
|
|
||||||
mOperation.start(mOnStartCallback);
|
mInterruptableOperation.start(mOnStartCallback);
|
||||||
|
|
||||||
assertThrows(IllegalStateException.class, () -> mOperation.abort());
|
assertThrows(IllegalStateException.class, () -> mInterruptableOperation.abort());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void abortFailsNicelyWhenNotDebuggableIfOperationIsRunning() {
|
public void abortFailsNicelyWhenNotDebuggableIfOperationIsRunning() {
|
||||||
mIsDebuggable = false;
|
mIsDebuggable = false;
|
||||||
when(mClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
when(mInterruptableClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
||||||
|
|
||||||
mOperation.start(mOnStartCallback);
|
mInterruptableOperation.start(mOnStartCallback);
|
||||||
|
|
||||||
mOperation.abort();
|
mInterruptableOperation.abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cancel() {
|
public void cancel() {
|
||||||
when(mClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
when(mInterruptableClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
||||||
|
|
||||||
final ClientMonitorCallback cancelCb = mock(ClientMonitorCallback.class);
|
final ClientMonitorCallback cancelCb = mock(ClientMonitorCallback.class);
|
||||||
mOperation.start(mOnStartCallback);
|
mInterruptableOperation.start(mOnStartCallback);
|
||||||
verify(mClientMonitor).start(mStartedCallbackCaptor.capture());
|
verify(mInterruptableClientMonitor).start(mStartedCallbackCaptor.capture());
|
||||||
mStartedCallbackCaptor.getValue().onClientStarted(mClientMonitor);
|
mStartedCallbackCaptor.getValue().onClientStarted(mInterruptableClientMonitor);
|
||||||
mOperation.cancel(mHandler, cancelCb);
|
mInterruptableOperation.cancel(mHandler, cancelCb);
|
||||||
|
|
||||||
assertThat(mOperation.isCanceling()).isTrue();
|
assertThat(mInterruptableOperation.isCanceling()).isTrue();
|
||||||
verify(mClientMonitor).cancel();
|
verify(mInterruptableClientMonitor).cancel();
|
||||||
verify(mClientMonitor, never()).destroy();
|
verify(mInterruptableClientMonitor, never()).destroy();
|
||||||
|
|
||||||
mStartedCallbackCaptor.getValue().onClientFinished(mClientMonitor, true);
|
mStartedCallbackCaptor.getValue().onClientFinished(mInterruptableClientMonitor,
|
||||||
|
true);
|
||||||
|
|
||||||
assertThat(mOperation.isFinished()).isTrue();
|
assertThat(mInterruptableOperation.isFinished()).isTrue();
|
||||||
assertThat(mOperation.isCanceling()).isFalse();
|
assertThat(mInterruptableOperation.isCanceling()).isFalse();
|
||||||
verify(mClientMonitor).destroy();
|
verify(mInterruptableClientMonitor).destroy();
|
||||||
|
|
||||||
// should be unused since the operation was started
|
// should be unused since the operation was started
|
||||||
verify(cancelCb, never()).onClientStarted(any());
|
verify(cancelCb, never()).onClientStarted(any());
|
||||||
@@ -313,61 +321,84 @@ public class BiometricSchedulerOperationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cancelWithoutStarting() {
|
public void cancelWithoutStarting() {
|
||||||
when(mClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
when(mInterruptableClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
||||||
|
|
||||||
final ClientMonitorCallback cancelCb = mock(ClientMonitorCallback.class);
|
final ClientMonitorCallback cancelCb = mock(ClientMonitorCallback.class);
|
||||||
mOperation.cancel(mHandler, cancelCb);
|
mInterruptableOperation.cancel(mHandler, cancelCb);
|
||||||
|
|
||||||
assertThat(mOperation.isCanceling()).isTrue();
|
assertThat(mInterruptableOperation.isCanceling()).isTrue();
|
||||||
ArgumentCaptor<ClientMonitorCallback> cbCaptor =
|
ArgumentCaptor<ClientMonitorCallback> cbCaptor =
|
||||||
ArgumentCaptor.forClass(ClientMonitorCallback.class);
|
ArgumentCaptor.forClass(ClientMonitorCallback.class);
|
||||||
verify(mClientMonitor).cancelWithoutStarting(cbCaptor.capture());
|
verify(mInterruptableClientMonitor).cancelWithoutStarting(cbCaptor.capture());
|
||||||
|
|
||||||
cbCaptor.getValue().onClientFinished(mClientMonitor, true);
|
cbCaptor.getValue().onClientFinished(mInterruptableClientMonitor, true);
|
||||||
verify(cancelCb).onClientFinished(eq(mClientMonitor), eq(true));
|
verify(cancelCb).onClientFinished(eq(mInterruptableClientMonitor), eq(true));
|
||||||
verify(mClientMonitor, never()).start(any());
|
verify(mInterruptableClientMonitor, never()).start(any());
|
||||||
verify(mClientMonitor, never()).cancel();
|
verify(mInterruptableClientMonitor, never()).cancel();
|
||||||
verify(mClientMonitor).destroy();
|
verify(mInterruptableClientMonitor).destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cancelCrashesWhenDebuggableIfOperationIsFinished() {
|
public void cancelCrashesWhenDebuggableIfOperationIsFinished() {
|
||||||
mIsDebuggable = true;
|
mIsDebuggable = true;
|
||||||
when(mClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
when(mInterruptableClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
||||||
|
|
||||||
mOperation.abort();
|
mInterruptableOperation.abort();
|
||||||
assertThat(mOperation.isFinished()).isTrue();
|
assertThat(mInterruptableOperation.isFinished()).isTrue();
|
||||||
|
|
||||||
final ClientMonitorCallback cancelCb = mock(ClientMonitorCallback.class);
|
final ClientMonitorCallback cancelCb = mock(ClientMonitorCallback.class);
|
||||||
assertThrows(IllegalStateException.class, () -> mOperation.cancel(mHandler, cancelCb));
|
assertThrows(IllegalStateException.class, () -> mInterruptableOperation.cancel(mHandler,
|
||||||
|
cancelCb));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cancelFailsNicelyWhenNotDebuggableIfOperationIsFinished() {
|
public void cancelFailsNicelyWhenNotDebuggableIfOperationIsFinished() {
|
||||||
mIsDebuggable = false;
|
mIsDebuggable = false;
|
||||||
when(mClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
when(mInterruptableClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
||||||
|
|
||||||
mOperation.abort();
|
mInterruptableOperation.abort();
|
||||||
assertThat(mOperation.isFinished()).isTrue();
|
assertThat(mInterruptableOperation.isFinished()).isTrue();
|
||||||
|
|
||||||
final ClientMonitorCallback cancelCb = mock(ClientMonitorCallback.class);
|
final ClientMonitorCallback cancelCb = mock(ClientMonitorCallback.class);
|
||||||
mOperation.cancel(mHandler, cancelCb);
|
mInterruptableOperation.cancel(mHandler, cancelCb);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void markCanceling() {
|
public void markCanceling_interruptableClient() {
|
||||||
when(mClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
when(mInterruptableClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
||||||
|
|
||||||
mOperation.markCanceling();
|
mInterruptableOperation.markCanceling();
|
||||||
|
|
||||||
assertThat(mOperation.isMarkedCanceling()).isTrue();
|
assertThat(mInterruptableOperation.isMarkedCanceling()).isTrue();
|
||||||
assertThat(mOperation.isCanceling()).isFalse();
|
assertThat(mInterruptableOperation.isCanceling()).isFalse();
|
||||||
assertThat(mOperation.isFinished()).isFalse();
|
assertThat(mInterruptableOperation.isFinished()).isFalse();
|
||||||
verify(mClientMonitor, never()).start(any());
|
verify(mInterruptableClientMonitor, never()).start(any());
|
||||||
verify(mClientMonitor, never()).cancel();
|
verify(mInterruptableClientMonitor, never()).cancel();
|
||||||
verify(mClientMonitor, never()).cancelWithoutStarting(any());
|
verify(mInterruptableClientMonitor, never()).cancelWithoutStarting(any());
|
||||||
verify(mClientMonitor, never()).unableToStart();
|
verify(mInterruptableClientMonitor, never()).unableToStart();
|
||||||
verify(mClientMonitor, never()).destroy();
|
verify(mInterruptableClientMonitor, never()).destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void markCanceling_nonInterruptableClient() {
|
||||||
|
mNonInterruptableOperation.markCanceling();
|
||||||
|
|
||||||
|
assertThat(mNonInterruptableOperation.isMarkedCanceling()).isFalse();
|
||||||
|
assertThat(mNonInterruptableOperation.isCanceling()).isFalse();
|
||||||
|
assertThat(mNonInterruptableOperation.isFinished()).isFalse();
|
||||||
|
verify(mNonInterruptableClientMonitor, never()).start(any());
|
||||||
|
verify(mNonInterruptableClientMonitor, never()).cancel();
|
||||||
|
verify(mNonInterruptableClientMonitor, never()).cancelWithoutStarting(any());
|
||||||
|
verify(mNonInterruptableClientMonitor, never()).destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void markCancelingForWatchdog() {
|
||||||
|
mNonInterruptableOperation.markCancelingForWatchdog();
|
||||||
|
mInterruptableOperation.markCancelingForWatchdog();
|
||||||
|
|
||||||
|
assertThat(mInterruptableOperation.isMarkedCanceling()).isTrue();
|
||||||
|
assertThat(mNonInterruptableOperation.isMarkedCanceling()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -381,26 +412,26 @@ public class BiometricSchedulerOperationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void markCancellingAndStart(Integer withCookie) {
|
private void markCancellingAndStart(Integer withCookie) {
|
||||||
when(mClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
when(mInterruptableClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
||||||
if (withCookie != null) {
|
if (withCookie != null) {
|
||||||
when(mClientMonitor.getCookie()).thenReturn(withCookie);
|
when(mInterruptableClientMonitor.getCookie()).thenReturn(withCookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
mOperation.markCanceling();
|
mInterruptableOperation.markCanceling();
|
||||||
final ClientMonitorCallback cb = mock(ClientMonitorCallback.class);
|
final ClientMonitorCallback cb = mock(ClientMonitorCallback.class);
|
||||||
if (withCookie != null) {
|
if (withCookie != null) {
|
||||||
mOperation.startWithCookie(cb, withCookie);
|
mInterruptableOperation.startWithCookie(cb, withCookie);
|
||||||
} else {
|
} else {
|
||||||
mOperation.start(cb);
|
mInterruptableOperation.start(cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
assertThat(mOperation.isFinished()).isTrue();
|
assertThat(mInterruptableOperation.isFinished()).isTrue();
|
||||||
verify(cb).onClientFinished(eq(mClientMonitor), eq(true));
|
verify(cb).onClientFinished(eq(mInterruptableClientMonitor), eq(true));
|
||||||
verify(mClientMonitor, never()).start(any());
|
verify(mInterruptableClientMonitor, never()).start(any());
|
||||||
verify(mClientMonitor, never()).cancel();
|
verify(mInterruptableClientMonitor, never()).cancel();
|
||||||
verify(mClientMonitor, never()).cancelWithoutStarting(any());
|
verify(mInterruptableClientMonitor, never()).cancelWithoutStarting(any());
|
||||||
verify(mClientMonitor, never()).unableToStart();
|
verify(mInterruptableClientMonitor, never()).unableToStart();
|
||||||
verify(mClientMonitor).destroy();
|
verify(mInterruptableClientMonitor).destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -414,23 +445,23 @@ public class BiometricSchedulerOperationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void cancelWatchdog(boolean start) {
|
private void cancelWatchdog(boolean start) {
|
||||||
when(mClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
when(mInterruptableClientMonitor.getFreshDaemon()).thenReturn(mHal);
|
||||||
|
|
||||||
mOperation.start(mOnStartCallback);
|
mInterruptableOperation.start(mOnStartCallback);
|
||||||
if (start) {
|
if (start) {
|
||||||
verify(mClientMonitor).start(mStartedCallbackCaptor.capture());
|
verify(mInterruptableClientMonitor).start(mStartedCallbackCaptor.capture());
|
||||||
mStartedCallbackCaptor.getValue().onClientStarted(mClientMonitor);
|
mStartedCallbackCaptor.getValue().onClientStarted(mInterruptableClientMonitor);
|
||||||
}
|
}
|
||||||
mOperation.cancel(mHandler, mock(ClientMonitorCallback.class));
|
mInterruptableOperation.cancel(mHandler, mock(ClientMonitorCallback.class));
|
||||||
|
|
||||||
assertThat(mOperation.isCanceling()).isTrue();
|
assertThat(mInterruptableOperation.isCanceling()).isTrue();
|
||||||
|
|
||||||
// omit call to onClientFinished and trigger watchdog
|
// omit call to onClientFinished and trigger watchdog
|
||||||
mOperation.mCancelWatchdog.run();
|
mInterruptableOperation.mCancelWatchdog.run();
|
||||||
|
|
||||||
assertThat(mOperation.isFinished()).isTrue();
|
assertThat(mInterruptableOperation.isFinished()).isTrue();
|
||||||
assertThat(mOperation.isCanceling()).isFalse();
|
assertThat(mInterruptableOperation.isCanceling()).isFalse();
|
||||||
verify(mOnStartCallback).onClientFinished(eq(mClientMonitor), eq(false));
|
verify(mOnStartCallback).onClientFinished(eq(mInterruptableClientMonitor), eq(false));
|
||||||
verify(mClientMonitor).destroy();
|
verify(mInterruptableClientMonitor).destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user