ConnectivityService: dumpsys args for dumping networks or requests only.

This patch adds two arguments to ConnectivityService dumpsys handler so
that only current networks or only current requests are dumped:

- "adb shell dumpsys connectivity networks" will dump current networks.
- "adb shell dumpsys connectivity requests" will dump current requests.

Bug: none
Test: Compiled, flashed, booted, checked that both new dumpsys args work
      as expected.

Change-Id: Ie28e6c800795eb49f386b609e8222a25e73dfc84
This commit is contained in:
Hugo Benichi
2018-09-03 08:32:56 +09:00
parent a480ba57f5
commit 5df91ce8be

View File

@@ -200,6 +200,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
private static final String DIAG_ARG = "--diag"; private static final String DIAG_ARG = "--diag";
public static final String SHORT_ARG = "--short"; public static final String SHORT_ARG = "--short";
private static final String TETHERING_ARG = "tethering"; private static final String TETHERING_ARG = "tethering";
private static final String NETWORK_ARG = "networks";
private static final String REQUEST_ARG = "requests";
private static final boolean DBG = true; private static final boolean DBG = true;
private static final boolean VDBG = false; private static final boolean VDBG = false;
@@ -1972,6 +1974,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
} else if (ArrayUtils.contains(args, TETHERING_ARG)) { } else if (ArrayUtils.contains(args, TETHERING_ARG)) {
mTethering.dump(fd, pw, args); mTethering.dump(fd, pw, args);
return; return;
} else if (ArrayUtils.contains(args, NETWORK_ARG)) {
dumpNetworks(pw);
return;
} else if (ArrayUtils.contains(args, REQUEST_ARG)) {
dumpNetworkRequests(pw);
return;
} }
pw.print("NetworkFactories for:"); pw.print("NetworkFactories for:");
@@ -1992,36 +2000,15 @@ public class ConnectivityService extends IConnectivityManager.Stub
pw.println("Current Networks:"); pw.println("Current Networks:");
pw.increaseIndent(); pw.increaseIndent();
for (NetworkAgentInfo nai : networksSortedById()) { dumpNetworks(pw);
pw.println(nai.toString());
pw.increaseIndent();
pw.println(String.format(
"Requests: REQUEST:%d LISTEN:%d BACKGROUND_REQUEST:%d total:%d",
nai.numForegroundNetworkRequests(),
nai.numNetworkRequests() - nai.numRequestNetworkRequests(),
nai.numBackgroundNetworkRequests(),
nai.numNetworkRequests()));
pw.increaseIndent();
for (int i = 0; i < nai.numNetworkRequests(); i++) {
pw.println(nai.requestAt(i).toString());
}
pw.decreaseIndent();
pw.println("Lingered:");
pw.increaseIndent();
nai.dumpLingerTimers(pw);
pw.decreaseIndent();
pw.decreaseIndent();
}
pw.decreaseIndent(); pw.decreaseIndent();
pw.println(); pw.println();
pw.println("Network Requests:"); pw.println("Network Requests:");
pw.increaseIndent(); pw.increaseIndent();
for (NetworkRequestInfo nri : requestsSortedById()) { dumpNetworkRequests(pw);
pw.println(nri.toString());
}
pw.println();
pw.decreaseIndent(); pw.decreaseIndent();
pw.println();
mLegacyTypeTracker.dump(pw); mLegacyTypeTracker.dump(pw);
@@ -2074,6 +2061,35 @@ public class ConnectivityService extends IConnectivityManager.Stub
} }
} }
private void dumpNetworks(IndentingPrintWriter pw) {
for (NetworkAgentInfo nai : networksSortedById()) {
pw.println(nai.toString());
pw.increaseIndent();
pw.println(String.format(
"Requests: REQUEST:%d LISTEN:%d BACKGROUND_REQUEST:%d total:%d",
nai.numForegroundNetworkRequests(),
nai.numNetworkRequests() - nai.numRequestNetworkRequests(),
nai.numBackgroundNetworkRequests(),
nai.numNetworkRequests()));
pw.increaseIndent();
for (int i = 0; i < nai.numNetworkRequests(); i++) {
pw.println(nai.requestAt(i).toString());
}
pw.decreaseIndent();
pw.println("Lingered:");
pw.increaseIndent();
nai.dumpLingerTimers(pw);
pw.decreaseIndent();
pw.decreaseIndent();
}
}
private void dumpNetworkRequests(IndentingPrintWriter pw) {
for (NetworkRequestInfo nri : requestsSortedById()) {
pw.println(nri.toString());
}
}
/** /**
* Return an array of all current NetworkAgentInfos sorted by network id. * Return an array of all current NetworkAgentInfos sorted by network id.
*/ */