Merge "Add Validation logging." into mnc-dev

This commit is contained in:
Robert Greenwalt
2015-06-26 22:40:29 +00:00
committed by Android (Google) Code Review
3 changed files with 69 additions and 16 deletions

View File

@@ -54,4 +54,18 @@ public final class LocalLog {
pw.println(itr.next()); pw.println(itr.next());
} }
} }
public static class ReadOnlyLocalLog {
private final LocalLog mLog;
ReadOnlyLocalLog(LocalLog log) {
mLog = log;
}
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
mLog.dump(fd, pw, args);
}
}
public ReadOnlyLocalLog readOnlyLocalLog() {
return new ReadOnlyLocalLog(this);
}
} }

View File

@@ -93,6 +93,9 @@ import android.security.Credentials;
import android.security.KeyStore; import android.security.KeyStore;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.LocalLog;
import android.util.LocalLog.ReadOnlyLocalLog;
import android.util.Pair;
import android.util.Slog; import android.util.Slog;
import android.util.SparseArray; import android.util.SparseArray;
import android.util.SparseBooleanArray; import android.util.SparseBooleanArray;
@@ -140,6 +143,7 @@ import java.net.Inet4Address;
import java.net.Inet6Address; import java.net.Inet6Address;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.ArrayDeque;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@@ -415,6 +419,20 @@ public class ConnectivityService extends IConnectivityManager.Stub
// sequence number of NetworkRequests // sequence number of NetworkRequests
private int mNextNetworkRequestId = 1; private int mNextNetworkRequestId = 1;
// Array of <Network,ReadOnlyLocalLogs> tracking network validation and results
private static final int MAX_VALIDATION_LOGS = 10;
private final ArrayDeque<Pair<Network,ReadOnlyLocalLog>> mValidationLogs =
new ArrayDeque<Pair<Network,ReadOnlyLocalLog>>(MAX_VALIDATION_LOGS);
private void addValidationLogs(ReadOnlyLocalLog log, Network network) {
synchronized(mValidationLogs) {
while (mValidationLogs.size() >= MAX_VALIDATION_LOGS) {
mValidationLogs.removeLast();
}
mValidationLogs.addFirst(new Pair(network, log));
}
}
/** /**
* Implements support for the legacy "one network per network type" model. * Implements support for the legacy "one network per network type" model.
* *
@@ -1716,11 +1734,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
return ret; return ret;
} }
private boolean shouldPerformDiagnostics(String[] args) { private boolean argsContain(String[] args, String target) {
for (String arg : args) { for (String arg : args) {
if (arg.equals("--diag")) { if (arg.equals(target)) return true;
return true;
}
} }
return false; return false;
} }
@@ -1738,7 +1754,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
} }
final List<NetworkDiagnostics> netDiags = new ArrayList<NetworkDiagnostics>(); final List<NetworkDiagnostics> netDiags = new ArrayList<NetworkDiagnostics>();
if (shouldPerformDiagnostics(args)) { if (argsContain(args, "--diag")) {
final long DIAG_TIME_MS = 5000; final long DIAG_TIME_MS = 5000;
for (NetworkAgentInfo nai : mNetworkAgentInfos.values()) { for (NetworkAgentInfo nai : mNetworkAgentInfos.values()) {
// Start gathering diagnostic information. // Start gathering diagnostic information.
@@ -1825,6 +1841,19 @@ public class ConnectivityService extends IConnectivityManager.Stub
} }
pw.decreaseIndent(); pw.decreaseIndent();
} }
if (argsContain(args, "--short") == false) {
pw.println();
synchronized (mValidationLogs) {
pw.println("mValidationLogs (most recent first):");
for (Pair<Network,ReadOnlyLocalLog> p : mValidationLogs) {
pw.println(p.first);
pw.increaseIndent();
p.second.dump(fd, pw, args);
pw.decreaseIndent();
}
}
}
} }
private boolean isLiveNetworkAgent(NetworkAgentInfo nai, String msg) { private boolean isLiveNetworkAgent(NetworkAgentInfo nai, String msg) {
@@ -3841,6 +3870,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
synchronized (this) { synchronized (this) {
nai.networkMonitor.systemReady = mSystemReady; nai.networkMonitor.systemReady = mSystemReady;
} }
addValidationLogs(nai.networkMonitor.getValidationLogs(), nai.network);
if (DBG) log("registerNetworkAgent " + nai); if (DBG) log("registerNetworkAgent " + nai);
mHandler.sendMessage(mHandler.obtainMessage(EVENT_REGISTER_NETWORK_AGENT, nai)); mHandler.sendMessage(mHandler.obtainMessage(EVENT_REGISTER_NETWORK_AGENT, nai));
return nai.network.netId; return nai.network.netId;

View File

@@ -47,6 +47,8 @@ import android.telephony.CellInfoGsm;
import android.telephony.CellInfoLte; import android.telephony.CellInfoLte;
import android.telephony.CellInfoWcdma; import android.telephony.CellInfoWcdma;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.util.LocalLog;
import android.util.LocalLog.ReadOnlyLocalLog;
import android.util.Log; import android.util.Log;
import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting;
@@ -232,6 +234,8 @@ public class NetworkMonitor extends StateMachine {
private CustomIntentReceiver mLaunchCaptivePortalAppBroadcastReceiver = null; private CustomIntentReceiver mLaunchCaptivePortalAppBroadcastReceiver = null;
private String mCaptivePortalLoggedInResponseToken = null; private String mCaptivePortalLoggedInResponseToken = null;
private final LocalLog validationLogs = new LocalLog(20); // 20 lines
public NetworkMonitor(Context context, Handler handler, NetworkAgentInfo networkAgentInfo, public NetworkMonitor(Context context, Handler handler, NetworkAgentInfo networkAgentInfo,
NetworkRequest defaultRequest) { NetworkRequest defaultRequest) {
// Add suffix indicating which NetworkMonitor we're talking about. // Add suffix indicating which NetworkMonitor we're talking about.
@@ -272,6 +276,15 @@ public class NetworkMonitor extends StateMachine {
Log.d(TAG + "/" + mNetworkAgentInfo.name(), s); Log.d(TAG + "/" + mNetworkAgentInfo.name(), s);
} }
private void validationLog(String s) {
if (DBG) log(s);
validationLogs.log(s);
}
public ReadOnlyLocalLog getValidationLogs() {
return validationLogs.readOnlyLocalLog();
}
// DefaultState is the parent of all States. It exists only to handle CMD_* messages but // DefaultState is the parent of all States. It exists only to handle CMD_* messages but
// does not entail any real state (hence no enter() or exit() routines). // does not entail any real state (hence no enter() or exit() routines).
private class DefaultState extends State { private class DefaultState extends State {
@@ -649,10 +662,8 @@ public class NetworkMonitor extends StateMachine {
fetchPac = true; fetchPac = true;
} }
} }
if (DBG) { validationLog("Checking " + url.toString() + " on " +
log("Checking " + url.toString() + " on " + mNetworkAgentInfo.networkInfo.getExtraInfo());
mNetworkAgentInfo.networkInfo.getExtraInfo());
}
urlConnection = (HttpURLConnection) mNetworkAgentInfo.network.openConnection(url); urlConnection = (HttpURLConnection) mNetworkAgentInfo.network.openConnection(url);
urlConnection.setInstanceFollowRedirects(fetchPac); urlConnection.setInstanceFollowRedirects(fetchPac);
urlConnection.setConnectTimeout(SOCKET_TIMEOUT_MS); urlConnection.setConnectTimeout(SOCKET_TIMEOUT_MS);
@@ -668,10 +679,8 @@ public class NetworkMonitor extends StateMachine {
long responseTimestamp = SystemClock.elapsedRealtime(); long responseTimestamp = SystemClock.elapsedRealtime();
httpResponseCode = urlConnection.getResponseCode(); httpResponseCode = urlConnection.getResponseCode();
if (DBG) { validationLog("isCaptivePortal: ret=" + httpResponseCode +
log("isCaptivePortal: ret=" + httpResponseCode + " headers=" + urlConnection.getHeaderFields());
" headers=" + urlConnection.getHeaderFields());
}
// NOTE: We may want to consider an "HTTP/1.0 204" response to be a captive // NOTE: We may want to consider an "HTTP/1.0 204" response to be a captive
// portal. The only example of this seen so far was a captive portal. For // portal. The only example of this seen so far was a captive portal. For
// the time being go with prior behavior of assuming it's not a captive // the time being go with prior behavior of assuming it's not a captive
@@ -684,12 +693,12 @@ public class NetworkMonitor extends StateMachine {
// sign-in to an empty page. Probably the result of a broken transparent proxy. // sign-in to an empty page. Probably the result of a broken transparent proxy.
// See http://b/9972012. // See http://b/9972012.
if (httpResponseCode == 200 && urlConnection.getContentLength() == 0) { if (httpResponseCode == 200 && urlConnection.getContentLength() == 0) {
if (DBG) log("Empty 200 response interpreted as 204 response."); validationLog("Empty 200 response interpreted as 204 response.");
httpResponseCode = 204; httpResponseCode = 204;
} }
if (httpResponseCode == 200 && fetchPac) { if (httpResponseCode == 200 && fetchPac) {
if (DBG) log("PAC fetch 200 response interpreted as 204 response."); validationLog("PAC fetch 200 response interpreted as 204 response.");
httpResponseCode = 204; httpResponseCode = 204;
} }
@@ -697,7 +706,7 @@ public class NetworkMonitor extends StateMachine {
httpResponseCode != 204 /* isCaptivePortal */, httpResponseCode != 204 /* isCaptivePortal */,
requestTimestamp, responseTimestamp); requestTimestamp, responseTimestamp);
} catch (IOException e) { } catch (IOException e) {
if (DBG) log("Probably not a portal: exception " + e); validationLog("Probably not a portal: exception " + e);
if (httpResponseCode == 599) { if (httpResponseCode == 599) {
// TODO: Ping gateway and DNS server and log results. // TODO: Ping gateway and DNS server and log results.
} }