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