Add a VpnTransportInfo object.
This currently stores the VPN type and a session name, but can be extended in the future. Bug: 173331190 Test: added coverage in VpnTest Test: added coverage in ConnectivityServiceTest Test: added coverage in NetworkAgentTest Change-Id: I450858a9fa332c8d896dbdb4c14337d5ec23677f
This commit is contained in:
@@ -205,6 +205,7 @@ import android.net.UidRangeParcel;
|
||||
import android.net.UnderlyingNetworkInfo;
|
||||
import android.net.Uri;
|
||||
import android.net.VpnManager;
|
||||
import android.net.VpnTransportInfo;
|
||||
import android.net.metrics.IpConnectivityLog;
|
||||
import android.net.shared.NetworkMonitorUtils;
|
||||
import android.net.shared.PrivateDnsConfig;
|
||||
@@ -1110,7 +1111,7 @@ public class ConnectivityServiceTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getActiveAppVpnType() {
|
||||
public int getActiveVpnType() {
|
||||
return mVpnType;
|
||||
}
|
||||
|
||||
@@ -1123,10 +1124,12 @@ public class ConnectivityServiceTest {
|
||||
private void registerAgent(boolean isAlwaysMetered, Set<UidRange> uids, LinkProperties lp)
|
||||
throws Exception {
|
||||
if (mAgentRegistered) throw new IllegalStateException("already registered");
|
||||
updateState(NetworkInfo.DetailedState.CONNECTING, "registerAgent");
|
||||
mConfig = new VpnConfig();
|
||||
setUids(uids);
|
||||
if (!isAlwaysMetered) mNetworkCapabilities.addCapability(NET_CAPABILITY_NOT_METERED);
|
||||
mInterface = VPN_IFNAME;
|
||||
mNetworkCapabilities.setTransportInfo(new VpnTransportInfo(getActiveVpnType()));
|
||||
mMockNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_VPN, lp,
|
||||
mNetworkCapabilities);
|
||||
mMockNetworkAgent.waitForIdle(TIMEOUT_MS);
|
||||
@@ -7322,6 +7325,7 @@ public class ConnectivityServiceTest {
|
||||
}
|
||||
|
||||
private void establishLegacyLockdownVpn() throws Exception {
|
||||
mMockVpn.setVpnType(VpnManager.TYPE_VPN_LEGACY);
|
||||
// The legacy lockdown VPN only supports userId 0.
|
||||
final Set<UidRange> ranges = Collections.singleton(UidRange.createForUser(PRIMARY_USER));
|
||||
mMockVpn.registerAgent(ranges);
|
||||
@@ -7434,6 +7438,9 @@ public class ConnectivityServiceTest {
|
||||
assertTrue(vpnNc.hasTransport(TRANSPORT_CELLULAR));
|
||||
assertFalse(vpnNc.hasTransport(TRANSPORT_WIFI));
|
||||
assertFalse(vpnNc.hasCapability(NET_CAPABILITY_NOT_METERED));
|
||||
VpnTransportInfo ti = (VpnTransportInfo) vpnNc.getTransportInfo();
|
||||
assertNotNull(ti);
|
||||
assertEquals(VpnManager.TYPE_VPN_LEGACY, ti.type);
|
||||
|
||||
// Switch default network from cell to wifi. Expect VPN to disconnect and reconnect.
|
||||
final LinkProperties wifiLp = new LinkProperties();
|
||||
|
||||
@@ -25,6 +25,7 @@ import static android.net.ConnectivityManager.NetworkCallback;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -74,6 +75,7 @@ import android.net.UidRange;
|
||||
import android.net.UidRangeParcel;
|
||||
import android.net.VpnManager;
|
||||
import android.net.VpnService;
|
||||
import android.net.VpnTransportInfo;
|
||||
import android.net.ipsec.ike.IkeSessionCallback;
|
||||
import android.net.ipsec.ike.exceptions.IkeProtocolException;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
@@ -984,6 +986,13 @@ public class VpnTest {
|
||||
startRacoon("hostname", "5.6.7.8"); // address returned by deps.resolve
|
||||
}
|
||||
|
||||
private void assertTransportInfoMatches(NetworkCapabilities nc, int type) {
|
||||
assertNotNull(nc);
|
||||
VpnTransportInfo ti = (VpnTransportInfo) nc.getTransportInfo();
|
||||
assertNotNull(ti);
|
||||
assertEquals(type, ti.type);
|
||||
}
|
||||
|
||||
public void startRacoon(final String serverAddr, final String expectedAddr)
|
||||
throws Exception {
|
||||
final ConditionVariable legacyRunnerReady = new ConditionVariable();
|
||||
@@ -1020,8 +1029,10 @@ public class VpnTest {
|
||||
|
||||
// Now wait for the runner to be ready before testing for the route.
|
||||
ArgumentCaptor<LinkProperties> lpCaptor = ArgumentCaptor.forClass(LinkProperties.class);
|
||||
ArgumentCaptor<NetworkCapabilities> ncCaptor =
|
||||
ArgumentCaptor.forClass(NetworkCapabilities.class);
|
||||
verify(mConnectivityManager, timeout(10_000)).registerNetworkAgent(any(), any(),
|
||||
lpCaptor.capture(), any(), anyInt(), any(), anyInt());
|
||||
lpCaptor.capture(), ncCaptor.capture(), anyInt(), any(), anyInt());
|
||||
|
||||
// In this test the expected address is always v4 so /32.
|
||||
// Note that the interface needs to be specified because RouteInfo objects stored in
|
||||
@@ -1031,6 +1042,8 @@ public class VpnTest {
|
||||
final List<RouteInfo> actualRoutes = lpCaptor.getValue().getRoutes();
|
||||
assertTrue("Expected throw route (" + expectedRoute + ") not found in " + actualRoutes,
|
||||
actualRoutes.contains(expectedRoute));
|
||||
|
||||
assertTransportInfoMatches(ncCaptor.getValue(), VpnManager.TYPE_VPN_LEGACY);
|
||||
} finally {
|
||||
// Now interrupt the thread, unblock the runner and clean up.
|
||||
vpn.mVpnRunner.exitVpnRunner();
|
||||
|
||||
Reference in New Issue
Block a user