Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
swan-amazon committed Aug 27, 2024
1 parent ebfbe6e commit 2396da5
Show file tree
Hide file tree
Showing 14 changed files with 174 additions and 468 deletions.
13 changes: 8 additions & 5 deletions src/app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ declare_args() {
config("enhanced_setup_flow_config") {
defines = []
if (chip_config_tc_required) {
defines += [
"CHIP_CONFIG_TC_REQUIRED=1",
"CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS=${chip_config_tc_required_acknowledgements}",
"CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION=${chip_config_tc_required_acknowledgements_version}",
]
defines += [ "CHIP_CONFIG_TC_REQUIRED=1" ]
} else {
defines += [ "CHIP_CONFIG_TC_REQUIRED=0" ]
}
Expand All @@ -93,6 +89,13 @@ buildconfig_header("app_buildconfig") {
"CHIP_CONFIG_ENABLE_BUSY_HANDLING_FOR_OPERATIONAL_SESSION_SETUP=${chip_enable_busy_handling_for_operational_session_setup}",
]

if (chip_config_tc_required) {
defines += [
"CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS=${chip_config_tc_required_acknowledgements}",
"CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION=${chip_config_tc_required_acknowledgements_version}",
]
}

if (chip_use_data_model_interface == "disabled") {
defines += [
"CHIP_CONFIG_USE_DATA_MODEL_INTERFACE=0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,6 @@ bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback(
else
{
#if CHIP_CONFIG_TC_REQUIRED
// CheckSuccess(CheckTermsAndConditionsAcknowledgementsStateOnCommissioningComplete(response.errorCode), Failure);

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

Optional<TermsAndConditions> acceptedTermsAndConditions;
Expand Down
11 changes: 7 additions & 4 deletions src/app/server/DefaultEnhancedSetupFlowProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
CHIP_ERROR chip::app::DefaultEnhancedSetupFlowProvider::Init(TermsAndConditionsProvider * const inTermsAndConditionsProvider)
{
VerifyOrReturnError(nullptr != inTermsAndConditionsProvider, CHIP_ERROR_INVALID_ARGUMENT);

mTermsAndConditionsProvider = inTermsAndConditionsProvider;

return CHIP_NO_ERROR;
}

Expand Down Expand Up @@ -55,18 +53,23 @@ CHIP_ERROR chip::app::DefaultEnhancedSetupFlowProvider::SetTermsAndConditionsAcc
return CHIP_NO_ERROR;
}

CHIP_ERROR chip::app::DefaultEnhancedSetupFlowProvider::ResetTermsAndConditionsAcceptance()
{
VerifyOrReturnError(nullptr != mTermsAndConditionsProvider, CHIP_ERROR_UNINITIALIZED);
ReturnErrorOnFailure(mTermsAndConditionsProvider->ResetAcceptance());
return CHIP_NO_ERROR;
}

CHIP_ERROR chip::app::DefaultEnhancedSetupFlowProvider::RevertTermsAndConditionsAcceptance()
{
VerifyOrReturnError(nullptr != mTermsAndConditionsProvider, CHIP_ERROR_UNINITIALIZED);
ReturnErrorOnFailure(mTermsAndConditionsProvider->RevertAcceptance());

return CHIP_NO_ERROR;
}

CHIP_ERROR chip::app::DefaultEnhancedSetupFlowProvider::CommitTermsAndConditionsAcceptance()
{
VerifyOrReturnError(nullptr != mTermsAndConditionsProvider, CHIP_ERROR_UNINITIALIZED);
ReturnErrorOnFailure(mTermsAndConditionsProvider->CommitAcceptance());

return CHIP_NO_ERROR;
}
2 changes: 2 additions & 0 deletions src/app/server/DefaultEnhancedSetupFlowProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class DefaultEnhancedSetupFlowProvider : public EnhancedSetupFlowProvider

virtual CHIP_ERROR SetTermsAndConditionsAcceptance(const Optional<TermsAndConditions> & inTermsAndConditions) override;

virtual CHIP_ERROR ResetTermsAndConditionsAcceptance() override;

virtual CHIP_ERROR RevertTermsAndConditionsAcceptance() override;

virtual CHIP_ERROR CommitTermsAndConditionsAcceptance() override;
Expand Down
57 changes: 38 additions & 19 deletions src/app/server/DefaultTermsAndConditionsProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,37 @@
#include <lib/support/DefaultStorageKeyAllocator.h>
#include <lib/support/SafeInt.h>

#if 0
/**
* @def CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS
*
* @brief Configures the required terms and conditions acknowledgements bitmask.
*
* This macro defines the required terms and conditions acknowledgements bitmask. The bit-field is 16 bits long, so the possible
* value range is [0, 65535). This setting can be used to require that terms and conditions are presented to the user during
* commissioning.
*/
#ifndef CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS
#error "CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS must be defined when CHIP_CONFIG_TC_REQUIRED is enabled."
#endif

/**
* @def CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION
*
* @brief Configures the latest known version of the terms and conditions.
*
* This macro defines the version number of the latest terms and conditions. It allows the application to iterate on revisions of
* the terms and conditions. A value of 0 indicates that no specific version is required. This setting can be used to enforce
* version-specific terms and conditions acknowledgements in the application. When the set of terms and conditions needs to be
* changed, the version number should be monotonically increased. If the latest terms and conditions version is updated (most
* likely during an OTA), then this may signal to the Administrator that updated terms and conditions should be presented to the
* user.
*/
#ifndef CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION
#error "CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION must be defined when CHIP_CONFIG_TC_REQUIRED is enabled."
#endif
#endif // 0

namespace {
constexpr chip::TLV::Tag kSerializationVersionTag = chip::TLV::ContextTag(1);
constexpr chip::TLV::Tag kAcceptedAcknowledgementsTag = chip::TLV::ContextTag(2);
Expand All @@ -39,16 +70,14 @@ constexpr size_t kEstimatedTlvBufferSize = chip::TLV::EstimateStructOverhead(siz
2; // Extra space for rollback compatibility
} // namespace

CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::Init(chip::PersistentStorageDelegate * const inPersistentStorageDelegate)
CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::Init(
chip::PersistentStorageDelegate * const inPersistentStorageDelegate,
const chip::Optional<chip::app::TermsAndConditions> & inRequiredTermsAndConditions)
{
VerifyOrReturnError(nullptr != inPersistentStorageDelegate, CHIP_ERROR_INVALID_ARGUMENT);

mPersistentStorageDelegate = inPersistentStorageDelegate;

mRequiredAcknowledgements = Optional<TermsAndConditions>({
.value = CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS,
.version = CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION,
});
mRequiredAcknowledgements = inRequiredTermsAndConditions;

if (CHIP_NO_ERROR == LoadAcceptance(mLatchedAcceptance))
{
Expand All @@ -60,7 +89,7 @@ CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::Init(chip::PersistentSt

CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::RevertAcceptance()
{
mTemporalAcceptance.SetValue(mLatchedAcceptance.Value());
mTemporalAcceptance = mLatchedAcceptance;
return CHIP_NO_ERROR;
}

Expand All @@ -77,23 +106,13 @@ CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::CommitAcceptance()

CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::GetAcceptance(Optional<TermsAndConditions> & outTermsAndConditions) const
{
if (!mTemporalAcceptance.HasValue())
{
return CHIP_ERROR_INCORRECT_STATE;
}

outTermsAndConditions.SetValue(mTemporalAcceptance.Value());
outTermsAndConditions = mTemporalAcceptance;
return CHIP_NO_ERROR;
}

CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::GetRequirements(Optional<TermsAndConditions> & outTermsAndConditions) const
{
if (!mRequiredAcknowledgements.HasValue())
{
return CHIP_ERROR_INCORRECT_STATE;
}

outTermsAndConditions.SetValue(mRequiredAcknowledgements.Value());
outTermsAndConditions = mRequiredAcknowledgements;
return CHIP_NO_ERROR;
}

Expand Down
3 changes: 2 additions & 1 deletion src/app/server/DefaultTermsAndConditionsProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class DefaultTermsAndConditionsProvider : public TermsAndConditionsProvider
*
* @param[in] inPersistentStorageDelegate Persistent storage delegate dependency.
*/
CHIP_ERROR Init(PersistentStorageDelegate * const inPersistentStorageDelegate);
CHIP_ERROR Init(PersistentStorageDelegate * const inPersistentStorageDelegate,
const chip::Optional<chip::app::TermsAndConditions> & inRequiredTermsAndConditions);

CHIP_ERROR SetAcceptance(const Optional<TermsAndConditions> & inTermsAndConditions) override;

Expand Down
2 changes: 2 additions & 0 deletions src/app/server/EnhancedSetupFlowProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class EnhancedSetupFlowProvider

virtual CHIP_ERROR SetTermsAndConditionsAcceptance(const Optional<TermsAndConditions> & inTermsAndConditions) = 0;

virtual CHIP_ERROR ResetTermsAndConditionsAcceptance() = 0;

virtual CHIP_ERROR RevertTermsAndConditionsAcceptance() = 0;

virtual CHIP_ERROR CommitTermsAndConditionsAcceptance() = 0;
Expand Down
3 changes: 1 addition & 2 deletions src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,7 @@ void Server::ScheduleFactoryReset()
PlatformMgr().HandleServerShuttingDown();
ConfigurationMgr().InitiateFactoryReset();
#if CHIP_CONFIG_TC_REQUIRED
// Clear accepted terms and conditions
GetInstance().GetEnhancedSetupFlowProvider()->RevertTermsAndConditionsAcceptance();
GetInstance().GetEnhancedSetupFlowProvider()->ResetTermsAndConditionsAcceptance();
#endif
});
}
Expand Down
9 changes: 8 additions & 1 deletion src/app/server/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,16 @@ struct CommonCaseDeviceServerInitParams : public ServerInitParams
#if CHIP_CONFIG_TC_REQUIRED
static app::DefaultEnhancedSetupFlowProvider sDefaultEnhancedSetupFlowProviderInstance;
static app::DefaultTermsAndConditionsProvider sDefaultTermsAndConditionsProviderInstance;

if (this->termsAndConditionsProvider == nullptr)
{
ReturnErrorOnFailure(sDefaultTermsAndConditionsProviderInstance.Init(this->persistentStorageDelegate));
Optional<app::TermsAndConditions> termsAndConditions = Optional<app::TermsAndConditions>({
.value = CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS,
.version = CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION,
});

ReturnErrorOnFailure(
sDefaultTermsAndConditionsProviderInstance.Init(this->persistentStorageDelegate, termsAndConditions));
this->termsAndConditionsProvider = &sDefaultTermsAndConditionsProviderInstance;
}

Expand Down
1 change: 0 additions & 1 deletion src/app/server/TermsAndConditionsProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include <stdint.h>

#include <lib/core/CHIPConfig.h>
#include <lib/core/CHIPError.h>
#include <lib/core/Optional.h>

Expand Down
1 change: 0 additions & 1 deletion src/app/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ chip_test_suite("tests") {
"TestCommandPathParams.cpp",
"TestConcreteAttributePath.cpp",
"TestDataModelSerialization.cpp",
"TestDefaultEnhancedSetupFlowProvider.cpp",
"TestDefaultOTARequestorStorage.cpp",
"TestDefaultTermsAndConditionsProvider.cpp",
"TestDefaultThreadNetworkDirectoryStorage.cpp",
Expand Down
Loading

0 comments on commit 2396da5

Please sign in to comment.