@@ -47,7 +47,8 @@ public class SignalStrength implements Parcelable {
4747 };
4848
4949 /** @hide */
50- public static final int INVALID_SNR = 0x7FFFFFFF ;
50+ //Use int max, as -1 is a valid value in signal strength
51+ public static final int INVALID = 0x7FFFFFFF ;
5152
5253 private int mGsmSignalStrength ; // Valid values are (0-31, 99) as defined in TS 27.007 8.5
5354 private int mGsmBitErrorRate ; // bit error rate (0-7, 99) as defined in TS 27.007 8.5
@@ -63,7 +64,6 @@ public class SignalStrength implements Parcelable {
6364 private int mLteCqi ;
6465
6566 private boolean isGsm ; // This value is set by the ServiceStateTracker onSignalStrengthResult
66-
6767 /**
6868 * Create a new SignalStrength from a intent notifier Bundle
6969 *
@@ -95,27 +95,36 @@ public SignalStrength() {
9595 mEvdoDbm = -1 ;
9696 mEvdoEcio = -1 ;
9797 mEvdoSnr = -1 ;
98- mLteSignalStrength = - 1 ;
99- mLteRsrp = - 1 ;
100- mLteRsrq = - 1 ;
101- mLteRssnr = INVALID_SNR ;
102- mLteCqi = - 1 ;
98+ mLteSignalStrength = 99 ;
99+ mLteRsrp = INVALID ;
100+ mLteRsrq = INVALID ;
101+ mLteRssnr = INVALID ;
102+ mLteCqi = INVALID ;
103103 isGsm = true ;
104104 }
105105
106106 /**
107- * Constructor
107+ * This constructor is used to create SignalStrength with default
108+ * values and set the isGsmFlag with the value passed in the input
108109 *
110+ * @param gsmFlag true if Gsm Phone,false if Cdma phone
111+ * @return newly created SignalStrength
109112 * @hide
110113 */
111- public SignalStrength (int gsmSignalStrength , int gsmBitErrorRate ,
112- int cdmaDbm , int cdmaEcio ,
113- int evdoDbm , int evdoEcio , int evdoSnr ,
114- int lteSignalStrength , int lteRsrp , int lteRsrq , int lteRssnr , int lteCqi ,
115- boolean gsm ) {
116- initialize (gsmSignalStrength , gsmBitErrorRate , cdmaDbm , cdmaEcio ,
117- evdoDbm , evdoEcio , evdoSnr , lteSignalStrength , lteRsrp ,
118- lteRsrq , lteRssnr , lteCqi , gsm );
114+ public SignalStrength (boolean gsmFlag ) {
115+ mGsmSignalStrength = 99 ;
116+ mGsmBitErrorRate = -1 ;
117+ mCdmaDbm = -1 ;
118+ mCdmaEcio = -1 ;
119+ mEvdoDbm = -1 ;
120+ mEvdoEcio = -1 ;
121+ mEvdoSnr = -1 ;
122+ mLteSignalStrength = 99 ;
123+ mLteRsrp = INVALID ;
124+ mLteRsrq = INVALID ;
125+ mLteRssnr = INVALID ;
126+ mLteCqi = INVALID ;
127+ isGsm = gsmFlag ;
119128 }
120129
121130 /**
@@ -124,68 +133,6 @@ public SignalStrength(int gsmSignalStrength, int gsmBitErrorRate,
124133 * @hide
125134 */
126135 public SignalStrength (int gsmSignalStrength , int gsmBitErrorRate ,
127- int cdmaDbm , int cdmaEcio ,
128- int evdoDbm , int evdoEcio , int evdoSnr ,
129- boolean gsm ) {
130- initialize (gsmSignalStrength , gsmBitErrorRate , cdmaDbm , cdmaEcio ,
131- evdoDbm , evdoEcio , evdoSnr , -1 , -1 ,
132- -1 , INVALID_SNR , -1 , gsm );
133- }
134-
135- /**
136- * Copy constructors
137- *
138- * @param s Source SignalStrength
139- *
140- * @hide
141- */
142- public SignalStrength (SignalStrength s ) {
143- copyFrom (s );
144- }
145-
146- /**
147- * Initialize gsm/cdma values, sets lte values to defaults.
148- *
149- * @param gsmSignalStrength
150- * @param gsmBitErrorRate
151- * @param cdmaDbm
152- * @param cdmaEcio
153- * @param evdoDbm
154- * @param evdoEcio
155- * @param evdoSnr
156- * @param gsm
157- *
158- * @hide
159- */
160- public void initialize (int gsmSignalStrength , int gsmBitErrorRate ,
161- int cdmaDbm , int cdmaEcio ,
162- int evdoDbm , int evdoEcio , int evdoSnr ,
163- boolean gsm ) {
164- initialize (gsmSignalStrength , gsmBitErrorRate , cdmaDbm , cdmaEcio ,
165- evdoDbm , evdoEcio , evdoSnr , -1 , -1 ,
166- -1 , INVALID_SNR , -1 , gsm );
167- }
168-
169- /**
170- * Initialize all the values
171- *
172- * @param gsmSignalStrength
173- * @param gsmBitErrorRate
174- * @param cdmaDbm
175- * @param cdmaEcio
176- * @param evdoDbm
177- * @param evdoEcio
178- * @param evdoSnr
179- * @param lteSignalStrength
180- * @param lteRsrp
181- * @param lteRsrq
182- * @param lteRssnr
183- * @param lteCqi
184- * @param gsm
185- *
186- * @hide
187- */
188- public void initialize (int gsmSignalStrength , int gsmBitErrorRate ,
189136 int cdmaDbm , int cdmaEcio ,
190137 int evdoDbm , int evdoEcio , int evdoSnr ,
191138 int lteSignalStrength , int lteRsrp , int lteRsrq , int lteRssnr , int lteCqi ,
@@ -288,7 +235,54 @@ public SignalStrength[] newArray(int size) {
288235 };
289236
290237 /**
291- * Get the GSM Signal Strength, valid values are (0-31, 99) as defined in TS 27.007 8.5
238+ * Validate the individual signal strength fields as per the range
239+ * specified in ril.h
240+ * Set to invalid any field that is not in the valid range
241+ * Cdma, evdo, lte rsrp & rsrq values are sign converted
242+ * when received from ril interface
243+ *
244+ * @return
245+ * Valid values for all signalstrength fields
246+ * @hide
247+ */
248+ public void validateInput () {
249+ if (DBG ) log ("Signal before validate=" + this );
250+ // TS 27.007 8.5
251+ mGsmSignalStrength = mGsmSignalStrength >= 0 ? mGsmSignalStrength : 99 ;
252+ // BER no change;
253+
254+ mCdmaDbm = mCdmaDbm > 0 ? -mCdmaDbm : -120 ;
255+ mCdmaEcio = (mCdmaEcio > 0 ) ? -mCdmaEcio : -160 ;
256+
257+ mEvdoDbm = (mEvdoDbm > 0 ) ? -mEvdoDbm : -120 ;
258+ mEvdoEcio = (mEvdoEcio > 0 ) ? -mEvdoEcio : -1 ;
259+ mEvdoSnr = ((mEvdoSnr > 0 ) && (mEvdoSnr <= 8 )) ? mEvdoSnr : -1 ;
260+
261+ // TS 36.214 Physical Layer Section 5.1.3, TS 36.331 RRC
262+ mLteSignalStrength = (mLteSignalStrength >= 0 ) ? mLteSignalStrength : 99 ;
263+ mLteRsrp = ((mLteRsrp >= 44 ) && (mLteRsrp <= 140 )) ? -mLteRsrp : SignalStrength .INVALID ;
264+ mLteRsrq = ((mLteRsrq >= 3 ) && (mLteRsrq <= 20 )) ? -mLteRsrq : SignalStrength .INVALID ;
265+ mLteRssnr = ((mLteRssnr >= -200 ) && (mLteRssnr <= 300 )) ? mLteRssnr
266+ : SignalStrength .INVALID ;
267+ // Cqi no change
268+ if (DBG ) log ("Signal after validate=" + this );
269+ }
270+
271+ /**
272+ * @param true - Gsm, Lte phones
273+ * false - Cdma phones
274+ *
275+ * Used by voice phone to set the isGsm
276+ * flag
277+ * @hide
278+ */
279+ public void setGsm (boolean gsmFlag ) {
280+ isGsm = gsmFlag ;
281+ }
282+
283+ /**
284+ * Get the GSM Signal Strength, valid values are (0-31, 99) as defined in TS
285+ * 27.007 8.5
292286 */
293287 public int getGsmSignalStrength () {
294288 return this .mGsmSignalStrength ;
@@ -345,25 +339,19 @@ public int getLevel() {
345339 int level ;
346340
347341 if (isGsm ) {
348- // TODO Need solve the discrepancy of invalid values between
349- // RIL_LTE_SignalStrength and here.
350- if ((mLteSignalStrength == -1 )
351- && (mLteRsrp == -1 )
352- && (mLteRsrq == -1 )
353- && (mLteCqi == -1 )) {
342+ level = getLteLevel ();
343+ if (level == SIGNAL_STRENGTH_NONE_OR_UNKNOWN ) {
354344 level = getGsmLevel ();
355- } else {
356- level = getLteLevel ();
357345 }
358346 } else {
359347 int cdmaLevel = getCdmaLevel ();
360348 int evdoLevel = getEvdoLevel ();
361349 if (evdoLevel == SIGNAL_STRENGTH_NONE_OR_UNKNOWN ) {
362350 /* We don't know evdo, use cdma */
363- level = getCdmaLevel () ;
351+ level = cdmaLevel ;
364352 } else if (cdmaLevel == SIGNAL_STRENGTH_NONE_OR_UNKNOWN ) {
365353 /* We don't know cdma, use evdo */
366- level = getEvdoLevel () ;
354+ level = evdoLevel ;
367355 } else {
368356 /* We know both, use the lowest level */
369357 level = cdmaLevel < evdoLevel ? cdmaLevel : evdoLevel ;
@@ -381,10 +369,7 @@ public int getLevel() {
381369 public int getAsuLevel () {
382370 int asuLevel ;
383371 if (isGsm ) {
384- if ((mLteSignalStrength == -1 )
385- && (mLteRsrp == -1 )
386- && (mLteRsrq == -1 )
387- && (mLteCqi == -1 )) {
372+ if (getLteLevel () == SIGNAL_STRENGTH_NONE_OR_UNKNOWN ) {
388373 asuLevel = getGsmAsuLevel ();
389374 } else {
390375 asuLevel = getLteAsuLevel ();
@@ -416,16 +401,17 @@ public int getDbm() {
416401 int dBm ;
417402
418403 if (isGsm ()) {
419- if ((mLteSignalStrength == -1 )
420- && (mLteRsrp == -1 )
421- && (mLteRsrq == -1 )
422- && (mLteCqi == -1 )) {
404+ if (getLteLevel () == SIGNAL_STRENGTH_NONE_OR_UNKNOWN ) {
423405 dBm = getGsmDbm ();
424406 } else {
425407 dBm = getLteDbm ();
426408 }
427409 } else {
428- dBm = getCdmaDbm ();
410+ int cdmaDbm = getCdmaDbm ();
411+ int evdoDbm = getEvdoDbm ();
412+
413+ return (evdoDbm == -120 ) ? cdmaDbm : ((cdmaDbm == -120 ) ? evdoDbm
414+ : (cdmaDbm < evdoDbm ? cdmaDbm : evdoDbm ));
429415 }
430416 if (DBG ) log ("getDbm=" + dBm );
431417 return dBm ;
@@ -620,34 +606,63 @@ public int getLteDbm() {
620606 * @hide
621607 */
622608 public int getLteLevel () {
623- int levelLteRsrp = 0 ;
624- int levelLteRssnr = 0 ;
609+ /*
610+ * TS 36.214 Physical Layer Section 5.1.3 TS 36.331 RRC RSSI = received
611+ * signal + noise RSRP = reference signal dBm RSRQ = quality of signal
612+ * dB= Number of Resource blocksxRSRP/RSSI SNR = gain=signal/noise ratio
613+ * = -10log P1/P2 dB
614+ */
615+ int rssiIconLevel = SIGNAL_STRENGTH_NONE_OR_UNKNOWN , rsrpIconLevel = -1 , snrIconLevel = -1 ;
616+
617+ if (mLteRsrp > -44 ) rsrpIconLevel = -1 ;
618+ else if (mLteRsrp >= -85 ) rsrpIconLevel = SIGNAL_STRENGTH_GREAT ;
619+ else if (mLteRsrp >= -95 ) rsrpIconLevel = SIGNAL_STRENGTH_GOOD ;
620+ else if (mLteRsrp >= -105 ) rsrpIconLevel = SIGNAL_STRENGTH_MODERATE ;
621+ else if (mLteRsrp >= -115 ) rsrpIconLevel = SIGNAL_STRENGTH_POOR ;
622+ else if (mLteRsrp >= -140 ) rsrpIconLevel = SIGNAL_STRENGTH_NONE_OR_UNKNOWN ;
623+
624+ /*
625+ * Values are -200 dB to +300 (SNR*10dB) RS_SNR >= 13.0 dB =>4 bars 4.5
626+ * dB <= RS_SNR < 13.0 dB => 3 bars 1.0 dB <= RS_SNR < 4.5 dB => 2 bars
627+ * -3.0 dB <= RS_SNR < 1.0 dB 1 bar RS_SNR < -3.0 dB/No Service Antenna
628+ * Icon Only
629+ */
630+ if (mLteRssnr > 300 ) snrIconLevel = -1 ;
631+ else if (mLteRssnr >= 130 ) snrIconLevel = SIGNAL_STRENGTH_GREAT ;
632+ else if (mLteRssnr >= 45 ) snrIconLevel = SIGNAL_STRENGTH_GOOD ;
633+ else if (mLteRssnr >= 10 ) snrIconLevel = SIGNAL_STRENGTH_MODERATE ;
634+ else if (mLteRssnr >= -30 ) snrIconLevel = SIGNAL_STRENGTH_POOR ;
635+ else if (mLteRssnr >= -200 )
636+ snrIconLevel = SIGNAL_STRENGTH_NONE_OR_UNKNOWN ;
637+
638+ if (DBG ) log ("getLTELevel - rsrp:" + mLteRsrp + " snr:" + mLteRssnr + " rsrpIconLevel:"
639+ + rsrpIconLevel + " snrIconLevel:" + snrIconLevel );
640+
641+ /* Choose a measurement type to use for notification */
642+ if (snrIconLevel != -1 && rsrpIconLevel != -1 ) {
643+ /*
644+ * The number of bars displayed shall be the smaller of the bars
645+ * associated with LTE RSRP and the bars associated with the LTE
646+ * RS_SNR
647+ */
648+ return (rsrpIconLevel < snrIconLevel ? rsrpIconLevel : snrIconLevel );
649+ }
625650
626- if (mLteRsrp == -1 ) levelLteRsrp = 0 ;
627- else if (mLteRsrp >= -95 ) levelLteRsrp = SIGNAL_STRENGTH_GREAT ;
628- else if (mLteRsrp >= -105 ) levelLteRsrp = SIGNAL_STRENGTH_GOOD ;
629- else if (mLteRsrp >= -115 ) levelLteRsrp = SIGNAL_STRENGTH_MODERATE ;
630- else levelLteRsrp = SIGNAL_STRENGTH_POOR ;
651+ if (snrIconLevel != -1 ) return snrIconLevel ;
631652
632- if (mLteRssnr == INVALID_SNR ) levelLteRssnr = 0 ;
633- else if (mLteRssnr >= 45 ) levelLteRssnr = SIGNAL_STRENGTH_GREAT ;
634- else if (mLteRssnr >= 10 ) levelLteRssnr = SIGNAL_STRENGTH_GOOD ;
635- else if (mLteRssnr >= -30 ) levelLteRssnr = SIGNAL_STRENGTH_MODERATE ;
636- else levelLteRssnr = SIGNAL_STRENGTH_POOR ;
653+ if (rsrpIconLevel != -1 ) return rsrpIconLevel ;
637654
638- int level ;
639- if (mLteRsrp == -1 )
640- level = levelLteRssnr ;
641- else if (mLteRssnr == INVALID_SNR )
642- level = levelLteRsrp ;
643- else
644- level = (levelLteRssnr < levelLteRsrp ) ? levelLteRssnr : levelLteRsrp ;
645-
646- if (DBG ) log ("Lte rsrp level: " +levelLteRsrp
647- + " snr level: " + levelLteRssnr + " level: " + level );
648- return level ;
649- }
655+ /* Valid values are (0-63, 99) as defined in TS 36.331 */
656+ if (mLteSignalStrength > 63 ) rssiIconLevel = SIGNAL_STRENGTH_NONE_OR_UNKNOWN ;
657+ else if (mLteSignalStrength >= 12 ) rssiIconLevel = SIGNAL_STRENGTH_GREAT ;
658+ else if (mLteSignalStrength >= 8 ) rssiIconLevel = SIGNAL_STRENGTH_GOOD ;
659+ else if (mLteSignalStrength >= 5 ) rssiIconLevel = SIGNAL_STRENGTH_MODERATE ;
660+ else if (mLteSignalStrength >= 0 ) rssiIconLevel = SIGNAL_STRENGTH_POOR ;
661+ if (DBG ) log ("getLTELevel - rssi:" + mLteSignalStrength + " rssiIconLevel:"
662+ + rssiIconLevel );
663+ return rssiIconLevel ;
650664
665+ }
651666 /**
652667 * Get the LTE signal level as an asu value between 0..97, 99 is unknown
653668 * Asu is calculated based on 3GPP RSRP. Refer to 3GPP 27.007 (Ver 10.3.0) Sec 8.69
@@ -657,8 +672,20 @@ else if (mLteRssnr == INVALID_SNR)
657672 public int getLteAsuLevel () {
658673 int lteAsuLevel = 99 ;
659674 int lteDbm = getLteDbm ();
660- if (lteDbm <= -140 ) lteAsuLevel = 0 ;
661- else if (lteDbm >= -43 ) lteAsuLevel = 97 ;
675+ /*
676+ * 3GPP 27.007 (Ver 10.3.0) Sec 8.69
677+ * 0 -140 dBm or less
678+ * 1 -139 dBm
679+ * 2...96 -138... -44 dBm
680+ * 97 -43 dBm or greater
681+ * 255 not known or not detectable
682+ */
683+ /*
684+ * validateInput will always give a valid range between -140 t0 -44 as
685+ * per ril.h. so RSRP >= -43 & <-140 will fall under asu level 255
686+ * and not 97 or 0
687+ */
688+ if (lteDbm == SignalStrength .INVALID ) lteAsuLevel = 255 ;
662689 else lteAsuLevel = lteDbm + 140 ;
663690 if (DBG ) log ("Lte Asu level: " +lteAsuLevel );
664691 return lteAsuLevel ;
0 commit comments