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