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);