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