Skip to content

Commit 3e66324

Browse files
committed
Init experiment
1 parent 20d1d66 commit 3e66324

File tree

18 files changed

+192
-23
lines changed

18 files changed

+192
-23
lines changed

doc/admx/DesktopAppInstaller.admx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@
4343
<decimal value="0" />
4444
</disabledValue>
4545
</policy>
46+
<policy name="EnableExperiments" class="Machine" displayName="$(string.EnableExperiments)" explainText="$(string.EnableExperimentsExplanation)" key="Software\Policies\Microsoft\Windows\AppInstaller" valueName="EnableExperiments">
47+
<parentCategory ref="AppInstaller" />
48+
<supportedOn ref="windows:SUPPORTED_Windows_10_0_RS5" />
49+
<enabledValue>
50+
<decimal value="1" />
51+
</enabledValue>
52+
<disabledValue>
53+
<decimal value="0" />
54+
</disabledValue>
55+
</policy>
4656
<policy name="EnableLocalManifestFiles" class="Machine" displayName="$(string.EnableLocalManifestFiles)" explainText="$(string.EnableLocalManifestFilesExplanation)" key="Software\Policies\Microsoft\Windows\AppInstaller" valueName="EnableLocalManifestFiles">
4757
<parentCategory ref="AppInstaller" />
4858
<supportedOn ref="windows:SUPPORTED_Windows_10_0_RS5" />

doc/admx/en-US/DesktopAppInstaller.adml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ If you disable this setting, users will not be able to change settings for the W
2525
If you enable or do not configure this setting, users will be able to enable experimental features for the Windows Package Manager.
2626

2727
If you disable this setting, users will not be able to enable experimental features for the Windows Package Manager.</string>
28+
<string id="EnableExperiments">Enable Windows Package Manager Experiments</string>
29+
<string id="EnableExperimentsExplanation">This policy controls whether users can enable experiments in the Windows Package Manager.
30+
31+
If you enable or do not configure this setting, users will be able to enable experiments for the Windows Package Manager.
32+
33+
If you disable this setting, users will not be able to enable experiments for the Windows Package Manager.</string>
2834
<string id="EnableLocalManifestFiles">Enable Windows Package Manager Local Manifest Files</string>
2935
<string id="EnableLocalManifestFilesExplanation">This policy controls whether users can install packages with local manifest files.
3036

src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,9 @@ They can be configured through the settings file 'winget settings'.</value>
897897
<data name="PolicyEnableExperimentalFeatures" xml:space="preserve">
898898
<value>Enable Windows App Installer Experimental Features</value>
899899
</data>
900+
<data name="PolicyEnableExperiments" xml:space="preserve">
901+
<value>Enable Windows App Installer Experiments</value>
902+
</data>
900903
<data name="PolicyEnableMSStoreSource" xml:space="preserve">
901904
<value>Enable Windows App Installer Microsoft Store Source</value>
902905
</data>

src/AppInstallerCommonCore/AppInstallerCommonCore.vcxproj

Lines changed: 18 additions & 13 deletions
Large diffs are not rendered by default.

src/AppInstallerCommonCore/AppInstallerCommonCore.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@
207207
<ClInclude Include="Public\winget\Fonts.h">
208208
<Filter>Public\winget</Filter>
209209
</ClInclude>
210+
<ClInclude Include="Public\winget\Experiment.h">
211+
<Filter>Public\winget</Filter>
212+
</ClInclude>
210213
</ItemGroup>
211214
<ItemGroup>
212215
<ClCompile Include="pch.cpp">
@@ -374,6 +377,9 @@
374377
<ClCompile Include="Fonts.cpp">
375378
<Filter>Source Files</Filter>
376379
</ClCompile>
380+
<ClCompile Include="Experiment.cpp">
381+
<Filter>Source Files</Filter>
382+
</ClCompile>
377383
</ItemGroup>
378384
<ItemGroup>
379385
<None Include="PropertySheet.props" />
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
// Copyright (c) Microsoft Corporation.
3+
// Licensed under the MIT License.
4+
#include "pch.h"
5+
#include "winget/Experiment.h"
6+
#include "winget/UserSettings.h"
7+
#include "Experiment/Experiment.h"
8+
9+
namespace AppInstaller::Settings
10+
{
11+
namespace
12+
{
13+
bool IsEnabledInternal(Experiment::Key key, const UserSettings& userSettings)
14+
{
15+
if (key == Experiment::Key::None)
16+
{
17+
return true;
18+
}
19+
20+
if (!GroupPolicies().IsEnabled(TogglePolicy::Policy::Experiments))
21+
{
22+
AICLI_LOG(Core, Info, <<
23+
"Experiments '" << Experiment::GetExperiment(key).Name() <<
24+
"' is disabled due to group policy: " << TogglePolicy::GetPolicy(TogglePolicy::Policy::Experiments).RegValueName());
25+
return false;
26+
}
27+
28+
auto experiments = userSettings.Get<Setting::Experiments>();
29+
auto experiment = Experiment::GetExperiment(key);
30+
auto jsonName = std::string(experiment.JsonName());
31+
if (experiments.find(jsonName) != experiments.end())
32+
{
33+
return experiments[jsonName];
34+
}
35+
36+
return AppInstaller::Experiment::IsEnabled(experiment.GetKey());
37+
}
38+
}
39+
40+
bool Experiment::IsEnabled(Key key)
41+
{
42+
return IsEnabledInternal(key, User());
43+
}
44+
45+
Experiment Experiment::GetExperiment(Key key)
46+
{
47+
switch (key)
48+
{
49+
case Key::CDN:
50+
return Experiment{ "CDN experiment", "CDN", "https://aka.ms/winget-settings", "CDN"};
51+
52+
default:
53+
THROW_HR(E_UNEXPECTED);
54+
}
55+
}
56+
57+
std::vector<Experiment> Experiment::GetAllExperiments()
58+
{
59+
std::vector<Experiment> result;
60+
61+
for (Key_t i = 0x1; i < static_cast<Key_t>(Key::Max); i = i << 1)
62+
{
63+
result.emplace_back(GetExperiment(static_cast<Key>(i)));
64+
}
65+
66+
return result;
67+
}
68+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
#pragma once
4+
#include <string>
5+
#include <type_traits>
6+
#include "AppInstallerStrings.h"
7+
8+
namespace AppInstaller::Settings
9+
{
10+
struct Experiment
11+
{
12+
enum class Key : unsigned
13+
{
14+
None = 0x0,
15+
CDN = 0x1,
16+
Max,
17+
};
18+
19+
using Key_t = std::underlying_type_t<Key>;
20+
21+
Experiment(std::string_view name, std::string_view jsonName, std::string_view link, std::string key) :
22+
m_name(name), m_jsonName(jsonName), m_link(link), m_key(key) {}
23+
24+
static bool IsEnabled(Key feature);
25+
26+
static Experiment GetExperiment(Experiment::Key key);
27+
static std::vector<Experiment> GetAllExperiments();
28+
29+
std::string_view Name() const { return m_name; }
30+
Utility::LocIndView JsonName() const { return m_jsonName; }
31+
std::string_view Link() const { return m_link; }
32+
std::string GetKey() const { return m_key; }
33+
34+
private:
35+
std::string_view m_name;
36+
Utility::LocIndView m_jsonName;
37+
std::string_view m_link;
38+
std::string m_key;
39+
};
40+
}

src/AppInstallerCommonCore/Public/winget/UserSettings.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ namespace AppInstaller::Settings
110110
DownloadDefaultDirectory,
111111
// Interactivity
112112
InteractivityDisable,
113+
// Experiments
114+
Experiments,
113115
#ifndef AICLI_DISABLE_TEST_HOOKS
114116
// Debug
115117
EnableSelfInitiatedMinidump,
@@ -200,7 +202,11 @@ namespace AppInstaller::Settings
200202
SETTINGMAPPING_SPECIALIZATION(Setting::LoggingChannelPreference, std::vector<std::string>, Logging::Channel, Logging::Channel::Defaults, ".logging.channels"sv);
201203
// Interactivity
202204
SETTINGMAPPING_SPECIALIZATION(Setting::InteractivityDisable, bool, bool, false, ".interactivity.disable"sv);
203-
205+
206+
// Experiments
207+
using Experiments_t = std::map<std::string, bool>;
208+
SETTINGMAPPING_SPECIALIZATION(Setting::Experiments, std::string, Experiments_t, {}, ".experiments"sv);
209+
204210
// Used to deduce the SettingVariant type; making a variant that includes std::monostate and all SettingMapping types.
205211
template <size_t... I>
206212
inline auto Deduce(std::index_sequence<I...>) { return std::variant<std::monostate, typename SettingMapping<static_cast<Setting>(I)>::value_t...>{}; }

src/AppInstallerSharedLib/GroupPolicy.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ namespace AppInstaller::Settings
326326
return TogglePolicy(policy, "EnableWindowsPackageManagerConfiguration"sv, String::PolicyEnableWinGetConfiguration);
327327
case TogglePolicy::Policy::ProxyCommandLineOptions:
328328
return TogglePolicy(policy, "EnableWindowsPackageManagerProxyCommandLineOptions"sv, String::PolicyEnableProxyCommandLineOptions);
329+
case TogglePolicy::Policy::Experiments:
330+
return TogglePolicy(policy, "EnableExperiments"sv, String::PolicyEnableExperiments);
329331
default:
330332
THROW_HR(E_UNEXPECTED);
331333
}

src/AppInstallerSharedLib/Public/winget/GroupPolicy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ namespace AppInstaller::Settings
4747
WinGetCommandLineInterfaces,
4848
Configuration,
4949
ProxyCommandLineOptions,
50+
Experiments,
5051
Max,
5152
};
5253

0 commit comments

Comments
 (0)