diff --git a/fastpair/BUILD b/fastpair/BUILD index 0bd8c36e..ecf40b43 100644 --- a/fastpair/BUILD +++ b/fastpair/BUILD @@ -36,7 +36,6 @@ cc_library( "//fastpair:__subpackages__", ], deps = [ - "//fastpair/internal/api:platform", "//fastpair/scanning/fastpair:scanning", "//internal/platform:base", "//internal/platform:logging", @@ -57,7 +56,6 @@ cc_test( shard_count = 8, deps = [ ":fastpair_controller", - "//fastpair/internal/api:platform", "//fastpair/scanning/fastpair:scanning", "//internal/platform:logging", "//internal/platform/implementation/g3", diff --git a/fastpair/client/windows/BUILD b/fastpair/client/windows/BUILD index b2389ee8..6c78d57c 100644 --- a/fastpair/client/windows/BUILD +++ b/fastpair/client/windows/BUILD @@ -36,7 +36,6 @@ lexan.cc_windows_dll( ], deps = [ "//fastpair:fastpair_controller", - "//fastpair/internal/api:platform", "//internal/platform:logging", "//internal/platform/implementation/windows", "//internal/platform/implementation/windows/generated:types", @@ -67,7 +66,6 @@ lexan.cc_windows_dll( ], deps = [ "//fastpair:fastpair_controller", - "//fastpair/internal/api:platform", "//internal/platform:logging", "//internal/platform/implementation/windows", "//internal/platform/implementation/windows/generated:types", diff --git a/fastpair/internal/api/BUILD b/fastpair/internal/api/BUILD deleted file mode 100644 index 61480fd4..00000000 --- a/fastpair/internal/api/BUILD +++ /dev/null @@ -1,12 +0,0 @@ -licenses(["notice"]) - -cc_library( - name = "platform", - textual_hdrs = glob(["**/*.h"]), - visibility = [ - "//fastpair:__subpackages__", - ], - deps = [ - "@com_google_absl//absl/strings", - ], -) diff --git a/fastpair/internal/api/fast_pair_platform.h b/fastpair/internal/api/fast_pair_platform.h deleted file mode 100644 index 8a5f57aa..00000000 --- a/fastpair/internal/api/fast_pair_platform.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef THIRD_PARTY_NEARBY_FASTPAIR_INTERNAL_API_FAST_PAIR_PLATFORM_H_ -#define THIRD_PARTY_NEARBY_FASTPAIR_INTERNAL_API_FAST_PAIR_PLATFORM_H_ - -#include -#include -#include - -#include "absl/strings/string_view.h" -#include "fastpair/internal/api/device_info.h" - -namespace nearby { -namespace api { - -class ImplementationFastPairPlatform { - public: - static std::unique_ptr CreateDeviceInfo(); -}; - -} // namespace api -} // namespace nearby - -#endif // THIRD_PARTY_NEARBY_FASTPAIR_INTERNAL_API_FAST_PAIR_PLATFORM_H_ diff --git a/fastpair/internal/impl/g3/BUILD b/fastpair/internal/impl/g3/BUILD deleted file mode 100644 index a681651c..00000000 --- a/fastpair/internal/impl/g3/BUILD +++ /dev/null @@ -1,36 +0,0 @@ -licenses(["notice"]) - -cc_library( - name = "platform_g3", - srcs = [ - "fast_pair_platform.cc", - ], - hdrs = [ - "device_info.h", - ], - visibility = [ - "//fastpair:__subpackages__", - ], - deps = [ - "//fastpair/internal/api:platform", - "@com_google_absl//absl/container:flat_hash_map", - "@com_google_absl//absl/strings", - ], -) - -cc_test( - name = "g3_test", - size = "small", - timeout = "short", - srcs = [ - "device_info_test.cc", - ], - shard_count = 8, - deps = [ - ":platform_g3", - "//fastpair/internal/api:platform", - "@com_github_protobuf_matchers//protobuf-matchers", - "@com_google_absl//absl/synchronization", - "@com_google_googletest//:gtest_main", - ], -) diff --git a/fastpair/internal/impl/g3/device_info_test.cc b/fastpair/internal/impl/g3/device_info_test.cc deleted file mode 100644 index c48b012f..00000000 --- a/fastpair/internal/impl/g3/device_info_test.cc +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "fastpair/internal/impl/g3/device_info.h" - -#include -#include - -#include "gtest/gtest.h" -#include "absl/synchronization/notification.h" -#include "fastpair/internal/api/device_info.h" - -namespace nearby { -namespace g3 { -namespace { - -TEST(DeviceInfo, GetOsType) { - EXPECT_EQ(DeviceInfo().GetOsType(), api::DeviceInfo::OsType::kChromeOs); -} - -TEST(DeviceInfo, IsScreenLocked) { - EXPECT_FALSE(DeviceInfo().IsScreenLocked()); -} - -TEST(DeviceInfo, RegisterScreenLockedListener) { - std::function listener_1 = - [](api::DeviceInfo::ScreenStatus) {}; - std::function listener_2 = - [](api::DeviceInfo::ScreenStatus) {}; - - DeviceInfo device_info; - EXPECT_EQ(device_info.screen_locked_listeners_.size(), 0); - - device_info.RegisterScreenLockedListener("listener_1", listener_1); - EXPECT_EQ(device_info.screen_locked_listeners_.size(), 1); - - device_info.RegisterScreenLockedListener("listener_2", listener_2); - EXPECT_EQ(device_info.screen_locked_listeners_.size(), 2); -} - -TEST(DeviceInfo, UnregisterScreenLockedListener) { - std::function listener_1 = - [](api::DeviceInfo::ScreenStatus) {}; - std::function listener_2 = - [](api::DeviceInfo::ScreenStatus) {}; - - DeviceInfo device_info; - EXPECT_EQ(device_info.screen_locked_listeners_.size(), 0); - - device_info.RegisterScreenLockedListener("listener_1", listener_1); - device_info.RegisterScreenLockedListener("listener_2", listener_2); - EXPECT_EQ(device_info.screen_locked_listeners_.size(), 2); - - device_info.UnregisterScreenLockedListener("listener_1"); - EXPECT_EQ(device_info.screen_locked_listeners_.size(), 1); - - device_info.UnregisterScreenLockedListener("listener_2"); - EXPECT_EQ(device_info.screen_locked_listeners_.size(), 0); -} - -} // namespace -} // namespace g3 -} // namespace nearby diff --git a/fastpair/internal/impl/g3/fast_pair_platform.cc b/fastpair/internal/impl/g3/fast_pair_platform.cc deleted file mode 100644 index 1dc7fbed..00000000 --- a/fastpair/internal/impl/g3/fast_pair_platform.cc +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "fastpair/internal/api/fast_pair_platform.h" - -#include - -#include "fastpair/internal/impl/g3/device_info.h" - -namespace nearby { -namespace api { - -std::unique_ptr -ImplementationFastPairPlatform::CreateDeviceInfo() { - return std::make_unique(); -} - -} // namespace api -} // namespace nearby diff --git a/fastpair/internal/impl/windows/BUILD b/fastpair/internal/impl/windows/BUILD index de441ceb..1b705969 100644 --- a/fastpair/internal/impl/windows/BUILD +++ b/fastpair/internal/impl/windows/BUILD @@ -27,13 +27,10 @@ cc_library( name = "platform_windows", srcs = [ "ble_gatt_client.cc", - "device_info.cc", - "fast_pair_platform.cc", "utils.cc", ], hdrs = [ "ble_gatt_client.h", - "device_info.h", "utils.h", ], copts = [ @@ -42,7 +39,6 @@ cc_library( defines = ["_SILENCE_CLANG_COROUTINE_MESSAGE"], visibility = ["//fastpair:__subpackages__"], deps = [ - "//fastpair/internal/api:platform", "//internal/platform:base", "//internal/platform:logging", "//internal/platform/implementation/windows", @@ -54,31 +50,3 @@ cc_library( "@com_google_absl//absl/synchronization", ], ) - -cc_test( - name = "platform_windows_test", - size = "small", - timeout = "short", - srcs = [ - "device_info_test.cc", - ], - copts = [ - "-Ithird_party/nearby/internal/platform/implementation/windows/generated", - ], - shard_count = 1, - deps = [ - ":platform_windows", - ":platform_windows_libs", - "//fastpair/internal/api:platform", - "//internal/platform:base", - "//internal/platform:logging", - "//internal/platform/implementation:types", - "//internal/platform/implementation/windows", - "//internal/platform/implementation/windows/generated:types", - "@com_github_protobuf_matchers//protobuf-matchers", - "@com_google_absl//absl/status", - "@com_google_absl//absl/strings", - "@com_google_absl//absl/synchronization", - "@com_google_googletest//:gtest_main", - ], -) diff --git a/fastpair/internal/impl/windows/device_info.cc b/fastpair/internal/impl/windows/device_info.cc deleted file mode 100644 index 2b65465d..00000000 --- a/fastpair/internal/impl/windows/device_info.cc +++ /dev/null @@ -1,200 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "fastpair/internal/impl/windows/device_info.h" - -#include -#include -#include - -#include -#include -#include -#include - -#include "absl/container/flat_hash_map.h" -#include "absl/strings/string_view.h" -#include "fastpair/internal/api/device_info.h" -#include "internal/platform/logging.h" -#include "winrt/Windows.Foundation.Collections.h" -#include "winrt/Windows.Foundation.h" -#include "winrt/Windows.System.h" - -namespace nearby { -namespace windows { - -constexpr char window_class_name[] = "FastPairDLL_MessageWindowClass"; -constexpr char window_name[] = "FastPairDLL_MessageWindow"; - -namespace { -// This WindowProc method must be static for the successful initialization of -// WNDCLASS -// window_class.lpfnWndProc = (WNDPROC) &DeviceInfo::WindowProc; -// where a WNDPROC typed function pointer is expected -// typedef LRESULT (CALLBACK* WNDPROC)(HWND,UINT,WPARAM,LPARAM) -// the calling convention used here CALLBACK is a macro defined as -// #define CALLBACK __stdcall -// -// If WindProc is not static and defined as a member function, it uses the -// __thiscall calling convention instead -// https://docs.microsoft.com/en-us/cpp/cpp/thiscall?view=msvc-170 -// https://isocpp.org/wiki/faq/pointers-to-members -// https://en.cppreference.com/w/cpp/language/pointer -// -// This is problematic because the function pointer now looks like this -// typedef LRESULT (CALLBACK* DeviceInfo_WNDPROC)(DeviceInfo* -// this,HWND,UINT,WPARAM,LPARAM) -// which causes casting errors -LRESULT CALLBACK WindowProc(HWND window_handle, UINT message, WPARAM wparam, - LPARAM lparam) { - DeviceInfo* self = reinterpret_cast( - GetWindowLongPtr(window_handle, GWLP_USERDATA)); - CREATESTRUCT* create_struct = reinterpret_cast(lparam); - LONG_PTR result = 0L; - switch (message) { - case WM_CREATE: - self = reinterpret_cast(create_struct->lpCreateParams); - self->message_window_handle_ = window_handle; - - // Store pointer to the self to the window's user data. - SetLastError(0); - result = SetWindowLongPtr(window_handle, GWLP_USERDATA, - reinterpret_cast(self)); - if (result == 0 && GetLastError() != 0) { - NEARBY_LOGS(ERROR) - << __func__ - << ": Error connecting message window to Fast Pair DLL."; - } - break; - case WM_WTSSESSION_CHANGE: - if (self) { - switch (wparam) { - case WTS_SESSION_LOCK: - for (auto& listener : self->screen_locked_listeners_) { - listener.second(api::DeviceInfo::ScreenStatus:: - kLocked); // Trigger registered callbacks - } - break; - case WTS_SESSION_UNLOCK: - for (auto& listener : self->screen_locked_listeners_) { - listener.second(api::DeviceInfo::ScreenStatus:: - kUnlocked); // Trigger registered callbacks - } - break; - } - } - break; - case WM_DESTROY: - SetLastError(0); - result = SetWindowLongPtr(window_handle, GWLP_USERDATA, NULL); - if (result == 0 && GetLastError() != 0) { - NEARBY_LOGS(ERROR) - << __func__ - << ": Error disconnecting message window to Fast Pair DLL."; - } - break; - } - - return DefWindowProc(window_handle, message, wparam, lparam); -} -} // namespace - -DeviceInfo::~DeviceInfo() { - UnregisterClass(MAKEINTATOM(registered_class_), instance_); -} - -api::DeviceInfo::OsType DeviceInfo::GetOsType() const { - return api::DeviceInfo::OsType::kWindows; -} - -bool DeviceInfo::IsScreenLocked() const { - DWORD session_id = WTSGetActiveConsoleSessionId(); - WTS_INFO_CLASS wts_info_class = WTSSessionInfoEx; - LPTSTR session_info_buffer = nullptr; - DWORD session_info_buffer_size_bytes = 0; - - WTSINFOEXW* wts_info = nullptr; - LONG session_state = WTS_SESSIONSTATE_UNKNOWN; - - if (WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, session_id, - wts_info_class, &session_info_buffer, - &session_info_buffer_size_bytes)) { - if (session_info_buffer_size_bytes > 0) { - wts_info = (WTSINFOEXW*)session_info_buffer; - if (wts_info->Level == 1) { - session_state = wts_info->Data.WTSInfoExLevel1.SessionFlags; - } - } - WTSFreeMemory(session_info_buffer); - session_info_buffer = nullptr; - } - bool isScreenLocked = session_state == WTS_SESSIONSTATE_LOCK; - - NEARBY_LOGS(INFO) << __func__ << "ScreenStatus: " - << (isScreenLocked ? "Locked" : "NotLocked"); - - return isScreenLocked; -} - -void DeviceInfo::RegisterScreenLockedListener( - absl::string_view listener_name, - std::function callback) { - if (message_window_handle_ == nullptr) { - instance_ = (HINSTANCE)GetModuleHandle(NULL); - - WNDCLASS window_class; - window_class.style = 0; - window_class.lpfnWndProc = (WNDPROC)&WindowProc; - window_class.cbClsExtra = 0; - window_class.cbWndExtra = 0; - window_class.hInstance = instance_; - window_class.hIcon = nullptr; - window_class.hCursor = nullptr; - window_class.hbrBackground = nullptr; - window_class.lpszMenuName = nullptr; - window_class.lpszClassName = window_class_name; - - registered_class_ = RegisterClass(&window_class); - - message_window_handle_ = CreateWindow( - MAKEINTATOM(registered_class_), // class atom from RegisterClass - window_name, // window name - 0, // window style - 0, // initial x position of window - 0, // initial y position of window - 0, // width - 0, // height - HWND_MESSAGE, // handle to the parent of window - // (message-only window in this case) - nullptr, // handle to a menu - instance_, // handle to the instance of the module - // associated to the window - this); // pointer to be passed to the window for additional data - - if (!message_window_handle_) { - NEARBY_LOGS(ERROR) - << __func__ << ": Failed to create message window for Fast Pair DLL."; - } - } - - screen_locked_listeners_.emplace(listener_name, callback); -} - -void DeviceInfo::UnregisterScreenLockedListener( - absl::string_view listener_name) { - screen_locked_listeners_.erase(listener_name); -} - -} // namespace windows -} // namespace nearby diff --git a/fastpair/internal/impl/windows/fast_pair_platform.cc b/fastpair/internal/impl/windows/fast_pair_platform.cc deleted file mode 100644 index 170356e8..00000000 --- a/fastpair/internal/impl/windows/fast_pair_platform.cc +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "fastpair/internal/api/fast_pair_platform.h" - -#include -#include -#include - -#include "absl/strings/string_view.h" -#include "fastpair/internal/impl/windows/device_info.h" - -namespace nearby { -namespace api { - -std::unique_ptr -ImplementationFastPairPlatform::CreateDeviceInfo() { - return std::make_unique(); -} - -} // namespace api -} // namespace nearby diff --git a/fastpair/internal/public/BUILD b/fastpair/internal/public/BUILD deleted file mode 100644 index 24f42115..00000000 --- a/fastpair/internal/public/BUILD +++ /dev/null @@ -1,32 +0,0 @@ -licenses(["notice"]) - -cc_library( - name = "types", - hdrs = [ - "device_info.h", - ], - visibility = ["//fastpair:__subpackages__"], - deps = [ - "//fastpair/internal/api:platform", - "//fastpair/internal/impl/g3:platform_g3", - "@com_google_absl//absl/status", - "@com_google_absl//absl/strings", - "@com_google_absl//absl/time", - ], -) - -cc_library( - name = "device_info", - srcs = [ - "device_info_impl.cc", - ], - hdrs = [ - "device_info_impl.h", - ], - visibility = ["//fastpair:__subpackages__"], - deps = [ - ":types", - "//fastpair/internal/api:platform", - "//fastpair/internal/impl/g3:platform_g3", - ], -) diff --git a/fastpair/internal/public/device_info.h b/fastpair/internal/public/device_info.h deleted file mode 100644 index ecd9780f..00000000 --- a/fastpair/internal/public/device_info.h +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef THIRD_PARTY_NEARBY_FASTPAIR_INTERNAL_PUBLIC_DEVICE_INFO_H_ -#define THIRD_PARTY_NEARBY_FASTPAIR_INTERNAL_PUBLIC_DEVICE_INFO_H_ - -#include -#include - -#include "absl/strings/string_view.h" -#include "fastpair/internal/api/device_info.h" -#include "fastpair/internal/api/fast_pair_platform.h" - -namespace nearby { -namespace fastpair { - -class DeviceInfo { - public: - virtual ~DeviceInfo() = default; - - virtual api::DeviceInfo::OsType GetOsType() const = 0; - - virtual bool IsScreenLocked() const = 0; - virtual void RegisterScreenLockedListener( - absl::string_view listener_name, - std::function callback) = 0; - virtual void UnregisterScreenLockedListener( - absl::string_view listener_name) = 0; -}; - -} // namespace fastpair -} // namespace nearby - -#endif // THIRD_PARTY_NEARBY_FASTPAIR_INTERNAL_PUBLIC_DEVICE_INFO_H_ diff --git a/fastpair/internal/public/device_info_impl.cc b/fastpair/internal/public/device_info_impl.cc deleted file mode 100644 index aaae6127..00000000 --- a/fastpair/internal/public/device_info_impl.cc +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "fastpair/internal/public/device_info_impl.h" - -#include -#include - -namespace nearby { -namespace fastpair { - -api::DeviceInfo::OsType DeviceInfoImpl::GetOsType() const { - return device_info_impl_->GetOsType(); -} - -bool DeviceInfoImpl::IsScreenLocked() const { - return device_info_impl_->IsScreenLocked(); -} - -void DeviceInfoImpl::RegisterScreenLockedListener( - absl::string_view listener_name, - std::function callback) { - device_info_impl_->RegisterScreenLockedListener(listener_name, callback); -} - -void DeviceInfoImpl::UnregisterScreenLockedListener( - absl::string_view listener_name) { - device_info_impl_->UnregisterScreenLockedListener(listener_name); -} - -} // namespace fastpair -} // namespace nearby diff --git a/fastpair/repository/BUILD b/fastpair/repository/BUILD index 0977d2ad..88b2aefc 100644 --- a/fastpair/repository/BUILD +++ b/fastpair/repository/BUILD @@ -18,10 +18,10 @@ cc_library( visibility = ["//fastpair:__subpackages__"], deps = [ "//fastpair/common", - "//fastpair/internal/api:platform", "//fastpair/proto:fastpair_cc_proto", "//internal/network:types", "//internal/platform:logging", + "//internal/platform/implementation:types", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", diff --git a/fastpair/repository/fast_pair_metadata_fetcher_impl.cc b/fastpair/repository/fast_pair_metadata_fetcher_impl.cc index c20b7dba..c70a1e05 100644 --- a/fastpair/repository/fast_pair_metadata_fetcher_impl.cc +++ b/fastpair/repository/fast_pair_metadata_fetcher_impl.cc @@ -19,7 +19,7 @@ #include "absl/strings/string_view.h" #include "fastpair/common/fast_pair_http_result.h" -#include "fastpair/internal/api/device_info.h" +#include "internal/platform/implementation/device_info.h" #include "internal/platform/logging.h" namespace nearby { diff --git a/fastpair/repository/fast_pair_metadata_fetcher_impl.h b/fastpair/repository/fast_pair_metadata_fetcher_impl.h index 825a3972..e7599999 100644 --- a/fastpair/repository/fast_pair_metadata_fetcher_impl.h +++ b/fastpair/repository/fast_pair_metadata_fetcher_impl.h @@ -22,10 +22,10 @@ #include "absl/container/flat_hash_map.h" #include "absl/status/statusor.h" -#include "fastpair/internal/api/device_info.h" #include "fastpair/repository/fast_pair_metadata_fetcher.h" #include "internal/network/http_client.h" #include "internal/network/url.h" +#include "internal/platform/implementation/device_info.h" namespace nearby { namespace fastpair { diff --git a/fastpair/repository/fast_pair_metadata_repository_impl.cc b/fastpair/repository/fast_pair_metadata_repository_impl.cc index 78394f44..c0de0260 100644 --- a/fastpair/repository/fast_pair_metadata_repository_impl.cc +++ b/fastpair/repository/fast_pair_metadata_repository_impl.cc @@ -23,15 +23,15 @@ #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" #include "fastpair/common/fast_pair_http_result.h" -#include "fastpair/internal/api/device_info.h" #include "fastpair/proto/fastpair_rpcs.proto.h" #include "fastpair/repository/fast_pair_metadata_fetcher.h" -#include "fastpair/repository/fast_pair_metadata_repository.h" #include "fastpair/repository/fast_pair_metadata_fetcher_impl.h" +#include "fastpair/repository/fast_pair_metadata_repository.h" +#include "internal/network/http_client.h" #include "internal/network/http_client_factory.h" #include "internal/network/url.h" +#include "internal/platform/implementation/device_info.h" #include "internal/platform/logging.h" -#include "internal/network/http_client.h" namespace nearby { namespace fastpair { diff --git a/internal/base/BUILD b/internal/base/BUILD index 91f1d139..2bdeef6f 100644 --- a/internal/base/BUILD +++ b/internal/base/BUILD @@ -33,6 +33,7 @@ cc_library( ], visibility = [ "//fastpair:__subpackages__", + "//internal:__subpackages__", "//location/nearby/cpp/fastpair:__subpackages__", ], deps = [ diff --git a/internal/platform/BUILD b/internal/platform/BUILD index 1417bdcf..d38291a2 100644 --- a/internal/platform/BUILD +++ b/internal/platform/BUILD @@ -303,6 +303,7 @@ cc_test( cc_library( name = "types", srcs = [ + "device_info_impl.cc", "monitored_runnable.cc", "pending_job_registry.cc", "pipe.cc", @@ -319,6 +320,8 @@ cc_library( "condition_variable.h", "count_down_latch.h", "crypto.h", + "device_info.h", + "device_info_impl.h", "direct_executor.h", "file.h", "future.h", @@ -362,6 +365,7 @@ cc_library( "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/functional:any_invocable", "@com_google_absl//absl/log:check", + "@com_google_absl//absl/strings", "@com_google_absl//absl/synchronization", "@com_google_absl//absl/time", "@com_google_glog//:glog", diff --git a/internal/platform/device_info.h b/internal/platform/device_info.h new file mode 100644 index 00000000..88254734 --- /dev/null +++ b/internal/platform/device_info.h @@ -0,0 +1,73 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef PLATFORM_PUBLIC_DEVICE_INFO_H_ +#define PLATFORM_PUBLIC_DEVICE_INFO_H_ + +#include +#include +#include +#include + +#include "absl/strings/string_view.h" +#include "internal/platform/implementation/device_info.h" +#include "internal/platform/implementation/platform.h" + +namespace nearby { + +class DeviceInfo { + public: + virtual ~DeviceInfo() = default; + + virtual std::u16string GetOsDeviceName() const = 0; + virtual api::DeviceInfo::DeviceType GetDeviceType() const = 0; + virtual api::DeviceInfo::OsType GetOsType() const = 0; + virtual std::optional GetFullName() const = 0; + virtual std::optional GetGivenName() const = 0; + virtual std::optional GetLastName() const = 0; + virtual std::optional GetProfileUserName() const = 0; + + virtual std::filesystem::path GetDownloadPath() const = 0; + virtual std::filesystem::path GetAppDataPath() const = 0; + virtual std::filesystem::path GetTemporaryPath() const = 0; + + virtual std::optional GetAvailableDiskSpaceInBytes( + const std::filesystem::path& path) const = 0; + + virtual bool IsScreenLocked() const = 0; + virtual void RegisterScreenLockedListener( + absl::string_view listener_name, + std::function callback) = 0; + virtual void UnregisterScreenLockedListener( + absl::string_view listener_name) = 0; + + // Returns localized device name depends on device type. + std::u16string GetDeviceTypeName() const { + // TODO(b/230132370): return localized device name. + switch (GetDeviceType()) { + case api::DeviceInfo::DeviceType::kPhone: + return u"Phone"; + case api::DeviceInfo::DeviceType::kTablet: + return u"Tablet"; + case api::DeviceInfo::DeviceType::kLaptop: + return u"PC"; + default: + return u"Unknown"; + } + } +}; + +} // namespace nearby + +#endif // PLATFORM_PUBLIC_DEVICE_INFO_H_ diff --git a/internal/platform/device_info_impl.cc b/internal/platform/device_info_impl.cc new file mode 100644 index 00000000..db593566 --- /dev/null +++ b/internal/platform/device_info_impl.cc @@ -0,0 +1,111 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "internal/platform/device_info_impl.h" + +#include +#include +#include +#include + +namespace nearby { + +std::u16string DeviceInfoImpl::GetOsDeviceName() const { + std::optional device_name = + device_info_impl_->GetOsDeviceName(); + if (device_name.has_value()) { + return *device_name; + } + + return u"unknown"; +} + +api::DeviceInfo::DeviceType DeviceInfoImpl::GetDeviceType() const { + return device_info_impl_->GetDeviceType(); +} + +api::DeviceInfo::OsType DeviceInfoImpl::GetOsType() const { + return device_info_impl_->GetOsType(); +} + +std::optional DeviceInfoImpl::GetFullName() const { + return device_info_impl_->GetFullName(); +} + +std::optional DeviceInfoImpl::GetGivenName() const { + return device_info_impl_->GetGivenName(); +} + +std::optional DeviceInfoImpl::GetLastName() const { + return device_info_impl_->GetLastName(); +} + +std::optional DeviceInfoImpl::GetProfileUserName() const { + return device_info_impl_->GetProfileUserName(); +} + +std::filesystem::path DeviceInfoImpl::GetDownloadPath() const { + std::optional path = + device_info_impl_->GetDownloadPath(); + if (path.has_value()) { + return *path; + } + return std::filesystem::temp_directory_path(); +} + +std::filesystem::path DeviceInfoImpl::GetAppDataPath() const { + std::optional path = + device_info_impl_->GetAppDataPath(); + if (path.has_value()) { + return *path; + } + return std::filesystem::temp_directory_path(); +} + +std::filesystem::path DeviceInfoImpl::GetTemporaryPath() const { + std::optional path = + device_info_impl_->GetTemporaryPath(); + if (path.has_value()) { + return *path; + } + return std::filesystem::temp_directory_path(); +} + +std::optional DeviceInfoImpl::GetAvailableDiskSpaceInBytes( + const std::filesystem::path& path) const { + std::error_code error_code; + std::filesystem::space_info space_info = + std::filesystem::space(path, error_code); + if (error_code.value() == 0) { + return space_info.available; + } + return std::nullopt; +} + +bool DeviceInfoImpl::IsScreenLocked() const { + return device_info_impl_->IsScreenLocked(); +} + +void DeviceInfoImpl::RegisterScreenLockedListener( + absl::string_view listener_name, + std::function callback) { + device_info_impl_->RegisterScreenLockedListener(listener_name, callback); +} + +void DeviceInfoImpl::UnregisterScreenLockedListener( + absl::string_view listener_name) { + device_info_impl_->UnregisterScreenLockedListener(listener_name); +} + +} // namespace nearby diff --git a/fastpair/internal/public/device_info_impl.h b/internal/platform/device_info_impl.h similarity index 52% rename from fastpair/internal/public/device_info_impl.h rename to internal/platform/device_info_impl.h index d75a9056..1c44d961 100644 --- a/fastpair/internal/public/device_info_impl.h +++ b/internal/platform/device_info_impl.h @@ -1,4 +1,4 @@ -// Copyright 2022 Google LLC +// Copyright 2021 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,27 +12,41 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef THIRD_PARTY_NEARBY_FASTPAIR_INTERNAL_PUBLIC_DEVICE_INFO_IMPL_H_ -#define THIRD_PARTY_NEARBY_FASTPAIR_INTERNAL_PUBLIC_DEVICE_INFO_IMPL_H_ +#ifndef PLATFORM_PUBLIC_DEVICE_INFO_IMPL_H_ +#define PLATFORM_PUBLIC_DEVICE_INFO_IMPL_H_ +#include #include #include +#include #include -#include "fastpair/internal/api/fast_pair_platform.h" -#include "fastpair/internal/public/device_info.h" +#include "internal/platform/device_info.h" +#include "internal/platform/implementation/platform.h" namespace nearby { -namespace fastpair { class DeviceInfoImpl : public DeviceInfo { public: DeviceInfoImpl() - : device_info_impl_( - api::ImplementationFastPairPlatform::CreateDeviceInfo()) {} + : device_info_impl_(api::ImplementationPlatform::CreateDeviceInfo()) {} + std::u16string GetOsDeviceName() const override; + api::DeviceInfo::DeviceType GetDeviceType() const override; api::DeviceInfo::OsType GetOsType() const override; + std::optional GetFullName() const override; + std::optional GetGivenName() const override; + std::optional GetLastName() const override; + std::optional GetProfileUserName() const override; + + std::filesystem::path GetDownloadPath() const override; + std::filesystem::path GetAppDataPath() const override; + std::filesystem::path GetTemporaryPath() const override; + + std::optional GetAvailableDiskSpaceInBytes( + const std::filesystem::path& path) const override; + bool IsScreenLocked() const override; void RegisterScreenLockedListener( absl::string_view listener_name, @@ -42,8 +56,6 @@ class DeviceInfoImpl : public DeviceInfo { private: std::unique_ptr device_info_impl_; }; - -} // namespace fastpair } // namespace nearby -#endif // THIRD_PARTY_NEARBY_FASTPAIR_INTERNAL_PUBLIC_DEVICE_INFO_IMPL_H_ +#endif // PLATFORM_PUBLIC_DEVICE_INFO_IMPL_H_ diff --git a/internal/platform/implementation/BUILD b/internal/platform/implementation/BUILD index 9fd2b3fc..d96453ce 100644 --- a/internal/platform/implementation/BUILD +++ b/internal/platform/implementation/BUILD @@ -23,6 +23,7 @@ cc_library( "condition_variable.h", "count_down_latch.h", "crypto.h", + "device_info.h", "executor.h", "future.h", "input_file.h", @@ -109,6 +110,7 @@ cc_library( "//connections/implementation:__subpackages__", "//fastpair:__subpackages__", "//internal:__pkg__", + "//internal:__subpackages__", "//internal/network:__subpackages__", "//internal/platform:__pkg__", "//internal/platform/implementation:__subpackages__", diff --git a/internal/platform/implementation/apple/BUILD b/internal/platform/implementation/apple/BUILD index f4398c51..317790ee 100644 --- a/internal/platform/implementation/apple/BUILD +++ b/internal/platform/implementation/apple/BUILD @@ -25,6 +25,7 @@ objc_library( "ble.mm", "bluetooth_adapter.mm", "crypto.mm", + "device_info.mm", "log_message.mm", "multi_thread_executor.mm", "platform.mm", @@ -36,6 +37,7 @@ objc_library( hdrs = [ "ble.h", "bluetooth_adapter.h", + "device_info.h", "log_message.h", "multi_thread_executor.h", "scheduled_executor.h", diff --git a/internal/platform/implementation/apple/device_info.h b/internal/platform/implementation/apple/device_info.h new file mode 100644 index 00000000..85ff0594 --- /dev/null +++ b/internal/platform/implementation/apple/device_info.h @@ -0,0 +1,60 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef PLATFORM_IMPL_APPLE_DEVICE_INFO_H_ +#define PLATFORM_IMPL_APPLE_DEVICE_INFO_H_ + +#include // NOLINT(build/c++17) +#include +#include +#include + +#include "absl/strings/string_view.h" +#include "internal/platform/implementation/device_info.h" + +namespace nearby { +namespace apple { + +class DeviceInfo : public api::DeviceInfo { + public: + std::optional GetOsDeviceName() const override; + + api::DeviceInfo::DeviceType GetDeviceType() const override; + + api::DeviceInfo::OsType GetOsType() const override; + + std::optional GetFullName() const override; + std::optional GetGivenName() const override; + std::optional GetLastName() const override; + std::optional GetProfileUserName() const override; + + std::optional GetDownloadPath() const override; + + std::optional GetAppDataPath() const override; + + std::optional GetTemporaryPath() const override; + + bool IsScreenLocked() const override; + + void RegisterScreenLockedListener( + absl::string_view listener_name, + std::function callback) override; + + void UnregisterScreenLockedListener(absl::string_view listener_name) override; +}; + +} // namespace apple +} // namespace nearby + +#endif // PLATFORM_IMPL_APPLE_DEVICE_INFO_H_ diff --git a/internal/platform/implementation/apple/device_info.mm b/internal/platform/implementation/apple/device_info.mm new file mode 100644 index 00000000..79d4f5fd --- /dev/null +++ b/internal/platform/implementation/apple/device_info.mm @@ -0,0 +1,62 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import "internal/platform/implementation/apple/device_info.h" + +#include // NOLINT(build/c++17) +#include +#include +#include +#include + +#include "absl/strings/string_view.h" +#include "internal/platform/implementation/device_info.h" + +namespace nearby { +namespace apple { + +std::optional DeviceInfo::GetOsDeviceName() const { return u"OS Device Name"; } + +api::DeviceInfo::DeviceType DeviceInfo::GetDeviceType() const { + return api::DeviceInfo::DeviceType::kLaptop; +} + +api::DeviceInfo::OsType DeviceInfo::GetOsType() const { return api::DeviceInfo::OsType::kIos; } + +std::optional DeviceInfo::GetFullName() const { return u"Full Name"; } +std::optional DeviceInfo::GetGivenName() const { return u"Given Name"; } +std::optional DeviceInfo::GetLastName() const { return u"Last Name"; } +std::optional DeviceInfo::GetProfileUserName() const { return "Username"; } + +std::optional DeviceInfo::GetDownloadPath() const { + return std::filesystem::temp_directory_path(); +} + +std::optional DeviceInfo::GetAppDataPath() const { + return std::filesystem::temp_directory_path(); +} + +std::optional DeviceInfo::GetTemporaryPath() const { + return std::filesystem::temp_directory_path(); +} + +bool DeviceInfo::IsScreenLocked() const { return false; } + +void DeviceInfo::RegisterScreenLockedListener( + absl::string_view listener_name, std::function callback) {} + +void DeviceInfo::UnregisterScreenLockedListener(absl::string_view listener_name) {} + +} // namespace apple +} // namespace nearby diff --git a/internal/platform/implementation/apple/platform.mm b/internal/platform/implementation/apple/platform.mm index 7e4bb715..c61224ac 100644 --- a/internal/platform/implementation/apple/platform.mm +++ b/internal/platform/implementation/apple/platform.mm @@ -22,6 +22,7 @@ #include "internal/platform/implementation/apple/ble.h" #include "internal/platform/implementation/apple/condition_variable.h" #include "internal/platform/implementation/apple/count_down_latch.h" +#include "internal/platform/implementation/apple/device_info.h" #import "internal/platform/implementation/apple/log_message.h" #import "internal/platform/implementation/apple/multi_thread_executor.h" #include "internal/platform/implementation/apple/mutex.h" @@ -182,5 +183,10 @@ std::unique_ptr ImplementationPlatform::CreateTimer() { return std::make_unique(); } +// TODO(b/261511530): Add implementation. +std::unique_ptr ImplementationPlatform::CreateDeviceInfo() { + return std::make_unique(); +} + } // namespace api } // namespace nearby diff --git a/fastpair/internal/api/device_info.h b/internal/platform/implementation/device_info.h similarity index 51% rename from fastpair/internal/api/device_info.h rename to internal/platform/implementation/device_info.h index 453b8a21..2b9cd05a 100644 --- a/fastpair/internal/api/device_info.h +++ b/internal/platform/implementation/device_info.h @@ -12,10 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef THIRD_PARTY_NEARBY_FASTPAIR_INTERNAL_API_DEVICE_INFO_H_ -#define THIRD_PARTY_NEARBY_FASTPAIR_INTERNAL_API_DEVICE_INFO_H_ +#ifndef PLATFORM_API_DEVICE_INFO_H_ +#define PLATFORM_API_DEVICE_INFO_H_ +#include #include +#include #include #include "absl/strings/string_view.h" @@ -25,24 +27,28 @@ namespace api { class DeviceInfo { public: - enum class ScreenStatus { - kUndetermined = 0, - kLocked = 1, - kUnlocked = 2, - }; - - enum class OsType { - kUnknown = 0, - kAndroid = 1, - kChromeOs = 2, - kIos = 3, - kWindows = 4, - }; + enum class ScreenStatus { kUndetermined = 0, kLocked, kUnlocked }; + enum class DeviceType { kUnknown = 0, kPhone, kTablet, kLaptop }; + enum class OsType { kUnknown = 0, kAndroid, kChromeOs, kIos, kWindows }; virtual ~DeviceInfo() = default; + // Gets device name. + virtual std::optional GetOsDeviceName() const = 0; + virtual DeviceType GetDeviceType() const = 0; virtual OsType GetOsType() const = 0; + // Gets basic information of current user. + virtual std::optional GetFullName() const = 0; + virtual std::optional GetGivenName() const = 0; + virtual std::optional GetLastName() const = 0; + virtual std::optional GetProfileUserName() const = 0; + + // Gets known paths of current user. + virtual std::optional GetDownloadPath() const = 0; + virtual std::optional GetAppDataPath() const = 0; + virtual std::optional GetTemporaryPath() const = 0; + // Monitor screen status virtual bool IsScreenLocked() const = 0; virtual void RegisterScreenLockedListener( @@ -55,4 +61,4 @@ class DeviceInfo { } // namespace api } // namespace nearby -#endif // THIRD_PARTY_NEARBY_FASTPAIR_INTERNAL_API_DEVICE_INFO_H_ +#endif // PLATFORM_API_DEVICE_INFO_H_ diff --git a/internal/platform/implementation/g3/BUILD b/internal/platform/implementation/g3/BUILD index 7c3008bf..115b6cd4 100644 --- a/internal/platform/implementation/g3/BUILD +++ b/internal/platform/implementation/g3/BUILD @@ -25,6 +25,7 @@ cc_library( "atomic_boolean.h", "atomic_reference.h", "condition_variable.h", + "device_info.h", "log_message.h", "multi_thread_executor.h", "mutex.h", @@ -41,6 +42,8 @@ cc_library( "//internal/platform/implementation:types", "//internal/platform/implementation/shared:count_down_latch", "//internal/platform/implementation/shared:posix_mutex", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/strings", "@com_google_absl//absl/synchronization", "@com_google_absl//absl/time", "@com_google_glog//:glog", diff --git a/fastpair/internal/impl/g3/device_info.h b/internal/platform/implementation/g3/device_info.h similarity index 54% rename from fastpair/internal/impl/g3/device_info.h rename to internal/platform/implementation/g3/device_info.h index 83705081..fe43530b 100644 --- a/fastpair/internal/impl/g3/device_info.h +++ b/internal/platform/implementation/g3/device_info.h @@ -12,26 +12,61 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef THIRD_PARTY_NEARBY_FASTPAIR_INTERNAL_IMPL_G3_DEVICE_INFO_H_ -#define THIRD_PARTY_NEARBY_FASTPAIR_INTERNAL_IMPL_G3_DEVICE_INFO_H_ +#ifndef PLATFORM_IMPL_G3_DEVICE_INFO_H_ +#define PLATFORM_IMPL_G3_DEVICE_INFO_H_ +#include #include +#include #include #include #include "absl/container/flat_hash_map.h" #include "absl/strings/string_view.h" -#include "fastpair/internal/api/device_info.h" +#include "internal/platform/implementation/device_info.h" namespace nearby { namespace g3 { class DeviceInfo : public api::DeviceInfo { public: - api::DeviceInfo::OsType GetOsType() const override { + std::optional GetOsDeviceName() const override { + return u"Windows"; + } + + api::DeviceInfo::DeviceType GetDeviceType() const override { + return api::DeviceInfo::DeviceType::kLaptop; + } + + api::DeviceInfo::OsType GetOsType() const override{ return api::DeviceInfo::OsType::kChromeOs; } + std::optional GetFullName() const override { + return u"nearby"; + } + std::optional GetGivenName() const override { + return u"nearby"; + } + std::optional GetLastName() const override { + return u"nearby"; + } + std::optional GetProfileUserName() const override { + return "nearby"; + } + + std::optional GetDownloadPath() const override { + return std::filesystem::temp_directory_path(); + } + + std::optional GetAppDataPath() const override { + return std::filesystem::temp_directory_path(); + } + + std::optional GetTemporaryPath() const override { + return std::filesystem::temp_directory_path(); + } + bool IsScreenLocked() const override { return false; } void RegisterScreenLockedListener( @@ -45,6 +80,7 @@ class DeviceInfo : public api::DeviceInfo { screen_locked_listeners_.erase(listener_name); } + private: absl::flat_hash_map> screen_locked_listeners_; @@ -53,4 +89,4 @@ class DeviceInfo : public api::DeviceInfo { } // namespace g3 } // namespace nearby -#endif // THIRD_PARTY_NEARBY_FASTPAIR_INTERNAL_IMPL_G3_DEVICE_INFO_H_ +#endif // PLATFORM_IMPL_G3_DEVICE_INFO_H_ diff --git a/internal/platform/implementation/g3/platform.cc b/internal/platform/implementation/g3/platform.cc index d092d233..e4056d14 100644 --- a/internal/platform/implementation/g3/platform.cc +++ b/internal/platform/implementation/g3/platform.cc @@ -48,6 +48,7 @@ #include "internal/platform/implementation/g3/bluetooth_classic.h" #include "internal/platform/implementation/g3/condition_variable.h" #include "internal/platform/implementation/g3/credential_storage_impl.h" +#include "internal/platform/implementation/g3/device_info.h" #include "internal/platform/implementation/g3/log_message.h" #include "internal/platform/implementation/g3/multi_thread_executor.h" #include "internal/platform/implementation/g3/mutex.h" @@ -229,5 +230,10 @@ std::unique_ptr ImplementationPlatform::CreateTimer() { return std::make_unique(); } +std::unique_ptr +ImplementationPlatform::CreateDeviceInfo() { + return std::make_unique(); +} + } // namespace api } // namespace nearby diff --git a/internal/platform/implementation/platform.h b/internal/platform/implementation/platform.h index 1e6e0028..c26deb36 100644 --- a/internal/platform/implementation/platform.h +++ b/internal/platform/implementation/platform.h @@ -31,6 +31,7 @@ #include "internal/platform/implementation/count_down_latch.h" #include "internal/platform/implementation/credential_storage.h" #include "internal/platform/implementation/crypto.h" +#include "internal/platform/implementation/device_info.h" #include "internal/platform/implementation/http_loader.h" #include "internal/platform/implementation/input_file.h" #include "internal/platform/implementation/log_message.h" @@ -130,6 +131,7 @@ class ImplementationPlatform { static std::unique_ptr CreateWifiHotspotMedium(); static std::unique_ptr CreateWifiDirectMedium(); static std::unique_ptr CreateTimer(); + static std::unique_ptr CreateDeviceInfo(); #ifndef NO_WEBRTC static std::unique_ptr CreateWebRtcMedium(); #endif diff --git a/internal/platform/implementation/windows/BUILD b/internal/platform/implementation/windows/BUILD index a7eff7fd..8310b346 100644 --- a/internal/platform/implementation/windows/BUILD +++ b/internal/platform/implementation/windows/BUILD @@ -16,6 +16,7 @@ licenses(["notice"]) cc_library( name = "types", srcs = [ + "device_info.cc", "log_message.cc", "timer.cc", ], @@ -24,6 +25,7 @@ cc_library( "atomic_reference.h", "bluetooth_adapter.h", "condition_variable.h", + "device_info.h", "executor.h", "future.h", "input_file.h", @@ -37,9 +39,12 @@ cc_library( "timer.h", "utils.h", ], + copts = ["-Ithird_party/nearby/internal/platform/implementation/windows/generated"], + defines = ["_SILENCE_CLANG_COROUTINE_MESSAGE"], deps = [ "//base", "//base:stringprintf", + "//internal/base:bluetooth_address", "//internal/platform:base", "//internal/platform:logging", "//internal/platform/implementation:types", @@ -219,6 +224,7 @@ cc_test( "bluetooth_adapter_test.cc", "count_down_latch_test.cc", "crypto_test.cc", + "device_info_test.cc", "executor_test.cc", "file_path_test.cc", "http_loader_test.cc", diff --git a/internal/platform/implementation/windows/device_info.cc b/internal/platform/implementation/windows/device_info.cc new file mode 100644 index 00000000..7286aa19 --- /dev/null +++ b/internal/platform/implementation/windows/device_info.cc @@ -0,0 +1,447 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "internal/platform/implementation/windows/device_info.h" + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "absl/container/flat_hash_map.h" +#include "absl/strings/string_view.h" +#include "internal/base/bluetooth_address.h" +#include "internal/platform/implementation/device_info.h" +#include "internal/platform/logging.h" +#include "winrt/Windows.Foundation.Collections.h" +#include "winrt/Windows.Foundation.h" +#include "winrt/Windows.System.h" + +namespace nearby { +namespace windows { + +using IInspectable = winrt::Windows::Foundation::IInspectable; +using KnownUserProperties = winrt::Windows::System::KnownUserProperties; +using User = winrt::Windows::System::User; +using UserType = winrt::Windows::System::UserType; +using UserAuthenticationStatus = + winrt::Windows::System::UserAuthenticationStatus; + +template +using IVectorView = winrt::Windows::Foundation::Collections::IVectorView; + +template +using IAsyncOperation = winrt::Windows::Foundation::IAsyncOperation; + +constexpr char window_class_name[] = "NearbySharingDLL_MessageWindowClass"; +constexpr char window_name[] = "NearbySharingDLL_MessageWindow"; + +namespace { +// This WindowProc method must be static for the successful initialization of +// WNDCLASS +// window_class.lpfnWndProc = (WNDPROC) &DeviceInfo::WindowProc; +// where a WNDPROC typed function pointer is expected +// typedef LRESULT (CALLBACK* WNDPROC)(HWND,UINT,WPARAM,LPARAM) +// the calling convention used here CALLBACK is a macro defined as +// #define CALLBACK __stdcall +// +// If WindProc is not static and defined as a member function, it uses the +// __thiscall calling convention instead +// https://docs.microsoft.com/en-us/cpp/cpp/thiscall?view=msvc-170 +// https://isocpp.org/wiki/faq/pointers-to-members +// https://en.cppreference.com/w/cpp/language/pointer +// +// This is problematic because the function pointer now looks like this +// typedef LRESULT (CALLBACK* DeviceInfo_WNDPROC)(DeviceInfo* +// this,HWND,UINT,WPARAM,LPARAM) +// which causes casting errors +LRESULT CALLBACK WindowProc(HWND window_handle, UINT message, WPARAM wparam, + LPARAM lparam) { + DeviceInfo* self = reinterpret_cast( + GetWindowLongPtr(window_handle, GWLP_USERDATA)); + CREATESTRUCT* create_struct = reinterpret_cast(lparam); + LONG_PTR result = 0L; + switch (message) { + case WM_CREATE: + self = reinterpret_cast(create_struct->lpCreateParams); + self->message_window_handle_ = window_handle; + + // Store pointer to the self to the window's user data. + SetLastError(0); + result = SetWindowLongPtr(window_handle, GWLP_USERDATA, + reinterpret_cast(self)); + if (result == 0 && GetLastError() != 0) { + NEARBY_LOGS(ERROR) + << __func__ + << ": Error connecting message window to Nearby Sharing DLL."; + } + break; + case WM_WTSSESSION_CHANGE: + if (self) { + switch (wparam) { + case WTS_SESSION_LOCK: + for (auto& listener : self->screen_locked_listeners_) { + listener.second(api::DeviceInfo::ScreenStatus:: + kLocked); // Trigger registered callbacks + } + break; + case WTS_SESSION_UNLOCK: + for (auto& listener : self->screen_locked_listeners_) { + listener.second(api::DeviceInfo::ScreenStatus:: + kUnlocked); // Trigger registered callbacks + } + break; + } + } + break; + case WM_DESTROY: + SetLastError(0); + result = SetWindowLongPtr(window_handle, GWLP_USERDATA, NULL); + if (result == 0 && GetLastError() != 0) { + NEARBY_LOGS(ERROR) + << __func__ + << ": Error disconnecting message window to Nearby Sharing DLL."; + } + break; + } + + return DefWindowProc(window_handle, message, wparam, lparam); +} +} // namespace + +DeviceInfo::~DeviceInfo() { + UnregisterClass(MAKEINTATOM(registered_class_), instance_); +} + +std::optional DeviceInfo::GetOsDeviceName() const { + DWORD size = 0; + + // Get length of the computer name. + if (!GetComputerNameExW(ComputerNameDnsHostname, nullptr, &size)) { + if (GetLastError() != ERROR_MORE_DATA) { + NEARBY_LOGS(ERROR) << ": Failed to get device name size, error:" + << GetLastError(); + return std::nullopt; + } + } + + WCHAR device_name[size]; + if (GetComputerNameExW(ComputerNameDnsHostname, device_name, &size)) { + std::wstring wide_name(device_name); + return std::u16string(wide_name.begin(), wide_name.end()); + } + + NEARBY_LOGS(ERROR) << ": Failed to get device name, error:" << GetLastError(); + return std::nullopt; +} + +api::DeviceInfo::DeviceType DeviceInfo::GetDeviceType() const { + // TODO(b/230132370): return correct device type on the Windows platform. + return api::DeviceInfo::DeviceType::kLaptop; +} + +api::DeviceInfo::OsType DeviceInfo::GetOsType() const { + return api::DeviceInfo::OsType::kWindows; +} + +std::optional DeviceInfo::GetFullName() const { + // FindAllAsync finds all users that are using this app. When we "Switch User" + // on Desktop,FindAllAsync() will still return the current user instead of all + // of them because the users who are switched out are not using the apps of + // the user who is switched in, so FindAllAsync() will not find them. (Under + // the UWP application model, each process runs under its own user account. + // That user account is different from the user account of the logged-in user. + // Processes aren't owned by the logged-in user for purposes of isolation.) + IVectorView users = + User::FindAllAsync(UserType::LocalUser, + UserAuthenticationStatus::LocallyAuthenticated) + .get(); + if (users == nullptr) { + NEARBY_LOGS(ERROR) << __func__ + << ": Error retrieving locally authenticated user."; + return std::nullopt; + } + + // On Windows Desktop apps, the first Windows.System.User instance + // returned in the IVectorView is always the current user. + // https://github.com/microsoft/Windows-task-snippets/blob/master/tasks/User-info.md + User current_user = users.GetAt(0); + + // Retrieve the human-readable properties for the current user + IAsyncOperation full_name_obj_async = + current_user.GetPropertyAsync(KnownUserProperties::DisplayName()); + IInspectable full_name_obj = full_name_obj_async.get(); + if (full_name_obj == nullptr) { + NEARBY_LOGS(ERROR) << __func__ << ": Error retrieving full name of user."; + return std::nullopt; + } + winrt::hstring full_name = full_name_obj.as(); + std::wstring wstr(full_name); + std::u16string u16str(wstr.begin(), wstr.end()); + + if (u16str.empty()) { + NEARBY_LOGS(ERROR) + << __func__ << ": Error unboxing string value for full name of user."; + return std::nullopt; + } + + return u16str; +} + +std::optional DeviceInfo::GetGivenName() const { + // FindAllAsync finds all users that are using this app. When we "Switch User" + // on Desktop,FindAllAsync() will still return the current user instead of all + // of them because the users who are switched out are not using the apps of + // the user who is switched in, so FindAllAsync() will not find them. (Under + // the UWP application model, each process runs under its own user account. + // That user account is different from the user account of the logged-in user. + // Processes aren't owned by the logged-in user for purposes of isolation.) + IVectorView users = + User::FindAllAsync(UserType::LocalUser, + UserAuthenticationStatus::LocallyAuthenticated) + .get(); + if (users == nullptr) { + NEARBY_LOGS(ERROR) << __func__ + << ": Error retrieving locally authenticated user."; + return std::nullopt; + } + + // On Windows Desktop apps, the first Windows.System.User instance + // returned in the IVectorView is always the current user. + // https://github.com/microsoft/Windows-task-snippets/blob/master/tasks/User-info.md + User current_user = users.GetAt(0); + + // Retrieve the human-readable properties for the current user + IAsyncOperation given_name_obj_async = + current_user.GetPropertyAsync(KnownUserProperties::FirstName()); + IInspectable given_name_obj = given_name_obj_async.get(); + if (given_name_obj == nullptr) { + NEARBY_LOGS(ERROR) << __func__ << ": Error retrieving first name of user."; + return std::nullopt; + } + winrt::hstring given_name = given_name_obj.as(); + std::wstring wstr(given_name); + std::u16string u16str(wstr.begin(), wstr.end()); + + if (u16str.empty()) { + NEARBY_LOGS(ERROR) + << __func__ << ": Error unboxing string value for first name of user."; + return std::nullopt; + } + + return u16str; +} + +std::optional DeviceInfo::GetLastName() const { + // FindAllAsync finds all users that are using this app. When we "Switch User" + // on Desktop,FindAllAsync() will still return the current user instead of all + // of them because the users who are switched out are not using the apps of + // the user who is switched in, so FindAllAsync() will not find them. (Under + // the UWP application model, each process runs under its own user account. + // That user account is different from the user account of the logged-in user. + // Processes aren't owned by the logged-in user for purposes of isolation.) + IVectorView users = + User::FindAllAsync(UserType::LocalUser, + UserAuthenticationStatus::LocallyAuthenticated) + .get(); + if (users == nullptr) { + NEARBY_LOGS(ERROR) << __func__ + << ": Error retrieving locally authenticated user."; + return std::nullopt; + } + + // On Windows Desktop apps, the first Windows.System.User instance + // returned in the IVectorView is always the current user. + // https://github.com/microsoft/Windows-task-snippets/blob/master/tasks/User-info.md + User current_user = users.GetAt(0); + + // Retrieve the human-readable properties for the current user + IAsyncOperation last_name_obj_async = + current_user.GetPropertyAsync(KnownUserProperties::LastName()); + IInspectable last_name_obj = last_name_obj_async.get(); + if (last_name_obj == nullptr) { + NEARBY_LOGS(ERROR) << __func__ << ": Error retrieving last name of user."; + return std::nullopt; + } + winrt::hstring last_name = last_name_obj.as(); + std::wstring wstr(last_name); + std::u16string u16str(wstr.begin(), wstr.end()); + + if (u16str.empty()) { + NEARBY_LOGS(ERROR) + << __func__ << ": Error unboxing string value for last name of user."; + return std::nullopt; + } + + return u16str; +} + +std::optional DeviceInfo::GetProfileUserName() const { + // FindAllAsync finds all users that are using this app. When we "Switch User" + // on Desktop,FindAllAsync() will still return the current user instead of all + // of them because the users who are switched out are not using the apps of + // the user who is switched in, so FindAllAsync() will not find them. (Under + // the UWP application model, each process runs under its own user account. + // That user account is different from the user account of the logged-in user. + // Processes aren't owned by the logged-in user for purposes of isolation.) + IVectorView users = + User::FindAllAsync(UserType::LocalUser, + UserAuthenticationStatus::LocallyAuthenticated) + .get(); + if (users == nullptr) { + NEARBY_LOGS(ERROR) << __func__ + << ": Error retrieving locally authenticated user."; + return std::nullopt; + } + + // On Windows Desktop apps, the first Windows.System.User instance + // returned in the IVectorView is always the current user. + // https://github.com/microsoft/Windows-task-snippets/blob/master/tasks/User-info.md + User current_user = users.GetAt(0); + + // Retrieve the human-readable properties for the current user + IAsyncOperation account_name_obj_async = + current_user.GetPropertyAsync(KnownUserProperties::AccountName()); + IInspectable account_name_obj = account_name_obj_async.get(); + if (account_name_obj == nullptr) { + NEARBY_LOGS(ERROR) << __func__ + << ": Error retrieving account name of user."; + return std::nullopt; + } + winrt::hstring account_name = account_name_obj.as(); + std::string account_name_string = winrt::to_string(account_name); + + if (account_name_string.empty()) { + NEARBY_LOGS(ERROR) + << __func__ + << ": Error unboxing string value for profile username of user."; + return std::nullopt; + } + + return account_name_string; +} + +std::optional DeviceInfo::GetDownloadPath() const { + PWSTR path; + HRESULT result = + SHGetKnownFolderPath(FOLDERID_Downloads, KF_FLAG_DEFAULT, nullptr, &path); + if (result == S_OK) { + std::wstring download_path{path}; + CoTaskMemFree(path); + return std::filesystem::path(download_path); + } + + CoTaskMemFree(path); + return std::nullopt; +} + +std::optional DeviceInfo::GetAppDataPath() const { + std::string path; + path.resize(MAX_PATH); + HRESULT result = SHGetFolderPathA(nullptr, CSIDL_LOCAL_APPDATA, nullptr, + SHGFP_TYPE_CURRENT, path.data()); + if (result == S_OK) { + path.resize(strlen(path.data())); + return std::filesystem::path(path); + } + + return std::nullopt; +} + +std::optional DeviceInfo::GetTemporaryPath() const { + return std::filesystem::temp_directory_path(); +} + +bool DeviceInfo::IsScreenLocked() const { + DWORD session_id = WTSGetActiveConsoleSessionId(); + WTS_INFO_CLASS wts_info_class = WTSSessionInfoEx; + LPTSTR session_info_buffer = nullptr; + DWORD session_info_buffer_size_bytes = 0; + + WTSINFOEXW* wts_info = nullptr; + LONG session_state = WTS_SESSIONSTATE_UNKNOWN; + + if (WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, session_id, + wts_info_class, &session_info_buffer, + &session_info_buffer_size_bytes)) { + if (session_info_buffer_size_bytes > 0) { + wts_info = (WTSINFOEXW*)session_info_buffer; + if (wts_info->Level == 1) { + session_state = wts_info->Data.WTSInfoExLevel1.SessionFlags; + } + } + WTSFreeMemory(session_info_buffer); + session_info_buffer = nullptr; + } + + return (session_state == WTS_SESSIONSTATE_LOCK); +} + +void DeviceInfo::RegisterScreenLockedListener( + absl::string_view listener_name, + std::function callback) { + if (message_window_handle_ == nullptr) { + instance_ = (HINSTANCE)GetModuleHandle(NULL); + + WNDCLASS window_class; + window_class.style = 0; + window_class.lpfnWndProc = (WNDPROC)&WindowProc; + window_class.cbClsExtra = 0; + window_class.cbWndExtra = 0; + window_class.hInstance = instance_; + window_class.hIcon = nullptr; + window_class.hCursor = nullptr; + window_class.hbrBackground = nullptr; + window_class.lpszMenuName = nullptr; + window_class.lpszClassName = window_class_name; + + registered_class_ = RegisterClass(&window_class); + + message_window_handle_ = CreateWindow( + MAKEINTATOM(registered_class_), // class atom from RegisterClass + window_name, // window name + 0, // window style + 0, // initial x position of window + 0, // initial y position of window + 0, // width + 0, // height + HWND_MESSAGE, // handle to the parent of window + // (message-only window in this case) + nullptr, // handle to a menu + instance_, // handle to the instance of the module + // associated to the window + this); // pointer to be passed to the window for additional data + + if (!message_window_handle_) { + NEARBY_LOGS(ERROR) + << __func__ + << ": Failed to create message window for Nearby Sharing DLL."; + } + } + + screen_locked_listeners_.emplace(listener_name, callback); +} + +void DeviceInfo::UnregisterScreenLockedListener( + absl::string_view listener_name) { + screen_locked_listeners_.erase(listener_name); +} + +} // namespace windows +} // namespace nearby diff --git a/fastpair/internal/impl/windows/device_info.h b/internal/platform/implementation/windows/device_info.h similarity index 62% rename from fastpair/internal/impl/windows/device_info.h rename to internal/platform/implementation/windows/device_info.h index 4e7f6b29..1543ede9 100644 --- a/fastpair/internal/impl/windows/device_info.h +++ b/internal/platform/implementation/windows/device_info.h @@ -1,4 +1,4 @@ -// Copyright 2022 Google LLC +// Copyright 2021 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,18 +12,21 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef THIRD_PARTY_NEARBY_FASTPAIR_INTERNAL_IMPL_WINDOWS_DEVICE_INFO_H_ -#define THIRD_PARTY_NEARBY_FASTPAIR_INTERNAL_IMPL_WINDOWS_DEVICE_INFO_H_ +#ifndef PLATFORM_IMPL_WINDOWS_DEVICE_INFO_H_ +#define PLATFORM_IMPL_WINDOWS_DEVICE_INFO_H_ #include #include +#include #include +#include #include #include "absl/container/flat_hash_map.h" #include "absl/strings/string_view.h" -#include "fastpair/internal/api/device_info.h" +#include "internal/platform/implementation/device_info.h" +#include "winrt/Windows.Foundation.h" namespace nearby { namespace windows { @@ -32,7 +35,17 @@ class DeviceInfo : public api::DeviceInfo { public: ~DeviceInfo() override; + std::optional GetOsDeviceName() const override; + api::DeviceInfo::DeviceType GetDeviceType() const override; api::DeviceInfo::OsType GetOsType() const override; + std::optional GetFullName() const override; + std::optional GetGivenName() const override; + std::optional GetLastName() const override; + std::optional GetProfileUserName() const override; + + std::optional GetDownloadPath() const override; + std::optional GetAppDataPath() const override; + std::optional GetTemporaryPath() const override; bool IsScreenLocked() const override; void RegisterScreenLockedListener( @@ -51,4 +64,4 @@ class DeviceInfo : public api::DeviceInfo { } // namespace windows } // namespace nearby -#endif // THIRD_PARTY_NEARBY_FASTPAIR_INTERNAL_IMPL_WINDOWS_DEVICE_INFO_H_ +#endif // PLATFORM_IMPL_WINDOWS_DEVICE_INFO_H_ diff --git a/fastpair/internal/impl/windows/device_info_test.cc b/internal/platform/implementation/windows/device_info_test.cc similarity index 72% rename from fastpair/internal/impl/windows/device_info_test.cc rename to internal/platform/implementation/windows/device_info_test.cc index 6fd4b296..460505c6 100644 --- a/fastpair/internal/impl/windows/device_info_test.cc +++ b/internal/platform/implementation/windows/device_info_test.cc @@ -1,4 +1,4 @@ -// Copyright 2022 Google LLC +// Copyright 2021 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,25 +12,61 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "fastpair/internal/impl/windows/device_info.h" +#include "internal/platform/implementation/windows/device_info.h" #include #include #include "gtest/gtest.h" #include "absl/synchronization/notification.h" -#include "fastpair/internal/api/device_info.h" +#include "internal/platform/implementation/device_info.h" namespace nearby { namespace windows { namespace { -TEST(DeviceInfo, DISABLED_GetOsType) { +TEST(DeviceInfo, DISABLED_GetComputerName) { + EXPECT_TRUE(DeviceInfo().GetOsDeviceName().has_value()); +} + +TEST(DeviceInfo, DISABLED_GetDeviceType) { + EXPECT_EQ(DeviceInfo().GetDeviceType(), api::DeviceInfo::DeviceType::kLaptop); +} + +TEST(DeviceInfo, GetOsType) { EXPECT_EQ(DeviceInfo().GetOsType(), api::DeviceInfo::OsType::kWindows); } +TEST(DeviceInfo, DISABLED_GetFullName) { + EXPECT_TRUE(DeviceInfo().GetFullName().has_value()); +} + +TEST(DeviceInfo, DISABLED_GetGivenName) { + EXPECT_TRUE(DeviceInfo().GetGivenName().has_value()); +} + +TEST(DeviceInfo, DISABLED_GetLastName) { + EXPECT_TRUE(DeviceInfo().GetLastName().has_value()); +} + +TEST(DeviceInfo, DISABLED_GetProfileUserName) { + EXPECT_TRUE(DeviceInfo().GetProfileUserName().has_value()); +} + +TEST(DeviceInfo, DISABLED_GetAppDataPath) { + EXPECT_TRUE(DeviceInfo().GetAppDataPath().has_value()); +} + +TEST(DeviceInfo, DISABLED_GetDownloadPath) { + EXPECT_TRUE(DeviceInfo().GetDownloadPath().has_value()); +} + +TEST(DeviceInfo, DISABLED_GetTemporaryPath) { + EXPECT_TRUE(DeviceInfo().GetTemporaryPath().has_value()); +} + TEST(DeviceInfo, DISABLED_IsScreenLocked) { - EXPECT_TRUE(DeviceInfo().IsScreenLocked()); + EXPECT_FALSE(DeviceInfo().IsScreenLocked()); } TEST(DeviceInfo, DISABLED_RegisterScreenLockedListener) { diff --git a/internal/platform/implementation/windows/generated/BUILD b/internal/platform/implementation/windows/generated/BUILD index db324943..a60892a1 100644 --- a/internal/platform/implementation/windows/generated/BUILD +++ b/internal/platform/implementation/windows/generated/BUILD @@ -30,6 +30,7 @@ cc_library( "uuid.lib", "winmm.lib", "winspool.lib", + "wtsapi32.lib", "comsuppwd.lib", "setupapi.lib", "dnsapi.lib", diff --git a/internal/platform/implementation/windows/platform.cc b/internal/platform/implementation/windows/platform.cc index 4bb7c366..1c31f29e 100644 --- a/internal/platform/implementation/windows/platform.cc +++ b/internal/platform/implementation/windows/platform.cc @@ -44,6 +44,7 @@ #include "internal/platform/implementation/windows/bluetooth_adapter.h" #include "internal/platform/implementation/windows/bluetooth_classic_medium.h" #include "internal/platform/implementation/windows/condition_variable.h" +#include "internal/platform/implementation/windows/device_info.h" #include "internal/platform/implementation/windows/executor.h" #include "internal/platform/implementation/windows/file.h" #include "internal/platform/implementation/windows/file_path.h" @@ -312,5 +313,9 @@ std::unique_ptr ImplementationPlatform::CreateTimer() { return std::make_unique(); } +std::unique_ptr ImplementationPlatform::CreateDeviceInfo() { + return std::make_unique(); +} + } // namespace api } // namespace nearby