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