Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
swan-amazon committed Aug 26, 2024
1 parent ac4633a commit dbccc78
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ CommissioningErrorEnum CheckTermsAndConditionsAcknowledgementsState(const Option
return CommissioningErrorEnum::kOk;
}

#if 0
CHIP_ERROR CheckTermsAndConditionsAcknowledgementsStateOnCommissioningComplete(CommissioningErrorEnum & errorCode)
{
EnhancedSetupFlowProvider * const enhancedSetupFlowProvider = Server::GetInstance().GetEnhancedSetupFlowProvider();
Expand All @@ -219,6 +220,7 @@ CHIP_ERROR CheckTermsAndConditionsAcknowledgementsStateOnCommissioningComplete(C

}
#endif
#endif

} // anonymous namespace

Expand Down Expand Up @@ -316,7 +318,29 @@ bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback(
else
{
#if CHIP_CONFIG_TC_REQUIRED
CheckSuccess(CheckTermsAndConditionsAcknowledgementsStateOnCommissioningComplete(response.errorCode), Failure);
// CheckSuccess(CheckTermsAndConditionsAcknowledgementsStateOnCommissioningComplete(response.errorCode), Failure);

EnhancedSetupFlowProvider * const enhancedSetupFlowProvider = Server::GetInstance().GetEnhancedSetupFlowProvider();

Optional<TermsAndConditions> acceptedTermsAndConditions;
Optional<TermsAndConditions> requiredTermsAndConditions;

enhancedSetupFlowProvider->GetTermsAndConditionsAcknowledgements(acceptedTermsAndConditions);
enhancedSetupFlowProvider->GetTermsAndConditionsRequirements(requiredTermsAndConditions);

ChipLogError(AppServer, "acceptedTermsAndConditions HasValue= %d", acceptedTermsAndConditions.HasValue());
if (acceptedTermsAndConditions.HasValue())
{
ChipLogError(AppServer, "acceptedTermsAndConditions Value= %d", acceptedTermsAndConditions.Value().value);
ChipLogError(AppServer, "acceptedTermsAndConditions Version= %d", acceptedTermsAndConditions.Value().version);
}

response.errorCode = CheckTermsAndConditionsAcknowledgementsState(requiredTermsAndConditions, acceptedTermsAndConditions);
if (CommissioningErrorEnum::kOk != response.errorCode)
{
commandObj->AddResponse(commandPath, response);
return true;
}
#endif

if (failSafe.NocCommandHasBeenInvoked())
Expand Down
21 changes: 16 additions & 5 deletions src/app/server/DefaultTermsAndConditionsProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::Init(chip::PersistentSt

CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::RevertAcceptance()
{
ChipLogProgress(AppServer, "DefaultTermsAndConditionsProvider: RevertAcceptance");
mTemporalAcceptance.SetValue(mLatchedAcceptance.Value());
return CHIP_NO_ERROR;
}
Expand All @@ -77,6 +78,8 @@ CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::CommitAcceptance()

CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::GetAcceptance(Optional<TermsAndConditions> &outTermsAndConditions) const
{
ChipLogProgress(AppServer, "DefaultTermsAndConditionsProvider: GetAcceptance");

if (!mTemporalAcceptance.HasValue())
{
return CHIP_ERROR_INCORRECT_STATE;
Expand All @@ -88,6 +91,8 @@ CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::GetAcceptance(Optional<

CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::GetRequirements(Optional<TermsAndConditions> &outTermsAndConditions) const
{
ChipLogProgress(AppServer, "DefaultTermsAndConditionsProvider: GetRequirements");

if (!mRequiredAcknowledgements.HasValue())
{
return CHIP_ERROR_INCORRECT_STATE;
Expand All @@ -99,6 +104,7 @@ CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::GetRequirements(Optiona

CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::ResetAcceptance()
{
ChipLogProgress(AppServer, "DefaultTermsAndConditionsProvider: ResetAcceptance");
VerifyOrReturnError(nullptr != mPersistentStorageDelegate, CHIP_ERROR_UNINITIALIZED);

const chip::StorageKeyName storageKey = DefaultStorageKeyAllocator::TermsAndConditionsAcceptance();
Expand All @@ -112,6 +118,7 @@ CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::ResetAcceptance()

CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::SetAcceptance(const Optional<TermsAndConditions> &inTermsAndConditions)
{
ChipLogProgress(AppServer, "DefaultTermsAndConditionsProvider: SetAcceptance");
mTemporalAcceptance.SetValue(inTermsAndConditions.Value());
return CHIP_NO_ERROR;
}
Expand All @@ -128,17 +135,19 @@ CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::LoadAcceptance(Optional
uint8_t buffer[kEstimatedTlvBufferSize] = { 0 };
uint16_t bufferSize = sizeof(buffer);

ChipLogProgress(AppServer, "DefaultTermsAndConditionsProvider: LoadAcceptance");

VerifyOrReturnError(nullptr != mPersistentStorageDelegate, CHIP_ERROR_UNINITIALIZED);

const chip::StorageKeyName storageKey = DefaultStorageKeyAllocator::TermsAndConditionsAcceptance();
CHIP_ERROR err = mPersistentStorageDelegate->SyncGetKeyValue(storageKey.KeyName(), &buffer, bufferSize);
if (CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND == err)
{
outTermsAndConditions.SetValue({
.value = acknowledgements,
.version = acknowledgementsVersion,
});
return CHIP_NO_ERROR;
// outTermsAndConditions.SetValue({
// .value = acknowledgements,
// .version = acknowledgementsVersion,
// });
return CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND;
}

VerifyOrReturnError(CHIP_NO_ERROR == err, err);
Expand Down Expand Up @@ -173,6 +182,8 @@ CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::StoreAcceptance(const O
chip::TLV::TLVWriter tlvWriter;
chip::TLV::TLVType tlvContainer;

ChipLogProgress(AppServer, "DefaultTermsAndConditionsProvider: StoreAcceptance");

VerifyOrReturnError(nullptr != mPersistentStorageDelegate, CHIP_ERROR_UNINITIALIZED);
VerifyOrReturnError(inTermsAndConditions.HasValue(), CHIP_ERROR_INCORRECT_STATE);

Expand Down
3 changes: 3 additions & 0 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3207,6 +3207,7 @@ void DeviceCommissioner::PerformCommissioningStep(DeviceProxy * proxy, Commissio

if (!params.GetRequireTermsAndConditionsAcknowledgement())
{
ChipLogProgress(Controller, "Setting Terms and Conditions: Skipped");
CommissioningStageComplete(CHIP_NO_ERROR);
return;
}
Expand All @@ -3222,6 +3223,8 @@ void DeviceCommissioner::PerformCommissioningStep(DeviceProxy * proxy, Commissio
TermsAndConditionsAcknowledgement termsAndConditionsAcknowledgement = params.GetTermsAndConditionsAcknowledgement().Value();
request.TCUserResponse = termsAndConditionsAcknowledgement.acceptedTermsAndConditions;
request.TCVersion = termsAndConditionsAcknowledgement.acceptedTermsAndConditionsVersion;

ChipLogProgress(Controller, "Setting Terms and Conditions: %hu, %hu", request.TCUserResponse, request.TCVersion);
CHIP_ERROR err =
SendCommissioningCommand(proxy, request, OnSetTCAcknowledgementsResponse, OnBasicFailure, endpoint, timeout);
if (err != CHIP_NO_ERROR)
Expand Down
Loading

0 comments on commit dbccc78

Please sign in to comment.