原生安卓WiFi信号去叹号去叉5.0-Android P

原生安卓WiFi信号去叹号去叉5.0-Android P

Captive Portal是安卓5引入的一种检测网络是否正常连接的机制,设计得非常有创意,通过HTTP返回的状态码是否是204来判断是否成功,如果访问得到了200带网页数据,那你就可能处在一个需要登录验证才能上网的环境里,比如说校园网,再比如说一些酒店提供的客户才能免费使用的WiFi(其实是通过DNS劫持实现的),如果连接超时(根本就连接不上)就在WiFi图标和信号图标上加一个标志,安卓5和6是叹号,安卓7改成一个叉了。

所以根本原因是谷歌默认设置了自家的验证服务,在中国大陆原生网络下无法访问。

谷歌设计了一个开关来控制是否启用这个特性,同时也提供了一个变量来控制待验证的服务器地址,国内的修改版ROM通常都改成了高通中国的地址,还有一些ROM设计了代码在重启的时候恢复这个设置,不知道是出于什么目的。

没更新7.0的时候,一直用小狐狸的叹号杀手,很不错的应用,可惜当时他已经很久不更新了,当时安卓N不能用,后来自己做了个小工具,想了想就干脆上架酷安吧,也能帮助大家,这样有了CaptiveMgr工具(Edit: 受软著新规影响已被酷安下架)。

CaptiveMgr-3.2下载
如果有root权限或者可以运行Shizuku可以直接用CaptiveMgr,比较方便。

以下为ADB手动操作,需要ADB环境,ADB配置不赘述。配置以后需要重启WiFi和数据流量(刷新飞行模式即可)

5.0 - 6.x

5和6还不支持HTTPS,直接修改即可

打开检测开关

先处理开关状态,这个变量删除就是默认开启的,删除操作随意执行,反正没影响,删除状态下获取这个变量会返回null。

1
2
3
4
5
6
# 查询状态
adb shell settings get global captive_portal_server
# 启用
adb shell settings delete global captive_portal_server
# 禁用(不会主动判断当前网络是否需要登录,需要手动打开网页触发登录页面)
adb shell settings put global captive_portal_server 0

修改服务器地址

1
2
3
4
5
6
# 查询当前地址
adb shell settings get global captive_portal_server
# 恢复默认地址(原生ROM为Google)
adb shell settings delete global captive_portal_server
# 设置地址到MIUI
adb shell settings put global captive_portal_server connect.rom.miui.com

7.0 - 7.1

这两个版本相比5和6没有大的更改,只是默认连接服务器的时候使用HTTPS,另外提供了一个开关用以指定是否使用HTTPS

打开检测开关

1
2
3
4
5
6
# 查询状态
adb shell settings get global captive_portal_server
# 删除(恢复默认)
adb shell settings delete global captive_portal_server
# 禁用(不会主动判断当前网络是否需要登录,需要手动打开网页触发登录页面)
adb shell settings put global captive_portal_server 0

设置HTTPS开关

1
2
3
4
5
6
# 查询HTTPS开关状态
adb shell settings get global captive_portal_use_https
# 启用HTTPS(直接删除则默认使用HTTPS)
adb shell settings delete global captive_portal_use_https
# 禁用HTTPS(写1启用 写0禁用)
adb shell settings put global captive_portal_use_https 0

修改服务器地址

1
2
3
4
5
6
# 查询当前地址
adb shell settings get global captive_portal_server
# 恢复默认地址(原生ROM为Google)
adb shell settings delete global captive_portal_server
# 设置地址到MIUI
adb shell settings put global captive_portal_server connect.rom.miui.com

7.1.1

这个版本把HTTPS和HTTP两个地址分开保存,并通过7.0加入的HTTPS开关来控制使用哪一个地址。

打开检测开关相关

1
2
3
4
5
6
# 查询状态
adb shell settings get global captive_portal_server
# 启用
adb shell settings delete global captive_portal_server
# 禁用(不会主动判断当前网络是否需要登录,需要手动打开网页触发登录页面)
adb shell settings put global captive_portal_server 0

设置HTTPS开关

1
2
3
4
5
6
# 查询HTTPS开关状态
adb shell settings get global captive_portal_use_https
# 启用HTTPS(直接删除则默认使用HTTPS)
adb shell settings delete global captive_portal_use_https
# 禁用HTTPS(写1启用 写0禁用)
adb shell settings put global captive_portal_use_https 0

修改服务器地址

1
2
3
4
5
6
# 恢复默认地址
adb shell settings delete global captive_portal_https_url
adb shell settings delete global captive_portal_http_url
# 分别修改两个地址
adb shell settings put global captive_portal_http_url http://connect.rom.miui.com/generate_204
adb shell settings put global captive_portal_https_url https://connect.rom.miui.com/generate_204

7.1.2 - 9.0

此版本服务器地址判断逻辑相比7.1.1没有更改,但是检测开关变了。

打开检测开关

1
2
3
4
5
6
# 查看当前状态
adb shell settings get global captive_portal_mode
# 启用检测
adb shell settings delete global captive_portal_mode
# 关闭检测
adb shell settings put global captive_portal_mode 0

设置服务器地址

1
2
3
4
5
6
# 恢复默认地址
adb shell settings delete global captive_portal_https_url
adb shell settings delete global captive_portal_http_url
# 分别修改两个地址
adb shell settings put global captive_portal_http_url http://connect.rom.miui.com/generate_204
adb shell settings put global captive_portal_https_url https://connect.rom.miui.com/generate_204