From 5b93bfb7c4e7177b241c9bfd1497d2f17e67e398 Mon Sep 17 00:00:00 2001 From: James Swan <122404367+swan-amazon@users.noreply.github.com> Date: Thu, 11 Jul 2024 20:00:14 +0000 Subject: [PATCH] wip: android chip-tool support --- src/app/tests/BUILD.gn | 1 + src/controller/CHIPDeviceController.cpp | 10 ++++++ src/controller/CHIPDeviceController.h | 2 ++ .../java/CHIPDeviceController-JNI.cpp | 36 +++++++++++++++++++ .../ChipDeviceController.java | 10 ++++++ 5 files changed, 59 insertions(+) diff --git a/src/app/tests/BUILD.gn b/src/app/tests/BUILD.gn index 7ae7f73218459f..cbf852af0f0d09 100644 --- a/src/app/tests/BUILD.gn +++ b/src/app/tests/BUILD.gn @@ -193,6 +193,7 @@ chip_test_suite("tests") { "${chip_root}/src/app", "${chip_root}/src/app/common:cluster-objects", "${chip_root}/src/app/icd/client:manager", + "${chip_root}/src/app/server:server", "${chip_root}/src/app/tests:helpers", "${chip_root}/src/app/util/mock:mock_ember", "${chip_root}/src/lib/core", diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index a3d657aa1ae7bb..9a63d728e84302 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -2684,6 +2684,16 @@ CHIP_ERROR DeviceCommissioner::ICDRegistrationInfoReady() return CHIP_NO_ERROR; } +CHIP_ERROR DeviceCommissioner::TermsAndConditionsAcknowledgementsReady() +{ + ReturnErrorCodeIf(mCommissioningStage != CommissioningStage::kConfigureTCAcknowledgments, CHIP_ERROR_INCORRECT_STATE); + + // need to advance to next step + CommissioningStageComplete(CHIP_NO_ERROR); + + return CHIP_NO_ERROR; +} + void DeviceCommissioner::OnNetworkConfigResponse(void * context, const NetworkCommissioning::Commands::NetworkConfigResponse::DecodableType & data) { diff --git a/src/controller/CHIPDeviceController.h b/src/controller/CHIPDeviceController.h index 6b69a0bf329cdd..56a2cb18c4a2ab 100644 --- a/src/controller/CHIPDeviceController.h +++ b/src/controller/CHIPDeviceController.h @@ -695,6 +695,8 @@ class DLL_EXPORT DeviceCommissioner : public DeviceController, */ CHIP_ERROR ICDRegistrationInfoReady(); + CHIP_ERROR TermsAndConditionsAcknowledgementsReady(); + /** * @brief * This function returns the current CommissioningStage for this commissioner. diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp index 93ab5ccd0a1012..bd0a44a2463f09 100644 --- a/src/controller/java/CHIPDeviceController-JNI.cpp +++ b/src/controller/java/CHIPDeviceController-JNI.cpp @@ -733,6 +733,9 @@ JNI_METHOD(void, pairDeviceWithAddress) { commissioningParams.SetDeviceAttestationDelegate(wrapper->GetDeviceAttestationDelegateBridge()); } + + commissioningParams.SetTermsAndConditionsAcknowledgement((const TermsAndConditionsAcknowledgement){ 1, 1 }); + err = wrapper->Controller()->PairDevice(static_cast(deviceId), rendezvousParams, commissioningParams); if (err != CHIP_NO_ERROR) @@ -933,6 +936,39 @@ JNI_METHOD(void, updateCommissioningNetworkCredentials) } } +JNI_METHOD(void, updateTermsAndConditionsAcknowledgements) +(JNIEnv * env, jobject self, jlong handle, jint acceptedTermsAndConditions, jint acceptedTermsAndConditionsVersion) +{ + ChipLogProgress(Controller, "updateTermsAndConditionsAcknowledgements() called"); + + // Check if the input values are within the range of uint16_t + if (acceptedTermsAndConditions < 0 || acceptedTermsAndConditions > 65535 || acceptedTermsAndConditionsVersion < 0 || + acceptedTermsAndConditionsVersion > 65535) + { + jclass illegalArgumentExceptionClass = env->FindClass("java/lang/IllegalArgumentException"); + if (illegalArgumentExceptionClass != nullptr) + { + env->ThrowNew(illegalArgumentExceptionClass, "Input values must be in the range 0 to 65535."); + } + return; + } + + AndroidDeviceControllerWrapper * wrapper = AndroidDeviceControllerWrapper::FromJNIHandle(handle); + + // Retrieve the commissioning parameters + CommissioningParameters commissioningParams = wrapper->GetAutoCommissioner()->GetCommissioningParameters(); + + TermsAndConditionsAcknowledgement termsAndConditionsAcknowledgement; + termsAndConditionsAcknowledgement.acceptedTermsAndConditions = static_cast(acceptedTermsAndConditions); + termsAndConditionsAcknowledgement.acceptedTermsAndConditionsVersion = static_cast(acceptedTermsAndConditionsVersion); + + // Update the commissioning parameters with the new terms and conditions + commissioningParams.SetTermsAndConditionsAcknowledgement(termsAndConditionsAcknowledgement); + + // Set the updated commissioning parameters back to the wrapper + wrapper->GetAutoCommissioner()->SetCommissioningParameters(commissioningParams); +} + JNI_METHOD(void, updateCommissioningICDRegistrationInfo) (JNIEnv * env, jobject self, jlong handle, jobject icdRegistrationInfo) { diff --git a/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java b/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java index 37e9e7093a1afc..75b8deb537fa39 100644 --- a/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java +++ b/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java @@ -580,6 +580,10 @@ public void updateCommissioningICDRegistrationInfo(ICDRegistrationInfo icdRegist updateCommissioningICDRegistrationInfo(deviceControllerPtr, icdRegistrationInfo); } + public void updateTermsAndConditionsAcknowledgements(int acceptedTermsAndConditions, int acceptedTermsAndConditionsVersion) throws java.lang.IllegalArgumentException { + updateTermsAndConditionsAcknowledgements(deviceControllerPtr, acceptedTermsAndConditions, acceptedTermsAndConditionsVersion); + } + public void unpairDevice(long deviceId) { unpairDevice(deviceControllerPtr, deviceId); } @@ -1717,6 +1721,8 @@ private native void setUseJavaCallbackForNOCRequest( private native void updateCommissioningNetworkCredentials( long deviceControllerPtr, NetworkCredentials networkCredentials); + private native void updateTermsAndConditionsAcknowledgements(long deviceControllerPtr, int acceptedTermsAndConditions, int acceptedTermsAndConditionsVersion) throws java.lang.IllegalArgumentException; + private native void updateCommissioningICDRegistrationInfo( long deviceControllerPtr, ICDRegistrationInfo icdRegistrationInfo); @@ -1793,6 +1799,10 @@ void onScanNetworksSuccess( Optional> threadScanResults); } + public interface TermsAndConditionsListener { + void onTermsAndConditionsAcknowlegementRequired(); + } + /** Interface to listen for callbacks from CHIPDeviceController. */ public interface CompletionListener {