From 388559273f73f893ce55839ef970b1bf64de02f6 Mon Sep 17 00:00:00 2001 From: Joonhaeng Heo Date: Wed, 6 Mar 2024 16:07:14 +0900 Subject: [PATCH] Fix Android Commissionable Device API when searched multiple devices --- .../src/main/java/com/google/chip/chiptool/ChipClient.kt | 5 ++++- src/controller/AbstractDnssdDiscoveryController.cpp | 3 ++- .../java/chip/platform/NsdManagerServiceResolver.java | 4 ++++ .../java/chip/platform/NsdServiceFinderAndResolver.java | 7 ------- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/ChipClient.kt b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/ChipClient.kt index 77c59d75d00c36..d1ad1657312d10 100644 --- a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/ChipClient.kt +++ b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/ChipClient.kt @@ -69,7 +69,10 @@ object ChipClient { AndroidBleManager(context), PreferencesKeyValueStoreManager(context), PreferencesConfigurationManager(context), - NsdManagerServiceResolver(context), + NsdManagerServiceResolver( + context, + NsdManagerServiceResolver.NsdManagerResolverAvailState() + ), NsdManagerServiceBrowser(context), ChipMdnsCallbackImpl(), DiagnosticDataProviderImpl(context) diff --git a/src/controller/AbstractDnssdDiscoveryController.cpp b/src/controller/AbstractDnssdDiscoveryController.cpp index d0f6d5dbd4066e..2443c5fe0b1ac9 100644 --- a/src/controller/AbstractDnssdDiscoveryController.cpp +++ b/src/controller/AbstractDnssdDiscoveryController.cpp @@ -35,7 +35,8 @@ void AbstractDnssdDiscoveryController::OnNodeDiscovered(const chip::Dnssd::Disco continue; } if (strcmp(discoveredNode.resolutionData.hostName, nodeData.resolutionData.hostName) == 0 && - discoveredNode.resolutionData.port == nodeData.resolutionData.port) + discoveredNode.resolutionData.port == nodeData.resolutionData.port && + discoveredNode.resolutionData.ipAddress == nodeData.resolutionData.ipAddress) { discoveredNode = nodeData; if (mDeviceDiscoveryDelegate != nullptr) diff --git a/src/platform/android/java/chip/platform/NsdManagerServiceResolver.java b/src/platform/android/java/chip/platform/NsdManagerServiceResolver.java index c01855172fcfe6..f89e7445c7d716 100644 --- a/src/platform/android/java/chip/platform/NsdManagerServiceResolver.java +++ b/src/platform/android/java/chip/platform/NsdManagerServiceResolver.java @@ -82,6 +82,10 @@ public void resolve( + serviceType + "'"); + if (nsdManagerResolverAvailState != null) { + nsdManagerResolverAvailState.acquireResolver(); + } + Runnable timeoutRunnable = new Runnable() { @Override diff --git a/src/platform/android/java/chip/platform/NsdServiceFinderAndResolver.java b/src/platform/android/java/chip/platform/NsdServiceFinderAndResolver.java index fc3425f7bd8889..e98013e0eee342 100644 --- a/src/platform/android/java/chip/platform/NsdServiceFinderAndResolver.java +++ b/src/platform/android/java/chip/platform/NsdServiceFinderAndResolver.java @@ -101,13 +101,6 @@ public void onServiceFound(NsdServiceInfo service) { if (stopDiscoveryRunnable.cancel(false)) { nsdManager.stopServiceDiscovery(this); - if (multicastLock.isHeld()) { - multicastLock.release(); - } - } - - if (nsdManagerResolverAvailState != null) { - nsdManagerResolverAvailState.acquireResolver(); } resolveService(service, callbackHandle, contextHandle, chipMdnsCallback, timeoutRunnable);