From c2b6a18b9b1feafd430412e64301c2353b3c8c61 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Tue, 9 Jun 2020 10:03:25 -0400 Subject: [PATCH] Use system captive portal URL The captive_portal_server setting is deprecated, and hard-wiring it as a string is also probably a bad idea. Since it's deprecated, this code will miss an override via the modern settings. This also hard-wired a slightly different fallback than ConnectivityService, and simply adjusting it here wouldn't stop that from happening again. It's best to just use the privileged API for obtaining the proper value. The choice of LOCAL_MAC_ADDRESS as the permission for this is a bit strange, but that's what is required, probably because a better fit didn't exist. Change-Id: I78d07d5ff96598cebf6d4ed032fe1516791836fe --- AndroidManifest.xml | 1 + privapp_whitelist_org.lineageos.setupwizard.xml | 1 + .../lineageos/setupwizard/CaptivePortalSetupActivity.java | 8 +++----- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 35086ea2..80cc5610 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -41,6 +41,7 @@ + diff --git a/privapp_whitelist_org.lineageos.setupwizard.xml b/privapp_whitelist_org.lineageos.setupwizard.xml index 3b1e5b6d..98e0a0f4 100644 --- a/privapp_whitelist_org.lineageos.setupwizard.xml +++ b/privapp_whitelist_org.lineageos.setupwizard.xml @@ -21,6 +21,7 @@ + diff --git a/src/org/lineageos/setupwizard/CaptivePortalSetupActivity.java b/src/org/lineageos/setupwizard/CaptivePortalSetupActivity.java index bae17d0b..6fde1431 100644 --- a/src/org/lineageos/setupwizard/CaptivePortalSetupActivity.java +++ b/src/org/lineageos/setupwizard/CaptivePortalSetupActivity.java @@ -25,7 +25,6 @@ import android.net.CaptivePortal; import android.net.ConnectivityManager; import android.net.ICaptivePortal; import android.os.AsyncTask; -import android.provider.Settings; import android.util.Log; import java.io.IOException; @@ -38,17 +37,16 @@ public class CaptivePortalSetupActivity extends SubBaseActivity { public static final String TAG = CaptivePortalSetupActivity.class.getSimpleName(); - private static final String DEFAULT_SERVER = "clients3.google.com"; private static final int CAPTIVE_PORTAL_SOCKET_TIMEOUT_MS = 10000; private URL mCaptivePortalUrl; @Override protected void onStartSubactivity() { - String server = Settings.Global.getString(getContentResolver(), "captive_portal_server"); - if (server == null) server = DEFAULT_SERVER; + ConnectivityManager connectivity = getSystemService(ConnectivityManager.class); + try { - mCaptivePortalUrl = new URL("http://" + server + "/generate_204"); + mCaptivePortalUrl = new URL(connectivity.getCaptivePortalServerUrl()); } catch (MalformedURLException e) { Log.e(TAG, "Not a valid url" + e); }