Skip to content

Commit

Permalink
fix(AudioSwitching): Fix issue for Windows 10 <= 1709 where the new a…
Browse files Browse the repository at this point in the history
…udio API aren't available

Fixes SOUNDSWITCH-GS
  • Loading branch information
Belphemur authored Dec 20, 2021
2 parents cf393ed + 5bce7e9 commit ad66ec0
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 4 deletions.
29 changes: 29 additions & 0 deletions SoundSwitch.Audio.Manager.Tests/AudioPolicyConfigTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using NUnit.Framework;
using SoundSwitch.Audio.Manager.Interop.Client.Extended;
using SoundSwitch.Audio.Manager.Interop.Client.Extended.Factory;

namespace SoundSwitch.Audio.Manager.Tests;

[TestFixture]
public sealed class AudioPolicyConfigTests
{
[Test]
public void CreateAudioPolicyConfigTest()
{
Assert.DoesNotThrow(() =>
{
AudioPolicyConfigFactory.Create();
});
}

[Test]
public void UnsupportedWindowsVersionTest()
{
var audioPolicyConfig = AudioPolicyConfigFactory.Create();
if (Environment.OSVersion.Version.Major < 10 || Environment.OSVersion.Version.Build <= AudioPolicyConfigFactory.OS_1709_VERSION)
Assert.True(audioPolicyConfig is UnsupportedAudioPolicyConfig, $"audioPolicyConfig should be {nameof(UnsupportedAudioPolicyConfig)} if not on Windows 10 versions above 1709");
else
Assert.True(audioPolicyConfig is AudioPolicyConfig, $"audioPolicyConfig should be a valid {nameof(AudioPolicyConfig)}");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
<PackageReference Include="coverlet.collector" Version="3.1.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\SoundSwitch.Audio.Manager\SoundSwitch.Audio.Manager.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using SoundSwitch.Audio.Manager.Interop.Com.Base;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

namespace SoundSwitch.Audio.Manager.Interop.Client.Extended.Factory
{
public static class AudioPolicyConfigFactory
internal static class AudioPolicyConfigFactory
{
internal const int OS_1709_VERSION = 16299;

public static IAudioPolicyConfig Create()
{
return ComThread.Invoke<IAudioPolicyConfig>(() =>
{
if (Environment.OSVersion.Version.Major < 10)
if (Environment.OSVersion.Version.Major < 10 || Environment.OSVersion.Version.Build <= OS_1709_VERSION)
{
return new UnsupportedAudioPolicyConfig();
}
Expand All @@ -21,7 +23,7 @@ public static IAudioPolicyConfig Create()
}
catch (BadImageFormatException)
{
// Handles cases where the OS is Windows 10 but the AudioSes.dll is still an older version (or just invalid)
// Handles cases where the OS is a supported version of Windows 10 but the AudioSes.dll is still an older version (or just invalid)
return new UnsupportedAudioPolicyConfig();
}
});
Expand Down
5 changes: 5 additions & 0 deletions SoundSwitch.Audio.Manager/SoundSwitch.Audio.Manager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@
<PropertyGroup>
<CsWinRTWindowsMetadata>sdk</CsWinRTWindowsMetadata>
</PropertyGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>SoundSwitch.Audio.Manager.Tests</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
</Project>
10 changes: 10 additions & 0 deletions SoundSwitch.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SoundSwitch.Tests", "SoundS
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoundSwitch.UI.Menu", "SoundSwitch.UI.Menu\SoundSwitch.UI.Menu.csproj", "{EAF89214-E434-4FC0-A928-E6DB1D9FBF26}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoundSwitch.Audio.Manager.Tests", "SoundSwitch.Audio.Manager.Tests\SoundSwitch.Audio.Manager.Tests.csproj", "{2B15926A-26C1-4F6C-A6B4-260A5CCC84A2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Beta|Any CPU = Beta|Any CPU
Expand Down Expand Up @@ -61,6 +63,14 @@ Global
{EAF89214-E434-4FC0-A928-E6DB1D9FBF26}.Release|Any CPU.Build.0 = Release|Any CPU
{EAF89214-E434-4FC0-A928-E6DB1D9FBF26}.Nightly|Any CPU.ActiveCfg = Nightly|Any CPU
{EAF89214-E434-4FC0-A928-E6DB1D9FBF26}.Nightly|Any CPU.Build.0 = Nightly|Any CPU
{2B15926A-26C1-4F6C-A6B4-260A5CCC84A2}.Beta|Any CPU.ActiveCfg = Debug|Any CPU
{2B15926A-26C1-4F6C-A6B4-260A5CCC84A2}.Beta|Any CPU.Build.0 = Debug|Any CPU
{2B15926A-26C1-4F6C-A6B4-260A5CCC84A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2B15926A-26C1-4F6C-A6B4-260A5CCC84A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2B15926A-26C1-4F6C-A6B4-260A5CCC84A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2B15926A-26C1-4F6C-A6B4-260A5CCC84A2}.Release|Any CPU.Build.0 = Release|Any CPU
{2B15926A-26C1-4F6C-A6B4-260A5CCC84A2}.Nightly|Any CPU.ActiveCfg = Debug|Any CPU
{2B15926A-26C1-4F6C-A6B4-260A5CCC84A2}.Nightly|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit ad66ec0

Please sign in to comment.