mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
@@ -44,19 +44,32 @@ api::DeviceInfo::OsType DeviceInfoImpl::GetOsType() const {
|
||||
}
|
||||
|
||||
FilePath DeviceInfoImpl::GetDownloadPath() const {
|
||||
return device_info_impl_->GetDownloadPath();
|
||||
std::optional<FilePath> path = device_info_impl_->GetDownloadPath();
|
||||
if (path.has_value()) {
|
||||
return *path;
|
||||
}
|
||||
return Files::GetTemporaryDirectory();
|
||||
}
|
||||
|
||||
FilePath DeviceInfoImpl::GetAppDataPath() const {
|
||||
return device_info_impl_->GetLocalAppDataPath(FilePath());
|
||||
std::optional<FilePath> path = device_info_impl_->GetLocalAppDataPath();
|
||||
if (path.has_value()) {
|
||||
return *path;
|
||||
}
|
||||
return Files::GetTemporaryDirectory();
|
||||
}
|
||||
|
||||
FilePath DeviceInfoImpl::GetTemporaryPath() const {
|
||||
return device_info_impl_->GetTemporaryPath();
|
||||
std::optional<FilePath> path = device_info_impl_->GetTemporaryPath();
|
||||
if (path.has_value()) {
|
||||
return *path;
|
||||
}
|
||||
return Files::GetTemporaryDirectory();
|
||||
}
|
||||
|
||||
FilePath DeviceInfoImpl::GetLogPath() const {
|
||||
return device_info_impl_->GetLogPath();
|
||||
std::optional<FilePath> path = device_info_impl_->GetLogPath();
|
||||
return path.value_or(GetTemporaryPath());
|
||||
}
|
||||
|
||||
std::optional<size_t> DeviceInfoImpl::GetAvailableDiskSpaceInBytes(
|
||||
|
||||
@@ -49,20 +49,27 @@
|
||||
}
|
||||
|
||||
- (void)testGetDownloadPath {
|
||||
XCTAssertNotNil(@(_deviceInfo->GetDownloadPath().GetPath().c_str()));
|
||||
XCTAssertNotNil(@(_deviceInfo->GetDownloadPath().value().GetPath().c_str()));
|
||||
}
|
||||
|
||||
- (void)testGetLocalAppDataPath {
|
||||
XCTAssertNotNil(
|
||||
@(_deviceInfo->GetLocalAppDataPath(nearby::FilePath("sub_path")).GetPath().c_str()));
|
||||
XCTAssertNotNil(@(_deviceInfo->GetLocalAppDataPath().value().GetPath().c_str()));
|
||||
}
|
||||
|
||||
- (void)testGetCommonAppDataPath {
|
||||
XCTAssertNotNil(@(_deviceInfo->GetCommonAppDataPath().value().GetPath().c_str()));
|
||||
}
|
||||
|
||||
- (void)testGetTemporaryPath {
|
||||
XCTAssertNotNil(@(_deviceInfo->GetTemporaryPath().GetPath().c_str()));
|
||||
XCTAssertNotNil(@(_deviceInfo->GetTemporaryPath().value().GetPath().c_str()));
|
||||
}
|
||||
|
||||
- (void)testGetLogPath {
|
||||
XCTAssertNotNil(@(_deviceInfo->GetLogPath().GetPath().c_str()));
|
||||
XCTAssertNotNil(@(_deviceInfo->GetLogPath().value().GetPath().c_str()));
|
||||
}
|
||||
|
||||
- (void)testGetCrashDumpPath {
|
||||
XCTAssertNotNil(@(_deviceInfo->GetCrashDumpPath().value().GetPath().c_str()));
|
||||
}
|
||||
|
||||
- (void)testIsScreenLocked {
|
||||
|
||||
@@ -34,13 +34,17 @@ class DeviceInfo : public api::DeviceInfo {
|
||||
|
||||
api::DeviceInfo::OsType GetOsType() const override;
|
||||
|
||||
FilePath GetDownloadPath() const override;
|
||||
std::optional<FilePath> GetDownloadPath() const override;
|
||||
|
||||
FilePath GetLocalAppDataPath(FilePath sub_path) const override;
|
||||
std::optional<FilePath> GetLocalAppDataPath() const override;
|
||||
|
||||
FilePath GetTemporaryPath() const override;
|
||||
std::optional<FilePath> GetCommonAppDataPath() const override;
|
||||
|
||||
FilePath GetLogPath() const override;
|
||||
std::optional<FilePath> GetTemporaryPath() const override;
|
||||
|
||||
std::optional<FilePath> GetLogPath() const override;
|
||||
|
||||
std::optional<FilePath> GetCrashDumpPath() const override;
|
||||
|
||||
bool IsScreenLocked() const override;
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ api::DeviceInfo::OsType DeviceInfo::GetOsType() const {
|
||||
#endif
|
||||
}
|
||||
|
||||
FilePath DeviceInfo::GetDownloadPath() const {
|
||||
std::optional<FilePath> DeviceInfo::GetDownloadPath() const {
|
||||
NSFileManager *manager = [NSFileManager defaultManager];
|
||||
|
||||
NSError *error = nil;
|
||||
@@ -90,24 +90,30 @@ FilePath DeviceInfo::GetDownloadPath() const {
|
||||
error:&error];
|
||||
if (!downloadsURL) {
|
||||
GNCLoggerError(@"Failed to get download path: %@", error);
|
||||
return GetTemporaryPath();
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return FilePath(absl::string_view([downloadsURL.path cString]));
|
||||
}
|
||||
|
||||
FilePath DeviceInfo::GetLocalAppDataPath(FilePath sub_path) const {
|
||||
return FilePath(absl::string_view([GNCLocalAppDataPath().path cString])).append(sub_path);
|
||||
std::optional<FilePath> DeviceInfo::GetLocalAppDataPath() const {
|
||||
return FilePath(absl::string_view([GNCLocalAppDataPath().path cString]));
|
||||
}
|
||||
|
||||
FilePath DeviceInfo::GetTemporaryPath() const {
|
||||
std::optional<FilePath> DeviceInfo::GetCommonAppDataPath() const { return GetLocalAppDataPath(); }
|
||||
|
||||
std::optional<FilePath> DeviceInfo::GetTemporaryPath() const {
|
||||
return FilePath(absl::string_view([NSTemporaryDirectory() cString]));
|
||||
}
|
||||
|
||||
FilePath DeviceInfo::GetLogPath() const {
|
||||
std::optional<FilePath> DeviceInfo::GetLogPath() const {
|
||||
return FilePath(absl::string_view([GNCLogPath().path cString]));
|
||||
}
|
||||
|
||||
std::optional<FilePath> DeviceInfo::GetCrashDumpPath() const {
|
||||
return FilePath(absl::string_view([GNCCrashDumpPath().path cString]));
|
||||
}
|
||||
|
||||
bool DeviceInfo::IsScreenLocked() const { return false; }
|
||||
|
||||
void DeviceInfo::RegisterScreenLockedListener(
|
||||
|
||||
@@ -46,10 +46,12 @@ class DeviceInfo {
|
||||
virtual OsType GetOsType() const = 0;
|
||||
|
||||
// Gets known paths of current user.
|
||||
virtual FilePath GetDownloadPath() const = 0;
|
||||
virtual FilePath GetLocalAppDataPath(FilePath sub_path) const = 0;
|
||||
virtual FilePath GetTemporaryPath() const = 0;
|
||||
virtual FilePath GetLogPath() const = 0;
|
||||
virtual std::optional<FilePath> GetDownloadPath() const = 0;
|
||||
virtual std::optional<FilePath> GetLocalAppDataPath() const = 0;
|
||||
virtual std::optional<FilePath> GetCommonAppDataPath() const = 0;
|
||||
virtual std::optional<FilePath> GetTemporaryPath() const = 0;
|
||||
virtual std::optional<FilePath> GetLogPath() const = 0;
|
||||
virtual std::optional<FilePath> GetCrashDumpPath() const = 0;
|
||||
|
||||
// Monitor screen status
|
||||
virtual bool IsScreenLocked() const = 0;
|
||||
|
||||
@@ -45,24 +45,33 @@ class DeviceInfo : public api::DeviceInfo {
|
||||
return api::DeviceInfo::OsType::kChromeOs;
|
||||
}
|
||||
|
||||
FilePath GetDownloadPath() const override {
|
||||
std::optional<FilePath> GetDownloadPath() const override {
|
||||
return Files::GetTemporaryDirectory();
|
||||
}
|
||||
|
||||
FilePath GetLocalAppDataPath(FilePath sub_path) const override {
|
||||
std::optional<FilePath> GetLocalAppDataPath() const override {
|
||||
if (MediumEnvironment::Instance()
|
||||
.GetEnvironmentConfig()
|
||||
.use_temporary_directory_for_app_path) {
|
||||
return Files::GetTemporaryDirectory().append(sub_path);
|
||||
return Files::GetTemporaryDirectory();
|
||||
}
|
||||
return GetAppDataPath().append(sub_path);
|
||||
|
||||
return GetAppDataPath();
|
||||
}
|
||||
|
||||
FilePath GetTemporaryPath() const override {
|
||||
std::optional<FilePath> GetCommonAppDataPath() const override {
|
||||
return Files::GetTemporaryDirectory();
|
||||
}
|
||||
|
||||
FilePath GetLogPath() const override {
|
||||
std::optional<FilePath> GetTemporaryPath() const override {
|
||||
return Files::GetTemporaryDirectory();
|
||||
}
|
||||
|
||||
std::optional<FilePath> GetLogPath() const override {
|
||||
return Files::GetTemporaryDirectory();
|
||||
}
|
||||
|
||||
std::optional<FilePath> GetCrashDumpPath() const override {
|
||||
return Files::GetTemporaryDirectory();
|
||||
}
|
||||
|
||||
|
||||
@@ -30,11 +30,27 @@
|
||||
#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()) {
|
||||
@@ -44,6 +60,7 @@ 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;
|
||||
}
|
||||
|
||||
@@ -51,7 +68,7 @@ api::DeviceInfo::OsType DeviceInfo::GetOsType() const {
|
||||
return api::DeviceInfo::OsType::kWindows;
|
||||
}
|
||||
|
||||
FilePath DeviceInfo::GetDownloadPath() const {
|
||||
std::optional<FilePath> DeviceInfo::GetDownloadPath() const {
|
||||
PWSTR path;
|
||||
HRESULT result =
|
||||
SHGetKnownFolderPath(FOLDERID_Downloads, KF_FLAG_DEFAULT, nullptr, &path);
|
||||
@@ -62,21 +79,39 @@ 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();
|
||||
}
|
||||
|
||||
FilePath DeviceInfo::GetLocalAppDataPath(FilePath sub_path) const {
|
||||
return nearby::platform::windows::GetLocalAppDataPath(sub_path);
|
||||
}
|
||||
|
||||
FilePath DeviceInfo::GetTemporaryPath() const {
|
||||
return Files::GetTemporaryDirectory();
|
||||
}
|
||||
|
||||
FilePath DeviceInfo::GetLogPath() const {
|
||||
std::optional<FilePath> DeviceInfo::GetLogPath() const {
|
||||
return nearby::platform::windows::GetLogPath();
|
||||
}
|
||||
|
||||
std::optional<FilePath> DeviceInfo::GetCrashDumpPath() const {
|
||||
return nearby::platform::windows::GetCrashDumpPath();
|
||||
}
|
||||
|
||||
bool DeviceInfo::IsScreenLocked() const {
|
||||
absl::MutexLock lock(mutex_);
|
||||
return session_manager_.IsScreenLocked();
|
||||
|
||||
@@ -37,10 +37,12 @@ class DeviceInfo : public api::DeviceInfo {
|
||||
api::DeviceInfo::DeviceType GetDeviceType() const override;
|
||||
api::DeviceInfo::OsType GetOsType() const override;
|
||||
|
||||
FilePath GetDownloadPath() const override;
|
||||
FilePath GetLocalAppDataPath(FilePath sub_path) const override;
|
||||
FilePath GetTemporaryPath() const override;
|
||||
FilePath GetLogPath() 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;
|
||||
|
||||
bool IsScreenLocked() const override;
|
||||
void RegisterScreenLockedListener(
|
||||
|
||||
@@ -40,20 +40,23 @@ TEST(DeviceInfo, GetOsType) {
|
||||
}
|
||||
|
||||
TEST(DeviceInfo, DISABLED_GetLocalAppDataPath) {
|
||||
EXPECT_FALSE(
|
||||
DeviceInfo().GetLocalAppDataPath(FilePath("sub_path")).IsEmpty());
|
||||
EXPECT_TRUE(DeviceInfo().GetLocalAppDataPath().has_value());
|
||||
}
|
||||
|
||||
TEST(DeviceInfo, DISABLED_GetDownloadPath) {
|
||||
EXPECT_FALSE(DeviceInfo().GetDownloadPath().IsEmpty());
|
||||
EXPECT_TRUE(DeviceInfo().GetDownloadPath().has_value());
|
||||
}
|
||||
|
||||
TEST(DeviceInfo, DISABLED_GetTemporaryPath) {
|
||||
EXPECT_FALSE(DeviceInfo().GetTemporaryPath().IsEmpty());
|
||||
EXPECT_TRUE(DeviceInfo().GetTemporaryPath().has_value());
|
||||
}
|
||||
|
||||
TEST(DeviceInfo, DISABLED_GetLogPath) {
|
||||
EXPECT_FALSE(DeviceInfo().GetLogPath().IsEmpty());
|
||||
EXPECT_TRUE(DeviceInfo().GetLogPath().has_value());
|
||||
}
|
||||
|
||||
TEST(DeviceInfo, DISABLED_GetCrashDumpPath) {
|
||||
EXPECT_TRUE(DeviceInfo().GetCrashDumpPath().has_value());
|
||||
}
|
||||
|
||||
TEST(DeviceInfo, DISABLED_IsScreenLocked) {
|
||||
|
||||
@@ -44,8 +44,7 @@ TEST(PreferencesRepository, LoadWithBadPath) {
|
||||
|
||||
TEST(PreferencesRepository, RecoverFromBadPreferences) {
|
||||
std::optional<FilePath> app_data_path =
|
||||
api::ImplementationPlatform::CreateDeviceInfo()->GetLocalAppDataPath(
|
||||
FilePath());
|
||||
api::ImplementationPlatform::CreateDeviceInfo()->GetLocalAppDataPath();
|
||||
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));
|
||||
@@ -64,8 +63,7 @@ TEST(PreferencesRepository, RecoverFromBadPreferences) {
|
||||
|
||||
TEST(PreferencesRepository, SaveAndLoadPreferences) {
|
||||
std::optional<FilePath> app_data_path =
|
||||
api::ImplementationPlatform::CreateDeviceInfo()->GetLocalAppDataPath(
|
||||
FilePath());
|
||||
api::ImplementationPlatform::CreateDeviceInfo()->GetLocalAppDataPath();
|
||||
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));
|
||||
@@ -88,8 +86,7 @@ TEST(PreferencesRepository, SaveAndLoadPreferences) {
|
||||
|
||||
TEST(PreferencesRepository, LoadFromBackup) {
|
||||
std::optional<FilePath> app_data_path =
|
||||
api::ImplementationPlatform::CreateDeviceInfo()->GetLocalAppDataPath(
|
||||
FilePath());
|
||||
api::ImplementationPlatform::CreateDeviceInfo()->GetLocalAppDataPath();
|
||||
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));
|
||||
@@ -126,8 +123,7 @@ TEST(PreferencesRepository, LoadFromBackup) {
|
||||
|
||||
TEST(PreferencesRepository, RecoverFromCorruption) {
|
||||
std::optional<FilePath> app_data_path =
|
||||
api::ImplementationPlatform::CreateDeviceInfo()->GetLocalAppDataPath(
|
||||
FilePath());
|
||||
api::ImplementationPlatform::CreateDeviceInfo()->GetLocalAppDataPath();
|
||||
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