mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Migrate device_info from location/nearby to third_party/nearby
PiperOrigin-RevId: 504935151
This commit is contained in:
committed by
Copybara-Service
parent
54fec27c00
commit
a0692e6306
@@ -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__",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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 <filesystem> // NOLINT(build/c++17)
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#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<std::u16string> GetOsDeviceName() const override;
|
||||
|
||||
api::DeviceInfo::DeviceType GetDeviceType() const override;
|
||||
|
||||
api::DeviceInfo::OsType GetOsType() const override;
|
||||
|
||||
std::optional<std::u16string> GetFullName() const override;
|
||||
std::optional<std::u16string> GetGivenName() const override;
|
||||
std::optional<std::u16string> GetLastName() const override;
|
||||
std::optional<std::string> GetProfileUserName() const override;
|
||||
|
||||
std::optional<std::filesystem::path> GetDownloadPath() const override;
|
||||
|
||||
std::optional<std::filesystem::path> GetAppDataPath() const override;
|
||||
|
||||
std::optional<std::filesystem::path> GetTemporaryPath() const override;
|
||||
|
||||
bool IsScreenLocked() const override;
|
||||
|
||||
void RegisterScreenLockedListener(
|
||||
absl::string_view listener_name,
|
||||
std::function<void(api::DeviceInfo::ScreenStatus)> callback) override;
|
||||
|
||||
void UnregisterScreenLockedListener(absl::string_view listener_name) override;
|
||||
};
|
||||
|
||||
} // namespace apple
|
||||
} // namespace nearby
|
||||
|
||||
#endif // PLATFORM_IMPL_APPLE_DEVICE_INFO_H_
|
||||
@@ -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 <filesystem> // NOLINT(build/c++17)
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/platform/implementation/device_info.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace apple {
|
||||
|
||||
std::optional<std::u16string> 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<std::u16string> DeviceInfo::GetFullName() const { return u"Full Name"; }
|
||||
std::optional<std::u16string> DeviceInfo::GetGivenName() const { return u"Given Name"; }
|
||||
std::optional<std::u16string> DeviceInfo::GetLastName() const { return u"Last Name"; }
|
||||
std::optional<std::string> DeviceInfo::GetProfileUserName() const { return "Username"; }
|
||||
|
||||
std::optional<std::filesystem::path> DeviceInfo::GetDownloadPath() const {
|
||||
return std::filesystem::temp_directory_path();
|
||||
}
|
||||
|
||||
std::optional<std::filesystem::path> DeviceInfo::GetAppDataPath() const {
|
||||
return std::filesystem::temp_directory_path();
|
||||
}
|
||||
|
||||
std::optional<std::filesystem::path> 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<void(api::DeviceInfo::ScreenStatus)> callback) {}
|
||||
|
||||
void DeviceInfo::UnregisterScreenLockedListener(absl::string_view listener_name) {}
|
||||
|
||||
} // namespace apple
|
||||
} // namespace nearby
|
||||
@@ -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<Timer> ImplementationPlatform::CreateTimer() {
|
||||
return std::make_unique<apple::Timer>();
|
||||
}
|
||||
|
||||
// TODO(b/261511530): Add implementation.
|
||||
std::unique_ptr<nearby::api::DeviceInfo> ImplementationPlatform::CreateDeviceInfo() {
|
||||
return std::make_unique<apple::DeviceInfo>();
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
} // namespace nearby
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
// 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_API_DEVICE_INFO_H_
|
||||
#define PLATFORM_API_DEVICE_INFO_H_
|
||||
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace api {
|
||||
|
||||
class DeviceInfo {
|
||||
public:
|
||||
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<std::u16string> GetOsDeviceName() const = 0;
|
||||
virtual DeviceType GetDeviceType() const = 0;
|
||||
virtual OsType GetOsType() const = 0;
|
||||
|
||||
// Gets basic information of current user.
|
||||
virtual std::optional<std::u16string> GetFullName() const = 0;
|
||||
virtual std::optional<std::u16string> GetGivenName() const = 0;
|
||||
virtual std::optional<std::u16string> GetLastName() const = 0;
|
||||
virtual std::optional<std::string> GetProfileUserName() const = 0;
|
||||
|
||||
// Gets known paths of current user.
|
||||
virtual std::optional<std::filesystem::path> GetDownloadPath() const = 0;
|
||||
virtual std::optional<std::filesystem::path> GetAppDataPath() const = 0;
|
||||
virtual std::optional<std::filesystem::path> GetTemporaryPath() const = 0;
|
||||
|
||||
// Monitor screen status
|
||||
virtual bool IsScreenLocked() const = 0;
|
||||
virtual void RegisterScreenLockedListener(
|
||||
absl::string_view listener_name,
|
||||
std::function<void(ScreenStatus)> callback) = 0;
|
||||
virtual void UnregisterScreenLockedListener(
|
||||
absl::string_view listener_name) = 0;
|
||||
};
|
||||
|
||||
} // namespace api
|
||||
} // namespace nearby
|
||||
|
||||
#endif // PLATFORM_API_DEVICE_INFO_H_
|
||||
@@ -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",
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
// 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_G3_DEVICE_INFO_H_
|
||||
#define PLATFORM_IMPL_G3_DEVICE_INFO_H_
|
||||
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/platform/implementation/device_info.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace g3 {
|
||||
|
||||
class DeviceInfo : public api::DeviceInfo {
|
||||
public:
|
||||
std::optional<std::u16string> 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<std::u16string> GetFullName() const override {
|
||||
return u"nearby";
|
||||
}
|
||||
std::optional<std::u16string> GetGivenName() const override {
|
||||
return u"nearby";
|
||||
}
|
||||
std::optional<std::u16string> GetLastName() const override {
|
||||
return u"nearby";
|
||||
}
|
||||
std::optional<std::string> GetProfileUserName() const override {
|
||||
return "nearby";
|
||||
}
|
||||
|
||||
std::optional<std::filesystem::path> GetDownloadPath() const override {
|
||||
return std::filesystem::temp_directory_path();
|
||||
}
|
||||
|
||||
std::optional<std::filesystem::path> GetAppDataPath() const override {
|
||||
return std::filesystem::temp_directory_path();
|
||||
}
|
||||
|
||||
std::optional<std::filesystem::path> GetTemporaryPath() const override {
|
||||
return std::filesystem::temp_directory_path();
|
||||
}
|
||||
|
||||
bool IsScreenLocked() const override { return false; }
|
||||
|
||||
void RegisterScreenLockedListener(
|
||||
absl::string_view listener_name,
|
||||
std::function<void(api::DeviceInfo::ScreenStatus)> callback) override {
|
||||
screen_locked_listeners_.emplace(listener_name, std::move(callback));
|
||||
}
|
||||
|
||||
void UnregisterScreenLockedListener(
|
||||
absl::string_view listener_name) override {
|
||||
screen_locked_listeners_.erase(listener_name);
|
||||
}
|
||||
|
||||
private:
|
||||
absl::flat_hash_map<std::string,
|
||||
std::function<void(api::DeviceInfo::ScreenStatus)>>
|
||||
screen_locked_listeners_;
|
||||
};
|
||||
|
||||
} // namespace g3
|
||||
} // namespace nearby
|
||||
|
||||
#endif // PLATFORM_IMPL_G3_DEVICE_INFO_H_
|
||||
@@ -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<Timer> ImplementationPlatform::CreateTimer() {
|
||||
return std::make_unique<g3::Timer>();
|
||||
}
|
||||
|
||||
std::unique_ptr<nearby::api::DeviceInfo>
|
||||
ImplementationPlatform::CreateDeviceInfo() {
|
||||
return std::make_unique<g3::DeviceInfo>();
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
} // namespace nearby
|
||||
|
||||
@@ -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<WifiHotspotMedium> CreateWifiHotspotMedium();
|
||||
static std::unique_ptr<WifiDirectMedium> CreateWifiDirectMedium();
|
||||
static std::unique_ptr<Timer> CreateTimer();
|
||||
static std::unique_ptr<DeviceInfo> CreateDeviceInfo();
|
||||
#ifndef NO_WEBRTC
|
||||
static std::unique_ptr<WebRtcMedium> CreateWebRtcMedium();
|
||||
#endif
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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 <shlobj_core.h>
|
||||
#include <windows.h>
|
||||
#include <wtsapi32.h>
|
||||
|
||||
#include <array>
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#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 <typename T>
|
||||
using IVectorView = winrt::Windows::Foundation::Collections::IVectorView<T>;
|
||||
|
||||
template <typename T>
|
||||
using IAsyncOperation = winrt::Windows::Foundation::IAsyncOperation<T>;
|
||||
|
||||
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<DeviceInfo*>(
|
||||
GetWindowLongPtr(window_handle, GWLP_USERDATA));
|
||||
CREATESTRUCT* create_struct = reinterpret_cast<CREATESTRUCT*>(lparam);
|
||||
LONG_PTR result = 0L;
|
||||
switch (message) {
|
||||
case WM_CREATE:
|
||||
self = reinterpret_cast<DeviceInfo*>(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<LONG_PTR>(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<std::u16string> 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<std::u16string> 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<User> 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<IInspectable> 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<winrt::hstring>();
|
||||
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<std::u16string> 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<User> 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<IInspectable> 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<winrt::hstring>();
|
||||
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<std::u16string> 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<User> 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<IInspectable> 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<winrt::hstring>();
|
||||
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<std::string> 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<User> 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<IInspectable> 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<winrt::hstring>();
|
||||
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<std::filesystem::path> 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<std::filesystem::path> 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<std::filesystem::path> 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<void(api::DeviceInfo::ScreenStatus)> 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
|
||||
@@ -0,0 +1,67 @@
|
||||
// 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_IMPL_WINDOWS_DEVICE_INFO_H_
|
||||
#define PLATFORM_IMPL_WINDOWS_DEVICE_INFO_H_
|
||||
|
||||
#include <guiddef.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <array>
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/platform/implementation/device_info.h"
|
||||
#include "winrt/Windows.Foundation.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace windows {
|
||||
|
||||
class DeviceInfo : public api::DeviceInfo {
|
||||
public:
|
||||
~DeviceInfo() override;
|
||||
|
||||
std::optional<std::u16string> GetOsDeviceName() const override;
|
||||
api::DeviceInfo::DeviceType GetDeviceType() const override;
|
||||
api::DeviceInfo::OsType GetOsType() const override;
|
||||
std::optional<std::u16string> GetFullName() const override;
|
||||
std::optional<std::u16string> GetGivenName() const override;
|
||||
std::optional<std::u16string> GetLastName() const override;
|
||||
std::optional<std::string> GetProfileUserName() const override;
|
||||
|
||||
std::optional<std::filesystem::path> GetDownloadPath() const override;
|
||||
std::optional<std::filesystem::path> GetAppDataPath() const override;
|
||||
std::optional<std::filesystem::path> GetTemporaryPath() const override;
|
||||
|
||||
bool IsScreenLocked() const override;
|
||||
void RegisterScreenLockedListener(
|
||||
absl::string_view listener_name,
|
||||
std::function<void(api::DeviceInfo::ScreenStatus)> callback) override;
|
||||
void UnregisterScreenLockedListener(absl::string_view listener_name) override;
|
||||
absl::flat_hash_map<std::string,
|
||||
std::function<void(api::DeviceInfo::ScreenStatus)>>
|
||||
screen_locked_listeners_;
|
||||
|
||||
HINSTANCE instance_ = nullptr;
|
||||
ATOM registered_class_ = NULL;
|
||||
HWND message_window_handle_ = nullptr;
|
||||
};
|
||||
|
||||
} // namespace windows
|
||||
} // namespace nearby
|
||||
|
||||
#endif // PLATFORM_IMPL_WINDOWS_DEVICE_INFO_H_
|
||||
@@ -0,0 +1,129 @@
|
||||
// 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 <functional>
|
||||
#include <string>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "absl/synchronization/notification.h"
|
||||
#include "internal/platform/implementation/device_info.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace windows {
|
||||
namespace {
|
||||
|
||||
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_FALSE(DeviceInfo().IsScreenLocked());
|
||||
}
|
||||
|
||||
TEST(DeviceInfo, DISABLED_RegisterScreenLockedListener) {
|
||||
std::function<void(api::DeviceInfo::ScreenStatus)> listener_1 =
|
||||
[](api::DeviceInfo::ScreenStatus) {};
|
||||
std::function<void(api::DeviceInfo::ScreenStatus)> 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, DISABLED_UnregisterScreenLockedListener) {
|
||||
std::function<void(api::DeviceInfo::ScreenStatus)> listener_1 =
|
||||
[](api::DeviceInfo::ScreenStatus) {};
|
||||
std::function<void(api::DeviceInfo::ScreenStatus)> 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);
|
||||
}
|
||||
|
||||
TEST(DeviceInfo, DISABLED_UpdateScreenLockedListener) {
|
||||
absl::Notification notification;
|
||||
|
||||
api::DeviceInfo::ScreenStatus screen_locked_tracker =
|
||||
api::DeviceInfo::ScreenStatus::kUndetermined;
|
||||
|
||||
std::function<void(api::DeviceInfo::ScreenStatus)> listener =
|
||||
[&screen_locked_tracker,
|
||||
¬ification](api::DeviceInfo::ScreenStatus status) {
|
||||
screen_locked_tracker = api::DeviceInfo::ScreenStatus::kLocked;
|
||||
notification.Notify();
|
||||
};
|
||||
|
||||
DeviceInfo device_info;
|
||||
device_info.RegisterScreenLockedListener("listener", listener);
|
||||
EXPECT_TRUE(notification.WaitForNotificationWithTimeout(absl::Seconds(5)));
|
||||
EXPECT_EQ(screen_locked_tracker, api::DeviceInfo::ScreenStatus::kLocked);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace windows
|
||||
} // namespace nearby
|
||||
@@ -30,6 +30,7 @@ cc_library(
|
||||
"uuid.lib",
|
||||
"winmm.lib",
|
||||
"winspool.lib",
|
||||
"wtsapi32.lib",
|
||||
"comsuppwd.lib",
|
||||
"setupapi.lib",
|
||||
"dnsapi.lib",
|
||||
|
||||
@@ -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<Timer> ImplementationPlatform::CreateTimer() {
|
||||
return std::make_unique<windows::Timer>();
|
||||
}
|
||||
|
||||
std::unique_ptr<DeviceInfo> ImplementationPlatform::CreateDeviceInfo() {
|
||||
return std::make_unique<windows::DeviceInfo>();
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
} // namespace nearby
|
||||
|
||||
Reference in New Issue
Block a user