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