Set safe mode alarm when validation reports NOT_VALID

Bug: 186257328
Test: atest FrameworksVcnTests
Change-Id: I80f37d42e4d61026b3521a4133257cd472c22f1a
This commit is contained in:
Benedict Wong
2021-04-27 14:52:36 -07:00
parent 9974b955e5
commit 44629199de
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();