From d070cbad64d2d6ac817efddfaf41a5cc13a5c116 Mon Sep 17 00:00:00 2001 From: Tian L <60599517+tian-lt@users.noreply.github.com> Date: Mon, 9 May 2022 08:33:09 +0800 Subject: [PATCH] fix crash: GetPolicyFromPathForUser (#1826) --- src/CalcViewModel/Common/NavCategory.cpp | 14 ++++++++++---- src/CalcViewModel/Common/NavCategory.h | 2 +- src/Calculator/App.xaml.cs | 3 ++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/CalcViewModel/Common/NavCategory.cpp b/src/CalcViewModel/Common/NavCategory.cpp index 51cb8dc7..829f7488 100644 --- a/src/CalcViewModel/Common/NavCategory.cpp +++ b/src/CalcViewModel/Common/NavCategory.cpp @@ -49,7 +49,7 @@ static constexpr int GRAPHING_ID = 17; namespace // put the utils within this TU { - Platform::Agile CurrentUser; + Platform::String^ CurrentUserId; std::mutex GraphingModeCheckMutex; bool IsGraphingModeEnabled() @@ -64,8 +64,14 @@ namespace // put the utils within this TU } else { + auto user = User::GetFromId(CurrentUserId); + if (user == nullptr) + { + return true; + } + auto namedPolicyData = NamedPolicy::GetPolicyFromPathForUser( - CurrentUser.Get(), + user, L"Education", L"AllowGraphingCalculator"); isEnabled = namedPolicyData->GetBoolean(); @@ -310,10 +316,10 @@ NavCategoryGroup::NavCategoryGroup(const NavCategoryGroupInitializer& groupIniti } } -void NavCategoryStates::SetCurrentUser(Windows::System::User^ user) +void NavCategoryStates::SetCurrentUser(Platform::String^ userId) { std::scoped_lock lock(GraphingModeCheckMutex); - CurrentUser = user; + CurrentUserId = userId; } IObservableVector ^ NavCategoryStates::CreateMenuOptions() diff --git a/src/CalcViewModel/Common/NavCategory.h b/src/CalcViewModel/Common/NavCategory.h index 15ef098f..810ccbed 100644 --- a/src/CalcViewModel/Common/NavCategory.h +++ b/src/CalcViewModel/Common/NavCategory.h @@ -152,7 +152,7 @@ namespace CalculatorApp::ViewModel public ref class NavCategoryStates sealed { public: - static void SetCurrentUser(Windows::System::User^ user); + static void SetCurrentUser(Platform::String^ user); static Windows::Foundation::Collections::IObservableVector ^ CreateMenuOptions(); static NavCategoryGroup ^ CreateCalculatorCategoryGroup(); static NavCategoryGroup ^ CreateConverterCategoryGroup(); diff --git a/src/Calculator/App.xaml.cs b/src/Calculator/App.xaml.cs index c18e76a6..6f40b325 100644 --- a/src/Calculator/App.xaml.cs +++ b/src/Calculator/App.xaml.cs @@ -85,7 +85,8 @@ namespace CalculatorApp // If the app got pre-launch activated, then save that state in a flag m_preLaunched = true; } - NavCategoryStates.SetCurrentUser(args.User); + + NavCategoryStates.SetCurrentUser(args.User.NonRoamableId); // It takes time to check GraphingMode at the 1st time. So, do it in a background thread Task.Run(() => NavCategoryStates.IsViewModeEnabled(ViewMode.Graphing));