From 6b64a80c6c851e637b5b9f0f55a7eeddc5c4bfc4 Mon Sep 17 00:00:00 2001 From: Sharad Binjola <31142146+sharadb-amazon@users.noreply.github.com> Date: Tue, 17 Oct 2023 21:08:01 -0700 Subject: [PATCH] tv-casting-app/android: resetting discovery state vars onStartDiscoveryFailed (#29836) --- .../jni/com/chip/casting/NsdDiscoveryListener.java | 1 + .../src/main/jni/com/chip/casting/TvCastingApp.java | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/NsdDiscoveryListener.java b/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/NsdDiscoveryListener.java index 905dcb67f86bc8..1a9556e5fdb6d2 100644 --- a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/NsdDiscoveryListener.java +++ b/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/NsdDiscoveryListener.java @@ -109,6 +109,7 @@ public void onDiscoveryStopped(String serviceType) { @Override public void onStartDiscoveryFailed(String serviceType, int errorCode) { Log.e(TAG, "Discovery failed to start: Error code:" + errorCode); + TvCastingApp.getInstance().resetDiscoveryState(); failureCallback.handle( new MatterError( 3, "NsdDiscoveryListener Discovery failed to start: Nsd Error code:" + errorCode)); diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/TvCastingApp.java b/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/TvCastingApp.java index a846ffcb7ee9a2..24852986768e7c 100644 --- a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/TvCastingApp.java +++ b/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/TvCastingApp.java @@ -297,6 +297,17 @@ public void stopVideoPlayerDiscovery() { } } + void resetDiscoveryState() { + synchronized (discoveryLock) { + Log.d(TAG, "TvCastingApp resetting discovery state"); + this.discoveryStarted = false; + this.nsdDiscoveryListener = null; + if (multicastLock != null && multicastLock.isHeld()) { + multicastLock.release(); + } + } + } + public native boolean openBasicCommissioningWindow( int duration, CommissioningCallbacks commissioningCallbacks,