Change log and crash dump locations from a per user data location to a per machine common data location.

PiperOrigin-RevId: 505711827
This commit is contained in:
hai007
2023-01-30 09:14:00 -08:00
committed by Copybara-Service
parent d1fe2bfe51
commit 3cbbecd53a
6 changed files with 27 additions and 0 deletions
@@ -45,6 +45,8 @@ class DeviceInfo : public api::DeviceInfo {
std::optional<std::filesystem::path> GetTemporaryPath() const override;
std::optional<std::filesystem::path> GetLogPath() const override;
bool IsScreenLocked() const override;
void RegisterScreenLockedListener(
@@ -51,6 +51,10 @@ std::optional<std::filesystem::path> DeviceInfo::GetTemporaryPath() const {
return std::filesystem::temp_directory_path();
}
std::optional<std::filesystem::path> DeviceInfo::GetLogPath() const {
return std::filesystem::temp_directory_path();
}
bool DeviceInfo::IsScreenLocked() const { return false; }
void DeviceInfo::RegisterScreenLockedListener(
@@ -48,6 +48,7 @@ class DeviceInfo {
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;
virtual std::optional<std::filesystem::path> GetLogPath() const = 0;
// Monitor screen status
virtual bool IsScreenLocked() const = 0;
@@ -67,6 +67,10 @@ class DeviceInfo : public api::DeviceInfo {
return std::filesystem::temp_directory_path();
}
std::optional<std::filesystem::path> GetLogPath() const override {
return std::filesystem::temp_directory_path();
}
bool IsScreenLocked() const override { return false; }
void RegisterScreenLockedListener(
@@ -51,6 +51,7 @@ using IAsyncOperation = winrt::Windows::Foundation::IAsyncOperation<T>;
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<std::filesystem::path> DeviceInfo::GetTemporaryPath() const {
return std::filesystem::temp_directory_path();
}
std::optional<std::filesystem::path> 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;
@@ -46,6 +46,7 @@ class DeviceInfo : public api::DeviceInfo {
std::optional<std::filesystem::path> GetDownloadPath() const override;
std::optional<std::filesystem::path> GetAppDataPath() const override;
std::optional<std::filesystem::path> GetTemporaryPath() const override;
std::optional<std::filesystem::path> GetLogPath() const override;
bool IsScreenLocked() const override;
void RegisterScreenLockedListener(