Minor fixes to VpnTransportInfo.
This CL addesses comments on aosp/1570921. Bug: 173331190 Test: new test coverage Change-Id: Ie8e1bd63bb818a03f4b17402e1b365577ca034a2
This commit is contained in:
@@ -17,7 +17,6 @@
|
|||||||
package android.net;
|
package android.net;
|
||||||
|
|
||||||
import static com.android.testutils.ParcelUtils.assertParcelSane;
|
import static com.android.testutils.ParcelUtils.assertParcelSane;
|
||||||
import static com.android.testutils.ParcelUtils.assertParcelingIsLossless;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.Assert.assertNotEquals;
|
||||||
@@ -36,7 +35,6 @@ public class VpnTransportInfoTest {
|
|||||||
public void testParceling() {
|
public void testParceling() {
|
||||||
VpnTransportInfo v = new VpnTransportInfo(VpnManager.TYPE_VPN_PLATFORM);
|
VpnTransportInfo v = new VpnTransportInfo(VpnManager.TYPE_VPN_PLATFORM);
|
||||||
assertParcelSane(v, 1 /* fieldCount */);
|
assertParcelSane(v, 1 /* fieldCount */);
|
||||||
assertParcelingIsLossless(v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -200,6 +200,7 @@ import android.net.ResolverParamsParcel;
|
|||||||
import android.net.RouteInfo;
|
import android.net.RouteInfo;
|
||||||
import android.net.RouteInfoParcel;
|
import android.net.RouteInfoParcel;
|
||||||
import android.net.SocketKeepalive;
|
import android.net.SocketKeepalive;
|
||||||
|
import android.net.TransportInfo;
|
||||||
import android.net.UidRange;
|
import android.net.UidRange;
|
||||||
import android.net.UidRangeParcel;
|
import android.net.UidRangeParcel;
|
||||||
import android.net.UnderlyingNetworkInfo;
|
import android.net.UnderlyingNetworkInfo;
|
||||||
@@ -1266,6 +1267,15 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void assertVpnTransportInfo(NetworkCapabilities nc, int type) {
|
||||||
|
assertNotNull(nc);
|
||||||
|
final TransportInfo ti = nc.getTransportInfo();
|
||||||
|
assertTrue("VPN TransportInfo is not a VpnTransportInfo: " + ti,
|
||||||
|
ti instanceof VpnTransportInfo);
|
||||||
|
assertEquals(type, ((VpnTransportInfo) ti).type);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void processBroadcastForVpn(Intent intent) {
|
private void processBroadcastForVpn(Intent intent) {
|
||||||
// The BroadcastReceiver for this broadcast checks it is being run on the handler thread.
|
// The BroadcastReceiver for this broadcast checks it is being run on the handler thread.
|
||||||
final Handler handler = new Handler(mCsHandlerThread.getLooper());
|
final Handler handler = new Handler(mCsHandlerThread.getLooper());
|
||||||
@@ -6410,6 +6420,8 @@ public class ConnectivityServiceTest {
|
|||||||
assertTrue(nc.hasCapability(NET_CAPABILITY_VALIDATED));
|
assertTrue(nc.hasCapability(NET_CAPABILITY_VALIDATED));
|
||||||
assertFalse(nc.hasCapability(NET_CAPABILITY_NOT_METERED));
|
assertFalse(nc.hasCapability(NET_CAPABILITY_NOT_METERED));
|
||||||
assertTrue(nc.hasCapability(NET_CAPABILITY_NOT_SUSPENDED));
|
assertTrue(nc.hasCapability(NET_CAPABILITY_NOT_SUSPENDED));
|
||||||
|
|
||||||
|
assertVpnTransportInfo(nc, VpnManager.TYPE_VPN_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertDefaultNetworkCapabilities(int userId, NetworkAgentWrapper... networks) {
|
private void assertDefaultNetworkCapabilities(int userId, NetworkAgentWrapper... networks) {
|
||||||
@@ -6449,6 +6461,7 @@ public class ConnectivityServiceTest {
|
|||||||
assertFalse(nc.hasCapability(NET_CAPABILITY_NOT_METERED));
|
assertFalse(nc.hasCapability(NET_CAPABILITY_NOT_METERED));
|
||||||
// A VPN without underlying networks is not suspended.
|
// A VPN without underlying networks is not suspended.
|
||||||
assertTrue(nc.hasCapability(NET_CAPABILITY_NOT_SUSPENDED));
|
assertTrue(nc.hasCapability(NET_CAPABILITY_NOT_SUSPENDED));
|
||||||
|
assertVpnTransportInfo(nc, VpnManager.TYPE_VPN_SERVICE);
|
||||||
|
|
||||||
final int userId = UserHandle.getUserId(Process.myUid());
|
final int userId = UserHandle.getUserId(Process.myUid());
|
||||||
assertDefaultNetworkCapabilities(userId /* no networks */);
|
assertDefaultNetworkCapabilities(userId /* no networks */);
|
||||||
@@ -6612,6 +6625,7 @@ public class ConnectivityServiceTest {
|
|||||||
// By default, VPN is set to track default network (i.e. its underlying networks is null).
|
// By default, VPN is set to track default network (i.e. its underlying networks is null).
|
||||||
// In case of no default network, VPN is considered metered.
|
// In case of no default network, VPN is considered metered.
|
||||||
assertFalse(nc.hasCapability(NET_CAPABILITY_NOT_METERED));
|
assertFalse(nc.hasCapability(NET_CAPABILITY_NOT_METERED));
|
||||||
|
assertVpnTransportInfo(nc, VpnManager.TYPE_VPN_SERVICE);
|
||||||
|
|
||||||
// Connect to Cell; Cell is the default network.
|
// Connect to Cell; Cell is the default network.
|
||||||
mCellNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_CELLULAR);
|
mCellNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_CELLULAR);
|
||||||
@@ -6669,6 +6683,7 @@ public class ConnectivityServiceTest {
|
|||||||
NetworkCapabilities nc = mCm.getNetworkCapabilities(mMockVpn.getNetwork());
|
NetworkCapabilities nc = mCm.getNetworkCapabilities(mMockVpn.getNetwork());
|
||||||
assertNotNull("nc=" + nc, nc.getUids());
|
assertNotNull("nc=" + nc, nc.getUids());
|
||||||
assertEquals(nc.getUids(), uidRangesForUid(uid));
|
assertEquals(nc.getUids(), uidRangesForUid(uid));
|
||||||
|
assertVpnTransportInfo(nc, VpnManager.TYPE_VPN_SERVICE);
|
||||||
|
|
||||||
// Set an underlying network and expect to see the VPN transports change.
|
// Set an underlying network and expect to see the VPN transports change.
|
||||||
mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI);
|
mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI);
|
||||||
|
|||||||
Reference in New Issue
Block a user