19066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/*
29066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Copyright (C) 2008 The Android Open Source Project
39066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
49066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
59066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * you may not use this file except in compliance with the License.
69066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * You may obtain a copy of the License at
79066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
89066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
99066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Unless required by applicable law or agreed to in writing, software
119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * See the License for the specific language governing permissions and
149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * limitations under the License.
159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpackage android.net;
189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.Parcelable;
209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.Parcel;
219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport java.util.EnumMap;
239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/**
25671644c3ef92a9153ea5bd495e132d5fe6674234Scott Main * Describes the status of a network interface.
26671644c3ef92a9153ea5bd495e132d5fe6674234Scott Main * <p>Use {@link ConnectivityManager#getActiveNetworkInfo()} to get an instance that represents
27671644c3ef92a9153ea5bd495e132d5fe6674234Scott Main * the current network connection.
289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpublic class NetworkInfo implements Parcelable {
309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Coarse-grained network state. This is probably what most applications should
339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * use, rather than {@link android.net.NetworkInfo.DetailedState DetailedState}.
349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * The mapping between the two is as follows:
359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * <br/><br/>
369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * <table>
379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * <tr><td><b>Detailed state</b></td><td><b>Coarse-grained state</b></td></tr>
389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * <tr><td><code>IDLE</code></td><td><code>DISCONNECTED</code></td></tr>
399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * <tr><td><code>SCANNING</code></td><td><code>CONNECTING</code></td></tr>
409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * <tr><td><code>CONNECTING</code></td><td><code>CONNECTING</code></td></tr>
419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * <tr><td><code>AUTHENTICATING</code></td><td><code>CONNECTING</code></td></tr>
42671644c3ef92a9153ea5bd495e132d5fe6674234Scott Main     * <tr><td><code>CONNECTED</code></td><td><code>CONNECTED</code></td></tr>
439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * <tr><td><code>DISCONNECTING</code></td><td><code>DISCONNECTING</code></td></tr>
449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * <tr><td><code>DISCONNECTED</code></td><td><code>DISCONNECTED</code></td></tr>
459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * <tr><td><code>UNAVAILABLE</code></td><td><code>DISCONNECTED</code></td></tr>
469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * <tr><td><code>FAILED</code></td><td><code>DISCONNECTED</code></td></tr>
479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * </table>
489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public enum State {
509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        CONNECTING, CONNECTED, SUSPENDED, DISCONNECTING, DISCONNECTED, UNKNOWN
519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * The fine-grained state of a network connection. This level of detail
559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * is probably of interest to few applications. Most should use
569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * {@link android.net.NetworkInfo.State State} instead.
579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public enum DetailedState {
599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /** Ready to start data connection setup. */
609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        IDLE,
619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /** Searching for an available access point. */
629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        SCANNING,
639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /** Currently setting up data connection. */
649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        CONNECTING,
659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /** Network link established, performing authentication. */
669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        AUTHENTICATING,
679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /** Awaiting response from DHCP server in order to assign IP address information. */
689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        OBTAINING_IPADDR,
699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /** IP traffic should be available. */
709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        CONNECTED,
719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /** IP traffic is suspended */
729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        SUSPENDED,
739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /** Currently tearing down data connection. */
749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        DISCONNECTING,
759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /** IP traffic not available. */
769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        DISCONNECTED,
779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /** Attempt to connect failed. */
78c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey        FAILED,
79c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey        /** Access to this network is blocked. */
8007573b32494acbabd21979d8b9584c1ed3f7a6adIrfan Sheriff        BLOCKED,
8107573b32494acbabd21979d8b9584c1ed3f7a6adIrfan Sheriff        /** Link has poor connectivity. */
82da6da0907b28d4704aabbdb1bbeb4300954670d1Irfan Sheriff        VERIFYING_POOR_LINK,
83da6da0907b28d4704aabbdb1bbeb4300954670d1Irfan Sheriff        /** Checking if network is a captive portal */
84da6da0907b28d4704aabbdb1bbeb4300954670d1Irfan Sheriff        CAPTIVE_PORTAL_CHECK,
859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * This is the map described in the Javadoc comment above. The positions
899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * of the elements of the array must correspond to the ordinal values
909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * of <code>DetailedState</code>.
919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private static final EnumMap<DetailedState, State> stateMap =
939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        new EnumMap<DetailedState, State>(DetailedState.class);
949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    static {
969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        stateMap.put(DetailedState.IDLE, State.DISCONNECTED);
979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        stateMap.put(DetailedState.SCANNING, State.DISCONNECTED);
989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        stateMap.put(DetailedState.CONNECTING, State.CONNECTING);
999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        stateMap.put(DetailedState.AUTHENTICATING, State.CONNECTING);
1009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        stateMap.put(DetailedState.OBTAINING_IPADDR, State.CONNECTING);
10107573b32494acbabd21979d8b9584c1ed3f7a6adIrfan Sheriff        stateMap.put(DetailedState.VERIFYING_POOR_LINK, State.CONNECTING);
102da6da0907b28d4704aabbdb1bbeb4300954670d1Irfan Sheriff        stateMap.put(DetailedState.CAPTIVE_PORTAL_CHECK, State.CONNECTING);
1039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        stateMap.put(DetailedState.CONNECTED, State.CONNECTED);
1049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        stateMap.put(DetailedState.SUSPENDED, State.SUSPENDED);
1059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        stateMap.put(DetailedState.DISCONNECTING, State.DISCONNECTING);
1069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        stateMap.put(DetailedState.DISCONNECTED, State.DISCONNECTED);
1079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        stateMap.put(DetailedState.FAILED, State.DISCONNECTED);
108c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey        stateMap.put(DetailedState.BLOCKED, State.DISCONNECTED);
1099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
110a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff
1119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private int mNetworkType;
1129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private int mSubtype;
1139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private String mTypeName;
1149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private String mSubtypeName;
1159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private State mState;
1169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private DetailedState mDetailedState;
1179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private String mReason;
1189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private String mExtraInfo;
1199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private boolean mIsFailover;
1209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private boolean mIsRoaming;
1219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Indicates whether network connectivity is possible:
1239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private boolean mIsAvailable;
1259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param type network type
1282ecc74f330959be0a3bde10e55110a8218c0887cEric Shienbrood     * @deprecated
1292ecc74f330959be0a3bde10e55110a8218c0887cEric Shienbrood     * @hide because this constructor was only meant for internal use (and
1302ecc74f330959be0a3bde10e55110a8218c0887cEric Shienbrood     * has now been superseded by the package-private constructor below).
1319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public NetworkInfo(int type) {}
1339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
134d649c12815bcf944b2c97371f3f60716a42a1557Irfan Sheriff    /**
135d649c12815bcf944b2c97371f3f60716a42a1557Irfan Sheriff     * @hide
136d649c12815bcf944b2c97371f3f60716a42a1557Irfan Sheriff     */
137d649c12815bcf944b2c97371f3f60716a42a1557Irfan Sheriff    public NetworkInfo(int type, int subtype, String typeName, String subtypeName) {
1389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (!ConnectivityManager.isNetworkTypeValid(type)) {
1399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            throw new IllegalArgumentException("Invalid network type: " + type);
1409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
1419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mNetworkType = type;
1429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mSubtype = subtype;
1439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mTypeName = typeName;
1449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mSubtypeName = subtypeName;
1459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        setDetailedState(DetailedState.IDLE, null, null);
1469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mState = State.UNKNOWN;
1478206ff30c23c76851bebc8d72a65e65b0f7f9a29Robert Greenwalt        mIsAvailable = false; // until we're told otherwise, assume unavailable
1489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mIsRoaming = false;
1499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
151c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey    /** {@hide} */
152c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey    public NetworkInfo(NetworkInfo source) {
153c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey        if (source != null) {
154c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey            mNetworkType = source.mNetworkType;
155c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey            mSubtype = source.mSubtype;
156c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey            mTypeName = source.mTypeName;
157c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey            mSubtypeName = source.mSubtypeName;
158c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey            mState = source.mState;
159c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey            mDetailedState = source.mDetailedState;
160c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey            mReason = source.mReason;
161c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey            mExtraInfo = source.mExtraInfo;
162c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey            mIsFailover = source.mIsFailover;
163c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey            mIsRoaming = source.mIsRoaming;
164c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey            mIsAvailable = source.mIsAvailable;
165c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey        }
166c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey    }
167c006f1aec15454782c35e028ad64d79a5c161cc1Jeff Sharkey
1689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
169671644c3ef92a9153ea5bd495e132d5fe6674234Scott Main     * Reports the type of network to which the
170671644c3ef92a9153ea5bd495e132d5fe6674234Scott Main     * info in this {@code NetworkInfo} pertains.
171671644c3ef92a9153ea5bd495e132d5fe6674234Scott Main     * @return one of {@link ConnectivityManager#TYPE_MOBILE}, {@link
172671644c3ef92a9153ea5bd495e132d5fe6674234Scott Main     * ConnectivityManager#TYPE_WIFI}, {@link ConnectivityManager#TYPE_WIMAX}, {@link
173671644c3ef92a9153ea5bd495e132d5fe6674234Scott Main     * ConnectivityManager#TYPE_ETHERNET},  {@link ConnectivityManager#TYPE_BLUETOOTH}, or other
174671644c3ef92a9153ea5bd495e132d5fe6674234Scott Main     * types defined by {@link ConnectivityManager}
1759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public int getType() {
177a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        synchronized (this) {
178a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            return mNetworkType;
179a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        }
1809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Return a network-type-specific integer describing the subtype
1849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * of the network.
1859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return the network subtype
1869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public int getSubtype() {
188a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        synchronized (this) {
189a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            return mSubtype;
190a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        }
1919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    void setSubtype(int subtype, String subtypeName) {
194a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        synchronized (this) {
195a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            mSubtype = subtype;
196a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            mSubtypeName = subtypeName;
197a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        }
1989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
2019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Return a human-readable name describe the type of the network,
2029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * for example "WIFI" or "MOBILE".
2039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return the name of the network type
2049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
2059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public String getTypeName() {
206a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        synchronized (this) {
207a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            return mTypeName;
208a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        }
2099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
2129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Return a human-readable name describing the subtype of the network.
2139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return the name of the network subtype
2149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
2159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public String getSubtypeName() {
216a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        synchronized (this) {
217a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            return mSubtypeName;
218a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        }
2199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
2229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Indicates whether network connectivity exists or is in the process
2239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * of being established. This is good for applications that need to
2249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * do anything related to the network other than read or write data.
2259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * For the latter, call {@link #isConnected()} instead, which guarantees
2269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * that the network is fully usable.
2279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return {@code true} if network connectivity exists or is in the process
2289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * of being established, {@code false} otherwise.
2299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
2309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public boolean isConnectedOrConnecting() {
231a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        synchronized (this) {
232a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            return mState == State.CONNECTED || mState == State.CONNECTING;
233a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        }
2349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
2379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Indicates whether network connectivity exists and it is possible to establish
2389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * connections and pass data.
239671644c3ef92a9153ea5bd495e132d5fe6674234Scott Main     * <p>Always call this before attempting to perform data transactions.
2409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return {@code true} if network connectivity exists, {@code false} otherwise.
2419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
2429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public boolean isConnected() {
243a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        synchronized (this) {
244a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            return mState == State.CONNECTED;
245a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        }
2469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
2499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Indicates whether network connectivity is possible. A network is unavailable
2509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * when a persistent or semi-persistent condition prevents the possibility
2519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * of connecting to that network. Examples include
2529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * <ul>
2539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * <li>The device is out of the coverage area for any network of this type.</li>
2549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * <li>The device is on a network other than the home network (i.e., roaming), and
2559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * data roaming has been disabled.</li>
2569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * <li>The device's radio is turned off, e.g., because airplane mode is enabled.</li>
2579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * </ul>
2589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return {@code true} if the network is available, {@code false} otherwise
2599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
2609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public boolean isAvailable() {
261a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        synchronized (this) {
262a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            return mIsAvailable;
263a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        }
2649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
2679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Sets if the network is available, ie, if the connectivity is possible.
2689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param isAvailable the new availability value.
2699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
2709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @hide
2719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
2729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public void setIsAvailable(boolean isAvailable) {
273a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        synchronized (this) {
274a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            mIsAvailable = isAvailable;
275a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        }
2769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
2799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Indicates whether the current attempt to connect to the network
2809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * resulted from the ConnectivityManager trying to fail over to this
2819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * network following a disconnect from another network.
2829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return {@code true} if this is a failover attempt, {@code false}
2839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * otherwise.
2849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
2859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public boolean isFailover() {
286a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        synchronized (this) {
287a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            return mIsFailover;
288a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        }
2899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
2929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Set the failover boolean.
2939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param isFailover {@code true} to mark the current connection attempt
2949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * as a failover.
2959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @hide
2969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
2979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public void setFailover(boolean isFailover) {
298a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        synchronized (this) {
299a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            mIsFailover = isFailover;
300a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        }
3019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
3049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Indicates whether the device is currently roaming on this network.
3059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * When {@code true}, it suggests that use of data on this network
3069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * may incur extra costs.
3079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return {@code true} if roaming is in effect, {@code false} otherwise.
3089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
3099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public boolean isRoaming() {
310a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        synchronized (this) {
311a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            return mIsRoaming;
312a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        }
3139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    void setRoaming(boolean isRoaming) {
316a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        synchronized (this) {
317a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            mIsRoaming = isRoaming;
318a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        }
3199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
3229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Reports the current coarse-grained state of the network.
3239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return the coarse-grained state
3249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
3259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public State getState() {
326a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        synchronized (this) {
327a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            return mState;
328a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        }
3299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
3329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Reports the current fine-grained state of the network.
3339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return the fine-grained state
3349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
3359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public DetailedState getDetailedState() {
336a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        synchronized (this) {
337a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            return mDetailedState;
338a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        }
3399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
3429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Sets the fine-grained state of the network.
3439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param detailedState the {@link DetailedState}.
3449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param reason a {@code String} indicating the reason for the state change,
3459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * if one was supplied. May be {@code null}.
3469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param extraInfo an optional {@code String} providing addditional network state
3479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * information passed up from the lower networking layers.
348d649c12815bcf944b2c97371f3f60716a42a1557Irfan Sheriff     * @hide
3499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
350d649c12815bcf944b2c97371f3f60716a42a1557Irfan Sheriff    public void setDetailedState(DetailedState detailedState, String reason, String extraInfo) {
351a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        synchronized (this) {
352a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            this.mDetailedState = detailedState;
353a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            this.mState = stateMap.get(detailedState);
354a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            this.mReason = reason;
355a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            this.mExtraInfo = extraInfo;
356a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        }
3579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
360d60ae7f6688ea83df536c2eb1101a74ae1914ac6Doug Zongker     * Set the extraInfo field.
361d60ae7f6688ea83df536c2eb1101a74ae1914ac6Doug Zongker     * @param extraInfo an optional {@code String} providing addditional network state
362d60ae7f6688ea83df536c2eb1101a74ae1914ac6Doug Zongker     * information passed up from the lower networking layers.
363d60ae7f6688ea83df536c2eb1101a74ae1914ac6Doug Zongker     * @hide
364d60ae7f6688ea83df536c2eb1101a74ae1914ac6Doug Zongker     */
365d60ae7f6688ea83df536c2eb1101a74ae1914ac6Doug Zongker    public void setExtraInfo(String extraInfo) {
366d60ae7f6688ea83df536c2eb1101a74ae1914ac6Doug Zongker        synchronized (this) {
367d60ae7f6688ea83df536c2eb1101a74ae1914ac6Doug Zongker            this.mExtraInfo = extraInfo;
368d60ae7f6688ea83df536c2eb1101a74ae1914ac6Doug Zongker        }
369d60ae7f6688ea83df536c2eb1101a74ae1914ac6Doug Zongker    }
370d60ae7f6688ea83df536c2eb1101a74ae1914ac6Doug Zongker
371d60ae7f6688ea83df536c2eb1101a74ae1914ac6Doug Zongker    /**
3729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Report the reason an attempt to establish connectivity failed,
3739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * if one is available.
3749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return the reason for failure, or null if not available
3759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
3769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public String getReason() {
377a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        synchronized (this) {
378a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            return mReason;
379a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        }
3809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
3839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Report the extra information about the network state, if any was
3849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * provided by the lower networking layers.,
3859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * if one is available.
3869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return the extra information, or null if not available
3879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
3889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public String getExtraInfo() {
389a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        synchronized (this) {
390a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            return mExtraInfo;
391a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        }
3929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    @Override
3959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public String toString() {
396a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        synchronized (this) {
397a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            StringBuilder builder = new StringBuilder("NetworkInfo: ");
398a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            builder.append("type: ").append(getTypeName()).append("[").append(getSubtypeName()).
399a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            append("], state: ").append(mState).append("/").append(mDetailedState).
400a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            append(", reason: ").append(mReason == null ? "(unspecified)" : mReason).
401a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            append(", extra: ").append(mExtraInfo == null ? "(none)" : mExtraInfo).
402a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            append(", roaming: ").append(mIsRoaming).
403a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            append(", failover: ").append(mIsFailover).
404a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            append(", isAvailable: ").append(mIsAvailable);
405a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            return builder.toString();
406a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        }
4079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
4089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
4109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Implement the Parcelable interface
4119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @hide
4129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
4139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public int describeContents() {
4149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return 0;
4159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
4169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
4189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Implement the Parcelable interface.
4199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @hide
4209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
4219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public void writeToParcel(Parcel dest, int flags) {
422a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        synchronized (this) {
423a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            dest.writeInt(mNetworkType);
424a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            dest.writeInt(mSubtype);
425a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            dest.writeString(mTypeName);
426a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            dest.writeString(mSubtypeName);
427a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            dest.writeString(mState.name());
428a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            dest.writeString(mDetailedState.name());
429a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            dest.writeInt(mIsFailover ? 1 : 0);
430a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            dest.writeInt(mIsAvailable ? 1 : 0);
431a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            dest.writeInt(mIsRoaming ? 1 : 0);
432a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            dest.writeString(mReason);
433a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff            dest.writeString(mExtraInfo);
434a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff        }
4359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
4369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
4389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Implement the Parcelable interface.
4399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @hide
4409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
4419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final Creator<NetworkInfo> CREATOR =
4429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        new Creator<NetworkInfo>() {
4439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            public NetworkInfo createFromParcel(Parcel in) {
4449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                int netType = in.readInt();
4459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                int subtype = in.readInt();
4469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                String typeName = in.readString();
4479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                String subtypeName = in.readString();
4489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                NetworkInfo netInfo = new NetworkInfo(netType, subtype, typeName, subtypeName);
4499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                netInfo.mState = State.valueOf(in.readString());
4509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                netInfo.mDetailedState = DetailedState.valueOf(in.readString());
4519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                netInfo.mIsFailover = in.readInt() != 0;
4529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                netInfo.mIsAvailable = in.readInt() != 0;
4539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                netInfo.mIsRoaming = in.readInt() != 0;
4549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                netInfo.mReason = in.readString();
4559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                netInfo.mExtraInfo = in.readString();
4569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return netInfo;
4579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
4589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            public NetworkInfo[] newArray(int size) {
4609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return new NetworkInfo[size];
4619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
4629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        };
4639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
464