Android rom开发:固定设置wifi热点的ip、ssid及密码
Android9.0起,开启wifi热点的逻辑进行了调整,ip ssid 密码均为随机生成,为便于通过wifi热点进行无线通信传输,特将固定设置wifi热点的ip、ssid及密码的方法总结如下:
modified: frameworks/base/services/core/java/com/android/server/connectivity/tethering/TetherInterfaceStateMachine.javaprivate boolean configureIPv4(boolean enabled) {if (VDBG) Log.d(TAG, "configureIPv4(" + enabled + ")");// TODO: Replace this hard-coded information with dynamically selected// config passed down to us by a higher layer IP-coordinating element.String ipAsString = null;int prefixLen = 0;if (mInterfaceType == ConnectivityManager.TETHERING_USB) {ipAsString = USB_NEAR_IFACE_ADDR;prefixLen = USB_PREFIX_LENGTH;} else if (mInterfaceType == ConnectivityManager.TETHERING_WIFI) {ipAsString = getRandomWifiIPv4Address();//ip固定设置为192.168.43.1ipAsString = "192.168.43.1";prefixLen = WIFI_HOST_IFACE_PREFIX_LENGTH;} else {// Nothing to do, BT does this elsewhere.return true;}final LinkAddress linkAddr;try {final InterfaceConfiguration ifcg = mNMService.getInterfaceConfig(mIfaceName);if (ifcg == null) {mLog.e("Received null interface config");return false;}InetAddress addr = NetworkUtils.numericToInetAddress(ipAsString);linkAddr = new LinkAddress(addr, prefixLen);ifcg.setLinkAddress(linkAddr);if (mInterfaceType == ConnectivityManager.TETHERING_WIFI) {// The WiFi stack has ownership of the interface up/down state.// It is unclear whether the Bluetooth or USB stacks will manage their own// state.ifcg.ignoreInterfaceUpDownStatus();} else {if (enabled) {ifcg.setInterfaceUp();} else {ifcg.setInterfaceDown();}}ifcg.clearFlag("running");mNMService.setInterfaceConfig(mIfaceName, ifcg);} catch (Exception e) {mLog.e("Error configuring interface " + e);return false;}// Directly-connected route.final RouteInfo route = new RouteInfo(linkAddr);if (enabled) {mLinkProperties.addLinkAddress(linkAddr);mLinkProperties.addRoute(route);} else {mLinkProperties.removeLinkAddress(linkAddr);mLinkProperties.removeRoute(route);}return true;
}modified: frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiApConfigStore.javaprivate WifiConfiguration getDefaultApConfiguration() {WifiConfiguration config = new WifiConfiguration();config.apBand = WifiConfiguration.AP_BAND_2GHZ;config.SSID = mContext.getResources().getString(R.string.wifi_tether_configure_ssid_default) + "_" + getRandomIntForDefaultSsid();config.allowedKeyManagement.set(KeyMgmt.WPA2_PSK);String randomUUID = UUID.randomUUID().toString();//first 12 chars from xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxxconfig.preSharedKey = randomUUID.substring(0, 8) + randomUUID.substring(9, 13);//默认AP的ssid和密码固定写死config.SSID = "AndroidAP_test";config.preSharedKey = "123456test";return config;
}
以上代码验证平台为Android9.0。
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
