Android下信号强度显示和信号刷新时间

android界面UI信号显示是通过RIL对通讯模块发送AT命令来实现的,如AT+CSQ,我们查看一般可以通过 logcat -b radio来获取一些RIL的实时信息


那么信号显示隔多长时间在在界面上刷新?

frameworks/base/telephony/java/com/android/internal/telephony/ServiceStateTracker.java

    /** Signal strength poll rate. */
  protected static final int POLL_PERIOD_MILLIS = 120 * 1000; 

它的信号刷新时间为2分钟,也就是说从我开机到信号显示大概需要2分钟的时间,这显示太长了

 protected static final int POLL_PERIOD_MILLIS = 12 * 1000;

我们可以将其改为12秒

那么信号在界面上的显示的信号强度又是 如何获取的呢?

frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarPolicy.java



        if (!isCdma()) {                                                   //GSM信号强度的获取
            int asu = mSignalStrength.getGsmSignalStrength();


            // ASU ranges from 0 to 31 - TS 27.007 Sec 8.5
            // asu = 0 (-113dB or less) is very weak
            // signal, its better to show 0 bars to the user in such cases.
            // asu = 99 is a special case, where the signal strength is unknown.
            if (asu <= 2 || asu == 99) iconLevel = 0;            
            else if (asu >= 12) iconLevel = 4;
            else if (asu >= 8)  iconLevel = 3;
            else if (asu >= 5)  iconLevel = 2;
            else iconLevel = 1;


            // Though mPhone is a Manager, this call is not an IPC
            if (mPhone.isNetworkRoaming()) {
                iconList = sSignalImages_r[mInetCondition];
            } else {
                iconList = sSignalImages[mInetCondition];
            }
        } else {
            iconList = sSignalImages[mInetCondition];


            // If 3G(EV) and 1x network are available than 3G should be //当有3G和1X(电信2.5G)网络的时候会显示EVDO网络
            // displayed, displayed RSSI should be from the EV side.           
            // If a voice call is made then RSSI should switch to 1x.                   //打电话的时候走的是1X网络,
            if ((mPhoneState == TelephonyManager.CALL_STATE_IDLE) && isEvdo()){
                iconLevel = getEvdoLevel();
                if (false) {
                    Slog.d(TAG, "use Evdo level=" + iconLevel + " to replace Cdma Level=" + getCdmaLevel());
                }
            } else {
                iconLevel = getCdmaLevel();
            }
        }
        mPhoneSignalIconId = iconList[iconLevel];
        mService.setIcon("phone_signal", mPhoneSignalIconId, 0);
    }


    private int getCdmaLevel() {                                                //CDMA信号显示
        final int cdmaDbm = mSignalStrength.getCdmaDbm();
        final int cdmaEcio = mSignalStrength.getCdmaEcio();
        int levelDbm = 0;
        int levelEcio = 0;


        if (cdmaDbm >= -75) levelDbm = 4;
        else if (cdmaDbm >= -85) levelDbm = 3;
        else if (cdmaDbm >= -95) levelDbm = 2;
        else if (cdmaDbm >= -100) levelDbm = 1;
        else levelDbm = 0;


        // Ec/Io are in dB*10
        if (cdmaEcio >= -90) levelEcio = 4;
        else if (cdmaEcio >= -110) levelEcio = 3;
        else if (cdmaEcio >= -130) levelEcio = 2;
        else if (cdmaEcio >= -150) levelEcio = 1;
        else levelEcio = 0;


        return (levelDbm < levelEcio) ? levelDbm : levelEcio;
    }


    private int getEvdoLevel() {                                             //EVDO网络显示 CDMA2000 3G信号显示(例如电信天翼3G)
        int evdoDbm = mSignalStrength.getEvdoDbm();
        int evdoSnr = mSignalStrength.getEvdoSnr();
        int levelEvdoDbm = 0;
        int levelEvdoSnr = 0;


        if (evdoDbm >= -65) levelEvdoDbm = 4;
        else if (evdoDbm >= -75) levelEvdoDbm = 3;
        else if (evdoDbm >= -90) levelEvdoDbm = 2;
        else if (evdoDbm >= -105) levelEvdoDbm = 1;
        else levelEvdoDbm = 0;


        if (evdoSnr >= 7) levelEvdoSnr = 4;
        else if (evdoSnr >= 5) levelEvdoSnr = 3;
        else if (evdoSnr >= 3) levelEvdoSnr = 2;
        else if (evdoSnr >= 1) levelEvdoSnr = 1;
        else levelEvdoSnr = 0;


        return (levelEvdoDbm < levelEvdoSnr) ? levelEvdoDbm : levelEvdoSnr;
    }

很多android手机信号并非很好,他们可以通过修改上面一段让界面显示的信号维持在某个区域内,当然每个模块的信号取值 RSSI值并不是全部遵循上面这段代码的分级标准,需对应相应的AT手册进行修改。



你可能感兴趣的:(软件开发)