2 * Copyright (C) 2014 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android.telephony;
19 import android.os.Parcel;
20 import android.os.Parcelable;
21 import android.telephony.TelephonyManager;
22 import android.net.LinkProperties;
25 * Contains precise data connection state.
27 * The following data connection information is included in returned PreciseDataConnectionState:
30 * <li>Data connection state.
31 * <li>Network type of the connection.
34 * <li>Data connection change reason.
35 * <li>The properties of the network link.
36 * <li>Data connection fail cause.
41 public class PreciseDataConnectionState implements Parcelable {
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 = "";
56 public PreciseDataConnectionState(int state, int networkType,
57 String apnType, String apn, String reason,
58 LinkProperties linkProperties, String failCause) {
60 mNetworkType = networkType;
64 mLinkProperties = linkProperties;
65 mFailCause = failCause;
73 public PreciseDataConnectionState() {
77 * Construct a PreciseDataConnectionState object from the given parcel.
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();
90 * Get data connection state
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
98 public int getDataConnectionState() {
103 * Get data connection network type
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
122 public int getDataConnectionNetworkType() {
127 * Get data connection APN type
129 public String getDataConnectionAPNType() {
134 * Get data connection APN.
136 public String getDataConnectionAPN() {
141 * Get data connection change reason.
143 public String getDataConnectionChangeReason() {
148 * Get the properties of the network link.
150 public LinkProperties getDataConnectionLinkProperties() {
151 return mLinkProperties;
155 * Get data connection fail cause, in case there was a failure.
157 public String getDataConnectionFailCause() {
162 public int describeContents() {
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);
177 public static final Parcelable.Creator<PreciseDataConnectionState> CREATOR
178 = new Parcelable.Creator<PreciseDataConnectionState>() {
180 public PreciseDataConnectionState createFromParcel(Parcel in) {
181 return new PreciseDataConnectionState(in);
184 public PreciseDataConnectionState[] newArray(int size) {
185 return new PreciseDataConnectionState[size];
190 public int hashCode() {
191 final int prime = 31;
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());
204 public boolean equals(Object obj) {
211 if (getClass() != obj.getClass()) {
214 PreciseDataConnectionState other = (PreciseDataConnectionState) obj;
216 if (other.mAPN != null) {
219 } else if (!mAPN.equals(other.mAPN)) {
222 if (mAPNType == null) {
223 if (other.mAPNType != null) {
226 } else if (!mAPNType.equals(other.mAPNType)) {
229 if (mFailCause == null) {
230 if (other.mFailCause != null) {
233 } else if (!mFailCause.equals(other.mFailCause)) {
236 if (mLinkProperties == null) {
237 if (other.mLinkProperties != null) {
240 } else if (!mLinkProperties.equals(other.mLinkProperties)) {
243 if (mNetworkType != other.mNetworkType) {
246 if (mReason == null) {
247 if (other.mReason != null) {
250 } else if (!mReason.equals(other.mReason)) {
253 if (mState != other.mState) {
260 public String toString() {
261 StringBuilder sb = new StringBuilder();
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);
271 return sb.toString();