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

Commit f0874dc2 authored by Remi NGUYEN VAN's avatar Remi NGUYEN VAN
Browse files

Only send skipped validation result to AIDL 11+

NetworkMonitor assumed that S would be able to handle
NETWORK_VALIDATION_RESULT_SKIPPED, but this is not the case on S builds
that do not have an update of the connectivity module.

Instead of checking for the platform being S, check for the actual
version of the remote via its stable AIDL callback version.

Bug: 197276728
Test: atest NetworkMonitorTest
Change-Id: Ib7e7ad2028414d9de402a0b780d17d03aac19247
parent 3f31b636
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -3483,11 +3483,11 @@ public class NetworkMonitor extends StateMachine {
        protected void reportEvaluationResult(int result, @Nullable String redirectUrl) {
            if (mCaptivePortalWantedAsIs) {
                result = NETWORK_VALIDATION_RESULT_VALID;
            } else if (!isValidationRequired() && mProbeCompleted == 0 && ShimUtils.isAtLeastS()) {
            } else if (!isValidationRequired() && mProbeCompleted == 0 && mCallbackVersion >= 11) {
                // If validation is not required AND no probes were attempted, the validation was
                // skipped. Report this to ConnectivityService for ConnectivityDiagnostics, but only
                // if the platform is Android S+, as ConnectivityService must also know how to
                // understand this bit.
                // if the platform has callback version 11+, as ConnectivityService must also know
                // how to understand this bit.
                result |= NETWORK_VALIDATION_RESULT_SKIPPED;
            }

+18 −13
Original line number Diff line number Diff line
@@ -589,7 +589,7 @@ public class NetworkMonitorTest {
    }

    private void resetCallbacks() {
        resetCallbacks(6);
        resetCallbacks(11);
    }

    private void resetCallbacks(int interfaceVersion) {
@@ -1796,12 +1796,8 @@ public class NetworkMonitorTest {
        runFailedNetworkTest();
    }

    private void doValidationSkippedTest(NetworkCapabilities nc) throws Exception {
        // For S+, the RESULT_SKIPPED bit will be included on networks that both do not require
        // validation and for which validation is not performed.
        final int validationResult = ShimUtils.isAtLeastS()
                ? NETWORK_VALIDATION_RESULT_VALID | NETWORK_VALIDATION_RESULT_SKIPPED
                : NETWORK_VALIDATION_RESULT_VALID;
    private void doValidationSkippedTest(NetworkCapabilities nc, int validationResult)
            throws Exception {
        runNetworkTest(TEST_LINK_PROPERTIES, nc, validationResult,
                0 /* probesSucceeded */, null /* redirectUrl */);
        verify(mCleartextDnsNetwork, never()).openConnection(any());
@@ -1809,7 +1805,15 @@ public class NetworkMonitorTest {

    @Test
    public void testNoInternetCapabilityValidated() throws Exception {
        doValidationSkippedTest(CELL_NO_INTERNET_CAPABILITIES);
        doValidationSkippedTest(CELL_NO_INTERNET_CAPABILITIES,
                NETWORK_VALIDATION_RESULT_VALID | NETWORK_VALIDATION_RESULT_SKIPPED);
    }

    @Test
    public void testNoInternetCapabilityValidated_OlderPlatform() throws Exception {
        // Before callbacks version 11, NETWORK_VALIDATION_RESULT_SKIPPED is not sent
        resetCallbacks(10);
        doValidationSkippedTest(CELL_NO_INTERNET_CAPABILITIES, NETWORK_VALIDATION_RESULT_VALID);
    }

    @Test
@@ -1822,7 +1826,8 @@ public class NetworkMonitorTest {
        if (ShimUtils.isAtLeastS()) {
            nc.addCapability(NET_CAPABILITY_NOT_VCN_MANAGED);
        }
        doValidationSkippedTest(nc);
        doValidationSkippedTest(nc,
                NETWORK_VALIDATION_RESULT_VALID | NETWORK_VALIDATION_RESULT_SKIPPED);
    }

    @Test
@@ -1835,7 +1840,8 @@ public class NetworkMonitorTest {
        if (ShimUtils.isAtLeastS()) {
            nc.addCapability(NET_CAPABILITY_NOT_VCN_MANAGED);
        }
        doValidationSkippedTest(nc);
        doValidationSkippedTest(nc,
                NETWORK_VALIDATION_RESULT_VALID | NETWORK_VALIDATION_RESULT_SKIPPED);
    }

    private NetworkCapabilities getVcnUnderlyingCarrierWifiCaps() {
@@ -2789,9 +2795,8 @@ public class NetworkMonitorTest {
                new NetworkCapabilities(WIFI_OEM_PAID_CAPABILITIES);
        networkCapabilities.removeCapability(NET_CAPABILITY_INTERNET);

        final int validationResult = ShimUtils.isAtLeastS()
                ? NETWORK_VALIDATION_RESULT_VALID | NETWORK_VALIDATION_RESULT_SKIPPED
                : NETWORK_VALIDATION_RESULT_VALID;
        final int validationResult =
                NETWORK_VALIDATION_RESULT_VALID | NETWORK_VALIDATION_RESULT_SKIPPED;
        runNetworkTest(TEST_LINK_PROPERTIES, networkCapabilities,
                validationResult, 0 /* probesSucceeded */, null /* redirectUrl */);