Android WIFI Ralink RT3070开发记录(3)

三、开发遇到的问题汇总

1、如果发现wifi当前是开着的,而却发现关机再重启却没自动开启的话,很有可能是飞行模式揉的货!修改数据库即可正常,如下:

sqlite3 /data/data/com.Android.providers.settings/databases/settings.db
delete from system where name = 'airplane_mode_on';
.exit

2、wi-fi信号强度问题

源码位置2.2和2.3不同,2.2在frameworks/base/services/java/com/android/server/status/StatusBarPolicy.java

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

2.3中单独成为一个apk,叫SystemUI.apk, 从源码位置也能看出来。更新wifi status bar部分代码如下:

else if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION) ||
                    action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION) ||
                    action.equals(WifiManager.RSSI_CHANGED_ACTION)) {
                updateWifi(intent); }

private final void updateWifi(Intent intent) {
        final String action = intent.getAction();
        if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {

final boolean enabled = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
                    WifiManager.WIFI_STATE_UNKNOWN) == WifiManager.WIFI_STATE_ENABLED;

if (!enabled) {
                // If disabled, hide the icon. (We show icon when connected.)
                mService.setIconVisibility("wifi", false);
            }

} else if (action.equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)) {
            final boolean enabled = intent.getBooleanExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED,
                                                          false);
            if (!enabled) {
                mService.setIconVisibility("wifi", false);
            }
        } else if (action.equals(WifiManager.RSSI_CHANGED_ACTION)) {
            int iconId;
           
            final int newRssi = intent.getIntExtra(WifiManager.EXTRA_NEW_RSSI, -200);
            int newSignalLevel = WifiManager.calculateSignalLevel(newRssi,
                                                                  sWifiSignalImages[0].length);
            if (newSignalLevel != mLastWifiSignalLevel) {
                mLastWifiSignalLevel = newSignalLevel;
                if (mIsWifiConnected) {
                    iconId = sWifiSignalImages[mInetCondition][newSignalLevel];
                } else {
                    iconId = sWifiTemporarilyNotConnectedImage;
                }
                mService.setIcon("wifi", iconId, 0);
            }
        }
    }

/**
    * Calculates the level of the signal. This should be used any time a signal
    * is being shown.
    *
    * @param rssi The power of the signal measured in RSSI.
    * @param numLevels The number of levels to consider in the calculated
    *            level.
    * @return A level of the signal, given in the range of 0 to numLevels-1
    *        (both inclusive).
    */
    public static int calculateSignalLevel(int rssi, int numLevels) {
        if (rssi <= MIN_RSSI) {
            return 0;
        } else if (rssi >= MAX_RSSI) {
            return numLevels - 1;
        } else {
            int partitionSize = (MAX_RSSI - MIN_RSSI) / (numLevels - 1);
            return (rssi - MIN_RSSI) / partitionSize;
        }
    }

I/WifiStateTracker( 1799): ----------getRssiApprox------------WifiNative.getRssiCommand():-20
I/WifiStateTracker( 1799): ---------------------->newRssi:-20
I/WifiStateTracker( 1799): ---------------------->newSignalLevel:3

根据log可发现level为-20,而根据计算公式算为 (-55 - (-100))/ 3 = 15;

若rssi level = -20,那么结果为 (-20 - (-100))/ 15 = 5。

后来发现自己忽略了前面一个if语句,-20 明显 > -55,将不进入计算分支,而直接计算 4 - 1 = 3;

所以问题就解决了!

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/93fe648b6176506667ec2b780329b1b4.html