mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Cleanup DeviceInfo
PiperOrigin-RevId: 891750619
This commit is contained in:
committed by
Copybara-Service
parent
300881d3ed
commit
90028655d2
@@ -30,27 +30,11 @@
|
||||
#include "internal/platform/implementation/windows/device_paths.h"
|
||||
#include "internal/platform/implementation/windows/string_utils.h"
|
||||
#include "internal/platform/implementation/windows/utils.h"
|
||||
#include "winrt/Windows.Foundation.Collections.h"
|
||||
#include "winrt/Windows.Foundation.h"
|
||||
#include "winrt/Windows.System.h"
|
||||
|
||||
namespace nearby::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;
|
||||
|
||||
using ::nearby::windows::string_utils::WideStringToString;
|
||||
|
||||
template <typename T>
|
||||
using IVectorView = winrt::Windows::Foundation::Collections::IVectorView<T>;
|
||||
|
||||
template <typename T>
|
||||
using IAsyncOperation = winrt::Windows::Foundation::IAsyncOperation<T>;
|
||||
|
||||
std::optional<std::string> DeviceInfo::GetOsDeviceName() const {
|
||||
std::optional<std::wstring> device_name = GetDnsHostName();
|
||||
if (device_name.has_value()) {
|
||||
@@ -60,7 +44,6 @@ std::optional<std::string> DeviceInfo::GetOsDeviceName() const {
|
||||
}
|
||||
|
||||
api::DeviceInfo::DeviceType DeviceInfo::GetDeviceType() const {
|
||||
// TODO(b/230132370): return correct device type on the Windows platform.
|
||||
return api::DeviceInfo::DeviceType::kLaptop;
|
||||
}
|
||||
|
||||
@@ -68,7 +51,7 @@ api::DeviceInfo::OsType DeviceInfo::GetOsType() const {
|
||||
return api::DeviceInfo::OsType::kWindows;
|
||||
}
|
||||
|
||||
std::optional<FilePath> DeviceInfo::GetDownloadPath() const {
|
||||
FilePath DeviceInfo::GetDownloadPath() const {
|
||||
PWSTR path;
|
||||
HRESULT result =
|
||||
SHGetKnownFolderPath(FOLDERID_Downloads, KF_FLAG_DEFAULT, nullptr, &path);
|
||||
@@ -79,37 +62,19 @@ std::optional<FilePath> DeviceInfo::GetDownloadPath() const {
|
||||
}
|
||||
|
||||
CoTaskMemFree(path);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<FilePath> DeviceInfo::GetLocalAppDataPath() const {
|
||||
return nearby::platform::windows::GetLocalAppDataPath(FilePath());
|
||||
}
|
||||
|
||||
std::optional<FilePath> DeviceInfo::GetCommonAppDataPath() const {
|
||||
PWSTR path;
|
||||
HRESULT result = SHGetKnownFolderPath(FOLDERID_ProgramData, KF_FLAG_DEFAULT,
|
||||
/*hToken=*/nullptr, &path);
|
||||
if (result == S_OK) {
|
||||
std::wstring common_app_data_path{path};
|
||||
CoTaskMemFree(path);
|
||||
return FilePath(std::wstring_view(common_app_data_path));
|
||||
}
|
||||
|
||||
CoTaskMemFree(path);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<FilePath> DeviceInfo::GetTemporaryPath() const {
|
||||
return Files::GetTemporaryDirectory();
|
||||
}
|
||||
|
||||
std::optional<FilePath> DeviceInfo::GetLogPath() const {
|
||||
return nearby::platform::windows::GetLogPath();
|
||||
FilePath DeviceInfo::GetLocalAppDataPath(FilePath sub_path) const {
|
||||
return nearby::platform::windows::GetLocalAppDataPath(sub_path);
|
||||
}
|
||||
|
||||
std::optional<FilePath> DeviceInfo::GetCrashDumpPath() const {
|
||||
return nearby::platform::windows::GetCrashDumpPath();
|
||||
FilePath DeviceInfo::GetTemporaryPath() const {
|
||||
return Files::GetTemporaryDirectory();
|
||||
}
|
||||
|
||||
FilePath DeviceInfo::GetLogPath() const {
|
||||
return nearby::platform::windows::GetLogPath();
|
||||
}
|
||||
|
||||
bool DeviceInfo::IsScreenLocked() const {
|
||||
|
||||
@@ -37,12 +37,10 @@ class DeviceInfo : public api::DeviceInfo {
|
||||
api::DeviceInfo::DeviceType GetDeviceType() const override;
|
||||
api::DeviceInfo::OsType GetOsType() const override;
|
||||
|
||||
std::optional<FilePath> GetDownloadPath() const override;
|
||||
std::optional<FilePath> GetLocalAppDataPath() const override;
|
||||
std::optional<FilePath> GetCommonAppDataPath() const override;
|
||||
std::optional<FilePath> GetTemporaryPath() const override;
|
||||
std::optional<FilePath> GetLogPath() const override;
|
||||
std::optional<FilePath> GetCrashDumpPath() const override;
|
||||
FilePath GetDownloadPath() const override;
|
||||
FilePath GetLocalAppDataPath(FilePath sub_path) const override;
|
||||
FilePath GetTemporaryPath() const override;
|
||||
FilePath GetLogPath() const override;
|
||||
|
||||
bool IsScreenLocked() const override;
|
||||
void RegisterScreenLockedListener(
|
||||
|
||||
@@ -40,23 +40,20 @@ TEST(DeviceInfo, GetOsType) {
|
||||
}
|
||||
|
||||
TEST(DeviceInfo, DISABLED_GetLocalAppDataPath) {
|
||||
EXPECT_TRUE(DeviceInfo().GetLocalAppDataPath().has_value());
|
||||
EXPECT_FALSE(
|
||||
DeviceInfo().GetLocalAppDataPath(FilePath("sub_path")).IsEmpty());
|
||||
}
|
||||
|
||||
TEST(DeviceInfo, DISABLED_GetDownloadPath) {
|
||||
EXPECT_TRUE(DeviceInfo().GetDownloadPath().has_value());
|
||||
EXPECT_FALSE(DeviceInfo().GetDownloadPath().IsEmpty());
|
||||
}
|
||||
|
||||
TEST(DeviceInfo, DISABLED_GetTemporaryPath) {
|
||||
EXPECT_TRUE(DeviceInfo().GetTemporaryPath().has_value());
|
||||
EXPECT_FALSE(DeviceInfo().GetTemporaryPath().IsEmpty());
|
||||
}
|
||||
|
||||
TEST(DeviceInfo, DISABLED_GetLogPath) {
|
||||
EXPECT_TRUE(DeviceInfo().GetLogPath().has_value());
|
||||
}
|
||||
|
||||
TEST(DeviceInfo, DISABLED_GetCrashDumpPath) {
|
||||
EXPECT_TRUE(DeviceInfo().GetCrashDumpPath().has_value());
|
||||
EXPECT_FALSE(DeviceInfo().GetLogPath().IsEmpty());
|
||||
}
|
||||
|
||||
TEST(DeviceInfo, DISABLED_IsScreenLocked) {
|
||||
|
||||
@@ -44,7 +44,8 @@ TEST(PreferencesRepository, LoadWithBadPath) {
|
||||
|
||||
TEST(PreferencesRepository, RecoverFromBadPreferences) {
|
||||
std::optional<FilePath> app_data_path =
|
||||
api::ImplementationPlatform::CreateDeviceInfo()->GetLocalAppDataPath();
|
||||
api::ImplementationPlatform::CreateDeviceInfo()->GetLocalAppDataPath(
|
||||
FilePath());
|
||||
ASSERT_TRUE(app_data_path.has_value());
|
||||
FilePath full_path = app_data_path->append(FilePath(kPreferencesPath));
|
||||
FilePath full_name = app_data_path->append(FilePath(kPreferencesFileName));
|
||||
@@ -63,7 +64,8 @@ TEST(PreferencesRepository, RecoverFromBadPreferences) {
|
||||
|
||||
TEST(PreferencesRepository, SaveAndLoadPreferences) {
|
||||
std::optional<FilePath> app_data_path =
|
||||
api::ImplementationPlatform::CreateDeviceInfo()->GetLocalAppDataPath();
|
||||
api::ImplementationPlatform::CreateDeviceInfo()->GetLocalAppDataPath(
|
||||
FilePath());
|
||||
ASSERT_TRUE(app_data_path.has_value());
|
||||
FilePath full_path = app_data_path->append(FilePath(kPreferencesPath));
|
||||
FilePath full_name = app_data_path->append(FilePath(kPreferencesFileName));
|
||||
@@ -86,7 +88,8 @@ TEST(PreferencesRepository, SaveAndLoadPreferences) {
|
||||
|
||||
TEST(PreferencesRepository, LoadFromBackup) {
|
||||
std::optional<FilePath> app_data_path =
|
||||
api::ImplementationPlatform::CreateDeviceInfo()->GetLocalAppDataPath();
|
||||
api::ImplementationPlatform::CreateDeviceInfo()->GetLocalAppDataPath(
|
||||
FilePath());
|
||||
ASSERT_TRUE(app_data_path.has_value());
|
||||
FilePath full_path = app_data_path->append(FilePath(kPreferencesPath));
|
||||
FilePath full_name = app_data_path->append(FilePath(kPreferencesFileName));
|
||||
@@ -123,7 +126,8 @@ TEST(PreferencesRepository, LoadFromBackup) {
|
||||
|
||||
TEST(PreferencesRepository, RecoverFromCorruption) {
|
||||
std::optional<FilePath> app_data_path =
|
||||
api::ImplementationPlatform::CreateDeviceInfo()->GetLocalAppDataPath();
|
||||
api::ImplementationPlatform::CreateDeviceInfo()->GetLocalAppDataPath(
|
||||
FilePath());
|
||||
ASSERT_TRUE(app_data_path.has_value());
|
||||
FilePath full_path = app_data_path->append(FilePath(kPreferencesPath));
|
||||
FilePath full_name = app_data_path->append(FilePath(kPreferencesFileName));
|
||||
|
||||
Reference in New Issue
Block a user