From 3d9ce368ffa52acc0bd5a4afe0789a896e225b62 Mon Sep 17 00:00:00 2001 From: Eiden Kim Date: Wed, 1 Feb 2023 23:13:33 -0800 Subject: [PATCH] Fixed crashpad db creation failure and changed root to CommonAppData. Changed captured Nearby Share Info to save to CommonAppData. Changed Clearcut root to CommonAppData. PiperOrigin-RevId: 506528040 --- internal/platform/device_info_impl.cc | 2 +- .../implementation/apple/device_info.h | 6 +++- .../implementation/apple/device_info.mm | 10 +++++- .../platform/implementation/device_info.h | 4 ++- .../platform/implementation/g3/device_info.h | 10 +++++- .../implementation/windows/device_info.cc | 36 ++++++++++++++++--- .../implementation/windows/device_info.h | 4 ++- .../windows/device_info_test.cc | 4 +-- 8 files changed, 64 insertions(+), 12 deletions(-) diff --git a/internal/platform/device_info_impl.cc b/internal/platform/device_info_impl.cc index db593566..702c83a0 100644 --- a/internal/platform/device_info_impl.cc +++ b/internal/platform/device_info_impl.cc @@ -66,7 +66,7 @@ std::filesystem::path DeviceInfoImpl::GetDownloadPath() const { std::filesystem::path DeviceInfoImpl::GetAppDataPath() const { std::optional path = - device_info_impl_->GetAppDataPath(); + device_info_impl_->GetLocalAppDataPath(); if (path.has_value()) { return *path; } diff --git a/internal/platform/implementation/apple/device_info.h b/internal/platform/implementation/apple/device_info.h index 83e80c8f..953f54c4 100644 --- a/internal/platform/implementation/apple/device_info.h +++ b/internal/platform/implementation/apple/device_info.h @@ -41,12 +41,16 @@ class DeviceInfo : public api::DeviceInfo { std::optional GetDownloadPath() const override; - std::optional GetAppDataPath() const override; + std::optional GetLocalAppDataPath() const override; + + std::optional GetCommonAppDataPath() const override; std::optional GetTemporaryPath() const override; std::optional GetLogPath() const override; + std::optional GetCrashDumpPath() 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 e8b6f5c5..98e7d472 100644 --- a/internal/platform/implementation/apple/device_info.mm +++ b/internal/platform/implementation/apple/device_info.mm @@ -43,7 +43,11 @@ std::optional DeviceInfo::GetDownloadPath() const { return std::filesystem::temp_directory_path(); } -std::optional DeviceInfo::GetAppDataPath() const { +std::optional DeviceInfo::GetLocalAppDataPath() const { + return std::filesystem::temp_directory_path(); +} + +std::optional DeviceInfo::GetCommonAppDataPath() const { return std::filesystem::temp_directory_path(); } @@ -55,6 +59,10 @@ std::optional DeviceInfo::GetLogPath() const { return std::filesystem::temp_directory_path(); } +std::optional DeviceInfo::GetCrashDumpPath() 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 bdc2dd62..7247fa85 100644 --- a/internal/platform/implementation/device_info.h +++ b/internal/platform/implementation/device_info.h @@ -46,9 +46,11 @@ class DeviceInfo { // Gets known paths of current user. virtual std::optional GetDownloadPath() const = 0; - virtual std::optional GetAppDataPath() const = 0; + virtual std::optional GetLocalAppDataPath() const = 0; + virtual std::optional GetCommonAppDataPath() const = 0; virtual std::optional GetTemporaryPath() const = 0; virtual std::optional GetLogPath() const = 0; + virtual std::optional GetCrashDumpPath() 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 ab92fbdd..e9a90ff3 100644 --- a/internal/platform/implementation/g3/device_info.h +++ b/internal/platform/implementation/g3/device_info.h @@ -59,7 +59,11 @@ class DeviceInfo : public api::DeviceInfo { return std::filesystem::temp_directory_path(); } - std::optional GetAppDataPath() const override { + std::optional GetLocalAppDataPath() const override { + return std::filesystem::temp_directory_path(); + } + + std::optional GetCommonAppDataPath() const override { return std::filesystem::temp_directory_path(); } @@ -71,6 +75,10 @@ class DeviceInfo : public api::DeviceInfo { return std::filesystem::temp_directory_path(); } + std::optional GetCrashDumpPath() 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 058d2735..e0232355 100644 --- a/internal/platform/implementation/windows/device_info.cc +++ b/internal/platform/implementation/windows/device_info.cc @@ -52,6 +52,8 @@ 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"; +constexpr char kCrashDumpsRelativePath[] = + "Google\\Nearby\\Sharing\\CrashDumps"; namespace { // This WindowProc method must be static for the successful initialization of @@ -352,7 +354,7 @@ std::optional DeviceInfo::GetDownloadPath() const { return std::nullopt; } -std::optional DeviceInfo::GetAppDataPath() const { +std::optional DeviceInfo::GetLocalAppDataPath() const { std::string path; path.resize(MAX_PATH); HRESULT result = SHGetFolderPathA(nullptr, CSIDL_LOCAL_APPDATA, nullptr, @@ -365,15 +367,28 @@ std::optional DeviceInfo::GetAppDataPath() const { return std::nullopt; } +std::optional DeviceInfo::GetCommonAppDataPath() const { + PWSTR path; + HRESULT result = SHGetKnownFolderPath(FOLDERID_ProgramData, KF_FLAG_DEFAULT, + /*hToken=*/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::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); + HRESULT result = SHGetKnownFolderPath(FOLDERID_ProgramData, KF_FLAG_DEFAULT, + /*hToken=*/nullptr, &path); if (result == S_OK) { std::filesystem::path prefixPath = path; CoTaskMemFree(path); @@ -383,6 +398,19 @@ std::optional DeviceInfo::GetLogPath() const { return std::nullopt; } +std::optional DeviceInfo::GetCrashDumpPath() 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 / kCrashDumpsRelativePath); + } + 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 b38c60f4..b8ea3995 100644 --- a/internal/platform/implementation/windows/device_info.h +++ b/internal/platform/implementation/windows/device_info.h @@ -44,9 +44,11 @@ class DeviceInfo : public api::DeviceInfo { std::optional GetProfileUserName() const override; std::optional GetDownloadPath() const override; - std::optional GetAppDataPath() const override; + std::optional GetLocalAppDataPath() const override; + std::optional GetCommonAppDataPath() const override; std::optional GetTemporaryPath() const override; std::optional GetLogPath() const override; + std::optional GetCrashDumpPath() const override; bool IsScreenLocked() const override; void RegisterScreenLockedListener( diff --git a/internal/platform/implementation/windows/device_info_test.cc b/internal/platform/implementation/windows/device_info_test.cc index 460505c6..63a3eaf0 100644 --- a/internal/platform/implementation/windows/device_info_test.cc +++ b/internal/platform/implementation/windows/device_info_test.cc @@ -53,8 +53,8 @@ TEST(DeviceInfo, DISABLED_GetProfileUserName) { EXPECT_TRUE(DeviceInfo().GetProfileUserName().has_value()); } -TEST(DeviceInfo, DISABLED_GetAppDataPath) { - EXPECT_TRUE(DeviceInfo().GetAppDataPath().has_value()); +TEST(DeviceInfo, DISABLED_GetLocalAppDataPath) { + EXPECT_TRUE(DeviceInfo().GetLocalAppDataPath().has_value()); } TEST(DeviceInfo, DISABLED_GetDownloadPath) {