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