在Android4.0的系統中,手機中顯示訊號強度格數的代碼在
frameworks\base\telephony\java\android\telephony\SignalStrength.java
getLevel( )函數,該函數是主要用來擷取訊號的強度。
[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( )擷取CdmaLevel,同樣也有getEvdoLevel( )函數,在上一個函數中,通過比較Evdo和Cdma的強度,來最終確定訊號的顯示強度,也就是我們在通知欄裡看到的訊號格數。
[java]
public int getCdmaLevel() {
final int cdmaDbm = getCdmaDbm();
final int cdmaEcio = getCdmaEcio();
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 (cdmaEcio >= -90) levelEcio = SIGNAL_STRENGTH_GREAT;
else if (cdmaEcio >= -110) levelEcio = SIGNAL_STRENGTH_GOOD;
else if (cdmaEcio >= -130) levelEcio = SIGNAL_STRENGTH_MODERATE;
else if (cdmaEcio >= -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 + ",cdmaEcio=" +cdmaEcio);
return level;
}
public int getCdmaLevel() {
final int cdmaDbm = getCdmaDbm();
final int cdmaEcio = getCdmaEcio();
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 (cdmaEcio >= -90) levelEcio = SIGNAL_STRENGTH_GREAT;
else if (cdmaEcio >= -110) levelEcio = SIGNAL_STRENGTH_GOOD;
else if (cdmaEcio >= -130) levelEcio = SIGNAL_STRENGTH_MODERATE;
else if (cdmaEcio >= -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 + ",cdmaEcio=" +cdmaEcio);
return level;
}