Home | History | Annotate | Download | only in telephony
      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.Bundle;
     20 import android.os.Parcel;
     21 import android.os.Parcelable;
     22 import android.telephony.Rlog;
     23 import android.telephony.TelephonyManager;
     24 import android.net.LinkProperties;
     25 
     26 /**
     27  * Contains precise data connection state.
     28  *
     29  * The following data connection information is included in returned PreciseDataConnectionState:
     30  *
     31  * <ul>
     32  *   <li>Data connection state.
     33  *   <li>Network type of the connection.
     34  *   <li>APN type.
     35  *   <li>APN.
     36  *   <li>Data connection change reason.
     37  *   <li>The properties of the network link.
     38  *   <li>Data connection fail cause.
     39  * </ul>
     40  *
     41  * @hide
     42  */
     43 public class PreciseDataConnectionState implements Parcelable {
     44 
     45     private int mState = TelephonyManager.DATA_UNKNOWN;
     46     private int mNetworkType = TelephonyManager.NETWORK_TYPE_UNKNOWN;
     47     private String mAPNType = "";
     48     private String mAPN = "";
     49     private String mReason = "";
     50     private LinkProperties mLinkProperties = null;
     51     private String mFailCause = "";
     52 
     53     /**
     54      * Constructor
     55      *
     56      * @hide
     57      */
     58     public PreciseDataConnectionState(int state, int networkType,
     59             String apnType, String apn, String reason,
     60             LinkProperties linkProperties, String failCause) {
     61         mState = state;
     62         mNetworkType = networkType;
     63         mAPNType = apnType;
     64         mAPN = apn;
     65         mReason = reason;
     66         mLinkProperties = linkProperties;
     67         mFailCause = failCause;
     68     }
     69 
     70     /**
     71      * Empty Constructor
     72      *
     73      * @hide
     74      */
     75     public PreciseDataConnectionState() {
     76     }
     77 
     78     /**
     79      * Construct a PreciseDataConnectionState object from the given parcel.
     80      */
     81     private PreciseDataConnectionState(Parcel in) {
     82         mState = in.readInt();
     83         mNetworkType = in.readInt();
     84         mAPNType = in.readString();
     85         mAPN = in.readString();
     86         mReason = in.readString();
     87         mLinkProperties = (LinkProperties)in.readParcelable(null);
     88         mFailCause = in.readString();
     89     }
     90 
     91     /**
     92      * Get data connection state
     93      *
     94      * @see TelephonyManager#DATA_UNKNOWN
     95      * @see TelephonyManager#DATA_DISCONNECTED
     96      * @see TelephonyManager#DATA_CONNECTING
     97      * @see TelephonyManager#DATA_CONNECTED
     98      * @see TelephonyManager#DATA_SUSPENDED
     99      */
    100     public int getDataConnectionState() {
    101         return mState;
    102     }
    103 
    104     /**
    105      * Get data connection network type
    106      *
    107      * @see TelephonyManager#NETWORK_TYPE_UNKNOWN
    108      * @see TelephonyManager#NETWORK_TYPE_GPRS
    109      * @see TelephonyManager#NETWORK_TYPE_EDGE
    110      * @see TelephonyManager#NETWORK_TYPE_UMTS
    111      * @see TelephonyManager#NETWORK_TYPE_CDMA
    112      * @see TelephonyManager#NETWORK_TYPE_EVDO_0
    113      * @see TelephonyManager#NETWORK_TYPE_EVDO_A
    114      * @see TelephonyManager#NETWORK_TYPE_1xRTT
    115      * @see TelephonyManager#NETWORK_TYPE_HSDPA
    116      * @see TelephonyManager#NETWORK_TYPE_HSUPA
    117      * @see TelephonyManager#NETWORK_TYPE_HSPA
    118      * @see TelephonyManager#NETWORK_TYPE_IDEN
    119      * @see TelephonyManager#NETWORK_TYPE_EVDO_B
    120      * @see TelephonyManager#NETWORK_TYPE_LTE
    121      * @see TelephonyManager#NETWORK_TYPE_EHRPD
    122      * @see TelephonyManager#NETWORK_TYPE_HSPAP
    123      */
    124     public int getDataConnectionNetworkType() {
    125         return mNetworkType;
    126     }
    127 
    128     /**
    129      * Get data connection APN type
    130      */
    131     public String getDataConnectionAPNType() {
    132         return mAPNType;
    133     }
    134 
    135     /**
    136      * Get data connection APN.
    137      */
    138     public String getDataConnectionAPN() {
    139         return mAPN;
    140     }
    141 
    142     /**
    143      * Get data connection change reason.
    144      */
    145     public String getDataConnectionChangeReason() {
    146         return mReason;
    147     }
    148 
    149     /**
    150      * Get the properties of the network link.
    151      */
    152     public LinkProperties getDataConnectionLinkProperties() {
    153         return mLinkProperties;
    154     }
    155 
    156     /**
    157      * Get data connection fail cause, in case there was a failure.
    158      */
    159     public String getDataConnectionFailCause() {
    160         return mFailCause;
    161     }
    162 
    163     @Override
    164     public int describeContents() {
    165         return 0;
    166     }
    167 
    168     @Override
    169     public void writeToParcel(Parcel out, int flags) {
    170         out.writeInt(mState);
    171         out.writeInt(mNetworkType);
    172         out.writeString(mAPNType);
    173         out.writeString(mAPN);
    174         out.writeString(mReason);
    175         out.writeParcelable(mLinkProperties, flags);
    176         out.writeString(mFailCause);
    177     }
    178 
    179     public static final Parcelable.Creator<PreciseDataConnectionState> CREATOR
    180             = new Parcelable.Creator<PreciseDataConnectionState>() {
    181 
    182         public PreciseDataConnectionState createFromParcel(Parcel in) {
    183             return new PreciseDataConnectionState(in);
    184         }
    185 
    186         public PreciseDataConnectionState[] newArray(int size) {
    187             return new PreciseDataConnectionState[size];
    188         }
    189     };
    190 
    191     @Override
    192     public int hashCode() {
    193         final int prime = 31;
    194         int result = 1;
    195         result = prime * result + mState;
    196         result = prime * result + mNetworkType;
    197         result = prime * result + ((mAPNType == null) ? 0 : mAPNType.hashCode());
    198         result = prime * result + ((mAPN == null) ? 0 : mAPN.hashCode());
    199         result = prime * result + ((mReason == null) ? 0 : mReason.hashCode());
    200         result = prime * result + ((mLinkProperties == null) ? 0 : mLinkProperties.hashCode());
    201         result = prime * result + ((mFailCause == null) ? 0 : mFailCause.hashCode());
    202         return result;
    203     }
    204 
    205     @Override
    206     public boolean equals(Object obj) {
    207         if (this == obj) {
    208             return true;
    209         }
    210         if (obj == null) {
    211             return false;
    212         }
    213         if (getClass() != obj.getClass()) {
    214             return false;
    215         }
    216         PreciseDataConnectionState other = (PreciseDataConnectionState) obj;
    217         if (mAPN == null) {
    218             if (other.mAPN != null) {
    219                 return false;
    220             }
    221         } else if (!mAPN.equals(other.mAPN)) {
    222             return false;
    223         }
    224         if (mAPNType == null) {
    225             if (other.mAPNType != null) {
    226                 return false;
    227             }
    228         } else if (!mAPNType.equals(other.mAPNType)) {
    229             return false;
    230         }
    231         if (mFailCause == null) {
    232             if (other.mFailCause != null) {
    233                 return false;
    234             }
    235         } else if (!mFailCause.equals(other.mFailCause)) {
    236             return false;
    237         }
    238         if (mLinkProperties == null) {
    239             if (other.mLinkProperties != null) {
    240                 return false;
    241             }
    242         } else if (!mLinkProperties.equals(other.mLinkProperties)) {
    243             return false;
    244         }
    245         if (mNetworkType != other.mNetworkType) {
    246             return false;
    247         }
    248         if (mReason == null) {
    249             if (other.mReason != null) {
    250                 return false;
    251             }
    252         } else if (!mReason.equals(other.mReason)) {
    253             return false;
    254         }
    255         if (mState != other.mState) {
    256             return false;
    257         }
    258         return true;
    259     }
    260 
    261     @Override
    262     public String toString() {
    263         StringBuilder sb = new StringBuilder();
    264 
    265         sb.append("Data Connection state: " + mState);
    266         sb.append(", Network type: " + mNetworkType);
    267         sb.append(", APN type: " + mAPNType);
    268         sb.append(", APN: " + mAPN);
    269         sb.append(", Change reason: " + mReason);
    270         sb.append(", Link properties: " + mLinkProperties);
    271         sb.append(", Fail cause: " + mFailCause);
    272 
    273         return sb.toString();
    274     }
    275 }
    276