From 1069776e38c77c1e22c7e67977b7c1327470cbdd Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Sat, 10 Sep 2022 15:15:09 -0400 Subject: [PATCH] Get multicast lock when publishing services on android (#22519) --- .../java/chip/platform/NsdManagerServiceResolver.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/platform/android/java/chip/platform/NsdManagerServiceResolver.java b/src/platform/android/java/chip/platform/NsdManagerServiceResolver.java index 630110296683ab..4fb5bcbe31d664 100644 --- a/src/platform/android/java/chip/platform/NsdManagerServiceResolver.java +++ b/src/platform/android/java/chip/platform/NsdManagerServiceResolver.java @@ -189,6 +189,9 @@ public void onServiceUnregistered(NsdServiceInfo serviceInfo) { "service " + serviceInfo.getServiceName() + "(" + this + ") onServiceUnregistered"); } }; + if (registrationListeners.size() == 0) { + multicastLock.acquire(); + } registrationListeners.add(registrationListener); nsdManager.registerService(serviceInfo, NsdManager.PROTOCOL_DNS_SD, registrationListener); @@ -198,6 +201,9 @@ public void onServiceUnregistered(NsdServiceInfo serviceInfo) { @Override public void removeServices() { Log.d(TAG, "removeServices: "); + if (registrationListeners.size() > 0) { + multicastLock.release(); + } for (NsdManager.RegistrationListener l : registrationListeners) { Log.i(TAG, "Remove " + l); nsdManager.unregisterService(l);