In the Android system, the code for displaying the number of signal strength cells in the mobile phone is
Frameworks \ base \ telephony \ java \ android \ telephony \ SignalStrength. java
GetLevel () function, which is mainly used to obtain the signal strength.
[Java]
Public int getLevel (){
Int level;
If (isGsm ){
Level = getLteLevel ();
If (level = SIGNAL_STRENGTH_NONE_OR_UNKNOWN ){
Level = getGsmLevel ();
}
} Else {
Int cdmaLevel = getCdmaLevel ();
Int evdoLevel = getEvdoLevel ();
If (evdoLevel = SIGNAL_STRENGTH_NONE_OR_UNKNOWN ){
/* We don't know evdo, use cdma */
Level = cdmaLevel;
} Else if (cdmaLevel = SIGNAL_STRENGTH_NONE_OR_UNKNOWN ){
/* We don't know cdma, use evdo */
Level = evdoLevel;
} Else {
/* We know both, use the lowest level */
// Level = cdmaLevel <evdoLevel? CdmaLevel: evdoLevel;
Level = cdmaLevel> evdoLevel? CdmaLevel: evdoLevel;
}
}
If (DBG) log ("getLevel =" + level );
Return level;
}
Public int getLevel (){
Int level;
If (isGsm ){
Level = getLteLevel ();
If (level = SIGNAL_STRENGTH_NONE_OR_UNKNOWN ){
Level = getGsmLevel ();
}
} Else {
Int cdmaLevel = getCdmaLevel ();
Int evdoLevel = getEvdoLevel ();
If (evdoLevel = SIGNAL_STRENGTH_NONE_OR_UNKNOWN ){
/* We don't know evdo, use cdma */
Level = cdmaLevel;
} Else if (cdmaLevel = SIGNAL_STRENGTH_NONE_OR_UNKNOWN ){
/* We don't know cdma, use evdo */
Level = evdoLevel;
} Else {
/* We know both, use the lowest level */
// Level = cdmaLevel <evdoLevel? CdmaLevel: evdoLevel;
Level = cdmaLevel> evdoLevel? CdmaLevel: evdoLevel;
}
}
If (DBG) log ("getLevel =" + level );
Return level;
} GetCdmaLevel () gets CdmaLevel, And the getEvdoLevel () function is also available. In the previous function, the signal display intensity is determined by comparing the Evdo and Cdma strength, that is, the number of signal cells we see in the notification bar.
[Java]
Public int getCdmaLevel (){
Final int cdmaDbm = getCdmaDbm ();
Final int CDMA ecio = getcdma ecio ();
Int levelDbm;
Int levelEcio;
If (cdmaDbm> =-75) levelDbm = SIGNAL_STRENGTH_GREAT;
Else if (cdmaDbm >=- 85) levelDbm = SIGNAL_STRENGTH_GOOD;
Else if (cdmaDbm >=- 95) levelDbm = SIGNAL_STRENGTH_MODERATE;
Else if (cdmaDbm >=- 100) levelDbm = SIGNAL_STRENGTH_POOR;
Else levelDbm = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
// Ec/Io are in dB * 10
If (CDMA ecio> =-90) levelEcio = SIGNAL_STRENGTH_GREAT;
Else if (CDMA ecio >=- 110) levelEcio = SIGNAL_STRENGTH_GOOD;
Else if (CDMA ecio> =-130) levelEcio = SIGNAL_STRENGTH_MODERATE;
Else if (CDMA ecio >=- 150) levelEcio = SIGNAL_STRENGTH_POOR;
Else levelEcio = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
Int level = (levelDbm <levelEcio )? LevelDbm: levelEcio;
If (DBG) log ("getCdmaLevel =" + level + ", cdmaDbm =" + cdmaDbm + ", CDMA ecio =" + CDMA ecio );
Return level;
}
Public int getCdmaLevel (){
Final int cdmaDbm = getCdmaDbm ();
Final int CDMA ecio = getcdma ecio ();
Int levelDbm;
Int levelEcio;
If (cdmaDbm> =-75) levelDbm = SIGNAL_STRENGTH_GREAT;
Else if (cdmaDbm >=- 85) levelDbm = SIGNAL_STRENGTH_GOOD;
Else if (cdmaDbm >=- 95) levelDbm = SIGNAL_STRENGTH_MODERATE;
Else if (cdmaDbm >=- 100) levelDbm = SIGNAL_STRENGTH_POOR;
Else levelDbm = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
// Ec/Io are in dB * 10
If (CDMA ecio> =-90) levelEcio = SIGNAL_STRENGTH_GREAT;
Else if (CDMA ecio >=- 110) levelEcio = SIGNAL_STRENGTH_GOOD;
Else if (CDMA ecio> =-130) levelEcio = SIGNAL_STRENGTH_MODERATE;
Else if (CDMA ecio >=- 150) levelEcio = SIGNAL_STRENGTH_POOR;
Else levelEcio = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
Int level = (levelDbm <levelEcio )? LevelDbm: levelEcio;
If (DBG) log ("getCdmaLevel =" + level + ", cdmaDbm =" + cdmaDbm + ", CDMA ecio =" + CDMA ecio );
Return level;
}