Skip to content

Commit

Permalink
[Examples/platform/linux] Set default TermsAndConditions if requested…
Browse files Browse the repository at this point in the history
… from the command line
  • Loading branch information
vivien-apple committed Jan 13, 2025
1 parent 2450d5f commit 8f3995e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
14 changes: 14 additions & 0 deletions examples/platform/linux/AppMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@
#include "ExampleAccessRestrictionProvider.h"
#endif

#if CHIP_CONFIG_TERMS_AND_CONDITIONS_REQUIRED
#include <app/server/TermsAndConditionsManager.h> // nogncheck
#endif

#if CHIP_DEVICE_LAYER_TARGET_DARWIN
#include <platform/Darwin/NetworkCommissioningDriver.h>
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
Expand Down Expand Up @@ -539,6 +543,16 @@ void ChipLinuxAppMainLoop(AppMainLoopImplementation * impl)
VerifyOrDie(initParams.InitializeStaticResourcesBeforeServerInit() == CHIP_NO_ERROR);
initParams.dataModelProvider = app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate);

#if CHIP_CONFIG_TERMS_AND_CONDITIONS_REQUIRED
if (LinuxDeviceOptions::GetInstance().tcVersion.HasValue() && LinuxDeviceOptions::GetInstance().tcRequired.HasValue())
{
uint16_t version = LinuxDeviceOptions::GetInstance().tcVersion.Value();
uint16_t required = LinuxDeviceOptions::GetInstance().tcRequired.Value();
Optional<app::TermsAndConditions> requiredAcknowledgements(app::TermsAndConditions(required, version));
app::TermsAndConditionsManager::GetInstance()->Init(initParams.persistentStorageDelegate, requiredAcknowledgements);
}
#endif // CHIP_CONFIG_TERMS_AND_CONDITIONS_REQUIRED

#if defined(ENABLE_CHIP_SHELL)
Engine::Root().Init();
Shell::RegisterCommissioneeCommands();
Expand Down
28 changes: 28 additions & 0 deletions examples/platform/linux/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ enum
kDeviceOption_WiFi_PAF,
#endif
kDeviceOption_DacProvider,
#if CHIP_CONFIG_TERMS_AND_CONDITIONS_REQUIRED
kDeviceOption_TermsAndConditions_Version,
kDeviceOption_TermsAndConditions_Required,
#endif
};

constexpr unsigned kAppUsageLength = 64;
Expand Down Expand Up @@ -204,6 +208,10 @@ OptionDef sDeviceOptionDefs[] = {
{ "faults", kArgumentRequired, kDeviceOption_FaultInjection },
#endif
{ "dac_provider", kArgumentRequired, kDeviceOption_DacProvider },
#if CHIP_CONFIG_TERMS_AND_CONDITIONS_REQUIRED
{ "tc-version", kArgumentRequired, kDeviceOption_TermsAndConditions_Version },
{ "tc-required", kArgumentRequired, kDeviceOption_TermsAndConditions_Required },
#endif
{}
};

Expand Down Expand Up @@ -362,6 +370,15 @@ const char * sDeviceOptionHelp =
" Specifies the time after which the device transitions from active to idle.\n"
"\n"
#endif
#if CHIP_CONFIG_TERMS_AND_CONDITIONS_REQUIRED
" --tc-version\n"
" Sets the minimum required version of the Terms and Conditions\n"
"\n"
" --tc-required\n"
" Sets the required acknowledgements for the Terms and Conditions as a 16-bit enumeration.\n"
" Each bit represents an ordinal corresponding to a specific acknowledgment requirement.\n"
"\n"
#endif
#if CHIP_WITH_NLFAULTINJECTION
" --faults <fault-string,...>\n"
" Inject specified fault(s) at runtime.\n"
Expand Down Expand Up @@ -747,6 +764,17 @@ bool HandleOption(const char * aProgram, OptionSet * aOptions, int aIdentifier,
LinuxDeviceOptions::GetInstance().dacProvider = &testDacProvider;
break;
}
#if CHIP_CONFIG_TERMS_AND_CONDITIONS_REQUIRED
case kDeviceOption_TermsAndConditions_Version: {
LinuxDeviceOptions::GetInstance().tcVersion.SetValue(static_cast<uint16_t>(atoi(aValue)));
break;
}

case kDeviceOption_TermsAndConditions_Required: {
LinuxDeviceOptions::GetInstance().tcRequired.SetValue(static_cast<uint16_t>(atoi(aValue)));
break;
}
#endif
default:
PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", aProgram, aName);
retval = false;
Expand Down
5 changes: 5 additions & 0 deletions examples/platform/linux/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <vector>

#include <access/AccessConfig.h>
#include <app/AppConfig.h>
#include <inet/InetInterface.h>
#include <lib/core/CHIPError.h>
#include <lib/core/Optional.h>
Expand Down Expand Up @@ -91,6 +92,10 @@ struct LinuxDeviceOptions
#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
chip::Optional<std::vector<chip::Access::AccessRestrictionProvider::Entry>> commissioningArlEntries;
chip::Optional<std::vector<chip::Access::AccessRestrictionProvider::Entry>> arlEntries;
#endif
#if CHIP_CONFIG_TERMS_AND_CONDITIONS_REQUIRED
chip::Optional<uint16_t> tcVersion;
chip::Optional<uint16_t> tcRequired;
#endif
static LinuxDeviceOptions & GetInstance();
};
Expand Down

0 comments on commit 8f3995e

Please sign in to comment.