Home | History | Annotate | Download | only in telephony
      1 /*
      2  * Copyright (C) 2006 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 
     24 /**
     25  * Contains phone state and service related information.
     26  *
     27  * The following phone information is included in returned ServiceState:
     28  *
     29  * <ul>
     30  *   <li>Service state: IN_SERVICE, OUT_OF_SERVICE, EMERGENCY_ONLY, POWER_OFF
     31  *   <li>Roaming indicator
     32  *   <li>Operator name, short name and numeric id
     33  *   <li>Network selection mode
     34  * </ul>
     35  */
     36 public class ServiceState implements Parcelable {
     37 
     38     static final String LOG_TAG = "PHONE";
     39     static final boolean DBG = true;
     40 
     41     /**
     42      * Normal operation condition, the phone is registered
     43      * with an operator either in home network or in roaming.
     44      */
     45     public static final int STATE_IN_SERVICE = 0;
     46 
     47     /**
     48      * Phone is not registered with any operator, the phone
     49      * can be currently searching a new operator to register to, or not
     50      * searching to registration at all, or registration is denied, or radio
     51      * signal is not available.
     52      */
     53     public static final int STATE_OUT_OF_SERVICE = 1;
     54 
     55     /**
     56      * The phone is registered and locked.  Only emergency numbers are allowed. {@more}
     57      */
     58     public static final int STATE_EMERGENCY_ONLY = 2;
     59 
     60     /**
     61      * Radio of telephony is explicitly powered off.
     62      */
     63     public static final int STATE_POWER_OFF = 3;
     64 
     65     /**
     66      * RIL level registration state values from ril.h
     67      * ((const char **)response)[0] is registration state 0-6,
     68      *              0 - Not registered, MT is not currently searching
     69      *                  a new operator to register
     70      *              1 - Registered, home network
     71      *              2 - Not registered, but MT is currently searching
     72      *                  a new operator to register
     73      *              3 - Registration denied
     74      *              4 - Unknown
     75      *              5 - Registered, roaming
     76      *             10 - Same as 0, but indicates that emergency calls
     77      *                  are enabled.
     78      *             12 - Same as 2, but indicates that emergency calls
     79      *                  are enabled.
     80      *             13 - Same as 3, but indicates that emergency calls
     81      *                  are enabled.
     82      *             14 - Same as 4, but indicates that emergency calls
     83      *                  are enabled.
     84      * @hide
     85      */
     86     public static final int RIL_REG_STATE_NOT_REG = 0;
     87     /** @hide */
     88     public static final int RIL_REG_STATE_HOME = 1;
     89     /** @hide */
     90     public static final int RIL_REG_STATE_SEARCHING = 2;
     91     /** @hide */
     92     public static final int RIL_REG_STATE_DENIED = 3;
     93     /** @hide */
     94     public static final int RIL_REG_STATE_UNKNOWN = 4;
     95     /** @hide */
     96     public static final int RIL_REG_STATE_ROAMING = 5;
     97     /** @hide */
     98     public static final int RIL_REG_STATE_NOT_REG_EMERGENCY_CALL_ENABLED = 10;
     99     /** @hide */
    100     public static final int RIL_REG_STATE_SEARCHING_EMERGENCY_CALL_ENABLED = 12;
    101     /** @hide */
    102     public static final int RIL_REG_STATE_DENIED_EMERGENCY_CALL_ENABLED = 13;
    103     /** @hide */
    104     public static final int RIL_REG_STATE_UNKNOWN_EMERGENCY_CALL_ENABLED = 14;
    105 
    106     /**
    107      * Available radio technologies for GSM, UMTS and CDMA.
    108      * Duplicates the constants from hardware/radio/include/ril.h
    109      * This should only be used by agents working with the ril.  Others
    110      * should use the equivalent TelephonyManager.NETWORK_TYPE_*
    111      */
    112     /** @hide */
    113     public static final int RIL_RADIO_TECHNOLOGY_UNKNOWN = 0;
    114     /** @hide */
    115     public static final int RIL_RADIO_TECHNOLOGY_GPRS = 1;
    116     /** @hide */
    117     public static final int RIL_RADIO_TECHNOLOGY_EDGE = 2;
    118     /** @hide */
    119     public static final int RIL_RADIO_TECHNOLOGY_UMTS = 3;
    120     /** @hide */
    121     public static final int RIL_RADIO_TECHNOLOGY_IS95A = 4;
    122     /** @hide */
    123     public static final int RIL_RADIO_TECHNOLOGY_IS95B = 5;
    124     /** @hide */
    125     public static final int RIL_RADIO_TECHNOLOGY_1xRTT = 6;
    126     /** @hide */
    127     public static final int RIL_RADIO_TECHNOLOGY_EVDO_0 = 7;
    128     /** @hide */
    129     public static final int RIL_RADIO_TECHNOLOGY_EVDO_A = 8;
    130     /** @hide */
    131     public static final int RIL_RADIO_TECHNOLOGY_HSDPA = 9;
    132     /** @hide */
    133     public static final int RIL_RADIO_TECHNOLOGY_HSUPA = 10;
    134     /** @hide */
    135     public static final int RIL_RADIO_TECHNOLOGY_HSPA = 11;
    136     /** @hide */
    137     public static final int RIL_RADIO_TECHNOLOGY_EVDO_B = 12;
    138     /** @hide */
    139     public static final int RIL_RADIO_TECHNOLOGY_EHRPD = 13;
    140     /** @hide */
    141     public static final int RIL_RADIO_TECHNOLOGY_LTE = 14;
    142     /** @hide */
    143     public static final int RIL_RADIO_TECHNOLOGY_HSPAP = 15;
    144     /**
    145      * GSM radio technology only supports voice. It does not support data.
    146      * @hide
    147      */
    148     public static final int RIL_RADIO_TECHNOLOGY_GSM = 16;
    149     /** @hide */
    150     public static final int RIL_RADIO_TECHNOLOGY_TD_SCDMA = 17;
    151 
    152     /**
    153      * Available registration states for GSM, UMTS and CDMA.
    154      */
    155     /** @hide */
    156     public static final int REGISTRATION_STATE_NOT_REGISTERED_AND_NOT_SEARCHING = 0;
    157     /** @hide */
    158     public static final int REGISTRATION_STATE_HOME_NETWORK = 1;
    159     /** @hide */
    160     public static final int REGISTRATION_STATE_NOT_REGISTERED_AND_SEARCHING = 2;
    161     /** @hide */
    162     public static final int REGISTRATION_STATE_REGISTRATION_DENIED = 3;
    163     /** @hide */
    164     public static final int REGISTRATION_STATE_UNKNOWN = 4;
    165     /** @hide */
    166     public static final int REGISTRATION_STATE_ROAMING = 5;
    167 
    168     private int mVoiceRegState = STATE_OUT_OF_SERVICE;
    169     private int mDataRegState = STATE_OUT_OF_SERVICE;
    170     private boolean mRoaming;
    171     private String mOperatorAlphaLong;
    172     private String mOperatorAlphaShort;
    173     private String mOperatorNumeric;
    174     private boolean mIsManualNetworkSelection;
    175 
    176     private boolean mIsEmergencyOnly;
    177 
    178     private int mRilVoiceRadioTechnology;
    179     private int mRilDataRadioTechnology;
    180 
    181     private boolean mCssIndicator;
    182     private int mNetworkId;
    183     private int mSystemId;
    184     private int mCdmaRoamingIndicator;
    185     private int mCdmaDefaultRoamingIndicator;
    186     private int mCdmaEriIconIndex;
    187     private int mCdmaEriIconMode;
    188 
    189     /**
    190      * Create a new ServiceState from a intent notifier Bundle
    191      *
    192      * This method is used by PhoneStateIntentReceiver and maybe by
    193      * external applications.
    194      *
    195      * @param m Bundle from intent notifier
    196      * @return newly created ServiceState
    197      * @hide
    198      */
    199     public static ServiceState newFromBundle(Bundle m) {
    200         ServiceState ret;
    201         ret = new ServiceState();
    202         ret.setFromNotifierBundle(m);
    203         return ret;
    204     }
    205 
    206     /**
    207      * Empty constructor
    208      */
    209     public ServiceState() {
    210     }
    211 
    212     /**
    213      * Copy constructors
    214      *
    215      * @param s Source service state
    216      */
    217     public ServiceState(ServiceState s) {
    218         copyFrom(s);
    219     }
    220 
    221     protected void copyFrom(ServiceState s) {
    222         mVoiceRegState = s.mVoiceRegState;
    223         mDataRegState = s.mDataRegState;
    224         mRoaming = s.mRoaming;
    225         mOperatorAlphaLong = s.mOperatorAlphaLong;
    226         mOperatorAlphaShort = s.mOperatorAlphaShort;
    227         mOperatorNumeric = s.mOperatorNumeric;
    228         mIsManualNetworkSelection = s.mIsManualNetworkSelection;
    229         mRilVoiceRadioTechnology = s.mRilVoiceRadioTechnology;
    230         mRilDataRadioTechnology = s.mRilDataRadioTechnology;
    231         mCssIndicator = s.mCssIndicator;
    232         mNetworkId = s.mNetworkId;
    233         mSystemId = s.mSystemId;
    234         mCdmaRoamingIndicator = s.mCdmaRoamingIndicator;
    235         mCdmaDefaultRoamingIndicator = s.mCdmaDefaultRoamingIndicator;
    236         mCdmaEriIconIndex = s.mCdmaEriIconIndex;
    237         mCdmaEriIconMode = s.mCdmaEriIconMode;
    238         mIsEmergencyOnly = s.mIsEmergencyOnly;
    239     }
    240 
    241     /**
    242      * Construct a ServiceState object from the given parcel.
    243      */
    244     public ServiceState(Parcel in) {
    245         mVoiceRegState = in.readInt();
    246         mDataRegState = in.readInt();
    247         mRoaming = in.readInt() != 0;
    248         mOperatorAlphaLong = in.readString();
    249         mOperatorAlphaShort = in.readString();
    250         mOperatorNumeric = in.readString();
    251         mIsManualNetworkSelection = in.readInt() != 0;
    252         mRilVoiceRadioTechnology = in.readInt();
    253         mRilDataRadioTechnology = in.readInt();
    254         mCssIndicator = (in.readInt() != 0);
    255         mNetworkId = in.readInt();
    256         mSystemId = in.readInt();
    257         mCdmaRoamingIndicator = in.readInt();
    258         mCdmaDefaultRoamingIndicator = in.readInt();
    259         mCdmaEriIconIndex = in.readInt();
    260         mCdmaEriIconMode = in.readInt();
    261         mIsEmergencyOnly = in.readInt() != 0;
    262     }
    263 
    264     public void writeToParcel(Parcel out, int flags) {
    265         out.writeInt(mVoiceRegState);
    266         out.writeInt(mDataRegState);
    267         out.writeInt(mRoaming ? 1 : 0);
    268         out.writeString(mOperatorAlphaLong);
    269         out.writeString(mOperatorAlphaShort);
    270         out.writeString(mOperatorNumeric);
    271         out.writeInt(mIsManualNetworkSelection ? 1 : 0);
    272         out.writeInt(mRilVoiceRadioTechnology);
    273         out.writeInt(mRilDataRadioTechnology);
    274         out.writeInt(mCssIndicator ? 1 : 0);
    275         out.writeInt(mNetworkId);
    276         out.writeInt(mSystemId);
    277         out.writeInt(mCdmaRoamingIndicator);
    278         out.writeInt(mCdmaDefaultRoamingIndicator);
    279         out.writeInt(mCdmaEriIconIndex);
    280         out.writeInt(mCdmaEriIconMode);
    281         out.writeInt(mIsEmergencyOnly ? 1 : 0);
    282     }
    283 
    284     public int describeContents() {
    285         return 0;
    286     }
    287 
    288     public static final Parcelable.Creator<ServiceState> CREATOR =
    289             new Parcelable.Creator<ServiceState>() {
    290         public ServiceState createFromParcel(Parcel in) {
    291             return new ServiceState(in);
    292         }
    293 
    294         public ServiceState[] newArray(int size) {
    295             return new ServiceState[size];
    296         }
    297     };
    298 
    299     /**
    300      * Get current voice service state
    301      */
    302     public int getState() {
    303         return getVoiceRegState();
    304     }
    305 
    306     /**
    307      * Get current voice service state
    308      *
    309      * @see #STATE_IN_SERVICE
    310      * @see #STATE_OUT_OF_SERVICE
    311      * @see #STATE_EMERGENCY_ONLY
    312      * @see #STATE_POWER_OFF
    313      *
    314      * @hide
    315      */
    316     public int getVoiceRegState() {
    317         return mVoiceRegState;
    318     }
    319 
    320     /**
    321      * Get current data service state
    322      *
    323      * @see #STATE_IN_SERVICE
    324      * @see #STATE_OUT_OF_SERVICE
    325      * @see #STATE_EMERGENCY_ONLY
    326      * @see #STATE_POWER_OFF
    327      *
    328      * @hide
    329      */
    330     public int getDataRegState() {
    331         return mDataRegState;
    332     }
    333 
    334     /**
    335      * Get current roaming indicator of phone
    336      * (note: not just decoding from TS 27.007 7.2)
    337      *
    338      * @return true if TS 27.007 7.2 roaming is true
    339      *              and ONS is different from SPN
    340      *
    341      */
    342     public boolean getRoaming() {
    343         return mRoaming;
    344     }
    345 
    346     /**
    347      * @hide
    348      */
    349     public boolean isEmergencyOnly() {
    350         return mIsEmergencyOnly;
    351     }
    352 
    353     /**
    354      * @hide
    355      */
    356     public int getCdmaRoamingIndicator(){
    357         return this.mCdmaRoamingIndicator;
    358     }
    359 
    360     /**
    361      * @hide
    362      */
    363     public int getCdmaDefaultRoamingIndicator(){
    364         return this.mCdmaDefaultRoamingIndicator;
    365     }
    366 
    367     /**
    368      * @hide
    369      */
    370     public int getCdmaEriIconIndex() {
    371         return this.mCdmaEriIconIndex;
    372     }
    373 
    374     /**
    375      * @hide
    376      */
    377     public int getCdmaEriIconMode() {
    378         return this.mCdmaEriIconMode;
    379     }
    380 
    381     /**
    382      * Get current registered operator name in long alphanumeric format.
    383      *
    384      * In GSM/UMTS, long format can be up to 16 characters long.
    385      * In CDMA, returns the ERI text, if set. Otherwise, returns the ONS.
    386      *
    387      * @return long name of operator, null if unregistered or unknown
    388      */
    389     public String getOperatorAlphaLong() {
    390         return mOperatorAlphaLong;
    391     }
    392 
    393     /**
    394      * Get current registered operator name in short alphanumeric format.
    395      *
    396      * In GSM/UMTS, short format can be up to 8 characters long.
    397      *
    398      * @return short name of operator, null if unregistered or unknown
    399      */
    400     public String getOperatorAlphaShort() {
    401         return mOperatorAlphaShort;
    402     }
    403 
    404     /**
    405      * Get current registered operator numeric id.
    406      *
    407      * In GSM/UMTS, numeric format is 3 digit country code plus 2 or 3 digit
    408      * network code.
    409      *
    410      * @return numeric format of operator, null if unregistered or unknown
    411      */
    412     /*
    413      * The country code can be decoded using
    414      * {@link com.android.internal.telephony.MccTable#countryCodeForMcc(int)}.
    415      */
    416     public String getOperatorNumeric() {
    417         return mOperatorNumeric;
    418     }
    419 
    420     /**
    421      * Get current network selection mode.
    422      *
    423      * @return true if manual mode, false if automatic mode
    424      */
    425     public boolean getIsManualSelection() {
    426         return mIsManualNetworkSelection;
    427     }
    428 
    429     @Override
    430     public int hashCode() {
    431         return ((mVoiceRegState * 31)
    432                 + (mDataRegState * 37)
    433                 + (mRoaming ? 1 : 0)
    434                 + (mIsManualNetworkSelection ? 1 : 0)
    435                 + ((null == mOperatorAlphaLong) ? 0 : mOperatorAlphaLong.hashCode())
    436                 + ((null == mOperatorAlphaShort) ? 0 : mOperatorAlphaShort.hashCode())
    437                 + ((null == mOperatorNumeric) ? 0 : mOperatorNumeric.hashCode())
    438                 + mCdmaRoamingIndicator
    439                 + mCdmaDefaultRoamingIndicator
    440                 + (mIsEmergencyOnly ? 1 : 0));
    441     }
    442 
    443     @Override
    444     public boolean equals (Object o) {
    445         ServiceState s;
    446 
    447         try {
    448             s = (ServiceState) o;
    449         } catch (ClassCastException ex) {
    450             return false;
    451         }
    452 
    453         if (o == null) {
    454             return false;
    455         }
    456 
    457         return (mVoiceRegState == s.mVoiceRegState
    458                 && mDataRegState == s.mDataRegState
    459                 && mRoaming == s.mRoaming
    460                 && mIsManualNetworkSelection == s.mIsManualNetworkSelection
    461                 && equalsHandlesNulls(mOperatorAlphaLong, s.mOperatorAlphaLong)
    462                 && equalsHandlesNulls(mOperatorAlphaShort, s.mOperatorAlphaShort)
    463                 && equalsHandlesNulls(mOperatorNumeric, s.mOperatorNumeric)
    464                 && equalsHandlesNulls(mRilVoiceRadioTechnology, s.mRilVoiceRadioTechnology)
    465                 && equalsHandlesNulls(mRilDataRadioTechnology, s.mRilDataRadioTechnology)
    466                 && equalsHandlesNulls(mCssIndicator, s.mCssIndicator)
    467                 && equalsHandlesNulls(mNetworkId, s.mNetworkId)
    468                 && equalsHandlesNulls(mSystemId, s.mSystemId)
    469                 && equalsHandlesNulls(mCdmaRoamingIndicator, s.mCdmaRoamingIndicator)
    470                 && equalsHandlesNulls(mCdmaDefaultRoamingIndicator,
    471                         s.mCdmaDefaultRoamingIndicator)
    472                 && mIsEmergencyOnly == s.mIsEmergencyOnly);
    473     }
    474 
    475     /**
    476      * Convert radio technology to String
    477      *
    478      * @param radioTechnology
    479      * @return String representation of the RAT
    480      *
    481      * @hide
    482      */
    483     public static String rilRadioTechnologyToString(int rt) {
    484         String rtString;
    485 
    486         switch(rt) {
    487             case RIL_RADIO_TECHNOLOGY_UNKNOWN:
    488                 rtString = "Unknown";
    489                 break;
    490             case RIL_RADIO_TECHNOLOGY_GPRS:
    491                 rtString = "GPRS";
    492                 break;
    493             case RIL_RADIO_TECHNOLOGY_EDGE:
    494                 rtString = "EDGE";
    495                 break;
    496             case RIL_RADIO_TECHNOLOGY_UMTS:
    497                 rtString = "UMTS";
    498                 break;
    499             case RIL_RADIO_TECHNOLOGY_IS95A:
    500                 rtString = "CDMA-IS95A";
    501                 break;
    502             case RIL_RADIO_TECHNOLOGY_IS95B:
    503                 rtString = "CDMA-IS95B";
    504                 break;
    505             case RIL_RADIO_TECHNOLOGY_1xRTT:
    506                 rtString = "1xRTT";
    507                 break;
    508             case RIL_RADIO_TECHNOLOGY_EVDO_0:
    509                 rtString = "EvDo-rev.0";
    510                 break;
    511             case RIL_RADIO_TECHNOLOGY_EVDO_A:
    512                 rtString = "EvDo-rev.A";
    513                 break;
    514             case RIL_RADIO_TECHNOLOGY_HSDPA:
    515                 rtString = "HSDPA";
    516                 break;
    517             case RIL_RADIO_TECHNOLOGY_HSUPA:
    518                 rtString = "HSUPA";
    519                 break;
    520             case RIL_RADIO_TECHNOLOGY_HSPA:
    521                 rtString = "HSPA";
    522                 break;
    523             case RIL_RADIO_TECHNOLOGY_EVDO_B:
    524                 rtString = "EvDo-rev.B";
    525                 break;
    526             case RIL_RADIO_TECHNOLOGY_EHRPD:
    527                 rtString = "eHRPD";
    528                 break;
    529             case RIL_RADIO_TECHNOLOGY_LTE:
    530                 rtString = "LTE";
    531                 break;
    532             case RIL_RADIO_TECHNOLOGY_HSPAP:
    533                 rtString = "HSPAP";
    534                 break;
    535             case RIL_RADIO_TECHNOLOGY_GSM:
    536                 rtString = "GSM";
    537                 break;
    538             default:
    539                 rtString = "Unexpected";
    540                 Rlog.w(LOG_TAG, "Unexpected radioTechnology=" + rt);
    541                 break;
    542         }
    543         return rtString;
    544     }
    545 
    546     @Override
    547     public String toString() {
    548         String radioTechnology = rilRadioTechnologyToString(mRilVoiceRadioTechnology);
    549         String dataRadioTechnology = rilRadioTechnologyToString(mRilDataRadioTechnology);
    550 
    551         return (mVoiceRegState + " " + mDataRegState + " " + (mRoaming ? "roaming" : "home")
    552                 + " " + mOperatorAlphaLong
    553                 + " " + mOperatorAlphaShort
    554                 + " " + mOperatorNumeric
    555                 + " " + (mIsManualNetworkSelection ? "(manual)" : "")
    556                 + " " + radioTechnology
    557                 + " " + dataRadioTechnology
    558                 + " " + (mCssIndicator ? "CSS supported" : "CSS not supported")
    559                 + " " + mNetworkId
    560                 + " " + mSystemId
    561                 + " RoamInd=" + mCdmaRoamingIndicator
    562                 + " DefRoamInd=" + mCdmaDefaultRoamingIndicator
    563                 + " EmergOnly=" + mIsEmergencyOnly);
    564     }
    565 
    566     private void setNullState(int state) {
    567         if (DBG) Rlog.d(LOG_TAG, "[ServiceState] setNullState=" + state);
    568         mVoiceRegState = state;
    569         mDataRegState = state;
    570         mRoaming = false;
    571         mOperatorAlphaLong = null;
    572         mOperatorAlphaShort = null;
    573         mOperatorNumeric = null;
    574         mIsManualNetworkSelection = false;
    575         mRilVoiceRadioTechnology = 0;
    576         mRilDataRadioTechnology = 0;
    577         mCssIndicator = false;
    578         mNetworkId = -1;
    579         mSystemId = -1;
    580         mCdmaRoamingIndicator = -1;
    581         mCdmaDefaultRoamingIndicator = -1;
    582         mCdmaEriIconIndex = -1;
    583         mCdmaEriIconMode = -1;
    584         mIsEmergencyOnly = false;
    585     }
    586 
    587     public void setStateOutOfService() {
    588         setNullState(STATE_OUT_OF_SERVICE);
    589     }
    590 
    591     public void setStateOff() {
    592         setNullState(STATE_POWER_OFF);
    593     }
    594 
    595     public void setState(int state) {
    596         setVoiceRegState(state);
    597         if (DBG) Rlog.e(LOG_TAG, "[ServiceState] setState deprecated use setVoiceRegState()");
    598     }
    599 
    600     /** @hide */
    601     public void setVoiceRegState(int state) {
    602         mVoiceRegState = state;
    603         if (DBG) Rlog.d(LOG_TAG, "[ServiceState] setVoiceRegState=" + mVoiceRegState);
    604     }
    605 
    606     /** @hide */
    607     public void setDataRegState(int state) {
    608         mDataRegState = state;
    609         if (DBG) Rlog.d(LOG_TAG, "[ServiceState] setDataRegState=" + mDataRegState);
    610     }
    611 
    612     public void setRoaming(boolean roaming) {
    613         mRoaming = roaming;
    614     }
    615 
    616 
    617     /**
    618      * @hide
    619      */
    620     public void setEmergencyOnly(boolean emergencyOnly) {
    621         mIsEmergencyOnly = emergencyOnly;
    622     }
    623 
    624     /**
    625      * @hide
    626      */
    627     public void setCdmaRoamingIndicator(int roaming) {
    628         this.mCdmaRoamingIndicator = roaming;
    629     }
    630 
    631     /**
    632      * @hide
    633      */
    634     public void setCdmaDefaultRoamingIndicator (int roaming) {
    635         this.mCdmaDefaultRoamingIndicator = roaming;
    636     }
    637 
    638     /**
    639      * @hide
    640      */
    641     public void setCdmaEriIconIndex(int index) {
    642         this.mCdmaEriIconIndex = index;
    643     }
    644 
    645     /**
    646      * @hide
    647      */
    648     public void setCdmaEriIconMode(int mode) {
    649         this.mCdmaEriIconMode = mode;
    650     }
    651 
    652     public void setOperatorName(String longName, String shortName, String numeric) {
    653         mOperatorAlphaLong = longName;
    654         mOperatorAlphaShort = shortName;
    655         mOperatorNumeric = numeric;
    656     }
    657 
    658     /**
    659      * In CDMA, mOperatorAlphaLong can be set from the ERI text.
    660      * This is done from the CDMAPhone and not from the CdmaServiceStateTracker.
    661      *
    662      * @hide
    663      */
    664     public void setOperatorAlphaLong(String longName) {
    665         mOperatorAlphaLong = longName;
    666     }
    667 
    668     public void setIsManualSelection(boolean isManual) {
    669         mIsManualNetworkSelection = isManual;
    670     }
    671 
    672     /**
    673      * Test whether two objects hold the same data values or both are null.
    674      *
    675      * @param a first obj
    676      * @param b second obj
    677      * @return true if two objects equal or both are null
    678      */
    679     private static boolean equalsHandlesNulls (Object a, Object b) {
    680         return (a == null) ? (b == null) : a.equals (b);
    681     }
    682 
    683     /**
    684      * Set ServiceState based on intent notifier map.
    685      *
    686      * @param m intent notifier map
    687      * @hide
    688      */
    689     private void setFromNotifierBundle(Bundle m) {
    690         mVoiceRegState = m.getInt("voiceRegState");
    691         mDataRegState = m.getInt("dataRegState");
    692         mRoaming = m.getBoolean("roaming");
    693         mOperatorAlphaLong = m.getString("operator-alpha-long");
    694         mOperatorAlphaShort = m.getString("operator-alpha-short");
    695         mOperatorNumeric = m.getString("operator-numeric");
    696         mIsManualNetworkSelection = m.getBoolean("manual");
    697         mRilVoiceRadioTechnology = m.getInt("radioTechnology");
    698         mRilDataRadioTechnology = m.getInt("dataRadioTechnology");
    699         mCssIndicator = m.getBoolean("cssIndicator");
    700         mNetworkId = m.getInt("networkId");
    701         mSystemId = m.getInt("systemId");
    702         mCdmaRoamingIndicator = m.getInt("cdmaRoamingIndicator");
    703         mCdmaDefaultRoamingIndicator = m.getInt("cdmaDefaultRoamingIndicator");
    704         mIsEmergencyOnly = m.getBoolean("emergencyOnly");
    705     }
    706 
    707     /**
    708      * Set intent notifier Bundle based on service state.
    709      *
    710      * @param m intent notifier Bundle
    711      * @hide
    712      */
    713     public void fillInNotifierBundle(Bundle m) {
    714         m.putInt("voiceRegState", mVoiceRegState);
    715         m.putInt("dataRegState", mDataRegState);
    716         m.putBoolean("roaming", Boolean.valueOf(mRoaming));
    717         m.putString("operator-alpha-long", mOperatorAlphaLong);
    718         m.putString("operator-alpha-short", mOperatorAlphaShort);
    719         m.putString("operator-numeric", mOperatorNumeric);
    720         m.putBoolean("manual", Boolean.valueOf(mIsManualNetworkSelection));
    721         m.putInt("radioTechnology", mRilVoiceRadioTechnology);
    722         m.putInt("dataRadioTechnology", mRilDataRadioTechnology);
    723         m.putBoolean("cssIndicator", mCssIndicator);
    724         m.putInt("networkId", mNetworkId);
    725         m.putInt("systemId", mSystemId);
    726         m.putInt("cdmaRoamingIndicator", mCdmaRoamingIndicator);
    727         m.putInt("cdmaDefaultRoamingIndicator", mCdmaDefaultRoamingIndicator);
    728         m.putBoolean("emergencyOnly", Boolean.valueOf(mIsEmergencyOnly));
    729     }
    730 
    731     /** @hide */
    732     public void setRilVoiceRadioTechnology(int rt) {
    733         this.mRilVoiceRadioTechnology = rt;
    734     }
    735 
    736     /** @hide */
    737     public void setRilDataRadioTechnology(int rt) {
    738         this.mRilDataRadioTechnology = rt;
    739         if (DBG) Rlog.d(LOG_TAG, "[ServiceState] setDataRadioTechnology=" + mRilDataRadioTechnology);
    740     }
    741 
    742     /** @hide */
    743     public void setCssIndicator(int css) {
    744         this.mCssIndicator = (css != 0);
    745     }
    746 
    747     /** @hide */
    748     public void setSystemAndNetworkId(int systemId, int networkId) {
    749         this.mSystemId = systemId;
    750         this.mNetworkId = networkId;
    751     }
    752 
    753     /** @hide */
    754     public int getRilVoiceRadioTechnology() {
    755         return this.mRilVoiceRadioTechnology;
    756     }
    757     /** @hide */
    758     public int getRilDataRadioTechnology() {
    759         return this.mRilDataRadioTechnology;
    760     }
    761     /**
    762      * @hide
    763      * @Deprecated to be removed Q3 2013 use {@link #getRilDataRadioTechnology} or
    764      * {@link #getRilVoiceRadioTechnology}
    765      */
    766     public int getRadioTechnology() {
    767         Rlog.e(LOG_TAG, "ServiceState.getRadioTechnology() DEPRECATED will be removed *******");
    768         return getRilDataRadioTechnology();
    769     }
    770 
    771     private int rilRadioTechnologyToNetworkType(int rt) {
    772         switch(rt) {
    773         case ServiceState.RIL_RADIO_TECHNOLOGY_GPRS:
    774             return TelephonyManager.NETWORK_TYPE_GPRS;
    775         case ServiceState.RIL_RADIO_TECHNOLOGY_EDGE:
    776             return TelephonyManager.NETWORK_TYPE_EDGE;
    777         case ServiceState.RIL_RADIO_TECHNOLOGY_UMTS:
    778             return TelephonyManager.NETWORK_TYPE_UMTS;
    779         case ServiceState.RIL_RADIO_TECHNOLOGY_HSDPA:
    780             return TelephonyManager.NETWORK_TYPE_HSDPA;
    781         case ServiceState.RIL_RADIO_TECHNOLOGY_HSUPA:
    782             return TelephonyManager.NETWORK_TYPE_HSUPA;
    783         case ServiceState.RIL_RADIO_TECHNOLOGY_HSPA:
    784             return TelephonyManager.NETWORK_TYPE_HSPA;
    785         case ServiceState.RIL_RADIO_TECHNOLOGY_IS95A:
    786         case ServiceState.RIL_RADIO_TECHNOLOGY_IS95B:
    787             return TelephonyManager.NETWORK_TYPE_CDMA;
    788         case ServiceState.RIL_RADIO_TECHNOLOGY_1xRTT:
    789             return TelephonyManager.NETWORK_TYPE_1xRTT;
    790         case ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_0:
    791             return TelephonyManager.NETWORK_TYPE_EVDO_0;
    792         case ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_A:
    793             return TelephonyManager.NETWORK_TYPE_EVDO_A;
    794         case ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_B:
    795             return TelephonyManager.NETWORK_TYPE_EVDO_B;
    796         case ServiceState.RIL_RADIO_TECHNOLOGY_EHRPD:
    797             return TelephonyManager.NETWORK_TYPE_EHRPD;
    798         case ServiceState.RIL_RADIO_TECHNOLOGY_LTE:
    799             return TelephonyManager.NETWORK_TYPE_LTE;
    800         case ServiceState.RIL_RADIO_TECHNOLOGY_HSPAP:
    801             return TelephonyManager.NETWORK_TYPE_HSPAP;
    802         case ServiceState.RIL_RADIO_TECHNOLOGY_GSM:
    803             return TelephonyManager.NETWORK_TYPE_GSM;
    804         default:
    805             return TelephonyManager.NETWORK_TYPE_UNKNOWN;
    806         }
    807     }
    808 
    809     /**
    810      * @Deprecated to be removed Q3 2013 use {@link #getVoiceNetworkType}
    811      * @hide
    812      */
    813     public int getNetworkType() {
    814         Rlog.e(LOG_TAG, "ServiceState.getNetworkType() DEPRECATED will be removed *******");
    815         return rilRadioTechnologyToNetworkType(mRilVoiceRadioTechnology);
    816     }
    817 
    818     /** @hide */
    819     public int getDataNetworkType() {
    820         return rilRadioTechnologyToNetworkType(mRilDataRadioTechnology);
    821     }
    822 
    823     /** @hide */
    824     public int getVoiceNetworkType() {
    825         return rilRadioTechnologyToNetworkType(mRilVoiceRadioTechnology);
    826     }
    827 
    828     /** @hide */
    829     public int getCssIndicator() {
    830         return this.mCssIndicator ? 1 : 0;
    831     }
    832 
    833     /** @hide */
    834     public int getNetworkId() {
    835         return this.mNetworkId;
    836     }
    837 
    838     /** @hide */
    839     public int getSystemId() {
    840         return this.mSystemId;
    841     }
    842 
    843     /** @hide */
    844     public static boolean isGsm(int radioTechnology) {
    845         return radioTechnology == RIL_RADIO_TECHNOLOGY_GPRS
    846                 || radioTechnology == RIL_RADIO_TECHNOLOGY_EDGE
    847                 || radioTechnology == RIL_RADIO_TECHNOLOGY_UMTS
    848                 || radioTechnology == RIL_RADIO_TECHNOLOGY_HSDPA
    849                 || radioTechnology == RIL_RADIO_TECHNOLOGY_HSUPA
    850                 || radioTechnology == RIL_RADIO_TECHNOLOGY_HSPA
    851                 || radioTechnology == RIL_RADIO_TECHNOLOGY_LTE
    852                 || radioTechnology == RIL_RADIO_TECHNOLOGY_HSPAP
    853                 || radioTechnology == RIL_RADIO_TECHNOLOGY_GSM
    854                 || radioTechnology == RIL_RADIO_TECHNOLOGY_TD_SCDMA;
    855     }
    856 
    857     /** @hide */
    858     public static boolean isCdma(int radioTechnology) {
    859         return radioTechnology == RIL_RADIO_TECHNOLOGY_IS95A
    860                 || radioTechnology == RIL_RADIO_TECHNOLOGY_IS95B
    861                 || radioTechnology == RIL_RADIO_TECHNOLOGY_1xRTT
    862                 || radioTechnology == RIL_RADIO_TECHNOLOGY_EVDO_0
    863                 || radioTechnology == RIL_RADIO_TECHNOLOGY_EVDO_A
    864                 || radioTechnology == RIL_RADIO_TECHNOLOGY_EVDO_B
    865                 || radioTechnology == RIL_RADIO_TECHNOLOGY_EHRPD;
    866     }
    867 }
    868