diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java
index 16322353add2d..4b1998a51aace 100644
--- a/core/java/android/net/ConnectivityManager.java
+++ b/core/java/android/net/ConnectivityManager.java
@@ -1345,12 +1345,15 @@ public class ConnectivityManager {
}
/**
- * Gets the URL that should be used for resolving whether a captive portal is present.
+ * Gets a URL that can be used for resolving whether a captive portal is present.
* 1. This URL should respond with a 204 response to a GET request to indicate no captive
* portal is present.
* 2. This URL must be HTTP as redirect responses are used to find captive portal
* sign-in pages. Captive portals cannot respond to HTTPS requests with redirects.
*
+ * The system network validation may be using different strategies to detect captive portals,
+ * so this method does not necessarily return a URL used by the system. It only returns a URL
+ * that may be relevant for other components trying to detect captive portals.
* @hide
*/
@SystemApi
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 97ae8e5215fe1..7698d271cfac9 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -302,6 +302,15 @@
Settings.Global.NETWORK_AVOID_BAD_WIFI. This is the default value of that setting. -->
1
+
+ http://connectivitycheck.gstatic.com/generate_204
+
0
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index a95fa540e33ab..05303c96ea808 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -1945,6 +1945,7 @@
+
diff --git a/packages/NetworkStack/res/values/config.xml b/packages/NetworkStack/res/values/config.xml
new file mode 100644
index 0000000000000..52425e57ba3ae
--- /dev/null
+++ b/packages/NetworkStack/res/values/config.xml
@@ -0,0 +1,5 @@
+
+
+
+ http://connectivitycheck.gstatic.com/generate_204
+
\ No newline at end of file
diff --git a/packages/NetworkStack/src/com/android/server/connectivity/NetworkMonitor.java b/packages/NetworkStack/src/com/android/server/connectivity/NetworkMonitor.java
index 48d9d7b142c7f..bd3d463052d00 100644
--- a/packages/NetworkStack/src/com/android/server/connectivity/NetworkMonitor.java
+++ b/packages/NetworkStack/src/com/android/server/connectivity/NetworkMonitor.java
@@ -83,6 +83,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.RingBufferIndices;
import com.android.internal.util.State;
import com.android.internal.util.StateMachine;
+import com.android.networkstack.R;
import java.io.IOException;
import java.net.HttpURLConnection;
@@ -1710,9 +1711,15 @@ public class NetworkMonitor extends StateMachine {
/**
* Get the captive portal server HTTP URL that is configured on the device.
+ *
+ * NetworkMonitor does not use {@link ConnectivityManager#getCaptivePortalServerUrl()} as
+ * it has its own updatable strategies to detect captive portals. The framework only advises
+ * on one URL that can be used, while NetworkMonitor may implement more complex logic.
*/
public String getCaptivePortalServerHttpUrl(Context context) {
- return NetworkMonitorUtils.getCaptivePortalServerHttpUrl(context);
+ final String defaultUrl =
+ context.getResources().getString(R.string.config_captive_portal_http_url);
+ return NetworkMonitorUtils.getCaptivePortalServerHttpUrl(context, defaultUrl);
}
/**
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java
index 52fcd4a968ca6..49d8c2d0d366b 100644
--- a/services/core/java/com/android/server/ConnectivityService.java
+++ b/services/core/java/com/android/server/ConnectivityService.java
@@ -6685,7 +6685,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
@Override
public String getCaptivePortalServerUrl() {
enforceConnectivityInternalPermission();
- return NetworkMonitorUtils.getCaptivePortalServerHttpUrl(mContext);
+ final String defaultUrl = mContext.getResources().getString(
+ R.string.config_networkDefaultCaptivePortalServerUrl);
+ return NetworkMonitorUtils.getCaptivePortalServerHttpUrl(mContext, defaultUrl);
}
@Override
diff --git a/services/net/java/android/net/shared/NetworkMonitorUtils.java b/services/net/java/android/net/shared/NetworkMonitorUtils.java
index 3d2a2de455397..a17cb46471586 100644
--- a/services/net/java/android/net/shared/NetworkMonitorUtils.java
+++ b/services/net/java/android/net/shared/NetworkMonitorUtils.java
@@ -44,18 +44,14 @@ public class NetworkMonitorUtils {
public static final String PERMISSION_ACCESS_NETWORK_CONDITIONS =
"android.permission.ACCESS_NETWORK_CONDITIONS";
- // TODO: once the URL is a resource overlay, remove and have the resource define the default
- private static final String DEFAULT_HTTP_URL =
- "http://connectivitycheck.gstatic.com/generate_204";
-
/**
* Get the captive portal server HTTP URL that is configured on the device.
*/
- public static String getCaptivePortalServerHttpUrl(Context context) {
+ public static String getCaptivePortalServerHttpUrl(Context context, String defaultUrl) {
final String settingUrl = Settings.Global.getString(
context.getContentResolver(),
Settings.Global.CAPTIVE_PORTAL_HTTP_URL);
- return settingUrl != null ? settingUrl : DEFAULT_HTTP_URL;
+ return settingUrl != null ? settingUrl : defaultUrl;
}
/**