From 3cbbecd53a1c28386f1d3592375e62bd5d030cfd Mon Sep 17 00:00:00 2001 From: hai007 Date: Mon, 30 Jan 2023 09:12:09 -0800 Subject: [PATCH] Change log and crash dump locations from a per user data location to a per machine common data location. PiperOrigin-RevId: 505711827 --- .../platform/implementation/apple/device_info.h | 2 ++ .../platform/implementation/apple/device_info.mm | 4 ++++ internal/platform/implementation/device_info.h | 1 + internal/platform/implementation/g3/device_info.h | 4 ++++ .../implementation/windows/device_info.cc | 15 +++++++++++++++ .../platform/implementation/windows/device_info.h | 1 + 6 files changed, 27 insertions(+) diff --git a/internal/platform/implementation/apple/device_info.h b/internal/platform/implementation/apple/device_info.h index 85ff0594..83e80c8f 100644 --- a/internal/platform/implementation/apple/device_info.h +++ b/internal/platform/implementation/apple/device_info.h @@ -45,6 +45,8 @@ class DeviceInfo : public api::DeviceInfo { std::optional GetTemporaryPath() const override; + std::optional GetLogPath() const override; + bool IsScreenLocked() const override; void RegisterScreenLockedListener( diff --git a/internal/platform/implementation/apple/device_info.mm b/internal/platform/implementation/apple/device_info.mm index 79d4f5fd..e8b6f5c5 100644 --- a/internal/platform/implementation/apple/device_info.mm +++ b/internal/platform/implementation/apple/device_info.mm @@ -51,6 +51,10 @@ std::optional DeviceInfo::GetTemporaryPath() const { return std::filesystem::temp_directory_path(); } +std::optional DeviceInfo::GetLogPath() const { + return std::filesystem::temp_directory_path(); +} + bool DeviceInfo::IsScreenLocked() const { return false; } void DeviceInfo::RegisterScreenLockedListener( diff --git a/internal/platform/implementation/device_info.h b/internal/platform/implementation/device_info.h index 2b9cd05a..bdc2dd62 100644 --- a/internal/platform/implementation/device_info.h +++ b/internal/platform/implementation/device_info.h @@ -48,6 +48,7 @@ class DeviceInfo { virtual std::optional GetDownloadPath() const = 0; virtual std::optional GetAppDataPath() const = 0; virtual std::optional GetTemporaryPath() const = 0; + virtual std::optional GetLogPath() const = 0; // Monitor screen status virtual bool IsScreenLocked() const = 0; diff --git a/internal/platform/implementation/g3/device_info.h b/internal/platform/implementation/g3/device_info.h index fe43530b..ab92fbdd 100644 --- a/internal/platform/implementation/g3/device_info.h +++ b/internal/platform/implementation/g3/device_info.h @@ -67,6 +67,10 @@ class DeviceInfo : public api::DeviceInfo { return std::filesystem::temp_directory_path(); } + std::optional GetLogPath() const override { + return std::filesystem::temp_directory_path(); + } + bool IsScreenLocked() const override { return false; } void RegisterScreenLockedListener( diff --git a/internal/platform/implementation/windows/device_info.cc b/internal/platform/implementation/windows/device_info.cc index 7286aa19..058d2735 100644 --- a/internal/platform/implementation/windows/device_info.cc +++ b/internal/platform/implementation/windows/device_info.cc @@ -51,6 +51,7 @@ using IAsyncOperation = winrt::Windows::Foundation::IAsyncOperation; constexpr char window_class_name[] = "NearbySharingDLL_MessageWindowClass"; constexpr char window_name[] = "NearbySharingDLL_MessageWindow"; +constexpr char kLogsRelativePath[] = "Google\\Nearby\\Sharing\\Logs"; namespace { // This WindowProc method must be static for the successful initialization of @@ -368,6 +369,20 @@ std::optional DeviceInfo::GetTemporaryPath() const { return std::filesystem::temp_directory_path(); } +std::optional DeviceInfo::GetLogPath() const { + PWSTR path; + HRESULT result = + SHGetKnownFolderPath(FOLDERID_ProgramData, KF_FLAG_DEFAULT, + /*hToken*/nullptr, &path); + if (result == S_OK) { + std::filesystem::path prefixPath = path; + CoTaskMemFree(path); + return std::filesystem::path(prefixPath / kLogsRelativePath); + } + CoTaskMemFree(path); + return std::nullopt; +} + bool DeviceInfo::IsScreenLocked() const { DWORD session_id = WTSGetActiveConsoleSessionId(); WTS_INFO_CLASS wts_info_class = WTSSessionInfoEx; diff --git a/internal/platform/implementation/windows/device_info.h b/internal/platform/implementation/windows/device_info.h index 1543ede9..b38c60f4 100644 --- a/internal/platform/implementation/windows/device_info.h +++ b/internal/platform/implementation/windows/device_info.h @@ -46,6 +46,7 @@ class DeviceInfo : public api::DeviceInfo { std::optional GetDownloadPath() const override; std::optional GetAppDataPath() const override; std::optional GetTemporaryPath() const override; + std::optional GetLogPath() const override; bool IsScreenLocked() const override; void RegisterScreenLockedListener(