Number of signal strength cells displayed on the smartphone

Source: Internet
Author: User

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;
}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.