@@ -48,7 +48,8 @@ public class SignalStrength implements Parcelable {
4848 };
4949
5050 /** @hide */
51- public static final int INVALID_SNR = 0x7FFFFFFF ;
51+ //Use int max, as -1 is a valid value in signal strength
52+ public static final int INVALID = 0x7FFFFFFF ;
5253
5354 private int mGsmSignalStrength ; // Valid values are (0-31, 99) as defined in TS 27.007 8.5
5455 private int mGsmBitErrorRate ; // bit error rate (0-7, 99) as defined in TS 27.007 8.5
@@ -64,7 +65,6 @@ public class SignalStrength implements Parcelable {
6465 private int mLteCqi ;
6566
6667 private boolean isGsm ; // This value is set by the ServiceStateTracker onSignalStrengthResult
67-
6868 /**
6969 * Create a new SignalStrength from a intent notifier Bundle
7070 *
@@ -96,14 +96,38 @@ public SignalStrength() {
9696 mEvdoDbm = -1 ;
9797 mEvdoEcio = -1 ;
9898 mEvdoSnr = -1 ;
99- mLteSignalStrength = - 1 ;
100- mLteRsrp = - 1 ;
101- mLteRsrq = - 1 ;
102- mLteRssnr = INVALID_SNR ;
103- mLteCqi = - 1 ;
99+ mLteSignalStrength = 99 ;
100+ mLteRsrp = INVALID ;
101+ mLteRsrq = INVALID ;
102+ mLteRssnr = INVALID ;
103+ mLteCqi = INVALID ;
104104 isGsm = true ;
105105 }
106106
107+ /**
108+ * This constructor is used to create SignalStrength with default
109+ * values and set the isGsmFlag with the value passed in the input
110+ *
111+ * @param gsmFlag true if Gsm Phone,false if Cdma phone
112+ * @return newly created SignalStrength
113+ * @hide
114+ */
115+ public SignalStrength (boolean gsmFlag ) {
116+ mGsmSignalStrength = 99 ;
117+ mGsmBitErrorRate = -1 ;
118+ mCdmaDbm = -1 ;
119+ mCdmaEcio = -1 ;
120+ mEvdoDbm = -1 ;
121+ mEvdoEcio = -1 ;
122+ mEvdoSnr = -1 ;
123+ mLteSignalStrength = 99 ;
124+ mLteRsrp = INVALID ;
125+ mLteRsrq = INVALID ;
126+ mLteRssnr = INVALID ;
127+ mLteCqi = INVALID ;
128+ isGsm = gsmFlag ;
129+ }
130+
107131 /**
108132 * Constructor
109133 *
@@ -138,9 +162,8 @@ public SignalStrength(int gsmSignalStrength, int gsmBitErrorRate,
138162 int cdmaDbm , int cdmaEcio ,
139163 int evdoDbm , int evdoEcio , int evdoSnr ,
140164 boolean gsm ) {
141- this (gsmSignalStrength , gsmBitErrorRate , cdmaDbm , cdmaEcio ,
142- evdoDbm , evdoEcio , evdoSnr , -1 , -1 ,
143- -1 , INVALID_SNR , -1 , gsm );
165+ this (gsmSignalStrength , gsmBitErrorRate , cdmaDbm , cdmaEcio , evdoDbm , evdoEcio , evdoSnr , 99 ,
166+ INVALID , INVALID , INVALID , INVALID , gsm );
144167 }
145168
146169 /**
@@ -236,7 +259,54 @@ public SignalStrength[] newArray(int size) {
236259 };
237260
238261 /**
239- * Get the GSM Signal Strength, valid values are (0-31, 99) as defined in TS 27.007 8.5
262+ * Validate the individual signal strength fields as per the range
263+ * specified in ril.h
264+ * Set to invalid any field that is not in the valid range
265+ * Cdma, evdo, lte rsrp & rsrq values are sign converted
266+ * when received from ril interface
267+ *
268+ * @return
269+ * Valid values for all signalstrength fields
270+ * @hide
271+ */
272+ public void validateInput () {
273+ if (DBG ) log ("Signal before validate=" + this );
274+ // TS 27.007 8.5
275+ mGsmSignalStrength = mGsmSignalStrength >= 0 ? mGsmSignalStrength : 99 ;
276+ // BER no change;
277+
278+ mCdmaDbm = mCdmaDbm > 0 ? -mCdmaDbm : -120 ;
279+ mCdmaEcio = (mCdmaEcio > 0 ) ? -mCdmaEcio : -160 ;
280+
281+ mEvdoDbm = (mEvdoDbm > 0 ) ? -mEvdoDbm : -120 ;
282+ mEvdoEcio = (mEvdoEcio > 0 ) ? -mEvdoEcio : -1 ;
283+ mEvdoSnr = ((mEvdoSnr > 0 ) && (mEvdoSnr <= 8 )) ? mEvdoSnr : -1 ;
284+
285+ // TS 36.214 Physical Layer Section 5.1.3, TS 36.331 RRC
286+ mLteSignalStrength = (mLteSignalStrength >= 0 ) ? mLteSignalStrength : 99 ;
287+ mLteRsrp = ((mLteRsrp >= 44 ) && (mLteRsrp <= 140 )) ? -mLteRsrp : SignalStrength .INVALID ;
288+ mLteRsrq = ((mLteRsrq >= 3 ) && (mLteRsrq <= 20 )) ? -mLteRsrq : SignalStrength .INVALID ;
289+ mLteRssnr = ((mLteRssnr >= -200 ) && (mLteRssnr <= 300 )) ? mLteRssnr
290+ : SignalStrength .INVALID ;
291+ // Cqi no change
292+ if (DBG ) log ("Signal after validate=" + this );
293+ }
294+
295+ /**
296+ * @param true - Gsm, Lte phones
297+ * false - Cdma phones
298+ *
299+ * Used by voice phone to set the isGsm
300+ * flag
301+ * @hide
302+ */
303+ public void setGsm (boolean gsmFlag ) {
304+ isGsm = gsmFlag ;
305+ }
306+
307+ /**
308+ * Get the GSM Signal Strength, valid values are (0-31, 99) as defined in TS
309+ * 27.007 8.5
240310 */
241311 public int getGsmSignalStrength () {
242312 return this .mGsmSignalStrength ;
@@ -293,25 +363,19 @@ public int getLevel() {
293363 int level ;
294364
295365 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 )) {
366+ level = getLteLevel ();
367+ if (level == SIGNAL_STRENGTH_NONE_OR_UNKNOWN ) {
302368 level = getGsmLevel ();
303- } else {
304- level = getLteLevel ();
305369 }
306370 } else {
307371 int cdmaLevel = getCdmaLevel ();
308372 int evdoLevel = getEvdoLevel ();
309373 if (evdoLevel == SIGNAL_STRENGTH_NONE_OR_UNKNOWN ) {
310374 /* We don't know evdo, use cdma */
311- level = getCdmaLevel () ;
375+ level = cdmaLevel ;
312376 } else if (cdmaLevel == SIGNAL_STRENGTH_NONE_OR_UNKNOWN ) {
313377 /* We don't know cdma, use evdo */
314- level = getEvdoLevel () ;
378+ level = evdoLevel ;
315379 } else {
316380 /* We know both, use the lowest level */
317381 level = cdmaLevel < evdoLevel ? cdmaLevel : evdoLevel ;
@@ -329,10 +393,7 @@ public int getLevel() {
329393 public int getAsuLevel () {
330394 int asuLevel ;
331395 if (isGsm ) {
332- if ((mLteSignalStrength == -1 )
333- && (mLteRsrp == -1 )
334- && (mLteRsrq == -1 )
335- && (mLteCqi == -1 )) {
396+ if (getLteLevel () == SIGNAL_STRENGTH_NONE_OR_UNKNOWN ) {
336397 asuLevel = getGsmAsuLevel ();
337398 } else {
338399 asuLevel = getLteAsuLevel ();
@@ -364,16 +425,17 @@ public int getDbm() {
364425 int dBm ;
365426
366427 if (isGsm ()) {
367- if ((mLteSignalStrength == -1 )
368- && (mLteRsrp == -1 )
369- && (mLteRsrq == -1 )
370- && (mLteCqi == -1 )) {
428+ if (getLteLevel () == SIGNAL_STRENGTH_NONE_OR_UNKNOWN ) {
371429 dBm = getGsmDbm ();
372430 } else {
373431 dBm = getLteDbm ();
374432 }
375433 } else {
376- dBm = getCdmaDbm ();
434+ int cdmaDbm = getCdmaDbm ();
435+ int evdoDbm = getEvdoDbm ();
436+
437+ return (evdoDbm == -120 ) ? cdmaDbm : ((cdmaDbm == -120 ) ? evdoDbm
438+ : (cdmaDbm < evdoDbm ? cdmaDbm : evdoDbm ));
377439 }
378440 if (DBG ) log ("getDbm=" + dBm );
379441 return dBm ;
@@ -568,34 +630,63 @@ public int getLteDbm() {
568630 * @hide
569631 */
570632 public int getLteLevel () {
571- int levelLteRsrp = 0 ;
572- int levelLteRssnr = 0 ;
633+ /*
634+ * TS 36.214 Physical Layer Section 5.1.3 TS 36.331 RRC RSSI = received
635+ * signal + noise RSRP = reference signal dBm RSRQ = quality of signal
636+ * dB= Number of Resource blocksxRSRP/RSSI SNR = gain=signal/noise ratio
637+ * = -10log P1/P2 dB
638+ */
639+ int rssiIconLevel = SIGNAL_STRENGTH_NONE_OR_UNKNOWN , rsrpIconLevel = -1 , snrIconLevel = -1 ;
640+
641+ if (mLteRsrp > -44 ) rsrpIconLevel = -1 ;
642+ else if (mLteRsrp >= -85 ) rsrpIconLevel = SIGNAL_STRENGTH_GREAT ;
643+ else if (mLteRsrp >= -95 ) rsrpIconLevel = SIGNAL_STRENGTH_GOOD ;
644+ else if (mLteRsrp >= -105 ) rsrpIconLevel = SIGNAL_STRENGTH_MODERATE ;
645+ else if (mLteRsrp >= -115 ) rsrpIconLevel = SIGNAL_STRENGTH_POOR ;
646+ else if (mLteRsrp >= -140 ) rsrpIconLevel = SIGNAL_STRENGTH_NONE_OR_UNKNOWN ;
647+
648+ /*
649+ * Values are -200 dB to +300 (SNR*10dB) RS_SNR >= 13.0 dB =>4 bars 4.5
650+ * dB <= RS_SNR < 13.0 dB => 3 bars 1.0 dB <= RS_SNR < 4.5 dB => 2 bars
651+ * -3.0 dB <= RS_SNR < 1.0 dB 1 bar RS_SNR < -3.0 dB/No Service Antenna
652+ * Icon Only
653+ */
654+ if (mLteRssnr > 300 ) snrIconLevel = -1 ;
655+ else if (mLteRssnr >= 130 ) snrIconLevel = SIGNAL_STRENGTH_GREAT ;
656+ else if (mLteRssnr >= 45 ) snrIconLevel = SIGNAL_STRENGTH_GOOD ;
657+ else if (mLteRssnr >= 10 ) snrIconLevel = SIGNAL_STRENGTH_MODERATE ;
658+ else if (mLteRssnr >= -30 ) snrIconLevel = SIGNAL_STRENGTH_POOR ;
659+ else if (mLteRssnr >= -200 )
660+ snrIconLevel = SIGNAL_STRENGTH_NONE_OR_UNKNOWN ;
661+
662+ if (DBG ) log ("getLTELevel - rsrp:" + mLteRsrp + " snr:" + mLteRssnr + " rsrpIconLevel:"
663+ + rsrpIconLevel + " snrIconLevel:" + snrIconLevel );
664+
665+ /* Choose a measurement type to use for notification */
666+ if (snrIconLevel != -1 && rsrpIconLevel != -1 ) {
667+ /*
668+ * The number of bars displayed shall be the smaller of the bars
669+ * associated with LTE RSRP and the bars associated with the LTE
670+ * RS_SNR
671+ */
672+ return (rsrpIconLevel < snrIconLevel ? rsrpIconLevel : snrIconLevel );
673+ }
573674
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 ;
675+ if (snrIconLevel != -1 ) return snrIconLevel ;
579676
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 ;
677+ if (rsrpIconLevel != -1 ) return rsrpIconLevel ;
585678
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- }
679+ /* Valid values are (0-63, 99) as defined in TS 36.331 */
680+ if (mLteSignalStrength > 63 ) rssiIconLevel = SIGNAL_STRENGTH_NONE_OR_UNKNOWN ;
681+ else if (mLteSignalStrength >= 12 ) rssiIconLevel = SIGNAL_STRENGTH_GREAT ;
682+ else if (mLteSignalStrength >= 8 ) rssiIconLevel = SIGNAL_STRENGTH_GOOD ;
683+ else if (mLteSignalStrength >= 5 ) rssiIconLevel = SIGNAL_STRENGTH_MODERATE ;
684+ else if (mLteSignalStrength >= 0 ) rssiIconLevel = SIGNAL_STRENGTH_POOR ;
685+ if (DBG ) log ("getLTELevel - rssi:" + mLteSignalStrength + " rssiIconLevel:"
686+ + rssiIconLevel );
687+ return rssiIconLevel ;
598688
689+ }
599690 /**
600691 * Get the LTE signal level as an asu value between 0..97, 99 is unknown
601692 * Asu is calculated based on 3GPP RSRP. Refer to 3GPP 27.007 (Ver 10.3.0) Sec 8.69
@@ -605,8 +696,20 @@ else if (mLteRssnr == INVALID_SNR)
605696 public int getLteAsuLevel () {
606697 int lteAsuLevel = 99 ;
607698 int lteDbm = getLteDbm ();
608- if (lteDbm <= -140 ) lteAsuLevel = 0 ;
609- else if (lteDbm >= -43 ) lteAsuLevel = 97 ;
699+ /*
700+ * 3GPP 27.007 (Ver 10.3.0) Sec 8.69
701+ * 0 -140 dBm or less
702+ * 1 -139 dBm
703+ * 2...96 -138... -44 dBm
704+ * 97 -43 dBm or greater
705+ * 255 not known or not detectable
706+ */
707+ /*
708+ * validateInput will always give a valid range between -140 t0 -44 as
709+ * per ril.h. so RSRP >= -43 & <-140 will fall under asu level 255
710+ * and not 97 or 0
711+ */
712+ if (lteDbm == SignalStrength .INVALID ) lteAsuLevel = 255 ;
610713 else lteAsuLevel = lteDbm + 140 ;
611714 if (DBG ) log ("Lte Asu level: " +lteAsuLevel );
612715 return lteAsuLevel ;
0 commit comments