Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Add StayActive support during commission flow for LIT #36028

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class DeviceProvisioningFragment : Fragment() {
override fun onICDRegistrationInfoRequired() {
Log.d(TAG, "onICDRegistrationInfoRequired")
deviceController.updateCommissioningICDRegistrationInfo(
ICDRegistrationInfo.newBuilder().build()
ICDRegistrationInfo.newBuilder().setICDStayActiveDurationMsec(30000L).build()
)
}

Expand Down
30 changes: 26 additions & 4 deletions src/controller/java/AndroidDeviceControllerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,28 +508,50 @@ CHIP_ERROR AndroidDeviceControllerWrapper::ApplyICDRegistrationInfo(chip::Contro
VerifyOrReturnError(icdRegistrationInfo != nullptr, CHIP_ERROR_INVALID_ARGUMENT);

JNIEnv * env = chip::JniReferences::GetInstance().GetEnvForCurrentThread();
if (env == nullptr)
{
ChipLogError(Controller, "Failed to retrieve JNIEnv in %s.", __func__);
return CHIP_ERROR_INCORRECT_STATE;
}

jmethodID getICDStayActiveDurationMsecMethod;
err = chip::JniReferences::GetInstance().FindMethod(env, icdRegistrationInfo, "getICDStayActiveDurationMsec",
"()Ljava/lang/Long;", &getICDStayActiveDurationMsecMethod);
ReturnErrorOnFailure(err);
jobject jStayActiveMsec = env->CallObjectMethod(icdRegistrationInfo, getICDStayActiveDurationMsecMethod);
if (jStayActiveMsec != nullptr)
{
jlong stayActiveMsec = chip::JniReferences::GetInstance().LongToPrimitive(jStayActiveMsec);
if (!chip::CanCastTo<uint32_t>(stayActiveMsec))
{
ChipLogError(Controller, "Failed to process stayActiveMsec in %s since this is not a valid 32-bit integer.", __func__);
return CHIP_ERROR_INVALID_ARGUMENT;
}
params.SetICDStayActiveDurationMsec(static_cast<uint32_t>(stayActiveMsec));
}

jmethodID getCheckInNodeIdMethod;
err = chip::JniReferences::GetInstance().FindMethod(env, icdRegistrationInfo, "getCheckInNodeId", "()Ljava/lang/Long;",
&getCheckInNodeIdMethod);
VerifyOrReturnError(err == CHIP_NO_ERROR, err);
ReturnErrorOnFailure(err);
jobject jCheckInNodeId = env->CallObjectMethod(icdRegistrationInfo, getCheckInNodeIdMethod);

jmethodID getMonitoredSubjectMethod;
err = chip::JniReferences::GetInstance().FindMethod(env, icdRegistrationInfo, "getMonitoredSubject", "()Ljava/lang/Long;",
&getMonitoredSubjectMethod);
VerifyOrReturnError(err == CHIP_NO_ERROR, err);
ReturnErrorOnFailure(err);
jobject jMonitoredSubject = env->CallObjectMethod(icdRegistrationInfo, getMonitoredSubjectMethod);

jmethodID getSymmetricKeyMethod;
err =
chip::JniReferences::GetInstance().FindMethod(env, icdRegistrationInfo, "getSymmetricKey", "()[B", &getSymmetricKeyMethod);
VerifyOrReturnError(err == CHIP_NO_ERROR, err);
ReturnErrorOnFailure(err);
jbyteArray jSymmetricKey = static_cast<jbyteArray>(env->CallObjectMethod(icdRegistrationInfo, getSymmetricKeyMethod));

jmethodID getClientTypeMethod;
err = chip::JniReferences::GetInstance().FindMethod(env, icdRegistrationInfo, "getClientType", "()Ljava/lang/Integer;",
&getClientTypeMethod);
VerifyOrReturnError(err == CHIP_NO_ERROR, err);
ReturnErrorOnFailure(err);
jobject jClientType = env->CallObjectMethod(icdRegistrationInfo, getClientTypeMethod);

chip::NodeId checkInNodeId = chip::kUndefinedNodeId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,19 @@ public class ICDRegistrationInfo {
@Nullable private final Long monitoredSubject;
@Nullable private final byte[] symmetricKey;
@Nullable private final Integer clientType;
@Nullable private final Long stayActiveDurationMsec;

private ICDRegistrationInfo(Builder builder) {
this.checkInNodeId = builder.checkInNodeId;
this.monitoredSubject = builder.monitoredSubject;
this.symmetricKey = builder.symmetricKey;
this.clientType = builder.clientType;
this.stayActiveDurationMsec = builder.stayActiveDurationMsec;
}

/** Returns the duration period to stay active. */
public Long getICDStayActiveDurationMsec() {
return stayActiveDurationMsec;
}

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

private Builder() {}

Expand Down Expand Up @@ -93,6 +101,15 @@ public Builder setClientType(Integer clientType) {
return this;
}

/**
* Request LIT device to stay active for specific duration after commission completes, the upper
* bound is 30 seconds.
*/
public Builder setICDStayActiveDurationMsec(Long stayActiveDurationMsec) {
this.stayActiveDurationMsec = stayActiveDurationMsec;
return this;
}

public ICDRegistrationInfo build() {
return new ICDRegistrationInfo(this);
}
Expand Down
Loading