mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Remove unnecessary DevicInfoImpl class.
PiperOrigin-RevId: 892102193
This commit is contained in:
committed by
Copybara-Service
parent
ac70b1f91f
commit
f088ef3b74
@@ -210,7 +210,6 @@ cc_library(
|
||||
srcs = [
|
||||
"blocking_queue_stream.cc",
|
||||
"clock_impl.cc",
|
||||
"device_info_impl.cc",
|
||||
"monitored_runnable.cc",
|
||||
"pending_job_registry.cc",
|
||||
"pipe.cc",
|
||||
@@ -231,8 +230,6 @@ cc_library(
|
||||
"condition_variable.h",
|
||||
"count_down_latch.h",
|
||||
"crypto.h",
|
||||
"device_info.h",
|
||||
"device_info_impl.h",
|
||||
"direct_executor.h",
|
||||
"file.h",
|
||||
"future.h",
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
// Copyright 2021 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.
|
||||
|
||||
#ifndef PLATFORM_PUBLIC_DEVICE_INFO_H_
|
||||
#define PLATFORM_PUBLIC_DEVICE_INFO_H_
|
||||
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/base/file_path.h"
|
||||
#include "internal/platform/implementation/device_info.h"
|
||||
|
||||
namespace nearby {
|
||||
|
||||
class DeviceInfo {
|
||||
public:
|
||||
virtual ~DeviceInfo() = default;
|
||||
|
||||
// All strings are UTF-8 encoded.
|
||||
virtual std::string GetOsDeviceName() const = 0;
|
||||
virtual api::DeviceInfo::DeviceType GetDeviceType() const = 0;
|
||||
virtual api::DeviceInfo::OsType GetOsType() const = 0;
|
||||
|
||||
virtual FilePath GetDownloadPath() const = 0;
|
||||
virtual FilePath GetAppDataPath() const = 0;
|
||||
virtual FilePath GetTemporaryPath() const = 0;
|
||||
virtual FilePath GetLogPath() const = 0;
|
||||
|
||||
virtual std::optional<size_t> GetAvailableDiskSpaceInBytes(
|
||||
const FilePath& path) const = 0;
|
||||
|
||||
virtual bool IsScreenLocked() const = 0;
|
||||
virtual void RegisterScreenLockedListener(
|
||||
absl::string_view listener_name,
|
||||
std::function<void(api::DeviceInfo::ScreenStatus)> callback) = 0;
|
||||
virtual void UnregisterScreenLockedListener(
|
||||
absl::string_view listener_name) = 0;
|
||||
|
||||
virtual bool PreventSleep() = 0;
|
||||
virtual bool AllowSleep() = 0;
|
||||
|
||||
// Returns UTF-8 encoded localized device name depending on device type.
|
||||
std::string GetDeviceTypeName() const {
|
||||
// TODO(b/230132370): return localized device name.
|
||||
switch (GetDeviceType()) {
|
||||
case api::DeviceInfo::DeviceType::kPhone:
|
||||
return "Phone";
|
||||
case api::DeviceInfo::DeviceType::kTablet:
|
||||
return "Tablet";
|
||||
case api::DeviceInfo::DeviceType::kLaptop:
|
||||
return "PC";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace nearby
|
||||
|
||||
#endif // PLATFORM_PUBLIC_DEVICE_INFO_H_
|
||||
@@ -1,88 +0,0 @@
|
||||
// Copyright 2021 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.
|
||||
|
||||
#include "internal/platform/device_info_impl.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/base/file_path.h"
|
||||
#include "internal/base/files.h"
|
||||
#include "internal/platform/implementation/device_info.h"
|
||||
|
||||
namespace nearby {
|
||||
|
||||
std::string DeviceInfoImpl::GetOsDeviceName() const {
|
||||
std::optional<std::string> device_name = device_info_impl_->GetOsDeviceName();
|
||||
if (device_name.has_value()) {
|
||||
return *device_name;
|
||||
}
|
||||
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
api::DeviceInfo::DeviceType DeviceInfoImpl::GetDeviceType() const {
|
||||
return device_info_impl_->GetDeviceType();
|
||||
}
|
||||
|
||||
api::DeviceInfo::OsType DeviceInfoImpl::GetOsType() const {
|
||||
return device_info_impl_->GetOsType();
|
||||
}
|
||||
|
||||
FilePath DeviceInfoImpl::GetDownloadPath() const {
|
||||
return device_info_impl_->GetDownloadPath();
|
||||
}
|
||||
|
||||
FilePath DeviceInfoImpl::GetAppDataPath() const {
|
||||
return device_info_impl_->GetLocalAppDataPath(FilePath());
|
||||
}
|
||||
|
||||
FilePath DeviceInfoImpl::GetTemporaryPath() const {
|
||||
return device_info_impl_->GetTemporaryPath();
|
||||
}
|
||||
|
||||
FilePath DeviceInfoImpl::GetLogPath() const {
|
||||
return device_info_impl_->GetLogPath();
|
||||
}
|
||||
|
||||
std::optional<size_t> DeviceInfoImpl::GetAvailableDiskSpaceInBytes(
|
||||
const FilePath& path) const {
|
||||
return Files::GetAvailableDiskSpaceInBytes(path);
|
||||
}
|
||||
|
||||
bool DeviceInfoImpl::IsScreenLocked() const {
|
||||
return device_info_impl_->IsScreenLocked();
|
||||
}
|
||||
|
||||
void DeviceInfoImpl::RegisterScreenLockedListener(
|
||||
absl::string_view listener_name,
|
||||
std::function<void(api::DeviceInfo::ScreenStatus)> callback) {
|
||||
device_info_impl_->RegisterScreenLockedListener(listener_name, callback);
|
||||
}
|
||||
|
||||
void DeviceInfoImpl::UnregisterScreenLockedListener(
|
||||
absl::string_view listener_name) {
|
||||
device_info_impl_->UnregisterScreenLockedListener(listener_name);
|
||||
}
|
||||
|
||||
bool DeviceInfoImpl::PreventSleep() {
|
||||
return device_info_impl_->PreventSleep();
|
||||
}
|
||||
|
||||
bool DeviceInfoImpl::AllowSleep() { return device_info_impl_->AllowSleep(); }
|
||||
|
||||
} // namespace nearby
|
||||
@@ -1,63 +0,0 @@
|
||||
// Copyright 2021 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.
|
||||
|
||||
#ifndef PLATFORM_PUBLIC_DEVICE_INFO_IMPL_H_
|
||||
#define PLATFORM_PUBLIC_DEVICE_INFO_IMPL_H_
|
||||
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/base/file_path.h"
|
||||
#include "internal/platform/device_info.h"
|
||||
#include "internal/platform/implementation/device_info.h"
|
||||
#include "internal/platform/implementation/platform.h"
|
||||
|
||||
namespace nearby {
|
||||
|
||||
class DeviceInfoImpl : public DeviceInfo {
|
||||
public:
|
||||
DeviceInfoImpl()
|
||||
: device_info_impl_(api::ImplementationPlatform::CreateDeviceInfo()) {}
|
||||
|
||||
std::string GetOsDeviceName() const override;
|
||||
api::DeviceInfo::DeviceType GetDeviceType() const override;
|
||||
api::DeviceInfo::OsType GetOsType() const override;
|
||||
|
||||
FilePath GetDownloadPath() const override;
|
||||
FilePath GetAppDataPath() const override;
|
||||
FilePath GetTemporaryPath() const override;
|
||||
FilePath GetLogPath() const override;
|
||||
|
||||
std::optional<size_t> GetAvailableDiskSpaceInBytes(
|
||||
const FilePath& path) const override;
|
||||
|
||||
bool IsScreenLocked() const override;
|
||||
void RegisterScreenLockedListener(
|
||||
absl::string_view listener_name,
|
||||
std::function<void(api::DeviceInfo::ScreenStatus)> callback) override;
|
||||
void UnregisterScreenLockedListener(absl::string_view listener_name) override;
|
||||
|
||||
bool PreventSleep() override;
|
||||
bool AllowSleep() override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<api::DeviceInfo> device_info_impl_;
|
||||
};
|
||||
} // namespace nearby
|
||||
|
||||
#endif // PLATFORM_PUBLIC_DEVICE_INFO_IMPL_H_
|
||||
@@ -54,6 +54,7 @@ cc_library(
|
||||
],
|
||||
deps = [
|
||||
"//internal/base:file_path",
|
||||
"//internal/base:files",
|
||||
"//internal/crypto_cros",
|
||||
"//internal/platform:base",
|
||||
"//internal/platform:mac_address",
|
||||
@@ -151,6 +152,7 @@ cc_library(
|
||||
"//location/nearby/analytics/cpp:__subpackages__",
|
||||
"//location/nearby/apps/better_together/plugins/preferences_native:__subpackages__",
|
||||
"//location/nearby/cpp/sharing:__subpackages__",
|
||||
"//sharing/internal/impl/common:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
":comm",
|
||||
|
||||
@@ -15,12 +15,14 @@
|
||||
#ifndef PLATFORM_API_DEVICE_INFO_H_
|
||||
#define PLATFORM_API_DEVICE_INFO_H_
|
||||
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/base/file_path.h"
|
||||
#include "internal/base/files.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace api {
|
||||
@@ -29,6 +31,23 @@ class DeviceInfo {
|
||||
public:
|
||||
enum class ScreenStatus { kUndetermined = 0, kLocked, kUnlocked };
|
||||
enum class DeviceType { kUnknown = 0, kPhone, kTablet, kLaptop };
|
||||
template <typename Sink>
|
||||
void AbslStringify(Sink& sink, DeviceType device_type) {
|
||||
switch (device_type) {
|
||||
case DeviceType::kUnknown:
|
||||
sink.Append("Unknown");
|
||||
return;
|
||||
case DeviceType::kPhone:
|
||||
sink.Append("Phone");
|
||||
return;
|
||||
case DeviceType::kTablet:
|
||||
sink.Append("Tablet");
|
||||
return;
|
||||
case DeviceType::kLaptop:
|
||||
sink.Append("PC");
|
||||
return;
|
||||
}
|
||||
}
|
||||
enum class OsType {
|
||||
kUnknown = 0,
|
||||
kAndroid,
|
||||
@@ -51,6 +70,11 @@ class DeviceInfo {
|
||||
virtual FilePath GetTemporaryPath() const = 0;
|
||||
virtual FilePath GetLogPath() const = 0;
|
||||
|
||||
virtual std::optional<size_t> GetAvailableDiskSpaceInBytes(
|
||||
const FilePath& path) const {
|
||||
return Files::GetAvailableDiskSpaceInBytes(path);
|
||||
};
|
||||
|
||||
// Monitor screen status
|
||||
virtual bool IsScreenLocked() const = 0;
|
||||
virtual void RegisterScreenLockedListener(
|
||||
|
||||
Reference in New Issue
Block a user