Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 917371f

Browse files
authored
Use PackageManager to locate installed UWP apps (#26120)
Replaces manual registry crawling with a lookup via Windows.Management.Deployment.PackageManager. This eliminates the need for the Registry class. Covered by existing tests. Issue: flutter/flutter#81756
1 parent 0fc1bea commit 917371f

8 files changed

Lines changed: 11 additions & 230 deletions

File tree

ci/licenses_golden/licenses_flutter

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,9 +1583,6 @@ FILE: ../../../flutter/shell/platform/windows/platform_handler_win32.h
15831583
FILE: ../../../flutter/shell/platform/windows/platform_handler_winuwp.cc
15841584
FILE: ../../../flutter/shell/platform/windows/platform_handler_winuwp.h
15851585
FILE: ../../../flutter/shell/platform/windows/public/flutter_windows.h
1586-
FILE: ../../../flutter/shell/platform/windows/registry.cc
1587-
FILE: ../../../flutter/shell/platform/windows/registry.h
1588-
FILE: ../../../flutter/shell/platform/windows/registry_unittests.cc
15891586
FILE: ../../../flutter/shell/platform/windows/string_conversion.cc
15901587
FILE: ../../../flutter/shell/platform/windows/string_conversion.h
15911588
FILE: ../../../flutter/shell/platform/windows/string_conversion_unittests.cc

shell/platform/windows/BUILD.gn

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,6 @@ source_set("flutter_windows_source") {
171171
]
172172
}
173173

174-
# Windows registry utilities.
175-
source_set("registry") {
176-
sources = [
177-
"registry.cc",
178-
"registry.h",
179-
]
180-
181-
if (target_os == "winuwp") {
182-
cflags = [ "/EHsc" ]
183-
}
184-
}
185-
186174
# String encoding conversion utilities.
187175
source_set("string_conversion") {
188176
sources = [
@@ -233,7 +221,6 @@ executable("flutter_windows_unittests") {
233221
sources = [
234222
# "flutter_project_bundle_unittests.cc", //TODO failing due to switches test failing. Blocked on https://github.com/flutter/flutter/issues/74153
235223
# "flutter_windows_engine_unittests.cc", //TODO failing to send / receive platform message get plugins working first. Blocked on https://github.com/flutter/flutter/issues/74155
236-
"registry_unittests.cc",
237224
"string_conversion_unittests.cc",
238225
"system_utils_unittests.cc",
239226
"testing/engine_modifier.h",
@@ -273,7 +260,6 @@ executable("flutter_windows_unittests") {
273260
":flutter_windows_fixtures",
274261
":flutter_windows_headers",
275262
":flutter_windows_source",
276-
":registry",
277263
"//flutter/shell/platform/common:common_cpp",
278264
"//flutter/shell/platform/embedder:embedder_as_internal_library",
279265
"//flutter/shell/platform/embedder:embedder_test_utils",
@@ -333,8 +319,6 @@ source_set("uwptool_utils") {
333319
"uwptool_utils.cc",
334320
"uwptool_utils.h",
335321
]
336-
337-
deps = [ ":registry" ]
338322
}
339323

340324
# Command-line tool used by the flutter tool that serves a similar purpose to

shell/platform/windows/registry.cc

Lines changed: 0 additions & 87 deletions
This file was deleted.

shell/platform/windows/registry.h

Lines changed: 0 additions & 61 deletions
This file was deleted.

shell/platform/windows/registry_unittests.cc

Lines changed: 0 additions & 50 deletions
This file was deleted.

shell/platform/windows/uwptool_main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ int main(int argc, char** argv) {
8686
}
8787

8888
// Write an informative message for the user to stderr.
89-
std::cerr << "Launched app with package_id " << package_id
89+
std::cerr << "Launched app with package ID " << package_id
9090
<< ". PID: " << std::endl;
9191
// Write the PID to stdout. The flutter tool reads this value in.
9292
std::cout << process_id << std::endl;

shell/platform/windows/uwptool_utils.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#include <Windows.h>
88
#include <Winreg.h>
99
#include <shobjidl_core.h>
10+
#include <winrt/Windows.ApplicationModel.h>
11+
#include <winrt/Windows.Foundation.Collections.h>
12+
#include <winrt/Windows.Management.Deployment.h>
1013
#include <winrt/base.h>
1114

1215
#include <string>
@@ -41,17 +44,14 @@ int Application::Launch(const std::wstring_view args) {
4144
}
4245

4346
std::vector<Application> ApplicationStore::GetInstalledApplications() {
44-
constexpr wchar_t kMappingsKey[] =
45-
L"\\Local Settings\\Software\\Microsoft\\Windows\\CurrentVersion"
46-
L"\\AppModel\\Repository\\Families";
47-
RegistryKey mappings_key(HKEY_CLASSES_ROOT, kMappingsKey, KEY_READ);
48-
if (!mappings_key.IsValid()) {
49-
return {};
50-
}
47+
using winrt::Windows::ApplicationModel::Package;
48+
using winrt::Windows::Management::Deployment::PackageManager;
5149

50+
// Find packages for the current user (default for empty string).
51+
PackageManager package_manager;
5252
std::unordered_set<std::wstring> package_ids;
53-
for (const std::wstring& subkey_name : mappings_key.GetSubKeyNames()) {
54-
package_ids.emplace(subkey_name);
53+
for (const Package& package : package_manager.FindPackagesForUser(L"")) {
54+
package_ids.emplace(package.Id().FamilyName().c_str());
5555
}
5656
std::vector<Application> apps(package_ids.begin(), package_ids.end());
5757
return apps;

shell/platform/windows/uwptool_utils.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <string>
99
#include <vector>
1010

11-
#include "flutter/shell/platform/windows/registry.h"
12-
1311
namespace flutter {
1412

1513
// A UWP application.
@@ -19,7 +17,7 @@ class Application {
1917
Application(const Application& other) = default;
2018
Application& operator=(const Application& other) = default;
2119

22-
// Returns the application user model ID.
20+
// Returns the package ID.
2321
std::wstring GetPackageId() const { return package_id_; }
2422

2523
// Launches the application with the specified list of launch arguments.

0 commit comments

Comments
 (0)