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
17package android.telephony;
18
19import android.os.Bundle;
20import android.os.Parcel;
21import android.os.Parcelable;
22import android.telephony.Rlog;
23import android.text.TextUtils;
24
25/**
26 * Contains phone state and service related information.
27 *
28 * The following phone information is included in returned ServiceState:
29 *
30 * <ul>
31 *   <li>Service state: IN_SERVICE, OUT_OF_SERVICE, EMERGENCY_ONLY, POWER_OFF
32 *   <li>Roaming indicator
33 *   <li>Operator name, short name and numeric id
34 *   <li>Network selection mode
35 * </ul>
36 */
37public class ServiceState implements Parcelable {
38
39    static final String LOG_TAG = "PHONE";
40    static final boolean DBG = false;
41    static final boolean VDBG = false;  // STOPSHIP if true
42
43    /**
44     * Normal operation condition, the phone is registered
45     * with an operator either in home network or in roaming.
46     */
47    public static final int STATE_IN_SERVICE = 0;
48
49    /**
50     * Phone is not registered with any operator, the phone
51     * can be currently searching a new operator to register to, or not
52     * searching to registration at all, or registration is denied, or radio
53     * signal is not available.
54     */
55    public static final int STATE_OUT_OF_SERVICE = 1;
56
57    /**
58     * The phone is registered and locked.  Only emergency numbers are allowed. {@more}
59     */
60    public static final int STATE_EMERGENCY_ONLY = 2;
61
62    /**
63     * Radio of telephony is explicitly powered off.
64     */
65    public static final int STATE_POWER_OFF = 3;
66
67    /**
68     * RIL level registration state values from ril.h
69     * ((const char **)response)[0] is registration state 0-6,
70     *              0 - Not registered, MT is not currently searching
71     *                  a new operator to register
72     *              1 - Registered, home network
73     *              2 - Not registered, but MT is currently searching
74     *                  a new operator to register
75     *              3 - Registration denied
76     *              4 - Unknown
77     *              5 - Registered, roaming
78     *             10 - Same as 0, but indicates that emergency calls
79     *                  are enabled.
80     *             12 - Same as 2, but indicates that emergency calls
81     *                  are enabled.
82     *             13 - Same as 3, but indicates that emergency calls
83     *                  are enabled.
84     *             14 - Same as 4, but indicates that emergency calls
85     *                  are enabled.
86     * @hide
87     */
88    public static final int RIL_REG_STATE_NOT_REG = 0;
89    /** @hide */
90    public static final int RIL_REG_STATE_HOME = 1;
91    /** @hide */
92    public static final int RIL_REG_STATE_SEARCHING = 2;
93    /** @hide */
94    public static final int RIL_REG_STATE_DENIED = 3;
95    /** @hide */
96    public static final int RIL_REG_STATE_UNKNOWN = 4;
97    /** @hide */
98    public static final int RIL_REG_STATE_ROAMING = 5;
99    /** @hide */
100    public static final int RIL_REG_STATE_NOT_REG_EMERGENCY_CALL_ENABLED = 10;
101    /** @hide */
102    public static final int RIL_REG_STATE_SEARCHING_EMERGENCY_CALL_ENABLED = 12;
103    /** @hide */
104    public static final int RIL_REG_STATE_DENIED_EMERGENCY_CALL_ENABLED = 13;
105    /** @hide */
106    public static final int RIL_REG_STATE_UNKNOWN_EMERGENCY_CALL_ENABLED = 14;
107
108    /**
109     * Available radio technologies for GSM, UMTS and CDMA.
110     * Duplicates the constants from hardware/radio/include/ril.h
111     * This should only be used by agents working with the ril.  Others
112     * should use the equivalent TelephonyManager.NETWORK_TYPE_*
113     */
114    /** @hide */
115    public static final int RIL_RADIO_TECHNOLOGY_UNKNOWN = 0;
116    /** @hide */
117    public static final int RIL_RADIO_TECHNOLOGY_GPRS = 1;
118    /** @hide */
119    public static final int RIL_RADIO_TECHNOLOGY_EDGE = 2;
120    /** @hide */
121    public static final int RIL_RADIO_TECHNOLOGY_UMTS = 3;
122    /** @hide */
123    public static final int RIL_RADIO_TECHNOLOGY_IS95A = 4;
124    /** @hide */
125    public static final int RIL_RADIO_TECHNOLOGY_IS95B = 5;
126    /** @hide */
127    public static final int RIL_RADIO_TECHNOLOGY_1xRTT = 6;
128    /** @hide */
129    public static final int RIL_RADIO_TECHNOLOGY_EVDO_0 = 7;
130    /** @hide */
131    public static final int RIL_RADIO_TECHNOLOGY_EVDO_A = 8;
132    /** @hide */
133    public static final int RIL_RADIO_TECHNOLOGY_HSDPA = 9;
134    /** @hide */
135    public static final int RIL_RADIO_TECHNOLOGY_HSUPA = 10;
136    /** @hide */
137    public static final int RIL_RADIO_TECHNOLOGY_HSPA = 11;
138    /** @hide */
139    public static final int RIL_RADIO_TECHNOLOGY_EVDO_B = 12;
140    /** @hide */
141    public static final int RIL_RADIO_TECHNOLOGY_EHRPD = 13;
142    /** @hide */
143    public static final int RIL_RADIO_TECHNOLOGY_LTE = 14;
144    /** @hide */
145    public static final int RIL_RADIO_TECHNOLOGY_HSPAP = 15;
146    /**
147     * GSM radio technology only supports voice. It does not support data.
148     * @hide
149     */
150    public static final int RIL_RADIO_TECHNOLOGY_GSM = 16;
151    /** @hide */
152    public static final int RIL_RADIO_TECHNOLOGY_TD_SCDMA = 17;
153    /**
154     * IWLAN
155     * @hide
156     */
157    public static final int RIL_RADIO_TECHNOLOGY_IWLAN = 18;
158
159    /**
160     * LTE_CA
161     * @hide
162     */
163    public static final int RIL_RADIO_TECHNOLOGY_LTE_CA = 19;
164
165    /** @hide */
166    public static final int RIL_RADIO_CDMA_TECHNOLOGY_BITMASK =
167            (1 << (RIL_RADIO_TECHNOLOGY_IS95A - 1))
168                    | (1 << (RIL_RADIO_TECHNOLOGY_IS95B - 1))
169                    | (1 << (RIL_RADIO_TECHNOLOGY_1xRTT - 1))
170                    | (1 << (RIL_RADIO_TECHNOLOGY_EVDO_0 - 1))
171                    | (1 << (RIL_RADIO_TECHNOLOGY_EVDO_A - 1))
172                    | (1 << (RIL_RADIO_TECHNOLOGY_EVDO_B - 1))
173                    | (1 << (RIL_RADIO_TECHNOLOGY_EHRPD - 1));
174
175    /**
176     * Available registration states for GSM, UMTS and CDMA.
177     */
178    /** @hide */
179    public static final int REGISTRATION_STATE_NOT_REGISTERED_AND_NOT_SEARCHING = 0;
180    /** @hide */
181    public static final int REGISTRATION_STATE_HOME_NETWORK = 1;
182    /** @hide */
183    public static final int REGISTRATION_STATE_NOT_REGISTERED_AND_SEARCHING = 2;
184    /** @hide */
185    public static final int REGISTRATION_STATE_REGISTRATION_DENIED = 3;
186    /** @hide */
187    public static final int REGISTRATION_STATE_UNKNOWN = 4;
188    /** @hide */
189    public static final int REGISTRATION_STATE_ROAMING = 5;
190
191    private int mVoiceRegState = STATE_OUT_OF_SERVICE;
192    private int mDataRegState = STATE_OUT_OF_SERVICE;
193
194    /**
195     * Roaming type
196     * HOME : in home network
197     * @hide
198     */
199    public static final int ROAMING_TYPE_NOT_ROAMING = 0;
200    /**
201     * Roaming type
202     * UNKNOWN : in a roaming network, but we can not tell if it's domestic or international
203     * @hide
204     */
205    public static final int ROAMING_TYPE_UNKNOWN = 1;
206    /**
207     * Roaming type
208     * DOMESTIC : in domestic roaming network
209     * @hide
210     */
211    public static final int ROAMING_TYPE_DOMESTIC = 2;
212    /**
213     * Roaming type
214     * INTERNATIONAL : in international roaming network
215     * @hide
216     */
217    public static final int ROAMING_TYPE_INTERNATIONAL = 3;
218
219    private int mVoiceRoamingType;
220    private int mDataRoamingType;
221    private String mVoiceOperatorAlphaLong;
222    private String mVoiceOperatorAlphaShort;
223    private String mVoiceOperatorNumeric;
224    private String mDataOperatorAlphaLong;
225    private String mDataOperatorAlphaShort;
226    private String mDataOperatorNumeric;
227    private boolean mIsManualNetworkSelection;
228
229    private boolean mIsEmergencyOnly;
230
231    private int mRilVoiceRadioTechnology;
232    private int mRilDataRadioTechnology;
233
234    private boolean mCssIndicator;
235    private int mNetworkId;
236    private int mSystemId;
237    private int mCdmaRoamingIndicator;
238    private int mCdmaDefaultRoamingIndicator;
239    private int mCdmaEriIconIndex;
240    private int mCdmaEriIconMode;
241
242    private boolean mIsDataRoamingFromRegistration;
243
244    private boolean mIsUsingCarrierAggregation;
245
246    /* EARFCN stands for E-UTRA Absolute Radio Frequency Channel Number,
247     * Reference: 3GPP TS 36.104 5.4.3 */
248    private int mLteEarfcnRsrpBoost = 0;
249
250    /**
251     * get String description of roaming type
252     * @hide
253     */
254    public static final String getRoamingLogString(int roamingType) {
255        switch (roamingType) {
256            case ROAMING_TYPE_NOT_ROAMING:
257                return "home";
258
259            case ROAMING_TYPE_UNKNOWN:
260                return "roaming";
261
262            case ROAMING_TYPE_DOMESTIC:
263                return "Domestic Roaming";
264
265            case ROAMING_TYPE_INTERNATIONAL:
266                return "International Roaming";
267
268            default:
269                return "UNKNOWN";
270        }
271    }
272
273    /**
274     * Create a new ServiceState from a intent notifier Bundle
275     *
276     * This method is used by PhoneStateIntentReceiver and maybe by
277     * external applications.
278     *
279     * @param m Bundle from intent notifier
280     * @return newly created ServiceState
281     * @hide
282     */
283    public static ServiceState newFromBundle(Bundle m) {
284        ServiceState ret;
285        ret = new ServiceState();
286        ret.setFromNotifierBundle(m);
287        return ret;
288    }
289
290    /**
291     * Empty constructor
292     */
293    public ServiceState() {
294    }
295
296    /**
297     * Copy constructors
298     *
299     * @param s Source service state
300     */
301    public ServiceState(ServiceState s) {
302        copyFrom(s);
303    }
304
305    protected void copyFrom(ServiceState s) {
306        mVoiceRegState = s.mVoiceRegState;
307        mDataRegState = s.mDataRegState;
308        mVoiceRoamingType = s.mVoiceRoamingType;
309        mDataRoamingType = s.mDataRoamingType;
310        mVoiceOperatorAlphaLong = s.mVoiceOperatorAlphaLong;
311        mVoiceOperatorAlphaShort = s.mVoiceOperatorAlphaShort;
312        mVoiceOperatorNumeric = s.mVoiceOperatorNumeric;
313        mDataOperatorAlphaLong = s.mDataOperatorAlphaLong;
314        mDataOperatorAlphaShort = s.mDataOperatorAlphaShort;
315        mDataOperatorNumeric = s.mDataOperatorNumeric;
316        mIsManualNetworkSelection = s.mIsManualNetworkSelection;
317        mRilVoiceRadioTechnology = s.mRilVoiceRadioTechnology;
318        mRilDataRadioTechnology = s.mRilDataRadioTechnology;
319        mCssIndicator = s.mCssIndicator;
320        mNetworkId = s.mNetworkId;
321        mSystemId = s.mSystemId;
322        mCdmaRoamingIndicator = s.mCdmaRoamingIndicator;
323        mCdmaDefaultRoamingIndicator = s.mCdmaDefaultRoamingIndicator;
324        mCdmaEriIconIndex = s.mCdmaEriIconIndex;
325        mCdmaEriIconMode = s.mCdmaEriIconMode;
326        mIsEmergencyOnly = s.mIsEmergencyOnly;
327        mIsDataRoamingFromRegistration = s.mIsDataRoamingFromRegistration;
328        mIsUsingCarrierAggregation = s.mIsUsingCarrierAggregation;
329        mLteEarfcnRsrpBoost = s.mLteEarfcnRsrpBoost;
330    }
331
332    /**
333     * Construct a ServiceState object from the given parcel.
334     */
335    public ServiceState(Parcel in) {
336        mVoiceRegState = in.readInt();
337        mDataRegState = in.readInt();
338        mVoiceRoamingType = in.readInt();
339        mDataRoamingType = in.readInt();
340        mVoiceOperatorAlphaLong = in.readString();
341        mVoiceOperatorAlphaShort = in.readString();
342        mVoiceOperatorNumeric = in.readString();
343        mDataOperatorAlphaLong = in.readString();
344        mDataOperatorAlphaShort = in.readString();
345        mDataOperatorNumeric = in.readString();
346        mIsManualNetworkSelection = in.readInt() != 0;
347        mRilVoiceRadioTechnology = in.readInt();
348        mRilDataRadioTechnology = in.readInt();
349        mCssIndicator = (in.readInt() != 0);
350        mNetworkId = in.readInt();
351        mSystemId = in.readInt();
352        mCdmaRoamingIndicator = in.readInt();
353        mCdmaDefaultRoamingIndicator = in.readInt();
354        mCdmaEriIconIndex = in.readInt();
355        mCdmaEriIconMode = in.readInt();
356        mIsEmergencyOnly = in.readInt() != 0;
357        mIsDataRoamingFromRegistration = in.readInt() != 0;
358        mIsUsingCarrierAggregation = in.readInt() != 0;
359        mLteEarfcnRsrpBoost = in.readInt();
360    }
361
362    public void writeToParcel(Parcel out, int flags) {
363        out.writeInt(mVoiceRegState);
364        out.writeInt(mDataRegState);
365        out.writeInt(mVoiceRoamingType);
366        out.writeInt(mDataRoamingType);
367        out.writeString(mVoiceOperatorAlphaLong);
368        out.writeString(mVoiceOperatorAlphaShort);
369        out.writeString(mVoiceOperatorNumeric);
370        out.writeString(mDataOperatorAlphaLong);
371        out.writeString(mDataOperatorAlphaShort);
372        out.writeString(mDataOperatorNumeric);
373        out.writeInt(mIsManualNetworkSelection ? 1 : 0);
374        out.writeInt(mRilVoiceRadioTechnology);
375        out.writeInt(mRilDataRadioTechnology);
376        out.writeInt(mCssIndicator ? 1 : 0);
377        out.writeInt(mNetworkId);
378        out.writeInt(mSystemId);
379        out.writeInt(mCdmaRoamingIndicator);
380        out.writeInt(mCdmaDefaultRoamingIndicator);
381        out.writeInt(mCdmaEriIconIndex);
382        out.writeInt(mCdmaEriIconMode);
383        out.writeInt(mIsEmergencyOnly ? 1 : 0);
384        out.writeInt(mIsDataRoamingFromRegistration ? 1 : 0);
385        out.writeInt(mIsUsingCarrierAggregation ? 1 : 0);
386        out.writeInt(mLteEarfcnRsrpBoost);
387    }
388
389    public int describeContents() {
390        return 0;
391    }
392
393    public static final Parcelable.Creator<ServiceState> CREATOR =
394            new Parcelable.Creator<ServiceState>() {
395        public ServiceState createFromParcel(Parcel in) {
396            return new ServiceState(in);
397        }
398
399        public ServiceState[] newArray(int size) {
400            return new ServiceState[size];
401        }
402    };
403
404    /**
405     * Get current voice service state
406     */
407    public int getState() {
408        return getVoiceRegState();
409    }
410
411    /**
412     * Get current voice service state
413     *
414     * @see #STATE_IN_SERVICE
415     * @see #STATE_OUT_OF_SERVICE
416     * @see #STATE_EMERGENCY_ONLY
417     * @see #STATE_POWER_OFF
418     *
419     * @hide
420     */
421    public int getVoiceRegState() {
422        return mVoiceRegState;
423    }
424
425    /**
426     * Get current data service state
427     *
428     * @see #STATE_IN_SERVICE
429     * @see #STATE_OUT_OF_SERVICE
430     * @see #STATE_EMERGENCY_ONLY
431     * @see #STATE_POWER_OFF
432     *
433     * @hide
434     */
435    public int getDataRegState() {
436        return mDataRegState;
437    }
438
439    /**
440     * Get current roaming indicator of phone
441     * (note: not just decoding from TS 27.007 7.2)
442     *
443     * @return true if TS 27.007 7.2 roaming is true
444     *              and ONS is different from SPN
445     */
446    public boolean getRoaming() {
447        return getVoiceRoaming() || getDataRoaming();
448    }
449
450    /**
451     * Get current voice network roaming status
452     * @return roaming status
453     * @hide
454     */
455    public boolean getVoiceRoaming() {
456        return mVoiceRoamingType != ROAMING_TYPE_NOT_ROAMING;
457    }
458
459    /**
460     * Get current voice network roaming type
461     * @return roaming type
462     * @hide
463     */
464    public int getVoiceRoamingType() {
465        return mVoiceRoamingType;
466    }
467
468    /**
469     * Get current data network roaming type
470     * @return roaming type
471     * @hide
472     */
473    public boolean getDataRoaming() {
474        return mDataRoamingType != ROAMING_TYPE_NOT_ROAMING;
475    }
476
477    /**
478     * Set whether data network registration state is roaming
479     *
480     * This should only be set to the roaming value received
481     * once the data registration phase has completed.
482     * @hide
483     */
484    public void setDataRoamingFromRegistration(boolean dataRoaming) {
485        mIsDataRoamingFromRegistration = dataRoaming;
486    }
487
488    /**
489     * Get whether data network registration state is roaming
490     * @return true if registration indicates roaming, false otherwise
491     * @hide
492     */
493    public boolean getDataRoamingFromRegistration() {
494        return mIsDataRoamingFromRegistration;
495    }
496
497    /**
498     * Get current data network roaming type
499     * @return roaming type
500     * @hide
501     */
502    public int getDataRoamingType() {
503        return mDataRoamingType;
504    }
505
506    /**
507     * @hide
508     */
509    public boolean isEmergencyOnly() {
510        return mIsEmergencyOnly;
511    }
512
513    /**
514     * @hide
515     */
516    public int getCdmaRoamingIndicator(){
517        return this.mCdmaRoamingIndicator;
518    }
519
520    /**
521     * @hide
522     */
523    public int getCdmaDefaultRoamingIndicator(){
524        return this.mCdmaDefaultRoamingIndicator;
525    }
526
527    /**
528     * @hide
529     */
530    public int getCdmaEriIconIndex() {
531        return this.mCdmaEriIconIndex;
532    }
533
534    /**
535     * @hide
536     */
537    public int getCdmaEriIconMode() {
538        return this.mCdmaEriIconMode;
539    }
540
541    /**
542     * Get current registered operator name in long alphanumeric format.
543     *
544     * In GSM/UMTS, long format can be up to 16 characters long.
545     * In CDMA, returns the ERI text, if set. Otherwise, returns the ONS.
546     *
547     * @return long name of operator, null if unregistered or unknown
548     */
549    public String getOperatorAlphaLong() {
550        return mVoiceOperatorAlphaLong;
551    }
552
553    /**
554     * Get current registered voice network operator name in long alphanumeric format.
555     * @return long name of operator
556     * @hide
557     */
558    public String getVoiceOperatorAlphaLong() {
559        return mVoiceOperatorAlphaLong;
560    }
561
562    /**
563     * Get current registered data network operator name in long alphanumeric format.
564     * @return long name of voice operator
565     * @hide
566     */
567    public String getDataOperatorAlphaLong() {
568        return mDataOperatorAlphaLong;
569    }
570
571    /**
572     * Get current registered operator name in short alphanumeric format.
573     *
574     * In GSM/UMTS, short format can be up to 8 characters long.
575     *
576     * @return short name of operator, null if unregistered or unknown
577     */
578    public String getOperatorAlphaShort() {
579        return mVoiceOperatorAlphaShort;
580    }
581
582    /**
583     * Get current registered voice network operator name in short alphanumeric format.
584     * @return short name of operator, null if unregistered or unknown
585     * @hide
586     */
587    public String getVoiceOperatorAlphaShort() {
588        return mVoiceOperatorAlphaShort;
589    }
590
591    /**
592     * Get current registered data network operator name in short alphanumeric format.
593     * @return short name of operator, null if unregistered or unknown
594     * @hide
595     */
596    public String getDataOperatorAlphaShort() {
597        return mDataOperatorAlphaShort;
598    }
599
600    /**
601     * Get current registered operator name in long alphanumeric format if
602     * available or short otherwise.
603     *
604     * @see #getOperatorAlphaLong
605     * @see #getOperatorAlphaShort
606     *
607     * @return name of operator, null if unregistered or unknown
608     * @hide
609     */
610    public String getOperatorAlpha() {
611        if (TextUtils.isEmpty(mVoiceOperatorAlphaLong)) {
612            return mVoiceOperatorAlphaShort;
613        }
614
615        return mVoiceOperatorAlphaLong;
616    }
617
618    /**
619     * Get current registered operator numeric id.
620     *
621     * In GSM/UMTS, numeric format is 3 digit country code plus 2 or 3 digit
622     * network code.
623     *
624     * @return numeric format of operator, null if unregistered or unknown
625     */
626    /*
627     * The country code can be decoded using
628     * {@link com.android.internal.telephony.MccTable#countryCodeForMcc(int)}.
629     */
630    public String getOperatorNumeric() {
631        return mVoiceOperatorNumeric;
632    }
633
634    /**
635     * Get current registered voice network operator numeric id.
636     * @return numeric format of operator, null if unregistered or unknown
637     * @hide
638     */
639    public String getVoiceOperatorNumeric() {
640        return mVoiceOperatorNumeric;
641    }
642
643    /**
644     * Get current registered data network operator numeric id.
645     * @return numeric format of operator, null if unregistered or unknown
646     * @hide
647     */
648    public String getDataOperatorNumeric() {
649        return mDataOperatorNumeric;
650    }
651
652    /**
653     * Get current network selection mode.
654     *
655     * @return true if manual mode, false if automatic mode
656     */
657    public boolean getIsManualSelection() {
658        return mIsManualNetworkSelection;
659    }
660
661    @Override
662    public int hashCode() {
663        return ((mVoiceRegState * 31)
664                + (mDataRegState * 37)
665                + mVoiceRoamingType
666                + mDataRoamingType
667                + (mIsManualNetworkSelection ? 1 : 0)
668                + ((null == mVoiceOperatorAlphaLong) ? 0 : mVoiceOperatorAlphaLong.hashCode())
669                + ((null == mVoiceOperatorAlphaShort) ? 0 : mVoiceOperatorAlphaShort.hashCode())
670                + ((null == mVoiceOperatorNumeric) ? 0 : mVoiceOperatorNumeric.hashCode())
671                + ((null == mDataOperatorAlphaLong) ? 0 : mDataOperatorAlphaLong.hashCode())
672                + ((null == mDataOperatorAlphaShort) ? 0 : mDataOperatorAlphaShort.hashCode())
673                + ((null == mDataOperatorNumeric) ? 0 : mDataOperatorNumeric.hashCode())
674                + mCdmaRoamingIndicator
675                + mCdmaDefaultRoamingIndicator
676                + (mIsEmergencyOnly ? 1 : 0)
677                + (mIsDataRoamingFromRegistration ? 1 : 0));
678    }
679
680    @Override
681    public boolean equals (Object o) {
682        ServiceState s;
683
684        try {
685            s = (ServiceState) o;
686        } catch (ClassCastException ex) {
687            return false;
688        }
689
690        if (o == null) {
691            return false;
692        }
693
694        return (mVoiceRegState == s.mVoiceRegState
695                && mDataRegState == s.mDataRegState
696                && mIsManualNetworkSelection == s.mIsManualNetworkSelection
697                && mVoiceRoamingType == s.mVoiceRoamingType
698                && mDataRoamingType == s.mDataRoamingType
699                && equalsHandlesNulls(mVoiceOperatorAlphaLong, s.mVoiceOperatorAlphaLong)
700                && equalsHandlesNulls(mVoiceOperatorAlphaShort, s.mVoiceOperatorAlphaShort)
701                && equalsHandlesNulls(mVoiceOperatorNumeric, s.mVoiceOperatorNumeric)
702                && equalsHandlesNulls(mDataOperatorAlphaLong, s.mDataOperatorAlphaLong)
703                && equalsHandlesNulls(mDataOperatorAlphaShort, s.mDataOperatorAlphaShort)
704                && equalsHandlesNulls(mDataOperatorNumeric, s.mDataOperatorNumeric)
705                && equalsHandlesNulls(mRilVoiceRadioTechnology, s.mRilVoiceRadioTechnology)
706                && equalsHandlesNulls(mRilDataRadioTechnology, s.mRilDataRadioTechnology)
707                && equalsHandlesNulls(mCssIndicator, s.mCssIndicator)
708                && equalsHandlesNulls(mNetworkId, s.mNetworkId)
709                && equalsHandlesNulls(mSystemId, s.mSystemId)
710                && equalsHandlesNulls(mCdmaRoamingIndicator, s.mCdmaRoamingIndicator)
711                && equalsHandlesNulls(mCdmaDefaultRoamingIndicator,
712                        s.mCdmaDefaultRoamingIndicator)
713                && mIsEmergencyOnly == s.mIsEmergencyOnly
714                && mIsDataRoamingFromRegistration == s.mIsDataRoamingFromRegistration
715                && mIsUsingCarrierAggregation == s.mIsUsingCarrierAggregation);
716    }
717
718    /**
719     * Convert radio technology to String
720     *
721     * @param radioTechnology
722     * @return String representation of the RAT
723     *
724     * @hide
725     */
726    public static String rilRadioTechnologyToString(int rt) {
727        String rtString;
728
729        switch(rt) {
730            case RIL_RADIO_TECHNOLOGY_UNKNOWN:
731                rtString = "Unknown";
732                break;
733            case RIL_RADIO_TECHNOLOGY_GPRS:
734                rtString = "GPRS";
735                break;
736            case RIL_RADIO_TECHNOLOGY_EDGE:
737                rtString = "EDGE";
738                break;
739            case RIL_RADIO_TECHNOLOGY_UMTS:
740                rtString = "UMTS";
741                break;
742            case RIL_RADIO_TECHNOLOGY_IS95A:
743                rtString = "CDMA-IS95A";
744                break;
745            case RIL_RADIO_TECHNOLOGY_IS95B:
746                rtString = "CDMA-IS95B";
747                break;
748            case RIL_RADIO_TECHNOLOGY_1xRTT:
749                rtString = "1xRTT";
750                break;
751            case RIL_RADIO_TECHNOLOGY_EVDO_0:
752                rtString = "EvDo-rev.0";
753                break;
754            case RIL_RADIO_TECHNOLOGY_EVDO_A:
755                rtString = "EvDo-rev.A";
756                break;
757            case RIL_RADIO_TECHNOLOGY_HSDPA:
758                rtString = "HSDPA";
759                break;
760            case RIL_RADIO_TECHNOLOGY_HSUPA:
761                rtString = "HSUPA";
762                break;
763            case RIL_RADIO_TECHNOLOGY_HSPA:
764                rtString = "HSPA";
765                break;
766            case RIL_RADIO_TECHNOLOGY_EVDO_B:
767                rtString = "EvDo-rev.B";
768                break;
769            case RIL_RADIO_TECHNOLOGY_EHRPD:
770                rtString = "eHRPD";
771                break;
772            case RIL_RADIO_TECHNOLOGY_LTE:
773                rtString = "LTE";
774                break;
775            case RIL_RADIO_TECHNOLOGY_HSPAP:
776                rtString = "HSPAP";
777                break;
778            case RIL_RADIO_TECHNOLOGY_GSM:
779                rtString = "GSM";
780                break;
781            case RIL_RADIO_TECHNOLOGY_IWLAN:
782                rtString = "IWLAN";
783                break;
784            case RIL_RADIO_TECHNOLOGY_TD_SCDMA:
785                rtString = "TD-SCDMA";
786                break;
787            case RIL_RADIO_TECHNOLOGY_LTE_CA:
788                rtString = "LTE_CA";
789                break;
790            default:
791                rtString = "Unexpected";
792                Rlog.w(LOG_TAG, "Unexpected radioTechnology=" + rt);
793                break;
794        }
795        return rtString;
796    }
797
798    /**
799     * Convert RIL Service State to String
800     *
801     * @param serviceState
802     * @return String representation of the ServiceState
803     *
804     * @hide
805     */
806    public static String rilServiceStateToString(int serviceState) {
807        switch(serviceState) {
808            case STATE_IN_SERVICE:
809                return "IN_SERVICE";
810            case STATE_OUT_OF_SERVICE:
811                return "OUT_OF_SERVICE";
812            case STATE_EMERGENCY_ONLY:
813                return "EMERGENCY_ONLY";
814            case STATE_POWER_OFF:
815                return "POWER_OFF";
816            default:
817                return "UNKNOWN";
818        }
819    }
820
821    @Override
822    public String toString() {
823        return new StringBuilder().append("{mVoiceRegState=").append(mVoiceRegState)
824            .append("(" + rilServiceStateToString(mVoiceRegState) + ")")
825            .append(", mDataRegState=").append(mDataRegState)
826            .append("(" + rilServiceStateToString(mDataRegState) + ")")
827            .append(", mVoiceRoamingType=").append(getRoamingLogString(mVoiceRoamingType))
828            .append(", mDataRoamingType=").append(getRoamingLogString(mDataRoamingType))
829            .append(", mVoiceOperatorAlphaLong=").append(mVoiceOperatorAlphaLong)
830            .append(", mVoiceOperatorAlphaShort=").append(mVoiceOperatorAlphaShort)
831            .append(", mDataOperatorAlphaLong=").append(mDataOperatorAlphaLong)
832            .append(", mDataOperatorAlphaShort=").append(mDataOperatorAlphaShort)
833            .append(", isManualNetworkSelection=").append(mIsManualNetworkSelection)
834            .append(mIsManualNetworkSelection ? "(manual)" : "(automatic)")
835            .append(", mRilVoiceRadioTechnology=").append(mRilVoiceRadioTechnology)
836            .append("(" + rilRadioTechnologyToString(mRilVoiceRadioTechnology) + ")")
837            .append(", mRilDataRadioTechnology=").append(mRilDataRadioTechnology)
838            .append("(" + rilRadioTechnologyToString(mRilDataRadioTechnology) + ")")
839            .append(", mCssIndicator=").append(mCssIndicator ? "supported" : "unsupported")
840            .append(", mNetworkId=").append(mNetworkId)
841            .append(", mSystemId=").append(mSystemId)
842            .append(", mCdmaRoamingIndicator=").append(mCdmaRoamingIndicator)
843            .append(", mCdmaDefaultRoamingIndicator=").append(mCdmaDefaultRoamingIndicator)
844            .append(", mIsEmergencyOnly=").append(mIsEmergencyOnly)
845            .append(", mIsDataRoamingFromRegistration=").append(mIsDataRoamingFromRegistration)
846            .append(", mIsUsingCarrierAggregation=").append(mIsUsingCarrierAggregation)
847            .append(", mLteEarfcnRsrpBoost=").append(mLteEarfcnRsrpBoost)
848            .append("}").toString();
849    }
850
851    private void setNullState(int state) {
852        if (DBG) Rlog.d(LOG_TAG, "[ServiceState] setNullState=" + state);
853        mVoiceRegState = state;
854        mDataRegState = state;
855        mVoiceRoamingType = ROAMING_TYPE_NOT_ROAMING;
856        mDataRoamingType = ROAMING_TYPE_NOT_ROAMING;
857        mVoiceOperatorAlphaLong = null;
858        mVoiceOperatorAlphaShort = null;
859        mVoiceOperatorNumeric = null;
860        mDataOperatorAlphaLong = null;
861        mDataOperatorAlphaShort = null;
862        mDataOperatorNumeric = null;
863        mIsManualNetworkSelection = false;
864        mRilVoiceRadioTechnology = 0;
865        mRilDataRadioTechnology = 0;
866        mCssIndicator = false;
867        mNetworkId = -1;
868        mSystemId = -1;
869        mCdmaRoamingIndicator = -1;
870        mCdmaDefaultRoamingIndicator = -1;
871        mCdmaEriIconIndex = -1;
872        mCdmaEriIconMode = -1;
873        mIsEmergencyOnly = false;
874        mIsDataRoamingFromRegistration = false;
875        mIsUsingCarrierAggregation = false;
876        mLteEarfcnRsrpBoost = 0;
877    }
878
879    public void setStateOutOfService() {
880        setNullState(STATE_OUT_OF_SERVICE);
881    }
882
883    public void setStateOff() {
884        setNullState(STATE_POWER_OFF);
885    }
886
887    public void setState(int state) {
888        setVoiceRegState(state);
889        if (DBG) Rlog.e(LOG_TAG, "[ServiceState] setState deprecated use setVoiceRegState()");
890    }
891
892    /** @hide */
893    public void setVoiceRegState(int state) {
894        mVoiceRegState = state;
895        if (DBG) Rlog.d(LOG_TAG, "[ServiceState] setVoiceRegState=" + mVoiceRegState);
896    }
897
898    /** @hide */
899    public void setDataRegState(int state) {
900        mDataRegState = state;
901        if (VDBG) Rlog.d(LOG_TAG, "[ServiceState] setDataRegState=" + mDataRegState);
902    }
903
904    public void setRoaming(boolean roaming) {
905        mVoiceRoamingType = (roaming ? ROAMING_TYPE_UNKNOWN : ROAMING_TYPE_NOT_ROAMING);
906        mDataRoamingType = mVoiceRoamingType;
907    }
908
909    /** @hide */
910    public void setVoiceRoaming(boolean roaming) {
911        mVoiceRoamingType = (roaming ? ROAMING_TYPE_UNKNOWN : ROAMING_TYPE_NOT_ROAMING);
912    }
913
914    /** @hide */
915    public void setVoiceRoamingType(int type) {
916        mVoiceRoamingType = type;
917    }
918
919    /** @hide */
920    public void setDataRoaming(boolean dataRoaming) {
921        mDataRoamingType = (dataRoaming ? ROAMING_TYPE_UNKNOWN : ROAMING_TYPE_NOT_ROAMING);
922    }
923
924    /** @hide */
925    public void setDataRoamingType(int type) {
926        mDataRoamingType = type;
927    }
928
929    /**
930     * @hide
931     */
932    public void setEmergencyOnly(boolean emergencyOnly) {
933        mIsEmergencyOnly = emergencyOnly;
934    }
935
936    /**
937     * @hide
938     */
939    public void setCdmaRoamingIndicator(int roaming) {
940        this.mCdmaRoamingIndicator = roaming;
941    }
942
943    /**
944     * @hide
945     */
946    public void setCdmaDefaultRoamingIndicator (int roaming) {
947        this.mCdmaDefaultRoamingIndicator = roaming;
948    }
949
950    /**
951     * @hide
952     */
953    public void setCdmaEriIconIndex(int index) {
954        this.mCdmaEriIconIndex = index;
955    }
956
957    /**
958     * @hide
959     */
960    public void setCdmaEriIconMode(int mode) {
961        this.mCdmaEriIconMode = mode;
962    }
963
964    public void setOperatorName(String longName, String shortName, String numeric) {
965        mVoiceOperatorAlphaLong = longName;
966        mVoiceOperatorAlphaShort = shortName;
967        mVoiceOperatorNumeric = numeric;
968        mDataOperatorAlphaLong = longName;
969        mDataOperatorAlphaShort = shortName;
970        mDataOperatorNumeric = numeric;
971    }
972
973    /** @hide */
974    public void setVoiceOperatorName(String longName, String shortName, String numeric) {
975        mVoiceOperatorAlphaLong = longName;
976        mVoiceOperatorAlphaShort = shortName;
977        mVoiceOperatorNumeric = numeric;
978    }
979
980    /** @hide */
981    public void setDataOperatorName(String longName, String shortName, String numeric) {
982        mDataOperatorAlphaLong = longName;
983        mDataOperatorAlphaShort = shortName;
984        mDataOperatorNumeric = numeric;
985    }
986
987    /**
988     * In CDMA, mOperatorAlphaLong can be set from the ERI text.
989     * This is done from the GsmCdmaPhone and not from the ServiceStateTracker.
990     *
991     * @hide
992     */
993    public void setOperatorAlphaLong(String longName) {
994        mVoiceOperatorAlphaLong = longName;
995        mDataOperatorAlphaLong = longName;
996    }
997
998    /** @hide */
999    public void setVoiceOperatorAlphaLong(String longName) {
1000        mVoiceOperatorAlphaLong = longName;
1001    }
1002
1003    /** @hide */
1004    public void setDataOperatorAlphaLong(String longName) {
1005        mDataOperatorAlphaLong = longName;
1006    }
1007
1008    public void setIsManualSelection(boolean isManual) {
1009        mIsManualNetworkSelection = isManual;
1010    }
1011
1012    /**
1013     * Test whether two objects hold the same data values or both are null.
1014     *
1015     * @param a first obj
1016     * @param b second obj
1017     * @return true if two objects equal or both are null
1018     */
1019    private static boolean equalsHandlesNulls (Object a, Object b) {
1020        return (a == null) ? (b == null) : a.equals (b);
1021    }
1022
1023    /**
1024     * Set ServiceState based on intent notifier map.
1025     *
1026     * @param m intent notifier map
1027     * @hide
1028     */
1029    private void setFromNotifierBundle(Bundle m) {
1030        mVoiceRegState = m.getInt("voiceRegState");
1031        mDataRegState = m.getInt("dataRegState");
1032        mVoiceRoamingType = m.getInt("voiceRoamingType");
1033        mDataRoamingType = m.getInt("dataRoamingType");
1034        mVoiceOperatorAlphaLong = m.getString("operator-alpha-long");
1035        mVoiceOperatorAlphaShort = m.getString("operator-alpha-short");
1036        mVoiceOperatorNumeric = m.getString("operator-numeric");
1037        mDataOperatorAlphaLong = m.getString("data-operator-alpha-long");
1038        mDataOperatorAlphaShort = m.getString("data-operator-alpha-short");
1039        mDataOperatorNumeric = m.getString("data-operator-numeric");
1040        mIsManualNetworkSelection = m.getBoolean("manual");
1041        mRilVoiceRadioTechnology = m.getInt("radioTechnology");
1042        mRilDataRadioTechnology = m.getInt("dataRadioTechnology");
1043        mCssIndicator = m.getBoolean("cssIndicator");
1044        mNetworkId = m.getInt("networkId");
1045        mSystemId = m.getInt("systemId");
1046        mCdmaRoamingIndicator = m.getInt("cdmaRoamingIndicator");
1047        mCdmaDefaultRoamingIndicator = m.getInt("cdmaDefaultRoamingIndicator");
1048        mIsEmergencyOnly = m.getBoolean("emergencyOnly");
1049        mIsDataRoamingFromRegistration = m.getBoolean("isDataRoamingFromRegistration");
1050        mIsUsingCarrierAggregation = m.getBoolean("isUsingCarrierAggregation");
1051        mLteEarfcnRsrpBoost = m.getInt("LteEarfcnRsrpBoost");
1052    }
1053
1054    /**
1055     * Set intent notifier Bundle based on service state.
1056     *
1057     * @param m intent notifier Bundle
1058     * @hide
1059     */
1060    public void fillInNotifierBundle(Bundle m) {
1061        m.putInt("voiceRegState", mVoiceRegState);
1062        m.putInt("dataRegState", mDataRegState);
1063        m.putInt("voiceRoamingType", mVoiceRoamingType);
1064        m.putInt("dataRoamingType", mDataRoamingType);
1065        m.putString("operator-alpha-long", mVoiceOperatorAlphaLong);
1066        m.putString("operator-alpha-short", mVoiceOperatorAlphaShort);
1067        m.putString("operator-numeric", mVoiceOperatorNumeric);
1068        m.putString("data-operator-alpha-long", mDataOperatorAlphaLong);
1069        m.putString("data-operator-alpha-short", mDataOperatorAlphaShort);
1070        m.putString("data-operator-numeric", mDataOperatorNumeric);
1071        m.putBoolean("manual", mIsManualNetworkSelection);
1072        m.putInt("radioTechnology", mRilVoiceRadioTechnology);
1073        m.putInt("dataRadioTechnology", mRilDataRadioTechnology);
1074        m.putBoolean("cssIndicator", mCssIndicator);
1075        m.putInt("networkId", mNetworkId);
1076        m.putInt("systemId", mSystemId);
1077        m.putInt("cdmaRoamingIndicator", mCdmaRoamingIndicator);
1078        m.putInt("cdmaDefaultRoamingIndicator", mCdmaDefaultRoamingIndicator);
1079        m.putBoolean("emergencyOnly", mIsEmergencyOnly);
1080        m.putBoolean("isDataRoamingFromRegistration", mIsDataRoamingFromRegistration);
1081        m.putBoolean("isUsingCarrierAggregation", mIsUsingCarrierAggregation);
1082        m.putInt("LteEarfcnRsrpBoost", mLteEarfcnRsrpBoost);
1083    }
1084
1085    /** @hide */
1086    public void setRilVoiceRadioTechnology(int rt) {
1087        if (rt == RIL_RADIO_TECHNOLOGY_LTE_CA) {
1088            rt = RIL_RADIO_TECHNOLOGY_LTE;
1089        }
1090
1091        this.mRilVoiceRadioTechnology = rt;
1092    }
1093
1094    /** @hide */
1095    public void setRilDataRadioTechnology(int rt) {
1096        if (rt == RIL_RADIO_TECHNOLOGY_LTE_CA) {
1097            rt = RIL_RADIO_TECHNOLOGY_LTE;
1098            this.mIsUsingCarrierAggregation = true;
1099        } else {
1100            this.mIsUsingCarrierAggregation = false;
1101        }
1102        this.mRilDataRadioTechnology = rt;
1103        if (VDBG) Rlog.d(LOG_TAG, "[ServiceState] setRilDataRadioTechnology=" +
1104                mRilDataRadioTechnology);
1105    }
1106
1107    /** @hide */
1108    public boolean isUsingCarrierAggregation() {
1109        return mIsUsingCarrierAggregation;
1110    }
1111
1112    /** @hide */
1113    public void setIsUsingCarrierAggregation(boolean ca) {
1114        mIsUsingCarrierAggregation = ca;
1115    }
1116
1117    /** @hide */
1118    public int getLteEarfcnRsrpBoost() {
1119        return mLteEarfcnRsrpBoost;
1120    }
1121
1122    /** @hide */
1123    public void setLteEarfcnRsrpBoost(int LteEarfcnRsrpBoost) {
1124        mLteEarfcnRsrpBoost = LteEarfcnRsrpBoost;
1125    }
1126
1127    /** @hide */
1128    public void setCssIndicator(int css) {
1129        this.mCssIndicator = (css != 0);
1130    }
1131
1132    /** @hide */
1133    public void setSystemAndNetworkId(int systemId, int networkId) {
1134        this.mSystemId = systemId;
1135        this.mNetworkId = networkId;
1136    }
1137
1138    /** @hide */
1139    public int getRilVoiceRadioTechnology() {
1140        return this.mRilVoiceRadioTechnology;
1141    }
1142    /** @hide */
1143    public int getRilDataRadioTechnology() {
1144        return this.mRilDataRadioTechnology;
1145    }
1146    /**
1147     * @hide
1148     * @Deprecated to be removed Q3 2013 use {@link #getRilDataRadioTechnology} or
1149     * {@link #getRilVoiceRadioTechnology}
1150     */
1151    public int getRadioTechnology() {
1152        Rlog.e(LOG_TAG, "ServiceState.getRadioTechnology() DEPRECATED will be removed *******");
1153        return getRilDataRadioTechnology();
1154    }
1155
1156    private int rilRadioTechnologyToNetworkType(int rt) {
1157        switch(rt) {
1158        case ServiceState.RIL_RADIO_TECHNOLOGY_GPRS:
1159            return TelephonyManager.NETWORK_TYPE_GPRS;
1160        case ServiceState.RIL_RADIO_TECHNOLOGY_EDGE:
1161            return TelephonyManager.NETWORK_TYPE_EDGE;
1162        case ServiceState.RIL_RADIO_TECHNOLOGY_UMTS:
1163            return TelephonyManager.NETWORK_TYPE_UMTS;
1164        case ServiceState.RIL_RADIO_TECHNOLOGY_HSDPA:
1165            return TelephonyManager.NETWORK_TYPE_HSDPA;
1166        case ServiceState.RIL_RADIO_TECHNOLOGY_HSUPA:
1167            return TelephonyManager.NETWORK_TYPE_HSUPA;
1168        case ServiceState.RIL_RADIO_TECHNOLOGY_HSPA:
1169            return TelephonyManager.NETWORK_TYPE_HSPA;
1170        case ServiceState.RIL_RADIO_TECHNOLOGY_IS95A:
1171        case ServiceState.RIL_RADIO_TECHNOLOGY_IS95B:
1172            return TelephonyManager.NETWORK_TYPE_CDMA;
1173        case ServiceState.RIL_RADIO_TECHNOLOGY_1xRTT:
1174            return TelephonyManager.NETWORK_TYPE_1xRTT;
1175        case ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_0:
1176            return TelephonyManager.NETWORK_TYPE_EVDO_0;
1177        case ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_A:
1178            return TelephonyManager.NETWORK_TYPE_EVDO_A;
1179        case ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_B:
1180            return TelephonyManager.NETWORK_TYPE_EVDO_B;
1181        case ServiceState.RIL_RADIO_TECHNOLOGY_EHRPD:
1182            return TelephonyManager.NETWORK_TYPE_EHRPD;
1183        case ServiceState.RIL_RADIO_TECHNOLOGY_LTE:
1184            return TelephonyManager.NETWORK_TYPE_LTE;
1185        case ServiceState.RIL_RADIO_TECHNOLOGY_HSPAP:
1186            return TelephonyManager.NETWORK_TYPE_HSPAP;
1187        case ServiceState.RIL_RADIO_TECHNOLOGY_GSM:
1188            return TelephonyManager.NETWORK_TYPE_GSM;
1189        case ServiceState.RIL_RADIO_TECHNOLOGY_TD_SCDMA:
1190            return TelephonyManager.NETWORK_TYPE_TD_SCDMA;
1191        case ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN:
1192            return TelephonyManager.NETWORK_TYPE_IWLAN;
1193        case ServiceState.RIL_RADIO_TECHNOLOGY_LTE_CA:
1194            return TelephonyManager.NETWORK_TYPE_LTE_CA;
1195        default:
1196            return TelephonyManager.NETWORK_TYPE_UNKNOWN;
1197        }
1198    }
1199
1200    /**
1201     * @Deprecated to be removed Q3 2013 use {@link #getVoiceNetworkType}
1202     * @hide
1203     */
1204    public int getNetworkType() {
1205        Rlog.e(LOG_TAG, "ServiceState.getNetworkType() DEPRECATED will be removed *******");
1206        return rilRadioTechnologyToNetworkType(mRilVoiceRadioTechnology);
1207    }
1208
1209    /** @hide */
1210    public int getDataNetworkType() {
1211        return rilRadioTechnologyToNetworkType(mRilDataRadioTechnology);
1212    }
1213
1214    /** @hide */
1215    public int getVoiceNetworkType() {
1216        return rilRadioTechnologyToNetworkType(mRilVoiceRadioTechnology);
1217    }
1218
1219    /** @hide */
1220    public int getCssIndicator() {
1221        return this.mCssIndicator ? 1 : 0;
1222    }
1223
1224    /** @hide */
1225    public int getNetworkId() {
1226        return this.mNetworkId;
1227    }
1228
1229    /** @hide */
1230    public int getSystemId() {
1231        return this.mSystemId;
1232    }
1233
1234    /** @hide */
1235    public static boolean isGsm(int radioTechnology) {
1236        return radioTechnology == RIL_RADIO_TECHNOLOGY_GPRS
1237                || radioTechnology == RIL_RADIO_TECHNOLOGY_EDGE
1238                || radioTechnology == RIL_RADIO_TECHNOLOGY_UMTS
1239                || radioTechnology == RIL_RADIO_TECHNOLOGY_HSDPA
1240                || radioTechnology == RIL_RADIO_TECHNOLOGY_HSUPA
1241                || radioTechnology == RIL_RADIO_TECHNOLOGY_HSPA
1242                || radioTechnology == RIL_RADIO_TECHNOLOGY_LTE
1243                || radioTechnology == RIL_RADIO_TECHNOLOGY_HSPAP
1244                || radioTechnology == RIL_RADIO_TECHNOLOGY_GSM
1245                || radioTechnology == RIL_RADIO_TECHNOLOGY_TD_SCDMA
1246                || radioTechnology == RIL_RADIO_TECHNOLOGY_IWLAN
1247                || radioTechnology == RIL_RADIO_TECHNOLOGY_LTE_CA;
1248
1249    }
1250
1251    /** @hide */
1252    public static boolean isCdma(int radioTechnology) {
1253        return radioTechnology == RIL_RADIO_TECHNOLOGY_IS95A
1254                || radioTechnology == RIL_RADIO_TECHNOLOGY_IS95B
1255                || radioTechnology == RIL_RADIO_TECHNOLOGY_1xRTT
1256                || radioTechnology == RIL_RADIO_TECHNOLOGY_EVDO_0
1257                || radioTechnology == RIL_RADIO_TECHNOLOGY_EVDO_A
1258                || radioTechnology == RIL_RADIO_TECHNOLOGY_EVDO_B
1259                || radioTechnology == RIL_RADIO_TECHNOLOGY_EHRPD;
1260    }
1261
1262    /** @hide */
1263    public static boolean isLte(int radioTechnology) {
1264        return radioTechnology == RIL_RADIO_TECHNOLOGY_LTE ||
1265                radioTechnology == RIL_RADIO_TECHNOLOGY_LTE_CA;
1266    }
1267
1268    /** @hide */
1269    public static boolean bearerBitmapHasCdma(int radioTechnologyBitmap) {
1270        return (RIL_RADIO_CDMA_TECHNOLOGY_BITMASK & radioTechnologyBitmap) != 0;
1271    }
1272
1273    /** @hide */
1274    public static boolean bitmaskHasTech(int bearerBitmask, int radioTech) {
1275        if (bearerBitmask == 0) {
1276            return true;
1277        } else if (radioTech >= 1) {
1278            return ((bearerBitmask & (1 << (radioTech - 1))) != 0);
1279        }
1280        return false;
1281    }
1282
1283    /** @hide */
1284    public static int getBitmaskForTech(int radioTech) {
1285        if (radioTech >= 1) {
1286            return (1 << (radioTech - 1));
1287        }
1288        return 0;
1289    }
1290
1291    /** @hide */
1292    public static int getBitmaskFromString(String bearerList) {
1293        String[] bearers = bearerList.split("\\|");
1294        int bearerBitmask = 0;
1295        for (String bearer : bearers) {
1296            int bearerInt = 0;
1297            try {
1298                bearerInt = Integer.parseInt(bearer.trim());
1299            } catch (NumberFormatException nfe) {
1300                return 0;
1301            }
1302
1303            if (bearerInt == 0) {
1304                return 0;
1305            }
1306
1307            bearerBitmask |= getBitmaskForTech(bearerInt);
1308        }
1309        return bearerBitmask;
1310    }
1311
1312    /**
1313     * Returns a merged ServiceState consisting of the base SS with voice settings from the
1314     * voice SS. The voice SS is only used if it is IN_SERVICE (otherwise the base SS is returned).
1315     * @hide
1316     * */
1317    public static ServiceState mergeServiceStates(ServiceState baseSs, ServiceState voiceSs) {
1318        if (voiceSs.mVoiceRegState != STATE_IN_SERVICE) {
1319            return baseSs;
1320        }
1321
1322        ServiceState newSs = new ServiceState(baseSs);
1323
1324        // voice overrides
1325        newSs.mVoiceRegState = voiceSs.mVoiceRegState;
1326        newSs.mIsEmergencyOnly = false; // only get here if voice is IN_SERVICE
1327
1328        return newSs;
1329    }
1330}
1331