[Zooper Widget General] brizey:
OK.

So I have this almost completely figured out.

Here is the git for how Android does signal bars for LTE:

/**
* Get LTE as level 0..4
*
* @hide
*/
public int getLteLevel() {
/*
* TS 36.214 Physical Layer Section 5.1.3 TS 36.331 RRC RSSI = received
* signal + noise RSRP = reference signal dBm RSRQ = quality of signal
* dB= Number of Resource blocksxRSRP/RSSI SNR = gain=signal/noise ratio
* = -10log P1/P2 dB
*/
int rssiIconLevel = SIGNAL_STRENGTH_NONE_OR_UNKNOWN, rsrpIconLevel = -1, snrIconLevel = -1;

if (mLteRsrp > -44) rsrpIconLevel = -1;
else if (mLteRsrp >= -85) rsrpIconLevel = SIGNAL_STRENGTH_GREAT;
else if (mLteRsrp >= -95) rsrpIconLevel = SIGNAL_STRENGTH_GOOD;
else if (mLteRsrp >= -105) rsrpIconLevel = SIGNAL_STRENGTH_MODERATE;
else if (mLteRsrp >= -115) rsrpIconLevel = SIGNAL_STRENGTH_POOR;
else if (mLteRsrp >= -140) rsrpIconLevel = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;

/*
* Values are -200 dB to +300 (SNR*10dB) RS_SNR >= 13.0 dB =>4 bars 4.5
* dB <= RS_SNR < 13.0 dB => 3 bars 1.0 dB <= RS_SNR < 4.5 dB => 2 bars
* -3.0 dB <= RS_SNR < 1.0 dB 1 bar RS_SNR < -3.0 dB/No Service Antenna
* Icon Only
*/
if (mLteRssnr > 300) snrIconLevel = -1;
else if (mLteRssnr >= 130) snrIconLevel = SIGNAL_STRENGTH_GREAT;
else if (mLteRssnr >= 45) snrIconLevel = SIGNAL_STRENGTH_GOOD;
else if (mLteRssnr >= 10) snrIconLevel = SIGNAL_STRENGTH_MODERATE;
else if (mLteRssnr >= -30) snrIconLevel = SIGNAL_STRENGTH_POOR;
else if (mLteRssnr >= -200)
snrIconLevel = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;

if (DBG) log("getLTELevel - rsrp:" + mLteRsrp + " snr:" + mLteRssnr + " rsrpIconLevel:"
+ rsrpIconLevel + " snrIconLevel:" + snrIconLevel);

/* Choose a measurement type to use for notification */
if (snrIconLevel != -1 && rsrpIconLevel != -1) {
/*
* The number of bars displayed shall be the smaller of the bars
* associated with LTE RSRP and the bars associated with the LTE
* RS_SNR
*/
return (rsrpIconLevel < snrIconLevel ? rsrpIconLevel : snrIconLevel);
}

if (snrIconLevel != -1) return snrIconLevel;

if (rsrpIconLevel != -1) return rsrpIconLevel;

/* Valid values are (0-63, 99) as defined in TS 36.331 */
if (mLteSignalStrength > 63) rssiIconLevel = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
else if (mLteSignalStrength >= 12) rssiIconLevel = SIGNAL_STRENGTH_GREAT;
else if (mLteSignalStrength >= 8) rssiIconLevel = SIGNAL_STRENGTH_GOOD;
else if (mLteSignalStrength >= 5) rssiIconLevel = SIGNAL_STRENGTH_MODERATE;
else if (mLteSignalStrength >= 0) rssiIconLevel = SIGNAL_STRENGTH_POOR;
if (DBG) log("getLTELevel - rssi:" + mLteSignalStrength + " rssiIconLevel:"
+ rssiIconLevel);
return rssiIconLevel;

}

And here are where these values are in the variable mSignalStrength that falls out of my script above:

public String toString() {
return ("SignalStrength:"
+ " " + mGsmSignalStrength
+ " " + mGsmBitErrorRate
+ " " + mCdmaDbm
+ " " + mCdmaEcio
+ " " + mEvdoDbm
+ " " + mEvdoEcio
+ " " + mEvdoSnr
+ " " + mLteSignalStrength
+ " " + mLteRsrp
+ " " + mLteRsrq
+ " " + mLteRssnr
+ " " + mLteCqi
+ " " + (isGsm ? "gsm|lte" : "cdma"));
}

Because of the way it gets parsed out of the dumpsys, mLteRsrp is field 12, mLteRssnr is field 14, and if you are not on LTE, you can use mCdmaDbm, which is field 6. (You have to add three to the field because the dumpsys output leads with a few spaces.) The 17th field tells you if you are on LTE or not. So basically, you can calculate the bars by RSRP and then by SNR, then take the lowest of the two.

By the way, if you want to do bars for 3G on cdma:

**
* Get Evdo as level 0..4
*
* @hide
*/
public int getEvdoLevel() {
int evdoDbm = getEvdoDbm();
int evdoSnr = getEvdoSnr();
int levelEvdoDbm;
int levelEvdoSnr;

if (evdoDbm >= -65) levelEvdoDbm = SIGNAL_STRENGTH_GREAT;
else if (evdoDbm >= -75) levelEvdoDbm = SIGNAL_STRENGTH_GOOD;
else if (evdoDbm >= -90) levelEvdoDbm = SIGNAL_STRENGTH_MODERATE;
else if (evdoDbm >= -105) levelEvdoDbm = SIGNAL_STRENGTH_POOR;
else levelEvdoDbm = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;

if (evdoSnr >= 7) levelEvdoSnr = SIGNAL_STRENGTH_GREAT;
else if (evdoSnr >= 5) levelEvdoSnr = SIGNAL_STRENGTH_GOOD;
else if (evdoSnr >= 3) levelEvdoSnr = SIGNAL_STRENGTH_MODERATE;
else if (evdoSnr >= 1) levelEvdoSnr = SIGNAL_STRENGTH_POOR;
else levelEvdoSnr = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;

int level = (levelEvdoDbm < levelEvdoSnr) ? levelEvdoDbm : levelEvdoSnr;
if (DBG) log("getEvdoLevel=" + level);
return level;
}

So similar to LTE, you pick the lowest number of bars for EvdoDbm or EvdoSnr. The signal strengths correspond to #bars: 4, 3, 2, 1, 0

This is from the master branch.