Skip to content

Commit 6724d74

Browse files
committed
[Examples/platform/linux] Set default TermsAndConditions if requested from the command line
1 parent a9e80ef commit 6724d74

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

examples/platform/linux/AppMain.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@
111111
#include "ExampleAccessRestrictionProvider.h"
112112
#endif
113113

114+
#if CHIP_CONFIG_TERMS_AND_CONDITIONS_REQUIRED
115+
#include <app/server/TermsAndConditionsManager.h> // nogncheck
116+
#endif
117+
114118
#if CHIP_DEVICE_LAYER_TARGET_DARWIN
115119
#include <platform/Darwin/NetworkCommissioningDriver.h>
116120
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
@@ -542,6 +546,16 @@ void ChipLinuxAppMainLoop(AppMainLoopImplementation * impl)
542546
VerifyOrDie(initParams.InitializeStaticResourcesBeforeServerInit() == CHIP_NO_ERROR);
543547
initParams.dataModelProvider = app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate);
544548

549+
#if CHIP_CONFIG_TERMS_AND_CONDITIONS_REQUIRED
550+
if (LinuxDeviceOptions::GetInstance().tcVersion.HasValue() && LinuxDeviceOptions::GetInstance().tcRequired.HasValue())
551+
{
552+
uint16_t version = LinuxDeviceOptions::GetInstance().tcVersion.Value();
553+
uint16_t required = LinuxDeviceOptions::GetInstance().tcRequired.Value();
554+
Optional<app::TermsAndConditions> requiredAcknowledgements(app::TermsAndConditions(required, version));
555+
app::TermsAndConditionsManager::GetInstance()->Init(initParams.persistentStorageDelegate, requiredAcknowledgements);
556+
}
557+
#endif // CHIP_CONFIG_TERMS_AND_CONDITIONS_REQUIRED
558+
545559
#if defined(ENABLE_CHIP_SHELL)
546560
Engine::Root().Init();
547561
Shell::RegisterCommissioneeCommands();

examples/platform/linux/Options.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ enum
128128
kDeviceOption_WiFi_PAF,
129129
#endif
130130
kDeviceOption_DacProvider,
131+
#if CHIP_CONFIG_TERMS_AND_CONDITIONS_REQUIRED
132+
kDeviceOption_TermsAndConditions_Version,
133+
kDeviceOption_TermsAndConditions_Required,
134+
#endif
131135
};
132136

133137
constexpr unsigned kAppUsageLength = 64;
@@ -204,6 +208,10 @@ OptionDef sDeviceOptionDefs[] = {
204208
{ "faults", kArgumentRequired, kDeviceOption_FaultInjection },
205209
#endif
206210
{ "dac_provider", kArgumentRequired, kDeviceOption_DacProvider },
211+
#if CHIP_CONFIG_TERMS_AND_CONDITIONS_REQUIRED
212+
{ "tc-version", kArgumentRequired, kDeviceOption_TermsAndConditions_Version },
213+
{ "tc-required", kArgumentRequired, kDeviceOption_TermsAndConditions_Required },
214+
#endif
207215
{}
208216
};
209217

@@ -362,6 +370,15 @@ const char * sDeviceOptionHelp =
362370
" Specifies the time after which the device transitions from active to idle.\n"
363371
"\n"
364372
#endif
373+
#if CHIP_CONFIG_TERMS_AND_CONDITIONS_REQUIRED
374+
" --tc-version\n"
375+
" Sets the minimum required version of the Terms and Conditions\n"
376+
"\n"
377+
" --tc-required\n"
378+
" Sets the required acknowledgements for the Terms and Conditions as a 16-bit enumeration.\n"
379+
" Each bit represents an ordinal corresponding to a specific acknowledgment requirement.\n"
380+
"\n"
381+
#endif
365382
#if CHIP_WITH_NLFAULTINJECTION
366383
" --faults <fault-string,...>\n"
367384
" Inject specified fault(s) at runtime.\n"
@@ -747,6 +764,17 @@ bool HandleOption(const char * aProgram, OptionSet * aOptions, int aIdentifier,
747764
LinuxDeviceOptions::GetInstance().dacProvider = &testDacProvider;
748765
break;
749766
}
767+
#if CHIP_CONFIG_TERMS_AND_CONDITIONS_REQUIRED
768+
case kDeviceOption_TermsAndConditions_Version: {
769+
LinuxDeviceOptions::GetInstance().tcVersion.SetValue(static_cast<uint16_t>(atoi(aValue)));
770+
break;
771+
}
772+
773+
case kDeviceOption_TermsAndConditions_Required: {
774+
LinuxDeviceOptions::GetInstance().tcRequired.SetValue(static_cast<uint16_t>(atoi(aValue)));
775+
break;
776+
}
777+
#endif
750778
default:
751779
PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", aProgram, aName);
752780
retval = false;

examples/platform/linux/Options.h

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <vector>
3030

3131
#include <access/AccessConfig.h>
32+
#include <app/AppConfig.h>
3233
#include <inet/InetInterface.h>
3334
#include <lib/core/CHIPError.h>
3435
#include <lib/core/Optional.h>
@@ -91,6 +92,10 @@ struct LinuxDeviceOptions
9192
#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
9293
chip::Optional<std::vector<chip::Access::AccessRestrictionProvider::Entry>> commissioningArlEntries;
9394
chip::Optional<std::vector<chip::Access::AccessRestrictionProvider::Entry>> arlEntries;
95+
#endif
96+
#if CHIP_CONFIG_TERMS_AND_CONDITIONS_REQUIRED
97+
chip::Optional<uint16_t> tcVersion;
98+
chip::Optional<uint16_t> tcRequired;
9499
#endif
95100
static LinuxDeviceOptions & GetInstance();
96101
};

0 commit comments

Comments
 (0)