1 /* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.telephony; 18 19 import android.annotation.IntDef; 20 import android.annotation.NonNull; 21 import android.annotation.Nullable; 22 import android.annotation.RequiresPermission; 23 import android.annotation.SystemApi; 24 import android.annotation.TestApi; 25 import android.compat.annotation.UnsupportedAppUsage; 26 import android.content.Intent; 27 import android.os.Build; 28 import android.os.Bundle; 29 import android.os.Parcel; 30 import android.os.Parcelable; 31 import android.telephony.AccessNetworkConstants.AccessNetworkType; 32 import android.telephony.AccessNetworkConstants.TransportType; 33 import android.telephony.Annotation.NetworkType; 34 import android.telephony.NetworkRegistrationInfo.Domain; 35 import android.telephony.NetworkRegistrationInfo.NRState; 36 import android.text.TextUtils; 37 38 import com.android.telephony.Rlog; 39 40 import java.lang.annotation.Retention; 41 import java.lang.annotation.RetentionPolicy; 42 import java.util.ArrayList; 43 import java.util.Arrays; 44 import java.util.List; 45 import java.util.Objects; 46 import java.util.stream.Collectors; 47 48 /** 49 * Contains phone state and service related information. 50 * 51 * The following phone information is included in returned ServiceState: 52 * 53 * <ul> 54 * <li>Service state: IN_SERVICE, OUT_OF_SERVICE, EMERGENCY_ONLY, POWER_OFF 55 * <li>Duplex mode: UNKNOWN, FDD, TDD 56 * <li>Roaming indicator 57 * <li>Operator name, short name and numeric id 58 * <li>Network selection mode 59 * </ul> 60 * 61 * For historical reasons this class is not declared as final; however, 62 * it should be treated as though it were final. 63 */ 64 public class ServiceState implements Parcelable { 65 66 static final String LOG_TAG = "PHONE"; 67 static final boolean DBG = false; 68 static final boolean VDBG = false; // STOPSHIP if true 69 70 /** @hide */ 71 @Retention(RetentionPolicy.SOURCE) 72 @IntDef(prefix = "STATE_", 73 value = {STATE_IN_SERVICE, STATE_OUT_OF_SERVICE, STATE_EMERGENCY_ONLY, 74 STATE_POWER_OFF}) 75 public @interface RegState {} 76 77 /** 78 * Normal operation condition, the phone is registered 79 * with an operator either in home network or in roaming. 80 */ 81 public static final int STATE_IN_SERVICE = TelephonyProtoEnums.SERVICE_STATE_IN_SERVICE; // 0 82 83 /** 84 * Phone is not registered with any operator, the phone 85 * can be currently searching a new operator to register to, or not 86 * searching to registration at all, or registration is denied, or radio 87 * signal is not available. 88 */ 89 public static final int STATE_OUT_OF_SERVICE = 90 TelephonyProtoEnums.SERVICE_STATE_OUT_OF_SERVICE; // 1 91 92 /** 93 * The phone is registered and locked. Only emergency numbers are allowed. {@more} 94 */ 95 //TODO: This state is not used anymore. It should be deprecated in a future release. 96 public static final int STATE_EMERGENCY_ONLY = 97 TelephonyProtoEnums.SERVICE_STATE_EMERGENCY_ONLY; // 2 98 99 /** 100 * Radio of telephony is explicitly powered off. 101 */ 102 public static final int STATE_POWER_OFF = TelephonyProtoEnums.SERVICE_STATE_POWER_OFF; // 3 103 104 /** @hide */ 105 @Retention(RetentionPolicy.SOURCE) 106 @IntDef(prefix = "FREQUENCY_RANGE_", 107 value = {FREQUENCY_RANGE_UNKNOWN, FREQUENCY_RANGE_LOW, FREQUENCY_RANGE_MID, 108 FREQUENCY_RANGE_HIGH, FREQUENCY_RANGE_MMWAVE}) 109 public @interface FrequencyRange {} 110 111 /** 112 * Indicates frequency range is unknown. 113 * @hide 114 */ 115 public static final int FREQUENCY_RANGE_UNKNOWN = 0; 116 117 /** 118 * Indicates the frequency range is below 1GHz. 119 * @hide 120 */ 121 public static final int FREQUENCY_RANGE_LOW = 1; 122 123 /** 124 * Indicates the frequency range is between 1GHz to 3GHz. 125 * @hide 126 */ 127 public static final int FREQUENCY_RANGE_MID = 2; 128 129 /** 130 * Indicates the frequency range is between 3GHz and 6GHz. 131 * @hide 132 */ 133 public static final int FREQUENCY_RANGE_HIGH = 3; 134 135 /** 136 * Indicates the frequency range is above 6GHz (millimeter wave frequency). 137 * @hide 138 */ 139 public static final int FREQUENCY_RANGE_MMWAVE = 4; 140 141 private static final List<Integer> FREQUENCY_RANGE_ORDER = Arrays.asList( 142 FREQUENCY_RANGE_UNKNOWN, 143 FREQUENCY_RANGE_LOW, 144 FREQUENCY_RANGE_MID, 145 FREQUENCY_RANGE_HIGH, 146 FREQUENCY_RANGE_MMWAVE); 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 635 * (note: not just decoding from TS 27.007 7.2) 636 * 637 * @return true if TS 27.007 7.2 roaming is true 638 * and ONS is different from SPN 639 */ getRoaming()640 public boolean getRoaming() { 641 return getVoiceRoaming() || getDataRoaming(); 642 } 643 644 /** 645 * Get current voice network roaming status 646 * @return roaming status 647 * @hide 648 */ 649 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getVoiceRoaming()650 public boolean getVoiceRoaming() { 651 return getVoiceRoamingType() != ROAMING_TYPE_NOT_ROAMING; 652 } 653 /** 654 * Get current voice network roaming type 655 * @return roaming type 656 * @hide 657 */ 658 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getVoiceRoamingType()659 public @RoamingType int getVoiceRoamingType() { 660 final NetworkRegistrationInfo regState = getNetworkRegistrationInfo( 661 NetworkRegistrationInfo.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN); 662 if (regState != null) { 663 return regState.getRoamingType(); 664 } 665 return ROAMING_TYPE_NOT_ROAMING; 666 } 667 668 /** 669 * Get whether the current data network is roaming. 670 * This value may be overwritten by resource overlay or carrier configuration. 671 * @see #getDataRoamingFromRegistration() to get the value from the network registration. 672 * @return roaming type 673 * @hide 674 */ 675 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getDataRoaming()676 public boolean getDataRoaming() { 677 return getDataRoamingType() != ROAMING_TYPE_NOT_ROAMING; 678 } 679 680 /** 681 * Set whether the data network registration state is roaming. 682 * This should only be set to the roaming value received 683 * once the data registration phase has completed. 684 * @hide 685 */ setDataRoamingFromRegistration(boolean dataRoaming)686 public void setDataRoamingFromRegistration(boolean dataRoaming) { 687 mIsDataRoamingFromRegistration = dataRoaming; 688 } 689 690 /** 691 * Get whether data network registration state is roaming. 692 * This value is set directly from the modem and will not be overwritten 693 * by resource overlay or carrier configuration. 694 * @return true if registration indicates roaming, false otherwise 695 * @hide 696 */ getDataRoamingFromRegistration()697 public boolean getDataRoamingFromRegistration() { 698 // TODO: all callers should refactor to get roaming state directly from modem 699 // this should not be exposed as a public API 700 return mIsDataRoamingFromRegistration; 701 } 702 703 /** 704 * Get current data network roaming type 705 * @return roaming type 706 * @hide 707 */ 708 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getDataRoamingType()709 public @RoamingType int getDataRoamingType() { 710 final NetworkRegistrationInfo regState = getNetworkRegistrationInfo( 711 NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN); 712 if (regState != null) { 713 return regState.getRoamingType(); 714 } 715 return ROAMING_TYPE_NOT_ROAMING; 716 } 717 718 /** 719 * @hide 720 */ 721 @UnsupportedAppUsage isEmergencyOnly()722 public boolean isEmergencyOnly() { 723 return mIsEmergencyOnly; 724 } 725 726 /** 727 * @hide 728 */ 729 @UnsupportedAppUsage getCdmaRoamingIndicator()730 public int getCdmaRoamingIndicator(){ 731 return this.mCdmaRoamingIndicator; 732 } 733 734 /** 735 * @hide 736 */ 737 @UnsupportedAppUsage getCdmaDefaultRoamingIndicator()738 public int getCdmaDefaultRoamingIndicator(){ 739 return this.mCdmaDefaultRoamingIndicator; 740 } 741 742 /** 743 * @hide 744 */ 745 @UnsupportedAppUsage getCdmaEriIconIndex()746 public int getCdmaEriIconIndex() { 747 return this.mCdmaEriIconIndex; 748 } 749 750 /** 751 * @hide 752 */ 753 @UnsupportedAppUsage getCdmaEriIconMode()754 public int getCdmaEriIconMode() { 755 return this.mCdmaEriIconMode; 756 } 757 758 /** 759 * Get current registered operator name in long alphanumeric format. 760 * 761 * In GSM/UMTS, long format can be up to 16 characters long. 762 * In CDMA, returns the ERI text, if set. Otherwise, returns the ONS. 763 * 764 * Require at least {@link android.Manifest.permission#ACCESS_FINE_LOCATION} or 765 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. Otherwise return null if the 766 * caller does not hold neither {@link android.Manifest.permission#ACCESS_FINE_LOCATION} nor 767 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. 768 * 769 * @return long name of operator, null if unregistered or unknown 770 */ 771 @RequiresPermission(anyOf = { 772 android.Manifest.permission.ACCESS_FINE_LOCATION, 773 android.Manifest.permission.ACCESS_COARSE_LOCATION 774 }) getOperatorAlphaLong()775 public String getOperatorAlphaLong() { 776 return mOperatorAlphaLong; 777 } 778 779 /** 780 * Get current registered voice network operator name in long alphanumeric format. 781 * 782 * Require at least {@link android.Manifest.permission#ACCESS_FINE_LOCATION} or 783 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. Otherwise return null if the 784 * caller does not hold neither {@link android.Manifest.permission#ACCESS_FINE_LOCATION} nor 785 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. 786 * 787 * @return long name of operator 788 * @hide 789 */ 790 @RequiresPermission(anyOf = { 791 android.Manifest.permission.ACCESS_FINE_LOCATION, 792 android.Manifest.permission.ACCESS_COARSE_LOCATION 793 }) 794 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, 795 publicAlternatives = "Use {@link #getOperatorAlphaLong} instead.") getVoiceOperatorAlphaLong()796 public String getVoiceOperatorAlphaLong() { 797 return mOperatorAlphaLong; 798 } 799 800 /** 801 * Get current registered operator name in short alphanumeric format. 802 * 803 * In GSM/UMTS, short format can be up to 8 characters long. 804 * 805 * Require at least {@link android.Manifest.permission#ACCESS_FINE_LOCATION} or 806 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. Otherwise return null if the 807 * caller does not hold neither {@link android.Manifest.permission#ACCESS_FINE_LOCATION} nor 808 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. 809 * 810 * @return short name of operator, null if unregistered or unknown 811 */ 812 @RequiresPermission(anyOf = { 813 android.Manifest.permission.ACCESS_FINE_LOCATION, 814 android.Manifest.permission.ACCESS_COARSE_LOCATION 815 }) getOperatorAlphaShort()816 public String getOperatorAlphaShort() { 817 return mOperatorAlphaShort; 818 } 819 820 /** 821 * Get current registered voice network operator name in short alphanumeric format. 822 * 823 * Require at least {@link android.Manifest.permission#ACCESS_FINE_LOCATION} or 824 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. Otherwise return null if the 825 * caller does not have neither {@link android.Manifest.permission#ACCESS_FINE_LOCATION} nor 826 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. 827 * 828 * @return short name of operator, null if unregistered or unknown 829 * @hide 830 */ 831 @RequiresPermission(anyOf = { 832 android.Manifest.permission.ACCESS_FINE_LOCATION, 833 android.Manifest.permission.ACCESS_COARSE_LOCATION 834 }) 835 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, 836 publicAlternatives = "Use {@link #getOperatorAlphaShort} instead.") getVoiceOperatorAlphaShort()837 public String getVoiceOperatorAlphaShort() { 838 return mOperatorAlphaShort; 839 } 840 841 /** 842 * Get current registered data network operator name in short alphanumeric format. 843 * 844 * Require at least {@link android.Manifest.permission#ACCESS_FINE_LOCATION} or 845 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. Otherwise return null if the 846 * caller does not have neither {@link android.Manifest.permission#ACCESS_FINE_LOCATION} nor 847 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. 848 * 849 * @return short name of operator, null if unregistered or unknown 850 * @hide 851 */ 852 @RequiresPermission(anyOf = { 853 android.Manifest.permission.ACCESS_FINE_LOCATION, 854 android.Manifest.permission.ACCESS_COARSE_LOCATION 855 }) 856 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, 857 publicAlternatives = "Use {@link #getOperatorAlphaShort} instead.") getDataOperatorAlphaShort()858 public String getDataOperatorAlphaShort() { 859 return mOperatorAlphaShort; 860 } 861 862 /** 863 * Get current registered operator name in long alphanumeric format if 864 * available or short otherwise. 865 * 866 * Require at least {@link android.Manifest.permission#ACCESS_FINE_LOCATION} or 867 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. Otherwise return null if the 868 * caller does not hold neither {@link android.Manifest.permission#ACCESS_FINE_LOCATION} nor 869 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. 870 * 871 * @see #getOperatorAlphaLong 872 * @see #getOperatorAlphaShort 873 * 874 * @return name of operator, null if unregistered or unknown 875 * @hide 876 */ 877 @RequiresPermission(anyOf = { 878 android.Manifest.permission.ACCESS_FINE_LOCATION, 879 android.Manifest.permission.ACCESS_COARSE_LOCATION 880 }) getOperatorAlpha()881 public String getOperatorAlpha() { 882 if (TextUtils.isEmpty(mOperatorAlphaLong)) { 883 return mOperatorAlphaShort; 884 } 885 886 return mOperatorAlphaLong; 887 } 888 889 /** 890 * Get current registered operator numeric id. 891 * 892 * In GSM/UMTS, numeric format is 3 digit country code plus 2 or 3 digit 893 * network code. 894 * 895 * Require at least {@link android.Manifest.permission#ACCESS_FINE_LOCATION} or 896 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. Otherwise return null if the 897 * caller does not hold neither {@link android.Manifest.permission#ACCESS_FINE_LOCATION} nor 898 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. 899 * 900 * @return numeric format of operator, null if unregistered or unknown 901 */ 902 /* 903 * The country code can be decoded using 904 * {@link com.android.internal.telephony.MccTable#countryCodeForMcc(int)}. 905 */ 906 @RequiresPermission(anyOf = { 907 android.Manifest.permission.ACCESS_FINE_LOCATION, 908 android.Manifest.permission.ACCESS_COARSE_LOCATION 909 }) getOperatorNumeric()910 public String getOperatorNumeric() { 911 return mOperatorNumeric; 912 } 913 914 /** 915 * Get current registered voice network operator numeric id. 916 * 917 * Require at least {@link android.Manifest.permission#ACCESS_FINE_LOCATION} or 918 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. Otherwise return null if the 919 * caller does not hold neither {@link android.Manifest.permission#ACCESS_FINE_LOCATION} nor 920 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. 921 * 922 * @return numeric format of operator, null if unregistered or unknown 923 * @hide 924 */ 925 @RequiresPermission(anyOf = { 926 android.Manifest.permission.ACCESS_FINE_LOCATION, 927 android.Manifest.permission.ACCESS_COARSE_LOCATION 928 }) 929 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getVoiceOperatorNumeric()930 public String getVoiceOperatorNumeric() { 931 return mOperatorNumeric; 932 } 933 934 /** 935 * Get current registered data network operator numeric id. 936 * 937 * Require at least {@link android.Manifest.permission#ACCESS_FINE_LOCATION} or 938 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. Otherwise return null if the 939 * caller does not hold neither {@link android.Manifest.permission#ACCESS_FINE_LOCATION} nor 940 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. 941 * 942 * @return numeric format of operator, null if unregistered or unknown 943 * @hide 944 */ 945 @RequiresPermission(anyOf = { 946 android.Manifest.permission.ACCESS_FINE_LOCATION, 947 android.Manifest.permission.ACCESS_COARSE_LOCATION 948 }) 949 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, 950 publicAlternatives = "Use {@link #getOperatorNumeric} instead.") getDataOperatorNumeric()951 public String getDataOperatorNumeric() { 952 return mOperatorNumeric; 953 } 954 955 /** 956 * Get current network selection mode. 957 * 958 * @return true if manual mode, false if automatic mode 959 */ getIsManualSelection()960 public boolean getIsManualSelection() { 961 return mIsManualNetworkSelection; 962 } 963 964 @Override hashCode()965 public int hashCode() { 966 synchronized (mNetworkRegistrationInfos) { 967 return Objects.hash( 968 mVoiceRegState, 969 mDataRegState, 970 mChannelNumber, 971 Arrays.hashCode(mCellBandwidths), 972 mOperatorAlphaLong, 973 mOperatorAlphaShort, 974 mOperatorNumeric, 975 mIsManualNetworkSelection, 976 mCssIndicator, 977 mNetworkId, 978 mSystemId, 979 mCdmaRoamingIndicator, 980 mCdmaDefaultRoamingIndicator, 981 mCdmaEriIconIndex, 982 mCdmaEriIconMode, 983 mIsEmergencyOnly, 984 mArfcnRsrpBoost, 985 mNetworkRegistrationInfos, 986 mNrFrequencyRange, 987 mOperatorAlphaLongRaw, 988 mOperatorAlphaShortRaw, 989 mIsDataRoamingFromRegistration, 990 mIsIwlanPreferred); 991 } 992 } 993 994 @Override equals(Object o)995 public boolean equals (Object o) { 996 if (!(o instanceof ServiceState)) return false; 997 ServiceState s = (ServiceState) o; 998 999 synchronized (mNetworkRegistrationInfos) { 1000 return mVoiceRegState == s.mVoiceRegState 1001 && mDataRegState == s.mDataRegState 1002 && mIsManualNetworkSelection == s.mIsManualNetworkSelection 1003 && mChannelNumber == s.mChannelNumber 1004 && Arrays.equals(mCellBandwidths, s.mCellBandwidths) 1005 && equalsHandlesNulls(mOperatorAlphaLong, s.mOperatorAlphaLong) 1006 && equalsHandlesNulls(mOperatorAlphaShort, s.mOperatorAlphaShort) 1007 && equalsHandlesNulls(mOperatorNumeric, s.mOperatorNumeric) 1008 && equalsHandlesNulls(mCssIndicator, s.mCssIndicator) 1009 && equalsHandlesNulls(mNetworkId, s.mNetworkId) 1010 && equalsHandlesNulls(mSystemId, s.mSystemId) 1011 && equalsHandlesNulls(mCdmaRoamingIndicator, s.mCdmaRoamingIndicator) 1012 && equalsHandlesNulls(mCdmaDefaultRoamingIndicator, 1013 s.mCdmaDefaultRoamingIndicator) 1014 && mIsEmergencyOnly == s.mIsEmergencyOnly 1015 && equalsHandlesNulls(mOperatorAlphaLongRaw, s.mOperatorAlphaLongRaw) 1016 && equalsHandlesNulls(mOperatorAlphaShortRaw, s.mOperatorAlphaShortRaw) 1017 && mNetworkRegistrationInfos.size() == s.mNetworkRegistrationInfos.size() 1018 && mNetworkRegistrationInfos.containsAll(s.mNetworkRegistrationInfos) 1019 && mNrFrequencyRange == s.mNrFrequencyRange 1020 && mIsDataRoamingFromRegistration == s.mIsDataRoamingFromRegistration 1021 && mIsIwlanPreferred == s.mIsIwlanPreferred; 1022 } 1023 } 1024 1025 /** 1026 * Convert roaming type to string 1027 * 1028 * @param roamingType roaming type 1029 * @return The roaming type in string format 1030 * 1031 * @hide 1032 */ roamingTypeToString(@oamingType int roamingType)1033 public static String roamingTypeToString(@RoamingType int roamingType) { 1034 switch (roamingType) { 1035 case ROAMING_TYPE_NOT_ROAMING: return "NOT_ROAMING"; 1036 case ROAMING_TYPE_UNKNOWN: return "UNKNOWN"; 1037 case ROAMING_TYPE_DOMESTIC: return "DOMESTIC"; 1038 case ROAMING_TYPE_INTERNATIONAL: return "INTERNATIONAL"; 1039 } 1040 return "Unknown roaming type " + roamingType; 1041 } 1042 1043 /** 1044 * Convert radio technology to String 1045 * 1046 * @param rt radioTechnology 1047 * @return String representation of the RAT 1048 * 1049 * @hide 1050 */ 1051 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) rilRadioTechnologyToString(int rt)1052 public static String rilRadioTechnologyToString(int rt) { 1053 String rtString; 1054 1055 switch(rt) { 1056 case RIL_RADIO_TECHNOLOGY_UNKNOWN: 1057 rtString = "Unknown"; 1058 break; 1059 case RIL_RADIO_TECHNOLOGY_GPRS: 1060 rtString = "GPRS"; 1061 break; 1062 case RIL_RADIO_TECHNOLOGY_EDGE: 1063 rtString = "EDGE"; 1064 break; 1065 case RIL_RADIO_TECHNOLOGY_UMTS: 1066 rtString = "UMTS"; 1067 break; 1068 case RIL_RADIO_TECHNOLOGY_IS95A: 1069 rtString = "CDMA-IS95A"; 1070 break; 1071 case RIL_RADIO_TECHNOLOGY_IS95B: 1072 rtString = "CDMA-IS95B"; 1073 break; 1074 case RIL_RADIO_TECHNOLOGY_1xRTT: 1075 rtString = "1xRTT"; 1076 break; 1077 case RIL_RADIO_TECHNOLOGY_EVDO_0: 1078 rtString = "EvDo-rev.0"; 1079 break; 1080 case RIL_RADIO_TECHNOLOGY_EVDO_A: 1081 rtString = "EvDo-rev.A"; 1082 break; 1083 case RIL_RADIO_TECHNOLOGY_HSDPA: 1084 rtString = "HSDPA"; 1085 break; 1086 case RIL_RADIO_TECHNOLOGY_HSUPA: 1087 rtString = "HSUPA"; 1088 break; 1089 case RIL_RADIO_TECHNOLOGY_HSPA: 1090 rtString = "HSPA"; 1091 break; 1092 case RIL_RADIO_TECHNOLOGY_EVDO_B: 1093 rtString = "EvDo-rev.B"; 1094 break; 1095 case RIL_RADIO_TECHNOLOGY_EHRPD: 1096 rtString = "eHRPD"; 1097 break; 1098 case RIL_RADIO_TECHNOLOGY_LTE: 1099 rtString = "LTE"; 1100 break; 1101 case RIL_RADIO_TECHNOLOGY_HSPAP: 1102 rtString = "HSPAP"; 1103 break; 1104 case RIL_RADIO_TECHNOLOGY_GSM: 1105 rtString = "GSM"; 1106 break; 1107 case RIL_RADIO_TECHNOLOGY_IWLAN: 1108 rtString = "IWLAN"; 1109 break; 1110 case RIL_RADIO_TECHNOLOGY_TD_SCDMA: 1111 rtString = "TD-SCDMA"; 1112 break; 1113 case RIL_RADIO_TECHNOLOGY_LTE_CA: 1114 rtString = "LTE_CA"; 1115 break; 1116 case RIL_RADIO_TECHNOLOGY_NR: 1117 rtString = "NR_SA"; 1118 break; 1119 default: 1120 rtString = "Unexpected"; 1121 Rlog.w(LOG_TAG, "Unexpected radioTechnology=" + rt); 1122 break; 1123 } 1124 return rtString; 1125 } 1126 1127 /** 1128 * Convert frequency range into string 1129 * 1130 * @param range The cellular frequency range 1131 * @return Frequency range in string format 1132 * 1133 * @hide 1134 */ frequencyRangeToString(@requencyRange int range)1135 public static @NonNull String frequencyRangeToString(@FrequencyRange int range) { 1136 switch (range) { 1137 case FREQUENCY_RANGE_UNKNOWN: return "UNKNOWN"; 1138 case FREQUENCY_RANGE_LOW: return "LOW"; 1139 case FREQUENCY_RANGE_MID: return "MID"; 1140 case FREQUENCY_RANGE_HIGH: return "HIGH"; 1141 case FREQUENCY_RANGE_MMWAVE: return "MMWAVE"; 1142 default: 1143 return Integer.toString(range); 1144 } 1145 } 1146 1147 /** 1148 * Convert RIL Service State to String 1149 * 1150 * @param serviceState 1151 * @return String representation of the ServiceState 1152 * 1153 * @hide 1154 */ rilServiceStateToString(int serviceState)1155 public static String rilServiceStateToString(int serviceState) { 1156 switch(serviceState) { 1157 case STATE_IN_SERVICE: 1158 return "IN_SERVICE"; 1159 case STATE_OUT_OF_SERVICE: 1160 return "OUT_OF_SERVICE"; 1161 case STATE_EMERGENCY_ONLY: 1162 return "EMERGENCY_ONLY"; 1163 case STATE_POWER_OFF: 1164 return "POWER_OFF"; 1165 default: 1166 return "UNKNOWN"; 1167 } 1168 } 1169 1170 @Override toString()1171 public String toString() { 1172 synchronized (mNetworkRegistrationInfos) { 1173 return new StringBuilder().append("{mVoiceRegState=").append(mVoiceRegState) 1174 .append("(" + rilServiceStateToString(mVoiceRegState) + ")") 1175 .append(", mDataRegState=").append(mDataRegState) 1176 .append("(" + rilServiceStateToString(mDataRegState) + ")") 1177 .append(", mChannelNumber=").append(mChannelNumber) 1178 .append(", duplexMode()=").append(getDuplexMode()) 1179 .append(", mCellBandwidths=").append(Arrays.toString(mCellBandwidths)) 1180 .append(", mOperatorAlphaLong=").append(mOperatorAlphaLong) 1181 .append(", mOperatorAlphaShort=").append(mOperatorAlphaShort) 1182 .append(", isManualNetworkSelection=").append(mIsManualNetworkSelection) 1183 .append(mIsManualNetworkSelection ? "(manual)" : "(automatic)") 1184 .append(", getRilVoiceRadioTechnology=").append(getRilVoiceRadioTechnology()) 1185 .append("(" + rilRadioTechnologyToString(getRilVoiceRadioTechnology()) + ")") 1186 .append(", getRilDataRadioTechnology=").append(getRilDataRadioTechnology()) 1187 .append("(" + rilRadioTechnologyToString(getRilDataRadioTechnology()) + ")") 1188 .append(", mCssIndicator=").append(mCssIndicator ? "supported" : "unsupported") 1189 .append(", mNetworkId=").append(mNetworkId) 1190 .append(", mSystemId=").append(mSystemId) 1191 .append(", mCdmaRoamingIndicator=").append(mCdmaRoamingIndicator) 1192 .append(", mCdmaDefaultRoamingIndicator=").append(mCdmaDefaultRoamingIndicator) 1193 .append(", mIsEmergencyOnly=").append(mIsEmergencyOnly) 1194 .append(", isUsingCarrierAggregation=").append(isUsingCarrierAggregation()) 1195 .append(", mArfcnRsrpBoost=").append(mArfcnRsrpBoost) 1196 .append(", mNetworkRegistrationInfos=").append(mNetworkRegistrationInfos) 1197 .append(", mNrFrequencyRange=").append(Build.IS_DEBUGGABLE 1198 ? mNrFrequencyRange : FREQUENCY_RANGE_UNKNOWN) 1199 .append(", mOperatorAlphaLongRaw=").append(mOperatorAlphaLongRaw) 1200 .append(", mOperatorAlphaShortRaw=").append(mOperatorAlphaShortRaw) 1201 .append(", mIsDataRoamingFromRegistration=") 1202 .append(mIsDataRoamingFromRegistration) 1203 .append(", mIsIwlanPreferred=").append(mIsIwlanPreferred) 1204 .append("}").toString(); 1205 } 1206 } 1207 1208 /** 1209 * Initialize the service state. Set everything to the default value. 1210 * 1211 * @param legacyMode {@code true} if the device is on IWLAN legacy mode, where IWLAN is 1212 * considered as a RAT on WWAN {@link NetworkRegistrationInfo}. {@code false} if the device 1213 * is on AP-assisted mode, where IWLAN should be reported through WLAN. 1214 * {@link NetworkRegistrationInfo}. 1215 */ init(boolean legacyMode)1216 private void init(boolean legacyMode) { 1217 if (DBG) Rlog.d(LOG_TAG, "init"); 1218 mVoiceRegState = STATE_OUT_OF_SERVICE; 1219 mDataRegState = STATE_OUT_OF_SERVICE; 1220 mChannelNumber = -1; 1221 mCellBandwidths = new int[0]; 1222 mOperatorAlphaLong = null; 1223 mOperatorAlphaShort = null; 1224 mOperatorNumeric = null; 1225 mIsManualNetworkSelection = false; 1226 mCssIndicator = false; 1227 mNetworkId = -1; 1228 mSystemId = -1; 1229 mCdmaRoamingIndicator = -1; 1230 mCdmaDefaultRoamingIndicator = -1; 1231 mCdmaEriIconIndex = -1; 1232 mCdmaEriIconMode = -1; 1233 mIsEmergencyOnly = false; 1234 mArfcnRsrpBoost = 0; 1235 mNrFrequencyRange = FREQUENCY_RANGE_UNKNOWN; 1236 synchronized (mNetworkRegistrationInfos) { 1237 mNetworkRegistrationInfos.clear(); 1238 addNetworkRegistrationInfo(new NetworkRegistrationInfo.Builder() 1239 .setDomain(NetworkRegistrationInfo.DOMAIN_CS) 1240 .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN) 1241 .setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_UNKNOWN) 1242 .build()); 1243 addNetworkRegistrationInfo(new NetworkRegistrationInfo.Builder() 1244 .setDomain(NetworkRegistrationInfo.DOMAIN_PS) 1245 .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN) 1246 .setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_UNKNOWN) 1247 .build()); 1248 if (!legacyMode) { 1249 addNetworkRegistrationInfo(new NetworkRegistrationInfo.Builder() 1250 .setDomain(NetworkRegistrationInfo.DOMAIN_PS) 1251 .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WLAN) 1252 .setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_UNKNOWN) 1253 .build()); 1254 } 1255 } 1256 mOperatorAlphaLongRaw = null; 1257 mOperatorAlphaShortRaw = null; 1258 mIsDataRoamingFromRegistration = false; 1259 mIsIwlanPreferred = false; 1260 } 1261 setStateOutOfService()1262 public void setStateOutOfService() { 1263 init(true); 1264 } 1265 setStateOff()1266 public void setStateOff() { 1267 init(true); 1268 mVoiceRegState = STATE_POWER_OFF; 1269 mDataRegState = STATE_POWER_OFF; 1270 } 1271 1272 /** 1273 * Set the service state to out-of-service 1274 * 1275 * @param legacyMode {@code true} if the device is on IWLAN legacy mode, where IWLAN is 1276 * considered as a RAT on WWAN {@link NetworkRegistrationInfo}. {@code false} if the device 1277 * is on AP-assisted mode, where IWLAN should be reported through WLAN. 1278 * @param powerOff {@code true} if this is a power off case (i.e. Airplane mode on). 1279 * @hide 1280 */ setOutOfService(boolean legacyMode, boolean powerOff)1281 public void setOutOfService(boolean legacyMode, boolean powerOff) { 1282 init(legacyMode); 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); 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 * @hide 2112 */ getBetterNRFrequencyRange(int range1, int range2)2113 public static final int getBetterNRFrequencyRange(int range1, int range2) { 2114 return FREQUENCY_RANGE_ORDER.indexOf(range1) > FREQUENCY_RANGE_ORDER.indexOf(range2) 2115 ? range1 2116 : range2; 2117 } 2118 2119 /** 2120 * Returns a copy of self with location-identifying information removed. 2121 * Always clears the NetworkRegistrationInfo's CellIdentity fields, but if removeCoarseLocation 2122 * is true, clears other info as well. 2123 * 2124 * @param removeCoarseLocation Whether to also remove coarse location information. 2125 * if false, it only clears fine location information such as 2126 * NetworkRegistrationInfo's CellIdentity fields; If true, it will 2127 * also remove other location information such as operator's MCC 2128 * and MNC. 2129 * @return the copied ServiceState with location info sanitized. 2130 * @hide 2131 */ 2132 @NonNull createLocationInfoSanitizedCopy(boolean removeCoarseLocation)2133 public ServiceState createLocationInfoSanitizedCopy(boolean removeCoarseLocation) { 2134 ServiceState state = new ServiceState(this); 2135 synchronized (state.mNetworkRegistrationInfos) { 2136 List<NetworkRegistrationInfo> networkRegistrationInfos = 2137 state.mNetworkRegistrationInfos.stream() 2138 .map(NetworkRegistrationInfo::sanitizeLocationInfo) 2139 .collect(Collectors.toList()); 2140 state.mNetworkRegistrationInfos.clear(); 2141 state.mNetworkRegistrationInfos.addAll(networkRegistrationInfos); 2142 } 2143 if (!removeCoarseLocation) return state; 2144 2145 state.mOperatorAlphaLong = null; 2146 state.mOperatorAlphaShort = null; 2147 state.mOperatorNumeric = null; 2148 state.mSystemId = UNKNOWN_ID; 2149 state.mNetworkId = UNKNOWN_ID; 2150 2151 return state; 2152 } 2153 2154 /** 2155 * @hide 2156 */ setOperatorAlphaLongRaw(String operatorAlphaLong)2157 public void setOperatorAlphaLongRaw(String operatorAlphaLong) { 2158 mOperatorAlphaLongRaw = operatorAlphaLong; 2159 } 2160 2161 /** 2162 * The current registered raw data network operator name in long alphanumeric format. 2163 * 2164 * The long format can be up to 16 characters long. 2165 * 2166 * @return long raw name of operator, null if unregistered or unknown 2167 * @hide 2168 */ 2169 @Nullable getOperatorAlphaLongRaw()2170 public String getOperatorAlphaLongRaw() { 2171 return mOperatorAlphaLongRaw; 2172 } 2173 2174 /** 2175 * @hide 2176 */ setOperatorAlphaShortRaw(String operatorAlphaShort)2177 public void setOperatorAlphaShortRaw(String operatorAlphaShort) { 2178 mOperatorAlphaShortRaw = operatorAlphaShort; 2179 } 2180 2181 /** 2182 * The current registered raw data network operator name in short alphanumeric format. 2183 * 2184 * The short format can be up to 8 characters long. 2185 * 2186 * @return short raw name of operator, null if unregistered or unknown 2187 * @hide 2188 */ 2189 @Nullable getOperatorAlphaShortRaw()2190 public String getOperatorAlphaShortRaw() { 2191 return mOperatorAlphaShortRaw; 2192 } 2193 2194 /** 2195 * Set to {@code true} if any data network is preferred on IWLAN. 2196 * 2197 * @param isIwlanPreferred {@code true} if IWLAN is preferred. 2198 * @hide 2199 */ setIwlanPreferred(boolean isIwlanPreferred)2200 public void setIwlanPreferred(boolean isIwlanPreferred) { 2201 mIsIwlanPreferred = isIwlanPreferred; 2202 } 2203 2204 /** 2205 * @return {@code true} if any data network is preferred on IWLAN. 2206 * 2207 * Note only when this value is true, {@link #getDataNetworkType()} will return 2208 * {@link TelephonyManager#NETWORK_TYPE_IWLAN} when AP-assisted mode device camps on both 2209 * cellular and IWLAN. This value does not affect legacy mode devices as the data network 2210 * type is directly reported by the modem. 2211 * 2212 * @hide 2213 */ isIwlanPreferred()2214 public boolean isIwlanPreferred() { 2215 return mIsIwlanPreferred; 2216 } 2217 2218 /** 2219 * This indicates whether the device is searching for service. 2220 * 2221 * This API reports the modem searching status for 2222 * {@link AccessNetworkConstants#TRANSPORT_TYPE_WWAN} (cellular) service in either 2223 * {@link NetworkRegistrationInfo#DOMAIN_CS} or {@link NetworkRegistrationInfo#DOMAIN_PS}. 2224 * This API will not report searching status for 2225 * {@link AccessNetworkConstants#TRANSPORT_TYPE_WLAN}. 2226 * 2227 * @return {@code true} whenever the modem is searching for service. 2228 */ isSearching()2229 public boolean isSearching() { 2230 NetworkRegistrationInfo psRegState = getNetworkRegistrationInfo( 2231 NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN); 2232 2233 if (psRegState != null && psRegState.getRegistrationState() 2234 == NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_SEARCHING) { 2235 return true; 2236 } 2237 2238 NetworkRegistrationInfo csRegState = getNetworkRegistrationInfo( 2239 NetworkRegistrationInfo.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN); 2240 2241 if (csRegState != null && csRegState.getRegistrationState() 2242 == NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_SEARCHING) { 2243 return true; 2244 } 2245 return false; 2246 } 2247 2248 /** 2249 * The frequency range is valid or not. 2250 * 2251 * @param frequencyRange The frequency range {@link FrequencyRange}. 2252 * @return {@code true} if valid, {@code false} otherwise. 2253 * 2254 * @hide 2255 */ isFrequencyRangeValid(int frequencyRange)2256 public static boolean isFrequencyRangeValid(int frequencyRange) { 2257 if (frequencyRange == FREQUENCY_RANGE_LOW 2258 || frequencyRange == FREQUENCY_RANGE_MID 2259 || frequencyRange == FREQUENCY_RANGE_HIGH 2260 || frequencyRange == FREQUENCY_RANGE_MMWAVE) { 2261 return true; 2262 } else { 2263 return false; 2264 } 2265 } 2266 } 2267