过滤Android系统设置中Wifi

因项目需要,对机顶盒做了不同配置的版本,低配版Wifi模组不支持5.8G的Wifi,所以需要把系统设置中的Wifi列表中的5.8G显示信息屏蔽掉。

信号参数(WorldWide Available)

2.4G信号:
   Frequency range:2.400G—-2.500GHz,即(2400MHz—–2500MHz),
   Bandwidth:100MHz,
   Center Frequency: 2.450GHz
5.8G信号:
   Frequency range:5.725G—-5.800GHz,即(5725MHz—–5800MHz),
   Bandwidth:100MHz,
   Center Frequency: 5.800GHz

怎么修改

通过跟踪系统设置的代码发现,要想过滤显示的Wifi热点,可以在WifiSettings.java中处理;不过很快你会发现,在AccessPoint中,并没有关于frequency的信息。所以,需要先对AccessPoint.java中定义相应的属性:

路径在\packages\apps\Settings\src\com\android\settings\wifi\AccessPoint.java:

    //add by dq begin
    private int frequency;

    public int getFrequency() {
        return frequency;
    }
    public void setFrequency(int frequency) {
        this.frequency = frequency;
    }
    //add by dq end
    ......

    private void loadResult(ScanResult result) {
        ssid = result.SSID;
        bssid = result.BSSID;
        security = getSecurity(result);
        wpsAvailable = security != SECURITY_EAP && result.capabilities.contains("WPS");
        if (security == SECURITY_PSK)
            pskType = getPskType(result);
        networkId = -1;
        mRssi = result.level;
        mScanResult = result;
        setFrequency(result.frequency);//add by dq
    }

接着,需要在WifiSettings.java中去做处理:

private void updateAccessPoints() {
  ....
  switch (wifiState) {
    case WifiManager.WIFI_STATE_ENABLED:
        for (AccessPoint accessPoint : accessPoints) {
           //add by dq begain to omit 5.8G wifi.    
           Log.d(TAG,"wifi ap   frequency:"
                       +accessPoint.getFrequency());
         int frequency = accessPoint.getFrequency();
         if(frequency >= 5725 && frequency <= 5800) {
               continue;
         }
         //add by dq end.
         getPreferenceScreen().addPreference(accessPoint);                
       }
    break;
}

源码中编译以后,5.8G的信号就从列表中屏蔽了。
2015.3.31

你可能感兴趣的:(Android)