From 64476eeb79878a2c7d7841164b131e50884a1d48 Mon Sep 17 00:00:00 2001 From: Sharad Binjola Date: Tue, 17 Oct 2023 16:22:37 -0700 Subject: [PATCH] tv-casting-app/android: resetting discovery state vars onStartDiscoveryFailed --- .../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 14561c2a32b006..b5f41567c40a52 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 @@ -179,6 +179,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,