一、目前Android引入的网络评估机制,当你连上网络后,会给目标产生204响应的服务器发送给一个请求,如果服务器返回的是状态码为204的响应,那么就被认为网络可以访问;否则,如返回的是其他状态码,那么将被视为网络访问需要登录操作等;没有响应的话,就被认为是网络不可访问。
二、产生这个问题的原因是Android系统默认测试网络的连接是用的google相关的域名,在国内网络无法访问,所以造成即手机连上网络也会提示“No Internet”。
三、解决方案一:暴力Disabled这个功能,把mIsCaptivePortalCheckEnabled 设置为false,实际测试是可以的。? ?
? ? ?1、文件路径:packages\modules\NetworkStack\src\com\android\server\connectivity\NetworkMonitor.java
? ? ?2、生效的地方:
四、解决方案二:增加一个国内可以访问的http_urls网站、当一个urls不能访问的时候访问另外一个,这里我增加http://connect.rom.miui.com/generate_204。下面是整个修改的内容:
diff --git a/packages/modules/NetworkStack/src/com/android/server/connectivity/NetworkMonitor.java b/packages/modules/NetworkStack/src/com/android/server/connectivity/NetworkMonitor.java
index 40de26e..3ee26fe 100755
--- a/packages/modules/NetworkStack/src/com/android/server/connectivity/NetworkMonitor.java
+++ b/packages/modules/NetworkStack/src/com/android/server/connectivity/NetworkMonitor.java
@@ -2311,7 +2311,7 @@ public class NetworkMonitor extends StateMachine {
long startTime = SystemClock.elapsedRealtime();
- final CaptivePortalProbeResult result;
+ CaptivePortalProbeResult result;
if (pacUrl != null) {
result = sendDnsAndHttpProbes(null, pacUrl, ValidationProbeEvent.PROBE_PAC);
reportHttpProbeResult(NETWORK_VALIDATION_PROBE_HTTP, result);
@@ -2324,6 +2324,10 @@ public class NetworkMonitor extends StateMachine {
result = sendMultiParallelHttpAndHttpsProbes(deps, proxyInfo, httpsUrls, httpUrls);
} else {
result = sendDnsAndHttpProbes(proxyInfo, httpUrls[0], ValidationProbeEvent.PROBE_HTTP);
+ if(result.isSuccessful() == false ){
+ Log.d(TAG, "Failed,Try another httpurl:" + String.format("%s",httpUrls[1]));
+ result = sendDnsAndHttpProbes(proxyInfo, httpUrls[1], ValidationProbeEvent.PROBE_HTTP);
+ }
reportHttpProbeResult(NETWORK_VALIDATION_PROBE_HTTP, result);
}
diff --git a/vendor/mediatek/proprietary/packages/overlay/vendor/NetworkStackResOverlay/res/values/config.xml b/vendor/mediatek/proprietary/packages/overlay/vendor/NetworkStackResOverlay/res/values/config.xml
old mode 100644
new mode 100755
index 0d9c88e..1d1ca0d
--- a/vendor/mediatek/proprietary/packages/overlay/vendor/NetworkStackResOverlay/res/values/config.xml
+++ b/vendor/mediatek/proprietary/packages/overlay/vendor/NetworkStackResOverlay/res/values/config.xml
@@ -12,6 +12,7 @@
</string-array>
<string-array name="config_captive_portal_http_urls" translatable="false">
+ <item>http://connect.rom.miui.com/generate_204</item>
<item>http://connectivitycheck.gstatic.com/generate_204</item>
</string-array>
五、参考文章:
https://www.jb51.net/article/161009.htm
Android8.1原生系统网络感叹号消除_落花时节又逢君-CSDN博客_android 网络感叹号
WIFI提示“已连接,但无法访问互联网”_hxm2011的博客-CSDN博客_wifi已连接但无法访问互联网
|