Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
swan-amazon committed Jun 11, 2024
1 parent 1d9494f commit fdb5d34
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"cwd": "/workspace/connectedhomeip/out/unified",
"env": {},
"stdio": [null, null, null],
"terminal": "console",
"terminal": "integrated",
"stopOnEntry": false
},
{
Expand Down
7 changes: 7 additions & 0 deletions src/app/server/DefaultEnhancedSetupFlowProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ CHIP_ERROR chip::app::DefaultEnhancedSetupFlowProvider::Init(TermsAndConditionsP
VerifyOrReturnError(nullptr != inTermsAndConditionsProvider, CHIP_ERROR_INVALID_ARGUMENT);

mTermsAndConditionsProvider = inTermsAndConditionsProvider;

return CHIP_NO_ERROR;
}

Expand All @@ -43,6 +44,7 @@ chip::app::DefaultEnhancedSetupFlowProvider::HasTermsAndConditionsRequiredAcknow
ReturnErrorOnFailure(mTermsAndConditionsProvider->GetAcceptance(acceptedAcknowledgements, acceptedAcknowledgementsVersion));

outAccepted = ((requiredAcknowledgements & acceptedAcknowledgements) == requiredAcknowledgements);

return CHIP_NO_ERROR;
}

Expand All @@ -59,6 +61,7 @@ CHIP_ERROR chip::app::DefaultEnhancedSetupFlowProvider::HasTermsAndConditionsReq
ReturnErrorOnFailure(mTermsAndConditionsProvider->GetAcceptance(acceptedAcknowledgements, acceptedAcknowledgementsVersion));

outAccepted = (acceptedAcknowledgementsVersion >= requiredAcknowledgementsVersion);

return CHIP_NO_ERROR;
}

Expand All @@ -71,6 +74,7 @@ CHIP_ERROR chip::app::DefaultEnhancedSetupFlowProvider::GetTermsAndConditionsReq
ReturnErrorOnFailure(mTermsAndConditionsProvider->GetRequirements(requiredAcknowledgements, requiredAcknowledgementsVersion));

outValue = requiredAcknowledgements;

return CHIP_NO_ERROR;
}

Expand All @@ -84,6 +88,7 @@ chip::app::DefaultEnhancedSetupFlowProvider::GetTermsAndConditionsRequiredAcknow
ReturnErrorOnFailure(mTermsAndConditionsProvider->GetRequirements(requiredAcknowledgements, requiredAcknowledgementsVersion));

outValue = requiredAcknowledgementsVersion;

return CHIP_NO_ERROR;
}

Expand All @@ -96,6 +101,7 @@ CHIP_ERROR chip::app::DefaultEnhancedSetupFlowProvider::GetTermsAndConditionsAcc
ReturnErrorOnFailure(mTermsAndConditionsProvider->GetAcceptance(acceptedAcknowledgements, acceptedAcknowledgementsVersion));

outValue = acceptedAcknowledgements;

return CHIP_NO_ERROR;
}

Expand All @@ -109,6 +115,7 @@ chip::app::DefaultEnhancedSetupFlowProvider::GetTermsAndConditionsAcceptedAcknow
ReturnErrorOnFailure(mTermsAndConditionsProvider->GetAcceptance(acceptedAcknowledgements, acceptedAcknowledgementsVersion));

outValue = acceptedAcknowledgementsVersion;

return CHIP_NO_ERROR;
}

Expand Down
25 changes: 14 additions & 11 deletions src/app/server/DefaultTermsAndConditionsProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ chip::app::DefaultTermsAndConditionsProvider::Init(chip::PersistentStorageDelega
VerifyOrReturnError(nullptr != inPersistentStorageDelegate, CHIP_ERROR_INVALID_ARGUMENT);

mPersistentStorageDelegate = inPersistentStorageDelegate;

return CHIP_NO_ERROR;
}

Expand All @@ -63,11 +64,11 @@ CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::GetAcceptance(uint16_t
uint16_t bufferSize = sizeof(buffer);
chip::TLV::TLVReader reader;

chip::StorageKeyName acknowledgementsVersionStorageKeyName = DefaultStorageKeyAllocator::TermsAndConditionsAcceptance(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION);
const char * acknowledgementsVersionKey = acknowledgementsVersionStorageKeyName.KeyName();

VerifyOrReturnError(nullptr != mPersistentStorageDelegate, CHIP_ERROR_UNINITIALIZED);
ReturnErrorOnFailure(mPersistentStorageDelegate->SyncGetKeyValue(acknowledgementsVersionKey, &buffer, bufferSize));

const chip::StorageKeyName storageKey =
DefaultStorageKeyAllocator::TermsAndConditionsAcceptance(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION);
ReturnErrorOnFailure(mPersistentStorageDelegate->SyncGetKeyValue(storageKey.KeyName(), &buffer, bufferSize));

reader.Init(buffer);
err = reader.Next(chip::TLV::kTLVType_Structure, chip::TLV::AnonymousTag());
Expand Down Expand Up @@ -101,6 +102,7 @@ CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::GetRequirements(uint16_
{
outAcknowledgementsValue = CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS;
outAcknowledgementsVersionValue = CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION;

return CHIP_NO_ERROR;
}

Expand All @@ -120,19 +122,20 @@ CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::SetAcceptance(uint16_t
ReturnErrorOnFailure(tlvWriter.EndContainer(containerType));
ReturnErrorOnFailure(tlvWriter.Finalize());

chip::StorageKeyName acknowledgementsVersionStorageKeyName = DefaultStorageKeyAllocator::TermsAndConditionsAcceptance(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION);
const char * acknowledgementsVersionKey = acknowledgementsVersionStorageKeyName.KeyName();
ReturnErrorOnFailure(mPersistentStorageDelegate->SyncSetKeyValue(acknowledgementsVersionKey, buffer, sizeof(buffer)));
const chip::StorageKeyName storageKey =
DefaultStorageKeyAllocator::TermsAndConditionsAcceptance(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION);
ReturnErrorOnFailure(mPersistentStorageDelegate->SyncSetKeyValue(storageKey.KeyName(), buffer, sizeof(buffer)));

return CHIP_NO_ERROR;
}

CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::ClearAcceptance()
{
chip::StorageKeyName acknowledgementsVersionStorageKeyName = DefaultStorageKeyAllocator::TermsAndConditionsAcceptance(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION);
const char * acknowledgementsVersionKey = acknowledgementsVersionStorageKeyName.KeyName();

VerifyOrReturnError(nullptr != mPersistentStorageDelegate, CHIP_ERROR_UNINITIALIZED);
ReturnErrorOnFailure(mPersistentStorageDelegate->SyncDeleteKeyValue(acknowledgementsVersionKey));

const chip::StorageKeyName storageKey =
DefaultStorageKeyAllocator::TermsAndConditionsAcceptance(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION);
ReturnErrorOnFailure(mPersistentStorageDelegate->SyncDeleteKeyValue(storageKey.KeyName()));

return CHIP_NO_ERROR;
}

0 comments on commit fdb5d34

Please sign in to comment.