Read URLs from handler thread
It's a preparation for dynamically changing the probing URLs
after NetworkMonitor being created. The probing URLs are final
members that are read at the constructor. The URLs may be
updated in the following commit. The URLs will be used in the
probing thread instead of handler thread which could cause
problems. Thus, take the probing URLs as parameters read from
handler thread to the probing thread.
Bug: 189738017
Bug: 181919957
Test: atest NetworkStackTests
Change-Id: Iee2d31a9cd37ad83792653cb796e304aff616d37
diff --git a/src/com/android/server/connectivity/NetworkMonitor.java b/src/com/android/server/connectivity/NetworkMonitor.java
index cb0ee18..158a1c3 100755
--- a/src/com/android/server/connectivity/NetworkMonitor.java
+++ b/src/com/android/server/connectivity/NetworkMonitor.java
@@ -1595,8 +1595,13 @@
final int token = ++mProbeToken;
final ValidationProperties deps = new ValidationProperties(mNetworkCapabilities);
+ final URL fallbackUrl = nextFallbackUrl();
+ final URL[] httpsUrls = Arrays.copyOf(
+ mCaptivePortalHttpsUrls, mCaptivePortalHttpsUrls.length);
+ final URL[] httpUrls = Arrays.copyOf(
+ mCaptivePortalHttpUrls, mCaptivePortalHttpUrls.length);
mThread = new Thread(() -> sendMessage(obtainMessage(CMD_PROBE_COMPLETE, token, 0,
- isCaptivePortal(deps))));
+ isCaptivePortal(deps, httpsUrls, httpUrls, fallbackUrl))));
mThread.start();
}
@@ -2345,15 +2350,14 @@
}
}
- private CaptivePortalProbeResult isCaptivePortal(ValidationProperties properties) {
+ private CaptivePortalProbeResult isCaptivePortal(ValidationProperties properties,
+ URL[] httpsUrls, URL[] httpUrls, URL fallbackUrl) {
if (!mIsCaptivePortalCheckEnabled) {
validationLog("Validation disabled.");
return CaptivePortalProbeResult.success(CaptivePortalProbeResult.PROBE_UNKNOWN);
}
URL pacUrl = null;
- final URL[] httpsUrls = mCaptivePortalHttpsUrls;
- final URL[] httpUrls = mCaptivePortalHttpUrls;
// On networks with a PAC instead of fetching a URL that should result in a 204
// response, we instead simply fetch the PAC script. This is done for a few reasons:
@@ -2394,7 +2398,7 @@
} else if (mUseHttps && httpsUrls.length == 1 && httpUrls.length == 1) {
// Probe results are reported inside sendHttpAndHttpsParallelWithFallbackProbes.
result = sendHttpAndHttpsParallelWithFallbackProbes(properties, proxyInfo,
- httpsUrls[0], httpUrls[0]);
+ httpsUrls[0], httpUrls[0], fallbackUrl);
} else if (mUseHttps) {
// Support result aggregation from multiple Urls.
result = sendMultiParallelHttpAndHttpsProbes(properties, proxyInfo, httpsUrls,
@@ -2996,7 +3000,8 @@
}
private CaptivePortalProbeResult sendHttpAndHttpsParallelWithFallbackProbes(
- ValidationProperties properties, ProxyInfo proxy, URL httpsUrl, URL httpUrl) {
+ ValidationProperties properties, ProxyInfo proxy, URL httpsUrl, URL httpUrl,
+ URL fallbackUrl) {
// Number of probes to wait for. If a probe completes with a conclusive answer
// it shortcuts the latch immediately by forcing the count to 0.
final CountDownLatch latch = new CountDownLatch(2);
@@ -3042,10 +3047,10 @@
// If a fallback method exists, use it to retry portal detection.
// If we have new-style probe specs, use those. Otherwise, use the fallback URLs.
final CaptivePortalProbeSpec probeSpec = nextFallbackSpec();
- final URL fallbackUrl = (probeSpec != null) ? probeSpec.getUrl() : nextFallbackUrl();
+ final URL fallback = (probeSpec != null) ? probeSpec.getUrl() : fallbackUrl;
CaptivePortalProbeResult fallbackProbeResult = null;
- if (fallbackUrl != null) {
- fallbackProbeResult = sendHttpProbe(fallbackUrl, PROBE_FALLBACK, probeSpec);
+ if (fallback != null) {
+ fallbackProbeResult = sendHttpProbe(fallback, PROBE_FALLBACK, probeSpec);
reportHttpProbeResult(NETWORK_VALIDATION_PROBE_FALLBACK, fallbackProbeResult);
if (fallbackProbeResult.isPortal()) {
return fallbackProbeResult;