OSDN Git Service

am cba75f31: am 47e743b9: am 4544b927: Hold a wake lock while dozing when wallpaper...
[android-x86/frameworks-base.git] / telephony / java / android / telephony / PreciseDataConnectionState.java
1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package android.telephony;
18
19 import android.os.Parcel;
20 import android.os.Parcelable;
21 import android.telephony.TelephonyManager;
22 import android.net.LinkProperties;
23
24 /**
25  * Contains precise data connection state.
26  *
27  * The following data connection information is included in returned PreciseDataConnectionState:
28  *
29  * <ul>
30  *   <li>Data connection state.
31  *   <li>Network type of the connection.
32  *   <li>APN type.
33  *   <li>APN.
34  *   <li>Data connection change reason.
35  *   <li>The properties of the network link.
36  *   <li>Data connection fail cause.
37  * </ul>
38  *
39  * @hide
40  */
41 public class PreciseDataConnectionState implements Parcelable {
42
43     private int mState = TelephonyManager.DATA_UNKNOWN;
44     private int mNetworkType = TelephonyManager.NETWORK_TYPE_UNKNOWN;
45     private String mAPNType = "";
46     private String mAPN = "";
47     private String mReason = "";
48     private LinkProperties mLinkProperties = null;
49     private String mFailCause = "";
50
51     /**
52      * Constructor
53      *
54      * @hide
55      */
56     public PreciseDataConnectionState(int state, int networkType,
57             String apnType, String apn, String reason,
58             LinkProperties linkProperties, String failCause) {
59         mState = state;
60         mNetworkType = networkType;
61         mAPNType = apnType;
62         mAPN = apn;
63         mReason = reason;
64         mLinkProperties = linkProperties;
65         mFailCause = failCause;
66     }
67
68     /**
69      * Empty Constructor
70      *
71      * @hide
72      */
73     public PreciseDataConnectionState() {
74     }
75
76     /**
77      * Construct a PreciseDataConnectionState object from the given parcel.
78      */
79     private PreciseDataConnectionState(Parcel in) {
80         mState = in.readInt();
81         mNetworkType = in.readInt();
82         mAPNType = in.readString();
83         mAPN = in.readString();
84         mReason = in.readString();
85         mLinkProperties = (LinkProperties)in.readParcelable(null);
86         mFailCause = in.readString();
87     }
88
89     /**
90      * Get data connection state
91      *
92      * @see TelephonyManager#DATA_UNKNOWN
93      * @see TelephonyManager#DATA_DISCONNECTED
94      * @see TelephonyManager#DATA_CONNECTING
95      * @see TelephonyManager#DATA_CONNECTED
96      * @see TelephonyManager#DATA_SUSPENDED
97      */
98     public int getDataConnectionState() {
99         return mState;
100     }
101
102     /**
103      * Get data connection network type
104      *
105      * @see TelephonyManager#NETWORK_TYPE_UNKNOWN
106      * @see TelephonyManager#NETWORK_TYPE_GPRS
107      * @see TelephonyManager#NETWORK_TYPE_EDGE
108      * @see TelephonyManager#NETWORK_TYPE_UMTS
109      * @see TelephonyManager#NETWORK_TYPE_CDMA
110      * @see TelephonyManager#NETWORK_TYPE_EVDO_0
111      * @see TelephonyManager#NETWORK_TYPE_EVDO_A
112      * @see TelephonyManager#NETWORK_TYPE_1xRTT
113      * @see TelephonyManager#NETWORK_TYPE_HSDPA
114      * @see TelephonyManager#NETWORK_TYPE_HSUPA
115      * @see TelephonyManager#NETWORK_TYPE_HSPA
116      * @see TelephonyManager#NETWORK_TYPE_IDEN
117      * @see TelephonyManager#NETWORK_TYPE_EVDO_B
118      * @see TelephonyManager#NETWORK_TYPE_LTE
119      * @see TelephonyManager#NETWORK_TYPE_EHRPD
120      * @see TelephonyManager#NETWORK_TYPE_HSPAP
121      */
122     public int getDataConnectionNetworkType() {
123         return mNetworkType;
124     }
125
126     /**
127      * Get data connection APN type
128      */
129     public String getDataConnectionAPNType() {
130         return mAPNType;
131     }
132
133     /**
134      * Get data connection APN.
135      */
136     public String getDataConnectionAPN() {
137         return mAPN;
138     }
139
140     /**
141      * Get data connection change reason.
142      */
143     public String getDataConnectionChangeReason() {
144         return mReason;
145     }
146
147     /**
148      * Get the properties of the network link.
149      */
150     public LinkProperties getDataConnectionLinkProperties() {
151         return mLinkProperties;
152     }
153
154     /**
155      * Get data connection fail cause, in case there was a failure.
156      */
157     public String getDataConnectionFailCause() {
158         return mFailCause;
159     }
160
161     @Override
162     public int describeContents() {
163         return 0;
164     }
165
166     @Override
167     public void writeToParcel(Parcel out, int flags) {
168         out.writeInt(mState);
169         out.writeInt(mNetworkType);
170         out.writeString(mAPNType);
171         out.writeString(mAPN);
172         out.writeString(mReason);
173         out.writeParcelable(mLinkProperties, flags);
174         out.writeString(mFailCause);
175     }
176
177     public static final Parcelable.Creator<PreciseDataConnectionState> CREATOR
178             = new Parcelable.Creator<PreciseDataConnectionState>() {
179
180         public PreciseDataConnectionState createFromParcel(Parcel in) {
181             return new PreciseDataConnectionState(in);
182         }
183
184         public PreciseDataConnectionState[] newArray(int size) {
185             return new PreciseDataConnectionState[size];
186         }
187     };
188
189     @Override
190     public int hashCode() {
191         final int prime = 31;
192         int result = 1;
193         result = prime * result + mState;
194         result = prime * result + mNetworkType;
195         result = prime * result + ((mAPNType == null) ? 0 : mAPNType.hashCode());
196         result = prime * result + ((mAPN == null) ? 0 : mAPN.hashCode());
197         result = prime * result + ((mReason == null) ? 0 : mReason.hashCode());
198         result = prime * result + ((mLinkProperties == null) ? 0 : mLinkProperties.hashCode());
199         result = prime * result + ((mFailCause == null) ? 0 : mFailCause.hashCode());
200         return result;
201     }
202
203     @Override
204     public boolean equals(Object obj) {
205         if (this == obj) {
206             return true;
207         }
208         if (obj == null) {
209             return false;
210         }
211         if (getClass() != obj.getClass()) {
212             return false;
213         }
214         PreciseDataConnectionState other = (PreciseDataConnectionState) obj;
215         if (mAPN == null) {
216             if (other.mAPN != null) {
217                 return false;
218             }
219         } else if (!mAPN.equals(other.mAPN)) {
220             return false;
221         }
222         if (mAPNType == null) {
223             if (other.mAPNType != null) {
224                 return false;
225             }
226         } else if (!mAPNType.equals(other.mAPNType)) {
227             return false;
228         }
229         if (mFailCause == null) {
230             if (other.mFailCause != null) {
231                 return false;
232             }
233         } else if (!mFailCause.equals(other.mFailCause)) {
234             return false;
235         }
236         if (mLinkProperties == null) {
237             if (other.mLinkProperties != null) {
238                 return false;
239             }
240         } else if (!mLinkProperties.equals(other.mLinkProperties)) {
241             return false;
242         }
243         if (mNetworkType != other.mNetworkType) {
244             return false;
245         }
246         if (mReason == null) {
247             if (other.mReason != null) {
248                 return false;
249             }
250         } else if (!mReason.equals(other.mReason)) {
251             return false;
252         }
253         if (mState != other.mState) {
254             return false;
255         }
256         return true;
257     }
258
259     @Override
260     public String toString() {
261         StringBuilder sb = new StringBuilder();
262
263         sb.append("Data Connection state: " + mState);
264         sb.append(", Network type: " + mNetworkType);
265         sb.append(", APN type: " + mAPNType);
266         sb.append(", APN: " + mAPN);
267         sb.append(", Change reason: " + mReason);
268         sb.append(", Link properties: " + mLinkProperties);
269         sb.append(", Fail cause: " + mFailCause);
270
271         return sb.toString();
272     }
273 }