NetworkState.java revision 21b5ee3f0e39be4a79bcfb2b79b0529f75f5cb58
1/*
2 * Copyright (C) 2011 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;
21
22/**
23 * Snapshot of network state.
24 *
25 * @hide
26 */
27public class NetworkState implements Parcelable {
28
29    public final NetworkInfo networkInfo;
30    public final LinkProperties linkProperties;
31    public final NetworkCapabilities networkCapabilities;
32    public final Network network;
33    /** Currently only used by testing. */
34    public final String subscriberId;
35    public final String networkId;
36
37    public NetworkState(NetworkInfo networkInfo, LinkProperties linkProperties,
38            NetworkCapabilities networkCapabilities, Network network) {
39        this(networkInfo, linkProperties, networkCapabilities, network, null, null);
40    }
41
42    public NetworkState(NetworkInfo networkInfo, LinkProperties linkProperties,
43            NetworkCapabilities networkCapabilities, Network network, String subscriberId,
44            String networkId) {
45        this.networkInfo = networkInfo;
46        this.linkProperties = linkProperties;
47        this.networkCapabilities = networkCapabilities;
48        this.network = network;
49        this.subscriberId = subscriberId;
50        this.networkId = networkId;
51    }
52
53    public NetworkState(Parcel in) {
54        networkInfo = in.readParcelable(null);
55        linkProperties = in.readParcelable(null);
56        networkCapabilities = in.readParcelable(null);
57        network = in.readParcelable(null);
58        subscriberId = in.readString();
59        networkId = in.readString();
60    }
61
62    @Override
63    public int describeContents() {
64        return 0;
65    }
66
67    @Override
68    public void writeToParcel(Parcel out, int flags) {
69        out.writeParcelable(networkInfo, flags);
70        out.writeParcelable(linkProperties, flags);
71        out.writeParcelable(networkCapabilities, flags);
72        out.writeParcelable(network, flags);
73        out.writeString(subscriberId);
74        out.writeString(networkId);
75    }
76
77    public static final Creator<NetworkState> CREATOR = new Creator<NetworkState>() {
78        @Override
79        public NetworkState createFromParcel(Parcel in) {
80            return new NetworkState(in);
81        }
82
83        @Override
84        public NetworkState[] newArray(int size) {
85            return new NetworkState[size];
86        }
87    };
88
89}
90