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

Commit 36910953 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

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

Change-Id: I927b143a0f24f420c4b0781150ea8b26777fee60
parents 3538b8c6 a7500731
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -103,11 +103,22 @@ public class CaptivePortalProbeResult {
    }

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

    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() {
+10 −1
Original line number Diff line number Diff line
@@ -2541,6 +2541,15 @@ public class NetworkMonitor extends StateMachine {

        final CaptivePortalProbeResult probeResult;
        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,
                    url.toString(), 1 << probeType);
        } else {
+29 −0
Original line number 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.WifiData;
import com.android.testutils.DevSdkIgnoreRule;
import com.android.testutils.DevSdkIgnoreRule.IgnoreAfter;
import com.android.testutils.DevSdkIgnoreRule.IgnoreUpTo;
import com.android.testutils.HandlerUtils;

@@ -1068,6 +1069,34 @@ public class NetworkMonitorTest {
        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 {
        setSslException(mHttpsConnection);
        setPortal302(mHttpConnection);