Android 中需要修改到系统默认热点名称或者密码可以参考本文。
源码位置:
frameworks\opt\net\wifi\service\java\com\android\server\wifi\WifiApConfigStore.java
默认热点名称也是随机生成的,如下代码:
private SoftApConfiguration getDefaultApConfiguration() {
SoftApConfiguration.Builder configBuilder = new SoftApConfiguration.Builder();
configBuilder.setBand(SoftApConfiguration.BAND_2GHZ); //默认2.4G
//名称:
configBuilder.setSsid(mContext.getResources().getString(
R.string.wifi_tether_configure_ssid_default) + "_" + getRandomIntForDefaultSsid());
if (ApConfigUtil.isWpa3SaeSupported(mContext)) {
configBuilder.setPassphrase(generatePassword(),
SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION);
} else {
configBuilder.setPassphrase(generatePassword(),
SoftApConfiguration.SECURITY_TYPE_WPA2_PSK); //默认热点加密都是WPA2_PSK类型
}
return configBuilder.build();
}
ApConfigUtil.isWpa3SaeSupported 方法是判断 config_wifi_softap_sae_supported 属性的值。
//WPA3_SAE 加密类型比较少用,系统默认为false
//默认热点加密都是WPA2_PSK类型
frameworks\opt\net\wifi\service\res\values\config.xml
//默认热点密码类型选择
false
//默认热点名称前缀
AndroidAP
private static final int RAND_SSID_INT_MIN = 1000;
private static final int RAND_SSID_INT_MAX = 9999;
//热点后缀
private static int getRandomIntForDefaultSsid() {
Random random = new Random();
return random.nextInt((RAND_SSID_INT_MAX - RAND_SSID_INT_MIN) + 1) + RAND_SSID_INT_MIN;
}
从上面代码看热点名称后缀是:1000 + (0-8999)的一个数值,即1000-9999的一个数值。
private static String generatePassword() {
// Characters that will be used for password generation. Some characters commonly known to
// be confusing like 0 and O excluded from this list.
final String allowed = "23456789abcdefghijkmnpqrstuvwxyz";
final int passLength = 15;
StringBuilder sb = new StringBuilder(passLength);
SecureRandom random = new SecureRandom();
for (int i = 0; i < passLength; i++) {
sb.append(allowed.charAt(random.nextInt(allowed.length())));
}
return sb.toString();
}
首次打开热点,或者未设置热点密码的情况打开热点的情况,会从上面的方法中获取密码字符串。
从上面代码可以看出,默认密码是15位长度,并且是从数字和普通字母中,随机获取组成的。
//设置无密码,10信道,2.4G的热点信号
public void setHotspot2_4(View view) {
private WifiManager mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
//使用Build形式配置对象
SoftApConfiguration.Builder configBuilder = new SoftApConfiguration.Builder();
configBuilder.setSsid(mHotspotName);
configBuilder.setChannel(10, SoftApConfiguration.BAND_2GHZ);
//30 分钟:30*60*1000 = 1800000 或者永久 2147483647
configBuilder.setShutdownTimeoutMillis(2147483647);
mWifiManager.setSoftApConfiguration(configBuilder.build());
}
setSoftApConfiguration方法是Android10 新增的方法,之前的方法:
WifiManager.setWifiApConfiguration(mConfig)已经失效!
ConnectivityManager mConnectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
mConnectivityManager.startTethering(ConnectivityManager.TETHERING_WIFI, true /* showProvisioningUi */,
mOnStartTetheringCallback, new Handler(Looper.getMainLooper()));
热点默认名称和密码都是在 WifiApConfigStore 类中定义可以自定修改
默认热点名称是 AndroidAP + 随机生成的1000-9999的数字
默认热点密码是15位随机生成的数字/字母普通字符串