Skip to content

Commit 32dda48

Browse files
authored
Merge branch 'master' into feature/add-logic-message-cluster
2 parents 03077ba + 3fe8ec6 commit 32dda48

File tree

86 files changed

+824
-770
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+824
-770
lines changed

.github/workflows/tests.yaml

+32-32
Large diffs are not rendered by default.

examples/android/CHIPTest/app/src/main/cpp/CHIPTest-JNI.cpp

+13-7
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,15 @@ jint JNI_OnLoad(JavaVM * jvm, void * reserved)
6363
ChipLogProgress(Test, "Loading Java class references.");
6464

6565
// Get various class references need by the API.
66-
err = JniReferences::GetInstance().GetClassRef(env, "com/tcl/chip/chiptest/TestEngine", sTestEngineCls);
66+
jobject testEngineCls;
67+
err = JniReferences::GetInstance().GetLocalClassRef(env, "com/tcl/chip/chiptest/TestEngine", sTestEngineCls);
6768
SuccessOrExit(err);
68-
69-
err = JniReferences::GetInstance().GetClassRef(env, "com/tcl/chip/chiptest/TestEngineException", sTestEngineExceptionCls);
69+
err = sTestEngineCls.Init(testEngineCls);
70+
SuccessOrExit(err);
71+
jobject testEngineExceptionCls;
72+
err = JniReferences::GetInstance().GetLocalClassRef(env, "com/tcl/chip/chiptest/TestEngineException", sTestEngineExceptionCls);
73+
SuccessOrExit(err);
74+
err = sTestEngineExceptionCls.Init(testEngineExceptionCls);
7075
SuccessOrExit(err);
7176
ChipLogProgress(Test, "Java class references loaded.");
7277

@@ -141,7 +146,7 @@ CHIP_ERROR N2J_Error(JNIEnv * env, CHIP_ERROR inErr, jthrowable & outEx)
141146
jmethodID constructor;
142147

143148
env->ExceptionClear();
144-
constructor = env->GetMethodID(sTestEngineExceptionCls, "<init>", "(ILjava/lang/String;)V");
149+
constructor = env->GetMethodID(sTestEngineExceptionCls.ObjectRef(), "<init>", "(ILjava/lang/String;)V");
145150
VerifyOrExit(constructor != NULL, err = CHIP_JNI_ERROR_METHOD_NOT_FOUND);
146151

147152
switch (inErr.AsInteger())
@@ -164,7 +169,8 @@ CHIP_ERROR N2J_Error(JNIEnv * env, CHIP_ERROR inErr, jthrowable & outEx)
164169
}
165170
errStrObj = (errStr != NULL) ? env->NewStringUTF(errStr) : NULL;
166171

167-
outEx = (jthrowable) env->NewObject(sTestEngineExceptionCls, constructor, static_cast<jint>(inErr.AsInteger()), errStrObj);
172+
outEx = (jthrowable) env->NewObject(sTestEngineExceptionCls.ObjectRef(), constructor, static_cast<jint>(inErr.AsInteger()),
173+
errStrObj);
168174
VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN);
169175

170176
exit:
@@ -184,7 +190,7 @@ static void onLog(const char * fmt, ...)
184190
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
185191
VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV);
186192

187-
method = env->GetStaticMethodID(sTestEngineCls, "onTestLog", "(Ljava/lang/String;)V");
193+
method = env->GetStaticMethodID(sTestEngineCls.ObjectRef(), "onTestLog", "(Ljava/lang/String;)V");
188194
VerifyOrExit(method != NULL, err = CHIP_JNI_ERROR_NO_ENV);
189195

190196
va_start(args, fmt);
@@ -195,7 +201,7 @@ static void onLog(const char * fmt, ...)
195201
ChipLogProgress(Test, "Calling Java onTestLog");
196202

197203
env->ExceptionClear();
198-
env->CallStaticVoidMethod(sTestEngineCls, method, strObj);
204+
env->CallStaticVoidMethod(sTestEngineCls.ObjectRef(), method, strObj);
199205
VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN);
200206

201207
exit:

examples/tv-app/android/java/ChannelManager.cpp

+22-21
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,12 @@ CHIP_ERROR ChannelManager::HandleGetChannelList(AttributeValueEncoder & aEncoder
6363
JniLocalReferenceScope scope(env);
6464

6565
ChipLogProgress(Zcl, "Received ChannelManager::HandleGetChannelList");
66-
VerifyOrExit(mChannelManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
66+
VerifyOrExit(mChannelManagerObject.HasValidObjectRef(), err = CHIP_ERROR_INCORRECT_STATE);
6767
VerifyOrExit(mGetChannelListMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
6868

6969
return aEncoder.EncodeList([this, env](const auto & encoder) -> CHIP_ERROR {
70-
jobjectArray channelInfoList = (jobjectArray) env->CallObjectMethod(mChannelManagerObject, mGetChannelListMethod);
70+
jobjectArray channelInfoList =
71+
(jobjectArray) env->CallObjectMethod(mChannelManagerObject.ObjectRef(), mGetChannelListMethod);
7172
if (env->ExceptionCheck())
7273
{
7374
ChipLogError(Zcl, "Java exception in ChannelManager::HandleGetChannelList");
@@ -140,11 +141,11 @@ CHIP_ERROR ChannelManager::HandleGetLineup(AttributeValueEncoder & aEncoder)
140141
JniLocalReferenceScope scope(env);
141142

142143
ChipLogProgress(Zcl, "Received ChannelManager::HandleGetLineup");
143-
VerifyOrExit(mChannelManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
144+
VerifyOrExit(mChannelManagerObject.HasValidObjectRef(), err = CHIP_ERROR_INCORRECT_STATE);
144145
VerifyOrExit(mGetLineupMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
145146

146147
{
147-
jobject channelLineupObject = env->CallObjectMethod(mChannelManagerObject, mGetLineupMethod);
148+
jobject channelLineupObject = env->CallObjectMethod(mChannelManagerObject.ObjectRef(), mGetLineupMethod);
148149
if (channelLineupObject != nullptr)
149150
{
150151
jclass channelLineupClazz = env->GetObjectClass(channelLineupObject);
@@ -203,11 +204,11 @@ CHIP_ERROR ChannelManager::HandleGetCurrentChannel(AttributeValueEncoder & aEnco
203204
JniLocalReferenceScope scope(env);
204205

205206
ChipLogProgress(Zcl, "Received ChannelManager::HandleGetCurrentChannel");
206-
VerifyOrExit(mChannelManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
207+
VerifyOrExit(mChannelManagerObject.HasValidObjectRef(), err = CHIP_ERROR_INCORRECT_STATE);
207208
VerifyOrExit(mGetCurrentChannelMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
208209

209210
{
210-
jobject channelInfoObject = env->CallObjectMethod(mChannelManagerObject, mGetCurrentChannelMethod);
211+
jobject channelInfoObject = env->CallObjectMethod(mChannelManagerObject.ObjectRef(), mGetCurrentChannelMethod);
211212
if (channelInfoObject != nullptr)
212213
{
213214
jclass channelClass = env->GetObjectClass(channelInfoObject);
@@ -278,13 +279,13 @@ void ChannelManager::HandleChangeChannel(CommandResponseHelper<ChangeChannelResp
278279
JniLocalReferenceScope scope(env);
279280

280281
ChipLogProgress(Zcl, "Received ChannelManager::HandleChangeChannel name %s", name.c_str());
281-
VerifyOrExit(mChannelManagerObject != nullptr, ChipLogError(Zcl, "mChannelManagerObject null"));
282+
VerifyOrExit(mChannelManagerObject.HasValidObjectRef(), ChipLogError(Zcl, "mChannelManagerObject null"));
282283
VerifyOrExit(mChangeChannelMethod != nullptr, ChipLogError(Zcl, "mChangeChannelMethod null"));
283284

284285
{
285286
UtfString jniname(env, name.c_str());
286287
env->ExceptionClear();
287-
jobject channelObject = env->CallObjectMethod(mChannelManagerObject, mChangeChannelMethod, jniname.jniValue());
288+
jobject channelObject = env->CallObjectMethod(mChannelManagerObject.ObjectRef(), mChangeChannelMethod, jniname.jniValue());
288289
if (env->ExceptionCheck())
289290
{
290291
ChipLogError(DeviceLayer, "Java exception in ChannelManager::HandleChangeChannel");
@@ -325,12 +326,12 @@ bool ChannelManager::HandleChangeChannelByNumber(const uint16_t & majorNumber, c
325326

326327
ChipLogProgress(Zcl, "Received ChannelManager::HandleChangeChannelByNumber majorNumber %d, minorNumber %d", majorNumber,
327328
minorNumber);
328-
VerifyOrExit(mChannelManagerObject != nullptr, ChipLogError(Zcl, "mChannelManagerObject null"));
329+
VerifyOrExit(mChannelManagerObject.HasValidObjectRef(), ChipLogError(Zcl, "mChannelManagerObject null"));
329330
VerifyOrExit(mChangeChannelByNumberMethod != nullptr, ChipLogError(Zcl, "mChangeChannelByNumberMethod null"));
330331

331332
env->ExceptionClear();
332333

333-
ret = env->CallBooleanMethod(mChannelManagerObject, mChangeChannelByNumberMethod, static_cast<jint>(majorNumber),
334+
ret = env->CallBooleanMethod(mChannelManagerObject.ObjectRef(), mChangeChannelByNumberMethod, static_cast<jint>(majorNumber),
334335
static_cast<jint>(minorNumber));
335336
if (env->ExceptionCheck())
336337
{
@@ -352,12 +353,12 @@ bool ChannelManager::HandleSkipChannel(const int16_t & count)
352353
JniLocalReferenceScope scope(env);
353354

354355
ChipLogProgress(Zcl, "Received ChannelManager::HandleSkipChannel count %d", count);
355-
VerifyOrExit(mChannelManagerObject != nullptr, ChipLogError(Zcl, "mChannelManagerObject null"));
356+
VerifyOrExit(mChannelManagerObject.HasValidObjectRef(), ChipLogError(Zcl, "mChannelManagerObject null"));
356357
VerifyOrExit(mSkipChannelMethod != nullptr, ChipLogError(Zcl, "mSkipChannelMethod null"));
357358

358359
env->ExceptionClear();
359360

360-
ret = env->CallBooleanMethod(mChannelManagerObject, mSkipChannelMethod, static_cast<jint>(count));
361+
ret = env->CallBooleanMethod(mChannelManagerObject.ObjectRef(), mSkipChannelMethod, static_cast<jint>(count));
361362
if (env->ExceptionCheck())
362363
{
363364
ChipLogError(DeviceLayer, "Java exception in ChannelManager::HandleSkipChannel");
@@ -390,7 +391,7 @@ void ChannelManager::HandleGetProgramGuide(
390391
std::vector<JniUtfString *> needToFreeStrings;
391392

392393
ChipLogProgress(Zcl, "Received ChannelManager::HandleGetProgramGuide");
393-
VerifyOrExit(mChannelManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
394+
VerifyOrExit(mChannelManagerObject.HasValidObjectRef(), err = CHIP_ERROR_INCORRECT_STATE);
394395
VerifyOrExit(mGetProgramGuideMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
395396

396397
{
@@ -401,7 +402,7 @@ void ChannelManager::HandleGetProgramGuide(
401402
jobjectArray externalIDListArray = (jobjectArray) env->NewObjectArray(0, env->FindClass("java/util/Map$Entry"), NULL);
402403

403404
jobject resp = env->CallObjectMethod(
404-
mChannelManagerObject, mGetProgramGuideMethod, static_cast<jlong>(startTime.ValueOr(0)),
405+
mChannelManagerObject.ObjectRef(), mGetProgramGuideMethod, static_cast<jlong>(startTime.ValueOr(0)),
405406
static_cast<jlong>(endTime.ValueOr(0)), channelsArray, jToken.jniValue(),
406407
static_cast<jboolean>(recordingFlag.ValueOr(0).Raw() != 0), externalIDListArray, jData.jniValue());
407408
if (env->ExceptionCheck())
@@ -596,7 +597,7 @@ bool ChannelManager::HandleRecordProgram(const chip::CharSpan & programIdentifie
596597
JniLocalReferenceScope scope(env);
597598

598599
ChipLogProgress(Zcl, "Received ChannelManager::HandleRecordProgram");
599-
VerifyOrExit(mChannelManagerObject != nullptr, ChipLogError(Zcl, "mChannelManagerObject null"));
600+
VerifyOrExit(mChannelManagerObject.HasValidObjectRef(), ChipLogError(Zcl, "mChannelManagerObject null"));
600601
VerifyOrExit(mRecordProgramMethod != nullptr, ChipLogError(Zcl, "mRecordProgramMethod null"));
601602

602603
env->ExceptionClear();
@@ -608,7 +609,7 @@ bool ChannelManager::HandleRecordProgram(const chip::CharSpan & programIdentifie
608609
UtfString jData(env, "");
609610
jobjectArray externalIDListArray = (jobjectArray) env->NewObjectArray(0, env->FindClass("java/util/Map$Entry"), NULL);
610611

611-
ret = env->CallBooleanMethod(mChannelManagerObject, mRecordProgramMethod, jIdentifier.jniValue(),
612+
ret = env->CallBooleanMethod(mChannelManagerObject.ObjectRef(), mRecordProgramMethod, jIdentifier.jniValue(),
612613
static_cast<jboolean>(shouldRecordSeries), externalIDListArray, jData.jniValue());
613614
if (env->ExceptionCheck())
614615
{
@@ -633,7 +634,7 @@ bool ChannelManager::HandleCancelRecordProgram(const chip::CharSpan & programIde
633634
JniLocalReferenceScope scope(env);
634635

635636
ChipLogProgress(Zcl, "Received ChannelManager::HandleCancelRecordProgram");
636-
VerifyOrExit(mChannelManagerObject != nullptr, ChipLogError(Zcl, "mChannelManagerObject null"));
637+
VerifyOrExit(mChannelManagerObject.HasValidObjectRef(), ChipLogError(Zcl, "mChannelManagerObject null"));
637638
VerifyOrExit(mCancelRecordProgramMethod != nullptr, ChipLogError(Zcl, "mCancelRecordProgramMethod null"));
638639

639640
env->ExceptionClear();
@@ -645,7 +646,7 @@ bool ChannelManager::HandleCancelRecordProgram(const chip::CharSpan & programIde
645646
UtfString jData(env, "");
646647
jobjectArray externalIDListArray = (jobjectArray) env->NewObjectArray(0, env->FindClass("java/util/Map$Entry"), NULL);
647648

648-
ret = env->CallBooleanMethod(mChannelManagerObject, mCancelRecordProgramMethod, jIdentifier.jniValue(),
649+
ret = env->CallBooleanMethod(mChannelManagerObject.ObjectRef(), mCancelRecordProgramMethod, jIdentifier.jniValue(),
649650
static_cast<jboolean>(shouldRecordSeries), externalIDListArray, jData.jniValue());
650651
if (env->ExceptionCheck())
651652
{
@@ -665,10 +666,10 @@ void ChannelManager::InitializeWithObjects(jobject managerObject)
665666
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
666667
VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Failed to GetEnvForCurrentThread for ChannelManager"));
667668

668-
mChannelManagerObject = env->NewGlobalRef(managerObject);
669-
VerifyOrReturn(mChannelManagerObject != nullptr, ChipLogError(Zcl, "Failed to NewGlobalRef ChannelManager"));
669+
VerifyOrReturn(mChannelManagerObject.Init(managerObject) == CHIP_NO_ERROR,
670+
ChipLogError(Zcl, "Failed to init mChannelManagerObject"));
670671

671-
jclass managerClass = env->GetObjectClass(mChannelManagerObject);
672+
jclass managerClass = env->GetObjectClass(managerObject);
672673
VerifyOrReturn(managerClass != nullptr, ChipLogError(Zcl, "Failed to get ChannelManager Java class"));
673674

674675
mGetChannelListMethod = env->GetMethodID(managerClass, "getChannelList", "()[Lcom/matter/tv/server/tvapp/ChannelInfo;");

examples/tv-app/android/java/ChannelManager.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <app/clusters/channel-server/channel-server.h>
2121
#include <jni.h>
22+
#include <lib/support/JniReferences.h>
2223

2324
using chip::CharSpan;
2425
using chip::app::AttributeValueEncoder;
@@ -66,7 +67,7 @@ class ChannelManager : public ChannelDelegate
6667
uint32_t GetFeatureMap(chip::EndpointId endpoint) override;
6768

6869
private:
69-
jobject mChannelManagerObject = nullptr;
70+
chip::JniGlobalReference mChannelManagerObject;
7071
jmethodID mGetChannelListMethod = nullptr;
7172
jmethodID mGetLineupMethod = nullptr;
7273
jmethodID mGetCurrentChannelMethod = nullptr;

examples/tv-app/android/java/ContentAppAttributeDelegate.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ std::string ContentAppAttributeDelegate::Read(const chip::app::ConcreteReadAttri
4747
ChipLogProgress(Zcl, "ContentAppAttributeDelegate::Read being called for endpoint %d cluster %d attribute %d",
4848
aPath.mEndpointId, aPath.mClusterId, aPath.mAttributeId);
4949

50-
jstring resp =
51-
(jstring) env->CallObjectMethod(mContentAppEndpointManager, mReadAttributeMethod, static_cast<jint>(aPath.mEndpointId),
52-
static_cast<jlong>(aPath.mClusterId), static_cast<jlong>(aPath.mAttributeId));
50+
jstring resp = static_cast<jstring>(
51+
env->CallObjectMethod(mContentAppEndpointManager.ObjectRef(), mReadAttributeMethod, static_cast<jint>(aPath.mEndpointId),
52+
static_cast<jlong>(aPath.mClusterId), static_cast<jlong>(aPath.mAttributeId)));
5353
if (env->ExceptionCheck())
5454
{
5555
ChipLogError(Zcl, "Java exception in ContentAppAttributeDelegate::Read");

examples/tv-app/android/java/ContentAppAttributeDelegate.h

+4-12
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,6 @@ class ContentAppAttributeDelegate
4444
InitializeJNIObjects(manager);
4545
}
4646

47-
~ContentAppAttributeDelegate()
48-
{
49-
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
50-
VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Failed to GetEnvForCurrentThread for ContentAppEndpointManager"));
51-
env->DeleteGlobalRef(mContentAppEndpointManager);
52-
}
53-
5447
std::string Read(const chip::app::ConcreteReadAttributePath & aPath);
5548

5649
private:
@@ -59,9 +52,8 @@ class ContentAppAttributeDelegate
5952
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
6053
VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Failed to GetEnvForCurrentThread for ContentAppEndpointManager"));
6154

62-
mContentAppEndpointManager = env->NewGlobalRef(manager);
63-
VerifyOrReturn(mContentAppEndpointManager != nullptr,
64-
ChipLogError(Zcl, "Failed to NewGlobalRef ContentAppEndpointManager"));
55+
VerifyOrReturn(mContentAppEndpointManager.Init(manager) == CHIP_NO_ERROR,
56+
ChipLogError(Zcl, "Failed to init mContentAppEndpointManager"));
6557

6658
jclass ContentAppEndpointManagerClass = env->GetObjectClass(manager);
6759
VerifyOrReturn(ContentAppEndpointManagerClass != nullptr,
@@ -75,8 +67,8 @@ class ContentAppAttributeDelegate
7567
}
7668
}
7769

78-
jobject mContentAppEndpointManager = nullptr;
79-
jmethodID mReadAttributeMethod = nullptr;
70+
chip::JniGlobalReference mContentAppEndpointManager;
71+
jmethodID mReadAttributeMethod = nullptr;
8072
};
8173

8274
} // namespace AppPlatform

examples/tv-app/android/java/ContentAppCommandDelegate.cpp

+14-5
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,16 @@ void ContentAppCommandDelegate::InvokeCommand(CommandHandlerInterface::HandlerCo
6969
std::string payload = JsonToString(value);
7070
UtfString jsonString(env, payload.c_str());
7171

72-
ChipLogProgress(Zcl, "ContentAppCommandDelegate::InvokeCommand send command being called with payload %s", payload.c_str());
72+
if (!mContentAppEndpointManager.HasValidObjectRef())
73+
{
74+
ChipLogProgress(Zcl, "mContentAppEndpointManager is not valid");
75+
return;
76+
}
7377

74-
jstring resp = (jstring) env->CallObjectMethod(
75-
mContentAppEndpointManager, mSendCommandMethod, static_cast<jint>(handlerContext.mRequestPath.mEndpointId),
78+
jstring resp = static_cast<jstring>(env->CallObjectMethod(
79+
mContentAppEndpointManager.ObjectRef(), mSendCommandMethod, static_cast<jint>(handlerContext.mRequestPath.mEndpointId),
7680
static_cast<jlong>(handlerContext.mRequestPath.mClusterId), static_cast<jlong>(handlerContext.mRequestPath.mCommandId),
77-
jsonString.jniValue());
81+
jsonString.jniValue()));
7882
if (env->ExceptionCheck())
7983
{
8084
ChipLogError(Zcl, "Java exception in ContentAppCommandDelegate::sendCommand");
@@ -106,8 +110,13 @@ Status ContentAppCommandDelegate::InvokeCommand(EndpointId epId, ClusterId clust
106110

107111
ChipLogProgress(Zcl, "ContentAppCommandDelegate::InvokeCommand send command being called with payload %s", payload.c_str());
108112

113+
if (!mContentAppEndpointManager.HasValidObjectRef())
114+
{
115+
return Protocols::InteractionModel::Status::Failure;
116+
}
117+
109118
jstring resp =
110-
(jstring) env->CallObjectMethod(mContentAppEndpointManager, mSendCommandMethod, static_cast<jint>(epId),
119+
(jstring) env->CallObjectMethod(mContentAppEndpointManager.ObjectRef(), mSendCommandMethod, static_cast<jint>(epId),
111120
static_cast<jlong>(clusterId), static_cast<jlong>(commandId), jsonString.jniValue());
112121
if (env->ExceptionCheck())
113122
{

examples/tv-app/android/java/ContentAppCommandDelegate.h

+4-12
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,6 @@ class ContentAppCommandDelegate : public CommandHandlerInterface
6464
InitializeJNIObjects(manager);
6565
};
6666

67-
~ContentAppCommandDelegate()
68-
{
69-
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
70-
VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Failed to GetEnvForCurrentThread for ContentAppEndpointManager"));
71-
env->DeleteGlobalRef(mContentAppEndpointManager);
72-
}
73-
7467
void InvokeCommand(CommandHandlerInterface::HandlerContext & handlerContext) override;
7568

7669
Status InvokeCommand(EndpointId epId, ClusterId clusterId, CommandId commandId, std::string payload, bool & commandHandled,
@@ -87,9 +80,8 @@ class ContentAppCommandDelegate : public CommandHandlerInterface
8780
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
8881
VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Failed to GetEnvForCurrentThread for ContentAppEndpointManager"));
8982

90-
mContentAppEndpointManager = env->NewGlobalRef(manager);
91-
VerifyOrReturn(mContentAppEndpointManager != nullptr,
92-
ChipLogError(Zcl, "Failed to NewGlobalRef ContentAppEndpointManager"));
83+
VerifyOrReturn(mContentAppEndpointManager.Init(manager) == CHIP_NO_ERROR,
84+
ChipLogError(Zcl, "Failed to init mContentAppEndpointManager"));
9385

9486
jclass ContentAppEndpointManagerClass = env->GetObjectClass(manager);
9587
VerifyOrReturn(ContentAppEndpointManagerClass != nullptr,
@@ -106,8 +98,8 @@ class ContentAppCommandDelegate : public CommandHandlerInterface
10698

10799
void FormatResponseData(CommandHandlerInterface::HandlerContext & handlerContext, const char * response);
108100

109-
jobject mContentAppEndpointManager = nullptr;
110-
jmethodID mSendCommandMethod = nullptr;
101+
chip::JniGlobalReference mContentAppEndpointManager;
102+
jmethodID mSendCommandMethod = nullptr;
111103
};
112104

113105
} // namespace AppPlatform

0 commit comments

Comments
 (0)