am 10a7d744: am 96cd7c14: am 635f8711: am a9e98343: Merge "Fix NOT_RESTRICTED network capability and enforce it." into lmp-dev
* commit '10a7d7449dae2aabf4f22f980e7efabf274a939a': Fix NOT_RESTRICTED network capability and enforce it.
This commit is contained in:
@@ -939,41 +939,6 @@ public class ConnectivityManager {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes the NET_CAPABILITY_NOT_RESTRICTED capability from the given
|
|
||||||
* NetworkCapabilities object if all the capabilities it provides are
|
|
||||||
* typically provided by restricted networks.
|
|
||||||
*
|
|
||||||
* TODO: consider:
|
|
||||||
* - Moving to NetworkCapabilities
|
|
||||||
* - Renaming it to guessRestrictedCapability and make it set the
|
|
||||||
* restricted capability bit in addition to clearing it.
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public static void maybeMarkCapabilitiesRestricted(NetworkCapabilities nc) {
|
|
||||||
for (int capability : nc.getCapabilities()) {
|
|
||||||
switch (capability) {
|
|
||||||
case NetworkCapabilities.NET_CAPABILITY_CBS:
|
|
||||||
case NetworkCapabilities.NET_CAPABILITY_DUN:
|
|
||||||
case NetworkCapabilities.NET_CAPABILITY_EIMS:
|
|
||||||
case NetworkCapabilities.NET_CAPABILITY_FOTA:
|
|
||||||
case NetworkCapabilities.NET_CAPABILITY_IA:
|
|
||||||
case NetworkCapabilities.NET_CAPABILITY_IMS:
|
|
||||||
case NetworkCapabilities.NET_CAPABILITY_RCS:
|
|
||||||
case NetworkCapabilities.NET_CAPABILITY_XCAP:
|
|
||||||
case NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED: //there by default
|
|
||||||
continue;
|
|
||||||
default:
|
|
||||||
// At least one capability usually provided by unrestricted
|
|
||||||
// networks. Conclude that this network is unrestricted.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// All the capabilities are typically provided by restricted networks.
|
|
||||||
// Conclude that this network is restricted.
|
|
||||||
nc.removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED);
|
|
||||||
}
|
|
||||||
|
|
||||||
private NetworkCapabilities networkCapabilitiesForFeature(int networkType, String feature) {
|
private NetworkCapabilities networkCapabilitiesForFeature(int networkType, String feature) {
|
||||||
if (networkType == TYPE_MOBILE) {
|
if (networkType == TYPE_MOBILE) {
|
||||||
int cap = -1;
|
int cap = -1;
|
||||||
@@ -996,14 +961,14 @@ public class ConnectivityManager {
|
|||||||
}
|
}
|
||||||
NetworkCapabilities netCap = new NetworkCapabilities();
|
NetworkCapabilities netCap = new NetworkCapabilities();
|
||||||
netCap.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR).addCapability(cap);
|
netCap.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR).addCapability(cap);
|
||||||
maybeMarkCapabilitiesRestricted(netCap);
|
netCap.maybeMarkCapabilitiesRestricted();
|
||||||
return netCap;
|
return netCap;
|
||||||
} else if (networkType == TYPE_WIFI) {
|
} else if (networkType == TYPE_WIFI) {
|
||||||
if ("p2p".equals(feature)) {
|
if ("p2p".equals(feature)) {
|
||||||
NetworkCapabilities netCap = new NetworkCapabilities();
|
NetworkCapabilities netCap = new NetworkCapabilities();
|
||||||
netCap.addTransportType(NetworkCapabilities.TRANSPORT_WIFI);
|
netCap.addTransportType(NetworkCapabilities.TRANSPORT_WIFI);
|
||||||
netCap.addCapability(NetworkCapabilities.NET_CAPABILITY_WIFI_P2P);
|
netCap.addCapability(NetworkCapabilities.NET_CAPABILITY_WIFI_P2P);
|
||||||
maybeMarkCapabilitiesRestricted(netCap);
|
netCap.maybeMarkCapabilitiesRestricted();
|
||||||
return netCap;
|
return netCap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public NetworkCapabilities() {
|
public NetworkCapabilities() {
|
||||||
|
mNetworkCapabilities = DEFAULT_CAPABILITIES;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NetworkCapabilities(NetworkCapabilities nc) {
|
public NetworkCapabilities(NetworkCapabilities nc) {
|
||||||
@@ -53,8 +54,7 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
* Represents the network's capabilities. If any are specified they will be satisfied
|
* Represents the network's capabilities. If any are specified they will be satisfied
|
||||||
* by any Network that matches all of them.
|
* by any Network that matches all of them.
|
||||||
*/
|
*/
|
||||||
private long mNetworkCapabilities = (1 << NET_CAPABILITY_NOT_RESTRICTED) |
|
private long mNetworkCapabilities;
|
||||||
(1 << NET_CAPABILITY_TRUSTED) | (1 << NET_CAPABILITY_NOT_VPN);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates this is a network that has the ability to reach the
|
* Indicates this is a network that has the ability to reach the
|
||||||
@@ -165,6 +165,28 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
private static final int MIN_NET_CAPABILITY = NET_CAPABILITY_MMS;
|
private static final int MIN_NET_CAPABILITY = NET_CAPABILITY_MMS;
|
||||||
private static final int MAX_NET_CAPABILITY = NET_CAPABILITY_VALIDATED;
|
private static final int MAX_NET_CAPABILITY = NET_CAPABILITY_VALIDATED;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Capabilities that are set by default when the object is constructed.
|
||||||
|
*/
|
||||||
|
private static final long DEFAULT_CAPABILITIES =
|
||||||
|
(1 << NET_CAPABILITY_NOT_RESTRICTED) |
|
||||||
|
(1 << NET_CAPABILITY_TRUSTED) |
|
||||||
|
(1 << NET_CAPABILITY_NOT_VPN);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Capabilities that suggest that a network is restricted.
|
||||||
|
* {@see #maybeMarkCapabilitiesRestricted}.
|
||||||
|
*/
|
||||||
|
private static final long RESTRICTED_CAPABILITIES =
|
||||||
|
(1 << NET_CAPABILITY_CBS) |
|
||||||
|
(1 << NET_CAPABILITY_DUN) |
|
||||||
|
(1 << NET_CAPABILITY_EIMS) |
|
||||||
|
(1 << NET_CAPABILITY_FOTA) |
|
||||||
|
(1 << NET_CAPABILITY_IA) |
|
||||||
|
(1 << NET_CAPABILITY_IMS) |
|
||||||
|
(1 << NET_CAPABILITY_RCS) |
|
||||||
|
(1 << NET_CAPABILITY_XCAP);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the given capability to this {@code NetworkCapability} instance.
|
* Adds the given capability to this {@code NetworkCapability} instance.
|
||||||
* Multiple capabilities may be applied sequentially. Note that when searching
|
* Multiple capabilities may be applied sequentially. Note that when searching
|
||||||
@@ -247,6 +269,22 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
return (nc.mNetworkCapabilities == this.mNetworkCapabilities);
|
return (nc.mNetworkCapabilities == this.mNetworkCapabilities);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the NET_CAPABILITY_NOT_RESTRICTED capability if all the capabilities it provides are
|
||||||
|
* typically provided by restricted networks.
|
||||||
|
*
|
||||||
|
* TODO: consider:
|
||||||
|
* - Renaming it to guessRestrictedCapability and make it set the
|
||||||
|
* restricted capability bit in addition to clearing it.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public void maybeMarkCapabilitiesRestricted() {
|
||||||
|
// If all the capabilities are typically provided by restricted networks, conclude that this
|
||||||
|
// network is restricted.
|
||||||
|
if ((mNetworkCapabilities & ~(DEFAULT_CAPABILITIES | RESTRICTED_CAPABILITIES)) == 0)
|
||||||
|
removeCapability(NET_CAPABILITY_NOT_RESTRICTED);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Representing the transport type. Apps should generally not care about transport. A
|
* 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
|
* request for a fast internet connection could be satisfied by a number of different
|
||||||
|
|||||||
@@ -85,7 +85,13 @@ public class NetworkRequest implements Parcelable {
|
|||||||
* Build {@link NetworkRequest} give the current set of capabilities.
|
* Build {@link NetworkRequest} give the current set of capabilities.
|
||||||
*/
|
*/
|
||||||
public NetworkRequest build() {
|
public NetworkRequest build() {
|
||||||
return new NetworkRequest(mNetworkCapabilities, ConnectivityManager.TYPE_NONE,
|
// Make a copy of mNetworkCapabilities so we don't inadvertently remove NOT_RESTRICTED
|
||||||
|
// when later an unrestricted capability could be added to mNetworkCapabilities, in
|
||||||
|
// which case NOT_RESTRICTED should be returned to mNetworkCapabilities, which
|
||||||
|
// maybeMarkCapabilitiesRestricted() doesn't add back.
|
||||||
|
final NetworkCapabilities nc = new NetworkCapabilities(mNetworkCapabilities);
|
||||||
|
nc.maybeMarkCapabilitiesRestricted();
|
||||||
|
return new NetworkRequest(nc, ConnectivityManager.TYPE_NONE,
|
||||||
ConnectivityManager.REQUEST_ID_UNSET);
|
ConnectivityManager.REQUEST_ID_UNSET);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -374,8 +374,10 @@ interface INetworkManagementService
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup a new physical network.
|
* Setup a new physical network.
|
||||||
|
* @param permission null if no permissions required to access this network. PERMISSION_NETWORK
|
||||||
|
* or PERMISSION_SYSTEM to set respective permission.
|
||||||
*/
|
*/
|
||||||
void createPhysicalNetwork(int netId);
|
void createPhysicalNetwork(int netId, String permission);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup a new VPN.
|
* Setup a new VPN.
|
||||||
@@ -402,6 +404,13 @@ interface INetworkManagementService
|
|||||||
void setDefaultNetId(int netId);
|
void setDefaultNetId(int netId);
|
||||||
void clearDefaultNetId();
|
void clearDefaultNetId();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set permission for a network.
|
||||||
|
* @param permission null to clear permissions. PERMISSION_NETWORK or PERMISSION_SYSTEM to set
|
||||||
|
* permission.
|
||||||
|
*/
|
||||||
|
void setNetworkPermission(int netId, String permission);
|
||||||
|
|
||||||
void setPermission(String permission, in int[] uids);
|
void setPermission(String permission, in int[] uids);
|
||||||
void clearPermission(in int[] uids);
|
void clearPermission(in int[] uids);
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import static android.net.ConnectivityManager.TYPE_NONE;
|
|||||||
import static android.net.ConnectivityManager.TYPE_VPN;
|
import static android.net.ConnectivityManager.TYPE_VPN;
|
||||||
import static android.net.ConnectivityManager.getNetworkTypeName;
|
import static android.net.ConnectivityManager.getNetworkTypeName;
|
||||||
import static android.net.ConnectivityManager.isNetworkTypeValid;
|
import static android.net.ConnectivityManager.isNetworkTypeValid;
|
||||||
|
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED;
|
||||||
import static android.net.NetworkPolicyManager.RULE_ALLOW_ALL;
|
import static android.net.NetworkPolicyManager.RULE_ALLOW_ALL;
|
||||||
import static android.net.NetworkPolicyManager.RULE_REJECT_METERED;
|
import static android.net.NetworkPolicyManager.RULE_REJECT_METERED;
|
||||||
|
|
||||||
@@ -3608,6 +3609,16 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
private void updateCapabilities(NetworkAgentInfo networkAgent,
|
private void updateCapabilities(NetworkAgentInfo networkAgent,
|
||||||
NetworkCapabilities networkCapabilities) {
|
NetworkCapabilities networkCapabilities) {
|
||||||
if (!Objects.equals(networkAgent.networkCapabilities, networkCapabilities)) {
|
if (!Objects.equals(networkAgent.networkCapabilities, networkCapabilities)) {
|
||||||
|
if (networkAgent.networkCapabilities.hasCapability(NET_CAPABILITY_NOT_RESTRICTED) !=
|
||||||
|
networkCapabilities.hasCapability(NET_CAPABILITY_NOT_RESTRICTED)) {
|
||||||
|
try {
|
||||||
|
mNetd.setNetworkPermission(networkAgent.network.netId,
|
||||||
|
networkCapabilities.hasCapability(NET_CAPABILITY_NOT_RESTRICTED) ?
|
||||||
|
null : NetworkManagementService.PERMISSION_SYSTEM);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
loge("Exception in setNetworkPermission: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
synchronized (networkAgent) {
|
synchronized (networkAgent) {
|
||||||
networkAgent.networkCapabilities = networkCapabilities;
|
networkAgent.networkCapabilities = networkCapabilities;
|
||||||
}
|
}
|
||||||
@@ -4037,7 +4048,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
(networkAgent.networkMisc == null ||
|
(networkAgent.networkMisc == null ||
|
||||||
!networkAgent.networkMisc.allowBypass));
|
!networkAgent.networkMisc.allowBypass));
|
||||||
} else {
|
} else {
|
||||||
mNetd.createPhysicalNetwork(networkAgent.network.netId);
|
mNetd.createPhysicalNetwork(networkAgent.network.netId,
|
||||||
|
networkAgent.networkCapabilities.hasCapability(
|
||||||
|
NET_CAPABILITY_NOT_RESTRICTED) ?
|
||||||
|
null : NetworkManagementService.PERMISSION_SYSTEM);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
loge("Error creating network " + networkAgent.network.netId + ": "
|
loge("Error creating network " + networkAgent.network.netId + ": "
|
||||||
|
|||||||
@@ -120,6 +120,19 @@ public class NetworkManagementService extends INetworkManagementService.Stub
|
|||||||
*/
|
*/
|
||||||
public static final String LIMIT_GLOBAL_ALERT = "globalAlert";
|
public static final String LIMIT_GLOBAL_ALERT = "globalAlert";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* String to pass to netd to indicate that a network is only accessible
|
||||||
|
* to apps that have the CHANGE_NETWORK_STATE permission.
|
||||||
|
*/
|
||||||
|
public static final String PERMISSION_NETWORK = "NETWORK";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* String to pass to netd to indicate that a network is only
|
||||||
|
* accessible to system apps and those with the CONNECTIVITY_INTERNAL
|
||||||
|
* permission.
|
||||||
|
*/
|
||||||
|
public static final String PERMISSION_SYSTEM = "SYSTEM";
|
||||||
|
|
||||||
class NetdResponseCode {
|
class NetdResponseCode {
|
||||||
/* Keep in sync with system/netd/server/ResponseCode.h */
|
/* Keep in sync with system/netd/server/ResponseCode.h */
|
||||||
public static final int InterfaceListResult = 110;
|
public static final int InterfaceListResult = 110;
|
||||||
@@ -2054,11 +2067,15 @@ public class NetworkManagementService extends INetworkManagementService.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createPhysicalNetwork(int netId) {
|
public void createPhysicalNetwork(int netId, String permission) {
|
||||||
mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
|
mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mConnector.execute("network", "create", netId);
|
if (permission != null) {
|
||||||
|
mConnector.execute("network", "create", netId, permission);
|
||||||
|
} else {
|
||||||
|
mConnector.execute("network", "create", netId);
|
||||||
|
}
|
||||||
} catch (NativeDaemonConnectorException e) {
|
} catch (NativeDaemonConnectorException e) {
|
||||||
throw e.rethrowAsParcelableException();
|
throw e.rethrowAsParcelableException();
|
||||||
}
|
}
|
||||||
@@ -2149,6 +2166,22 @@ public class NetworkManagementService extends INetworkManagementService.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setNetworkPermission(int netId, String permission) {
|
||||||
|
mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (permission != null) {
|
||||||
|
mConnector.execute("network", "permission", "network", "set", permission, netId);
|
||||||
|
} else {
|
||||||
|
mConnector.execute("network", "permission", "network", "clear", netId);
|
||||||
|
}
|
||||||
|
} catch (NativeDaemonConnectorException e) {
|
||||||
|
throw e.rethrowAsParcelableException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPermission(String permission, int[] uids) {
|
public void setPermission(String permission, int[] uids) {
|
||||||
mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
|
mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
|
||||||
|
|||||||
Reference in New Issue
Block a user