Add underlying networks into NetworkAgentInfo if any

Now, VPN will set underlying networks into NetworkCapabilities
directly. So the declaredUnderlyingNetworks can also be set
directly when creating a NetworkAgentInfo.

Bug: 191918368
Test: atest FrameworksNetTests:ConnectivityServiceTest
Change-Id: I507072d00ae1eb0c391e5261ab93e359b9c4cb5c
This commit is contained in:
lucaslin
2021-10-19 15:04:56 +08:00
parent 39379a40bd
commit 6adf5ac19b
4 changed files with 155 additions and 43 deletions

View File

@@ -2032,6 +2032,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
if (!checkSettingsPermission(callerPid, callerUid)) {
newNc.setUids(null);
newNc.setSSID(null);
newNc.setUnderlyingNetworks(null);
}
if (newNc.getNetworkSpecifier() != null) {
newNc.setNetworkSpecifier(newNc.getNetworkSpecifier().redact());
@@ -7305,7 +7306,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
boolean suspended = true; // suspended if all underlying are suspended
boolean hadUnderlyingNetworks = false;
ArrayList<Network> newUnderlyingNetworks = null;
if (null != underlyingNetworks) {
newUnderlyingNetworks = new ArrayList<>();
for (Network underlyingNetwork : underlyingNetworks) {
final NetworkAgentInfo underlying =
getNetworkAgentInfoForNetwork(underlyingNetwork);
@@ -7335,6 +7338,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
// If this network is not suspended, the VPN is not suspended (the VPN
// is able to transfer some data).
suspended &= !underlyingCaps.hasCapability(NET_CAPABILITY_NOT_SUSPENDED);
newUnderlyingNetworks.add(underlyingNetwork);
}
}
if (!hadUnderlyingNetworks) {
@@ -7352,6 +7356,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
newNc.setCapability(NET_CAPABILITY_NOT_ROAMING, !roaming);
newNc.setCapability(NET_CAPABILITY_NOT_CONGESTED, !congested);
newNc.setCapability(NET_CAPABILITY_NOT_SUSPENDED, !suspended);
newNc.setUnderlyingNetworks(newUnderlyingNetworks);
}
/**