mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Add implementation for log file path
PiperOrigin-RevId: 794256202
This commit is contained in:
committed by
Copybara-Service
parent
c1b902b6ac
commit
bff02013c9
@@ -77,6 +77,7 @@ objc_library(
|
||||
aspect_hints = ["//tools/build_defs/swift:no_module"],
|
||||
features = ["-layering_check"],
|
||||
deps = [
|
||||
":GNCDevicePaths",
|
||||
":comm",
|
||||
":Platform_cc",
|
||||
":Shared",
|
||||
@@ -102,6 +103,7 @@ objc_library(
|
||||
"//internal/platform/implementation/apple/Mediums",
|
||||
"//internal/platform/implementation/shared:file",
|
||||
"//internal/platform/implementation/apple/Log:GNCLogger",
|
||||
"//internal/platform:cancellation_flag",
|
||||
] + select({
|
||||
"@platforms//os:platform_ios": [
|
||||
"//third_party/apple_frameworks:UIKit",
|
||||
@@ -225,6 +227,16 @@ objc_library(
|
||||
],
|
||||
)
|
||||
|
||||
objc_library(
|
||||
name = "GNCDevicePaths",
|
||||
srcs = ["GNCDevicePaths.m"],
|
||||
hdrs = ["GNCDevicePaths.h"],
|
||||
deps = [
|
||||
"//internal/platform/implementation/apple/Log:GNCLogger",
|
||||
"//third_party/apple_frameworks:Foundation",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "Platform_cc",
|
||||
srcs = [
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
// Copyright 2025 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Returns the path to the LocalAppData directory for the given app path.
|
||||
NSURL *_Nullable GNCLocalAppDataPath();
|
||||
|
||||
// Returns the path to the log directory.
|
||||
NSURL *_Nullable GNCLogPath();
|
||||
|
||||
// Returns the path to the crash dump directory.
|
||||
NSURL *_Nullable GNCCrashDumpPath();
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,46 @@
|
||||
// Copyright 2020 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#import "internal/platform/implementation/apple/GNCDevicePaths.h"
|
||||
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
NSURL *_Nullable GNCLocalAppDataPath() {
|
||||
NSFileManager *manager = [NSFileManager defaultManager];
|
||||
|
||||
NSError *error = nil;
|
||||
NSURL *applicationSupportURL = [manager URLForDirectory:NSApplicationSupportDirectory
|
||||
inDomain:NSUserDomainMask
|
||||
appropriateForURL:nil
|
||||
create:YES
|
||||
error:&error];
|
||||
if (!applicationSupportURL) {
|
||||
GNCLoggerError(@"Failed to get application support path: %@", error);
|
||||
return nil;
|
||||
}
|
||||
|
||||
return applicationSupportURL;
|
||||
}
|
||||
|
||||
NSURL *_Nullable GNCLogPath() {
|
||||
return [GNCLocalAppDataPath() URLByAppendingPathComponent:@"Google/Nearby/Sharing/Logs"];
|
||||
}
|
||||
|
||||
NSURL *_Nullable GNCCrashDumpPath() {
|
||||
return [GNCLocalAppDataPath() URLByAppendingPathComponent:@"Google/Nearby/Sharing/CrashDumps"];
|
||||
}
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "internal/base/file_path.h"
|
||||
#include "internal/platform/implementation/device_info.h"
|
||||
|
||||
#import "internal/platform/implementation/apple/GNCDevicePaths.h"
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
|
||||
namespace nearby {
|
||||
@@ -96,20 +97,7 @@ std::optional<FilePath> DeviceInfo::GetDownloadPath() const {
|
||||
}
|
||||
|
||||
std::optional<FilePath> DeviceInfo::GetLocalAppDataPath() const {
|
||||
NSFileManager *manager = [NSFileManager defaultManager];
|
||||
|
||||
NSError *error = nil;
|
||||
NSURL *applicationSupportURL = [manager URLForDirectory:NSApplicationSupportDirectory
|
||||
inDomain:NSUserDomainMask
|
||||
appropriateForURL:nil
|
||||
create:YES
|
||||
error:&error];
|
||||
if (!applicationSupportURL) {
|
||||
GNCLoggerError(@"Failed to get application support path: %@", error);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return FilePath(absl::string_view([applicationSupportURL.path cString]));
|
||||
return FilePath(absl::string_view([GNCLocalAppDataPath().path cString]));
|
||||
}
|
||||
|
||||
std::optional<FilePath> DeviceInfo::GetCommonAppDataPath() const { return GetLocalAppDataPath(); }
|
||||
@@ -119,47 +107,11 @@ std::optional<FilePath> DeviceInfo::GetTemporaryPath() const {
|
||||
}
|
||||
|
||||
std::optional<FilePath> DeviceInfo::GetLogPath() const {
|
||||
NSFileManager *manager = [NSFileManager defaultManager];
|
||||
|
||||
NSError *error = nil;
|
||||
NSURL *applicationSupportURL = [manager URLForDirectory:NSApplicationSupportDirectory
|
||||
inDomain:NSUserDomainMask
|
||||
appropriateForURL:nil
|
||||
create:YES
|
||||
error:&error];
|
||||
if (!applicationSupportURL) {
|
||||
GNCLoggerError(@"Failed to get application support path: %@", error);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// TODO(b/276937308): This should not hard-code Nearby Share's log directory, but this matches the
|
||||
// current Windows implmementation.
|
||||
NSURL *logsURL =
|
||||
[applicationSupportURL URLByAppendingPathComponent:@"Google/Nearby/Sharing/Logs"];
|
||||
|
||||
return FilePath(absl::string_view([logsURL.path cString]));
|
||||
return FilePath(absl::string_view([GNCLogPath().path cString]));
|
||||
}
|
||||
|
||||
std::optional<FilePath> DeviceInfo::GetCrashDumpPath() const {
|
||||
NSFileManager *manager = [NSFileManager defaultManager];
|
||||
|
||||
NSError *error = nil;
|
||||
NSURL *applicationSupportURL = [manager URLForDirectory:NSApplicationSupportDirectory
|
||||
inDomain:NSUserDomainMask
|
||||
appropriateForURL:nil
|
||||
create:YES
|
||||
error:&error];
|
||||
if (!applicationSupportURL) {
|
||||
GNCLoggerError(@"Failed to get application support path: %@", error);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// TODO(b/276937308): This should not hard-code Nearby Share's crash dump directory, but this
|
||||
// matches the current Windows implmementation.
|
||||
NSURL *crashDumpsURL =
|
||||
[applicationSupportURL URLByAppendingPathComponent:@"Google/Nearby/Sharing/CrashDumps"];
|
||||
|
||||
return FilePath(absl::string_view([crashDumpsURL.path cString]));
|
||||
return FilePath(absl::string_view([GNCCrashDumpPath().path cString]));
|
||||
}
|
||||
|
||||
bool DeviceInfo::IsScreenLocked() const { return false; }
|
||||
|
||||
Reference in New Issue
Block a user