Skip to content

Commit 6a254ac

Browse files
joonhaengHeorestyled-commitsyunhanw-googlemkardous-silabs
authored
[Android] Support ICD Check in message (project-chip#32476)
* Add Android Checkin * Restyled by clang-format * Restyled by clang-format * Add enableServerInteractions comment * Restyled by whitespace * Restyled by google-java-format * Update src/controller/java/src/chip/devicecontroller/ControllerParams.java Co-authored-by: mkardous-silabs <84793247+mkardous-silabs@users.noreply.github.com> * Update ControllerParams.java address comment --------- Co-authored-by: Restyled.io <commits@restyled.io> Co-authored-by: yunhanw-google <yunhanw@google.com> Co-authored-by: mkardous-silabs <84793247+mkardous-silabs@users.noreply.github.com>
1 parent 622ca76 commit 6a254ac

File tree

7 files changed

+59
-13
lines changed

7 files changed

+59
-13
lines changed

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ object ChipClient {
4848

4949
if (!this::chipDeviceController.isInitialized) {
5050
chipDeviceController =
51-
ChipDeviceController(ControllerParams.newBuilder().setControllerVendorId(VENDOR_ID).build())
51+
ChipDeviceController(
52+
ControllerParams.newBuilder()
53+
.setControllerVendorId(VENDOR_ID)
54+
.setEnableServerInteractions(true)
55+
.build()
56+
)
5257

5358
// Set delegate for attestation trust store for device attestation verifier.
5459
// It will replace the default attestation trust store.

src/controller/java/AndroidDeviceControllerWrapper.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ AndroidDeviceControllerWrapper * AndroidDeviceControllerWrapper::AllocateNew(
104104
jobject keypairDelegate, jbyteArray rootCertificate, jbyteArray intermediateCertificate, jbyteArray nodeOperationalCertificate,
105105
jbyteArray ipkEpochKey, uint16_t listenPort, uint16_t controllerVendorId, uint16_t failsafeTimerSeconds,
106106
bool attemptNetworkScanWiFi, bool attemptNetworkScanThread, bool skipCommissioningComplete,
107-
bool skipAttestationCertificateValidation, jstring countryCode, CHIP_ERROR * errInfoOnFailure)
107+
bool skipAttestationCertificateValidation, jstring countryCode, bool enableServerInteractions, CHIP_ERROR * errInfoOnFailure)
108108
{
109109
if (errInfoOnFailure == nullptr)
110110
{
@@ -351,6 +351,9 @@ AndroidDeviceControllerWrapper * AndroidDeviceControllerWrapper::AllocateNew(
351351
setupParams.controllerNOC = nocSpan;
352352
}
353353

354+
initParams.enableServerInteractions = enableServerInteractions;
355+
setupParams.enableServerInteractions = enableServerInteractions;
356+
354357
*errInfoOnFailure = DeviceControllerFactory::GetInstance().Init(initParams);
355358
if (*errInfoOnFailure != CHIP_NO_ERROR)
356359
{
@@ -393,6 +396,11 @@ AndroidDeviceControllerWrapper * AndroidDeviceControllerWrapper::AllocateNew(
393396

394397
wrapper->getICDClientStorage()->UpdateFabricList(wrapper->Controller()->GetFabricIndex());
395398

399+
auto engine = chip::app::InteractionModelEngine::GetInstance();
400+
*errInfoOnFailure = wrapper->mCheckInDelegate.Init(&wrapper->mICDClientStorage, engine);
401+
*errInfoOnFailure = wrapper->mCheckInHandler.Init(DeviceControllerFactory::GetInstance().GetSystemState()->ExchangeMgr(),
402+
&wrapper->mICDClientStorage, &wrapper->mCheckInDelegate, engine);
403+
396404
memset(ipkBuffer.data(), 0, ipkBuffer.size());
397405

398406
if (*errInfoOnFailure != CHIP_NO_ERROR)
@@ -769,6 +777,7 @@ void AndroidDeviceControllerWrapper::OnReadCommissioningInfo(const chip::Control
769777

770778
// For ICD
771779
mUserActiveModeTriggerHint = info.icd.userActiveModeTriggerHint;
780+
memset(mUserActiveModeTriggerInstructionBuffer, 0x00, kUserActiveModeTriggerInstructionBufferLen);
772781
CopyCharSpanToMutableCharSpan(info.icd.userActiveModeTriggerInstruction, mUserActiveModeTriggerInstruction);
773782

774783
env->CallVoidMethod(mJavaObjectRef.ObjectRef(), onReadCommissioningInfoMethod, static_cast<jint>(info.basic.vendorId),

src/controller/java/AndroidDeviceControllerWrapper.h

+16-10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
#include <jni.h>
2626

27+
#include <app/icd/client/CheckInHandler.h>
28+
#include <app/icd/client/DefaultCheckInDelegate.h>
2729
#include <app/icd/client/DefaultICDClientStorage.h>
2830
#include <controller/CHIPDeviceController.h>
2931
#include <credentials/GroupDataProviderImpl.h>
@@ -170,19 +172,21 @@ class AndroidDeviceControllerWrapper : public chip::Controller::DevicePairingDel
170172
* @param[in] skipCommissioningComplete whether to skip the CASE commissioningComplete command during commissioning
171173
* @param[out] errInfoOnFailure a pointer to a CHIP_ERROR that will be populated if this method returns nullptr
172174
*/
173-
static AndroidDeviceControllerWrapper * AllocateNew(
174-
JavaVM * vm, jobject deviceControllerObj, chip::NodeId nodeId, chip::FabricId fabricId, const chip::CATValues & cats,
175-
chip::System::Layer * systemLayer, chip::Inet::EndPointManager<chip::Inet::TCPEndPoint> * tcpEndPointManager,
176-
chip::Inet::EndPointManager<chip::Inet::UDPEndPoint> * udpEndPointManager,
175+
static AndroidDeviceControllerWrapper *
176+
AllocateNew(JavaVM * vm, jobject deviceControllerObj, chip::NodeId nodeId, chip::FabricId fabricId,
177+
const chip::CATValues & cats, chip::System::Layer * systemLayer,
178+
chip::Inet::EndPointManager<chip::Inet::TCPEndPoint> * tcpEndPointManager,
179+
chip::Inet::EndPointManager<chip::Inet::UDPEndPoint> * udpEndPointManager,
177180
#ifdef JAVA_MATTER_CONTROLLER_TEST
178-
ExampleOperationalCredentialsIssuerPtr opCredsIssuer,
181+
ExampleOperationalCredentialsIssuerPtr opCredsIssuer,
179182
#else
180-
AndroidOperationalCredentialsIssuerPtr opCredsIssuer,
183+
AndroidOperationalCredentialsIssuerPtr opCredsIssuer,
181184
#endif
182-
jobject keypairDelegate, jbyteArray rootCertificate, jbyteArray intermediateCertificate,
183-
jbyteArray nodeOperationalCertificate, jbyteArray ipkEpochKey, uint16_t listenPort, uint16_t controllerVendorId,
184-
uint16_t failsafeTimerSeconds, bool attemptNetworkScanWiFi, bool attemptNetworkScanThread, bool skipCommissioningComplete,
185-
bool skipAttestationCertificateValidation, jstring countryCode, CHIP_ERROR * errInfoOnFailure);
185+
jobject keypairDelegate, jbyteArray rootCertificate, jbyteArray intermediateCertificate,
186+
jbyteArray nodeOperationalCertificate, jbyteArray ipkEpochKey, uint16_t listenPort, uint16_t controllerVendorId,
187+
uint16_t failsafeTimerSeconds, bool attemptNetworkScanWiFi, bool attemptNetworkScanThread,
188+
bool skipCommissioningComplete, bool skipAttestationCertificateValidation, jstring countryCode,
189+
bool enableServerInteractions, CHIP_ERROR * errInfoOnFailure);
186190

187191
void Shutdown();
188192

@@ -221,6 +225,8 @@ class AndroidDeviceControllerWrapper : public chip::Controller::DevicePairingDel
221225
chip::Crypto::RawKeySessionKeystore mSessionKeystore;
222226

223227
chip::app::DefaultICDClientStorage mICDClientStorage;
228+
chip::app::DefaultCheckInDelegate mCheckInDelegate;
229+
chip::app::CheckInHandler mCheckInHandler;
224230

225231
JavaVM * mJavaVM = nullptr;
226232
chip::JniGlobalReference mJavaObjectRef;

src/controller/java/CHIPDeviceController-JNI.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,11 @@ JNI_METHOD(jlong, newDeviceController)(JNIEnv * env, jobject self, jobject contr
350350
err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getAdminSubject", "()J", &getAdminSubject);
351351
SuccessOrExit(err);
352352

353+
jmethodID getEnableServerInteractions;
354+
err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getEnableServerInteractions", "()Z",
355+
&getEnableServerInteractions);
356+
SuccessOrExit(err);
357+
353358
{
354359
uint64_t fabricId = static_cast<uint64_t>(env->CallLongMethod(controllerParams, getFabricId));
355360
uint16_t listenPort = static_cast<uint16_t>(env->CallIntMethod(controllerParams, getUdpListenPort));
@@ -370,6 +375,7 @@ JNI_METHOD(jlong, newDeviceController)(JNIEnv * env, jobject self, jobject contr
370375
uint64_t adminSubject = static_cast<uint64_t>(env->CallLongMethod(controllerParams, getAdminSubject));
371376
jobject countryCodeOptional = env->CallObjectMethod(controllerParams, getCountryCode);
372377
jobject regulatoryLocationOptional = env->CallObjectMethod(controllerParams, getRegulatoryLocation);
378+
bool enableServerInteractions = env->CallBooleanMethod(controllerParams, getEnableServerInteractions) == JNI_TRUE;
373379

374380
jobject countryCode;
375381
err = chip::JniReferences::GetInstance().GetOptionalValue(countryCodeOptional, countryCode);
@@ -387,7 +393,7 @@ JNI_METHOD(jlong, newDeviceController)(JNIEnv * env, jobject self, jobject contr
387393
DeviceLayer::TCPEndPointManager(), DeviceLayer::UDPEndPointManager(), std::move(opCredsIssuer), keypairDelegate,
388394
rootCertificate, intermediateCertificate, operationalCertificate, ipk, listenPort, controllerVendorId,
389395
failsafeTimerSeconds, attemptNetworkScanWiFi, attemptNetworkScanThread, skipCommissioningComplete,
390-
skipAttestationCertificateValidation, static_cast<jstring>(countryCode), &err);
396+
skipAttestationCertificateValidation, static_cast<jstring>(countryCode), enableServerInteractions, &err);
391397
SuccessOrExit(err);
392398

393399
if (caseFailsafeTimerSeconds > 0)

src/controller/java/src/chip/devicecontroller/ControllerParams.java

+18
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public final class ControllerParams {
2323
@Nullable private final byte[] operationalCertificate;
2424
@Nullable private final byte[] ipk;
2525
private final long adminSubject;
26+
private final boolean enableServerInteractions;
2627

2728
/** @param udpListenPort the UDP listening port, or 0 to pick any available port. */
2829
private ControllerParams(Builder builder) {
@@ -43,6 +44,7 @@ private ControllerParams(Builder builder) {
4344
this.operationalCertificate = builder.operationalCertificate;
4445
this.ipk = builder.ipk;
4546
this.adminSubject = builder.adminSubject;
47+
this.enableServerInteractions = builder.enableServerInteractions;
4648
}
4749

4850
public long getFabricId() {
@@ -114,6 +116,10 @@ public long getAdminSubject() {
114116
return adminSubject;
115117
}
116118

119+
public boolean getEnableServerInteractions() {
120+
return enableServerInteractions;
121+
}
122+
117123
/** Returns parameters with ephemerally generated operational credentials */
118124
public static Builder newBuilder() {
119125
return new Builder();
@@ -152,6 +158,7 @@ public static class Builder {
152158
@Nullable private byte[] operationalCertificate = null;
153159
@Nullable private byte[] ipk = null;
154160
private long adminSubject = 0;
161+
private boolean enableServerInteractions = false;
155162

156163
private Builder() {}
157164

@@ -357,6 +364,17 @@ public Builder setAdminSubject(long adminSubject) {
357364
return this;
358365
}
359366

367+
/**
368+
* Controls enabling server interactions on a controller. For ICD check-in message, this feature
369+
* has to be enabled.
370+
*
371+
* @param enableServerInteractions indicates whether to enable server interactions.
372+
*/
373+
public Builder setEnableServerInteractions(boolean enableServerInteractions) {
374+
this.enableServerInteractions = enableServerInteractions;
375+
return this;
376+
}
377+
360378
public ControllerParams build() {
361379
return new ControllerParams(this);
362380
}

src/controller/java/src/matter/controller/ControllerParams.kt

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ constructor(
3232
val udpListenPort: Int = UDP_PORT_AUTO,
3333
val vendorId: Int = VENDOR_ID_TEST,
3434
val countryCode: String? = null,
35+
val enableServerInteractions: Boolean = false,
3536
) {
3637
companion object {
3738
/** Matter assigned vendor ID for Google. */

src/controller/java/src/matter/controller/MatterControllerImpl.kt

+1
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ class MatterControllerImpl(params: ControllerParams) : MatterController {
543543
.setUdpListenPort(params.udpListenPort)
544544
.setControllerVendorId(params.vendorId)
545545
.setCountryCode(params.countryCode)
546+
.setEnableServerInteractions(params.enableServerInteractions)
546547

547548
if (config != null) {
548549
val intermediateCertificate = config.certificateData.intermediateCertificate

0 commit comments

Comments
 (0)