From 035f65367be6ad8f70e99088fd356fffaa53c2b4 Mon Sep 17 00:00:00 2001 From: Remi NGUYEN VAN Date: Wed, 20 Mar 2019 14:22:49 +0900 Subject: [PATCH] Separate NetworkMonitor/framework portal URL The framework cannot return URLs used by the updatable NetworkStack, which may use configurable URLs, changing URLs, or mechanisms not involving URLs to detect captive portals. NetworkMonitor has already been using random fallback URLs for a while that do not match the value returned by ConnectivityManager#getCaptivePortalServerUrl. With this change, the default value returned by the framework is configured in framework resources as config_networkDefaultCaptivePortalServerUrl. NetworkMonitor behavior may change as it is an updatable component, but the current URL is configured in NetworkMonitor resources as config_captive_portal_http_url. Test: flashed, booted, WiFi and captive portal working Test: ConnectivityManager#getCaptivePortalServerUrl returns correct value. Bug: 127908503 Change-Id: I371dedc5b22efa909d7fd58e1ebe9b8aaced9780 --- core/java/android/net/ConnectivityManager.java | 5 ++++- .../core/java/com/android/server/ConnectivityService.java | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java index 16322353ad..4b1998a51a 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/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index 52fcd4a968..49d8c2d0d3 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