blob: f1314da1ae8ba7ab19fa6b4124b0cee712b80ab0 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.telephony;
18
Cassied53df962017-12-05 13:34:33 -080019import android.annotation.IntDef;
Jack Yu8eb6ca82019-03-01 12:04:50 -080020import android.annotation.NonNull;
21import android.annotation.Nullable;
Jack Yuf2add902018-07-12 15:10:34 -070022import android.annotation.SystemApi;
Jack Yu1b8b3892018-02-22 17:37:38 -080023import android.annotation.TestApi;
Artur Satayev54af4fc2019-12-10 17:47:56 +000024import android.compat.annotation.UnsupportedAppUsage;
chen xu02811692018-10-03 19:07:09 -070025import android.content.Intent;
chen xuf513b522018-10-18 16:52:40 -070026import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.os.Bundle;
28import android.os.Parcel;
29import android.os.Parcelable;
Jack Yu677cfaa22018-01-31 00:33:20 -080030import android.telephony.AccessNetworkConstants.AccessNetworkType;
Jack Yuef25faf2019-03-14 15:42:09 -070031import android.telephony.AccessNetworkConstants.TransportType;
Chen Xuc9d4ee12019-09-26 16:11:59 -070032import android.telephony.Annotation.NetworkType;
Jack Yue27d3fd2019-03-15 14:49:53 -070033import android.telephony.NetworkRegistrationInfo.Domain;
Jack Yu20d71402019-03-16 23:00:35 -070034import android.telephony.NetworkRegistrationInfo.NRState;
Zoran Jovanovic47495eb2016-11-02 09:56:38 +010035import android.text.TextUtils;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036
Sarah Chin96169ca2020-01-07 17:45:05 -080037import com.android.telephony.Rlog;
38
Cassied53df962017-12-05 13:34:33 -080039import java.lang.annotation.Retention;
40import java.lang.annotation.RetentionPolicy;
Jack Yud5f1de12017-12-21 11:00:05 -080041import java.util.ArrayList;
Jack Yu677cfaa22018-01-31 00:33:20 -080042import java.util.Arrays;
Jack Yud5f1de12017-12-21 11:00:05 -080043import java.util.List;
Nathan Haroldb220fde2018-06-27 17:07:52 -070044import java.util.Objects;
Hall Liuee313732018-11-27 14:36:51 -080045import java.util.stream.Collectors;
Jack Yud5f1de12017-12-21 11:00:05 -080046
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047/**
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
Eric Schwarzenbach09a77732018-01-18 14:42:00 -080054 * <li>Duplex mode: UNKNOWN, FDD, TDD
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055 * <li>Roaming indicator
56 * <li>Operator name, short name and numeric id
57 * <li>Network selection mode
58 * </ul>
Cody Kesting19618712019-03-15 16:22:08 -070059 *
60 * For historical reasons this class is not declared as final; however,
61 * it should be treated as though it were final.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062 */
63public class ServiceState implements Parcelable {
64
Wink Saville767a6622009-04-02 01:37:02 -070065 static final String LOG_TAG = "PHONE";
Joe Onoratoa102dd02016-02-01 17:48:18 -080066 static final boolean DBG = false;
Jack Yu87f47e92016-01-05 15:50:40 -080067 static final boolean VDBG = false; // STOPSHIP if true
Wink Saville767a6622009-04-02 01:37:02 -070068
SongFerngWange5202be2019-12-02 21:19:24 +080069 /** @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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076 /**
77 * Normal operation condition, the phone is registered
78 * with an operator either in home network or in roaming.
79 */
Yangster4ccebea2018-10-09 17:09:02 -070080 public static final int STATE_IN_SERVICE = TelephonyProtoEnums.SERVICE_STATE_IN_SERVICE; // 0
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081
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 */
Yangster4ccebea2018-10-09 17:09:02 -070088 public static final int STATE_OUT_OF_SERVICE =
89 TelephonyProtoEnums.SERVICE_STATE_OUT_OF_SERVICE; // 1
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090
91 /**
92 * The phone is registered and locked. Only emergency numbers are allowed. {@more}
93 */
SongFerngWange5202be2019-12-02 21:19:24 +080094 //TODO: This state is not used anymore. It should be deprecated in a future release.
Yangster4ccebea2018-10-09 17:09:02 -070095 public static final int STATE_EMERGENCY_ONLY =
96 TelephonyProtoEnums.SERVICE_STATE_EMERGENCY_ONLY; // 2
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097
98 /**
Jake Hamby390de222010-05-10 18:46:45 -070099 * Radio of telephony is explicitly powered off.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 */
Yangster4ccebea2018-10-09 17:09:02 -0700101 public static final int STATE_POWER_OFF = TelephonyProtoEnums.SERVICE_STATE_POWER_OFF; // 3
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102
Eric Schwarzenbach09a77732018-01-18 14:42:00 -0800103 /** @hide */
104 @Retention(RetentionPolicy.SOURCE)
Pengquan Meng6aa52132018-11-13 17:06:34 -0800105 @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 */
Sarah Chin65277df2019-10-17 14:59:59 -0700114 public static final int FREQUENCY_RANGE_UNKNOWN = 0;
Pengquan Meng6aa52132018-11-13 17:06:34 -0800115
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
Pengquan Meng424acc72018-11-27 16:45:17 -0800140 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
Pengquan Meng6aa52132018-11-13 17:06:34 -0800147 /** @hide */
148 @Retention(RetentionPolicy.SOURCE)
149 @IntDef(prefix = "DUPLEX_MODE_",
150 value = {DUPLEX_MODE_UNKNOWN, DUPLEX_MODE_FDD, DUPLEX_MODE_TDD})
Eric Schwarzenbach09a77732018-01-18 14:42:00 -0800151 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
Wink Saville767a6622009-04-02 01:37:02 -0700168 /**
169 * Available radio technologies for GSM, UMTS and CDMA.
Robert Greenwalt1434d7b2012-02-17 13:14:08 -0800170 * 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_*
Wink Saville767a6622009-04-02 01:37:02 -0700173 */
174 /** @hide */
Robert Greenwalt1434d7b2012-02-17 13:14:08 -0800175 public static final int RIL_RADIO_TECHNOLOGY_UNKNOWN = 0;
Wink Saville767a6622009-04-02 01:37:02 -0700176 /** @hide */
Robert Greenwalt1434d7b2012-02-17 13:14:08 -0800177 public static final int RIL_RADIO_TECHNOLOGY_GPRS = 1;
Wink Saville767a6622009-04-02 01:37:02 -0700178 /** @hide */
Robert Greenwalt1434d7b2012-02-17 13:14:08 -0800179 public static final int RIL_RADIO_TECHNOLOGY_EDGE = 2;
Wink Saville767a6622009-04-02 01:37:02 -0700180 /** @hide */
Robert Greenwalt1434d7b2012-02-17 13:14:08 -0800181 public static final int RIL_RADIO_TECHNOLOGY_UMTS = 3;
Wink Saville767a6622009-04-02 01:37:02 -0700182 /** @hide */
Robert Greenwalt1434d7b2012-02-17 13:14:08 -0800183 public static final int RIL_RADIO_TECHNOLOGY_IS95A = 4;
Wink Saville767a6622009-04-02 01:37:02 -0700184 /** @hide */
Robert Greenwalt1434d7b2012-02-17 13:14:08 -0800185 public static final int RIL_RADIO_TECHNOLOGY_IS95B = 5;
Wink Saville767a6622009-04-02 01:37:02 -0700186 /** @hide */
Robert Greenwalt1434d7b2012-02-17 13:14:08 -0800187 public static final int RIL_RADIO_TECHNOLOGY_1xRTT = 6;
Wink Saville767a6622009-04-02 01:37:02 -0700188 /** @hide */
Robert Greenwalt1434d7b2012-02-17 13:14:08 -0800189 public static final int RIL_RADIO_TECHNOLOGY_EVDO_0 = 7;
Wink Saville767a6622009-04-02 01:37:02 -0700190 /** @hide */
Robert Greenwalt1434d7b2012-02-17 13:14:08 -0800191 public static final int RIL_RADIO_TECHNOLOGY_EVDO_A = 8;
Li Zheebe66342009-08-14 19:22:16 +0800192 /** @hide */
Robert Greenwalt1434d7b2012-02-17 13:14:08 -0800193 public static final int RIL_RADIO_TECHNOLOGY_HSDPA = 9;
Li Zheebe66342009-08-14 19:22:16 +0800194 /** @hide */
Robert Greenwalt1434d7b2012-02-17 13:14:08 -0800195 public static final int RIL_RADIO_TECHNOLOGY_HSUPA = 10;
Li Zheebe66342009-08-14 19:22:16 +0800196 /** @hide */
Robert Greenwalt1434d7b2012-02-17 13:14:08 -0800197 public static final int RIL_RADIO_TECHNOLOGY_HSPA = 11;
Naveen Kalla0a5174a2010-04-21 14:48:03 -0700198 /** @hide */
Robert Greenwalt1434d7b2012-02-17 13:14:08 -0800199 public static final int RIL_RADIO_TECHNOLOGY_EVDO_B = 12;
Wink Saville9d7d6282011-03-12 14:52:01 -0800200 /** @hide */
Robert Greenwalt1434d7b2012-02-17 13:14:08 -0800201 public static final int RIL_RADIO_TECHNOLOGY_EHRPD = 13;
Wink Saville9d7d6282011-03-12 14:52:01 -0800202 /** @hide */
Robert Greenwalt1434d7b2012-02-17 13:14:08 -0800203 public static final int RIL_RADIO_TECHNOLOGY_LTE = 14;
Ramesh Sudinif5727612011-03-08 15:51:52 -0600204 /** @hide */
Robert Greenwalt1434d7b2012-02-17 13:14:08 -0800205 public static final int RIL_RADIO_TECHNOLOGY_HSPAP = 15;
Naveen Kallafc2cbe92011-12-29 15:07:41 -0800206 /**
207 * GSM radio technology only supports voice. It does not support data.
208 * @hide
209 */
Robert Greenwalt1434d7b2012-02-17 13:14:08 -0800210 public static final int RIL_RADIO_TECHNOLOGY_GSM = 16;
Etan Cohen6415fba32014-10-02 11:06:23 -0700211 /** @hide */
212 public static final int RIL_RADIO_TECHNOLOGY_TD_SCDMA = 17;
Yashdev Singhbece9262015-02-23 13:04:51 -0800213 /**
214 * IWLAN
215 * @hide
216 */
chen xuf4c5c6e2018-11-18 18:56:00 -0800217 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
Yashdev Singhbece9262015-02-23 13:04:51 -0800218 public static final int RIL_RADIO_TECHNOLOGY_IWLAN = 18;
Jack Yufa530b42016-01-04 10:04:34 -0800219
Ajay Nambi7965fa42015-05-14 18:48:33 -0700220 /**
221 * LTE_CA
222 * @hide
223 */
224 public static final int RIL_RADIO_TECHNOLOGY_LTE_CA = 19;
225
Cassied53df962017-12-05 13:34:33 -0800226 /**
Pengquan Meng6b849c22018-11-27 19:32:39 -0800227 * NR(New Radio) 5G.
228 * @hide
Cassied53df962017-12-05 13:34:33 -0800229 */
Pengquan Meng6b849c22018-11-27 19:32:39 -0800230 public static final int RIL_RADIO_TECHNOLOGY_NR = 20;
231
232 /**
Daniel Brightd75d5342019-12-20 10:30:18 -0800233 * 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 /**
Pengquan Meng6b849c22018-11-27 19:32:39 -0800263 * The number of the radio technologies.
264 */
265 private static final int NEXT_RIL_RADIO_TECHNOLOGY = 21;
Cassied53df962017-12-05 13:34:33 -0800266
Jack Yufa530b42016-01-04 10:04:34 -0800267 /** @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
Wink Saville0dde2c22012-11-16 08:12:11 -0800277 private int mVoiceRegState = STATE_OUT_OF_SERVICE;
278 private int mDataRegState = STATE_OUT_OF_SERVICE;
Jing Zhaoe6edb162014-07-18 09:34:36 -0500279
chen xu02811692018-10-03 19:07:09 -0700280 /** @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 {}
chen xue6e2a642018-11-05 15:59:57 -0800289
Jing Zhaoe6edb162014-07-18 09:34:36 -0500290 /**
chen xue6e2a642018-11-05 15:59:57 -0800291 * Not roaming, registered in home network.
Jing Zhaoe6edb162014-07-18 09:34:36 -0500292 * @hide
293 */
chen xue6e2a642018-11-05 15:59:57 -0800294 @SystemApi
Jing Zhaoe6edb162014-07-18 09:34:36 -0500295 public static final int ROAMING_TYPE_NOT_ROAMING = 0;
296 /**
chen xue6e2a642018-11-05 15:59:57 -0800297 * registered in a roaming network, but can not tell if it's domestic or international.
Jing Zhaoe6edb162014-07-18 09:34:36 -0500298 * @hide
299 */
chen xue6e2a642018-11-05 15:59:57 -0800300 @SystemApi
Jing Zhaoe6edb162014-07-18 09:34:36 -0500301 public static final int ROAMING_TYPE_UNKNOWN = 1;
302 /**
chen xue6e2a642018-11-05 15:59:57 -0800303 * registered in a domestic roaming network
Jing Zhaoe6edb162014-07-18 09:34:36 -0500304 * @hide
305 */
chen xue6e2a642018-11-05 15:59:57 -0800306 @SystemApi
Jing Zhaoe6edb162014-07-18 09:34:36 -0500307 public static final int ROAMING_TYPE_DOMESTIC = 2;
308 /**
chen xue6e2a642018-11-05 15:59:57 -0800309 * registered in an international roaming network
Jing Zhaoe6edb162014-07-18 09:34:36 -0500310 * @hide
311 */
chen xue6e2a642018-11-05 15:59:57 -0800312 @SystemApi
Jing Zhaoe6edb162014-07-18 09:34:36 -0500313 public static final int ROAMING_TYPE_INTERNATIONAL = 3;
314
Jack Yu9cd3b7b2018-01-02 15:51:34 -0800315 /**
Jack Yu2661fac2018-03-15 13:51:05 -0700316 * Unknown ID. Could be returned by {@link #getCdmaNetworkId()} or {@link #getCdmaSystemId()}
Jack Yu9cd3b7b2018-01-02 15:51:34 -0800317 */
318 public static final int UNKNOWN_ID = -1;
319
Amit Mahajanbb61b172020-01-23 18:00:08 -0800320 /**
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
SongFerngWang2b1ea8d2019-11-20 02:11:09 +0800328 private String mOperatorAlphaLong;
329 private String mOperatorAlphaShort;
330 private String mOperatorNumeric;
Chen Xu4c0b06d2018-10-22 16:54:39 +0000331 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800332 private boolean mIsManualNetworkSelection;
333
John Wang56c2d2f2010-04-07 08:57:17 -0700334 private boolean mIsEmergencyOnly;
Wink Saville0dde2c22012-11-16 08:12:11 -0800335
Mathew Inwood55418ea2018-12-20 15:30:45 +0000336 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Wink Saville767a6622009-04-02 01:37:02 -0700337 private boolean mCssIndicator;
Chen Xu4c0b06d2018-10-22 16:54:39 +0000338 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
Wink Saville767a6622009-04-02 01:37:02 -0700339 private int mNetworkId;
Chen Xu4c0b06d2018-10-22 16:54:39 +0000340 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
Wink Saville767a6622009-04-02 01:37:02 -0700341 private int mSystemId;
Mathew Inwood55418ea2018-12-20 15:30:45 +0000342 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Wink Savillee9b06d72009-05-18 21:47:50 -0700343 private int mCdmaRoamingIndicator;
Mathew Inwood55418ea2018-12-20 15:30:45 +0000344 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Wink Savillee9b06d72009-05-18 21:47:50 -0700345 private int mCdmaDefaultRoamingIndicator;
Mathew Inwood55418ea2018-12-20 15:30:45 +0000346 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700347 private int mCdmaEriIconIndex;
Mathew Inwood55418ea2018-12-20 15:30:45 +0000348 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700349 private int mCdmaEriIconMode;
Wink Saville767a6622009-04-02 01:37:02 -0700350
Pengquan Meng6aa52132018-11-13 17:06:34 -0800351 @FrequencyRange
352 private int mNrFrequencyRange;
Eric Schwarzenbach09a77732018-01-18 14:42:00 -0800353 private int mChannelNumber;
354 private int[] mCellBandwidths = new int[0];
355
Sooraj Sasindranc5659ca2017-03-08 23:43:17 -0800356 /* EARFCN stands for E-UTRA Absolute Radio Frequency Channel Number,
357 * Reference: 3GPP TS 36.104 5.4.3 */
358 private int mLteEarfcnRsrpBoost = 0;
359
Jack Yu4c118092019-05-16 14:27:29 -0700360 private final List<NetworkRegistrationInfo> mNetworkRegistrationInfos = new ArrayList<>();
Jack Yud5f1de12017-12-21 11:00:05 -0800361
SongFerngWang3cbcf752019-03-21 23:14:20 +0800362 private String mOperatorAlphaLongRaw;
363 private String mOperatorAlphaShortRaw;
Sarah Chind4b4da22020-01-07 16:32:39 -0800364 private boolean mIsDataRoamingFromRegistration;
Jack Yua74f2d82019-05-21 17:16:22 -0700365 private boolean mIsIwlanPreferred;
SongFerngWang3cbcf752019-03-21 23:14:20 +0800366
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800367 /**
Jing Zhaoe6edb162014-07-18 09:34:36 -0500368 * get String description of roaming type
369 * @hide
370 */
371 public static final String getRoamingLogString(int roamingType) {
372 switch (roamingType) {
373 case ROAMING_TYPE_NOT_ROAMING:
374 return "home";
375
376 case ROAMING_TYPE_UNKNOWN:
377 return "roaming";
378
379 case ROAMING_TYPE_DOMESTIC:
380 return "Domestic Roaming";
381
382 case ROAMING_TYPE_INTERNATIONAL:
383 return "International Roaming";
384
385 default:
386 return "UNKNOWN";
387 }
388 }
389
390 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800391 * Create a new ServiceState from a intent notifier Bundle
392 *
Malcolm Chen8a8b1202019-12-27 16:49:44 -0800393 * This method is used to get ServiceState object from extras upon receiving
394 * {@link Intent#ACTION_SERVICE_STATE}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 *
396 * @param m Bundle from intent notifier
397 * @return newly created ServiceState
398 * @hide
399 */
Jordan Liu657ef5a2019-08-16 14:07:03 -0700400 @NonNull
Malcolm Chen9993fd62020-04-28 16:14:01 -0700401 @UnsupportedAppUsage
Jordan Liu657ef5a2019-08-16 14:07:03 -0700402 public static ServiceState newFromBundle(@NonNull Bundle m) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800403 ServiceState ret;
404 ret = new ServiceState();
405 ret.setFromNotifierBundle(m);
406 return ret;
407 }
408
409 /**
410 * Empty constructor
411 */
412 public ServiceState() {
413 }
414
415 /**
416 * Copy constructors
417 *
418 * @param s Source service state
419 */
420 public ServiceState(ServiceState s) {
421 copyFrom(s);
422 }
423
424 protected void copyFrom(ServiceState s) {
Wink Saville0dde2c22012-11-16 08:12:11 -0800425 mVoiceRegState = s.mVoiceRegState;
426 mDataRegState = s.mDataRegState;
SongFerngWang2b1ea8d2019-11-20 02:11:09 +0800427 mOperatorAlphaLong = s.mOperatorAlphaLong;
428 mOperatorAlphaShort = s.mOperatorAlphaShort;
429 mOperatorNumeric = s.mOperatorNumeric;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800430 mIsManualNetworkSelection = s.mIsManualNetworkSelection;
Wink Saville767a6622009-04-02 01:37:02 -0700431 mCssIndicator = s.mCssIndicator;
432 mNetworkId = s.mNetworkId;
433 mSystemId = s.mSystemId;
Wink Savillee9b06d72009-05-18 21:47:50 -0700434 mCdmaRoamingIndicator = s.mCdmaRoamingIndicator;
435 mCdmaDefaultRoamingIndicator = s.mCdmaDefaultRoamingIndicator;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700436 mCdmaEriIconIndex = s.mCdmaEriIconIndex;
437 mCdmaEriIconMode = s.mCdmaEriIconMode;
John Wang56c2d2f2010-04-07 08:57:17 -0700438 mIsEmergencyOnly = s.mIsEmergencyOnly;
Jack Yu7d20eae2018-02-22 14:24:16 -0800439 mChannelNumber = s.mChannelNumber;
yifan.bai257be472018-08-21 13:42:58 +0800440 mCellBandwidths = s.mCellBandwidths == null ? null :
441 Arrays.copyOf(s.mCellBandwidths, s.mCellBandwidths.length);
Sooraj Sasindranc5659ca2017-03-08 23:43:17 -0800442 mLteEarfcnRsrpBoost = s.mLteEarfcnRsrpBoost;
Jack Yu4c118092019-05-16 14:27:29 -0700443 synchronized (mNetworkRegistrationInfos) {
444 mNetworkRegistrationInfos.clear();
445 mNetworkRegistrationInfos.addAll(s.getNetworkRegistrationInfoList());
446 }
Pengquan Meng6aa52132018-11-13 17:06:34 -0800447 mNrFrequencyRange = s.mNrFrequencyRange;
SongFerngWang3cbcf752019-03-21 23:14:20 +0800448 mOperatorAlphaLongRaw = s.mOperatorAlphaLongRaw;
449 mOperatorAlphaShortRaw = s.mOperatorAlphaShortRaw;
Sarah Chind4b4da22020-01-07 16:32:39 -0800450 mIsDataRoamingFromRegistration = s.mIsDataRoamingFromRegistration;
Jack Yua74f2d82019-05-21 17:16:22 -0700451 mIsIwlanPreferred = s.mIsIwlanPreferred;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800452 }
453
454 /**
455 * Construct a ServiceState object from the given parcel.
Jack Yu6bd48a22019-03-01 14:52:59 -0800456 *
457 * @deprecated The constructor takes parcel should not be public at the beginning. Use
458 * {@link #ServiceState()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800459 */
Jack Yu6bd48a22019-03-01 14:52:59 -0800460 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800461 public ServiceState(Parcel in) {
Wink Saville0dde2c22012-11-16 08:12:11 -0800462 mVoiceRegState = in.readInt();
463 mDataRegState = in.readInt();
SongFerngWang2b1ea8d2019-11-20 02:11:09 +0800464 mOperatorAlphaLong = in.readString();
465 mOperatorAlphaShort = in.readString();
466 mOperatorNumeric = in.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800467 mIsManualNetworkSelection = in.readInt() != 0;
Wink Saville767a6622009-04-02 01:37:02 -0700468 mCssIndicator = (in.readInt() != 0);
469 mNetworkId = in.readInt();
470 mSystemId = in.readInt();
Wink Savillee9b06d72009-05-18 21:47:50 -0700471 mCdmaRoamingIndicator = in.readInt();
472 mCdmaDefaultRoamingIndicator = in.readInt();
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700473 mCdmaEriIconIndex = in.readInt();
474 mCdmaEriIconMode = in.readInt();
John Wang56c2d2f2010-04-07 08:57:17 -0700475 mIsEmergencyOnly = in.readInt() != 0;
Sooraj Sasindranc5659ca2017-03-08 23:43:17 -0800476 mLteEarfcnRsrpBoost = in.readInt();
Jack Yu4c118092019-05-16 14:27:29 -0700477 synchronized (mNetworkRegistrationInfos) {
478 in.readList(mNetworkRegistrationInfos, NetworkRegistrationInfo.class.getClassLoader());
479 }
Eric Schwarzenbach09a77732018-01-18 14:42:00 -0800480 mChannelNumber = in.readInt();
481 mCellBandwidths = in.createIntArray();
Pengquan Meng6aa52132018-11-13 17:06:34 -0800482 mNrFrequencyRange = in.readInt();
SongFerngWang3cbcf752019-03-21 23:14:20 +0800483 mOperatorAlphaLongRaw = in.readString();
484 mOperatorAlphaShortRaw = in.readString();
Sarah Chind4b4da22020-01-07 16:32:39 -0800485 mIsDataRoamingFromRegistration = in.readBoolean();
Jack Yua74f2d82019-05-21 17:16:22 -0700486 mIsIwlanPreferred = in.readBoolean();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800487 }
488
489 public void writeToParcel(Parcel out, int flags) {
Wink Saville0dde2c22012-11-16 08:12:11 -0800490 out.writeInt(mVoiceRegState);
491 out.writeInt(mDataRegState);
SongFerngWang2b1ea8d2019-11-20 02:11:09 +0800492 out.writeString(mOperatorAlphaLong);
493 out.writeString(mOperatorAlphaShort);
494 out.writeString(mOperatorNumeric);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800495 out.writeInt(mIsManualNetworkSelection ? 1 : 0);
Wink Saville767a6622009-04-02 01:37:02 -0700496 out.writeInt(mCssIndicator ? 1 : 0);
497 out.writeInt(mNetworkId);
498 out.writeInt(mSystemId);
Wink Savillee9b06d72009-05-18 21:47:50 -0700499 out.writeInt(mCdmaRoamingIndicator);
500 out.writeInt(mCdmaDefaultRoamingIndicator);
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700501 out.writeInt(mCdmaEriIconIndex);
502 out.writeInt(mCdmaEriIconMode);
John Wang56c2d2f2010-04-07 08:57:17 -0700503 out.writeInt(mIsEmergencyOnly ? 1 : 0);
Sooraj Sasindranc5659ca2017-03-08 23:43:17 -0800504 out.writeInt(mLteEarfcnRsrpBoost);
Jack Yu4c118092019-05-16 14:27:29 -0700505 synchronized (mNetworkRegistrationInfos) {
506 out.writeList(mNetworkRegistrationInfos);
507 }
Eric Schwarzenbach09a77732018-01-18 14:42:00 -0800508 out.writeInt(mChannelNumber);
509 out.writeIntArray(mCellBandwidths);
Pengquan Meng6aa52132018-11-13 17:06:34 -0800510 out.writeInt(mNrFrequencyRange);
SongFerngWang3cbcf752019-03-21 23:14:20 +0800511 out.writeString(mOperatorAlphaLongRaw);
512 out.writeString(mOperatorAlphaShortRaw);
Sarah Chind4b4da22020-01-07 16:32:39 -0800513 out.writeBoolean(mIsDataRoamingFromRegistration);
Jack Yua74f2d82019-05-21 17:16:22 -0700514 out.writeBoolean(mIsIwlanPreferred);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800515 }
516
517 public int describeContents() {
518 return 0;
519 }
520
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700521 public static final @android.annotation.NonNull Parcelable.Creator<ServiceState> CREATOR =
Jake Hamby390de222010-05-10 18:46:45 -0700522 new Parcelable.Creator<ServiceState>() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800523 public ServiceState createFromParcel(Parcel in) {
524 return new ServiceState(in);
525 }
526
527 public ServiceState[] newArray(int size) {
528 return new ServiceState[size];
529 }
530 };
531
532 /**
Wink Saville0dde2c22012-11-16 08:12:11 -0800533 * Get current voice service state
534 */
535 public int getState() {
536 return getVoiceRegState();
537 }
538
539 /**
540 * Get current voice service state
Wink Savilleb690ac32012-11-14 17:03:01 -0800541 *
Wink Saville69e25222012-11-15 15:16:45 -0800542 * @see #STATE_IN_SERVICE
543 * @see #STATE_OUT_OF_SERVICE
544 * @see #STATE_EMERGENCY_ONLY
545 * @see #STATE_POWER_OFF
Wink Saville0dde2c22012-11-16 08:12:11 -0800546 *
547 * @hide
Wink Savilleb690ac32012-11-14 17:03:01 -0800548 */
Chen Xu4c0b06d2018-10-22 16:54:39 +0000549 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
Wink Saville0dde2c22012-11-16 08:12:11 -0800550 public int getVoiceRegState() {
551 return mVoiceRegState;
552 }
553
554 /**
SongFerngWange5202be2019-12-02 21:19:24 +0800555 * Get current data registration state.
Wink Saville0dde2c22012-11-16 08:12:11 -0800556 *
557 * @see #STATE_IN_SERVICE
558 * @see #STATE_OUT_OF_SERVICE
559 * @see #STATE_EMERGENCY_ONLY
560 * @see #STATE_POWER_OFF
561 *
SongFerngWangd82fbaf2019-12-02 21:19:24 +0800562 * @return current data registration state
SongFerngWange5202be2019-12-02 21:19:24 +0800563 *
Wink Saville0dde2c22012-11-16 08:12:11 -0800564 * @hide
565 */
chen xu75355b32019-01-29 15:56:40 -0800566 @UnsupportedAppUsage
Wink Saville0dde2c22012-11-16 08:12:11 -0800567 public int getDataRegState() {
568 return mDataRegState;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569 }
570
571 /**
SongFerngWange5202be2019-12-02 21:19:24 +0800572 * Get current data registration state.
573 *
574 * @see #STATE_IN_SERVICE
575 * @see #STATE_OUT_OF_SERVICE
576 * @see #STATE_EMERGENCY_ONLY
577 * @see #STATE_POWER_OFF
578 *
SongFerngWangd82fbaf2019-12-02 21:19:24 +0800579 * @return current data registration state
SongFerngWange5202be2019-12-02 21:19:24 +0800580 *
581 * @hide
582 */
SongFerngWange5202be2019-12-02 21:19:24 +0800583 public @RegState int getDataRegistrationState() {
584 return getDataRegState();
585 }
586
587 /**
Eric Schwarzenbach09a77732018-01-18 14:42:00 -0800588 * Get the current duplex mode
589 *
590 * @see #DUPLEX_MODE_UNKNOWN
591 * @see #DUPLEX_MODE_FDD
592 * @see #DUPLEX_MODE_TDD
593 *
594 * @return Current {@code DuplexMode} for the phone
595 */
596 @DuplexMode
597 public int getDuplexMode() {
Sarah Chin96169ca2020-01-07 17:45:05 -0800598 // support LTE/NR duplex mode
599 if (!isPsOnlyTech(getRilDataRadioTechnology())) {
Eric Schwarzenbach2c1a1772018-03-02 17:47:13 -0800600 return DUPLEX_MODE_UNKNOWN;
601 }
602
603 int band = AccessNetworkUtils.getOperatingBandForEarfcn(mChannelNumber);
604 return AccessNetworkUtils.getDuplexModeForEutranBand(band);
Eric Schwarzenbach09a77732018-01-18 14:42:00 -0800605 }
606
607 /**
608 * Get the channel number of the current primary serving cell, or -1 if unknown
609 *
610 * <p>This is EARFCN for LTE, UARFCN for UMTS, and ARFCN for GSM.
611 *
612 * @return Channel number of primary serving cell
613 */
614 public int getChannelNumber() {
615 return mChannelNumber;
616 }
617
618 /**
619 * Get an array of cell bandwidths (kHz) for the current serving cells
620 *
621 * @return Current serving cell bandwidths
622 */
Eric Schwarzenbach09a77732018-01-18 14:42:00 -0800623 public int[] getCellBandwidths() {
Eric Schwarzenbachc119a862018-03-22 13:49:25 -0700624 return mCellBandwidths == null ? new int[0] : mCellBandwidths;
Eric Schwarzenbach09a77732018-01-18 14:42:00 -0800625 }
626
627 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800628 * Get current roaming indicator of phone
629 * (note: not just decoding from TS 27.007 7.2)
630 *
631 * @return true if TS 27.007 7.2 roaming is true
632 * and ONS is different from SPN
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800633 */
634 public boolean getRoaming() {
Jing Zhaoe6edb162014-07-18 09:34:36 -0500635 return getVoiceRoaming() || getDataRoaming();
636 }
637
638 /**
639 * Get current voice network roaming status
640 * @return roaming status
641 * @hide
642 */
Chen Xu4c0b06d2018-10-22 16:54:39 +0000643 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
Jing Zhaoe6edb162014-07-18 09:34:36 -0500644 public boolean getVoiceRoaming() {
chen xu02811692018-10-03 19:07:09 -0700645 return getVoiceRoamingType() != ROAMING_TYPE_NOT_ROAMING;
Jing Zhaoe6edb162014-07-18 09:34:36 -0500646 }
Jing Zhaoe6edb162014-07-18 09:34:36 -0500647 /**
648 * Get current voice network roaming type
649 * @return roaming type
650 * @hide
651 */
chen xuf4c5c6e2018-11-18 18:56:00 -0800652 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
chen xu02811692018-10-03 19:07:09 -0700653 public @RoamingType int getVoiceRoamingType() {
Jack Yue27d3fd2019-03-15 14:49:53 -0700654 final NetworkRegistrationInfo regState = getNetworkRegistrationInfo(
655 NetworkRegistrationInfo.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
chen xu02811692018-10-03 19:07:09 -0700656 if (regState != null) {
657 return regState.getRoamingType();
658 }
659 return ROAMING_TYPE_NOT_ROAMING;
Jing Zhaoe6edb162014-07-18 09:34:36 -0500660 }
661
662 /**
Sarah Chind4b4da22020-01-07 16:32:39 -0800663 * Get whether the current data network is roaming.
664 * This value may be overwritten by resource overlay or carrier configuration.
665 * @see #getDataRoamingFromRegistration() to get the value from the network registration.
Jing Zhaoe6edb162014-07-18 09:34:36 -0500666 * @return roaming type
667 * @hide
668 */
Chen Xu4c0b06d2018-10-22 16:54:39 +0000669 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
Jing Zhaoe6edb162014-07-18 09:34:36 -0500670 public boolean getDataRoaming() {
chen xu02811692018-10-03 19:07:09 -0700671 return getDataRoamingType() != ROAMING_TYPE_NOT_ROAMING;
Chris Manton1428f432015-08-10 13:32:24 -0700672 }
673
674 /**
Sarah Chind4b4da22020-01-07 16:32:39 -0800675 * Set whether the data network registration state is roaming.
676 * This should only be set to the roaming value received
677 * once the data registration phase has completed.
678 * @hide
679 */
680 public void setDataRoamingFromRegistration(boolean dataRoaming) {
681 mIsDataRoamingFromRegistration = dataRoaming;
682 }
683
684 /**
685 * Get whether data network registration state is roaming.
686 * This value is set directly from the modem and will not be overwritten
687 * by resource overlay or carrier configuration.
Chris Manton1428f432015-08-10 13:32:24 -0700688 * @return true if registration indicates roaming, false otherwise
689 * @hide
690 */
691 public boolean getDataRoamingFromRegistration() {
Sarah Chinba01f232020-03-10 11:46:42 -0700692 // TODO: all callers should refactor to get roaming state directly from modem
693 // this should not be exposed as a public API
Sarah Chind4b4da22020-01-07 16:32:39 -0800694 return mIsDataRoamingFromRegistration;
Chris Manton1428f432015-08-10 13:32:24 -0700695 }
696
697 /**
Jing Zhaoe6edb162014-07-18 09:34:36 -0500698 * Get current data network roaming type
699 * @return roaming type
700 * @hide
701 */
chen xuf4c5c6e2018-11-18 18:56:00 -0800702 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
chen xu02811692018-10-03 19:07:09 -0700703 public @RoamingType int getDataRoamingType() {
Jack Yue27d3fd2019-03-15 14:49:53 -0700704 final NetworkRegistrationInfo regState = getNetworkRegistrationInfo(
705 NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
chen xu02811692018-10-03 19:07:09 -0700706 if (regState != null) {
707 return regState.getRoamingType();
708 }
709 return ROAMING_TYPE_NOT_ROAMING;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800710 }
711
Wink Savillee9b06d72009-05-18 21:47:50 -0700712 /**
713 * @hide
714 */
Mathew Inwooda8382062018-08-16 17:01:12 +0100715 @UnsupportedAppUsage
John Wang56c2d2f2010-04-07 08:57:17 -0700716 public boolean isEmergencyOnly() {
717 return mIsEmergencyOnly;
718 }
719
720 /**
721 * @hide
722 */
Mathew Inwooda8382062018-08-16 17:01:12 +0100723 @UnsupportedAppUsage
Wink Savillee9b06d72009-05-18 21:47:50 -0700724 public int getCdmaRoamingIndicator(){
725 return this.mCdmaRoamingIndicator;
726 }
727
728 /**
729 * @hide
730 */
Mathew Inwooda8382062018-08-16 17:01:12 +0100731 @UnsupportedAppUsage
Wink Savillee9b06d72009-05-18 21:47:50 -0700732 public int getCdmaDefaultRoamingIndicator(){
733 return this.mCdmaDefaultRoamingIndicator;
Wink Saville767a6622009-04-02 01:37:02 -0700734 }
735
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800736 /**
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700737 * @hide
738 */
Mathew Inwooda8382062018-08-16 17:01:12 +0100739 @UnsupportedAppUsage
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700740 public int getCdmaEriIconIndex() {
741 return this.mCdmaEriIconIndex;
742 }
743
744 /**
745 * @hide
746 */
Mathew Inwooda8382062018-08-16 17:01:12 +0100747 @UnsupportedAppUsage
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700748 public int getCdmaEriIconMode() {
749 return this.mCdmaEriIconMode;
750 }
751
752 /**
Jake Hamby390de222010-05-10 18:46:45 -0700753 * Get current registered operator name in long alphanumeric format.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800754 *
Jake Hamby390de222010-05-10 18:46:45 -0700755 * In GSM/UMTS, long format can be up to 16 characters long.
756 * In CDMA, returns the ERI text, if set. Otherwise, returns the ONS.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800757 *
758 * @return long name of operator, null if unregistered or unknown
759 */
760 public String getOperatorAlphaLong() {
SongFerngWang2b1ea8d2019-11-20 02:11:09 +0800761 return mOperatorAlphaLong;
Jing Zhaoe6edb162014-07-18 09:34:36 -0500762 }
763
764 /**
765 * Get current registered voice network operator name in long alphanumeric format.
766 * @return long name of operator
767 * @hide
768 */
SongFerngWang2b1ea8d2019-11-20 02:11:09 +0800769 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q,
770 publicAlternatives = "Use {@link #getOperatorAlphaLong} instead.")
Jing Zhaoe6edb162014-07-18 09:34:36 -0500771 public String getVoiceOperatorAlphaLong() {
SongFerngWang2b1ea8d2019-11-20 02:11:09 +0800772 return mOperatorAlphaLong;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800773 }
774
775 /**
Jake Hamby390de222010-05-10 18:46:45 -0700776 * Get current registered operator name in short alphanumeric format.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800777 *
Jake Hamby390de222010-05-10 18:46:45 -0700778 * In GSM/UMTS, short format can be up to 8 characters long.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800779 *
780 * @return short name of operator, null if unregistered or unknown
781 */
782 public String getOperatorAlphaShort() {
SongFerngWang2b1ea8d2019-11-20 02:11:09 +0800783 return mOperatorAlphaShort;
Jing Zhaoe6edb162014-07-18 09:34:36 -0500784 }
785
786 /**
787 * Get current registered voice network operator name in short alphanumeric format.
788 * @return short name of operator, null if unregistered or unknown
789 * @hide
790 */
SongFerngWang2b1ea8d2019-11-20 02:11:09 +0800791 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q,
792 publicAlternatives = "Use {@link #getOperatorAlphaShort} instead.")
Jing Zhaoe6edb162014-07-18 09:34:36 -0500793 public String getVoiceOperatorAlphaShort() {
SongFerngWang2b1ea8d2019-11-20 02:11:09 +0800794 return mOperatorAlphaShort;
Jing Zhaoe6edb162014-07-18 09:34:36 -0500795 }
796
797 /**
798 * Get current registered data network operator name in short alphanumeric format.
799 * @return short name of operator, null if unregistered or unknown
800 * @hide
801 */
SongFerngWang2b1ea8d2019-11-20 02:11:09 +0800802 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q,
803 publicAlternatives = "Use {@link #getOperatorAlphaShort} instead.")
Jing Zhaoe6edb162014-07-18 09:34:36 -0500804 public String getDataOperatorAlphaShort() {
SongFerngWang2b1ea8d2019-11-20 02:11:09 +0800805 return mOperatorAlphaShort;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800806 }
807
808 /**
Zoran Jovanovic47495eb2016-11-02 09:56:38 +0100809 * Get current registered operator name in long alphanumeric format if
810 * available or short otherwise.
811 *
812 * @see #getOperatorAlphaLong
813 * @see #getOperatorAlphaShort
814 *
815 * @return name of operator, null if unregistered or unknown
816 * @hide
817 */
818 public String getOperatorAlpha() {
SongFerngWang2b1ea8d2019-11-20 02:11:09 +0800819 if (TextUtils.isEmpty(mOperatorAlphaLong)) {
820 return mOperatorAlphaShort;
Zoran Jovanovic47495eb2016-11-02 09:56:38 +0100821 }
822
SongFerngWang2b1ea8d2019-11-20 02:11:09 +0800823 return mOperatorAlphaLong;
Zoran Jovanovic47495eb2016-11-02 09:56:38 +0100824 }
825
826 /**
Jake Hamby390de222010-05-10 18:46:45 -0700827 * Get current registered operator numeric id.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800828 *
829 * In GSM/UMTS, numeric format is 3 digit country code plus 2 or 3 digit
Jake Hamby390de222010-05-10 18:46:45 -0700830 * network code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800831 *
832 * @return numeric format of operator, null if unregistered or unknown
833 */
Jean-Baptiste Querue25863c2010-05-18 11:54:42 -0700834 /*
Jake Hamby390de222010-05-10 18:46:45 -0700835 * The country code can be decoded using
836 * {@link com.android.internal.telephony.MccTable#countryCodeForMcc(int)}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800837 */
838 public String getOperatorNumeric() {
SongFerngWang2b1ea8d2019-11-20 02:11:09 +0800839 return mOperatorNumeric;
Jing Zhaoe6edb162014-07-18 09:34:36 -0500840 }
841
842 /**
843 * Get current registered voice network operator numeric id.
844 * @return numeric format of operator, null if unregistered or unknown
845 * @hide
846 */
chen xuf4c5c6e2018-11-18 18:56:00 -0800847 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
Jing Zhaoe6edb162014-07-18 09:34:36 -0500848 public String getVoiceOperatorNumeric() {
SongFerngWang2b1ea8d2019-11-20 02:11:09 +0800849 return mOperatorNumeric;
Jing Zhaoe6edb162014-07-18 09:34:36 -0500850 }
851
852 /**
853 * Get current registered data network operator numeric id.
854 * @return numeric format of operator, null if unregistered or unknown
855 * @hide
856 */
SongFerngWang2b1ea8d2019-11-20 02:11:09 +0800857 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q,
858 publicAlternatives = "Use {@link #getOperatorNumeric} instead.")
Jing Zhaoe6edb162014-07-18 09:34:36 -0500859 public String getDataOperatorNumeric() {
SongFerngWang2b1ea8d2019-11-20 02:11:09 +0800860 return mOperatorNumeric;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800861 }
862
863 /**
Jake Hamby390de222010-05-10 18:46:45 -0700864 * Get current network selection mode.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800865 *
866 * @return true if manual mode, false if automatic mode
867 */
868 public boolean getIsManualSelection() {
869 return mIsManualNetworkSelection;
870 }
871
872 @Override
873 public int hashCode() {
Jack Yu4c118092019-05-16 14:27:29 -0700874 synchronized (mNetworkRegistrationInfos) {
875 return Objects.hash(
876 mVoiceRegState,
877 mDataRegState,
878 mChannelNumber,
879 Arrays.hashCode(mCellBandwidths),
SongFerngWang2b1ea8d2019-11-20 02:11:09 +0800880 mOperatorAlphaLong,
881 mOperatorAlphaShort,
882 mOperatorNumeric,
Jack Yu4c118092019-05-16 14:27:29 -0700883 mIsManualNetworkSelection,
884 mCssIndicator,
885 mNetworkId,
886 mSystemId,
887 mCdmaRoamingIndicator,
888 mCdmaDefaultRoamingIndicator,
889 mCdmaEriIconIndex,
890 mCdmaEriIconMode,
891 mIsEmergencyOnly,
892 mLteEarfcnRsrpBoost,
893 mNetworkRegistrationInfos,
894 mNrFrequencyRange,
895 mOperatorAlphaLongRaw,
Jack Yua74f2d82019-05-21 17:16:22 -0700896 mOperatorAlphaShortRaw,
Sarah Chind4b4da22020-01-07 16:32:39 -0800897 mIsDataRoamingFromRegistration,
Jack Yua74f2d82019-05-21 17:16:22 -0700898 mIsIwlanPreferred);
Jack Yu4c118092019-05-16 14:27:29 -0700899 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800900 }
901
902 @Override
903 public boolean equals (Object o) {
Nathan Harold7ee5f212018-06-27 17:21:17 -0700904 if (!(o instanceof ServiceState)) return false;
905 ServiceState s = (ServiceState) o;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800906
Jack Yu4c118092019-05-16 14:27:29 -0700907 synchronized (mNetworkRegistrationInfos) {
908 return mVoiceRegState == s.mVoiceRegState
909 && mDataRegState == s.mDataRegState
910 && mIsManualNetworkSelection == s.mIsManualNetworkSelection
911 && mChannelNumber == s.mChannelNumber
912 && Arrays.equals(mCellBandwidths, s.mCellBandwidths)
SongFerngWang2b1ea8d2019-11-20 02:11:09 +0800913 && equalsHandlesNulls(mOperatorAlphaLong, s.mOperatorAlphaLong)
914 && equalsHandlesNulls(mOperatorAlphaShort, s.mOperatorAlphaShort)
915 && equalsHandlesNulls(mOperatorNumeric, s.mOperatorNumeric)
Jack Yu4c118092019-05-16 14:27:29 -0700916 && equalsHandlesNulls(mCssIndicator, s.mCssIndicator)
917 && equalsHandlesNulls(mNetworkId, s.mNetworkId)
918 && equalsHandlesNulls(mSystemId, s.mSystemId)
919 && equalsHandlesNulls(mCdmaRoamingIndicator, s.mCdmaRoamingIndicator)
920 && equalsHandlesNulls(mCdmaDefaultRoamingIndicator,
921 s.mCdmaDefaultRoamingIndicator)
922 && mIsEmergencyOnly == s.mIsEmergencyOnly
923 && equalsHandlesNulls(mOperatorAlphaLongRaw, s.mOperatorAlphaLongRaw)
924 && equalsHandlesNulls(mOperatorAlphaShortRaw, s.mOperatorAlphaShortRaw)
925 && mNetworkRegistrationInfos.size() == s.mNetworkRegistrationInfos.size()
926 && mNetworkRegistrationInfos.containsAll(s.mNetworkRegistrationInfos)
Jack Yua74f2d82019-05-21 17:16:22 -0700927 && mNrFrequencyRange == s.mNrFrequencyRange
Sarah Chind4b4da22020-01-07 16:32:39 -0800928 && mIsDataRoamingFromRegistration == s.mIsDataRoamingFromRegistration
Jack Yua74f2d82019-05-21 17:16:22 -0700929 && mIsIwlanPreferred == s.mIsIwlanPreferred;
Jack Yu4c118092019-05-16 14:27:29 -0700930 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800931 }
932
Wink Savilledb09b5d2011-06-03 09:06:28 -0700933 /**
Jack Yu8fdb7502019-01-31 13:30:05 -0800934 * Convert roaming type to string
935 *
936 * @param roamingType roaming type
937 * @return The roaming type in string format
938 *
939 * @hide
940 */
941 public static String roamingTypeToString(@RoamingType int roamingType) {
942 switch (roamingType) {
943 case ROAMING_TYPE_NOT_ROAMING: return "NOT_ROAMING";
944 case ROAMING_TYPE_UNKNOWN: return "UNKNOWN";
945 case ROAMING_TYPE_DOMESTIC: return "DOMESTIC";
946 case ROAMING_TYPE_INTERNATIONAL: return "INTERNATIONAL";
947 }
948 return "Unknown roaming type " + roamingType;
949 }
950
951 /**
Wink Savilledb09b5d2011-06-03 09:06:28 -0700952 * Convert radio technology to String
953 *
Jack Yud5f1de12017-12-21 11:00:05 -0800954 * @param rt radioTechnology
Wink Savilledb09b5d2011-06-03 09:06:28 -0700955 * @return String representation of the RAT
956 *
957 * @hide
958 */
Mathew Inwooda8382062018-08-16 17:01:12 +0100959 @UnsupportedAppUsage
Robert Greenwalt1434d7b2012-02-17 13:14:08 -0800960 public static String rilRadioTechnologyToString(int rt) {
Wink Savilledb09b5d2011-06-03 09:06:28 -0700961 String rtString;
962
963 switch(rt) {
Robert Greenwalt1434d7b2012-02-17 13:14:08 -0800964 case RIL_RADIO_TECHNOLOGY_UNKNOWN:
Wink Savilledb09b5d2011-06-03 09:06:28 -0700965 rtString = "Unknown";
966 break;
Robert Greenwalt1434d7b2012-02-17 13:14:08 -0800967 case RIL_RADIO_TECHNOLOGY_GPRS:
Wink Savilledb09b5d2011-06-03 09:06:28 -0700968 rtString = "GPRS";
969 break;
Robert Greenwalt1434d7b2012-02-17 13:14:08 -0800970 case RIL_RADIO_TECHNOLOGY_EDGE:
Wink Savilledb09b5d2011-06-03 09:06:28 -0700971 rtString = "EDGE";
972 break;
Robert Greenwalt1434d7b2012-02-17 13:14:08 -0800973 case RIL_RADIO_TECHNOLOGY_UMTS:
Wink Savilledb09b5d2011-06-03 09:06:28 -0700974 rtString = "UMTS";
975 break;
Robert Greenwalt1434d7b2012-02-17 13:14:08 -0800976 case RIL_RADIO_TECHNOLOGY_IS95A:
Wink Savilledb09b5d2011-06-03 09:06:28 -0700977 rtString = "CDMA-IS95A";
978 break;
Robert Greenwalt1434d7b2012-02-17 13:14:08 -0800979 case RIL_RADIO_TECHNOLOGY_IS95B:
Wink Savilledb09b5d2011-06-03 09:06:28 -0700980 rtString = "CDMA-IS95B";
981 break;
Robert Greenwalt1434d7b2012-02-17 13:14:08 -0800982 case RIL_RADIO_TECHNOLOGY_1xRTT:
Wink Savilledb09b5d2011-06-03 09:06:28 -0700983 rtString = "1xRTT";
984 break;
Robert Greenwalt1434d7b2012-02-17 13:14:08 -0800985 case RIL_RADIO_TECHNOLOGY_EVDO_0:
Wink Savilledb09b5d2011-06-03 09:06:28 -0700986 rtString = "EvDo-rev.0";
987 break;
Robert Greenwalt1434d7b2012-02-17 13:14:08 -0800988 case RIL_RADIO_TECHNOLOGY_EVDO_A:
Wink Savilledb09b5d2011-06-03 09:06:28 -0700989 rtString = "EvDo-rev.A";
990 break;
Robert Greenwalt1434d7b2012-02-17 13:14:08 -0800991 case RIL_RADIO_TECHNOLOGY_HSDPA:
Wink Savilledb09b5d2011-06-03 09:06:28 -0700992 rtString = "HSDPA";
993 break;
Robert Greenwalt1434d7b2012-02-17 13:14:08 -0800994 case RIL_RADIO_TECHNOLOGY_HSUPA:
Wink Savilledb09b5d2011-06-03 09:06:28 -0700995 rtString = "HSUPA";
996 break;
Robert Greenwalt1434d7b2012-02-17 13:14:08 -0800997 case RIL_RADIO_TECHNOLOGY_HSPA:
Wink Savilledb09b5d2011-06-03 09:06:28 -0700998 rtString = "HSPA";
999 break;
Robert Greenwalt1434d7b2012-02-17 13:14:08 -08001000 case RIL_RADIO_TECHNOLOGY_EVDO_B:
Wink Savilledb09b5d2011-06-03 09:06:28 -07001001 rtString = "EvDo-rev.B";
1002 break;
Robert Greenwalt1434d7b2012-02-17 13:14:08 -08001003 case RIL_RADIO_TECHNOLOGY_EHRPD:
Wink Savilledb09b5d2011-06-03 09:06:28 -07001004 rtString = "eHRPD";
1005 break;
Robert Greenwalt1434d7b2012-02-17 13:14:08 -08001006 case RIL_RADIO_TECHNOLOGY_LTE:
Wink Savilledb09b5d2011-06-03 09:06:28 -07001007 rtString = "LTE";
1008 break;
Robert Greenwalt1434d7b2012-02-17 13:14:08 -08001009 case RIL_RADIO_TECHNOLOGY_HSPAP:
Wink Savilledb09b5d2011-06-03 09:06:28 -07001010 rtString = "HSPAP";
1011 break;
Robert Greenwalt1434d7b2012-02-17 13:14:08 -08001012 case RIL_RADIO_TECHNOLOGY_GSM:
Naveen Kallafc2cbe92011-12-29 15:07:41 -08001013 rtString = "GSM";
1014 break;
Yashdev Singhbece9262015-02-23 13:04:51 -08001015 case RIL_RADIO_TECHNOLOGY_IWLAN:
1016 rtString = "IWLAN";
1017 break;
Sungmin Choi36980862015-08-26 11:05:46 -07001018 case RIL_RADIO_TECHNOLOGY_TD_SCDMA:
1019 rtString = "TD-SCDMA";
1020 break;
Ajay Nambi7965fa42015-05-14 18:48:33 -07001021 case RIL_RADIO_TECHNOLOGY_LTE_CA:
1022 rtString = "LTE_CA";
1023 break;
Avinash Nalluri61b44a22019-06-19 19:13:28 -07001024 case RIL_RADIO_TECHNOLOGY_NR:
Sarah Chind1941e572019-12-13 11:12:28 -08001025 rtString = "NR_SA";
Avinash Nalluri61b44a22019-06-19 19:13:28 -07001026 break;
Wink Savilledb09b5d2011-06-03 09:06:28 -07001027 default:
1028 rtString = "Unexpected";
Wink Saville599a90c2012-11-27 12:29:13 -08001029 Rlog.w(LOG_TAG, "Unexpected radioTechnology=" + rt);
Wink Savilledb09b5d2011-06-03 09:06:28 -07001030 break;
1031 }
Robert Greenwalt1434d7b2012-02-17 13:14:08 -08001032 return rtString;
Wink Savilledb09b5d2011-06-03 09:06:28 -07001033 }
1034
Nathan Harold9acfe6f2017-08-02 10:51:47 -07001035 /**
Jack Yue7580a72020-06-12 16:05:58 -07001036 * Convert frequency range into string
1037 *
1038 * @param range The cellular frequency range
1039 * @return Frequency range in string format
1040 *
1041 * @hide
1042 */
1043 public static @NonNull String frequencyRangeToString(@FrequencyRange int range) {
1044 switch (range) {
1045 case FREQUENCY_RANGE_UNKNOWN: return "UNKNOWN";
1046 case FREQUENCY_RANGE_LOW: return "LOW";
1047 case FREQUENCY_RANGE_MID: return "MID";
1048 case FREQUENCY_RANGE_HIGH: return "HIGH";
1049 case FREQUENCY_RANGE_MMWAVE: return "MMWAVE";
1050 default:
1051 return Integer.toString(range);
1052 }
1053 }
1054
1055 /**
Nathan Harold9acfe6f2017-08-02 10:51:47 -07001056 * Convert RIL Service State to String
1057 *
1058 * @param serviceState
1059 * @return String representation of the ServiceState
1060 *
1061 * @hide
1062 */
1063 public static String rilServiceStateToString(int serviceState) {
1064 switch(serviceState) {
1065 case STATE_IN_SERVICE:
1066 return "IN_SERVICE";
1067 case STATE_OUT_OF_SERVICE:
1068 return "OUT_OF_SERVICE";
1069 case STATE_EMERGENCY_ONLY:
1070 return "EMERGENCY_ONLY";
1071 case STATE_POWER_OFF:
1072 return "POWER_OFF";
1073 default:
1074 return "UNKNOWN";
1075 }
1076 }
1077
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078 @Override
1079 public String toString() {
Jack Yu4c118092019-05-16 14:27:29 -07001080 synchronized (mNetworkRegistrationInfos) {
1081 return new StringBuilder().append("{mVoiceRegState=").append(mVoiceRegState)
1082 .append("(" + rilServiceStateToString(mVoiceRegState) + ")")
1083 .append(", mDataRegState=").append(mDataRegState)
1084 .append("(" + rilServiceStateToString(mDataRegState) + ")")
1085 .append(", mChannelNumber=").append(mChannelNumber)
1086 .append(", duplexMode()=").append(getDuplexMode())
1087 .append(", mCellBandwidths=").append(Arrays.toString(mCellBandwidths))
SongFerngWang2b1ea8d2019-11-20 02:11:09 +08001088 .append(", mOperatorAlphaLong=").append(mOperatorAlphaLong)
1089 .append(", mOperatorAlphaShort=").append(mOperatorAlphaShort)
Jack Yu4c118092019-05-16 14:27:29 -07001090 .append(", isManualNetworkSelection=").append(mIsManualNetworkSelection)
1091 .append(mIsManualNetworkSelection ? "(manual)" : "(automatic)")
1092 .append(", getRilVoiceRadioTechnology=").append(getRilVoiceRadioTechnology())
1093 .append("(" + rilRadioTechnologyToString(getRilVoiceRadioTechnology()) + ")")
1094 .append(", getRilDataRadioTechnology=").append(getRilDataRadioTechnology())
1095 .append("(" + rilRadioTechnologyToString(getRilDataRadioTechnology()) + ")")
1096 .append(", mCssIndicator=").append(mCssIndicator ? "supported" : "unsupported")
1097 .append(", mNetworkId=").append(mNetworkId)
1098 .append(", mSystemId=").append(mSystemId)
1099 .append(", mCdmaRoamingIndicator=").append(mCdmaRoamingIndicator)
1100 .append(", mCdmaDefaultRoamingIndicator=").append(mCdmaDefaultRoamingIndicator)
1101 .append(", mIsEmergencyOnly=").append(mIsEmergencyOnly)
1102 .append(", isUsingCarrierAggregation=").append(isUsingCarrierAggregation())
1103 .append(", mLteEarfcnRsrpBoost=").append(mLteEarfcnRsrpBoost)
1104 .append(", mNetworkRegistrationInfos=").append(mNetworkRegistrationInfos)
1105 .append(", mNrFrequencyRange=").append(mNrFrequencyRange)
1106 .append(", mOperatorAlphaLongRaw=").append(mOperatorAlphaLongRaw)
1107 .append(", mOperatorAlphaShortRaw=").append(mOperatorAlphaShortRaw)
Sarah Chind4b4da22020-01-07 16:32:39 -08001108 .append(", mIsDataRoamingFromRegistration=")
1109 .append(mIsDataRoamingFromRegistration)
Jack Yua74f2d82019-05-21 17:16:22 -07001110 .append(", mIsIwlanPreferred=").append(mIsIwlanPreferred)
Jack Yu4c118092019-05-16 14:27:29 -07001111 .append("}").toString();
1112 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001113 }
1114
Jack Yu5ff5ab52019-04-02 13:14:03 -07001115 private void init() {
1116 if (DBG) Rlog.d(LOG_TAG, "init");
1117 mVoiceRegState = STATE_OUT_OF_SERVICE;
1118 mDataRegState = STATE_OUT_OF_SERVICE;
Eric Schwarzenbach09a77732018-01-18 14:42:00 -08001119 mChannelNumber = -1;
1120 mCellBandwidths = new int[0];
SongFerngWang2b1ea8d2019-11-20 02:11:09 +08001121 mOperatorAlphaLong = null;
1122 mOperatorAlphaShort = null;
1123 mOperatorNumeric = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001124 mIsManualNetworkSelection = false;
Wink Saville767a6622009-04-02 01:37:02 -07001125 mCssIndicator = false;
1126 mNetworkId = -1;
1127 mSystemId = -1;
Wink Savillee9b06d72009-05-18 21:47:50 -07001128 mCdmaRoamingIndicator = -1;
1129 mCdmaDefaultRoamingIndicator = -1;
Robert Greenwalt98e0b142009-10-08 21:15:52 -07001130 mCdmaEriIconIndex = -1;
1131 mCdmaEriIconMode = -1;
John Wang56c2d2f2010-04-07 08:57:17 -07001132 mIsEmergencyOnly = false;
Sooraj Sasindranc5659ca2017-03-08 23:43:17 -08001133 mLteEarfcnRsrpBoost = 0;
Pengquan Meng6aa52132018-11-13 17:06:34 -08001134 mNrFrequencyRange = FREQUENCY_RANGE_UNKNOWN;
Jack Yu4c118092019-05-16 14:27:29 -07001135 synchronized (mNetworkRegistrationInfos) {
1136 mNetworkRegistrationInfos.clear();
1137 addNetworkRegistrationInfo(new NetworkRegistrationInfo.Builder()
1138 .setDomain(NetworkRegistrationInfo.DOMAIN_CS)
1139 .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
1140 .setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_UNKNOWN)
1141 .build());
1142 addNetworkRegistrationInfo(new NetworkRegistrationInfo.Builder()
1143 .setDomain(NetworkRegistrationInfo.DOMAIN_PS)
1144 .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
1145 .setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_UNKNOWN)
1146 .build());
1147 }
SongFerngWang3cbcf752019-03-21 23:14:20 +08001148 mOperatorAlphaLongRaw = null;
1149 mOperatorAlphaShortRaw = null;
Sarah Chind4b4da22020-01-07 16:32:39 -08001150 mIsDataRoamingFromRegistration = false;
Jack Yua74f2d82019-05-21 17:16:22 -07001151 mIsIwlanPreferred = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001152 }
1153
Robert Greenwalta2267452011-06-30 12:24:26 -07001154 public void setStateOutOfService() {
Jack Yu5ff5ab52019-04-02 13:14:03 -07001155 init();
Robert Greenwalta2267452011-06-30 12:24:26 -07001156 }
1157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001158 public void setStateOff() {
Jack Yu5ff5ab52019-04-02 13:14:03 -07001159 init();
1160 mVoiceRegState = STATE_POWER_OFF;
1161 mDataRegState = STATE_POWER_OFF;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001162 }
1163
1164 public void setState(int state) {
Wink Saville0dde2c22012-11-16 08:12:11 -08001165 setVoiceRegState(state);
Wink Saville599a90c2012-11-27 12:29:13 -08001166 if (DBG) Rlog.e(LOG_TAG, "[ServiceState] setState deprecated use setVoiceRegState()");
Wink Saville0dde2c22012-11-16 08:12:11 -08001167 }
1168
1169 /** @hide */
Mathew Inwooda8382062018-08-16 17:01:12 +01001170 @UnsupportedAppUsage
Wink Saville0dde2c22012-11-16 08:12:11 -08001171 public void setVoiceRegState(int state) {
1172 mVoiceRegState = state;
Wink Saville599a90c2012-11-27 12:29:13 -08001173 if (DBG) Rlog.d(LOG_TAG, "[ServiceState] setVoiceRegState=" + mVoiceRegState);
Wink Saville0dde2c22012-11-16 08:12:11 -08001174 }
1175
1176 /** @hide */
Mathew Inwood55418ea2018-12-20 15:30:45 +00001177 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Wink Saville0dde2c22012-11-16 08:12:11 -08001178 public void setDataRegState(int state) {
1179 mDataRegState = state;
Jack Yu87f47e92016-01-05 15:50:40 -08001180 if (VDBG) Rlog.d(LOG_TAG, "[ServiceState] setDataRegState=" + mDataRegState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001181 }
1182
Eric Schwarzenbach09a77732018-01-18 14:42:00 -08001183 /** @hide */
Malcolm Chena1d5e9f2018-04-03 17:43:30 -07001184 @TestApi
Eric Schwarzenbach09a77732018-01-18 14:42:00 -08001185 public void setCellBandwidths(int[] bandwidths) {
1186 mCellBandwidths = bandwidths;
1187 }
1188
1189 /** @hide */
Malcolm Chena1d5e9f2018-04-03 17:43:30 -07001190 @TestApi
Eric Schwarzenbach09a77732018-01-18 14:42:00 -08001191 public void setChannelNumber(int channelNumber) {
1192 mChannelNumber = channelNumber;
1193 }
1194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001195 public void setRoaming(boolean roaming) {
chen xu02811692018-10-03 19:07:09 -07001196 setVoiceRoaming(roaming);
1197 setDataRoaming(roaming);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001198 }
1199
Jing Zhaoe6edb162014-07-18 09:34:36 -05001200 /** @hide */
Mathew Inwooda8382062018-08-16 17:01:12 +01001201 @UnsupportedAppUsage
Jing Zhaoe6edb162014-07-18 09:34:36 -05001202 public void setVoiceRoaming(boolean roaming) {
chen xu02811692018-10-03 19:07:09 -07001203 setVoiceRoamingType(roaming ? ROAMING_TYPE_UNKNOWN : ROAMING_TYPE_NOT_ROAMING);
Jing Zhaoe6edb162014-07-18 09:34:36 -05001204 }
1205
1206 /** @hide */
Cody Kestinge19048e2019-03-15 11:20:01 -07001207 @TestApi
chen xu02811692018-10-03 19:07:09 -07001208 public void setVoiceRoamingType(@RoamingType int type) {
Jack Yu37538592019-04-16 08:20:18 -07001209 NetworkRegistrationInfo regInfo = getNetworkRegistrationInfo(
Jack Yue27d3fd2019-03-15 14:49:53 -07001210 NetworkRegistrationInfo.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
Jack Yu37538592019-04-16 08:20:18 -07001211 if (regInfo == null) {
1212 regInfo = new NetworkRegistrationInfo.Builder()
Jack Yu20d71402019-03-16 23:00:35 -07001213 .setDomain(NetworkRegistrationInfo.DOMAIN_CS)
1214 .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
1215 .build();
chen xu02811692018-10-03 19:07:09 -07001216 }
Jack Yu37538592019-04-16 08:20:18 -07001217 regInfo.setRoamingType(type);
1218 addNetworkRegistrationInfo(regInfo);
Jing Zhaoe6edb162014-07-18 09:34:36 -05001219 }
1220
1221 /** @hide */
Mathew Inwooda8382062018-08-16 17:01:12 +01001222 @UnsupportedAppUsage
Jing Zhaoe6edb162014-07-18 09:34:36 -05001223 public void setDataRoaming(boolean dataRoaming) {
chen xu02811692018-10-03 19:07:09 -07001224 setDataRoamingType(dataRoaming ? ROAMING_TYPE_UNKNOWN : ROAMING_TYPE_NOT_ROAMING);
Jing Zhaoe6edb162014-07-18 09:34:36 -05001225 }
1226
1227 /** @hide */
Cody Kestinge19048e2019-03-15 11:20:01 -07001228 @TestApi
chen xu02811692018-10-03 19:07:09 -07001229 public void setDataRoamingType(@RoamingType int type) {
Jack Yu37538592019-04-16 08:20:18 -07001230 NetworkRegistrationInfo regInfo = getNetworkRegistrationInfo(
Jack Yue27d3fd2019-03-15 14:49:53 -07001231 NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
Jack Yu37538592019-04-16 08:20:18 -07001232 if (regInfo == null) {
1233 regInfo = new NetworkRegistrationInfo.Builder()
Jack Yu20d71402019-03-16 23:00:35 -07001234 .setDomain(NetworkRegistrationInfo.DOMAIN_PS)
1235 .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
1236 .build();
chen xu02811692018-10-03 19:07:09 -07001237 }
Jack Yu37538592019-04-16 08:20:18 -07001238 regInfo.setRoamingType(type);
1239 addNetworkRegistrationInfo(regInfo);
Jing Zhaoe6edb162014-07-18 09:34:36 -05001240 }
John Wang56c2d2f2010-04-07 08:57:17 -07001241
1242 /**
1243 * @hide
1244 */
Mathew Inwood55418ea2018-12-20 15:30:45 +00001245 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
John Wang56c2d2f2010-04-07 08:57:17 -07001246 public void setEmergencyOnly(boolean emergencyOnly) {
1247 mIsEmergencyOnly = emergencyOnly;
1248 }
1249
Wink Savillee9b06d72009-05-18 21:47:50 -07001250 /**
1251 * @hide
1252 */
Mathew Inwood55418ea2018-12-20 15:30:45 +00001253 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Wink Savillee9b06d72009-05-18 21:47:50 -07001254 public void setCdmaRoamingIndicator(int roaming) {
1255 this.mCdmaRoamingIndicator = roaming;
1256 }
1257
1258 /**
1259 * @hide
1260 */
Mathew Inwood55418ea2018-12-20 15:30:45 +00001261 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Wink Savillee9b06d72009-05-18 21:47:50 -07001262 public void setCdmaDefaultRoamingIndicator (int roaming) {
1263 this.mCdmaDefaultRoamingIndicator = roaming;
Wink Saville767a6622009-04-02 01:37:02 -07001264 }
1265
Robert Greenwalt98e0b142009-10-08 21:15:52 -07001266 /**
1267 * @hide
1268 */
Mathew Inwood55418ea2018-12-20 15:30:45 +00001269 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Robert Greenwalt98e0b142009-10-08 21:15:52 -07001270 public void setCdmaEriIconIndex(int index) {
1271 this.mCdmaEriIconIndex = index;
1272 }
1273
1274 /**
1275 * @hide
1276 */
Mathew Inwood55418ea2018-12-20 15:30:45 +00001277 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Robert Greenwalt98e0b142009-10-08 21:15:52 -07001278 public void setCdmaEriIconMode(int mode) {
1279 this.mCdmaEriIconMode = mode;
1280 }
1281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001282 public void setOperatorName(String longName, String shortName, String numeric) {
SongFerngWang2b1ea8d2019-11-20 02:11:09 +08001283 mOperatorAlphaLong = longName;
1284 mOperatorAlphaShort = shortName;
1285 mOperatorNumeric = numeric;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001286 }
1287
Wink Savillee9b06d72009-05-18 21:47:50 -07001288 /**
Jake Hamby390de222010-05-10 18:46:45 -07001289 * In CDMA, mOperatorAlphaLong can be set from the ERI text.
Jack Yu67140302015-12-10 12:27:58 -08001290 * This is done from the GsmCdmaPhone and not from the ServiceStateTracker.
Wink Savillee9b06d72009-05-18 21:47:50 -07001291 *
1292 * @hide
1293 */
Mathew Inwooda8382062018-08-16 17:01:12 +01001294 @UnsupportedAppUsage
SongFerngWang2b1ea8d2019-11-20 02:11:09 +08001295 public void setOperatorAlphaLong(@Nullable String longName) {
1296 mOperatorAlphaLong = longName;
Wink Savillee9b06d72009-05-18 21:47:50 -07001297 }
1298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001299 public void setIsManualSelection(boolean isManual) {
1300 mIsManualNetworkSelection = isManual;
1301 }
Wink Saville767a6622009-04-02 01:37:02 -07001302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001303 /**
Jake Hamby390de222010-05-10 18:46:45 -07001304 * Test whether two objects hold the same data values or both are null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001305 *
1306 * @param a first obj
1307 * @param b second obj
1308 * @return true if two objects equal or both are null
1309 */
Mathew Inwood55418ea2018-12-20 15:30:45 +00001310 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001311 private static boolean equalsHandlesNulls (Object a, Object b) {
1312 return (a == null) ? (b == null) : a.equals (b);
1313 }
1314
1315 /**
Jake Hamby390de222010-05-10 18:46:45 -07001316 * Set ServiceState based on intent notifier map.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001317 *
1318 * @param m intent notifier map
1319 * @hide
1320 */
Mathew Inwooda8382062018-08-16 17:01:12 +01001321 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001322 private void setFromNotifierBundle(Bundle m) {
Amit Mahajanbb61b172020-01-23 18:00:08 -08001323 ServiceState ssFromBundle = m.getParcelable(EXTRA_SERVICE_STATE);
chen xu02811692018-10-03 19:07:09 -07001324 if (ssFromBundle != null) {
1325 copyFrom(ssFromBundle);
1326 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001327 }
1328
1329 /**
Jake Hamby390de222010-05-10 18:46:45 -07001330 * Set intent notifier Bundle based on service state.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001331 *
Malcolm Chen8a8b1202019-12-27 16:49:44 -08001332 * Put ServiceState object and its fields into bundle which is used by TelephonyRegistry
1333 * to broadcast {@link Intent#ACTION_SERVICE_STATE}.
1334 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001335 * @param m intent notifier Bundle
1336 * @hide
Malcolm Chen8a8b1202019-12-27 16:49:44 -08001337 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001338 */
Malcolm Chen9993fd62020-04-28 16:14:01 -07001339 @UnsupportedAppUsage
Malcolm Chen8a8b1202019-12-27 16:49:44 -08001340 public void fillInNotifierBundle(@NonNull Bundle m) {
Amit Mahajanbb61b172020-01-23 18:00:08 -08001341 m.putParcelable(EXTRA_SERVICE_STATE, this);
chen xu02811692018-10-03 19:07:09 -07001342 // serviceState already consists of below entries.
1343 // for backward compatibility, we continue fill in below entries.
Wink Saville0dde2c22012-11-16 08:12:11 -08001344 m.putInt("voiceRegState", mVoiceRegState);
1345 m.putInt("dataRegState", mDataRegState);
chen xu02811692018-10-03 19:07:09 -07001346 m.putInt("dataRoamingType", getDataRoamingType());
1347 m.putInt("voiceRoamingType", getVoiceRoamingType());
SongFerngWang2b1ea8d2019-11-20 02:11:09 +08001348 m.putString("operator-alpha-long", mOperatorAlphaLong);
1349 m.putString("operator-alpha-short", mOperatorAlphaShort);
1350 m.putString("operator-numeric", mOperatorNumeric);
1351 m.putString("data-operator-alpha-long", mOperatorAlphaLong);
1352 m.putString("data-operator-alpha-short", mOperatorAlphaShort);
1353 m.putString("data-operator-numeric", mOperatorNumeric);
Tobias Thiererb0800dc2016-04-21 17:51:41 +01001354 m.putBoolean("manual", mIsManualNetworkSelection);
Jack Yu5ff5ab52019-04-02 13:14:03 -07001355 m.putInt("radioTechnology", getRilVoiceRadioTechnology());
1356 m.putInt("dataRadioTechnology", getRadioTechnology());
Wink Saville767a6622009-04-02 01:37:02 -07001357 m.putBoolean("cssIndicator", mCssIndicator);
1358 m.putInt("networkId", mNetworkId);
1359 m.putInt("systemId", mSystemId);
Wink Savillee9b06d72009-05-18 21:47:50 -07001360 m.putInt("cdmaRoamingIndicator", mCdmaRoamingIndicator);
1361 m.putInt("cdmaDefaultRoamingIndicator", mCdmaDefaultRoamingIndicator);
Tobias Thiererb0800dc2016-04-21 17:51:41 +01001362 m.putBoolean("emergencyOnly", mIsEmergencyOnly);
chen xu02811692018-10-03 19:07:09 -07001363 m.putBoolean("isDataRoamingFromRegistration", getDataRoamingFromRegistration());
Jack Yu5ff5ab52019-04-02 13:14:03 -07001364 m.putBoolean("isUsingCarrierAggregation", isUsingCarrierAggregation());
Sooraj Sasindranc5659ca2017-03-08 23:43:17 -08001365 m.putInt("LteEarfcnRsrpBoost", mLteEarfcnRsrpBoost);
Eric Schwarzenbach09a77732018-01-18 14:42:00 -08001366 m.putInt("ChannelNumber", mChannelNumber);
1367 m.putIntArray("CellBandwidths", mCellBandwidths);
Pengquan Meng6aa52132018-11-13 17:06:34 -08001368 m.putInt("mNrFrequencyRange", mNrFrequencyRange);
SongFerngWang3cbcf752019-03-21 23:14:20 +08001369 m.putString("operator-alpha-long-raw", mOperatorAlphaLongRaw);
1370 m.putString("operator-alpha-short-raw", mOperatorAlphaShortRaw);
Wink Saville767a6622009-04-02 01:37:02 -07001371 }
1372
Wink Saville767a6622009-04-02 01:37:02 -07001373 /** @hide */
Malcolm Chena1d5e9f2018-04-03 17:43:30 -07001374 @TestApi
chen xuf513b522018-10-18 16:52:40 -07001375 public void setRilVoiceRadioTechnology(@RilRadioTechnology int rt) {
Jack Yu5ff5ab52019-04-02 13:14:03 -07001376 Rlog.e(LOG_TAG, "ServiceState.setRilVoiceRadioTechnology() called. It's encouraged to "
1377 + "use addNetworkRegistrationInfo() instead *******");
1378 // Sync to network registration state
Jack Yu37538592019-04-16 08:20:18 -07001379 NetworkRegistrationInfo regInfo = getNetworkRegistrationInfo(
Jack Yue27d3fd2019-03-15 14:49:53 -07001380 NetworkRegistrationInfo.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
Jack Yu37538592019-04-16 08:20:18 -07001381 if (regInfo == null) {
1382 regInfo = new NetworkRegistrationInfo.Builder()
Jack Yu20d71402019-03-16 23:00:35 -07001383 .setDomain(NetworkRegistrationInfo.DOMAIN_CS)
1384 .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
1385 .build();
chen xuf513b522018-10-18 16:52:40 -07001386 }
Jack Yu37538592019-04-16 08:20:18 -07001387 regInfo.setAccessNetworkTechnology(rilRadioTechnologyToNetworkType(rt));
1388 addNetworkRegistrationInfo(regInfo);
Wink Saville0dde2c22012-11-16 08:12:11 -08001389 }
1390
Jack Yu5ff5ab52019-04-02 13:14:03 -07001391
Wink Saville0dde2c22012-11-16 08:12:11 -08001392 /** @hide */
Malcolm Chena1d5e9f2018-04-03 17:43:30 -07001393 @TestApi
chen xuf513b522018-10-18 16:52:40 -07001394 public void setRilDataRadioTechnology(@RilRadioTechnology int rt) {
Jack Yu5ff5ab52019-04-02 13:14:03 -07001395 Rlog.e(LOG_TAG, "ServiceState.setRilDataRadioTechnology() called. It's encouraged to "
1396 + "use addNetworkRegistrationInfo() instead *******");
1397 // Sync to network registration state. Always write down the WWAN transport. For AP-assisted
1398 // mode device, use addNetworkRegistrationInfo() to set the correct transport if RAT
1399 // is IWLAN.
Jack Yu37538592019-04-16 08:20:18 -07001400 NetworkRegistrationInfo regInfo = getNetworkRegistrationInfo(
Jack Yue27d3fd2019-03-15 14:49:53 -07001401 NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
chen xuf513b522018-10-18 16:52:40 -07001402
Jack Yu37538592019-04-16 08:20:18 -07001403 if (regInfo == null) {
1404 regInfo = new NetworkRegistrationInfo.Builder()
Jack Yu20d71402019-03-16 23:00:35 -07001405 .setDomain(NetworkRegistrationInfo.DOMAIN_PS)
1406 .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
1407 .build();
chen xuf513b522018-10-18 16:52:40 -07001408 }
Jack Yu37538592019-04-16 08:20:18 -07001409 regInfo.setAccessNetworkTechnology(rilRadioTechnologyToNetworkType(rt));
1410 addNetworkRegistrationInfo(regInfo);
Wink Saville767a6622009-04-02 01:37:02 -07001411 }
1412
1413 /** @hide */
Robert Greenwaltea0d71392016-07-28 18:50:10 -07001414 public boolean isUsingCarrierAggregation() {
Rambo Wang8a41bbf2020-05-08 14:50:21 -07001415 boolean isUsingCa = false;
Jack Yu5ff5ab52019-04-02 13:14:03 -07001416 NetworkRegistrationInfo nri = getNetworkRegistrationInfo(
1417 NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
1418 if (nri != null) {
1419 DataSpecificRegistrationInfo dsri = nri.getDataSpecificInfo();
1420 if (dsri != null) {
Rambo Wang8a41bbf2020-05-08 14:50:21 -07001421 isUsingCa = dsri.isUsingCarrierAggregation();
Jack Yu5ff5ab52019-04-02 13:14:03 -07001422 }
1423 }
Rambo Wang8a41bbf2020-05-08 14:50:21 -07001424 return isUsingCa || getCellBandwidths().length > 1;
Robert Greenwaltea0d71392016-07-28 18:50:10 -07001425 }
1426
1427 /** @hide */
1428 public void setIsUsingCarrierAggregation(boolean ca) {
Jack Yu5ff5ab52019-04-02 13:14:03 -07001429 NetworkRegistrationInfo nri = getNetworkRegistrationInfo(
1430 NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
1431 if (nri != null) {
1432 DataSpecificRegistrationInfo dsri = nri.getDataSpecificInfo();
1433 if (dsri != null) {
1434 dsri.setIsUsingCarrierAggregation(ca);
Qiong Liuc43aef72019-08-26 18:58:07 +08001435 addNetworkRegistrationInfo(nri);
Jack Yu5ff5ab52019-04-02 13:14:03 -07001436 }
1437 }
Robert Greenwaltea0d71392016-07-28 18:50:10 -07001438 }
1439
Pengquan Meng6aa52132018-11-13 17:06:34 -08001440 /**
Jayachandran C4d62c632019-11-07 00:47:28 -08001441 * Get the 5G NR frequency range the device is currently registered.
1442 *
Pengquan Meng6aa52132018-11-13 17:06:34 -08001443 * @return the frequency range of 5G NR.
1444 * @hide
1445 */
1446 public @FrequencyRange int getNrFrequencyRange() {
1447 return mNrFrequencyRange;
1448 }
1449
1450 /**
Jack Yu20d71402019-03-16 23:00:35 -07001451 * Get the NR 5G state of the mobile data network.
1452 * @return the NR 5G state.
Pengquan Meng123cd322018-12-06 17:48:05 -08001453 * @hide
1454 */
Jack Yu20d71402019-03-16 23:00:35 -07001455 public @NRState int getNrState() {
Jack Yu37538592019-04-16 08:20:18 -07001456 final NetworkRegistrationInfo regInfo = getNetworkRegistrationInfo(
Jack Yue27d3fd2019-03-15 14:49:53 -07001457 NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
Jack Yu37538592019-04-16 08:20:18 -07001458 if (regInfo == null) return NetworkRegistrationInfo.NR_STATE_NONE;
1459 return regInfo.getNrState();
Pengquan Meng123cd322018-12-06 17:48:05 -08001460 }
1461
1462 /**
Pengquan Meng6aa52132018-11-13 17:06:34 -08001463 * @param nrFrequencyRange the frequency range of 5G NR.
1464 * @hide
1465 */
1466 public void setNrFrequencyRange(@FrequencyRange int nrFrequencyRange) {
1467 mNrFrequencyRange = nrFrequencyRange;
1468 }
1469
Robert Greenwaltea0d71392016-07-28 18:50:10 -07001470 /** @hide */
Sooraj Sasindranc5659ca2017-03-08 23:43:17 -08001471 public int getLteEarfcnRsrpBoost() {
1472 return mLteEarfcnRsrpBoost;
1473 }
1474
1475 /** @hide */
1476 public void setLteEarfcnRsrpBoost(int LteEarfcnRsrpBoost) {
1477 mLteEarfcnRsrpBoost = LteEarfcnRsrpBoost;
1478 }
1479
1480 /** @hide */
Mathew Inwood55418ea2018-12-20 15:30:45 +00001481 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Wink Saville767a6622009-04-02 01:37:02 -07001482 public void setCssIndicator(int css) {
1483 this.mCssIndicator = (css != 0);
1484 }
1485
1486 /** @hide */
Jack Yu1b8b3892018-02-22 17:37:38 -08001487 @TestApi
Jack Yu2661fac2018-03-15 13:51:05 -07001488 public void setCdmaSystemAndNetworkId(int systemId, int networkId) {
Wink Saville767a6622009-04-02 01:37:02 -07001489 this.mSystemId = systemId;
1490 this.mNetworkId = networkId;
1491 }
1492
1493 /** @hide */
Mathew Inwooda8382062018-08-16 17:01:12 +01001494 @UnsupportedAppUsage
Wink Saville0dde2c22012-11-16 08:12:11 -08001495 public int getRilVoiceRadioTechnology() {
Jack Yu5ff5ab52019-04-02 13:14:03 -07001496 NetworkRegistrationInfo wwanRegInfo = getNetworkRegistrationInfo(
1497 NetworkRegistrationInfo.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
1498 if (wwanRegInfo != null) {
1499 return networkTypeToRilRadioTechnology(wwanRegInfo.getAccessNetworkTechnology());
1500 }
1501 return RIL_RADIO_TECHNOLOGY_UNKNOWN;
Wink Saville767a6622009-04-02 01:37:02 -07001502 }
Mathias Agopiand13f9aa2012-02-24 19:28:42 -08001503 /** @hide */
Mathew Inwooda8382062018-08-16 17:01:12 +01001504 @UnsupportedAppUsage
Wink Saville0dde2c22012-11-16 08:12:11 -08001505 public int getRilDataRadioTechnology() {
Jack Yua74f2d82019-05-21 17:16:22 -07001506 return networkTypeToRilRadioTechnology(getDataNetworkType());
Wink Saville0dde2c22012-11-16 08:12:11 -08001507 }
Jack Yua74f2d82019-05-21 17:16:22 -07001508
Wink Saville0dde2c22012-11-16 08:12:11 -08001509 /**
1510 * @hide
1511 * @Deprecated to be removed Q3 2013 use {@link #getRilDataRadioTechnology} or
1512 * {@link #getRilVoiceRadioTechnology}
1513 */
Mathew Inwooda8382062018-08-16 17:01:12 +01001514 @UnsupportedAppUsage
Mathias Agopiand13f9aa2012-02-24 19:28:42 -08001515 public int getRadioTechnology() {
Wink Saville599a90c2012-11-27 12:29:13 -08001516 Rlog.e(LOG_TAG, "ServiceState.getRadioTechnology() DEPRECATED will be removed *******");
Wink Saville0dde2c22012-11-16 08:12:11 -08001517 return getRilDataRadioTechnology();
Mathias Agopiand13f9aa2012-02-24 19:28:42 -08001518 }
Wink Saville767a6622009-04-02 01:37:02 -07001519
SongFerngWange5202be2019-12-02 21:19:24 +08001520 /**
1521 * Transform RIL radio technology {@link RilRadioTechnology} value to Network
1522 * type {@link NetworkType}.
1523 *
1524 * @param rat The RIL radio technology {@link RilRadioTechnology}.
1525 * @return The network type {@link NetworkType}.
1526 *
1527 * @hide
1528 */
Pengquan Meng82e6b2a2018-12-07 14:41:18 -08001529 public static int rilRadioTechnologyToNetworkType(@RilRadioTechnology int rat) {
1530 switch(rat) {
Taesu Leee376b8c2019-11-14 14:41:40 +09001531 case RIL_RADIO_TECHNOLOGY_GPRS:
Pengquan Meng82e6b2a2018-12-07 14:41:18 -08001532 return TelephonyManager.NETWORK_TYPE_GPRS;
Taesu Leee376b8c2019-11-14 14:41:40 +09001533 case RIL_RADIO_TECHNOLOGY_EDGE:
Pengquan Meng82e6b2a2018-12-07 14:41:18 -08001534 return TelephonyManager.NETWORK_TYPE_EDGE;
Taesu Leee376b8c2019-11-14 14:41:40 +09001535 case RIL_RADIO_TECHNOLOGY_UMTS:
Pengquan Meng82e6b2a2018-12-07 14:41:18 -08001536 return TelephonyManager.NETWORK_TYPE_UMTS;
Taesu Leee376b8c2019-11-14 14:41:40 +09001537 case RIL_RADIO_TECHNOLOGY_HSDPA:
Pengquan Meng82e6b2a2018-12-07 14:41:18 -08001538 return TelephonyManager.NETWORK_TYPE_HSDPA;
Taesu Leee376b8c2019-11-14 14:41:40 +09001539 case RIL_RADIO_TECHNOLOGY_HSUPA:
Pengquan Meng82e6b2a2018-12-07 14:41:18 -08001540 return TelephonyManager.NETWORK_TYPE_HSUPA;
Taesu Leee376b8c2019-11-14 14:41:40 +09001541 case RIL_RADIO_TECHNOLOGY_HSPA:
Pengquan Meng82e6b2a2018-12-07 14:41:18 -08001542 return TelephonyManager.NETWORK_TYPE_HSPA;
Taesu Leee376b8c2019-11-14 14:41:40 +09001543 case RIL_RADIO_TECHNOLOGY_IS95A:
1544 case RIL_RADIO_TECHNOLOGY_IS95B:
Pengquan Meng82e6b2a2018-12-07 14:41:18 -08001545 return TelephonyManager.NETWORK_TYPE_CDMA;
Taesu Leee376b8c2019-11-14 14:41:40 +09001546 case RIL_RADIO_TECHNOLOGY_1xRTT:
Pengquan Meng82e6b2a2018-12-07 14:41:18 -08001547 return TelephonyManager.NETWORK_TYPE_1xRTT;
Taesu Leee376b8c2019-11-14 14:41:40 +09001548 case RIL_RADIO_TECHNOLOGY_EVDO_0:
Pengquan Meng82e6b2a2018-12-07 14:41:18 -08001549 return TelephonyManager.NETWORK_TYPE_EVDO_0;
Taesu Leee376b8c2019-11-14 14:41:40 +09001550 case RIL_RADIO_TECHNOLOGY_EVDO_A:
Pengquan Meng82e6b2a2018-12-07 14:41:18 -08001551 return TelephonyManager.NETWORK_TYPE_EVDO_A;
Taesu Leee376b8c2019-11-14 14:41:40 +09001552 case RIL_RADIO_TECHNOLOGY_EVDO_B:
Pengquan Meng82e6b2a2018-12-07 14:41:18 -08001553 return TelephonyManager.NETWORK_TYPE_EVDO_B;
Taesu Leee376b8c2019-11-14 14:41:40 +09001554 case RIL_RADIO_TECHNOLOGY_EHRPD:
Pengquan Meng82e6b2a2018-12-07 14:41:18 -08001555 return TelephonyManager.NETWORK_TYPE_EHRPD;
Taesu Leee376b8c2019-11-14 14:41:40 +09001556 case RIL_RADIO_TECHNOLOGY_LTE:
Pengquan Meng82e6b2a2018-12-07 14:41:18 -08001557 return TelephonyManager.NETWORK_TYPE_LTE;
Taesu Leee376b8c2019-11-14 14:41:40 +09001558 case RIL_RADIO_TECHNOLOGY_HSPAP:
Pengquan Meng82e6b2a2018-12-07 14:41:18 -08001559 return TelephonyManager.NETWORK_TYPE_HSPAP;
Taesu Leee376b8c2019-11-14 14:41:40 +09001560 case RIL_RADIO_TECHNOLOGY_GSM:
Pengquan Meng82e6b2a2018-12-07 14:41:18 -08001561 return TelephonyManager.NETWORK_TYPE_GSM;
Taesu Leee376b8c2019-11-14 14:41:40 +09001562 case RIL_RADIO_TECHNOLOGY_TD_SCDMA:
Pengquan Meng82e6b2a2018-12-07 14:41:18 -08001563 return TelephonyManager.NETWORK_TYPE_TD_SCDMA;
Taesu Leee376b8c2019-11-14 14:41:40 +09001564 case RIL_RADIO_TECHNOLOGY_IWLAN:
Pengquan Meng82e6b2a2018-12-07 14:41:18 -08001565 return TelephonyManager.NETWORK_TYPE_IWLAN;
Taesu Leee376b8c2019-11-14 14:41:40 +09001566 case RIL_RADIO_TECHNOLOGY_LTE_CA:
Pengquan Meng82e6b2a2018-12-07 14:41:18 -08001567 return TelephonyManager.NETWORK_TYPE_LTE_CA;
Taesu Leee376b8c2019-11-14 14:41:40 +09001568 case RIL_RADIO_TECHNOLOGY_NR:
Pengquan Meng82e6b2a2018-12-07 14:41:18 -08001569 return TelephonyManager.NETWORK_TYPE_NR;
1570 default:
1571 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
Robert Greenwalt1434d7b2012-02-17 13:14:08 -08001572 }
1573 }
1574
Wink Saville0dde2c22012-11-16 08:12:11 -08001575 /** @hide */
Jack Yu677cfaa22018-01-31 00:33:20 -08001576 public static int rilRadioTechnologyToAccessNetworkType(@RilRadioTechnology int rt) {
1577 switch(rt) {
1578 case RIL_RADIO_TECHNOLOGY_GPRS:
1579 case RIL_RADIO_TECHNOLOGY_EDGE:
1580 case RIL_RADIO_TECHNOLOGY_GSM:
1581 return AccessNetworkType.GERAN;
1582 case RIL_RADIO_TECHNOLOGY_UMTS:
1583 case RIL_RADIO_TECHNOLOGY_HSDPA:
1584 case RIL_RADIO_TECHNOLOGY_HSPAP:
1585 case RIL_RADIO_TECHNOLOGY_HSUPA:
1586 case RIL_RADIO_TECHNOLOGY_HSPA:
1587 case RIL_RADIO_TECHNOLOGY_TD_SCDMA:
1588 return AccessNetworkType.UTRAN;
1589 case RIL_RADIO_TECHNOLOGY_IS95A:
1590 case RIL_RADIO_TECHNOLOGY_IS95B:
1591 case RIL_RADIO_TECHNOLOGY_1xRTT:
1592 case RIL_RADIO_TECHNOLOGY_EVDO_0:
1593 case RIL_RADIO_TECHNOLOGY_EVDO_A:
1594 case RIL_RADIO_TECHNOLOGY_EVDO_B:
1595 case RIL_RADIO_TECHNOLOGY_EHRPD:
1596 return AccessNetworkType.CDMA2000;
1597 case RIL_RADIO_TECHNOLOGY_LTE:
1598 case RIL_RADIO_TECHNOLOGY_LTE_CA:
1599 return AccessNetworkType.EUTRAN;
Sarah Chind1941e572019-12-13 11:12:28 -08001600 case RIL_RADIO_TECHNOLOGY_NR:
1601 return AccessNetworkType.NGRAN;
Jack Yu677cfaa22018-01-31 00:33:20 -08001602 case RIL_RADIO_TECHNOLOGY_IWLAN:
1603 return AccessNetworkType.IWLAN;
1604 case RIL_RADIO_TECHNOLOGY_UNKNOWN:
1605 default:
1606 return AccessNetworkType.UNKNOWN;
1607 }
1608 }
1609
SongFerngWange5202be2019-12-02 21:19:24 +08001610 /**
1611 * Transform network type {@link NetworkType} value to RIL radio technology
1612 * {@link RilRadioTechnology}.
1613 *
1614 * @param networkType The network type {@link NetworkType}.
1615 * @return The RIL radio technology {@link RilRadioTechnology}.
1616 *
1617 * @hide
1618 */
Malcolm Chen0a01c6b2018-01-29 17:09:21 -08001619 public static int networkTypeToRilRadioTechnology(int networkType) {
1620 switch(networkType) {
1621 case TelephonyManager.NETWORK_TYPE_GPRS:
Taesu Leee376b8c2019-11-14 14:41:40 +09001622 return RIL_RADIO_TECHNOLOGY_GPRS;
Malcolm Chen0a01c6b2018-01-29 17:09:21 -08001623 case TelephonyManager.NETWORK_TYPE_EDGE:
Taesu Leee376b8c2019-11-14 14:41:40 +09001624 return RIL_RADIO_TECHNOLOGY_EDGE;
Malcolm Chen0a01c6b2018-01-29 17:09:21 -08001625 case TelephonyManager.NETWORK_TYPE_UMTS:
Taesu Leee376b8c2019-11-14 14:41:40 +09001626 return RIL_RADIO_TECHNOLOGY_UMTS;
Malcolm Chen0a01c6b2018-01-29 17:09:21 -08001627 case TelephonyManager.NETWORK_TYPE_HSDPA:
Taesu Leee376b8c2019-11-14 14:41:40 +09001628 return RIL_RADIO_TECHNOLOGY_HSDPA;
Malcolm Chen0a01c6b2018-01-29 17:09:21 -08001629 case TelephonyManager.NETWORK_TYPE_HSUPA:
Taesu Leee376b8c2019-11-14 14:41:40 +09001630 return RIL_RADIO_TECHNOLOGY_HSUPA;
Malcolm Chen0a01c6b2018-01-29 17:09:21 -08001631 case TelephonyManager.NETWORK_TYPE_HSPA:
Taesu Leee376b8c2019-11-14 14:41:40 +09001632 return RIL_RADIO_TECHNOLOGY_HSPA;
Malcolm Chen0a01c6b2018-01-29 17:09:21 -08001633 case TelephonyManager.NETWORK_TYPE_CDMA:
Taesu Leee376b8c2019-11-14 14:41:40 +09001634 return RIL_RADIO_TECHNOLOGY_IS95A;
Malcolm Chen0a01c6b2018-01-29 17:09:21 -08001635 case TelephonyManager.NETWORK_TYPE_1xRTT:
Taesu Leee376b8c2019-11-14 14:41:40 +09001636 return RIL_RADIO_TECHNOLOGY_1xRTT;
Malcolm Chen0a01c6b2018-01-29 17:09:21 -08001637 case TelephonyManager.NETWORK_TYPE_EVDO_0:
Taesu Leee376b8c2019-11-14 14:41:40 +09001638 return RIL_RADIO_TECHNOLOGY_EVDO_0;
Malcolm Chen0a01c6b2018-01-29 17:09:21 -08001639 case TelephonyManager.NETWORK_TYPE_EVDO_A:
Taesu Leee376b8c2019-11-14 14:41:40 +09001640 return RIL_RADIO_TECHNOLOGY_EVDO_A;
Malcolm Chen0a01c6b2018-01-29 17:09:21 -08001641 case TelephonyManager.NETWORK_TYPE_EVDO_B:
Taesu Leee376b8c2019-11-14 14:41:40 +09001642 return RIL_RADIO_TECHNOLOGY_EVDO_B;
Malcolm Chen0a01c6b2018-01-29 17:09:21 -08001643 case TelephonyManager.NETWORK_TYPE_EHRPD:
Taesu Leee376b8c2019-11-14 14:41:40 +09001644 return RIL_RADIO_TECHNOLOGY_EHRPD;
Malcolm Chen0a01c6b2018-01-29 17:09:21 -08001645 case TelephonyManager.NETWORK_TYPE_LTE:
Taesu Leee376b8c2019-11-14 14:41:40 +09001646 return RIL_RADIO_TECHNOLOGY_LTE;
Malcolm Chen0a01c6b2018-01-29 17:09:21 -08001647 case TelephonyManager.NETWORK_TYPE_HSPAP:
Taesu Leee376b8c2019-11-14 14:41:40 +09001648 return RIL_RADIO_TECHNOLOGY_HSPAP;
Malcolm Chen0a01c6b2018-01-29 17:09:21 -08001649 case TelephonyManager.NETWORK_TYPE_GSM:
Taesu Leee376b8c2019-11-14 14:41:40 +09001650 return RIL_RADIO_TECHNOLOGY_GSM;
Malcolm Chen0a01c6b2018-01-29 17:09:21 -08001651 case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
Taesu Leee376b8c2019-11-14 14:41:40 +09001652 return RIL_RADIO_TECHNOLOGY_TD_SCDMA;
Malcolm Chen0a01c6b2018-01-29 17:09:21 -08001653 case TelephonyManager.NETWORK_TYPE_IWLAN:
Taesu Leee376b8c2019-11-14 14:41:40 +09001654 return RIL_RADIO_TECHNOLOGY_IWLAN;
Malcolm Chen0a01c6b2018-01-29 17:09:21 -08001655 case TelephonyManager.NETWORK_TYPE_LTE_CA:
Taesu Leee376b8c2019-11-14 14:41:40 +09001656 return RIL_RADIO_TECHNOLOGY_LTE_CA;
Avinash Nalluri61b44a22019-06-19 19:13:28 -07001657 case TelephonyManager.NETWORK_TYPE_NR:
Taesu Leee376b8c2019-11-14 14:41:40 +09001658 return RIL_RADIO_TECHNOLOGY_NR;
Malcolm Chen0a01c6b2018-01-29 17:09:21 -08001659 default:
Taesu Leee376b8c2019-11-14 14:41:40 +09001660 return RIL_RADIO_TECHNOLOGY_UNKNOWN;
Malcolm Chen0a01c6b2018-01-29 17:09:21 -08001661 }
1662 }
1663
Jack Yua74f2d82019-05-21 17:16:22 -07001664 /**
1665 * Get current data network type.
1666 *
1667 * Note that for IWLAN AP-assisted mode device, which is reporting both camped access networks
1668 * (cellular RAT and IWLAN)at the same time, this API is simulating the old legacy mode device
1669 * behavior,
1670 *
1671 * @return Current data network type
1672 * @hide
1673 */
Hall Liu58849332019-12-27 19:42:20 -08001674 @TestApi
Chen Xuc9d4ee12019-09-26 16:11:59 -07001675 public @NetworkType int getDataNetworkType() {
Jack Yua74f2d82019-05-21 17:16:22 -07001676 final NetworkRegistrationInfo iwlanRegInfo = getNetworkRegistrationInfo(
Jack Yue27d3fd2019-03-15 14:49:53 -07001677 NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WLAN);
Jack Yua74f2d82019-05-21 17:16:22 -07001678 final NetworkRegistrationInfo wwanRegInfo = getNetworkRegistrationInfo(
1679 NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
1680
1681 // For legacy mode device, or AP-assisted mode device but IWLAN is out of service, use
1682 // the RAT from cellular.
1683 if (iwlanRegInfo == null || !iwlanRegInfo.isInService()) {
1684 return (wwanRegInfo != null) ? wwanRegInfo.getAccessNetworkTechnology()
1685 : TelephonyManager.NETWORK_TYPE_UNKNOWN;
Jack Yu2bd03202019-02-20 15:48:07 -08001686 }
1687
Jack Yua74f2d82019-05-21 17:16:22 -07001688 // At this point, it must be an AP-assisted mode device and IWLAN is in service. We should
1689 // use the RAT from IWLAN service is cellular is out of service, or when both are in service
1690 // and any APN type of data is preferred on IWLAN.
1691 if (!wwanRegInfo.isInService() || mIsIwlanPreferred) {
1692 return iwlanRegInfo.getAccessNetworkTechnology();
chen xuf513b522018-10-18 16:52:40 -07001693 }
Jack Yua74f2d82019-05-21 17:16:22 -07001694
1695 // If both cellular and IWLAN are in service, but no APN is preferred on IWLAN, still use
1696 // the RAT from cellular.
1697 return wwanRegInfo.getAccessNetworkTechnology();
Wink Saville0dde2c22012-11-16 08:12:11 -08001698 }
1699
1700 /** @hide */
chen xuf513b522018-10-18 16:52:40 -07001701 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
Chen Xuc9d4ee12019-09-26 16:11:59 -07001702 public @NetworkType int getVoiceNetworkType() {
Jack Yue27d3fd2019-03-15 14:49:53 -07001703 final NetworkRegistrationInfo regState = getNetworkRegistrationInfo(
1704 NetworkRegistrationInfo.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
chen xuf513b522018-10-18 16:52:40 -07001705 if (regState != null) {
1706 return regState.getAccessNetworkTechnology();
1707 }
1708 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
Wink Saville0dde2c22012-11-16 08:12:11 -08001709 }
1710
Robert Greenwalt1434d7b2012-02-17 13:14:08 -08001711 /** @hide */
Mathew Inwood55418ea2018-12-20 15:30:45 +00001712 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Wink Saville767a6622009-04-02 01:37:02 -07001713 public int getCssIndicator() {
1714 return this.mCssIndicator ? 1 : 0;
1715 }
1716
Jack Yu9cd3b7b2018-01-02 15:51:34 -08001717 /**
1718 * Get the CDMA NID (Network Identification Number), a number uniquely identifying a network
1719 * within a wireless system. (Defined in 3GPP2 C.S0023 3.4.8)
1720 * @return The CDMA NID or {@link #UNKNOWN_ID} if not available.
1721 */
Jack Yu2661fac2018-03-15 13:51:05 -07001722 public int getCdmaNetworkId() {
Wink Saville767a6622009-04-02 01:37:02 -07001723 return this.mNetworkId;
1724 }
1725
Jack Yu9cd3b7b2018-01-02 15:51:34 -08001726 /**
1727 * Get the CDMA SID (System Identification Number), a number uniquely identifying a wireless
1728 * system. (Defined in 3GPP2 C.S0023 3.4.8)
1729 * @return The CDMA SID or {@link #UNKNOWN_ID} if not available.
1730 */
Jack Yu2661fac2018-03-15 13:51:05 -07001731 public int getCdmaSystemId() {
Wink Saville767a6622009-04-02 01:37:02 -07001732 return this.mSystemId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001733 }
Naveen Kallafc2cbe92011-12-29 15:07:41 -08001734
1735 /** @hide */
Mathew Inwooda8382062018-08-16 17:01:12 +01001736 @UnsupportedAppUsage
Naveen Kallafc2cbe92011-12-29 15:07:41 -08001737 public static boolean isGsm(int radioTechnology) {
Robert Greenwalt1434d7b2012-02-17 13:14:08 -08001738 return radioTechnology == RIL_RADIO_TECHNOLOGY_GPRS
1739 || radioTechnology == RIL_RADIO_TECHNOLOGY_EDGE
1740 || radioTechnology == RIL_RADIO_TECHNOLOGY_UMTS
1741 || radioTechnology == RIL_RADIO_TECHNOLOGY_HSDPA
1742 || radioTechnology == RIL_RADIO_TECHNOLOGY_HSUPA
1743 || radioTechnology == RIL_RADIO_TECHNOLOGY_HSPA
1744 || radioTechnology == RIL_RADIO_TECHNOLOGY_LTE
1745 || radioTechnology == RIL_RADIO_TECHNOLOGY_HSPAP
Etan Cohen5e5bc4b2014-10-08 17:10:33 -07001746 || radioTechnology == RIL_RADIO_TECHNOLOGY_GSM
Yashdev Singhbece9262015-02-23 13:04:51 -08001747 || radioTechnology == RIL_RADIO_TECHNOLOGY_TD_SCDMA
Ajay Nambi7965fa42015-05-14 18:48:33 -07001748 || radioTechnology == RIL_RADIO_TECHNOLOGY_IWLAN
Sukanya Rajkhowaab815c12019-03-25 16:51:26 -07001749 || radioTechnology == RIL_RADIO_TECHNOLOGY_LTE_CA
1750 || radioTechnology == RIL_RADIO_TECHNOLOGY_NR;
Ajay Nambi7965fa42015-05-14 18:48:33 -07001751
Naveen Kallafc2cbe92011-12-29 15:07:41 -08001752 }
1753
1754 /** @hide */
Mathew Inwooda8382062018-08-16 17:01:12 +01001755 @UnsupportedAppUsage
Naveen Kallafc2cbe92011-12-29 15:07:41 -08001756 public static boolean isCdma(int radioTechnology) {
Robert Greenwalt1434d7b2012-02-17 13:14:08 -08001757 return radioTechnology == RIL_RADIO_TECHNOLOGY_IS95A
1758 || radioTechnology == RIL_RADIO_TECHNOLOGY_IS95B
1759 || radioTechnology == RIL_RADIO_TECHNOLOGY_1xRTT
1760 || radioTechnology == RIL_RADIO_TECHNOLOGY_EVDO_0
1761 || radioTechnology == RIL_RADIO_TECHNOLOGY_EVDO_A
1762 || radioTechnology == RIL_RADIO_TECHNOLOGY_EVDO_B
Etan Cohen5e5bc4b2014-10-08 17:10:33 -07001763 || radioTechnology == RIL_RADIO_TECHNOLOGY_EHRPD;
Naveen Kallafc2cbe92011-12-29 15:07:41 -08001764 }
Etan Cohendcc07362014-09-23 16:03:44 -07001765
Amit Mahajan13a98b62015-02-26 10:46:17 -08001766 /** @hide */
Sarah Chin96169ca2020-01-07 17:45:05 -08001767 public static boolean isPsOnlyTech(int radioTechnology) {
1768 return radioTechnology == RIL_RADIO_TECHNOLOGY_LTE
1769 || radioTechnology == RIL_RADIO_TECHNOLOGY_LTE_CA
1770 || radioTechnology == RIL_RADIO_TECHNOLOGY_NR;
Ajay Nambi7965fa42015-05-14 18:48:33 -07001771 }
1772
1773 /** @hide */
Sukanya Rajkhowaab815c12019-03-25 16:51:26 -07001774 public static boolean isPsTech(int radioTechnology) {
1775 return radioTechnology == RIL_RADIO_TECHNOLOGY_LTE ||
1776 radioTechnology == RIL_RADIO_TECHNOLOGY_LTE_CA ||
1777 radioTechnology == RIL_RADIO_TECHNOLOGY_NR;
1778 }
1779
1780 /** @hide */
Mathew Inwood55418ea2018-12-20 15:30:45 +00001781 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Jack Yu7d675e52018-12-17 16:09:03 -08001782 public static boolean bearerBitmapHasCdma(int networkTypeBitmask) {
1783 return (RIL_RADIO_CDMA_TECHNOLOGY_BITMASK
1784 & convertNetworkTypeBitmaskToBearerBitmask(networkTypeBitmask)) != 0;
Amit Mahajan13a98b62015-02-26 10:46:17 -08001785 }
1786
1787 /** @hide */
Mathew Inwooda8382062018-08-16 17:01:12 +01001788 @UnsupportedAppUsage
Amit Mahajan13a98b62015-02-26 10:46:17 -08001789 public static boolean bitmaskHasTech(int bearerBitmask, int radioTech) {
1790 if (bearerBitmask == 0) {
1791 return true;
1792 } else if (radioTech >= 1) {
1793 return ((bearerBitmask & (1 << (radioTech - 1))) != 0);
1794 }
1795 return false;
1796 }
1797
1798 /** @hide */
1799 public static int getBitmaskForTech(int radioTech) {
1800 if (radioTech >= 1) {
1801 return (1 << (radioTech - 1));
1802 }
1803 return 0;
1804 }
1805
1806 /** @hide */
1807 public static int getBitmaskFromString(String bearerList) {
1808 String[] bearers = bearerList.split("\\|");
1809 int bearerBitmask = 0;
1810 for (String bearer : bearers) {
1811 int bearerInt = 0;
1812 try {
1813 bearerInt = Integer.parseInt(bearer.trim());
1814 } catch (NumberFormatException nfe) {
1815 return 0;
1816 }
1817
1818 if (bearerInt == 0) {
1819 return 0;
1820 }
1821
1822 bearerBitmask |= getBitmaskForTech(bearerInt);
1823 }
1824 return bearerBitmask;
1825 }
1826
SongFerngWange5202be2019-12-02 21:19:24 +08001827 /**
1828 * Convert network type bitmask to bearer bitmask.
1829 *
1830 * @param networkTypeBitmask The network type bitmask value
1831 * @return The bearer bitmask value.
1832 *
1833 * @hide
1834 */
Cassied53df962017-12-05 13:34:33 -08001835 public static int convertNetworkTypeBitmaskToBearerBitmask(int networkTypeBitmask) {
1836 if (networkTypeBitmask == 0) {
1837 return 0;
1838 }
1839 int bearerBitmask = 0;
1840 for (int bearerInt = 0; bearerInt < NEXT_RIL_RADIO_TECHNOLOGY; bearerInt++) {
1841 if (bitmaskHasTech(networkTypeBitmask, rilRadioTechnologyToNetworkType(bearerInt))) {
1842 bearerBitmask |= getBitmaskForTech(bearerInt);
1843 }
1844 }
1845 return bearerBitmask;
1846 }
1847
SongFerngWange5202be2019-12-02 21:19:24 +08001848 /**
1849 * Convert bearer bitmask to network type bitmask.
1850 *
1851 * @param bearerBitmask The bearer bitmask value.
1852 * @return The network type bitmask value.
1853 *
1854 * @hide
1855 */
Cassied53df962017-12-05 13:34:33 -08001856 public static int convertBearerBitmaskToNetworkTypeBitmask(int bearerBitmask) {
1857 if (bearerBitmask == 0) {
1858 return 0;
1859 }
1860 int networkTypeBitmask = 0;
1861 for (int bearerInt = 0; bearerInt < NEXT_RIL_RADIO_TECHNOLOGY; bearerInt++) {
1862 if (bitmaskHasTech(bearerBitmask, bearerInt)) {
1863 networkTypeBitmask |= getBitmaskForTech(rilRadioTechnologyToNetworkType(bearerInt));
1864 }
1865 }
1866 return networkTypeBitmask;
1867 }
1868
Etan Cohendcc07362014-09-23 16:03:44 -07001869 /**
1870 * Returns a merged ServiceState consisting of the base SS with voice settings from the
1871 * voice SS. The voice SS is only used if it is IN_SERVICE (otherwise the base SS is returned).
1872 * @hide
1873 * */
Mathew Inwooda8382062018-08-16 17:01:12 +01001874 @UnsupportedAppUsage
Etan Cohendcc07362014-09-23 16:03:44 -07001875 public static ServiceState mergeServiceStates(ServiceState baseSs, ServiceState voiceSs) {
1876 if (voiceSs.mVoiceRegState != STATE_IN_SERVICE) {
1877 return baseSs;
1878 }
1879
1880 ServiceState newSs = new ServiceState(baseSs);
1881
1882 // voice overrides
1883 newSs.mVoiceRegState = voiceSs.mVoiceRegState;
1884 newSs.mIsEmergencyOnly = false; // only get here if voice is IN_SERVICE
1885
1886 return newSs;
1887 }
Jack Yud5f1de12017-12-21 11:00:05 -08001888
1889 /**
Jack Yue27d3fd2019-03-15 14:49:53 -07001890 * Get all of the available network registration info.
Jack Yud5f1de12017-12-21 11:00:05 -08001891 *
Jack Yue27d3fd2019-03-15 14:49:53 -07001892 * @return List of {@link NetworkRegistrationInfo}
Jack Yud5f1de12017-12-21 11:00:05 -08001893 */
Jack Yu8eb6ca82019-03-01 12:04:50 -08001894 @NonNull
Jack Yue27d3fd2019-03-15 14:49:53 -07001895 public List<NetworkRegistrationInfo> getNetworkRegistrationInfoList() {
1896 synchronized (mNetworkRegistrationInfos) {
Jack Yu37538592019-04-16 08:20:18 -07001897 List<NetworkRegistrationInfo> newList = new ArrayList<>();
1898 for (NetworkRegistrationInfo nri : mNetworkRegistrationInfos) {
1899 newList.add(new NetworkRegistrationInfo(nri));
1900 }
1901 return newList;
Malcolm Chen574b41a2018-02-13 15:42:58 -08001902 }
Jack Yud5f1de12017-12-21 11:00:05 -08001903 }
1904
1905 /**
Jack Yue27d3fd2019-03-15 14:49:53 -07001906 * Get the network registration info list for the transport type.
Jack Yud5f1de12017-12-21 11:00:05 -08001907 *
Jack Yuef25faf2019-03-14 15:42:09 -07001908 * @param transportType The transport type
Jack Yue27d3fd2019-03-15 14:49:53 -07001909 * @return List of {@link NetworkRegistrationInfo}
Jack Yud5f1de12017-12-21 11:00:05 -08001910 * @hide
1911 */
Jack Yu8eb6ca82019-03-01 12:04:50 -08001912 @NonNull
Jack Yuf2add902018-07-12 15:10:34 -07001913 @SystemApi
Jack Yue27d3fd2019-03-15 14:49:53 -07001914 public List<NetworkRegistrationInfo> getNetworkRegistrationInfoListForTransportType(
Jack Yuef25faf2019-03-14 15:42:09 -07001915 @TransportType int transportType) {
Jack Yue27d3fd2019-03-15 14:49:53 -07001916 List<NetworkRegistrationInfo> list = new ArrayList<>();
Malcolm Chen574b41a2018-02-13 15:42:58 -08001917
Jack Yue27d3fd2019-03-15 14:49:53 -07001918 synchronized (mNetworkRegistrationInfos) {
1919 for (NetworkRegistrationInfo networkRegistrationInfo : mNetworkRegistrationInfos) {
1920 if (networkRegistrationInfo.getTransportType() == transportType) {
Jack Yu37538592019-04-16 08:20:18 -07001921 list.add(new NetworkRegistrationInfo(networkRegistrationInfo));
Malcolm Chen574b41a2018-02-13 15:42:58 -08001922 }
Jack Yud5f1de12017-12-21 11:00:05 -08001923 }
1924 }
Malcolm Chen574b41a2018-02-13 15:42:58 -08001925
Jack Yud5f1de12017-12-21 11:00:05 -08001926 return list;
1927 }
1928
1929 /**
Jack Yue27d3fd2019-03-15 14:49:53 -07001930 * Get the network registration info list for the network domain.
Jack Yud5f1de12017-12-21 11:00:05 -08001931 *
Jack Yue27d3fd2019-03-15 14:49:53 -07001932 * @param domain The network {@link NetworkRegistrationInfo.Domain domain}
1933 * @return List of {@link NetworkRegistrationInfo}
Jack Yud5f1de12017-12-21 11:00:05 -08001934 * @hide
1935 */
Jack Yu8eb6ca82019-03-01 12:04:50 -08001936 @NonNull
Jack Yuf2add902018-07-12 15:10:34 -07001937 @SystemApi
Jack Yue27d3fd2019-03-15 14:49:53 -07001938 public List<NetworkRegistrationInfo> getNetworkRegistrationInfoListForDomain(
Jack Yub4ae4772018-10-02 11:14:38 -07001939 @Domain int domain) {
Jack Yue27d3fd2019-03-15 14:49:53 -07001940 List<NetworkRegistrationInfo> list = new ArrayList<>();
Jack Yub4ae4772018-10-02 11:14:38 -07001941
Jack Yue27d3fd2019-03-15 14:49:53 -07001942 synchronized (mNetworkRegistrationInfos) {
1943 for (NetworkRegistrationInfo networkRegistrationInfo : mNetworkRegistrationInfos) {
Nathan Haroldc41cb732019-12-17 13:06:54 -08001944 if ((networkRegistrationInfo.getDomain() & domain) != 0) {
Jack Yu37538592019-04-16 08:20:18 -07001945 list.add(new NetworkRegistrationInfo(networkRegistrationInfo));
Jack Yub4ae4772018-10-02 11:14:38 -07001946 }
1947 }
1948 }
1949
1950 return list;
1951 }
1952
1953 /**
Jack Yu37a1fc32018-10-02 17:01:51 -07001954 * Get the network registration state for the transport type and network domain.
Mingming Caia42253b2020-01-30 17:10:38 -08001955 * If multiple domains are in the input bitmask, only the first one from
1956 * networkRegistrationInfo.getDomain() will be returned.
Jack Yub4ae4772018-10-02 11:14:38 -07001957 *
Jack Yue27d3fd2019-03-15 14:49:53 -07001958 * @param domain The network {@link NetworkRegistrationInfo.Domain domain}
Jack Yuef25faf2019-03-14 15:42:09 -07001959 * @param transportType The transport type
Jack Yue27d3fd2019-03-15 14:49:53 -07001960 * @return The matching {@link NetworkRegistrationInfo}
Jack Yub4ae4772018-10-02 11:14:38 -07001961 * @hide
Jack Yub4ae4772018-10-02 11:14:38 -07001962 */
Jack Yu8eb6ca82019-03-01 12:04:50 -08001963 @Nullable
Jack Yub4ae4772018-10-02 11:14:38 -07001964 @SystemApi
Jack Yue27d3fd2019-03-15 14:49:53 -07001965 public NetworkRegistrationInfo getNetworkRegistrationInfo(@Domain int domain,
1966 @TransportType int transportType) {
1967 synchronized (mNetworkRegistrationInfos) {
1968 for (NetworkRegistrationInfo networkRegistrationInfo : mNetworkRegistrationInfos) {
1969 if (networkRegistrationInfo.getTransportType() == transportType
Nathan Haroldc41cb732019-12-17 13:06:54 -08001970 && (networkRegistrationInfo.getDomain() & domain) != 0) {
Jack Yu37538592019-04-16 08:20:18 -07001971 return new NetworkRegistrationInfo(networkRegistrationInfo);
Malcolm Chen574b41a2018-02-13 15:42:58 -08001972 }
Jack Yud5f1de12017-12-21 11:00:05 -08001973 }
1974 }
Malcolm Chen574b41a2018-02-13 15:42:58 -08001975
Jack Yud5f1de12017-12-21 11:00:05 -08001976 return null;
1977 }
Malcolm Chen574b41a2018-02-13 15:42:58 -08001978
1979 /**
1980 * @hide
1981 */
Jack Yudba10322019-03-21 16:33:15 -07001982 @TestApi
Jack Yu37538592019-04-16 08:20:18 -07001983 public void addNetworkRegistrationInfo(NetworkRegistrationInfo nri) {
1984 if (nri == null) return;
Malcolm Chen574b41a2018-02-13 15:42:58 -08001985
Jack Yue27d3fd2019-03-15 14:49:53 -07001986 synchronized (mNetworkRegistrationInfos) {
1987 for (int i = 0; i < mNetworkRegistrationInfos.size(); i++) {
1988 NetworkRegistrationInfo curRegState = mNetworkRegistrationInfos.get(i);
Jack Yu37538592019-04-16 08:20:18 -07001989 if (curRegState.getTransportType() == nri.getTransportType()
1990 && curRegState.getDomain() == nri.getDomain()) {
Jack Yue27d3fd2019-03-15 14:49:53 -07001991 mNetworkRegistrationInfos.remove(i);
Malcolm Chen574b41a2018-02-13 15:42:58 -08001992 break;
1993 }
1994 }
1995
Jack Yu37538592019-04-16 08:20:18 -07001996 mNetworkRegistrationInfos.add(new NetworkRegistrationInfo(nri));
Malcolm Chen574b41a2018-02-13 15:42:58 -08001997 }
1998 }
Pengquan Meng424acc72018-11-27 16:45:17 -08001999
2000 /**
2001 * @hide
2002 */
2003 public static final int getBetterNRFrequencyRange(int range1, int range2) {
2004 return FREQUENCY_RANGE_ORDER.indexOf(range1) > FREQUENCY_RANGE_ORDER.indexOf(range2)
2005 ? range1
2006 : range2;
2007 }
Hall Liuee313732018-11-27 14:36:51 -08002008
2009 /**
2010 * Returns a copy of self with location-identifying information removed.
Jack Yue27d3fd2019-03-15 14:49:53 -07002011 * Always clears the NetworkRegistrationInfo's CellIdentity fields, but if removeCoarseLocation
Hall Liuee313732018-11-27 14:36:51 -08002012 * is true, clears other info as well.
Malcolm Chen00f7b722019-12-26 17:11:29 -08002013 *
2014 * @param removeCoarseLocation Whether to also remove coarse location information.
2015 * if false, it only clears fine location information such as
2016 * NetworkRegistrationInfo's CellIdentity fields; If true, it will
2017 * also remove other location information such as operator's MCC
2018 * and MNC.
2019 * @return the copied ServiceState with location info sanitized.
Hall Liuee313732018-11-27 14:36:51 -08002020 * @hide
2021 */
Malcolm Chen00f7b722019-12-26 17:11:29 -08002022 @NonNull
2023 public ServiceState createLocationInfoSanitizedCopy(boolean removeCoarseLocation) {
Hall Liuee313732018-11-27 14:36:51 -08002024 ServiceState state = new ServiceState(this);
Jack Yu4c118092019-05-16 14:27:29 -07002025 synchronized (state.mNetworkRegistrationInfos) {
2026 List<NetworkRegistrationInfo> networkRegistrationInfos =
2027 state.mNetworkRegistrationInfos.stream()
2028 .map(NetworkRegistrationInfo::sanitizeLocationInfo)
2029 .collect(Collectors.toList());
2030 state.mNetworkRegistrationInfos.clear();
2031 state.mNetworkRegistrationInfos.addAll(networkRegistrationInfos);
Hall Liuee313732018-11-27 14:36:51 -08002032 }
2033 if (!removeCoarseLocation) return state;
2034
SongFerngWang2b1ea8d2019-11-20 02:11:09 +08002035 state.mOperatorAlphaLong = null;
2036 state.mOperatorAlphaShort = null;
2037 state.mOperatorNumeric = null;
Hall Liuee313732018-11-27 14:36:51 -08002038
2039 return state;
2040 }
SongFerngWang3cbcf752019-03-21 23:14:20 +08002041
2042 /**
2043 * @hide
2044 */
2045 public void setOperatorAlphaLongRaw(String operatorAlphaLong) {
2046 mOperatorAlphaLongRaw = operatorAlphaLong;
2047 }
2048
2049 /**
2050 * The current registered raw data network operator name in long alphanumeric format.
2051 *
Jayachandran C86c4ed72020-02-27 15:18:33 -08002052 * The long format can be up to 16 characters long.
2053 *
Jayachandran C98e84ea2019-11-06 21:55:32 -08002054 * @return long raw name of operator, null if unregistered or unknown
Sarah Chinb800cbd2020-02-19 12:25:36 -08002055 * @hide
SongFerngWang3cbcf752019-03-21 23:14:20 +08002056 */
Jayachandran C98e84ea2019-11-06 21:55:32 -08002057 @Nullable
SongFerngWang3cbcf752019-03-21 23:14:20 +08002058 public String getOperatorAlphaLongRaw() {
2059 return mOperatorAlphaLongRaw;
2060 }
2061
2062 /**
2063 * @hide
2064 */
2065 public void setOperatorAlphaShortRaw(String operatorAlphaShort) {
2066 mOperatorAlphaShortRaw = operatorAlphaShort;
2067 }
2068
2069 /**
2070 * The current registered raw data network operator name in short alphanumeric format.
2071 *
Jayachandran C86c4ed72020-02-27 15:18:33 -08002072 * The short format can be up to 8 characters long.
2073 *
Jayachandran C98e84ea2019-11-06 21:55:32 -08002074 * @return short raw name of operator, null if unregistered or unknown
Sarah Chinb800cbd2020-02-19 12:25:36 -08002075 * @hide
SongFerngWang3cbcf752019-03-21 23:14:20 +08002076 */
Jayachandran C98e84ea2019-11-06 21:55:32 -08002077 @Nullable
SongFerngWang3cbcf752019-03-21 23:14:20 +08002078 public String getOperatorAlphaShortRaw() {
2079 return mOperatorAlphaShortRaw;
2080 }
Jack Yua74f2d82019-05-21 17:16:22 -07002081
2082 /**
2083 * Set to {@code true} if any data network is preferred on IWLAN.
2084 *
2085 * @param isIwlanPreferred {@code true} if IWLAN is preferred.
2086 * @hide
2087 */
2088 public void setIwlanPreferred(boolean isIwlanPreferred) {
2089 mIsIwlanPreferred = isIwlanPreferred;
2090 }
Jack Yu7ebfc332019-06-12 11:00:16 -07002091
2092 /**
2093 * @return {@code true} if any data network is preferred on IWLAN.
2094 *
2095 * Note only when this value is true, {@link #getDataNetworkType()} will return
2096 * {@link TelephonyManager#NETWORK_TYPE_IWLAN} when AP-assisted mode device camps on both
2097 * cellular and IWLAN. This value does not affect legacy mode devices as the data network
2098 * type is directly reported by the modem.
2099 *
2100 * @hide
2101 */
2102 public boolean isIwlanPreferred() {
2103 return mIsIwlanPreferred;
2104 }
shiluc0e176d2019-12-02 10:32:00 -08002105
shilu814f1892020-01-24 16:21:56 -08002106 /**
2107 * This indicates whether the device is searching for service.
2108 *
2109 * This API reports the modem searching status for
2110 * {@link AccessNetworkConstants#TRANSPORT_TYPE_WWAN} (cellular) service in either
2111 * {@link NetworkRegistrationInfo#DOMAIN_CS} or {@link NetworkRegistrationInfo#DOMAIN_PS}.
2112 * This API will not report searching status for
2113 * {@link AccessNetworkConstants#TRANSPORT_TYPE_WLAN}.
2114 *
2115 * @return {@code true} whenever the modem is searching for service.
2116 */
shiluc0e176d2019-12-02 10:32:00 -08002117 public boolean isSearching() {
2118 NetworkRegistrationInfo psRegState = getNetworkRegistrationInfo(
2119 NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
2120
2121 if (psRegState != null && psRegState.getRegistrationState()
2122 == NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_SEARCHING) {
2123 return true;
2124 }
2125
2126 NetworkRegistrationInfo csRegState = getNetworkRegistrationInfo(
2127 NetworkRegistrationInfo.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
2128
2129 if (csRegState != null && csRegState.getRegistrationState()
2130 == NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_SEARCHING) {
2131 return true;
2132 }
2133 return false;
2134 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002135}