Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interfaces for "Enhanced UX Notification for Video and Audio Call Feature" #4783

Merged
merged 16 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions dev/AppNotifications/AppNotification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,16 @@ namespace winrt::Microsoft::Windows::AppNotifications::implementation
auto lock{ m_lock.lock_exclusive() };
m_notificationId = id;
}

winrt::Microsoft::Windows::AppNotifications::AppNotificationDevicesData AppNotification::DevicesData()
{
auto lock{ m_lock.lock_shared() };
return m_devicesData;
}

void AppNotification::DevicesData(winrt::Microsoft::Windows::AppNotifications::AppNotificationDevicesData const& devicesData)
{
auto lock{ m_lock.lock_exclusive() };
m_devicesData = devicesData;
}
}
5 changes: 5 additions & 0 deletions dev/AppNotifications/AppNotification.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ namespace winrt::Microsoft::Windows::AppNotifications::implementation
// IAppNotificationInternal
void SetNotificationId(uint32_t id);

winrt::Microsoft::Windows::AppNotifications::AppNotificationDevicesData DevicesData();
void DevicesData(winrt::Microsoft::Windows::AppNotifications::AppNotificationDevicesData const& value);

private:
winrt::hstring m_tag{};
winrt::hstring m_group{};
Expand All @@ -49,6 +52,8 @@ namespace winrt::Microsoft::Windows::AppNotifications::implementation
{ winrt::Microsoft::Windows::AppNotifications::AppNotificationPriority::Default };
bool m_suppressDisplay{ false };
wil::srwlock m_lock;

winrt::Microsoft::Windows::AppNotifications::AppNotificationDevicesData m_devicesData{ nullptr };
};
}
namespace winrt::Microsoft::Windows::AppNotifications::factory_implementation
Expand Down
46 changes: 46 additions & 0 deletions dev/AppNotifications/AppNotificationDevicesData.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "pch.h"
#include "AppNotificationDevicesData.h"
#include "Microsoft.Windows.AppNotifications.AppNotificationDevicesData.g.cpp"
#include <IsWindowsVersion.h>

namespace winrt::Microsoft::Windows::AppNotifications::implementation
{
hstring AppNotificationDevicesData::CameraDeviceId()
{
return m_cameraDeviceId;
}

void AppNotificationDevicesData::CameraDeviceId(hstring const& value)
{
m_cameraDeviceId = value;
satkh marked this conversation as resolved.
Show resolved Hide resolved
}

hstring AppNotificationDevicesData::MicrophoneDeviceId()
{
return m_microphoneDeviceId;
}

void AppNotificationDevicesData::MicrophoneDeviceId(hstring const& value)
{
m_microphoneDeviceId = value;
}

hstring AppNotificationDevicesData::SpeakerDeviceId()
{
return m_speakerDeviceId;
}

void AppNotificationDevicesData::SpeakerDeviceId(hstring const& value)
{
m_speakerDeviceId = value;
}

/// <summary>
/// verifies if video calling is supported <TO DO>
/// </summary>
/// <returns>bool</returns>
bool AppNotificationDevicesData::IsVideoOrAudioCallingSupported()
{
return WindowsVersion::IsWindows11_23H1OrGreater(); // Windows 11 23H1 or greater
satkh marked this conversation as resolved.
Show resolved Hide resolved
}
}
34 changes: 34 additions & 0 deletions dev/AppNotifications/AppNotificationDevicesData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once
#include "Microsoft.Windows.AppNotifications.AppNotificationDevicesData.g.h"

namespace winrt::Microsoft::Windows::AppNotifications::implementation
{
struct AppNotificationDevicesData : AppNotificationDevicesDataT<AppNotificationDevicesData>
{
AppNotificationDevicesData() = default;

// Getters
hstring CameraDeviceId();
hstring MicrophoneDeviceId();
hstring SpeakerDeviceId();

// Setters
void CameraDeviceId(hstring const& value);
void MicrophoneDeviceId(hstring const& value);
void SpeakerDeviceId(hstring const& value);

static bool IsVideoOrAudioCallingSupported();

private:

hstring m_cameraDeviceId{};
hstring m_microphoneDeviceId{};
hstring m_speakerDeviceId{};
};
}
namespace winrt::Microsoft::Windows::AppNotifications::factory_implementation
{
struct AppNotificationDevicesData : AppNotificationDevicesDataT<AppNotificationDevicesData, implementation::AppNotificationDevicesData>
{
};
}
25 changes: 24 additions & 1 deletion dev/AppNotifications/AppNotifications.idl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation and Contributors.
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.
import "..\AppLifecycle\AppLifecycle.idl";

Expand Down Expand Up @@ -111,6 +111,29 @@ namespace Microsoft.Windows.AppNotifications

// Gets or sets whether a Notification's pop-up UI is displayed on the user's screen.
Boolean SuppressDisplay;

// Gets or sets the Notification Device Data
AppNotificationDevicesData DevicesData;
satkh marked this conversation as resolved.
Show resolved Hide resolved
satkh marked this conversation as resolved.
Show resolved Hide resolved
satkh marked this conversation as resolved.
Show resolved Hide resolved
satkh marked this conversation as resolved.
Show resolved Hide resolved
}

// The Notification Device Data
[contract(AppNotificationsContract, 2)]
satkh marked this conversation as resolved.
Show resolved Hide resolved
runtimeclass AppNotificationDevicesData
satkh marked this conversation as resolved.
Show resolved Hide resolved
satkh marked this conversation as resolved.
Show resolved Hide resolved
{
// Initializes a new Instance of NotificationDevicesData
AppNotificationDevicesData();

// Checks if Video or Audio Calling is supported
static Boolean IsVideoOrAudioCallingSupported();
satkh marked this conversation as resolved.
Show resolved Hide resolved

// Gets or sets the Camera Device Id
String CameraDeviceId{ get; set; };
satkh marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is set to the empty string (note: String cannot be null) or an invalid device identifier, I presume your toast will not show anything?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Toast will show system default device id as the ticked one if it's null / empty
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Device validation is performed within the shell code. First, the shell invokes the existing enumerate API to retrieve a list of connected devices. It then compares these devices with those provided by the aforementioned APIs. If a match is found, the device is selected for preview and selected in the list (as shown in last mock image above). Otherwise, 'system default' devices will be displayed for preview and selection.

satkh marked this conversation as resolved.
Show resolved Hide resolved

// Gets or sets the Microphone Device Id
String MicrophoneDeviceId{ get; set; };
satkh marked this conversation as resolved.
Show resolved Hide resolved

// Gets or sets the Speaker Device Id
String SpeakerDeviceId{ get; set; };
satkh marked this conversation as resolved.
Show resolved Hide resolved
}

// The manager class which encompasses all App Notification API Functionality
Expand Down
4 changes: 4 additions & 0 deletions dev/AppNotifications/AppNotifications.vcxitems
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<ClInclude Include="$(MSBuildThisFileDirectory)NotificationTransientProperties.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)NotificationProgressData.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)ShellLocalization.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)AppNotificationDevicesData.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)NotificationDevicesData.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="$(MSBuildThisFileDirectory)AppNotificationActivatedEventArgs.cpp" />
Expand All @@ -35,6 +37,8 @@
<ClCompile Include="$(MSBuildThisFileDirectory)NotificationTransientProperties.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)NotificationProgressData.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)ShellLocalization.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)AppNotificationDevicesData.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)NotificationDevicesData.cpp" />
</ItemGroup>
<ItemGroup>
<Midl Include="$(MSBuildThisFileDirectory)AppNotifications.idl" />
Expand Down
41 changes: 41 additions & 0 deletions dev/AppNotifications/NotificationDevicesData.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.

#include "pch.h"

#include "AppNotificationDevicesData.h"
#include "NotificationDevicesData.h"
#include "AppNotificationUtility.h"

using namespace Microsoft::Windows::AppNotifications::Helpers;

NotificationDevicesData::NotificationDevicesData(winrt::AppNotificationDevicesData const& devicesData)
: m_devicesData(devicesData)
{
}

STDMETHODIMP NotificationDevicesData::get_CameraDeviceId(_Out_ HSTRING* value) noexcept try
satkh marked this conversation as resolved.
Show resolved Hide resolved
{
*value = safe_make_unique_hstring(m_devicesData.CameraDeviceId().c_str()).release();
return S_OK;
}
CATCH_RETURN()

STDMETHODIMP NotificationDevicesData::get_MicrophoneDeviceId(_Out_ HSTRING* value) noexcept try
{
*value = safe_make_unique_hstring(m_devicesData.MicrophoneDeviceId().c_str()).release();
return S_OK;
}
CATCH_RETURN()


STDMETHODIMP NotificationDevicesData::get_SpeakerDeviceId(_Out_ HSTRING* value) noexcept try
{
*value = safe_make_unique_hstring(m_devicesData.SpeakerDeviceId().c_str()).release();
return S_OK;
}
CATCH_RETURN()




31 changes: 31 additions & 0 deletions dev/AppNotifications/NotificationDevicesData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.

#pragma once

#include <frameworkUdk/ToastNotificationsRT.h>

namespace winrt
{
using namespace winrt::Microsoft::Windows::AppNotifications;
}

namespace ToastABI
{
using namespace ::ABI::Microsoft::Internal::ToastNotifications;
}

struct NotificationDevicesData : winrt::implements<NotificationDevicesData, ToastABI::IToastDevicesData>
{
NotificationDevicesData(winrt::AppNotificationDevicesData const& devicesData);

STDMETHOD(get_CameraDeviceId)(_Out_ HSTRING* value) noexcept;

STDMETHOD(get_MicrophoneDeviceId)(_Out_ HSTRING* value) noexcept;

STDMETHOD(get_SpeakerDeviceId)(_Out_ HSTRING* value) noexcept;

private:

winrt::AppNotificationDevicesData m_devicesData;
};
24 changes: 23 additions & 1 deletion dev/AppNotifications/NotificationProperties.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation and Contributors.
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.

#include "pch.h"
Expand All @@ -8,6 +8,8 @@
#include "AppNotificationUtility.h"
#include "../PushNotifications/PushNotificationUtility.h"
#include "NotificationProgressData.h"
#include "NotificationDevicesData.h"
#include "AppNotificationDevicesData.h"

namespace winrt
{
Expand Down Expand Up @@ -47,6 +49,14 @@ NotificationProperties::NotificationProperties(winrt::AppNotification const& toa
{
m_toastProgressData = winrt::make_self<NotificationProgressData>(toastNotification.Progress());
}

satkh marked this conversation as resolved.
Show resolved Hide resolved
if (winrt::AppNotificationDevicesData::IsVideoOrAudioCallingSupported())
{
if (toastNotification.DevicesData() != nullptr)
{
m_toastDevicesData = winrt::make_self<NotificationDevicesData>(toastNotification.DevicesData());
}
}
}

STDMETHODIMP_(HRESULT __stdcall) NotificationProperties::get_NotificationId(_Out_ unsigned int* notificationId) noexcept
Expand Down Expand Up @@ -147,3 +157,15 @@ STDMETHODIMP_(HRESULT __stdcall) NotificationProperties::get_ActivityId(_Out_ GU
*activityId = GUID_NULL;
return S_OK;
}

STDMETHODIMP_(HRESULT __stdcall) NotificationProperties::get_ToastDevicesData(_Out_ ToastABI::IToastDevicesData** devicesData) noexcept
{
*devicesData = nullptr;
auto lock{ m_lock.lock_shared() };
if (m_toastDevicesData != nullptr)
satkh marked this conversation as resolved.
Show resolved Hide resolved
{
m_toastDevicesData.copy_to(devicesData);
}

return S_OK;
}
7 changes: 5 additions & 2 deletions dev/AppNotifications/NotificationProperties.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) Microsoft Corporation and Contributors.
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.

#pragma once

#include <frameworkUdk/ToastNotificationsRT.h>

struct NotificationProperties : winrt::implements<NotificationProperties, ::ABI::Microsoft::Internal::ToastNotifications::INotificationProperties>
struct NotificationProperties : winrt::implements<NotificationProperties, ::ABI::Microsoft::Internal::ToastNotifications::INotificationProperties, ::ABI::Microsoft::Internal::ToastNotifications::INotificationProperties2>
{
NotificationProperties(winrt::Microsoft::Windows::AppNotifications::AppNotification const& toastNotification);

Expand All @@ -31,6 +31,8 @@ struct NotificationProperties : winrt::implements<NotificationProperties, ::ABI:

STDMETHOD(get_ActivityId)(_Out_ GUID* activityId) noexcept;

STDMETHOD(get_ToastDevicesData)(_Out_ ABI::Microsoft::Internal::ToastNotifications::IToastDevicesData** devicesData) noexcept;

private:
wil::srwlock m_lock;

Expand All @@ -49,4 +51,5 @@ struct NotificationProperties : winrt::implements<NotificationProperties, ::ABI:
bool m_expiresOnReboot = false;

winrt::com_ptr<ABI::Microsoft::Internal::ToastNotifications::IToastProgressData> m_toastProgressData{ nullptr };
winrt::com_ptr<ABI::Microsoft::Internal::ToastNotifications::IToastDevicesData> m_toastDevicesData{ nullptr };
};
41 changes: 40 additions & 1 deletion test/AppNotificationTests/BaseTestSuite.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#include "pch.h"
Expand Down Expand Up @@ -598,3 +598,42 @@ void BaseTestSuite::VerifyExplicitAppId()
RegisterWithAppNotificationManager();
AppNotificationManager::Default().Unregister();
}

void BaseTestSuite::VerifyToastDevicesDataAllDevicesSet()
{
AppNotification toast{ CreateToastNotification() };

AppNotificationDevicesData devicesData{ nullptr };
devicesData.CameraDeviceId(L"CameraDeviceId");
devicesData.MicrophoneDeviceId(L"MicrophoneDeviceId");
devicesData.SpeakerDeviceId(L"SpeakerDeviceId");

toast.DevicesData(devicesData);

VERIFY_ARE_EQUAL(toast.DevicesData().CameraDeviceId(), L"CameraDeviceId");
VERIFY_ARE_EQUAL(toast.DevicesData().MicrophoneDeviceId(), L"MicrophoneDeviceId");
VERIFY_ARE_EQUAL(toast.DevicesData().SpeakerDeviceId(), L"SpeakerDeviceId");
}

void BaseTestSuite::VerifyToastDevicesDataNoDevicesSet()
{
AppNotification toast{ CreateToastNotification() };

VERIFY_ARE_EQUAL(toast.DevicesData().CameraDeviceId(), L"");
VERIFY_ARE_EQUAL(toast.DevicesData().MicrophoneDeviceId(), L"");
VERIFY_ARE_EQUAL(toast.DevicesData().SpeakerDeviceId(), L"");
}

void BaseTestSuite::VerifyToastDevicesDataNotAllDevicesSet()
{
AppNotification toast{ CreateToastNotification() };

AppNotificationDevicesData devicesData{ nullptr };
devicesData.CameraDeviceId(L"CameraDeviceId");

toast.DevicesData(devicesData);

VERIFY_ARE_EQUAL(toast.DevicesData().CameraDeviceId(), L"CameraDeviceId");
VERIFY_ARE_EQUAL(toast.DevicesData().MicrophoneDeviceId(), L"");
VERIFY_ARE_EQUAL(toast.DevicesData().SpeakerDeviceId(), L"");
}
6 changes: 5 additions & 1 deletion test/AppNotificationTests/BaseTestSuite.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#include "pch.h"
Expand Down Expand Up @@ -54,6 +54,10 @@ class BaseTestSuite
void VerifyToastProgressDataSequence0Fail();
void VerifyIconPathExists();
void VerifyExplicitAppId();
void VerifyToastDevicesDataAllDevicesSet();
void VerifyToastDevicesDataNotAllDevicesSet();
void VerifyToastDevicesDataNoDevicesSet();

private:
void RegisterWithAppNotificationManager();
void UnregisterAllWithAppNotificationManager();
Expand Down