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