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
This commit is contained in:
Daniel Micay
2020-06-09 10:03:25 -04:00
committed by Michael Bestas
parent f1bfe7e2de
commit c2b6a18b9b
3 changed files with 5 additions and 5 deletions

View File

@@ -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);
}