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

Commit 898f7200 authored by Remi NGUYEN VAN's avatar Remi NGUYEN VAN Committed by Automerger Merge Worker
Browse files

Report probe URL as redirect on 200 portals am: a7500731 am: 36910953

Original change: https://android-review.googlesource.com/c/platform/packages/modules/NetworkStack/+/1719397

Change-Id: I5633a652fc2d382d3b916723bd307eeb2bde0c64
parents 729a12c1 36910953
Loading
Loading
Loading
Loading
+13 −2
Original line number Original line Diff line number Diff line
@@ -103,11 +103,22 @@ public class CaptivePortalProbeResult {
    }
    }


    public boolean isSuccessful() {
    public boolean isSuccessful() {
        return mHttpResponseCode == SUCCESS_CODE;
        return isSuccessCode(mHttpResponseCode);
    }
    }


    public boolean isPortal() {
    public boolean isPortal() {
        return !isSuccessful() && (mHttpResponseCode >= 200) && (mHttpResponseCode <= 399);
        return isPortalCode(mHttpResponseCode);
    }

    private static boolean isSuccessCode(int responseCode) {
        return responseCode == SUCCESS_CODE;
    }

    /**
     * @return Whether the specified HTTP return code indicates a captive portal.
     */
    public static boolean isPortalCode(int responseCode) {
        return !isSuccessCode(responseCode) && (responseCode >= 200) && (responseCode <= 399);
    }
    }


    public boolean isFailed() {
    public boolean isFailed() {
+10 −1
Original line number Original line Diff line number Diff line
@@ -2541,6 +2541,15 @@ public class NetworkMonitor extends StateMachine {


        final CaptivePortalProbeResult probeResult;
        final CaptivePortalProbeResult probeResult;
        if (probeSpec == null) {
        if (probeSpec == null) {
            if (CaptivePortalProbeResult.isPortalCode(httpResponseCode)
                    && TextUtils.isEmpty(redirectUrl)
                    && ShimUtils.isAtLeastS()) {
                // If a portal is a non-redirect portal (often portals that return HTTP 200 with a
                // login page for all HTTP requests), report the probe URL as the login URL starting
                // from S (b/172048052). This avoids breaking assumptions that
                // [is a portal] is equivalent to [there is a login URL].
                redirectUrl = url.toString();
            }
            probeResult = new CaptivePortalProbeResult(httpResponseCode, redirectUrl,
            probeResult = new CaptivePortalProbeResult(httpResponseCode, redirectUrl,
                    url.toString(), 1 << probeType);
                    url.toString(), 1 << probeType);
        } else {
        } else {
+29 −0
Original line number Original line Diff line number Diff line
@@ -155,6 +155,7 @@ import com.android.server.connectivity.nano.CellularData;
import com.android.server.connectivity.nano.DnsEvent;
import com.android.server.connectivity.nano.DnsEvent;
import com.android.server.connectivity.nano.WifiData;
import com.android.server.connectivity.nano.WifiData;
import com.android.testutils.DevSdkIgnoreRule;
import com.android.testutils.DevSdkIgnoreRule;
import com.android.testutils.DevSdkIgnoreRule.IgnoreAfter;
import com.android.testutils.DevSdkIgnoreRule.IgnoreUpTo;
import com.android.testutils.DevSdkIgnoreRule.IgnoreUpTo;
import com.android.testutils.HandlerUtils;
import com.android.testutils.HandlerUtils;


@@ -1068,6 +1069,34 @@ public class NetworkMonitorTest {
        runPortalNetworkTest();
        runPortalNetworkTest();
    }
    }


    @Test
    public void testIsCaptivePortal_Http200EmptyResponse() throws Exception {
        setSslException(mHttpsConnection);
        setStatus(mHttpConnection, 200);
        // Invalid if there is no content (can't login to an empty page)
        runNetworkTest(VALIDATION_RESULT_INVALID, 0 /* probesSucceeded */, null);
        verify(mCallbacks, never()).showProvisioningNotification(any(), any());
    }

    private void doCaptivePortal200ResponseTest(String expectedRedirectUrl) throws Exception {
        setSslException(mHttpsConnection);
        setStatus(mHttpConnection, 200);
        doReturn(100L).when(mHttpConnection).getContentLengthLong();
        // Redirect URL was null before S
        runNetworkTest(VALIDATION_RESULT_PORTAL, 0 /* probesSucceeded */, expectedRedirectUrl);
        verify(mCallbacks, timeout(HANDLER_TIMEOUT_MS)).showProvisioningNotification(any(), any());
    }

    @Test @IgnoreAfter(Build.VERSION_CODES.R)
    public void testIsCaptivePortal_HttpProbeIs200Portal_R() throws Exception {
        doCaptivePortal200ResponseTest(null);
    }

    @Test @IgnoreUpTo(Build.VERSION_CODES.R)
    public void testIsCaptivePortal_HttpProbeIs200Portal() throws Exception {
        doCaptivePortal200ResponseTest(TEST_HTTP_URL);
    }

    private void setupPrivateIpResponse(String privateAddr) throws Exception {
    private void setupPrivateIpResponse(String privateAddr) throws Exception {
        setSslException(mHttpsConnection);
        setSslException(mHttpsConnection);
        setPortal302(mHttpConnection);
        setPortal302(mHttpConnection);