1 /* 2 * Copyright (C) 2012 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.ElapsedRealtimeLong; 20 import android.annotation.NonNull; 21 import android.compat.annotation.UnsupportedAppUsage; 22 import android.os.Build; 23 import android.os.Bundle; 24 import android.os.Parcel; 25 import android.os.Parcelable; 26 import android.os.PersistableBundle; 27 import android.os.SystemClock; 28 29 import com.android.telephony.Rlog; 30 31 import java.util.ArrayList; 32 import java.util.List; 33 import java.util.Objects; 34 35 /** 36 * Contains phone signal strength related information. 37 */ 38 public class SignalStrength implements Parcelable { 39 40 private static final String LOG_TAG = "SignalStrength"; 41 private static final boolean DBG = false; 42 43 /** @hide */ 44 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) 45 public static final int SIGNAL_STRENGTH_NONE_OR_UNKNOWN = 46 CellSignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN; // = 0 47 /** @hide */ 48 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) 49 public static final int SIGNAL_STRENGTH_POOR = 50 CellSignalStrength.SIGNAL_STRENGTH_POOR; // = 1 51 /** @hide */ 52 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) 53 public static final int SIGNAL_STRENGTH_MODERATE = 54 CellSignalStrength.SIGNAL_STRENGTH_MODERATE; // = 2 55 /** @hide */ 56 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) 57 public static final int SIGNAL_STRENGTH_GOOD = 58 CellSignalStrength.SIGNAL_STRENGTH_GOOD; // = 3 59 /** @hide */ 60 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) 61 public static final int SIGNAL_STRENGTH_GREAT = 62 CellSignalStrength.SIGNAL_STRENGTH_GREAT; // = 4 63 /** @hide */ 64 @UnsupportedAppUsage 65 public static final int NUM_SIGNAL_STRENGTH_BINS = 5; 66 67 /** 68 * Indicates the invalid measures of signal strength. 69 * 70 * For example, this can be returned by {@link #getEvdoDbm()} or {@link #getCdmaDbm()} 71 */ 72 public static final int INVALID = Integer.MAX_VALUE; 73 74 private static final int LTE_RSRP_THRESHOLDS_NUM = 4; 75 76 private static final int WCDMA_RSCP_THRESHOLDS_NUM = 4; 77 78 /* The type of signal measurement */ 79 private static final String MEASUREMENT_TYPE_RSCP = "rscp"; 80 81 // Timestamp of SignalStrength since boot 82 // Effectively final. Timestamp is set during construction of SignalStrength 83 private long mTimestampMillis; 84 85 private boolean mLteAsPrimaryInNrNsa = true; 86 87 CellSignalStrengthCdma mCdma; 88 CellSignalStrengthGsm mGsm; 89 CellSignalStrengthWcdma mWcdma; 90 CellSignalStrengthTdscdma mTdscdma; 91 CellSignalStrengthLte mLte; 92 CellSignalStrengthNr mNr; 93 94 /** 95 * Create a new SignalStrength from a intent notifier Bundle 96 * 97 * This method may be used by external applications. 98 * 99 * @param m Bundle from intent notifier 100 * @return newly created SignalStrength 101 * 102 * @hide 103 */ 104 @UnsupportedAppUsage newFromBundle(Bundle m)105 public static SignalStrength newFromBundle(Bundle m) { 106 SignalStrength ret; 107 ret = new SignalStrength(); 108 ret.setFromNotifierBundle(m); 109 return ret; 110 } 111 112 /** 113 * This constructor is used to create SignalStrength with default 114 * values. 115 * 116 * @return newly created SignalStrength 117 * @hide 118 */ 119 @UnsupportedAppUsage SignalStrength()120 public SignalStrength() { 121 this(new CellSignalStrengthCdma(), new CellSignalStrengthGsm(), 122 new CellSignalStrengthWcdma(), new CellSignalStrengthTdscdma(), 123 new CellSignalStrengthLte(), new CellSignalStrengthNr()); 124 } 125 126 /** 127 * Constructor with all fields present 128 * 129 * @hide 130 */ SignalStrength( @onNull CellSignalStrengthCdma cdma, @NonNull CellSignalStrengthGsm gsm, @NonNull CellSignalStrengthWcdma wcdma, @NonNull CellSignalStrengthTdscdma tdscdma, @NonNull CellSignalStrengthLte lte, @NonNull CellSignalStrengthNr nr)131 public SignalStrength( 132 @NonNull CellSignalStrengthCdma cdma, 133 @NonNull CellSignalStrengthGsm gsm, 134 @NonNull CellSignalStrengthWcdma wcdma, 135 @NonNull CellSignalStrengthTdscdma tdscdma, 136 @NonNull CellSignalStrengthLte lte, 137 @NonNull CellSignalStrengthNr nr) { 138 mCdma = cdma; 139 mGsm = gsm; 140 mWcdma = wcdma; 141 mTdscdma = tdscdma; 142 mLte = lte; 143 mNr = nr; 144 mTimestampMillis = SystemClock.elapsedRealtime(); 145 } 146 147 /** 148 * Constructor for Radio HAL V1.0 149 * 150 * @hide 151 */ SignalStrength(android.hardware.radio.V1_0.SignalStrength signalStrength)152 public SignalStrength(android.hardware.radio.V1_0.SignalStrength signalStrength) { 153 this(new CellSignalStrengthCdma(signalStrength.cdma, signalStrength.evdo), 154 new CellSignalStrengthGsm(signalStrength.gw), 155 new CellSignalStrengthWcdma(), 156 new CellSignalStrengthTdscdma(signalStrength.tdScdma), 157 new CellSignalStrengthLte(signalStrength.lte), 158 new CellSignalStrengthNr()); 159 } 160 161 /** 162 * Constructor for Radio HAL V1.2 163 * 164 * @hide 165 */ SignalStrength(android.hardware.radio.V1_2.SignalStrength signalStrength)166 public SignalStrength(android.hardware.radio.V1_2.SignalStrength signalStrength) { 167 this(new CellSignalStrengthCdma(signalStrength.cdma, signalStrength.evdo), 168 new CellSignalStrengthGsm(signalStrength.gsm), 169 new CellSignalStrengthWcdma(signalStrength.wcdma), 170 new CellSignalStrengthTdscdma(signalStrength.tdScdma), 171 new CellSignalStrengthLte(signalStrength.lte), 172 new CellSignalStrengthNr()); 173 } 174 175 /** 176 * Constructor for Radio HAL V1.4. 177 * 178 * @param signalStrength signal strength reported from modem. 179 * @hide 180 */ SignalStrength(android.hardware.radio.V1_4.SignalStrength signalStrength)181 public SignalStrength(android.hardware.radio.V1_4.SignalStrength signalStrength) { 182 this(new CellSignalStrengthCdma(signalStrength.cdma, signalStrength.evdo), 183 new CellSignalStrengthGsm(signalStrength.gsm), 184 new CellSignalStrengthWcdma(signalStrength.wcdma), 185 new CellSignalStrengthTdscdma(signalStrength.tdscdma), 186 new CellSignalStrengthLte(signalStrength.lte), 187 new CellSignalStrengthNr(signalStrength.nr)); 188 } 189 190 /** 191 * Constructor for Radio HAL V1.6. 192 * 193 * @param signalStrength signal strength reported from modem. 194 * @hide 195 */ SignalStrength(android.hardware.radio.V1_6.SignalStrength signalStrength)196 public SignalStrength(android.hardware.radio.V1_6.SignalStrength signalStrength) { 197 this(new CellSignalStrengthCdma(signalStrength.cdma, signalStrength.evdo), 198 new CellSignalStrengthGsm(signalStrength.gsm), 199 new CellSignalStrengthWcdma(signalStrength.wcdma), 200 new CellSignalStrengthTdscdma(signalStrength.tdscdma), 201 new CellSignalStrengthLte(signalStrength.lte), 202 new CellSignalStrengthNr(signalStrength.nr)); 203 } 204 getPrimary()205 private CellSignalStrength getPrimary() { 206 // This behavior is intended to replicate the legacy behavior of getLevel() by prioritizing 207 // newer faster RATs for default/for display purposes. 208 209 if (mLteAsPrimaryInNrNsa) { 210 if (mLte.isValid()) return mLte; 211 } 212 if (mNr.isValid()) return mNr; 213 if (mLte.isValid()) return mLte; 214 if (mCdma.isValid()) return mCdma; 215 if (mTdscdma.isValid()) return mTdscdma; 216 if (mWcdma.isValid()) return mWcdma; 217 if (mGsm.isValid()) return mGsm; 218 return mLte; 219 } 220 221 /** 222 * Returns a List of CellSignalStrength Components of this SignalStrength Report. 223 * 224 * Use this API to access underlying 225 * {@link android.telephony#CellSignalStrength CellSignalStrength} objects that provide more 226 * granular information about the SignalStrength report. Only valid (non-empty) 227 * CellSignalStrengths will be returned. The order of any returned elements is not guaranteed, 228 * and the list may contain more than one instance of a CellSignalStrength type. 229 * 230 * @return a List of CellSignalStrength or an empty List if there are no valid measurements. 231 * 232 * @see android.telephony#CellSignalStrength 233 * @see android.telephony#CellSignalStrengthNr 234 * @see android.telephony#CellSignalStrengthLte 235 * @see android.telephony#CellSignalStrengthTdscdma 236 * @see android.telephony#CellSignalStrengthWcdma 237 * @see android.telephony#CellSignalStrengthCdma 238 * @see android.telephony#CellSignalStrengthGsm 239 */ getCellSignalStrengths()240 @NonNull public List<CellSignalStrength> getCellSignalStrengths() { 241 return getCellSignalStrengths(CellSignalStrength.class); 242 } 243 244 /** 245 * Returns a List of CellSignalStrength Components of this SignalStrength Report. 246 * 247 * Use this API to access underlying 248 * {@link android.telephony#CellSignalStrength CellSignalStrength} objects that provide more 249 * granular information about the SignalStrength report. Only valid (non-empty) 250 * CellSignalStrengths will be returned. The order of any returned elements is not guaranteed, 251 * and the list may contain more than one instance of a CellSignalStrength type. 252 * 253 * @param clazz a class type that extends 254 * {@link android.telephony.CellSignalStrength CellSignalStrength} to filter possible 255 * return values. 256 * @return a List of CellSignalStrength or an empty List if there are no valid measurements. 257 * 258 * @see android.telephony#CellSignalStrength 259 * @see android.telephony#CellSignalStrengthNr 260 * @see android.telephony#CellSignalStrengthLte 261 * @see android.telephony#CellSignalStrengthTdscdma 262 * @see android.telephony#CellSignalStrengthWcdma 263 * @see android.telephony#CellSignalStrengthCdma 264 * @see android.telephony#CellSignalStrengthGsm 265 */ getCellSignalStrengths( @onNull Class<T> clazz)266 @NonNull public <T extends CellSignalStrength> List<T> getCellSignalStrengths( 267 @NonNull Class<T> clazz) { 268 List<T> cssList = new ArrayList<>(2); // Usually have 2 or fewer elems 269 if (mLte.isValid() && clazz.isAssignableFrom(CellSignalStrengthLte.class)) { 270 cssList.add((T) mLte); 271 } 272 if (mCdma.isValid() && clazz.isAssignableFrom(CellSignalStrengthCdma.class)) { 273 cssList.add((T) mCdma); 274 } 275 if (mTdscdma.isValid() && clazz.isAssignableFrom(CellSignalStrengthTdscdma.class)) { 276 cssList.add((T) mTdscdma); 277 } 278 if (mWcdma.isValid() && clazz.isAssignableFrom(CellSignalStrengthWcdma.class)) { 279 cssList.add((T) mWcdma); 280 } 281 if (mGsm.isValid() && clazz.isAssignableFrom(CellSignalStrengthGsm.class)) { 282 cssList.add((T) mGsm); 283 } 284 if (mNr.isValid() && clazz.isAssignableFrom(CellSignalStrengthNr.class)) { 285 cssList.add((T) mNr); 286 } 287 return cssList; 288 } 289 290 /** @hide */ updateLevel(PersistableBundle cc, ServiceState ss)291 public void updateLevel(PersistableBundle cc, ServiceState ss) { 292 if (cc != null) { 293 mLteAsPrimaryInNrNsa = cc.getBoolean( 294 CarrierConfigManager.KEY_SIGNAL_STRENGTH_NR_NSA_USE_LTE_AS_PRIMARY_BOOL, true); 295 } 296 mCdma.updateLevel(cc, ss); 297 mGsm.updateLevel(cc, ss); 298 mWcdma.updateLevel(cc, ss); 299 mTdscdma.updateLevel(cc, ss); 300 mLte.updateLevel(cc, ss); 301 mNr.updateLevel(cc, ss); 302 } 303 304 /** 305 * This constructor is used to create a copy of an existing SignalStrength object. 306 * 307 * @param s Source SignalStrength 308 */ SignalStrength(@onNull SignalStrength s)309 public SignalStrength(@NonNull SignalStrength s) { 310 copyFrom(s); 311 } 312 313 /** 314 * @hide 315 */ 316 @UnsupportedAppUsage copyFrom(SignalStrength s)317 protected void copyFrom(SignalStrength s) { 318 mCdma = new CellSignalStrengthCdma(s.mCdma); 319 mGsm = new CellSignalStrengthGsm(s.mGsm); 320 mWcdma = new CellSignalStrengthWcdma(s.mWcdma); 321 mTdscdma = new CellSignalStrengthTdscdma(s.mTdscdma); 322 mLte = new CellSignalStrengthLte(s.mLte); 323 mNr = new CellSignalStrengthNr(s.mNr); 324 mTimestampMillis = s.getTimestampMillis(); 325 } 326 327 /** 328 * Construct a SignalStrength object from the given parcel. 329 * 330 * @hide 331 */ 332 @UnsupportedAppUsage SignalStrength(Parcel in)333 public SignalStrength(Parcel in) { 334 if (DBG) log("Size of signalstrength parcel:" + in.dataSize()); 335 336 mCdma = in.readParcelable(CellSignalStrengthCdma.class.getClassLoader()); 337 mGsm = in.readParcelable(CellSignalStrengthGsm.class.getClassLoader()); 338 mWcdma = in.readParcelable(CellSignalStrengthWcdma.class.getClassLoader()); 339 mTdscdma = in.readParcelable(CellSignalStrengthTdscdma.class.getClassLoader()); 340 mLte = in.readParcelable(CellSignalStrengthLte.class.getClassLoader()); 341 mNr = in.readParcelable(CellSignalStrengthLte.class.getClassLoader()); 342 mTimestampMillis = in.readLong(); 343 } 344 345 /** 346 * {@link Parcelable#writeToParcel} 347 */ writeToParcel(Parcel out, int flags)348 public void writeToParcel(Parcel out, int flags) { 349 out.writeParcelable(mCdma, flags); 350 out.writeParcelable(mGsm, flags); 351 out.writeParcelable(mWcdma, flags); 352 out.writeParcelable(mTdscdma, flags); 353 out.writeParcelable(mLte, flags); 354 out.writeParcelable(mNr, flags); 355 out.writeLong(mTimestampMillis); 356 } 357 358 /** 359 * @return timestamp in milliseconds since boot for {@link SignalStrength}. 360 * This timestamp reports the approximate time that the signal was measured and reported 361 * by the modem. It can be used to compare the recency of {@link SignalStrength} instances. 362 */ 363 @ElapsedRealtimeLong getTimestampMillis()364 public long getTimestampMillis() { 365 return mTimestampMillis; 366 } 367 368 /** 369 * {@link Parcelable#describeContents} 370 */ describeContents()371 public int describeContents() { 372 return 0; 373 } 374 375 /** 376 * {@link Parcelable.Creator} 377 * 378 */ 379 public static final @android.annotation.NonNull Parcelable.Creator<SignalStrength> CREATOR = 380 new Parcelable.Creator<SignalStrength>() { 381 public SignalStrength createFromParcel(Parcel in) { 382 return new SignalStrength(in); 383 } 384 385 public SignalStrength[] newArray(int size) { 386 return new SignalStrength[size]; 387 } 388 }; 389 390 /** 391 * Get the GSM RSSI in ASU. 392 * 393 * Asu is calculated based on 3GPP RSRP. Refer to 3GPP 27.007 (Ver 10.3.0) Sec 8.69 394 * 395 * @return RSSI in ASU 0..31, 99, or UNAVAILABLE 396 * 397 * @deprecated this information should be retrieved from 398 * {@link CellSignalStrengthGsm#getAsuLevel}. 399 * @see android.telephony#CellSignalStrengthGsm 400 * @see android.telephony.SignalStrength#getCellSignalStrengths 401 */ 402 @Deprecated getGsmSignalStrength()403 public int getGsmSignalStrength() { 404 return mGsm.getAsuLevel(); 405 } 406 407 /** 408 * Get the GSM bit error rate (0-7, 99) as defined in TS 27.007 8.5 409 * 410 * @deprecated this information should be retrieved from 411 * {@link CellSignalStrengthGsm#getBitErrorRate}. 412 * 413 * @see android.telephony#CellSignalStrengthGsm 414 * @see android.telephony.SignalStrength#getCellSignalStrengths() 415 */ 416 @Deprecated getGsmBitErrorRate()417 public int getGsmBitErrorRate() { 418 return mGsm.getBitErrorRate(); 419 } 420 421 /** 422 * Get the CDMA RSSI value in dBm 423 * 424 * @return the CDMA RSSI value or {@link #INVALID} if invalid 425 * 426 * @deprecated this information should be retrieved from 427 * {@link CellSignalStrengthCdma#getCdmaDbm}. 428 * 429 * @see android.telephony#CellSignalStrengthCdma 430 * @see android.telephony.SignalStrength#getCellSignalStrengths() 431 */ 432 @Deprecated getCdmaDbm()433 public int getCdmaDbm() { 434 return mCdma.getCdmaDbm(); 435 } 436 437 /** 438 * Get the CDMA Ec/Io value in dB*10 439 * 440 * @deprecated this information should be retrieved from 441 * {@link CellSignalStrengthCdma#getCdmaEcio}. 442 * 443 * @see android.telephony#CellSignalStrengthCdma 444 * @see android.telephony.SignalStrength#getCellSignalStrengths() 445 */ 446 @Deprecated getCdmaEcio()447 public int getCdmaEcio() { 448 return mCdma.getCdmaEcio(); 449 } 450 451 /** 452 * Get the EVDO RSSI value in dBm 453 * 454 * @return the EVDO RSSI value or {@link #INVALID} if invalid 455 * 456 * @deprecated this information should be retrieved from 457 * {@link CellSignalStrengthCdma#getEvdoDbm}. 458 * 459 * @see android.telephony#CellSignalStrengthCdma 460 * @see android.telephony.SignalStrength#getCellSignalStrengths() 461 */ 462 @Deprecated getEvdoDbm()463 public int getEvdoDbm() { 464 return mCdma.getEvdoDbm(); 465 } 466 467 /** 468 * Get the EVDO Ec/Io value in dB*10 469 * 470 * @deprecated this information should be retrieved from 471 * {@link CellSignalStrengthCdma#getEvdoEcio}. 472 * 473 * @see android.telephony#CellSignalStrengthCdma 474 * @see android.telephony.SignalStrength#getCellSignalStrengths() 475 */ 476 @Deprecated getEvdoEcio()477 public int getEvdoEcio() { 478 return mCdma.getEvdoEcio(); 479 } 480 481 /** 482 * Get the signal to noise ratio. Valid values are 0-8. 8 is the highest. 483 * 484 * @deprecated this information should be retrieved from 485 * {@link CellSignalStrengthCdma#getEvdoSnr}. 486 * 487 * @see android.telephony#CellSignalStrengthCdma 488 * @see android.telephony.SignalStrength#getCellSignalStrengths() 489 */ 490 @Deprecated getEvdoSnr()491 public int getEvdoSnr() { 492 return mCdma.getEvdoSnr(); 493 } 494 495 /** 496 * @deprecated this information should be retrieved from 497 * {@link CellSignalStrengthLte#getRssi}. 498 * 499 * @see android.telephony#CellSignalStrengthLte 500 * @see android.telephony.SignalStrength#getCellSignalStrengths() 501 * @hide 502 */ 503 @Deprecated 504 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getLteSignalStrength()505 public int getLteSignalStrength() { 506 return mLte.getRssi(); 507 } 508 509 /** 510 * @deprecated this information should be retrieved from 511 * {@link CellSignalStrengthLte#getRsrp}. 512 * 513 * @see android.telephony#CellSignalStrengthLte 514 * @see android.telephony.SignalStrength#getCellSignalStrengths() 515 * @hide 516 */ 517 @Deprecated 518 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getLteRsrp()519 public int getLteRsrp() { 520 return mLte.getRsrp(); 521 } 522 523 /** 524 * @deprecated this information should be retrieved from 525 * {@link CellSignalStrengthLte#getRsrq}. 526 * 527 * @see android.telephony#CellSignalStrengthLte 528 * @see android.telephony.SignalStrength#getCellSignalStrengths() 529 * @hide 530 */ 531 @Deprecated 532 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getLteRsrq()533 public int getLteRsrq() { 534 return mLte.getRsrq(); 535 } 536 537 /** 538 * @deprecated this information should be retrieved from 539 * {@link CellSignalStrengthLte#getRssnr}. 540 * 541 * @see android.telephony#CellSignalStrengthLte 542 * @see android.telephony.SignalStrength#getCellSignalStrengths() 543 * @hide 544 */ 545 @Deprecated 546 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getLteRssnr()547 public int getLteRssnr() { 548 return mLte.getRssnr(); 549 } 550 551 /** 552 * @deprecated this information should be retrieved from 553 * {@link CellSignalStrengthLte#getCqi}. 554 * 555 * @see android.telephony#CellSignalStrengthLte 556 * @see android.telephony.SignalStrength#getCellSignalStrengths() 557 * @hide 558 */ 559 @Deprecated 560 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getLteCqi()561 public int getLteCqi() { 562 return mLte.getCqi(); 563 } 564 565 /** 566 * Retrieve an abstract level value for the overall signal strength. 567 * 568 * @return a single integer from 0 to 4 representing the general signal quality. 569 * This may take into account many different radio technology inputs. 570 * 0 represents very poor signal strength 571 * while 4 represents a very strong signal strength. 572 */ getLevel()573 public int getLevel() { 574 int level = getPrimary().getLevel(); 575 if (level < SIGNAL_STRENGTH_NONE_OR_UNKNOWN || level > SIGNAL_STRENGTH_GREAT) { 576 loge("Invalid Level " + level + ", this=" + this); 577 return SIGNAL_STRENGTH_NONE_OR_UNKNOWN; 578 } 579 return getPrimary().getLevel(); 580 } 581 582 /** 583 * Get the signal level as an asu value with a range dependent on the underlying technology. 584 * 585 * @deprecated this information should be retrieved from 586 * {@link CellSignalStrength#getAsuLevel}. Because the levels vary by technology, 587 * this method is misleading and should not be used. 588 * @see android.telephony#CellSignalStrength 589 * @see android.telephony.SignalStrength#getCellSignalStrengths 590 * @hide 591 */ 592 @Deprecated 593 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getAsuLevel()594 public int getAsuLevel() { 595 return getPrimary().getAsuLevel(); 596 } 597 598 /** 599 * Get the signal strength as dBm 600 * 601 * @deprecated this information should be retrieved from 602 * {@link CellSignalStrength#getDbm()}. Because the levels vary by technology, 603 * this method is misleading and should not be used. 604 * @see android.telephony#CellSignalStrength 605 * @see android.telephony.SignalStrength#getCellSignalStrengths 606 * @hide 607 */ 608 @Deprecated 609 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getDbm()610 public int getDbm() { 611 return getPrimary().getDbm(); 612 } 613 614 /** 615 * Get Gsm signal strength as dBm 616 * 617 * @deprecated this information should be retrieved from 618 * {@link CellSignalStrengthGsm#getDbm}. 619 * 620 * @see android.telephony#CellSignalStrengthGsm 621 * @see android.telephony.SignalStrength#getCellSignalStrengths() 622 * @hide 623 */ 624 @Deprecated 625 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getGsmDbm()626 public int getGsmDbm() { 627 return mGsm.getDbm(); 628 } 629 630 /** 631 * Get gsm as level 0..4 632 * 633 * @deprecated this information should be retrieved from 634 * {@link CellSignalStrengthGsm#getLevel}. 635 * 636 * @see android.telephony#CellSignalStrengthGsm 637 * @see android.telephony.SignalStrength#getCellSignalStrengths() 638 * @hide 639 */ 640 @Deprecated 641 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getGsmLevel()642 public int getGsmLevel() { 643 return mGsm.getLevel(); 644 } 645 646 /** 647 * Get the gsm signal level as an asu value between 0..31, 99 is unknown 648 * 649 * @deprecated this information should be retrieved from 650 * {@link CellSignalStrengthGsm#getAsuLevel}. 651 * 652 * @see android.telephony#CellSignalStrengthGsm 653 * @see android.telephony.SignalStrength#getCellSignalStrengths() 654 * @hide 655 */ 656 @Deprecated 657 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getGsmAsuLevel()658 public int getGsmAsuLevel() { 659 return mGsm.getAsuLevel(); 660 } 661 662 /** 663 * Get cdma as level 0..4 664 * 665 * @deprecated this information should be retrieved from 666 * {@link CellSignalStrengthCdma#getLevel}. 667 * 668 * @see android.telephony#CellSignalStrengthCdma 669 * @see android.telephony.SignalStrength#getCellSignalStrengths() 670 * @hide 671 */ 672 @Deprecated 673 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getCdmaLevel()674 public int getCdmaLevel() { 675 return mCdma.getLevel(); 676 } 677 678 /** 679 * Get the cdma signal level as an asu value between 0..31, 99 is unknown 680 * 681 * @deprecated this information should be retrieved from 682 * {@link CellSignalStrengthCdma#getAsuLevel}. Since there is no definition of 683 * ASU for CDMA, the resultant value is Android-specific and is not recommended 684 * for use. 685 * 686 * @see android.telephony#CellSignalStrengthCdma 687 * @see android.telephony.SignalStrength#getCellSignalStrengths() 688 * @hide 689 */ 690 @Deprecated 691 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getCdmaAsuLevel()692 public int getCdmaAsuLevel() { 693 return mCdma.getAsuLevel(); 694 } 695 696 /** 697 * Get Evdo as level 0..4 698 * 699 * @deprecated this information should be retrieved from 700 * {@link CellSignalStrengthCdma#getEvdoLevel}. 701 * 702 * @see android.telephony#CellSignalStrengthCdma 703 * @see android.telephony.SignalStrength#getCellSignalStrengths() 704 * @hide 705 */ 706 @Deprecated 707 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getEvdoLevel()708 public int getEvdoLevel() { 709 return mCdma.getEvdoLevel(); 710 } 711 712 /** 713 * Get the evdo signal level as an asu value between 0..31, 99 is unknown 714 * 715 * @deprecated this information should be retrieved from 716 * {@link CellSignalStrengthCdma#getEvdoAsuLevel}. Since there is no definition of 717 * ASU for EvDO, the resultant value is Android-specific and is not recommended 718 * for use. 719 * 720 * @see android.telephony#CellSignalStrengthCdma 721 * @see android.telephony.SignalStrength#getCellSignalStrengths() 722 * @hide 723 */ 724 @Deprecated 725 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getEvdoAsuLevel()726 public int getEvdoAsuLevel() { 727 return mCdma.getEvdoAsuLevel(); 728 } 729 730 /** 731 * Get LTE as dBm 732 * 733 * @deprecated this information should be retrieved from 734 * {@link CellSignalStrengthLte#getDbm}. 735 * 736 * @see android.telephony#CellSignalStrengthLte 737 * @see android.telephony.SignalStrength#getCellSignalStrengths() 738 * @hide 739 */ 740 @Deprecated 741 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getLteDbm()742 public int getLteDbm() { 743 return mLte.getRsrp(); 744 } 745 746 /** 747 * Get LTE as level 0..4 748 * 749 * @deprecated this information should be retrieved from 750 * {@link CellSignalStrengthLte#getLevel}. 751 * 752 * @see android.telephony#CellSignalStrengthLte 753 * @see android.telephony.SignalStrength#getCellSignalStrengths() 754 * @hide 755 */ 756 @Deprecated 757 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getLteLevel()758 public int getLteLevel() { 759 return mLte.getLevel(); 760 } 761 762 /** 763 * Get the LTE signal level as an asu value between 0..97, 99 is unknown 764 * Asu is calculated based on 3GPP RSRP. Refer to 3GPP 27.007 (Ver 10.3.0) Sec 8.69 765 * 766 * @deprecated this information should be retrieved from 767 * {@link CellSignalStrengthLte#getAsuLevel}. 768 * 769 * @see android.telephony#CellSignalStrengthLte 770 * @see android.telephony.SignalStrength#getCellSignalStrengths() 771 * @hide 772 */ 773 @Deprecated 774 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getLteAsuLevel()775 public int getLteAsuLevel() { 776 return mLte.getAsuLevel(); 777 } 778 779 /** 780 * @return true if this is for GSM 781 * 782 * @deprecated This method returns true if there are any 3gpp type SignalStrength elements in 783 * this SignalStrength report or if the report contains no valid SignalStrength 784 * information. Instead callers should use 785 * {@link android.telephony.SignalStrength#getCellSignalStrengths 786 * getCellSignalStrengths()} to determine which types of information are contained 787 * in the SignalStrength report. 788 */ 789 @Deprecated isGsm()790 public boolean isGsm() { 791 return !(getPrimary() instanceof CellSignalStrengthCdma); 792 } 793 794 /** 795 * @return get TD-SCDMA dBm 796 * 797 * @deprecated this information should be retrieved from 798 * {@link CellSignalStrengthTdscdma#getDbm}. 799 * 800 * @see android.telephony#CellSignalStrengthTdscdma 801 * @see android.telephony.SignalStrength#getCellSignalStrengths() 802 * @hide 803 */ 804 @Deprecated 805 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getTdScdmaDbm()806 public int getTdScdmaDbm() { 807 return mTdscdma.getRscp(); 808 } 809 810 /** 811 * Get TD-SCDMA as level 0..4 812 * Range : 25 to 120 813 * INT_MAX: 0x7FFFFFFF denotes invalid value 814 * Reference: 3GPP TS 25.123, section 9.1.1.1 815 * 816 * @deprecated this information should be retrieved from 817 * {@link CellSignalStrengthTdscdma#getLevel}. 818 * 819 * @see android.telephony#CellSignalStrengthTdscdma 820 * @see android.telephony.SignalStrength#getCellSignalStrengths() 821 * @hide 822 */ 823 @Deprecated 824 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getTdScdmaLevel()825 public int getTdScdmaLevel() { 826 return mTdscdma.getLevel(); 827 } 828 829 /** 830 * Get the TD-SCDMA signal level as an asu value. 831 * 832 * @deprecated this information should be retrieved from 833 * {@link CellSignalStrengthTdscdma#getAsuLevel}. 834 * 835 * @see android.telephony#CellSignalStrengthTdscdma 836 * @see android.telephony.SignalStrength#getCellSignalStrengths() 837 * @hide 838 */ 839 @Deprecated 840 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getTdScdmaAsuLevel()841 public int getTdScdmaAsuLevel() { 842 return mTdscdma.getAsuLevel(); 843 } 844 845 /** 846 * Gets WCDMA RSCP as a dBm value between -120 and -24, as defined in TS 27.007 8.69. 847 * 848 * @deprecated this information should be retrieved from 849 * {@link CellSignalStrengthWcdma#getRscp}. 850 * 851 * @see android.telephony#CellSignalStrengthWcdma 852 * @see android.telephony.SignalStrength#getCellSignalStrengths() 853 * @hide 854 */ 855 @Deprecated getWcdmaRscp()856 public int getWcdmaRscp() { 857 return mWcdma.getRscp(); 858 } 859 860 /** 861 * Get the WCDMA signal level as an ASU value between 0-96, 255 is unknown 862 * 863 * @deprecated this information should be retrieved from 864 * {@link CellSignalStrengthWcdma#getAsuLevel}. 865 * 866 * @see android.telephony#CellSignalStrengthWcdma 867 * @see android.telephony.SignalStrength#getCellSignalStrengths() 868 * @hide 869 */ 870 @Deprecated getWcdmaAsuLevel()871 public int getWcdmaAsuLevel() { 872 /* 873 * 3GPP 27.007 (Ver 10.3.0) Sec 8.69 874 * 0 -120 dBm or less 875 * 1 -119 dBm 876 * 2...95 -118... -25 dBm 877 * 96 -24 dBm or greater 878 * 255 not known or not detectable 879 */ 880 return mWcdma.getAsuLevel(); 881 } 882 883 /** 884 * Gets WCDMA signal strength as a dBm value between -120 and -24, as defined in TS 27.007 8.69. 885 * 886 * @deprecated this information should be retrieved from 887 * {@link CellSignalStrengthWcdma#getDbm}. 888 * 889 * @see android.telephony#CellSignalStrengthWcdma 890 * @see android.telephony.SignalStrength#getCellSignalStrengths() 891 * @hide 892 */ 893 @Deprecated getWcdmaDbm()894 public int getWcdmaDbm() { 895 return mWcdma.getDbm(); 896 } 897 898 /** 899 * Get WCDMA as level 0..4 900 * 901 * @deprecated this information should be retrieved from 902 * {@link CellSignalStrengthWcdma#getDbm}. 903 * 904 * @see android.telephony#CellSignalStrengthWcdma 905 * @see android.telephony.SignalStrength#getCellSignalStrengths() 906 * @hide 907 */ 908 @Deprecated getWcdmaLevel()909 public int getWcdmaLevel() { 910 return mWcdma.getLevel(); 911 } 912 913 /** 914 * @return hash code 915 */ 916 @Override hashCode()917 public int hashCode() { 918 return Objects.hash(mCdma, mGsm, mWcdma, mTdscdma, mLte, mNr); 919 } 920 921 /** 922 * @return true if the signal strengths are the same 923 */ 924 @Override equals(Object o)925 public boolean equals (Object o) { 926 if (!(o instanceof SignalStrength)) return false; 927 928 SignalStrength s = (SignalStrength) o; 929 930 return mCdma.equals(s.mCdma) 931 && mGsm.equals(s.mGsm) 932 && mWcdma.equals(s.mWcdma) 933 && mTdscdma.equals(s.mTdscdma) 934 && mLte.equals(s.mLte) 935 && mNr.equals(s.mNr); 936 } 937 938 /** 939 * @return string representation. 940 */ 941 @Override toString()942 public String toString() { 943 return new StringBuilder().append("SignalStrength:{") 944 .append("mCdma=").append(mCdma) 945 .append(",mGsm=").append(mGsm) 946 .append(",mWcdma=").append(mWcdma) 947 .append(",mTdscdma=").append(mTdscdma) 948 .append(",mLte=").append(mLte) 949 .append(",mNr=").append(mNr) 950 .append(",primary=").append(getPrimary().getClass().getSimpleName()) 951 .append("}") 952 .toString(); 953 } 954 955 /** 956 * Set SignalStrength based on intent notifier map 957 * 958 * @param m intent notifier map 959 * 960 * @deprecated this method relies on non-stable implementation details, and full access to 961 * internal storage is available via {@link getCellSignalStrengths()}. 962 * @hide 963 */ 964 @Deprecated 965 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) setFromNotifierBundle(Bundle m)966 private void setFromNotifierBundle(Bundle m) { 967 mCdma = m.getParcelable("Cdma"); 968 mGsm = m.getParcelable("Gsm"); 969 mWcdma = m.getParcelable("Wcdma"); 970 mTdscdma = m.getParcelable("Tdscdma"); 971 mLte = m.getParcelable("Lte"); 972 mNr = m.getParcelable("Nr"); 973 } 974 975 /** 976 * Set intent notifier Bundle based on SignalStrength 977 * 978 * @param m intent notifier Bundle 979 * 980 * @deprecated this method relies on non-stable implementation details, and full access to 981 * internal storage is available via {@link getCellSignalStrengths()}. 982 * @hide 983 */ 984 @Deprecated 985 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) fillInNotifierBundle(Bundle m)986 public void fillInNotifierBundle(Bundle m) { 987 m.putParcelable("Cdma", mCdma); 988 m.putParcelable("Gsm", mGsm); 989 m.putParcelable("Wcdma", mWcdma); 990 m.putParcelable("Tdscdma", mTdscdma); 991 m.putParcelable("Lte", mLte); 992 m.putParcelable("Nr", mNr); 993 } 994 995 /** 996 * log warning 997 */ log(String s)998 private static void log(String s) { 999 Rlog.w(LOG_TAG, s); 1000 } 1001 1002 /** 1003 * log error 1004 */ loge(String s)1005 private static void loge(String s) { 1006 Rlog.e(LOG_TAG, s); 1007 } 1008 } 1009