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

Commit bdebc297 authored by Hugo Benichi's avatar Hugo Benichi Committed by android-build-merger
Browse files

Merge "NetworkMonitor: improve captive portal validation logs" am: d6933a6c

am: deb64ea1

Change-Id: I8d9304663e8b5019b65bf048cc7a72e6e9e43043
parents f0928412 deb64ea1
Loading
Loading
Loading
Loading
+20 −15
Original line number Diff line number Diff line
@@ -301,6 +301,11 @@ public class NetworkMonitor extends StateMachine {
        if (DBG) Log.d(TAG + "/" + mNetworkAgentInfo.name(), s);
    }

    private void validationLog(int probeType, Object url, String msg) {
        String probeName = ValidationProbeEvent.getProbeName(probeType);
        validationLog(String.format("%s %s %s", probeName, url, msg));
    }

    private void validationLog(String s) {
        if (DBG) log(s);
        validationLogs.log(s);
@@ -752,20 +757,19 @@ public class NetworkMonitor extends StateMachine {
        String connectInfo;
        try {
            InetAddress[] addresses = mNetworkAgentInfo.network.getAllByName(host);
            result = ValidationProbeEvent.DNS_SUCCESS;
            StringBuffer buffer = new StringBuffer(host).append("=");
            StringBuffer buffer = new StringBuffer();
            for (InetAddress address : addresses) {
                buffer.append(address.getHostAddress());
                if (address != addresses[addresses.length-1]) buffer.append(",");
                buffer.append(',').append(address.getHostAddress());
            }
            connectInfo = buffer.toString();
            result = ValidationProbeEvent.DNS_SUCCESS;
            connectInfo = "OK " + buffer.substring(1);
        } catch (UnknownHostException e) {
            result = ValidationProbeEvent.DNS_FAILURE;
            connectInfo = host;
            connectInfo = "FAIL";
        }
        final long latency = watch.stop();
        String resultString = (ValidationProbeEvent.DNS_SUCCESS == result) ? "OK" : "FAIL";
        validationLog(String.format("%s %s %dms, %s", name, resultString, latency, connectInfo));
        validationLog(ValidationProbeEvent.PROBE_DNS, host,
                String.format("%dms %s", latency, connectInfo));
        logValidationProbe(latency, ValidationProbeEvent.PROBE_DNS, result);
    }

@@ -801,8 +805,7 @@ public class NetworkMonitor extends StateMachine {
            // Time how long it takes to get a response to our request
            long responseTimestamp = SystemClock.elapsedRealtime();

            validationLog(ValidationProbeEvent.getProbeName(probeType) + " " + url +
                    " time=" + (responseTimestamp - requestTimestamp) + "ms" +
            validationLog(probeType, url, "time=" + (responseTimestamp - requestTimestamp) + "ms" +
                    " ret=" + httpResponseCode +
                    " request=" + requestHeader +
                    " headers=" + urlConnection.getHeaderFields());
@@ -814,27 +817,29 @@ public class NetworkMonitor extends StateMachine {
            // proxy server.
            if (httpResponseCode == 200) {
                if (probeType == ValidationProbeEvent.PROBE_PAC) {
                    validationLog("PAC fetch 200 response interpreted as 204 response.");
                    validationLog(
                            probeType, url, "PAC fetch 200 response interpreted as 204 response.");
                    httpResponseCode = 204;
                } else if (urlConnection.getContentLengthLong() == 0) {
                    // Consider 200 response with "Content-length=0" to not be a captive portal.
                    // There's no point in considering this a captive portal as the user cannot
                    // sign-in to an empty page. Probably the result of a broken transparent proxy.
                    // See http://b/9972012.
                    validationLog(
                    validationLog(probeType, url,
                        "200 response with Content-length=0 interpreted as 204 response.");
                    httpResponseCode = 204;
                } else if (urlConnection.getContentLengthLong() == -1) {
                    // When no Content-length (default value == -1), attempt to read a byte from the
                    // response. Do not use available() as it is unreliable. See http://b/33498325.
                    if (urlConnection.getInputStream().read() == -1) {
                        validationLog("Empty 200 response interpreted as 204 response.");
                        validationLog(
                                probeType, url, "Empty 200 response interpreted as 204 response.");
                        httpResponseCode = 204;
                    }
                }
            }
        } catch (IOException e) {
            validationLog("Probably not a portal: exception " + e);
            validationLog(probeType, url, "Probably not a portal: exception " + e);
            if (httpResponseCode == 599) {
                // TODO: Ping gateway and DNS server and log results.
            }