admin管理员组文章数量:1565262
Android9.0起,开启wifi热点的逻辑进行了调整,ip ssid 密码均为随机生成,为便于通过wifi热点进行无线通信传输,特将固定设置wifi热点的ip、ssid及密码的方法总结如下:
modified: frameworks/base/services/core/java/com/android/server/connectivity/tethering/TetherInterfaceStateMachine.java
private 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.1
ipAsString = "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.java
private 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-xxxxxxxxxxxx
config.preSharedKey = randomUUID.substring(0, 8) + randomUUID.substring(9, 13);
//默认AP的ssid和密码固定写死
config.SSID = "AndroidAP_test";
config.preSharedKey = "123456test";
return config;
}
以上代码验证平台为Android9.0。
版权声明:本文标题:Android rom开发:固定设置wifi热点的ip、ssid及密码 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dongtai/1727523022a1119004.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论