From 3721928ea9767d2c002e659771966a003860071b Mon Sep 17 00:00:00 2001 From: "Hui.Li-TCL" Date: Sat, 19 Feb 2022 06:47:39 +0800 Subject: [PATCH] fix mdns leak on android (#15292) * fix removeServices exception, we missed clear registrationListeners * fix restyled-io and ci errors * remove try catch * fix restyled-io and ci errors --- .../chip/platform/NsdManagerServiceResolver.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/platform/android/java/chip/platform/NsdManagerServiceResolver.java b/src/platform/android/java/chip/platform/NsdManagerServiceResolver.java index dbbb9052c710f0..63a28d3ffd5a8e 100644 --- a/src/platform/android/java/chip/platform/NsdManagerServiceResolver.java +++ b/src/platform/android/java/chip/platform/NsdManagerServiceResolver.java @@ -168,23 +168,31 @@ public void onUnregistrationFailed(NsdServiceInfo serviceInfo, int errorCode) { @Override public void onServiceRegistered(NsdServiceInfo serviceInfo) { - Log.i(TAG, "service " + serviceInfo.getServiceName() + " onServiceRegistered"); + Log.i( + TAG, + "service " + serviceInfo.getServiceName() + "(" + this + ") onServiceRegistered"); } @Override public void onServiceUnregistered(NsdServiceInfo serviceInfo) { - Log.i(TAG, "service " + serviceInfo.getServiceName() + " onServiceRegistered"); + Log.i( + TAG, + "service " + serviceInfo.getServiceName() + "(" + this + ") onServiceUnregistered"); } }; registrationListeners.add(registrationListener); nsdManager.registerService(serviceInfo, NsdManager.PROTOCOL_DNS_SD, registrationListener); + Log.d(TAG, "publish " + registrationListener + " count = " + registrationListeners.size()); } @Override public void removeServices() { + Log.d(TAG, "removeServices: "); for (NsdManager.RegistrationListener l : registrationListeners) { + Log.i(TAG, "Remove " + l); nsdManager.unregisterService(l); } + registrationListeners.clear(); } }