From f7208e9857e41612141fcfa153b5af2dff4bd528 Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Wed, 4 Jun 2014 19:59:21 +0900 Subject: [PATCH] Call a network restricted only if all capabilities are restricted When guessing whether a network is restricted or not (e.g., when constructing a NetworkCapabilities object from an APN type, or when constructing a request using startUsingNetworkFeature), only assume the network is restricted if all the capabilities it provides are typically provided by restricted networks (e.g., IMS, FOTA, etc.). Previous code would conclude a network was restricted even if it supported one "restricted" capability, so for example an APN that provides both Internet connectivity and FOTA was marked as restricted. This caused it to become ineligible to provide the default Internet connection, because that must be unrestricted. Also expand the list of restricted APN types a bit. Bug: 15417453 Change-Id: I8c385f2cc83c695449dc8cf943d918321716fe58 --- .../java/android/net/ConnectivityManager.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java index c4cbdd54d2..b96f16646c 100644 --- a/core/java/android/net/ConnectivityManager.java +++ b/core/java/android/net/ConnectivityManager.java @@ -872,22 +872,36 @@ public class ConnectivityManager { /** * Removes the NET_CAPABILITY_NOT_RESTRICTED capability from the given - * NetworkCapabilities object if it lists any capabilities that are - * typically provided by retricted networks. + * 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 (Integer capability: nc.getNetworkCapabilities()) { + for (Integer capability : nc.getNetworkCapabilities()) { switch (capability.intValue()) { 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: - nc.removeNetworkCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED); - break; + case NetworkCapabilities.NET_CAPABILITY_RCS: + case NetworkCapabilities.NET_CAPABILITY_XCAP: + 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.removeNetworkCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED); } private NetworkCapabilities networkCapabilitiesForFeature(int networkType, String feature) {