Use NetdUtils instead of NetworkManagementService in Vpn
NetdUtils has the same method(e.g. setInterfaceUp) as NetworkManagementService so using the one inside NetdUtils instead and try to remove NetworkManagementService from Vpn in the following commit. Bug: 170598012 Test: atest FrameworksNetTests Change-Id: I867556478fbc8c8ca8baa4e4c438a47b3beebe39
This commit is contained in:
@@ -21,6 +21,8 @@ import static android.content.pm.UserInfo.FLAG_MANAGED_PROFILE;
|
||||
import static android.content.pm.UserInfo.FLAG_PRIMARY;
|
||||
import static android.content.pm.UserInfo.FLAG_RESTRICTED;
|
||||
import static android.net.ConnectivityManager.NetworkCallback;
|
||||
import static android.net.INetd.IF_STATE_DOWN;
|
||||
import static android.net.INetd.IF_STATE_UP;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -61,6 +63,7 @@ import android.net.ConnectivityManager;
|
||||
import android.net.INetd;
|
||||
import android.net.Ikev2VpnProfile;
|
||||
import android.net.InetAddresses;
|
||||
import android.net.InterfaceConfigurationParcel;
|
||||
import android.net.IpPrefix;
|
||||
import android.net.IpSecManager;
|
||||
import android.net.IpSecTunnelInterfaceResponse;
|
||||
@@ -870,17 +873,28 @@ public class VpnTest {
|
||||
eq(AppOpsManager.MODE_IGNORED));
|
||||
}
|
||||
|
||||
private NetworkCallback triggerOnAvailableAndGetCallback() {
|
||||
private NetworkCallback triggerOnAvailableAndGetCallback() throws Exception {
|
||||
final ArgumentCaptor<NetworkCallback> networkCallbackCaptor =
|
||||
ArgumentCaptor.forClass(NetworkCallback.class);
|
||||
verify(mConnectivityManager, timeout(TEST_TIMEOUT_MS))
|
||||
.requestNetwork(any(), networkCallbackCaptor.capture());
|
||||
|
||||
// onAvailable() will trigger onDefaultNetworkChanged(), so NetdUtils#setInterfaceUp will be
|
||||
// invoked. Set the return value of INetd#interfaceGetCfg to prevent NullPointerException.
|
||||
final InterfaceConfigurationParcel config = new InterfaceConfigurationParcel();
|
||||
config.flags = new String[] {IF_STATE_DOWN};
|
||||
when(mNetd.interfaceGetCfg(anyString())).thenReturn(config);
|
||||
final NetworkCallback cb = networkCallbackCaptor.getValue();
|
||||
cb.onAvailable(TEST_NETWORK);
|
||||
return cb;
|
||||
}
|
||||
|
||||
private void verifyInterfaceSetCfgWithFlags(String flag) throws Exception {
|
||||
// Add a timeout for waiting for interfaceSetCfg to be called.
|
||||
verify(mNetd, timeout(TEST_TIMEOUT_MS)).interfaceSetCfg(argThat(
|
||||
config -> Arrays.asList(config.flags).contains(flag)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartPlatformVpnAuthenticationFailed() throws Exception {
|
||||
final ArgumentCaptor<IkeSessionCallback> captor =
|
||||
@@ -892,6 +906,8 @@ public class VpnTest {
|
||||
final Vpn vpn = startLegacyVpn(createVpn(primaryUser.id), (mVpnProfile));
|
||||
final NetworkCallback cb = triggerOnAvailableAndGetCallback();
|
||||
|
||||
verifyInterfaceSetCfgWithFlags(IF_STATE_UP);
|
||||
|
||||
// Wait for createIkeSession() to be called before proceeding in order to ensure consistent
|
||||
// state
|
||||
verify(mIkev2SessionCreator, timeout(TEST_TIMEOUT_MS))
|
||||
@@ -910,6 +926,8 @@ public class VpnTest {
|
||||
final Vpn vpn = startLegacyVpn(createVpn(primaryUser.id), mVpnProfile);
|
||||
final NetworkCallback cb = triggerOnAvailableAndGetCallback();
|
||||
|
||||
verifyInterfaceSetCfgWithFlags(IF_STATE_UP);
|
||||
|
||||
// Wait for createIkeSession() to be called before proceeding in order to ensure consistent
|
||||
// state
|
||||
verify(mConnectivityManager, timeout(TEST_TIMEOUT_MS)).unregisterNetworkCallback(eq(cb));
|
||||
|
||||
Reference in New Issue
Block a user