Skip to content

Commit

Permalink
Init experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
AmelBawa-msft committed Nov 14, 2024
1 parent 20d1d66 commit 3e66324
Show file tree
Hide file tree
Showing 18 changed files with 192 additions and 23 deletions.
10 changes: 10 additions & 0 deletions doc/admx/DesktopAppInstaller.admx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@
<decimal value="0" />
</disabledValue>
</policy>
<policy name="EnableExperiments" class="Machine" displayName="$(string.EnableExperiments)" explainText="$(string.EnableExperimentsExplanation)" key="Software\Policies\Microsoft\Windows\AppInstaller" valueName="EnableExperiments">
<parentCategory ref="AppInstaller" />
<supportedOn ref="windows:SUPPORTED_Windows_10_0_RS5" />
<enabledValue>
<decimal value="1" />
</enabledValue>
<disabledValue>
<decimal value="0" />
</disabledValue>
</policy>
<policy name="EnableLocalManifestFiles" class="Machine" displayName="$(string.EnableLocalManifestFiles)" explainText="$(string.EnableLocalManifestFilesExplanation)" key="Software\Policies\Microsoft\Windows\AppInstaller" valueName="EnableLocalManifestFiles">
<parentCategory ref="AppInstaller" />
<supportedOn ref="windows:SUPPORTED_Windows_10_0_RS5" />
Expand Down
6 changes: 6 additions & 0 deletions doc/admx/en-US/DesktopAppInstaller.adml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ If you disable this setting, users will not be able to change settings for the W
If you enable or do not configure this setting, users will be able to enable experimental features for the Windows Package Manager.

If you disable this setting, users will not be able to enable experimental features for the Windows Package Manager.</string>
<string id="EnableExperiments">Enable Windows Package Manager Experiments</string>
<string id="EnableExperimentsExplanation">This policy controls whether users can enable experiments in the Windows Package Manager.

If you enable or do not configure this setting, users will be able to enable experiments for the Windows Package Manager.

If you disable this setting, users will not be able to enable experiments for the Windows Package Manager.</string>
<string id="EnableLocalManifestFiles">Enable Windows Package Manager Local Manifest Files</string>
<string id="EnableLocalManifestFilesExplanation">This policy controls whether users can install packages with local manifest files.

Expand Down
3 changes: 3 additions & 0 deletions src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,9 @@ They can be configured through the settings file 'winget settings'.</value>
<data name="PolicyEnableExperimentalFeatures" xml:space="preserve">
<value>Enable Windows App Installer Experimental Features</value>
</data>
<data name="PolicyEnableExperiments" xml:space="preserve">
<value>Enable Windows App Installer Experiments</value>
</data>
<data name="PolicyEnableMSStoreSource" xml:space="preserve">
<value>Enable Windows App Installer Microsoft Store Source</value>
</data>
Expand Down
31 changes: 18 additions & 13 deletions src/AppInstallerCommonCore/AppInstallerCommonCore.vcxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@
<ClInclude Include="Public\winget\Fonts.h">
<Filter>Public\winget</Filter>
</ClInclude>
<ClInclude Include="Public\winget\Experiment.h">
<Filter>Public\winget</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp">
Expand Down Expand Up @@ -374,6 +377,9 @@
<ClCompile Include="Fonts.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Experiment.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="PropertySheet.props" />
Expand Down
68 changes: 68 additions & 0 deletions src/AppInstallerCommonCore/Experiment.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "pch.h"
#include "winget/Experiment.h"
#include "winget/UserSettings.h"
#include "Experiment/Experiment.h"

namespace AppInstaller::Settings
{
namespace
{
bool IsEnabledInternal(Experiment::Key key, const UserSettings& userSettings)
{
if (key == Experiment::Key::None)
{
return true;
}

if (!GroupPolicies().IsEnabled(TogglePolicy::Policy::Experiments))
{
AICLI_LOG(Core, Info, <<
"Experiments '" << Experiment::GetExperiment(key).Name() <<
"' is disabled due to group policy: " << TogglePolicy::GetPolicy(TogglePolicy::Policy::Experiments).RegValueName());
return false;
}

auto experiments = userSettings.Get<Setting::Experiments>();
auto experiment = Experiment::GetExperiment(key);
auto jsonName = std::string(experiment.JsonName());
if (experiments.find(jsonName) != experiments.end())
{
return experiments[jsonName];
}

return AppInstaller::Experiment::IsEnabled(experiment.GetKey());
}
}

bool Experiment::IsEnabled(Key key)
{
return IsEnabledInternal(key, User());
}

Experiment Experiment::GetExperiment(Key key)
{
switch (key)
{
case Key::CDN:
return Experiment{ "CDN experiment", "CDN", "https://aka.ms/winget-settings", "CDN"};

default:
THROW_HR(E_UNEXPECTED);
}
}

std::vector<Experiment> Experiment::GetAllExperiments()
{
std::vector<Experiment> result;

for (Key_t i = 0x1; i < static_cast<Key_t>(Key::Max); i = i << 1)
{
result.emplace_back(GetExperiment(static_cast<Key>(i)));
}

return result;
}
}
40 changes: 40 additions & 0 deletions src/AppInstallerCommonCore/Public/winget/Experiment.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#pragma once
#include <string>
#include <type_traits>
#include "AppInstallerStrings.h"

namespace AppInstaller::Settings
{
struct Experiment
{
enum class Key : unsigned
{
None = 0x0,
CDN = 0x1,
Max,
};

using Key_t = std::underlying_type_t<Key>;

Experiment(std::string_view name, std::string_view jsonName, std::string_view link, std::string key) :
m_name(name), m_jsonName(jsonName), m_link(link), m_key(key) {}

static bool IsEnabled(Key feature);

static Experiment GetExperiment(Experiment::Key key);
static std::vector<Experiment> GetAllExperiments();

std::string_view Name() const { return m_name; }
Utility::LocIndView JsonName() const { return m_jsonName; }
std::string_view Link() const { return m_link; }
std::string GetKey() const { return m_key; }

private:
std::string_view m_name;
Utility::LocIndView m_jsonName;
std::string_view m_link;
std::string m_key;
};
}
8 changes: 7 additions & 1 deletion src/AppInstallerCommonCore/Public/winget/UserSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ namespace AppInstaller::Settings
DownloadDefaultDirectory,
// Interactivity
InteractivityDisable,
// Experiments
Experiments,
#ifndef AICLI_DISABLE_TEST_HOOKS
// Debug
EnableSelfInitiatedMinidump,
Expand Down Expand Up @@ -200,7 +202,11 @@ namespace AppInstaller::Settings
SETTINGMAPPING_SPECIALIZATION(Setting::LoggingChannelPreference, std::vector<std::string>, Logging::Channel, Logging::Channel::Defaults, ".logging.channels"sv);
// Interactivity
SETTINGMAPPING_SPECIALIZATION(Setting::InteractivityDisable, bool, bool, false, ".interactivity.disable"sv);


// Experiments
using Experiments_t = std::map<std::string, bool>;
SETTINGMAPPING_SPECIALIZATION(Setting::Experiments, std::string, Experiments_t, {}, ".experiments"sv);

// Used to deduce the SettingVariant type; making a variant that includes std::monostate and all SettingMapping types.
template <size_t... I>
inline auto Deduce(std::index_sequence<I...>) { return std::variant<std::monostate, typename SettingMapping<static_cast<Setting>(I)>::value_t...>{}; }
Expand Down
2 changes: 2 additions & 0 deletions src/AppInstallerSharedLib/GroupPolicy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ namespace AppInstaller::Settings
return TogglePolicy(policy, "EnableWindowsPackageManagerConfiguration"sv, String::PolicyEnableWinGetConfiguration);
case TogglePolicy::Policy::ProxyCommandLineOptions:
return TogglePolicy(policy, "EnableWindowsPackageManagerProxyCommandLineOptions"sv, String::PolicyEnableProxyCommandLineOptions);
case TogglePolicy::Policy::Experiments:
return TogglePolicy(policy, "EnableExperiments"sv, String::PolicyEnableExperiments);
default:
THROW_HR(E_UNEXPECTED);
}
Expand Down
1 change: 1 addition & 0 deletions src/AppInstallerSharedLib/Public/winget/GroupPolicy.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace AppInstaller::Settings
WinGetCommandLineInterfaces,
Configuration,
ProxyCommandLineOptions,
Experiments,
Max,
};

Expand Down
1 change: 1 addition & 0 deletions src/AppInstallerSharedLib/Public/winget/Resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ namespace AppInstaller
WINGET_DEFINE_RESOURCE_STRINGID(PolicyEnableWindowsPackageManagerCommandLineInterfaces);
WINGET_DEFINE_RESOURCE_STRINGID(PolicyEnableWinGetConfiguration);
WINGET_DEFINE_RESOURCE_STRINGID(PolicyEnableProxyCommandLineOptions);
WINGET_DEFINE_RESOURCE_STRINGID(PolicyEnableExperiments);

WINGET_DEFINE_RESOURCE_STRINGID(SettingsWarningInvalidFieldFormat);
WINGET_DEFINE_RESOURCE_STRINGID(SettingsWarningInvalidFieldValue);
Expand Down
4 changes: 2 additions & 2 deletions src/Internal/Experiment/Experiment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

namespace AppInstaller::Experiment
{
bool IsEnabled(const std::string&, bool overrideResult)
bool IsEnabled(const std::string&)
{
return overrideResult;
return true;
}
}
2 changes: 1 addition & 1 deletion src/Internal/Experiment/Experiment.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

namespace AppInstaller::Experiment
{
bool IsEnabled(const std::string& experimentKey, bool overrideResult = false);
bool IsEnabled(const std::string& experimentKey);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// <copyright file="EnumPolicyExtension.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. Licensed under the MIT License.
// </copyright>
Expand Down Expand Up @@ -50,6 +50,8 @@ public static string GetResourceString(this Policy policy)
return GroupPolicyResource.PolicyEnableWindowsPackageManagerCommandLineInterfaces;
case Policy.Configuration:
return GroupPolicyResource.PolicyEnableWinGetConfiguration;
case Policy.Experiments:
return GroupPolicyResource.PolicyEnableExperiments;
default:
return string.Empty;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// <copyright file="Enums.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. Licensed under the MIT License.
// </copyright>
Expand Down Expand Up @@ -96,6 +96,11 @@ public enum Policy
/// Enabled configuration.
/// </summary>
Configuration,

/// <summary>
/// Enabled experiments.
/// </summary>
Experiments,
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// <copyright file="TogglePolicy.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. Licensed under the MIT License.
// </copyright>
Expand Down Expand Up @@ -125,6 +125,8 @@ internal static TogglePolicy Create(Policy policy)
return new TogglePolicy(policy, "EnableWindowsPackageManagerCommandLineInterfaces", GroupPolicyResource.PolicyEnableWindowsPackageManagerCommandLineInterfaces);
case Policy.Configuration:
return new TogglePolicy(policy, "EnableWindowsPackageManagerConfiguration", GroupPolicyResource.PolicyEnableWinGetConfiguration);
case Policy.Experiments:
return new TogglePolicy(policy, "EnableExperiments", GroupPolicyResource.PolicyEnableExperiments);
default:
throw new ArgumentException(null, nameof(policy));
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Expand Down Expand Up @@ -135,6 +135,9 @@
<data name="PolicyEnableExperimentalFeatures" xml:space="preserve">
<value>Enable Windows App Installer Experimental Features</value>
</data>
<data name="PolicyEnableExperiments" xml:space="preserve">
<value>Enable Windows App Installer Experiments</value>
</data>
<data name="PolicyEnableHashOverride" xml:space="preserve">
<value>Enable Windows App Installer Hash Override</value>
</data>
Expand Down Expand Up @@ -168,4 +171,4 @@
<data name="PolicyNotFound" xml:space="preserve">
<value>Error occurred when retrieving policy settings for the Group Policy : {0}</value>
</data>
</root>
</root>

0 comments on commit 3e66324

Please sign in to comment.