智能手機中顯示訊號強度格數

來源:互聯網
上載者:User

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

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.