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