Skip to content

Commit 52d2bae

Browse files
Merge branch 'project-chip:master' into master
2 parents 966f7c0 + af3727b commit 52d2bae

File tree

4 files changed

+47
-5
lines changed

4 files changed

+47
-5
lines changed

examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/DeviceProvisioningFragment.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ class DeviceProvisioningFragment : Fragment() {
289289
override fun onICDRegistrationInfoRequired() {
290290
Log.d(TAG, "onICDRegistrationInfoRequired")
291291
deviceController.updateCommissioningICDRegistrationInfo(
292-
ICDRegistrationInfo.newBuilder().build()
292+
ICDRegistrationInfo.newBuilder().setICDStayActiveDurationMsec(30000L).build()
293293
)
294294
}
295295

src/controller/java/AndroidDeviceControllerWrapper.cpp

+20-4
Original file line numberDiff line numberDiff line change
@@ -508,28 +508,44 @@ CHIP_ERROR AndroidDeviceControllerWrapper::ApplyICDRegistrationInfo(chip::Contro
508508
VerifyOrReturnError(icdRegistrationInfo != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
509509

510510
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 != 0)
523+
{
524+
params.SetICDStayActiveDurationMsec(chip::JniReferences::GetInstance().IntegerToPrimitive(jStayActiveMsec));
525+
}
526+
511527
jmethodID getCheckInNodeIdMethod;
512528
err = chip::JniReferences::GetInstance().FindMethod(env, icdRegistrationInfo, "getCheckInNodeId", "()Ljava/lang/Long;",
513529
&getCheckInNodeIdMethod);
514-
VerifyOrReturnError(err == CHIP_NO_ERROR, err);
530+
ReturnErrorOnFailure(err);
515531
jobject jCheckInNodeId = env->CallObjectMethod(icdRegistrationInfo, getCheckInNodeIdMethod);
516532

517533
jmethodID getMonitoredSubjectMethod;
518534
err = chip::JniReferences::GetInstance().FindMethod(env, icdRegistrationInfo, "getMonitoredSubject", "()Ljava/lang/Long;",
519535
&getMonitoredSubjectMethod);
520-
VerifyOrReturnError(err == CHIP_NO_ERROR, err);
536+
ReturnErrorOnFailure(err);
521537
jobject jMonitoredSubject = env->CallObjectMethod(icdRegistrationInfo, getMonitoredSubjectMethod);
522538

523539
jmethodID getSymmetricKeyMethod;
524540
err =
525541
chip::JniReferences::GetInstance().FindMethod(env, icdRegistrationInfo, "getSymmetricKey", "()[B", &getSymmetricKeyMethod);
526-
VerifyOrReturnError(err == CHIP_NO_ERROR, err);
542+
ReturnErrorOnFailure(err);
527543
jbyteArray jSymmetricKey = static_cast<jbyteArray>(env->CallObjectMethod(icdRegistrationInfo, getSymmetricKeyMethod));
528544

529545
jmethodID getClientTypeMethod;
530546
err = chip::JniReferences::GetInstance().FindMethod(env, icdRegistrationInfo, "getClientType", "()Ljava/lang/Integer;",
531547
&getClientTypeMethod);
532-
VerifyOrReturnError(err == CHIP_NO_ERROR, err);
548+
ReturnErrorOnFailure(err);
533549
jobject jClientType = env->CallObjectMethod(icdRegistrationInfo, getClientTypeMethod);
534550

535551
chip::NodeId checkInNodeId = chip::kUndefinedNodeId;

src/controller/java/src/chip/devicecontroller/ICDRegistrationInfo.java

+17
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,19 @@ public class ICDRegistrationInfo {
2525
@Nullable private final Long monitoredSubject;
2626
@Nullable private final byte[] symmetricKey;
2727
@Nullable private final Integer clientType;
28+
@Nullable private final Long stayActiveDurationMsec;
2829

2930
private ICDRegistrationInfo(Builder builder) {
3031
this.checkInNodeId = builder.checkInNodeId;
3132
this.monitoredSubject = builder.monitoredSubject;
3233
this.symmetricKey = builder.symmetricKey;
3334
this.clientType = builder.clientType;
35+
this.stayActiveDurationMsec = builder.stayActiveDurationMsec;
36+
}
37+
38+
/** Returns the duration period to stay active. */
39+
public Long getICDStayActiveDurationMsec() {
40+
return stayActiveDurationMsec;
3441
}
3542

3643
/** Returns the check in node ID. */
@@ -62,6 +69,7 @@ public static class Builder {
6269
@Nullable private Long monitoredSubject = null;
6370
@Nullable private byte[] symmetricKey = null;
6471
@Nullable private Integer clientType = null;
72+
@Nullable private Long stayActiveDurationMsec = null;
6573

6674
private Builder() {}
6775

@@ -93,6 +101,15 @@ public Builder setClientType(Integer clientType) {
93101
return this;
94102
}
95103

104+
/**
105+
* Request LIT device to stay active for specific duration after commission completes, the upper
106+
* bound is 30 seconds.
107+
*/
108+
public Builder setICDStayActiveDurationMsec(Long stayActiveDurationMsec) {
109+
this.stayActiveDurationMsec = stayActiveDurationMsec;
110+
return this;
111+
}
112+
96113
public ICDRegistrationInfo build() {
97114
return new ICDRegistrationInfo(this);
98115
}

src/darwin/Framework/CHIP/MTRDevice_Concrete.mm

+9
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,9 @@ - (void)_ensureSubscriptionForExistingDelegates:(NSString *)reason
757757
}
758758
if ([self _deviceUsesThread]) {
759759
MTR_LOG(" => %@ - device is a thread device, scheduling in pool", self);
760+
mtr_weakify(self);
760761
[self _scheduleSubscriptionPoolWork:^{
762+
mtr_strongify(self);
761763
[self->_deviceController asyncDispatchToMatterQueue:^{
762764
std::lock_guard lock(self->_lock);
763765
[self _setupSubscriptionWithReason:[NSString stringWithFormat:@"%@ and scheduled subscription is happening", reason]];
@@ -1165,10 +1167,13 @@ - (void)_scheduleSubscriptionPoolWork:(dispatch_block_t)workBlock inNanoseconds:
11651167
return;
11661168
}
11671169

1170+
mtr_weakify(self);
11681171
dispatch_block_t workBlockToQueue = ^{
1172+
mtr_strongify(self);
11691173
// In the case where a resubscription triggering event happened and already established, running the work block should result in a no-op
11701174
MTRAsyncWorkItem * workItem = [[MTRAsyncWorkItem alloc] initWithQueue:self.queue];
11711175
[workItem setReadyHandler:^(id _Nonnull context, NSInteger retryCount, MTRAsyncWorkCompletionBlock _Nonnull completion) {
1176+
mtr_strongify(self);
11721177
MTR_LOG("%@ - work item is ready to attempt pooled subscription", self);
11731178
os_unfair_lock_lock(&self->_lock);
11741179
#ifdef DEBUG
@@ -1246,7 +1251,9 @@ - (void)_handleResubscriptionNeededWithDelayOnDeviceQueue:(NSNumber *)resubscrip
12461251

12471252
// Use the existing _triggerResubscribeWithReason mechanism, which does the right checks when
12481253
// this block is run -- if other triggering events had happened, this would become a no-op.
1254+
mtr_weakify(self);
12491255
auto resubscriptionBlock = ^{
1256+
mtr_strongify(self);
12501257
[self->_deviceController asyncDispatchToMatterQueue:^{
12511258
[self _triggerResubscribeWithReason:@"ResubscriptionNeeded timer fired" nodeLikelyReachable:NO];
12521259
} errorHandler:^(NSError * _Nonnull error) {
@@ -1357,7 +1364,9 @@ - (void)_doHandleSubscriptionReset:(NSNumber * _Nullable)retryDelay
13571364

13581365
// Call _reattemptSubscriptionNowIfNeededWithReason when timer fires - if subscription is
13591366
// in a better state at that time this will be a no-op.
1367+
mtr_weakify(self);
13601368
auto resubscriptionBlock = ^{
1369+
mtr_strongify(self);
13611370
[self->_deviceController asyncDispatchToMatterQueue:^{
13621371
std::lock_guard lock(self->_lock);
13631372
[self _reattemptSubscriptionNowIfNeededWithReason:@"got subscription reset"];

0 commit comments

Comments
 (0)