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

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

Merge "Do not revalidate before network is ready" am: d116ad58 am: 4b3fba29

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

Change-Id: I1052ece169610e27496782837c8fd112a8a0ca91
parents 62c43b4f 4b3fba29
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -793,6 +793,11 @@ public class NetworkMonitor extends StateMachine {
                    return HANDLED;
                case CMD_FORCE_REEVALUATION:
                case CMD_CAPTIVE_PORTAL_RECHECK:
                    if (getCurrentState() == mDefaultState) {
                        // Before receiving CMD_NETWORK_CONNECTED (when still in mDefaultState),
                        // requests to reevaluate are not valid: drop them.
                        return HANDLED;
                    }
                    String msg = "Forcing reevaluation for UID " + message.arg1;
                    final DnsStallDetector dsd = getDnsStallDetector();
                    if (dsd != null) {
+27 −0
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ import static org.junit.Assume.assumeTrue;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.after;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.atLeastOnce;
@@ -1229,6 +1230,32 @@ public class NetworkMonitorTest {
        verify(mCapportApiConnection, times(1)).getResponseCode();
    }

    @Test
    public void testIsCaptivePortal_NoRevalidationBeforeNetworkConnected() throws Exception {
        assumeTrue(CaptivePortalDataShimImpl.isSupported());

        final NetworkMonitor nm = makeCellMeteredNetworkMonitor();

        final LinkProperties lp = makeCapportLPs();

        // LinkProperties changed, but NM should not revalidate before notifyNetworkConnected
        nm.notifyLinkPropertiesChanged(lp);
        verify(mHttpConnection, after(100).never()).getResponseCode();
        verify(mHttpsConnection, never()).getResponseCode();
        verify(mCapportApiConnection, never()).getResponseCode();

        setValidProbes();
        setApiContent(mCapportApiConnection, "{'captive': true, "
                + "'user-portal-url': '" + TEST_LOGIN_URL + "'}");

        // After notifyNetworkConnected, validation uses the capport API contents
        nm.notifyNetworkConnected(lp, CELL_METERED_CAPABILITIES);
        verifyNetworkTested(VALIDATION_RESULT_PORTAL, 0 /* probesSucceeded */, TEST_LOGIN_URL);

        verify(mHttpConnection, never()).getResponseCode();
        verify(mCapportApiConnection).getResponseCode();
    }

    @Test
    public void testIsCaptivePortal_CapportApiNotPortalNotValidated() throws Exception {
        assumeTrue(CaptivePortalDataShimImpl.isSupported());