When the Android system connects to WIFI, it shows that the network connection is limited

Problem Description

Use the Android device to open the settings, select WIFI and enter the correct password to connect, it will be displayed 已连接,无网络, and then become 网络连接受限, you can actually use this WIFI to surf the Internet.

problem analysis

Abnormal Log

D NetworkMonitor/100: PROBE_DNS www.google.com 107ms OK 104.244.46.85
D NetworkMonitor/100: PROBE_DNS connectivitycheck.gstatic.com 118ms OK 203.208.50.66
D NetworkMonitor/100: PROBE_HTTP http://connectivitycheck.gstatic.com/generate_204 time=35ms ret=302 request={
    
    Connection=[close], User-Agent=[Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.32 Safari/537.36]} headers={
    
    null=[HTTP/1.0 302 Moved Temporarily], Allow=[GET,POST,HEAD], Location=[http://10.10.1.2:8080/cn/index.html], MIME-Version=[1.0], Pragma=[No-Cache], Server=[AP Server 1.0], X-Android-Received-Millis=[1615220820212], X-Android-Response-Source=[NETWORK 302], X-Android-Selected-Protocol=[http/1.0], X-Android-Sent-Millis=[1615220820196]}
D NetworkMonitor/100: PROBE_HTTPS https://www.google.com/generate_204 Probe failed with exception javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
D NetworkMonitor/100: isCaptivePortal: isSuccessful()=false isPortal()=true RedirectUrl=http://10.10.1.2:8080/cn/index.html isPartialConnectivity()=false Time=172ms

It can be seen from the log that when connecting to WIFI, the network verification will be performed to determine whether it is available. The HTTP verification is successful, but the HTTPS verification fails, so it will be displayed that there will be a short period of time during the 网络连接受限connection process, which 已连接,无网络is normal. The URL verified by HTTPS https://www.google.com/generate_204cannot be accessed in China, so the verification will fail. The method that can be adopted is to replace this URL.

packages/modules/NetworkStack/src/com/android/server/connectivity/NetworkMonitor.java 

#校验源码部分
private CaptivePortalProbeResult sendDnsAndHttpProbes(ProxyInfo proxy, URL url, int probeType) {
    
    
        // Pre-resolve the captive portal server host so we can log it.
        // Only do this if HttpURLConnection is about to, to avoid any potentially
        // unnecessary resolution.
        final String host = (proxy != null) ? proxy.getHost() : url.getHost();
        // This method cannot safely report probe results because it might not be running on the
        // state machine thread. Reporting results here would cause races and potentially send
        // information to callers that does not make sense because the state machine has already
        // changed state.
        sendDnsProbe(host);
        return sendHttpProbe(url, probeType, null);
}

# HTTPS网址相关源码
private final URL mCaptivePortalHttpsUrl;
mCaptivePortalHttpsUrl = makeURL(getCaptivePortalServerHttpsUrl());
public String getCaptivePortalServerHttpUrl() {
    
    
    return getSettingFromResource(mContext, R.string.config_captive_portal_http_url,
            R.string.default_captive_portal_http_url, CAPTIVE_PORTAL_HTTP_URL);
}

solution

packages/modules/NetworkStack/res/values/config.xml 

<!-- HTTP URL for network validation, to use for detecting captive portals. -->
<string name="default_captive_portal_http_url" translatable="false">http://connectivitycheck.gstatic.com/generate_204</string>
<!-- HTTPS URL for network validation, to use for confirming internet connectivity. -->
- <string name="default_captive_portal_https_url" translatable="false">https://www.google.com/generate_204</string>
+ <string name="default_captive_portal_https_url" translatable="false">https://developers.google.cn/generate_204</string>

There is another solution on the Internet as follows, which is to turn off the verification. This solution can realize the problem of not showing that the network connection is limited, but when connecting to the WIFI that needs to be logged in, it cannot be connected.

frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java

loadSetting(stmt, Settings.Global.LID_BEHAVIOR, defaultLidBehavior);
loadStringSetting(stmt, Settings.Global.NTP_SERVER_2,
            R.string.def_ntp_server_2);
+ loadSetting(stmt, Global.CAPTIVE_PORTAL_MODE, Global.CAPTIVE_PORTAL_MODE_IGNORE);

Regarding the value of captive_portal_mode
0: Disable detection completely
1: When it is detected that a login is required, a pop-up window will remind (default value)
2: When it is detected that a login is required, the hotspot will be automatically disconnected and no longer automatically connected

Guess you like

Origin blog.csdn.net/weixin_44008788/article/details/115797278