1. 程式人生 > >[RK3288][Android6.0] 一律執行WLAN漫遊掃描選項

[RK3288][Android6.0] 一律執行WLAN漫遊掃描選項

Platform: Rockchip
OS: Android 6.0
Kernel: 3.10.92

開發者選項中有一欄是“”Always allow Wi‑Fi Roam Scans“
這裡寫圖片描述
解釋是執行WLAN漫遊掃描,看它是如何影響掃描執行流程

對應是string name在
packages/apps/Settings/res/values/strings.xml:3645:
<string name="wifi_allow_scan_with_traffic">Always allow Wi\u2011Fi Roam Scans</string>

程式碼裡查詢wifi_allow_scan_with_traffic
DevelopmentSettings.java


private static final String WIFI_ALLOW_SCAN_WITH_TRAFFIC_KEY = "wifi_allow_scan_with_traffic";
mWifiAllowScansWithTraffic = findAndInitSwitchPref(WIFI_ALLOW_SCAN_WITH_TRAFFIC_KEY);
點切換選項時,觸發click操作:

public boolean onPreferenceTreeClick()
{
    } else if (preference == mWifiAllowScansWithTraffic) {
        writeWifiAllowScansWithTrafficOptions();
}

private
void writeWifiAllowScansWithTrafficOptions() { mWifiManager.setAllowScansWithTraffic(mWifiAllowScansWithTraffic.isChecked() ? 1 : 0); }

WifiStateMachine.java

public void setAllowScansWithTraffic(int enabled) {
    mWifiConfigStore.alwaysEnableScansWhileAssociated.set(enabled);
}

存到了mWifiConfigStore,找對應的get介面

public int getAllowScansWithTraffic() {
  return mWifiConfigStore.alwaysEnableScansWhileAssociated.get();
}

getAllowScansWithTraffic呼叫的地方

boolean allowFullBandScanAndAssociated() {
    // Too much traffic at the interface, hence no full band scan
    if (getAllowScansWithTraffic() == 0) {
        return false;
    }
}

當螢幕狀態變化的時候,會呼叫

private void handleScreenStateChanged(boolean screenOn) {
 if (screenOn) {
  //如果allowFullBandScanAndAssociated()返回false,那麼無論是startGScanConnectedModeOffload()
  //還是startDelayedScan()都無法執行scan了
  if (getCurrentState() == mConnectedState
            && allowFullBandScanAndAssociated()) {
        if (useHalBasedAutoJoinOffload()) {
            startGScanConnectedModeOffload("screenOnConnected");
        } else {
            // Scan after 500ms
            startDelayedScan(500, null, null);
        }
    }
  }
}