Merge "Allow MANAGE_TEST_NETWORKS to register limited agents" am: a982d12943 am: 3870a078e3

Change-Id: Ia0f76216636ae11d1d9cbea5ed6ff0ee4e2a3f5b
This commit is contained in:
Chalard Jean
2020-03-25 10:49:54 +00:00
committed by Automerger Merge Worker
2 changed files with 50 additions and 2 deletions

View File

@@ -414,6 +414,20 @@ public final class NetworkCapabilities implements Parcelable {
| (1 << NET_CAPABILITY_FOREGROUND)
| (1 << NET_CAPABILITY_PARTIAL_CONNECTIVITY);
/**
* Capabilities that are allowed for test networks. This list must be set so that it is safe
* for an unprivileged user to create a network with these capabilities via shell. As such,
* it must never contain capabilities that are generally useful to the system, such as
* INTERNET, IMS, SUPL, etc.
*/
private static final long TEST_NETWORKS_ALLOWED_CAPABILITIES =
(1 << NET_CAPABILITY_NOT_METERED)
| (1 << NET_CAPABILITY_NOT_RESTRICTED)
| (1 << NET_CAPABILITY_NOT_VPN)
| (1 << NET_CAPABILITY_NOT_ROAMING)
| (1 << NET_CAPABILITY_NOT_CONGESTED)
| (1 << NET_CAPABILITY_NOT_SUSPENDED);
/**
* Adds the given capability to this {@code NetworkCapability} instance.
* Note that when searching for a network to satisfy a request, all capabilities
@@ -645,6 +659,21 @@ public final class NetworkCapabilities implements Parcelable {
}
}
/**
* Test networks have strong restrictions on what capabilities they can have. Enforce these
* restrictions.
* @hide
*/
public void restrictCapabilitesForTestNetwork() {
final long originalCapabilities = mNetworkCapabilities;
final NetworkSpecifier originalSpecifier = mNetworkSpecifier;
clearAll();
// Reset the transports to only contain TRANSPORT_TEST.
mTransportTypes = (1 << TRANSPORT_TEST);
mNetworkCapabilities = originalCapabilities & TEST_NETWORKS_ALLOWED_CAPABILITIES;
mNetworkSpecifier = originalSpecifier;
}
/**
* Representing the transport type. Apps should generally not care about transport. A
* request for a fast internet connection could be satisfied by a number of different