Allow non-VPNs to have underlying networks.
Certain network types, like the VCN, have underlying networks for the purpose of data usage, but do not want to propagate the underlying network capabilities. Allow these networks to set underlying networks, but continue not to propagate the capabilities. Bug: 190620024 Test: new unit test Change-Id: I53d6080f48707ff3c37fbfbef534284ba77a7432
This commit is contained in:
parent
5440e0b8e8
commit
bd079455f1
1 changed files with 97 additions and 18 deletions
|
|
@ -3249,11 +3249,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||
}
|
||||
case NetworkAgent.EVENT_UNDERLYING_NETWORKS_CHANGED: {
|
||||
// TODO: prevent loops, e.g., if a network declares itself as underlying.
|
||||
if (!nai.supportsUnderlyingNetworks()) {
|
||||
Log.wtf(TAG, "Non-virtual networks cannot have underlying networks");
|
||||
break;
|
||||
}
|
||||
|
||||
final List<Network> underlying = (List<Network>) arg.second;
|
||||
|
||||
if (isLegacyLockdownNai(nai)
|
||||
|
|
@ -5246,12 +5241,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||
* information, e.g underlying ifaces.
|
||||
*/
|
||||
private UnderlyingNetworkInfo createVpnInfo(NetworkAgentInfo nai) {
|
||||
if (!nai.isVPN()) return null;
|
||||
|
||||
Network[] underlyingNetworks = nai.declaredUnderlyingNetworks;
|
||||
// see VpnService.setUnderlyingNetworks()'s javadoc about how to interpret
|
||||
// the underlyingNetworks list.
|
||||
if (underlyingNetworks == null) {
|
||||
// TODO: stop using propagateUnderlyingCapabilities here, for example, by always
|
||||
// initializing NetworkAgentInfo#declaredUnderlyingNetworks to an empty array.
|
||||
if (underlyingNetworks == null && nai.propagateUnderlyingCapabilities()) {
|
||||
final NetworkAgentInfo defaultNai = getDefaultNetworkForUid(
|
||||
nai.networkCapabilities.getOwnerUid());
|
||||
if (defaultNai != null) {
|
||||
|
|
@ -5300,7 +5295,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||
private boolean hasUnderlyingNetwork(NetworkAgentInfo nai, Network network) {
|
||||
// TODO: support more than one level of underlying networks, either via a fixed-depth search
|
||||
// (e.g., 2 levels of underlying networks), or via loop detection, or....
|
||||
if (!nai.supportsUnderlyingNetworks()) return false;
|
||||
if (!nai.propagateUnderlyingCapabilities()) return false;
|
||||
final Network[] underlying = underlyingNetworksOrDefault(
|
||||
nai.networkCapabilities.getOwnerUid(), nai.declaredUnderlyingNetworks);
|
||||
return CollectionUtils.contains(underlying, network);
|
||||
|
|
@ -7272,7 +7267,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||
newNc.addCapability(NET_CAPABILITY_NOT_ROAMING);
|
||||
}
|
||||
|
||||
if (nai.supportsUnderlyingNetworks()) {
|
||||
if (nai.propagateUnderlyingCapabilities()) {
|
||||
applyUnderlyingCapabilities(nai.declaredUnderlyingNetworks, nai.declaredCapabilities,
|
||||
newNc);
|
||||
}
|
||||
|
|
@ -8407,7 +8402,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||
networkAgent.networkCapabilities.addCapability(NET_CAPABILITY_FOREGROUND);
|
||||
|
||||
if (!createNativeNetwork(networkAgent)) return;
|
||||
if (networkAgent.supportsUnderlyingNetworks()) {
|
||||
if (networkAgent.propagateUnderlyingCapabilities()) {
|
||||
// Initialize the network's capabilities to their starting values according to the
|
||||
// underlying networks. This ensures that the capabilities are correct before
|
||||
// anything happens to the network.
|
||||
|
|
@ -9316,7 +9311,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||
|
||||
private boolean ownsVpnRunningOverNetwork(int uid, Network network) {
|
||||
for (NetworkAgentInfo virtual : mNetworkAgentInfos) {
|
||||
if (virtual.supportsUnderlyingNetworks()
|
||||
if (virtual.propagateUnderlyingCapabilities()
|
||||
&& virtual.networkCapabilities.getOwnerUid() == uid
|
||||
&& CollectionUtils.contains(virtual.declaredUnderlyingNetworks, network)) {
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Reference in a new issue