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

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

Merge "Have test URLs replace all validation URLs" am: a531526d am: cbd0e12f am: 959e624b

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

Change-Id: I74969350ad7790e64300d6e26e4a9f0194b47280
parents a8459558 959e624b
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -1904,7 +1904,7 @@ public class NetworkMonitor extends StateMachine {
    }

    @Nullable
    private String getTestUrl(@NonNull String key) {
    private URL getTestUrl(@NonNull String key) {
        final String strExpiration = mDependencies.getDeviceConfigProperty(NAMESPACE_CONNECTIVITY,
                TEST_URL_EXPIRATION_TIME, null);
        if (strExpiration == null) return null;
@@ -1920,13 +1920,13 @@ public class NetworkMonitor extends StateMachine {
        final long now = System.currentTimeMillis();
        if (expTime < now || (expTime - now) > TEST_URL_EXPIRATION_MS) return null;

        return mDependencies.getDeviceConfigProperty(NAMESPACE_CONNECTIVITY,
        final String strUrl = mDependencies.getDeviceConfigProperty(NAMESPACE_CONNECTIVITY,
                key, null /* defaultValue */);
        if (!isValidTestUrl(strUrl)) return null;
        return makeURL(strUrl);
    }

    private String getCaptivePortalServerHttpsUrl() {
        final String testUrl = getTestUrl(TEST_CAPTIVE_PORTAL_HTTPS_URL);
        if (isValidTestUrl(testUrl)) return testUrl;
        return getSettingFromResource(mCustomizedContext,
                R.string.config_captive_portal_https_url, CAPTIVE_PORTAL_HTTPS_URL,
                mCustomizedContext.getResources().getString(
@@ -2007,8 +2007,6 @@ public class NetworkMonitor extends StateMachine {
     * on one URL that can be used, while NetworkMonitor may implement more complex logic.
     */
    public String getCaptivePortalServerHttpUrl() {
        final String testUrl = getTestUrl(TEST_CAPTIVE_PORTAL_HTTP_URL);
        if (isValidTestUrl(testUrl)) return testUrl;
        return getSettingFromResource(mCustomizedContext,
                R.string.config_captive_portal_http_url, CAPTIVE_PORTAL_HTTP_URL,
                mCustomizedContext.getResources().getString(
@@ -2086,6 +2084,9 @@ public class NetworkMonitor extends StateMachine {
    }

    private URL[] makeCaptivePortalHttpsUrls() {
        final URL testUrl = getTestUrl(TEST_CAPTIVE_PORTAL_HTTPS_URL);
        if (testUrl != null) return new URL[] { testUrl };

        final String firstUrl = getCaptivePortalServerHttpsUrl();
        try {
            final URL[] settingProviderUrls =
@@ -2104,6 +2105,9 @@ public class NetworkMonitor extends StateMachine {
    }

    private URL[] makeCaptivePortalHttpUrls() {
        final URL testUrl = getTestUrl(TEST_CAPTIVE_PORTAL_HTTP_URL);
        if (testUrl != null) return new URL[] { testUrl };

        final String firstUrl = getCaptivePortalServerHttpUrl();
        try {
            final URL[] settingProviderUrls =
+26 −0
Original line number Diff line number Diff line
@@ -1540,6 +1540,32 @@ public class NetworkMonitorTest {
        verify(mHttpConnection).getResponseCode();
    }

    @Test
    public void testIsCaptivePortal_TestUrlsWithUrlOverlays() throws Exception {
        setupResourceForMultipleProbes();
        doReturn(TEST_HTTPS_URL).when(mResources)
                .getString(R.string.config_captive_portal_https_url);
        doReturn(TEST_HTTP_URL).when(mResources)
                .getString(R.string.config_captive_portal_http_url);

        setDeviceConfig(TEST_URL_EXPIRATION_TIME,
                String.valueOf(currentTimeMillis() + TimeUnit.MINUTES.toMillis(9)));
        setDeviceConfig(TEST_CAPTIVE_PORTAL_HTTPS_URL, TEST_OVERRIDE_URL);
        setDeviceConfig(TEST_CAPTIVE_PORTAL_HTTP_URL, TEST_OVERRIDE_URL);
        setStatus(mTestOverriddenUrlConnection, 204);

        runValidatedNetworkTest();
        verify(mHttpsConnection, never()).getResponseCode();
        verify(mHttpConnection, never()).getResponseCode();
        verify(mOtherHttpsConnection1, never()).getResponseCode();
        verify(mOtherHttpsConnection2, never()).getResponseCode();
        verify(mOtherHttpConnection1, never()).getResponseCode();
        verify(mOtherHttpConnection2, never()).getResponseCode();

        // Used for both HTTP and HTTPS: can be called once (if HTTPS validates first) or twice
        verify(mTestOverriddenUrlConnection, atLeastOnce()).getResponseCode();
    }

    @Test
    public void testIsDataStall_EvaluationDisabled() {
        setDataStallEvaluationType(0);