Skip to content

Commit 7fcc60f

Browse files
[Android] Add StayActive support during commission flow for LIT (project-chip#35959)
1 parent 4a21a8d commit 7fcc60f

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-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
}

0 commit comments

Comments
 (0)