blob: cbb6dfe75faece0421b923f1d096691f103f4c4e [file] [log] [blame]
Robert Greenwalt1448f052014-04-08 13:41:39 -07001/*
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
17package android.net;
18
19import android.os.Parcel;
20import android.os.Parcelable;
Robert Greenwalt5f90bcc2014-07-09 17:25:41 -070021import android.text.TextUtils;
Robert Greenwalt1448f052014-04-08 13:41:39 -070022import java.lang.IllegalArgumentException;
Robert Greenwalt1448f052014-04-08 13:41:39 -070023
24/**
Robert Greenwalt01d004e2014-05-18 15:24:21 -070025 * 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 Saville4e2dea72014-09-20 11:04:03 -070030 * needs high bandwidth and risk obsolescence when a new, fast network appears (like LTE),
Robert Greenwalt01d004e2014-05-18 15:24:21 -070031 * 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 Greenwalt1448f052014-04-08 13:41:39 -070034 */
35public final class NetworkCapabilities implements Parcelable {
Robert Greenwalt7569f182014-06-08 16:42:59 -070036 /**
37 * @hide
38 */
Robert Greenwalt01d004e2014-05-18 15:24:21 -070039 public NetworkCapabilities() {
Lorenzo Colittif7058f52015-04-27 11:31:55 +090040 clearAll();
Lorenzo Colitti260a36d2015-07-08 12:49:04 +090041 mNetworkCapabilities = DEFAULT_CAPABILITIES;
Robert Greenwalt01d004e2014-05-18 15:24:21 -070042 }
43
44 public NetworkCapabilities(NetworkCapabilities nc) {
45 if (nc != null) {
46 mNetworkCapabilities = nc.mNetworkCapabilities;
47 mTransportTypes = nc.mTransportTypes;
48 mLinkUpBandwidthKbps = nc.mLinkUpBandwidthKbps;
49 mLinkDownBandwidthKbps = nc.mLinkDownBandwidthKbps;
Robert Greenwalt94badcc2014-07-10 14:53:24 -070050 mNetworkSpecifier = nc.mNetworkSpecifier;
Lorenzo Colittic3f21f32015-07-06 23:50:27 +090051 mSignalStrength = nc.mSignalStrength;
Robert Greenwalt01d004e2014-05-18 15:24:21 -070052 }
53 }
Robert Greenwalt1448f052014-04-08 13:41:39 -070054
55 /**
Lorenzo Colittif7058f52015-04-27 11:31:55 +090056 * Completely clears the contents of this object, removing even the capabilities that are set
57 * by default when the object is constructed.
58 * @hide
59 */
60 public void clearAll() {
61 mNetworkCapabilities = mTransportTypes = 0;
62 mLinkUpBandwidthKbps = mLinkDownBandwidthKbps = 0;
63 mNetworkSpecifier = null;
Lorenzo Colittic3f21f32015-07-06 23:50:27 +090064 mSignalStrength = SIGNAL_STRENGTH_UNSPECIFIED;
Lorenzo Colittif7058f52015-04-27 11:31:55 +090065 }
66
67 /**
Robert Greenwalt1448f052014-04-08 13:41:39 -070068 * Represents the network's capabilities. If any are specified they will be satisfied
69 * by any Network that matches all of them.
70 */
Lorenzo Colittif7058f52015-04-27 11:31:55 +090071 private long mNetworkCapabilities;
Robert Greenwalt1448f052014-04-08 13:41:39 -070072
73 /**
Robert Greenwalt01d004e2014-05-18 15:24:21 -070074 * Indicates this is a network that has the ability to reach the
75 * carrier's MMSC for sending and receiving MMS messages.
Robert Greenwalt1448f052014-04-08 13:41:39 -070076 */
77 public static final int NET_CAPABILITY_MMS = 0;
Robert Greenwalt01d004e2014-05-18 15:24:21 -070078
79 /**
80 * Indicates this is a network that has the ability to reach the carrier's
81 * SUPL server, used to retrieve GPS information.
82 */
Robert Greenwalt1448f052014-04-08 13:41:39 -070083 public static final int NET_CAPABILITY_SUPL = 1;
Robert Greenwalt01d004e2014-05-18 15:24:21 -070084
85 /**
86 * Indicates this is a network that has the ability to reach the carrier's
87 * DUN or tethering gateway.
88 */
Robert Greenwalt1448f052014-04-08 13:41:39 -070089 public static final int NET_CAPABILITY_DUN = 2;
Robert Greenwalt01d004e2014-05-18 15:24:21 -070090
91 /**
92 * Indicates this is a network that has the ability to reach the carrier's
93 * FOTA portal, used for over the air updates.
94 */
Robert Greenwalt1448f052014-04-08 13:41:39 -070095 public static final int NET_CAPABILITY_FOTA = 3;
Robert Greenwalt01d004e2014-05-18 15:24:21 -070096
97 /**
98 * Indicates this is a network that has the ability to reach the carrier's
99 * IMS servers, used for network registration and signaling.
100 */
Robert Greenwalt1448f052014-04-08 13:41:39 -0700101 public static final int NET_CAPABILITY_IMS = 4;
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700102
103 /**
104 * Indicates this is a network that has the ability to reach the carrier's
105 * CBS servers, used for carrier specific services.
106 */
Robert Greenwalt1448f052014-04-08 13:41:39 -0700107 public static final int NET_CAPABILITY_CBS = 5;
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700108
109 /**
110 * Indicates this is a network that has the ability to reach a Wi-Fi direct
111 * peer.
112 */
Robert Greenwalt1448f052014-04-08 13:41:39 -0700113 public static final int NET_CAPABILITY_WIFI_P2P = 6;
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700114
115 /**
116 * Indicates this is a network that has the ability to reach a carrier's
117 * Initial Attach servers.
118 */
Robert Greenwalt1448f052014-04-08 13:41:39 -0700119 public static final int NET_CAPABILITY_IA = 7;
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700120
121 /**
122 * Indicates this is a network that has the ability to reach a carrier's
123 * RCS servers, used for Rich Communication Services.
124 */
Robert Greenwalt1448f052014-04-08 13:41:39 -0700125 public static final int NET_CAPABILITY_RCS = 8;
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700126
127 /**
128 * Indicates this is a network that has the ability to reach a carrier's
129 * XCAP servers, used for configuration and control.
130 */
Robert Greenwalt1448f052014-04-08 13:41:39 -0700131 public static final int NET_CAPABILITY_XCAP = 9;
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700132
133 /**
134 * Indicates this is a network that has the ability to reach a carrier's
Robert Greenwalt4bd43892015-07-09 14:49:35 -0700135 * Emergency IMS servers or other services, used for network signaling
136 * during emergency calls.
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700137 */
Robert Greenwalt1448f052014-04-08 13:41:39 -0700138 public static final int NET_CAPABILITY_EIMS = 10;
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700139
140 /**
141 * Indicates that this network is unmetered.
142 */
Robert Greenwalt1448f052014-04-08 13:41:39 -0700143 public static final int NET_CAPABILITY_NOT_METERED = 11;
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700144
145 /**
146 * Indicates that this network should be able to reach the internet.
147 */
Robert Greenwalt1448f052014-04-08 13:41:39 -0700148 public static final int NET_CAPABILITY_INTERNET = 12;
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700149
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 Greenwalt1448f052014-04-08 13:41:39 -0700156 public static final int NET_CAPABILITY_NOT_RESTRICTED = 13;
157
Robert Greenwalt16e12ab2014-07-08 15:31:37 -0700158 /**
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 Jensen76b610a2015-03-18 09:33:07 -0400166 /**
Paul Jensen6bc2c2c2014-05-07 15:27:40 -0400167 * Indicates that this network is not a VPN. This capability is set by default and should be
Paul Jensen76b610a2015-03-18 09:33:07 -0400168 * explicitly cleared for VPN networks.
Paul Jensen6bc2c2c2014-05-07 15:27:40 -0400169 */
170 public static final int NET_CAPABILITY_NOT_VPN = 15;
171
Lorenzo Colitti403aa262014-11-28 11:21:30 +0900172 /**
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.
Lorenzo Colitti403aa262014-11-28 11:21:30 +0900176 */
177 public static final int NET_CAPABILITY_VALIDATED = 16;
Robert Greenwalt16e12ab2014-07-08 15:31:37 -0700178
Paul Jensen3d194ea2015-06-16 14:27:36 -0400179 /**
180 * Indicates that this network was found to have a captive portal in place last time it was
181 * probed.
182 */
183 public static final int NET_CAPABILITY_CAPTIVE_PORTAL = 17;
184
Robert Greenwalt1448f052014-04-08 13:41:39 -0700185 private static final int MIN_NET_CAPABILITY = NET_CAPABILITY_MMS;
Paul Jensen3d194ea2015-06-16 14:27:36 -0400186 private static final int MAX_NET_CAPABILITY = NET_CAPABILITY_CAPTIVE_PORTAL;
Robert Greenwalt1448f052014-04-08 13:41:39 -0700187
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700188 /**
Lorenzo Colitti260a36d2015-07-08 12:49:04 +0900189 * Network capabilities that are expected to be mutable, i.e., can change while a particular
190 * network is connected.
191 */
192 private static final long MUTABLE_CAPABILITIES =
193 // TRUSTED can change when user explicitly connects to an untrusted network in Settings.
194 // http://b/18206275
195 (1 << NET_CAPABILITY_TRUSTED) |
196 (1 << NET_CAPABILITY_VALIDATED) |
197 (1 << NET_CAPABILITY_CAPTIVE_PORTAL);
198
199 /**
Etan Cohenddb9ef02015-11-18 10:56:15 -0800200 * Network specifier for factories which want to match any network specifier
201 * (NS) in a request. Behavior:
202 * <li>Empty NS in request matches any network factory NS</li>
203 * <li>Empty NS in the network factory NS only matches a request with an
204 * empty NS</li>
205 * <li>"*" (this constant) NS in the network factory matches requests with
206 * any NS</li>
207 *
208 * @hide
209 */
210 public static final String MATCH_ALL_REQUESTS_NETWORK_SPECIFIER = "*";
211
212 /**
Lorenzo Colitti260a36d2015-07-08 12:49:04 +0900213 * Network capabilities that are not allowed in NetworkRequests. This exists because the
214 * NetworkFactory / NetworkAgent model does not deal well with the situation where a
215 * capability's presence cannot be known in advance. If such a capability is requested, then we
216 * can get into a cycle where the NetworkFactory endlessly churns out NetworkAgents that then
217 * get immediately torn down because they do not have the requested capability.
218 */
219 private static final long NON_REQUESTABLE_CAPABILITIES =
220 (1 << NET_CAPABILITY_VALIDATED) |
221 (1 << NET_CAPABILITY_CAPTIVE_PORTAL);
222
223 /**
224 * Capabilities that are set by default when the object is constructed.
225 */
226 private static final long DEFAULT_CAPABILITIES =
227 (1 << NET_CAPABILITY_NOT_RESTRICTED) |
228 (1 << NET_CAPABILITY_TRUSTED) |
229 (1 << NET_CAPABILITY_NOT_VPN);
230
231 /**
Paul Jensen487ffe72015-07-24 15:57:11 -0400232 * Capabilities that suggest that a network is restricted.
233 * {@see #maybeMarkCapabilitiesRestricted}.
234 */
235 private static final long RESTRICTED_CAPABILITIES =
236 (1 << NET_CAPABILITY_CBS) |
237 (1 << NET_CAPABILITY_DUN) |
238 (1 << NET_CAPABILITY_EIMS) |
239 (1 << NET_CAPABILITY_FOTA) |
240 (1 << NET_CAPABILITY_IA) |
241 (1 << NET_CAPABILITY_IMS) |
242 (1 << NET_CAPABILITY_RCS) |
243 (1 << NET_CAPABILITY_XCAP);
244
245 /**
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700246 * Adds the given capability to this {@code NetworkCapability} instance.
247 * Multiple capabilities may be applied sequentially. Note that when searching
248 * for a network to satisfy a request, all capabilities requested must be satisfied.
249 *
Robert Greenwalt7569f182014-06-08 16:42:59 -0700250 * @param capability the {@code NetworkCapabilities.NET_CAPABILITY_*} to be added.
Pierre Imaic8419a82016-03-22 17:54:54 +0900251 * @return This NetworkCapabilities instance, to facilitate chaining.
Robert Greenwalt7569f182014-06-08 16:42:59 -0700252 * @hide
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700253 */
Robert Greenwalt7569f182014-06-08 16:42:59 -0700254 public NetworkCapabilities addCapability(int capability) {
255 if (capability < MIN_NET_CAPABILITY || capability > MAX_NET_CAPABILITY) {
Robert Greenwalt1448f052014-04-08 13:41:39 -0700256 throw new IllegalArgumentException("NetworkCapability out of range");
257 }
Robert Greenwalt7569f182014-06-08 16:42:59 -0700258 mNetworkCapabilities |= 1 << capability;
259 return this;
Robert Greenwalt1448f052014-04-08 13:41:39 -0700260 }
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700261
262 /**
263 * Removes (if found) the given capability from this {@code NetworkCapability} instance.
264 *
Robert Greenwalt7569f182014-06-08 16:42:59 -0700265 * @param capability the {@code NetworkCapabilities.NET_CAPABILTIY_*} to be removed.
Pierre Imaic8419a82016-03-22 17:54:54 +0900266 * @return This NetworkCapabilities instance, to facilitate chaining.
Robert Greenwalt7569f182014-06-08 16:42:59 -0700267 * @hide
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700268 */
Robert Greenwalt7569f182014-06-08 16:42:59 -0700269 public NetworkCapabilities removeCapability(int capability) {
270 if (capability < MIN_NET_CAPABILITY || capability > MAX_NET_CAPABILITY) {
Robert Greenwalt1448f052014-04-08 13:41:39 -0700271 throw new IllegalArgumentException("NetworkCapability out of range");
272 }
Robert Greenwalt7569f182014-06-08 16:42:59 -0700273 mNetworkCapabilities &= ~(1 << capability);
274 return this;
Robert Greenwalt1448f052014-04-08 13:41:39 -0700275 }
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700276
277 /**
278 * Gets all the capabilities set on this {@code NetworkCapability} instance.
279 *
Robert Greenwalt7569f182014-06-08 16:42:59 -0700280 * @return an array of {@code NetworkCapabilities.NET_CAPABILITY_*} values
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700281 * for this instance.
Robert Greenwalt7569f182014-06-08 16:42:59 -0700282 * @hide
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700283 */
Robert Greenwalt7569f182014-06-08 16:42:59 -0700284 public int[] getCapabilities() {
Robert Greenwalt1448f052014-04-08 13:41:39 -0700285 return enumerateBits(mNetworkCapabilities);
286 }
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700287
288 /**
289 * Tests for the presence of a capabilitity on this instance.
290 *
Robert Greenwalt7569f182014-06-08 16:42:59 -0700291 * @param capability the {@code NetworkCapabilities.NET_CAPABILITY_*} to be tested for.
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700292 * @return {@code true} if set on this instance.
293 */
Robert Greenwalt7569f182014-06-08 16:42:59 -0700294 public boolean hasCapability(int capability) {
295 if (capability < MIN_NET_CAPABILITY || capability > MAX_NET_CAPABILITY) {
Robert Greenwalt5c55e332014-05-08 00:02:04 -0700296 return false;
297 }
Robert Greenwalt7569f182014-06-08 16:42:59 -0700298 return ((mNetworkCapabilities & (1 << capability)) != 0);
Robert Greenwalt5c55e332014-05-08 00:02:04 -0700299 }
Robert Greenwalt1448f052014-04-08 13:41:39 -0700300
Robert Greenwalt7569f182014-06-08 16:42:59 -0700301 private int[] enumerateBits(long val) {
302 int size = Long.bitCount(val);
303 int[] result = new int[size];
304 int index = 0;
Robert Greenwalt1448f052014-04-08 13:41:39 -0700305 int resource = 0;
306 while (val > 0) {
Robert Greenwalt7569f182014-06-08 16:42:59 -0700307 if ((val & 1) == 1) result[index++] = resource;
Robert Greenwalt1448f052014-04-08 13:41:39 -0700308 val = val >> 1;
309 resource++;
310 }
311 return result;
312 }
313
314 private void combineNetCapabilities(NetworkCapabilities nc) {
315 this.mNetworkCapabilities |= nc.mNetworkCapabilities;
316 }
317
Lorenzo Colitti260a36d2015-07-08 12:49:04 +0900318 /**
319 * Convenience function that returns a human-readable description of the first mutable
320 * capability we find. Used to present an error message to apps that request mutable
321 * capabilities.
322 *
323 * @hide
324 */
325 public String describeFirstNonRequestableCapability() {
326 if (hasCapability(NET_CAPABILITY_VALIDATED)) return "NET_CAPABILITY_VALIDATED";
327 if (hasCapability(NET_CAPABILITY_CAPTIVE_PORTAL)) return "NET_CAPABILITY_CAPTIVE_PORTAL";
328 // This cannot happen unless the preceding checks are incomplete.
329 if ((mNetworkCapabilities & NON_REQUESTABLE_CAPABILITIES) != 0) {
330 return "unknown non-requestable capabilities " + Long.toHexString(mNetworkCapabilities);
331 }
332 if (mLinkUpBandwidthKbps != 0 || mLinkDownBandwidthKbps != 0) return "link bandwidth";
Lorenzo Colittic3f21f32015-07-06 23:50:27 +0900333 if (hasSignalStrength()) return "signalStrength";
Lorenzo Colitti260a36d2015-07-08 12:49:04 +0900334 return null;
335 }
336
337 private boolean satisfiedByNetCapabilities(NetworkCapabilities nc, boolean onlyImmutable) {
338 long networkCapabilities = this.mNetworkCapabilities;
339 if (onlyImmutable) {
340 networkCapabilities = networkCapabilities & ~MUTABLE_CAPABILITIES;
341 }
342 return ((nc.mNetworkCapabilities & networkCapabilities) == networkCapabilities);
Robert Greenwalt1448f052014-04-08 13:41:39 -0700343 }
344
Robert Greenwalt06314e42014-10-29 14:04:06 -0700345 /** @hide */
346 public boolean equalsNetCapabilities(NetworkCapabilities nc) {
Robert Greenwalt1448f052014-04-08 13:41:39 -0700347 return (nc.mNetworkCapabilities == this.mNetworkCapabilities);
348 }
349
Lorenzo Colitti260a36d2015-07-08 12:49:04 +0900350 private boolean equalsNetCapabilitiesImmutable(NetworkCapabilities that) {
351 return ((this.mNetworkCapabilities & ~MUTABLE_CAPABILITIES) ==
352 (that.mNetworkCapabilities & ~MUTABLE_CAPABILITIES));
353 }
354
Robert Greenwalt1448f052014-04-08 13:41:39 -0700355 /**
Paul Jensen487ffe72015-07-24 15:57:11 -0400356 * Removes the NET_CAPABILITY_NOT_RESTRICTED capability if all the capabilities it provides are
357 * typically provided by restricted networks.
358 *
359 * TODO: consider:
360 * - Renaming it to guessRestrictedCapability and make it set the
361 * restricted capability bit in addition to clearing it.
362 * @hide
363 */
364 public void maybeMarkCapabilitiesRestricted() {
365 // If all the capabilities are typically provided by restricted networks, conclude that this
366 // network is restricted.
Paul Jensenaae613d2015-08-19 11:06:15 -0400367 if ((mNetworkCapabilities & ~(DEFAULT_CAPABILITIES | RESTRICTED_CAPABILITIES)) == 0 &&
368 // Must have at least some restricted capabilities, otherwise a request for an
369 // internet-less network will get marked restricted.
370 (mNetworkCapabilities & RESTRICTED_CAPABILITIES) != 0) {
Paul Jensen487ffe72015-07-24 15:57:11 -0400371 removeCapability(NET_CAPABILITY_NOT_RESTRICTED);
Paul Jensenaae613d2015-08-19 11:06:15 -0400372 }
Paul Jensen487ffe72015-07-24 15:57:11 -0400373 }
374
375 /**
Robert Greenwalt1448f052014-04-08 13:41:39 -0700376 * Representing the transport type. Apps should generally not care about transport. A
377 * request for a fast internet connection could be satisfied by a number of different
378 * transports. If any are specified here it will be satisfied a Network that matches
379 * any of them. If a caller doesn't care about the transport it should not specify any.
380 */
381 private long mTransportTypes;
382
383 /**
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700384 * Indicates this network uses a Cellular transport.
Robert Greenwalt1448f052014-04-08 13:41:39 -0700385 */
386 public static final int TRANSPORT_CELLULAR = 0;
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700387
388 /**
389 * Indicates this network uses a Wi-Fi transport.
390 */
Robert Greenwalt1448f052014-04-08 13:41:39 -0700391 public static final int TRANSPORT_WIFI = 1;
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700392
393 /**
394 * Indicates this network uses a Bluetooth transport.
395 */
Robert Greenwalt1448f052014-04-08 13:41:39 -0700396 public static final int TRANSPORT_BLUETOOTH = 2;
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700397
398 /**
399 * Indicates this network uses an Ethernet transport.
400 */
Robert Greenwalt1448f052014-04-08 13:41:39 -0700401 public static final int TRANSPORT_ETHERNET = 3;
402
Paul Jensen6bc2c2c2014-05-07 15:27:40 -0400403 /**
404 * Indicates this network uses a VPN transport.
405 */
406 public static final int TRANSPORT_VPN = 4;
407
Etan Cohenbd9fdbe2016-06-20 09:27:12 -0700408 /**
Etan Cohen0849ded2016-10-26 11:22:06 -0700409 * Indicates this network uses a Wi-Fi Aware transport.
Etan Cohenbd9fdbe2016-06-20 09:27:12 -0700410 *
Etan Cohen0849ded2016-10-26 11:22:06 -0700411 * @hide PROPOSED_AWARE_API
Etan Cohenbd9fdbe2016-06-20 09:27:12 -0700412 */
Etan Cohen0849ded2016-10-26 11:22:06 -0700413 public static final int TRANSPORT_WIFI_AWARE = 5;
Etan Cohenbd9fdbe2016-06-20 09:27:12 -0700414
Robert Greenwalt1448f052014-04-08 13:41:39 -0700415 private static final int MIN_TRANSPORT = TRANSPORT_CELLULAR;
Etan Cohen0849ded2016-10-26 11:22:06 -0700416 private static final int MAX_TRANSPORT = TRANSPORT_WIFI_AWARE;
Robert Greenwalt1448f052014-04-08 13:41:39 -0700417
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700418 /**
419 * Adds the given transport type to this {@code NetworkCapability} instance.
420 * Multiple transports may be applied sequentially. Note that when searching
421 * for a network to satisfy a request, any listed in the request will satisfy the request.
422 * For example {@code TRANSPORT_WIFI} and {@code TRANSPORT_ETHERNET} added to a
423 * {@code NetworkCapabilities} would cause either a Wi-Fi network or an Ethernet network
424 * to be selected. This is logically different than
425 * {@code NetworkCapabilities.NET_CAPABILITY_*} listed above.
426 *
427 * @param transportType the {@code NetworkCapabilities.TRANSPORT_*} to be added.
Pierre Imaic8419a82016-03-22 17:54:54 +0900428 * @return This NetworkCapabilities instance, to facilitate chaining.
Robert Greenwalt7569f182014-06-08 16:42:59 -0700429 * @hide
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700430 */
Robert Greenwalt7569f182014-06-08 16:42:59 -0700431 public NetworkCapabilities addTransportType(int transportType) {
Robert Greenwalt1448f052014-04-08 13:41:39 -0700432 if (transportType < MIN_TRANSPORT || transportType > MAX_TRANSPORT) {
433 throw new IllegalArgumentException("TransportType out of range");
434 }
435 mTransportTypes |= 1 << transportType;
Robert Greenwalt5f90bcc2014-07-09 17:25:41 -0700436 setNetworkSpecifier(mNetworkSpecifier); // used for exception checking
Robert Greenwalt7569f182014-06-08 16:42:59 -0700437 return this;
Robert Greenwalt1448f052014-04-08 13:41:39 -0700438 }
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700439
440 /**
441 * Removes (if found) the given transport from this {@code NetworkCapability} instance.
442 *
443 * @param transportType the {@code NetworkCapabilities.TRANSPORT_*} to be removed.
Pierre Imaic8419a82016-03-22 17:54:54 +0900444 * @return This NetworkCapabilities instance, to facilitate chaining.
Robert Greenwalt7569f182014-06-08 16:42:59 -0700445 * @hide
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700446 */
Robert Greenwalt7569f182014-06-08 16:42:59 -0700447 public NetworkCapabilities removeTransportType(int transportType) {
Robert Greenwalt1448f052014-04-08 13:41:39 -0700448 if (transportType < MIN_TRANSPORT || transportType > MAX_TRANSPORT) {
449 throw new IllegalArgumentException("TransportType out of range");
450 }
451 mTransportTypes &= ~(1 << transportType);
Robert Greenwalt5f90bcc2014-07-09 17:25:41 -0700452 setNetworkSpecifier(mNetworkSpecifier); // used for exception checking
Robert Greenwalt7569f182014-06-08 16:42:59 -0700453 return this;
Robert Greenwalt1448f052014-04-08 13:41:39 -0700454 }
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700455
456 /**
457 * Gets all the transports set on this {@code NetworkCapability} instance.
458 *
Robert Greenwalt7569f182014-06-08 16:42:59 -0700459 * @return an array of {@code NetworkCapabilities.TRANSPORT_*} values
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700460 * for this instance.
Robert Greenwalt7569f182014-06-08 16:42:59 -0700461 * @hide
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700462 */
Robert Greenwalt7569f182014-06-08 16:42:59 -0700463 public int[] getTransportTypes() {
Robert Greenwalt1448f052014-04-08 13:41:39 -0700464 return enumerateBits(mTransportTypes);
465 }
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700466
467 /**
468 * Tests for the presence of a transport on this instance.
469 *
470 * @param transportType the {@code NetworkCapabilities.TRANSPORT_*} to be tested for.
471 * @return {@code true} if set on this instance.
472 */
Robert Greenwalt5c55e332014-05-08 00:02:04 -0700473 public boolean hasTransport(int transportType) {
474 if (transportType < MIN_TRANSPORT || transportType > MAX_TRANSPORT) {
475 return false;
476 }
477 return ((mTransportTypes & (1 << transportType)) != 0);
478 }
Robert Greenwalt1448f052014-04-08 13:41:39 -0700479
480 private void combineTransportTypes(NetworkCapabilities nc) {
481 this.mTransportTypes |= nc.mTransportTypes;
482 }
483 private boolean satisfiedByTransportTypes(NetworkCapabilities nc) {
484 return ((this.mTransportTypes == 0) ||
485 ((this.mTransportTypes & nc.mTransportTypes) != 0));
486 }
Robert Greenwalt06314e42014-10-29 14:04:06 -0700487 /** @hide */
488 public boolean equalsTransportTypes(NetworkCapabilities nc) {
Robert Greenwalt1448f052014-04-08 13:41:39 -0700489 return (nc.mTransportTypes == this.mTransportTypes);
490 }
491
492 /**
493 * Passive link bandwidth. This is a rough guide of the expected peak bandwidth
494 * for the first hop on the given transport. It is not measured, but may take into account
495 * link parameters (Radio technology, allocated channels, etc).
496 */
497 private int mLinkUpBandwidthKbps;
498 private int mLinkDownBandwidthKbps;
499
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700500 /**
501 * Sets the upstream bandwidth for this network in Kbps. This always only refers to
502 * the estimated first hop transport bandwidth.
503 * <p>
504 * Note that when used to request a network, this specifies the minimum acceptable.
505 * When received as the state of an existing network this specifies the typical
506 * first hop bandwidth expected. This is never measured, but rather is inferred
507 * from technology type and other link parameters. It could be used to differentiate
508 * between very slow 1xRTT cellular links and other faster networks or even between
509 * 802.11b vs 802.11AC wifi technologies. It should not be used to differentiate between
510 * fast backhauls and slow backhauls.
511 *
512 * @param upKbps the estimated first hop upstream (device to network) bandwidth.
Robert Greenwalt7569f182014-06-08 16:42:59 -0700513 * @hide
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700514 */
Robert Greenwalt1448f052014-04-08 13:41:39 -0700515 public void setLinkUpstreamBandwidthKbps(int upKbps) {
516 mLinkUpBandwidthKbps = upKbps;
517 }
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700518
519 /**
520 * Retrieves the upstream bandwidth for this network in Kbps. This always only refers to
521 * the estimated first hop transport bandwidth.
522 *
523 * @return The estimated first hop upstream (device to network) bandwidth.
524 */
Robert Greenwalt1448f052014-04-08 13:41:39 -0700525 public int getLinkUpstreamBandwidthKbps() {
526 return mLinkUpBandwidthKbps;
527 }
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700528
529 /**
530 * Sets the downstream bandwidth for this network in Kbps. This always only refers to
531 * the estimated first hop transport bandwidth.
532 * <p>
533 * Note that when used to request a network, this specifies the minimum acceptable.
534 * When received as the state of an existing network this specifies the typical
535 * first hop bandwidth expected. This is never measured, but rather is inferred
536 * from technology type and other link parameters. It could be used to differentiate
537 * between very slow 1xRTT cellular links and other faster networks or even between
538 * 802.11b vs 802.11AC wifi technologies. It should not be used to differentiate between
539 * fast backhauls and slow backhauls.
540 *
541 * @param downKbps the estimated first hop downstream (network to device) bandwidth.
Robert Greenwalt7569f182014-06-08 16:42:59 -0700542 * @hide
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700543 */
Robert Greenwalt1448f052014-04-08 13:41:39 -0700544 public void setLinkDownstreamBandwidthKbps(int downKbps) {
545 mLinkDownBandwidthKbps = downKbps;
546 }
Robert Greenwalt01d004e2014-05-18 15:24:21 -0700547
548 /**
549 * Retrieves the downstream bandwidth for this network in Kbps. This always only refers to
550 * the estimated first hop transport bandwidth.
551 *
552 * @return The estimated first hop downstream (network to device) bandwidth.
553 */
Robert Greenwalt1448f052014-04-08 13:41:39 -0700554 public int getLinkDownstreamBandwidthKbps() {
555 return mLinkDownBandwidthKbps;
556 }
557
558 private void combineLinkBandwidths(NetworkCapabilities nc) {
559 this.mLinkUpBandwidthKbps =
560 Math.max(this.mLinkUpBandwidthKbps, nc.mLinkUpBandwidthKbps);
561 this.mLinkDownBandwidthKbps =
562 Math.max(this.mLinkDownBandwidthKbps, nc.mLinkDownBandwidthKbps);
563 }
564 private boolean satisfiedByLinkBandwidths(NetworkCapabilities nc) {
565 return !(this.mLinkUpBandwidthKbps > nc.mLinkUpBandwidthKbps ||
566 this.mLinkDownBandwidthKbps > nc.mLinkDownBandwidthKbps);
567 }
568 private boolean equalsLinkBandwidths(NetworkCapabilities nc) {
569 return (this.mLinkUpBandwidthKbps == nc.mLinkUpBandwidthKbps &&
570 this.mLinkDownBandwidthKbps == nc.mLinkDownBandwidthKbps);
571 }
572
Robert Greenwalt5f90bcc2014-07-09 17:25:41 -0700573 private String mNetworkSpecifier;
574 /**
575 * Sets the optional bearer specific network specifier.
576 * This has no meaning if a single transport is also not specified, so calling
577 * this without a single transport set will generate an exception, as will
578 * subsequently adding or removing transports after this is set.
579 * </p>
580 * The interpretation of this {@code String} is bearer specific and bearers that use
581 * it should document their particulars. For example, Bluetooth may use some sort of
Robert Greenwalt94badcc2014-07-10 14:53:24 -0700582 * device id while WiFi could used SSID and/or BSSID. Cellular may use carrier SPN (name)
583 * or Subscription ID.
Robert Greenwalt5f90bcc2014-07-09 17:25:41 -0700584 *
585 * @param networkSpecifier An {@code String} of opaque format used to specify the bearer
586 * specific network specifier where the bearer has a choice of
587 * networks.
Pierre Imaic8419a82016-03-22 17:54:54 +0900588 * @return This NetworkCapabilities instance, to facilitate chaining.
Robert Greenwalt5f90bcc2014-07-09 17:25:41 -0700589 * @hide
590 */
Pierre Imaic8419a82016-03-22 17:54:54 +0900591 public NetworkCapabilities setNetworkSpecifier(String networkSpecifier) {
Robert Greenwalt5f90bcc2014-07-09 17:25:41 -0700592 if (TextUtils.isEmpty(networkSpecifier) == false && Long.bitCount(mTransportTypes) != 1) {
593 throw new IllegalStateException("Must have a single transport specified to use " +
594 "setNetworkSpecifier");
595 }
596 mNetworkSpecifier = networkSpecifier;
Pierre Imaic8419a82016-03-22 17:54:54 +0900597 return this;
Robert Greenwalt5f90bcc2014-07-09 17:25:41 -0700598 }
599
600 /**
601 * Gets the optional bearer specific network specifier.
602 *
603 * @return The optional {@code String} specifying the bearer specific network specifier.
604 * See {@link #setNetworkSpecifier}.
605 * @hide
606 */
607 public String getNetworkSpecifier() {
608 return mNetworkSpecifier;
609 }
610
611 private void combineSpecifiers(NetworkCapabilities nc) {
612 String otherSpecifier = nc.getNetworkSpecifier();
613 if (TextUtils.isEmpty(otherSpecifier)) return;
614 if (TextUtils.isEmpty(mNetworkSpecifier) == false) {
615 throw new IllegalStateException("Can't combine two networkSpecifiers");
616 }
617 setNetworkSpecifier(otherSpecifier);
618 }
619 private boolean satisfiedBySpecifier(NetworkCapabilities nc) {
620 return (TextUtils.isEmpty(mNetworkSpecifier) ||
Etan Cohenddb9ef02015-11-18 10:56:15 -0800621 mNetworkSpecifier.equals(nc.mNetworkSpecifier) ||
622 MATCH_ALL_REQUESTS_NETWORK_SPECIFIER.equals(nc.mNetworkSpecifier));
Robert Greenwalt5f90bcc2014-07-09 17:25:41 -0700623 }
624 private boolean equalsSpecifier(NetworkCapabilities nc) {
625 if (TextUtils.isEmpty(mNetworkSpecifier)) {
626 return TextUtils.isEmpty(nc.mNetworkSpecifier);
627 } else {
628 return mNetworkSpecifier.equals(nc.mNetworkSpecifier);
629 }
630 }
631
Robert Greenwalt1448f052014-04-08 13:41:39 -0700632 /**
Lorenzo Colittic3f21f32015-07-06 23:50:27 +0900633 * Magic value that indicates no signal strength provided. A request specifying this value is
634 * always satisfied.
635 *
636 * @hide
637 */
638 public static final int SIGNAL_STRENGTH_UNSPECIFIED = Integer.MIN_VALUE;
639
640 /**
641 * Signal strength. This is a signed integer, and higher values indicate better signal.
642 * The exact units are bearer-dependent. For example, Wi-Fi uses RSSI.
643 */
644 private int mSignalStrength;
645
646 /**
647 * Sets the signal strength. This is a signed integer, with higher values indicating a stronger
648 * signal. The exact units are bearer-dependent. For example, Wi-Fi uses the same RSSI units
649 * reported by WifiManager.
650 * <p>
651 * Note that when used to register a network callback, this specifies the minimum acceptable
652 * signal strength. When received as the state of an existing network it specifies the current
653 * value. A value of code SIGNAL_STRENGTH_UNSPECIFIED} means no value when received and has no
654 * effect when requesting a callback.
655 *
656 * @param signalStrength the bearer-specific signal strength.
657 * @hide
658 */
659 public void setSignalStrength(int signalStrength) {
660 mSignalStrength = signalStrength;
661 }
662
663 /**
664 * Returns {@code true} if this object specifies a signal strength.
665 *
666 * @hide
667 */
668 public boolean hasSignalStrength() {
669 return mSignalStrength > SIGNAL_STRENGTH_UNSPECIFIED;
670 }
671
672 /**
673 * Retrieves the signal strength.
674 *
675 * @return The bearer-specific signal strength.
676 * @hide
677 */
678 public int getSignalStrength() {
679 return mSignalStrength;
680 }
681
682 private void combineSignalStrength(NetworkCapabilities nc) {
683 this.mSignalStrength = Math.max(this.mSignalStrength, nc.mSignalStrength);
684 }
685
686 private boolean satisfiedBySignalStrength(NetworkCapabilities nc) {
687 return this.mSignalStrength <= nc.mSignalStrength;
688 }
689
690 private boolean equalsSignalStrength(NetworkCapabilities nc) {
691 return this.mSignalStrength == nc.mSignalStrength;
692 }
693
694 /**
Robert Greenwalt1448f052014-04-08 13:41:39 -0700695 * Combine a set of Capabilities to this one. Useful for coming up with the complete set
Lorenzo Colitti260a36d2015-07-08 12:49:04 +0900696 * @hide
Robert Greenwalt1448f052014-04-08 13:41:39 -0700697 */
698 public void combineCapabilities(NetworkCapabilities nc) {
699 combineNetCapabilities(nc);
700 combineTransportTypes(nc);
701 combineLinkBandwidths(nc);
Robert Greenwalt5f90bcc2014-07-09 17:25:41 -0700702 combineSpecifiers(nc);
Lorenzo Colittic3f21f32015-07-06 23:50:27 +0900703 combineSignalStrength(nc);
Robert Greenwalt1448f052014-04-08 13:41:39 -0700704 }
705
706 /**
Lorenzo Colitti260a36d2015-07-08 12:49:04 +0900707 * Check if our requirements are satisfied by the given {@code NetworkCapabilities}.
708 *
709 * @param nc the {@code NetworkCapabilities} that may or may not satisfy our requirements.
710 * @param onlyImmutable if {@code true}, do not consider mutable requirements such as link
711 * bandwidth, signal strength, or validation / captive portal status.
712 *
713 * @hide
714 */
715 private boolean satisfiedByNetworkCapabilities(NetworkCapabilities nc, boolean onlyImmutable) {
716 return (nc != null &&
717 satisfiedByNetCapabilities(nc, onlyImmutable) &&
718 satisfiedByTransportTypes(nc) &&
719 (onlyImmutable || satisfiedByLinkBandwidths(nc)) &&
Lorenzo Colittic3f21f32015-07-06 23:50:27 +0900720 satisfiedBySpecifier(nc) &&
721 (onlyImmutable || satisfiedBySignalStrength(nc)));
Lorenzo Colitti260a36d2015-07-08 12:49:04 +0900722 }
723
724 /**
725 * Check if our requirements are satisfied by the given {@code NetworkCapabilities}.
726 *
727 * @param nc the {@code NetworkCapabilities} that may or may not satisfy our requirements.
728 *
729 * @hide
Robert Greenwalt1448f052014-04-08 13:41:39 -0700730 */
731 public boolean satisfiedByNetworkCapabilities(NetworkCapabilities nc) {
Lorenzo Colitti260a36d2015-07-08 12:49:04 +0900732 return satisfiedByNetworkCapabilities(nc, false);
733 }
734
735 /**
736 * Check if our immutable requirements are satisfied by the given {@code NetworkCapabilities}.
737 *
738 * @param nc the {@code NetworkCapabilities} that may or may not satisfy our requirements.
739 *
740 * @hide
741 */
742 public boolean satisfiedByImmutableNetworkCapabilities(NetworkCapabilities nc) {
743 return satisfiedByNetworkCapabilities(nc, true);
744 }
745
746 /**
747 * Checks that our immutable capabilities are the same as those of the given
748 * {@code NetworkCapabilities}.
749 *
750 * @hide
751 */
752 public boolean equalImmutableCapabilities(NetworkCapabilities nc) {
753 if (nc == null) return false;
754 return (equalsNetCapabilitiesImmutable(nc) &&
755 equalsTransportTypes(nc) &&
756 equalsSpecifier(nc));
Robert Greenwalt1448f052014-04-08 13:41:39 -0700757 }
758
759 @Override
760 public boolean equals(Object obj) {
761 if (obj == null || (obj instanceof NetworkCapabilities == false)) return false;
762 NetworkCapabilities that = (NetworkCapabilities)obj;
763 return (equalsNetCapabilities(that) &&
764 equalsTransportTypes(that) &&
Robert Greenwalt5f90bcc2014-07-09 17:25:41 -0700765 equalsLinkBandwidths(that) &&
Lorenzo Colittic3f21f32015-07-06 23:50:27 +0900766 equalsSignalStrength(that) &&
Robert Greenwalt5f90bcc2014-07-09 17:25:41 -0700767 equalsSpecifier(that));
Robert Greenwalt1448f052014-04-08 13:41:39 -0700768 }
769
770 @Override
771 public int hashCode() {
772 return ((int)(mNetworkCapabilities & 0xFFFFFFFF) +
773 ((int)(mNetworkCapabilities >> 32) * 3) +
774 ((int)(mTransportTypes & 0xFFFFFFFF) * 5) +
775 ((int)(mTransportTypes >> 32) * 7) +
776 (mLinkUpBandwidthKbps * 11) +
Robert Greenwalt5f90bcc2014-07-09 17:25:41 -0700777 (mLinkDownBandwidthKbps * 13) +
Lorenzo Colittic3f21f32015-07-06 23:50:27 +0900778 (TextUtils.isEmpty(mNetworkSpecifier) ? 0 : mNetworkSpecifier.hashCode() * 17) +
779 (mSignalStrength * 19));
Robert Greenwalt1448f052014-04-08 13:41:39 -0700780 }
781
Wink Saville4e2dea72014-09-20 11:04:03 -0700782 @Override
Robert Greenwalt1448f052014-04-08 13:41:39 -0700783 public int describeContents() {
784 return 0;
785 }
Wink Saville4e2dea72014-09-20 11:04:03 -0700786 @Override
Robert Greenwalt1448f052014-04-08 13:41:39 -0700787 public void writeToParcel(Parcel dest, int flags) {
788 dest.writeLong(mNetworkCapabilities);
789 dest.writeLong(mTransportTypes);
790 dest.writeInt(mLinkUpBandwidthKbps);
791 dest.writeInt(mLinkDownBandwidthKbps);
Robert Greenwalt5f90bcc2014-07-09 17:25:41 -0700792 dest.writeString(mNetworkSpecifier);
Lorenzo Colittic3f21f32015-07-06 23:50:27 +0900793 dest.writeInt(mSignalStrength);
Robert Greenwalt1448f052014-04-08 13:41:39 -0700794 }
Lorenzo Colittic3f21f32015-07-06 23:50:27 +0900795
Robert Greenwalt1448f052014-04-08 13:41:39 -0700796 public static final Creator<NetworkCapabilities> CREATOR =
797 new Creator<NetworkCapabilities>() {
Wink Saville4e2dea72014-09-20 11:04:03 -0700798 @Override
Robert Greenwalt1448f052014-04-08 13:41:39 -0700799 public NetworkCapabilities createFromParcel(Parcel in) {
800 NetworkCapabilities netCap = new NetworkCapabilities();
801
802 netCap.mNetworkCapabilities = in.readLong();
803 netCap.mTransportTypes = in.readLong();
804 netCap.mLinkUpBandwidthKbps = in.readInt();
805 netCap.mLinkDownBandwidthKbps = in.readInt();
Robert Greenwalt5f90bcc2014-07-09 17:25:41 -0700806 netCap.mNetworkSpecifier = in.readString();
Lorenzo Colittic3f21f32015-07-06 23:50:27 +0900807 netCap.mSignalStrength = in.readInt();
Robert Greenwalt1448f052014-04-08 13:41:39 -0700808 return netCap;
809 }
Wink Saville4e2dea72014-09-20 11:04:03 -0700810 @Override
Robert Greenwalt1448f052014-04-08 13:41:39 -0700811 public NetworkCapabilities[] newArray(int size) {
812 return new NetworkCapabilities[size];
813 }
814 };
815
Wink Saville4e2dea72014-09-20 11:04:03 -0700816 @Override
Robert Greenwalt1448f052014-04-08 13:41:39 -0700817 public String toString() {
Robert Greenwalt7569f182014-06-08 16:42:59 -0700818 int[] types = getTransportTypes();
Hugo Benichi5df9d722016-04-25 17:16:35 +0900819 String transports = (types.length > 0) ? " Transports: " + transportNamesOf(types) : "";
Robert Greenwalt1448f052014-04-08 13:41:39 -0700820
Robert Greenwalt7569f182014-06-08 16:42:59 -0700821 types = getCapabilities();
822 String capabilities = (types.length > 0 ? " Capabilities: " : "");
823 for (int i = 0; i < types.length; ) {
824 switch (types[i]) {
Robert Greenwalt1448f052014-04-08 13:41:39 -0700825 case NET_CAPABILITY_MMS: capabilities += "MMS"; break;
826 case NET_CAPABILITY_SUPL: capabilities += "SUPL"; break;
827 case NET_CAPABILITY_DUN: capabilities += "DUN"; break;
828 case NET_CAPABILITY_FOTA: capabilities += "FOTA"; break;
829 case NET_CAPABILITY_IMS: capabilities += "IMS"; break;
830 case NET_CAPABILITY_CBS: capabilities += "CBS"; break;
831 case NET_CAPABILITY_WIFI_P2P: capabilities += "WIFI_P2P"; break;
832 case NET_CAPABILITY_IA: capabilities += "IA"; break;
833 case NET_CAPABILITY_RCS: capabilities += "RCS"; break;
834 case NET_CAPABILITY_XCAP: capabilities += "XCAP"; break;
835 case NET_CAPABILITY_EIMS: capabilities += "EIMS"; break;
836 case NET_CAPABILITY_NOT_METERED: capabilities += "NOT_METERED"; break;
837 case NET_CAPABILITY_INTERNET: capabilities += "INTERNET"; break;
838 case NET_CAPABILITY_NOT_RESTRICTED: capabilities += "NOT_RESTRICTED"; break;
Robert Greenwalt16e12ab2014-07-08 15:31:37 -0700839 case NET_CAPABILITY_TRUSTED: capabilities += "TRUSTED"; break;
Paul Jensen6bc2c2c2014-05-07 15:27:40 -0400840 case NET_CAPABILITY_NOT_VPN: capabilities += "NOT_VPN"; break;
Lorenzo Colitti76f67792015-05-14 17:28:27 +0900841 case NET_CAPABILITY_VALIDATED: capabilities += "VALIDATED"; break;
Paul Jensencf4c2c62015-07-01 14:16:32 -0400842 case NET_CAPABILITY_CAPTIVE_PORTAL: capabilities += "CAPTIVE_PORTAL"; break;
Robert Greenwalt1448f052014-04-08 13:41:39 -0700843 }
Robert Greenwalt7569f182014-06-08 16:42:59 -0700844 if (++i < types.length) capabilities += "&";
Robert Greenwalt1448f052014-04-08 13:41:39 -0700845 }
846
847 String upBand = ((mLinkUpBandwidthKbps > 0) ? " LinkUpBandwidth>=" +
848 mLinkUpBandwidthKbps + "Kbps" : "");
849 String dnBand = ((mLinkDownBandwidthKbps > 0) ? " LinkDnBandwidth>=" +
850 mLinkDownBandwidthKbps + "Kbps" : "");
851
Robert Greenwalt5f90bcc2014-07-09 17:25:41 -0700852 String specifier = (mNetworkSpecifier == null ?
853 "" : " Specifier: <" + mNetworkSpecifier + ">");
854
Lorenzo Colittic3f21f32015-07-06 23:50:27 +0900855 String signalStrength = (hasSignalStrength() ? " SignalStrength: " + mSignalStrength : "");
856
857 return "[" + transports + capabilities + upBand + dnBand + specifier + signalStrength + "]";
Robert Greenwalt1448f052014-04-08 13:41:39 -0700858 }
Hugo Benichi5df9d722016-04-25 17:16:35 +0900859
860 /**
861 * @hide
862 */
863 public static String transportNamesOf(int[] types) {
864 String transports = "";
865 for (int i = 0; i < types.length;) {
866 switch (types[i]) {
867 case TRANSPORT_CELLULAR: transports += "CELLULAR"; break;
868 case TRANSPORT_WIFI: transports += "WIFI"; break;
869 case TRANSPORT_BLUETOOTH: transports += "BLUETOOTH"; break;
870 case TRANSPORT_ETHERNET: transports += "ETHERNET"; break;
871 case TRANSPORT_VPN: transports += "VPN"; break;
Etan Cohen0849ded2016-10-26 11:22:06 -0700872 case TRANSPORT_WIFI_AWARE: transports += "WIFI_AWARE"; break;
Hugo Benichi5df9d722016-04-25 17:16:35 +0900873 }
874 if (++i < types.length) transports += "|";
875 }
876 return transports;
877 }
Robert Greenwalt1448f052014-04-08 13:41:39 -0700878}