From 6baebebbe1032fc3b957916002f51e4b2e53f73d Mon Sep 17 00:00:00 2001 From: lucaslin Date: Thu, 14 Jul 2022 08:50:45 +0800 Subject: [PATCH] Test if VpnManager event will be sent to Settings VPN or not Bug: 236315805 Test: atest FrameworksNetTests:VpnTest Change-Id: I0ee4a70ded4937a1573d34cddab552f762e4fc18 --- .../android/server/connectivity/VpnTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/unit/java/com/android/server/connectivity/VpnTest.java b/tests/unit/java/com/android/server/connectivity/VpnTest.java index 5c1992d9d0..02c54dbb22 100644 --- a/tests/unit/java/com/android/server/connectivity/VpnTest.java +++ b/tests/unit/java/com/android/server/connectivity/VpnTest.java @@ -1589,6 +1589,30 @@ public class VpnTest extends VpnTestBase { assertEquals(LegacyVpnInfo.STATE_FAILED, vpn.getLegacyVpnInfo().state); } + @Test + public void testVpnManagerEventWillNotBeSentToSettingsVpn() throws Exception { + startLegacyVpn(createVpn(PRIMARY_USER.id), mVpnProfile); + triggerOnAvailableAndGetCallback(); + + verifyInterfaceSetCfgWithFlags(IF_STATE_UP); + + final IkeNonProtocolException exception = mock(IkeNonProtocolException.class); + final IkeTimeoutException ikeTimeoutException = + new IkeTimeoutException("IkeTimeoutException"); + when(exception.getCause()).thenReturn(ikeTimeoutException); + + final ArgumentCaptor captor = + ArgumentCaptor.forClass(IkeSessionCallback.class); + verify(mIkev2SessionCreator, timeout(TEST_TIMEOUT_MS)) + .createIkeSession(any(), any(), any(), any(), captor.capture(), any()); + final IkeSessionCallback ikeCb = captor.getValue(); + ikeCb.onClosedWithException(exception); + + final Context userContext = + mContext.createContextAsUser(UserHandle.of(PRIMARY_USER.id), 0 /* flags */); + verify(userContext, never()).startService(any()); + } + private void setAndVerifyAlwaysOnPackage(Vpn vpn, int uid, boolean lockdownEnabled) { assertTrue(vpn.setAlwaysOnPackage(TEST_VPN_PKG, lockdownEnabled, null));