Skip to content

Commit

Permalink
[nxp fromtree] [Android] Add StayActive support during commission flo…
Browse files Browse the repository at this point in the history
…w for LIT (project-chip#36028)

* [Android] Add StayActive support during commission flow for LIT (project-chip#35959)

* Fix crash when handling jStayActiveMsec (project-chip#35997)
(cherry picked from commit 3e1f7ad)
  • Loading branch information
yunhanw-google authored and andrei-menzopol committed Oct 18, 2024
1 parent cf63957 commit 7629b94
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
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

0 comments on commit 7629b94

Please sign in to comment.