Snap for 9061588 from 76cba9b4587c5416c86cec2ae211ce609c22df94 to mainline-permission-release Change-Id: Icbc3b12588fdaa4fe8b970ff49eeb69c892c32db
diff --git a/src/com/android/server/connectivity/NetworkMonitor.java b/src/com/android/server/connectivity/NetworkMonitor.java index da6c289..61cb143 100755 --- a/src/com/android/server/connectivity/NetworkMonitor.java +++ b/src/com/android/server/connectivity/NetworkMonitor.java
@@ -442,6 +442,10 @@ private final String mCaptivePortalHttpsUrlFromSetting; private final String mCaptivePortalHttpUrlFromSetting; @Nullable + private final URL mTestCaptivePortalHttpsUrl; + @Nullable + private final URL mTestCaptivePortalHttpUrl; + @Nullable private final CaptivePortalProbeSpec[] mCaptivePortalFallbackSpecs; // The probing URLs may be updated after constructor if system notifies configuration changed. @@ -613,6 +617,9 @@ mDependencies.getSetting(context, CAPTIVE_PORTAL_HTTPS_URL, null); mCaptivePortalHttpUrlFromSetting = mDependencies.getSetting(context, CAPTIVE_PORTAL_HTTP_URL, null); + mTestCaptivePortalHttpsUrl = + getTestUrl(TEST_CAPTIVE_PORTAL_HTTPS_URL, validationLogs, deps); + mTestCaptivePortalHttpUrl = getTestUrl(TEST_CAPTIVE_PORTAL_HTTP_URL, validationLogs, deps); mIsCaptivePortalCheckEnabled = getIsCaptivePortalCheckEnabled(); mPrivateIpNoInternetEnabled = getIsPrivateIpNoInternetEnabled(); mMetricsEnabled = deps.isFeatureEnabled(context, NAMESPACE_CONNECTIVITY, @@ -2065,8 +2072,9 @@ } @Nullable - private URL getTestUrl(@NonNull String key) { - final String strExpiration = mDependencies.getDeviceConfigProperty(NAMESPACE_CONNECTIVITY, + private static URL getTestUrl(@NonNull String key, @NonNull SharedLog log, + @NonNull Dependencies deps) { + final String strExpiration = deps.getDeviceConfigProperty(NAMESPACE_CONNECTIVITY, TEST_URL_EXPIRATION_TIME, null); if (strExpiration == null) return null; @@ -2074,23 +2082,23 @@ try { expTime = Long.parseUnsignedLong(strExpiration); } catch (NumberFormatException e) { - loge("Invalid test URL expiration time format", e); + log.e("Invalid test URL expiration time format", e); return null; } final long now = System.currentTimeMillis(); if (expTime < now || (expTime - now) > TEST_URL_EXPIRATION_MS) { - logw("Skipping test URL with expiration " + expTime + ", now " + now); + log.w("Skipping test URL with expiration " + expTime + ", now " + now); return null; } - final String strUrl = mDependencies.getDeviceConfigProperty(NAMESPACE_CONNECTIVITY, + final String strUrl = deps.getDeviceConfigProperty(NAMESPACE_CONNECTIVITY, key, null /* defaultValue */); if (!isValidTestUrl(strUrl)) { - logw("Skipping invalid test URL " + strUrl); + log.w("Skipping invalid test URL " + strUrl); return null; } - return makeURL(strUrl); + return makeURL(strUrl, log); } private String getCaptivePortalServerHttpsUrl(@NonNull Context context) { @@ -2251,8 +2259,7 @@ } private URL[] makeCaptivePortalHttpsUrls(@NonNull Context context) { - final URL testUrl = getTestUrl(TEST_CAPTIVE_PORTAL_HTTPS_URL); - if (testUrl != null) return new URL[] { testUrl }; + if (mTestCaptivePortalHttpsUrl != null) return new URL[] { mTestCaptivePortalHttpsUrl }; final String firstUrl = getCaptivePortalServerHttpsUrl(context); try { @@ -2272,8 +2279,7 @@ } private URL[] makeCaptivePortalHttpUrls(@NonNull Context context) { - final URL testUrl = getTestUrl(TEST_CAPTIVE_PORTAL_HTTP_URL); - if (testUrl != null) return new URL[] { testUrl }; + if (mTestCaptivePortalHttpUrl != null) return new URL[] { mTestCaptivePortalHttpUrl }; final String firstUrl = getCaptivePortalServerHttpUrl(context); try { @@ -3171,12 +3177,18 @@ } } - private URL makeURL(String url) { + @Nullable + private URL makeURL(@Nullable String url) { + return makeURL(url, mValidationLogs); + } + + @Nullable + private static URL makeURL(@Nullable String url, @NonNull SharedLog log) { if (url != null) { try { return new URL(url); } catch (MalformedURLException e) { - validationLog("Bad URL: " + url); + log.w("Bad URL: " + url); } } return null;