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