• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.NonNull;
21 import android.annotation.Nullable;
22 import android.annotation.SystemApi;
23 import android.annotation.TestApi;
24 import android.compat.annotation.UnsupportedAppUsage;
25 import android.content.Intent;
26 import android.os.Build;
27 import android.os.Bundle;
28 import android.os.Parcel;
29 import android.os.Parcelable;
30 import android.telephony.AccessNetworkConstants.AccessNetworkType;
31 import android.telephony.AccessNetworkConstants.TransportType;
32 import android.telephony.Annotation.NetworkType;
33 import android.telephony.NetworkRegistrationInfo.Domain;
34 import android.telephony.NetworkRegistrationInfo.NRState;
35 import android.text.TextUtils;
36 
37 import com.android.telephony.Rlog;
38 
39 import java.lang.annotation.Retention;
40 import java.lang.annotation.RetentionPolicy;
41 import java.util.ArrayList;
42 import java.util.Arrays;
43 import java.util.List;
44 import java.util.Objects;
45 import java.util.stream.Collectors;
46 
47 /**
48  * Contains phone state and service related information.
49  *
50  * The following phone information is included in returned ServiceState:
51  *
52  * <ul>
53  *   <li>Service state: IN_SERVICE, OUT_OF_SERVICE, EMERGENCY_ONLY, POWER_OFF
54  *   <li>Duplex mode: UNKNOWN, FDD, TDD
55  *   <li>Roaming indicator
56  *   <li>Operator name, short name and numeric id
57  *   <li>Network selection mode
58  * </ul>
59  *
60  * For historical reasons this class is not declared as final; however,
61  * it should be treated as though it were final.
62  */
63 public class ServiceState implements Parcelable {
64 
65     static final String LOG_TAG = "PHONE";
66     static final boolean DBG = false;
67     static final boolean VDBG = false;  // STOPSHIP if true
68 
69     /** @hide */
70     @Retention(RetentionPolicy.SOURCE)
71     @IntDef(prefix = "STATE_",
72             value = {STATE_IN_SERVICE, STATE_OUT_OF_SERVICE, STATE_EMERGENCY_ONLY,
73                     STATE_POWER_OFF})
74     public @interface RegState {}
75 
76     /**
77      * Normal operation condition, the phone is registered
78      * with an operator either in home network or in roaming.
79      */
80     public static final int STATE_IN_SERVICE = TelephonyProtoEnums.SERVICE_STATE_IN_SERVICE; // 0
81 
82     /**
83      * Phone is not registered with any operator, the phone
84      * can be currently searching a new operator to register to, or not
85      * searching to registration at all, or registration is denied, or radio
86      * signal is not available.
87      */
88     public static final int STATE_OUT_OF_SERVICE =
89             TelephonyProtoEnums.SERVICE_STATE_OUT_OF_SERVICE;  // 1
90 
91     /**
92      * The phone is registered and locked.  Only emergency numbers are allowed. {@more}
93      */
94     //TODO: This state is not used anymore. It should be deprecated in a future release.
95     public static final int STATE_EMERGENCY_ONLY =
96             TelephonyProtoEnums.SERVICE_STATE_EMERGENCY_ONLY;  // 2
97 
98     /**
99      * Radio of telephony is explicitly powered off.
100      */
101     public static final int STATE_POWER_OFF = TelephonyProtoEnums.SERVICE_STATE_POWER_OFF;  // 3
102 
103     /** @hide */
104     @Retention(RetentionPolicy.SOURCE)
105     @IntDef(prefix = "FREQUENCY_RANGE_",
106             value = {FREQUENCY_RANGE_UNKNOWN, FREQUENCY_RANGE_LOW, FREQUENCY_RANGE_MID,
107                     FREQUENCY_RANGE_HIGH, FREQUENCY_RANGE_MMWAVE})
108     public @interface FrequencyRange {}
109 
110     /**
111      * Indicates frequency range is unknown.
112      * @hide
113      */
114     public static final int FREQUENCY_RANGE_UNKNOWN = 0;
115 
116     /**
117      * Indicates the frequency range is below 1GHz.
118      * @hide
119      */
120     public static final int FREQUENCY_RANGE_LOW = 1;
121 
122     /**
123      * Indicates the frequency range is between 1GHz to 3GHz.
124      * @hide
125      */
126     public static final int FREQUENCY_RANGE_MID = 2;
127 
128     /**
129      * Indicates the frequency range is between 3GHz and 6GHz.
130      * @hide
131      */
132     public static final int FREQUENCY_RANGE_HIGH = 3;
133 
134     /**
135      * Indicates the frequency range is above 6GHz (millimeter wave frequency).
136      * @hide
137      */
138     public static final int FREQUENCY_RANGE_MMWAVE = 4;
139 
140     private static final List<Integer> FREQUENCY_RANGE_ORDER = Arrays.asList(
141             FREQUENCY_RANGE_UNKNOWN,
142             FREQUENCY_RANGE_LOW,
143             FREQUENCY_RANGE_MID,
144             FREQUENCY_RANGE_HIGH,
145             FREQUENCY_RANGE_MMWAVE);
146 
147     /** @hide */
148     @Retention(RetentionPolicy.SOURCE)
149     @IntDef(prefix = "DUPLEX_MODE_",
150             value = {DUPLEX_MODE_UNKNOWN, DUPLEX_MODE_FDD, DUPLEX_MODE_TDD})
151     public @interface DuplexMode {}
152 
153     /**
154      * Duplex mode for the phone is unknown.
155      */
156     public static final int DUPLEX_MODE_UNKNOWN = 0;
157 
158     /**
159      * Duplex mode for the phone is frequency-division duplexing.
160      */
161     public static final int DUPLEX_MODE_FDD = 1;
162 
163     /**
164      * Duplex mode for the phone is time-division duplexing.
165      */
166     public static final int DUPLEX_MODE_TDD = 2;
167 
168     /**
169      * Available radio technologies for GSM, UMTS and CDMA.
170      * Duplicates the constants from hardware/radio/include/ril.h
171      * This should only be used by agents working with the ril.  Others
172      * should use the equivalent TelephonyManager.NETWORK_TYPE_*
173      */
174     /** @hide */
175     public static final int RIL_RADIO_TECHNOLOGY_UNKNOWN = 0;
176     /** @hide */
177     public static final int RIL_RADIO_TECHNOLOGY_GPRS = 1;
178     /** @hide */
179     public static final int RIL_RADIO_TECHNOLOGY_EDGE = 2;
180     /** @hide */
181     public static final int RIL_RADIO_TECHNOLOGY_UMTS = 3;
182     /** @hide */
183     public static final int RIL_RADIO_TECHNOLOGY_IS95A = 4;
184     /** @hide */
185     public static final int RIL_RADIO_TECHNOLOGY_IS95B = 5;
186     /** @hide */
187     public static final int RIL_RADIO_TECHNOLOGY_1xRTT = 6;
188     /** @hide */
189     public static final int RIL_RADIO_TECHNOLOGY_EVDO_0 = 7;
190     /** @hide */
191     public static final int RIL_RADIO_TECHNOLOGY_EVDO_A = 8;
192     /** @hide */
193     public static final int RIL_RADIO_TECHNOLOGY_HSDPA = 9;
194     /** @hide */
195     public static final int RIL_RADIO_TECHNOLOGY_HSUPA = 10;
196     /** @hide */
197     public static final int RIL_RADIO_TECHNOLOGY_HSPA = 11;
198     /** @hide */
199     public static final int RIL_RADIO_TECHNOLOGY_EVDO_B = 12;
200     /** @hide */
201     public static final int RIL_RADIO_TECHNOLOGY_EHRPD = 13;
202     /** @hide */
203     public static final int RIL_RADIO_TECHNOLOGY_LTE = 14;
204     /** @hide */
205     public static final int RIL_RADIO_TECHNOLOGY_HSPAP = 15;
206     /**
207      * GSM radio technology only supports voice. It does not support data.
208      * @hide
209      */
210     public static final int RIL_RADIO_TECHNOLOGY_GSM = 16;
211     /** @hide */
212     public static final int RIL_RADIO_TECHNOLOGY_TD_SCDMA = 17;
213     /**
214      * IWLAN
215      * @hide
216      */
217     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
218     public static final int RIL_RADIO_TECHNOLOGY_IWLAN = 18;
219 
220     /**
221      * LTE_CA
222      * @hide
223      */
224     public static final int RIL_RADIO_TECHNOLOGY_LTE_CA = 19;
225 
226     /**
227      * NR(New Radio) 5G.
228      * @hide
229      */
230     public static final int  RIL_RADIO_TECHNOLOGY_NR = 20;
231 
232     /**
233      * RIL Radio Annotation
234      * @hide
235      */
236     @Retention(RetentionPolicy.SOURCE)
237     @IntDef(prefix = {"RIL_RADIO_TECHNOLOGY_" }, value = {
238         ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN,
239         ServiceState.RIL_RADIO_TECHNOLOGY_GPRS,
240         ServiceState.RIL_RADIO_TECHNOLOGY_EDGE,
241         ServiceState.RIL_RADIO_TECHNOLOGY_UMTS,
242         ServiceState.RIL_RADIO_TECHNOLOGY_IS95A,
243         ServiceState.RIL_RADIO_TECHNOLOGY_IS95B,
244         ServiceState.RIL_RADIO_TECHNOLOGY_1xRTT,
245         ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_0,
246         ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_A,
247         ServiceState.RIL_RADIO_TECHNOLOGY_HSDPA,
248         ServiceState.RIL_RADIO_TECHNOLOGY_HSUPA,
249         ServiceState.RIL_RADIO_TECHNOLOGY_HSPA,
250         ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_B,
251         ServiceState.RIL_RADIO_TECHNOLOGY_EHRPD,
252         ServiceState.RIL_RADIO_TECHNOLOGY_LTE,
253         ServiceState.RIL_RADIO_TECHNOLOGY_HSPAP,
254         ServiceState.RIL_RADIO_TECHNOLOGY_GSM,
255         ServiceState.RIL_RADIO_TECHNOLOGY_TD_SCDMA,
256         ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN,
257         ServiceState.RIL_RADIO_TECHNOLOGY_LTE_CA,
258         ServiceState.RIL_RADIO_TECHNOLOGY_NR})
259     public @interface RilRadioTechnology {}
260 
261 
262     /**
263      * The number of the radio technologies.
264      */
265     private static final int NEXT_RIL_RADIO_TECHNOLOGY = 21;
266 
267     /** @hide */
268     public static final int RIL_RADIO_CDMA_TECHNOLOGY_BITMASK =
269             (1 << (RIL_RADIO_TECHNOLOGY_IS95A - 1))
270                     | (1 << (RIL_RADIO_TECHNOLOGY_IS95B - 1))
271                     | (1 << (RIL_RADIO_TECHNOLOGY_1xRTT - 1))
272                     | (1 << (RIL_RADIO_TECHNOLOGY_EVDO_0 - 1))
273                     | (1 << (RIL_RADIO_TECHNOLOGY_EVDO_A - 1))
274                     | (1 << (RIL_RADIO_TECHNOLOGY_EVDO_B - 1))
275                     | (1 << (RIL_RADIO_TECHNOLOGY_EHRPD - 1));
276 
277     private int mVoiceRegState = STATE_OUT_OF_SERVICE;
278     private int mDataRegState = STATE_OUT_OF_SERVICE;
279 
280     /** @hide */
281     @Retention(RetentionPolicy.SOURCE)
282     @IntDef(prefix = { "ROAMING_TYPE_" }, value = {
283             ROAMING_TYPE_NOT_ROAMING,
284             ROAMING_TYPE_UNKNOWN,
285             ROAMING_TYPE_DOMESTIC,
286             ROAMING_TYPE_INTERNATIONAL
287     })
288     public @interface RoamingType {}
289 
290     /**
291      * Not roaming, registered in home network.
292      * @hide
293      */
294     @SystemApi
295     public static final int ROAMING_TYPE_NOT_ROAMING = 0;
296     /**
297      * registered in a roaming network, but can not tell if it's domestic or international.
298      * @hide
299      */
300     @SystemApi
301     public static final int ROAMING_TYPE_UNKNOWN = 1;
302     /**
303      * registered in a domestic roaming network
304      * @hide
305      */
306     @SystemApi
307     public static final int ROAMING_TYPE_DOMESTIC = 2;
308     /**
309      * registered in an international roaming network
310      * @hide
311      */
312     @SystemApi
313     public static final int ROAMING_TYPE_INTERNATIONAL = 3;
314 
315     /**
316      * Unknown ID. Could be returned by {@link #getCdmaNetworkId()} or {@link #getCdmaSystemId()}
317      */
318     public static final int UNKNOWN_ID = -1;
319 
320     /**
321      * A parcelable extra used with {@link Intent#ACTION_SERVICE_STATE} representing the service
322      * state.
323      * @hide
324      */
325     private static final String EXTRA_SERVICE_STATE = "android.intent.extra.SERVICE_STATE";
326 
327 
328     private String mOperatorAlphaLong;
329     private String mOperatorAlphaShort;
330     private String mOperatorNumeric;
331     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
332     private boolean mIsManualNetworkSelection;
333 
334     private boolean mIsEmergencyOnly;
335 
336     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
337     private boolean mCssIndicator;
338     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
339     private int mNetworkId;
340     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
341     private int mSystemId;
342     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
343     private int mCdmaRoamingIndicator;
344     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
345     private int mCdmaDefaultRoamingIndicator;
346     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
347     private int mCdmaEriIconIndex;
348     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
349     private int mCdmaEriIconMode;
350 
351     @FrequencyRange
352     private int mNrFrequencyRange;
353     private int mChannelNumber;
354     private int[] mCellBandwidths = new int[0];
355 
356     /**
357      *  ARFCN stands for Absolute Radio Frequency Channel Number. This field is current used for
358      *  LTE where it represents the boost for EARFCN (Reference: 3GPP TS 36.104 5.4.3) and for NR
359      *  where it's for NR ARFCN (Reference: 3GPP TS 36.108) */
360     private int mArfcnRsrpBoost = 0;
361 
362     private final List<NetworkRegistrationInfo> mNetworkRegistrationInfos = new ArrayList<>();
363 
364     private String mOperatorAlphaLongRaw;
365     private String mOperatorAlphaShortRaw;
366     private boolean mIsDataRoamingFromRegistration;
367     private boolean mIsIwlanPreferred;
368 
369     /**
370      * get String description of roaming type
371      * @hide
372      */
getRoamingLogString(int roamingType)373     public static final String getRoamingLogString(int roamingType) {
374         switch (roamingType) {
375             case ROAMING_TYPE_NOT_ROAMING:
376                 return "home";
377 
378             case ROAMING_TYPE_UNKNOWN:
379                 return "roaming";
380 
381             case ROAMING_TYPE_DOMESTIC:
382                 return "Domestic Roaming";
383 
384             case ROAMING_TYPE_INTERNATIONAL:
385                 return "International Roaming";
386 
387             default:
388                 return "UNKNOWN";
389         }
390     }
391 
392     /**
393      * Create a new ServiceState from a intent notifier Bundle
394      *
395      * This method is used to get ServiceState object from extras upon receiving
396      * {@link Intent#ACTION_SERVICE_STATE}.
397      *
398      * @param m Bundle from intent notifier
399      * @return newly created ServiceState
400      * @hide
401      */
402     @NonNull
403     @UnsupportedAppUsage
newFromBundle(@onNull Bundle m)404     public static ServiceState newFromBundle(@NonNull Bundle m) {
405         ServiceState ret;
406         ret = new ServiceState();
407         ret.setFromNotifierBundle(m);
408         return ret;
409     }
410 
411     /**
412      * Empty constructor
413      */
ServiceState()414     public ServiceState() {
415     }
416 
417     /**
418      * Copy constructors
419      *
420      * @param s Source service state
421      */
ServiceState(ServiceState s)422     public ServiceState(ServiceState s) {
423         copyFrom(s);
424     }
425 
copyFrom(ServiceState s)426     protected void copyFrom(ServiceState s) {
427         mVoiceRegState = s.mVoiceRegState;
428         mDataRegState = s.mDataRegState;
429         mOperatorAlphaLong = s.mOperatorAlphaLong;
430         mOperatorAlphaShort = s.mOperatorAlphaShort;
431         mOperatorNumeric = s.mOperatorNumeric;
432         mIsManualNetworkSelection = s.mIsManualNetworkSelection;
433         mCssIndicator = s.mCssIndicator;
434         mNetworkId = s.mNetworkId;
435         mSystemId = s.mSystemId;
436         mCdmaRoamingIndicator = s.mCdmaRoamingIndicator;
437         mCdmaDefaultRoamingIndicator = s.mCdmaDefaultRoamingIndicator;
438         mCdmaEriIconIndex = s.mCdmaEriIconIndex;
439         mCdmaEriIconMode = s.mCdmaEriIconMode;
440         mIsEmergencyOnly = s.mIsEmergencyOnly;
441         mChannelNumber = s.mChannelNumber;
442         mCellBandwidths = s.mCellBandwidths == null ? null :
443                 Arrays.copyOf(s.mCellBandwidths, s.mCellBandwidths.length);
444         mArfcnRsrpBoost = s.mArfcnRsrpBoost;
445         synchronized (mNetworkRegistrationInfos) {
446             mNetworkRegistrationInfos.clear();
447             mNetworkRegistrationInfos.addAll(s.getNetworkRegistrationInfoList());
448         }
449         mNrFrequencyRange = s.mNrFrequencyRange;
450         mOperatorAlphaLongRaw = s.mOperatorAlphaLongRaw;
451         mOperatorAlphaShortRaw = s.mOperatorAlphaShortRaw;
452         mIsDataRoamingFromRegistration = s.mIsDataRoamingFromRegistration;
453         mIsIwlanPreferred = s.mIsIwlanPreferred;
454     }
455 
456     /**
457      * Construct a ServiceState object from the given parcel.
458      *
459      * @deprecated The constructor takes parcel should not be public at the beginning. Use
460      * {@link #ServiceState()} instead.
461      */
462     @Deprecated
ServiceState(Parcel in)463     public ServiceState(Parcel in) {
464         mVoiceRegState = in.readInt();
465         mDataRegState = in.readInt();
466         mOperatorAlphaLong = in.readString();
467         mOperatorAlphaShort = in.readString();
468         mOperatorNumeric = in.readString();
469         mIsManualNetworkSelection = in.readInt() != 0;
470         mCssIndicator = (in.readInt() != 0);
471         mNetworkId = in.readInt();
472         mSystemId = in.readInt();
473         mCdmaRoamingIndicator = in.readInt();
474         mCdmaDefaultRoamingIndicator = in.readInt();
475         mCdmaEriIconIndex = in.readInt();
476         mCdmaEriIconMode = in.readInt();
477         mIsEmergencyOnly = in.readInt() != 0;
478         mArfcnRsrpBoost = in.readInt();
479         synchronized (mNetworkRegistrationInfos) {
480             in.readList(mNetworkRegistrationInfos, NetworkRegistrationInfo.class.getClassLoader());
481         }
482         mChannelNumber = in.readInt();
483         mCellBandwidths = in.createIntArray();
484         mNrFrequencyRange = in.readInt();
485         mOperatorAlphaLongRaw = in.readString();
486         mOperatorAlphaShortRaw = in.readString();
487         mIsDataRoamingFromRegistration = in.readBoolean();
488         mIsIwlanPreferred = in.readBoolean();
489     }
490 
writeToParcel(Parcel out, int flags)491     public void writeToParcel(Parcel out, int flags) {
492         out.writeInt(mVoiceRegState);
493         out.writeInt(mDataRegState);
494         out.writeString(mOperatorAlphaLong);
495         out.writeString(mOperatorAlphaShort);
496         out.writeString(mOperatorNumeric);
497         out.writeInt(mIsManualNetworkSelection ? 1 : 0);
498         out.writeInt(mCssIndicator ? 1 : 0);
499         out.writeInt(mNetworkId);
500         out.writeInt(mSystemId);
501         out.writeInt(mCdmaRoamingIndicator);
502         out.writeInt(mCdmaDefaultRoamingIndicator);
503         out.writeInt(mCdmaEriIconIndex);
504         out.writeInt(mCdmaEriIconMode);
505         out.writeInt(mIsEmergencyOnly ? 1 : 0);
506         out.writeInt(mArfcnRsrpBoost);
507         synchronized (mNetworkRegistrationInfos) {
508             out.writeList(mNetworkRegistrationInfos);
509         }
510         out.writeInt(mChannelNumber);
511         out.writeIntArray(mCellBandwidths);
512         out.writeInt(mNrFrequencyRange);
513         out.writeString(mOperatorAlphaLongRaw);
514         out.writeString(mOperatorAlphaShortRaw);
515         out.writeBoolean(mIsDataRoamingFromRegistration);
516         out.writeBoolean(mIsIwlanPreferred);
517     }
518 
describeContents()519     public int describeContents() {
520         return 0;
521     }
522 
523     public static final @android.annotation.NonNull Parcelable.Creator<ServiceState> CREATOR =
524             new Parcelable.Creator<ServiceState>() {
525         public ServiceState createFromParcel(Parcel in) {
526             return new ServiceState(in);
527         }
528 
529         public ServiceState[] newArray(int size) {
530             return new ServiceState[size];
531         }
532     };
533 
534     /**
535      * Get current voice service state
536      */
getState()537     public int getState() {
538         return getVoiceRegState();
539     }
540 
541     /**
542      * Get current voice service state
543      *
544      * @see #STATE_IN_SERVICE
545      * @see #STATE_OUT_OF_SERVICE
546      * @see #STATE_EMERGENCY_ONLY
547      * @see #STATE_POWER_OFF
548      *
549      * @hide
550      */
551     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
getVoiceRegState()552     public int getVoiceRegState() {
553         return mVoiceRegState;
554     }
555 
556     /**
557      * Get current data registration state.
558      *
559      * @see #STATE_IN_SERVICE
560      * @see #STATE_OUT_OF_SERVICE
561      * @see #STATE_EMERGENCY_ONLY
562      * @see #STATE_POWER_OFF
563      *
564      * @return current data registration state
565      *
566      * @hide
567      */
568     @UnsupportedAppUsage
569     @TestApi
getDataRegState()570     public int getDataRegState() {
571         return mDataRegState;
572     }
573 
574     /**
575      * Get current data registration state.
576      *
577      * @see #STATE_IN_SERVICE
578      * @see #STATE_OUT_OF_SERVICE
579      * @see #STATE_EMERGENCY_ONLY
580      * @see #STATE_POWER_OFF
581      *
582      * @return current data registration state
583      *
584      * @hide
585      */
getDataRegistrationState()586     public @RegState int getDataRegistrationState() {
587         return getDataRegState();
588     }
589 
590     /**
591      * Get the current duplex mode
592      *
593      * @see #DUPLEX_MODE_UNKNOWN
594      * @see #DUPLEX_MODE_FDD
595      * @see #DUPLEX_MODE_TDD
596      *
597      * @return Current {@code DuplexMode} for the phone
598      */
599     @DuplexMode
getDuplexMode()600     public int getDuplexMode() {
601         // support LTE/NR duplex mode
602         if (!isPsOnlyTech(getRilDataRadioTechnology())) {
603             return DUPLEX_MODE_UNKNOWN;
604         }
605 
606         int band = AccessNetworkUtils.getOperatingBandForEarfcn(mChannelNumber);
607         return AccessNetworkUtils.getDuplexModeForEutranBand(band);
608     }
609 
610     /**
611      * Get the channel number of the current primary serving cell, or -1 if unknown
612      *
613      * <p>This is EARFCN for LTE, UARFCN for UMTS, and ARFCN for GSM.
614      *
615      * @return Channel number of primary serving cell
616      */
getChannelNumber()617     public int getChannelNumber() {
618         return mChannelNumber;
619     }
620 
621     /**
622      * Get an array of cell bandwidths (kHz) for the current serving cells
623      *
624      * @return Current serving cell bandwidths
625      */
getCellBandwidths()626     public int[] getCellBandwidths() {
627         return mCellBandwidths == null ? new int[0] : mCellBandwidths;
628     }
629 
630     /**
631      * Get current roaming indicator of phone
632      * (note: not just decoding from TS 27.007 7.2)
633      *
634      * @return true if TS 27.007 7.2 roaming is true
635      *              and ONS is different from SPN
636      */
getRoaming()637     public boolean getRoaming() {
638         return getVoiceRoaming() || getDataRoaming();
639     }
640 
641     /**
642      * Get current voice network roaming status
643      * @return roaming status
644      * @hide
645      */
646     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
getVoiceRoaming()647     public boolean getVoiceRoaming() {
648         return getVoiceRoamingType() != ROAMING_TYPE_NOT_ROAMING;
649     }
650     /**
651      * Get current voice network roaming type
652      * @return roaming type
653      * @hide
654      */
655     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
getVoiceRoamingType()656     public @RoamingType int getVoiceRoamingType() {
657         final NetworkRegistrationInfo regState = getNetworkRegistrationInfo(
658                 NetworkRegistrationInfo.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
659         if (regState != null) {
660             return regState.getRoamingType();
661         }
662         return ROAMING_TYPE_NOT_ROAMING;
663     }
664 
665     /**
666      * Get whether the current data network is roaming.
667      * This value may be overwritten by resource overlay or carrier configuration.
668      * @see #getDataRoamingFromRegistration() to get the value from the network registration.
669      * @return roaming type
670      * @hide
671      */
672     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
getDataRoaming()673     public boolean getDataRoaming() {
674         return getDataRoamingType() != ROAMING_TYPE_NOT_ROAMING;
675     }
676 
677     /**
678      * Set whether the data network registration state is roaming.
679      * This should only be set to the roaming value received
680      * once the data registration phase has completed.
681      * @hide
682      */
setDataRoamingFromRegistration(boolean dataRoaming)683     public void setDataRoamingFromRegistration(boolean dataRoaming) {
684         mIsDataRoamingFromRegistration = dataRoaming;
685     }
686 
687     /**
688      * Get whether data network registration state is roaming.
689      * This value is set directly from the modem and will not be overwritten
690      * by resource overlay or carrier configuration.
691      * @return true if registration indicates roaming, false otherwise
692      * @hide
693      */
getDataRoamingFromRegistration()694     public boolean getDataRoamingFromRegistration() {
695         // TODO: all callers should refactor to get roaming state directly from modem
696         // this should not be exposed as a public API
697         return mIsDataRoamingFromRegistration;
698     }
699 
700     /**
701      * Get current data network roaming type
702      * @return roaming type
703      * @hide
704      */
705     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
getDataRoamingType()706     public @RoamingType int getDataRoamingType() {
707         final NetworkRegistrationInfo regState = getNetworkRegistrationInfo(
708                 NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
709         if (regState != null) {
710             return regState.getRoamingType();
711         }
712         return ROAMING_TYPE_NOT_ROAMING;
713     }
714 
715     /**
716      * @hide
717      */
718     @UnsupportedAppUsage
isEmergencyOnly()719     public boolean isEmergencyOnly() {
720         return mIsEmergencyOnly;
721     }
722 
723     /**
724      * @hide
725      */
726     @UnsupportedAppUsage
getCdmaRoamingIndicator()727     public int getCdmaRoamingIndicator(){
728         return this.mCdmaRoamingIndicator;
729     }
730 
731     /**
732      * @hide
733      */
734     @UnsupportedAppUsage
getCdmaDefaultRoamingIndicator()735     public int getCdmaDefaultRoamingIndicator(){
736         return this.mCdmaDefaultRoamingIndicator;
737     }
738 
739     /**
740      * @hide
741      */
742     @UnsupportedAppUsage
getCdmaEriIconIndex()743     public int getCdmaEriIconIndex() {
744         return this.mCdmaEriIconIndex;
745     }
746 
747     /**
748      * @hide
749      */
750     @UnsupportedAppUsage
getCdmaEriIconMode()751     public int getCdmaEriIconMode() {
752         return this.mCdmaEriIconMode;
753     }
754 
755     /**
756      * Get current registered operator name in long alphanumeric format.
757      *
758      * In GSM/UMTS, long format can be up to 16 characters long.
759      * In CDMA, returns the ERI text, if set. Otherwise, returns the ONS.
760      *
761      * Require at least {@link android.Manifest.permission#ACCESS_FINE_LOCATION} or
762      * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. Otherwise return null if the
763      * caller does not hold neither {@link android.Manifest.permission#ACCESS_FINE_LOCATION} nor
764      * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}.
765      *
766      * @return long name of operator, null if unregistered or unknown
767      */
getOperatorAlphaLong()768     public String getOperatorAlphaLong() {
769         return mOperatorAlphaLong;
770     }
771 
772     /**
773      * Get current registered voice network operator name in long alphanumeric format.
774      *
775      * Require at least {@link android.Manifest.permission#ACCESS_FINE_LOCATION} or
776      * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. Otherwise return null if the
777      * caller does not hold neither {@link android.Manifest.permission#ACCESS_FINE_LOCATION} nor
778      * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}.
779      *
780      * @return long name of operator
781      * @hide
782      */
783     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q,
784             publicAlternatives = "Use {@link #getOperatorAlphaLong} instead.")
getVoiceOperatorAlphaLong()785     public String getVoiceOperatorAlphaLong() {
786         return mOperatorAlphaLong;
787     }
788 
789     /**
790      * Get current registered operator name in short alphanumeric format.
791      *
792      * In GSM/UMTS, short format can be up to 8 characters long.
793      *
794      * Require at least {@link android.Manifest.permission#ACCESS_FINE_LOCATION} or
795      * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. Otherwise return null if the
796      * caller does not hold neither {@link android.Manifest.permission#ACCESS_FINE_LOCATION} nor
797      * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}.
798      *
799      * @return short name of operator, null if unregistered or unknown
800      */
getOperatorAlphaShort()801     public String getOperatorAlphaShort() {
802         return mOperatorAlphaShort;
803     }
804 
805     /**
806      * Get current registered voice network operator name in short alphanumeric format.
807      *
808      * Require at least {@link android.Manifest.permission#ACCESS_FINE_LOCATION} or
809      * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. Otherwise return null if the
810      * caller does not have neither {@link android.Manifest.permission#ACCESS_FINE_LOCATION} nor
811      * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}.
812      *
813      * @return short name of operator, null if unregistered or unknown
814      * @hide
815      */
816     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q,
817             publicAlternatives = "Use {@link #getOperatorAlphaShort} instead.")
getVoiceOperatorAlphaShort()818     public String getVoiceOperatorAlphaShort() {
819         return mOperatorAlphaShort;
820     }
821 
822     /**
823      * Get current registered data network operator name in short alphanumeric format.
824      *
825      * Require at least {@link android.Manifest.permission#ACCESS_FINE_LOCATION} or
826      * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. Otherwise return null if the
827      * caller does not have neither {@link android.Manifest.permission#ACCESS_FINE_LOCATION} nor
828      * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}.
829      *
830      * @return short name of operator, null if unregistered or unknown
831      * @hide
832      */
833     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q,
834             publicAlternatives = "Use {@link #getOperatorAlphaShort} instead.")
getDataOperatorAlphaShort()835     public String getDataOperatorAlphaShort() {
836         return mOperatorAlphaShort;
837     }
838 
839     /**
840      * Get current registered operator name in long alphanumeric format if
841      * available or short otherwise.
842      *
843      * Require at least {@link android.Manifest.permission#ACCESS_FINE_LOCATION} or
844      * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. Otherwise return null if the
845      * caller does not hold neither {@link android.Manifest.permission#ACCESS_FINE_LOCATION} nor
846      * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}.
847      *
848      * @see #getOperatorAlphaLong
849      * @see #getOperatorAlphaShort
850      *
851      * @return name of operator, null if unregistered or unknown
852      * @hide
853      */
getOperatorAlpha()854     public String getOperatorAlpha() {
855         if (TextUtils.isEmpty(mOperatorAlphaLong)) {
856             return mOperatorAlphaShort;
857         }
858 
859         return mOperatorAlphaLong;
860     }
861 
862     /**
863      * Get current registered operator numeric id.
864      *
865      * In GSM/UMTS, numeric format is 3 digit country code plus 2 or 3 digit
866      * network code.
867      *
868      * Require at least {@link android.Manifest.permission#ACCESS_FINE_LOCATION} or
869      * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. Otherwise return null if the
870      * caller does not hold neither {@link android.Manifest.permission#ACCESS_FINE_LOCATION} nor
871      * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}.
872      *
873      * @return numeric format of operator, null if unregistered or unknown
874      */
875     /*
876      * The country code can be decoded using
877      * {@link com.android.internal.telephony.MccTable#countryCodeForMcc(int)}.
878      */
getOperatorNumeric()879     public String getOperatorNumeric() {
880         return mOperatorNumeric;
881     }
882 
883     /**
884      * Get current registered voice network operator numeric id.
885      *
886      * Require at least {@link android.Manifest.permission#ACCESS_FINE_LOCATION} or
887      * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. Otherwise return null if the
888      * caller does not hold neither {@link android.Manifest.permission#ACCESS_FINE_LOCATION} nor
889      * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}.
890      *
891      * @return numeric format of operator, null if unregistered or unknown
892      * @hide
893      */
894     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
getVoiceOperatorNumeric()895     public String getVoiceOperatorNumeric() {
896         return mOperatorNumeric;
897     }
898 
899     /**
900      * Get current registered data network operator numeric id.
901      *
902      * Require at least {@link android.Manifest.permission#ACCESS_FINE_LOCATION} or
903      * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. Otherwise return null if the
904      * caller does not hold neither {@link android.Manifest.permission#ACCESS_FINE_LOCATION} nor
905      * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}.
906      *
907      * @return numeric format of operator, null if unregistered or unknown
908      * @hide
909      */
910     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q,
911             publicAlternatives = "Use {@link #getOperatorNumeric} instead.")
getDataOperatorNumeric()912     public String getDataOperatorNumeric() {
913         return mOperatorNumeric;
914     }
915 
916     /**
917      * Get current network selection mode.
918      *
919      * @return true if manual mode, false if automatic mode
920      */
getIsManualSelection()921     public boolean getIsManualSelection() {
922         return mIsManualNetworkSelection;
923     }
924 
925     @Override
hashCode()926     public int hashCode() {
927         synchronized (mNetworkRegistrationInfos) {
928             return Objects.hash(
929                     mVoiceRegState,
930                     mDataRegState,
931                     mChannelNumber,
932                     Arrays.hashCode(mCellBandwidths),
933                     mOperatorAlphaLong,
934                     mOperatorAlphaShort,
935                     mOperatorNumeric,
936                     mIsManualNetworkSelection,
937                     mCssIndicator,
938                     mNetworkId,
939                     mSystemId,
940                     mCdmaRoamingIndicator,
941                     mCdmaDefaultRoamingIndicator,
942                     mCdmaEriIconIndex,
943                     mCdmaEriIconMode,
944                     mIsEmergencyOnly,
945                     mArfcnRsrpBoost,
946                     mNetworkRegistrationInfos,
947                     mNrFrequencyRange,
948                     mOperatorAlphaLongRaw,
949                     mOperatorAlphaShortRaw,
950                     mIsDataRoamingFromRegistration,
951                     mIsIwlanPreferred);
952         }
953     }
954 
955     @Override
equals(Object o)956     public boolean equals (Object o) {
957         if (!(o instanceof ServiceState)) return false;
958         ServiceState s = (ServiceState) o;
959 
960         synchronized (mNetworkRegistrationInfos) {
961             return mVoiceRegState == s.mVoiceRegState
962                     && mDataRegState == s.mDataRegState
963                     && mIsManualNetworkSelection == s.mIsManualNetworkSelection
964                     && mChannelNumber == s.mChannelNumber
965                     && Arrays.equals(mCellBandwidths, s.mCellBandwidths)
966                     && equalsHandlesNulls(mOperatorAlphaLong, s.mOperatorAlphaLong)
967                     && equalsHandlesNulls(mOperatorAlphaShort, s.mOperatorAlphaShort)
968                     && equalsHandlesNulls(mOperatorNumeric, s.mOperatorNumeric)
969                     && equalsHandlesNulls(mCssIndicator, s.mCssIndicator)
970                     && equalsHandlesNulls(mNetworkId, s.mNetworkId)
971                     && equalsHandlesNulls(mSystemId, s.mSystemId)
972                     && equalsHandlesNulls(mCdmaRoamingIndicator, s.mCdmaRoamingIndicator)
973                     && equalsHandlesNulls(mCdmaDefaultRoamingIndicator,
974                     s.mCdmaDefaultRoamingIndicator)
975                     && mIsEmergencyOnly == s.mIsEmergencyOnly
976                     && equalsHandlesNulls(mOperatorAlphaLongRaw, s.mOperatorAlphaLongRaw)
977                     && equalsHandlesNulls(mOperatorAlphaShortRaw, s.mOperatorAlphaShortRaw)
978                     && mNetworkRegistrationInfos.size() == s.mNetworkRegistrationInfos.size()
979                     && mNetworkRegistrationInfos.containsAll(s.mNetworkRegistrationInfos)
980                     && mNrFrequencyRange == s.mNrFrequencyRange
981                     && mIsDataRoamingFromRegistration == s.mIsDataRoamingFromRegistration
982                     && mIsIwlanPreferred == s.mIsIwlanPreferred;
983         }
984     }
985 
986     /**
987      * Convert roaming type to string
988      *
989      * @param roamingType roaming type
990      * @return The roaming type in string format
991      *
992      * @hide
993      */
roamingTypeToString(@oamingType int roamingType)994     public static String roamingTypeToString(@RoamingType int roamingType) {
995         switch (roamingType) {
996             case ROAMING_TYPE_NOT_ROAMING: return "NOT_ROAMING";
997             case ROAMING_TYPE_UNKNOWN: return "UNKNOWN";
998             case ROAMING_TYPE_DOMESTIC: return "DOMESTIC";
999             case ROAMING_TYPE_INTERNATIONAL: return "INTERNATIONAL";
1000         }
1001         return "Unknown roaming type " + roamingType;
1002     }
1003 
1004     /**
1005      * Convert radio technology to String
1006      *
1007      * @param rt radioTechnology
1008      * @return String representation of the RAT
1009      *
1010      * @hide
1011      */
1012     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
rilRadioTechnologyToString(int rt)1013     public static String rilRadioTechnologyToString(int rt) {
1014         String rtString;
1015 
1016         switch(rt) {
1017             case RIL_RADIO_TECHNOLOGY_UNKNOWN:
1018                 rtString = "Unknown";
1019                 break;
1020             case RIL_RADIO_TECHNOLOGY_GPRS:
1021                 rtString = "GPRS";
1022                 break;
1023             case RIL_RADIO_TECHNOLOGY_EDGE:
1024                 rtString = "EDGE";
1025                 break;
1026             case RIL_RADIO_TECHNOLOGY_UMTS:
1027                 rtString = "UMTS";
1028                 break;
1029             case RIL_RADIO_TECHNOLOGY_IS95A:
1030                 rtString = "CDMA-IS95A";
1031                 break;
1032             case RIL_RADIO_TECHNOLOGY_IS95B:
1033                 rtString = "CDMA-IS95B";
1034                 break;
1035             case RIL_RADIO_TECHNOLOGY_1xRTT:
1036                 rtString = "1xRTT";
1037                 break;
1038             case RIL_RADIO_TECHNOLOGY_EVDO_0:
1039                 rtString = "EvDo-rev.0";
1040                 break;
1041             case RIL_RADIO_TECHNOLOGY_EVDO_A:
1042                 rtString = "EvDo-rev.A";
1043                 break;
1044             case RIL_RADIO_TECHNOLOGY_HSDPA:
1045                 rtString = "HSDPA";
1046                 break;
1047             case RIL_RADIO_TECHNOLOGY_HSUPA:
1048                 rtString = "HSUPA";
1049                 break;
1050             case RIL_RADIO_TECHNOLOGY_HSPA:
1051                 rtString = "HSPA";
1052                 break;
1053             case RIL_RADIO_TECHNOLOGY_EVDO_B:
1054                 rtString = "EvDo-rev.B";
1055                 break;
1056             case RIL_RADIO_TECHNOLOGY_EHRPD:
1057                 rtString = "eHRPD";
1058                 break;
1059             case RIL_RADIO_TECHNOLOGY_LTE:
1060                 rtString = "LTE";
1061                 break;
1062             case RIL_RADIO_TECHNOLOGY_HSPAP:
1063                 rtString = "HSPAP";
1064                 break;
1065             case RIL_RADIO_TECHNOLOGY_GSM:
1066                 rtString = "GSM";
1067                 break;
1068             case RIL_RADIO_TECHNOLOGY_IWLAN:
1069                 rtString = "IWLAN";
1070                 break;
1071             case RIL_RADIO_TECHNOLOGY_TD_SCDMA:
1072                 rtString = "TD-SCDMA";
1073                 break;
1074             case RIL_RADIO_TECHNOLOGY_LTE_CA:
1075                 rtString = "LTE_CA";
1076                 break;
1077             case RIL_RADIO_TECHNOLOGY_NR:
1078                 rtString = "NR_SA";
1079                 break;
1080             default:
1081                 rtString = "Unexpected";
1082                 Rlog.w(LOG_TAG, "Unexpected radioTechnology=" + rt);
1083                 break;
1084         }
1085         return rtString;
1086     }
1087 
1088     /**
1089      * Convert frequency range into string
1090      *
1091      * @param range The cellular frequency range
1092      * @return Frequency range in string format
1093      *
1094      * @hide
1095      */
frequencyRangeToString(@requencyRange int range)1096     public static @NonNull String frequencyRangeToString(@FrequencyRange int range) {
1097         switch (range) {
1098             case FREQUENCY_RANGE_UNKNOWN: return "UNKNOWN";
1099             case FREQUENCY_RANGE_LOW: return "LOW";
1100             case FREQUENCY_RANGE_MID: return "MID";
1101             case FREQUENCY_RANGE_HIGH: return "HIGH";
1102             case FREQUENCY_RANGE_MMWAVE: return "MMWAVE";
1103             default:
1104                 return Integer.toString(range);
1105         }
1106     }
1107 
1108     /**
1109      * Convert RIL Service State to String
1110      *
1111      * @param serviceState
1112      * @return String representation of the ServiceState
1113      *
1114      * @hide
1115      */
rilServiceStateToString(int serviceState)1116     public static String rilServiceStateToString(int serviceState) {
1117         switch(serviceState) {
1118             case STATE_IN_SERVICE:
1119                 return "IN_SERVICE";
1120             case STATE_OUT_OF_SERVICE:
1121                 return "OUT_OF_SERVICE";
1122             case STATE_EMERGENCY_ONLY:
1123                 return "EMERGENCY_ONLY";
1124             case STATE_POWER_OFF:
1125                 return "POWER_OFF";
1126             default:
1127                 return "UNKNOWN";
1128         }
1129     }
1130 
1131     @Override
toString()1132     public String toString() {
1133         synchronized (mNetworkRegistrationInfos) {
1134             return new StringBuilder().append("{mVoiceRegState=").append(mVoiceRegState)
1135                     .append("(" + rilServiceStateToString(mVoiceRegState) + ")")
1136                     .append(", mDataRegState=").append(mDataRegState)
1137                     .append("(" + rilServiceStateToString(mDataRegState) + ")")
1138                     .append(", mChannelNumber=").append(mChannelNumber)
1139                     .append(", duplexMode()=").append(getDuplexMode())
1140                     .append(", mCellBandwidths=").append(Arrays.toString(mCellBandwidths))
1141                     .append(", mOperatorAlphaLong=").append(mOperatorAlphaLong)
1142                     .append(", mOperatorAlphaShort=").append(mOperatorAlphaShort)
1143                     .append(", isManualNetworkSelection=").append(mIsManualNetworkSelection)
1144                     .append(mIsManualNetworkSelection ? "(manual)" : "(automatic)")
1145                     .append(", getRilVoiceRadioTechnology=").append(getRilVoiceRadioTechnology())
1146                     .append("(" + rilRadioTechnologyToString(getRilVoiceRadioTechnology()) + ")")
1147                     .append(", getRilDataRadioTechnology=").append(getRilDataRadioTechnology())
1148                     .append("(" + rilRadioTechnologyToString(getRilDataRadioTechnology()) + ")")
1149                     .append(", mCssIndicator=").append(mCssIndicator ? "supported" : "unsupported")
1150                     .append(", mNetworkId=").append(mNetworkId)
1151                     .append(", mSystemId=").append(mSystemId)
1152                     .append(", mCdmaRoamingIndicator=").append(mCdmaRoamingIndicator)
1153                     .append(", mCdmaDefaultRoamingIndicator=").append(mCdmaDefaultRoamingIndicator)
1154                     .append(", mIsEmergencyOnly=").append(mIsEmergencyOnly)
1155                     .append(", isUsingCarrierAggregation=").append(isUsingCarrierAggregation())
1156                     .append(", mArfcnRsrpBoost=").append(mArfcnRsrpBoost)
1157                     .append(", mNetworkRegistrationInfos=").append(mNetworkRegistrationInfos)
1158                     .append(", mNrFrequencyRange=").append(Build.IS_DEBUGGABLE
1159                             ? mNrFrequencyRange : FREQUENCY_RANGE_UNKNOWN)
1160                     .append(", mOperatorAlphaLongRaw=").append(mOperatorAlphaLongRaw)
1161                     .append(", mOperatorAlphaShortRaw=").append(mOperatorAlphaShortRaw)
1162                     .append(", mIsDataRoamingFromRegistration=")
1163                     .append(mIsDataRoamingFromRegistration)
1164                     .append(", mIsIwlanPreferred=").append(mIsIwlanPreferred)
1165                     .append("}").toString();
1166         }
1167     }
1168 
init()1169     private void init() {
1170         if (DBG) Rlog.d(LOG_TAG, "init");
1171         mVoiceRegState = STATE_OUT_OF_SERVICE;
1172         mDataRegState = STATE_OUT_OF_SERVICE;
1173         mChannelNumber = -1;
1174         mCellBandwidths = new int[0];
1175         mOperatorAlphaLong = null;
1176         mOperatorAlphaShort = null;
1177         mOperatorNumeric = null;
1178         mIsManualNetworkSelection = false;
1179         mCssIndicator = false;
1180         mNetworkId = -1;
1181         mSystemId = -1;
1182         mCdmaRoamingIndicator = -1;
1183         mCdmaDefaultRoamingIndicator = -1;
1184         mCdmaEriIconIndex = -1;
1185         mCdmaEriIconMode = -1;
1186         mIsEmergencyOnly = false;
1187         mArfcnRsrpBoost = 0;
1188         mNrFrequencyRange = FREQUENCY_RANGE_UNKNOWN;
1189         synchronized (mNetworkRegistrationInfos) {
1190             mNetworkRegistrationInfos.clear();
1191             addNetworkRegistrationInfo(new NetworkRegistrationInfo.Builder()
1192                     .setDomain(NetworkRegistrationInfo.DOMAIN_CS)
1193                     .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
1194                     .setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_UNKNOWN)
1195                     .build());
1196             addNetworkRegistrationInfo(new NetworkRegistrationInfo.Builder()
1197                     .setDomain(NetworkRegistrationInfo.DOMAIN_PS)
1198                     .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
1199                     .setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_UNKNOWN)
1200                     .build());
1201         }
1202         mOperatorAlphaLongRaw = null;
1203         mOperatorAlphaShortRaw = null;
1204         mIsDataRoamingFromRegistration = false;
1205         mIsIwlanPreferred = false;
1206     }
1207 
setStateOutOfService()1208     public void setStateOutOfService() {
1209         init();
1210     }
1211 
setStateOff()1212     public void setStateOff() {
1213         init();
1214         mVoiceRegState = STATE_POWER_OFF;
1215         mDataRegState = STATE_POWER_OFF;
1216     }
1217 
setState(int state)1218     public void setState(int state) {
1219         setVoiceRegState(state);
1220         if (DBG) Rlog.e(LOG_TAG, "[ServiceState] setState deprecated use setVoiceRegState()");
1221     }
1222 
1223     /** @hide */
1224     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
setVoiceRegState(int state)1225     public void setVoiceRegState(int state) {
1226         mVoiceRegState = state;
1227         if (DBG) Rlog.d(LOG_TAG, "[ServiceState] setVoiceRegState=" + mVoiceRegState);
1228     }
1229 
1230     /** @hide */
1231     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
setDataRegState(int state)1232     public void setDataRegState(int state) {
1233         mDataRegState = state;
1234         if (VDBG) Rlog.d(LOG_TAG, "[ServiceState] setDataRegState=" + mDataRegState);
1235     }
1236 
1237     /** @hide */
1238     @TestApi
setCellBandwidths(int[] bandwidths)1239     public void setCellBandwidths(int[] bandwidths) {
1240         mCellBandwidths = bandwidths;
1241     }
1242 
1243     /** @hide */
1244     @TestApi
setChannelNumber(int channelNumber)1245     public void setChannelNumber(int channelNumber) {
1246         mChannelNumber = channelNumber;
1247     }
1248 
setRoaming(boolean roaming)1249     public void setRoaming(boolean roaming) {
1250         setVoiceRoaming(roaming);
1251         setDataRoaming(roaming);
1252     }
1253 
1254     /** @hide */
1255     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
setVoiceRoaming(boolean roaming)1256     public void setVoiceRoaming(boolean roaming) {
1257         setVoiceRoamingType(roaming ? ROAMING_TYPE_UNKNOWN : ROAMING_TYPE_NOT_ROAMING);
1258     }
1259 
1260     /** @hide */
1261     @TestApi
setVoiceRoamingType(@oamingType int type)1262     public void setVoiceRoamingType(@RoamingType int type) {
1263         NetworkRegistrationInfo regInfo = getNetworkRegistrationInfo(
1264                 NetworkRegistrationInfo.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
1265         if (regInfo == null) {
1266             regInfo = new NetworkRegistrationInfo.Builder()
1267                     .setDomain(NetworkRegistrationInfo.DOMAIN_CS)
1268                     .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
1269                     .build();
1270         }
1271         regInfo.setRoamingType(type);
1272         addNetworkRegistrationInfo(regInfo);
1273     }
1274 
1275     /** @hide */
1276     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
setDataRoaming(boolean dataRoaming)1277     public void setDataRoaming(boolean dataRoaming) {
1278         setDataRoamingType(dataRoaming ? ROAMING_TYPE_UNKNOWN : ROAMING_TYPE_NOT_ROAMING);
1279     }
1280 
1281     /** @hide */
1282     @TestApi
setDataRoamingType(@oamingType int type)1283     public void setDataRoamingType(@RoamingType int type) {
1284         NetworkRegistrationInfo regInfo = getNetworkRegistrationInfo(
1285                 NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
1286         if (regInfo == null) {
1287             regInfo = new NetworkRegistrationInfo.Builder()
1288                     .setDomain(NetworkRegistrationInfo.DOMAIN_PS)
1289                     .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
1290                     .build();
1291         }
1292         regInfo.setRoamingType(type);
1293         addNetworkRegistrationInfo(regInfo);
1294     }
1295 
1296     /**
1297      * @hide
1298      */
1299     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
setEmergencyOnly(boolean emergencyOnly)1300     public void setEmergencyOnly(boolean emergencyOnly) {
1301         mIsEmergencyOnly = emergencyOnly;
1302     }
1303 
1304     /**
1305      * @hide
1306      */
1307     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
setCdmaRoamingIndicator(int roaming)1308     public void setCdmaRoamingIndicator(int roaming) {
1309         this.mCdmaRoamingIndicator = roaming;
1310     }
1311 
1312     /**
1313      * @hide
1314      */
1315     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
setCdmaDefaultRoamingIndicator(int roaming)1316     public void setCdmaDefaultRoamingIndicator (int roaming) {
1317         this.mCdmaDefaultRoamingIndicator = roaming;
1318     }
1319 
1320     /**
1321      * @hide
1322      */
1323     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
setCdmaEriIconIndex(int index)1324     public void setCdmaEriIconIndex(int index) {
1325         this.mCdmaEriIconIndex = index;
1326     }
1327 
1328     /**
1329      * @hide
1330      */
1331     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
setCdmaEriIconMode(int mode)1332     public void setCdmaEriIconMode(int mode) {
1333         this.mCdmaEriIconMode = mode;
1334     }
1335 
setOperatorName(String longName, String shortName, String numeric)1336     public void setOperatorName(String longName, String shortName, String numeric) {
1337         mOperatorAlphaLong = longName;
1338         mOperatorAlphaShort = shortName;
1339         mOperatorNumeric = numeric;
1340     }
1341 
1342     /**
1343      * In CDMA, mOperatorAlphaLong can be set from the ERI text.
1344      * This is done from the GsmCdmaPhone and not from the ServiceStateTracker.
1345      *
1346      * @hide
1347      */
1348     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
setOperatorAlphaLong(@ullable String longName)1349     public void setOperatorAlphaLong(@Nullable String longName) {
1350         mOperatorAlphaLong = longName;
1351     }
1352 
setIsManualSelection(boolean isManual)1353     public void setIsManualSelection(boolean isManual) {
1354         mIsManualNetworkSelection = isManual;
1355     }
1356 
1357     /**
1358      * Test whether two objects hold the same data values or both are null.
1359      *
1360      * @param a first obj
1361      * @param b second obj
1362      * @return true if two objects equal or both are null
1363      */
1364     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
equalsHandlesNulls(Object a, Object b)1365     private static boolean equalsHandlesNulls (Object a, Object b) {
1366         return (a == null) ? (b == null) : a.equals (b);
1367     }
1368 
1369     /**
1370      * Set ServiceState based on intent notifier map.
1371      *
1372      * @param m intent notifier map
1373      * @hide
1374      */
1375     @UnsupportedAppUsage
setFromNotifierBundle(Bundle m)1376     private void setFromNotifierBundle(Bundle m) {
1377         ServiceState ssFromBundle = m.getParcelable(EXTRA_SERVICE_STATE);
1378         if (ssFromBundle != null) {
1379             copyFrom(ssFromBundle);
1380         }
1381     }
1382 
1383     /**
1384      * Set intent notifier Bundle based on service state.
1385      *
1386      * Put ServiceState object and its fields into bundle which is used by TelephonyRegistry
1387      * to broadcast {@link Intent#ACTION_SERVICE_STATE}.
1388      *
1389      * @param m intent notifier Bundle
1390      * @hide
1391      *
1392      */
1393     @UnsupportedAppUsage
fillInNotifierBundle(@onNull Bundle m)1394     public void fillInNotifierBundle(@NonNull Bundle m) {
1395         m.putParcelable(EXTRA_SERVICE_STATE, this);
1396         // serviceState already consists of below entries.
1397         // for backward compatibility, we continue fill in below entries.
1398         m.putInt("voiceRegState", mVoiceRegState);
1399         m.putInt("dataRegState", mDataRegState);
1400         m.putInt("dataRoamingType", getDataRoamingType());
1401         m.putInt("voiceRoamingType", getVoiceRoamingType());
1402         m.putString("operator-alpha-long", mOperatorAlphaLong);
1403         m.putString("operator-alpha-short", mOperatorAlphaShort);
1404         m.putString("operator-numeric", mOperatorNumeric);
1405         m.putString("data-operator-alpha-long", mOperatorAlphaLong);
1406         m.putString("data-operator-alpha-short", mOperatorAlphaShort);
1407         m.putString("data-operator-numeric", mOperatorNumeric);
1408         m.putBoolean("manual", mIsManualNetworkSelection);
1409         m.putInt("radioTechnology", getRilVoiceRadioTechnology());
1410         m.putInt("dataRadioTechnology", getRadioTechnology());
1411         m.putBoolean("cssIndicator", mCssIndicator);
1412         m.putInt("networkId", mNetworkId);
1413         m.putInt("systemId", mSystemId);
1414         m.putInt("cdmaRoamingIndicator", mCdmaRoamingIndicator);
1415         m.putInt("cdmaDefaultRoamingIndicator", mCdmaDefaultRoamingIndicator);
1416         m.putBoolean("emergencyOnly", mIsEmergencyOnly);
1417         m.putBoolean("isDataRoamingFromRegistration", getDataRoamingFromRegistration());
1418         m.putBoolean("isUsingCarrierAggregation", isUsingCarrierAggregation());
1419         m.putInt("ArfcnRsrpBoost", mArfcnRsrpBoost);
1420         m.putInt("ChannelNumber", mChannelNumber);
1421         m.putIntArray("CellBandwidths", mCellBandwidths);
1422         m.putInt("mNrFrequencyRange", mNrFrequencyRange);
1423         m.putString("operator-alpha-long-raw", mOperatorAlphaLongRaw);
1424         m.putString("operator-alpha-short-raw", mOperatorAlphaShortRaw);
1425     }
1426 
1427     /** @hide */
1428     @TestApi
setRilVoiceRadioTechnology(@ilRadioTechnology int rt)1429     public void setRilVoiceRadioTechnology(@RilRadioTechnology int rt) {
1430         Rlog.e(LOG_TAG, "ServiceState.setRilVoiceRadioTechnology() called. It's encouraged to "
1431                 + "use addNetworkRegistrationInfo() instead *******");
1432         // Sync to network registration state
1433         NetworkRegistrationInfo regInfo = getNetworkRegistrationInfo(
1434                 NetworkRegistrationInfo.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
1435         if (regInfo == null) {
1436             regInfo = new NetworkRegistrationInfo.Builder()
1437                     .setDomain(NetworkRegistrationInfo.DOMAIN_CS)
1438                     .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
1439                     .build();
1440         }
1441         regInfo.setAccessNetworkTechnology(rilRadioTechnologyToNetworkType(rt));
1442         addNetworkRegistrationInfo(regInfo);
1443     }
1444 
1445 
1446     /** @hide */
1447     @TestApi
setRilDataRadioTechnology(@ilRadioTechnology int rt)1448     public void setRilDataRadioTechnology(@RilRadioTechnology int rt) {
1449         Rlog.e(LOG_TAG, "ServiceState.setRilDataRadioTechnology() called. It's encouraged to "
1450                 + "use addNetworkRegistrationInfo() instead *******");
1451         // Sync to network registration state. Always write down the WWAN transport. For AP-assisted
1452         // mode device, use addNetworkRegistrationInfo() to set the correct transport if RAT
1453         // is IWLAN.
1454         NetworkRegistrationInfo regInfo = getNetworkRegistrationInfo(
1455                 NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
1456 
1457         if (regInfo == null) {
1458             regInfo = new NetworkRegistrationInfo.Builder()
1459                     .setDomain(NetworkRegistrationInfo.DOMAIN_PS)
1460                     .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
1461                     .build();
1462         }
1463         regInfo.setAccessNetworkTechnology(rilRadioTechnologyToNetworkType(rt));
1464         addNetworkRegistrationInfo(regInfo);
1465     }
1466 
1467     /** @hide */
isUsingCarrierAggregation()1468     public boolean isUsingCarrierAggregation() {
1469         if (getCellBandwidths().length > 1) return true;
1470 
1471         synchronized (mNetworkRegistrationInfos) {
1472             for (NetworkRegistrationInfo nri : mNetworkRegistrationInfos) {
1473                 if (nri.isUsingCarrierAggregation()) return true;
1474             }
1475         }
1476         return false;
1477     }
1478 
1479     /**
1480      * Get the 5G NR frequency range the device is currently registered.
1481      *
1482      * @return the frequency range of 5G NR.
1483      * @hide
1484      */
getNrFrequencyRange()1485     public @FrequencyRange int getNrFrequencyRange() {
1486         return mNrFrequencyRange;
1487     }
1488 
1489     /**
1490      * Get the NR 5G state of the mobile data network.
1491      * @return the NR 5G state.
1492      * @hide
1493      */
getNrState()1494     public @NRState int getNrState() {
1495         final NetworkRegistrationInfo regInfo = getNetworkRegistrationInfo(
1496                 NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
1497         if (regInfo == null) return NetworkRegistrationInfo.NR_STATE_NONE;
1498         return regInfo.getNrState();
1499     }
1500 
1501     /**
1502      * @param nrFrequencyRange the frequency range of 5G NR.
1503      * @hide
1504      */
setNrFrequencyRange(@requencyRange int nrFrequencyRange)1505     public void setNrFrequencyRange(@FrequencyRange int nrFrequencyRange) {
1506         mNrFrequencyRange = nrFrequencyRange;
1507     }
1508 
1509     /** @hide */
getArfcnRsrpBoost()1510     public int getArfcnRsrpBoost() {
1511         return mArfcnRsrpBoost;
1512     }
1513 
1514     /** @hide */
setArfcnRsrpBoost(int arfcnRsrpBoost)1515     public void setArfcnRsrpBoost(int arfcnRsrpBoost) {
1516         mArfcnRsrpBoost = arfcnRsrpBoost;
1517     }
1518 
1519     /** @hide */
1520     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
setCssIndicator(int css)1521     public void setCssIndicator(int css) {
1522         this.mCssIndicator = (css != 0);
1523     }
1524 
1525     /** @hide */
1526     @TestApi
setCdmaSystemAndNetworkId(int systemId, int networkId)1527     public void setCdmaSystemAndNetworkId(int systemId, int networkId) {
1528         this.mSystemId = systemId;
1529         this.mNetworkId = networkId;
1530     }
1531 
1532     /** @hide */
1533     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
getRilVoiceRadioTechnology()1534     public int getRilVoiceRadioTechnology() {
1535         NetworkRegistrationInfo wwanRegInfo = getNetworkRegistrationInfo(
1536                 NetworkRegistrationInfo.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
1537         if (wwanRegInfo != null) {
1538             return networkTypeToRilRadioTechnology(wwanRegInfo.getAccessNetworkTechnology());
1539         }
1540         return RIL_RADIO_TECHNOLOGY_UNKNOWN;
1541     }
1542     /** @hide */
1543     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
getRilDataRadioTechnology()1544     public int getRilDataRadioTechnology() {
1545         return networkTypeToRilRadioTechnology(getDataNetworkType());
1546     }
1547 
1548     /**
1549      * @hide
1550      * @Deprecated to be removed Q3 2013 use {@link #getRilDataRadioTechnology} or
1551      * {@link #getRilVoiceRadioTechnology}
1552      */
1553     @UnsupportedAppUsage
getRadioTechnology()1554     public int getRadioTechnology() {
1555         Rlog.e(LOG_TAG, "ServiceState.getRadioTechnology() DEPRECATED will be removed *******");
1556         return getRilDataRadioTechnology();
1557     }
1558 
1559     /**
1560      * Transform RIL radio technology {@link RilRadioTechnology} value to Network
1561      * type {@link NetworkType}.
1562      *
1563      * @param rat The RIL radio technology {@link RilRadioTechnology}.
1564      * @return The network type {@link NetworkType}.
1565      *
1566      * @hide
1567      */
rilRadioTechnologyToNetworkType(@ilRadioTechnology int rat)1568     public static int rilRadioTechnologyToNetworkType(@RilRadioTechnology int rat) {
1569         switch(rat) {
1570             case RIL_RADIO_TECHNOLOGY_GPRS:
1571                 return TelephonyManager.NETWORK_TYPE_GPRS;
1572             case RIL_RADIO_TECHNOLOGY_EDGE:
1573                 return TelephonyManager.NETWORK_TYPE_EDGE;
1574             case RIL_RADIO_TECHNOLOGY_UMTS:
1575                 return TelephonyManager.NETWORK_TYPE_UMTS;
1576             case RIL_RADIO_TECHNOLOGY_HSDPA:
1577                 return TelephonyManager.NETWORK_TYPE_HSDPA;
1578             case RIL_RADIO_TECHNOLOGY_HSUPA:
1579                 return TelephonyManager.NETWORK_TYPE_HSUPA;
1580             case RIL_RADIO_TECHNOLOGY_HSPA:
1581                 return TelephonyManager.NETWORK_TYPE_HSPA;
1582             case RIL_RADIO_TECHNOLOGY_IS95A:
1583             case RIL_RADIO_TECHNOLOGY_IS95B:
1584                 return TelephonyManager.NETWORK_TYPE_CDMA;
1585             case RIL_RADIO_TECHNOLOGY_1xRTT:
1586                 return TelephonyManager.NETWORK_TYPE_1xRTT;
1587             case RIL_RADIO_TECHNOLOGY_EVDO_0:
1588                 return TelephonyManager.NETWORK_TYPE_EVDO_0;
1589             case RIL_RADIO_TECHNOLOGY_EVDO_A:
1590                 return TelephonyManager.NETWORK_TYPE_EVDO_A;
1591             case RIL_RADIO_TECHNOLOGY_EVDO_B:
1592                 return TelephonyManager.NETWORK_TYPE_EVDO_B;
1593             case RIL_RADIO_TECHNOLOGY_EHRPD:
1594                 return TelephonyManager.NETWORK_TYPE_EHRPD;
1595             case RIL_RADIO_TECHNOLOGY_LTE:
1596                 return TelephonyManager.NETWORK_TYPE_LTE;
1597             case RIL_RADIO_TECHNOLOGY_HSPAP:
1598                 return TelephonyManager.NETWORK_TYPE_HSPAP;
1599             case RIL_RADIO_TECHNOLOGY_GSM:
1600                 return TelephonyManager.NETWORK_TYPE_GSM;
1601             case RIL_RADIO_TECHNOLOGY_TD_SCDMA:
1602                 return TelephonyManager.NETWORK_TYPE_TD_SCDMA;
1603             case RIL_RADIO_TECHNOLOGY_IWLAN:
1604                 return TelephonyManager.NETWORK_TYPE_IWLAN;
1605             case RIL_RADIO_TECHNOLOGY_LTE_CA:
1606                 return TelephonyManager.NETWORK_TYPE_LTE_CA;
1607             case RIL_RADIO_TECHNOLOGY_NR:
1608                 return TelephonyManager.NETWORK_TYPE_NR;
1609             default:
1610                 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
1611         }
1612     }
1613 
1614     /** @hide */
rilRadioTechnologyToAccessNetworkType(@ilRadioTechnology int rt)1615     public static int rilRadioTechnologyToAccessNetworkType(@RilRadioTechnology int rt) {
1616         switch(rt) {
1617             case RIL_RADIO_TECHNOLOGY_GPRS:
1618             case RIL_RADIO_TECHNOLOGY_EDGE:
1619             case RIL_RADIO_TECHNOLOGY_GSM:
1620                 return AccessNetworkType.GERAN;
1621             case RIL_RADIO_TECHNOLOGY_UMTS:
1622             case RIL_RADIO_TECHNOLOGY_HSDPA:
1623             case RIL_RADIO_TECHNOLOGY_HSPAP:
1624             case RIL_RADIO_TECHNOLOGY_HSUPA:
1625             case RIL_RADIO_TECHNOLOGY_HSPA:
1626             case RIL_RADIO_TECHNOLOGY_TD_SCDMA:
1627                 return AccessNetworkType.UTRAN;
1628             case RIL_RADIO_TECHNOLOGY_IS95A:
1629             case RIL_RADIO_TECHNOLOGY_IS95B:
1630             case RIL_RADIO_TECHNOLOGY_1xRTT:
1631             case RIL_RADIO_TECHNOLOGY_EVDO_0:
1632             case RIL_RADIO_TECHNOLOGY_EVDO_A:
1633             case RIL_RADIO_TECHNOLOGY_EVDO_B:
1634             case RIL_RADIO_TECHNOLOGY_EHRPD:
1635                 return AccessNetworkType.CDMA2000;
1636             case RIL_RADIO_TECHNOLOGY_LTE:
1637             case RIL_RADIO_TECHNOLOGY_LTE_CA:
1638                 return AccessNetworkType.EUTRAN;
1639             case RIL_RADIO_TECHNOLOGY_NR:
1640                 return AccessNetworkType.NGRAN;
1641             case RIL_RADIO_TECHNOLOGY_IWLAN:
1642                 return AccessNetworkType.IWLAN;
1643             case RIL_RADIO_TECHNOLOGY_UNKNOWN:
1644             default:
1645                 return AccessNetworkType.UNKNOWN;
1646         }
1647     }
1648 
1649     /**
1650      * Transform network type {@link NetworkType} value to RIL radio technology
1651      * {@link RilRadioTechnology}.
1652      *
1653      * @param networkType The network type {@link NetworkType}.
1654      * @return The RIL radio technology {@link RilRadioTechnology}.
1655      *
1656      * @hide
1657      */
networkTypeToRilRadioTechnology(int networkType)1658     public static int networkTypeToRilRadioTechnology(int networkType) {
1659         switch(networkType) {
1660             case TelephonyManager.NETWORK_TYPE_GPRS:
1661                 return RIL_RADIO_TECHNOLOGY_GPRS;
1662             case TelephonyManager.NETWORK_TYPE_EDGE:
1663                 return RIL_RADIO_TECHNOLOGY_EDGE;
1664             case TelephonyManager.NETWORK_TYPE_UMTS:
1665                 return RIL_RADIO_TECHNOLOGY_UMTS;
1666             case TelephonyManager.NETWORK_TYPE_HSDPA:
1667                 return RIL_RADIO_TECHNOLOGY_HSDPA;
1668             case TelephonyManager.NETWORK_TYPE_HSUPA:
1669                 return RIL_RADIO_TECHNOLOGY_HSUPA;
1670             case TelephonyManager.NETWORK_TYPE_HSPA:
1671                 return RIL_RADIO_TECHNOLOGY_HSPA;
1672             case TelephonyManager.NETWORK_TYPE_CDMA:
1673                 return RIL_RADIO_TECHNOLOGY_IS95A;
1674             case TelephonyManager.NETWORK_TYPE_1xRTT:
1675                 return RIL_RADIO_TECHNOLOGY_1xRTT;
1676             case TelephonyManager.NETWORK_TYPE_EVDO_0:
1677                 return RIL_RADIO_TECHNOLOGY_EVDO_0;
1678             case TelephonyManager.NETWORK_TYPE_EVDO_A:
1679                 return RIL_RADIO_TECHNOLOGY_EVDO_A;
1680             case TelephonyManager.NETWORK_TYPE_EVDO_B:
1681                 return RIL_RADIO_TECHNOLOGY_EVDO_B;
1682             case TelephonyManager.NETWORK_TYPE_EHRPD:
1683                 return RIL_RADIO_TECHNOLOGY_EHRPD;
1684             case TelephonyManager.NETWORK_TYPE_LTE:
1685                 return RIL_RADIO_TECHNOLOGY_LTE;
1686             case TelephonyManager.NETWORK_TYPE_HSPAP:
1687                 return RIL_RADIO_TECHNOLOGY_HSPAP;
1688             case TelephonyManager.NETWORK_TYPE_GSM:
1689                 return RIL_RADIO_TECHNOLOGY_GSM;
1690             case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
1691                 return RIL_RADIO_TECHNOLOGY_TD_SCDMA;
1692             case TelephonyManager.NETWORK_TYPE_IWLAN:
1693                 return RIL_RADIO_TECHNOLOGY_IWLAN;
1694             case TelephonyManager.NETWORK_TYPE_LTE_CA:
1695                 return RIL_RADIO_TECHNOLOGY_LTE_CA;
1696             case TelephonyManager.NETWORK_TYPE_NR:
1697                 return RIL_RADIO_TECHNOLOGY_NR;
1698             default:
1699                 return RIL_RADIO_TECHNOLOGY_UNKNOWN;
1700         }
1701     }
1702 
1703     /**
1704      * Get current data network type.
1705      *
1706      * Note that for IWLAN AP-assisted mode device, which is reporting both camped access networks
1707      * (cellular RAT and IWLAN)at the same time, this API is simulating the old legacy mode device
1708      * behavior,
1709      *
1710      * @return Current data network type
1711      * @hide
1712      */
1713     @TestApi
getDataNetworkType()1714     public @NetworkType int getDataNetworkType() {
1715         final NetworkRegistrationInfo iwlanRegInfo = getNetworkRegistrationInfo(
1716                 NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WLAN);
1717         final NetworkRegistrationInfo wwanRegInfo = getNetworkRegistrationInfo(
1718                 NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
1719 
1720         // For legacy mode device, or AP-assisted mode device but IWLAN is out of service, use
1721         // the RAT from cellular.
1722         if (iwlanRegInfo == null || !iwlanRegInfo.isInService()) {
1723             return (wwanRegInfo != null) ? wwanRegInfo.getAccessNetworkTechnology()
1724                     : TelephonyManager.NETWORK_TYPE_UNKNOWN;
1725         }
1726 
1727         // At this point, it must be an AP-assisted mode device and IWLAN is in service. We should
1728         // use the RAT from IWLAN service is cellular is out of service, or when both are in service
1729         // and any APN type of data is preferred on IWLAN.
1730         if (!wwanRegInfo.isInService() || mIsIwlanPreferred) {
1731             return iwlanRegInfo.getAccessNetworkTechnology();
1732         }
1733 
1734         // If both cellular and IWLAN are in service, but no APN is preferred on IWLAN, still use
1735         // the RAT from cellular.
1736         return wwanRegInfo.getAccessNetworkTechnology();
1737     }
1738 
1739     /** @hide */
1740     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
getVoiceNetworkType()1741     public @NetworkType int getVoiceNetworkType() {
1742         final NetworkRegistrationInfo regState = getNetworkRegistrationInfo(
1743                 NetworkRegistrationInfo.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
1744         if (regState != null) {
1745             return regState.getAccessNetworkTechnology();
1746         }
1747         return TelephonyManager.NETWORK_TYPE_UNKNOWN;
1748     }
1749 
1750     /** @hide */
1751     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
getCssIndicator()1752     public int getCssIndicator() {
1753         return this.mCssIndicator ? 1 : 0;
1754     }
1755 
1756     /**
1757      * Get the CDMA NID (Network Identification Number), a number uniquely identifying a network
1758      * within a wireless system. (Defined in 3GPP2 C.S0023 3.4.8)
1759      * @return The CDMA NID or {@link #UNKNOWN_ID} if not available.
1760      */
getCdmaNetworkId()1761     public int getCdmaNetworkId() {
1762         return this.mNetworkId;
1763     }
1764 
1765     /**
1766      * Get the CDMA SID (System Identification Number), a number uniquely identifying a wireless
1767      * system. (Defined in 3GPP2 C.S0023 3.4.8)
1768      * @return The CDMA SID or {@link #UNKNOWN_ID} if not available.
1769      */
getCdmaSystemId()1770     public int getCdmaSystemId() {
1771         return this.mSystemId;
1772     }
1773 
1774     /** @hide */
1775     @UnsupportedAppUsage
isGsm(int radioTechnology)1776     public static boolean isGsm(int radioTechnology) {
1777         return radioTechnology == RIL_RADIO_TECHNOLOGY_GPRS
1778                 || radioTechnology == RIL_RADIO_TECHNOLOGY_EDGE
1779                 || radioTechnology == RIL_RADIO_TECHNOLOGY_UMTS
1780                 || radioTechnology == RIL_RADIO_TECHNOLOGY_HSDPA
1781                 || radioTechnology == RIL_RADIO_TECHNOLOGY_HSUPA
1782                 || radioTechnology == RIL_RADIO_TECHNOLOGY_HSPA
1783                 || radioTechnology == RIL_RADIO_TECHNOLOGY_LTE
1784                 || radioTechnology == RIL_RADIO_TECHNOLOGY_HSPAP
1785                 || radioTechnology == RIL_RADIO_TECHNOLOGY_GSM
1786                 || radioTechnology == RIL_RADIO_TECHNOLOGY_TD_SCDMA
1787                 || radioTechnology == RIL_RADIO_TECHNOLOGY_IWLAN
1788                 || radioTechnology == RIL_RADIO_TECHNOLOGY_LTE_CA
1789                 || radioTechnology == RIL_RADIO_TECHNOLOGY_NR;
1790 
1791     }
1792 
1793     /** @hide */
1794     @UnsupportedAppUsage
isCdma(int radioTechnology)1795     public static boolean isCdma(int radioTechnology) {
1796         return radioTechnology == RIL_RADIO_TECHNOLOGY_IS95A
1797                 || radioTechnology == RIL_RADIO_TECHNOLOGY_IS95B
1798                 || radioTechnology == RIL_RADIO_TECHNOLOGY_1xRTT
1799                 || radioTechnology == RIL_RADIO_TECHNOLOGY_EVDO_0
1800                 || radioTechnology == RIL_RADIO_TECHNOLOGY_EVDO_A
1801                 || radioTechnology == RIL_RADIO_TECHNOLOGY_EVDO_B
1802                 || radioTechnology == RIL_RADIO_TECHNOLOGY_EHRPD;
1803     }
1804 
1805     /** @hide */
isPsOnlyTech(int radioTechnology)1806     public static boolean isPsOnlyTech(int radioTechnology) {
1807         return radioTechnology == RIL_RADIO_TECHNOLOGY_LTE
1808                 || radioTechnology == RIL_RADIO_TECHNOLOGY_LTE_CA
1809                 || radioTechnology == RIL_RADIO_TECHNOLOGY_NR;
1810     }
1811 
1812     /** @hide */
1813     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
bearerBitmapHasCdma(int networkTypeBitmask)1814     public static boolean bearerBitmapHasCdma(int networkTypeBitmask) {
1815         return (RIL_RADIO_CDMA_TECHNOLOGY_BITMASK
1816                 & convertNetworkTypeBitmaskToBearerBitmask(networkTypeBitmask)) != 0;
1817     }
1818 
1819     /** @hide */
1820     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
bitmaskHasTech(int bearerBitmask, int radioTech)1821     public static boolean bitmaskHasTech(int bearerBitmask, int radioTech) {
1822         if (bearerBitmask == 0) {
1823             return true;
1824         } else if (radioTech >= 1) {
1825             return ((bearerBitmask & (1 << (radioTech - 1))) != 0);
1826         }
1827         return false;
1828     }
1829 
1830     /** @hide */
getBitmaskForTech(int radioTech)1831     public static int getBitmaskForTech(int radioTech) {
1832         if (radioTech >= 1) {
1833             return (1 << (radioTech - 1));
1834         }
1835         return 0;
1836     }
1837 
1838     /** @hide */
getBitmaskFromString(String bearerList)1839     public static int getBitmaskFromString(String bearerList) {
1840         String[] bearers = bearerList.split("\\|");
1841         int bearerBitmask = 0;
1842         for (String bearer : bearers) {
1843             int bearerInt = 0;
1844             try {
1845                 bearerInt = Integer.parseInt(bearer.trim());
1846             } catch (NumberFormatException nfe) {
1847                 return 0;
1848             }
1849 
1850             if (bearerInt == 0) {
1851                 return 0;
1852             }
1853 
1854             bearerBitmask |= getBitmaskForTech(bearerInt);
1855         }
1856         return bearerBitmask;
1857     }
1858 
1859     /**
1860      * Convert network type bitmask to bearer bitmask.
1861      *
1862      * @param networkTypeBitmask The network type bitmask value
1863      * @return The bearer bitmask value.
1864      *
1865      * @hide
1866      */
convertNetworkTypeBitmaskToBearerBitmask(int networkTypeBitmask)1867     public static int convertNetworkTypeBitmaskToBearerBitmask(int networkTypeBitmask) {
1868         if (networkTypeBitmask == 0) {
1869             return 0;
1870         }
1871         int bearerBitmask = 0;
1872         for (int bearerInt = 0; bearerInt < NEXT_RIL_RADIO_TECHNOLOGY; bearerInt++) {
1873             if (bitmaskHasTech(networkTypeBitmask, rilRadioTechnologyToNetworkType(bearerInt))) {
1874                 bearerBitmask |= getBitmaskForTech(bearerInt);
1875             }
1876         }
1877         return bearerBitmask;
1878     }
1879 
1880     /**
1881      * Convert bearer bitmask to network type bitmask.
1882      *
1883      * @param bearerBitmask The bearer bitmask value.
1884      * @return The network type bitmask value.
1885      *
1886      * @hide
1887      */
convertBearerBitmaskToNetworkTypeBitmask(int bearerBitmask)1888     public static int convertBearerBitmaskToNetworkTypeBitmask(int bearerBitmask) {
1889         if (bearerBitmask == 0) {
1890             return 0;
1891         }
1892         int networkTypeBitmask = 0;
1893         for (int bearerInt = 0; bearerInt < NEXT_RIL_RADIO_TECHNOLOGY; bearerInt++) {
1894             if (bitmaskHasTech(bearerBitmask, bearerInt)) {
1895                 networkTypeBitmask |= getBitmaskForTech(rilRadioTechnologyToNetworkType(bearerInt));
1896             }
1897         }
1898         return networkTypeBitmask;
1899     }
1900 
1901     /**
1902      * Returns a merged ServiceState consisting of the base SS with voice settings from the
1903      * voice SS. The voice SS is only used if it is IN_SERVICE (otherwise the base SS is returned).
1904      * @hide
1905      * */
1906     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
mergeServiceStates(ServiceState baseSs, ServiceState voiceSs)1907     public static ServiceState mergeServiceStates(ServiceState baseSs, ServiceState voiceSs) {
1908         if (voiceSs.mVoiceRegState != STATE_IN_SERVICE) {
1909             return baseSs;
1910         }
1911 
1912         ServiceState newSs = new ServiceState(baseSs);
1913 
1914         // voice overrides
1915         newSs.mVoiceRegState = voiceSs.mVoiceRegState;
1916         newSs.mIsEmergencyOnly = false; // only get here if voice is IN_SERVICE
1917 
1918         return newSs;
1919     }
1920 
1921     /**
1922      * Get all of the available network registration info.
1923      *
1924      * @return List of {@link NetworkRegistrationInfo}
1925      */
1926     @NonNull
getNetworkRegistrationInfoList()1927     public List<NetworkRegistrationInfo> getNetworkRegistrationInfoList() {
1928         synchronized (mNetworkRegistrationInfos) {
1929             List<NetworkRegistrationInfo> newList = new ArrayList<>();
1930             for (NetworkRegistrationInfo nri : mNetworkRegistrationInfos) {
1931                 newList.add(new NetworkRegistrationInfo(nri));
1932             }
1933             return newList;
1934         }
1935     }
1936 
1937     /**
1938      * Get the network registration info list for the transport type.
1939      *
1940      * @param transportType The transport type
1941      * @return List of {@link NetworkRegistrationInfo}
1942      * @hide
1943      */
1944     @NonNull
1945     @SystemApi
getNetworkRegistrationInfoListForTransportType( @ransportType int transportType)1946     public List<NetworkRegistrationInfo> getNetworkRegistrationInfoListForTransportType(
1947             @TransportType int transportType) {
1948         List<NetworkRegistrationInfo> list = new ArrayList<>();
1949 
1950         synchronized (mNetworkRegistrationInfos) {
1951             for (NetworkRegistrationInfo networkRegistrationInfo : mNetworkRegistrationInfos) {
1952                 if (networkRegistrationInfo.getTransportType() == transportType) {
1953                     list.add(new NetworkRegistrationInfo(networkRegistrationInfo));
1954                 }
1955             }
1956         }
1957 
1958         return list;
1959     }
1960 
1961     /**
1962      * Get the network registration info list for the network domain.
1963      *
1964      * @param domain The network {@link NetworkRegistrationInfo.Domain domain}
1965      * @return List of {@link NetworkRegistrationInfo}
1966      * @hide
1967      */
1968     @NonNull
1969     @SystemApi
getNetworkRegistrationInfoListForDomain( @omain int domain)1970     public List<NetworkRegistrationInfo> getNetworkRegistrationInfoListForDomain(
1971             @Domain int domain) {
1972         List<NetworkRegistrationInfo> list = new ArrayList<>();
1973 
1974         synchronized (mNetworkRegistrationInfos) {
1975             for (NetworkRegistrationInfo networkRegistrationInfo : mNetworkRegistrationInfos) {
1976                 if ((networkRegistrationInfo.getDomain() & domain) != 0) {
1977                     list.add(new NetworkRegistrationInfo(networkRegistrationInfo));
1978                 }
1979             }
1980         }
1981 
1982         return list;
1983     }
1984 
1985     /**
1986      * Get the network registration state for the transport type and network domain.
1987      * If multiple domains are in the input bitmask, only the first one from
1988      * networkRegistrationInfo.getDomain() will be returned.
1989      *
1990      * @param domain The network {@link NetworkRegistrationInfo.Domain domain}
1991      * @param transportType The transport type
1992      * @return The matching {@link NetworkRegistrationInfo}
1993      * @hide
1994      */
1995     @Nullable
1996     @SystemApi
getNetworkRegistrationInfo(@omain int domain, @TransportType int transportType)1997     public NetworkRegistrationInfo getNetworkRegistrationInfo(@Domain int domain,
1998                                                               @TransportType int transportType) {
1999         synchronized (mNetworkRegistrationInfos) {
2000             for (NetworkRegistrationInfo networkRegistrationInfo : mNetworkRegistrationInfos) {
2001                 if (networkRegistrationInfo.getTransportType() == transportType
2002                         && (networkRegistrationInfo.getDomain() & domain) != 0) {
2003                     return new NetworkRegistrationInfo(networkRegistrationInfo);
2004                 }
2005             }
2006         }
2007 
2008         return null;
2009     }
2010 
2011     /**
2012      * @hide
2013      */
2014     @TestApi
addNetworkRegistrationInfo(NetworkRegistrationInfo nri)2015     public void addNetworkRegistrationInfo(NetworkRegistrationInfo nri) {
2016         if (nri == null) return;
2017 
2018         synchronized (mNetworkRegistrationInfos) {
2019             for (int i = 0; i < mNetworkRegistrationInfos.size(); i++) {
2020                 NetworkRegistrationInfo curRegState = mNetworkRegistrationInfos.get(i);
2021                 if (curRegState.getTransportType() == nri.getTransportType()
2022                         && curRegState.getDomain() == nri.getDomain()) {
2023                     mNetworkRegistrationInfos.remove(i);
2024                     break;
2025                 }
2026             }
2027 
2028             mNetworkRegistrationInfos.add(new NetworkRegistrationInfo(nri));
2029         }
2030     }
2031 
2032     /**
2033      * @hide
2034      */
getBetterNRFrequencyRange(int range1, int range2)2035     public static final int getBetterNRFrequencyRange(int range1, int range2) {
2036         return FREQUENCY_RANGE_ORDER.indexOf(range1) > FREQUENCY_RANGE_ORDER.indexOf(range2)
2037                 ? range1
2038                 : range2;
2039     }
2040 
2041     /**
2042      * Returns a copy of self with location-identifying information removed.
2043      * Always clears the NetworkRegistrationInfo's CellIdentity fields, but if removeCoarseLocation
2044      * is true, clears other info as well.
2045      *
2046      * @param removeCoarseLocation Whether to also remove coarse location information.
2047      *                             if false, it only clears fine location information such as
2048      *                             NetworkRegistrationInfo's CellIdentity fields; If true, it will
2049      *                             also remove other location information such as operator's MCC
2050      *                             and MNC.
2051      * @return the copied ServiceState with location info sanitized.
2052      * @hide
2053      */
2054     @NonNull
createLocationInfoSanitizedCopy(boolean removeCoarseLocation)2055     public ServiceState createLocationInfoSanitizedCopy(boolean removeCoarseLocation) {
2056         ServiceState state = new ServiceState(this);
2057         synchronized (state.mNetworkRegistrationInfos) {
2058             List<NetworkRegistrationInfo> networkRegistrationInfos =
2059                     state.mNetworkRegistrationInfos.stream()
2060                             .map(NetworkRegistrationInfo::sanitizeLocationInfo)
2061                             .collect(Collectors.toList());
2062             state.mNetworkRegistrationInfos.clear();
2063             state.mNetworkRegistrationInfos.addAll(networkRegistrationInfos);
2064         }
2065         if (!removeCoarseLocation) return state;
2066 
2067         state.mOperatorAlphaLong = null;
2068         state.mOperatorAlphaShort = null;
2069         state.mOperatorNumeric = null;
2070 
2071         return state;
2072     }
2073 
2074     /**
2075      * @hide
2076      */
setOperatorAlphaLongRaw(String operatorAlphaLong)2077     public void setOperatorAlphaLongRaw(String operatorAlphaLong) {
2078         mOperatorAlphaLongRaw = operatorAlphaLong;
2079     }
2080 
2081     /**
2082      * The current registered raw data network operator name in long alphanumeric format.
2083      *
2084      * The long format can be up to 16 characters long.
2085      *
2086      * @return long raw name of operator, null if unregistered or unknown
2087      * @hide
2088      */
2089     @Nullable
getOperatorAlphaLongRaw()2090     public String getOperatorAlphaLongRaw() {
2091         return mOperatorAlphaLongRaw;
2092     }
2093 
2094     /**
2095      * @hide
2096      */
setOperatorAlphaShortRaw(String operatorAlphaShort)2097     public void setOperatorAlphaShortRaw(String operatorAlphaShort) {
2098         mOperatorAlphaShortRaw = operatorAlphaShort;
2099     }
2100 
2101     /**
2102      * The current registered raw data network operator name in short alphanumeric format.
2103      *
2104      * The short format can be up to 8 characters long.
2105      *
2106      * @return short raw name of operator, null if unregistered or unknown
2107      * @hide
2108      */
2109     @Nullable
getOperatorAlphaShortRaw()2110     public String getOperatorAlphaShortRaw() {
2111         return mOperatorAlphaShortRaw;
2112     }
2113 
2114     /**
2115      * Set to {@code true} if any data network is preferred on IWLAN.
2116      *
2117      * @param isIwlanPreferred {@code true} if IWLAN is preferred.
2118      * @hide
2119      */
setIwlanPreferred(boolean isIwlanPreferred)2120     public void setIwlanPreferred(boolean isIwlanPreferred) {
2121         mIsIwlanPreferred = isIwlanPreferred;
2122     }
2123 
2124     /**
2125      * @return {@code true} if any data network is preferred on IWLAN.
2126      *
2127      * Note only when this value is true, {@link #getDataNetworkType()} will return
2128      * {@link TelephonyManager#NETWORK_TYPE_IWLAN} when AP-assisted mode device camps on both
2129      * cellular and IWLAN. This value does not affect legacy mode devices as the data network
2130      * type is directly reported by the modem.
2131      *
2132      * @hide
2133      */
isIwlanPreferred()2134     public boolean isIwlanPreferred() {
2135         return mIsIwlanPreferred;
2136     }
2137 
2138     /**
2139      * This indicates whether the device is searching for service.
2140      *
2141      * This API reports the modem searching status for
2142      * {@link AccessNetworkConstants#TRANSPORT_TYPE_WWAN} (cellular) service in either
2143      * {@link NetworkRegistrationInfo#DOMAIN_CS} or {@link NetworkRegistrationInfo#DOMAIN_PS}.
2144      * This API will not report searching status for
2145      * {@link AccessNetworkConstants#TRANSPORT_TYPE_WLAN}.
2146      *
2147      * @return {@code true} whenever the modem is searching for service.
2148      */
isSearching()2149     public boolean isSearching() {
2150         NetworkRegistrationInfo psRegState = getNetworkRegistrationInfo(
2151                 NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
2152 
2153         if (psRegState != null && psRegState.getRegistrationState()
2154                 == NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_SEARCHING) {
2155             return true;
2156         }
2157 
2158         NetworkRegistrationInfo csRegState = getNetworkRegistrationInfo(
2159                 NetworkRegistrationInfo.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
2160 
2161         if (csRegState != null && csRegState.getRegistrationState()
2162                 == NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_SEARCHING) {
2163             return true;
2164         }
2165         return false;
2166     }
2167 
2168     /**
2169      * The frequency range is valid or not.
2170      *
2171      * @param frequencyRange The frequency range {@link FrequencyRange}.
2172      * @return {@code true} if valid, {@code false} otherwise.
2173      *
2174      * @hide
2175      */
isFrequencyRangeValid(int frequencyRange)2176     public static boolean isFrequencyRangeValid(int frequencyRange) {
2177         if (frequencyRange == FREQUENCY_RANGE_LOW
2178                 || frequencyRange == FREQUENCY_RANGE_MID
2179                 || frequencyRange == FREQUENCY_RANGE_HIGH
2180                 || frequencyRange == FREQUENCY_RANGE_MMWAVE) {
2181             return true;
2182         } else {
2183             return false;
2184         }
2185     }
2186 }
2187