Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b7c2487c authored by Udam Saini's avatar Udam Saini
Browse files

Makes captive portal server calculation in one place.

This also creates a hidden api for the captive portal server calculation
so that the Setup Wizard can use this as well.

bug:13246857
Change-Id: I4dfd0916df97cfce13252c7cc15f7bd05ed95f77
parent 5a5d6aee
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -24122,6 +24122,7 @@ package android.net {
    method public android.net.Network[] getAllNetworks();
    method public deprecated boolean getBackgroundDataSetting();
    method public android.net.Network getBoundNetworkForProcess();
    method public java.lang.String getCaptivePortalServerUrl();
    method public android.net.ProxyInfo getDefaultProxy();
    method public android.net.LinkProperties getLinkProperties(android.net.Network);
    method public android.net.NetworkCapabilities getNetworkCapabilities(android.net.Network);
+19 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import static com.android.internal.util.Preconditions.checkNotNull;

import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SystemApi;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
@@ -897,6 +898,24 @@ public class ConnectivityManager {
        }
    }

    /**
     * Gets the URL that should 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.
     *
     * @hide
     */
    @SystemApi
    public String getCaptivePortalServerUrl() {
        try {
            return mService.getCaptivePortalServerUrl();
        } catch (RemoteException e) {
            return null;
        }
    }

    /**
     * Tells the underlying networking system that the caller wants to
     * begin using the named feature. The interpretation of {@code feature}
+2 −0
Original line number Diff line number Diff line
@@ -165,4 +165,6 @@ interface IConnectivityManager
            in IBinder binder, String srcAddr, int srcPort, String dstAddr);

    void stopKeepalive(in Network network, int slot);

    String getCaptivePortalServerUrl();
}
+3 −6
Original line number Diff line number Diff line
@@ -56,7 +56,6 @@ import java.util.Random;

public class CaptivePortalLoginActivity extends Activity {
    private static final String TAG = "CaptivePortalLogin";
    private static final String DEFAULT_SERVER = "connectivitycheck.gstatic.com";
    private static final int SOCKET_TIMEOUT_MS = 10000;

    private enum Result { DISMISSED, UNWANTED, WANTED_AS_IS };
@@ -72,16 +71,14 @@ public class CaptivePortalLoginActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        String server = Settings.Global.getString(getContentResolver(), "captive_portal_server");
        if (server == null) server = DEFAULT_SERVER;
        mCm = ConnectivityManager.from(this);
        String url = getIntent().getStringExtra(ConnectivityManager.EXTRA_CAPTIVE_PORTAL_URL);
        if (url == null) url = mCm.getCaptivePortalServerUrl();
        try {
            mURL = url != null ? new URL(url) : new URL("http", server, "/generate_204");
            mURL = new URL(url);
        } catch (MalformedURLException e) {
            // System misconfigured, bail out in a way that at least provides network access.
            Log.e(TAG, "Invalid captive portal URL, server=" + server);
            Log.e(TAG, "Invalid captive portal URL, url=" + url);
            done(Result.WANTED_AS_IS);
        }
        mNetwork = getIntent().getParcelableExtra(ConnectivityManager.EXTRA_NETWORK);
+5 −0
Original line number Diff line number Diff line
@@ -4847,6 +4847,11 @@ public class ConnectivityService extends IConnectivityManager.Stub
        return success;
    }

    @Override
    public String getCaptivePortalServerUrl() {
        return NetworkMonitor.getCaptivePortalServerUrl(mContext);
    }

    @Override
    public void startNattKeepalive(Network network, int intervalSeconds, Messenger messenger,
            IBinder binder, String srcAddr, int srcPort, String dstAddr) {
Loading