修改wifi softAP SSID

修改wifi softAP默认SSID


andorid4.0之前的版本修改softap ssid是在WifiService.java里面

private boolean setWifiApEnabledBlocking


而4.0之后的版本将最初给SSID赋值的地方移到了WifiApConfigStore.java里面。这个4.0状态机机制使用之后对softap的一点改动。

    /* Generate a default WPA2 based configuration with a random password.
       We are changing the Wifi Ap configuration storage from secure settings to a
       flat file accessible only by the system. A WPA2 based default configuration
       will keep the device secure after the update */
    private void setDefaultApConfiguration() {
        WifiConfiguration config = new WifiConfiguration();
        config.SSID = mContext.getString(R.string.wifi_tether_configure_ssid_default);
        config.allowedKeyManagement.set(KeyMgmt.WPA2_PSK);
        String randomUUID = UUID.randomUUID().toString();
        //first 12 chars from xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
        config.preSharedKey = randomUUID.substring(0, 8) + randomUUID.substring(9,13);
        sendMessage(WifiStateMachine.CMD_SET_AP_CONFIG, config);
    } 

其实在wifi状态机启动的时候已经将ssid默认值写好了

public WifiStateMachine(Context context, String wlanInterface) {

...

        WifiApConfigStore wifiApConfigStore = WifiApConfigStore.makeWifiApConfigStore(
                context, getHandler());
        wifiApConfigStore.loadApConfiguration();

...

}


今天改了ssid的默认值,所以将方法分享给大家。开源嘛,知识属于大家。

private void setDefaultApConfiguration() {
         WifiConfiguration config = new WifiConfiguration();
-        config.SSID = mContext.getString(R.string.wifi_tether_configure_ssid_default);
+        //The default softap ssid should be the product name
+        //config.SSID = mContext.getString(R.string.wifi_tether_configure_ssid_default);
+        config.SSID = SystemProperties.get("ro.build.product");//这里是将ssid默认值改成产品的名字
         config.allowedKeyManagement.set(KeyMgmt.WPA2_PSK);
         String randomUUID = UUID.randomUUID().toString();
         //first 12 chars from xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx





你可能感兴趣的:(wifi)