本文档提供了针对Android 6.0设备在连接Wi-Fi时遇到“已连接但无法上网”的问题解决方案,详细解释了故障原因并给出了操作步骤。
以下是经过修改后的代码段:
```java
diff --git a/services/core/java/com/android/server/connectivity/NetworkMonitor.java b/services/core/java/com/android/server/connectivity/NetworkMonitor.java
index 35e80ca..06a07c2 100755
--- a/services/core/java/com/android/server/connectivity/NetworkMonitor.java
+++ b/services/core/java/com/android/server/connectivity/NetworkMonitor.java
@@ -671,7 +671,7 @@ public class NetworkMonitor extends StateMachine {
HttpURLConnection urlConnection = null;
int httpResponseCode = 599;
try {
- URL url = new URL(http, mServer, /generate_204);
+ URL url = new URL(http, www.baidu.com, /more/index.html);
// On networks with a PAC instead of fetching a URL that should result in a 204
// response, we instead simply fetch the PAC script. This is done for a few reasons:
// 1. At present our PAC code does not yet handle multiple PACs on multiple networks
@@ -730,6 +730,11 @@ public class NetworkMonitor extends StateMachine {
// Theres no point in considering this a captive portal as the user cannot
// sign-in to an empty page. Probably the result of a broken transparent proxy.
if (httpResponseCode == 200) {
+ if (DBG) log(www.baidu.com 200 response interpreted as 204 response.);
+ httpResponseCode = 204;
+ }
+ if (httpResponseCode == 200 && urlConnection.getContentLength() == 0) {
if (DBG) log(Empty 200 response interpreted as 204 response.);
httpResponseCode = 204;
```
该段代码修改了URL,并增加了对特定HTTP响应码的处理逻辑,以确保在网络配置代理(PAC)的情况下正确解析和处理请求。