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 @android.ravenwood.annotation.RavenwoodKeepPartialClass 65 public class ServiceState implements Parcelable { 66 67 static final String LOG_TAG = "PHONE"; 68 static final boolean DBG = false; 69 static final boolean VDBG = false; // STOPSHIP if true 70 71 /** @hide */ 72 @Retention(RetentionPolicy.SOURCE) 73 @IntDef(prefix = "STATE_", 74 value = {STATE_IN_SERVICE, STATE_OUT_OF_SERVICE, STATE_EMERGENCY_ONLY, 75 STATE_POWER_OFF}) 76 public @interface RegState {} 77 78 /** 79 * Normal operation condition, the phone is registered 80 * with an operator either in home network or in roaming. 81 */ 82 public static final int STATE_IN_SERVICE = TelephonyProtoEnums.SERVICE_STATE_IN_SERVICE; // 0 83 84 /** 85 * Phone is not registered with any operator, the phone 86 * can be currently searching a new operator to register to, or not 87 * searching to registration at all, or registration is denied, or radio 88 * signal is not available. 89 */ 90 public static final int STATE_OUT_OF_SERVICE = 91 TelephonyProtoEnums.SERVICE_STATE_OUT_OF_SERVICE; // 1 92 93 /** 94 * The phone is registered and locked. Only emergency numbers are allowed. {@more} 95 */ 96 //TODO: This state is not used anymore. It should be deprecated in a future release. 97 public static final int STATE_EMERGENCY_ONLY = 98 TelephonyProtoEnums.SERVICE_STATE_EMERGENCY_ONLY; // 2 99 100 /** 101 * Radio of telephony is explicitly powered off. 102 */ 103 public static final int STATE_POWER_OFF = TelephonyProtoEnums.SERVICE_STATE_POWER_OFF; // 3 104 105 /** @hide */ 106 @Retention(RetentionPolicy.SOURCE) 107 @IntDef(prefix = "FREQUENCY_RANGE_", 108 value = {FREQUENCY_RANGE_UNKNOWN, FREQUENCY_RANGE_LOW, FREQUENCY_RANGE_MID, 109 FREQUENCY_RANGE_HIGH, FREQUENCY_RANGE_MMWAVE}) 110 public @interface FrequencyRange {} 111 112 /** 113 * Indicates frequency range is unknown. 114 * @hide 115 */ 116 public static final int FREQUENCY_RANGE_UNKNOWN = 0; 117 118 /** 119 * Indicates the frequency range is below 1GHz. 120 * @hide 121 */ 122 public static final int FREQUENCY_RANGE_LOW = 1; 123 124 /** 125 * Indicates the frequency range is between 1GHz to 3GHz. 126 * @hide 127 */ 128 public static final int FREQUENCY_RANGE_MID = 2; 129 130 /** 131 * Indicates the frequency range is between 3GHz and 6GHz. 132 * @hide 133 */ 134 public static final int FREQUENCY_RANGE_HIGH = 3; 135 136 /** 137 * Indicates the frequency range is above 6GHz (millimeter wave frequency). 138 * @hide 139 */ 140 public static final int FREQUENCY_RANGE_MMWAVE = 4; 141 142 /** 143 * Number of frequency ranges. 144 * @hide 145 */ 146 public static final int FREQUENCY_RANGE_COUNT = 5; 147 148 /** @hide */ 149 @Retention(RetentionPolicy.SOURCE) 150 @IntDef(prefix = "DUPLEX_MODE_", 151 value = {DUPLEX_MODE_UNKNOWN, DUPLEX_MODE_FDD, DUPLEX_MODE_TDD}) 152 public @interface DuplexMode {} 153 154 /** 155 * Duplex mode for the phone is unknown. 156 */ 157 public static final int DUPLEX_MODE_UNKNOWN = 0; 158 159 /** 160 * Duplex mode for the phone is frequency-division duplexing. 161 */ 162 public static final int DUPLEX_MODE_FDD = 1; 163 164 /** 165 * Duplex mode for the phone is time-division duplexing. 166 */ 167 public static final int DUPLEX_MODE_TDD = 2; 168 169 /** 170 * Available radio technologies for GSM, UMTS and CDMA. 171 * Duplicates the constants from hardware/radio/include/ril.h 172 * This should only be used by agents working with the ril. Others 173 * should use the equivalent TelephonyManager.NETWORK_TYPE_* 174 */ 175 /** @hide */ 176 public static final int RIL_RADIO_TECHNOLOGY_UNKNOWN = 0; 177 /** @hide */ 178 public static final int RIL_RADIO_TECHNOLOGY_GPRS = 1; 179 /** @hide */ 180 public static final int RIL_RADIO_TECHNOLOGY_EDGE = 2; 181 /** @hide */ 182 public static final int RIL_RADIO_TECHNOLOGY_UMTS = 3; 183 /** @hide */ 184 public static final int RIL_RADIO_TECHNOLOGY_IS95A = 4; 185 /** @hide */ 186 public static final int RIL_RADIO_TECHNOLOGY_IS95B = 5; 187 /** @hide */ 188 public static final int RIL_RADIO_TECHNOLOGY_1xRTT = 6; 189 /** @hide */ 190 public static final int RIL_RADIO_TECHNOLOGY_EVDO_0 = 7; 191 /** @hide */ 192 public static final int RIL_RADIO_TECHNOLOGY_EVDO_A = 8; 193 /** @hide */ 194 public static final int RIL_RADIO_TECHNOLOGY_HSDPA = 9; 195 /** @hide */ 196 public static final int RIL_RADIO_TECHNOLOGY_HSUPA = 10; 197 /** @hide */ 198 public static final int RIL_RADIO_TECHNOLOGY_HSPA = 11; 199 /** @hide */ 200 public static final int RIL_RADIO_TECHNOLOGY_EVDO_B = 12; 201 /** @hide */ 202 public static final int RIL_RADIO_TECHNOLOGY_EHRPD = 13; 203 /** @hide */ 204 public static final int RIL_RADIO_TECHNOLOGY_LTE = 14; 205 /** @hide */ 206 public static final int RIL_RADIO_TECHNOLOGY_HSPAP = 15; 207 /** 208 * GSM radio technology only supports voice. It does not support data. 209 * @hide 210 */ 211 public static final int RIL_RADIO_TECHNOLOGY_GSM = 16; 212 /** @hide */ 213 public static final int RIL_RADIO_TECHNOLOGY_TD_SCDMA = 17; 214 /** 215 * IWLAN 216 * @hide 217 */ 218 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) 219 public static final int RIL_RADIO_TECHNOLOGY_IWLAN = 18; 220 221 /** 222 * LTE_CA 223 * @hide 224 */ 225 public static final int RIL_RADIO_TECHNOLOGY_LTE_CA = 19; 226 227 /** 228 * NR(New Radio) 5G. 229 * @hide 230 */ 231 public static final int RIL_RADIO_TECHNOLOGY_NR = 20; 232 233 /** 234 * RIL Radio Annotation 235 * @hide 236 */ 237 @Retention(RetentionPolicy.SOURCE) 238 @IntDef(prefix = {"RIL_RADIO_TECHNOLOGY_" }, value = { 239 ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN, 240 ServiceState.RIL_RADIO_TECHNOLOGY_GPRS, 241 ServiceState.RIL_RADIO_TECHNOLOGY_EDGE, 242 ServiceState.RIL_RADIO_TECHNOLOGY_UMTS, 243 ServiceState.RIL_RADIO_TECHNOLOGY_IS95A, 244 ServiceState.RIL_RADIO_TECHNOLOGY_IS95B, 245 ServiceState.RIL_RADIO_TECHNOLOGY_1xRTT, 246 ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_0, 247 ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_A, 248 ServiceState.RIL_RADIO_TECHNOLOGY_HSDPA, 249 ServiceState.RIL_RADIO_TECHNOLOGY_HSUPA, 250 ServiceState.RIL_RADIO_TECHNOLOGY_HSPA, 251 ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_B, 252 ServiceState.RIL_RADIO_TECHNOLOGY_EHRPD, 253 ServiceState.RIL_RADIO_TECHNOLOGY_LTE, 254 ServiceState.RIL_RADIO_TECHNOLOGY_HSPAP, 255 ServiceState.RIL_RADIO_TECHNOLOGY_GSM, 256 ServiceState.RIL_RADIO_TECHNOLOGY_TD_SCDMA, 257 ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN, 258 ServiceState.RIL_RADIO_TECHNOLOGY_LTE_CA, 259 ServiceState.RIL_RADIO_TECHNOLOGY_NR}) 260 public @interface RilRadioTechnology {} 261 262 263 /** 264 * The number of the radio technologies. 265 */ 266 private static final int NEXT_RIL_RADIO_TECHNOLOGY = 21; 267 268 /** @hide */ 269 public static final int RIL_RADIO_CDMA_TECHNOLOGY_BITMASK = 270 (1 << (RIL_RADIO_TECHNOLOGY_IS95A - 1)) 271 | (1 << (RIL_RADIO_TECHNOLOGY_IS95B - 1)) 272 | (1 << (RIL_RADIO_TECHNOLOGY_1xRTT - 1)) 273 | (1 << (RIL_RADIO_TECHNOLOGY_EVDO_0 - 1)) 274 | (1 << (RIL_RADIO_TECHNOLOGY_EVDO_A - 1)) 275 | (1 << (RIL_RADIO_TECHNOLOGY_EVDO_B - 1)) 276 | (1 << (RIL_RADIO_TECHNOLOGY_EHRPD - 1)); 277 278 private int mVoiceRegState = STATE_OUT_OF_SERVICE; 279 private int mDataRegState = STATE_OUT_OF_SERVICE; 280 281 /** @hide */ 282 @Retention(RetentionPolicy.SOURCE) 283 @IntDef(prefix = { "ROAMING_TYPE_" }, value = { 284 ROAMING_TYPE_NOT_ROAMING, 285 ROAMING_TYPE_UNKNOWN, 286 ROAMING_TYPE_DOMESTIC, 287 ROAMING_TYPE_INTERNATIONAL 288 }) 289 public @interface RoamingType {} 290 291 /** 292 * Not roaming, registered in home network. 293 * @hide 294 */ 295 @SystemApi 296 public static final int ROAMING_TYPE_NOT_ROAMING = 0; 297 /** 298 * registered in a roaming network, but can not tell if it's domestic or international. 299 * @hide 300 */ 301 @SystemApi 302 public static final int ROAMING_TYPE_UNKNOWN = 1; 303 /** 304 * registered in a domestic roaming network 305 * @hide 306 */ 307 @SystemApi 308 public static final int ROAMING_TYPE_DOMESTIC = 2; 309 /** 310 * registered in an international roaming network 311 * @hide 312 */ 313 @SystemApi 314 public static final int ROAMING_TYPE_INTERNATIONAL = 3; 315 316 /** 317 * Unknown ID. Could be returned by {@link #getCdmaNetworkId()} or {@link #getCdmaSystemId()} 318 */ 319 public static final int UNKNOWN_ID = -1; 320 321 /** 322 * A parcelable extra used with {@link Intent#ACTION_SERVICE_STATE} representing the service 323 * state. 324 * @hide 325 */ 326 private static final String EXTRA_SERVICE_STATE = "android.intent.extra.SERVICE_STATE"; 327 328 329 private String mOperatorAlphaLong; 330 private String mOperatorAlphaShort; 331 private String mOperatorNumeric; 332 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) 333 private boolean mIsManualNetworkSelection; 334 335 private boolean mIsEmergencyOnly; 336 337 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) 338 private boolean mCssIndicator; 339 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) 340 private int mNetworkId; 341 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) 342 private int mSystemId; 343 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) 344 private int mCdmaRoamingIndicator; 345 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) 346 private int mCdmaDefaultRoamingIndicator; 347 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) 348 private int mCdmaEriIconIndex; 349 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) 350 private int mCdmaEriIconMode; 351 352 @FrequencyRange 353 private int mNrFrequencyRange; 354 private int mChannelNumber; 355 private int[] mCellBandwidths = new int[0]; 356 357 /** 358 * ARFCN stands for Absolute Radio Frequency Channel Number. This field is current used for 359 * LTE where it represents the boost for EARFCN (Reference: 3GPP TS 36.104 5.4.3) and for NR 360 * where it's for NR ARFCN (Reference: 3GPP TS 36.108) */ 361 private int mArfcnRsrpBoost = 0; 362 363 private final List<NetworkRegistrationInfo> mNetworkRegistrationInfos = new ArrayList<>(); 364 365 private String mOperatorAlphaLongRaw; 366 private String mOperatorAlphaShortRaw; 367 private boolean mIsDataRoamingFromRegistration; 368 private boolean mIsIwlanPreferred; 369 370 /** 371 * get String description of roaming type 372 * @hide 373 */ getRoamingLogString(int roamingType)374 public static final String getRoamingLogString(int roamingType) { 375 switch (roamingType) { 376 case ROAMING_TYPE_NOT_ROAMING: 377 return "home"; 378 379 case ROAMING_TYPE_UNKNOWN: 380 return "roaming"; 381 382 case ROAMING_TYPE_DOMESTIC: 383 return "Domestic Roaming"; 384 385 case ROAMING_TYPE_INTERNATIONAL: 386 return "International Roaming"; 387 388 default: 389 return "UNKNOWN"; 390 } 391 } 392 393 /** 394 * Create a new ServiceState from a intent notifier Bundle 395 * 396 * This method is used to get ServiceState object from extras upon receiving 397 * {@link Intent#ACTION_SERVICE_STATE}. 398 * 399 * @param m Bundle from intent notifier 400 * @return newly created ServiceState 401 * @hide 402 */ 403 @NonNull 404 @UnsupportedAppUsage newFromBundle(@onNull Bundle m)405 public static ServiceState newFromBundle(@NonNull Bundle m) { 406 ServiceState ret; 407 ret = new ServiceState(); 408 ret.setFromNotifierBundle(m); 409 return ret; 410 } 411 412 /** 413 * Empty constructor 414 */ ServiceState()415 public ServiceState() { 416 } 417 418 /** 419 * Copy constructors 420 * 421 * @param s Source service state 422 */ ServiceState(ServiceState s)423 public ServiceState(ServiceState s) { 424 copyFrom(s); 425 } 426 copyFrom(ServiceState s)427 protected void copyFrom(ServiceState s) { 428 mVoiceRegState = s.mVoiceRegState; 429 mDataRegState = s.mDataRegState; 430 mOperatorAlphaLong = s.mOperatorAlphaLong; 431 mOperatorAlphaShort = s.mOperatorAlphaShort; 432 mOperatorNumeric = s.mOperatorNumeric; 433 mIsManualNetworkSelection = s.mIsManualNetworkSelection; 434 mCssIndicator = s.mCssIndicator; 435 mNetworkId = s.mNetworkId; 436 mSystemId = s.mSystemId; 437 mCdmaRoamingIndicator = s.mCdmaRoamingIndicator; 438 mCdmaDefaultRoamingIndicator = s.mCdmaDefaultRoamingIndicator; 439 mCdmaEriIconIndex = s.mCdmaEriIconIndex; 440 mCdmaEriIconMode = s.mCdmaEriIconMode; 441 mIsEmergencyOnly = s.mIsEmergencyOnly; 442 mChannelNumber = s.mChannelNumber; 443 mCellBandwidths = s.mCellBandwidths == null ? null : 444 Arrays.copyOf(s.mCellBandwidths, s.mCellBandwidths.length); 445 mArfcnRsrpBoost = s.mArfcnRsrpBoost; 446 synchronized (mNetworkRegistrationInfos) { 447 mNetworkRegistrationInfos.clear(); 448 for (NetworkRegistrationInfo nri : s.getNetworkRegistrationInfoList()) { 449 mNetworkRegistrationInfos.add(new NetworkRegistrationInfo(nri)); 450 } 451 } 452 mNrFrequencyRange = s.mNrFrequencyRange; 453 mOperatorAlphaLongRaw = s.mOperatorAlphaLongRaw; 454 mOperatorAlphaShortRaw = s.mOperatorAlphaShortRaw; 455 mIsDataRoamingFromRegistration = s.mIsDataRoamingFromRegistration; 456 mIsIwlanPreferred = s.mIsIwlanPreferred; 457 } 458 459 /** 460 * Construct a ServiceState object from the given parcel. 461 * 462 * @deprecated The constructor takes parcel should not be public at the beginning. Use 463 * {@link #ServiceState()} instead. 464 */ 465 @Deprecated ServiceState(Parcel in)466 public ServiceState(Parcel in) { 467 mVoiceRegState = in.readInt(); 468 mDataRegState = in.readInt(); 469 mOperatorAlphaLong = in.readString(); 470 mOperatorAlphaShort = in.readString(); 471 mOperatorNumeric = in.readString(); 472 mIsManualNetworkSelection = in.readInt() != 0; 473 mCssIndicator = (in.readInt() != 0); 474 mNetworkId = in.readInt(); 475 mSystemId = in.readInt(); 476 mCdmaRoamingIndicator = in.readInt(); 477 mCdmaDefaultRoamingIndicator = in.readInt(); 478 mCdmaEriIconIndex = in.readInt(); 479 mCdmaEriIconMode = in.readInt(); 480 mIsEmergencyOnly = in.readInt() != 0; 481 mArfcnRsrpBoost = in.readInt(); 482 synchronized (mNetworkRegistrationInfos) { 483 in.readList(mNetworkRegistrationInfos, NetworkRegistrationInfo.class.getClassLoader(), android.telephony.NetworkRegistrationInfo.class); 484 } 485 mChannelNumber = in.readInt(); 486 mCellBandwidths = in.createIntArray(); 487 mNrFrequencyRange = in.readInt(); 488 mOperatorAlphaLongRaw = in.readString(); 489 mOperatorAlphaShortRaw = in.readString(); 490 mIsDataRoamingFromRegistration = in.readBoolean(); 491 mIsIwlanPreferred = in.readBoolean(); 492 } 493 writeToParcel(Parcel out, int flags)494 public void writeToParcel(Parcel out, int flags) { 495 out.writeInt(mVoiceRegState); 496 out.writeInt(mDataRegState); 497 out.writeString(mOperatorAlphaLong); 498 out.writeString(mOperatorAlphaShort); 499 out.writeString(mOperatorNumeric); 500 out.writeInt(mIsManualNetworkSelection ? 1 : 0); 501 out.writeInt(mCssIndicator ? 1 : 0); 502 out.writeInt(mNetworkId); 503 out.writeInt(mSystemId); 504 out.writeInt(mCdmaRoamingIndicator); 505 out.writeInt(mCdmaDefaultRoamingIndicator); 506 out.writeInt(mCdmaEriIconIndex); 507 out.writeInt(mCdmaEriIconMode); 508 out.writeInt(mIsEmergencyOnly ? 1 : 0); 509 out.writeInt(mArfcnRsrpBoost); 510 synchronized (mNetworkRegistrationInfos) { 511 out.writeList(mNetworkRegistrationInfos); 512 } 513 out.writeInt(mChannelNumber); 514 out.writeIntArray(mCellBandwidths); 515 out.writeInt(mNrFrequencyRange); 516 out.writeString(mOperatorAlphaLongRaw); 517 out.writeString(mOperatorAlphaShortRaw); 518 out.writeBoolean(mIsDataRoamingFromRegistration); 519 out.writeBoolean(mIsIwlanPreferred); 520 } 521 describeContents()522 public int describeContents() { 523 return 0; 524 } 525 526 public static final @android.annotation.NonNull Parcelable.Creator<ServiceState> CREATOR = 527 new Parcelable.Creator<ServiceState>() { 528 public ServiceState createFromParcel(Parcel in) { 529 return new ServiceState(in); 530 } 531 532 public ServiceState[] newArray(int size) { 533 return new ServiceState[size]; 534 } 535 }; 536 537 /** 538 * Get current voice service state 539 */ getState()540 public int getState() { 541 return getVoiceRegState(); 542 } 543 544 /** 545 * Get current voice service state 546 * 547 * @see #STATE_IN_SERVICE 548 * @see #STATE_OUT_OF_SERVICE 549 * @see #STATE_EMERGENCY_ONLY 550 * @see #STATE_POWER_OFF 551 * 552 * @hide 553 */ 554 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getVoiceRegState()555 public int getVoiceRegState() { 556 return mVoiceRegState; 557 } 558 559 /** 560 * Get current data registration state. 561 * 562 * @see #STATE_IN_SERVICE 563 * @see #STATE_OUT_OF_SERVICE 564 * @see #STATE_EMERGENCY_ONLY 565 * @see #STATE_POWER_OFF 566 * 567 * @return current data registration state 568 * 569 * @hide 570 */ 571 @UnsupportedAppUsage 572 @TestApi getDataRegState()573 public int getDataRegState() { 574 return mDataRegState; 575 } 576 577 /** 578 * Get current data registration state. 579 * 580 * @see #STATE_IN_SERVICE 581 * @see #STATE_OUT_OF_SERVICE 582 * @see #STATE_EMERGENCY_ONLY 583 * @see #STATE_POWER_OFF 584 * 585 * @return current data registration state 586 * 587 * @hide 588 */ getDataRegistrationState()589 public @RegState int getDataRegistrationState() { 590 return getDataRegState(); 591 } 592 593 /** 594 * Get the current duplex mode 595 * 596 * @see #DUPLEX_MODE_UNKNOWN 597 * @see #DUPLEX_MODE_FDD 598 * @see #DUPLEX_MODE_TDD 599 * 600 * @return Current {@code DuplexMode} for the phone 601 */ 602 @DuplexMode getDuplexMode()603 public int getDuplexMode() { 604 // support LTE/NR duplex mode 605 if (!isPsOnlyTech(getRilDataRadioTechnology())) { 606 return DUPLEX_MODE_UNKNOWN; 607 } 608 609 int band = AccessNetworkUtils.getOperatingBandForEarfcn(mChannelNumber); 610 return AccessNetworkUtils.getDuplexModeForEutranBand(band); 611 } 612 613 /** 614 * Get the channel number of the current primary serving cell, or -1 if unknown 615 * 616 * <p>This is NRARFCN for NR, EARFCN for LTE, UARFCN for UMTS, and ARFCN for GSM. 617 * 618 * @return Channel number of primary serving cell 619 */ getChannelNumber()620 public int getChannelNumber() { 621 return mChannelNumber; 622 } 623 624 /** 625 * Get an array of cell bandwidths (kHz) for the current serving cells 626 * 627 * @return Current serving cell bandwidths 628 */ getCellBandwidths()629 public int[] getCellBandwidths() { 630 return mCellBandwidths == null ? new int[0] : mCellBandwidths; 631 } 632 633 /** 634 * Get current roaming indicator of phone. This roaming state could be overridden by the carrier 635 * config. 636 * (note: not just decoding from TS 27.007 7.2) 637 * @see TelephonyDisplayInfo#isRoaming() for visualization purpose. 638 * @return true if TS 27.007 7.2 roaming is true 639 * and ONS is different from SPN 640 * @see CarrierConfigManager#KEY_FORCE_HOME_NETWORK_BOOL 641 * @see CarrierConfigManager#KEY_GSM_ROAMING_NETWORKS_STRING_ARRAY 642 * @see CarrierConfigManager#KEY_GSM_NONROAMING_NETWORKS_STRING_ARRAY 643 * @see CarrierConfigManager#KEY_CDMA_ROAMING_NETWORKS_STRING_ARRAY 644 * @see CarrierConfigManager#KEY_CDMA_NONROAMING_NETWORKS_STRING_ARRAY 645 */ getRoaming()646 public boolean getRoaming() { 647 return getVoiceRoaming() || getDataRoaming(); 648 } 649 650 /** 651 * Get current voice network roaming status 652 * @return roaming status 653 * @hide 654 */ 655 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getVoiceRoaming()656 public boolean getVoiceRoaming() { 657 return getVoiceRoamingType() != ROAMING_TYPE_NOT_ROAMING; 658 } 659 660 /** 661 * Get current voice roaming type. This roaming type could be overridden by the carrier config. 662 * @return roaming type 663 * @hide 664 */ 665 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getVoiceRoamingType()666 public @RoamingType int getVoiceRoamingType() { 667 final NetworkRegistrationInfo regState = getNetworkRegistrationInfo( 668 NetworkRegistrationInfo.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN); 669 if (regState != null) { 670 return regState.getRoamingType(); 671 } 672 return ROAMING_TYPE_NOT_ROAMING; 673 } 674 675 /** 676 * Get whether the current data network is roaming. 677 * This value may be overwritten by resource overlay or carrier configuration. 678 * @see #getDataRoamingFromRegistration() to get the value from the network registration. 679 * @return roaming type 680 * @hide 681 */ 682 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getDataRoaming()683 public boolean getDataRoaming() { 684 return getDataRoamingType() != ROAMING_TYPE_NOT_ROAMING; 685 } 686 687 /** 688 * Set whether the data network registration state is roaming. 689 * This should only be set to the roaming value received 690 * once the data registration phase has completed. 691 * @hide 692 */ setDataRoamingFromRegistration(boolean dataRoaming)693 public void setDataRoamingFromRegistration(boolean dataRoaming) { 694 mIsDataRoamingFromRegistration = dataRoaming; 695 } 696 697 /** 698 * Get whether data network registration state is roaming. 699 * This value is set directly from the modem and will not be overwritten 700 * by resource overlay or carrier configuration. 701 * @return true if registration indicates roaming, false otherwise 702 * @hide 703 */ getDataRoamingFromRegistration()704 public boolean getDataRoamingFromRegistration() { 705 // TODO: all callers should refactor to get roaming state directly from modem 706 // this should not be exposed as a public API 707 return mIsDataRoamingFromRegistration; 708 } 709 710 /** 711 * Get current data roaming type. This roaming type could be overridden by the carrier config. 712 * @return roaming type 713 * @hide 714 */ 715 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getDataRoamingType()716 public @RoamingType int getDataRoamingType() { 717 final NetworkRegistrationInfo regState = getNetworkRegistrationInfo( 718 NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN); 719 if (regState != null) { 720 return regState.getRoamingType(); 721 } 722 return ROAMING_TYPE_NOT_ROAMING; 723 } 724 725 /** 726 * @hide 727 */ 728 @UnsupportedAppUsage isEmergencyOnly()729 public boolean isEmergencyOnly() { 730 return mIsEmergencyOnly; 731 } 732 733 /** 734 * @hide 735 */ 736 @UnsupportedAppUsage getCdmaRoamingIndicator()737 public int getCdmaRoamingIndicator(){ 738 return this.mCdmaRoamingIndicator; 739 } 740 741 /** 742 * @hide 743 */ 744 @UnsupportedAppUsage getCdmaDefaultRoamingIndicator()745 public int getCdmaDefaultRoamingIndicator(){ 746 return this.mCdmaDefaultRoamingIndicator; 747 } 748 749 /** 750 * @hide 751 */ 752 @UnsupportedAppUsage getCdmaEriIconIndex()753 public int getCdmaEriIconIndex() { 754 return this.mCdmaEriIconIndex; 755 } 756 757 /** 758 * @hide 759 */ 760 @UnsupportedAppUsage getCdmaEriIconMode()761 public int getCdmaEriIconMode() { 762 return this.mCdmaEriIconMode; 763 } 764 765 /** 766 * Get current registered operator name in long alphanumeric format. 767 * 768 * In GSM/UMTS, long format can be up to 16 characters long. 769 * In CDMA, returns the ERI text, if set. Otherwise, returns the ONS. 770 * 771 * Require at least {@link android.Manifest.permission#ACCESS_FINE_LOCATION} or 772 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. Otherwise return null if the 773 * caller does not hold neither {@link android.Manifest.permission#ACCESS_FINE_LOCATION} nor 774 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. 775 * 776 * @return long name of operator, null if unregistered or unknown 777 */ 778 @RequiresPermission(anyOf = { 779 android.Manifest.permission.ACCESS_FINE_LOCATION, 780 android.Manifest.permission.ACCESS_COARSE_LOCATION 781 }) getOperatorAlphaLong()782 public String getOperatorAlphaLong() { 783 return mOperatorAlphaLong; 784 } 785 786 /** 787 * Get current registered voice network operator name in long alphanumeric format. 788 * 789 * Require at least {@link android.Manifest.permission#ACCESS_FINE_LOCATION} or 790 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. Otherwise return null if the 791 * caller does not hold neither {@link android.Manifest.permission#ACCESS_FINE_LOCATION} nor 792 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. 793 * 794 * @return long name of operator 795 * @hide 796 */ 797 @RequiresPermission(anyOf = { 798 android.Manifest.permission.ACCESS_FINE_LOCATION, 799 android.Manifest.permission.ACCESS_COARSE_LOCATION 800 }) 801 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, 802 publicAlternatives = "Use {@link #getOperatorAlphaLong} instead.") getVoiceOperatorAlphaLong()803 public String getVoiceOperatorAlphaLong() { 804 return mOperatorAlphaLong; 805 } 806 807 /** 808 * Get current registered operator name in short alphanumeric format. 809 * 810 * In GSM/UMTS, short format can be up to 8 characters long. 811 * 812 * Require at least {@link android.Manifest.permission#ACCESS_FINE_LOCATION} or 813 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. Otherwise return null if the 814 * caller does not hold neither {@link android.Manifest.permission#ACCESS_FINE_LOCATION} nor 815 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. 816 * 817 * @return short name of operator, null if unregistered or unknown 818 */ 819 @RequiresPermission(anyOf = { 820 android.Manifest.permission.ACCESS_FINE_LOCATION, 821 android.Manifest.permission.ACCESS_COARSE_LOCATION 822 }) getOperatorAlphaShort()823 public String getOperatorAlphaShort() { 824 return mOperatorAlphaShort; 825 } 826 827 /** 828 * Get current registered voice network operator name in short alphanumeric format. 829 * 830 * Require at least {@link android.Manifest.permission#ACCESS_FINE_LOCATION} or 831 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. Otherwise return null if the 832 * caller does not have neither {@link android.Manifest.permission#ACCESS_FINE_LOCATION} nor 833 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. 834 * 835 * @return short name of operator, null if unregistered or unknown 836 * @hide 837 */ 838 @RequiresPermission(anyOf = { 839 android.Manifest.permission.ACCESS_FINE_LOCATION, 840 android.Manifest.permission.ACCESS_COARSE_LOCATION 841 }) 842 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, 843 publicAlternatives = "Use {@link #getOperatorAlphaShort} instead.") getVoiceOperatorAlphaShort()844 public String getVoiceOperatorAlphaShort() { 845 return mOperatorAlphaShort; 846 } 847 848 /** 849 * Get current registered data network operator name in short alphanumeric format. 850 * 851 * Require at least {@link android.Manifest.permission#ACCESS_FINE_LOCATION} or 852 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. Otherwise return null if the 853 * caller does not have neither {@link android.Manifest.permission#ACCESS_FINE_LOCATION} nor 854 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. 855 * 856 * @return short name of operator, null if unregistered or unknown 857 * @hide 858 */ 859 @RequiresPermission(anyOf = { 860 android.Manifest.permission.ACCESS_FINE_LOCATION, 861 android.Manifest.permission.ACCESS_COARSE_LOCATION 862 }) 863 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, 864 publicAlternatives = "Use {@link #getOperatorAlphaShort} instead.") getDataOperatorAlphaShort()865 public String getDataOperatorAlphaShort() { 866 return mOperatorAlphaShort; 867 } 868 869 /** 870 * Get current registered operator name in long alphanumeric format if 871 * available or short otherwise. 872 * 873 * Require at least {@link android.Manifest.permission#ACCESS_FINE_LOCATION} or 874 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. Otherwise return null if the 875 * caller does not hold neither {@link android.Manifest.permission#ACCESS_FINE_LOCATION} nor 876 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. 877 * 878 * @see #getOperatorAlphaLong 879 * @see #getOperatorAlphaShort 880 * 881 * @return name of operator, null if unregistered or unknown 882 * @hide 883 */ 884 @RequiresPermission(anyOf = { 885 android.Manifest.permission.ACCESS_FINE_LOCATION, 886 android.Manifest.permission.ACCESS_COARSE_LOCATION 887 }) getOperatorAlpha()888 public String getOperatorAlpha() { 889 if (TextUtils.isEmpty(mOperatorAlphaLong)) { 890 return mOperatorAlphaShort; 891 } 892 893 return mOperatorAlphaLong; 894 } 895 896 /** 897 * Get current registered operator numeric id. 898 * 899 * In GSM/UMTS, numeric format is 3 digit country code plus 2 or 3 digit 900 * network code. 901 * 902 * Require at least {@link android.Manifest.permission#ACCESS_FINE_LOCATION} or 903 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. Otherwise return null if the 904 * caller does not hold neither {@link android.Manifest.permission#ACCESS_FINE_LOCATION} nor 905 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. 906 * 907 * @return numeric format of operator, null if unregistered or unknown 908 */ 909 /* 910 * The country code can be decoded using 911 * {@link com.android.internal.telephony.MccTable#countryCodeForMcc(int)}. 912 */ 913 @RequiresPermission(anyOf = { 914 android.Manifest.permission.ACCESS_FINE_LOCATION, 915 android.Manifest.permission.ACCESS_COARSE_LOCATION 916 }) getOperatorNumeric()917 public String getOperatorNumeric() { 918 return mOperatorNumeric; 919 } 920 921 /** 922 * Get current registered voice network operator numeric id. 923 * 924 * Require at least {@link android.Manifest.permission#ACCESS_FINE_LOCATION} or 925 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. Otherwise return null if the 926 * caller does not hold neither {@link android.Manifest.permission#ACCESS_FINE_LOCATION} nor 927 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. 928 * 929 * @return numeric format of operator, null if unregistered or unknown 930 * @hide 931 */ 932 @RequiresPermission(anyOf = { 933 android.Manifest.permission.ACCESS_FINE_LOCATION, 934 android.Manifest.permission.ACCESS_COARSE_LOCATION 935 }) 936 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getVoiceOperatorNumeric()937 public String getVoiceOperatorNumeric() { 938 return mOperatorNumeric; 939 } 940 941 /** 942 * Get current registered data network operator numeric id. 943 * 944 * Require at least {@link android.Manifest.permission#ACCESS_FINE_LOCATION} or 945 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. Otherwise return null if the 946 * caller does not hold neither {@link android.Manifest.permission#ACCESS_FINE_LOCATION} nor 947 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. 948 * 949 * @return numeric format of operator, null if unregistered or unknown 950 * @hide 951 */ 952 @RequiresPermission(anyOf = { 953 android.Manifest.permission.ACCESS_FINE_LOCATION, 954 android.Manifest.permission.ACCESS_COARSE_LOCATION 955 }) 956 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, 957 publicAlternatives = "Use {@link #getOperatorNumeric} instead.") getDataOperatorNumeric()958 public String getDataOperatorNumeric() { 959 return mOperatorNumeric; 960 } 961 962 /** 963 * Get current network selection mode. 964 * 965 * @return true if manual mode, false if automatic mode 966 */ getIsManualSelection()967 public boolean getIsManualSelection() { 968 return mIsManualNetworkSelection; 969 } 970 971 @Override hashCode()972 public int hashCode() { 973 synchronized (mNetworkRegistrationInfos) { 974 return Objects.hash( 975 mVoiceRegState, 976 mDataRegState, 977 mChannelNumber, 978 Arrays.hashCode(mCellBandwidths), 979 mOperatorAlphaLong, 980 mOperatorAlphaShort, 981 mOperatorNumeric, 982 mIsManualNetworkSelection, 983 mCssIndicator, 984 mNetworkId, 985 mSystemId, 986 mCdmaRoamingIndicator, 987 mCdmaDefaultRoamingIndicator, 988 mCdmaEriIconIndex, 989 mCdmaEriIconMode, 990 mIsEmergencyOnly, 991 mArfcnRsrpBoost, 992 mNetworkRegistrationInfos, 993 mNrFrequencyRange, 994 mOperatorAlphaLongRaw, 995 mOperatorAlphaShortRaw, 996 mIsDataRoamingFromRegistration, 997 mIsIwlanPreferred); 998 } 999 } 1000 1001 @Override equals(Object o)1002 public boolean equals (Object o) { 1003 if (!(o instanceof ServiceState)) return false; 1004 ServiceState s = (ServiceState) o; 1005 1006 synchronized (mNetworkRegistrationInfos) { 1007 return mVoiceRegState == s.mVoiceRegState 1008 && mDataRegState == s.mDataRegState 1009 && mIsManualNetworkSelection == s.mIsManualNetworkSelection 1010 && mChannelNumber == s.mChannelNumber 1011 && Arrays.equals(mCellBandwidths, s.mCellBandwidths) 1012 && equalsHandlesNulls(mOperatorAlphaLong, s.mOperatorAlphaLong) 1013 && equalsHandlesNulls(mOperatorAlphaShort, s.mOperatorAlphaShort) 1014 && equalsHandlesNulls(mOperatorNumeric, s.mOperatorNumeric) 1015 && equalsHandlesNulls(mCssIndicator, s.mCssIndicator) 1016 && equalsHandlesNulls(mNetworkId, s.mNetworkId) 1017 && equalsHandlesNulls(mSystemId, s.mSystemId) 1018 && equalsHandlesNulls(mCdmaRoamingIndicator, s.mCdmaRoamingIndicator) 1019 && equalsHandlesNulls(mCdmaDefaultRoamingIndicator, 1020 s.mCdmaDefaultRoamingIndicator) 1021 && mIsEmergencyOnly == s.mIsEmergencyOnly 1022 && equalsHandlesNulls(mOperatorAlphaLongRaw, s.mOperatorAlphaLongRaw) 1023 && equalsHandlesNulls(mOperatorAlphaShortRaw, s.mOperatorAlphaShortRaw) 1024 && mNetworkRegistrationInfos.size() == s.mNetworkRegistrationInfos.size() 1025 && mNetworkRegistrationInfos.containsAll(s.mNetworkRegistrationInfos) 1026 && mNrFrequencyRange == s.mNrFrequencyRange 1027 && mIsDataRoamingFromRegistration == s.mIsDataRoamingFromRegistration 1028 && mIsIwlanPreferred == s.mIsIwlanPreferred; 1029 } 1030 } 1031 1032 /** 1033 * Convert roaming type to string 1034 * 1035 * @param roamingType roaming type 1036 * @return The roaming type in string format 1037 * 1038 * @hide 1039 */ roamingTypeToString(@oamingType int roamingType)1040 public static String roamingTypeToString(@RoamingType int roamingType) { 1041 switch (roamingType) { 1042 case ROAMING_TYPE_NOT_ROAMING: return "NOT_ROAMING"; 1043 case ROAMING_TYPE_UNKNOWN: return "UNKNOWN"; 1044 case ROAMING_TYPE_DOMESTIC: return "DOMESTIC"; 1045 case ROAMING_TYPE_INTERNATIONAL: return "INTERNATIONAL"; 1046 } 1047 return "Unknown roaming type " + roamingType; 1048 } 1049 1050 /** 1051 * Convert radio technology to String 1052 * 1053 * @param rt radioTechnology 1054 * @return String representation of the RAT 1055 * 1056 * @hide 1057 */ 1058 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) rilRadioTechnologyToString(int rt)1059 public static String rilRadioTechnologyToString(int rt) { 1060 String rtString; 1061 1062 switch(rt) { 1063 case RIL_RADIO_TECHNOLOGY_UNKNOWN: 1064 rtString = "Unknown"; 1065 break; 1066 case RIL_RADIO_TECHNOLOGY_GPRS: 1067 rtString = "GPRS"; 1068 break; 1069 case RIL_RADIO_TECHNOLOGY_EDGE: 1070 rtString = "EDGE"; 1071 break; 1072 case RIL_RADIO_TECHNOLOGY_UMTS: 1073 rtString = "UMTS"; 1074 break; 1075 case RIL_RADIO_TECHNOLOGY_IS95A: 1076 rtString = "CDMA-IS95A"; 1077 break; 1078 case RIL_RADIO_TECHNOLOGY_IS95B: 1079 rtString = "CDMA-IS95B"; 1080 break; 1081 case RIL_RADIO_TECHNOLOGY_1xRTT: 1082 rtString = "1xRTT"; 1083 break; 1084 case RIL_RADIO_TECHNOLOGY_EVDO_0: 1085 rtString = "EvDo-rev.0"; 1086 break; 1087 case RIL_RADIO_TECHNOLOGY_EVDO_A: 1088 rtString = "EvDo-rev.A"; 1089 break; 1090 case RIL_RADIO_TECHNOLOGY_HSDPA: 1091 rtString = "HSDPA"; 1092 break; 1093 case RIL_RADIO_TECHNOLOGY_HSUPA: 1094 rtString = "HSUPA"; 1095 break; 1096 case RIL_RADIO_TECHNOLOGY_HSPA: 1097 rtString = "HSPA"; 1098 break; 1099 case RIL_RADIO_TECHNOLOGY_EVDO_B: 1100 rtString = "EvDo-rev.B"; 1101 break; 1102 case RIL_RADIO_TECHNOLOGY_EHRPD: 1103 rtString = "eHRPD"; 1104 break; 1105 case RIL_RADIO_TECHNOLOGY_LTE: 1106 rtString = "LTE"; 1107 break; 1108 case RIL_RADIO_TECHNOLOGY_HSPAP: 1109 rtString = "HSPAP"; 1110 break; 1111 case RIL_RADIO_TECHNOLOGY_GSM: 1112 rtString = "GSM"; 1113 break; 1114 case RIL_RADIO_TECHNOLOGY_IWLAN: 1115 rtString = "IWLAN"; 1116 break; 1117 case RIL_RADIO_TECHNOLOGY_TD_SCDMA: 1118 rtString = "TD-SCDMA"; 1119 break; 1120 case RIL_RADIO_TECHNOLOGY_LTE_CA: 1121 rtString = "LTE_CA"; 1122 break; 1123 case RIL_RADIO_TECHNOLOGY_NR: 1124 rtString = "NR_SA"; 1125 break; 1126 default: 1127 rtString = "Unexpected"; 1128 Rlog.w(LOG_TAG, "Unexpected radioTechnology=" + rt); 1129 break; 1130 } 1131 return rtString; 1132 } 1133 1134 /** 1135 * Convert frequency range into string 1136 * 1137 * @param range The cellular frequency range 1138 * @return Frequency range in string format 1139 * 1140 * @hide 1141 */ 1142 @android.ravenwood.annotation.RavenwoodKeep frequencyRangeToString(@requencyRange int range)1143 public static @NonNull String frequencyRangeToString(@FrequencyRange int range) { 1144 switch (range) { 1145 case FREQUENCY_RANGE_UNKNOWN: return "UNKNOWN"; 1146 case FREQUENCY_RANGE_LOW: return "LOW"; 1147 case FREQUENCY_RANGE_MID: return "MID"; 1148 case FREQUENCY_RANGE_HIGH: return "HIGH"; 1149 case FREQUENCY_RANGE_MMWAVE: return "MMWAVE"; 1150 default: 1151 return Integer.toString(range); 1152 } 1153 } 1154 1155 /** 1156 * Convert RIL Service State to String 1157 * 1158 * @param serviceState 1159 * @return String representation of the ServiceState 1160 * 1161 * @hide 1162 */ rilServiceStateToString(int serviceState)1163 public static String rilServiceStateToString(int serviceState) { 1164 switch(serviceState) { 1165 case STATE_IN_SERVICE: 1166 return "IN_SERVICE"; 1167 case STATE_OUT_OF_SERVICE: 1168 return "OUT_OF_SERVICE"; 1169 case STATE_EMERGENCY_ONLY: 1170 return "EMERGENCY_ONLY"; 1171 case STATE_POWER_OFF: 1172 return "POWER_OFF"; 1173 default: 1174 return "UNKNOWN"; 1175 } 1176 } 1177 1178 @Override toString()1179 public String toString() { 1180 synchronized (mNetworkRegistrationInfos) { 1181 return new StringBuilder().append("{mVoiceRegState=").append(mVoiceRegState) 1182 .append("(" + rilServiceStateToString(mVoiceRegState) + ")") 1183 .append(", mDataRegState=").append(mDataRegState) 1184 .append("(" + rilServiceStateToString(mDataRegState) + ")") 1185 .append(", mChannelNumber=").append(mChannelNumber) 1186 .append(", duplexMode()=").append(getDuplexMode()) 1187 .append(", mCellBandwidths=").append(Arrays.toString(mCellBandwidths)) 1188 .append(", mOperatorAlphaLong=").append(mOperatorAlphaLong) 1189 .append(", mOperatorAlphaShort=").append(mOperatorAlphaShort) 1190 .append(", isManualNetworkSelection=").append(mIsManualNetworkSelection) 1191 .append(mIsManualNetworkSelection ? "(manual)" : "(automatic)") 1192 .append(", getRilVoiceRadioTechnology=").append(getRilVoiceRadioTechnology()) 1193 .append("(" + rilRadioTechnologyToString(getRilVoiceRadioTechnology()) + ")") 1194 .append(", getRilDataRadioTechnology=").append(getRilDataRadioTechnology()) 1195 .append("(" + rilRadioTechnologyToString(getRilDataRadioTechnology()) + ")") 1196 .append(", mCssIndicator=").append(mCssIndicator ? "supported" : "unsupported") 1197 .append(", mNetworkId=").append(mNetworkId) 1198 .append(", mSystemId=").append(mSystemId) 1199 .append(", mCdmaRoamingIndicator=").append(mCdmaRoamingIndicator) 1200 .append(", mCdmaDefaultRoamingIndicator=").append(mCdmaDefaultRoamingIndicator) 1201 .append(", mIsEmergencyOnly=").append(mIsEmergencyOnly) 1202 .append(", isUsingCarrierAggregation=").append(isUsingCarrierAggregation()) 1203 .append(", mArfcnRsrpBoost=").append(mArfcnRsrpBoost) 1204 .append(", mNetworkRegistrationInfos=").append(mNetworkRegistrationInfos) 1205 .append(", mNrFrequencyRange=").append(Build.IS_DEBUGGABLE 1206 ? mNrFrequencyRange : FREQUENCY_RANGE_UNKNOWN) 1207 .append(", mOperatorAlphaLongRaw=").append(mOperatorAlphaLongRaw) 1208 .append(", mOperatorAlphaShortRaw=").append(mOperatorAlphaShortRaw) 1209 .append(", mIsDataRoamingFromRegistration=") 1210 .append(mIsDataRoamingFromRegistration) 1211 .append(", mIsIwlanPreferred=").append(mIsIwlanPreferred) 1212 .append(", mIsUsingNonTerrestrialNetwork=") 1213 .append(isUsingNonTerrestrialNetwork()) 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 */ isUsingNonTerrestrialNetwork()2263 public boolean isUsingNonTerrestrialNetwork() { 2264 synchronized (mNetworkRegistrationInfos) { 2265 for (NetworkRegistrationInfo nri : mNetworkRegistrationInfos) { 2266 if (nri.isNonTerrestrialNetwork()) return true; 2267 } 2268 } 2269 return false; 2270 } 2271 } 2272