From 8f3995e52bd3fbe09ba036c0d632e43a73993e87 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Thu, 19 Dec 2024 13:01:16 +0100 Subject: [PATCH] [Examples/platform/linux] Set default TermsAndConditions if requested from the command line --- examples/platform/linux/AppMain.cpp | 14 ++++++++++++++ examples/platform/linux/Options.cpp | 28 ++++++++++++++++++++++++++++ examples/platform/linux/Options.h | 5 +++++ 3 files changed, 47 insertions(+) diff --git a/examples/platform/linux/AppMain.cpp b/examples/platform/linux/AppMain.cpp index c35e3e7db141ca..baf0ed6cf62eac 100644 --- a/examples/platform/linux/AppMain.cpp +++ b/examples/platform/linux/AppMain.cpp @@ -108,6 +108,10 @@ #include "ExampleAccessRestrictionProvider.h" #endif +#if CHIP_CONFIG_TERMS_AND_CONDITIONS_REQUIRED +#include // nogncheck +#endif + #if CHIP_DEVICE_LAYER_TARGET_DARWIN #include #if CHIP_DEVICE_CONFIG_ENABLE_WIFI @@ -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 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(); diff --git a/examples/platform/linux/Options.cpp b/examples/platform/linux/Options.cpp index e3b7ba42675f41..fa56b62feac4c1 100644 --- a/examples/platform/linux/Options.cpp +++ b/examples/platform/linux/Options.cpp @@ -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; @@ -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 {} }; @@ -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 \n" " Inject specified fault(s) at runtime.\n" @@ -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(atoi(aValue))); + break; + } + + case kDeviceOption_TermsAndConditions_Required: { + LinuxDeviceOptions::GetInstance().tcRequired.SetValue(static_cast(atoi(aValue))); + break; + } +#endif default: PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", aProgram, aName); retval = false; diff --git a/examples/platform/linux/Options.h b/examples/platform/linux/Options.h index d9b1716bd39e95..6cad0469e02270 100644 --- a/examples/platform/linux/Options.h +++ b/examples/platform/linux/Options.h @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -91,6 +92,10 @@ struct LinuxDeviceOptions #if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS chip::Optional> commissioningArlEntries; chip::Optional> arlEntries; +#endif +#if CHIP_CONFIG_TERMS_AND_CONDITIONS_REQUIRED + chip::Optional tcVersion; + chip::Optional tcRequired; #endif static LinuxDeviceOptions & GetInstance(); };