Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.net; |
| 18 | |
| 19 | import android.os.Parcel; |
| 20 | import android.os.Parcelable; |
Robert Greenwalt | 5f90bcc | 2014-07-09 17:25:41 -0700 | [diff] [blame] | 21 | import android.text.TextUtils; |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 22 | import java.lang.IllegalArgumentException; |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 23 | |
| 24 | /** |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 25 | * This class represents the capabilities of a network. This is used both to specify |
| 26 | * needs to {@link ConnectivityManager} and when inspecting a network. |
| 27 | * |
| 28 | * Note that this replaces the old {@link ConnectivityManager#TYPE_MOBILE} method |
| 29 | * of network selection. Rather than indicate a need for Wi-Fi because an application |
Wink Saville | 4e2dea7 | 2014-09-20 11:04:03 -0700 | [diff] [blame] | 30 | * needs high bandwidth and risk obsolescence when a new, fast network appears (like LTE), |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 31 | * the application should specify it needs high bandwidth. Similarly if an application |
| 32 | * needs an unmetered network for a bulk transfer it can specify that rather than assuming |
| 33 | * all cellular based connections are metered and all Wi-Fi based connections are not. |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 34 | */ |
| 35 | public final class NetworkCapabilities implements Parcelable { |
Robert Greenwalt | 7569f18 | 2014-06-08 16:42:59 -0700 | [diff] [blame] | 36 | /** |
| 37 | * @hide |
| 38 | */ |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 39 | public NetworkCapabilities() { |
Lorenzo Colitti | f7058f5 | 2015-04-27 11:31:55 +0900 | [diff] [blame^] | 40 | clearAll(); |
| 41 | mNetworkCapabilities = |
| 42 | (1 << NET_CAPABILITY_NOT_RESTRICTED) | |
| 43 | (1 << NET_CAPABILITY_TRUSTED) | |
| 44 | (1 << NET_CAPABILITY_NOT_VPN); |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | public NetworkCapabilities(NetworkCapabilities nc) { |
| 48 | if (nc != null) { |
| 49 | mNetworkCapabilities = nc.mNetworkCapabilities; |
| 50 | mTransportTypes = nc.mTransportTypes; |
| 51 | mLinkUpBandwidthKbps = nc.mLinkUpBandwidthKbps; |
| 52 | mLinkDownBandwidthKbps = nc.mLinkDownBandwidthKbps; |
Robert Greenwalt | 94badcc | 2014-07-10 14:53:24 -0700 | [diff] [blame] | 53 | mNetworkSpecifier = nc.mNetworkSpecifier; |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 54 | } |
| 55 | } |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 56 | |
| 57 | /** |
Lorenzo Colitti | f7058f5 | 2015-04-27 11:31:55 +0900 | [diff] [blame^] | 58 | * Completely clears the contents of this object, removing even the capabilities that are set |
| 59 | * by default when the object is constructed. |
| 60 | * @hide |
| 61 | */ |
| 62 | public void clearAll() { |
| 63 | mNetworkCapabilities = mTransportTypes = 0; |
| 64 | mLinkUpBandwidthKbps = mLinkDownBandwidthKbps = 0; |
| 65 | mNetworkSpecifier = null; |
| 66 | } |
| 67 | |
| 68 | /** |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 69 | * Represents the network's capabilities. If any are specified they will be satisfied |
| 70 | * by any Network that matches all of them. |
| 71 | */ |
Lorenzo Colitti | f7058f5 | 2015-04-27 11:31:55 +0900 | [diff] [blame^] | 72 | private long mNetworkCapabilities; |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 73 | |
| 74 | /** |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 75 | * Indicates this is a network that has the ability to reach the |
| 76 | * carrier's MMSC for sending and receiving MMS messages. |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 77 | */ |
| 78 | public static final int NET_CAPABILITY_MMS = 0; |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 79 | |
| 80 | /** |
| 81 | * Indicates this is a network that has the ability to reach the carrier's |
| 82 | * SUPL server, used to retrieve GPS information. |
| 83 | */ |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 84 | public static final int NET_CAPABILITY_SUPL = 1; |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 85 | |
| 86 | /** |
| 87 | * Indicates this is a network that has the ability to reach the carrier's |
| 88 | * DUN or tethering gateway. |
| 89 | */ |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 90 | public static final int NET_CAPABILITY_DUN = 2; |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 91 | |
| 92 | /** |
| 93 | * Indicates this is a network that has the ability to reach the carrier's |
| 94 | * FOTA portal, used for over the air updates. |
| 95 | */ |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 96 | public static final int NET_CAPABILITY_FOTA = 3; |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 97 | |
| 98 | /** |
| 99 | * Indicates this is a network that has the ability to reach the carrier's |
| 100 | * IMS servers, used for network registration and signaling. |
| 101 | */ |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 102 | public static final int NET_CAPABILITY_IMS = 4; |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 103 | |
| 104 | /** |
| 105 | * Indicates this is a network that has the ability to reach the carrier's |
| 106 | * CBS servers, used for carrier specific services. |
| 107 | */ |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 108 | public static final int NET_CAPABILITY_CBS = 5; |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 109 | |
| 110 | /** |
| 111 | * Indicates this is a network that has the ability to reach a Wi-Fi direct |
| 112 | * peer. |
| 113 | */ |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 114 | public static final int NET_CAPABILITY_WIFI_P2P = 6; |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 115 | |
| 116 | /** |
| 117 | * Indicates this is a network that has the ability to reach a carrier's |
| 118 | * Initial Attach servers. |
| 119 | */ |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 120 | public static final int NET_CAPABILITY_IA = 7; |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 121 | |
| 122 | /** |
| 123 | * Indicates this is a network that has the ability to reach a carrier's |
| 124 | * RCS servers, used for Rich Communication Services. |
| 125 | */ |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 126 | public static final int NET_CAPABILITY_RCS = 8; |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 127 | |
| 128 | /** |
| 129 | * Indicates this is a network that has the ability to reach a carrier's |
| 130 | * XCAP servers, used for configuration and control. |
| 131 | */ |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 132 | public static final int NET_CAPABILITY_XCAP = 9; |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 133 | |
| 134 | /** |
| 135 | * Indicates this is a network that has the ability to reach a carrier's |
| 136 | * Emergency IMS servers, used for network signaling during emergency calls. |
| 137 | */ |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 138 | public static final int NET_CAPABILITY_EIMS = 10; |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 139 | |
| 140 | /** |
| 141 | * Indicates that this network is unmetered. |
| 142 | */ |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 143 | public static final int NET_CAPABILITY_NOT_METERED = 11; |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 144 | |
| 145 | /** |
| 146 | * Indicates that this network should be able to reach the internet. |
| 147 | */ |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 148 | public static final int NET_CAPABILITY_INTERNET = 12; |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 149 | |
| 150 | /** |
| 151 | * Indicates that this network is available for general use. If this is not set |
| 152 | * applications should not attempt to communicate on this network. Note that this |
| 153 | * is simply informative and not enforcement - enforcement is handled via other means. |
| 154 | * Set by default. |
| 155 | */ |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 156 | public static final int NET_CAPABILITY_NOT_RESTRICTED = 13; |
| 157 | |
Robert Greenwalt | 16e12ab | 2014-07-08 15:31:37 -0700 | [diff] [blame] | 158 | /** |
| 159 | * Indicates that the user has indicated implicit trust of this network. This |
| 160 | * generally means it's a sim-selected carrier, a plugged in ethernet, a paired |
| 161 | * BT device or a wifi the user asked to connect to. Untrusted networks |
| 162 | * are probably limited to unknown wifi AP. Set by default. |
| 163 | */ |
| 164 | public static final int NET_CAPABILITY_TRUSTED = 14; |
| 165 | |
Paul Jensen | 76b610a | 2015-03-18 09:33:07 -0400 | [diff] [blame] | 166 | /** |
Paul Jensen | 6bc2c2c | 2014-05-07 15:27:40 -0400 | [diff] [blame] | 167 | * Indicates that this network is not a VPN. This capability is set by default and should be |
Paul Jensen | 76b610a | 2015-03-18 09:33:07 -0400 | [diff] [blame] | 168 | * explicitly cleared for VPN networks. |
Paul Jensen | 6bc2c2c | 2014-05-07 15:27:40 -0400 | [diff] [blame] | 169 | */ |
| 170 | public static final int NET_CAPABILITY_NOT_VPN = 15; |
| 171 | |
Lorenzo Colitti | 403aa26 | 2014-11-28 11:21:30 +0900 | [diff] [blame] | 172 | /** |
| 173 | * Indicates that connectivity on this network was successfully validated. For example, for a |
| 174 | * network with NET_CAPABILITY_INTERNET, it means that Internet connectivity was successfully |
| 175 | * detected. |
| 176 | * @hide |
| 177 | */ |
| 178 | public static final int NET_CAPABILITY_VALIDATED = 16; |
Robert Greenwalt | 16e12ab | 2014-07-08 15:31:37 -0700 | [diff] [blame] | 179 | |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 180 | private static final int MIN_NET_CAPABILITY = NET_CAPABILITY_MMS; |
Lorenzo Colitti | 403aa26 | 2014-11-28 11:21:30 +0900 | [diff] [blame] | 181 | private static final int MAX_NET_CAPABILITY = NET_CAPABILITY_VALIDATED; |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 182 | |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 183 | /** |
| 184 | * Adds the given capability to this {@code NetworkCapability} instance. |
| 185 | * Multiple capabilities may be applied sequentially. Note that when searching |
| 186 | * for a network to satisfy a request, all capabilities requested must be satisfied. |
| 187 | * |
Robert Greenwalt | 7569f18 | 2014-06-08 16:42:59 -0700 | [diff] [blame] | 188 | * @param capability the {@code NetworkCapabilities.NET_CAPABILITY_*} to be added. |
| 189 | * @return This NetworkCapability to facilitate chaining. |
| 190 | * @hide |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 191 | */ |
Robert Greenwalt | 7569f18 | 2014-06-08 16:42:59 -0700 | [diff] [blame] | 192 | public NetworkCapabilities addCapability(int capability) { |
| 193 | if (capability < MIN_NET_CAPABILITY || capability > MAX_NET_CAPABILITY) { |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 194 | throw new IllegalArgumentException("NetworkCapability out of range"); |
| 195 | } |
Robert Greenwalt | 7569f18 | 2014-06-08 16:42:59 -0700 | [diff] [blame] | 196 | mNetworkCapabilities |= 1 << capability; |
| 197 | return this; |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 198 | } |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 199 | |
| 200 | /** |
| 201 | * Removes (if found) the given capability from this {@code NetworkCapability} instance. |
| 202 | * |
Robert Greenwalt | 7569f18 | 2014-06-08 16:42:59 -0700 | [diff] [blame] | 203 | * @param capability the {@code NetworkCapabilities.NET_CAPABILTIY_*} to be removed. |
| 204 | * @return This NetworkCapability to facilitate chaining. |
| 205 | * @hide |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 206 | */ |
Robert Greenwalt | 7569f18 | 2014-06-08 16:42:59 -0700 | [diff] [blame] | 207 | public NetworkCapabilities removeCapability(int capability) { |
| 208 | if (capability < MIN_NET_CAPABILITY || capability > MAX_NET_CAPABILITY) { |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 209 | throw new IllegalArgumentException("NetworkCapability out of range"); |
| 210 | } |
Robert Greenwalt | 7569f18 | 2014-06-08 16:42:59 -0700 | [diff] [blame] | 211 | mNetworkCapabilities &= ~(1 << capability); |
| 212 | return this; |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 213 | } |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 214 | |
| 215 | /** |
| 216 | * Gets all the capabilities set on this {@code NetworkCapability} instance. |
| 217 | * |
Robert Greenwalt | 7569f18 | 2014-06-08 16:42:59 -0700 | [diff] [blame] | 218 | * @return an array of {@code NetworkCapabilities.NET_CAPABILITY_*} values |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 219 | * for this instance. |
Robert Greenwalt | 7569f18 | 2014-06-08 16:42:59 -0700 | [diff] [blame] | 220 | * @hide |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 221 | */ |
Robert Greenwalt | 7569f18 | 2014-06-08 16:42:59 -0700 | [diff] [blame] | 222 | public int[] getCapabilities() { |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 223 | return enumerateBits(mNetworkCapabilities); |
| 224 | } |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 225 | |
| 226 | /** |
| 227 | * Tests for the presence of a capabilitity on this instance. |
| 228 | * |
Robert Greenwalt | 7569f18 | 2014-06-08 16:42:59 -0700 | [diff] [blame] | 229 | * @param capability the {@code NetworkCapabilities.NET_CAPABILITY_*} to be tested for. |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 230 | * @return {@code true} if set on this instance. |
| 231 | */ |
Robert Greenwalt | 7569f18 | 2014-06-08 16:42:59 -0700 | [diff] [blame] | 232 | public boolean hasCapability(int capability) { |
| 233 | if (capability < MIN_NET_CAPABILITY || capability > MAX_NET_CAPABILITY) { |
Robert Greenwalt | 5c55e33 | 2014-05-08 00:02:04 -0700 | [diff] [blame] | 234 | return false; |
| 235 | } |
Robert Greenwalt | 7569f18 | 2014-06-08 16:42:59 -0700 | [diff] [blame] | 236 | return ((mNetworkCapabilities & (1 << capability)) != 0); |
Robert Greenwalt | 5c55e33 | 2014-05-08 00:02:04 -0700 | [diff] [blame] | 237 | } |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 238 | |
Robert Greenwalt | 7569f18 | 2014-06-08 16:42:59 -0700 | [diff] [blame] | 239 | private int[] enumerateBits(long val) { |
| 240 | int size = Long.bitCount(val); |
| 241 | int[] result = new int[size]; |
| 242 | int index = 0; |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 243 | int resource = 0; |
| 244 | while (val > 0) { |
Robert Greenwalt | 7569f18 | 2014-06-08 16:42:59 -0700 | [diff] [blame] | 245 | if ((val & 1) == 1) result[index++] = resource; |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 246 | val = val >> 1; |
| 247 | resource++; |
| 248 | } |
| 249 | return result; |
| 250 | } |
| 251 | |
| 252 | private void combineNetCapabilities(NetworkCapabilities nc) { |
| 253 | this.mNetworkCapabilities |= nc.mNetworkCapabilities; |
| 254 | } |
| 255 | |
| 256 | private boolean satisfiedByNetCapabilities(NetworkCapabilities nc) { |
| 257 | return ((nc.mNetworkCapabilities & this.mNetworkCapabilities) == this.mNetworkCapabilities); |
| 258 | } |
| 259 | |
Robert Greenwalt | 06314e4 | 2014-10-29 14:04:06 -0700 | [diff] [blame] | 260 | /** @hide */ |
| 261 | public boolean equalsNetCapabilities(NetworkCapabilities nc) { |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 262 | return (nc.mNetworkCapabilities == this.mNetworkCapabilities); |
| 263 | } |
| 264 | |
| 265 | /** |
| 266 | * Representing the transport type. Apps should generally not care about transport. A |
| 267 | * request for a fast internet connection could be satisfied by a number of different |
| 268 | * transports. If any are specified here it will be satisfied a Network that matches |
| 269 | * any of them. If a caller doesn't care about the transport it should not specify any. |
| 270 | */ |
| 271 | private long mTransportTypes; |
| 272 | |
| 273 | /** |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 274 | * Indicates this network uses a Cellular transport. |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 275 | */ |
| 276 | public static final int TRANSPORT_CELLULAR = 0; |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 277 | |
| 278 | /** |
| 279 | * Indicates this network uses a Wi-Fi transport. |
| 280 | */ |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 281 | public static final int TRANSPORT_WIFI = 1; |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 282 | |
| 283 | /** |
| 284 | * Indicates this network uses a Bluetooth transport. |
| 285 | */ |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 286 | public static final int TRANSPORT_BLUETOOTH = 2; |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 287 | |
| 288 | /** |
| 289 | * Indicates this network uses an Ethernet transport. |
| 290 | */ |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 291 | public static final int TRANSPORT_ETHERNET = 3; |
| 292 | |
Paul Jensen | 6bc2c2c | 2014-05-07 15:27:40 -0400 | [diff] [blame] | 293 | /** |
| 294 | * Indicates this network uses a VPN transport. |
| 295 | */ |
| 296 | public static final int TRANSPORT_VPN = 4; |
| 297 | |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 298 | private static final int MIN_TRANSPORT = TRANSPORT_CELLULAR; |
Paul Jensen | 6bc2c2c | 2014-05-07 15:27:40 -0400 | [diff] [blame] | 299 | private static final int MAX_TRANSPORT = TRANSPORT_VPN; |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 300 | |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 301 | /** |
| 302 | * Adds the given transport type to this {@code NetworkCapability} instance. |
| 303 | * Multiple transports may be applied sequentially. Note that when searching |
| 304 | * for a network to satisfy a request, any listed in the request will satisfy the request. |
| 305 | * For example {@code TRANSPORT_WIFI} and {@code TRANSPORT_ETHERNET} added to a |
| 306 | * {@code NetworkCapabilities} would cause either a Wi-Fi network or an Ethernet network |
| 307 | * to be selected. This is logically different than |
| 308 | * {@code NetworkCapabilities.NET_CAPABILITY_*} listed above. |
| 309 | * |
| 310 | * @param transportType the {@code NetworkCapabilities.TRANSPORT_*} to be added. |
Robert Greenwalt | 7569f18 | 2014-06-08 16:42:59 -0700 | [diff] [blame] | 311 | * @return This NetworkCapability to facilitate chaining. |
| 312 | * @hide |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 313 | */ |
Robert Greenwalt | 7569f18 | 2014-06-08 16:42:59 -0700 | [diff] [blame] | 314 | public NetworkCapabilities addTransportType(int transportType) { |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 315 | if (transportType < MIN_TRANSPORT || transportType > MAX_TRANSPORT) { |
| 316 | throw new IllegalArgumentException("TransportType out of range"); |
| 317 | } |
| 318 | mTransportTypes |= 1 << transportType; |
Robert Greenwalt | 5f90bcc | 2014-07-09 17:25:41 -0700 | [diff] [blame] | 319 | setNetworkSpecifier(mNetworkSpecifier); // used for exception checking |
Robert Greenwalt | 7569f18 | 2014-06-08 16:42:59 -0700 | [diff] [blame] | 320 | return this; |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 321 | } |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 322 | |
| 323 | /** |
| 324 | * Removes (if found) the given transport from this {@code NetworkCapability} instance. |
| 325 | * |
| 326 | * @param transportType the {@code NetworkCapabilities.TRANSPORT_*} to be removed. |
Robert Greenwalt | 7569f18 | 2014-06-08 16:42:59 -0700 | [diff] [blame] | 327 | * @return This NetworkCapability to facilitate chaining. |
| 328 | * @hide |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 329 | */ |
Robert Greenwalt | 7569f18 | 2014-06-08 16:42:59 -0700 | [diff] [blame] | 330 | public NetworkCapabilities removeTransportType(int transportType) { |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 331 | if (transportType < MIN_TRANSPORT || transportType > MAX_TRANSPORT) { |
| 332 | throw new IllegalArgumentException("TransportType out of range"); |
| 333 | } |
| 334 | mTransportTypes &= ~(1 << transportType); |
Robert Greenwalt | 5f90bcc | 2014-07-09 17:25:41 -0700 | [diff] [blame] | 335 | setNetworkSpecifier(mNetworkSpecifier); // used for exception checking |
Robert Greenwalt | 7569f18 | 2014-06-08 16:42:59 -0700 | [diff] [blame] | 336 | return this; |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 337 | } |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 338 | |
| 339 | /** |
| 340 | * Gets all the transports set on this {@code NetworkCapability} instance. |
| 341 | * |
Robert Greenwalt | 7569f18 | 2014-06-08 16:42:59 -0700 | [diff] [blame] | 342 | * @return an array of {@code NetworkCapabilities.TRANSPORT_*} values |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 343 | * for this instance. |
Robert Greenwalt | 7569f18 | 2014-06-08 16:42:59 -0700 | [diff] [blame] | 344 | * @hide |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 345 | */ |
Robert Greenwalt | 7569f18 | 2014-06-08 16:42:59 -0700 | [diff] [blame] | 346 | public int[] getTransportTypes() { |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 347 | return enumerateBits(mTransportTypes); |
| 348 | } |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 349 | |
| 350 | /** |
| 351 | * Tests for the presence of a transport on this instance. |
| 352 | * |
| 353 | * @param transportType the {@code NetworkCapabilities.TRANSPORT_*} to be tested for. |
| 354 | * @return {@code true} if set on this instance. |
| 355 | */ |
Robert Greenwalt | 5c55e33 | 2014-05-08 00:02:04 -0700 | [diff] [blame] | 356 | public boolean hasTransport(int transportType) { |
| 357 | if (transportType < MIN_TRANSPORT || transportType > MAX_TRANSPORT) { |
| 358 | return false; |
| 359 | } |
| 360 | return ((mTransportTypes & (1 << transportType)) != 0); |
| 361 | } |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 362 | |
| 363 | private void combineTransportTypes(NetworkCapabilities nc) { |
| 364 | this.mTransportTypes |= nc.mTransportTypes; |
| 365 | } |
| 366 | private boolean satisfiedByTransportTypes(NetworkCapabilities nc) { |
| 367 | return ((this.mTransportTypes == 0) || |
| 368 | ((this.mTransportTypes & nc.mTransportTypes) != 0)); |
| 369 | } |
Robert Greenwalt | 06314e4 | 2014-10-29 14:04:06 -0700 | [diff] [blame] | 370 | /** @hide */ |
| 371 | public boolean equalsTransportTypes(NetworkCapabilities nc) { |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 372 | return (nc.mTransportTypes == this.mTransportTypes); |
| 373 | } |
| 374 | |
| 375 | /** |
| 376 | * Passive link bandwidth. This is a rough guide of the expected peak bandwidth |
| 377 | * for the first hop on the given transport. It is not measured, but may take into account |
| 378 | * link parameters (Radio technology, allocated channels, etc). |
| 379 | */ |
| 380 | private int mLinkUpBandwidthKbps; |
| 381 | private int mLinkDownBandwidthKbps; |
| 382 | |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 383 | /** |
| 384 | * Sets the upstream bandwidth for this network in Kbps. This always only refers to |
| 385 | * the estimated first hop transport bandwidth. |
| 386 | * <p> |
| 387 | * Note that when used to request a network, this specifies the minimum acceptable. |
| 388 | * When received as the state of an existing network this specifies the typical |
| 389 | * first hop bandwidth expected. This is never measured, but rather is inferred |
| 390 | * from technology type and other link parameters. It could be used to differentiate |
| 391 | * between very slow 1xRTT cellular links and other faster networks or even between |
| 392 | * 802.11b vs 802.11AC wifi technologies. It should not be used to differentiate between |
| 393 | * fast backhauls and slow backhauls. |
| 394 | * |
| 395 | * @param upKbps the estimated first hop upstream (device to network) bandwidth. |
Robert Greenwalt | 7569f18 | 2014-06-08 16:42:59 -0700 | [diff] [blame] | 396 | * @hide |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 397 | */ |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 398 | public void setLinkUpstreamBandwidthKbps(int upKbps) { |
| 399 | mLinkUpBandwidthKbps = upKbps; |
| 400 | } |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 401 | |
| 402 | /** |
| 403 | * Retrieves the upstream bandwidth for this network in Kbps. This always only refers to |
| 404 | * the estimated first hop transport bandwidth. |
| 405 | * |
| 406 | * @return The estimated first hop upstream (device to network) bandwidth. |
| 407 | */ |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 408 | public int getLinkUpstreamBandwidthKbps() { |
| 409 | return mLinkUpBandwidthKbps; |
| 410 | } |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 411 | |
| 412 | /** |
| 413 | * Sets the downstream bandwidth for this network in Kbps. This always only refers to |
| 414 | * the estimated first hop transport bandwidth. |
| 415 | * <p> |
| 416 | * Note that when used to request a network, this specifies the minimum acceptable. |
| 417 | * When received as the state of an existing network this specifies the typical |
| 418 | * first hop bandwidth expected. This is never measured, but rather is inferred |
| 419 | * from technology type and other link parameters. It could be used to differentiate |
| 420 | * between very slow 1xRTT cellular links and other faster networks or even between |
| 421 | * 802.11b vs 802.11AC wifi technologies. It should not be used to differentiate between |
| 422 | * fast backhauls and slow backhauls. |
| 423 | * |
| 424 | * @param downKbps the estimated first hop downstream (network to device) bandwidth. |
Robert Greenwalt | 7569f18 | 2014-06-08 16:42:59 -0700 | [diff] [blame] | 425 | * @hide |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 426 | */ |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 427 | public void setLinkDownstreamBandwidthKbps(int downKbps) { |
| 428 | mLinkDownBandwidthKbps = downKbps; |
| 429 | } |
Robert Greenwalt | 01d004e | 2014-05-18 15:24:21 -0700 | [diff] [blame] | 430 | |
| 431 | /** |
| 432 | * Retrieves the downstream bandwidth for this network in Kbps. This always only refers to |
| 433 | * the estimated first hop transport bandwidth. |
| 434 | * |
| 435 | * @return The estimated first hop downstream (network to device) bandwidth. |
| 436 | */ |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 437 | public int getLinkDownstreamBandwidthKbps() { |
| 438 | return mLinkDownBandwidthKbps; |
| 439 | } |
| 440 | |
| 441 | private void combineLinkBandwidths(NetworkCapabilities nc) { |
| 442 | this.mLinkUpBandwidthKbps = |
| 443 | Math.max(this.mLinkUpBandwidthKbps, nc.mLinkUpBandwidthKbps); |
| 444 | this.mLinkDownBandwidthKbps = |
| 445 | Math.max(this.mLinkDownBandwidthKbps, nc.mLinkDownBandwidthKbps); |
| 446 | } |
| 447 | private boolean satisfiedByLinkBandwidths(NetworkCapabilities nc) { |
| 448 | return !(this.mLinkUpBandwidthKbps > nc.mLinkUpBandwidthKbps || |
| 449 | this.mLinkDownBandwidthKbps > nc.mLinkDownBandwidthKbps); |
| 450 | } |
| 451 | private boolean equalsLinkBandwidths(NetworkCapabilities nc) { |
| 452 | return (this.mLinkUpBandwidthKbps == nc.mLinkUpBandwidthKbps && |
| 453 | this.mLinkDownBandwidthKbps == nc.mLinkDownBandwidthKbps); |
| 454 | } |
| 455 | |
Robert Greenwalt | 5f90bcc | 2014-07-09 17:25:41 -0700 | [diff] [blame] | 456 | private String mNetworkSpecifier; |
| 457 | /** |
| 458 | * Sets the optional bearer specific network specifier. |
| 459 | * This has no meaning if a single transport is also not specified, so calling |
| 460 | * this without a single transport set will generate an exception, as will |
| 461 | * subsequently adding or removing transports after this is set. |
| 462 | * </p> |
| 463 | * The interpretation of this {@code String} is bearer specific and bearers that use |
| 464 | * it should document their particulars. For example, Bluetooth may use some sort of |
Robert Greenwalt | 94badcc | 2014-07-10 14:53:24 -0700 | [diff] [blame] | 465 | * device id while WiFi could used SSID and/or BSSID. Cellular may use carrier SPN (name) |
| 466 | * or Subscription ID. |
Robert Greenwalt | 5f90bcc | 2014-07-09 17:25:41 -0700 | [diff] [blame] | 467 | * |
| 468 | * @param networkSpecifier An {@code String} of opaque format used to specify the bearer |
| 469 | * specific network specifier where the bearer has a choice of |
| 470 | * networks. |
| 471 | * @hide |
| 472 | */ |
| 473 | public void setNetworkSpecifier(String networkSpecifier) { |
| 474 | if (TextUtils.isEmpty(networkSpecifier) == false && Long.bitCount(mTransportTypes) != 1) { |
| 475 | throw new IllegalStateException("Must have a single transport specified to use " + |
| 476 | "setNetworkSpecifier"); |
| 477 | } |
| 478 | mNetworkSpecifier = networkSpecifier; |
| 479 | } |
| 480 | |
| 481 | /** |
| 482 | * Gets the optional bearer specific network specifier. |
| 483 | * |
| 484 | * @return The optional {@code String} specifying the bearer specific network specifier. |
| 485 | * See {@link #setNetworkSpecifier}. |
| 486 | * @hide |
| 487 | */ |
| 488 | public String getNetworkSpecifier() { |
| 489 | return mNetworkSpecifier; |
| 490 | } |
| 491 | |
| 492 | private void combineSpecifiers(NetworkCapabilities nc) { |
| 493 | String otherSpecifier = nc.getNetworkSpecifier(); |
| 494 | if (TextUtils.isEmpty(otherSpecifier)) return; |
| 495 | if (TextUtils.isEmpty(mNetworkSpecifier) == false) { |
| 496 | throw new IllegalStateException("Can't combine two networkSpecifiers"); |
| 497 | } |
| 498 | setNetworkSpecifier(otherSpecifier); |
| 499 | } |
| 500 | private boolean satisfiedBySpecifier(NetworkCapabilities nc) { |
| 501 | return (TextUtils.isEmpty(mNetworkSpecifier) || |
| 502 | mNetworkSpecifier.equals(nc.mNetworkSpecifier)); |
| 503 | } |
| 504 | private boolean equalsSpecifier(NetworkCapabilities nc) { |
| 505 | if (TextUtils.isEmpty(mNetworkSpecifier)) { |
| 506 | return TextUtils.isEmpty(nc.mNetworkSpecifier); |
| 507 | } else { |
| 508 | return mNetworkSpecifier.equals(nc.mNetworkSpecifier); |
| 509 | } |
| 510 | } |
| 511 | |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 512 | /** |
| 513 | * Combine a set of Capabilities to this one. Useful for coming up with the complete set |
| 514 | * {@hide} |
| 515 | */ |
| 516 | public void combineCapabilities(NetworkCapabilities nc) { |
| 517 | combineNetCapabilities(nc); |
| 518 | combineTransportTypes(nc); |
| 519 | combineLinkBandwidths(nc); |
Robert Greenwalt | 5f90bcc | 2014-07-09 17:25:41 -0700 | [diff] [blame] | 520 | combineSpecifiers(nc); |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | /** |
| 524 | * Check if our requirements are satisfied by the given Capabilities. |
| 525 | * {@hide} |
| 526 | */ |
| 527 | public boolean satisfiedByNetworkCapabilities(NetworkCapabilities nc) { |
Robert Greenwalt | 5c55e33 | 2014-05-08 00:02:04 -0700 | [diff] [blame] | 528 | return (nc != null && |
| 529 | satisfiedByNetCapabilities(nc) && |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 530 | satisfiedByTransportTypes(nc) && |
Robert Greenwalt | 5f90bcc | 2014-07-09 17:25:41 -0700 | [diff] [blame] | 531 | satisfiedByLinkBandwidths(nc) && |
| 532 | satisfiedBySpecifier(nc)); |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | @Override |
| 536 | public boolean equals(Object obj) { |
| 537 | if (obj == null || (obj instanceof NetworkCapabilities == false)) return false; |
| 538 | NetworkCapabilities that = (NetworkCapabilities)obj; |
| 539 | return (equalsNetCapabilities(that) && |
| 540 | equalsTransportTypes(that) && |
Robert Greenwalt | 5f90bcc | 2014-07-09 17:25:41 -0700 | [diff] [blame] | 541 | equalsLinkBandwidths(that) && |
| 542 | equalsSpecifier(that)); |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | @Override |
| 546 | public int hashCode() { |
| 547 | return ((int)(mNetworkCapabilities & 0xFFFFFFFF) + |
| 548 | ((int)(mNetworkCapabilities >> 32) * 3) + |
| 549 | ((int)(mTransportTypes & 0xFFFFFFFF) * 5) + |
| 550 | ((int)(mTransportTypes >> 32) * 7) + |
| 551 | (mLinkUpBandwidthKbps * 11) + |
Robert Greenwalt | 5f90bcc | 2014-07-09 17:25:41 -0700 | [diff] [blame] | 552 | (mLinkDownBandwidthKbps * 13) + |
| 553 | (TextUtils.isEmpty(mNetworkSpecifier) ? 0 : mNetworkSpecifier.hashCode() * 17)); |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 554 | } |
| 555 | |
Wink Saville | 4e2dea7 | 2014-09-20 11:04:03 -0700 | [diff] [blame] | 556 | @Override |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 557 | public int describeContents() { |
| 558 | return 0; |
| 559 | } |
Wink Saville | 4e2dea7 | 2014-09-20 11:04:03 -0700 | [diff] [blame] | 560 | @Override |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 561 | public void writeToParcel(Parcel dest, int flags) { |
| 562 | dest.writeLong(mNetworkCapabilities); |
| 563 | dest.writeLong(mTransportTypes); |
| 564 | dest.writeInt(mLinkUpBandwidthKbps); |
| 565 | dest.writeInt(mLinkDownBandwidthKbps); |
Robert Greenwalt | 5f90bcc | 2014-07-09 17:25:41 -0700 | [diff] [blame] | 566 | dest.writeString(mNetworkSpecifier); |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 567 | } |
| 568 | public static final Creator<NetworkCapabilities> CREATOR = |
| 569 | new Creator<NetworkCapabilities>() { |
Wink Saville | 4e2dea7 | 2014-09-20 11:04:03 -0700 | [diff] [blame] | 570 | @Override |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 571 | public NetworkCapabilities createFromParcel(Parcel in) { |
| 572 | NetworkCapabilities netCap = new NetworkCapabilities(); |
| 573 | |
| 574 | netCap.mNetworkCapabilities = in.readLong(); |
| 575 | netCap.mTransportTypes = in.readLong(); |
| 576 | netCap.mLinkUpBandwidthKbps = in.readInt(); |
| 577 | netCap.mLinkDownBandwidthKbps = in.readInt(); |
Robert Greenwalt | 5f90bcc | 2014-07-09 17:25:41 -0700 | [diff] [blame] | 578 | netCap.mNetworkSpecifier = in.readString(); |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 579 | return netCap; |
| 580 | } |
Wink Saville | 4e2dea7 | 2014-09-20 11:04:03 -0700 | [diff] [blame] | 581 | @Override |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 582 | public NetworkCapabilities[] newArray(int size) { |
| 583 | return new NetworkCapabilities[size]; |
| 584 | } |
| 585 | }; |
| 586 | |
Wink Saville | 4e2dea7 | 2014-09-20 11:04:03 -0700 | [diff] [blame] | 587 | @Override |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 588 | public String toString() { |
Robert Greenwalt | 7569f18 | 2014-06-08 16:42:59 -0700 | [diff] [blame] | 589 | int[] types = getTransportTypes(); |
| 590 | String transports = (types.length > 0 ? " Transports: " : ""); |
| 591 | for (int i = 0; i < types.length;) { |
| 592 | switch (types[i]) { |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 593 | case TRANSPORT_CELLULAR: transports += "CELLULAR"; break; |
| 594 | case TRANSPORT_WIFI: transports += "WIFI"; break; |
| 595 | case TRANSPORT_BLUETOOTH: transports += "BLUETOOTH"; break; |
| 596 | case TRANSPORT_ETHERNET: transports += "ETHERNET"; break; |
Paul Jensen | 6bc2c2c | 2014-05-07 15:27:40 -0400 | [diff] [blame] | 597 | case TRANSPORT_VPN: transports += "VPN"; break; |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 598 | } |
Robert Greenwalt | 7569f18 | 2014-06-08 16:42:59 -0700 | [diff] [blame] | 599 | if (++i < types.length) transports += "|"; |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 600 | } |
| 601 | |
Robert Greenwalt | 7569f18 | 2014-06-08 16:42:59 -0700 | [diff] [blame] | 602 | types = getCapabilities(); |
| 603 | String capabilities = (types.length > 0 ? " Capabilities: " : ""); |
| 604 | for (int i = 0; i < types.length; ) { |
| 605 | switch (types[i]) { |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 606 | case NET_CAPABILITY_MMS: capabilities += "MMS"; break; |
| 607 | case NET_CAPABILITY_SUPL: capabilities += "SUPL"; break; |
| 608 | case NET_CAPABILITY_DUN: capabilities += "DUN"; break; |
| 609 | case NET_CAPABILITY_FOTA: capabilities += "FOTA"; break; |
| 610 | case NET_CAPABILITY_IMS: capabilities += "IMS"; break; |
| 611 | case NET_CAPABILITY_CBS: capabilities += "CBS"; break; |
| 612 | case NET_CAPABILITY_WIFI_P2P: capabilities += "WIFI_P2P"; break; |
| 613 | case NET_CAPABILITY_IA: capabilities += "IA"; break; |
| 614 | case NET_CAPABILITY_RCS: capabilities += "RCS"; break; |
| 615 | case NET_CAPABILITY_XCAP: capabilities += "XCAP"; break; |
| 616 | case NET_CAPABILITY_EIMS: capabilities += "EIMS"; break; |
| 617 | case NET_CAPABILITY_NOT_METERED: capabilities += "NOT_METERED"; break; |
| 618 | case NET_CAPABILITY_INTERNET: capabilities += "INTERNET"; break; |
| 619 | case NET_CAPABILITY_NOT_RESTRICTED: capabilities += "NOT_RESTRICTED"; break; |
Robert Greenwalt | 16e12ab | 2014-07-08 15:31:37 -0700 | [diff] [blame] | 620 | case NET_CAPABILITY_TRUSTED: capabilities += "TRUSTED"; break; |
Paul Jensen | 6bc2c2c | 2014-05-07 15:27:40 -0400 | [diff] [blame] | 621 | case NET_CAPABILITY_NOT_VPN: capabilities += "NOT_VPN"; break; |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 622 | } |
Robert Greenwalt | 7569f18 | 2014-06-08 16:42:59 -0700 | [diff] [blame] | 623 | if (++i < types.length) capabilities += "&"; |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | String upBand = ((mLinkUpBandwidthKbps > 0) ? " LinkUpBandwidth>=" + |
| 627 | mLinkUpBandwidthKbps + "Kbps" : ""); |
| 628 | String dnBand = ((mLinkDownBandwidthKbps > 0) ? " LinkDnBandwidth>=" + |
| 629 | mLinkDownBandwidthKbps + "Kbps" : ""); |
| 630 | |
Robert Greenwalt | 5f90bcc | 2014-07-09 17:25:41 -0700 | [diff] [blame] | 631 | String specifier = (mNetworkSpecifier == null ? |
| 632 | "" : " Specifier: <" + mNetworkSpecifier + ">"); |
| 633 | |
| 634 | return "[" + transports + capabilities + upBand + dnBand + specifier + "]"; |
Robert Greenwalt | 1448f05 | 2014-04-08 13:41:39 -0700 | [diff] [blame] | 635 | } |
| 636 | } |