From fb6665c9cc01df294d96419d807192cf800a0648 Mon Sep 17 00:00:00 2001 From: Remi NGUYEN VAN Date: Tue, 9 Apr 2019 02:04:54 -0700 Subject: [PATCH] Expose captive portal urls for configuration Carriers in Mainland China need to customize certain captive portal urls. The main issue is that google servers are not accessible in Mainland China. Added the following captive portal resources to be targeted for overlay. - config_captive_portal_http_url - config_captive_portal_https_url - config_captive_portal_fallback_urls (string-array) - config_captive_portal_fallback_probe_specs (string-array) These values can be customized for e g diffent countries Bug: 111819230 Test: atest FrameworksNetTests NetworkStackTests Test: Add a product RRO that targets a specific country code, insert a SIM card that matches that country code and check the log what URL is used. Merged-In: I54050b28bbfb93e0b7e509dbe0e987a0b902b7d9 Merged-In: I1f734c5f864bb2f2bc8ba1a66fe33d3480554f69 (cherry picked from commit e3896f71e103be5624b114db9f03a152161ccb4d) Change-Id: I278f2888851d38edb59157f8623541fbe94549b6 --- .../android/server/ConnectivityService.java | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index 57de67e1a3..d9b92a664d 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -108,7 +108,6 @@ import android.net.VpnService; import android.net.metrics.IpConnectivityLog; import android.net.metrics.NetworkEvent; import android.net.netlink.InetDiagMessage; -import android.net.shared.NetworkMonitorUtils; import android.net.shared.PrivateDnsConfig; import android.net.util.MultinetworkPolicyTracker; import android.net.util.NetdService; @@ -238,6 +237,16 @@ public class ConnectivityService extends IConnectivityManager.Stub private static final boolean LOGD_BLOCKED_NETWORKINFO = true; + /** + * Default URL to use for {@link #getCaptivePortalServerUrl()}. This should not be changed + * by OEMs for configuration purposes, as this value is overridden by + * Settings.Global.CAPTIVE_PORTAL_HTTP_URL. + * R.string.config_networkCaptivePortalServerUrl should be overridden instead for this purpose + * (preferably via runtime resource overlays). + */ + private static final String DEFAULT_CAPTIVE_PORTAL_HTTP_URL = + "http://connectivitycheck.gstatic.com/generate_204"; + // TODO: create better separation between radio types and network types // how long to wait before switching back to a radio's default network @@ -6701,9 +6710,20 @@ public class ConnectivityService extends IConnectivityManager.Stub @Override public String getCaptivePortalServerUrl() { enforceConnectivityInternalPermission(); - final String defaultUrl = mContext.getResources().getString( - R.string.config_networkDefaultCaptivePortalServerUrl); - return NetworkMonitorUtils.getCaptivePortalServerHttpUrl(mContext, defaultUrl); + String settingUrl = mContext.getResources().getString( + R.string.config_networkCaptivePortalServerUrl); + + if (!TextUtils.isEmpty(settingUrl)) { + return settingUrl; + } + + settingUrl = Settings.Global.getString(mContext.getContentResolver(), + Settings.Global.CAPTIVE_PORTAL_HTTP_URL); + if (!TextUtils.isEmpty(settingUrl)) { + return settingUrl; + } + + return DEFAULT_CAPTIVE_PORTAL_HTTP_URL; } @Override