Merge "Always trigger safe mode callbacks" am: 831f78825b am: 24e038e8a4 am: a03a566bb1 am: ce69365479
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1811936 Change-Id: I7f92cc2b136bda7543738621298d5783c5a364cf
This commit is contained in:
@@ -352,7 +352,7 @@ public class Vcn extends Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleSafeModeStatusChanged() {
|
private void handleSafeModeStatusChanged() {
|
||||||
logDbg("VcnGatewayConnection safe mode status changed");
|
logVdbg("VcnGatewayConnection safe mode status changed");
|
||||||
boolean hasSafeModeGatewayConnection = false;
|
boolean hasSafeModeGatewayConnection = false;
|
||||||
|
|
||||||
// If any VcnGatewayConnection is in safe mode, mark the entire VCN as being in safe mode
|
// If any VcnGatewayConnection is in safe mode, mark the entire VCN as being in safe mode
|
||||||
@@ -368,7 +368,7 @@ public class Vcn extends Handler {
|
|||||||
hasSafeModeGatewayConnection ? VCN_STATUS_CODE_SAFE_MODE : VCN_STATUS_CODE_ACTIVE;
|
hasSafeModeGatewayConnection ? VCN_STATUS_CODE_SAFE_MODE : VCN_STATUS_CODE_ACTIVE;
|
||||||
if (oldStatus != mCurrentStatus) {
|
if (oldStatus != mCurrentStatus) {
|
||||||
mVcnCallback.onSafeModeStatusChanged(hasSafeModeGatewayConnection);
|
mVcnCallback.onSafeModeStatusChanged(hasSafeModeGatewayConnection);
|
||||||
logDbg(
|
logInfo(
|
||||||
"Safe mode "
|
"Safe mode "
|
||||||
+ (mCurrentStatus == VCN_STATUS_CODE_SAFE_MODE ? "entered" : "exited"));
|
+ (mCurrentStatus == VCN_STATUS_CODE_SAFE_MODE ? "entered" : "exited"));
|
||||||
}
|
}
|
||||||
@@ -539,6 +539,16 @@ public class Vcn extends Handler {
|
|||||||
Slog.d(TAG, getLogPrefix() + msg, tr);
|
Slog.d(TAG, getLogPrefix() + msg, tr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void logInfo(String msg) {
|
||||||
|
Slog.i(TAG, getLogPrefix() + msg);
|
||||||
|
LOCAL_LOG.log(getLogPrefix() + "INFO: " + msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void logInfo(String msg, Throwable tr) {
|
||||||
|
Slog.i(TAG, getLogPrefix() + msg, tr);
|
||||||
|
LOCAL_LOG.log(getLogPrefix() + "INFO: " + msg + tr);
|
||||||
|
}
|
||||||
|
|
||||||
private void logErr(String msg) {
|
private void logErr(String msg) {
|
||||||
Slog.e(TAG, getLogPrefix() + msg);
|
Slog.e(TAG, getLogPrefix() + msg);
|
||||||
LOCAL_LOG.log(getLogPrefix() + "ERR: " + msg);
|
LOCAL_LOG.log(getLogPrefix() + "ERR: " + msg);
|
||||||
|
|||||||
@@ -1677,10 +1677,8 @@ public class VcnGatewayConnection extends StateMachine {
|
|||||||
mFailedAttempts = 0;
|
mFailedAttempts = 0;
|
||||||
cancelSafeModeAlarm();
|
cancelSafeModeAlarm();
|
||||||
|
|
||||||
if (mIsInSafeMode) {
|
mIsInSafeMode = false;
|
||||||
mIsInSafeMode = false;
|
mGatewayStatusCallback.onSafeModeStatusChanged();
|
||||||
mGatewayStatusCallback.onSafeModeStatusChanged();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void applyTransform(
|
protected void applyTransform(
|
||||||
|
|||||||
@@ -322,6 +322,7 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection
|
|||||||
triggerValidation(NetworkAgent.VALIDATION_STATUS_VALID);
|
triggerValidation(NetworkAgent.VALIDATION_STATUS_VALID);
|
||||||
verify(mSafeModeTimeoutAlarm).cancel();
|
verify(mSafeModeTimeoutAlarm).cancel();
|
||||||
assertFalse(mGatewayConnection.isInSafeMode());
|
assertFalse(mGatewayConnection.isInSafeMode());
|
||||||
|
verifySafeModeStateAndCallbackFired(1 /* invocationCount */, false /* isInSafeMode */);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -391,6 +392,7 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection
|
|||||||
|
|
||||||
triggerValidation(NetworkAgent.VALIDATION_STATUS_VALID);
|
triggerValidation(NetworkAgent.VALIDATION_STATUS_VALID);
|
||||||
|
|
||||||
|
verifySafeModeStateAndCallbackFired(2 /* invocationCount */, false /* isInSafeMode */);
|
||||||
assertFalse(mGatewayConnection.isInSafeMode());
|
assertFalse(mGatewayConnection.isInSafeMode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,7 +402,7 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection
|
|||||||
mTestLooper.dispatchAll();
|
mTestLooper.dispatchAll();
|
||||||
|
|
||||||
triggerValidation(NetworkAgent.VALIDATION_STATUS_VALID);
|
triggerValidation(NetworkAgent.VALIDATION_STATUS_VALID);
|
||||||
assertFalse(mGatewayConnection.isInSafeMode());
|
verifySafeModeStateAndCallbackFired(1 /* invocationCount */, false /* isInSafeMode */);
|
||||||
|
|
||||||
// Trigger a failed validation, and the subsequent safemode timeout.
|
// Trigger a failed validation, and the subsequent safemode timeout.
|
||||||
triggerValidation(NetworkAgent.VALIDATION_STATUS_NOT_VALID);
|
triggerValidation(NetworkAgent.VALIDATION_STATUS_NOT_VALID);
|
||||||
@@ -416,7 +418,7 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection
|
|||||||
runnableCaptor.getValue().run();
|
runnableCaptor.getValue().run();
|
||||||
mTestLooper.dispatchAll();
|
mTestLooper.dispatchAll();
|
||||||
|
|
||||||
assertTrue(mGatewayConnection.isInSafeMode());
|
verifySafeModeStateAndCallbackFired(2 /* invocationCount */, true /* isInSafeMode */);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Consumer<VcnNetworkAgent> setupNetworkAndGetUnwantedCallback() {
|
private Consumer<VcnNetworkAgent> setupNetworkAndGetUnwantedCallback() {
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import static com.android.server.vcn.VcnTestUtils.setupIpSecManager;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
import static org.mockito.Mockito.CALLS_REAL_METHODS;
|
import static org.mockito.Mockito.CALLS_REAL_METHODS;
|
||||||
@@ -301,6 +300,11 @@ public class VcnGatewayConnectionTestBase {
|
|||||||
expectCanceled);
|
expectCanceled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void verifySafeModeStateAndCallbackFired(int invocationCount, boolean isInSafeMode) {
|
||||||
|
verify(mGatewayStatusCallback, times(invocationCount)).onSafeModeStatusChanged();
|
||||||
|
assertEquals(isInSafeMode, mGatewayConnection.isInSafeMode());
|
||||||
|
}
|
||||||
|
|
||||||
protected void verifySafeModeTimeoutNotifiesCallbackAndUnregistersNetworkAgent(
|
protected void verifySafeModeTimeoutNotifiesCallbackAndUnregistersNetworkAgent(
|
||||||
@NonNull State expectedState) {
|
@NonNull State expectedState) {
|
||||||
// Set a VcnNetworkAgent, and expect it to be unregistered and cleared
|
// Set a VcnNetworkAgent, and expect it to be unregistered and cleared
|
||||||
@@ -314,9 +318,8 @@ public class VcnGatewayConnectionTestBase {
|
|||||||
delayedEvent.run();
|
delayedEvent.run();
|
||||||
mTestLooper.dispatchAll();
|
mTestLooper.dispatchAll();
|
||||||
|
|
||||||
verify(mGatewayStatusCallback).onSafeModeStatusChanged();
|
|
||||||
assertEquals(expectedState, mGatewayConnection.getCurrentState());
|
assertEquals(expectedState, mGatewayConnection.getCurrentState());
|
||||||
assertTrue(mGatewayConnection.isInSafeMode());
|
verifySafeModeStateAndCallbackFired(1, true);
|
||||||
|
|
||||||
verify(mockNetworkAgent).unregister();
|
verify(mockNetworkAgent).unregister();
|
||||||
assertNull(mGatewayConnection.getNetworkAgent());
|
assertNull(mGatewayConnection.getNetworkAgent());
|
||||||
|
|||||||
Reference in New Issue
Block a user