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

Commit 78156e47 authored by Cody Kesting's avatar Cody Kesting
Browse files

Notify the platform if network validation is skipped in NetworkMonitor.

This CL defines a NETWORK_VALIDATION_RESULT bit for reporting whether a
Network was actually tested for connectivity by NetworkMonitor.

Bug: 162407730
Test: atest NetworkStackTests
Change-Id: Ic855a1679039123fa392158b5e1d85523f7cd666
parent f3ca3c54
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ interface INetworkMonitor {
  const int NETWORK_TEST_RESULT_PARTIAL_CONNECTIVITY = 2;
  const int NETWORK_VALIDATION_RESULT_VALID = 1;
  const int NETWORK_VALIDATION_RESULT_PARTIAL = 2;
  const int NETWORK_VALIDATION_RESULT_SKIPPED = 4;
  const int NETWORK_VALIDATION_PROBE_DNS = 4;
  const int NETWORK_VALIDATION_PROBE_HTTP = 8;
  const int NETWORK_VALIDATION_PROBE_HTTPS = 16;
+8 −2
Original line number Diff line number Diff line
@@ -44,10 +44,16 @@ oneway interface INetworkMonitor {
    // are set, then it's equal to NETWORK_TEST_RESULT_INVALID. If NETWORK_VALIDATION_RESULT_VALID
    // is set, then the network validates and equal to NETWORK_TEST_RESULT_VALID. If
    // NETWORK_VALIDATION_RESULT_PARTIAL is set, then the network has partial connectivity which
    // is equal to NETWORK_TEST_RESULT_PARTIAL_CONNECTIVITY. NETWORK_VALIDATION_PROBE_* is set
    // when the specific probe result of the network is resolved.
    // is equal to NETWORK_TEST_RESULT_PARTIAL_CONNECTIVITY. Networks receiving validation that both
    // do not require validation and are not validated will have NETWORK_VALIDATION_RESULT_SKIPPED
    // set. NETWORK_VALIDATION_PROBE_* is set when the specific probe result of the network is
    // resolved.
    const int NETWORK_VALIDATION_RESULT_VALID = 0x01;
    const int NETWORK_VALIDATION_RESULT_PARTIAL = 0x02;
    const int NETWORK_VALIDATION_RESULT_SKIPPED = 0x04;

    // NETWORK_VALIDATION_RESULT_* and NETWORK_VALIDATION_PROBE_* are independent values sent in
    // different ints.
    const int NETWORK_VALIDATION_PROBE_DNS = 0x04;
    const int NETWORK_VALIDATION_PROBE_HTTP = 0x08;
    const int NETWORK_VALIDATION_PROBE_HTTPS = 0x10;
+9 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import static android.net.INetworkMonitor.NETWORK_VALIDATION_PROBE_HTTP;
import static android.net.INetworkMonitor.NETWORK_VALIDATION_PROBE_HTTPS;
import static android.net.INetworkMonitor.NETWORK_VALIDATION_PROBE_PRIVDNS;
import static android.net.INetworkMonitor.NETWORK_VALIDATION_RESULT_PARTIAL;
import static android.net.INetworkMonitor.NETWORK_VALIDATION_RESULT_SKIPPED;
import static android.net.INetworkMonitor.NETWORK_VALIDATION_RESULT_VALID;
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_METERED;
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED;
@@ -3435,6 +3436,14 @@ public class NetworkMonitor extends StateMachine {
        }

        protected void reportEvaluationResult(int result, @Nullable String redirectUrl) {
            if (!isValidationRequired() && mProbeCompleted == 0 && ShimUtils.isAtLeastS()) {
                // 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.
                result |= NETWORK_VALIDATION_RESULT_SKIPPED;
            }

            mEvaluationResult = result;
            mRedirectUrl = redirectUrl;
            final NetworkTestResultParcelable p = new NetworkTestResultParcelable();
+13 −3
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static android.net.INetworkMonitor.NETWORK_VALIDATION_PROBE_HTTP;
import static android.net.INetworkMonitor.NETWORK_VALIDATION_PROBE_HTTPS;
import static android.net.INetworkMonitor.NETWORK_VALIDATION_PROBE_PRIVDNS;
import static android.net.INetworkMonitor.NETWORK_VALIDATION_RESULT_PARTIAL;
import static android.net.INetworkMonitor.NETWORK_VALIDATION_RESULT_SKIPPED;
import static android.net.INetworkMonitor.NETWORK_VALIDATION_RESULT_VALID;
import static android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET;
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_METERED;
@@ -1794,8 +1795,13 @@ public class NetworkMonitorTest {

    @Test
    public void testNoInternetCapabilityValidated() throws Exception {
        runNetworkTest(TEST_LINK_PROPERTIES, CELL_NO_INTERNET_CAPABILITIES,
                NETWORK_VALIDATION_RESULT_VALID, 0 /* probesSucceeded */, null /* redirectUrl */);
        // 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;
        runNetworkTest(TEST_LINK_PROPERTIES, CELL_NO_INTERNET_CAPABILITIES, validationResult,
                0 /* probesSucceeded */, null /* redirectUrl */);
        verify(mCleartextDnsNetwork, never()).openConnection(any());
    }

@@ -2678,8 +2684,12 @@ public class NetworkMonitorTest {
        final NetworkCapabilities networkCapabilities =
                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;
        runNetworkTest(TEST_LINK_PROPERTIES, networkCapabilities,
                NETWORK_VALIDATION_RESULT_VALID, 0 /* probesSucceeded */, null /* redirectUrl */);
                validationResult, 0 /* probesSucceeded */, null /* redirectUrl */);

        verify(mCleartextDnsNetwork, never()).openConnection(any());
        verify(mHttpsConnection, never()).getResponseCode();