Add service type clients to servicediscovery dumpsys
Add service type clients, and their listener counts to
servicediscovery dumpsys. This information will help identify
currently discovered services and monitor for client leaks.
Sample output:
DiscoveryManager:
ServiceTypeClient: Type{_nmt079019787._tcp.local} \
SocketKey{ network=116 interfaceIndex=68 } with 1 \
listeners.
ServiceTypeClient: Type{_nmt079019787._tcp.local} \
SocketKey{ network=115 interfaceIndex=67 } with 1 \
listeners.
ServiceTypeClient: Type{_nmt079019787._tcp.local} \
SocketKey{ network=100 interfaceIndex=47 } with 1 \
listeners.
Bug: 324156009
Test: dumpsys servicediscovery
Change-Id: Idde31b9aabd6194c3f92e72c2345cbdd33f4b0fd
diff --git a/service-t/src/com/android/server/NsdService.java b/service-t/src/com/android/server/NsdService.java
index 9ba49d2..c045eaf 100644
--- a/service-t/src/com/android/server/NsdService.java
+++ b/service-t/src/com/android/server/NsdService.java
@@ -92,6 +92,7 @@
import com.android.modules.utils.build.SdkLevel;
import com.android.net.module.util.CollectionUtils;
import com.android.net.module.util.DeviceConfigUtils;
+import com.android.net.module.util.HandlerUtils;
import com.android.net.module.util.InetAddressUtils;
import com.android.net.module.util.PermissionUtils;
import com.android.net.module.util.SharedLog;
@@ -2510,6 +2511,14 @@
pw.increaseIndent();
mServiceLogs.reverseDump(pw);
pw.decreaseIndent();
+
+ //Dump DiscoveryManager
+ pw.println();
+ pw.println("DiscoveryManager:");
+ pw.increaseIndent();
+ HandlerUtils.runWithScissorsForDump(
+ mNsdStateMachine.getHandler(), () -> mMdnsDiscoveryManager.dump(pw), 10_000);
+ pw.decreaseIndent();
}
private abstract static class ClientRequest {