From a12044215b1148826ea9a88d5d1102378b13922f Mon Sep 17 00:00:00 2001 From: Paul Jensen Date: Fri, 28 Aug 2015 11:58:50 -0400 Subject: Fix NOT_RESTRICTED network capability and enforce it. With this change: 1. NOT_RESTRICTED should be removed from NetworkRequests that bring up special restricted carrier networks (e.g. IMS, FOTA). 2. NetworkRequests without NOT_RESTRICTED require CONNECTIVITY_INTERNAL permission to register 3. Binding sockets to networks without NOT_RESTRICTED requires CONNECTIVITY_INTERNAL permission Bug:21637535 Change-Id: I5991d39facaa6b690e969fe15dcbeec52e918321 (cherry picked from commit 487ffe7d3d84bf65212158f7098e8a84b5b55e09) --- core/java/android/net/ConnectivityManager.java | 39 ++------------------------ 1 file changed, 2 insertions(+), 37 deletions(-) (limited to 'core/java/android/net/ConnectivityManager.java') diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java index 9194ca8..7cde005 100644 --- a/core/java/android/net/ConnectivityManager.java +++ b/core/java/android/net/ConnectivityManager.java @@ -941,41 +941,6 @@ public class ConnectivityManager { 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) { if (networkType == TYPE_MOBILE) { int cap = -1; @@ -998,14 +963,14 @@ public class ConnectivityManager { } NetworkCapabilities netCap = new NetworkCapabilities(); netCap.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR).addCapability(cap); - maybeMarkCapabilitiesRestricted(netCap); + netCap.maybeMarkCapabilitiesRestricted(); return netCap; } else if (networkType == TYPE_WIFI) { if ("p2p".equals(feature)) { NetworkCapabilities netCap = new NetworkCapabilities(); netCap.addTransportType(NetworkCapabilities.TRANSPORT_WIFI); netCap.addCapability(NetworkCapabilities.NET_CAPABILITY_WIFI_P2P); - maybeMarkCapabilitiesRestricted(netCap); + netCap.maybeMarkCapabilitiesRestricted(); return netCap; } } -- cgit v1.1