ConnectivityService: Sort requests and networks in dumpsys.

This patch adds two utility functions for sorting requests and networks
tracked by ConnectivityService by request id and network id
respectively.

These utility functions are then used to improve the output of
adb shell dumpsys connectivity so that networks and requests are
printed in a more stable fashion.

Bug: none
Test: Compiled, flashed, booted, checked output of adb shell
      dumpsys connectivity.

Change-Id: I3cb9b2ceab64145611a416dcb8c5d512838a2626
This commit is contained in:
Hugo Benichi
2018-09-03 08:19:02 +09:00
parent b71c6a1b7e
commit a480ba57f5

View File

@@ -180,6 +180,7 @@ import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -1945,7 +1946,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
private void dumpNetworkDiagnostics(IndentingPrintWriter pw) {
final List<NetworkDiagnostics> netDiags = new ArrayList<NetworkDiagnostics>();
final long DIAG_TIME_MS = 5000;
for (NetworkAgentInfo nai : mNetworkAgentInfos.values()) {
for (NetworkAgentInfo nai : networksSortedById()) {
// Start gathering diagnostic information.
netDiags.add(new NetworkDiagnostics(
nai.network,
@@ -1991,7 +1992,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
pw.println("Current Networks:");
pw.increaseIndent();
for (NetworkAgentInfo nai : mNetworkAgentInfos.values()) {
for (NetworkAgentInfo nai : networksSortedById()) {
pw.println(nai.toString());
pw.increaseIndent();
pw.println(String.format(
@@ -2016,7 +2017,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
pw.println("Network Requests:");
pw.increaseIndent();
for (NetworkRequestInfo nri : mNetworkRequests.values()) {
for (NetworkRequestInfo nri : requestsSortedById()) {
pw.println(nri.toString());
}
pw.println();
@@ -2073,6 +2074,26 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
}
/**
* Return an array of all current NetworkAgentInfos sorted by network id.
*/
private NetworkAgentInfo[] networksSortedById() {
NetworkAgentInfo[] networks = new NetworkAgentInfo[0];
networks = mNetworkAgentInfos.values().toArray(networks);
Arrays.sort(networks, Comparator.comparingInt(nai -> nai.network.netId));
return networks;
}
/**
* Return an array of all current NetworkRequest sorted by request id.
*/
private NetworkRequestInfo[] requestsSortedById() {
NetworkRequestInfo[] requests = new NetworkRequestInfo[0];
requests = mNetworkRequests.values().toArray(requests);
Arrays.sort(requests, Comparator.comparingInt(nri -> nri.request.requestId));
return requests;
}
private boolean isLiveNetworkAgent(NetworkAgentInfo nai, int what) {
if (nai.network == null) return false;
final NetworkAgentInfo officialNai = getNetworkAgentInfoForNetwork(nai.network);
@@ -2864,7 +2885,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
pw.println("User setting: " + description);
pw.println("Network overrides:");
pw.increaseIndent();
for (NetworkAgentInfo nai : mNetworkAgentInfos.values()) {
for (NetworkAgentInfo nai : networksSortedById()) {
if (nai.avoidUnvalidated) {
pw.println(nai.name());
}