Skip to content

Commit eb0bc31

Browse files
authored
Revert "Revert "DynamicDependencies: Use Win11 APIs if available #3704 #4083 (#4108)" (#4118)" (#4135)" (#4140)
* Revert "Revert "DynamicDependencies: Use Win11 APIs if available #3704 #4083 (#4108)" (#4118)" (#4135)" This reverts commit 117ed20. * Disable DynamicDependency-delegate-to-OS by changing IsSupported() (not reverting the world) * PackageRuntimeManager tests rely on OS DynDep functionality but Setup was a parallel version check when it should have been IsSupported. Fixed so they're all using the same answer * Doh! Had the check reversed -- if (foo) should have been if (!foo). Fixed * Tweak TryCreatePackageDependency when calling the OS with an invaliud package family name we get back STATEREPOSITORY_E_DEPENDENCY_NOT_RESOLVED but should return to the caller E_INVALIDARG * Remove false skip-tests check. The surgical IsSupported disables all delegation to OS APIs. When that changes we WANT the tests to run and canary any problem * Bad test passing too long a VersionTag. Tweaked Bootstrapper to spew WIL message and deal instead of FAIL_FAST * Fixed PackageDependency.m_packageFullName was never set and .PackageId string fields (e.g. .name) weren't properly set, though they weren't used so not noticed or harm (before the resolution fix - next sentence...). Fixed TryCreatePackageDependency() wasn't resolving the dependency unless the MddCreatePackageDependencyOptions_DoNotVerifyDependencyResolution option was specified. Fixed up some test issues as well asupdates in sync with the fixes (above) * Fixed tests to correctly match (fixed) implementation * Improved some test logging. Fided up a few tests out of date with the latest behavior
1 parent 3a25597 commit eb0bc31

File tree

65 files changed

+1205
-1212
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1205
-1212
lines changed

WindowsAppRuntime.sln

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Microsoft.Process.Environme
261261
EndProject
262262
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ChangeTracker", "dev\EnvironmentManager\ChangeTracker\ChangeTracker.vcxitems", "{E15C3465-9D45-495D-92CE-B91EF45E8623}"
263263
EndProject
264-
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WindowsAppRuntime_MSIXInstallFromPath", "dev\WindowsAppRuntime_MSIXInstallFromPath\WindowsAppRuntime_MSIXInstallFromPath.vcxproj", "{D45D4170-E055-4926-8B03-04DAA5F02C6C}"
265-
EndProject
266264
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Framework.Widgets", "test\DynamicDependency\data\Framework.Widgets\Framework.Widgets.vcxproj", "{09DDAE21-397F-4263-8561-7F2FF28127CF}"
267265
EndProject
268266
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DynamicDependencyLifetimeManagerShadow", "dev\DynamicDependency\DynamicDependencyLifetimeManagerShadow\DynamicDependencyLifetimeManagerShadow.vcxproj", "{6539E9E1-BF36-40E5-86BC-070E99DB7B7B}"
@@ -1320,20 +1318,6 @@ Global
13201318
{0B01DB78-F115-4C90-B28F-7819071303C6}.Release|x64.Build.0 = Release|x64
13211319
{0B01DB78-F115-4C90-B28F-7819071303C6}.Release|x86.ActiveCfg = Release|Win32
13221320
{0B01DB78-F115-4C90-B28F-7819071303C6}.Release|x86.Build.0 = Release|Win32
1323-
{D45D4170-E055-4926-8B03-04DAA5F02C6C}.Debug|Any CPU.ActiveCfg = Debug|Win32
1324-
{D45D4170-E055-4926-8B03-04DAA5F02C6C}.Debug|ARM64.ActiveCfg = Debug|ARM64
1325-
{D45D4170-E055-4926-8B03-04DAA5F02C6C}.Debug|ARM64.Build.0 = Debug|ARM64
1326-
{D45D4170-E055-4926-8B03-04DAA5F02C6C}.Debug|x64.ActiveCfg = Debug|x64
1327-
{D45D4170-E055-4926-8B03-04DAA5F02C6C}.Debug|x64.Build.0 = Debug|x64
1328-
{D45D4170-E055-4926-8B03-04DAA5F02C6C}.Debug|x86.ActiveCfg = Debug|Win32
1329-
{D45D4170-E055-4926-8B03-04DAA5F02C6C}.Debug|x86.Build.0 = Debug|Win32
1330-
{D45D4170-E055-4926-8B03-04DAA5F02C6C}.Release|Any CPU.ActiveCfg = Release|Win32
1331-
{D45D4170-E055-4926-8B03-04DAA5F02C6C}.Release|ARM64.ActiveCfg = Release|ARM64
1332-
{D45D4170-E055-4926-8B03-04DAA5F02C6C}.Release|ARM64.Build.0 = Release|ARM64
1333-
{D45D4170-E055-4926-8B03-04DAA5F02C6C}.Release|x64.ActiveCfg = Release|x64
1334-
{D45D4170-E055-4926-8B03-04DAA5F02C6C}.Release|x64.Build.0 = Release|x64
1335-
{D45D4170-E055-4926-8B03-04DAA5F02C6C}.Release|x86.ActiveCfg = Release|Win32
1336-
{D45D4170-E055-4926-8B03-04DAA5F02C6C}.Release|x86.Build.0 = Release|Win32
13371321
{09DDAE21-397F-4263-8561-7F2FF28127CF}.Debug|Any CPU.ActiveCfg = Debug|Win32
13381322
{09DDAE21-397F-4263-8561-7F2FF28127CF}.Debug|ARM64.ActiveCfg = Debug|ARM64
13391323
{09DDAE21-397F-4263-8561-7F2FF28127CF}.Debug|ARM64.Build.0 = Debug|ARM64
@@ -2491,7 +2475,6 @@ Global
24912475
{6967798A-AC07-4994-8FE9-DC9442F88E97} = {B4196B13-AB24-492E-9147-03CC7F2CAE59}
24922476
{2F3FAD1B-D3DF-4866-A3A3-C2C777D55638} = {8ABB3637-75DB-4DC3-BFB1-0933FFA4269B}
24932477
{E15C3465-9D45-495D-92CE-B91EF45E8623} = {6967798A-AC07-4994-8FE9-DC9442F88E97}
2494-
{D45D4170-E055-4926-8B03-04DAA5F02C6C} = {448ED2E5-0B37-4D97-9E6B-8C10A507976A}
24952478
{09DDAE21-397F-4263-8561-7F2FF28127CF} = {0C534F12-B076-47E5-A05B-2A711233AC6F}
24962479
{6539E9E1-BF36-40E5-86BC-070E99DB7B7B} = {6CD01EF6-D4A4-4801-ADCF-344CF87FF942}
24972480
{4B30C685-8490-440F-9879-A75D45DAA361} = {AC5FFC80-92FE-4933-BED2-EC5519AC4440}
@@ -2656,7 +2639,6 @@ Global
26562639
dev\DynamicDependency\API\DynamicDependency.vcxitems*{bf055a59-0919-4e34-9b76-dd055495cc5a}*SharedItemsImports = 9
26572640
test\inc\inc.vcxitems*{c62688a1-16a0-4729-b6ed-842f4faa29f3}*SharedItemsImports = 4
26582641
dev\AccessControl\AccessControl.vcxitems*{c91bcb93-9ed1-4acd-85f3-26f9f6ac52e3}*SharedItemsImports = 9
2659-
dev\Common\Common.vcxitems*{d45d4170-e055-4926-8b03-04daa5f02c6c}*SharedItemsImports = 4
26602642
test\inc\inc.vcxitems*{d5667df6-a151-4081-abc7-b93e8e5604ce}*SharedItemsImports = 4
26612643
dev\Deployment\Deployment.vcxitems*{db38fb4d-d04f-4c1d-93e0-f8ae259c5fd6}*SharedItemsImports = 9
26622644
dev\EnvironmentManager\ChangeTracker\ChangeTracker.vcxitems*{e15c3465-9d45-495d-92ce-b91ef45e8623}*SharedItemsImports = 9

build/CopyFilesToStagingDir.ps1

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,6 @@ PublishFile $FullBuildOutput\WindowsAppRuntime_BootstrapDLL\Microsoft.WindowsApp
172172
PublishFile $FullBuildOutput\WindowsAppRuntime_BootstrapDLL\Microsoft.WindowsAppRuntime.Bootstrap.dll $NugetDir\runtimes\win-$Platform\native
173173
PublishFile $FullBuildOutput\WindowsAppRuntime_BootstrapDLL\Microsoft.WindowsAppRuntime.Bootstrap.pdb $NugetDir\runtimes\win10-$Platform\native
174174
#
175-
# Tools
176-
PublishFile $FullBuildOutput\WindowsAppRuntime_MSIXInstallFromPath\WindowsAppRuntime_MSIXInstallFromPath.exe $NugetDir\tools\$Platform
177-
PublishFile $FullBuildOutput\WindowsAppRuntime_MSIXInstallFromPath\WindowsAppRuntime_MSIXInstallFromPath.pdb $NugetDir\tools\$Platform
178-
#
179175
# WinMD for UWP apps
180176
PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windows.ApplicationModel.DynamicDependency.winmd $NugetDir\lib\uap10.0
181177
PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windows.ApplicationModel.WindowsAppRuntime.winmd $NugetDir\lib\uap10.0

dev/Common/IsWindowsVersion.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ inline bool IsWindows11_22H2OrGreater()
5252
// GetPackageGraphRevisionId() added to kernelbase.dll in NTDDI_WIN10_NI (aka Windows 11 22H2)
5353
return IsExportPresent(L"kernelbase.dll", "GetPackageGraphRevisionId");
5454
}
55+
inline bool IsWindows11_23H1OrGreater()
56+
{
57+
// TryCreatePackageDependency2() added to in NTDDI_WIN10_GE (aka Windows 11 23H1)
58+
return IsExportPresent(L"api-ms-win-appmodel-runtime-l1-1-7.dll", "TryCreatePackageDependency2");
59+
}
5560
}
5661

5762
#endif // __ISWINDOWSVERSION_H

dev/Common/WindowsAppRuntime.VersionInfo.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation and Contributors.
1+
// Copyright (c) Microsoft Corporation and Contributors.
22
// Licensed under the MIT License.
33

44
#include "pch.h"
@@ -7,6 +7,8 @@
77

88
#include "WindowsAppRuntime.VersionInfo.h"
99

10+
#include "MddWin11.h"
11+
1012
// Function prototype of the function exported by the resource DLL
1113
// (defined later in the build pipeline so we can't #include a header from there)
1214
STDAPI_(const void*) WindowsAppRuntime_GetVersionInfo();
@@ -115,11 +117,20 @@ STDAPI WindowsAppRuntime_VersionInfo_TestInitialize(
115117
PCWSTR frameworkPackageFamilyName,
116118
PCWSTR mainPackageFamilyName) noexcept try
117119
{
118-
// Both or neither must be valued
120+
// Verify parameters
119121
const bool frameworkPackageFamilyNameIsEmpty{ !frameworkPackageFamilyName || (*frameworkPackageFamilyName == L'0') };
120122
const bool mainPackageFamilyNameIsEmpty{ !mainPackageFamilyName || (*mainPackageFamilyName == L'0') };
121-
FAIL_FAST_HR_IF(E_UNEXPECTED, frameworkPackageFamilyNameIsEmpty && !mainPackageFamilyNameIsEmpty);
122-
FAIL_FAST_HR_IF(E_UNEXPECTED, !frameworkPackageFamilyNameIsEmpty && mainPackageFamilyNameIsEmpty);
123+
if (MddCore::Win11::IsSupported())
124+
{
125+
// Framework is optional but Main is never specified
126+
FAIL_FAST_HR_IF(E_UNEXPECTED, !mainPackageFamilyNameIsEmpty);
127+
}
128+
else
129+
{
130+
// Both or neither must be valued
131+
FAIL_FAST_HR_IF(E_UNEXPECTED, frameworkPackageFamilyNameIsEmpty && !mainPackageFamilyNameIsEmpty);
132+
FAIL_FAST_HR_IF(E_UNEXPECTED, !frameworkPackageFamilyNameIsEmpty && mainPackageFamilyNameIsEmpty);
133+
}
123134

124135
// Update our state
125136
if (frameworkPackageFamilyNameIsEmpty)
@@ -132,7 +143,7 @@ STDAPI WindowsAppRuntime_VersionInfo_TestInitialize(
132143
{
133144
// Initialize test support
134145
g_test_frameworkPackageFamilyName = frameworkPackageFamilyName;
135-
g_test_mainPackageFamilyName = mainPackageFamilyName;
146+
g_test_mainPackageFamilyName = (!mainPackageFamilyName ? L"" : mainPackageFamilyName);
136147
}
137148
return S_OK;
138149
}

dev/Common/WindowsAppRuntime.VersionInfo.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation and Contributors.
1+
// Copyright (c) Microsoft Corporation and Contributors.
22
// Licensed under the MIT License.
33

44
#ifndef __MICROSFT_WINDOWSAPPRUNTIME_VERSIONINFO_H
@@ -68,6 +68,18 @@ inline void TestInitialize(
6868
THROW_IF_FAILED(WindowsAppRuntime_VersionInfo_TestInitialize(frameworkPackageFamilyName, mainPackageFamilyName));
6969
}
7070

71+
/// Initialize VersionInfo's test support. This will constrain package enumeration
72+
/// and matching for test purposes.
73+
///
74+
/// @param frameworkPackageFamilyName only match framework packages with this family name
75+
///
76+
/// @note Not for product use. This is for test purposes only to verify the implementation.
77+
inline void TestInitialize(
78+
_In_ PCWSTR frameworkPackageFamilyName)
79+
{
80+
THROW_IF_FAILED(WindowsAppRuntime_VersionInfo_TestInitialize(frameworkPackageFamilyName, nullptr));
81+
}
82+
7183
/// Shutdown VersionInfo's test support.
7284
///
7385
/// @note Not for product use. This is for test purposes only to verify the implementation.

dev/DynamicDependency/API/DynamicDependency.vcxitems

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
<ClCompile Include="$(MSBuildThisFileDirectory)M.AM.DD.PackageDependencyRank.cpp" />
2424
<ClCompile Include="$(MSBuildThisFileDirectory)MddDetourPackageGraph.cpp" />
2525
<ClCompile Include="$(MSBuildThisFileDirectory)MddLifetimeManagement.cpp" />
26-
<ClCompile Include="$(MSBuildThisFileDirectory)MddWin11.cpp" />
2726
<ClCompile Include="$(MSBuildThisFileDirectory)MddWinRT.cpp" />
2827
<ClCompile Include="$(MSBuildThisFileDirectory)MsixDynamicDependency.cpp" />
2928
<ClCompile Include="$(MSBuildThisFileDirectory)PackageDependency.cpp" />

dev/DynamicDependency/API/DynamicDependency.vcxitems.filters

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@
5050
<ClCompile Include="$(MSBuildThisFileDirectory)DataStore.cpp">
5151
<Filter>Source Files</Filter>
5252
</ClCompile>
53-
<ClCompile Include="$(MSBuildThisFileDirectory)MddWin11.cpp">
54-
<Filter>Source Files</Filter>
55-
</ClCompile>
5653
<ClCompile Include="$(MSBuildThisFileDirectory)MddWinRT.cpp">
5754
<Filter>Source Files</Filter>
5855
</ClCompile>

dev/DynamicDependency/API/M.AM.DD.PackageDependency.cpp

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation and Contributors.
1+
// Copyright (c) Microsoft Corporation and Contributors.
22
// Licensed under the MIT License.
33

44
#include "pch.h"
@@ -16,6 +16,8 @@
1616

1717
#include <M.AM.Converters.h>
1818

19+
#include "MddWin11.h"
20+
1921
namespace winrt::Microsoft::Windows::ApplicationModel::DynamicDependency::implementation
2022
{
2123
PackageDependency::PackageDependency(hstring const& id) :
@@ -25,21 +27,37 @@ namespace winrt::Microsoft::Windows::ApplicationModel::DynamicDependency::implem
2527

2628
winrt::PackageDependency PackageDependency::GetFromId(hstring const& id)
2729
{
28-
auto tokenUser{ wil::get_token_information<TOKEN_USER>(GetCurrentThreadEffectiveToken()) };
29-
auto exists{ MddCore::PackageDependencyManager::ExistsPackageDependency(tokenUser->User.Sid, id.c_str()) };
30-
if (!exists)
30+
// Use the Win11 APIs if available (instead of Detour'ing to our own implementation)
31+
if (MddCore::Win11::IsSupported())
32+
{
33+
//TODO:47775758 GetResolved2 GetPackageDependencyInfo2(userSid, id.c_str(), &packageDependencyInfo)
34+
}
35+
else
3136
{
32-
return nullptr;
37+
auto tokenUser{ wil::get_token_information<TOKEN_USER>(GetCurrentThreadEffectiveToken()) };
38+
auto exists{ MddCore::PackageDependencyManager::ExistsPackageDependency(tokenUser->User.Sid, id.c_str()) };
39+
if (!exists)
40+
{
41+
return nullptr;
42+
}
3343
}
3444
return winrt::make<implementation::PackageDependency>(id);
3545
}
3646

3747
winrt::PackageDependency PackageDependency::GetFromIdForSystem(hstring const& id)
3848
{
39-
auto exists{ MddCore::PackageDependencyManager::ExistsPackageDependency(nullptr, id.c_str()) };
40-
if (!exists)
49+
// Use the Win11 APIs if available (instead of Detour'ing to our own implementation)
50+
if (MddCore::Win11::IsSupported())
51+
{
52+
//TODO:47775758 GetResolved2 GetPackageDependencyInfo2(userSid, id.c_str(), &packageDependencyInfo)
53+
}
54+
else
4155
{
42-
return nullptr;
56+
auto exists{ MddCore::PackageDependencyManager::ExistsPackageDependency(nullptr, id.c_str()) };
57+
if (!exists)
58+
{
59+
return nullptr;
60+
}
4361
}
4462
return winrt::make<implementation::PackageDependency>(id);
4563
}

dev/DynamicDependency/API/MddDetourPackageGraph.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation and Contributors.
1+
// Copyright (c) Microsoft Corporation and Contributors.
22
// Licensed under the MIT License.
33

44
#include "pch.h"
@@ -9,6 +9,8 @@
99

1010
#include "PackageGraphManager.h"
1111

12+
#include "MddWin11.h"
13+
1214
#include <../Detours/detours.h>
1315

1416
// Windows provides HRESULT_FROM_WIN32() but not the reverse. We need that for compat reasons.
@@ -110,6 +112,13 @@ typedef UINT32 (WINAPI* GetPackageGraphRevisionIdFunction)();
110112

111113
HRESULT WINAPI MddDetourPackageGraphInitialize() noexcept
112114
{
115+
// Use the Win11 APIs if available (instead of Detour'ing to our own implementation)
116+
if (MddCore::Win11::IsSupported())
117+
{
118+
RETURN_IF_FAILED(MddWin11Initialize());
119+
return S_OK;
120+
}
121+
113122
// Detour package graph APIs to our implementation
114123
FAIL_FAST_IF_WIN32_ERROR(DetourUpdateThread(GetCurrentThread()));
115124
FAIL_FAST_IF_WIN32_ERROR(DetourAttach(&(PVOID&)TrueGetCurrentPackageInfo, DynamicGetCurrentPackageInfo));
@@ -160,6 +169,13 @@ HRESULT WINAPI MddDetourPackageGraphInitialize() noexcept
160169

161170
HRESULT _MddDetourPackageGraphShutdown() noexcept
162171
{
172+
// Use the Win11 APIs if available (instead of Detour'ing to our own implementation)
173+
if (MddCore::Win11::IsSupported())
174+
{
175+
MddWin11Shutdown();
176+
return S_OK;
177+
}
178+
163179
// Stop Detour'ing package graph APIs to our implementation (undo in reverse order we started Detour'ing APIs)
164180
if (TrueGetPackageGraphRevisionId)
165181
{

0 commit comments

Comments
 (0)