From 1d4f577e4fbbb5043c42f0739d480e5188329da1 Mon Sep 17 00:00:00 2001 From: Joonhaeng Heo Date: Wed, 28 Feb 2024 08:38:43 +0900 Subject: [PATCH] Add Android Checkin --- .../main/java/com/google/chip/chiptool/ChipClient.kt | 7 ++++++- .../java/AndroidDeviceControllerWrapper.cpp | 11 ++++++++++- src/controller/java/AndroidDeviceControllerWrapper.h | 6 +++++- src/controller/java/CHIPDeviceController-JNI.cpp | 7 ++++++- .../src/chip/devicecontroller/ControllerParams.java | 12 ++++++++++++ .../java/src/matter/controller/ControllerParams.kt | 1 + .../src/matter/controller/MatterControllerImpl.kt | 1 + 7 files changed, 41 insertions(+), 4 deletions(-) diff --git a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/ChipClient.kt b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/ChipClient.kt index 77c59d75d00c36..6372b14c5fa71f 100644 --- a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/ChipClient.kt +++ b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/ChipClient.kt @@ -48,7 +48,12 @@ object ChipClient { if (!this::chipDeviceController.isInitialized) { chipDeviceController = - ChipDeviceController(ControllerParams.newBuilder().setControllerVendorId(VENDOR_ID).build()) + ChipDeviceController( + ControllerParams.newBuilder() + .setControllerVendorId(VENDOR_ID) + .setEnableServerInteractions(true) + .build() + ) // Set delegate for attestation trust store for device attestation verifier. // It will replace the default attestation trust store. diff --git a/src/controller/java/AndroidDeviceControllerWrapper.cpp b/src/controller/java/AndroidDeviceControllerWrapper.cpp index 74e1187ef2a03b..b03ed10a84df1b 100644 --- a/src/controller/java/AndroidDeviceControllerWrapper.cpp +++ b/src/controller/java/AndroidDeviceControllerWrapper.cpp @@ -104,7 +104,7 @@ AndroidDeviceControllerWrapper * AndroidDeviceControllerWrapper::AllocateNew( jobject keypairDelegate, jbyteArray rootCertificate, jbyteArray intermediateCertificate, jbyteArray nodeOperationalCertificate, jbyteArray ipkEpochKey, uint16_t listenPort, uint16_t controllerVendorId, uint16_t failsafeTimerSeconds, bool attemptNetworkScanWiFi, bool attemptNetworkScanThread, bool skipCommissioningComplete, - bool skipAttestationCertificateValidation, CHIP_ERROR * errInfoOnFailure) + bool skipAttestationCertificateValidation, bool enableServerInteractions, CHIP_ERROR * errInfoOnFailure) { if (errInfoOnFailure == nullptr) { @@ -332,6 +332,9 @@ AndroidDeviceControllerWrapper * AndroidDeviceControllerWrapper::AllocateNew( setupParams.controllerNOC = nocSpan; } + initParams.enableServerInteractions = enableServerInteractions; + setupParams.enableServerInteractions = enableServerInteractions; + *errInfoOnFailure = DeviceControllerFactory::GetInstance().Init(initParams); if (*errInfoOnFailure != CHIP_NO_ERROR) { @@ -374,6 +377,11 @@ AndroidDeviceControllerWrapper * AndroidDeviceControllerWrapper::AllocateNew( wrapper->getICDClientStorage()->UpdateFabricList(wrapper->Controller()->GetFabricIndex()); + auto engine = chip::app::InteractionModelEngine::GetInstance(); + *errInfoOnFailure = wrapper->mCheckInDelegate.Init(&wrapper->mICDClientStorage, engine); + *errInfoOnFailure = wrapper->mCheckInHandler.Init(DeviceControllerFactory::GetInstance().GetSystemState()->ExchangeMgr(), + &wrapper->mICDClientStorage, &wrapper->mCheckInDelegate, engine); + memset(ipkBuffer.data(), 0, ipkBuffer.size()); if (*errInfoOnFailure != CHIP_NO_ERROR) @@ -749,6 +757,7 @@ void AndroidDeviceControllerWrapper::OnReadCommissioningInfo(const chip::Control // For ICD mUserActiveModeTriggerHint = info.icd.userActiveModeTriggerHint; + memset(mUserActiveModeTriggerInstructionBuffer, 0x00, kUserActiveModeTriggerInstructionBufferLen); CopyCharSpanToMutableCharSpan(info.icd.userActiveModeTriggerInstruction, mUserActiveModeTriggerInstruction); env->CallVoidMethod(mJavaObjectRef.ObjectRef(), onReadCommissioningInfoMethod, static_cast(info.basic.vendorId), diff --git a/src/controller/java/AndroidDeviceControllerWrapper.h b/src/controller/java/AndroidDeviceControllerWrapper.h index ac279370f62c4a..24ff8289194c2b 100644 --- a/src/controller/java/AndroidDeviceControllerWrapper.h +++ b/src/controller/java/AndroidDeviceControllerWrapper.h @@ -24,6 +24,8 @@ #include +#include +#include #include #include #include @@ -184,7 +186,7 @@ class AndroidDeviceControllerWrapper : public chip::Controller::DevicePairingDel jobject keypairDelegate, jbyteArray rootCertificate, jbyteArray intermediateCertificate, jbyteArray nodeOperationalCertificate, jbyteArray ipkEpochKey, uint16_t listenPort, uint16_t controllerVendorId, uint16_t failsafeTimerSeconds, bool attemptNetworkScanWiFi, bool attemptNetworkScanThread, - bool skipCommissioningComplete, bool skipAttestationCertificateValidation, CHIP_ERROR * errInfoOnFailure); + bool skipCommissioningComplete, bool skipAttestationCertificateValidation, bool enableServerInteractions, CHIP_ERROR * errInfoOnFailure); void Shutdown(); @@ -223,6 +225,8 @@ class AndroidDeviceControllerWrapper : public chip::Controller::DevicePairingDel chip::Crypto::RawKeySessionKeystore mSessionKeystore; chip::app::DefaultICDClientStorage mICDClientStorage; + chip::app::DefaultCheckInDelegate mCheckInDelegate; + chip::app::CheckInHandler mCheckInHandler; JavaVM * mJavaVM = nullptr; chip::JniGlobalReference mJavaObjectRef; diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp index fc2c0694b29849..7c4771abddd510 100644 --- a/src/controller/java/CHIPDeviceController-JNI.cpp +++ b/src/controller/java/CHIPDeviceController-JNI.cpp @@ -350,6 +350,10 @@ JNI_METHOD(jlong, newDeviceController)(JNIEnv * env, jobject self, jobject contr err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getAdminSubject", "()J", &getAdminSubject); SuccessOrExit(err); + jmethodID getEnableServerInteractions; + err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getEnableServerInteractions", "()Z", &getEnableServerInteractions); + SuccessOrExit(err); + { uint64_t fabricId = static_cast(env->CallLongMethod(controllerParams, getFabricId)); uint16_t listenPort = static_cast(env->CallIntMethod(controllerParams, getUdpListenPort)); @@ -370,6 +374,7 @@ JNI_METHOD(jlong, newDeviceController)(JNIEnv * env, jobject self, jobject contr uint64_t adminSubject = static_cast(env->CallLongMethod(controllerParams, getAdminSubject)); jobject countryCodeOptional = env->CallObjectMethod(controllerParams, getCountryCode); jobject regulatoryLocationOptional = env->CallObjectMethod(controllerParams, getRegulatoryLocation); + bool enableServerInteractions = env->CallBooleanMethod(controllerParams, getEnableServerInteractions) == JNI_TRUE; #ifdef JAVA_MATTER_CONTROLLER_TEST std::unique_ptr opCredsIssuer( @@ -383,7 +388,7 @@ JNI_METHOD(jlong, newDeviceController)(JNIEnv * env, jobject self, jobject contr DeviceLayer::TCPEndPointManager(), DeviceLayer::UDPEndPointManager(), std::move(opCredsIssuer), keypairDelegate, rootCertificate, intermediateCertificate, operationalCertificate, ipk, listenPort, controllerVendorId, failsafeTimerSeconds, attemptNetworkScanWiFi, attemptNetworkScanThread, skipCommissioningComplete, - skipAttestationCertificateValidation, &err); + skipAttestationCertificateValidation, enableServerInteractions, &err); SuccessOrExit(err); if (caseFailsafeTimerSeconds > 0) diff --git a/src/controller/java/src/chip/devicecontroller/ControllerParams.java b/src/controller/java/src/chip/devicecontroller/ControllerParams.java index ca41cf900902af..cc48570b91826e 100644 --- a/src/controller/java/src/chip/devicecontroller/ControllerParams.java +++ b/src/controller/java/src/chip/devicecontroller/ControllerParams.java @@ -23,6 +23,7 @@ public final class ControllerParams { @Nullable private final byte[] operationalCertificate; @Nullable private final byte[] ipk; private final long adminSubject; + private final boolean enableServerInteractions; /** @param udpListenPort the UDP listening port, or 0 to pick any available port. */ private ControllerParams(Builder builder) { @@ -43,6 +44,7 @@ private ControllerParams(Builder builder) { this.operationalCertificate = builder.operationalCertificate; this.ipk = builder.ipk; this.adminSubject = builder.adminSubject; + this.enableServerInteractions = builder.enableServerInteractions; } public long getFabricId() { @@ -114,6 +116,10 @@ public long getAdminSubject() { return adminSubject; } + public boolean getEnableServerInteractions() { + return enableServerInteractions; + } + /** Returns parameters with ephemerally generated operational credentials */ public static Builder newBuilder() { return new Builder(); @@ -152,6 +158,7 @@ public static class Builder { @Nullable private byte[] operationalCertificate = null; @Nullable private byte[] ipk = null; private long adminSubject = 0; + private boolean enableServerInteractions = false; private Builder() {} @@ -357,6 +364,11 @@ public Builder setAdminSubject(long adminSubject) { return this; } + public Builder setEnableServerInteractions(boolean enableServerInteractions) { + this.enableServerInteractions = enableServerInteractions; + return this; + } + public ControllerParams build() { return new ControllerParams(this); } diff --git a/src/controller/java/src/matter/controller/ControllerParams.kt b/src/controller/java/src/matter/controller/ControllerParams.kt index d0fb23222ea68e..35ac25549910a7 100644 --- a/src/controller/java/src/matter/controller/ControllerParams.kt +++ b/src/controller/java/src/matter/controller/ControllerParams.kt @@ -32,6 +32,7 @@ constructor( val udpListenPort: Int = UDP_PORT_AUTO, val vendorId: Int = VENDOR_ID_TEST, val countryCode: String? = null, + val enableServerInteractions: Boolean = false, ) { companion object { /** Matter assigned vendor ID for Google. */ diff --git a/src/controller/java/src/matter/controller/MatterControllerImpl.kt b/src/controller/java/src/matter/controller/MatterControllerImpl.kt index 6ae71f33a0faac..dde29eeb7c5354 100644 --- a/src/controller/java/src/matter/controller/MatterControllerImpl.kt +++ b/src/controller/java/src/matter/controller/MatterControllerImpl.kt @@ -543,6 +543,7 @@ class MatterControllerImpl(params: ControllerParams) : MatterController { .setUdpListenPort(params.udpListenPort) .setControllerVendorId(params.vendorId) .setCountryCode(params.countryCode) + .setEnableServerInteractions(params.enableServerInteractions) if (config != null) { val intermediateCertificate = config.certificateData.intermediateCertificate