@@ -508,28 +508,50 @@ CHIP_ERROR AndroidDeviceControllerWrapper::ApplyICDRegistrationInfo(chip::Contro
508
508
VerifyOrReturnError (icdRegistrationInfo != nullptr , CHIP_ERROR_INVALID_ARGUMENT);
509
509
510
510
JNIEnv * env = chip::JniReferences::GetInstance ().GetEnvForCurrentThread ();
511
+ if (env == nullptr )
512
+ {
513
+ ChipLogError (Controller, " Failed to retrieve JNIEnv in %s." , __func__);
514
+ return CHIP_ERROR_INCORRECT_STATE;
515
+ }
516
+
517
+ jmethodID getICDStayActiveDurationMsecMethod;
518
+ err = chip::JniReferences::GetInstance ().FindMethod (env, icdRegistrationInfo, " getICDStayActiveDurationMsec" ,
519
+ " ()Ljava/lang/Long;" , &getICDStayActiveDurationMsecMethod);
520
+ ReturnErrorOnFailure (err);
521
+ jobject jStayActiveMsec = env->CallObjectMethod (icdRegistrationInfo, getICDStayActiveDurationMsecMethod);
522
+ if (jStayActiveMsec != nullptr )
523
+ {
524
+ jlong stayActiveMsec = chip::JniReferences::GetInstance ().LongToPrimitive (jStayActiveMsec);
525
+ if (!chip::CanCastTo<uint32_t >(stayActiveMsec))
526
+ {
527
+ ChipLogError (Controller, " Failed to process stayActiveMsec in %s since this is not a valid 32-bit integer." , __func__);
528
+ return CHIP_ERROR_INVALID_ARGUMENT;
529
+ }
530
+ params.SetICDStayActiveDurationMsec (static_cast <uint32_t >(stayActiveMsec));
531
+ }
532
+
511
533
jmethodID getCheckInNodeIdMethod;
512
534
err = chip::JniReferences::GetInstance ().FindMethod (env, icdRegistrationInfo, " getCheckInNodeId" , " ()Ljava/lang/Long;" ,
513
535
&getCheckInNodeIdMethod);
514
- VerifyOrReturnError (err == CHIP_NO_ERROR, err);
536
+ ReturnErrorOnFailure ( err);
515
537
jobject jCheckInNodeId = env->CallObjectMethod (icdRegistrationInfo, getCheckInNodeIdMethod);
516
538
517
539
jmethodID getMonitoredSubjectMethod;
518
540
err = chip::JniReferences::GetInstance ().FindMethod (env, icdRegistrationInfo, " getMonitoredSubject" , " ()Ljava/lang/Long;" ,
519
541
&getMonitoredSubjectMethod);
520
- VerifyOrReturnError (err == CHIP_NO_ERROR, err);
542
+ ReturnErrorOnFailure ( err);
521
543
jobject jMonitoredSubject = env->CallObjectMethod (icdRegistrationInfo, getMonitoredSubjectMethod);
522
544
523
545
jmethodID getSymmetricKeyMethod;
524
546
err =
525
547
chip::JniReferences::GetInstance ().FindMethod (env, icdRegistrationInfo, " getSymmetricKey" , " ()[B" , &getSymmetricKeyMethod);
526
- VerifyOrReturnError (err == CHIP_NO_ERROR, err);
548
+ ReturnErrorOnFailure ( err);
527
549
jbyteArray jSymmetricKey = static_cast <jbyteArray>(env->CallObjectMethod (icdRegistrationInfo, getSymmetricKeyMethod));
528
550
529
551
jmethodID getClientTypeMethod;
530
552
err = chip::JniReferences::GetInstance ().FindMethod (env, icdRegistrationInfo, " getClientType" , " ()Ljava/lang/Integer;" ,
531
553
&getClientTypeMethod);
532
- VerifyOrReturnError (err == CHIP_NO_ERROR, err);
554
+ ReturnErrorOnFailure ( err);
533
555
jobject jClientType = env->CallObjectMethod (icdRegistrationInfo, getClientTypeMethod);
534
556
535
557
chip::NodeId checkInNodeId = chip::kUndefinedNodeId ;
0 commit comments