Test passing an underlying network array with null network in it.

Current code treats these nulls as if they weren't there.

Bug: 173331190
Test: test-only change
Change-Id: Id4632e1b004c09910b4b7613f7233d2c19e2f0ac
This commit is contained in:
Lorenzo Colitti
2020-11-25 22:59:08 +09:00
parent b7769533c1
commit 6ae6681892

View File

@@ -4943,8 +4943,6 @@ public class ConnectivityServiceTest {
final Network[] cellAndVpn = new Network[] { final Network[] cellAndVpn = new Network[] {
mCellNetworkAgent.getNetwork(), mMockVpn.getNetwork()}; mCellNetworkAgent.getNetwork(), mMockVpn.getNetwork()};
Network[] cellAndWifi = new Network[] {
mCellNetworkAgent.getNetwork(), mWiFiNetworkAgent.getNetwork()};
// A VPN with default (null) underlying networks sets the underlying network's interfaces... // A VPN with default (null) underlying networks sets the underlying network's interfaces...
expectForceUpdateIfaces(cellAndVpn, MOBILE_IFNAME, Process.myUid(), VPN_IFNAME, expectForceUpdateIfaces(cellAndVpn, MOBILE_IFNAME, Process.myUid(), VPN_IFNAME,
@@ -4954,10 +4952,13 @@ public class ConnectivityServiceTest {
mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI); mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI);
mWiFiNetworkAgent.connect(false); mWiFiNetworkAgent.connect(false);
mWiFiNetworkAgent.sendLinkProperties(wifiLp); mWiFiNetworkAgent.sendLinkProperties(wifiLp);
final Network[] onlyNull = new Network[]{null};
final Network[] wifiAndVpn = new Network[] { final Network[] wifiAndVpn = new Network[] {
mWiFiNetworkAgent.getNetwork(), mMockVpn.getNetwork()}; mWiFiNetworkAgent.getNetwork(), mMockVpn.getNetwork()};
cellAndWifi = new Network[] { final Network[] cellAndWifi = new Network[] {
mCellNetworkAgent.getNetwork(), mWiFiNetworkAgent.getNetwork()}; mCellNetworkAgent.getNetwork(), mWiFiNetworkAgent.getNetwork()};
final Network[] cellNullAndWifi = new Network[] {
mCellNetworkAgent.getNetwork(), null, mWiFiNetworkAgent.getNetwork()};
waitForIdle(); waitForIdle();
assertEquals(wifiLp, mService.getActiveLinkProperties()); assertEquals(wifiLp, mService.getActiveLinkProperties());
@@ -4983,6 +4984,13 @@ public class ConnectivityServiceTest {
new String[]{MOBILE_IFNAME, WIFI_IFNAME}); new String[]{MOBILE_IFNAME, WIFI_IFNAME});
reset(mStatsService); reset(mStatsService);
// Null underlying networks are ignored.
mService.setUnderlyingNetworksForVpn(cellNullAndWifi);
waitForIdle();
expectForceUpdateIfaces(wifiAndVpn, MOBILE_IFNAME, Process.myUid(), VPN_IFNAME,
new String[]{MOBILE_IFNAME, WIFI_IFNAME});
reset(mStatsService);
// If an underlying network disconnects, that interface should no longer be underlying. // If an underlying network disconnects, that interface should no longer be underlying.
// This doesn't actually work because disconnectAndDestroyNetwork only notifies // This doesn't actually work because disconnectAndDestroyNetwork only notifies
// NetworkStatsService before the underlying network is actually removed. So the underlying // NetworkStatsService before the underlying network is actually removed. So the underlying
@@ -5017,6 +5025,7 @@ public class ConnectivityServiceTest {
argThat(vpnInfos -> vpnInfos[0].underlyingIfaces.length == 1 argThat(vpnInfos -> vpnInfos[0].underlyingIfaces.length == 1
&& WIFI_IFNAME.equals(vpnInfos[0].underlyingIfaces[0]))); && WIFI_IFNAME.equals(vpnInfos[0].underlyingIfaces[0])));
mEthernetNetworkAgent.disconnect(); mEthernetNetworkAgent.disconnect();
waitForIdle();
reset(mStatsService); reset(mStatsService);
// When a VPN declares no underlying networks (i.e., no connectivity), getAllVpnInfo // When a VPN declares no underlying networks (i.e., no connectivity), getAllVpnInfo
@@ -5029,6 +5038,18 @@ public class ConnectivityServiceTest {
waitForIdle(); waitForIdle();
expectForceUpdateIfaces(wifiAndVpn, null); expectForceUpdateIfaces(wifiAndVpn, null);
reset(mStatsService); reset(mStatsService);
// Specifying only a null underlying network is the same as no networks.
mService.setUnderlyingNetworksForVpn(onlyNull);
waitForIdle();
expectForceUpdateIfaces(wifiAndVpn, null);
reset(mStatsService);
// Specifying networks that are all disconnected is the same as specifying no networks.
mService.setUnderlyingNetworksForVpn(onlyCell);
waitForIdle();
expectForceUpdateIfaces(wifiAndVpn, null);
reset(mStatsService);
} }
@Test @Test