commit 0de06fab8dff370d1fd12a163d6a5c862f74d0fc
parent 26a2173bc1a9ac0b3c5c66802a4fb44f16361fe1
Author: JohnMcPMS <johnmcp@microsoft.com>
Date: Fri, 28 Apr 2023 12:18:20 -0700
Make entitlement best effort (#3172)
Make entitlement acquisition best effort rather than required. A recent change caused some issues for us regarding the entitlement process, and since the entitlement isn't actually required to install, just attempt to get it and log if it failed. Even if the underlying issue is resolved, this change will prevent future issues from having the same level of impact.
This may lead to an issue where the entitlement acquisition fails, the package is installed, but attempting to run it fails because the entitlement cannot be acquired then either (by the OS in the background). Given the choice between the two failure modes though, it seems far better to remove these false negatives and create the (my gut says fewer) false positives that will result.
Diffstat:
3 files changed, 45 insertions(+), 46 deletions(-)
diff --git a/src/AppInstallerCLICore/Resources.h b/src/AppInstallerCLICore/Resources.h
@@ -266,10 +266,6 @@ namespace AppInstaller::CLI::Resource
WINGET_DEFINE_RESOURCE_STRINGID(MsixArgumentDescription);
WINGET_DEFINE_RESOURCE_STRINGID(MsixSignatureHashFailed);
WINGET_DEFINE_RESOURCE_STRINGID(MSStoreAppBlocked);
- WINGET_DEFINE_RESOURCE_STRINGID(MSStoreInstallGetEntitlementNetworkError);
- WINGET_DEFINE_RESOURCE_STRINGID(MSStoreInstallGetEntitlementNoStoreAccount);
- WINGET_DEFINE_RESOURCE_STRINGID(MSStoreInstallGetEntitlementServerError);
- WINGET_DEFINE_RESOURCE_STRINGID(MSStoreInstallGetEntitlementSuccess);
WINGET_DEFINE_RESOURCE_STRINGID(MSStoreInstallOrUpdateFailed);
WINGET_DEFINE_RESOURCE_STRINGID(MSStoreInstallTryGetEntitlement);
WINGET_DEFINE_RESOURCE_STRINGID(MSStoreStoreClientBlocked);
diff --git a/src/AppInstallerCLICore/Workflows/MSStoreInstallerHandler.cpp b/src/AppInstallerCLICore/Workflows/MSStoreInstallerHandler.cpp
@@ -79,48 +79,69 @@ namespace AppInstaller::CLI::Workflow
return errorCode;
}
- bool GetFreeEntitlement(Execution::Context& context, const std::wstring& productId)
+ // The type of entitlement we were able to acquire/ensure.
+ enum class EntitlementType
+ {
+ None,
+ User,
+ Device,
+ };
+
+ EntitlementType EnsureFreeEntitlement(Execution::Context& context, const std::wstring& productId)
{
AppInstallManager installManager;
+ AICLI_LOG(CLI, Error, << "Getting entitlement for ProductId: " << Utility::ConvertToUTF8(productId));
+
// Verifying/Acquiring product ownership
context.Reporter.Info() << Resource::String::MSStoreInstallTryGetEntitlement << std::endl;
- GetEntitlementResult result{ nullptr };
+ GetEntitlementResult entitlementResult{ nullptr };
+ EntitlementType result = EntitlementType::None;
if (Manifest::ConvertToScopeEnum(context.Args.GetArg(Execution::Args::Type::InstallScope)) == Manifest::ScopeEnum::Machine)
{
- AICLI_LOG(CLI, Info, << "Get device entitlement.");
- result = installManager.GetFreeDeviceEntitlementAsync(productId, winrt::hstring(), winrt::hstring()).get();
+ AICLI_LOG(CLI, Info, << "Get device entitlement (machine scope install).");
+ result = EntitlementType::Device;
+ entitlementResult = installManager.GetFreeDeviceEntitlementAsync(productId, winrt::hstring(), winrt::hstring()).get();
}
else
{
AICLI_LOG(CLI, Info, << "Get user entitlement.");
- result = installManager.GetFreeUserEntitlementAsync(productId, winrt::hstring(), winrt::hstring()).get();
- if (result.Status() == GetEntitlementStatus::NoStoreAccount)
+ result = EntitlementType::User;
+ entitlementResult = installManager.GetFreeUserEntitlementAsync(productId, winrt::hstring(), winrt::hstring()).get();
+
+ if (entitlementResult.Status() == GetEntitlementStatus::NoStoreAccount)
{
- AICLI_LOG(CLI, Info, << "Get device entitlement.");
- result = installManager.GetFreeDeviceEntitlementAsync(productId, winrt::hstring(), winrt::hstring()).get();
+ AICLI_LOG(CLI, Info, << "Get device entitlement (no store account).");
+ result = EntitlementType::Device;
+ entitlementResult = installManager.GetFreeDeviceEntitlementAsync(productId, winrt::hstring(), winrt::hstring()).get();
}
}
- if (result.Status() == GetEntitlementStatus::Succeeded)
+ if (entitlementResult.Status() == GetEntitlementStatus::Succeeded)
{
- context.Reporter.Info() << Resource::String::MSStoreInstallGetEntitlementSuccess << std::endl;
AICLI_LOG(CLI, Info, << "Get entitlement succeeded.");
}
- else if (result.Status() == GetEntitlementStatus::NetworkError)
- {
- context.Reporter.Info() << Resource::String::MSStoreInstallGetEntitlementNetworkError << std::endl;
- AICLI_LOG(CLI, Error, << "Get entitlement failed. Network error.");
- }
- else if (result.Status() == GetEntitlementStatus::ServerError)
+ else
{
- context.Reporter.Info() << Resource::String::MSStoreInstallGetEntitlementServerError << std::endl;
- AICLI_LOG(CLI, Error, << "Get entitlement failed Server error. ProductId: " << Utility::ConvertToUTF8(productId));
+ result = EntitlementType::None;
+
+ if (entitlementResult.Status() == GetEntitlementStatus::NetworkError)
+ {
+ AICLI_LOG(CLI, Error, << "Get entitlement failed. Network error.");
+ }
+ else if (entitlementResult.Status() == GetEntitlementStatus::ServerError)
+ {
+ AICLI_LOG(CLI, Error, << "Get entitlement failed. Server error.");
+ }
+ else
+ {
+ AICLI_LOG(CLI, Error, << "Get entitlement failed. Unknown status: " << static_cast<int32_t>(entitlementResult.Status()));
+ }
}
- return result.Status() == GetEntitlementStatus::Succeeded;
+ return result;
}
}
@@ -135,11 +156,8 @@ namespace AppInstaller::CLI::Workflow
{
auto productId = Utility::ConvertToUTF16(context.Get<Execution::Data::Installer>()->ProductId);
- // Verifying/Acquiring product ownership
- if (!GetFreeEntitlement(context, productId))
- {
- AICLI_TERMINATE_CONTEXT(APPINSTALLER_CLI_ERROR_MSSTORE_INSTALL_FAILED);
- }
+ // Best effort verifying/acquiring product ownership.
+ std::ignore = EnsureFreeEntitlement(context, productId);
AppInstallManager installManager;
AppInstallOptions installOptions;
@@ -184,7 +202,7 @@ namespace AppInstaller::CLI::Workflow
else
{
auto errorCodeString = GetErrorCodeString(errorCode);
- context.Reporter.Info() << Resource::String::MSStoreInstallOrUpdateFailed(errorCodeString) << std::endl;
+ context.Reporter.Error() << Resource::String::MSStoreInstallOrUpdateFailed(errorCodeString) << std::endl;
context.Add<Execution::Data::OperationReturnCode>(errorCode);
AICLI_LOG(CLI, Error, << "MSStore install failed. ProductId: " << Utility::ConvertToUTF8(productId) << " HResult: " << errorCodeString);
AICLI_TERMINATE_CONTEXT(errorCode);
@@ -195,11 +213,8 @@ namespace AppInstaller::CLI::Workflow
{
auto productId = Utility::ConvertToUTF16(context.Get<Execution::Data::Installer>()->ProductId);
- // Verifying/Acquiring product ownership
- if (!GetFreeEntitlement(context, productId))
- {
- AICLI_TERMINATE_CONTEXT(APPINSTALLER_CLI_ERROR_MSSTORE_INSTALL_FAILED);
- }
+ // Best effort verifying/acquiring product ownership.
+ std::ignore = EnsureFreeEntitlement(context, productId);
AppInstallManager installManager;
AppUpdateOptions updateOptions;
diff --git a/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw b/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw
@@ -386,18 +386,6 @@ They can be configured through the settings file 'winget settings'.</value>
<value>Failed to install or upgrade Microsoft Store package. Error code: {0}</value>
<comment>{Locked="{0}"} Error message displayed when a Microsoft Store application package fails to install or upgrade. {0} is a placeholder replaced by an error code.</comment>
</data>
- <data name="MSStoreInstallGetEntitlementNetworkError" xml:space="preserve">
- <value>Verifying/Requesting package acquisition failed: network error</value>
- </data>
- <data name="MSStoreInstallGetEntitlementNoStoreAccount" xml:space="preserve">
- <value>Verifying/Requesting package acquisition failed: no store account found</value>
- </data>
- <data name="MSStoreInstallGetEntitlementServerError" xml:space="preserve">
- <value>Verifying/Requesting package acquisition failed: server error</value>
- </data>
- <data name="MSStoreInstallGetEntitlementSuccess" xml:space="preserve">
- <value>Verifying/Requesting package acquisition success</value>
- </data>
<data name="MSStoreStoreClientBlocked" xml:space="preserve">
<value>Failed to install or upgrade Microsoft Store package because Microsoft Store client is blocked by policy</value>
</data>