Skip to content

Commit 6ba907e

Browse files
Addressed comments by yunhanw-google related to error checking and logging and also fixed a tv-casting-app connection bug (#33010)
1 parent bfdb5da commit 6ba907e

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

examples/tv-casting-app/android/App/app/src/main/java/com/matter/casting/DiscoveryExampleFragment.java

-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ public void onResume() {
216216
public void onPause() {
217217
super.onPause();
218218
Log.i(TAG, "onPause() called");
219-
stopDiscovery();
220219
}
221220

222221
/** Interface for notifying the host. */

examples/tv-casting-app/android/App/app/src/main/jni/cpp/core/CastingPlayerDiscovery-JNI.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ JNI_METHOD(jobject, removeCastingPlayerChangeListener)(JNIEnv * env, jobject, jo
246246

247247
return support::convertMatterErrorFromCppToJava(CHIP_NO_ERROR);
248248
}
249-
else if (DiscoveryDelegateImpl::GetInstance()->castingPlayerChangeListenerJavaObject.ObjectRef() == nullptr)
249+
else if (!DiscoveryDelegateImpl::GetInstance()->castingPlayerChangeListenerJavaObject.HasValidObjectRef())
250250
{
251251
ChipLogError(
252252
AppServer,

src/platform/android/DnssdImpl.cpp

+17-2
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ CHIP_ERROR ChipDnssdBrowse(const char * type, DnssdServiceProtocol protocol, Ine
191191

192192
std::string serviceType = GetFullTypeWithSubTypes(type, protocol);
193193
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
194+
VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NO_ENV,
195+
ChipLogError(Discovery, "Failed to GetEnvForCurrentThread for ChipDnssdBrowse"));
194196
UtfString jniServiceType(env, serviceType.c_str());
195197

196198
env->CallVoidMethod(sBrowserObject.ObjectRef(), sBrowseMethod, jniServiceType.jniValue(), reinterpret_cast<jlong>(callback),
@@ -204,22 +206,29 @@ CHIP_ERROR ChipDnssdBrowse(const char * type, DnssdServiceProtocol protocol, Ine
204206
return CHIP_JNI_ERROR_EXCEPTION_THROWN;
205207
}
206208

207-
auto sdCtx = chip::Platform::New<BrowseContext>(callback);
209+
auto sdCtx = chip::Platform::New<BrowseContext>(callback);
210+
VerifyOrReturnError(nullptr != sdCtx, CHIP_ERROR_NO_MEMORY,
211+
ChipLogError(Discovery, "Failed allocate memory for BrowseContext in ChipDnssdBrowse"));
208212
*browseIdentifier = reinterpret_cast<intptr_t>(sdCtx);
209213

210214
return CHIP_NO_ERROR;
211215
}
212216

213217
CHIP_ERROR ChipDnssdStopBrowse(intptr_t browseIdentifier)
214218
{
219+
VerifyOrReturnError(browseIdentifier != 0, CHIP_ERROR_INVALID_ARGUMENT,
220+
ChipLogError(Discovery, "ChipDnssdStopBrowse Invalid argument browseIdentifier = 0"));
215221
VerifyOrReturnError(sBrowserObject.HasValidObjectRef() && sStopBrowseMethod != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
216222

217223
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
218-
auto ctx = reinterpret_cast<BrowseContext *>(browseIdentifier);
224+
VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NO_ENV,
225+
ChipLogError(Discovery, "Failed to GetEnvForCurrentThread for ChipDnssdStopBrowse"));
226+
auto ctx = reinterpret_cast<BrowseContext *>(browseIdentifier);
219227

220228
env->CallVoidMethod(sBrowserObject.ObjectRef(), sStopBrowseMethod, reinterpret_cast<jlong>(ctx->callback));
221229

222230
chip::Platform::Delete(ctx);
231+
ctx = nullptr;
223232
if (env->ExceptionCheck())
224233
{
225234
ChipLogError(Discovery, "Java exception in ChipDnssdStopBrowse");
@@ -339,6 +348,12 @@ void InitializeWithObjects(jobject resolverObject, jobject browserObject, jobjec
339348
env->ExceptionClear();
340349
}
341350

351+
if (sStopBrowseMethod == nullptr)
352+
{
353+
ChipLogError(Discovery, "Failed to access Discover 'stopDiscover' method");
354+
env->ExceptionClear();
355+
}
356+
342357
if (sGetTextEntryKeysMethod == nullptr)
343358
{
344359
ChipLogError(Discovery, "Failed to access MdnsCallback 'getTextEntryKeys' method");

0 commit comments

Comments
 (0)