@@ -53,11 +53,12 @@ CHIP_ERROR MediaInputManager::HandleGetInputList(chip::app::AttributeValueEncode
53
53
{
54
54
CHIP_ERROR err = CHIP_NO_ERROR;
55
55
JNIEnv * env = JniReferences::GetInstance ().GetEnvForCurrentThread ();
56
+ VerifyOrReturnError (env != nullptr , CHIP_JNI_ERROR_NO_ENV, ChipLogError (Zcl, " Could not get JNIEnv for current thread" ));
57
+ JniLocalReferenceManager manager (env);
56
58
57
59
ChipLogProgress (Zcl, " Received MediaInputManager::HandleGetInputList" );
58
60
VerifyOrExit (mMediaInputManagerObject != nullptr , err = CHIP_ERROR_INCORRECT_STATE);
59
61
VerifyOrExit (mGetInputListMethod != nullptr , err = CHIP_ERROR_INCORRECT_STATE);
60
- VerifyOrExit (env != NULL , err = CHIP_JNI_ERROR_NO_ENV);
61
62
62
63
return aEncoder.EncodeList ([this , env](const auto & encoder) -> CHIP_ERROR {
63
64
jobjectArray inputArray = (jobjectArray) env->CallObjectMethod (mMediaInputManagerObject , mGetInputListMethod );
@@ -123,6 +124,8 @@ uint8_t MediaInputManager::HandleGetCurrentInput()
123
124
CHIP_ERROR err = CHIP_NO_ERROR;
124
125
jint index = -1 ;
125
126
JNIEnv * env = JniReferences::GetInstance ().GetEnvForCurrentThread ();
127
+ VerifyOrReturnValue (env != nullptr , 0 , ChipLogError (Zcl, " Could not get JNIEnv for current thread" ));
128
+ JniLocalReferenceManager manager (env);
126
129
127
130
ChipLogProgress (Zcl, " Received MediaInputManager::HandleGetCurrentInput" );
128
131
VerifyOrExit (mMediaInputManagerObject != nullptr , err = CHIP_ERROR_INCORRECT_STATE);
@@ -153,11 +156,12 @@ bool MediaInputManager::HandleSelectInput(const uint8_t index)
153
156
{
154
157
jboolean ret = JNI_FALSE;
155
158
JNIEnv * env = JniReferences::GetInstance ().GetEnvForCurrentThread ();
159
+ VerifyOrReturnValue (env != nullptr , false , ChipLogError (Zcl, " Could not get JNIEnv for current thread" ));
160
+ JniLocalReferenceManager manager (env);
156
161
157
162
ChipLogProgress (Zcl, " Received MediaInputManager::HandleSelectInput %d" , index );
158
163
VerifyOrExit (mMediaInputManagerObject != nullptr , ChipLogError (Zcl, " mMediaInputManagerObject null" ));
159
164
VerifyOrExit (mSelectInputMethod != nullptr , ChipLogError (Zcl, " mSelectInputMethod null" ));
160
- VerifyOrExit (env != NULL , ChipLogError (Zcl, " env null" ));
161
165
162
166
env->ExceptionClear ();
163
167
ret = env->CallBooleanMethod (mMediaInputManagerObject , mSelectInputMethod , static_cast <jint>(index ));
@@ -177,11 +181,12 @@ bool MediaInputManager::HandleShowInputStatus()
177
181
{
178
182
jboolean ret = JNI_FALSE;
179
183
JNIEnv * env = JniReferences::GetInstance ().GetEnvForCurrentThread ();
184
+ VerifyOrReturnValue (env != nullptr , false , ChipLogError (Zcl, " Could not get JNIEnv for current thread" ));
185
+ JniLocalReferenceManager manager (env);
180
186
181
187
ChipLogProgress (Zcl, " Received MediaInputManager::HandleShowInputStatus" );
182
188
VerifyOrExit (mMediaInputManagerObject != nullptr , ChipLogError (Zcl, " mMediaInputManagerObject null" ));
183
189
VerifyOrExit (mShowInputStatusMethod != nullptr , ChipLogError (Zcl, " mShowInputStatusMethod null" ));
184
- VerifyOrExit (env != NULL , ChipLogError (Zcl, " env null" ));
185
190
186
191
env->ExceptionClear ();
187
192
ret = env->CallBooleanMethod (mMediaInputManagerObject , mShowInputStatusMethod );
@@ -201,11 +206,12 @@ bool MediaInputManager::HandleHideInputStatus()
201
206
{
202
207
jboolean ret = JNI_FALSE;
203
208
JNIEnv * env = JniReferences::GetInstance ().GetEnvForCurrentThread ();
209
+ VerifyOrReturnValue (env != nullptr , false , ChipLogError (Zcl, " Could not get JNIEnv for current thread" ));
210
+ JniLocalReferenceManager manager (env);
204
211
205
212
ChipLogProgress (Zcl, " Received MediaInputManager::HandleHideInputStatus" );
206
213
VerifyOrExit (mMediaInputManagerObject != nullptr , ChipLogError (Zcl, " mMediaInputManagerObject null" ));
207
214
VerifyOrExit (mHideInputStatusMethod != nullptr , ChipLogError (Zcl, " mHideInputStatusMethod null" ));
208
- VerifyOrExit (env != NULL , ChipLogError (Zcl, " env null" ));
209
215
210
216
env->ExceptionClear ();
211
217
ret = env->CallBooleanMethod (mMediaInputManagerObject , mHideInputStatusMethod );
@@ -226,11 +232,12 @@ bool MediaInputManager::HandleRenameInput(const uint8_t index, const chip::CharS
226
232
std::string inputname (name.data (), name.size ());
227
233
jboolean ret = JNI_FALSE;
228
234
JNIEnv * env = JniReferences::GetInstance ().GetEnvForCurrentThread ();
235
+ VerifyOrReturnValue (env != nullptr , false , ChipLogError (Zcl, " Could not get JNIEnv for current thread" ));
236
+ JniLocalReferenceManager manager (env);
229
237
230
238
ChipLogProgress (Zcl, " Received MediaInputManager::HandleRenameInput %d to %s" , index , name.data ());
231
239
VerifyOrExit (mMediaInputManagerObject != nullptr , ChipLogError (Zcl, " mMediaInputManagerObject null" ));
232
240
VerifyOrExit (mRenameInputMethod != nullptr , ChipLogError (Zcl, " mHideInputStatusMethod null" ));
233
- VerifyOrExit (env != NULL , ChipLogError (Zcl, " env null" ));
234
241
235
242
{
236
243
UtfString jniInputname (env, inputname.data ());
0 commit comments