blob: 89d99617dfbf0831b34ec5b78e8c56a3e15e5860 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2008 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
Mathew Inwoodfa3a7462018-08-08 14:52:47 +010019import android.annotation.UnsupportedAppUsage;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import android.os.Parcel;
Jeff Sharkey43d2a172017-07-12 10:50:42 -060021import android.os.Parcelable;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022
Jeff Sharkey836ecb52013-01-03 11:21:24 -080023import com.android.internal.annotations.VisibleForTesting;
24
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import java.util.EnumMap;
26
27/**
Scott Main671644c2011-10-06 19:02:28 -070028 * Describes the status of a network interface.
29 * <p>Use {@link ConnectivityManager#getActiveNetworkInfo()} to get an instance that represents
30 * the current network connection.
junyulai3822c8a2018-12-13 12:47:51 +080031 *
32 * @deprecated Callers should instead use the {@link ConnectivityManager.NetworkCallback} API to
33 * learn about connectivity changes, or switch to use
34 * {@link ConnectivityManager#getNetworkCapabilities} or
35 * {@link ConnectivityManager#getLinkProperties} to get information synchronously. Keep
36 * in mind that while callbacks are guaranteed to be called for every event in order,
37 * synchronous calls have no such constraints, and as such it is unadvisable to use the
38 * synchronous methods inside the callbacks as they will often not offer a view of
39 * networking that is consistent (that is: they may return a past or a future state with
40 * respect to the event being processed by the callback). Instead, callers are advised
41 * to only use the arguments of the callbacks, possibly memorizing the specific bits of
42 * information they need to keep from one callback to another.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043 */
junyulai3822c8a2018-12-13 12:47:51 +080044@Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045public class NetworkInfo implements Parcelable {
46
47 /**
48 * Coarse-grained network state. This is probably what most applications should
49 * use, rather than {@link android.net.NetworkInfo.DetailedState DetailedState}.
50 * The mapping between the two is as follows:
51 * <br/><br/>
52 * <table>
53 * <tr><td><b>Detailed state</b></td><td><b>Coarse-grained state</b></td></tr>
54 * <tr><td><code>IDLE</code></td><td><code>DISCONNECTED</code></td></tr>
Chalard Jean8117f932018-03-08 13:54:53 +090055 * <tr><td><code>SCANNING</code></td><td><code>DISCONNECTED</code></td></tr>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056 * <tr><td><code>CONNECTING</code></td><td><code>CONNECTING</code></td></tr>
57 * <tr><td><code>AUTHENTICATING</code></td><td><code>CONNECTING</code></td></tr>
Chalard Jean8117f932018-03-08 13:54:53 +090058 * <tr><td><code>OBTAINING_IPADDR</code></td><td><code>CONNECTING</code></td></tr>
59 * <tr><td><code>VERIFYING_POOR_LINK</code></td><td><code>CONNECTING</code></td></tr>
60 * <tr><td><code>CAPTIVE_PORTAL_CHECK</code></td><td><code>CONNECTING</code></td></tr>
Scott Main671644c2011-10-06 19:02:28 -070061 * <tr><td><code>CONNECTED</code></td><td><code>CONNECTED</code></td></tr>
Chalard Jean8117f932018-03-08 13:54:53 +090062 * <tr><td><code>SUSPENDED</code></td><td><code>SUSPENDED</code></td></tr>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063 * <tr><td><code>DISCONNECTING</code></td><td><code>DISCONNECTING</code></td></tr>
64 * <tr><td><code>DISCONNECTED</code></td><td><code>DISCONNECTED</code></td></tr>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065 * <tr><td><code>FAILED</code></td><td><code>DISCONNECTED</code></td></tr>
Chalard Jean8117f932018-03-08 13:54:53 +090066 * <tr><td><code>BLOCKED</code></td><td><code>DISCONNECTED</code></td></tr>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067 * </table>
junyulai3822c8a2018-12-13 12:47:51 +080068 *
69 * @deprecated See {@link NetworkInfo}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070 */
junyulai3822c8a2018-12-13 12:47:51 +080071 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072 public enum State {
73 CONNECTING, CONNECTED, SUSPENDED, DISCONNECTING, DISCONNECTED, UNKNOWN
74 }
75
76 /**
77 * The fine-grained state of a network connection. This level of detail
78 * is probably of interest to few applications. Most should use
79 * {@link android.net.NetworkInfo.State State} instead.
junyulai3822c8a2018-12-13 12:47:51 +080080 *
81 * @deprecated See {@link NetworkInfo}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 */
junyulai3822c8a2018-12-13 12:47:51 +080083 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084 public enum DetailedState {
85 /** Ready to start data connection setup. */
86 IDLE,
87 /** Searching for an available access point. */
88 SCANNING,
89 /** Currently setting up data connection. */
90 CONNECTING,
91 /** Network link established, performing authentication. */
92 AUTHENTICATING,
93 /** Awaiting response from DHCP server in order to assign IP address information. */
94 OBTAINING_IPADDR,
95 /** IP traffic should be available. */
96 CONNECTED,
97 /** IP traffic is suspended */
98 SUSPENDED,
99 /** Currently tearing down data connection. */
100 DISCONNECTING,
101 /** IP traffic not available. */
102 DISCONNECTED,
103 /** Attempt to connect failed. */
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700104 FAILED,
105 /** Access to this network is blocked. */
Irfan Sheriff07573b32012-01-27 21:00:19 -0800106 BLOCKED,
107 /** Link has poor connectivity. */
Irfan Sheriffda6da092012-08-16 12:49:23 -0700108 VERIFYING_POOR_LINK,
109 /** Checking if network is a captive portal */
Wink Saville67c38212013-09-05 12:02:25 -0700110 CAPTIVE_PORTAL_CHECK
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111 }
112
113 /**
114 * This is the map described in the Javadoc comment above. The positions
115 * of the elements of the array must correspond to the ordinal values
116 * of <code>DetailedState</code>.
117 */
118 private static final EnumMap<DetailedState, State> stateMap =
119 new EnumMap<DetailedState, State>(DetailedState.class);
120
121 static {
122 stateMap.put(DetailedState.IDLE, State.DISCONNECTED);
123 stateMap.put(DetailedState.SCANNING, State.DISCONNECTED);
124 stateMap.put(DetailedState.CONNECTING, State.CONNECTING);
125 stateMap.put(DetailedState.AUTHENTICATING, State.CONNECTING);
126 stateMap.put(DetailedState.OBTAINING_IPADDR, State.CONNECTING);
Irfan Sheriff07573b32012-01-27 21:00:19 -0800127 stateMap.put(DetailedState.VERIFYING_POOR_LINK, State.CONNECTING);
Irfan Sheriffda6da092012-08-16 12:49:23 -0700128 stateMap.put(DetailedState.CAPTIVE_PORTAL_CHECK, State.CONNECTING);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129 stateMap.put(DetailedState.CONNECTED, State.CONNECTED);
130 stateMap.put(DetailedState.SUSPENDED, State.SUSPENDED);
131 stateMap.put(DetailedState.DISCONNECTING, State.DISCONNECTING);
132 stateMap.put(DetailedState.DISCONNECTED, State.DISCONNECTED);
133 stateMap.put(DetailedState.FAILED, State.DISCONNECTED);
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700134 stateMap.put(DetailedState.BLOCKED, State.DISCONNECTED);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135 }
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137 private int mNetworkType;
138 private int mSubtype;
139 private String mTypeName;
140 private String mSubtypeName;
141 private State mState;
142 private DetailedState mDetailedState;
143 private String mReason;
144 private String mExtraInfo;
145 private boolean mIsFailover;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146 private boolean mIsAvailable;
Jeff Sharkeyf07c7b92016-04-22 09:50:16 -0600147 private boolean mIsRoaming;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148
149 /**
Irfan Sheriffd649c122010-06-09 15:39:36 -0700150 * @hide
151 */
Mathew Inwoodfa3a7462018-08-08 14:52:47 +0100152 @UnsupportedAppUsage
Irfan Sheriffd649c122010-06-09 15:39:36 -0700153 public NetworkInfo(int type, int subtype, String typeName, String subtypeName) {
Hugo Benichi16f0a942017-06-20 14:07:59 +0900154 if (!ConnectivityManager.isNetworkTypeValid(type)
155 && type != ConnectivityManager.TYPE_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 throw new IllegalArgumentException("Invalid network type: " + type);
157 }
158 mNetworkType = type;
159 mSubtype = subtype;
160 mTypeName = typeName;
161 mSubtypeName = subtypeName;
162 setDetailedState(DetailedState.IDLE, null, null);
163 mState = State.UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 }
165
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700166 /** {@hide} */
Mathew Inwoodfa3a7462018-08-08 14:52:47 +0100167 @UnsupportedAppUsage
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700168 public NetworkInfo(NetworkInfo source) {
169 if (source != null) {
Narayan Kamath12b28ce2013-10-11 13:43:30 +0100170 synchronized (source) {
171 mNetworkType = source.mNetworkType;
172 mSubtype = source.mSubtype;
173 mTypeName = source.mTypeName;
174 mSubtypeName = source.mSubtypeName;
175 mState = source.mState;
176 mDetailedState = source.mDetailedState;
177 mReason = source.mReason;
178 mExtraInfo = source.mExtraInfo;
179 mIsFailover = source.mIsFailover;
Narayan Kamath12b28ce2013-10-11 13:43:30 +0100180 mIsAvailable = source.mIsAvailable;
Jeff Sharkeyf07c7b92016-04-22 09:50:16 -0600181 mIsRoaming = source.mIsRoaming;
Narayan Kamath12b28ce2013-10-11 13:43:30 +0100182 }
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700183 }
184 }
185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186 /**
Scott Main671644c2011-10-06 19:02:28 -0700187 * Reports the type of network to which the
188 * info in this {@code NetworkInfo} pertains.
189 * @return one of {@link ConnectivityManager#TYPE_MOBILE}, {@link
190 * ConnectivityManager#TYPE_WIFI}, {@link ConnectivityManager#TYPE_WIMAX}, {@link
191 * ConnectivityManager#TYPE_ETHERNET}, {@link ConnectivityManager#TYPE_BLUETOOTH}, or other
Chalard Jean8117f932018-03-08 13:54:53 +0900192 * types defined by {@link ConnectivityManager}.
193 * @deprecated Callers should switch to checking {@link NetworkCapabilities#hasTransport}
194 * instead with one of the NetworkCapabilities#TRANSPORT_* constants :
195 * {@link #getType} and {@link #getTypeName} cannot account for networks using
196 * multiple transports. Note that generally apps should not care about transport;
197 * {@link NetworkCapabilities#NET_CAPABILITY_NOT_METERED} and
198 * {@link NetworkCapabilities#getLinkDownstreamBandwidthKbps} are calls that
199 * apps concerned with meteredness or bandwidth should be looking at, as they
200 * offer this information with much better accuracy.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800201 */
Chalard Jean8117f932018-03-08 13:54:53 +0900202 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800203 public int getType() {
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700204 synchronized (this) {
205 return mNetworkType;
206 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207 }
208
209 /**
Chalard Jean8117f932018-03-08 13:54:53 +0900210 * @deprecated Use {@link NetworkCapabilities} instead
Robert Greenwaltb90b20b2014-06-02 15:32:02 -0700211 * @hide
212 */
Chalard Jean8117f932018-03-08 13:54:53 +0900213 @Deprecated
Robert Greenwaltb90b20b2014-06-02 15:32:02 -0700214 public void setType(int type) {
215 synchronized (this) {
216 mNetworkType = type;
217 }
218 }
219
220 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 * Return a network-type-specific integer describing the subtype
222 * of the network.
223 * @return the network subtype
junyulai05986c62018-08-07 19:50:45 +0800224 * @deprecated Use {@link android.telephony.TelephonyManager#getDataNetworkType} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225 */
junyulai05986c62018-08-07 19:50:45 +0800226 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800227 public int getSubtype() {
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700228 synchronized (this) {
229 return mSubtype;
230 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231 }
232
Robert Greenwalt3192dec2014-05-27 13:20:24 -0700233 /**
234 * @hide
235 */
Mathew Inwoodfa3a7462018-08-08 14:52:47 +0100236 @UnsupportedAppUsage
Robert Greenwalt3192dec2014-05-27 13:20:24 -0700237 public void setSubtype(int subtype, String subtypeName) {
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700238 synchronized (this) {
239 mSubtype = subtype;
240 mSubtypeName = subtypeName;
241 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800242 }
243
244 /**
245 * Return a human-readable name describe the type of the network,
246 * for example "WIFI" or "MOBILE".
247 * @return the name of the network type
Chalard Jean8117f932018-03-08 13:54:53 +0900248 * @deprecated Callers should switch to checking {@link NetworkCapabilities#hasTransport}
249 * instead with one of the NetworkCapabilities#TRANSPORT_* constants :
250 * {@link #getType} and {@link #getTypeName} cannot account for networks using
251 * multiple transports. Note that generally apps should not care about transport;
252 * {@link NetworkCapabilities#NET_CAPABILITY_NOT_METERED} and
253 * {@link NetworkCapabilities#getLinkDownstreamBandwidthKbps} are calls that
254 * apps concerned with meteredness or bandwidth should be looking at, as they
255 * offer this information with much better accuracy.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800256 */
Chalard Jean8117f932018-03-08 13:54:53 +0900257 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800258 public String getTypeName() {
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700259 synchronized (this) {
260 return mTypeName;
261 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800262 }
263
264 /**
265 * Return a human-readable name describing the subtype of the network.
266 * @return the name of the network subtype
junyulai05986c62018-08-07 19:50:45 +0800267 * @deprecated Use {@link android.telephony.TelephonyManager#getDataNetworkType} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 */
junyulai05986c62018-08-07 19:50:45 +0800269 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270 public String getSubtypeName() {
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700271 synchronized (this) {
272 return mSubtypeName;
273 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800274 }
275
276 /**
277 * Indicates whether network connectivity exists or is in the process
278 * of being established. This is good for applications that need to
279 * do anything related to the network other than read or write data.
280 * For the latter, call {@link #isConnected()} instead, which guarantees
281 * that the network is fully usable.
282 * @return {@code true} if network connectivity exists or is in the process
283 * of being established, {@code false} otherwise.
Chalard Jean8117f932018-03-08 13:54:53 +0900284 * @deprecated Apps should instead use the
285 * {@link android.net.ConnectivityManager.NetworkCallback} API to
286 * learn about connectivity changes.
287 * {@link ConnectivityManager#registerDefaultNetworkCallback} and
288 * {@link ConnectivityManager#registerNetworkCallback}. These will
289 * give a more accurate picture of the connectivity state of
290 * the device and let apps react more easily and quickly to changes.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800291 */
Chalard Jean8117f932018-03-08 13:54:53 +0900292 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800293 public boolean isConnectedOrConnecting() {
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700294 synchronized (this) {
295 return mState == State.CONNECTED || mState == State.CONNECTING;
296 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800297 }
298
299 /**
300 * Indicates whether network connectivity exists and it is possible to establish
301 * connections and pass data.
Scott Main671644c2011-10-06 19:02:28 -0700302 * <p>Always call this before attempting to perform data transactions.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800303 * @return {@code true} if network connectivity exists, {@code false} otherwise.
junyulai05986c62018-08-07 19:50:45 +0800304 * @deprecated Apps should instead use the
305 * {@link android.net.ConnectivityManager.NetworkCallback} API to
306 * learn about connectivity changes. See
307 * {@link ConnectivityManager#registerDefaultNetworkCallback} and
308 * {@link ConnectivityManager#registerNetworkCallback}. These will
309 * give a more accurate picture of the connectivity state of
310 * the device and let apps react more easily and quickly to changes.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800311 */
junyulai05986c62018-08-07 19:50:45 +0800312 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800313 public boolean isConnected() {
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700314 synchronized (this) {
315 return mState == State.CONNECTED;
316 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800317 }
318
319 /**
320 * Indicates whether network connectivity is possible. A network is unavailable
321 * when a persistent or semi-persistent condition prevents the possibility
322 * of connecting to that network. Examples include
323 * <ul>
324 * <li>The device is out of the coverage area for any network of this type.</li>
325 * <li>The device is on a network other than the home network (i.e., roaming), and
326 * data roaming has been disabled.</li>
327 * <li>The device's radio is turned off, e.g., because airplane mode is enabled.</li>
328 * </ul>
Chalard Jean8117f932018-03-08 13:54:53 +0900329 * Since Android L, this always returns {@code true}, because the system only
330 * returns info for available networks.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800331 * @return {@code true} if the network is available, {@code false} otherwise
Chalard Jean8117f932018-03-08 13:54:53 +0900332 * @deprecated Apps should instead use the
333 * {@link android.net.ConnectivityManager.NetworkCallback} API to
334 * learn about connectivity changes.
335 * {@link ConnectivityManager#registerDefaultNetworkCallback} and
336 * {@link ConnectivityManager#registerNetworkCallback}. These will
337 * give a more accurate picture of the connectivity state of
338 * the device and let apps react more easily and quickly to changes.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800339 */
Chalard Jean8117f932018-03-08 13:54:53 +0900340 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341 public boolean isAvailable() {
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700342 synchronized (this) {
343 return mIsAvailable;
344 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800345 }
346
347 /**
348 * Sets if the network is available, ie, if the connectivity is possible.
349 * @param isAvailable the new availability value.
Chalard Jean8117f932018-03-08 13:54:53 +0900350 * @deprecated Use {@link NetworkCapabilities} instead
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800351 *
352 * @hide
353 */
Chalard Jean8117f932018-03-08 13:54:53 +0900354 @Deprecated
Mathew Inwoodfa3a7462018-08-08 14:52:47 +0100355 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356 public void setIsAvailable(boolean isAvailable) {
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700357 synchronized (this) {
358 mIsAvailable = isAvailable;
359 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800360 }
361
362 /**
363 * Indicates whether the current attempt to connect to the network
364 * resulted from the ConnectivityManager trying to fail over to this
365 * network following a disconnect from another network.
366 * @return {@code true} if this is a failover attempt, {@code false}
367 * otherwise.
Chalard Jean8117f932018-03-08 13:54:53 +0900368 * @deprecated This field is not populated in recent Android releases,
369 * and does not make a lot of sense in a multi-network world.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800370 */
Chalard Jean8117f932018-03-08 13:54:53 +0900371 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800372 public boolean isFailover() {
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700373 synchronized (this) {
374 return mIsFailover;
375 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 }
377
378 /**
379 * Set the failover boolean.
380 * @param isFailover {@code true} to mark the current connection attempt
381 * as a failover.
Chalard Jean8117f932018-03-08 13:54:53 +0900382 * @deprecated This hasn't been set in any recent Android release.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800383 * @hide
384 */
Chalard Jean8117f932018-03-08 13:54:53 +0900385 @Deprecated
Mathew Inwoodfa3a7462018-08-08 14:52:47 +0100386 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 public void setFailover(boolean isFailover) {
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700388 synchronized (this) {
389 mIsFailover = isFailover;
390 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800391 }
392
393 /**
Jeff Sharkey72f9c422017-10-27 17:22:59 -0600394 * Indicates whether the device is currently roaming on this network. When
395 * {@code true}, it suggests that use of data on this network may incur
396 * extra costs.
397 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800398 * @return {@code true} if roaming is in effect, {@code false} otherwise.
Jeff Sharkey72f9c422017-10-27 17:22:59 -0600399 * @deprecated Callers should switch to checking
400 * {@link NetworkCapabilities#NET_CAPABILITY_NOT_ROAMING}
401 * instead, since that handles more complex situations, such as
402 * VPNs.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800403 */
Jeff Sharkey72f9c422017-10-27 17:22:59 -0600404 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800405 public boolean isRoaming() {
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700406 synchronized (this) {
407 return mIsRoaming;
408 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800409 }
410
Chalard Jean8117f932018-03-08 13:54:53 +0900411 /**
412 * @deprecated Use {@link NetworkCapabilities#NET_CAPABILITY_NOT_ROAMING} instead.
413 * {@hide}
414 */
Jeff Sharkey836ecb52013-01-03 11:21:24 -0800415 @VisibleForTesting
Jeff Sharkey72f9c422017-10-27 17:22:59 -0600416 @Deprecated
Mathew Inwoodfa3a7462018-08-08 14:52:47 +0100417 @UnsupportedAppUsage
Jeff Sharkey836ecb52013-01-03 11:21:24 -0800418 public void setRoaming(boolean isRoaming) {
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700419 synchronized (this) {
420 mIsRoaming = isRoaming;
421 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 }
423
424 /**
425 * Reports the current coarse-grained state of the network.
426 * @return the coarse-grained state
Chalard Jean8117f932018-03-08 13:54:53 +0900427 * @deprecated Apps should instead use the
428 * {@link android.net.ConnectivityManager.NetworkCallback} API to
429 * learn about connectivity changes.
430 * {@link ConnectivityManager#registerDefaultNetworkCallback} and
431 * {@link ConnectivityManager#registerNetworkCallback}. These will
432 * give a more accurate picture of the connectivity state of
433 * the device and let apps react more easily and quickly to changes.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800434 */
Chalard Jean8117f932018-03-08 13:54:53 +0900435 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800436 public State getState() {
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700437 synchronized (this) {
438 return mState;
439 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800440 }
441
442 /**
443 * Reports the current fine-grained state of the network.
444 * @return the fine-grained state
junyulai05986c62018-08-07 19:50:45 +0800445 * @deprecated Apps should instead use the
446 * {@link android.net.ConnectivityManager.NetworkCallback} API to
447 * learn about connectivity changes. See
448 * {@link ConnectivityManager#registerDefaultNetworkCallback} and
449 * {@link ConnectivityManager#registerNetworkCallback}. These will
450 * give a more accurate picture of the connectivity state of
451 * the device and let apps react more easily and quickly to changes.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800452 */
junyulai05986c62018-08-07 19:50:45 +0800453 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454 public DetailedState getDetailedState() {
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700455 synchronized (this) {
456 return mDetailedState;
457 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800458 }
459
460 /**
461 * Sets the fine-grained state of the network.
462 * @param detailedState the {@link DetailedState}.
463 * @param reason a {@code String} indicating the reason for the state change,
464 * if one was supplied. May be {@code null}.
465 * @param extraInfo an optional {@code String} providing addditional network state
466 * information passed up from the lower networking layers.
Chalard Jean8117f932018-03-08 13:54:53 +0900467 * @deprecated Use {@link NetworkCapabilities} instead.
Irfan Sheriffd649c122010-06-09 15:39:36 -0700468 * @hide
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800469 */
Chalard Jean8117f932018-03-08 13:54:53 +0900470 @Deprecated
Mathew Inwoodfa3a7462018-08-08 14:52:47 +0100471 @UnsupportedAppUsage
Irfan Sheriffd649c122010-06-09 15:39:36 -0700472 public void setDetailedState(DetailedState detailedState, String reason, String extraInfo) {
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700473 synchronized (this) {
474 this.mDetailedState = detailedState;
475 this.mState = stateMap.get(detailedState);
476 this.mReason = reason;
477 this.mExtraInfo = extraInfo;
478 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800479 }
480
481 /**
Doug Zongkerd60ae7f2011-11-03 12:45:42 -0700482 * Set the extraInfo field.
483 * @param extraInfo an optional {@code String} providing addditional network state
484 * information passed up from the lower networking layers.
junyulai3822c8a2018-12-13 12:47:51 +0800485 * @deprecated See {@link NetworkInfo#getExtraInfo}.
Doug Zongkerd60ae7f2011-11-03 12:45:42 -0700486 * @hide
487 */
junyulai3822c8a2018-12-13 12:47:51 +0800488 @Deprecated
Doug Zongkerd60ae7f2011-11-03 12:45:42 -0700489 public void setExtraInfo(String extraInfo) {
490 synchronized (this) {
491 this.mExtraInfo = extraInfo;
492 }
493 }
494
495 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496 * Report the reason an attempt to establish connectivity failed,
497 * if one is available.
498 * @return the reason for failure, or null if not available
Chalard Jean8117f932018-03-08 13:54:53 +0900499 * @deprecated This method does not have a consistent contract that could make it useful
500 * to callers.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501 */
502 public String getReason() {
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700503 synchronized (this) {
504 return mReason;
505 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800506 }
507
508 /**
509 * Report the extra information about the network state, if any was
Ang Li953b5622014-09-15 14:44:01 -0700510 * provided by the lower networking layers.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800511 * @return the extra information, or null if not available
junyulai3822c8a2018-12-13 12:47:51 +0800512 * @deprecated Use other services e.g. WifiManager to get additional information passed up from
513 * the lower networking layers.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800514 */
junyulai3822c8a2018-12-13 12:47:51 +0800515 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800516 public String getExtraInfo() {
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700517 synchronized (this) {
518 return mExtraInfo;
519 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800520 }
521
522 @Override
523 public String toString() {
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700524 synchronized (this) {
Robert Greenwaltc9c90c72014-05-13 15:36:27 -0700525 StringBuilder builder = new StringBuilder("[");
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700526 builder.append("type: ").append(getTypeName()).append("[").append(getSubtypeName()).
527 append("], state: ").append(mState).append("/").append(mDetailedState).
528 append(", reason: ").append(mReason == null ? "(unspecified)" : mReason).
529 append(", extra: ").append(mExtraInfo == null ? "(none)" : mExtraInfo).
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700530 append(", failover: ").append(mIsFailover).
Jeff Sharkeyf07c7b92016-04-22 09:50:16 -0600531 append(", available: ").append(mIsAvailable).
532 append(", roaming: ").append(mIsRoaming).
Robert Greenwaltc9c90c72014-05-13 15:36:27 -0700533 append("]");
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700534 return builder.toString();
535 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 }
537
Jeff Sharkeyf07c7b92016-04-22 09:50:16 -0600538 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800539 public int describeContents() {
540 return 0;
541 }
542
Jeff Sharkeyf07c7b92016-04-22 09:50:16 -0600543 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800544 public void writeToParcel(Parcel dest, int flags) {
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700545 synchronized (this) {
546 dest.writeInt(mNetworkType);
547 dest.writeInt(mSubtype);
548 dest.writeString(mTypeName);
549 dest.writeString(mSubtypeName);
550 dest.writeString(mState.name());
551 dest.writeString(mDetailedState.name());
552 dest.writeInt(mIsFailover ? 1 : 0);
553 dest.writeInt(mIsAvailable ? 1 : 0);
554 dest.writeInt(mIsRoaming ? 1 : 0);
555 dest.writeString(mReason);
556 dest.writeString(mExtraInfo);
557 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800558 }
559
Jeff Sharkeyf07c7b92016-04-22 09:50:16 -0600560 public static final Creator<NetworkInfo> CREATOR = new Creator<NetworkInfo>() {
561 @Override
562 public NetworkInfo createFromParcel(Parcel in) {
563 int netType = in.readInt();
564 int subtype = in.readInt();
565 String typeName = in.readString();
566 String subtypeName = in.readString();
567 NetworkInfo netInfo = new NetworkInfo(netType, subtype, typeName, subtypeName);
568 netInfo.mState = State.valueOf(in.readString());
569 netInfo.mDetailedState = DetailedState.valueOf(in.readString());
570 netInfo.mIsFailover = in.readInt() != 0;
571 netInfo.mIsAvailable = in.readInt() != 0;
572 netInfo.mIsRoaming = in.readInt() != 0;
Jeff Sharkeyf07c7b92016-04-22 09:50:16 -0600573 netInfo.mReason = in.readString();
574 netInfo.mExtraInfo = in.readString();
575 return netInfo;
576 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800577
Jeff Sharkeyf07c7b92016-04-22 09:50:16 -0600578 @Override
579 public NetworkInfo[] newArray(int size) {
580 return new NetworkInfo[size];
581 }
582 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583}