Support "dumpsys connectivity trafficcontroller"

Enable ConnectivityService to dump BPF maps from libtraffic_controller.

Bug: 202086915
Test: adb shell dumpsys connectivity trafficcontroller
Test: atest CtsNetTestCases:ConnectivityManagerTest#testDumpBpfNetMaps
Test: run CTS in I021789813f116940d581e2c4a1fd357ff47bfa08
Change-Id: Ib0e935ee2b714ac61daceba6d13fa7a20f97f68f
This commit is contained in:
Ken Chen 2022-01-25 11:10:42 +08:00
commit e6d511f785

View file

@ -313,6 +313,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
public static final String SHORT_ARG = "--short";
private static final String NETWORK_ARG = "networks";
private static final String REQUEST_ARG = "requests";
private static final String TRAFFICCONTROLLER_ARG = "trafficcontroller";
private static final boolean DBG = true;
private static final boolean DDBG = Log.isLoggable(TAG, Log.DEBUG);
@ -3212,6 +3213,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
} else if (CollectionUtils.contains(args, REQUEST_ARG)) {
dumpNetworkRequests(pw);
return;
} else if (CollectionUtils.contains(args, TRAFFICCONTROLLER_ARG)) {
boolean verbose = !CollectionUtils.contains(args, SHORT_ARG);
dumpTrafficController(pw, fd, verbose);
return;
}
pw.print("NetworkProviders for:");
@ -3429,6 +3434,17 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
}
private void dumpTrafficController(IndentingPrintWriter pw, final FileDescriptor fd,
boolean verbose) {
try {
mBpfNetMaps.dump(fd, verbose);
} catch (ServiceSpecificException e) {
pw.println(e.getMessage());
} catch (IOException e) {
loge("Dump BPF maps failed, " + e);
}
}
private void dumpAllRequestInfoLogsToLogcat() {
try (PrintWriter logPw = new PrintWriter(new Writer() {
@Override