Merge "Set safe mode alarm when validation reports NOT_VALID"

This commit is contained in:
Benedict Wong
2021-04-28 01:47:08 +00:00
committed by Gerrit Code Review
2 changed files with 41 additions and 2 deletions

View File

@@ -1558,8 +1558,22 @@ public class VcnGatewayConnection extends StateMachine {
teardownAsynchronously();
} /* networkUnwantedCallback */,
(status) -> {
if (status == NetworkAgent.VALIDATION_STATUS_VALID) {
clearFailedAttemptCounterAndSafeModeAlarm();
switch (status) {
case NetworkAgent.VALIDATION_STATUS_VALID:
clearFailedAttemptCounterAndSafeModeAlarm();
break;
case NetworkAgent.VALIDATION_STATUS_NOT_VALID:
// Will only set a new alarm if no safe mode alarm is
// currently scheduled.
setSafeModeAlarm();
break;
default:
Slog.wtf(
TAG,
"Unknown validation status "
+ status
+ "; ignoring");
break;
}
} /* validationStatusCallback */);

View File

@@ -343,6 +343,31 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection
assertFalse(mGatewayConnection.isInSafeMode());
}
@Test
public void testSubsequentFailedValidationTriggersSafeMode() throws Exception {
triggerChildOpened();
mTestLooper.dispatchAll();
triggerValidation(NetworkAgent.VALIDATION_STATUS_VALID);
assertFalse(mGatewayConnection.isInSafeMode());
// Trigger a failed validation, and the subsequent safemode timeout.
triggerValidation(NetworkAgent.VALIDATION_STATUS_NOT_VALID);
mTestLooper.dispatchAll();
final ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class);
verify(mDeps, times(2))
.newWakeupMessage(
eq(mVcnContext),
any(),
eq(VcnGatewayConnection.SAFEMODE_TIMEOUT_ALARM),
runnableCaptor.capture());
runnableCaptor.getValue().run();
mTestLooper.dispatchAll();
assertTrue(mGatewayConnection.isInSafeMode());
}
private Consumer<VcnNetworkAgent> setupNetworkAndGetUnwantedCallback() {
triggerChildOpened();
mTestLooper.dispatchAll();