Skip to content

Commit

Permalink
wip: android chip-tool support
Browse files Browse the repository at this point in the history
  • Loading branch information
swan-amazon committed Jul 16, 2024
1 parent 20c3465 commit 5b93bfb
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/app/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 10 additions & 0 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 2 additions & 0 deletions src/controller/CHIPDeviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
36 changes: 36 additions & 0 deletions src/controller/java/CHIPDeviceController-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,9 @@ JNI_METHOD(void, pairDeviceWithAddress)
{
commissioningParams.SetDeviceAttestationDelegate(wrapper->GetDeviceAttestationDelegateBridge());
}

commissioningParams.SetTermsAndConditionsAcknowledgement((const TermsAndConditionsAcknowledgement){ 1, 1 });

err = wrapper->Controller()->PairDevice(static_cast<chip::NodeId>(deviceId), rendezvousParams, commissioningParams);

if (err != CHIP_NO_ERROR)
Expand Down Expand Up @@ -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<uint16_t>(acceptedTermsAndConditions);
termsAndConditionsAcknowledgement.acceptedTermsAndConditionsVersion = static_cast<uint16_t>(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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -1793,6 +1799,10 @@ void onScanNetworksSuccess(
Optional<ArrayList<ThreadScanResult>> threadScanResults);
}

public interface TermsAndConditionsListener {
void onTermsAndConditionsAcknowlegementRequired();
}

/** Interface to listen for callbacks from CHIPDeviceController. */
public interface CompletionListener {

Expand Down

0 comments on commit 5b93bfb

Please sign in to comment.