DO NOT MERGE NetworkMonitor: send one DNS probe per web probe
am: eb5e9aa2ce
Change-Id: I2e3d9794e56d434f838ead9f12ee4edc74a3d6f2
This commit is contained in:
@@ -707,48 +707,13 @@ public class NetworkMonitor extends StateMachine {
|
|||||||
|
|
||||||
long startTime = SystemClock.elapsedRealtime();
|
long startTime = SystemClock.elapsedRealtime();
|
||||||
|
|
||||||
// Pre-resolve the captive portal server host so we can log it.
|
final CaptivePortalProbeResult result;
|
||||||
// Only do this if HttpURLConnection is about to, to avoid any potentially
|
|
||||||
// unnecessary resolution.
|
|
||||||
String hostToResolve = null;
|
|
||||||
if (pacUrl != null) {
|
if (pacUrl != null) {
|
||||||
hostToResolve = pacUrl.getHost();
|
result = sendDnsAndHttpProbes(null, pacUrl, ValidationProbeEvent.PROBE_PAC);
|
||||||
} else if (proxyInfo != null) {
|
|
||||||
hostToResolve = proxyInfo.getHost();
|
|
||||||
} else {
|
|
||||||
hostToResolve = httpUrl.getHost();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!TextUtils.isEmpty(hostToResolve)) {
|
|
||||||
String probeName = ValidationProbeEvent.getProbeName(ValidationProbeEvent.PROBE_DNS);
|
|
||||||
final Stopwatch dnsTimer = new Stopwatch().start();
|
|
||||||
int dnsResult;
|
|
||||||
long dnsLatency;
|
|
||||||
try {
|
|
||||||
InetAddress[] addresses = mNetworkAgentInfo.network.getAllByName(hostToResolve);
|
|
||||||
dnsResult = ValidationProbeEvent.DNS_SUCCESS;
|
|
||||||
dnsLatency = dnsTimer.stop();
|
|
||||||
final StringBuffer connectInfo = new StringBuffer(", " + hostToResolve + "=");
|
|
||||||
for (InetAddress address : addresses) {
|
|
||||||
connectInfo.append(address.getHostAddress());
|
|
||||||
if (address != addresses[addresses.length-1]) connectInfo.append(",");
|
|
||||||
}
|
|
||||||
validationLog(probeName + " OK " + dnsLatency + "ms" + connectInfo);
|
|
||||||
} catch (UnknownHostException e) {
|
|
||||||
dnsResult = ValidationProbeEvent.DNS_FAILURE;
|
|
||||||
dnsLatency = dnsTimer.stop();
|
|
||||||
validationLog(probeName + " FAIL " + dnsLatency + "ms, " + hostToResolve);
|
|
||||||
}
|
|
||||||
logValidationProbe(dnsLatency, ValidationProbeEvent.PROBE_DNS, dnsResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
CaptivePortalProbeResult result;
|
|
||||||
if (pacUrl != null) {
|
|
||||||
result = sendHttpProbe(pacUrl, ValidationProbeEvent.PROBE_PAC);
|
|
||||||
} else if (mUseHttps) {
|
} else if (mUseHttps) {
|
||||||
result = sendParallelHttpProbes(httpsUrl, httpUrl, fallbackUrl);
|
result = sendParallelHttpProbes(proxyInfo, httpsUrl, httpUrl, fallbackUrl);
|
||||||
} else {
|
} else {
|
||||||
result = sendHttpProbe(httpUrl, ValidationProbeEvent.PROBE_HTTP);
|
result = sendDnsAndHttpProbes(proxyInfo, httpUrl, ValidationProbeEvent.PROBE_HTTP);
|
||||||
}
|
}
|
||||||
|
|
||||||
long endTime = SystemClock.elapsedRealtime();
|
long endTime = SystemClock.elapsedRealtime();
|
||||||
@@ -761,8 +726,50 @@ public class NetworkMonitor extends StateMachine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do a URL fetch on a known server to see if we get the data we expect.
|
* Do a DNS resolution and URL fetch on a known web server to see if we get the data we expect.
|
||||||
* Returns HTTP response code.
|
* @return a CaptivePortalProbeResult inferred from the HTTP response.
|
||||||
|
*/
|
||||||
|
private CaptivePortalProbeResult sendDnsAndHttpProbes(ProxyInfo proxy, URL url, int probeType) {
|
||||||
|
// Pre-resolve the captive portal server host so we can log it.
|
||||||
|
// Only do this if HttpURLConnection is about to, to avoid any potentially
|
||||||
|
// unnecessary resolution.
|
||||||
|
final String host = (proxy != null) ? proxy.getHost() : url.getHost();
|
||||||
|
sendDnsProbe(host);
|
||||||
|
return sendHttpProbe(url, probeType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Do a DNS resolution of the given server. */
|
||||||
|
private void sendDnsProbe(String host) {
|
||||||
|
if (TextUtils.isEmpty(host)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String name = ValidationProbeEvent.getProbeName(ValidationProbeEvent.PROBE_DNS);
|
||||||
|
final Stopwatch watch = new Stopwatch().start();
|
||||||
|
int result;
|
||||||
|
String connectInfo;
|
||||||
|
try {
|
||||||
|
InetAddress[] addresses = mNetworkAgentInfo.network.getAllByName(host);
|
||||||
|
result = ValidationProbeEvent.DNS_SUCCESS;
|
||||||
|
StringBuffer buffer = new StringBuffer(host).append("=");
|
||||||
|
for (InetAddress address : addresses) {
|
||||||
|
buffer.append(address.getHostAddress());
|
||||||
|
if (address != addresses[addresses.length-1]) buffer.append(",");
|
||||||
|
}
|
||||||
|
connectInfo = buffer.toString();
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
result = ValidationProbeEvent.DNS_FAILURE;
|
||||||
|
connectInfo = host;
|
||||||
|
}
|
||||||
|
final long latency = watch.stop();
|
||||||
|
String resultString = (ValidationProbeEvent.DNS_SUCCESS == result) ? "OK" : "FAIL";
|
||||||
|
validationLog(String.format("%s %s %dms, %s", name, resultString, latency, connectInfo));
|
||||||
|
logValidationProbe(latency, ValidationProbeEvent.PROBE_DNS, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do a URL fetch on a known web server to see if we get the data we expect.
|
||||||
|
* @return a CaptivePortalProbeResult inferred from the HTTP response.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected CaptivePortalProbeResult sendHttpProbe(URL url, int probeType) {
|
protected CaptivePortalProbeResult sendHttpProbe(URL url, int probeType) {
|
||||||
@@ -829,7 +836,7 @@ public class NetworkMonitor extends StateMachine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private CaptivePortalProbeResult sendParallelHttpProbes(
|
private CaptivePortalProbeResult sendParallelHttpProbes(
|
||||||
URL httpsUrl, URL httpUrl, URL fallbackUrl) {
|
ProxyInfo proxy, URL httpsUrl, URL httpUrl, URL fallbackUrl) {
|
||||||
// Number of probes to wait for. If a probe completes with a conclusive answer
|
// 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.
|
// it shortcuts the latch immediately by forcing the count to 0.
|
||||||
final CountDownLatch latch = new CountDownLatch(2);
|
final CountDownLatch latch = new CountDownLatch(2);
|
||||||
@@ -849,9 +856,10 @@ public class NetworkMonitor extends StateMachine {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (mIsHttps) {
|
if (mIsHttps) {
|
||||||
mResult = sendHttpProbe(httpsUrl, ValidationProbeEvent.PROBE_HTTPS);
|
mResult =
|
||||||
|
sendDnsAndHttpProbes(proxy, httpsUrl, ValidationProbeEvent.PROBE_HTTPS);
|
||||||
} else {
|
} else {
|
||||||
mResult = sendHttpProbe(httpUrl, ValidationProbeEvent.PROBE_HTTP);
|
mResult = sendDnsAndHttpProbes(proxy, httpUrl, ValidationProbeEvent.PROBE_HTTP);
|
||||||
}
|
}
|
||||||
if ((mIsHttps && mResult.isSuccessful()) || (!mIsHttps && mResult.isPortal())) {
|
if ((mIsHttps && mResult.isSuccessful()) || (!mIsHttps && mResult.isPortal())) {
|
||||||
// Stop waiting immediately if https succeeds or if http finds a portal.
|
// Stop waiting immediately if https succeeds or if http finds a portal.
|
||||||
|
|||||||
Reference in New Issue
Block a user