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

Commit fc12d63b authored by Chalard Jean's avatar Chalard Jean
Browse files

Have NetworkStackService implement notifyNetworkConnectedParcel

Test: NetworkStackIntegrationTests
Change-Id: I76171e333acca2667bc60db1dd73ca2d5eada742
parent d25c7f1b
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -158,7 +158,7 @@ java_library {
    min_sdk_version: "29",
    min_sdk_version: "29",
    static_libs: [
    static_libs: [
        "ipmemorystore-aidl-interfaces-V10-java",
        "ipmemorystore-aidl-interfaces-V10-java",
        "networkstack-aidl-interfaces-V13-java",
        "networkstack-aidl-interfaces-V14-java",
    ],
    ],
    visibility: ["//packages/modules/NetworkStack:__subpackages__"],
    visibility: ["//packages/modules/NetworkStack:__subpackages__"],
    apex_available: [
    apex_available: [
+1 −1
Original line number Original line Diff line number Diff line
@@ -77,7 +77,7 @@ oneway interface INetworkMonitor {
    void notifyLinkPropertiesChanged(in LinkProperties lp);
    void notifyLinkPropertiesChanged(in LinkProperties lp);
    void notifyNetworkCapabilitiesChanged(in NetworkCapabilities nc);
    void notifyNetworkCapabilitiesChanged(in NetworkCapabilities nc);
    /**
    /**
     * Notify NetworkMonitor that this network connected, used on T+.
     * Notify NetworkMonitor that this network connected, version 2
     */
     */
    void notifyNetworkConnectedParcel(in NetworkMonitorParameters params);
    void notifyNetworkConnectedParcel(in NetworkMonitorParameters params);
}
}
+14 −0
Original line number Original line Diff line number Diff line
@@ -43,6 +43,7 @@ import android.net.dhcp.DhcpServingParamsParcel;
import android.net.dhcp.IDhcpServerCallbacks;
import android.net.dhcp.IDhcpServerCallbacks;
import android.net.ip.IIpClientCallbacks;
import android.net.ip.IIpClientCallbacks;
import android.net.ip.IpClient;
import android.net.ip.IpClient;
import android.net.networkstack.aidl.NetworkMonitorParameters;
import android.net.shared.PrivateDnsConfig;
import android.net.shared.PrivateDnsConfig;
import android.net.util.SharedLog;
import android.net.util.SharedLog;
import android.os.Build;
import android.os.Build;
@@ -612,12 +613,25 @@ public class NetworkStackService extends Service {
            mNm.notifyDnsResponse(returnCode);
            mNm.notifyDnsResponse(returnCode);
        }
        }


        /**
         * Send a notification to NetworkMonitor indicating that the network is now connected.
         * @Deprecated use notifyNetworkConnectedParcel, which also passes the NetworkAgentConfig.
         */
        @Override
        @Override
        public void notifyNetworkConnected(LinkProperties lp, NetworkCapabilities nc) {
        public void notifyNetworkConnected(LinkProperties lp, NetworkCapabilities nc) {
            mPermChecker.enforceNetworkStackCallingPermission();
            mPermChecker.enforceNetworkStackCallingPermission();
            mNm.notifyNetworkConnected(lp, nc);
            mNm.notifyNetworkConnected(lp, nc);
        }
        }


        /**
         * Send a notification to NetworkMonitor indicating that the network is now connected.
         */
        @Override
        public void notifyNetworkConnectedParcel(NetworkMonitorParameters params) {
            mPermChecker.enforceNetworkStackCallingPermission();
            mNm.notifyNetworkConnectedParcel(params);
        }

        @Override
        @Override
        public void notifyNetworkDisconnected() {
        public void notifyNetworkDisconnected() {
            mPermChecker.enforceNetworkStackCallingPermission();
            mPermChecker.enforceNetworkStackCallingPermission();
+19 −7
Original line number Original line Diff line number Diff line
@@ -113,6 +113,7 @@ import android.net.captiveportal.CaptivePortalProbeSpec;
import android.net.metrics.IpConnectivityLog;
import android.net.metrics.IpConnectivityLog;
import android.net.metrics.NetworkEvent;
import android.net.metrics.NetworkEvent;
import android.net.metrics.ValidationProbeEvent;
import android.net.metrics.ValidationProbeEvent;
import android.net.networkstack.aidl.NetworkMonitorParameters;
import android.net.shared.NetworkMonitorUtils;
import android.net.shared.NetworkMonitorUtils;
import android.net.shared.PrivateDnsConfig;
import android.net.shared.PrivateDnsConfig;
import android.net.util.DataStallUtils.EvaluationType;
import android.net.util.DataStallUtils.EvaluationType;
@@ -144,7 +145,6 @@ import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.text.TextUtils;
import android.util.Log;
import android.util.Log;
import android.util.Pair;
import android.util.SparseArray;
import android.util.SparseArray;


import androidx.annotation.ArrayRes;
import androidx.annotation.ArrayRes;
@@ -693,17 +693,29 @@ public class NetworkMonitor extends StateMachine {


    /**
    /**
     * Send a notification to NetworkMonitor indicating that the network is now connected.
     * Send a notification to NetworkMonitor indicating that the network is now connected.
     * @Deprecated use notifyNetworkConnectedParcel. This method is called on R-, or in
     *             cases where the Connectivity module is old in S.
     */
     */
    public void notifyNetworkConnected(LinkProperties lp, NetworkCapabilities nc) {
    public void notifyNetworkConnected(LinkProperties lp, NetworkCapabilities nc) {
        sendMessage(CMD_NETWORK_CONNECTED, new Pair<>(
        final NetworkMonitorParameters params = new NetworkMonitorParameters();
                new LinkProperties(lp), new NetworkCapabilities(nc)));
        params.linkProperties = lp;
        params.networkCapabilities = nc;
        notifyNetworkConnectedParcel(params);
    }

    /**
     * Send a notification to NetworkMonitor indicating that the network is now connected.
     * Called in S when the Connectivity module is recent enough, or in T+ in all cases.
     */
    public void notifyNetworkConnectedParcel(NetworkMonitorParameters params) {
        sendMessage(CMD_NETWORK_CONNECTED, params);
    }
    }


    private void updateConnectedNetworkAttributes(Message connectedMsg) {
    private void updateConnectedNetworkAttributes(Message connectedMsg) {
        final Pair<LinkProperties, NetworkCapabilities> attrs =
        final NetworkMonitorParameters params = (NetworkMonitorParameters) connectedMsg.obj;
                (Pair<LinkProperties, NetworkCapabilities>) connectedMsg.obj;
        // TODO : also read the NetworkAgentConfig
        mLinkProperties = attrs.first;
        mLinkProperties = params.linkProperties;
        mNetworkCapabilities = attrs.second;
        mNetworkCapabilities = params.networkCapabilities;
        suppressNotificationIfNetworkRestricted();
        suppressNotificationIfNetworkRestricted();
    }
    }


+58 −39
Original line number Original line Diff line number Diff line
@@ -115,11 +115,13 @@ import android.net.INetworkMonitorCallbacks;
import android.net.InetAddresses;
import android.net.InetAddresses;
import android.net.LinkProperties;
import android.net.LinkProperties;
import android.net.Network;
import android.net.Network;
import android.net.NetworkAgentConfig;
import android.net.NetworkCapabilities;
import android.net.NetworkCapabilities;
import android.net.NetworkTestResultParcelable;
import android.net.NetworkTestResultParcelable;
import android.net.Uri;
import android.net.Uri;
import android.net.captiveportal.CaptivePortalProbeResult;
import android.net.captiveportal.CaptivePortalProbeResult;
import android.net.metrics.IpConnectivityLog;
import android.net.metrics.IpConnectivityLog;
import android.net.networkstack.aidl.NetworkMonitorParameters;
import android.net.shared.PrivateDnsConfig;
import android.net.shared.PrivateDnsConfig;
import android.net.util.SharedLog;
import android.net.util.SharedLog;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiInfo;
@@ -296,6 +298,8 @@ public class NetworkMonitorTest {
    private static final int TEST_MIN_STALL_EVALUATE_INTERVAL_MS = 500;
    private static final int TEST_MIN_STALL_EVALUATE_INTERVAL_MS = 500;
    private static final int STALL_EXPECTED_LAST_PROBE_TIME_MS =
    private static final int STALL_EXPECTED_LAST_PROBE_TIME_MS =
            TEST_MIN_STALL_EVALUATE_INTERVAL_MS + HANDLER_TIMEOUT_MS;
            TEST_MIN_STALL_EVALUATE_INTERVAL_MS + HANDLER_TIMEOUT_MS;
    private static final NetworkAgentConfig TEST_AGENT_CONFIG =
            new NetworkAgentConfig.Builder().build();
    private static final LinkProperties TEST_LINK_PROPERTIES = new LinkProperties();
    private static final LinkProperties TEST_LINK_PROPERTIES = new LinkProperties();


    // Cannot have a static member for the LinkProperties with captive portal API information, as
    // Cannot have a static member for the LinkProperties with captive portal API information, as
@@ -754,9 +758,10 @@ public class NetworkMonitorTest {
                .addCapability(NET_CAPABILITY_INTERNET);
                .addCapability(NET_CAPABILITY_INTERNET);
        doReturn(TEST_SPEED_TEST_URL).when(mResources).getString(
        doReturn(TEST_SPEED_TEST_URL).when(mResources).getString(
                R.string.config_evaluating_bandwidth_url);
                R.string.config_evaluating_bandwidth_url);
        final NetworkMonitor nm = runNetworkTest(TEST_LINK_PROPERTIES, meteredCap,
        final NetworkMonitor nm = runNetworkTest(TEST_AGENT_CONFIG, TEST_LINK_PROPERTIES,
                NETWORK_VALIDATION_RESULT_VALID, NETWORK_VALIDATION_PROBE_DNS
                meteredCap, NETWORK_VALIDATION_RESULT_VALID,
                | NETWORK_VALIDATION_PROBE_HTTPS, null /* redirectUrl */);
                NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_HTTPS,
                null /* redirectUrl */);
        // Evaluating bandwidth process won't be executed when the network is metered wifi.
        // Evaluating bandwidth process won't be executed when the network is metered wifi.
        // Check that the connection hasn't been opened and the state should transition to validated
        // Check that the connection hasn't been opened and the state should transition to validated
        // state directly.
        // state directly.
@@ -774,9 +779,10 @@ public class NetworkMonitorTest {
                .addCapability(NET_CAPABILITY_INTERNET)
                .addCapability(NET_CAPABILITY_INTERNET)
                .addCapability(NET_CAPABILITY_NOT_METERED);
                .addCapability(NET_CAPABILITY_NOT_METERED);
        doReturn("").when(mResources).getString(R.string.config_evaluating_bandwidth_url);
        doReturn("").when(mResources).getString(R.string.config_evaluating_bandwidth_url);
        final NetworkMonitor nm = runNetworkTest(TEST_LINK_PROPERTIES, nonMeteredCap,
        final NetworkMonitor nm = runNetworkTest(TEST_AGENT_CONFIG, TEST_LINK_PROPERTIES,
                NETWORK_VALIDATION_RESULT_VALID, NETWORK_VALIDATION_PROBE_DNS
                nonMeteredCap, NETWORK_VALIDATION_RESULT_VALID,
                | NETWORK_VALIDATION_PROBE_HTTPS, null /* redirectUrl */);
                NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_HTTPS,
                null /* redirectUrl */);
        // Non-metered network with wrong configuration(the config_evaluating_bandwidth_url is
        // Non-metered network with wrong configuration(the config_evaluating_bandwidth_url is
        // empty). Check that the connection hasn't been opened and the state should transition to
        // empty). Check that the connection hasn't been opened and the state should transition to
        // validated state directly.
        // validated state directly.
@@ -1307,8 +1313,8 @@ public class NetworkMonitorTest {
                + "'seconds-remaining': " + secondsRemaining + "}");
                + "'seconds-remaining': " + secondsRemaining + "}");
        setPortal302(mHttpConnection);
        setPortal302(mHttpConnection);


        runNetworkTest(makeCapportLPs(), CELL_METERED_CAPABILITIES, VALIDATION_RESULT_PORTAL,
        runNetworkTest(TEST_AGENT_CONFIG, makeCapportLPs(), CELL_METERED_CAPABILITIES,
                0 /* probesSucceeded*/, TEST_LOGIN_URL);
                VALIDATION_RESULT_PORTAL, 0 /* probesSucceeded*/, TEST_LOGIN_URL);


        verify(mCapportApiConnection).getResponseCode();
        verify(mCapportApiConnection).getResponseCode();


@@ -1329,8 +1335,8 @@ public class NetworkMonitorTest {
                + "'bytes-remaining': " + bytesRemaining + ","
                + "'bytes-remaining': " + bytesRemaining + ","
                + "'seconds-remaining': " + secondsRemaining + "}");
                + "'seconds-remaining': " + secondsRemaining + "}");


        runNetworkTest(makeCapportLPs(), CELL_METERED_CAPABILITIES, VALIDATION_RESULT_PORTAL,
        runNetworkTest(TEST_AGENT_CONFIG, makeCapportLPs(), CELL_METERED_CAPABILITIES,
                0 /* probesSucceeded*/, TEST_LOGIN_URL);
                VALIDATION_RESULT_PORTAL, 0 /* probesSucceeded*/, TEST_LOGIN_URL);


        verify(mHttpConnection, never()).getResponseCode();
        verify(mHttpConnection, never()).getResponseCode();
        verify(mCapportApiConnection).getResponseCode();
        verify(mCapportApiConnection).getResponseCode();
@@ -1390,7 +1396,8 @@ public class NetworkMonitorTest {
                + "'user-portal-url': '" + TEST_LOGIN_URL + "'}");
                + "'user-portal-url': '" + TEST_LOGIN_URL + "'}");


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


        verify(mHttpConnection, never()).getResponseCode();
        verify(mHttpConnection, never()).getResponseCode();
@@ -1404,8 +1411,8 @@ public class NetworkMonitorTest {
        setStatus(mHttpConnection, 500);
        setStatus(mHttpConnection, 500);
        setApiContent(mCapportApiConnection, "{'captive': false,"
        setApiContent(mCapportApiConnection, "{'captive': false,"
                + "'venue-info-url': '" + TEST_VENUE_INFO_URL + "'}");
                + "'venue-info-url': '" + TEST_VENUE_INFO_URL + "'}");
        runNetworkTest(makeCapportLPs(), CELL_METERED_CAPABILITIES, VALIDATION_RESULT_INVALID,
        runNetworkTest(TEST_AGENT_CONFIG, makeCapportLPs(), CELL_METERED_CAPABILITIES,
                0 /* probesSucceeded */, null /* redirectUrl */);
                VALIDATION_RESULT_INVALID, 0 /* probesSucceeded */, null /* redirectUrl */);


        final ArgumentCaptor<CaptivePortalData> capportCaptor = ArgumentCaptor.forClass(
        final ArgumentCaptor<CaptivePortalData> capportCaptor = ArgumentCaptor.forClass(
                CaptivePortalData.class);
                CaptivePortalData.class);
@@ -1420,7 +1427,7 @@ public class NetworkMonitorTest {
        setStatus(mHttpConnection, 204);
        setStatus(mHttpConnection, 204);
        setApiContent(mCapportApiConnection, "{'captive': false,"
        setApiContent(mCapportApiConnection, "{'captive': false,"
                + "'venue-info-url': '" + TEST_VENUE_INFO_URL + "'}");
                + "'venue-info-url': '" + TEST_VENUE_INFO_URL + "'}");
        runNetworkTest(makeCapportLPs(), CELL_METERED_CAPABILITIES,
        runNetworkTest(TEST_AGENT_CONFIG, makeCapportLPs(), CELL_METERED_CAPABILITIES,
                NETWORK_VALIDATION_RESULT_PARTIAL,
                NETWORK_VALIDATION_RESULT_PARTIAL,
                NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_HTTP,
                NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_HTTP,
                null /* redirectUrl */);
                null /* redirectUrl */);
@@ -1438,7 +1445,7 @@ public class NetworkMonitorTest {
        setStatus(mHttpConnection, 204);
        setStatus(mHttpConnection, 204);
        setApiContent(mCapportApiConnection, "{'captive': false,"
        setApiContent(mCapportApiConnection, "{'captive': false,"
                + "'venue-info-url': '" + TEST_VENUE_INFO_URL + "'}");
                + "'venue-info-url': '" + TEST_VENUE_INFO_URL + "'}");
        runNetworkTest(makeCapportLPs(), CELL_METERED_CAPABILITIES,
        runNetworkTest(TEST_AGENT_CONFIG, makeCapportLPs(), CELL_METERED_CAPABILITIES,
                NETWORK_VALIDATION_RESULT_VALID,
                NETWORK_VALIDATION_RESULT_VALID,
                NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_HTTP
                NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_HTTP
                        | NETWORK_VALIDATION_PROBE_HTTPS,
                        | NETWORK_VALIDATION_PROBE_HTTPS,
@@ -1456,7 +1463,7 @@ public class NetworkMonitorTest {
        setSslException(mHttpsConnection);
        setSslException(mHttpsConnection);
        setPortal302(mHttpConnection);
        setPortal302(mHttpConnection);
        setApiContent(mCapportApiConnection, "{SomeInvalidText");
        setApiContent(mCapportApiConnection, "{SomeInvalidText");
        runNetworkTest(makeCapportLPs(), CELL_METERED_CAPABILITIES,
        runNetworkTest(TEST_AGENT_CONFIG, makeCapportLPs(), CELL_METERED_CAPABILITIES,
                VALIDATION_RESULT_PORTAL, 0 /* probesSucceeded */,
                VALIDATION_RESULT_PORTAL, 0 /* probesSucceeded */,
                TEST_LOGIN_URL);
                TEST_LOGIN_URL);


@@ -1470,7 +1477,7 @@ public class NetworkMonitorTest {
        setPortal302(mHttpConnection);
        setPortal302(mHttpConnection);
        final LinkProperties lp = new LinkProperties(TEST_LINK_PROPERTIES);
        final LinkProperties lp = new LinkProperties(TEST_LINK_PROPERTIES);
        lp.setCaptivePortalApiUrl(Uri.parse(url));
        lp.setCaptivePortalApiUrl(Uri.parse(url));
        runNetworkTest(makeCapportLPs(), CELL_METERED_CAPABILITIES,
        runNetworkTest(TEST_AGENT_CONFIG, makeCapportLPs(), CELL_METERED_CAPABILITIES,
                VALIDATION_RESULT_PORTAL, 0 /* probesSucceeded */,
                VALIDATION_RESULT_PORTAL, 0 /* probesSucceeded */,
                TEST_LOGIN_URL);
                TEST_LOGIN_URL);


@@ -1503,9 +1510,8 @@ public class NetworkMonitorTest {
        setPortal302(mHttpConnection);
        setPortal302(mHttpConnection);
        setApiContent(mCapportApiConnection, "{'captive': false,"
        setApiContent(mCapportApiConnection, "{'captive': false,"
                + "'venue-info-url': '" + TEST_VENUE_INFO_URL + "'}");
                + "'venue-info-url': '" + TEST_VENUE_INFO_URL + "'}");
        runNetworkTest(makeCapportLPs(), CELL_METERED_CAPABILITIES, VALIDATION_RESULT_PORTAL,
        runNetworkTest(TEST_AGENT_CONFIG, makeCapportLPs(), CELL_METERED_CAPABILITIES,
                0 /* probesSucceeded */,
                VALIDATION_RESULT_PORTAL, 0 /* probesSucceeded */, TEST_LOGIN_URL);
                TEST_LOGIN_URL);


        verify(mCallbacks, never()).notifyCaptivePortalDataChanged(any());
        verify(mCallbacks, never()).notifyCaptivePortalDataChanged(any());
        verify(mHttpConnection).getResponseCode();
        verify(mHttpConnection).getResponseCode();
@@ -1860,7 +1866,7 @@ public class NetworkMonitorTest {


    private void doValidationSkippedTest(NetworkCapabilities nc, int validationResult)
    private void doValidationSkippedTest(NetworkCapabilities nc, int validationResult)
            throws Exception {
            throws Exception {
        runNetworkTest(TEST_LINK_PROPERTIES, nc, validationResult,
        runNetworkTest(TEST_AGENT_CONFIG, TEST_LINK_PROPERTIES, nc, validationResult,
                0 /* probesSucceeded */, null /* redirectUrl */);
                0 /* probesSucceeded */, null /* redirectUrl */);
        verify(mCleartextDnsNetwork, never()).openConnection(any());
        verify(mCleartextDnsNetwork, never()).openConnection(any());
    }
    }
@@ -1924,7 +1930,7 @@ public class NetworkMonitorTest {
        setStatus(mHttpsConnection, 204);
        setStatus(mHttpsConnection, 204);
        setStatus(mHttpConnection, 204);
        setStatus(mHttpConnection, 204);


        final NetworkMonitor nm = runNetworkTest(
        final NetworkMonitor nm = runNetworkTest(TEST_AGENT_CONFIG,
                TEST_LINK_PROPERTIES, getVcnUnderlyingCarrierWifiCaps(),
                TEST_LINK_PROPERTIES, getVcnUnderlyingCarrierWifiCaps(),
                NETWORK_VALIDATION_RESULT_VALID,
                NETWORK_VALIDATION_RESULT_VALID,
                NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_HTTPS,
                NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_HTTPS,
@@ -1940,7 +1946,7 @@ public class NetworkMonitorTest {
        setStatus(mHttpConnection, 500);
        setStatus(mHttpConnection, 500);
        setStatus(mFallbackConnection, 404);
        setStatus(mFallbackConnection, 404);


        final NetworkMonitor nm = runNetworkTest(
        final NetworkMonitor nm = runNetworkTest(TEST_AGENT_CONFIG,
                TEST_LINK_PROPERTIES, getVcnUnderlyingCarrierWifiCaps(),
                TEST_LINK_PROPERTIES, getVcnUnderlyingCarrierWifiCaps(),
                VALIDATION_RESULT_INVALID, 0 /* probesSucceeded */, null /* redirectUrl */);
                VALIDATION_RESULT_INVALID, 0 /* probesSucceeded */, null /* redirectUrl */);
        assertEquals(VALIDATION_RESULT_INVALID,
        assertEquals(VALIDATION_RESULT_INVALID,
@@ -2066,7 +2072,8 @@ public class NetworkMonitorTest {


        WrappedNetworkMonitor wnm = makeCellNotMeteredNetworkMonitor();
        WrappedNetworkMonitor wnm = makeCellNotMeteredNetworkMonitor();
        wnm.notifyPrivateDnsSettingsChanged(new PrivateDnsConfig("dns.google", new InetAddress[0]));
        wnm.notifyPrivateDnsSettingsChanged(new PrivateDnsConfig("dns.google", new InetAddress[0]));
        wnm.notifyNetworkConnected(TEST_LINK_PROPERTIES, CELL_NOT_METERED_CAPABILITIES);
        wnm.notifyNetworkConnectedParcel(makeParams(TEST_AGENT_CONFIG, TEST_LINK_PROPERTIES,
                CELL_NOT_METERED_CAPABILITIES));
        verifyNetworkTested(VALIDATION_RESULT_INVALID,
        verifyNetworkTested(VALIDATION_RESULT_INVALID,
                NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_HTTPS);
                NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_HTTPS);
        verify(mCallbacks, timeout(HANDLER_TIMEOUT_MS)).notifyProbeStatusChanged(
        verify(mCallbacks, timeout(HANDLER_TIMEOUT_MS)).notifyProbeStatusChanged(
@@ -2093,7 +2100,8 @@ public class NetworkMonitorTest {


        WrappedNetworkMonitor wnm = makeCellNotMeteredNetworkMonitor();
        WrappedNetworkMonitor wnm = makeCellNotMeteredNetworkMonitor();
        wnm.notifyPrivateDnsSettingsChanged(new PrivateDnsConfig("dns.google", new InetAddress[0]));
        wnm.notifyPrivateDnsSettingsChanged(new PrivateDnsConfig("dns.google", new InetAddress[0]));
        wnm.notifyNetworkConnected(TEST_LINK_PROPERTIES, CELL_NOT_METERED_CAPABILITIES);
        wnm.notifyNetworkConnectedParcel(makeParams(TEST_AGENT_CONFIG, TEST_LINK_PROPERTIES,
                CELL_NOT_METERED_CAPABILITIES));
        verifyNetworkTested(VALIDATION_RESULT_INVALID,
        verifyNetworkTested(VALIDATION_RESULT_INVALID,
                NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_HTTPS);
                NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_HTTPS);
        verify(mCallbacks, timeout(HANDLER_TIMEOUT_MS).times(1)).notifyProbeStatusChanged(
        verify(mCallbacks, timeout(HANDLER_TIMEOUT_MS).times(1)).notifyProbeStatusChanged(
@@ -2224,7 +2232,7 @@ public class NetworkMonitorTest {
            nm = null;
            nm = null;
            fail("Undefined transport type");
            fail("Undefined transport type");
        }
        }
        nm.notifyNetworkConnected(TEST_LINK_PROPERTIES, nc);
        nm.notifyNetworkConnectedParcel(makeParams(TEST_AGENT_CONFIG, TEST_LINK_PROPERTIES, nc));
        verifyNetworkTested(NETWORK_VALIDATION_RESULT_VALID,
        verifyNetworkTested(NETWORK_VALIDATION_RESULT_VALID,
                NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_HTTPS);
                NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_HTTPS);
        nm.setLastProbeTime(SystemClock.elapsedRealtime() - STALL_EXPECTED_LAST_PROBE_TIME_MS);
        nm.setLastProbeTime(SystemClock.elapsedRealtime() - STALL_EXPECTED_LAST_PROBE_TIME_MS);
@@ -2534,7 +2542,8 @@ public class NetworkMonitorTest {
        setStatus(mHttpsConnection, 204);
        setStatus(mHttpsConnection, 204);
        setStatus(mHttpConnection, 204);
        setStatus(mHttpConnection, 204);
        final NetworkMonitor nm = makeMonitor(CELL_METERED_CAPABILITIES);
        final NetworkMonitor nm = makeMonitor(CELL_METERED_CAPABILITIES);
        nm.notifyNetworkConnected(TEST_LINK_PROPERTIES, CELL_METERED_CAPABILITIES);
        nm.notifyNetworkConnectedParcel(makeParams(TEST_AGENT_CONFIG, TEST_LINK_PROPERTIES,
                CELL_METERED_CAPABILITIES));


        verify(mCallbacks, timeout(HANDLER_TIMEOUT_MS))
        verify(mCallbacks, timeout(HANDLER_TIMEOUT_MS))
                .notifyNetworkTested(eq(NETWORK_VALIDATION_RESULT_VALID
                .notifyNetworkTested(eq(NETWORK_VALIDATION_RESULT_VALID
@@ -2799,7 +2808,8 @@ public class NetworkMonitorTest {
        monitor.notifyLinkPropertiesChanged(linkProperties);
        monitor.notifyLinkPropertiesChanged(linkProperties);
        final NetworkCapabilities networkCapabilities =
        final NetworkCapabilities networkCapabilities =
                new NetworkCapabilities(WIFI_NOT_METERED_CAPABILITIES);
                new NetworkCapabilities(WIFI_NOT_METERED_CAPABILITIES);
        monitor.notifyNetworkConnected(linkProperties, networkCapabilities);
        monitor.notifyNetworkConnectedParcel(makeParams(TEST_AGENT_CONFIG,
                linkProperties, networkCapabilities));
        verify(mCallbacks, timeout(HANDLER_TIMEOUT_MS).times(1))
        verify(mCallbacks, timeout(HANDLER_TIMEOUT_MS).times(1))
                .showProvisioningNotification(any(), any());
                .showProvisioningNotification(any(), any());
        assertCaptivePortalAppReceiverRegistered(true /* isPortal */);
        assertCaptivePortalAppReceiverRegistered(true /* isPortal */);
@@ -2827,8 +2837,8 @@ public class NetworkMonitorTest {
    public void testOemPaidNetworkValidated() throws Exception {
    public void testOemPaidNetworkValidated() throws Exception {
        setValidProbes();
        setValidProbes();


        final NetworkMonitor nm = runNetworkTest(TEST_LINK_PROPERTIES,
        final NetworkMonitor nm = runNetworkTest(
                WIFI_OEM_PAID_CAPABILITIES,
                TEST_AGENT_CONFIG, TEST_LINK_PROPERTIES, WIFI_OEM_PAID_CAPABILITIES,
                NETWORK_VALIDATION_RESULT_VALID,
                NETWORK_VALIDATION_RESULT_VALID,
                NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_HTTPS,
                NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_HTTPS,
                null /* redirectUrl */);
                null /* redirectUrl */);
@@ -2842,8 +2852,7 @@ public class NetworkMonitorTest {
        setStatus(mHttpConnection, 500);
        setStatus(mHttpConnection, 500);
        setStatus(mFallbackConnection, 404);
        setStatus(mFallbackConnection, 404);


        runNetworkTest(TEST_LINK_PROPERTIES,
        runNetworkTest(TEST_AGENT_CONFIG, TEST_LINK_PROPERTIES, WIFI_OEM_PAID_CAPABILITIES,
                WIFI_OEM_PAID_CAPABILITIES,
                VALIDATION_RESULT_INVALID, 0 /* probesSucceeded */, null /* redirectUrl */);
                VALIDATION_RESULT_INVALID, 0 /* probesSucceeded */, null /* redirectUrl */);
    }
    }


@@ -2859,7 +2868,7 @@ public class NetworkMonitorTest {


        final int validationResult =
        final int validationResult =
                NETWORK_VALIDATION_RESULT_VALID | NETWORK_VALIDATION_RESULT_SKIPPED;
                NETWORK_VALIDATION_RESULT_VALID | NETWORK_VALIDATION_RESULT_SKIPPED;
        runNetworkTest(TEST_LINK_PROPERTIES, networkCapabilities,
        runNetworkTest(TEST_AGENT_CONFIG, TEST_LINK_PROPERTIES, networkCapabilities,
                validationResult, 0 /* probesSucceeded */, null /* redirectUrl */);
                validationResult, 0 /* probesSucceeded */, null /* redirectUrl */);


        verify(mCleartextDnsNetwork, never()).openConnection(any());
        verify(mCleartextDnsNetwork, never()).openConnection(any());
@@ -2874,7 +2883,7 @@ public class NetworkMonitorTest {
        setStatus(mFallbackConnection, 404);
        setStatus(mFallbackConnection, 404);
        setPortal302(mHttpConnection);
        setPortal302(mHttpConnection);


        runNetworkTest(TEST_LINK_PROPERTIES, WIFI_OEM_PAID_CAPABILITIES,
        runNetworkTest(TEST_AGENT_CONFIG, TEST_LINK_PROPERTIES, WIFI_OEM_PAID_CAPABILITIES,
                VALIDATION_RESULT_PORTAL, 0 /* probesSucceeded */,
                VALIDATION_RESULT_PORTAL, 0 /* probesSucceeded */,
                TEST_LOGIN_URL);
                TEST_LOGIN_URL);


@@ -3000,14 +3009,15 @@ public class NetworkMonitorTest {


    private NetworkMonitor runNetworkTest(int testResult, int probesSucceeded, String redirectUrl)
    private NetworkMonitor runNetworkTest(int testResult, int probesSucceeded, String redirectUrl)
            throws RemoteException {
            throws RemoteException {
        return runNetworkTest(TEST_LINK_PROPERTIES, CELL_METERED_CAPABILITIES, testResult,
        return runNetworkTest(TEST_AGENT_CONFIG, TEST_LINK_PROPERTIES, CELL_METERED_CAPABILITIES,
                probesSucceeded, redirectUrl);
                testResult, probesSucceeded, redirectUrl);
    }
    }


    private NetworkMonitor runNetworkTest(LinkProperties lp, NetworkCapabilities nc,
    private NetworkMonitor runNetworkTest(NetworkAgentConfig config,
            LinkProperties lp, NetworkCapabilities nc,
            int testResult, int probesSucceeded, String redirectUrl) throws RemoteException {
            int testResult, int probesSucceeded, String redirectUrl) throws RemoteException {
        final NetworkMonitor monitor = makeMonitor(nc);
        final NetworkMonitor monitor = makeMonitor(nc);
        monitor.notifyNetworkConnected(lp, nc);
        monitor.notifyNetworkConnectedParcel(makeParams(config, lp, nc));
        verifyNetworkTested(testResult, probesSucceeded, redirectUrl);
        verifyNetworkTested(testResult, probesSucceeded, redirectUrl);
        HandlerUtils.waitForIdle(monitor.getHandler(), HANDLER_TIMEOUT_MS);
        HandlerUtils.waitForIdle(monitor.getHandler(), HANDLER_TIMEOUT_MS);


@@ -3045,7 +3055,16 @@ public class NetworkMonitorTest {
    }
    }


    private void notifyNetworkConnected(NetworkMonitor nm, NetworkCapabilities nc) {
    private void notifyNetworkConnected(NetworkMonitor nm, NetworkCapabilities nc) {
        nm.notifyNetworkConnected(TEST_LINK_PROPERTIES, nc);
        nm.notifyNetworkConnectedParcel(makeParams(TEST_AGENT_CONFIG, TEST_LINK_PROPERTIES, nc));
    }

    private NetworkMonitorParameters makeParams(@NonNull final NetworkAgentConfig config,
            @NonNull final LinkProperties prop, @NonNull final NetworkCapabilities caps) {
        final NetworkMonitorParameters params = new NetworkMonitorParameters();
        params.networkAgentConfig = config;
        params.linkProperties = prop;
        params.networkCapabilities = caps;
        return params;
    }
    }


    private void setSslException(HttpURLConnection connection) throws IOException {
    private void setSslException(HttpURLConnection connection) throws IOException {