ServiceState.java revision 6b6d5dadfa2fce42df9c7f6445e1b1c9c970d426
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    /**
247     * get String description of roaming type
248     * @hide
249     */
250    public static final String getRoamingLogString(int roamingType) {
251        switch (roamingType) {
252            case ROAMING_TYPE_NOT_ROAMING:
253                return "home";
254
255            case ROAMING_TYPE_UNKNOWN:
256                return "roaming";
257
258            case ROAMING_TYPE_DOMESTIC:
259                return "Domestic Roaming";
260
261            case ROAMING_TYPE_INTERNATIONAL:
262                return "International Roaming";
263
264            default:
265                return "UNKNOWN";
266        }
267    }
268
269    /**
270     * Create a new ServiceState from a intent notifier Bundle
271     *
272     * This method is used by PhoneStateIntentReceiver and maybe by
273     * external applications.
274     *
275     * @param m Bundle from intent notifier
276     * @return newly created ServiceState
277     * @hide
278     */
279    public static ServiceState newFromBundle(Bundle m) {
280        ServiceState ret;
281        ret = new ServiceState();
282        ret.setFromNotifierBundle(m);
283        return ret;
284    }
285
286    /**
287     * Empty constructor
288     */
289    public ServiceState() {
290    }
291
292    /**
293     * Copy constructors
294     *
295     * @param s Source service state
296     */
297    public ServiceState(ServiceState s) {
298        copyFrom(s);
299    }
300
301    protected void copyFrom(ServiceState s) {
302        mVoiceRegState = s.mVoiceRegState;
303        mDataRegState = s.mDataRegState;
304        mVoiceRoamingType = s.mVoiceRoamingType;
305        mDataRoamingType = s.mDataRoamingType;
306        mVoiceOperatorAlphaLong = s.mVoiceOperatorAlphaLong;
307        mVoiceOperatorAlphaShort = s.mVoiceOperatorAlphaShort;
308        mVoiceOperatorNumeric = s.mVoiceOperatorNumeric;
309        mDataOperatorAlphaLong = s.mDataOperatorAlphaLong;
310        mDataOperatorAlphaShort = s.mDataOperatorAlphaShort;
311        mDataOperatorNumeric = s.mDataOperatorNumeric;
312        mIsManualNetworkSelection = s.mIsManualNetworkSelection;
313        mRilVoiceRadioTechnology = s.mRilVoiceRadioTechnology;
314        mRilDataRadioTechnology = s.mRilDataRadioTechnology;
315        mCssIndicator = s.mCssIndicator;
316        mNetworkId = s.mNetworkId;
317        mSystemId = s.mSystemId;
318        mCdmaRoamingIndicator = s.mCdmaRoamingIndicator;
319        mCdmaDefaultRoamingIndicator = s.mCdmaDefaultRoamingIndicator;
320        mCdmaEriIconIndex = s.mCdmaEriIconIndex;
321        mCdmaEriIconMode = s.mCdmaEriIconMode;
322        mIsEmergencyOnly = s.mIsEmergencyOnly;
323        mIsDataRoamingFromRegistration = s.mIsDataRoamingFromRegistration;
324        mIsUsingCarrierAggregation = s.mIsUsingCarrierAggregation;
325    }
326
327    /**
328     * Construct a ServiceState object from the given parcel.
329     */
330    public ServiceState(Parcel in) {
331        mVoiceRegState = in.readInt();
332        mDataRegState = in.readInt();
333        mVoiceRoamingType = in.readInt();
334        mDataRoamingType = in.readInt();
335        mVoiceOperatorAlphaLong = in.readString();
336        mVoiceOperatorAlphaShort = in.readString();
337        mVoiceOperatorNumeric = in.readString();
338        mDataOperatorAlphaLong = in.readString();
339        mDataOperatorAlphaShort = in.readString();
340        mDataOperatorNumeric = in.readString();
341        mIsManualNetworkSelection = in.readInt() != 0;
342        mRilVoiceRadioTechnology = in.readInt();
343        mRilDataRadioTechnology = in.readInt();
344        mCssIndicator = (in.readInt() != 0);
345        mNetworkId = in.readInt();
346        mSystemId = in.readInt();
347        mCdmaRoamingIndicator = in.readInt();
348        mCdmaDefaultRoamingIndicator = in.readInt();
349        mCdmaEriIconIndex = in.readInt();
350        mCdmaEriIconMode = in.readInt();
351        mIsEmergencyOnly = in.readInt() != 0;
352        mIsDataRoamingFromRegistration = in.readInt() != 0;
353        mIsUsingCarrierAggregation = in.readInt() != 0;
354    }
355
356    public void writeToParcel(Parcel out, int flags) {
357        out.writeInt(mVoiceRegState);
358        out.writeInt(mDataRegState);
359        out.writeInt(mVoiceRoamingType);
360        out.writeInt(mDataRoamingType);
361        out.writeString(mVoiceOperatorAlphaLong);
362        out.writeString(mVoiceOperatorAlphaShort);
363        out.writeString(mVoiceOperatorNumeric);
364        out.writeString(mDataOperatorAlphaLong);
365        out.writeString(mDataOperatorAlphaShort);
366        out.writeString(mDataOperatorNumeric);
367        out.writeInt(mIsManualNetworkSelection ? 1 : 0);
368        out.writeInt(mRilVoiceRadioTechnology);
369        out.writeInt(mRilDataRadioTechnology);
370        out.writeInt(mCssIndicator ? 1 : 0);
371        out.writeInt(mNetworkId);
372        out.writeInt(mSystemId);
373        out.writeInt(mCdmaRoamingIndicator);
374        out.writeInt(mCdmaDefaultRoamingIndicator);
375        out.writeInt(mCdmaEriIconIndex);
376        out.writeInt(mCdmaEriIconMode);
377        out.writeInt(mIsEmergencyOnly ? 1 : 0);
378        out.writeInt(mIsDataRoamingFromRegistration ? 1 : 0);
379        out.writeInt(mIsUsingCarrierAggregation ? 1 : 0);
380    }
381
382    public int describeContents() {
383        return 0;
384    }
385
386    public static final Parcelable.Creator<ServiceState> CREATOR =
387            new Parcelable.Creator<ServiceState>() {
388        public ServiceState createFromParcel(Parcel in) {
389            return new ServiceState(in);
390        }
391
392        public ServiceState[] newArray(int size) {
393            return new ServiceState[size];
394        }
395    };
396
397    /**
398     * Get current voice service state
399     */
400    public int getState() {
401        return getVoiceRegState();
402    }
403
404    /**
405     * Get current voice service state
406     *
407     * @see #STATE_IN_SERVICE
408     * @see #STATE_OUT_OF_SERVICE
409     * @see #STATE_EMERGENCY_ONLY
410     * @see #STATE_POWER_OFF
411     *
412     * @hide
413     */
414    public int getVoiceRegState() {
415        return mVoiceRegState;
416    }
417
418    /**
419     * Get current data service state
420     *
421     * @see #STATE_IN_SERVICE
422     * @see #STATE_OUT_OF_SERVICE
423     * @see #STATE_EMERGENCY_ONLY
424     * @see #STATE_POWER_OFF
425     *
426     * @hide
427     */
428    public int getDataRegState() {
429        return mDataRegState;
430    }
431
432    /**
433     * Get current roaming indicator of phone
434     * (note: not just decoding from TS 27.007 7.2)
435     *
436     * @return true if TS 27.007 7.2 roaming is true
437     *              and ONS is different from SPN
438     */
439    public boolean getRoaming() {
440        return getVoiceRoaming() || getDataRoaming();
441    }
442
443    /**
444     * Get current voice network roaming status
445     * @return roaming status
446     * @hide
447     */
448    public boolean getVoiceRoaming() {
449        return mVoiceRoamingType != ROAMING_TYPE_NOT_ROAMING;
450    }
451
452    /**
453     * Get current voice network roaming type
454     * @return roaming type
455     * @hide
456     */
457    public int getVoiceRoamingType() {
458        return mVoiceRoamingType;
459    }
460
461    /**
462     * Get current data network roaming type
463     * @return roaming type
464     * @hide
465     */
466    public boolean getDataRoaming() {
467        return mDataRoamingType != ROAMING_TYPE_NOT_ROAMING;
468    }
469
470    /**
471     * Set whether data network registration state is roaming
472     *
473     * This should only be set to the roaming value received
474     * once the data registration phase has completed.
475     * @hide
476     */
477    public void setDataRoamingFromRegistration(boolean dataRoaming) {
478        mIsDataRoamingFromRegistration = dataRoaming;
479    }
480
481    /**
482     * Get whether data network registration state is roaming
483     * @return true if registration indicates roaming, false otherwise
484     * @hide
485     */
486    public boolean getDataRoamingFromRegistration() {
487        return mIsDataRoamingFromRegistration;
488    }
489
490    /**
491     * Get current data network roaming type
492     * @return roaming type
493     * @hide
494     */
495    public int getDataRoamingType() {
496        return mDataRoamingType;
497    }
498
499    /**
500     * @hide
501     */
502    public boolean isEmergencyOnly() {
503        return mIsEmergencyOnly;
504    }
505
506    /**
507     * @hide
508     */
509    public int getCdmaRoamingIndicator(){
510        return this.mCdmaRoamingIndicator;
511    }
512
513    /**
514     * @hide
515     */
516    public int getCdmaDefaultRoamingIndicator(){
517        return this.mCdmaDefaultRoamingIndicator;
518    }
519
520    /**
521     * @hide
522     */
523    public int getCdmaEriIconIndex() {
524        return this.mCdmaEriIconIndex;
525    }
526
527    /**
528     * @hide
529     */
530    public int getCdmaEriIconMode() {
531        return this.mCdmaEriIconMode;
532    }
533
534    /**
535     * Get current registered operator name in long alphanumeric format.
536     *
537     * In GSM/UMTS, long format can be up to 16 characters long.
538     * In CDMA, returns the ERI text, if set. Otherwise, returns the ONS.
539     *
540     * @return long name of operator, null if unregistered or unknown
541     */
542    public String getOperatorAlphaLong() {
543        return mVoiceOperatorAlphaLong;
544    }
545
546    /**
547     * Get current registered voice network operator name in long alphanumeric format.
548     * @return long name of operator
549     * @hide
550     */
551    public String getVoiceOperatorAlphaLong() {
552        return mVoiceOperatorAlphaLong;
553    }
554
555    /**
556     * Get current registered data network operator name in long alphanumeric format.
557     * @return long name of voice operator
558     * @hide
559     */
560    public String getDataOperatorAlphaLong() {
561        return mDataOperatorAlphaLong;
562    }
563
564    /**
565     * Get current registered operator name in short alphanumeric format.
566     *
567     * In GSM/UMTS, short format can be up to 8 characters long.
568     *
569     * @return short name of operator, null if unregistered or unknown
570     */
571    public String getOperatorAlphaShort() {
572        return mVoiceOperatorAlphaShort;
573    }
574
575    /**
576     * Get current registered voice network operator name in short alphanumeric format.
577     * @return short name of operator, null if unregistered or unknown
578     * @hide
579     */
580    public String getVoiceOperatorAlphaShort() {
581        return mVoiceOperatorAlphaShort;
582    }
583
584    /**
585     * Get current registered data network operator name in short alphanumeric format.
586     * @return short name of operator, null if unregistered or unknown
587     * @hide
588     */
589    public String getDataOperatorAlphaShort() {
590        return mDataOperatorAlphaShort;
591    }
592
593    /**
594     * Get current registered operator name in long alphanumeric format if
595     * available or short otherwise.
596     *
597     * @see #getOperatorAlphaLong
598     * @see #getOperatorAlphaShort
599     *
600     * @return name of operator, null if unregistered or unknown
601     * @hide
602     */
603    public String getOperatorAlpha() {
604        if (TextUtils.isEmpty(mVoiceOperatorAlphaLong)) {
605            return mVoiceOperatorAlphaShort;
606        }
607
608        return mVoiceOperatorAlphaLong;
609    }
610
611    /**
612     * Get current registered operator numeric id.
613     *
614     * In GSM/UMTS, numeric format is 3 digit country code plus 2 or 3 digit
615     * network code.
616     *
617     * @return numeric format of operator, null if unregistered or unknown
618     */
619    /*
620     * The country code can be decoded using
621     * {@link com.android.internal.telephony.MccTable#countryCodeForMcc(int)}.
622     */
623    public String getOperatorNumeric() {
624        return mVoiceOperatorNumeric;
625    }
626
627    /**
628     * Get current registered voice network operator numeric id.
629     * @return numeric format of operator, null if unregistered or unknown
630     * @hide
631     */
632    public String getVoiceOperatorNumeric() {
633        return mVoiceOperatorNumeric;
634    }
635
636    /**
637     * Get current registered data network operator numeric id.
638     * @return numeric format of operator, null if unregistered or unknown
639     * @hide
640     */
641    public String getDataOperatorNumeric() {
642        return mDataOperatorNumeric;
643    }
644
645    /**
646     * Get current network selection mode.
647     *
648     * @return true if manual mode, false if automatic mode
649     */
650    public boolean getIsManualSelection() {
651        return mIsManualNetworkSelection;
652    }
653
654    @Override
655    public int hashCode() {
656        return ((mVoiceRegState * 31)
657                + (mDataRegState * 37)
658                + mVoiceRoamingType
659                + mDataRoamingType
660                + (mIsManualNetworkSelection ? 1 : 0)
661                + ((null == mVoiceOperatorAlphaLong) ? 0 : mVoiceOperatorAlphaLong.hashCode())
662                + ((null == mVoiceOperatorAlphaShort) ? 0 : mVoiceOperatorAlphaShort.hashCode())
663                + ((null == mVoiceOperatorNumeric) ? 0 : mVoiceOperatorNumeric.hashCode())
664                + ((null == mDataOperatorAlphaLong) ? 0 : mDataOperatorAlphaLong.hashCode())
665                + ((null == mDataOperatorAlphaShort) ? 0 : mDataOperatorAlphaShort.hashCode())
666                + ((null == mDataOperatorNumeric) ? 0 : mDataOperatorNumeric.hashCode())
667                + mCdmaRoamingIndicator
668                + mCdmaDefaultRoamingIndicator
669                + (mIsEmergencyOnly ? 1 : 0)
670                + (mIsDataRoamingFromRegistration ? 1 : 0));
671    }
672
673    @Override
674    public boolean equals (Object o) {
675        ServiceState s;
676
677        try {
678            s = (ServiceState) o;
679        } catch (ClassCastException ex) {
680            return false;
681        }
682
683        if (o == null) {
684            return false;
685        }
686
687        return (mVoiceRegState == s.mVoiceRegState
688                && mDataRegState == s.mDataRegState
689                && mIsManualNetworkSelection == s.mIsManualNetworkSelection
690                && mVoiceRoamingType == s.mVoiceRoamingType
691                && mDataRoamingType == s.mDataRoamingType
692                && equalsHandlesNulls(mVoiceOperatorAlphaLong, s.mVoiceOperatorAlphaLong)
693                && equalsHandlesNulls(mVoiceOperatorAlphaShort, s.mVoiceOperatorAlphaShort)
694                && equalsHandlesNulls(mVoiceOperatorNumeric, s.mVoiceOperatorNumeric)
695                && equalsHandlesNulls(mDataOperatorAlphaLong, s.mDataOperatorAlphaLong)
696                && equalsHandlesNulls(mDataOperatorAlphaShort, s.mDataOperatorAlphaShort)
697                && equalsHandlesNulls(mDataOperatorNumeric, s.mDataOperatorNumeric)
698                && equalsHandlesNulls(mRilVoiceRadioTechnology, s.mRilVoiceRadioTechnology)
699                && equalsHandlesNulls(mRilDataRadioTechnology, s.mRilDataRadioTechnology)
700                && equalsHandlesNulls(mCssIndicator, s.mCssIndicator)
701                && equalsHandlesNulls(mNetworkId, s.mNetworkId)
702                && equalsHandlesNulls(mSystemId, s.mSystemId)
703                && equalsHandlesNulls(mCdmaRoamingIndicator, s.mCdmaRoamingIndicator)
704                && equalsHandlesNulls(mCdmaDefaultRoamingIndicator,
705                        s.mCdmaDefaultRoamingIndicator)
706                && mIsEmergencyOnly == s.mIsEmergencyOnly
707                && mIsDataRoamingFromRegistration == s.mIsDataRoamingFromRegistration
708                && mIsUsingCarrierAggregation == s.mIsUsingCarrierAggregation);
709    }
710
711    /**
712     * Convert radio technology to String
713     *
714     * @param radioTechnology
715     * @return String representation of the RAT
716     *
717     * @hide
718     */
719    public static String rilRadioTechnologyToString(int rt) {
720        String rtString;
721
722        switch(rt) {
723            case RIL_RADIO_TECHNOLOGY_UNKNOWN:
724                rtString = "Unknown";
725                break;
726            case RIL_RADIO_TECHNOLOGY_GPRS:
727                rtString = "GPRS";
728                break;
729            case RIL_RADIO_TECHNOLOGY_EDGE:
730                rtString = "EDGE";
731                break;
732            case RIL_RADIO_TECHNOLOGY_UMTS:
733                rtString = "UMTS";
734                break;
735            case RIL_RADIO_TECHNOLOGY_IS95A:
736                rtString = "CDMA-IS95A";
737                break;
738            case RIL_RADIO_TECHNOLOGY_IS95B:
739                rtString = "CDMA-IS95B";
740                break;
741            case RIL_RADIO_TECHNOLOGY_1xRTT:
742                rtString = "1xRTT";
743                break;
744            case RIL_RADIO_TECHNOLOGY_EVDO_0:
745                rtString = "EvDo-rev.0";
746                break;
747            case RIL_RADIO_TECHNOLOGY_EVDO_A:
748                rtString = "EvDo-rev.A";
749                break;
750            case RIL_RADIO_TECHNOLOGY_HSDPA:
751                rtString = "HSDPA";
752                break;
753            case RIL_RADIO_TECHNOLOGY_HSUPA:
754                rtString = "HSUPA";
755                break;
756            case RIL_RADIO_TECHNOLOGY_HSPA:
757                rtString = "HSPA";
758                break;
759            case RIL_RADIO_TECHNOLOGY_EVDO_B:
760                rtString = "EvDo-rev.B";
761                break;
762            case RIL_RADIO_TECHNOLOGY_EHRPD:
763                rtString = "eHRPD";
764                break;
765            case RIL_RADIO_TECHNOLOGY_LTE:
766                rtString = "LTE";
767                break;
768            case RIL_RADIO_TECHNOLOGY_HSPAP:
769                rtString = "HSPAP";
770                break;
771            case RIL_RADIO_TECHNOLOGY_GSM:
772                rtString = "GSM";
773                break;
774            case RIL_RADIO_TECHNOLOGY_IWLAN:
775                rtString = "IWLAN";
776                break;
777            case RIL_RADIO_TECHNOLOGY_TD_SCDMA:
778                rtString = "TD-SCDMA";
779                break;
780            case RIL_RADIO_TECHNOLOGY_LTE_CA:
781                rtString = "LTE_CA";
782                break;
783            default:
784                rtString = "Unexpected";
785                Rlog.w(LOG_TAG, "Unexpected radioTechnology=" + rt);
786                break;
787        }
788        return rtString;
789    }
790
791    @Override
792    public String toString() {
793        String radioTechnology = rilRadioTechnologyToString(mRilVoiceRadioTechnology);
794        String dataRadioTechnology = rilRadioTechnologyToString(mRilDataRadioTechnology);
795
796        return (mVoiceRegState + " " + mDataRegState
797                + " "
798                + "voice " + getRoamingLogString(mVoiceRoamingType)
799                + " "
800                + "data " + getRoamingLogString(mDataRoamingType)
801                + " " + mVoiceOperatorAlphaLong
802                + " " + mVoiceOperatorAlphaShort
803                + " " + mVoiceOperatorNumeric
804                + " " + mDataOperatorAlphaLong
805                + " " + mDataOperatorAlphaShort
806                + " " + mDataOperatorNumeric
807                + " " + (mIsManualNetworkSelection ? "(manual)" : "")
808                + " " + radioTechnology
809                + " " + dataRadioTechnology
810                + " " + (mCssIndicator ? "CSS supported" : "CSS not supported")
811                + " " + mNetworkId
812                + " " + mSystemId
813                + " RoamInd=" + mCdmaRoamingIndicator
814                + " DefRoamInd=" + mCdmaDefaultRoamingIndicator
815                + " EmergOnly=" + mIsEmergencyOnly
816                + " IsDataRoamingFromRegistration=" + mIsDataRoamingFromRegistration
817                + " IsUsingCarrierAggregation=" + mIsUsingCarrierAggregation);
818    }
819
820    private void setNullState(int state) {
821        if (DBG) Rlog.d(LOG_TAG, "[ServiceState] setNullState=" + state);
822        mVoiceRegState = state;
823        mDataRegState = state;
824        mVoiceRoamingType = ROAMING_TYPE_NOT_ROAMING;
825        mDataRoamingType = ROAMING_TYPE_NOT_ROAMING;
826        mVoiceOperatorAlphaLong = null;
827        mVoiceOperatorAlphaShort = null;
828        mVoiceOperatorNumeric = null;
829        mDataOperatorAlphaLong = null;
830        mDataOperatorAlphaShort = null;
831        mDataOperatorNumeric = null;
832        mIsManualNetworkSelection = false;
833        mRilVoiceRadioTechnology = 0;
834        mRilDataRadioTechnology = 0;
835        mCssIndicator = false;
836        mNetworkId = -1;
837        mSystemId = -1;
838        mCdmaRoamingIndicator = -1;
839        mCdmaDefaultRoamingIndicator = -1;
840        mCdmaEriIconIndex = -1;
841        mCdmaEriIconMode = -1;
842        mIsEmergencyOnly = false;
843        mIsDataRoamingFromRegistration = false;
844        mIsUsingCarrierAggregation = false;
845    }
846
847    public void setStateOutOfService() {
848        setNullState(STATE_OUT_OF_SERVICE);
849    }
850
851    public void setStateOff() {
852        setNullState(STATE_POWER_OFF);
853    }
854
855    public void setState(int state) {
856        setVoiceRegState(state);
857        if (DBG) Rlog.e(LOG_TAG, "[ServiceState] setState deprecated use setVoiceRegState()");
858    }
859
860    /** @hide */
861    public void setVoiceRegState(int state) {
862        mVoiceRegState = state;
863        if (DBG) Rlog.d(LOG_TAG, "[ServiceState] setVoiceRegState=" + mVoiceRegState);
864    }
865
866    /** @hide */
867    public void setDataRegState(int state) {
868        mDataRegState = state;
869        if (VDBG) Rlog.d(LOG_TAG, "[ServiceState] setDataRegState=" + mDataRegState);
870    }
871
872    public void setRoaming(boolean roaming) {
873        mVoiceRoamingType = (roaming ? ROAMING_TYPE_UNKNOWN : ROAMING_TYPE_NOT_ROAMING);
874        mDataRoamingType = mVoiceRoamingType;
875    }
876
877    /** @hide */
878    public void setVoiceRoaming(boolean roaming) {
879        mVoiceRoamingType = (roaming ? ROAMING_TYPE_UNKNOWN : ROAMING_TYPE_NOT_ROAMING);
880    }
881
882    /** @hide */
883    public void setVoiceRoamingType(int type) {
884        mVoiceRoamingType = type;
885    }
886
887    /** @hide */
888    public void setDataRoaming(boolean dataRoaming) {
889        mDataRoamingType = (dataRoaming ? ROAMING_TYPE_UNKNOWN : ROAMING_TYPE_NOT_ROAMING);
890    }
891
892    /** @hide */
893    public void setDataRoamingType(int type) {
894        mDataRoamingType = type;
895    }
896
897    /**
898     * @hide
899     */
900    public void setEmergencyOnly(boolean emergencyOnly) {
901        mIsEmergencyOnly = emergencyOnly;
902    }
903
904    /**
905     * @hide
906     */
907    public void setCdmaRoamingIndicator(int roaming) {
908        this.mCdmaRoamingIndicator = roaming;
909    }
910
911    /**
912     * @hide
913     */
914    public void setCdmaDefaultRoamingIndicator (int roaming) {
915        this.mCdmaDefaultRoamingIndicator = roaming;
916    }
917
918    /**
919     * @hide
920     */
921    public void setCdmaEriIconIndex(int index) {
922        this.mCdmaEriIconIndex = index;
923    }
924
925    /**
926     * @hide
927     */
928    public void setCdmaEriIconMode(int mode) {
929        this.mCdmaEriIconMode = mode;
930    }
931
932    public void setOperatorName(String longName, String shortName, String numeric) {
933        mVoiceOperatorAlphaLong = longName;
934        mVoiceOperatorAlphaShort = shortName;
935        mVoiceOperatorNumeric = numeric;
936        mDataOperatorAlphaLong = longName;
937        mDataOperatorAlphaShort = shortName;
938        mDataOperatorNumeric = numeric;
939    }
940
941    /** @hide */
942    public void setVoiceOperatorName(String longName, String shortName, String numeric) {
943        mVoiceOperatorAlphaLong = longName;
944        mVoiceOperatorAlphaShort = shortName;
945        mVoiceOperatorNumeric = numeric;
946    }
947
948    /** @hide */
949    public void setDataOperatorName(String longName, String shortName, String numeric) {
950        mDataOperatorAlphaLong = longName;
951        mDataOperatorAlphaShort = shortName;
952        mDataOperatorNumeric = numeric;
953    }
954
955    /**
956     * In CDMA, mOperatorAlphaLong can be set from the ERI text.
957     * This is done from the GsmCdmaPhone and not from the ServiceStateTracker.
958     *
959     * @hide
960     */
961    public void setOperatorAlphaLong(String longName) {
962        mVoiceOperatorAlphaLong = longName;
963        mDataOperatorAlphaLong = longName;
964    }
965
966    /** @hide */
967    public void setVoiceOperatorAlphaLong(String longName) {
968        mVoiceOperatorAlphaLong = longName;
969    }
970
971    /** @hide */
972    public void setDataOperatorAlphaLong(String longName) {
973        mDataOperatorAlphaLong = longName;
974    }
975
976    public void setIsManualSelection(boolean isManual) {
977        mIsManualNetworkSelection = isManual;
978    }
979
980    /**
981     * Test whether two objects hold the same data values or both are null.
982     *
983     * @param a first obj
984     * @param b second obj
985     * @return true if two objects equal or both are null
986     */
987    private static boolean equalsHandlesNulls (Object a, Object b) {
988        return (a == null) ? (b == null) : a.equals (b);
989    }
990
991    /**
992     * Set ServiceState based on intent notifier map.
993     *
994     * @param m intent notifier map
995     * @hide
996     */
997    private void setFromNotifierBundle(Bundle m) {
998        mVoiceRegState = m.getInt("voiceRegState");
999        mDataRegState = m.getInt("dataRegState");
1000        mVoiceRoamingType = m.getInt("voiceRoamingType");
1001        mDataRoamingType = m.getInt("dataRoamingType");
1002        mVoiceOperatorAlphaLong = m.getString("operator-alpha-long");
1003        mVoiceOperatorAlphaShort = m.getString("operator-alpha-short");
1004        mVoiceOperatorNumeric = m.getString("operator-numeric");
1005        mDataOperatorAlphaLong = m.getString("data-operator-alpha-long");
1006        mDataOperatorAlphaShort = m.getString("data-operator-alpha-short");
1007        mDataOperatorNumeric = m.getString("data-operator-numeric");
1008        mIsManualNetworkSelection = m.getBoolean("manual");
1009        mRilVoiceRadioTechnology = m.getInt("radioTechnology");
1010        mRilDataRadioTechnology = m.getInt("dataRadioTechnology");
1011        mCssIndicator = m.getBoolean("cssIndicator");
1012        mNetworkId = m.getInt("networkId");
1013        mSystemId = m.getInt("systemId");
1014        mCdmaRoamingIndicator = m.getInt("cdmaRoamingIndicator");
1015        mCdmaDefaultRoamingIndicator = m.getInt("cdmaDefaultRoamingIndicator");
1016        mIsEmergencyOnly = m.getBoolean("emergencyOnly");
1017        mIsDataRoamingFromRegistration = m.getBoolean("isDataRoamingFromRegistration");
1018        mIsUsingCarrierAggregation = m.getBoolean("isUsingCarrierAggregation");
1019    }
1020
1021    /**
1022     * Set intent notifier Bundle based on service state.
1023     *
1024     * @param m intent notifier Bundle
1025     * @hide
1026     */
1027    public void fillInNotifierBundle(Bundle m) {
1028        m.putInt("voiceRegState", mVoiceRegState);
1029        m.putInt("dataRegState", mDataRegState);
1030        m.putInt("voiceRoamingType", mVoiceRoamingType);
1031        m.putInt("dataRoamingType", mDataRoamingType);
1032        m.putString("operator-alpha-long", mVoiceOperatorAlphaLong);
1033        m.putString("operator-alpha-short", mVoiceOperatorAlphaShort);
1034        m.putString("operator-numeric", mVoiceOperatorNumeric);
1035        m.putString("data-operator-alpha-long", mDataOperatorAlphaLong);
1036        m.putString("data-operator-alpha-short", mDataOperatorAlphaShort);
1037        m.putString("data-operator-numeric", mDataOperatorNumeric);
1038        m.putBoolean("manual", mIsManualNetworkSelection);
1039        m.putInt("radioTechnology", mRilVoiceRadioTechnology);
1040        m.putInt("dataRadioTechnology", mRilDataRadioTechnology);
1041        m.putBoolean("cssIndicator", mCssIndicator);
1042        m.putInt("networkId", mNetworkId);
1043        m.putInt("systemId", mSystemId);
1044        m.putInt("cdmaRoamingIndicator", mCdmaRoamingIndicator);
1045        m.putInt("cdmaDefaultRoamingIndicator", mCdmaDefaultRoamingIndicator);
1046        m.putBoolean("emergencyOnly", mIsEmergencyOnly);
1047        m.putBoolean("isDataRoamingFromRegistration", mIsDataRoamingFromRegistration);
1048        m.putBoolean("isUsingCarrierAggregation", mIsUsingCarrierAggregation);
1049    }
1050
1051    /** @hide */
1052    public void setRilVoiceRadioTechnology(int rt) {
1053        if (rt == RIL_RADIO_TECHNOLOGY_LTE_CA) {
1054            rt = RIL_RADIO_TECHNOLOGY_LTE;
1055        }
1056
1057        this.mRilVoiceRadioTechnology = rt;
1058    }
1059
1060    /** @hide */
1061    public void setRilDataRadioTechnology(int rt) {
1062        if (rt == RIL_RADIO_TECHNOLOGY_LTE_CA) {
1063            rt = RIL_RADIO_TECHNOLOGY_LTE;
1064            this.mIsUsingCarrierAggregation = true;
1065        } else {
1066            this.mIsUsingCarrierAggregation = false;
1067        }
1068        this.mRilDataRadioTechnology = rt;
1069        if (VDBG) Rlog.d(LOG_TAG, "[ServiceState] setRilDataRadioTechnology=" +
1070                mRilDataRadioTechnology);
1071    }
1072
1073    /** @hide */
1074    public boolean isUsingCarrierAggregation() {
1075        return mIsUsingCarrierAggregation;
1076    }
1077
1078    /** @hide */
1079    public void setIsUsingCarrierAggregation(boolean ca) {
1080        mIsUsingCarrierAggregation = ca;
1081    }
1082
1083    /** @hide */
1084    public void setCssIndicator(int css) {
1085        this.mCssIndicator = (css != 0);
1086    }
1087
1088    /** @hide */
1089    public void setSystemAndNetworkId(int systemId, int networkId) {
1090        this.mSystemId = systemId;
1091        this.mNetworkId = networkId;
1092    }
1093
1094    /** @hide */
1095    public int getRilVoiceRadioTechnology() {
1096        return this.mRilVoiceRadioTechnology;
1097    }
1098    /** @hide */
1099    public int getRilDataRadioTechnology() {
1100        return this.mRilDataRadioTechnology;
1101    }
1102    /**
1103     * @hide
1104     * @Deprecated to be removed Q3 2013 use {@link #getRilDataRadioTechnology} or
1105     * {@link #getRilVoiceRadioTechnology}
1106     */
1107    public int getRadioTechnology() {
1108        Rlog.e(LOG_TAG, "ServiceState.getRadioTechnology() DEPRECATED will be removed *******");
1109        return getRilDataRadioTechnology();
1110    }
1111
1112    private int rilRadioTechnologyToNetworkType(int rt) {
1113        switch(rt) {
1114        case ServiceState.RIL_RADIO_TECHNOLOGY_GPRS:
1115            return TelephonyManager.NETWORK_TYPE_GPRS;
1116        case ServiceState.RIL_RADIO_TECHNOLOGY_EDGE:
1117            return TelephonyManager.NETWORK_TYPE_EDGE;
1118        case ServiceState.RIL_RADIO_TECHNOLOGY_UMTS:
1119            return TelephonyManager.NETWORK_TYPE_UMTS;
1120        case ServiceState.RIL_RADIO_TECHNOLOGY_HSDPA:
1121            return TelephonyManager.NETWORK_TYPE_HSDPA;
1122        case ServiceState.RIL_RADIO_TECHNOLOGY_HSUPA:
1123            return TelephonyManager.NETWORK_TYPE_HSUPA;
1124        case ServiceState.RIL_RADIO_TECHNOLOGY_HSPA:
1125            return TelephonyManager.NETWORK_TYPE_HSPA;
1126        case ServiceState.RIL_RADIO_TECHNOLOGY_IS95A:
1127        case ServiceState.RIL_RADIO_TECHNOLOGY_IS95B:
1128            return TelephonyManager.NETWORK_TYPE_CDMA;
1129        case ServiceState.RIL_RADIO_TECHNOLOGY_1xRTT:
1130            return TelephonyManager.NETWORK_TYPE_1xRTT;
1131        case ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_0:
1132            return TelephonyManager.NETWORK_TYPE_EVDO_0;
1133        case ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_A:
1134            return TelephonyManager.NETWORK_TYPE_EVDO_A;
1135        case ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_B:
1136            return TelephonyManager.NETWORK_TYPE_EVDO_B;
1137        case ServiceState.RIL_RADIO_TECHNOLOGY_EHRPD:
1138            return TelephonyManager.NETWORK_TYPE_EHRPD;
1139        case ServiceState.RIL_RADIO_TECHNOLOGY_LTE:
1140            return TelephonyManager.NETWORK_TYPE_LTE;
1141        case ServiceState.RIL_RADIO_TECHNOLOGY_HSPAP:
1142            return TelephonyManager.NETWORK_TYPE_HSPAP;
1143        case ServiceState.RIL_RADIO_TECHNOLOGY_GSM:
1144            return TelephonyManager.NETWORK_TYPE_GSM;
1145        case ServiceState.RIL_RADIO_TECHNOLOGY_TD_SCDMA:
1146            return TelephonyManager.NETWORK_TYPE_TD_SCDMA;
1147        case ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN:
1148            return TelephonyManager.NETWORK_TYPE_IWLAN;
1149        case ServiceState.RIL_RADIO_TECHNOLOGY_LTE_CA:
1150            return TelephonyManager.NETWORK_TYPE_LTE_CA;
1151        default:
1152            return TelephonyManager.NETWORK_TYPE_UNKNOWN;
1153        }
1154    }
1155
1156    /**
1157     * @Deprecated to be removed Q3 2013 use {@link #getVoiceNetworkType}
1158     * @hide
1159     */
1160    public int getNetworkType() {
1161        Rlog.e(LOG_TAG, "ServiceState.getNetworkType() DEPRECATED will be removed *******");
1162        return rilRadioTechnologyToNetworkType(mRilVoiceRadioTechnology);
1163    }
1164
1165    /** @hide */
1166    public int getDataNetworkType() {
1167        return rilRadioTechnologyToNetworkType(mRilDataRadioTechnology);
1168    }
1169
1170    /** @hide */
1171    public int getVoiceNetworkType() {
1172        return rilRadioTechnologyToNetworkType(mRilVoiceRadioTechnology);
1173    }
1174
1175    /** @hide */
1176    public int getCssIndicator() {
1177        return this.mCssIndicator ? 1 : 0;
1178    }
1179
1180    /** @hide */
1181    public int getNetworkId() {
1182        return this.mNetworkId;
1183    }
1184
1185    /** @hide */
1186    public int getSystemId() {
1187        return this.mSystemId;
1188    }
1189
1190    /** @hide */
1191    public static boolean isGsm(int radioTechnology) {
1192        return radioTechnology == RIL_RADIO_TECHNOLOGY_GPRS
1193                || radioTechnology == RIL_RADIO_TECHNOLOGY_EDGE
1194                || radioTechnology == RIL_RADIO_TECHNOLOGY_UMTS
1195                || radioTechnology == RIL_RADIO_TECHNOLOGY_HSDPA
1196                || radioTechnology == RIL_RADIO_TECHNOLOGY_HSUPA
1197                || radioTechnology == RIL_RADIO_TECHNOLOGY_HSPA
1198                || radioTechnology == RIL_RADIO_TECHNOLOGY_LTE
1199                || radioTechnology == RIL_RADIO_TECHNOLOGY_HSPAP
1200                || radioTechnology == RIL_RADIO_TECHNOLOGY_GSM
1201                || radioTechnology == RIL_RADIO_TECHNOLOGY_TD_SCDMA
1202                || radioTechnology == RIL_RADIO_TECHNOLOGY_IWLAN
1203                || radioTechnology == RIL_RADIO_TECHNOLOGY_LTE_CA;
1204
1205    }
1206
1207    /** @hide */
1208    public static boolean isCdma(int radioTechnology) {
1209        return radioTechnology == RIL_RADIO_TECHNOLOGY_IS95A
1210                || radioTechnology == RIL_RADIO_TECHNOLOGY_IS95B
1211                || radioTechnology == RIL_RADIO_TECHNOLOGY_1xRTT
1212                || radioTechnology == RIL_RADIO_TECHNOLOGY_EVDO_0
1213                || radioTechnology == RIL_RADIO_TECHNOLOGY_EVDO_A
1214                || radioTechnology == RIL_RADIO_TECHNOLOGY_EVDO_B
1215                || radioTechnology == RIL_RADIO_TECHNOLOGY_EHRPD;
1216    }
1217
1218    /** @hide */
1219    public static boolean isLte(int radioTechnology) {
1220        return radioTechnology == RIL_RADIO_TECHNOLOGY_LTE ||
1221                radioTechnology == RIL_RADIO_TECHNOLOGY_LTE_CA;
1222    }
1223
1224    /** @hide */
1225    public static boolean bearerBitmapHasCdma(int radioTechnologyBitmap) {
1226        return (RIL_RADIO_CDMA_TECHNOLOGY_BITMASK & radioTechnologyBitmap) != 0;
1227    }
1228
1229    /** @hide */
1230    public static boolean bitmaskHasTech(int bearerBitmask, int radioTech) {
1231        if (bearerBitmask == 0) {
1232            return true;
1233        } else if (radioTech >= 1) {
1234            return ((bearerBitmask & (1 << (radioTech - 1))) != 0);
1235        }
1236        return false;
1237    }
1238
1239    /** @hide */
1240    public static int getBitmaskForTech(int radioTech) {
1241        if (radioTech >= 1) {
1242            return (1 << (radioTech - 1));
1243        }
1244        return 0;
1245    }
1246
1247    /** @hide */
1248    public static int getBitmaskFromString(String bearerList) {
1249        String[] bearers = bearerList.split("\\|");
1250        int bearerBitmask = 0;
1251        for (String bearer : bearers) {
1252            int bearerInt = 0;
1253            try {
1254                bearerInt = Integer.parseInt(bearer.trim());
1255            } catch (NumberFormatException nfe) {
1256                return 0;
1257            }
1258
1259            if (bearerInt == 0) {
1260                return 0;
1261            }
1262
1263            bearerBitmask |= getBitmaskForTech(bearerInt);
1264        }
1265        return bearerBitmask;
1266    }
1267
1268    /**
1269     * Returns a merged ServiceState consisting of the base SS with voice settings from the
1270     * voice SS. The voice SS is only used if it is IN_SERVICE (otherwise the base SS is returned).
1271     * @hide
1272     * */
1273    public static ServiceState mergeServiceStates(ServiceState baseSs, ServiceState voiceSs) {
1274        if (voiceSs.mVoiceRegState != STATE_IN_SERVICE) {
1275            return baseSs;
1276        }
1277
1278        ServiceState newSs = new ServiceState(baseSs);
1279
1280        // voice overrides
1281        newSs.mVoiceRegState = voiceSs.mVoiceRegState;
1282        newSs.mIsEmergencyOnly = false; // only get here if voice is IN_SERVICE
1283
1284        return newSs;
1285    }
1286}
1287