From 82ce049f1222bb3b06d78e77179d33fafa8c2ffc Mon Sep 17 00:00:00 2001 From: eric langlois Date: Thu, 13 Jan 2022 06:33:05 -0800 Subject: [PATCH 01/25] Wnp toast notifications (#1981) * Adding temp idl for base branch * Create .cpp/.h files for handling toastnotifications * Introduce ToastNotification Registration APIs (#1875) * Introduce ToastRegistration APIs and associated taef tests * Address comments * Address minor comments * Add support for Release x64 for ToastNotificationTestApp * Addressing nits * Add GetActivatorGuid function * Last nits * Update error messages Co-authored-by: Paul Purifoy * Forward integrate main into WNP_ToastNotifications (#1970) * Added header so MddBootstrapAutoInitializer.cpp compiles regardless of precompiled headers (#1947) * Update dependencies from https://dev.azure.com/microsoft/ProjectReunion/_git/ProjectReunionInternal build Maestro-UpdateEngCommon_2201.10001 (#1962) Microsoft.WinAppSDK.EngCommon From Version 1.0.0-20211213.0-CI -> To Version 1.0.0-20220110.0-CI Co-authored-by: dotnet-maestro[bot] * Run the Foundation test suite from the Internal Integraiton tests (#1963) Co-authored-by: Howard Kapustein Co-authored-by: reunion-maestro[bot] <81196566+reunion-maestro[bot]@users.noreply.github.com> Co-authored-by: dotnet-maestro[bot] Co-authored-by: Kyaw Thant <48363984+kythant@users.noreply.github.com> Co-authored-by: Eric Langlois * Revert "Forward integrate main into WNP_ToastNotifications (#1970)" This reverts commit a981a1e05c0e218451e1d3c1d92d45cc679ade13. Co-authored-by: Paul Purifoy Co-authored-by: Sharath Manchala <10109130+sharath2727@users.noreply.github.com> Co-authored-by: Howard Kapustein Co-authored-by: reunion-maestro[bot] <81196566+reunion-maestro[bot]@users.noreply.github.com> Co-authored-by: dotnet-maestro[bot] Co-authored-by: Kyaw Thant <48363984+kythant@users.noreply.github.com> Co-authored-by: Eric Langlois --- .../PushNotificationsDemoApp/main.cpp | 4 + .../ToastNotificationsTestApp.cpp | 258 ++++++++++++++++++ 2 files changed, 262 insertions(+) create mode 100644 test/TestApps/ToastNotificationsTestApp/ToastNotificationsTestApp.cpp diff --git a/test/TestApps/PushNotificationsDemoApp/main.cpp b/test/TestApps/PushNotificationsDemoApp/main.cpp index 2bbcb73655..89405595a7 100644 --- a/test/TestApps/PushNotificationsDemoApp/main.cpp +++ b/test/TestApps/PushNotificationsDemoApp/main.cpp @@ -109,6 +109,10 @@ int main() ToastNotificationManager::Default().RegisterActivator(activationInfo); } + ToastAssets assets(L"ToastNotificationApp", winrt::Windows::Foundation::Uri{ LR"(C:\Windows\System32\WindowsSecurityIcon.png)" }); + auto activationInfo = ToastActivationInfo::CreateFromToastAssets(assets); + ToastNotificationManager::Default().RegisterActivator(activationInfo); + if (PushNotificationManager::IsActivatorSupported(PushNotificationRegistrationActivators::ComActivator)) { PushNotificationActivationInfo info( diff --git a/test/TestApps/ToastNotificationsTestApp/ToastNotificationsTestApp.cpp b/test/TestApps/ToastNotificationsTestApp/ToastNotificationsTestApp.cpp new file mode 100644 index 0000000000..dcfabe0358 --- /dev/null +++ b/test/TestApps/ToastNotificationsTestApp/ToastNotificationsTestApp.cpp @@ -0,0 +1,258 @@ +#include "pch.h" +#include +#include +#include +#include "WindowsAppRuntime.Test.AppModel.h" + +namespace winrt +{ + using namespace winrt::Microsoft::Windows::AppLifecycle; + using namespace winrt::Windows::ApplicationModel::Activation; + using namespace winrt::Windows::Foundation; + using namespace winrt::Microsoft::Windows::ToastNotifications; +} + +bool VerifyFailedRegisterActivatorUsingNullClsid() +{ + try + { + auto activationInfo = winrt::ToastActivationInfo::CreateFromActivationGuid(winrt::guid(GUID_NULL)); + + winrt::ToastNotificationManager::Default().RegisterActivator(activationInfo); + } + catch (...) + { + return winrt::to_hresult() == E_INVALIDARG; + } + + return false; +} + +bool VerifyFailedRegisterActivatorUsingNullClsid_Unpackaged() +{ + try + { + auto activationInfo = winrt::ToastActivationInfo::CreateFromActivationGuid(winrt::guid(GUID_NULL)); + + winrt::ToastNotificationManager::Default().RegisterActivator(activationInfo); + } + catch (...) + { + return winrt::to_hresult() == E_ILLEGAL_METHOD_CALL; + } + + return false; +} + +bool VerifyFailedRegisterActivatorUsingNullAssets() +{ + try + { + auto activationInfo = winrt::ToastActivationInfo::CreateFromToastAssets(nullptr); + + winrt::ToastNotificationManager::Default().RegisterActivator(activationInfo); + } + catch (...) + { + return winrt::to_hresult() == E_ILLEGAL_METHOD_CALL; + } + + return false; +} + +bool VerifyFailedRegisterActivatorUsingNullAssets_Unpackaged() +{ + try + { + auto activationInfo = winrt::ToastActivationInfo::CreateFromToastAssets(nullptr); + + winrt::ToastNotificationManager::Default().RegisterActivator(activationInfo); + } + catch (...) + { + return winrt::to_hresult() == E_POINTER; + } + + return false; +} + +bool VerifyRegisterActivatorandUnRegisterActivatorUsingClsid() +{ + auto activationInfo = winrt::ToastActivationInfo::CreateFromActivationGuid(winrt::guid("1940DBA9-0F64-4F0D-8A4B-5D207B812E61")); + + winrt::ToastNotificationManager::Default().RegisterActivator(activationInfo); + + winrt::ToastNotificationManager::Default().UnregisterActivator(); + + return true; +} + +bool VerifyRegisterActivatorandUnRegisterActivatorUsingAssets_Unpackaged() +{ + winrt::ToastAssets assets(L"ToastNotificationApp", winrt::Uri{ LR"(C:\Windows\System32\WindowsSecurityIcon.png)" }); + + auto activationInfo = winrt::ToastActivationInfo::CreateFromToastAssets(assets); + + winrt::ToastNotificationManager::Default().RegisterActivator(activationInfo); + + winrt::ToastNotificationManager::Default().UnregisterActivator(); + + return true; +} + +bool VerifyFailedMultipleRegisterActivatorUsingSameClsid() +{ + try + { + auto activationInfo = winrt::ToastActivationInfo::CreateFromActivationGuid(winrt::guid("1940DBA9-0F64-4F0D-8A4B-5D207B812E61")); + + winrt::ToastNotificationManager::Default().RegisterActivator(activationInfo); + + winrt::ToastNotificationManager::Default().RegisterActivator(activationInfo); + } + catch (...) + { + return winrt::to_hresult() == E_INVALIDARG; + } + + return false; +} + +bool VerifyFailedMultipleRegisterActivatorUsingSameAssets_Unpackaged() +{ + try + { + winrt::ToastAssets assets(L"ToastNotificationApp", winrt::Uri{ LR"(C:\Windows\System32\WindowsSecurityIcon.png)" }); + + auto activationInfo = winrt::ToastActivationInfo::CreateFromToastAssets(assets); + + winrt::ToastNotificationManager::Default().RegisterActivator(activationInfo); + + winrt::ToastNotificationManager::Default().RegisterActivator(activationInfo); + } + catch (...) + { + return winrt::to_hresult() == E_INVALIDARG; + } + + return false; +} + +bool VerifyFailedToastAssetsWithEmptyDisplayName_Unpackaged() +{ + try + { + winrt::ToastAssets assets(L"", winrt::Uri{LR"(C:\Windows\System32\WindowsSecurityIcon.png)"}); + + auto activationInfo = winrt::ToastActivationInfo::CreateFromToastAssets(assets); + } + catch (...) + { + return winrt::to_hresult() == E_INVALIDARG; + } + + return false; +} + +bool VerifyFailedToastAssetsWithEmptyIconPath_Unpackaged() +{ + try + { + winrt::ToastAssets assets(L"ToastNotificationApp", winrt::Uri{ L""}); + + auto activationInfo = winrt::ToastActivationInfo::CreateFromToastAssets(assets); + } + catch (...) + { + return winrt::to_hresult() == E_POINTER; + } + + return false; +} + +bool VerifyFailedToastAssetsWithNullIconPath_Unpackaged() +{ + try + { + winrt::ToastAssets assets(L"ToastNotificationApp", nullptr); + + auto activationInfo = winrt::ToastActivationInfo::CreateFromToastAssets(assets); + } + catch (...) + { + return winrt::to_hresult() == E_POINTER; + } + + return false; +} + +std::string unitTestNameFromLaunchArguments(const winrt::ILaunchActivatedEventArgs& launchArgs) +{ + std::string unitTestName = to_string(launchArgs.Arguments()); + auto argStart = unitTestName.rfind(" "); + if (argStart != std::wstring::npos) + { + unitTestName = unitTestName.substr(argStart + 1); + } + + return unitTestName; +} + +std::map const& GetSwitchMapping() +{ + static std::map switchMapping = { + { "VerifyFailedRegisterActivatorUsingNullClsid", &VerifyFailedRegisterActivatorUsingNullClsid }, + { "VerifyFailedRegisterActivatorUsingNullClsid_Unpackaged", &VerifyFailedRegisterActivatorUsingNullClsid_Unpackaged}, + { "VerifyFailedRegisterActivatorUsingNullAssets", &VerifyFailedRegisterActivatorUsingNullAssets }, + { "VerifyRegisterActivatorandUnRegisterActivatorUsingClsid", &VerifyRegisterActivatorandUnRegisterActivatorUsingClsid }, + { "VerifyRegisterActivatorandUnRegisterActivatorUsingAssets_Unpackaged", &VerifyRegisterActivatorandUnRegisterActivatorUsingAssets_Unpackaged }, + { "VerifyFailedMultipleRegisterActivatorUsingSameClsid", &VerifyFailedMultipleRegisterActivatorUsingSameClsid }, + { "VerifyFailedMultipleRegisterActivatorUsingSameAssets_Unpackaged", &VerifyFailedMultipleRegisterActivatorUsingSameAssets_Unpackaged }, + { "VerifyFailedToastAssetsWithEmptyDisplayName_Unpackaged", &VerifyFailedToastAssetsWithEmptyDisplayName_Unpackaged }, + { "VerifyFailedToastAssetsWithEmptyIconPath_Unpackaged", &VerifyFailedToastAssetsWithEmptyIconPath_Unpackaged }, + { "VerifyFailedToastAssetsWithNullIconPath_Unpackaged", &VerifyFailedToastAssetsWithNullIconPath_Unpackaged }, + }; + return switchMapping; +} + +bool runUnitTest(std::string unitTest) +{ + auto const& switchMapping = GetSwitchMapping(); + auto it = switchMapping.find(unitTest); + if (it == switchMapping.end()) + { + return false; + } + + return it->second(); +} + + +int main() try +{ + bool testResult = false; + auto scope_exit = wil::scope_exit([&] { + ::Test::Bootstrap::CleanupBootstrap(); + }); + + ::Test::Bootstrap::SetupBootstrap(); + + auto args = winrt::AppInstance::GetCurrent().GetActivatedEventArgs(); + auto kind = args.Kind(); + + if (kind == winrt::ExtendedActivationKind::Launch) + { + auto unitTest = unitTestNameFromLaunchArguments(args.Data().as()); + std::cout << unitTest << std::endl; + + testResult = runUnitTest(unitTest); + } + + return testResult ? 0 : 1; // We want 0 to be success and 1 failure +} +catch (...) +{ + std::cout << winrt::to_string(winrt::to_message()) << std::endl; + + return 1; // in the event of unhandled test crash +} From 984a8834879aabff31b75f5b7f27ce856c102340 Mon Sep 17 00:00:00 2001 From: eric langlois Date: Thu, 13 Jan 2022 10:12:19 -0800 Subject: [PATCH 02/25] User/erlangl/purifoypaul/arm64 build fix (#1983) * Adding temp idl for base branch * Create .cpp/.h files for handling toastnotifications * Introduce ToastNotification Registration APIs (#1875) * Introduce ToastRegistration APIs and associated taef tests * Address comments * Address minor comments * Add support for Release x64 for ToastNotificationTestApp * Addressing nits * Add GetActivatorGuid function * Last nits * Update error messages Co-authored-by: Paul Purifoy * Forward integrate main into WNP_ToastNotifications (#1970) * Added header so MddBootstrapAutoInitializer.cpp compiles regardless of precompiled headers (#1947) * Update dependencies from https://dev.azure.com/microsoft/ProjectReunion/_git/ProjectReunionInternal build Maestro-UpdateEngCommon_2201.10001 (#1962) Microsoft.WinAppSDK.EngCommon From Version 1.0.0-20211213.0-CI -> To Version 1.0.0-20220110.0-CI Co-authored-by: dotnet-maestro[bot] * Run the Foundation test suite from the Internal Integraiton tests (#1963) Co-authored-by: Howard Kapustein Co-authored-by: reunion-maestro[bot] <81196566+reunion-maestro[bot]@users.noreply.github.com> Co-authored-by: dotnet-maestro[bot] Co-authored-by: Kyaw Thant <48363984+kythant@users.noreply.github.com> Co-authored-by: Eric Langlois * Fixing build files for ToastNotificationTestApp/ToastNotificationTests * File was renamed to main Co-authored-by: Paul Purifoy Co-authored-by: Sharath Manchala <10109130+sharath2727@users.noreply.github.com> Co-authored-by: Howard Kapustein Co-authored-by: reunion-maestro[bot] <81196566+reunion-maestro[bot]@users.noreply.github.com> Co-authored-by: dotnet-maestro[bot] Co-authored-by: Kyaw Thant <48363984+kythant@users.noreply.github.com> Co-authored-by: Eric Langlois --- .../ToastNotificationsTestApp.cpp | 258 ------------------ 1 file changed, 258 deletions(-) delete mode 100644 test/TestApps/ToastNotificationsTestApp/ToastNotificationsTestApp.cpp diff --git a/test/TestApps/ToastNotificationsTestApp/ToastNotificationsTestApp.cpp b/test/TestApps/ToastNotificationsTestApp/ToastNotificationsTestApp.cpp deleted file mode 100644 index dcfabe0358..0000000000 --- a/test/TestApps/ToastNotificationsTestApp/ToastNotificationsTestApp.cpp +++ /dev/null @@ -1,258 +0,0 @@ -#include "pch.h" -#include -#include -#include -#include "WindowsAppRuntime.Test.AppModel.h" - -namespace winrt -{ - using namespace winrt::Microsoft::Windows::AppLifecycle; - using namespace winrt::Windows::ApplicationModel::Activation; - using namespace winrt::Windows::Foundation; - using namespace winrt::Microsoft::Windows::ToastNotifications; -} - -bool VerifyFailedRegisterActivatorUsingNullClsid() -{ - try - { - auto activationInfo = winrt::ToastActivationInfo::CreateFromActivationGuid(winrt::guid(GUID_NULL)); - - winrt::ToastNotificationManager::Default().RegisterActivator(activationInfo); - } - catch (...) - { - return winrt::to_hresult() == E_INVALIDARG; - } - - return false; -} - -bool VerifyFailedRegisterActivatorUsingNullClsid_Unpackaged() -{ - try - { - auto activationInfo = winrt::ToastActivationInfo::CreateFromActivationGuid(winrt::guid(GUID_NULL)); - - winrt::ToastNotificationManager::Default().RegisterActivator(activationInfo); - } - catch (...) - { - return winrt::to_hresult() == E_ILLEGAL_METHOD_CALL; - } - - return false; -} - -bool VerifyFailedRegisterActivatorUsingNullAssets() -{ - try - { - auto activationInfo = winrt::ToastActivationInfo::CreateFromToastAssets(nullptr); - - winrt::ToastNotificationManager::Default().RegisterActivator(activationInfo); - } - catch (...) - { - return winrt::to_hresult() == E_ILLEGAL_METHOD_CALL; - } - - return false; -} - -bool VerifyFailedRegisterActivatorUsingNullAssets_Unpackaged() -{ - try - { - auto activationInfo = winrt::ToastActivationInfo::CreateFromToastAssets(nullptr); - - winrt::ToastNotificationManager::Default().RegisterActivator(activationInfo); - } - catch (...) - { - return winrt::to_hresult() == E_POINTER; - } - - return false; -} - -bool VerifyRegisterActivatorandUnRegisterActivatorUsingClsid() -{ - auto activationInfo = winrt::ToastActivationInfo::CreateFromActivationGuid(winrt::guid("1940DBA9-0F64-4F0D-8A4B-5D207B812E61")); - - winrt::ToastNotificationManager::Default().RegisterActivator(activationInfo); - - winrt::ToastNotificationManager::Default().UnregisterActivator(); - - return true; -} - -bool VerifyRegisterActivatorandUnRegisterActivatorUsingAssets_Unpackaged() -{ - winrt::ToastAssets assets(L"ToastNotificationApp", winrt::Uri{ LR"(C:\Windows\System32\WindowsSecurityIcon.png)" }); - - auto activationInfo = winrt::ToastActivationInfo::CreateFromToastAssets(assets); - - winrt::ToastNotificationManager::Default().RegisterActivator(activationInfo); - - winrt::ToastNotificationManager::Default().UnregisterActivator(); - - return true; -} - -bool VerifyFailedMultipleRegisterActivatorUsingSameClsid() -{ - try - { - auto activationInfo = winrt::ToastActivationInfo::CreateFromActivationGuid(winrt::guid("1940DBA9-0F64-4F0D-8A4B-5D207B812E61")); - - winrt::ToastNotificationManager::Default().RegisterActivator(activationInfo); - - winrt::ToastNotificationManager::Default().RegisterActivator(activationInfo); - } - catch (...) - { - return winrt::to_hresult() == E_INVALIDARG; - } - - return false; -} - -bool VerifyFailedMultipleRegisterActivatorUsingSameAssets_Unpackaged() -{ - try - { - winrt::ToastAssets assets(L"ToastNotificationApp", winrt::Uri{ LR"(C:\Windows\System32\WindowsSecurityIcon.png)" }); - - auto activationInfo = winrt::ToastActivationInfo::CreateFromToastAssets(assets); - - winrt::ToastNotificationManager::Default().RegisterActivator(activationInfo); - - winrt::ToastNotificationManager::Default().RegisterActivator(activationInfo); - } - catch (...) - { - return winrt::to_hresult() == E_INVALIDARG; - } - - return false; -} - -bool VerifyFailedToastAssetsWithEmptyDisplayName_Unpackaged() -{ - try - { - winrt::ToastAssets assets(L"", winrt::Uri{LR"(C:\Windows\System32\WindowsSecurityIcon.png)"}); - - auto activationInfo = winrt::ToastActivationInfo::CreateFromToastAssets(assets); - } - catch (...) - { - return winrt::to_hresult() == E_INVALIDARG; - } - - return false; -} - -bool VerifyFailedToastAssetsWithEmptyIconPath_Unpackaged() -{ - try - { - winrt::ToastAssets assets(L"ToastNotificationApp", winrt::Uri{ L""}); - - auto activationInfo = winrt::ToastActivationInfo::CreateFromToastAssets(assets); - } - catch (...) - { - return winrt::to_hresult() == E_POINTER; - } - - return false; -} - -bool VerifyFailedToastAssetsWithNullIconPath_Unpackaged() -{ - try - { - winrt::ToastAssets assets(L"ToastNotificationApp", nullptr); - - auto activationInfo = winrt::ToastActivationInfo::CreateFromToastAssets(assets); - } - catch (...) - { - return winrt::to_hresult() == E_POINTER; - } - - return false; -} - -std::string unitTestNameFromLaunchArguments(const winrt::ILaunchActivatedEventArgs& launchArgs) -{ - std::string unitTestName = to_string(launchArgs.Arguments()); - auto argStart = unitTestName.rfind(" "); - if (argStart != std::wstring::npos) - { - unitTestName = unitTestName.substr(argStart + 1); - } - - return unitTestName; -} - -std::map const& GetSwitchMapping() -{ - static std::map switchMapping = { - { "VerifyFailedRegisterActivatorUsingNullClsid", &VerifyFailedRegisterActivatorUsingNullClsid }, - { "VerifyFailedRegisterActivatorUsingNullClsid_Unpackaged", &VerifyFailedRegisterActivatorUsingNullClsid_Unpackaged}, - { "VerifyFailedRegisterActivatorUsingNullAssets", &VerifyFailedRegisterActivatorUsingNullAssets }, - { "VerifyRegisterActivatorandUnRegisterActivatorUsingClsid", &VerifyRegisterActivatorandUnRegisterActivatorUsingClsid }, - { "VerifyRegisterActivatorandUnRegisterActivatorUsingAssets_Unpackaged", &VerifyRegisterActivatorandUnRegisterActivatorUsingAssets_Unpackaged }, - { "VerifyFailedMultipleRegisterActivatorUsingSameClsid", &VerifyFailedMultipleRegisterActivatorUsingSameClsid }, - { "VerifyFailedMultipleRegisterActivatorUsingSameAssets_Unpackaged", &VerifyFailedMultipleRegisterActivatorUsingSameAssets_Unpackaged }, - { "VerifyFailedToastAssetsWithEmptyDisplayName_Unpackaged", &VerifyFailedToastAssetsWithEmptyDisplayName_Unpackaged }, - { "VerifyFailedToastAssetsWithEmptyIconPath_Unpackaged", &VerifyFailedToastAssetsWithEmptyIconPath_Unpackaged }, - { "VerifyFailedToastAssetsWithNullIconPath_Unpackaged", &VerifyFailedToastAssetsWithNullIconPath_Unpackaged }, - }; - return switchMapping; -} - -bool runUnitTest(std::string unitTest) -{ - auto const& switchMapping = GetSwitchMapping(); - auto it = switchMapping.find(unitTest); - if (it == switchMapping.end()) - { - return false; - } - - return it->second(); -} - - -int main() try -{ - bool testResult = false; - auto scope_exit = wil::scope_exit([&] { - ::Test::Bootstrap::CleanupBootstrap(); - }); - - ::Test::Bootstrap::SetupBootstrap(); - - auto args = winrt::AppInstance::GetCurrent().GetActivatedEventArgs(); - auto kind = args.Kind(); - - if (kind == winrt::ExtendedActivationKind::Launch) - { - auto unitTest = unitTestNameFromLaunchArguments(args.Data().as()); - std::cout << unitTest << std::endl; - - testResult = runUnitTest(unitTest); - } - - return testResult ? 0 : 1; // We want 0 to be success and 1 failure -} -catch (...) -{ - std::cout << winrt::to_string(winrt::to_message()) << std::endl; - - return 1; // in the event of unhandled test crash -} From eb6591e48ad345cbacae6d5e283628269721c6ac Mon Sep 17 00:00:00 2001 From: Paul Purifoy <33183370+pmpurifoy@users.noreply.github.com> Date: Tue, 18 Jan 2022 12:58:57 -0800 Subject: [PATCH 03/25] Add ToastNotificationManger::Setting API (#1984) * Add ToastNotificationManger::Setting API * Addressing nits * Update ToastNotificationManager.cpp --- dev/ToastNotifications/ToastNotificationManager.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/dev/ToastNotifications/ToastNotificationManager.cpp b/dev/ToastNotifications/ToastNotificationManager.cpp index c2676ca983..3108cf617a 100644 --- a/dev/ToastNotifications/ToastNotificationManager.cpp +++ b/dev/ToastNotifications/ToastNotificationManager.cpp @@ -10,7 +10,6 @@ #include "ToastNotificationUtility.h" #include #include - static winrt::event> g_toastHandlers; winrt::event>& GetToastHandlers() From 52695d2d39132514143dbfe2b863a17be2381c2b Mon Sep 17 00:00:00 2001 From: Paul Purifoy <33183370+pmpurifoy@users.noreply.github.com> Date: Tue, 18 Jan 2022 15:42:25 -0800 Subject: [PATCH 04/25] Add Foreground/Background handlers for ToastActivation (#1973) * Adding temp idl for base branch * Create .cpp/.h files for handling toastnotifications * Introduce ToastNotification Registration APIs (#1875) * Introduce ToastRegistration APIs and associated taef tests * Address comments * Address minor comments * Add support for Release x64 for ToastNotificationTestApp * Addressing nits * Add GetActivatorGuid function * Last nits * Update error messages Co-authored-by: Paul Purifoy * Copy branch based on WNP_ToastNotifications * Address nit * Addressing nits * Address nits * Change name from ToastActivation->AppNotification * Change more constants * Reuse deserialize function Co-authored-by: Sharath Manchala <10109130+sharath2727@users.noreply.github.com> --- test/TestApps/ToastNotificationsTestApp/main.cpp | 11 +++++++++++ .../Package.appxmanifest | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/test/TestApps/ToastNotificationsTestApp/main.cpp b/test/TestApps/ToastNotificationsTestApp/main.cpp index ab95adfa34..a329bb4bc3 100644 --- a/test/TestApps/ToastNotificationsTestApp/main.cpp +++ b/test/TestApps/ToastNotificationsTestApp/main.cpp @@ -35,6 +35,17 @@ winrt::ToastNotification GetToastNotification() return winrt::ToastNotification(xmlDocument); } +bool BackgroundActivationTest() // Activating application for background test. +{ + return true; +} + +bool UnregisterBackgroundActivationTest() +{ + winrt::ToastNotificationManager::Default().UnregisterActivator(); + return true; +} + bool VerifyFailedRegisterActivatorUsingNullClsid() { try diff --git a/test/TestApps/ToastNotificationsTestAppPackage/Package.appxmanifest b/test/TestApps/ToastNotificationsTestAppPackage/Package.appxmanifest index 82398d33c4..a8887425b4 100644 --- a/test/TestApps/ToastNotificationsTestAppPackage/Package.appxmanifest +++ b/test/TestApps/ToastNotificationsTestAppPackage/Package.appxmanifest @@ -50,7 +50,7 @@ - + From 971e67f8e53a3af644c50fb52cce9ae0e06ee721 Mon Sep 17 00:00:00 2001 From: Daniel Ayala <14967941+danielayala94@users.noreply.github.com> Date: Fri, 21 Jan 2022 17:06:24 -0800 Subject: [PATCH 05/25] Implemented ToastNotification + unit tests (#1996) Implemented ToastNotification + unit tests --- test/TestApps/ToastNotificationsTestApp/main.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/TestApps/ToastNotificationsTestApp/main.cpp b/test/TestApps/ToastNotificationsTestApp/main.cpp index a329bb4bc3..5cb3fab12b 100644 --- a/test/TestApps/ToastNotificationsTestApp/main.cpp +++ b/test/TestApps/ToastNotificationsTestApp/main.cpp @@ -46,6 +46,16 @@ bool UnregisterBackgroundActivationTest() return true; } +winrt::ToastNotification GetToastNotification() +{ + winrt::hstring xmlPayload{ L"intrepidToast" }; + + winrt::XmlDocument xmlDocument{}; + xmlDocument.LoadXml(xmlPayload); + + return winrt::ToastNotification(xmlDocument); +} + bool VerifyFailedRegisterActivatorUsingNullClsid() { try From a423b51d23928d8329efe6bc9c48d793b5ce9e3f Mon Sep 17 00:00:00 2001 From: Paul Purifoy <33183370+pmpurifoy@users.noreply.github.com> Date: Tue, 25 Jan 2022 13:22:08 -0800 Subject: [PATCH 06/25] Add ToastRegistration functions to PushNotificationsLongRunningTask (#1976) * Adding temp idl for base branch * Create .cpp/.h files for handling toastnotifications * Introduce ToastNotification Registration APIs (#1875) * Introduce ToastRegistration APIs and associated taef tests * Address comments * Address minor comments * Add support for Release x64 for ToastNotificationTestApp * Addressing nits * Add GetActivatorGuid function * Last nits * Update error messages Co-authored-by: Paul Purifoy * Rebase to WPN_ToastNotifications * Update externs.h * Rename toastGuid->appId * Addressing nits * Add sink check to AddToastRegistrationMapping * Adding lock to HasSinkForAppId * Change lock to shared lock * Add unit tests, rename appId->toastAppId * Add BuildAppIdentifier * Remove HasSinkForAppId * Move toastStorage to ToastNotificationManager * Address nits * Update platform.cpp * Adding packaged apps treated as unpackaged scenario * Flip the bool * Update platform.cpp * Fix remaining nits * last nits Co-authored-by: Sharath Manchala <10109130+sharath2727@users.noreply.github.com> --- .../PushNotificationsLongRunningTask/packages.config | 2 +- .../PushNotificationsDemoApp.vcxproj | 2 +- test/TestApps/PushNotificationsDemoApp/main.cpp | 5 ----- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/packages.config b/dev/PushNotifications/PushNotificationsLongRunningTask/packages.config index fa49afb662..187841df87 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/packages.config +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/packages.config @@ -6,4 +6,4 @@ - + \ No newline at end of file diff --git a/test/TestApps/PushNotificationsDemoApp/PushNotificationsDemoApp.vcxproj b/test/TestApps/PushNotificationsDemoApp/PushNotificationsDemoApp.vcxproj index 3cf835cddf..687dd62f49 100644 --- a/test/TestApps/PushNotificationsDemoApp/PushNotificationsDemoApp.vcxproj +++ b/test/TestApps/PushNotificationsDemoApp/PushNotificationsDemoApp.vcxproj @@ -285,4 +285,4 @@ - \ No newline at end of file + diff --git a/test/TestApps/PushNotificationsDemoApp/main.cpp b/test/TestApps/PushNotificationsDemoApp/main.cpp index 89405595a7..03f1aafd64 100644 --- a/test/TestApps/PushNotificationsDemoApp/main.cpp +++ b/test/TestApps/PushNotificationsDemoApp/main.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include "WindowsAppRuntime.Test.AppModel.h" using namespace winrt::Microsoft::Windows::AppLifecycle; @@ -168,9 +167,5 @@ int main() } ToastNotificationManager::Default().UnregisterActivator(); - if (!Test::AppModel::IsPackagedProcess()) - { - MddBootstrapShutdown(); - } return 0; } From e7e3f6ca7047c0cf28af85638043ee5378440568 Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Tue, 25 Jan 2022 17:14:38 -0800 Subject: [PATCH 07/25] First iteration of ToastNotificationDemoApp --- WindowsAppRuntime.sln | 9 +- dev/AppLifecycle/AppInstance.cpp | 2 +- .../Package.appxmanifest | 2 +- .../ToastNotificationsDemoApp.vcxproj | 279 ++++++++++++++++++ .../ToastNotificationsDemoApp.vcxproj.filters | 17 ++ .../ToastNotificationsDemoApp/main.cpp | 187 ++++++++++++ .../ToastNotificationsDemoApp/packages.config | 6 + .../ToastNotificationsDemoApp/pch.cpp | 3 + test/TestApps/ToastNotificationsDemoApp/pch.h | 19 ++ .../Images/LockScreenLogo.scale-200.png | Bin 0 -> 1430 bytes .../Images/SplashScreen.scale-200.png | Bin 0 -> 7700 bytes .../Images/Square150x150Logo.scale-200.png | Bin 0 -> 2937 bytes .../Images/Square44x44Logo.scale-200.png | Bin 0 -> 1647 bytes ...x44Logo.targetsize-24_altform-unplated.png | Bin 0 -> 1255 bytes .../Images/StoreLogo.png | Bin 0 -> 1451 bytes .../Images/Wide310x150Logo.scale-200.png | Bin 0 -> 3204 bytes .../Package.appxmanifest | 76 +++++ .../ToastNotificationsDemoPackage.wapproj | 88 ++++++ test/ToastNotificationTests/APITests.cpp | 3 + 19 files changed, 685 insertions(+), 6 deletions(-) create mode 100644 test/TestApps/ToastNotificationsDemoApp/ToastNotificationsDemoApp.vcxproj create mode 100644 test/TestApps/ToastNotificationsDemoApp/ToastNotificationsDemoApp.vcxproj.filters create mode 100644 test/TestApps/ToastNotificationsDemoApp/main.cpp create mode 100644 test/TestApps/ToastNotificationsDemoApp/packages.config create mode 100644 test/TestApps/ToastNotificationsDemoApp/pch.cpp create mode 100644 test/TestApps/ToastNotificationsDemoApp/pch.h create mode 100644 test/TestApps/ToastNotificationsDemoPackage/Images/LockScreenLogo.scale-200.png create mode 100644 test/TestApps/ToastNotificationsDemoPackage/Images/SplashScreen.scale-200.png create mode 100644 test/TestApps/ToastNotificationsDemoPackage/Images/Square150x150Logo.scale-200.png create mode 100644 test/TestApps/ToastNotificationsDemoPackage/Images/Square44x44Logo.scale-200.png create mode 100644 test/TestApps/ToastNotificationsDemoPackage/Images/Square44x44Logo.targetsize-24_altform-unplated.png create mode 100644 test/TestApps/ToastNotificationsDemoPackage/Images/StoreLogo.png create mode 100644 test/TestApps/ToastNotificationsDemoPackage/Images/Wide310x150Logo.scale-200.png create mode 100644 test/TestApps/ToastNotificationsDemoPackage/Package.appxmanifest create mode 100644 test/TestApps/ToastNotificationsDemoPackage/ToastNotificationsDemoPackage.wapproj diff --git a/WindowsAppRuntime.sln b/WindowsAppRuntime.sln index c45e696da4..6ff3d2cfe6 100644 --- a/WindowsAppRuntime.sln +++ b/WindowsAppRuntime.sln @@ -300,6 +300,7 @@ Global dev\UndockedRegFreeWinRT\UndockedRegFreeWinRT.vcxitems*{56371ca6-144b-4989-a4e9-391ad4fa7651}*SharedItemsImports = 9 test\inc\inc.vcxitems*{56a1d696-feda-4333-bf37-772ebececb10}*SharedItemsImports = 4 test\inc\inc.vcxitems*{5b2d17fe-c371-417f-860c-3d32397c2404}*SharedItemsImports = 4 + test\inc\inc.vcxitems*{72e682c6-2ffd-4d1d-99f1-07b400867699}*SharedItemsImports = 4 test\inc\inc.vcxitems*{7c502995-59c3-483b-86ba-815985353633}*SharedItemsImports = 4 dev\Licensing\Licensing.vcxitems*{885a43fa-052d-4b0d-a2dc-13ee15796435}*SharedItemsImports = 9 test\inc\inc.vcxitems*{8e52d7ea-a200-4a6b-ba74-8efb49468caf}*SharedItemsImports = 4 @@ -1228,10 +1229,10 @@ Global {A3FBA80D-5B35-471F-9A45-DB4B29E195B9} = {AC5FFC80-92FE-4933-BED2-EC5519AC4440} {91D03B95-1B0C-4BEB-8441-30DA7D615538} = {448ED2E5-0B37-4D97-9E6B-8C10A507976A} {103C0C23-7BA8-4D44-A63C-83488E2E3A81} = {91D03B95-1B0C-4BEB-8441-30DA7D615538} - {5B2D17FE-C371-417F-860C-3D32397C2404} = {AC5FFC80-92FE-4933-BED2-EC5519AC4440} - {424A6D96-37EE-4456-8347-08AB425C8DBE} = {AC5FFC80-92FE-4933-BED2-EC5519AC4440} - {56A1D696-FEDA-4333-BF37-772EBECECB10} = {AC5FFC80-92FE-4933-BED2-EC5519AC4440} - {D012E4BB-F16B-472D-A26D-D449CEFA988E} = {AC5FFC80-92FE-4933-BED2-EC5519AC4440} + {5B2D17FE-C371-417F-860C-3D32397C2404} = {2C6DFE11-B59C-4EE2-8669-AECA96FB69A3} + {424A6D96-37EE-4456-8347-08AB425C8DBE} = {2C6DFE11-B59C-4EE2-8669-AECA96FB69A3} + {56A1D696-FEDA-4333-BF37-772EBECECB10} = {55288381-8BF9-4982-94A4-180ADD59166D} + {D012E4BB-F16B-472D-A26D-D449CEFA988E} = {55288381-8BF9-4982-94A4-180ADD59166D} {0A5FEE93-48B7-40EC-BB9A-B27D11060DA9} = {8630F7AA-2969-4DC9-8700-9B468C1DC21D} {1307DD1B-BBE8-4CD0-B1A0-0DB6D61EEAA0} = {91D03B95-1B0C-4BEB-8441-30DA7D615538} {A1B25DCF-6A54-414D-8E24-F4D24EE9299D} = {8630F7AA-2969-4DC9-8700-9B468C1DC21D} diff --git a/dev/AppLifecycle/AppInstance.cpp b/dev/AppLifecycle/AppInstance.cpp index 765dbfa815..4314626ab1 100644 --- a/dev/AppLifecycle/AppInstance.cpp +++ b/dev/AppLifecycle/AppInstance.cpp @@ -68,7 +68,7 @@ namespace winrt::Microsoft::Windows::AppLifecycle::implementation wil::unique_hlocal_ptr argv{ CommandLineToArgvW(commandLine.c_str(), &argc) }; - PCWSTR activationKinds[] = { c_msProtocolArgumentString, c_pushProtocolArgumentString }; + PCWSTR activationKinds[] = { c_msProtocolArgumentString, c_pushProtocolArgumentString, c_toastProtocolArgumentString }; for (auto activationKind : activationKinds) { auto [ kind, data ] = GetActivationArguments(argv.get(), argc, activationKind); diff --git a/test/TestApps/PushNotificationsDemoPackage/Package.appxmanifest b/test/TestApps/PushNotificationsDemoPackage/Package.appxmanifest index 65d30def92..99129ec444 100644 --- a/test/TestApps/PushNotificationsDemoPackage/Package.appxmanifest +++ b/test/TestApps/PushNotificationsDemoPackage/Package.appxmanifest @@ -43,7 +43,7 @@ - + WindowsAppRuntimeTestProtocol diff --git a/test/TestApps/ToastNotificationsDemoApp/ToastNotificationsDemoApp.vcxproj b/test/TestApps/ToastNotificationsDemoApp/ToastNotificationsDemoApp.vcxproj new file mode 100644 index 0000000000..a40f5cacb3 --- /dev/null +++ b/test/TestApps/ToastNotificationsDemoApp/ToastNotificationsDemoApp.vcxproj @@ -0,0 +1,279 @@ + + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + Debug + ARM64 + + + Release + ARM64 + + + + 16.0 + Win32Proj + {72e682c6-2ffd-4d1d-99f1-07b400867699} + ToastNotificationsDemoApp + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + false + + + Application + false + v142 + true + Unicode + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + true + + + false + + + + Use + Level3 + true + %(AdditionalIncludeDirectories);$(OutDir)\..\WindowsAppRuntime_DLL;$(OutDir)\..\WindowsAppRuntime_BootstrapDLL;..\..\inc + WIN32;_DEBUG;%(PreprocessorDefinitions) + pch.h + stdcpp17 + + + Console + %(AdditionalLibraryDirectories);$(OutDir)\..\WindowsAppRuntime_DLL + onecore.lib;onecoreuap.lib;Microsoft.WindowsAppRuntime.lib;%(AdditionalDependencies) + + + + + Use + Level3 + true + true + true + %(AdditionalIncludeDirectories);$(OutDir)\..\WindowsAppRuntime_DLL;$(OutDir)\..\WindowsAppRuntime_BootstrapDLL;..\..\inc + WIN32;NDEBUG;%(PreprocessorDefinitions) + pch.h + stdcpp17 + + + Console + true + true + %(AdditionalLibraryDirectories);$(OutDir)\..\WindowsAppRuntime_DLL + onecore.lib;onecoreuap.lib;Microsoft.WindowsAppRuntime.lib;%(AdditionalDependencies) + + + + + Use + Level3 + true + %(AdditionalIncludeDirectories);$(OutDir)\..\WindowsAppRuntime_DLL;$(OutDir)\..\WindowsAppRuntime_BootstrapDLL;..\..\inc + _DEBUG;%(PreprocessorDefinitions) + pch.h + stdcpp17 + + + Console + %(AdditionalLibraryDirectories);$(OutDir)\..\WindowsAppRuntime_DLL + onecore.lib;onecoreuap.lib;Microsoft.WindowsAppRuntime.lib;%(AdditionalDependencies) + + + + + Use + Level3 + true + true + true + %(AdditionalIncludeDirectories);$(OutDir)\..\WindowsAppRuntime_DLL;$(OutDir)\..\WindowsAppRuntime_BootstrapDLL;..\..\inc + NDEBUG;%(PreprocessorDefinitions) + pch.h + stdcpp17 + + + Console + true + true + %(AdditionalLibraryDirectories);$(OutDir)\..\WindowsAppRuntime_DLL + onecore.lib;onecoreuap.lib;Microsoft.WindowsAppRuntime.lib;%(AdditionalDependencies) + + + + + Use + Level3 + true + %(AdditionalIncludeDirectories);$(OutDir)\..\WindowsAppRuntime_DLL;$(OutDir)\..\WindowsAppRuntime_BootstrapDLL;..\..\inc + _DEBUG;%(PreprocessorDefinitions) + pch.h + stdcpp17 + + + Console + %(AdditionalLibraryDirectories);$(OutDir)\..\WindowsAppRuntime_DLL + onecore.lib;onecoreuap.lib;Microsoft.WindowsAppRuntime.lib;%(AdditionalDependencies) + + + + + Use + Level3 + true + true + true + %(AdditionalIncludeDirectories);$(OutDir)\..\WindowsAppRuntime_DLL;$(OutDir)\..\WindowsAppRuntime_BootstrapDLL;..\..\inc + NDEBUG;%(PreprocessorDefinitions) + pch.h + stdcpp17 + + + Console + true + true + %(AdditionalLibraryDirectories);$(OutDir)\..\WindowsAppRuntime_DLL + onecore.lib;onecoreuap.lib;Microsoft.WindowsAppRuntime.lib;%(AdditionalDependencies) + + + + + + Create + + + + + + + + + + + $(OutDir)\..\WindowsAppRuntime_DLL\Microsoft.Windows.AppLifecycle.winmd + true + $(OutDir)\..\WindowsAppRuntime_DLL\Microsoft.WindowsAppRuntime.dll + + + $(OutDir)\..\WindowsAppRuntime_DLL\Microsoft.Windows.PushNotifications.winmd + true + $(OutDir)\..\WindowsAppRuntime_DLL\Microsoft.WindowsAppRuntime.dll + + + $(OutDir)\..\WindowsAppRuntime_DLL\Microsoft.Windows.ToastNotifications.winmd + true + $(OutDir)\..\WindowsAppRuntime_DLL\Microsoft.WindowsAppRuntime.dll + + + + + {f76b776e-86f5-48c5-8fc7-d2795ecc9746} + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + diff --git a/test/TestApps/ToastNotificationsDemoApp/ToastNotificationsDemoApp.vcxproj.filters b/test/TestApps/ToastNotificationsDemoApp/ToastNotificationsDemoApp.vcxproj.filters new file mode 100644 index 0000000000..a8a65633bf --- /dev/null +++ b/test/TestApps/ToastNotificationsDemoApp/ToastNotificationsDemoApp.vcxproj.filters @@ -0,0 +1,17 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + \ No newline at end of file diff --git a/test/TestApps/ToastNotificationsDemoApp/main.cpp b/test/TestApps/ToastNotificationsDemoApp/main.cpp new file mode 100644 index 0000000000..373242d37f --- /dev/null +++ b/test/TestApps/ToastNotificationsDemoApp/main.cpp @@ -0,0 +1,187 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. +#include "pch.h" +#include +#include +#include +#include "WindowsAppRuntime.Test.AppModel.h" + +using namespace winrt::Microsoft::Windows::AppLifecycle; +using namespace winrt::Microsoft::Windows::PushNotifications; +using namespace winrt::Microsoft::Windows::ToastNotifications; +using namespace winrt::Windows::ApplicationModel::Activation; +using namespace winrt::Windows::ApplicationModel::Background; // BackgroundTask APIs +using namespace winrt::Windows::Foundation; +using namespace winrt::Windows::Foundation::Collections; +using namespace winrt::Windows::Storage; +using namespace winrt::Windows::Storage::Streams; + +winrt::Windows::Foundation::IAsyncOperation RequestChannelAsync() +{ + // To obtain an AAD RemoteIdentifier for your app, + // follow the instructions on https://docs.microsoft.com/azure/active-directory/develop/quickstart-register-app + auto channelOperation = PushNotificationManager::CreateChannelAsync( + winrt::guid("0160ee84-0c53-4851-9ff2-d7f5a87ed914")); + + // Setup the inprogress event handler + channelOperation.Progress( + [](auto&& sender, auto&& args) + { + if (args.status == PushNotificationChannelStatus::InProgress) + { + // This is basically a noop since it isn't really an error state + std::cout << "Channel request is in progress." << std::endl << std::endl; + } + else if (args.status == PushNotificationChannelStatus::InProgressRetry) + { + LOG_HR_MSG( + args.extendedError, + "The channel request is in back-off retry mode because of a retryable error! Expect delays in acquiring it. RetryCount = %d", + args.retryCount); + } + }); + + auto result = co_await channelOperation; + + if (result.Status() == PushNotificationChannelStatus::CompletedSuccess) + { + auto channelUri = result.Channel().Uri(); + + std::cout << "channelUri: " << winrt::to_string(channelUri.ToString()) << std::endl << std::endl; + + auto channelExpiry = result.Channel().ExpirationTime(); + + // Register Push Event for Foreground + winrt::event_token token = result.Channel().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& args) + { + auto payload = args.Payload(); + + // Do stuff to process the raw payload + std::string payloadString(payload.begin(), payload.end()); + std::cout << "Push notification content received from FOREGROUND: " << payloadString << std::endl << std::endl; + args.Handled(true); + }); + // Caller's responsibility to keep the channel alive + co_return result.Channel(); + } + else if (result.Status() == PushNotificationChannelStatus::CompletedFailure) + { + LOG_HR_MSG(result.ExtendedError(), "We hit a critical non-retryable error with channel request!"); + co_return nullptr; + } + else + { + LOG_HR_MSG(result.ExtendedError(), "Some other failure occurred."); + co_return nullptr; + } + +}; + +winrt::Microsoft::Windows::PushNotifications::PushNotificationChannel RequestChannel() +{ + auto task = RequestChannelAsync(); + if (task.wait_for(std::chrono::seconds(300)) != AsyncStatus::Completed) + { + task.Cancel(); + return nullptr; + } + + auto result = task.GetResults(); + return result; +} + +std::wstring GetEnumString(ToastNotificationSetting const& setting) +{ + static std::map enumMapping = { + { ToastNotificationSetting::Enabled, L"Enabled"}, + { ToastNotificationSetting::DisabledForApplication, L"DisabledForApplication" }, + { ToastNotificationSetting::DisabledForUser, L"DisabledForUser"}, + { ToastNotificationSetting::DisabledByGroupPolicy, L"DisabledByGroupPolicy"}, + { ToastNotificationSetting::DisabledByManifest, L"DisabledByManifest"} + }; + return enumMapping[setting]; +} + +int main() +{ + // Retrieve the app scenario. + bool isPackaged{ Test::AppModel::IsPackagedProcess() }; + + std::wcout << L"--------------------------------" << std::endl; + std::wcout << L"- Toast Notifications Demo App -" << std::endl; + std::wcout << L"--------------------------------" << std::endl << std::endl; + + // Display if app is running as packaged | unpackaged. + std::wcout << L"Running as " << (isPackaged ? L"packaged." : L"unpackaged.") << std::endl << std::endl; + + // Grab an instance of ToastNotificationManager + auto toastNotificationManager{ ToastNotificationManager::Default() }; + + // Display the current ToastNotificationSetting for the app. + std::wcout << L"Printing ToastNotificationSetting for app: " << GetEnumString(toastNotificationManager.Setting()) << std::endl << std::endl; + + ToastActivationInfo activationInfo{ nullptr }; + // Create toastActivationInfo depending on packaged | unpackaged scenario. + if (isPackaged) + { + std::wcout << L"Calling ToastActivationInfo::CreateFromActivationGuid with nitro activation guid..." << std::endl; + activationInfo = ToastActivationInfo::CreateFromActivationGuid(winrt::guid("FE8C7374-A28F-4CBE-8D28-4288CBDFD431")); + std::wcout << L"Done." << std::endl << std::endl; + } + else + { + std::wcout << L"Calling ToastActivationInfo::CreateFromToastAssets..." << std::endl; + ToastAssets assets(L"ToastNotificationApp", Uri{ LR"(C:\Windows\System32\WindowsSecurityIcon.png)" }); + activationInfo = ToastActivationInfo::CreateFromToastAssets(assets); + std::wcout << L"Done." << std::endl << std::endl; + } + + // Registering app for activation + std::wcout << L"Calling ToastNotificationManager::RegisterActivator(activationInfo)..." << std::endl; + toastNotificationManager.RegisterActivator(activationInfo); + std::wcout << L"Done." << std::endl << std::endl; + + // Retrieve the activation event args + auto args = AppInstance::GetCurrent().GetActivatedEventArgs(); + auto kind = args.Kind(); + + // Check if activated from background by ToastActivation + if (kind == ExtendedActivationKind::AppNotification) + { + std::wcout << L"Activated by ToastActivation from background." << std::endl; + ToastActivatedEventArgs toastArgs{ args.Data().as() }; + winrt::hstring arguments{ toastArgs.ActivationArgs() }; + std::wcout << arguments.c_str() << std::endl << std::endl; + + IMap userInput = toastArgs.UserInput(); + for (auto pair : userInput) + { + std::wcout << "Key= " << pair.Key().c_str() << " " << "Value= " << pair.Value().c_str() << std::endl; + } + std::wcout << std::endl; + } + + // Setting up foreground handler for ToastActivation + std::wcout << L"Registering foreground handler to receive ToastActivationEventArgs..." << std::endl; + winrt::event_token token = toastNotificationManager.ToastActivated([](const auto&, winrt::Microsoft::Windows::ToastNotifications::ToastActivatedEventArgs const& toastArgs) + { + printf("ToastActivation received foreground!\n"); + winrt::hstring arguments{ toastArgs.ActivationArgs() }; + std::wcout << arguments.c_str() << std::endl << std::endl; + + IMap userInput{ toastArgs.UserInput() }; + for (auto pair : userInput) + { + std::wcout << "Key= " << pair.Key().c_str() << " " << "Value= " << pair.Value().c_str() << std::endl; + } + std::wcout << std::endl; + }); + std::wcout << L"Done." << std::endl << std::endl; + + std::wcout << L"Requesting PushNotificationChannel..." << std::endl << std::endl; + PushNotificationChannel channel{ RequestChannel() }; + + std::wcout << L"Press enter to exit the app." << std::endl << std::endl; + std::cin.ignore(); + return 0; +} diff --git a/test/TestApps/ToastNotificationsDemoApp/packages.config b/test/TestApps/ToastNotificationsDemoApp/packages.config new file mode 100644 index 0000000000..6922924db5 --- /dev/null +++ b/test/TestApps/ToastNotificationsDemoApp/packages.config @@ -0,0 +1,6 @@ + + + + + + diff --git a/test/TestApps/ToastNotificationsDemoApp/pch.cpp b/test/TestApps/ToastNotificationsDemoApp/pch.cpp new file mode 100644 index 0000000000..8c646996e9 --- /dev/null +++ b/test/TestApps/ToastNotificationsDemoApp/pch.cpp @@ -0,0 +1,3 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. +#include "pch.h" diff --git a/test/TestApps/ToastNotificationsDemoApp/pch.h b/test/TestApps/ToastNotificationsDemoApp/pch.h new file mode 100644 index 0000000000..c7a7d50c5a --- /dev/null +++ b/test/TestApps/ToastNotificationsDemoApp/pch.h @@ -0,0 +1,19 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. +#pragma once + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/test/TestApps/ToastNotificationsDemoPackage/Images/LockScreenLogo.scale-200.png b/test/TestApps/ToastNotificationsDemoPackage/Images/LockScreenLogo.scale-200.png new file mode 100644 index 0000000000000000000000000000000000000000..735f57adb5dfc01886d137b4e493d7e97cf13af3 GIT binary patch literal 1430 zcmaJ>TTC2P7~aKltDttVHYH6u8Io4i*}3fO&d$gd*bA_<3j~&e7%8(eXJLfhS!M@! zKrliY>>6yT4+Kr95$!DoD(Qn-5TP|{V_KS`k~E6(LGS@#`v$hQo&^^BKsw3HIsZBT z_y6C2n`lK@apunKojRQ^(_P}Mgewt$(^BBKCTZ;*xa?J3wQ7~@S0lUvbcLeq1Bg4o zH-bvQi|wt~L7q$~a-gDFP!{&TQfc3fX*6=uHv* zT&1&U(-)L%Xp^djI2?~eBF2cxC@YOP$+9d?P&h?lPy-9M2UT9fg5jKm1t$m#iWE{M zIf%q9@;fyT?0UP>tcw-bLkz;s2LlKl2qeP0w zECS7Ate+Awk|KQ+DOk;fl}Xsy4o^CY=pwq%QAAKKl628_yNPsK>?A>%D8fQG6IgdJ ztnxttBz#NI_a@fk7SU`WtrpsfZsNs9^0(2a z@C3#YO3>k~w7?2hipBf{#b6`}Xw1hlG$yi?;1dDs7k~xDAw@jiI*+tc;t2Lflg&bM)0!Y;0_@=w%`LW^8DsYpS#-bLOklX9r?Ei}TScw|4DbpW%+7 zFgAI)f51s}{y-eWb|vrU-Ya!GuYKP)J7z#*V_k^Xo>4!1Yqj*m)x&0L^tg3GJbVAJ zJ-Pl$R=NAabouV=^z_t;^K*0AvFs!vYU>_<|I^#c?>>CR<(T?=%{;U=aI*SbZADLH z&(f2wz_Y0??Tf|g;?|1Znw6}6U43Q#qNRwv1vp9uFn1)V#*4p&%$mP9x&15^OaBiDS(XppT|z^>;B{PLVEbS3IFYV yGvCsSX*m literal 0 HcmV?d00001 diff --git a/test/TestApps/ToastNotificationsDemoPackage/Images/SplashScreen.scale-200.png b/test/TestApps/ToastNotificationsDemoPackage/Images/SplashScreen.scale-200.png new file mode 100644 index 0000000000000000000000000000000000000000..023e7f1feda78d5100569825acedfd213a0d84e9 GIT binary patch literal 7700 zcmeHLYj~4Yw%(;oxoEH#Kxq-eR|+VkP17b#Vk;?4QwkI+A{L04G+#<<(x#Un1#+h5>eArRq zTw$)ZvTWW_Y?bDho0nPVTh08+s`sp!j74rJTTtXIDww0SILedFv?sZ?yb@@}GN;#8 znk_b~Q(A0YR#uV4ef!osoV1M3;vQ8N$O|fStfgf$S5;ddUNv`tWtGjM;koG#N;7M< zP*84lnx(bn_KF&9Z5Ai$)#Cs3a|$OFw>WKCT$of*L7_CqQEinflT|W{JT+aKp-E0v zsxmYg)1(T>DROm+LN1eQw8}KCTp=C!$H7`PU!t9_Hw@TsTI2`udRZv*!a5`#A9hK6Y95L(CDUX&_@QxKV z_feX{UhA#ZWlvgpL$#w^D#lq`_A4AzDqd|Zv6y9PX&DNcN|l}_D^{q@GG&H^Pg583 z8FI6N8^H7b5WjGp;urW)d7F+_lcp%KsLX0viCmE(OHH+=%ZfD_=`voUuoUxFO^L;- z;!;2{g-YiiO6m4bs89OuF9!p{FGtH-f%8<2gY!h9s)4ciN%{Kh1+`}{^}M~+TDH9N z^Z5PlgVXMC&2&k*Hw^Lb9gny#ro$MOIxIt{+r)EA10$VR3 zanN8D{TUkl+v0CQ_>ZoHP<M-x#8@8ZiT#$Kh`(uRaX1g$Bg|qy$<#7 zSSAi{Nb8Y=lvNVeio+UGLCAtoLBfL`iOv`)yoJMDJBN>4IH@(l7YRF;61@>qq1iM9 zr@b#OC~SAxSle?5Pp8Z78{VO0YFr1x7kZU64Z23eLf2T2#6J_t;-E}DkB?NufZ0Ug zi?J&byXeaB-uTNVhuiM!UVQw}bZrJ3GtAETYp->!{q#zfN7D3AS9@Q7*V^85jGx#R z(QxYV(wW#F0XF9^^s>>H8pPlVJ>)3Oz z&_X8Sf@~?cH_O*cgi$U#`v`RRfv#y3m(ZpKk^5uLup+lVs$~}FZU$r_+}#hl%?g5m z-u-}-666ssp-xWQak~>PPy$mRc|~?pVSs1_@mBEXpPVfLF6(Ktf1S* zPPh@QZ=tFMs?LM2(5P3L2;l_6XX6s&cYsP1ip#eg0`ZEP0HGYh{UmS@o`MihLLvkU zgyAG0G`b1|qjxxh1(ODKFE%AP}Dq=3vK$P7TXP4GrM1kQ72!GUVMDl`rDC&2;TA}*nF z8$nQD&6ys_nc1*E7$*1S@R8$ymy(sQV}imGSedB@{!QR5P&N_H=-^o!?LsWs+2|mH z-e=)T^SvI)=_JIm7}j4;@*Z17=(#}m=~YF~z~CLI+vdAGlJDcdF$TM?CVI1%LhUrN zaa6DJ=Yh$)$k&Oz{-~8yw^GM^8prYxSxo zvI4k#ibryMa%%*8oI-5m61Koa_A_xg=(fwp0aBX{;X4Q;NXUhtaoJDo1>TqhWtn=_ zd5~chq#&6~c%8JZK#t_&J(9EVUU&upYeIovLt1>vaHe}UUq>#RGQj!EN#5+0@T`(@ z^g~>*c`VGRiSt;!$_4+0hk^I!@O3``5=sZ8IwlxWW7km1B&_t&E*u0_9UBa#VqwY* zz>nxv?FAsVnRaD(Bui=6i==BFUw0k4n$>`umU`F2l?7CYTD^)c2X+d9X&ddS9|gj? zM?knGkGCX&W8offw8aLC2$D{PjC3nVZwd4k?eZH8*mZ)U@3Qk8RDFOz_#WUA#vnzy zyP>KrCfKwSXea7}jgJjBc}PGY+4#6%lbZyjhy`5sZd_Vy6Wz;ixa?czkN}J9It1K6 zY!eu>|AwF^fwZlLAYyQI*lM@^>O>Iu6Vf6i>Q$?v!SeUS<{>UYMwz$*%Aq?w^`j{h z!$GZbhu=^D{&ET8;))LL%ZBDZkQqRd2;u~!d9bHGmLRhLDctNgYyjsuvoSZ#iVdoB z2!f--UUA#U;<{je#?cYt^{PIyKa%hW>}uepWMyAI{{Zo7?2>?$c9;whJae%oN|I-kpTQSx_C$Z&;f zi2i)qmEn=y4U0uvk)$m;zKfjPK@oc?I`}1Jzl$Q~aoKBd3kt7L#7gyt|A_qgz6ai< z=X%D1i!d2h?rHR^R8SUj&G||dkC?DT>{o#Yau<@uqVT{Xef&XG}5*E4aPk{}~ zplx&XhaV)&1EfI3Em;Bw#O5SV^c;{twb-1Rw)+=0!e_BLbd7tYmXCH0wrlOSS+~`7He8Iqx0{CN+DVit9;*6L~JAN zD&cyT)2?h}xnYmL?^)<7YyzZ3$FHU^Eg;DLqAV{#wv#Wj7S`Jdl1pX&{3(uZ?!uh} zDc$ZTNV*7le_W6}Hju~GMTxZQ1aWCeUc%!jv3MHAzt>Y-nQK%zfT*3ebDQA5b?iGn; zBjv3B+GhLTexd_(CzZDP4|#n5^~scvB6#Pk%Ho!kQ>yYw((Dv{6=$g3jT1!u6gORW zx5#`7Wy-ZHRa~IxGHdrp(bm%lf>2%J660nj$fCqN(epv@y!l9s7@k6EvxS{AMP>WY zX4$@F8^kayphIx-RGO$+LYl9YdoI5d|4#q9##`_F5Xnx`&GPzp2fB{-{P@ATw=X@~ z_|&^UMWAKD;jjBKTK(~o?cUFRK8EX=6>cXpfzg4ZpMB>*w_^8GSiT-Jp|xBOnzM+j z*09-@-~qJ(eqWq5@R4i^u4^{McCP(!3}C|v_WsTR*bIUxN(Nx`u##3B4{sE`Z`v8w zAwIG`?1~PkID~W{uDzmqH98Pew_1(;x2%8r^vY{)_&J2K)cN{W+h5+g)ZcjP&Ci#O zgy|8K@4kyMfwilHd&6TDlhb%++Pk!>9HRld6HT7gwyZGrxS$}CsD6`>6!!2K1@Mjf z(P0WYB7V_OFZyeWrbOFb>O54BNXf~K&?}3=^v;v_wT{DKr?jN^DtN&DXwX%u?s*c6`%8>WFz z7}YW^tp0bp^NriE)AB6M2l<7rn7fzePtR*omOevpfm9n?}2V*+0iW;S)C zhg`NAjL?D=W#k*$aR{>pGf~lD-rVtD;5jW1_*Jn1j1=es@Kcx4ySM_bwcQCT=d+DV z>Sz~L=Hj@(X%31nK$mWI@7d>}ORB`K(p=+`UD)+99YUGQc7y^bHZ1F(8|tL0 zdK*DT0kSXG_{BKTpP2*2PecdKV9;dq$^ZZDP;Nyq1kp-&GI5eAyZsK!e3V zK@rPy*{(`KIfo+lc878mDKk^V#`VT05}64kBtk%DgwLrOvLMj5-;*GNKv6c6pzMuL z6EP%ob|_0IW}lLRXCP2!9wWhEw3LA7iF#1O1mIZ@Z=6&bz41F;@S_GvYAG-#CW3z{ zP3+6vHhvP&A3$##Vo9$dT^#MoGg^|MDm=Bt1d2RRwSZ<;ZHICpLBv5Xs!D?BH^(9_ z7`H=N&^v|Z-%mP}wNzG{aiFCsRgwzwq!N6obW9+7(R; z(SZ=23`|`>qil!LMGG{_Heq!BD>(Y-zV9wD)}hz25JA37YR%39;kI4y9pgtcUass6 zP24}ZY$vvYeI`zy&)A_X#nY3017ap*0&jx|mVwyGhg3;!keU53a}Uhm3BZI$N$6Se zLWlAmy1S0xKJm4G_U@sN_Tm=`$xWJSEwKU98rZ&)1R^*$$1vA3oG#&*%SMxY_~oGP zP&PFJatFLM-Ps%84IV-+Ow)T{C7cqUAvauy4C z(FRz&?6$Rypj{xO!`y=*J5o4@U8Q-(y5(*=YoKeZ+-1YdljXxkA#B)zo=FeQH#?Le zycNUmEEHWO9a=X^pb#&cOq7-`7UA87#|S22)<7RUtZo|(zibX=w;K3qur9vy#`MNV z6UUcf9ZwEnKCCp+OoBnF@OdbvH)ANXO0o~Pi9l8=x3))}L<#vO0-~O4!~--Ket?d} zJaqsj<@CD1%S2cTW%rOP{Vto%0sGW~1RMa_j^)5nil0Yw- z0EE#bP+l4#P^%PQ+N*oxu1Zq05xZ!bXfYTg>9c{(Iw*lnjR^>kz%lAN^zFce7rppy zY8zA~3GD=A6d*hze&l4D_wA~+O!56)BZTe_rEu}Ezi<4!kG|W#amBZ5{&XS2@6R~H z{9o^y*BkH4$~yX9U&@CgbOzX1bn9xqF|zh$Dh0Y5y*E0e90*$!ObrHY3Ok0`2=O~r zCuke6KrP9KOf?V(YDsM<6pX2nVoN%M$LT^q#FmtaF?1^27F*IcNX~XRB(|hCFvdcc zc)$=S-)acdk$g4?_>jRqxpI6M3vHZk?0c^3=byamYDNf;uB{3NlKW5IhnOS3DNkMV z?tK8?kJ}pmvp%&&eTVOVjHP`q34hN1@!aK}H(K!vI`~gf|Gv+FNEQD5Yd<~yX7k_l h&G-K)@HZb3BABY{)U1?^%I#E6`MGoTtustd{~yM6srvu` literal 0 HcmV?d00001 diff --git a/test/TestApps/ToastNotificationsDemoPackage/Images/Square150x150Logo.scale-200.png b/test/TestApps/ToastNotificationsDemoPackage/Images/Square150x150Logo.scale-200.png new file mode 100644 index 0000000000000000000000000000000000000000..af49fec1a5484db1d52a7f9b5ec90a27c7030186 GIT binary patch literal 2937 zcma)84OCO-8BSud5)jwMLRVKgX(S?$n?Ld|vrsm<$CF7)&zTbyy1FE5bU`Q17MRv`9ue$;R(@8kR;#vJ*IM0>cJIAOte!d7oRgdH zd%ySjdB6L9=gX^A6)VzH7p2l@v~3zJAMw|DFy#^)F@@F*`mqUn=Il>l)8_+ab;nOW{%+iPx z+s{Eu|&pIs)Z7{La9~?xKfyl z#43?gjEL15d4WbOZo#SiP%>DB^+BcnJ=7dHEe;r#G=tuw|ka z%q@}##Uh7;tc%L_64m(kHtw74ty%BJMb)_1)#S0j`)F8_1jF7vScpsnH=0V19bO8y zR`0SjIdCUo&=>JwMQF8KHA<{ODHTiQh}0^@5QRmCA?gOH6_H3K^-_sNB^RrdNuK-R zOO*vOrKCVvDwgUck`kF(E7j{I#iiN;b*ZdCt4m@HPA`EuEqGGf4%!K<;(=I=&Vyrw z%TwcWtxa}8mCZ%Cyf&ActJ6_$ox5z6-D!0-dvnRx6t7y3d+h6QYpKWO;8OdnvERo7 zuEf>ih5`wqY)~o@OeVt-wM?Q!>QzdGRj!bz6fzYrfw$hZfAKzr2-M+D+R>}~oT574c;_3zquHcElqKIsryILt3g8n3jcMb+j?i?-L3FpZJ z2WRVBRdDPc+G5aaYg#5hpE+6nQ|(VSoxT3|biF;BUq#==-27Xi=gihDPYP$7?=9cP zYKE$jeQ|3~_L0VG-(F~2ZPyD0=k{J4Q~h(t__{-mz_w8{JDY9{`1ouzz!Vr5!ECdE z6U~O1k8c}24V7~zzXWTV-Pe4)y}wQJS&q%H5`Fo_f_JvIU489aCX$;P`u#!I-=^4ijC2{&9!O&h>mi?9oYD=GC#%)6{GzN6nQYw+Fal50!#x^asjBBR50i`+mho*ttoqV)ubM2KD9S~k7+FR4>{29?6 z{!l6kDdyTN0YJ9LgkPWeXm|gyi@zM3?0@{&pXT12w|78&W-q!RRF)&iLCEZVH<|fR zN0fr2^t8H(>L?>K#>^+jWROLral(Qy-xoBq1U7A&DV||wClb)Otd9?(gZ|8znMF}D zf<1haWz^s0qgecz;RFGt0C-B4g`jNGHsFU+;{<%t65v^sjk^h$lmWn#B0#_)9ij&d z-~lc`A)YYExi^7sBuPM^Y|wA2g*5?`K?#7tzELQYNxGo$UB$4J8RJp1k(8Jj+~hMT zlN~>M@KTTh^--8y3PK_NZ@AC!{PT=CziBzGd+wTJ^@icH!Bd}%)g8V)%K?|c&WTUk zy}qv1C%(fjRoZ4ozC3{O%@5?)XzH35zHns$pgU*Q?fj4v?fp1Qbm+j;3l;9jam9Da zXVcKjPlQ73x78QPu|Ffm6x?`~e3oD=gl=4kYK?={kD5j~QCXU)`HSdduNNENzA*2$ zOm3PzF!lN5e*06-f1Uot67wY#{o-S1!KZ7E=!~7ynnk9_iJR#kFoNbAOT#^2Gd17F zMmvU6>lndZQGd|ax9kUoXXO+$N?|j@6qpsF&_j7YXvwo_C{JpmLw5&#e6k>atv%es z5)7r*Wvv_JkUpT}M!_o!nVlEk1Zbl=a*2hQ*<|%*K1Glj^FcF`6kTzGQ3lz~2tCc@ z&x|tj;aH&1&9HwcJBcT`;{?a+pnej;M1HO(6Z{#J!cZA04hnFl;NXA+&`=7bjW_^o zfC40u3LMG?NdPtwGl>Tq6u}*QG)}-y;)lu-_>ee3kibW(69n0$0Zy!}9rQz%*v1iO zT9_H>99yIrSPYVy6^);rR}7Yo=J_T@hi+qhTZXnVWyf;JDYm5#eYLTxr*?kiNn!+Y zQ+LUkBafNJ#rH#C(?d5^;gw9o#%daEI{mA*LHPIHPU`#|H$hD zwm>0&+kahQ)E#%~k>&5@&#Vg82H?s%71=)(soi@174pi9--2{w{1$}Sz4zGn3Du&x bht0Iza^2ykEt4(epJ78uh5nDlX8(TxzDYwP literal 0 HcmV?d00001 diff --git a/test/TestApps/ToastNotificationsDemoPackage/Images/Square44x44Logo.scale-200.png b/test/TestApps/ToastNotificationsDemoPackage/Images/Square44x44Logo.scale-200.png new file mode 100644 index 0000000000000000000000000000000000000000..ce342a2ec8a61291ba76c54604aea7e9d20af11b GIT binary patch literal 1647 zcmaJ?eM}Q)7(e+G1Q(|`V9JhTI2>MkceK4;p;PR&$Pi?ejk3YQ_3o`S&|W_dsOZ8# zWPTt69g`t$ab`0cj-Y0yiBSOqmd)tG7G(}M5aP0_%&9TijB#&)I{zSE^4@#z^FF`l z`8{8`o%wlL(UI|y2!cdsuVamHH~H86F!*-15em4)NqUpCQM5?aoC_eCf@lV4wvF2a zjDQn1JBL69f&@2M3rvzJcfE!eZ8FZUBlFlC5RD)it33{mF9#B82AiyQE%w)`vlwa> zv{<1sm&kSKK$&%2jSFn7$t&P%%6Ue>R=EAnG8N7fqynWG8L3p!4801a;8{+nliO(qd(jNJ_?+9W3#hLIDLoT6~3fx9=`CC-D}-AMrpEO7HK zt3$GicGPc?GmDjy7K2P@La;eu4!$zWCZ`ym{Z$b zu-O6RM&K4JT|BIZB`E-gxqG%FzanI#+2FFmqHqXG7yxWB=w55RGOM)$xMb(>kSNR z2w=1AZi%z=AmG~yea~XaXJR!v7vLn(RUnELfiB1|6D84ICOS}^Zo2AdN}<&*h}G_u z{xZ!(%>tLT3J3<5XhWy-tg+6)0nmUUENLW8TWA{R6bgVd3X;anYFZ^IRis*_P-C-r z;i>%1^eL3UI2-{w8nuFFcs0e~7J{O2k^~Ce%+Ly4U?|=!0LH=t6()xi<^I-rs+9sF z*q{E-CxZbGPeu#a;XJwE;9S1?#R&uns>^0G3p`hEUF*v`M?@h%T%J%RChmD|EVydq zmHWh*_=S%emRC*mhxaVLzT@>Z2SX0u9v*DIJ@WC^kLVdlGV6LpK$KIrlJqc zpJ921)+3JJdTx|<`G&kXpKkjGJv=76R`yYIQ{#c-`%+`#V(7}Q;&@6U8!Td1`d;?N z_9mnI#?AA}4J!r)LN4!E-@H5eXauuB7TOawS>Y|{-P?NNx-lq+z1W-+y(;39P&&LP zL{N80?&=C*qKmdA^moMZRuPcD!B<*mq$ch=0Cnlitw#txRWhb3%TQvPqjkC`F69G4b! ze7z9MZ#+;_#l?H37UqUhDFb^l&s2{oM$3I0o^Q!yx;;V)QmCMo)Tb_ui|mit8MS?U zm##6$sZZ1$@|s%?l@>4Z<*Q}sRBSKMhb4I{e5LdEhsHIHTe8Bod5c>6QtT>$XgUBz z6MK`kO$=jmt@FqggOhJ5j~e@ygRbG;<{Vu)*+nn9aQeo0;$#j;|MS=S$&L?BeV25z xs3B`@=#`5TF{^6(A1rvdY@|-RtQ|iS5{tyX+wH?;n8E)G$kykv-D^wh{{!TZT%7;_ literal 0 HcmV?d00001 diff --git a/test/TestApps/ToastNotificationsDemoPackage/Images/Square44x44Logo.targetsize-24_altform-unplated.png b/test/TestApps/ToastNotificationsDemoPackage/Images/Square44x44Logo.targetsize-24_altform-unplated.png new file mode 100644 index 0000000000000000000000000000000000000000..f6c02ce97e0a802b85f6021e822c89f8bf57d5cd GIT binary patch literal 1255 zcmaJ>TWs4@7*5+{G#S+&C!qC#> zf>5N3P6jO*Cz>ug*(_DmW=)kea&m$gZ^+nyiF`;j%w@}y8)>p*SH}C`m?DXeieF2U zyQHecc_L%Gh!7GMt+hG06y;+|p4>m~}PjA}rKViGiEnn7G0ZO<>G|7q;2?NwGCM3s?eued6%hd$B+ z*kQJ{#~$S=DFE(%=E+UkmlEI*%3llUf~8Ja9YU1Vui0IbGBkW_gHB%Rd&!!ioX zs40O?i9I{};kle7GMvE7(rk`la=gTI)47=>%?q@^iL-nUo3}h4S}N-KHn8t5mVP8w z&bSErwp+37 zNJJ8?a|{r5Q3R0Z5s-LB1WHOwYC@7pCHWND#cL1cZ?{kJ368_*(UDWUDyb<}0y@o# zfMF016iMWPCb6obAxT$JlB6(2DrlXDTB&!0`!m??4F(qWMhjVZo?JXQmz`1*58Z=& zcDmB|S-E@j?BoFGix0flckqdS4jsPNzhfWyWIM98GxcLs89C(~dw%$_t;JjX-SD}E zfiGV;{8Q%8r}w9x>EEigW81>`kvnU@pK)4+xk9@+bNj9L!AAZ@SZ@q|)&BmY3+HZx zul~BeG4|}-;L%cHViQGQX?^zFfO0&#cHwel=d`lH9sJ-@Sl@n*(8J2>%Ac`IxyY?Q z{=GhWvC#gu-~Ia7*n{=+;qM?Ul_wy1+u7ho;=`>EwP^g~R@{unBds`!#@}tluZQpS zm)M~nYEifJWJGx?_6DcTy>#uh%>!H9=hb^(v`=m3F1{L>db=<5_tm+_&knAQ2EU$s Mu9UqpbNZeC0BbUo^Z)<= literal 0 HcmV?d00001 diff --git a/test/TestApps/ToastNotificationsDemoPackage/Images/StoreLogo.png b/test/TestApps/ToastNotificationsDemoPackage/Images/StoreLogo.png new file mode 100644 index 0000000000000000000000000000000000000000..7385b56c0e4d3c6b0efe3324aa1194157d837826 GIT binary patch literal 1451 zcmaJ>eN5D57_Z|bH;{0+1#mbl)eTU3{h)Wf7EZV?;HD@XL@{B`Ui%(2aMxQ~xdXSv z5nzWi(LW)U2=Vc-cY@s7nPt{i0hc6!7xN4NNHI#EQl>YNBy8l4%x9gr_W-j zEZMQmmTIy(>;lblRfh`dIyTgc9W5d!VP$L4(kKrN1c5G~(O_#xG zAJCNTstD^5SeXFB+&$h=ToJP2H>xr$iqPs-#O*;4(!Fjw25-!gEb*)mU}=)J;Iu>w zxK(5XoD0wrPSKQ~rbL^Cw6O_03*l*}i=ydbu7adJ6y;%@tjFeXIXT+ms30pmbOP%Q zX}S;+LBh8Tea~TSkHzvX6$rYb)+n&{kSbIqh|c7hmlxmwSiq5iVhU#iEQ<>a18|O^Sln-8t&+t`*{qBWo5M?wFM(JuimAOb5!K#D}XbslM@#1ZVz_;!9U zpfEpLAOz=0g@bd6Xj_ILi-x^!M}73h^o@}hM$1jflTs|Yuj9AL@A3<-?MV4!^4q`e z)fO@A;{9K^?W?DbnesnPr6kK>$zaKo&;FhFd(GYFCIU^T+OIMb%Tqo+P%oq(IdX7S zf6+HLO?7o0m+p>~Tp5UrXWh!UH!wZ5kv!E`_w)PTpI(#Iw{AS`gH4^b(bm^ZCq^FZ zY9DD7bH}rq9mg88+KgA$Zp!iWncuU2n1AuIa@=sWvUR-s`Qb{R*kk(SPU^`$6BXz8 zn#7yaFOIK%qGxyi`dYtm#&qqox0$h=pNi#u=M8zUG@bpiZ=3sT=1}Trr}39cC)H|v zbL?W)=&s4zrh)7>L(|cc%$1#!zfL?HjpeP%T+x_a+jZ16b^iKOHxFEX$7d|8${H-* zIrOJ5w&i$>*D>AKaIoYg`;{L@jM((Kt?$N$5OnuPqVvq**Nm}(f0wwOF%iX_Pba;V z;m@wxX&NcV3?<1+u?A{y_DIj7#m3Af1rCE)o`D&Y3}0%7E;iX1yMDiS)sh0wKi!36 zL!Wmq?P^Ku&rK~HJd97KkLTRl>ScGFYZNlYytWnhmuu|)L&ND8_PmkayQb{HOY640 bno1(wj@u8DCVuFR|31B*4ek@pZJqxCDDe1x literal 0 HcmV?d00001 diff --git a/test/TestApps/ToastNotificationsDemoPackage/Images/Wide310x150Logo.scale-200.png b/test/TestApps/ToastNotificationsDemoPackage/Images/Wide310x150Logo.scale-200.png new file mode 100644 index 0000000000000000000000000000000000000000..288995b397fdbef1fb7e85afd71445d5de1952c5 GIT binary patch literal 3204 zcmbVPeQXow8NYmBd90>}0NP?GhXW~VaeThm=a0tV#EwJMI!)6M3}|c4_Bl3=Kd>G0 z(GHx1wl<7(tP?FsOQkTilSo*iIvF%uArExJ73~P zSv1xEy!U(Wd4A9D`FQV@W3@F^qJ@PEF$@z`Z!*BbFsS(^?B zyiAzJ+q})bkgiQHWqEb*jJD-coHYr1^iocg)l!Qa{Xqs-l~6J}p-|##ZHYofskQ3$ zI0;xzXyhazBeXhIsg5A=%ufo@f)1yy&ScKS0;HF^!r_2UE^lpZEom(+@duma3awTv zCrCL-%D_SvYWIcdHkmI}#50(fkUi)Qgx!80ju>g1za^}ff>JI8Z@^-iCiaCgg@TgF z+vtE?Q9{VQUX&MW9SYYmGcxA14%N2@7FwBTD4N<(2{nWgV8$e3?-F=L^&FrtWn~(U_Q~~^uYiyeY6-KoTnfh9AWz@ zIKje0)u!_Lw)E}G!#kEfwKVdNt(UAf9*f>tEL_(=xco-T%jTi@7YlC3hs2ik%Le0H ztj}RTeCF(5mwvi3_56>-yB?l;J>-1%!9~=fs|QcNG3J~a@JCu`4SB460s0ZO+##4fFUSGLcj_ja^fL4&BKALfb#$6$O?>P@qx2Agl^x0i&ugt zsy5Pyu=()`7HRMG3IB7F1@`_ z+-!J%#i6e^U$e#+C%Q>_qVRzWRsG^W_n+@OcX@vzI&z;mzHNb!GQ?LWA(wtpqHqTM z1OFw_{Zn?fD)p)`c`kOgv{de=v@suGRqY{N^U7gI1VF3*F=obwaXI6ob5__Yn zVTguS!%(NI09J8x#AO_aW!9W7k*UvB;IWDFC3srwftr{kHj%g)fvnAm;&h_dnl~

MY- zf+K}sCe8qU6Ujs`3ua{U0Of$R_gVQBuUA za0v=mu#vIOqiiAZOr&h*$WyOw&k-xr$;G4Ixa!#TJNr>95(h>l%)PUy4p+^SgR(uR zta%k*?ny-+nAr8spEk1fo{J4i!b^Fia`N{_F6@zidA2ZTTrjl#^5Z-2KfB@Cu}l9s z(*|Z2jc?p~vn2f)3y9i*7zJV1L{$?|&q)4oaT;uXi6>1GkRXVTOzAz(RHEmr=eFIi z`}<>-Q?K0GN8!IYxeP1XKXO+jsJbp~o^);Bc;%b7Flpe7;1`Ny@3r7ZR;?R)aJt8C ziNlEC<@3f_lIV4TwV}&e;D!Ee5_|e#g0LUh=5vmYWYm7&2h*M>QPKvGh9-)wfMMW3 z8J9b%1k7dzPzO0_NGQy92BZ^FR6R~6;^6?lqO;-QUP4BY%cG%3vEhbm#>4vIhPBh3 z-+pZGjh$x%Hp{?=FHsMp0&wNPlj00us{&`1ZOZTqs8%4X&xH=UDr*xyBW(Zp&Em94 zf)ZSfn#yg0N)>!1kWdkqJ^S*z0FF5|fj&qcE#Na|%OY0$uO>!&hP+1ywfD_WXk@4J(?MBftK7>$Nvqh@tDuarN%PrTLQ2Uzysx>UV=V zk^RrDSvdQ?0;=hY67EgII-f4`t=+i*yS=Y~!XlqIy_4x&%+OdfbKOFPXS2X5%4R{N z$SQMX^AK6(fA + + + + + + + Toast Notifications Win32 Demo App + Microsoft Corporation + Images\StoreLogo.png + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + WindowsAppRuntimeTestProtocol + + + + + + + + + + + + + + + + + + diff --git a/test/TestApps/ToastNotificationsDemoPackage/ToastNotificationsDemoPackage.wapproj b/test/TestApps/ToastNotificationsDemoPackage/ToastNotificationsDemoPackage.wapproj new file mode 100644 index 0000000000..cd4c7b8c49 --- /dev/null +++ b/test/TestApps/ToastNotificationsDemoPackage/ToastNotificationsDemoPackage.wapproj @@ -0,0 +1,88 @@ + + + + 15.0 + + + + Debug + x86 + + + Release + x86 + + + Debug + x64 + + + Release + x64 + + + Debug + ARM64 + + + Release + ARM64 + + + + $(MSBuildExtensionsPath)\Microsoft\DesktopBridge\ + + + + e695a08e-8735-41cd-ae55-a5b589ba297f + 10.0.19041.0 + 10.0.17763.0 + en-US + True + ..\ToastNotificationsDemoApp\ToastNotificationsDemoApp.vcxproj + true + False + $(SolutionDir)temp\MSTest.pfx + SHA256 + True + True + $(Platform) + 0 + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + + Designer + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/ToastNotificationTests/APITests.cpp b/test/ToastNotificationTests/APITests.cpp index a181eecfee..0b1f2b3afe 100644 --- a/test/ToastNotificationTests/APITests.cpp +++ b/test/ToastNotificationTests/APITests.cpp @@ -51,6 +51,7 @@ namespace Test::ToastNotifications { // Cleanup previous installations. Need this to remove any manual installations outside of running this tests. TP::RemovePackage(GetTestPackageFullName()); + TP::RemovePackage_PushNotificationsLongRunningTask(); TP::RemovePackage_DynamicDependencyLifetimeManager(); TP::RemovePackage_DynamicDependencyDataStore(); TP::RemovePackage_WindowsAppRuntimeFramework(); @@ -58,6 +59,7 @@ namespace Test::ToastNotifications TP::AddPackage_WindowsAppRuntimeFramework(); // Installs WARfwk TP::AddPackage_DynamicDependencyDataStore(); // Installs WARmain TP::AddPackage_DynamicDependencyLifetimeManager(); // Installs WARddlm + TP::AddPackage_PushNotificationsLongRunningTask(); // Installs the PushNotifications long running task. TP::WapProj::AddPackage(TAEF::GetDeploymentDir(), GetTestPackageFile(), L".msix"); // Installs ToastNotificationsTestApp.msix } catch (...) @@ -76,6 +78,7 @@ namespace Test::ToastNotifications { // Remove in reverse order to avoid conflicts between inter-dependent packages. TP::RemovePackage(GetTestPackageFullName()); + TP::RemovePackage_PushNotificationsLongRunningTask(); TP::RemovePackage_DynamicDependencyLifetimeManager(); TP::RemovePackage_DynamicDependencyDataStore(); TP::RemovePackage_WindowsAppRuntimeFramework(); From 81b592184c01be27031a218cc7b7d9fe8c2cdd73 Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Tue, 25 Jan 2022 18:15:25 -0800 Subject: [PATCH 08/25] Current iteration --- .../ToastNotificationsDemoApp.vcxproj | 5 ++++- test/TestApps/ToastNotificationsDemoApp/main.cpp | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/test/TestApps/ToastNotificationsDemoApp/ToastNotificationsDemoApp.vcxproj b/test/TestApps/ToastNotificationsDemoApp/ToastNotificationsDemoApp.vcxproj index a40f5cacb3..93faa3dee0 100644 --- a/test/TestApps/ToastNotificationsDemoApp/ToastNotificationsDemoApp.vcxproj +++ b/test/TestApps/ToastNotificationsDemoApp/ToastNotificationsDemoApp.vcxproj @@ -276,4 +276,7 @@ - + + + + \ No newline at end of file diff --git a/test/TestApps/ToastNotificationsDemoApp/main.cpp b/test/TestApps/ToastNotificationsDemoApp/main.cpp index 373242d37f..ea018cbca3 100644 --- a/test/TestApps/ToastNotificationsDemoApp/main.cpp +++ b/test/TestApps/ToastNotificationsDemoApp/main.cpp @@ -5,6 +5,7 @@ #include #include #include "WindowsAppRuntime.Test.AppModel.h" +#include using namespace winrt::Microsoft::Windows::AppLifecycle; using namespace winrt::Microsoft::Windows::PushNotifications; @@ -106,6 +107,13 @@ int main() { // Retrieve the app scenario. bool isPackaged{ Test::AppModel::IsPackagedProcess() }; + if (!isPackaged) + { + // Major.Minor version, MinVersion=0 to find any framework package for this major.minor version + const UINT32 c_Version_MajorMinor{ 0x00040001 }; + const PACKAGE_VERSION minVersion{}; + RETURN_IF_FAILED(MddBootstrapInitialize(c_Version_MajorMinor, nullptr, minVersion)); + } std::wcout << L"--------------------------------" << std::endl; std::wcout << L"- Toast Notifications Demo App -" << std::endl; @@ -183,5 +191,11 @@ int main() std::wcout << L"Press enter to exit the app." << std::endl << std::endl; std::cin.ignore(); + + toastNotificationManager.UnregisterActivator(); + if (!isPackaged) + { + MddBootstrapShutdown(); + } return 0; } From 5a6dcbf2c0146c00bc7e4a468703ee1f5933ec55 Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Wed, 26 Jan 2022 09:53:29 -0800 Subject: [PATCH 09/25] Adding DelayLoad Bootstrap.dll to make app hybrid --- .../ToastNotificationsDemoApp.vcxproj | 6 ++++++ test/TestApps/ToastNotificationsDemoApp/main.cpp | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/test/TestApps/ToastNotificationsDemoApp/ToastNotificationsDemoApp.vcxproj b/test/TestApps/ToastNotificationsDemoApp/ToastNotificationsDemoApp.vcxproj index 93faa3dee0..c99bb7f773 100644 --- a/test/TestApps/ToastNotificationsDemoApp/ToastNotificationsDemoApp.vcxproj +++ b/test/TestApps/ToastNotificationsDemoApp/ToastNotificationsDemoApp.vcxproj @@ -133,6 +133,7 @@ Console %(AdditionalLibraryDirectories);$(OutDir)\..\WindowsAppRuntime_DLL onecore.lib;onecoreuap.lib;Microsoft.WindowsAppRuntime.lib;%(AdditionalDependencies) + Microsoft.WindowsAppRuntime.Bootstrap.dll;%(DelayLoadDLLs) @@ -153,6 +154,7 @@ true %(AdditionalLibraryDirectories);$(OutDir)\..\WindowsAppRuntime_DLL onecore.lib;onecoreuap.lib;Microsoft.WindowsAppRuntime.lib;%(AdditionalDependencies) + Microsoft.WindowsAppRuntime.Bootstrap.dll;%(DelayLoadDLLs) @@ -169,6 +171,7 @@ Console %(AdditionalLibraryDirectories);$(OutDir)\..\WindowsAppRuntime_DLL onecore.lib;onecoreuap.lib;Microsoft.WindowsAppRuntime.lib;%(AdditionalDependencies) + Microsoft.WindowsAppRuntime.Bootstrap.dll;%(DelayLoadDLLs) @@ -189,6 +192,7 @@ true %(AdditionalLibraryDirectories);$(OutDir)\..\WindowsAppRuntime_DLL onecore.lib;onecoreuap.lib;Microsoft.WindowsAppRuntime.lib;%(AdditionalDependencies) + Microsoft.WindowsAppRuntime.Bootstrap.dll;%(DelayLoadDLLs) @@ -205,6 +209,7 @@ Console %(AdditionalLibraryDirectories);$(OutDir)\..\WindowsAppRuntime_DLL onecore.lib;onecoreuap.lib;Microsoft.WindowsAppRuntime.lib;%(AdditionalDependencies) + Microsoft.WindowsAppRuntime.Bootstrap.dll;%(DelayLoadDLLs) @@ -225,6 +230,7 @@ true %(AdditionalLibraryDirectories);$(OutDir)\..\WindowsAppRuntime_DLL onecore.lib;onecoreuap.lib;Microsoft.WindowsAppRuntime.lib;%(AdditionalDependencies) + Microsoft.WindowsAppRuntime.Bootstrap.dll;%(DelayLoadDLLs) diff --git a/test/TestApps/ToastNotificationsDemoApp/main.cpp b/test/TestApps/ToastNotificationsDemoApp/main.cpp index ea018cbca3..84cd0717a7 100644 --- a/test/TestApps/ToastNotificationsDemoApp/main.cpp +++ b/test/TestApps/ToastNotificationsDemoApp/main.cpp @@ -192,7 +192,8 @@ int main() std::wcout << L"Press enter to exit the app." << std::endl << std::endl; std::cin.ignore(); - toastNotificationManager.UnregisterActivator(); + // If you want to stop receiving ToastNotifications for the app + /* toastNotificationManager.UnregisterActivator(); */ if (!isPackaged) { MddBootstrapShutdown(); From 6329259a8089593e2602745fc20778a9a7e8c5bd Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Sat, 29 Jan 2022 20:24:25 -0800 Subject: [PATCH 10/25] Update PushNotificationManager.cpp --- .../PushNotificationManager.cpp | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/dev/PushNotifications/PushNotificationManager.cpp b/dev/PushNotifications/PushNotificationManager.cpp index 1574368a5d..8dc13d97c5 100644 --- a/dev/PushNotifications/PushNotificationManager.cpp +++ b/dev/PushNotifications/PushNotificationManager.cpp @@ -89,22 +89,15 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation THROW_IF_FAILED(notificationPlatform->RegisterFullTrustApplication(processName.get(), remoteId, &unpackagedAppUserModelId)); } - winrt::hresult CreateChannelWithRemoteIdHelper(const winrt::guid& remoteId, ChannelDetails& channelInfo) noexcept try + winrt::hresult CreateChannelWithRemoteIdHelper(wil::unique_cotaskmem_string const& appUserModelId, const winrt::guid& remoteId, ChannelDetails& channelInfo) noexcept try { - wchar_t appUserModelId[APPLICATION_USER_MODEL_ID_MAX_LENGTH] = {}; - UINT32 appUserModelIdSize{ ARRAYSIZE(appUserModelId) }; - - THROW_IF_FAILED(GetCurrentApplicationUserModelId(&appUserModelIdSize, appUserModelId)); - - THROW_HR_IF(E_INVALIDARG, (appUserModelIdSize > APPLICATION_USER_MODEL_ID_MAX_LENGTH) || (appUserModelIdSize == 0)); - HRESULT operationalCode{}; ABI::Windows::Foundation::DateTime channelExpiryTime{}; wil::unique_cotaskmem_string channelId; wil::unique_cotaskmem_string channelUri; THROW_IF_FAILED(PushNotifications_CreateChannelWithRemoteIdentifier( - appUserModelId, + appUserModelId.get(), remoteId, &operationalCode, &channelId, @@ -114,7 +107,7 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation THROW_IF_FAILED(operationalCode); winrt::copy_from_abi(channelInfo.channelExpiryTime, &channelExpiryTime); - channelInfo.appUserModelId = winrt::hstring{ appUserModelId }; + channelInfo.appUserModelId = winrt::hstring{ appUserModelId.get() }; channelInfo.channelId = winrt::hstring{ channelId.get() }; channelInfo.channelUri = winrt::hstring{ channelUri.get() }; @@ -157,8 +150,9 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation { if (IsActivatorSupported(PushNotificationRegistrationActivators::PushTrigger)) { + auto appUserModelId{ PushNotificationHelpers::GetAppUserModelId() }; ChannelDetails channelInfo{}; - winrt::hresult hr = CreateChannelWithRemoteIdHelper(remoteId, channelInfo); + winrt::hresult hr{ CreateChannelWithRemoteIdHelper(appUserModelId, remoteId, channelInfo) }; // RemoteId APIs are not applicable for downlevel OS versions. // So we get error E_NOTIMPL and we fallback to calling into @@ -198,8 +192,9 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation { wil::unique_cotaskmem_string unpackagedAppUserModelId; RegisterUnpackagedApplicationHelper(remoteId, unpackagedAppUserModelId); - PushNotificationChannelManager channelManager{}; - winrt::PushNotificationChannel pushChannelReceived{ co_await channelManager.CreatePushNotificationChannelForApplicationAsync(unpackagedAppUserModelId.get()) }; + + ChannelDetails channelInfo{}; + winrt::hresult hr{ CreateChannelWithRemoteIdHelper(unpackagedAppUserModelId, remoteId, channelInfo) }; auto notificationPlatform{ PushNotificationHelpers::GetNotificationPlatform() }; @@ -213,7 +208,7 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation PushNotificationTelemetry::ChannelRequestedByApi(S_OK, remoteId, usingLegacyImplementation); co_return winrt::make( - winrt::make(pushChannelReceived), + winrt::make(channelInfo), S_OK, PushNotificationChannelStatus::CompletedSuccess); } From a37642724026fa8b5d9bc6cadafd634e261d7c30 Mon Sep 17 00:00:00 2001 From: Paul Purifoy <33183370+pmpurifoy@users.noreply.github.com> Date: Wed, 2 Feb 2022 14:46:56 -0800 Subject: [PATCH 11/25] User/purifoypaul/rs5 packaged com activation (#2044) * Initial Commit * Working packaged background RS5 * Remove IRawSerializer * Update NotificationListener.cpp --- .../PushNotificationActivationInfo.cpp | 5 -- .../PushNotificationActivationInfo.h | 1 - .../PushNotificationBackgroundTask.cpp | 19 ++++++- .../PushNotificationManager.cpp | 11 +++- dev/PushNotifications/PushNotifications.idl | 4 +- .../NotificationsLongRunningProcess.idl | 2 +- .../NotificationListener.cpp | 21 +++++++- .../NotificationListener.h | 5 +- .../NotificationListenerManager.cpp | 12 ++--- .../NotificationListenerManager.h | 4 +- .../PushBackgroundTaskInstance.cpp | 53 +++++++++++++++++++ .../PushBackgroundTaskInstance.h | 34 ++++++++++++ .../PushNotificationsLongRunningTask.vcxproj | 2 + ...tificationsLongRunningTask.vcxproj.filters | 6 +++ .../PushNotificationsLongRunningTask/pch.h | 4 +- .../platform.cpp | 28 +++++++--- .../platform.h | 8 +-- dev/PushNotifications/externs.h | 17 +++++- .../PushNotificationsDemoApp/main.cpp | 6 +-- 19 files changed, 202 insertions(+), 40 deletions(-) create mode 100644 dev/PushNotifications/PushNotificationsLongRunningTask/PushBackgroundTaskInstance.cpp create mode 100644 dev/PushNotifications/PushNotificationsLongRunningTask/PushBackgroundTaskInstance.h diff --git a/dev/PushNotifications/PushNotificationActivationInfo.cpp b/dev/PushNotifications/PushNotificationActivationInfo.cpp index 342168ae12..79a5d3bbfb 100644 --- a/dev/PushNotifications/PushNotificationActivationInfo.cpp +++ b/dev/PushNotifications/PushNotificationActivationInfo.cpp @@ -20,11 +20,6 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation THROW_HR_IF(E_NOTIMPL, !::Microsoft::Windows::PushNotifications::Feature_PushNotifications::IsEnabled()); } - PushNotificationActivationInfo::PushNotificationActivationInfo(winrt::PushNotificationRegistrationActivators const& activators) : m_activators(activators), m_taskClsid(GUID_NULL) - { - THROW_HR_IF(E_NOTIMPL, !::Microsoft::Windows::PushNotifications::Feature_PushNotifications::IsEnabled()); - } - winrt::guid PushNotificationActivationInfo::TaskClsid() { return m_taskClsid; diff --git a/dev/PushNotifications/PushNotificationActivationInfo.h b/dev/PushNotifications/PushNotificationActivationInfo.h index 92b80af662..84f4201a6b 100644 --- a/dev/PushNotifications/PushNotificationActivationInfo.h +++ b/dev/PushNotifications/PushNotificationActivationInfo.h @@ -9,7 +9,6 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation struct PushNotificationActivationInfo : PushNotificationActivationInfoT { PushNotificationActivationInfo(Microsoft::Windows::PushNotifications::PushNotificationRegistrationActivators const& activators, winrt::guid const& taskClsid); - PushNotificationActivationInfo(Microsoft::Windows::PushNotifications::PushNotificationRegistrationActivators const& activators); winrt::guid TaskClsid(); Microsoft::Windows::PushNotifications::PushNotificationRegistrationActivators Activators(); diff --git a/dev/PushNotifications/PushNotificationBackgroundTask.cpp b/dev/PushNotifications/PushNotificationBackgroundTask.cpp index 0064416ede..2ad3eb60d5 100644 --- a/dev/PushNotifications/PushNotificationBackgroundTask.cpp +++ b/dev/PushNotifications/PushNotificationBackgroundTask.cpp @@ -12,6 +12,12 @@ #include "PushNotificationReceivedEventArgs.h" #include "externs.h" +#include "PushNotificationUtility.h" + +namespace PushNotificationHelpers +{ + using namespace winrt::Microsoft::Windows::PushNotifications::Helpers; +} namespace winrt { @@ -23,8 +29,17 @@ namespace winrt void PushNotificationBackgroundTask::Run(winrt::IBackgroundTaskInstance const& taskInstance) { auto appProperties = winrt::CoreApplication::Properties(); - winrt::PushNotificationReceivedEventArgs activatedEventArgs = winrt::make(taskInstance); - appProperties.Insert(ACTIVATED_EVENT_ARGS_KEY, activatedEventArgs); + if (PushNotificationHelpers::IsPackagedAppScenario()) + { + winrt::PushNotificationReceivedEventArgs activatedEventArgs{ winrt::make(taskInstance) }; + appProperties.Insert(ACTIVATED_EVENT_ARGS_KEY, activatedEventArgs); + } + else + { + winrt::hstring payload{ winrt::unbox_value(taskInstance.TriggerDetails()) }; + winrt::PushNotificationReceivedEventArgs activatedEventArgs{ winrt::make(payload.c_str()) }; + appProperties.Insert(UNPACKAGED_EVENT_ARGS_KEY, activatedEventArgs); + } SetEvent(GetWaitHandleForArgs().get()); } diff --git a/dev/PushNotifications/PushNotificationManager.cpp b/dev/PushNotifications/PushNotificationManager.cpp index 8dc13d97c5..99127ece5f 100644 --- a/dev/PushNotifications/PushNotificationManager.cpp +++ b/dev/PushNotifications/PushNotificationManager.cpp @@ -49,6 +49,7 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation static winrt::Windows::ApplicationModel::Background::IBackgroundTaskRegistration s_pushTriggerRegistration{ nullptr }; static wil::unique_com_class_object_cookie s_comActivatorRegistration; static bool s_protocolRegistration{ false }; + static winrt::guid s_taskClsid{ GUID_NULL }; static wil::srwlock s_activatorInfoLock; inline constexpr auto c_maxBackoff{ 5min }; @@ -200,7 +201,7 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation wil::unique_cotaskmem_string processName; THROW_IF_FAILED(GetCurrentProcessPath(processName)); - THROW_IF_FAILED(notificationPlatform->RegisterLongRunningActivator(processName.get())); + THROW_IF_FAILED(notificationPlatform->RegisterLongRunningActivator(processName.get(), s_taskClsid)); std::wstring toastAppId{ RetrieveToastAppId() }; THROW_IF_FAILED(notificationPlatform->AddToastRegistrationMapping(processName.get(), toastAppId.c_str())); @@ -269,9 +270,17 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation THROW_HR_IF(E_INVALIDARG, s_protocolRegistration); } + s_taskClsid = details.TaskClsid(); wil::unique_cotaskmem_string unpackagedAppUserModelId; RegisterUnpackagedApplicationHelper(GUID_NULL, unpackagedAppUserModelId); // create default registration for app + THROW_IF_FAILED(::CoRegisterClassObject( + s_taskClsid, + winrt::make().get(), + CLSCTX_LOCAL_SERVER, + REGCLS_MULTIPLEUSE, + &s_comActivatorRegistration)); + { auto lock = s_activatorInfoLock.lock_exclusive(); s_protocolRegistration = true; diff --git a/dev/PushNotifications/PushNotifications.idl b/dev/PushNotifications/PushNotifications.idl index 7e41a286ab..e3c978de98 100644 --- a/dev/PushNotifications/PushNotifications.idl +++ b/dev/PushNotifications/PushNotifications.idl @@ -39,11 +39,9 @@ namespace Microsoft.Windows.PushNotifications // Initialize using a Registration option and optionally defined parameters like manifest defined activatorId // 1) If kind = PushTrigger is specified, only the Push Trigger will be Registered with Background Infra // 2) If kind = ComActivator is specified, the Background Task component will be Registered as an in-process COM server + // 3) If kind = ProtocolActivator is specified, the LRP will CoCreateInstance the application in background scenarios PushNotificationActivationInfo(PushNotificationRegistrationActivators activators, Guid taskClsid); - // Applications that need to use ProtocolActivator will use this constructor - PushNotificationActivationInfo(PushNotificationRegistrationActivators activators); - // The CLSID associated with the Client COM server that Windows App SDK will activate Guid TaskClsid{ get; }; diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask.ProxyStub/NotificationsLongRunningProcess.idl b/dev/PushNotifications/PushNotificationsLongRunningTask.ProxyStub/NotificationsLongRunningProcess.idl index 9011a91b7b..d2018e0427 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask.ProxyStub/NotificationsLongRunningProcess.idl +++ b/dev/PushNotifications/PushNotificationsLongRunningTask.ProxyStub/NotificationsLongRunningProcess.idl @@ -19,7 +19,7 @@ interface IWpnForegroundSink : IUnknown [pointer_default(unique)] interface INotificationsLongRunningPlatform : IUnknown { - HRESULT RegisterLongRunningActivator([in] LPCWSTR processName); + HRESULT RegisterLongRunningActivator([in] LPCWSTR processName, [in] GUID comServerClsid); HRESULT UnregisterLongRunningActivator([in] LPCWSTR processName); diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListener.cpp b/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListener.cpp index 373d52db02..e144394e3c 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListener.cpp +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListener.cpp @@ -2,7 +2,10 @@ #include "pch.h" #include "../PushNotificationUtility.h" +#include +#include "PushBackgroundTaskInstance.h" +using namespace winrt::Windows::ApplicationModel::Background; namespace ToastNotifications { using namespace ABI::Microsoft::Internal::ToastNotifications; @@ -12,10 +15,12 @@ HRESULT NotificationListener::RuntimeClassInitialize( std::shared_ptr foregroundSinkManager, std::shared_ptr toastRegistrationManager, std::wstring const& appId, - std::wstring const& processName) noexcept try + std::wstring const& processName, + winrt::guid const& comServerClsid) noexcept try { m_foregroundSinkManager = foregroundSinkManager; m_toastRegistrationManager = toastRegistrationManager; + m_comServerClsid = comServerClsid; m_appId = appId; m_processName = processName; @@ -32,7 +37,19 @@ STDMETHODIMP_(HRESULT __stdcall) NotificationListener::OnRawNotificationReceived if (!m_foregroundSinkManager->InvokeForegroundHandlers(m_appId, payloadArray, payloadLength)) { - THROW_IF_FAILED(winrt::Microsoft::Windows::PushNotifications::Helpers::ProtocolLaunchHelper(m_processName, payloadLength, payload)); + if (m_comServerClsid == winrt::guid()) + { + THROW_IF_FAILED(winrt::Microsoft::Windows::PushNotifications::Helpers::ProtocolLaunchHelper(m_processName, payloadLength, payload)); + } + else + { + std::wstring payloadString(payloadArray.begin(), payloadArray.end()); + + auto localBackgroundTask = winrt::create_instance(m_comServerClsid, CLSCTX_ALL); + auto pushBackgroundTaskInstance{ winrt::make_self() }; + pushBackgroundTaskInstance->SetRawNotificationPayload(payloadString); + localBackgroundTask.Run(*pushBackgroundTaskInstance); + } }; return S_OK; diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListener.h b/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListener.h index 6bccf8193f..a20f676b26 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListener.h +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListener.h @@ -12,7 +12,8 @@ class NotificationListener : public Microsoft::WRL::RuntimeClass<::ABI::Microsof std::shared_ptr foregroundSinkManager, std::shared_ptr toastRegistrationManager, std::wstring const& appId, - std::wstring const& processName) noexcept; + std::wstring const& processName, + winrt::guid const& comServerClsid) noexcept; STDMETHOD(OnRawNotificationReceived)(unsigned int payloadLength, _In_ byte* payload, _In_ HSTRING correlationVector) noexcept; STDMETHOD(OnToastNotificationReceived)(ABI::Microsoft::Internal::ToastNotifications::INotificationProperties* notificationProperties, @@ -23,6 +24,6 @@ class NotificationListener : public Microsoft::WRL::RuntimeClass<::ABI::Microsof std::wstring m_appId; std::wstring m_processName; - + winrt::guid m_comServerClsid; wil::srwlock m_lock; }; diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListenerManager.cpp b/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListenerManager.cpp index b11fae0753..c0dee8ac45 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListenerManager.cpp +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListenerManager.cpp @@ -9,26 +9,24 @@ void NotificationListenerManager::Initialize(std::shared_ptr& appIdList) +void NotificationListenerManager::SetAppIdMapping(std::map>& appIdList) { for (auto appData : appIdList) { - AddListener(appData.first, appData.second); + AddListener(appData.first, appData.second.first, appData.second.second); } } -void NotificationListenerManager::AddListener(std::wstring const& appId, std::wstring const& processName) +void NotificationListenerManager::AddListener(std::wstring const& appId, std::wstring const& processName, winrt::guid const& comServerClsid) { THROW_HR_IF(E_INVALIDARG, appId.empty()); - THROW_HR_IF(E_INVALIDARG, processName.empty()); - - + THROW_HR_IF(E_INVALIDARG, processName.empty()); // Make sure we keep the long running sink up-to-date with wpncore. ComPtr newListener; { auto lock{ m_lock.lock_shared() }; - THROW_IF_FAILED(MakeAndInitialize(&newListener, m_foregroundSinkManager, m_toastRegistrationManager, appId, processName)); + THROW_IF_FAILED(MakeAndInitialize(&newListener, m_foregroundSinkManager, m_toastRegistrationManager, appId, processName, comServerClsid)); } THROW_IF_FAILED(PushNotifications_RegisterNotificationSinkForFullTrustApplication(appId.c_str(), newListener.Get())); diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListenerManager.h b/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListenerManager.h index 3a7e906842..a0f43718a6 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListenerManager.h +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListenerManager.h @@ -12,9 +12,9 @@ class NotificationListenerManager // This function has to be called after initializing the ForegroundSinkManager during Platform initialization void Initialize(std::shared_ptr foregroundSinkManager, std::shared_ptr toastRegistrationManager); - void SetAppIdMapping(std::map& appIdList); + void SetAppIdMapping(std::map>& appIdList); - void AddListener(std::wstring const& appId, std::wstring const& processName); + void AddListener(std::wstring const& appId, std::wstring const& processName, winrt::guid const& comServerClsid); void RemoveListener(std::wstring appId); bool IsEmpty(); diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/PushBackgroundTaskInstance.cpp b/dev/PushNotifications/PushNotificationsLongRunningTask/PushBackgroundTaskInstance.cpp new file mode 100644 index 0000000000..a5a4665b7f --- /dev/null +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/PushBackgroundTaskInstance.cpp @@ -0,0 +1,53 @@ +#pragma once + +#include "pch.h" + +#include "PushBackgroundTaskInstance.h" +#include + +using namespace winrt::Windows::Networking::PushNotifications; + +winrt::guid PushBackgroundTaskInstance::InstanceId() +{ + return winrt::guid(); +} + +UINT32 PushBackgroundTaskInstance::SuspendedCount() +{ + return 0; +} + +UINT32 PushBackgroundTaskInstance::Progress() +{ + return 0; +} + +UINT32 PushBackgroundTaskInstance::Progress(UINT32 progress) +{ + return 0; +} + +winrt::Windows::ApplicationModel::Background::BackgroundTaskRegistration PushBackgroundTaskInstance::Task() +{ + return nullptr; +} + +winrt::event_token PushBackgroundTaskInstance::Canceled(winrt::Windows::ApplicationModel::Background::BackgroundTaskCanceledEventHandler const& handler) +{ + return winrt::event_token{}; +} + +void PushBackgroundTaskInstance::Canceled(winrt::event_token const& token) noexcept +{ + return; +} + +winrt::Windows::ApplicationModel::Background::BackgroundTaskDeferral PushBackgroundTaskInstance::GetDeferral() +{ + return nullptr; +} + +winrt::Windows::Foundation::IInspectable PushBackgroundTaskInstance::TriggerDetails() +{ + return winrt::box_value(m_payload); +} diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/PushBackgroundTaskInstance.h b/dev/PushNotifications/PushNotificationsLongRunningTask/PushBackgroundTaskInstance.h new file mode 100644 index 0000000000..3dd5276a2e --- /dev/null +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/PushBackgroundTaskInstance.h @@ -0,0 +1,34 @@ +#include + +struct PushBackgroundTaskInstance : winrt::implements +{ + PushBackgroundTaskInstance() {}; + + winrt::guid InstanceId(); + UINT32 SuspendedCount(); + UINT32 Progress(); + UINT32 Progress(UINT32 progress); + winrt::Windows::ApplicationModel::Background::BackgroundTaskRegistration Task(); + winrt::Windows::Foundation::IInspectable TriggerDetails(); + winrt::event_token Canceled(winrt::Windows::ApplicationModel::Background::BackgroundTaskCanceledEventHandler const& handler); + void Canceled(winrt::event_token const& token) noexcept; + winrt::Windows::ApplicationModel::Background::BackgroundTaskDeferral GetDeferral(); + + void SetRawNotificationPayload(std::wstring const& payload) { m_payload = payload; }; +private: + std::wstring m_payload; +}; + +struct PushBackgroundTaskInstanceFactory : winrt::implements +{ + HRESULT __stdcall CreateInstance(_In_opt_ IUnknown* aggregateInterface, _In_ REFIID interfaceId, _Outptr_ VOID** object) noexcept final + { + RETURN_HR_IF(CLASS_E_NOAGGREGATION, aggregateInterface != nullptr); + return winrt::make().as(interfaceId, object); + } + + HRESULT __stdcall LockServer(BOOL) noexcept final + { + return S_OK; + } +}; diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj b/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj index e5b654a7eb..9ab65f3f0d 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj @@ -232,6 +232,7 @@ + @@ -243,6 +244,7 @@ + diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj.filters b/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj.filters index 5a66aedcae..e550c16df5 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj.filters +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj.filters @@ -39,6 +39,9 @@ Header Files + + Source Files + @@ -68,6 +71,9 @@ Source Files + + Source Files + diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/pch.h b/dev/PushNotifications/PushNotificationsLongRunningTask/pch.h index 06a9eae8b1..d81dbb7f94 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/pch.h +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/pch.h @@ -22,7 +22,9 @@ #include #include - +#include +#include +#include #include #include diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/platform.cpp b/dev/PushNotifications/PushNotificationsLongRunningTask/platform.cpp index 7c595459ad..8a2418c923 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/platform.cpp +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/platform.cpp @@ -23,6 +23,9 @@ void NotificationsLongRunningPlatformImpl::Initialize() m_rawStorage = Storage::ApplicationData::Current().LocalSettings().CreateContainer( L"Raw", Storage::ApplicationDataCreateDisposition::Always); + m_comServerClsidStorage = Storage::ApplicationData::Current().LocalSettings().CreateContainer( + L"ComServerClsid", Storage::ApplicationDataCreateDisposition::Always); + m_foregroundSinkManager = std::make_shared(); m_toastRegistrationManager = std::make_shared(); @@ -73,7 +76,7 @@ STDMETHODIMP_(HRESULT __stdcall) NotificationsLongRunningPlatformImpl::RegisterF } CATCH_RETURN() -STDMETHODIMP_(HRESULT __stdcall) NotificationsLongRunningPlatformImpl::RegisterLongRunningActivator(_In_ PCWSTR processName) noexcept try +STDMETHODIMP_(HRESULT __stdcall) NotificationsLongRunningPlatformImpl::RegisterLongRunningActivator(_In_ PCWSTR processName, GUID comServerClsid) noexcept try { auto lock = m_lock.lock_shared(); THROW_HR_IF(WPN_E_PLATFORM_UNAVAILABLE, m_shutdown); @@ -85,7 +88,8 @@ STDMETHODIMP_(HRESULT __stdcall) NotificationsLongRunningPlatformImpl::RegisterL return S_OK; } - m_notificationListenerManager.AddListener(appId, processName); + AddComServerClsid(appId, comServerClsid); + m_notificationListenerManager.AddListener(appId, processName, comServerClsid); m_lifetimeManager.Cancel(); @@ -106,6 +110,7 @@ STDMETHODIMP_(HRESULT __stdcall) NotificationsLongRunningPlatformImpl::Unregiste m_foregroundSinkManager->Remove(appId); RemoveAppIdentifier(appId); + RemoveComServerClsid(appId); RemoveToastHelper(processName); } @@ -182,9 +187,9 @@ CATCH_RETURN() // Returns a map of key-value pairs, where key is appId and value is processName. // It should only be called by Initialize(), which already acquired a lock. -std::map NotificationsLongRunningPlatformImpl::GetFullTrustApps() +std::map> NotificationsLongRunningPlatformImpl::GetFullTrustApps() { - std::map mapOfFullTrustApps; + std::map> mapOfFullTrustApps; // Get list of full trust apps with valid channels from wpncore wil::unique_cotaskmem_array_ptr appIds; @@ -192,13 +197,14 @@ std::map NotificationsLongRunningPlatformImpl::GetFu // Get list of apps from Storage auto values{ m_rawStorage.Values() }; - + auto comServerClsidValues{ m_comServerClsidStorage.Values() }; for (size_t i = 0; i < appIds.size(); ++i) { if (values.HasKey(appIds[i])) { winrt::hstring processName{ winrt::unbox_value(values.Lookup(appIds[i])) }; - mapOfFullTrustApps.emplace(reinterpret_cast(appIds[i]), processName.c_str()); + winrt::guid comServerClsid{ winrt::unbox_value(comServerClsidValues.Lookup(appIds[i])) }; + mapOfFullTrustApps.emplace(reinterpret_cast(appIds[i]), std::pair{ processName.c_str(), comServerClsid }); } } @@ -240,6 +246,16 @@ const std::wstring NotificationsLongRunningPlatformImpl::BuildAppIdentifier(std: return guidStr.get(); } +void NotificationsLongRunningPlatformImpl::AddComServerClsid(std::wstring const& appId, winrt::guid const& comServerClsid) +{ + m_comServerClsidStorage.Values().Insert(appId, winrt::box_value(comServerClsid)); +} + +void NotificationsLongRunningPlatformImpl::RemoveComServerClsid(std::wstring const& appId) +{ + m_comServerClsidStorage.Values().Remove(appId); +} + void NotificationsLongRunningPlatformImpl::RemoveAppIdentifier(std::wstring const& appId) { m_rawStorage.Values().Remove(appId); diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/platform.h b/dev/PushNotifications/PushNotificationsLongRunningTask/platform.h index c7c3516254..303463c6a9 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/platform.h +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/platform.h @@ -15,7 +15,7 @@ struct __declspec(uuid(PUSHNOTIFICATIONS_IMPL_CLSID_STRING)) NotificationsLongRu STDMETHOD(RegisterFullTrustApplication)(_In_ PCWSTR processName, GUID remoteId, _Out_ PWSTR* appId) noexcept; - STDMETHOD(RegisterLongRunningActivator)(_In_ PCWSTR processName) noexcept; + STDMETHOD(RegisterLongRunningActivator)(_In_ PCWSTR processName, GUID comServerClsid) noexcept; STDMETHOD(UnregisterLongRunningActivator)(_In_ PCWSTR processName) noexcept; @@ -28,14 +28,16 @@ struct __declspec(uuid(PUSHNOTIFICATIONS_IMPL_CLSID_STRING)) NotificationsLongRu STDMETHOD(RemoveToastRegistrationMapping)(_In_ PCWSTR processName) noexcept; private: - std::map GetFullTrustApps(); + std::map> GetFullTrustApps(); const std::wstring GetAppIdentifier(std::wstring const& processName); const std::wstring BuildAppIdentifier(std::wstring const& processName); + void AddComServerClsid(std::wstring const& appId, winrt::guid const& comServerClsid); + void RemoveComServerClsid(std::wstring const& appId); void RemoveAppIdentifier(std::wstring const& processName); void RemoveToastHelper(std::wstring const& processName); winrt::Windows::Storage::ApplicationDataContainer m_rawStorage{ nullptr }; - + winrt::Windows::Storage::ApplicationDataContainer m_comServerClsidStorage{ nullptr }; wil::srwlock m_lock; bool m_initialized = false; diff --git a/dev/PushNotifications/externs.h b/dev/PushNotifications/externs.h index d0eb2d1b58..9ecb3a04b3 100644 --- a/dev/PushNotifications/externs.h +++ b/dev/PushNotifications/externs.h @@ -4,10 +4,17 @@ #pragma once #include "pch.h" #include +#include "PushNotificationUtility.h" wil::unique_event& GetWaitHandleForArgs(); inline const winrt::hstring ACTIVATED_EVENT_ARGS_KEY = L"GlobalActivatedEventArgs"; +inline const winrt::hstring UNPACKAGED_EVENT_ARGS_KEY = L"UnpackagedActivatedEventArgs"; + +namespace PushNotificationHelpers +{ + using namespace winrt::Microsoft::Windows::PushNotifications::Helpers; +} struct ChannelDetails { @@ -28,5 +35,13 @@ inline winrt::Windows::Foundation::IInspectable GetArgsFromComStore() THROW_HR_IF(HRESULT_FROM_WIN32(ERROR_TIMEOUT), !GetWaitHandleForArgs().wait(receiveArgsTimeoutInMSec)); // If COM static store was uninit, let it throw - return winrt::Windows::ApplicationModel::Core::CoreApplication::Properties().Lookup(ACTIVATED_EVENT_ARGS_KEY); + if (PushNotificationHelpers::IsPackagedAppScenario()) + { + return winrt::Windows::ApplicationModel::Core::CoreApplication::Properties().Lookup(ACTIVATED_EVENT_ARGS_KEY); + } + else + { + return winrt::Windows::ApplicationModel::Core::CoreApplication::Properties().Lookup(UNPACKAGED_EVENT_ARGS_KEY); + } + } diff --git a/test/TestApps/PushNotificationsDemoApp/main.cpp b/test/TestApps/PushNotificationsDemoApp/main.cpp index 03f1aafd64..0401c283aa 100644 --- a/test/TestApps/PushNotificationsDemoApp/main.cpp +++ b/test/TestApps/PushNotificationsDemoApp/main.cpp @@ -56,8 +56,8 @@ winrt::Windows::Foundation::IAsyncOperation RequestChan auto payload = args.Payload(); // Do stuff to process the raw payload - std::string payloadString(payload.begin(), payload.end()); - std::cout << "Push notification content received from FOREGROUND: " << payloadString << std::endl << std::endl; + std::wstring payloadString(payload.begin(), payload.end()); + std::wcout << L"Push notification content received from FOREGROUND: " << payloadString << std::endl << std::endl; args.Handled(true); }); // Caller's responsibility to keep the channel alive @@ -122,7 +122,7 @@ int main() } else { - PushNotificationActivationInfo info(PushNotificationRegistrationActivators::ProtocolActivator); + PushNotificationActivationInfo info(PushNotificationRegistrationActivators::ProtocolActivator, winrt::guid("ccd2ae3f-764f-4ae3-be45-9804761b28b2")); PushNotificationManager::RegisterActivator(info); } From 032831d65ea1727646dbe44d6afd20d05d7d7aa6 Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Wed, 2 Feb 2022 15:34:42 -0800 Subject: [PATCH 12/25] Update PushActivationInfo --- WindowsAppRuntime.sln | 5 ----- .../PushNotificationActivationInfo.cpp | 5 +++++ .../PushNotificationActivationInfo.h | 1 + dev/PushNotifications/PushNotificationManager.cpp | 15 +++++++++------ dev/PushNotifications/PushNotifications.idl | 3 +++ test/TestApps/PushNotificationsDemoApp/main.cpp | 1 + 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/WindowsAppRuntime.sln b/WindowsAppRuntime.sln index 6ff3d2cfe6..35813be3da 100644 --- a/WindowsAppRuntime.sln +++ b/WindowsAppRuntime.sln @@ -300,7 +300,6 @@ Global dev\UndockedRegFreeWinRT\UndockedRegFreeWinRT.vcxitems*{56371ca6-144b-4989-a4e9-391ad4fa7651}*SharedItemsImports = 9 test\inc\inc.vcxitems*{56a1d696-feda-4333-bf37-772ebececb10}*SharedItemsImports = 4 test\inc\inc.vcxitems*{5b2d17fe-c371-417f-860c-3d32397c2404}*SharedItemsImports = 4 - test\inc\inc.vcxitems*{72e682c6-2ffd-4d1d-99f1-07b400867699}*SharedItemsImports = 4 test\inc\inc.vcxitems*{7c502995-59c3-483b-86ba-815985353633}*SharedItemsImports = 4 dev\Licensing\Licensing.vcxitems*{885a43fa-052d-4b0d-a2dc-13ee15796435}*SharedItemsImports = 9 test\inc\inc.vcxitems*{8e52d7ea-a200-4a6b-ba74-8efb49468caf}*SharedItemsImports = 4 @@ -1229,10 +1228,6 @@ Global {A3FBA80D-5B35-471F-9A45-DB4B29E195B9} = {AC5FFC80-92FE-4933-BED2-EC5519AC4440} {91D03B95-1B0C-4BEB-8441-30DA7D615538} = {448ED2E5-0B37-4D97-9E6B-8C10A507976A} {103C0C23-7BA8-4D44-A63C-83488E2E3A81} = {91D03B95-1B0C-4BEB-8441-30DA7D615538} - {5B2D17FE-C371-417F-860C-3D32397C2404} = {2C6DFE11-B59C-4EE2-8669-AECA96FB69A3} - {424A6D96-37EE-4456-8347-08AB425C8DBE} = {2C6DFE11-B59C-4EE2-8669-AECA96FB69A3} - {56A1D696-FEDA-4333-BF37-772EBECECB10} = {55288381-8BF9-4982-94A4-180ADD59166D} - {D012E4BB-F16B-472D-A26D-D449CEFA988E} = {55288381-8BF9-4982-94A4-180ADD59166D} {0A5FEE93-48B7-40EC-BB9A-B27D11060DA9} = {8630F7AA-2969-4DC9-8700-9B468C1DC21D} {1307DD1B-BBE8-4CD0-B1A0-0DB6D61EEAA0} = {91D03B95-1B0C-4BEB-8441-30DA7D615538} {A1B25DCF-6A54-414D-8E24-F4D24EE9299D} = {8630F7AA-2969-4DC9-8700-9B468C1DC21D} diff --git a/dev/PushNotifications/PushNotificationActivationInfo.cpp b/dev/PushNotifications/PushNotificationActivationInfo.cpp index 79a5d3bbfb..342168ae12 100644 --- a/dev/PushNotifications/PushNotificationActivationInfo.cpp +++ b/dev/PushNotifications/PushNotificationActivationInfo.cpp @@ -20,6 +20,11 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation THROW_HR_IF(E_NOTIMPL, !::Microsoft::Windows::PushNotifications::Feature_PushNotifications::IsEnabled()); } + PushNotificationActivationInfo::PushNotificationActivationInfo(winrt::PushNotificationRegistrationActivators const& activators) : m_activators(activators), m_taskClsid(GUID_NULL) + { + THROW_HR_IF(E_NOTIMPL, !::Microsoft::Windows::PushNotifications::Feature_PushNotifications::IsEnabled()); + } + winrt::guid PushNotificationActivationInfo::TaskClsid() { return m_taskClsid; diff --git a/dev/PushNotifications/PushNotificationActivationInfo.h b/dev/PushNotifications/PushNotificationActivationInfo.h index 84f4201a6b..92b80af662 100644 --- a/dev/PushNotifications/PushNotificationActivationInfo.h +++ b/dev/PushNotifications/PushNotificationActivationInfo.h @@ -9,6 +9,7 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation struct PushNotificationActivationInfo : PushNotificationActivationInfoT { PushNotificationActivationInfo(Microsoft::Windows::PushNotifications::PushNotificationRegistrationActivators const& activators, winrt::guid const& taskClsid); + PushNotificationActivationInfo(Microsoft::Windows::PushNotifications::PushNotificationRegistrationActivators const& activators); winrt::guid TaskClsid(); Microsoft::Windows::PushNotifications::PushNotificationRegistrationActivators Activators(); diff --git a/dev/PushNotifications/PushNotificationManager.cpp b/dev/PushNotifications/PushNotificationManager.cpp index 99127ece5f..2898ffc8fe 100644 --- a/dev/PushNotifications/PushNotificationManager.cpp +++ b/dev/PushNotifications/PushNotificationManager.cpp @@ -274,12 +274,15 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation wil::unique_cotaskmem_string unpackagedAppUserModelId; RegisterUnpackagedApplicationHelper(GUID_NULL, unpackagedAppUserModelId); // create default registration for app - THROW_IF_FAILED(::CoRegisterClassObject( - s_taskClsid, - winrt::make().get(), - CLSCTX_LOCAL_SERVER, - REGCLS_MULTIPLEUSE, - &s_comActivatorRegistration)); + if (AppModel::Identity::IsPackagedProcess()) + { + THROW_IF_FAILED(::CoRegisterClassObject( + s_taskClsid, + winrt::make().get(), + CLSCTX_LOCAL_SERVER, + REGCLS_MULTIPLEUSE, + &s_comActivatorRegistration)); + } { auto lock = s_activatorInfoLock.lock_exclusive(); diff --git a/dev/PushNotifications/PushNotifications.idl b/dev/PushNotifications/PushNotifications.idl index e3c978de98..1d3f67e595 100644 --- a/dev/PushNotifications/PushNotifications.idl +++ b/dev/PushNotifications/PushNotifications.idl @@ -42,6 +42,9 @@ namespace Microsoft.Windows.PushNotifications // 3) If kind = ProtocolActivator is specified, the LRP will CoCreateInstance the application in background scenarios PushNotificationActivationInfo(PushNotificationRegistrationActivators activators, Guid taskClsid); + // Unpackaged applications that need to register for activation will use this constructor + PushNotificationActivationInfo(PushNotificationRegistrationActivators activators); + // The CLSID associated with the Client COM server that Windows App SDK will activate Guid TaskClsid{ get; }; diff --git a/test/TestApps/PushNotificationsDemoApp/main.cpp b/test/TestApps/PushNotificationsDemoApp/main.cpp index 0401c283aa..0da96f0010 100644 --- a/test/TestApps/PushNotificationsDemoApp/main.cpp +++ b/test/TestApps/PushNotificationsDemoApp/main.cpp @@ -5,6 +5,7 @@ #include #include #include "WindowsAppRuntime.Test.AppModel.h" +#include "MddBootstrap.h" using namespace winrt::Microsoft::Windows::AppLifecycle; using namespace winrt::Microsoft::Windows::PushNotifications; From 45b72cf7925bbd15b94f5f054bd7658a6d8e4fd0 Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Thu, 3 Feb 2022 10:32:21 -0800 Subject: [PATCH 13/25] Currently working on nits --- dev/AppLifecycle/ActivationRegistrationManager.h | 2 +- dev/AppLifecycle/AppInstance.cpp | 4 ++-- test/TestApps/PushNotificationsDemoApp/main.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dev/AppLifecycle/ActivationRegistrationManager.h b/dev/AppLifecycle/ActivationRegistrationManager.h index 374586308e..d7ef5dcde2 100644 --- a/dev/AppLifecycle/ActivationRegistrationManager.h +++ b/dev/AppLifecycle/ActivationRegistrationManager.h @@ -11,7 +11,7 @@ namespace winrt::Microsoft::Windows::AppLifecycle::implementation static PCWSTR c_argumentSuffix{ L":" }; static PCWSTR c_msProtocolArgumentString{ L"ms-protocol" }; static PCWSTR c_pushProtocolArgumentString{ L"WindowsAppRuntimePushServer" }; - static PCWSTR c_toastProtocolArgumentString{ L"AppNotificationActivated" }; + static PCWSTR c_appNotificationProtocolArgumentString{ L"AppNotificationActivated" }; static PCWSTR c_runKeyPath{ LR"(Software\Microsoft\Windows\CurrentVersion\Run\)" }; struct ActivationRegistrationManager diff --git a/dev/AppLifecycle/AppInstance.cpp b/dev/AppLifecycle/AppInstance.cpp index 4314626ab1..f48f075124 100644 --- a/dev/AppLifecycle/AppInstance.cpp +++ b/dev/AppLifecycle/AppInstance.cpp @@ -68,7 +68,7 @@ namespace winrt::Microsoft::Windows::AppLifecycle::implementation wil::unique_hlocal_ptr argv{ CommandLineToArgvW(commandLine.c_str(), &argc) }; - PCWSTR activationKinds[] = { c_msProtocolArgumentString, c_pushProtocolArgumentString, c_toastProtocolArgumentString }; + PCWSTR activationKinds[] = { c_msProtocolArgumentString, c_pushProtocolArgumentString, c_appNotificationProtocolArgumentString }; for (auto activationKind : activationKinds) { auto [ kind, data ] = GetActivationArguments(argv.get(), argc, activationKind); @@ -488,7 +488,7 @@ namespace winrt::Microsoft::Windows::AppLifecycle::implementation // protocol, except the catch-all LaunchActivatedEventArgs case. if (!contractArgument.empty()) { - if (contractArgument == c_pushProtocolArgumentString || contractArgument == c_toastProtocolArgumentString) + if (contractArgument == c_pushProtocolArgumentString || contractArgument == c_appNotificationProtocolArgumentString) { // Generate a basic encoded launch Uri for Push/Toast activations PCWSTR contractId = (contractArgument == c_pushProtocolArgumentString) ? c_pushContractId : c_toastContractId; diff --git a/test/TestApps/PushNotificationsDemoApp/main.cpp b/test/TestApps/PushNotificationsDemoApp/main.cpp index 0da96f0010..ca91771f40 100644 --- a/test/TestApps/PushNotificationsDemoApp/main.cpp +++ b/test/TestApps/PushNotificationsDemoApp/main.cpp @@ -123,7 +123,7 @@ int main() } else { - PushNotificationActivationInfo info(PushNotificationRegistrationActivators::ProtocolActivator, winrt::guid("ccd2ae3f-764f-4ae3-be45-9804761b28b2")); + PushNotificationActivationInfo info(PushNotificationRegistrationActivators::ProtocolActivator); PushNotificationManager::RegisterActivator(info); } From 243c2bcb51de00add6569ce320ca32459e26d601 Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Fri, 4 Feb 2022 14:04:29 -0800 Subject: [PATCH 14/25] Addressing comments --- dev/AppLifecycle/AppInstance.cpp | 2 +- dev/AppLifecycle/ExtensionContract.h | 2 +- .../GetNotificationEventArgs.h | 2 +- .../PushNotificationBackgroundTask.cpp | 13 +--- .../PushNotificationChannel.cpp | 2 +- .../PushNotificationManager.cpp | 59 ++++++------------- .../PushNotificationManager.h | 15 ++--- dev/PushNotifications/PushNotifications.idl | 15 +++-- .../NotificationsLongRunningProcess.idl | 4 +- .../NotificationListener.cpp | 4 +- .../NotificationListenerManager.cpp | 3 +- .../PushBackgroundTaskInstance.cpp | 8 +-- .../PushBackgroundTaskInstance.h | 7 ++- .../PushNotificationsLongRunningTask.vcxproj | 2 + ...tificationsLongRunningTask.vcxproj.filters | 6 ++ .../PushRawNotification.cpp | 27 +++++++++ .../PushRawNotification.h | 29 +++++++++ .../PushNotificationsLongRunningTask/pch.h | 3 +- .../platform.cpp | 49 ++++++++------- .../platform.h | 8 +-- dev/PushNotifications/externs.h | 13 +--- .../PushNotificationsDemoApp/main.cpp | 7 +-- 22 files changed, 154 insertions(+), 126 deletions(-) create mode 100644 dev/PushNotifications/PushNotificationsLongRunningTask/PushRawNotification.cpp create mode 100644 dev/PushNotifications/PushNotificationsLongRunningTask/PushRawNotification.h diff --git a/dev/AppLifecycle/AppInstance.cpp b/dev/AppLifecycle/AppInstance.cpp index f48f075124..f6713aac17 100644 --- a/dev/AppLifecycle/AppInstance.cpp +++ b/dev/AppLifecycle/AppInstance.cpp @@ -491,7 +491,7 @@ namespace winrt::Microsoft::Windows::AppLifecycle::implementation if (contractArgument == c_pushProtocolArgumentString || contractArgument == c_appNotificationProtocolArgumentString) { // Generate a basic encoded launch Uri for Push/Toast activations - PCWSTR contractId = (contractArgument == c_pushProtocolArgumentString) ? c_pushContractId : c_toastContractId; + PCWSTR contractId = (contractArgument == c_pushProtocolArgumentString) ? c_pushContractId : c_appNotificationContractId; std::wstring tempContractData = GenerateEncodedLaunchUri(L"App", contractId); contractArgument = c_msProtocolArgumentString; diff --git a/dev/AppLifecycle/ExtensionContract.h b/dev/AppLifecycle/ExtensionContract.h index 74c42d3b0d..a7c845b654 100644 --- a/dev/AppLifecycle/ExtensionContract.h +++ b/dev/AppLifecycle/ExtensionContract.h @@ -26,7 +26,7 @@ namespace winrt::Microsoft::Windows::AppLifecycle::implementation { ExtendedActivationKind::Protocol, c_protocolContractId, &ProtocolActivatedEventArgs::Deserialize }, { ExtendedActivationKind::StartupTask, c_startupTaskContractId, &StartupActivatedEventArgs::Deserialize }, { ExtendedActivationKind::Push, c_pushContractId, &winrt::Microsoft::Windows::PushNotifications::Deserialize }, - { ExtendedActivationKind::AppNotification, c_toastContractId, &winrt::Microsoft::Windows::PushNotifications::Deserialize }, + { ExtendedActivationKind::AppNotification, c_appNotificationContractId, &winrt::Microsoft::Windows::PushNotifications::Deserialize }, }; inline bool IsEncodedLaunch(winrt::Windows::Foundation::Uri const& uri) diff --git a/dev/PushNotifications/GetNotificationEventArgs.h b/dev/PushNotifications/GetNotificationEventArgs.h index df8b44c146..ff30ec6fb0 100644 --- a/dev/PushNotifications/GetNotificationEventArgs.h +++ b/dev/PushNotifications/GetNotificationEventArgs.h @@ -7,7 +7,7 @@ #include "externs.h" constexpr PCWSTR c_pushContractId = L"Windows.Push"; -constexpr PCWSTR c_toastContractId = L"Windows.Toast"; +constexpr PCWSTR c_appNotificationContractId = L"Windows.Toast"; namespace winrt::Microsoft::Windows::PushNotifications { diff --git a/dev/PushNotifications/PushNotificationBackgroundTask.cpp b/dev/PushNotifications/PushNotificationBackgroundTask.cpp index 2ad3eb60d5..2acf4542d4 100644 --- a/dev/PushNotifications/PushNotificationBackgroundTask.cpp +++ b/dev/PushNotifications/PushNotificationBackgroundTask.cpp @@ -29,17 +29,8 @@ namespace winrt void PushNotificationBackgroundTask::Run(winrt::IBackgroundTaskInstance const& taskInstance) { auto appProperties = winrt::CoreApplication::Properties(); - if (PushNotificationHelpers::IsPackagedAppScenario()) - { - winrt::PushNotificationReceivedEventArgs activatedEventArgs{ winrt::make(taskInstance) }; - appProperties.Insert(ACTIVATED_EVENT_ARGS_KEY, activatedEventArgs); - } - else - { - winrt::hstring payload{ winrt::unbox_value(taskInstance.TriggerDetails()) }; - winrt::PushNotificationReceivedEventArgs activatedEventArgs{ winrt::make(payload.c_str()) }; - appProperties.Insert(UNPACKAGED_EVENT_ARGS_KEY, activatedEventArgs); - } + winrt::PushNotificationReceivedEventArgs activatedEventArgs{ winrt::make(taskInstance) }; + appProperties.Insert(ACTIVATED_EVENT_ARGS_KEY, activatedEventArgs); SetEvent(GetWaitHandleForArgs().get()); } diff --git a/dev/PushNotifications/PushNotificationChannel.cpp b/dev/PushNotifications/PushNotificationChannel.cpp index 658e2db70b..d8666dcbf9 100644 --- a/dev/PushNotifications/PushNotificationChannel.cpp +++ b/dev/PushNotifications/PushNotificationChannel.cpp @@ -71,7 +71,7 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation } else { - THROW_IF_FAILED(PushNotifications_CloseChannel(m_channelInfo.appUserModelId.c_str(), m_channelInfo.channelId.c_str())); + THROW_IF_FAILED(PushNotifications_CloseChannel(m_channelInfo.appId.c_str(), m_channelInfo.channelId.c_str())); } PushNotificationTelemetry::ChannelClosedByApi(S_OK); diff --git a/dev/PushNotifications/PushNotificationManager.cpp b/dev/PushNotifications/PushNotificationManager.cpp index 2898ffc8fe..63934c1cc3 100644 --- a/dev/PushNotifications/PushNotificationManager.cpp +++ b/dev/PushNotifications/PushNotificationManager.cpp @@ -90,7 +90,7 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation THROW_IF_FAILED(notificationPlatform->RegisterFullTrustApplication(processName.get(), remoteId, &unpackagedAppUserModelId)); } - winrt::hresult CreateChannelWithRemoteIdHelper(wil::unique_cotaskmem_string const& appUserModelId, const winrt::guid& remoteId, ChannelDetails& channelInfo) noexcept try + winrt::hresult CreateChannelWithRemoteIdHelper(wil::unique_cotaskmem_string const& appId, const winrt::guid& remoteId, ChannelDetails& channelInfo) noexcept try { HRESULT operationalCode{}; ABI::Windows::Foundation::DateTime channelExpiryTime{}; @@ -98,7 +98,7 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation wil::unique_cotaskmem_string channelUri; THROW_IF_FAILED(PushNotifications_CreateChannelWithRemoteIdentifier( - appUserModelId.get(), + appId.get(), remoteId, &operationalCode, &channelId, @@ -108,7 +108,7 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation THROW_IF_FAILED(operationalCode); winrt::copy_from_abi(channelInfo.channelExpiryTime, &channelExpiryTime); - channelInfo.appUserModelId = winrt::hstring{ appUserModelId.get() }; + channelInfo.appId = winrt::hstring{ appId.get() }; channelInfo.channelId = winrt::hstring{ channelId.get() }; channelInfo.channelUri = winrt::hstring{ channelUri.get() }; @@ -116,6 +116,12 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation } CATCH_RETURN() + winrt::Microsoft::Windows::PushNotifications::PushNotificationManager PushNotificationManager::Default() + { + static auto pushNotificationManager{ winrt::make() }; + return pushNotificationManager; + } + winrt::IAsyncOperationWithProgress PushNotificationManager::CreateChannelAsync(const winrt::guid remoteId) { THROW_HR_IF(E_NOTIMPL, !::Microsoft::Windows::PushNotifications::Feature_PushNotifications::IsEnabled()); @@ -168,22 +174,6 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation S_OK, PushNotificationChannelStatus::CompletedSuccess); } - else if (hr == E_NOTIMPL) - { - usingLegacyImplementation = true; - - PushNotificationChannelManager channelManager{}; - winrt::PushNotificationChannel pushChannelReceived{ nullptr }; - - pushChannelReceived = co_await channelManager.CreatePushNotificationChannelForApplicationAsync(); - - PushNotificationTelemetry::ChannelRequestedByApi(S_OK, remoteId, usingLegacyImplementation); - - co_return winrt::make( - winrt::make(pushChannelReceived), - S_OK, - PushNotificationChannelStatus::CompletedSuccess); - } else { winrt::check_hresult(hr); @@ -191,6 +181,7 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation } else { + // AppId is generated by PushNotificationLongRunningTask singleton wil::unique_cotaskmem_string unpackagedAppUserModelId; RegisterUnpackagedApplicationHelper(remoteId, unpackagedAppUserModelId); @@ -201,7 +192,7 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation wil::unique_cotaskmem_string processName; THROW_IF_FAILED(GetCurrentProcessPath(processName)); - THROW_IF_FAILED(notificationPlatform->RegisterLongRunningActivator(processName.get(), s_taskClsid)); + THROW_IF_FAILED(notificationPlatform->RegisterLongRunningActivatorWithClsid(processName.get(), s_taskClsid)); std::wstring toastAppId{ RetrieveToastAppId() }; THROW_IF_FAILED(notificationPlatform->AddToastRegistrationMapping(processName.get(), toastAppId.c_str())); @@ -270,20 +261,10 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation THROW_HR_IF(E_INVALIDARG, s_protocolRegistration); } - s_taskClsid = details.TaskClsid(); + // AppId generated by PushNotificationsLongRunningTask singleton wil::unique_cotaskmem_string unpackagedAppUserModelId; RegisterUnpackagedApplicationHelper(GUID_NULL, unpackagedAppUserModelId); // create default registration for app - if (AppModel::Identity::IsPackagedProcess()) - { - THROW_IF_FAILED(::CoRegisterClassObject( - s_taskClsid, - winrt::make().get(), - CLSCTX_LOCAL_SERVER, - REGCLS_MULTIPLEUSE, - &s_comActivatorRegistration)); - } - { auto lock = s_activatorInfoLock.lock_exclusive(); s_protocolRegistration = true; @@ -292,7 +273,7 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation BackgroundTaskBuilder builder{ nullptr }; - if (WI_IsFlagSet(registrationActivators, PushNotificationRegistrationActivators::PushTrigger)) + if (WI_IsFlagSet(registrationActivators, PushNotificationRegistrationActivators::PushTrigger) && PushNotificationHelpers::IsPackagedAppScenario()) { GUID taskClsid = details.TaskClsid(); THROW_HR_IF(E_INVALIDARG, taskClsid == GUID_NULL); @@ -373,6 +354,7 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation GetWaitHandleForArgs().create(); + s_taskClsid = taskClsid; THROW_IF_FAILED(::CoRegisterClassObject( taskClsid, winrt::make().get(), @@ -491,17 +473,14 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation auto isProtocolActivatorSet{ WI_IsFlagSet(activators, PushNotificationRegistrationActivators::ProtocolActivator) }; THROW_HR_IF(E_INVALIDARG, isBackgroundTaskFlagSet && isProtocolActivatorSet); // Invalid flag combination - if (PushNotificationHelpers::IsPackagedAppScenario()) + if (AppModel::Identity::IsPackagedProcess() && isBackgroundTaskFlagSet) { - if (isProtocolActivatorSet) // ProtocolActivator unsupported if COM activation is available - { - return false; - } - return isBackgroundTaskFlagSet; + return true; } - else + else if(!AppModel::Identity::IsPackagedProcess() && isProtocolActivatorSet) { - return isProtocolActivatorSet; + return true; } + return false; } } diff --git a/dev/PushNotifications/PushNotificationManager.h b/dev/PushNotifications/PushNotificationManager.h index f2b56cc473..98d05fc1fb 100644 --- a/dev/PushNotifications/PushNotificationManager.h +++ b/dev/PushNotifications/PushNotificationManager.h @@ -8,17 +8,18 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation { - struct PushNotificationManager + struct PushNotificationManager : PushNotificationManagerT { - PushNotificationManager() = delete; + PushNotificationManager() = default; - static void RegisterActivator(Microsoft::Windows::PushNotifications::PushNotificationActivationInfo const& details); - static void UnregisterActivator(Microsoft::Windows::PushNotifications::PushNotificationRegistrationActivators const& activators); - static void UnregisterAllActivators(); + static winrt::Microsoft::Windows::PushNotifications::PushNotificationManager Default(); + void RegisterActivator(Microsoft::Windows::PushNotifications::PushNotificationActivationInfo const& details); + void UnregisterActivator(Microsoft::Windows::PushNotifications::PushNotificationRegistrationActivators const& activators); + void UnregisterAllActivators(); - static winrt::Windows::Foundation::IAsyncOperationWithProgress CreateChannelAsync(winrt::guid const remoteId); + winrt::Windows::Foundation::IAsyncOperationWithProgress CreateChannelAsync(winrt::guid const remoteId); - static bool IsActivatorSupported(Microsoft::Windows::PushNotifications::PushNotificationRegistrationActivators const& activators); + bool IsActivatorSupported(Microsoft::Windows::PushNotifications::PushNotificationRegistrationActivators const& activators); }; } diff --git a/dev/PushNotifications/PushNotifications.idl b/dev/PushNotifications/PushNotifications.idl index 1d3f67e595..7e19b466b2 100644 --- a/dev/PushNotifications/PushNotifications.idl +++ b/dev/PushNotifications/PushNotifications.idl @@ -113,24 +113,27 @@ namespace Microsoft.Windows.PushNotifications }; [feature(Feature_PushNotifications)] - static runtimeclass PushNotificationManager + runtimeclass PushNotificationManager { + // Gets a Default instance of a PushNotificationManager + static PushNotificationManager Default{ get; }; + // Register an activator using an ActivationInfo context and cache the flag for unregister - static void RegisterActivator(PushNotificationActivationInfo details); + void RegisterActivator(PushNotificationActivationInfo details); // Unregister any activator given PushNotificationRegistrationActivators // 1) If kind = PushTrigger is specified, the trigger itself will be removed // 2) If kind = ComActivator is specified, the Project Reunion Background Task component will no longer act as an InProc COM Server // 3) If kind = ProtocolActivator is specified, the application will be unregistered from the long running process that handles activation - static void UnregisterActivator(PushNotificationRegistrationActivators activators); + void UnregisterActivator(PushNotificationRegistrationActivators activators); // Unregister all activators registered for the application - static void UnregisterAllActivators(); + void UnregisterAllActivators(); // Request a Push Channel with an encoded RemoteId from WNS. RemoteId is an AAD identifier GUID - static Windows.Foundation.IAsyncOperationWithProgress CreateChannelAsync(Guid remoteId); + Windows.Foundation.IAsyncOperationWithProgress CreateChannelAsync(Guid remoteId); // Applications will call this to check which flags are supported for RegisterActivator - static Boolean IsActivatorSupported(PushNotificationRegistrationActivators activators); + Boolean IsActivatorSupported(PushNotificationRegistrationActivators activators); }; } diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask.ProxyStub/NotificationsLongRunningProcess.idl b/dev/PushNotifications/PushNotificationsLongRunningTask.ProxyStub/NotificationsLongRunningProcess.idl index d2018e0427..67cd23a580 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask.ProxyStub/NotificationsLongRunningProcess.idl +++ b/dev/PushNotifications/PushNotificationsLongRunningTask.ProxyStub/NotificationsLongRunningProcess.idl @@ -19,7 +19,9 @@ interface IWpnForegroundSink : IUnknown [pointer_default(unique)] interface INotificationsLongRunningPlatform : IUnknown { - HRESULT RegisterLongRunningActivator([in] LPCWSTR processName, [in] GUID comServerClsid); + HRESULT RegisterLongRunningActivator([in] LPCWSTR processName); + + HRESULT RegisterLongRunningActivatorWithClsid([in] LPCWSTR processName, [in] GUID comServerClsid); HRESULT UnregisterLongRunningActivator([in] LPCWSTR processName); diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListener.cpp b/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListener.cpp index e144394e3c..b3f959e423 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListener.cpp +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListener.cpp @@ -44,10 +44,10 @@ STDMETHODIMP_(HRESULT __stdcall) NotificationListener::OnRawNotificationReceived else { std::wstring payloadString(payloadArray.begin(), payloadArray.end()); + auto pushRawNotification{ winrt::make_self(payloadString) }; + auto pushBackgroundTaskInstance{ winrt::make_self(pushRawNotification) }; auto localBackgroundTask = winrt::create_instance(m_comServerClsid, CLSCTX_ALL); - auto pushBackgroundTaskInstance{ winrt::make_self() }; - pushBackgroundTaskInstance->SetRawNotificationPayload(payloadString); localBackgroundTask.Run(*pushBackgroundTaskInstance); } }; diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListenerManager.cpp b/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListenerManager.cpp index c0dee8ac45..a28f0ab43a 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListenerManager.cpp +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListenerManager.cpp @@ -9,11 +9,12 @@ void NotificationListenerManager::Initialize(std::shared_ptr (processName, comServerClsid) void NotificationListenerManager::SetAppIdMapping(std::map>& appIdList) { for (auto appData : appIdList) { - AddListener(appData.first, appData.second.first, appData.second.second); + AddListener(appData.first /* appId */, appData.second.first /* processName */, appData.second.second /* comServerClsid */); } } diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/PushBackgroundTaskInstance.cpp b/dev/PushNotifications/PushNotificationsLongRunningTask/PushBackgroundTaskInstance.cpp index a5a4665b7f..0d86433887 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/PushBackgroundTaskInstance.cpp +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/PushBackgroundTaskInstance.cpp @@ -22,7 +22,7 @@ UINT32 PushBackgroundTaskInstance::Progress() return 0; } -UINT32 PushBackgroundTaskInstance::Progress(UINT32 progress) +UINT32 PushBackgroundTaskInstance::Progress(UINT32 /* progress */) { return 0; } @@ -32,12 +32,12 @@ winrt::Windows::ApplicationModel::Background::BackgroundTaskRegistration PushBac return nullptr; } -winrt::event_token PushBackgroundTaskInstance::Canceled(winrt::Windows::ApplicationModel::Background::BackgroundTaskCanceledEventHandler const& handler) +winrt::event_token PushBackgroundTaskInstance::Canceled(winrt::Windows::ApplicationModel::Background::BackgroundTaskCanceledEventHandler const& /* handler */) { return winrt::event_token{}; } -void PushBackgroundTaskInstance::Canceled(winrt::event_token const& token) noexcept +void PushBackgroundTaskInstance::Canceled(winrt::event_token const& /* token */) noexcept { return; } @@ -49,5 +49,5 @@ winrt::Windows::ApplicationModel::Background::BackgroundTaskDeferral PushBackgro winrt::Windows::Foundation::IInspectable PushBackgroundTaskInstance::TriggerDetails() { - return winrt::box_value(m_payload); + return *m_rawNotification.get(); } diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/PushBackgroundTaskInstance.h b/dev/PushNotifications/PushNotificationsLongRunningTask/PushBackgroundTaskInstance.h index 3dd5276a2e..97c1edd3c6 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/PushBackgroundTaskInstance.h +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/PushBackgroundTaskInstance.h @@ -1,8 +1,11 @@ #include +// Mocks IBackgroundTaskInstance to send raw payloads to packaged apps in +// PushNotificationBackgroundTask::Run by com activation from PushNotificationsLongRunningProcess struct PushBackgroundTaskInstance : winrt::implements { PushBackgroundTaskInstance() {}; + PushBackgroundTaskInstance(winrt::com_ptr rawNotification): m_rawNotification(rawNotification) {}; winrt::guid InstanceId(); UINT32 SuspendedCount(); @@ -13,10 +16,8 @@ struct PushBackgroundTaskInstance : winrt::implements m_rawNotification{ nullptr }; }; struct PushBackgroundTaskInstanceFactory : winrt::implements diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj b/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj index 9ab65f3f0d..9e25cefadc 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj @@ -233,6 +233,7 @@ + @@ -245,6 +246,7 @@ + diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj.filters b/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj.filters index e550c16df5..8525dae2e6 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj.filters +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj.filters @@ -42,6 +42,9 @@ Source Files + + Source Files + @@ -74,6 +77,9 @@ Source Files + + Source Files + diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/PushRawNotification.cpp b/dev/PushNotifications/PushNotificationsLongRunningTask/PushRawNotification.cpp new file mode 100644 index 0000000000..15eea37d5f --- /dev/null +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/PushRawNotification.cpp @@ -0,0 +1,27 @@ + +#pragma once + +#include "pch.h" +#include + +winrt::Windows::Foundation::Collections::IMapView PushRawNotification::Headers() +{ + return winrt::Windows::Foundation::Collections::IMapView{}; +} + +winrt::hstring PushRawNotification::ChannelId() +{ + return winrt::hstring(); +} + +winrt::hstring PushRawNotification::Content() +{ + return winrt::hstring(m_payload); +} + +winrt::Windows::Storage::Streams::IBuffer PushRawNotification::ContentBytes() +{ + return winrt::Windows::Security::Cryptography::CryptographicBuffer::ConvertStringToBinary( + m_payload, + winrt::Windows::Security::Cryptography::BinaryStringEncoding::Utf8); +} diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/PushRawNotification.h b/dev/PushNotifications/PushNotificationsLongRunningTask/PushRawNotification.h new file mode 100644 index 0000000000..5c25f64ff0 --- /dev/null +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/PushRawNotification.h @@ -0,0 +1,29 @@ +#include +#include + +struct PushRawNotification : winrt::implements +{ + PushRawNotification() {}; + PushRawNotification(std::wstring const& payload): m_payload(payload) {}; + + winrt::Windows::Foundation::Collections::IMapView Headers(); + winrt::hstring ChannelId(); + winrt::hstring Content(); + winrt::Windows::Storage::Streams::IBuffer ContentBytes(); +private: + std::wstring m_payload; +}; + +struct PushRawNotificationFactory : winrt::implements +{ + HRESULT __stdcall CreateInstance(_In_opt_ IUnknown* aggregateInterface, _In_ REFIID interfaceId, _Outptr_ VOID** object) noexcept final + { + RETURN_HR_IF(CLASS_E_NOAGGREGATION, aggregateInterface != nullptr); + return winrt::make().as(interfaceId, object); + } + + HRESULT __stdcall LockServer(BOOL) noexcept final + { + return S_OK; + } +}; diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/pch.h b/dev/PushNotifications/PushNotificationsLongRunningTask/pch.h index d81dbb7f94..338f49be8d 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/pch.h +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/pch.h @@ -26,9 +26,8 @@ #include #include #include - #include - +#include "PushRawNotification.h" // UDK/ProxyStub files #define MIDL_NS_PREFIX #include diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/platform.cpp b/dev/PushNotifications/PushNotificationsLongRunningTask/platform.cpp index 8a2418c923..ea0e7d0e73 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/platform.cpp +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/platform.cpp @@ -76,26 +76,41 @@ STDMETHODIMP_(HRESULT __stdcall) NotificationsLongRunningPlatformImpl::RegisterF } CATCH_RETURN() -STDMETHODIMP_(HRESULT __stdcall) NotificationsLongRunningPlatformImpl::RegisterLongRunningActivator(_In_ PCWSTR processName, GUID comServerClsid) noexcept try +STDMETHODIMP_(HRESULT __stdcall) NotificationsLongRunningPlatformImpl::RegisterLongRunningActivator(_In_ PCWSTR processName) noexcept try { auto lock = m_lock.lock_shared(); THROW_HR_IF(WPN_E_PLATFORM_UNAVAILABLE, m_shutdown); + RegisterLongRunningActivatorHelper(processName, GUID_NULL); + return S_OK; +} +CATCH_RETURN() + +STDMETHODIMP_(HRESULT __stdcall) NotificationsLongRunningPlatformImpl::RegisterLongRunningActivatorWithClsid(_In_ PCWSTR processName, GUID comServerClsid) noexcept try +{ + auto lock = m_lock.lock_shared(); + THROW_HR_IF(WPN_E_PLATFORM_UNAVAILABLE, m_shutdown); + + RegisterLongRunningActivatorHelper(processName, comServerClsid); + return S_OK; +} +CATCH_RETURN() + +void NotificationsLongRunningPlatformImpl::RegisterLongRunningActivatorHelper(PCWSTR processName, GUID comServerClsid) +{ // NotificationsLongRunningPlatformImpl::RegisterFullTrustApplication should be called before this or we ignore the call const std::wstring appId{ GetAppIdentifier(processName) }; if (appId.empty()) { - return S_OK; + return; } AddComServerClsid(appId, comServerClsid); m_notificationListenerManager.AddListener(appId, processName, comServerClsid); m_lifetimeManager.Cancel(); - - return S_OK; + return; } -CATCH_RETURN() STDMETHODIMP_(HRESULT __stdcall) NotificationsLongRunningPlatformImpl::UnregisterLongRunningActivator(_In_ PCWSTR processName) noexcept try { @@ -109,9 +124,9 @@ STDMETHODIMP_(HRESULT __stdcall) NotificationsLongRunningPlatformImpl::Unregiste m_notificationListenerManager.RemoveListener(appId); m_foregroundSinkManager->Remove(appId); - RemoveAppIdentifier(appId); - RemoveComServerClsid(appId); - RemoveToastHelper(processName); + m_rawStorage.Values().Remove(appId); + m_comServerClsidStorage.Values().Remove(appId); + m_toastRegistrationManager->Remove(processName); } if (m_notificationListenerManager.IsEmpty()) @@ -180,7 +195,7 @@ STDMETHODIMP_(HRESULT __stdcall) NotificationsLongRunningPlatformImpl::RemoveToa auto lock{ m_lock.lock_exclusive() }; THROW_HR_IF(WPN_E_PLATFORM_UNAVAILABLE, m_shutdown); - RemoveToastHelper(processName); + m_toastRegistrationManager->Remove(processName); return S_OK; } CATCH_RETURN() @@ -250,19 +265,3 @@ void NotificationsLongRunningPlatformImpl::AddComServerClsid(std::wstring const& { m_comServerClsidStorage.Values().Insert(appId, winrt::box_value(comServerClsid)); } - -void NotificationsLongRunningPlatformImpl::RemoveComServerClsid(std::wstring const& appId) -{ - m_comServerClsidStorage.Values().Remove(appId); -} - -void NotificationsLongRunningPlatformImpl::RemoveAppIdentifier(std::wstring const& appId) -{ - m_rawStorage.Values().Remove(appId); -} - -void NotificationsLongRunningPlatformImpl::RemoveToastHelper(std::wstring const& processName) -{ - m_toastRegistrationManager->Remove(processName); -} - diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/platform.h b/dev/PushNotifications/PushNotificationsLongRunningTask/platform.h index 303463c6a9..09ed5fa50d 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/platform.h +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/platform.h @@ -15,7 +15,9 @@ struct __declspec(uuid(PUSHNOTIFICATIONS_IMPL_CLSID_STRING)) NotificationsLongRu STDMETHOD(RegisterFullTrustApplication)(_In_ PCWSTR processName, GUID remoteId, _Out_ PWSTR* appId) noexcept; - STDMETHOD(RegisterLongRunningActivator)(_In_ PCWSTR processName, GUID comServerClsid) noexcept; + STDMETHOD(RegisterLongRunningActivator)(_In_ PCWSTR processName) noexcept; + + STDMETHOD(RegisterLongRunningActivatorWithClsid)(_In_ PCWSTR processName, GUID comServerClsid) noexcept; STDMETHOD(UnregisterLongRunningActivator)(_In_ PCWSTR processName) noexcept; @@ -29,12 +31,10 @@ struct __declspec(uuid(PUSHNOTIFICATIONS_IMPL_CLSID_STRING)) NotificationsLongRu private: std::map> GetFullTrustApps(); + void RegisterLongRunningActivatorHelper(PCWSTR processName, GUID comServerClsid); const std::wstring GetAppIdentifier(std::wstring const& processName); const std::wstring BuildAppIdentifier(std::wstring const& processName); void AddComServerClsid(std::wstring const& appId, winrt::guid const& comServerClsid); - void RemoveComServerClsid(std::wstring const& appId); - void RemoveAppIdentifier(std::wstring const& processName); - void RemoveToastHelper(std::wstring const& processName); winrt::Windows::Storage::ApplicationDataContainer m_rawStorage{ nullptr }; winrt::Windows::Storage::ApplicationDataContainer m_comServerClsidStorage{ nullptr }; diff --git a/dev/PushNotifications/externs.h b/dev/PushNotifications/externs.h index 9ecb3a04b3..d66d139b9c 100644 --- a/dev/PushNotifications/externs.h +++ b/dev/PushNotifications/externs.h @@ -9,7 +9,6 @@ wil::unique_event& GetWaitHandleForArgs(); inline const winrt::hstring ACTIVATED_EVENT_ARGS_KEY = L"GlobalActivatedEventArgs"; -inline const winrt::hstring UNPACKAGED_EVENT_ARGS_KEY = L"UnpackagedActivatedEventArgs"; namespace PushNotificationHelpers { @@ -20,7 +19,7 @@ struct ChannelDetails { winrt::hstring channelUri; winrt::hstring channelId; - winrt::hstring appUserModelId; + winrt::hstring appId; winrt::Windows::Foundation::DateTime channelExpiryTime; }; @@ -35,13 +34,5 @@ inline winrt::Windows::Foundation::IInspectable GetArgsFromComStore() THROW_HR_IF(HRESULT_FROM_WIN32(ERROR_TIMEOUT), !GetWaitHandleForArgs().wait(receiveArgsTimeoutInMSec)); // If COM static store was uninit, let it throw - if (PushNotificationHelpers::IsPackagedAppScenario()) - { - return winrt::Windows::ApplicationModel::Core::CoreApplication::Properties().Lookup(ACTIVATED_EVENT_ARGS_KEY); - } - else - { - return winrt::Windows::ApplicationModel::Core::CoreApplication::Properties().Lookup(UNPACKAGED_EVENT_ARGS_KEY); - } - + return winrt::Windows::ApplicationModel::Core::CoreApplication::Properties().Lookup(ACTIVATED_EVENT_ARGS_KEY); } diff --git a/test/TestApps/PushNotificationsDemoApp/main.cpp b/test/TestApps/PushNotificationsDemoApp/main.cpp index ca91771f40..8bbc13a6b8 100644 --- a/test/TestApps/PushNotificationsDemoApp/main.cpp +++ b/test/TestApps/PushNotificationsDemoApp/main.cpp @@ -6,6 +6,7 @@ #include #include "WindowsAppRuntime.Test.AppModel.h" #include "MddBootstrap.h" +#include "WindowsAppRuntime.Test.Bootstrap.h" using namespace winrt::Microsoft::Windows::AppLifecycle; using namespace winrt::Microsoft::Windows::PushNotifications; @@ -99,11 +100,7 @@ int main() } else { - // Major.Minor version, MinVersion=0 to find any framework package for this major.minor version - const UINT32 c_Version_MajorMinor{ 0x00040001 }; - const PACKAGE_VERSION minVersion{}; - RETURN_IF_FAILED(MddBootstrapInitialize(c_Version_MajorMinor, nullptr, minVersion)); - + Test::Bootstrap::SetupBootstrap(); ToastAssets assets(L"ToastNotificationApp", winrt::Windows::Foundation::Uri{ LR"(C:\Windows\System32\WindowsSecurityIcon.png)" }); auto activationInfo = ToastActivationInfo::CreateFromToastAssets(assets); ToastNotificationManager::Default().RegisterActivator(activationInfo); From d1f22da78e531c98c35963b7b909285d63ee4f22 Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Sun, 6 Feb 2022 16:46:24 -0800 Subject: [PATCH 15/25] Cleaning up PushNotificationChannel.cpp + nits --- .../PushNotificationChannel.cpp | 123 +++++------------- .../PushNotificationChannel.h | 15 +-- .../PushNotificationManager.cpp | 50 +++---- .../platform.cpp | 7 +- .../platform.h | 3 +- .../PushNotificationsDemoApp/main.cpp | 39 +++--- 6 files changed, 81 insertions(+), 156 deletions(-) diff --git a/dev/PushNotifications/PushNotificationChannel.cpp b/dev/PushNotifications/PushNotificationChannel.cpp index d8666dcbf9..68222396ae 100644 --- a/dev/PushNotifications/PushNotificationChannel.cpp +++ b/dev/PushNotifications/PushNotificationChannel.cpp @@ -11,7 +11,6 @@ #include #include "externs.h" #include "PushNotificationTelemetry.h" -#include #include "PushNotificationUtility.h" namespace winrt::Windows @@ -32,141 +31,89 @@ namespace PushNotificationHelpers namespace winrt::Microsoft::Windows::PushNotifications::implementation { - PushNotificationChannel::PushNotificationChannel(winrt::Windows::PushNotificationChannel const& channel): m_channel(channel) - { - THROW_HR_IF(E_NOTIMPL, !::Microsoft::Windows::PushNotifications::Feature_PushNotifications::IsEnabled()); - } - winrt::Windows::Uri PushNotificationChannel::Uri() { - if (m_channel) - { - return winrt::Windows::Uri{ m_channel.Uri() }; - } - else - { - return winrt::Windows::Uri{ m_channelInfo.channelUri }; - } + return winrt::Windows::Uri{ m_channelInfo.channelUri }; } winrt::Windows::DateTime PushNotificationChannel::ExpirationTime() { - if (m_channel) - { - return m_channel.ExpirationTime(); - } - else - { - return m_channelInfo.channelExpiryTime; - } + return m_channelInfo.channelExpiryTime; } void PushNotificationChannel::Close() { try { - if (m_channel) - { - m_channel.Close(); - } - else - { - THROW_IF_FAILED(PushNotifications_CloseChannel(m_channelInfo.appId.c_str(), m_channelInfo.channelId.c_str())); - } - + THROW_IF_FAILED(PushNotifications_CloseChannel(m_channelInfo.appId.c_str(), m_channelInfo.channelId.c_str())); PushNotificationTelemetry::ChannelClosedByApi(S_OK); } catch (...) { - auto channelCloseException = hresult_error(to_hresult()); + auto channelCloseException { hresult_error(to_hresult()) }; PushNotificationTelemetry::ChannelClosedByApi(channelCloseException.code()); if (channelCloseException.code() != HRESULT_FROM_WIN32(ERROR_NOT_FOUND)) { - throw hresult_error(to_hresult()); + throw channelCloseException; } } } winrt::event_token PushNotificationChannel::PushReceived(winrt::Windows::TypedEventHandler handler) { - if (PushNotificationHelpers::IsPackagedAppScenario()) + bool registeredEvent { false }; { - if (m_channel) - { - return m_channel.PushNotificationReceived([weak_self = get_weak(), handler](auto&&, auto&& args) - { - if (auto strong = weak_self.get()) - { - auto pushArgs = winrt::make(args); - pushArgs.Handled(true); - handler(*strong, pushArgs); - }; - }); - } - else - { - // The channelUri is directly obtained when we request Channel from UDK using RemoteId - auto lock = m_lock.lock_exclusive(); - - if (!m_foregroundHandlerCount) - { - auto appUserModelId{ winrt::Microsoft::Helpers::GetAppUserModelId() }; - - THROW_IF_FAILED(PushNotifications_RegisterNotificationSinkForFullTrustApplication(appUserModelId.get(), this)); - } + auto lock { m_lock.lock_shared() }; + registeredEvent = bool(m_foregroundHandlers); + } - ++m_foregroundHandlerCount; + if(!registeredEvent) + { + if(PushNotificationHelpers::IsPackagedAppScenario()) + { + auto appUserModelId{ winrt::Microsoft::Helpers::GetAppUserModelId() }; - return m_foregroundHandlers.add(handler); + // Register foreground event through the UDK + THROW_IF_FAILED(PushNotifications_RegisterNotificationSinkForFullTrustApplication(appUserModelId.get(), this)); } - } - else - { - auto lock = m_lock.lock_exclusive(); - if (!m_foregroundHandlerCount++) + else { auto notificationsLongRunningPlatform{ winrt::Microsoft::Helpers::GetNotificationPlatform() }; wil::unique_cotaskmem_string processName; THROW_IF_FAILED(GetCurrentProcessPath(processName)); - THROW_IF_FAILED(notificationsLongRunningPlatform->RegisterForegroundActivator(this, processName.get())); + // Register foreground event through the LRP + THROW_IF_FAILED(notificationsLongRunningPlatform->RegisterForegroundActivator(this, processName.get())); } - return m_foregroundHandlers.add(handler); } + + auto lock { m_lock.lock_exclusive() }; + return m_foregroundHandlers.add(handler); } void PushNotificationChannel::PushReceived(winrt::event_token const& token) noexcept { - if (PushNotificationHelpers::IsPackagedAppScenario()) + bool registeredEvent { false }; { - if (m_channel) - { - m_channel.PushNotificationReceived(token); - } - else - { - auto lock = m_lock.lock_exclusive(); - - if (m_foregroundHandlerCount == 1) - { - auto appUserModelId{ winrt::Microsoft::Helpers::GetAppUserModelId() }; + auto lock { m_lock.lock_exclusive() }; + m_foregroundHandlers.remove(token); + registeredEvent = bool(m_foregroundHandlers); + } - THROW_IF_FAILED(PushNotifications_UnregisterNotificationSinkForFullTrustApplication(appUserModelId.get())); - } + if(!registeredEvent) + { + if (PushNotificationHelpers::IsPackagedAppScenario()) + { + auto appUserModelId{ winrt::Microsoft::Helpers::GetAppUserModelId() }; - m_foregroundHandlers.remove(token); - --m_foregroundHandlerCount; + // Unregister foreground sink in UDK + THROW_IF_FAILED(PushNotifications_UnregisterNotificationSinkForFullTrustApplication(appUserModelId.get())); } - } - else - { - auto lock = m_lock.lock_exclusive(); - m_foregroundHandlers.remove(token); - if (!--m_foregroundHandlerCount) + else { auto notificationsLongRunningPlatform{ winrt::Microsoft::Helpers::GetNotificationPlatform() }; diff --git a/dev/PushNotifications/PushNotificationChannel.h b/dev/PushNotifications/PushNotificationChannel.h index 1a1595acd1..9b79dee737 100644 --- a/dev/PushNotifications/PushNotificationChannel.h +++ b/dev/PushNotifications/PushNotificationChannel.h @@ -6,6 +6,7 @@ #include #include "winrt/Windows.Networking.PushNotifications.h" #include +#include #include "externs.h" namespace winrt::Microsoft::Windows::PushNotifications::implementation @@ -16,9 +17,12 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation struct PushNotificationChannel : PushNotificationChannelT { - PushNotificationChannel(winrt::Windows::Networking::PushNotifications::PushNotificationChannel const& channel); + PushNotificationChannel(struct ChannelDetails channelInfo) + { + THROW_HR_IF(E_NOTIMPL, !::Microsoft::Windows::PushNotifications::Feature_PushNotifications::IsEnabled()); - PushNotificationChannel(struct ChannelDetails const& channelInfo) : m_channelInfo(channelInfo) {}; + std::swap(m_channelInfo, channelInfo); + }; winrt::Windows::Foundation::Uri Uri(); winrt::Windows::Foundation::DateTime ExpirationTime(); @@ -34,14 +38,9 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation HRESULT __stdcall OnRawNotificationReceived(unsigned int payloadLength, _In_ byte* payload, _In_ HSTRING /*correlationVector */) noexcept; private: - bool IsPackagedAppScenario(); - bool IsBackgroundTaskBuilderAvailable(); - - const winrt::Windows::Networking::PushNotifications::PushNotificationChannel m_channel{ nullptr }; - const struct ChannelDetails m_channelInfo{}; + struct ChannelDetails m_channelInfo{}; winrt::event m_foregroundHandlers; - ULONG m_foregroundHandlerCount = 0; wil::srwlock m_lock; }; } diff --git a/dev/PushNotifications/PushNotificationManager.cpp b/dev/PushNotifications/PushNotificationManager.cpp index 63934c1cc3..2851b79229 100644 --- a/dev/PushNotifications/PushNotificationManager.cpp +++ b/dev/PushNotifications/PushNotificationManager.cpp @@ -18,7 +18,6 @@ #include #include #include "NotificationsLongRunningProcess_h.h" -#include #include "PushNotificationUtility.h" #include "ToastNotificationUtility.h" @@ -155,38 +154,18 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation { try { + ChannelDetails channelInfo{}; if (IsActivatorSupported(PushNotificationRegistrationActivators::PushTrigger)) { auto appUserModelId{ PushNotificationHelpers::GetAppUserModelId() }; - ChannelDetails channelInfo{}; - winrt::hresult hr{ CreateChannelWithRemoteIdHelper(appUserModelId, remoteId, channelInfo) }; - - // RemoteId APIs are not applicable for downlevel OS versions. - // So we get error E_NOTIMPL and we fallback to calling into - // public WinRT API CreatePushNotificationChannelForApplicationAsync - // to request a channel. - if (SUCCEEDED(hr)) - { - PushNotificationTelemetry::ChannelRequestedByApi(S_OK, remoteId, usingLegacyImplementation); - - co_return winrt::make( - winrt::make(channelInfo), - S_OK, - PushNotificationChannelStatus::CompletedSuccess); - } - else - { - winrt::check_hresult(hr); - } + THROW_IF_FAILED(CreateChannelWithRemoteIdHelper(appUserModelId, remoteId, channelInfo)); } else { // AppId is generated by PushNotificationLongRunningTask singleton wil::unique_cotaskmem_string unpackagedAppUserModelId; RegisterUnpackagedApplicationHelper(remoteId, unpackagedAppUserModelId); - - ChannelDetails channelInfo{}; - winrt::hresult hr{ CreateChannelWithRemoteIdHelper(unpackagedAppUserModelId, remoteId, channelInfo) }; + winrt::check_hresult(CreateChannelWithRemoteIdHelper(unpackagedAppUserModelId, remoteId, channelInfo)); auto notificationPlatform{ PushNotificationHelpers::GetNotificationPlatform() }; @@ -196,18 +175,17 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation std::wstring toastAppId{ RetrieveToastAppId() }; THROW_IF_FAILED(notificationPlatform->AddToastRegistrationMapping(processName.get(), toastAppId.c_str())); - - PushNotificationTelemetry::ChannelRequestedByApi(S_OK, remoteId, usingLegacyImplementation); - - co_return winrt::make( - winrt::make(channelInfo), - S_OK, - PushNotificationChannelStatus::CompletedSuccess); } + + PushNotificationTelemetry::ChannelRequestedByApi(S_OK, remoteId, usingLegacyImplementation); + co_return winrt::make( + winrt::make(channelInfo), + S_OK, + PushNotificationChannelStatus::CompletedSuccess); } catch (...) { - auto channelRequestException = hresult_error(to_hresult(), take_ownership_from_abi); + auto channelRequestException{ hresult_error(to_hresult(), take_ownership_from_abi) }; if ((backOffTime <= c_maxBackoff) && IsChannelRequestRetryable(channelRequestException.code())) { @@ -348,13 +326,17 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation THROW_HR_IF(E_INVALIDARG, taskClsid == GUID_NULL); { - auto lock = s_activatorInfoLock.lock_shared(); + auto lock{ s_activatorInfoLock.lock_shared() }; THROW_HR_IF_MSG(E_INVALIDARG, s_comActivatorRegistration, "ComActivator already registered."); } GetWaitHandleForArgs().create(); - s_taskClsid = taskClsid; + { + auto lock{ s_activatorInfoLock.lock_exclusive() }; + s_taskClsid = taskClsid; + } + THROW_IF_FAILED(::CoRegisterClassObject( taskClsid, winrt::make().get(), diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/platform.cpp b/dev/PushNotifications/PushNotificationsLongRunningTask/platform.cpp index ea0e7d0e73..794a6488d4 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/platform.cpp +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/platform.cpp @@ -105,7 +105,7 @@ void NotificationsLongRunningPlatformImpl::RegisterLongRunningActivatorHelper(PC return; } - AddComServerClsid(appId, comServerClsid); + m_comServerClsidStorage.Values().Insert(appId, winrt::box_value(comServerClsid)); m_notificationListenerManager.AddListener(appId, processName, comServerClsid); m_lifetimeManager.Cancel(); @@ -260,8 +260,3 @@ const std::wstring NotificationsLongRunningPlatformImpl::BuildAppIdentifier(std: m_rawStorage.Values().Insert(guidStr.get(), winrt::box_value(processName.c_str())); return guidStr.get(); } - -void NotificationsLongRunningPlatformImpl::AddComServerClsid(std::wstring const& appId, winrt::guid const& comServerClsid) -{ - m_comServerClsidStorage.Values().Insert(appId, winrt::box_value(comServerClsid)); -} diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/platform.h b/dev/PushNotifications/PushNotificationsLongRunningTask/platform.h index 09ed5fa50d..ca7be0a823 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/platform.h +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/platform.h @@ -30,11 +30,10 @@ struct __declspec(uuid(PUSHNOTIFICATIONS_IMPL_CLSID_STRING)) NotificationsLongRu STDMETHOD(RemoveToastRegistrationMapping)(_In_ PCWSTR processName) noexcept; private: - std::map> GetFullTrustApps(); + std::map> GetFullTrustApps(); // AppId -> (processName, comServerGuid) void RegisterLongRunningActivatorHelper(PCWSTR processName, GUID comServerClsid); const std::wstring GetAppIdentifier(std::wstring const& processName); const std::wstring BuildAppIdentifier(std::wstring const& processName); - void AddComServerClsid(std::wstring const& appId, winrt::guid const& comServerClsid); winrt::Windows::Storage::ApplicationDataContainer m_rawStorage{ nullptr }; winrt::Windows::Storage::ApplicationDataContainer m_comServerClsidStorage{ nullptr }; diff --git a/test/TestApps/PushNotificationsDemoApp/main.cpp b/test/TestApps/PushNotificationsDemoApp/main.cpp index 8bbc13a6b8..9ee9e1d677 100644 --- a/test/TestApps/PushNotificationsDemoApp/main.cpp +++ b/test/TestApps/PushNotificationsDemoApp/main.cpp @@ -4,9 +4,8 @@ #include #include #include +#include #include "WindowsAppRuntime.Test.AppModel.h" -#include "MddBootstrap.h" -#include "WindowsAppRuntime.Test.Bootstrap.h" using namespace winrt::Microsoft::Windows::AppLifecycle; using namespace winrt::Microsoft::Windows::PushNotifications; @@ -21,7 +20,7 @@ winrt::Windows::Foundation::IAsyncOperation RequestChan { // To obtain an AAD RemoteIdentifier for your app, // follow the instructions on https://docs.microsoft.com/azure/active-directory/develop/quickstart-register-app - auto channelOperation = PushNotificationManager::CreateChannelAsync( + auto channelOperation = PushNotificationManager::Default().CreateChannelAsync( winrt::guid("0160ee84-0c53-4851-9ff2-d7f5a87ed914")); // Setup the inprogress event handler @@ -58,8 +57,8 @@ winrt::Windows::Foundation::IAsyncOperation RequestChan auto payload = args.Payload(); // Do stuff to process the raw payload - std::wstring payloadString(payload.begin(), payload.end()); - std::wcout << L"Push notification content received from FOREGROUND: " << payloadString << std::endl << std::endl; + std::string payloadString(payload.begin(), payload.end()); + std::cout << "Push notification content received from FOREGROUND: " << payloadString << std::endl << std::endl; args.Handled(true); }); // Caller's responsibility to keep the channel alive @@ -98,30 +97,30 @@ int main() auto activationInfo = ToastActivationInfo::CreateFromActivationGuid(winrt::guid("28C29657-DB85-49D2-9974-C61094CA8280")); ToastNotificationManager::Default().RegisterActivator(activationInfo); } - else - { - Test::Bootstrap::SetupBootstrap(); + else + { + // Major.Minor version, MinVersion=0 to find any framework package for this major.minor version + const UINT32 c_Version_MajorMinor{ 0x00040001 }; + const PACKAGE_VERSION minVersion{}; + RETURN_IF_FAILED(MddBootstrapInitialize(c_Version_MajorMinor, nullptr, minVersion)); + ToastAssets assets(L"ToastNotificationApp", winrt::Windows::Foundation::Uri{ LR"(C:\Windows\System32\WindowsSecurityIcon.png)" }); auto activationInfo = ToastActivationInfo::CreateFromToastAssets(assets); ToastNotificationManager::Default().RegisterActivator(activationInfo); - } - - ToastAssets assets(L"ToastNotificationApp", winrt::Windows::Foundation::Uri{ LR"(C:\Windows\System32\WindowsSecurityIcon.png)" }); - auto activationInfo = ToastActivationInfo::CreateFromToastAssets(assets); - ToastNotificationManager::Default().RegisterActivator(activationInfo); + } - if (PushNotificationManager::IsActivatorSupported(PushNotificationRegistrationActivators::ComActivator)) + if (PushNotificationManager::Default().IsActivatorSupported(PushNotificationRegistrationActivators::ComActivator)) { PushNotificationActivationInfo info( PushNotificationRegistrationActivators::PushTrigger | PushNotificationRegistrationActivators::ComActivator, winrt::guid("ccd2ae3f-764f-4ae3-be45-9804761b28b2")); // same clsid as app manifest - PushNotificationManager::RegisterActivator(info); + PushNotificationManager::Default().RegisterActivator(info); } else { PushNotificationActivationInfo info(PushNotificationRegistrationActivators::ProtocolActivator); - PushNotificationManager::RegisterActivator(info); + PushNotificationManager::Default().RegisterActivator(info); } auto args = AppInstance::GetCurrent().GetActivatedEventArgs(); @@ -158,12 +157,16 @@ int main() std::cin.ignore(); } - if (PushNotificationManager::IsActivatorSupported(PushNotificationRegistrationActivators::ComActivator)) + if (PushNotificationManager::Default().IsActivatorSupported(PushNotificationRegistrationActivators::ComActivator)) { // Don't unregister PushTrigger because we still want to receive push notifications from background infrastructure. - PushNotificationManager::UnregisterActivator(PushNotificationRegistrationActivators::ComActivator); + PushNotificationManager::Default().UnregisterActivator(PushNotificationRegistrationActivators::ComActivator); } ToastNotificationManager::Default().UnregisterActivator(); + if (!Test::AppModel::IsPackagedProcess()) + { + MddBootstrapShutdown(); + } return 0; } From 898c7549b331ec01e63bd0128a4cf8b304996f99 Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Mon, 7 Feb 2022 14:12:31 -0800 Subject: [PATCH 16/25] Issues with PushRawNotification --- .../PushNotificationBackgroundTask.cpp | 13 +++++++-- .../NotificationListener.cpp | 3 +- .../PushBackgroundTaskInstance.cpp | 2 +- .../PushBackgroundTaskInstance.h | 4 +-- .../PushNotificationsLongRunningTask.vcxproj | 2 -- ...tificationsLongRunningTask.vcxproj.filters | 6 ---- .../PushRawNotification.cpp | 27 ----------------- .../PushRawNotification.h | 29 ------------------- .../PushNotificationsLongRunningTask/pch.h | 2 +- dev/PushNotifications/externs.h | 10 ++++++- 10 files changed, 25 insertions(+), 73 deletions(-) delete mode 100644 dev/PushNotifications/PushNotificationsLongRunningTask/PushRawNotification.cpp delete mode 100644 dev/PushNotifications/PushNotificationsLongRunningTask/PushRawNotification.h diff --git a/dev/PushNotifications/PushNotificationBackgroundTask.cpp b/dev/PushNotifications/PushNotificationBackgroundTask.cpp index 2acf4542d4..051b12919e 100644 --- a/dev/PushNotifications/PushNotificationBackgroundTask.cpp +++ b/dev/PushNotifications/PushNotificationBackgroundTask.cpp @@ -29,8 +29,17 @@ namespace winrt void PushNotificationBackgroundTask::Run(winrt::IBackgroundTaskInstance const& taskInstance) { auto appProperties = winrt::CoreApplication::Properties(); - winrt::PushNotificationReceivedEventArgs activatedEventArgs{ winrt::make(taskInstance) }; - appProperties.Insert(ACTIVATED_EVENT_ARGS_KEY, activatedEventArgs); + if (PushNotificationHelpers::IsPackagedAppScenario()) + { + winrt::PushNotificationReceivedEventArgs activatedEventArgs{ winrt::make(taskInstance) }; + appProperties.Insert(ACTIVATED_EVENT_ARGS_KEY, activatedEventArgs); + } + else + { + winrt::hstring payload{ winrt::unbox_value(taskInstance.TriggerDetails()) }; + winrt::PushNotificationReceivedEventArgs activatedEventArgs{ winrt::make(payload.c_str()) }; + appProperties.Insert(LRP_ACTIVATED_EVENT_ARGS_KEY, activatedEventArgs); + } SetEvent(GetWaitHandleForArgs().get()); } diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListener.cpp b/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListener.cpp index b3f959e423..b3465ba5c1 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListener.cpp +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListener.cpp @@ -44,8 +44,7 @@ STDMETHODIMP_(HRESULT __stdcall) NotificationListener::OnRawNotificationReceived else { std::wstring payloadString(payloadArray.begin(), payloadArray.end()); - auto pushRawNotification{ winrt::make_self(payloadString) }; - auto pushBackgroundTaskInstance{ winrt::make_self(pushRawNotification) }; + auto pushBackgroundTaskInstance{ winrt::make_self(payloadString) }; auto localBackgroundTask = winrt::create_instance(m_comServerClsid, CLSCTX_ALL); localBackgroundTask.Run(*pushBackgroundTaskInstance); diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/PushBackgroundTaskInstance.cpp b/dev/PushNotifications/PushNotificationsLongRunningTask/PushBackgroundTaskInstance.cpp index 0d86433887..e7c78d6389 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/PushBackgroundTaskInstance.cpp +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/PushBackgroundTaskInstance.cpp @@ -49,5 +49,5 @@ winrt::Windows::ApplicationModel::Background::BackgroundTaskDeferral PushBackgro winrt::Windows::Foundation::IInspectable PushBackgroundTaskInstance::TriggerDetails() { - return *m_rawNotification.get(); + return winrt::box_value(m_payload); } diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/PushBackgroundTaskInstance.h b/dev/PushNotifications/PushNotificationsLongRunningTask/PushBackgroundTaskInstance.h index 97c1edd3c6..860c70fdf0 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/PushBackgroundTaskInstance.h +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/PushBackgroundTaskInstance.h @@ -5,7 +5,7 @@ struct PushBackgroundTaskInstance : winrt::implements { PushBackgroundTaskInstance() {}; - PushBackgroundTaskInstance(winrt::com_ptr rawNotification): m_rawNotification(rawNotification) {}; + PushBackgroundTaskInstance(std::wstring const& payload): m_payload(payload) {}; winrt::guid InstanceId(); UINT32 SuspendedCount(); @@ -17,7 +17,7 @@ struct PushBackgroundTaskInstance : winrt::implements m_rawNotification{ nullptr }; + std::wstring m_payload; }; struct PushBackgroundTaskInstanceFactory : winrt::implements diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj b/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj index 9e25cefadc..9ab65f3f0d 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj @@ -233,7 +233,6 @@ - @@ -246,7 +245,6 @@ - diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj.filters b/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj.filters index 8525dae2e6..e550c16df5 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj.filters +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj.filters @@ -42,9 +42,6 @@ Source Files - - Source Files - @@ -77,9 +74,6 @@ Source Files - - Source Files - diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/PushRawNotification.cpp b/dev/PushNotifications/PushNotificationsLongRunningTask/PushRawNotification.cpp deleted file mode 100644 index 15eea37d5f..0000000000 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/PushRawNotification.cpp +++ /dev/null @@ -1,27 +0,0 @@ - -#pragma once - -#include "pch.h" -#include - -winrt::Windows::Foundation::Collections::IMapView PushRawNotification::Headers() -{ - return winrt::Windows::Foundation::Collections::IMapView{}; -} - -winrt::hstring PushRawNotification::ChannelId() -{ - return winrt::hstring(); -} - -winrt::hstring PushRawNotification::Content() -{ - return winrt::hstring(m_payload); -} - -winrt::Windows::Storage::Streams::IBuffer PushRawNotification::ContentBytes() -{ - return winrt::Windows::Security::Cryptography::CryptographicBuffer::ConvertStringToBinary( - m_payload, - winrt::Windows::Security::Cryptography::BinaryStringEncoding::Utf8); -} diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/PushRawNotification.h b/dev/PushNotifications/PushNotificationsLongRunningTask/PushRawNotification.h deleted file mode 100644 index 5c25f64ff0..0000000000 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/PushRawNotification.h +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include - -struct PushRawNotification : winrt::implements -{ - PushRawNotification() {}; - PushRawNotification(std::wstring const& payload): m_payload(payload) {}; - - winrt::Windows::Foundation::Collections::IMapView Headers(); - winrt::hstring ChannelId(); - winrt::hstring Content(); - winrt::Windows::Storage::Streams::IBuffer ContentBytes(); -private: - std::wstring m_payload; -}; - -struct PushRawNotificationFactory : winrt::implements -{ - HRESULT __stdcall CreateInstance(_In_opt_ IUnknown* aggregateInterface, _In_ REFIID interfaceId, _Outptr_ VOID** object) noexcept final - { - RETURN_HR_IF(CLASS_E_NOAGGREGATION, aggregateInterface != nullptr); - return winrt::make().as(interfaceId, object); - } - - HRESULT __stdcall LockServer(BOOL) noexcept final - { - return S_OK; - } -}; diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/pch.h b/dev/PushNotifications/PushNotificationsLongRunningTask/pch.h index 338f49be8d..6d8be97e55 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/pch.h +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/pch.h @@ -27,7 +27,7 @@ #include #include #include -#include "PushRawNotification.h" + // UDK/ProxyStub files #define MIDL_NS_PREFIX #include diff --git a/dev/PushNotifications/externs.h b/dev/PushNotifications/externs.h index d66d139b9c..b484342e1f 100644 --- a/dev/PushNotifications/externs.h +++ b/dev/PushNotifications/externs.h @@ -9,6 +9,7 @@ wil::unique_event& GetWaitHandleForArgs(); inline const winrt::hstring ACTIVATED_EVENT_ARGS_KEY = L"GlobalActivatedEventArgs"; +inline const winrt::hstring LRP_ACTIVATED_EVENT_ARGS_KEY = L"LRPActivatedEventArgs"; namespace PushNotificationHelpers { @@ -34,5 +35,12 @@ inline winrt::Windows::Foundation::IInspectable GetArgsFromComStore() THROW_HR_IF(HRESULT_FROM_WIN32(ERROR_TIMEOUT), !GetWaitHandleForArgs().wait(receiveArgsTimeoutInMSec)); // If COM static store was uninit, let it throw - return winrt::Windows::ApplicationModel::Core::CoreApplication::Properties().Lookup(ACTIVATED_EVENT_ARGS_KEY); + if (PushNotificationHelpers::IsPackagedAppScenario()) + { + return winrt::Windows::ApplicationModel::Core::CoreApplication::Properties().Lookup(ACTIVATED_EVENT_ARGS_KEY); + } + else + { + return winrt::Windows::ApplicationModel::Core::CoreApplication::Properties().Lookup(LRP_ACTIVATED_EVENT_ARGS_KEY); + } } From e1c7203678dc0ad8226a193c0caf6919a6bd1db0 Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Mon, 7 Feb 2022 14:13:58 -0800 Subject: [PATCH 17/25] Update PushNotificationManager.cpp --- dev/PushNotifications/PushNotificationManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/PushNotifications/PushNotificationManager.cpp b/dev/PushNotifications/PushNotificationManager.cpp index 2851b79229..ed465dd8fe 100644 --- a/dev/PushNotifications/PushNotificationManager.cpp +++ b/dev/PushNotifications/PushNotificationManager.cpp @@ -165,7 +165,7 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation // AppId is generated by PushNotificationLongRunningTask singleton wil::unique_cotaskmem_string unpackagedAppUserModelId; RegisterUnpackagedApplicationHelper(remoteId, unpackagedAppUserModelId); - winrt::check_hresult(CreateChannelWithRemoteIdHelper(unpackagedAppUserModelId, remoteId, channelInfo)); + THROW_IF_FAILED(CreateChannelWithRemoteIdHelper(unpackagedAppUserModelId, remoteId, channelInfo)); auto notificationPlatform{ PushNotificationHelpers::GetNotificationPlatform() }; From 8cddc986c6a2f18653cd7d2ef91d1a047e06831d Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Tue, 8 Feb 2022 10:55:20 -0800 Subject: [PATCH 18/25] Fixing some nits --- .../PushNotificationBackgroundTask.cpp | 3 ++ .../PushNotificationChannel.cpp | 35 ++++++++----------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/dev/PushNotifications/PushNotificationBackgroundTask.cpp b/dev/PushNotifications/PushNotificationBackgroundTask.cpp index 051b12919e..0cf0124ff5 100644 --- a/dev/PushNotifications/PushNotificationBackgroundTask.cpp +++ b/dev/PushNotifications/PushNotificationBackgroundTask.cpp @@ -29,6 +29,8 @@ namespace winrt void PushNotificationBackgroundTask::Run(winrt::IBackgroundTaskInstance const& taskInstance) { auto appProperties = winrt::CoreApplication::Properties(); + // This function can be triggered by either OS background infrastructure + // or by the PushNotificationsLongRunningProcess. if (PushNotificationHelpers::IsPackagedAppScenario()) { winrt::PushNotificationReceivedEventArgs activatedEventArgs{ winrt::make(taskInstance) }; @@ -36,6 +38,7 @@ void PushNotificationBackgroundTask::Run(winrt::IBackgroundTaskInstance const& t } else { + // Need to mock a RawNotification object instead of winrt boxing: https://github.com/microsoft/WindowsAppSDK/issues/2075 winrt::hstring payload{ winrt::unbox_value(taskInstance.TriggerDetails()) }; winrt::PushNotificationReceivedEventArgs activatedEventArgs{ winrt::make(payload.c_str()) }; appProperties.Insert(LRP_ACTIVATED_EVENT_ARGS_KEY, activatedEventArgs); diff --git a/dev/PushNotifications/PushNotificationChannel.cpp b/dev/PushNotifications/PushNotificationChannel.cpp index 68222396ae..f7f6c7d5f2 100644 --- a/dev/PushNotifications/PushNotificationChannel.cpp +++ b/dev/PushNotifications/PushNotificationChannel.cpp @@ -5,7 +5,6 @@ #include #include "PushNotificationChannel.h" #include "Microsoft.Windows.PushNotifications.PushNotificationChannel.g.cpp" -#include #include #include "PushNotificationReceivedEventArgs.h" #include @@ -13,16 +12,9 @@ #include "PushNotificationTelemetry.h" #include "PushNotificationUtility.h" -namespace winrt::Windows -{ - using namespace winrt::Windows::Networking::PushNotifications; - using namespace winrt::Windows::Foundation; - using namespace winrt::Windows::Metadata; -} -namespace winrt::Microsoft -{ - using namespace winrt::Microsoft::Windows::PushNotifications; -} +using namespace winrt::Windows::Foundation; +using namespace winrt::Microsoft::Windows::PushNotifications; + namespace PushNotificationHelpers { @@ -31,12 +23,12 @@ namespace PushNotificationHelpers namespace winrt::Microsoft::Windows::PushNotifications::implementation { - winrt::Windows::Uri PushNotificationChannel::Uri() + Uri PushNotificationChannel::Uri() { - return winrt::Windows::Uri{ m_channelInfo.channelUri }; + return winrt::Windows::Foundation::Uri{ m_channelInfo.channelUri }; } - winrt::Windows::DateTime PushNotificationChannel::ExpirationTime() + DateTime PushNotificationChannel::ExpirationTime() { return m_channelInfo.channelExpiryTime; } @@ -62,7 +54,7 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation } } - winrt::event_token PushNotificationChannel::PushReceived(winrt::Windows::TypedEventHandler handler) + winrt::event_token PushNotificationChannel::PushReceived(TypedEventHandler handler) { bool registeredEvent { false }; { @@ -74,14 +66,14 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation { if(PushNotificationHelpers::IsPackagedAppScenario()) { - auto appUserModelId{ winrt::Microsoft::Helpers::GetAppUserModelId() }; + auto appUserModelId{ PushNotificationHelpers::GetAppUserModelId() }; // Register foreground event through the UDK THROW_IF_FAILED(PushNotifications_RegisterNotificationSinkForFullTrustApplication(appUserModelId.get(), this)); } else { - auto notificationsLongRunningPlatform{ winrt::Microsoft::Helpers::GetNotificationPlatform() }; + auto notificationsLongRunningPlatform{ PushNotificationHelpers::GetNotificationPlatform() }; wil::unique_cotaskmem_string processName; THROW_IF_FAILED(GetCurrentProcessPath(processName)); @@ -106,16 +98,17 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation if(!registeredEvent) { + // Packaged apps with BI available will remove their handlers from the platform. + // Unpackaged apps / Packaged apps treated as unpackaged will unregister from Long Running process. if (PushNotificationHelpers::IsPackagedAppScenario()) { - auto appUserModelId{ winrt::Microsoft::Helpers::GetAppUserModelId() }; + auto appUserModelId{ PushNotificationHelpers::GetAppUserModelId() }; - // Unregister foreground sink in UDK THROW_IF_FAILED(PushNotifications_UnregisterNotificationSinkForFullTrustApplication(appUserModelId.get())); } else { - auto notificationsLongRunningPlatform{ winrt::Microsoft::Helpers::GetNotificationPlatform() }; + auto notificationsLongRunningPlatform{ PushNotificationHelpers::GetNotificationPlatform() }; wil::unique_cotaskmem_string processName; THROW_IF_FAILED(GetCurrentProcessPath(processName)); @@ -143,7 +136,7 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation { wil::unique_cotaskmem_string processName; THROW_IF_FAILED(GetCurrentProcessPath(processName)); - THROW_IF_FAILED(winrt::Microsoft::Helpers::ProtocolLaunchHelper(processName.get(), payloadLength, payload)); + THROW_IF_FAILED(PushNotificationHelpers::ProtocolLaunchHelper(processName.get(), payloadLength, payload)); } return S_OK; From 6a47493c54f89cc9162eb8dbdffe7c31f975ee16 Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Tue, 8 Feb 2022 16:33:54 -0800 Subject: [PATCH 19/25] Move CoCreate packaged apps to helpers --- .../PushBackgroundTaskInstance.h | 18 +++---- .../PushNotificationChannel.cpp | 13 +++-- .../PushNotificationManager.cpp | 15 +++--- .../PushNotificationUtility.h | 12 +++++ .../PushNotifications.vcxitems | 1 + .../NotificationListener.cpp | 13 +++-- .../PushBackgroundTaskInstance.cpp | 53 ------------------- .../PushNotificationsLongRunningTask.vcxproj | 2 - ...tificationsLongRunningTask.vcxproj.filters | 6 --- dev/PushNotifications/externs.h | 1 + 10 files changed, 47 insertions(+), 87 deletions(-) rename dev/PushNotifications/{PushNotificationsLongRunningTask => }/PushBackgroundTaskInstance.h (68%) delete mode 100644 dev/PushNotifications/PushNotificationsLongRunningTask/PushBackgroundTaskInstance.cpp diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/PushBackgroundTaskInstance.h b/dev/PushNotifications/PushBackgroundTaskInstance.h similarity index 68% rename from dev/PushNotifications/PushNotificationsLongRunningTask/PushBackgroundTaskInstance.h rename to dev/PushNotifications/PushBackgroundTaskInstance.h index 860c70fdf0..0b4993aea6 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/PushBackgroundTaskInstance.h +++ b/dev/PushNotifications/PushBackgroundTaskInstance.h @@ -7,15 +7,15 @@ struct PushBackgroundTaskInstance : winrt::implementsRegisterLongRunningActivatorWithClsid(processName.get(), s_taskClsid)); + THROW_IF_FAILED(notificationPlatform->RegisterLongRunningActivatorWithClsid(processName.get(), GetComServerClsid())); std::wstring toastAppId{ RetrieveToastAppId() }; THROW_IF_FAILED(notificationPlatform->AddToastRegistrationMapping(processName.get(), toastAppId.c_str())); @@ -331,11 +336,7 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation } GetWaitHandleForArgs().create(); - - { - auto lock{ s_activatorInfoLock.lock_exclusive() }; - s_taskClsid = taskClsid; - } + GetComServerClsid() = taskClsid; THROW_IF_FAILED(::CoRegisterClassObject( taskClsid, diff --git a/dev/PushNotifications/PushNotificationUtility.h b/dev/PushNotifications/PushNotificationUtility.h index e5b89298fb..4b9fe9099c 100644 --- a/dev/PushNotifications/PushNotificationUtility.h +++ b/dev/PushNotifications/PushNotificationUtility.h @@ -6,6 +6,7 @@ #include "NotificationsLongRunningProcess_h.h" #include #include "../Common/AppModel.Identity.h" +#include "PushBackgroundTaskInstance.h" namespace winrt { @@ -108,6 +109,17 @@ namespace winrt::Microsoft::Windows::PushNotifications::Helpers } CATCH_RETURN() + inline HRESULT PackagedAppLauncherByClsid(winrt::guid const& comServerClsid, unsigned int payloadLength, _In_reads_(payloadLength) byte* payload) noexcept try + { + auto payloadAsWideString{ Utf8BytesToWideString(payloadLength, payload) }; + auto pushBackgroundTaskInstance{ winrt::make_self(payloadAsWideString) }; + + auto localBackgroundTask = winrt::create_instance(comServerClsid, CLSCTX_ALL); + localBackgroundTask.Run(*pushBackgroundTaskInstance); + return S_OK; + } + CATCH_RETURN() + inline wil::com_ptr GetNotificationPlatform() { return wil::CoCreateInstance(CLSCTX_LOCAL_SERVER); diff --git a/dev/PushNotifications/PushNotifications.vcxitems b/dev/PushNotifications/PushNotifications.vcxitems index 3e6d5a339d..67f0907d9f 100644 --- a/dev/PushNotifications/PushNotifications.vcxitems +++ b/dev/PushNotifications/PushNotifications.vcxitems @@ -27,6 +27,7 @@ + diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListener.cpp b/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListener.cpp index b3465ba5c1..3b13b001fb 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListener.cpp +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/NotificationListener.cpp @@ -3,7 +3,6 @@ #include "pch.h" #include "../PushNotificationUtility.h" #include -#include "PushBackgroundTaskInstance.h" using namespace winrt::Windows::ApplicationModel::Background; namespace ToastNotifications @@ -11,6 +10,10 @@ namespace ToastNotifications using namespace ABI::Microsoft::Internal::ToastNotifications; } +namespace PushNotificationHelpers +{ + using namespace winrt::Microsoft::Windows::PushNotifications::Helpers; +} HRESULT NotificationListener::RuntimeClassInitialize( std::shared_ptr foregroundSinkManager, std::shared_ptr toastRegistrationManager, @@ -39,15 +42,11 @@ STDMETHODIMP_(HRESULT __stdcall) NotificationListener::OnRawNotificationReceived { if (m_comServerClsid == winrt::guid()) { - THROW_IF_FAILED(winrt::Microsoft::Windows::PushNotifications::Helpers::ProtocolLaunchHelper(m_processName, payloadLength, payload)); + THROW_IF_FAILED(PushNotificationHelpers::ProtocolLaunchHelper(m_processName, payloadLength, payload)); } else { - std::wstring payloadString(payloadArray.begin(), payloadArray.end()); - auto pushBackgroundTaskInstance{ winrt::make_self(payloadString) }; - - auto localBackgroundTask = winrt::create_instance(m_comServerClsid, CLSCTX_ALL); - localBackgroundTask.Run(*pushBackgroundTaskInstance); + THROW_IF_FAILED(PushNotificationHelpers::PackagedAppLauncherByClsid(m_comServerClsid, payloadLength, payload)); } }; diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/PushBackgroundTaskInstance.cpp b/dev/PushNotifications/PushNotificationsLongRunningTask/PushBackgroundTaskInstance.cpp deleted file mode 100644 index e7c78d6389..0000000000 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/PushBackgroundTaskInstance.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#pragma once - -#include "pch.h" - -#include "PushBackgroundTaskInstance.h" -#include - -using namespace winrt::Windows::Networking::PushNotifications; - -winrt::guid PushBackgroundTaskInstance::InstanceId() -{ - return winrt::guid(); -} - -UINT32 PushBackgroundTaskInstance::SuspendedCount() -{ - return 0; -} - -UINT32 PushBackgroundTaskInstance::Progress() -{ - return 0; -} - -UINT32 PushBackgroundTaskInstance::Progress(UINT32 /* progress */) -{ - return 0; -} - -winrt::Windows::ApplicationModel::Background::BackgroundTaskRegistration PushBackgroundTaskInstance::Task() -{ - return nullptr; -} - -winrt::event_token PushBackgroundTaskInstance::Canceled(winrt::Windows::ApplicationModel::Background::BackgroundTaskCanceledEventHandler const& /* handler */) -{ - return winrt::event_token{}; -} - -void PushBackgroundTaskInstance::Canceled(winrt::event_token const& /* token */) noexcept -{ - return; -} - -winrt::Windows::ApplicationModel::Background::BackgroundTaskDeferral PushBackgroundTaskInstance::GetDeferral() -{ - return nullptr; -} - -winrt::Windows::Foundation::IInspectable PushBackgroundTaskInstance::TriggerDetails() -{ - return winrt::box_value(m_payload); -} diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj b/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj index 9ab65f3f0d..e5b654a7eb 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj @@ -232,7 +232,6 @@ - @@ -244,7 +243,6 @@ - diff --git a/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj.filters b/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj.filters index e550c16df5..5a66aedcae 100644 --- a/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj.filters +++ b/dev/PushNotifications/PushNotificationsLongRunningTask/PushNotificationsLongRunningTask.vcxproj.filters @@ -39,9 +39,6 @@ Header Files - - Source Files - @@ -71,9 +68,6 @@ Source Files - - Source Files - diff --git a/dev/PushNotifications/externs.h b/dev/PushNotifications/externs.h index b484342e1f..427319b5c2 100644 --- a/dev/PushNotifications/externs.h +++ b/dev/PushNotifications/externs.h @@ -7,6 +7,7 @@ #include "PushNotificationUtility.h" wil::unique_event& GetWaitHandleForArgs(); +winrt::guid& GetComServerClsid(); inline const winrt::hstring ACTIVATED_EVENT_ARGS_KEY = L"GlobalActivatedEventArgs"; inline const winrt::hstring LRP_ACTIVATED_EVENT_ARGS_KEY = L"LRPActivatedEventArgs"; From bc6102c78594d3fad422bab5d202c43ce7247798 Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Wed, 9 Feb 2022 22:17:37 -0800 Subject: [PATCH 20/25] Remove background activation when args is handled --- dev/PushNotifications/PushNotificationChannel.cpp | 6 +----- dev/PushNotifications/PushNotificationManager.cpp | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/dev/PushNotifications/PushNotificationChannel.cpp b/dev/PushNotifications/PushNotificationChannel.cpp index 5ccae75f0f..5d06bc53cb 100644 --- a/dev/PushNotifications/PushNotificationChannel.cpp +++ b/dev/PushNotifications/PushNotificationChannel.cpp @@ -134,11 +134,7 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation if (!foregroundHandled) { - if (AppModel::Identity::IsPackagedProcess()) - { - THROW_IF_FAILED(PushNotificationHelpers::PackagedAppLauncherByClsid(GetComServerClsid(), payloadLength, payload)); - } - else + if (!AppModel::Identity::IsPackagedProcess()) { wil::unique_cotaskmem_string processName; THROW_IF_FAILED(GetCurrentProcessPath(processName)); diff --git a/dev/PushNotifications/PushNotificationManager.cpp b/dev/PushNotifications/PushNotificationManager.cpp index d94191b4f6..f28f443dde 100644 --- a/dev/PushNotifications/PushNotificationManager.cpp +++ b/dev/PushNotifications/PushNotificationManager.cpp @@ -160,7 +160,7 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation try { ChannelDetails channelInfo{}; - if (IsActivatorSupported(PushNotificationRegistrationActivators::PushTrigger)) + if (PushNotificationHelpers::IsPackagedAppScenario()) { auto appUserModelId{ PushNotificationHelpers::GetAppUserModelId() }; THROW_IF_FAILED(CreateChannelWithRemoteIdHelper(appUserModelId, remoteId, channelInfo)); From dfaaad4f8f0ae869cf1476ccb00619eb3f104756 Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Thu, 10 Feb 2022 21:55:54 -0800 Subject: [PATCH 21/25] Update main.cpp --- test/TestApps/PushNotificationsDemoApp/main.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/test/TestApps/PushNotificationsDemoApp/main.cpp b/test/TestApps/PushNotificationsDemoApp/main.cpp index 7ad7bf6f27..b2aa63a7cb 100644 --- a/test/TestApps/PushNotificationsDemoApp/main.cpp +++ b/test/TestApps/PushNotificationsDemoApp/main.cpp @@ -93,20 +93,11 @@ winrt::Microsoft::Windows::PushNotifications::PushNotificationChannel RequestCha int main() { if (!Test::AppModel::IsPackagedProcess()) - { - auto activationInfo = ToastActivationInfo::CreateFromActivationGuid(winrt::guid("28C29657-DB85-49D2-9974-C61094CA8280")); - ToastNotificationManager::Default().RegisterActivator(activationInfo); - } - else { // Major.Minor version, MinVersion=0 to find any framework package for this major.minor version const UINT32 c_Version_MajorMinor{ 0x00040001 }; const PACKAGE_VERSION minVersion{}; RETURN_IF_FAILED(MddBootstrapInitialize(c_Version_MajorMinor, nullptr, minVersion)); - - ToastAssets assets(L"ToastNotificationApp", winrt::Windows::Foundation::Uri{ LR"(C:\Windows\System32\WindowsSecurityIcon.png)" }); - auto activationInfo = ToastActivationInfo::CreateFromToastAssets(assets); - ToastNotificationManager::Default().RegisterActivator(activationInfo); } if (PushNotificationManager::Default().IsActivatorSupported(PushNotificationRegistrationActivators::ComActivator)) From e76cae07a3e20a54cc9a73a4bb189115c02656e6 Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Mon, 14 Feb 2022 10:51:55 -0800 Subject: [PATCH 22/25] Remove legacyImplementation from telemetry --- dev/PushNotifications/PushNotificationChannel.cpp | 4 ++-- dev/PushNotifications/PushNotificationManager.cpp | 7 +++---- dev/PushNotifications/PushNotificationManager.h | 2 +- dev/PushNotifications/PushNotificationTelemetry.h | 4 +--- dev/PushNotifications/PushNotifications.idl | 2 +- 5 files changed, 8 insertions(+), 11 deletions(-) diff --git a/dev/PushNotifications/PushNotificationChannel.cpp b/dev/PushNotifications/PushNotificationChannel.cpp index 5d06bc53cb..aa8c82b736 100644 --- a/dev/PushNotifications/PushNotificationChannel.cpp +++ b/dev/PushNotifications/PushNotificationChannel.cpp @@ -68,7 +68,7 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation { auto appUserModelId{ PushNotificationHelpers::GetAppUserModelId() }; - // Register foreground event through the UDK + // Register a sink with platform which is initialized in the current process THROW_IF_FAILED(PushNotifications_RegisterNotificationSinkForFullTrustApplication(appUserModelId.get(), this)); } else @@ -78,7 +78,7 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation wil::unique_cotaskmem_string processName; THROW_IF_FAILED(GetCurrentProcessPath(processName)); - // Register foreground event through the LRP + // Register a sink with platform brokered through PushNotificationsLongRunningProcess THROW_IF_FAILED(notificationsLongRunningPlatform->RegisterForegroundActivator(this, processName.get())); } } diff --git a/dev/PushNotifications/PushNotificationManager.cpp b/dev/PushNotifications/PushNotificationManager.cpp index c227caa443..36cf77613d 100644 --- a/dev/PushNotifications/PushNotificationManager.cpp +++ b/dev/PushNotifications/PushNotificationManager.cpp @@ -132,7 +132,6 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation THROW_HR_IF(E_NOTIMPL, !::Microsoft::Windows::PushNotifications::Feature_PushNotifications::IsEnabled()); wil::winrt_module_reference moduleRef{}; - bool usingLegacyImplementation{ false }; try { @@ -183,7 +182,7 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation THROW_IF_FAILED(notificationPlatform->AddToastRegistrationMapping(processName.get(), toastAppId.c_str())); } - PushNotificationTelemetry::ChannelRequestedByApi(S_OK, remoteId, usingLegacyImplementation); + PushNotificationTelemetry::ChannelRequestedByApi(S_OK, remoteId); co_return winrt::make( winrt::make(channelInfo), S_OK, @@ -203,7 +202,7 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation } else { - PushNotificationTelemetry::ChannelRequestedByApi(channelRequestException.code(), remoteId, usingLegacyImplementation); + PushNotificationTelemetry::ChannelRequestedByApi(channelRequestException.code(), remoteId); co_return winrt::make( nullptr, @@ -217,7 +216,7 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation } catch (...) { - PushNotificationTelemetry::ChannelRequestedByApi(wil::ResultFromCaughtException(), remoteId, usingLegacyImplementation); + PushNotificationTelemetry::ChannelRequestedByApi(wil::ResultFromCaughtException(), remoteId); throw; } } diff --git a/dev/PushNotifications/PushNotificationManager.h b/dev/PushNotifications/PushNotificationManager.h index 98d05fc1fb..3120f2c487 100644 --- a/dev/PushNotifications/PushNotificationManager.h +++ b/dev/PushNotifications/PushNotificationManager.h @@ -19,7 +19,7 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation winrt::Windows::Foundation::IAsyncOperationWithProgress CreateChannelAsync(winrt::guid const remoteId); - bool IsActivatorSupported(Microsoft::Windows::PushNotifications::PushNotificationRegistrationActivators const& activators); + static bool IsActivatorSupported(Microsoft::Windows::PushNotifications::PushNotificationRegistrationActivators const& activators); }; } diff --git a/dev/PushNotifications/PushNotificationTelemetry.h b/dev/PushNotifications/PushNotificationTelemetry.h index fc62ca3606..31be2a5f07 100644 --- a/dev/PushNotifications/PushNotificationTelemetry.h +++ b/dev/PushNotifications/PushNotificationTelemetry.h @@ -21,8 +21,7 @@ class PushNotificationTelemetry : public wil::TraceLoggingProvider public: DEFINE_EVENT_METHOD(ChannelRequestedByApi)( winrt::hresult hr, - const winrt::guid& remoteId, - bool usingLegacyImplementation) noexcept try + const winrt::guid& remoteId) noexcept try { if (c_maxEventLimit >= UpdateLogEventCount()) { @@ -32,7 +31,6 @@ class PushNotificationTelemetry : public wil::TraceLoggingProvider _GENERIC_PARTB_FIELDS_ENABLED, TraceLoggingHexUInt32(hr, "OperationResult"), TraceLoggingGuid(remoteId, "RemoteId"), - TraceLoggingBool(usingLegacyImplementation, "usingLegacyImplementation"), TraceLoggingBool(IsPackagedApp(), "IsAppPackaged"), TraceLoggingWideString(GetAppName(), "AppName")); } diff --git a/dev/PushNotifications/PushNotifications.idl b/dev/PushNotifications/PushNotifications.idl index 7e19b466b2..7fb3a82b2e 100644 --- a/dev/PushNotifications/PushNotifications.idl +++ b/dev/PushNotifications/PushNotifications.idl @@ -134,6 +134,6 @@ namespace Microsoft.Windows.PushNotifications Windows.Foundation.IAsyncOperationWithProgress CreateChannelAsync(Guid remoteId); // Applications will call this to check which flags are supported for RegisterActivator - Boolean IsActivatorSupported(PushNotificationRegistrationActivators activators); + static Boolean IsActivatorSupported(PushNotificationRegistrationActivators activators); }; } From 3a6edd99476ce147bf65a123422f99433134a5d5 Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Mon, 14 Feb 2022 11:46:06 -0800 Subject: [PATCH 23/25] Add Default to TestApp --- .../PushNotificationsTestApp/main.cpp | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/test/TestApps/PushNotificationsTestApp/main.cpp b/test/TestApps/PushNotificationsTestApp/main.cpp index a8fabd0728..1eea034c34 100644 --- a/test/TestApps/PushNotificationsTestApp/main.cpp +++ b/test/TestApps/PushNotificationsTestApp/main.cpp @@ -24,7 +24,7 @@ bool ChannelRequestUsingNullRemoteId() { try { - auto channelOperation = PushNotificationManager::CreateChannelAsync(winrt::guid()).get(); + auto channelOperation = PushNotificationManager::Default().CreateChannelAsync(winrt::guid()).get(); } catch (...) { @@ -54,7 +54,7 @@ HRESULT ChannelRequestHelper(IAsyncOperationWithProgress Date: Mon, 14 Feb 2022 12:10:09 -0800 Subject: [PATCH 24/25] Update main.cpp --- test/TestApps/ToastNotificationsDemoApp/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/TestApps/ToastNotificationsDemoApp/main.cpp b/test/TestApps/ToastNotificationsDemoApp/main.cpp index 6d34eadc34..0c491fd97d 100644 --- a/test/TestApps/ToastNotificationsDemoApp/main.cpp +++ b/test/TestApps/ToastNotificationsDemoApp/main.cpp @@ -25,7 +25,7 @@ winrt::IAsyncOperation RequestChannelAsync() { // To obtain an AAD RemoteIdentifier for your app, // follow the instructions on https://docs.microsoft.com/azure/active-directory/develop/quickstart-register-app - auto channelOperation = winrt::PushNotificationManager::CreateChannelAsync( + auto channelOperation = winrt::PushNotificationManager::Default().CreateChannelAsync( winrt::guid("0160ee84-0c53-4851-9ff2-d7f5a87ed914")); // Setup the inprogress event handler From abafda7483f23c956441f33f07dac3ac1af55016 Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Mon, 14 Feb 2022 12:36:32 -0800 Subject: [PATCH 25/25] Update main.cpp --- .../ToastNotificationsTestApp/main.cpp | 23 ++----------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/test/TestApps/ToastNotificationsTestApp/main.cpp b/test/TestApps/ToastNotificationsTestApp/main.cpp index c48b83bab0..90d2cd7cbd 100644 --- a/test/TestApps/ToastNotificationsTestApp/main.cpp +++ b/test/TestApps/ToastNotificationsTestApp/main.cpp @@ -47,27 +47,6 @@ winrt::AppNotificationProgressData GetToastProgressData(std::wstring const& stat return progressData; } -bool BackgroundActivationTest() // Activating application for background test. -{ - return true; -} - -bool UnregisterBackgroundActivationTest() -{ - winrt::ToastNotificationManager::Default().UnregisterActivator(); - return true; -} - -winrt::ToastNotification GetToastNotification() -{ - winrt::hstring xmlPayload{ L"intrepidToast" }; - - winrt::XmlDocument xmlDocument{}; - xmlDocument.LoadXml(xmlPayload); - - return winrt::ToastNotification(xmlDocument); -} - bool VerifyFailedRegisterActivatorUsingNullClsid() { try @@ -564,6 +543,7 @@ bool VerifyUpdateToastProgressDataUsingEmptyTagAndValidGroup() { return winrt::to_hresult() == E_INVALIDARG; } + return false; } bool VerifyUpdateToastProgressDataUsingEmptyTagAndEmptyGroup() @@ -578,6 +558,7 @@ bool VerifyUpdateToastProgressDataUsingEmptyTagAndEmptyGroup() { return winrt::to_hresult() == E_INVALIDARG; } + return false; } bool VerifyFailedUpdateNotificationDataWithNonExistentTagAndGroup()