diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 20f5b456aac7f..e4cc2420556b5 100755 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -1583,9 +1583,6 @@ FILE: ../../../flutter/shell/platform/windows/platform_handler_win32.h FILE: ../../../flutter/shell/platform/windows/platform_handler_winuwp.cc FILE: ../../../flutter/shell/platform/windows/platform_handler_winuwp.h FILE: ../../../flutter/shell/platform/windows/public/flutter_windows.h -FILE: ../../../flutter/shell/platform/windows/registry.cc -FILE: ../../../flutter/shell/platform/windows/registry.h -FILE: ../../../flutter/shell/platform/windows/registry_unittests.cc FILE: ../../../flutter/shell/platform/windows/string_conversion.cc FILE: ../../../flutter/shell/platform/windows/string_conversion.h FILE: ../../../flutter/shell/platform/windows/string_conversion_unittests.cc diff --git a/shell/platform/windows/BUILD.gn b/shell/platform/windows/BUILD.gn index e57c6f9926cb7..3402ed8434abf 100644 --- a/shell/platform/windows/BUILD.gn +++ b/shell/platform/windows/BUILD.gn @@ -171,18 +171,6 @@ source_set("flutter_windows_source") { ] } -# Windows registry utilities. -source_set("registry") { - sources = [ - "registry.cc", - "registry.h", - ] - - if (target_os == "winuwp") { - cflags = [ "/EHsc" ] - } -} - # String encoding conversion utilities. source_set("string_conversion") { sources = [ @@ -233,7 +221,6 @@ executable("flutter_windows_unittests") { sources = [ # "flutter_project_bundle_unittests.cc", //TODO failing due to switches test failing. Blocked on https://github.com/flutter/flutter/issues/74153 # "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 - "registry_unittests.cc", "string_conversion_unittests.cc", "system_utils_unittests.cc", "testing/engine_modifier.h", @@ -273,7 +260,6 @@ executable("flutter_windows_unittests") { ":flutter_windows_fixtures", ":flutter_windows_headers", ":flutter_windows_source", - ":registry", "//flutter/shell/platform/common:common_cpp", "//flutter/shell/platform/embedder:embedder_as_internal_library", "//flutter/shell/platform/embedder:embedder_test_utils", @@ -333,8 +319,6 @@ source_set("uwptool_utils") { "uwptool_utils.cc", "uwptool_utils.h", ] - - deps = [ ":registry" ] } # Command-line tool used by the flutter tool that serves a similar purpose to diff --git a/shell/platform/windows/registry.cc b/shell/platform/windows/registry.cc deleted file mode 100644 index cb6ddc6cc8a72..0000000000000 --- a/shell/platform/windows/registry.cc +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "flutter/shell/platform/windows/registry.h" - -#include -#include - -namespace flutter { - -RegistryKey::RegistryKey(HKEY key, REGSAM access) - : RegistryKey(key, L"", access) {} - -RegistryKey::RegistryKey(HKEY parent_key, - const std::wstring_view subkey, - REGSAM access) { - LSTATUS result = ::RegOpenKeyEx(parent_key, subkey.data(), 0, access, &key_); - if (result != ERROR_SUCCESS) { - key_ = nullptr; - } -} - -RegistryKey::RegistryKey(const RegistryKey& parent_key, - const std::wstring_view subkey, - REGSAM access) - : RegistryKey(parent_key.key_, subkey, access) {} - -RegistryKey::~RegistryKey() { - Close(); -} - -void RegistryKey::Close() { - if (IsValid()) { - ::RegCloseKey(key_); - key_ = nullptr; - } -} - -std::vector RegistryKey::GetSubKeyNames() const { - if (!IsValid()) { - return {}; - } - - // Get the count of subkeys, and maximum key size in wchar_t. - DWORD max_key_buf_size; - DWORD subkey_count; - LSTATUS result = ::RegQueryInfoKey( - key_, nullptr, nullptr, nullptr, &subkey_count, &max_key_buf_size, - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr); - - // Collect all subkey names. - std::vector subkey_names; - for (int i = 0; i < subkey_count; ++i) { - DWORD key_buf_size = max_key_buf_size; - auto key_buf = std::make_unique(max_key_buf_size); - result = ::RegEnumKeyExW(key_, i, key_buf.get(), &key_buf_size, nullptr, - nullptr, nullptr, nullptr); - if (result == ERROR_SUCCESS) { - subkey_names.emplace_back(key_buf.get()); - } - } - return subkey_names; -} - -LONG RegistryKey::ReadValue(const std::wstring_view name, - std::wstring* out_value) const { - assert(out_value != nullptr); - - // Get the value size, in bytes. - DWORD value_size; - LSTATUS result = ::RegGetValueW(key_, L"", name.data(), RRF_RT_REG_SZ, - nullptr, nullptr, &value_size); - if (result != ERROR_SUCCESS) { - return result; - } - - auto value_buf = std::make_unique(value_size / sizeof(wchar_t)); - result = ::RegGetValueW(key_, L"", name.data(), RRF_RT_REG_SZ, nullptr, - value_buf.get(), &value_size); - if (result == ERROR_SUCCESS) { - *out_value = value_buf.get(); - } - return result; -} - -} // namespace flutter diff --git a/shell/platform/windows/registry.h b/shell/platform/windows/registry.h deleted file mode 100644 index 1bd71b325a049..0000000000000 --- a/shell/platform/windows/registry.h +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_REGISTRY_H_ -#define FLUTTER_SHELL_PLATFORM_WINDOWS_REGISTRY_H_ - -#include -#include - -#include -#include - -namespace flutter { - -// A Windows Registry key. -// -// The Windows registry is structured as a hierarchy of named keys, each of -// which may contain a set of named values of various datatypes. RegistryKey -// objects own the underlying HKEY handle and ensure cleanup at or prior to -// destruction. -class RegistryKey { - public: - // Opens the specified key. - RegistryKey(HKEY key, REGSAM access); - - // Opens a key relative to the specified parent key. - RegistryKey(HKEY parent_key, const std::wstring_view subkey, REGSAM access); - - // Opens a key relative to the specified parent key. - RegistryKey(const RegistryKey& parent_key, - const std::wstring_view subkey, - REGSAM access); - - ~RegistryKey(); - - // Prevent copying. - RegistryKey(const RegistryKey& other) = delete; - RegistryKey& operator=(const RegistryKey& other) = delete; - - // Closes the registry key and releases resources. - void Close(); - - // Returns true if the key is valid. - bool IsValid() const { return key_ != nullptr; } - - // Returns a list of all direct subkey names for this key. - std::vector GetSubKeyNames() const; - - // Reads a string value from the key. - // - // Returns ERROR_SUCCESS on success. - LONG ReadValue(const std::wstring_view name, std::wstring* out_value) const; - - private: - HKEY key_ = nullptr; -}; - -} // namespace flutter - -#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_REGISTRY_H_ diff --git a/shell/platform/windows/registry_unittests.cc b/shell/platform/windows/registry_unittests.cc deleted file mode 100644 index 21a6467dc2753..0000000000000 --- a/shell/platform/windows/registry_unittests.cc +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "flutter/shell/platform/windows/registry.h" - -#include -#include - -#include - -#include "gtest/gtest.h" - -namespace flutter { -namespace testing { - -// TODO(cbracken): write registry values to be tested, then cleanup. -// https://github.com/flutter/flutter/issues/82095 - -// Verify that a registry key is marked invalid after close. -TEST(RegistryKey, CloseInvalidates) { - RegistryKey key(HKEY_USERS, L".DEFAULT\\Environment", KEY_READ); - ASSERT_TRUE(key.IsValid()); - key.Close(); - ASSERT_FALSE(key.IsValid()); -} - -// Verify that subkeys can be read. -TEST(RegistryKey, GetSubKeyNames) { - RegistryKey key(HKEY_USERS, L".DEFAULT", KEY_READ); - ASSERT_TRUE(key.IsValid()); - - std::vector subkey_names = key.GetSubKeyNames(); - EXPECT_GE(subkey_names.size(), 1); - EXPECT_TRUE(std::find(subkey_names.begin(), subkey_names.end(), - L"Environment") != subkey_names.end()); -} - -// Verify that values can be read. -TEST(RegistryKey, GetValue) { - RegistryKey key(HKEY_USERS, L".DEFAULT\\Environment", KEY_READ); - ASSERT_TRUE(key.IsValid()); - - std::wstring path; - ASSERT_EQ(key.ReadValue(L"Path", &path), ERROR_SUCCESS); - EXPECT_FALSE(path.empty()); -} - -} // namespace testing -} // namespace flutter diff --git a/shell/platform/windows/uwptool_main.cc b/shell/platform/windows/uwptool_main.cc index 196bcc2715f25..f58071088f4f7 100644 --- a/shell/platform/windows/uwptool_main.cc +++ b/shell/platform/windows/uwptool_main.cc @@ -86,7 +86,7 @@ int main(int argc, char** argv) { } // Write an informative message for the user to stderr. - std::cerr << "Launched app with package_id " << package_id + std::cerr << "Launched app with package ID " << package_id << ". PID: " << std::endl; // Write the PID to stdout. The flutter tool reads this value in. std::cout << process_id << std::endl; diff --git a/shell/platform/windows/uwptool_utils.cc b/shell/platform/windows/uwptool_utils.cc index e63dac7707776..f3b8fefb00345 100644 --- a/shell/platform/windows/uwptool_utils.cc +++ b/shell/platform/windows/uwptool_utils.cc @@ -7,6 +7,9 @@ #include #include #include +#include +#include +#include #include #include @@ -41,17 +44,14 @@ int Application::Launch(const std::wstring_view args) { } std::vector ApplicationStore::GetInstalledApplications() { - constexpr wchar_t kMappingsKey[] = - L"\\Local Settings\\Software\\Microsoft\\Windows\\CurrentVersion" - L"\\AppModel\\Repository\\Families"; - RegistryKey mappings_key(HKEY_CLASSES_ROOT, kMappingsKey, KEY_READ); - if (!mappings_key.IsValid()) { - return {}; - } + using winrt::Windows::ApplicationModel::Package; + using winrt::Windows::Management::Deployment::PackageManager; + // Find packages for the current user (default for empty string). + PackageManager package_manager; std::unordered_set package_ids; - for (const std::wstring& subkey_name : mappings_key.GetSubKeyNames()) { - package_ids.emplace(subkey_name); + for (const Package& package : package_manager.FindPackagesForUser(L"")) { + package_ids.emplace(package.Id().FamilyName().c_str()); } std::vector apps(package_ids.begin(), package_ids.end()); return apps; diff --git a/shell/platform/windows/uwptool_utils.h b/shell/platform/windows/uwptool_utils.h index d798395732927..9b6469aa5c08a 100644 --- a/shell/platform/windows/uwptool_utils.h +++ b/shell/platform/windows/uwptool_utils.h @@ -8,8 +8,6 @@ #include #include -#include "flutter/shell/platform/windows/registry.h" - namespace flutter { // A UWP application. @@ -19,7 +17,7 @@ class Application { Application(const Application& other) = default; Application& operator=(const Application& other) = default; - // Returns the application user model ID. + // Returns the package ID. std::wstring GetPackageId() const { return package_id_; } // Launches the application with the specified list of launch arguments.