• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 Qualcomm Innovation Center, Inc.  All Rights Reserved.
3  * Copyright (C) 2009 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 package android.telephony;
19 
20 import android.os.Bundle;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 import android.util.Log;
24 
25 /**
26  * Contains phone signal strength related information.
27  */
28 public class SignalStrength implements Parcelable {
29 
30     private static final String LOG_TAG = "SignalStrength";
31     private static final boolean DBG = false;
32 
33     /** @hide */
34     public static final int SIGNAL_STRENGTH_NONE_OR_UNKNOWN = 0;
35     /** @hide */
36     public static final int SIGNAL_STRENGTH_POOR = 1;
37     /** @hide */
38     public static final int SIGNAL_STRENGTH_MODERATE = 2;
39     /** @hide */
40     public static final int SIGNAL_STRENGTH_GOOD = 3;
41     /** @hide */
42     public static final int SIGNAL_STRENGTH_GREAT = 4;
43     /** @hide */
44     public static final int NUM_SIGNAL_STRENGTH_BINS = 5;
45     /** @hide */
46     public static final String[] SIGNAL_STRENGTH_NAMES = {
47         "none", "poor", "moderate", "good", "great"
48     };
49 
50     /** @hide */
51     public static final int INVALID_SNR = 0x7FFFFFFF;
52 
53     private int mGsmSignalStrength; // Valid values are (0-31, 99) as defined in TS 27.007 8.5
54     private int mGsmBitErrorRate;   // bit error rate (0-7, 99) as defined in TS 27.007 8.5
55     private int mCdmaDbm;   // This value is the RSSI value
56     private int mCdmaEcio;  // This value is the Ec/Io
57     private int mEvdoDbm;   // This value is the EVDO RSSI value
58     private int mEvdoEcio;  // This value is the EVDO Ec/Io
59     private int mEvdoSnr;   // Valid values are 0-8.  8 is the highest signal to noise ratio
60     private int mLteSignalStrength;
61     private int mLteRsrp;
62     private int mLteRsrq;
63     private int mLteRssnr;
64     private int mLteCqi;
65 
66     private boolean isGsm; // This value is set by the ServiceStateTracker onSignalStrengthResult
67 
68     /**
69      * Create a new SignalStrength from a intent notifier Bundle
70      *
71      * This method is used by PhoneStateIntentReceiver and maybe by
72      * external applications.
73      *
74      * @param m Bundle from intent notifier
75      * @return newly created SignalStrength
76      *
77      * @hide
78      */
newFromBundle(Bundle m)79     public static SignalStrength newFromBundle(Bundle m) {
80         SignalStrength ret;
81         ret = new SignalStrength();
82         ret.setFromNotifierBundle(m);
83         return ret;
84     }
85 
86     /**
87      * Empty constructor
88      *
89      * @hide
90      */
SignalStrength()91     public SignalStrength() {
92         mGsmSignalStrength = 99;
93         mGsmBitErrorRate = -1;
94         mCdmaDbm = -1;
95         mCdmaEcio = -1;
96         mEvdoDbm = -1;
97         mEvdoEcio = -1;
98         mEvdoSnr = -1;
99         mLteSignalStrength = -1;
100         mLteRsrp = -1;
101         mLteRsrq = -1;
102         mLteRssnr = INVALID_SNR;
103         mLteCqi = -1;
104         isGsm = true;
105     }
106 
107     /**
108      * Constructor
109      *
110      * @hide
111      */
SignalStrength(int gsmSignalStrength, int gsmBitErrorRate, int cdmaDbm, int cdmaEcio, int evdoDbm, int evdoEcio, int evdoSnr, int lteSignalStrength, int lteRsrp, int lteRsrq, int lteRssnr, int lteCqi, boolean gsm)112     public SignalStrength(int gsmSignalStrength, int gsmBitErrorRate,
113             int cdmaDbm, int cdmaEcio,
114             int evdoDbm, int evdoEcio, int evdoSnr,
115             int lteSignalStrength, int lteRsrp, int lteRsrq, int lteRssnr, int lteCqi,
116             boolean gsm) {
117         mGsmSignalStrength = gsmSignalStrength;
118         mGsmBitErrorRate = gsmBitErrorRate;
119         mCdmaDbm = cdmaDbm;
120         mCdmaEcio = cdmaEcio;
121         mEvdoDbm = evdoDbm;
122         mEvdoEcio = evdoEcio;
123         mEvdoSnr = evdoSnr;
124         mLteSignalStrength = lteSignalStrength;
125         mLteRsrp = lteRsrp;
126         mLteRsrq = lteRsrq;
127         mLteRssnr = lteRssnr;
128         mLteCqi = lteCqi;
129         isGsm = gsm;
130     }
131 
132     /**
133      * Constructor
134      *
135      * @hide
136      */
SignalStrength(int gsmSignalStrength, int gsmBitErrorRate, int cdmaDbm, int cdmaEcio, int evdoDbm, int evdoEcio, int evdoSnr, boolean gsm)137     public SignalStrength(int gsmSignalStrength, int gsmBitErrorRate,
138             int cdmaDbm, int cdmaEcio,
139             int evdoDbm, int evdoEcio, int evdoSnr,
140             boolean gsm) {
141         this(gsmSignalStrength, gsmBitErrorRate, cdmaDbm, cdmaEcio,
142                 evdoDbm, evdoEcio, evdoSnr, -1, -1,
143                 -1, INVALID_SNR, -1, gsm);
144     }
145 
146     /**
147      * Copy constructors
148      *
149      * @param s Source SignalStrength
150      *
151      * @hide
152      */
SignalStrength(SignalStrength s)153     public SignalStrength(SignalStrength s) {
154         copyFrom(s);
155     }
156 
157     /**
158      * @hide
159      */
copyFrom(SignalStrength s)160     protected void copyFrom(SignalStrength s) {
161         mGsmSignalStrength = s.mGsmSignalStrength;
162         mGsmBitErrorRate = s.mGsmBitErrorRate;
163         mCdmaDbm = s.mCdmaDbm;
164         mCdmaEcio = s.mCdmaEcio;
165         mEvdoDbm = s.mEvdoDbm;
166         mEvdoEcio = s.mEvdoEcio;
167         mEvdoSnr = s.mEvdoSnr;
168         mLteSignalStrength = s.mLteSignalStrength;
169         mLteRsrp = s.mLteRsrp;
170         mLteRsrq = s.mLteRsrq;
171         mLteRssnr = s.mLteRssnr;
172         mLteCqi = s.mLteCqi;
173         isGsm = s.isGsm;
174     }
175 
176     /**
177      * Construct a SignalStrength object from the given parcel.
178      *
179      * @hide
180      */
SignalStrength(Parcel in)181     public SignalStrength(Parcel in) {
182         mGsmSignalStrength = in.readInt();
183         mGsmBitErrorRate = in.readInt();
184         mCdmaDbm = in.readInt();
185         mCdmaEcio = in.readInt();
186         mEvdoDbm = in.readInt();
187         mEvdoEcio = in.readInt();
188         mEvdoSnr = in.readInt();
189         mLteSignalStrength = in.readInt();
190         mLteRsrp = in.readInt();
191         mLteRsrq = in.readInt();
192         mLteRssnr = in.readInt();
193         mLteCqi = in.readInt();
194         isGsm = (in.readInt() != 0);
195     }
196 
197     /**
198      * {@link Parcelable#writeToParcel}
199      */
writeToParcel(Parcel out, int flags)200     public void writeToParcel(Parcel out, int flags) {
201         out.writeInt(mGsmSignalStrength);
202         out.writeInt(mGsmBitErrorRate);
203         out.writeInt(mCdmaDbm);
204         out.writeInt(mCdmaEcio);
205         out.writeInt(mEvdoDbm);
206         out.writeInt(mEvdoEcio);
207         out.writeInt(mEvdoSnr);
208         out.writeInt(mLteSignalStrength);
209         out.writeInt(mLteRsrp);
210         out.writeInt(mLteRsrq);
211         out.writeInt(mLteRssnr);
212         out.writeInt(mLteCqi);
213         out.writeInt(isGsm ? 1 : 0);
214     }
215 
216     /**
217      * {@link Parcelable#describeContents}
218      */
describeContents()219     public int describeContents() {
220         return 0;
221     }
222 
223     /**
224      * {@link Parcelable.Creator}
225      *
226      * @hide
227      */
228     public static final Parcelable.Creator<SignalStrength> CREATOR = new Parcelable.Creator() {
229         public SignalStrength createFromParcel(Parcel in) {
230             return new SignalStrength(in);
231         }
232 
233         public SignalStrength[] newArray(int size) {
234             return new SignalStrength[size];
235         }
236     };
237 
238     /**
239      * Get the GSM Signal Strength, valid values are (0-31, 99) as defined in TS 27.007 8.5
240      */
getGsmSignalStrength()241     public int getGsmSignalStrength() {
242         return this.mGsmSignalStrength;
243     }
244 
245     /**
246      * Get the GSM bit error rate (0-7, 99) as defined in TS 27.007 8.5
247      */
getGsmBitErrorRate()248     public int getGsmBitErrorRate() {
249         return this.mGsmBitErrorRate;
250     }
251 
252     /**
253      * Get the CDMA RSSI value in dBm
254      */
getCdmaDbm()255     public int getCdmaDbm() {
256         return this.mCdmaDbm;
257     }
258 
259     /**
260      * Get the CDMA Ec/Io value in dB*10
261      */
getCdmaEcio()262     public int getCdmaEcio() {
263         return this.mCdmaEcio;
264     }
265 
266     /**
267      * Get the EVDO RSSI value in dBm
268      */
getEvdoDbm()269     public int getEvdoDbm() {
270         return this.mEvdoDbm;
271     }
272 
273     /**
274      * Get the EVDO Ec/Io value in dB*10
275      */
getEvdoEcio()276     public int getEvdoEcio() {
277         return this.mEvdoEcio;
278     }
279 
280     /**
281      * Get the signal to noise ratio. Valid values are 0-8. 8 is the highest.
282      */
getEvdoSnr()283     public int getEvdoSnr() {
284         return this.mEvdoSnr;
285     }
286 
287     /**
288      * Get signal level as an int from 0..4
289      *
290      * @hide
291      */
getLevel()292     public int getLevel() {
293         int level;
294 
295         if (isGsm) {
296             // TODO Need solve the discrepancy of invalid values between
297             // RIL_LTE_SignalStrength and here.
298             if ((mLteSignalStrength == -1)
299                     && (mLteRsrp == -1)
300                     && (mLteRsrq == -1)
301                     && (mLteCqi == -1)) {
302                 level = getGsmLevel();
303             } else {
304                 level = getLteLevel();
305             }
306         } else {
307             int cdmaLevel = getCdmaLevel();
308             int evdoLevel = getEvdoLevel();
309             if (evdoLevel == SIGNAL_STRENGTH_NONE_OR_UNKNOWN) {
310                 /* We don't know evdo, use cdma */
311                 level = getCdmaLevel();
312             } else if (cdmaLevel == SIGNAL_STRENGTH_NONE_OR_UNKNOWN) {
313                 /* We don't know cdma, use evdo */
314                 level = getEvdoLevel();
315             } else {
316                 /* We know both, use the lowest level */
317                 level = cdmaLevel < evdoLevel ? cdmaLevel : evdoLevel;
318             }
319         }
320         if (DBG) log("getLevel=" + level);
321         return level;
322     }
323 
324     /**
325      * Get the signal level as an asu value between 0..31, 99 is unknown
326      *
327      * @hide
328      */
329     public int getAsuLevel() {
330         int asuLevel;
331         if (isGsm) {
332             if ((mLteSignalStrength == -1)
333                     && (mLteRsrp == -1)
334                     && (mLteRsrq == -1)
335                     && (mLteCqi == -1)) {
336                 asuLevel = getGsmAsuLevel();
337             } else {
338                 asuLevel = getLteAsuLevel();
339             }
340         } else {
341             int cdmaAsuLevel = getCdmaAsuLevel();
342             int evdoAsuLevel = getEvdoAsuLevel();
343             if (evdoAsuLevel == 0) {
344                 /* We don't know evdo use, cdma */
345                 asuLevel = cdmaAsuLevel;
346             } else if (cdmaAsuLevel == 0) {
347                 /* We don't know cdma use, evdo */
348                 asuLevel = evdoAsuLevel;
349             } else {
350                 /* We know both, use the lowest level */
351                 asuLevel = cdmaAsuLevel < evdoAsuLevel ? cdmaAsuLevel : evdoAsuLevel;
352             }
353         }
354         if (DBG) log("getAsuLevel=" + asuLevel);
355         return asuLevel;
356     }
357 
358     /**
359      * Get the signal strength as dBm
360      *
361      * @hide
362      */
363     public int getDbm() {
364         int dBm;
365 
366         if(isGsm()) {
367             if ((mLteSignalStrength == -1)
368                     && (mLteRsrp == -1)
369                     && (mLteRsrq == -1)
370                     && (mLteCqi == -1)) {
371                 dBm = getGsmDbm();
372             } else {
373                 dBm = getLteDbm();
374             }
375         } else {
376             dBm = getCdmaDbm();
377         }
378         if (DBG) log("getDbm=" + dBm);
379         return dBm;
380     }
381 
382     /**
383      * Get Gsm signal strength as dBm
384      *
385      * @hide
386      */
387     public int getGsmDbm() {
388         int dBm;
389 
390         int gsmSignalStrength = getGsmSignalStrength();
391         int asu = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
392         if (asu != -1) {
393             dBm = -113 + (2 * asu);
394         } else {
395             dBm = -1;
396         }
397         if (DBG) log("getGsmDbm=" + dBm);
398         return dBm;
399     }
400 
401     /**
402      * Get gsm as level 0..4
403      *
404      * @hide
405      */
406     public int getGsmLevel() {
407         int level;
408 
409         // ASU ranges from 0 to 31 - TS 27.007 Sec 8.5
410         // asu = 0 (-113dB or less) is very weak
411         // signal, its better to show 0 bars to the user in such cases.
412         // asu = 99 is a special case, where the signal strength is unknown.
413         int asu = getGsmSignalStrength();
414         if (asu <= 2 || asu == 99) level = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
415         else if (asu >= 12) level = SIGNAL_STRENGTH_GREAT;
416         else if (asu >= 8)  level = SIGNAL_STRENGTH_GOOD;
417         else if (asu >= 5)  level = SIGNAL_STRENGTH_MODERATE;
418         else level = SIGNAL_STRENGTH_POOR;
419         if (DBG) log("getGsmLevel=" + level);
420         return level;
421     }
422 
423     /**
424      * Get the gsm signal level as an asu value between 0..31, 99 is unknown
425      *
426      * @hide
427      */
getGsmAsuLevel()428     public int getGsmAsuLevel() {
429         // ASU ranges from 0 to 31 - TS 27.007 Sec 8.5
430         // asu = 0 (-113dB or less) is very weak
431         // signal, its better to show 0 bars to the user in such cases.
432         // asu = 99 is a special case, where the signal strength is unknown.
433         int level = getGsmSignalStrength();
434         if (DBG) log("getGsmAsuLevel=" + level);
435         return level;
436     }
437 
438     /**
439      * Get cdma as level 0..4
440      *
441      * @hide
442      */
getCdmaLevel()443     public int getCdmaLevel() {
444         final int cdmaDbm = getCdmaDbm();
445         final int cdmaEcio = getCdmaEcio();
446         int levelDbm;
447         int levelEcio;
448 
449         if (cdmaDbm >= -75) levelDbm = SIGNAL_STRENGTH_GREAT;
450         else if (cdmaDbm >= -85) levelDbm = SIGNAL_STRENGTH_GOOD;
451         else if (cdmaDbm >= -95) levelDbm = SIGNAL_STRENGTH_MODERATE;
452         else if (cdmaDbm >= -100) levelDbm = SIGNAL_STRENGTH_POOR;
453         else levelDbm = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
454 
455         // Ec/Io are in dB*10
456         if (cdmaEcio >= -90) levelEcio = SIGNAL_STRENGTH_GREAT;
457         else if (cdmaEcio >= -110) levelEcio = SIGNAL_STRENGTH_GOOD;
458         else if (cdmaEcio >= -130) levelEcio = SIGNAL_STRENGTH_MODERATE;
459         else if (cdmaEcio >= -150) levelEcio = SIGNAL_STRENGTH_POOR;
460         else levelEcio = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
461 
462         int level = (levelDbm < levelEcio) ? levelDbm : levelEcio;
463         if (DBG) log("getCdmaLevel=" + level);
464         return level;
465     }
466 
467     /**
468      * Get the cdma signal level as an asu value between 0..31, 99 is unknown
469      *
470      * @hide
471      */
getCdmaAsuLevel()472     public int getCdmaAsuLevel() {
473         final int cdmaDbm = getCdmaDbm();
474         final int cdmaEcio = getCdmaEcio();
475         int cdmaAsuLevel;
476         int ecioAsuLevel;
477 
478         if (cdmaDbm >= -75) cdmaAsuLevel = 16;
479         else if (cdmaDbm >= -82) cdmaAsuLevel = 8;
480         else if (cdmaDbm >= -90) cdmaAsuLevel = 4;
481         else if (cdmaDbm >= -95) cdmaAsuLevel = 2;
482         else if (cdmaDbm >= -100) cdmaAsuLevel = 1;
483         else cdmaAsuLevel = 99;
484 
485         // Ec/Io are in dB*10
486         if (cdmaEcio >= -90) ecioAsuLevel = 16;
487         else if (cdmaEcio >= -100) ecioAsuLevel = 8;
488         else if (cdmaEcio >= -115) ecioAsuLevel = 4;
489         else if (cdmaEcio >= -130) ecioAsuLevel = 2;
490         else if (cdmaEcio >= -150) ecioAsuLevel = 1;
491         else ecioAsuLevel = 99;
492 
493         int level = (cdmaAsuLevel < ecioAsuLevel) ? cdmaAsuLevel : ecioAsuLevel;
494         if (DBG) log("getCdmaAsuLevel=" + level);
495         return level;
496     }
497 
498     /**
499      * Get Evdo as level 0..4
500      *
501      * @hide
502      */
getEvdoLevel()503     public int getEvdoLevel() {
504         int evdoDbm = getEvdoDbm();
505         int evdoSnr = getEvdoSnr();
506         int levelEvdoDbm;
507         int levelEvdoSnr;
508 
509         if (evdoDbm >= -65) levelEvdoDbm = SIGNAL_STRENGTH_GREAT;
510         else if (evdoDbm >= -75) levelEvdoDbm = SIGNAL_STRENGTH_GOOD;
511         else if (evdoDbm >= -90) levelEvdoDbm = SIGNAL_STRENGTH_MODERATE;
512         else if (evdoDbm >= -105) levelEvdoDbm = SIGNAL_STRENGTH_POOR;
513         else levelEvdoDbm = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
514 
515         if (evdoSnr >= 7) levelEvdoSnr = SIGNAL_STRENGTH_GREAT;
516         else if (evdoSnr >= 5) levelEvdoSnr = SIGNAL_STRENGTH_GOOD;
517         else if (evdoSnr >= 3) levelEvdoSnr = SIGNAL_STRENGTH_MODERATE;
518         else if (evdoSnr >= 1) levelEvdoSnr = SIGNAL_STRENGTH_POOR;
519         else levelEvdoSnr = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
520 
521         int level = (levelEvdoDbm < levelEvdoSnr) ? levelEvdoDbm : levelEvdoSnr;
522         if (DBG) log("getEvdoLevel=" + level);
523         return level;
524     }
525 
526     /**
527      * Get the evdo signal level as an asu value between 0..31, 99 is unknown
528      *
529      * @hide
530      */
getEvdoAsuLevel()531     public int getEvdoAsuLevel() {
532         int evdoDbm = getEvdoDbm();
533         int evdoSnr = getEvdoSnr();
534         int levelEvdoDbm;
535         int levelEvdoSnr;
536 
537         if (evdoDbm >= -65) levelEvdoDbm = 16;
538         else if (evdoDbm >= -75) levelEvdoDbm = 8;
539         else if (evdoDbm >= -85) levelEvdoDbm = 4;
540         else if (evdoDbm >= -95) levelEvdoDbm = 2;
541         else if (evdoDbm >= -105) levelEvdoDbm = 1;
542         else levelEvdoDbm = 99;
543 
544         if (evdoSnr >= 7) levelEvdoSnr = 16;
545         else if (evdoSnr >= 6) levelEvdoSnr = 8;
546         else if (evdoSnr >= 5) levelEvdoSnr = 4;
547         else if (evdoSnr >= 3) levelEvdoSnr = 2;
548         else if (evdoSnr >= 1) levelEvdoSnr = 1;
549         else levelEvdoSnr = 99;
550 
551         int level = (levelEvdoDbm < levelEvdoSnr) ? levelEvdoDbm : levelEvdoSnr;
552         if (DBG) log("getEvdoAsuLevel=" + level);
553         return level;
554     }
555 
556     /**
557      * Get LTE as dBm
558      *
559      * @hide
560      */
getLteDbm()561     public int getLteDbm() {
562         return mLteRsrp;
563     }
564 
565     /**
566      * Get LTE as level 0..4
567      *
568      * @hide
569      */
getLteLevel()570     public int getLteLevel() {
571         int levelLteRsrp = 0;
572         int levelLteRssnr = 0;
573 
574         if (mLteRsrp == -1) levelLteRsrp = 0;
575         else if (mLteRsrp >= -95) levelLteRsrp = SIGNAL_STRENGTH_GREAT;
576         else if (mLteRsrp >= -105) levelLteRsrp = SIGNAL_STRENGTH_GOOD;
577         else if (mLteRsrp >= -115) levelLteRsrp = SIGNAL_STRENGTH_MODERATE;
578         else levelLteRsrp = SIGNAL_STRENGTH_POOR;
579 
580         if (mLteRssnr == INVALID_SNR) levelLteRssnr = 0;
581         else if (mLteRssnr >= 45) levelLteRssnr = SIGNAL_STRENGTH_GREAT;
582         else if (mLteRssnr >= 10) levelLteRssnr = SIGNAL_STRENGTH_GOOD;
583         else if (mLteRssnr >= -30) levelLteRssnr = SIGNAL_STRENGTH_MODERATE;
584         else levelLteRssnr = SIGNAL_STRENGTH_POOR;
585 
586         int level;
587         if (mLteRsrp == -1)
588             level = levelLteRssnr;
589         else if (mLteRssnr == INVALID_SNR)
590             level = levelLteRsrp;
591         else
592             level = (levelLteRssnr < levelLteRsrp) ? levelLteRssnr : levelLteRsrp;
593 
594         if (DBG) log("Lte rsrp level: "+levelLteRsrp
595                 + " snr level: " + levelLteRssnr + " level: " + level);
596         return level;
597     }
598 
599     /**
600      * Get the LTE signal level as an asu value between 0..97, 99 is unknown
601      * Asu is calculated based on 3GPP RSRP. Refer to 3GPP 27.007 (Ver 10.3.0) Sec 8.69
602      *
603      * @hide
604      */
getLteAsuLevel()605     public int getLteAsuLevel() {
606         int lteAsuLevel = 99;
607         int lteDbm = getLteDbm();
608         if (lteDbm <= -140) lteAsuLevel = 0;
609         else if (lteDbm >= -43) lteAsuLevel = 97;
610         else lteAsuLevel = lteDbm + 140;
611         if (DBG) log("Lte Asu level: "+lteAsuLevel);
612         return lteAsuLevel;
613     }
614 
615     /**
616      * @return true if this is for GSM
617      */
isGsm()618     public boolean isGsm() {
619         return this.isGsm;
620     }
621 
622     /**
623      * @return hash code
624      */
625     @Override
hashCode()626     public int hashCode() {
627         int primeNum = 31;
628         return ((mGsmSignalStrength * primeNum)
629                 + (mGsmBitErrorRate * primeNum)
630                 + (mCdmaDbm * primeNum) + (mCdmaEcio * primeNum)
631                 + (mEvdoDbm * primeNum) + (mEvdoEcio * primeNum) + (mEvdoSnr * primeNum)
632                 + (mLteSignalStrength * primeNum) + (mLteRsrp * primeNum)
633                 + (mLteRsrq * primeNum) + (mLteRssnr * primeNum) + (mLteCqi * primeNum)
634                 + (isGsm ? 1 : 0));
635     }
636 
637     /**
638      * @return true if the signal strengths are the same
639      */
640     @Override
equals(Object o)641     public boolean equals (Object o) {
642         SignalStrength s;
643 
644         try {
645             s = (SignalStrength) o;
646         } catch (ClassCastException ex) {
647             return false;
648         }
649 
650         if (o == null) {
651             return false;
652         }
653 
654         return (mGsmSignalStrength == s.mGsmSignalStrength
655                 && mGsmBitErrorRate == s.mGsmBitErrorRate
656                 && mCdmaDbm == s.mCdmaDbm
657                 && mCdmaEcio == s.mCdmaEcio
658                 && mEvdoDbm == s.mEvdoDbm
659                 && mEvdoEcio == s.mEvdoEcio
660                 && mEvdoSnr == s.mEvdoSnr
661                 && mLteSignalStrength == s.mLteSignalStrength
662                 && mLteRsrp == s.mLteRsrp
663                 && mLteRsrq == s.mLteRsrq
664                 && mLteRssnr == s.mLteRssnr
665                 && mLteCqi == s.mLteCqi
666                 && isGsm == s.isGsm);
667     }
668 
669     /**
670      * @return string representation.
671      */
672     @Override
toString()673     public String toString() {
674         return ("SignalStrength:"
675                 + " " + mGsmSignalStrength
676                 + " " + mGsmBitErrorRate
677                 + " " + mCdmaDbm
678                 + " " + mCdmaEcio
679                 + " " + mEvdoDbm
680                 + " " + mEvdoEcio
681                 + " " + mEvdoSnr
682                 + " " + mLteSignalStrength
683                 + " " + mLteRsrp
684                 + " " + mLteRsrq
685                 + " " + mLteRssnr
686                 + " " + mLteCqi
687                 + " " + (isGsm ? "gsm|lte" : "cdma"));
688     }
689 
690     /**
691      * Set SignalStrength based on intent notifier map
692      *
693      * @param m intent notifier map
694      * @hide
695      */
setFromNotifierBundle(Bundle m)696     private void setFromNotifierBundle(Bundle m) {
697         mGsmSignalStrength = m.getInt("GsmSignalStrength");
698         mGsmBitErrorRate = m.getInt("GsmBitErrorRate");
699         mCdmaDbm = m.getInt("CdmaDbm");
700         mCdmaEcio = m.getInt("CdmaEcio");
701         mEvdoDbm = m.getInt("EvdoDbm");
702         mEvdoEcio = m.getInt("EvdoEcio");
703         mEvdoSnr = m.getInt("EvdoSnr");
704         mLteSignalStrength = m.getInt("LteSignalStrength");
705         mLteRsrp = m.getInt("LteRsrp");
706         mLteRsrq = m.getInt("LteRsrq");
707         mLteRssnr = m.getInt("LteRssnr");
708         mLteCqi = m.getInt("LteCqi");
709         isGsm = m.getBoolean("isGsm");
710     }
711 
712     /**
713      * Set intent notifier Bundle based on SignalStrength
714      *
715      * @param m intent notifier Bundle
716      * @hide
717      */
fillInNotifierBundle(Bundle m)718     public void fillInNotifierBundle(Bundle m) {
719         m.putInt("GsmSignalStrength", mGsmSignalStrength);
720         m.putInt("GsmBitErrorRate", mGsmBitErrorRate);
721         m.putInt("CdmaDbm", mCdmaDbm);
722         m.putInt("CdmaEcio", mCdmaEcio);
723         m.putInt("EvdoDbm", mEvdoDbm);
724         m.putInt("EvdoEcio", mEvdoEcio);
725         m.putInt("EvdoSnr", mEvdoSnr);
726         m.putInt("LteSignalStrength", mLteSignalStrength);
727         m.putInt("LteRsrp", mLteRsrp);
728         m.putInt("LteRsrq", mLteRsrq);
729         m.putInt("LteRssnr", mLteRssnr);
730         m.putInt("LteCqi", mLteCqi);
731         m.putBoolean("isGsm", Boolean.valueOf(isGsm));
732     }
733 
734     /**
735      * log
736      */
log(String s)737     private static void log(String s) {
738         Log.w(LOG_TAG, s);
739     }
740 }
741