mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Remove unnecessary DevicInfoImpl class.
PiperOrigin-RevId: 892102193
This commit is contained in:
committed by
Copybara-Service
parent
ac70b1f91f
commit
f088ef3b74
@@ -61,7 +61,7 @@
|
||||
#include "internal/platform/cancelable_alarm.h"
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#ifndef NEARBY_CHROMIUM
|
||||
#include "internal/platform/device_info_impl.h"
|
||||
#include "internal/platform/implementation/device_info.h"
|
||||
#endif
|
||||
#include "internal/platform/error_code_params.h"
|
||||
#include "internal/platform/error_code_recorder.h"
|
||||
@@ -1340,10 +1340,11 @@ void ClientProxy::InitializePreferencesManager() {
|
||||
void ClientProxy::InitializePreferencesManager() {
|
||||
LOG(INFO) << "ClientProxy [InitializePreferencesManager]: client="
|
||||
<< GetClientId();
|
||||
auto device_info_ = std::make_unique<nearby::DeviceInfoImpl>();
|
||||
std::unique_ptr<nearby::api::DeviceInfo> device_info_ =
|
||||
nearby::api::ImplementationPlatform::CreateDeviceInfo();
|
||||
|
||||
FilePath preferences_path =
|
||||
device_info_->GetAppDataPath().append(FilePath(kPreferencesFilePath));
|
||||
device_info_->GetLocalAppDataPath(FilePath(kPreferencesFilePath));
|
||||
|
||||
if (!Files::FileExists(preferences_path)) {
|
||||
Files::CreateDirectories(preferences_path);
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -27,14 +27,15 @@
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/base/file_path.h"
|
||||
#include "internal/base/files.h"
|
||||
#include "internal/platform/device_info.h"
|
||||
#include "internal/platform/implementation/device_info.h"
|
||||
|
||||
namespace nearby {
|
||||
|
||||
class FakeDeviceInfo : public DeviceInfo {
|
||||
class FakeDeviceInfo : public api::DeviceInfo {
|
||||
public:
|
||||
std::string GetOsDeviceName() const override { return device_name_; }
|
||||
std::optional<std::string> GetOsDeviceName() const override {
|
||||
return device_name_;
|
||||
}
|
||||
|
||||
api::DeviceInfo::DeviceType GetDeviceType() const override {
|
||||
return device_type_;
|
||||
@@ -46,8 +47,10 @@ class FakeDeviceInfo : public DeviceInfo {
|
||||
return download_path_;
|
||||
}
|
||||
|
||||
FilePath GetAppDataPath() const override {
|
||||
return app_data_path_;
|
||||
FilePath GetLocalAppDataPath(FilePath sub_path) const override {
|
||||
FilePath path = app_data_path_;
|
||||
path.append(sub_path);
|
||||
return path;
|
||||
}
|
||||
|
||||
FilePath GetTemporaryPath() const override { return temp_path_; }
|
||||
|
||||
@@ -51,13 +51,16 @@ TEST(FakeDeviceInfo, GetDownloadPath) {
|
||||
Files::GetTemporaryDirectory().append(FilePath("test")));
|
||||
}
|
||||
|
||||
TEST(FakeDeviceInfo, GetAppDataPath) {
|
||||
TEST(FakeDeviceInfo, GetLocalAppDataPath) {
|
||||
FakeDeviceInfo device_info;
|
||||
EXPECT_EQ(device_info.GetAppDataPath(), Files::GetTemporaryDirectory());
|
||||
EXPECT_EQ(device_info.GetLocalAppDataPath(FilePath("abc")),
|
||||
Files::GetTemporaryDirectory().append(FilePath("abc")));
|
||||
device_info.SetAppDataPath(
|
||||
Files::GetTemporaryDirectory().append(FilePath("test")));
|
||||
EXPECT_EQ(device_info.GetAppDataPath(),
|
||||
Files::GetTemporaryDirectory().append(FilePath("test")));
|
||||
EXPECT_EQ(device_info.GetLocalAppDataPath(FilePath("def")),
|
||||
Files::GetTemporaryDirectory()
|
||||
.append(FilePath("test"))
|
||||
.append(FilePath("def")));
|
||||
}
|
||||
|
||||
TEST(FakeDeviceInfo, GetTemporaryPath) {
|
||||
@@ -76,7 +79,8 @@ TEST(FakeDeviceInfo, GetAvailableDiskSpaceInBytes) {
|
||||
device_info.SetTemporaryPath(FilePath("temp"));
|
||||
|
||||
device_info.SetAvailableDiskSpaceInBytes(device_info.GetDownloadPath(), 10);
|
||||
device_info.SetAvailableDiskSpaceInBytes(device_info.GetAppDataPath(), 100);
|
||||
device_info.SetAvailableDiskSpaceInBytes(
|
||||
device_info.GetLocalAppDataPath(FilePath()), 100);
|
||||
device_info.SetAvailableDiskSpaceInBytes(device_info.GetTemporaryPath(),
|
||||
1000);
|
||||
|
||||
@@ -84,7 +88,8 @@ TEST(FakeDeviceInfo, GetAvailableDiskSpaceInBytes) {
|
||||
device_info.GetAvailableDiskSpaceInBytes(device_info.GetDownloadPath()),
|
||||
10);
|
||||
EXPECT_EQ(
|
||||
device_info.GetAvailableDiskSpaceInBytes(device_info.GetAppDataPath()),
|
||||
device_info.GetAvailableDiskSpaceInBytes(
|
||||
device_info.GetLocalAppDataPath(FilePath())),
|
||||
100);
|
||||
EXPECT_EQ(
|
||||
device_info.GetAvailableDiskSpaceInBytes(device_info.GetTemporaryPath()),
|
||||
|
||||
+2
-5
@@ -258,12 +258,10 @@ cc_library(
|
||||
srcs = ["nearby_connection_impl.cc"],
|
||||
hdrs = ["nearby_connection_impl.h"],
|
||||
deps = [
|
||||
":connection_types",
|
||||
":types",
|
||||
"//internal/platform:types",
|
||||
"//internal/platform/implementation:types",
|
||||
"//sharing/internal/public:logging",
|
||||
"@com_google_absl//absl/base:core_headers",
|
||||
"@com_google_absl//absl/strings",
|
||||
"@com_google_absl//absl/synchronization",
|
||||
],
|
||||
)
|
||||
@@ -303,8 +301,6 @@ cc_library(
|
||||
hdrs = ["nearby_sharing_util.h"],
|
||||
deps = [
|
||||
":types",
|
||||
"//internal/base:file_path",
|
||||
"//internal/platform:types",
|
||||
"//proto:sharing_enums_cc_proto",
|
||||
"//sharing/certificates",
|
||||
"//sharing/common:enum",
|
||||
@@ -382,6 +378,7 @@ cc_library(
|
||||
"//internal/analytics:event_logger",
|
||||
"//internal/base",
|
||||
"//internal/base:file_path",
|
||||
"//internal/base:files",
|
||||
"//internal/flags:nearby_flags",
|
||||
"//internal/network:url",
|
||||
"//internal/platform:base",
|
||||
|
||||
@@ -42,6 +42,7 @@ cc_library(
|
||||
"//internal/base:file_path",
|
||||
"//internal/platform:mac_address",
|
||||
"//internal/platform:types",
|
||||
"//internal/platform/implementation:types",
|
||||
"//location/nearby/sharing/lib/account:account_manager",
|
||||
"//location/nearby/sharing/lib/sync:sync_binding_prefs_cc_proto",
|
||||
"//sharing/proto:share_cc_proto",
|
||||
@@ -71,16 +72,10 @@ cc_library(
|
||||
"//internal/base:file_path",
|
||||
"//internal/platform:mac_address",
|
||||
"//internal/platform:types",
|
||||
"//internal/platform/implementation:types",
|
||||
"//location/nearby/sharing/lib/account:account_manager",
|
||||
"//sharing/analytics",
|
||||
"//sharing/internal/public:logging",
|
||||
"//sharing/proto:share_cc_proto",
|
||||
"@com_google_absl//absl/base:core_headers",
|
||||
"@com_google_absl//absl/functional:any_invocable",
|
||||
"@com_google_absl//absl/status",
|
||||
"@com_google_absl//absl/status:statusor",
|
||||
"@com_google_absl//absl/strings",
|
||||
"@com_google_absl//absl/synchronization",
|
||||
"@com_google_absl//absl/types:span",
|
||||
"@com_google_googletest//:gtest_for_library_testonly",
|
||||
],
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include "gmock/gmock.h"
|
||||
#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/task_runner.h"
|
||||
#include "sharing/internal/api/app_info.h"
|
||||
#include "sharing/internal/api/bluetooth_adapter.h"
|
||||
@@ -72,7 +72,7 @@ class MockSharingPlatform : public SharingPlatform {
|
||||
|
||||
MOCK_METHOD(AccountManager&, GetAccountManager, (), (override));
|
||||
MOCK_METHOD(TaskRunner&, GetDefaultTaskRunner, (), (override));
|
||||
MOCK_METHOD(nearby::DeviceInfo&, GetDeviceInfo, (), (override));
|
||||
MOCK_METHOD(nearby::api::DeviceInfo&, GetDeviceInfo, (), (override));
|
||||
MOCK_METHOD(std::unique_ptr<PublicCertificateDatabase>,
|
||||
CreatePublicCertificateDatabase, (const FilePath& database_path),
|
||||
(override));
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#include "location/nearby/sharing/lib/account/account_manager.h"
|
||||
#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/task_runner.h"
|
||||
#include "sharing/internal/api/app_info.h"
|
||||
#include "sharing/internal/api/bluetooth_adapter.h"
|
||||
@@ -65,7 +65,7 @@ class SharingPlatform {
|
||||
virtual PreferenceManager& GetPreferenceManager() = 0;
|
||||
virtual AccountManager& GetAccountManager() = 0;
|
||||
virtual TaskRunner& GetDefaultTaskRunner() = 0;
|
||||
virtual nearby::DeviceInfo& GetDeviceInfo() = 0;
|
||||
virtual nearby::api::DeviceInfo& GetDeviceInfo() = 0;
|
||||
virtual std::unique_ptr<PublicCertificateDatabase>
|
||||
CreatePublicCertificateDatabase(const FilePath& database_path) = 0;
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@ cc_library(
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//internal/base",
|
||||
"//internal/platform:types",
|
||||
"//internal/platform/implementation:types",
|
||||
"//location/nearby/sharing/lib/account:account_manager",
|
||||
"//sharing/common:enum",
|
||||
|
||||
@@ -23,9 +23,8 @@
|
||||
|
||||
#include "location/nearby/sharing/lib/account/account_manager.h"
|
||||
#include "absl/memory/memory.h"
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/strings/substitute.h"
|
||||
#include "internal/platform/device_info.h"
|
||||
#include "internal/platform/implementation/device_info.h"
|
||||
#include "sharing/common/nearby_share_enums.h"
|
||||
#include "sharing/internal/api/preference_manager.h"
|
||||
@@ -42,8 +41,6 @@ namespace {
|
||||
using ::nearby::api::DeviceInfo;
|
||||
using ::nearby::sharing::api::PreferenceManager;
|
||||
|
||||
constexpr absl::string_view kDefaultDeviceName = "$0\'s $1";
|
||||
|
||||
// Returns a truncated version of |name| that is |max_length| characters long.
|
||||
// For example, name="Reallylongname" with max_length=9 will return "Really...".
|
||||
// name="Reallylongname" with max_length=20 will return "Reallylongname".
|
||||
@@ -71,7 +68,7 @@ NearbyShareLocalDeviceDataManagerImpl::Factory*
|
||||
std::unique_ptr<NearbyShareLocalDeviceDataManager>
|
||||
NearbyShareLocalDeviceDataManagerImpl::Factory::Create(
|
||||
PreferenceManager& preference_manager,
|
||||
AccountManager& account_manager, nearby::DeviceInfo& device_info) {
|
||||
AccountManager& account_manager, nearby::api::DeviceInfo& device_info) {
|
||||
if (test_factory_) {
|
||||
return test_factory_->CreateInstance();
|
||||
}
|
||||
@@ -90,7 +87,7 @@ NearbyShareLocalDeviceDataManagerImpl::Factory::~Factory() = default;
|
||||
|
||||
NearbyShareLocalDeviceDataManagerImpl::NearbyShareLocalDeviceDataManagerImpl(
|
||||
PreferenceManager& preference_manager, AccountManager& account_manager,
|
||||
nearby::DeviceInfo& device_info)
|
||||
nearby::api::DeviceInfo& device_info)
|
||||
: preference_manager_(preference_manager),
|
||||
account_manager_(account_manager),
|
||||
device_info_(device_info) {}
|
||||
@@ -147,20 +144,24 @@ std::string NearbyShareLocalDeviceDataManagerImpl::GetDefaultDeviceName()
|
||||
if (os_type == DeviceInfo::OsType::kMacOS ||
|
||||
os_type == DeviceInfo::OsType::kIos || !account.has_value() ||
|
||||
account->given_name.empty()) {
|
||||
std::string device_name = device_info_.GetOsDeviceName();
|
||||
std::string device_name =
|
||||
device_info_.GetOsDeviceName().value_or("unknown");
|
||||
return GetTruncatedName(device_name, kNearbyShareDeviceNameMaxLength);
|
||||
}
|
||||
std::string given_name = account->given_name;
|
||||
std::string device_type = device_info_.GetDeviceTypeName();
|
||||
uint64_t untruncated_length =
|
||||
absl::Substitute(kDefaultDeviceName, given_name, device_type).length();
|
||||
DeviceInfo::DeviceType device_type = device_info_.GetDeviceType();
|
||||
std::string device_name = absl::StrCat(given_name, "'s ", device_type);
|
||||
uint64_t untruncated_length = device_name.length();
|
||||
if (untruncated_length <= kNearbyShareDeviceNameMaxLength) {
|
||||
return device_name;
|
||||
}
|
||||
uint64_t overflow_length =
|
||||
untruncated_length - kNearbyShareDeviceNameMaxLength;
|
||||
|
||||
std::string truncated_name =
|
||||
GetTruncatedName(given_name, given_name.length() - overflow_length);
|
||||
|
||||
return absl::Substitute(kDefaultDeviceName, truncated_name, device_type);
|
||||
return absl::StrCat(truncated_name, "'s ", device_type);
|
||||
}
|
||||
|
||||
} // namespace nearby::sharing
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
#include "location/nearby/sharing/lib/account/account_manager.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/platform/device_info.h"
|
||||
#include "internal/platform/implementation/device_info.h"
|
||||
#include "sharing/common/nearby_share_enums.h"
|
||||
#include "sharing/internal/api/preference_manager.h"
|
||||
#include "sharing/local_device_data/nearby_share_local_device_data_manager.h"
|
||||
@@ -40,7 +40,7 @@ class NearbyShareLocalDeviceDataManagerImpl
|
||||
public:
|
||||
static std::unique_ptr<NearbyShareLocalDeviceDataManager> Create(
|
||||
nearby::sharing::api::PreferenceManager& preference_manager,
|
||||
AccountManager& account_manager, nearby::DeviceInfo& device_info);
|
||||
AccountManager& account_manager, nearby::api::DeviceInfo& device_info);
|
||||
static void SetFactoryForTesting(Factory* test_factory);
|
||||
|
||||
protected:
|
||||
@@ -61,7 +61,7 @@ class NearbyShareLocalDeviceDataManagerImpl
|
||||
private:
|
||||
NearbyShareLocalDeviceDataManagerImpl(
|
||||
nearby::sharing::api::PreferenceManager& preference_manager,
|
||||
AccountManager& account_manager, nearby::DeviceInfo& device_info);
|
||||
AccountManager& account_manager, nearby::api::DeviceInfo& device_info);
|
||||
|
||||
DeviceNameValidationResult ValidateDeviceName(absl::string_view name);
|
||||
|
||||
@@ -73,7 +73,7 @@ class NearbyShareLocalDeviceDataManagerImpl
|
||||
|
||||
nearby::sharing::api::PreferenceManager& preference_manager_;
|
||||
AccountManager& account_manager_;
|
||||
nearby::DeviceInfo& device_info_;
|
||||
nearby::api::DeviceInfo& device_info_;
|
||||
};
|
||||
|
||||
} // namespace nearby::sharing
|
||||
|
||||
@@ -109,11 +109,11 @@ class NearbyShareLocalDeviceDataManagerImplTest
|
||||
}
|
||||
|
||||
std::string GetDeviceName() const {
|
||||
return fake_device_info_.GetOsDeviceName();
|
||||
return fake_device_info_.GetOsDeviceName().value_or("unknown");
|
||||
}
|
||||
|
||||
std::string GetDeviceTypeName() const {
|
||||
return fake_device_info_.GetDeviceTypeName();
|
||||
nearby::FakeDeviceInfo::DeviceType GetDeviceType() const {
|
||||
return fake_device_info_.GetDeviceType();
|
||||
}
|
||||
|
||||
protected:
|
||||
@@ -138,7 +138,7 @@ TEST_F(NearbyShareLocalDeviceDataManagerImplTest, DefaultDeviceName) {
|
||||
fake_account_manager().SetAccount(account);
|
||||
EXPECT_EQ(absl::Substitute(kDefaultDeviceName,
|
||||
kFakeGivenName,
|
||||
GetDeviceTypeName()),
|
||||
GetDeviceType()),
|
||||
manager()->GetDeviceName());
|
||||
|
||||
// Make sure that when we use a given name that is very long we truncate
|
||||
@@ -152,7 +152,7 @@ TEST_F(NearbyShareLocalDeviceDataManagerImplTest, SetDeviceName) {
|
||||
CreateManager();
|
||||
|
||||
std::string expected_default_device_name =
|
||||
absl::Substitute(kDefaultDeviceName, kFakeGivenName, GetDeviceTypeName());
|
||||
absl::Substitute(kDefaultDeviceName, kFakeGivenName, GetDeviceType());
|
||||
EXPECT_EQ(manager()->GetDeviceName(), expected_default_device_name);
|
||||
EXPECT_TRUE(notifications().empty());
|
||||
|
||||
|
||||
@@ -22,12 +22,12 @@
|
||||
#include <vector>
|
||||
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "internal/platform/device_info.h"
|
||||
#include "internal/platform/implementation/device_info.h"
|
||||
#include "sharing/internal/public/logging.h"
|
||||
|
||||
namespace nearby::sharing {
|
||||
|
||||
NearbyConnectionImpl::NearbyConnectionImpl(nearby::DeviceInfo& device_info)
|
||||
NearbyConnectionImpl::NearbyConnectionImpl(nearby::api::DeviceInfo& device_info)
|
||||
: device_info_(device_info) {
|
||||
if (!device_info_.PreventSleep()) {
|
||||
LOG(WARNING) << __func__ << ":Failed to prevent device sleep.";
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
#include "absl/base/thread_annotations.h"
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "internal/platform/device_info.h"
|
||||
#include "internal/platform/implementation/device_info.h"
|
||||
#include "sharing/nearby_connection.h"
|
||||
|
||||
namespace nearby::sharing {
|
||||
@@ -32,7 +32,7 @@ class NearbyConnectionsManager;
|
||||
|
||||
class NearbyConnectionImpl : public NearbyConnection {
|
||||
public:
|
||||
explicit NearbyConnectionImpl(nearby::DeviceInfo& device_info);
|
||||
explicit NearbyConnectionImpl(nearby::api::DeviceInfo& device_info);
|
||||
~NearbyConnectionImpl() override;
|
||||
|
||||
// NearbyConnection:
|
||||
@@ -46,7 +46,7 @@ class NearbyConnectionImpl : public NearbyConnection {
|
||||
void WriteMessage(std::vector<uint8_t> bytes) ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
private:
|
||||
nearby::DeviceInfo& device_info_;
|
||||
nearby::api::DeviceInfo& device_info_;
|
||||
|
||||
absl::Mutex mutex_;
|
||||
std::function<void(std::optional<std::vector<uint8_t>> bytes)> read_callback_
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include "internal/analytics/event_logger.h"
|
||||
#include "internal/platform/device_info.h"
|
||||
#include "internal/platform/implementation/device_info.h"
|
||||
#include "internal/platform/task_runner.h"
|
||||
#include "sharing/internal/public/context.h"
|
||||
#include "sharing/nearby_connections_manager.h"
|
||||
@@ -29,7 +29,7 @@ namespace nearby::sharing {
|
||||
std::unique_ptr<NearbyConnectionsManager>
|
||||
NearbyConnectionsManagerFactory::CreateConnectionsManager(
|
||||
nearby::TaskRunner* connections_callback_task_runner, Context* context,
|
||||
nearby::DeviceInfo& device_info,
|
||||
nearby::api::DeviceInfo& device_info,
|
||||
nearby::analytics::EventLogger* event_logger) {
|
||||
return std::make_unique<NearbyConnectionsManagerImpl>(
|
||||
connections_callback_task_runner, context,
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include "internal/analytics/event_logger.h"
|
||||
#include "internal/platform/device_info.h"
|
||||
#include "internal/platform/implementation/device_info.h"
|
||||
#include "internal/platform/task_runner.h"
|
||||
#include "sharing/internal/public/context.h"
|
||||
#include "sharing/nearby_connections_manager.h"
|
||||
@@ -33,7 +33,7 @@ class NearbyConnectionsManagerFactory {
|
||||
// that NearbySharingService is running on.
|
||||
static std::unique_ptr<NearbyConnectionsManager> CreateConnectionsManager(
|
||||
nearby::TaskRunner* connections_callback_task_runner, Context* context,
|
||||
nearby::DeviceInfo& device_info,
|
||||
nearby::api::DeviceInfo& device_info,
|
||||
nearby::analytics::EventLogger* event_logger = nullptr);
|
||||
|
||||
private:
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#include "absl/types/span.h"
|
||||
#include "internal/base/file_path.h"
|
||||
#include "internal/flags/nearby_flags.h"
|
||||
#include "internal/platform/device_info.h"
|
||||
#include "internal/platform/implementation/device_info.h"
|
||||
#include "internal/platform/mutex_lock.h"
|
||||
#include "internal/platform/task_runner.h"
|
||||
#include "sharing/advertisement.h"
|
||||
@@ -150,7 +150,8 @@ std::string PayloadStatusToString(PayloadStatus status) {
|
||||
|
||||
NearbyConnectionsManagerImpl::NearbyConnectionsManagerImpl(
|
||||
TaskRunner* connections_callback_task_runner, Context* context,
|
||||
ConnectivityManager& connectivity_manager, nearby::DeviceInfo& device_info,
|
||||
ConnectivityManager& connectivity_manager,
|
||||
nearby::api::DeviceInfo& device_info,
|
||||
std::unique_ptr<NearbyConnectionsService> nearby_connections_service)
|
||||
: connections_callback_task_runner_(connections_callback_task_runner),
|
||||
context_(context),
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include "absl/container/flat_hash_set.h"
|
||||
#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/mutex.h"
|
||||
#include "internal/platform/task_runner.h"
|
||||
#include "internal/platform/timer.h"
|
||||
@@ -49,7 +49,7 @@ class NearbyConnectionsManagerImpl : public NearbyConnectionsManager {
|
||||
explicit NearbyConnectionsManagerImpl(
|
||||
nearby::TaskRunner* connections_callback_task_runner, Context* context,
|
||||
nearby::ConnectivityManager& connectivity_manager,
|
||||
nearby::DeviceInfo& device_info,
|
||||
nearby::api::DeviceInfo& device_info,
|
||||
std::unique_ptr<NearbyConnectionsService> nearby_connections_service);
|
||||
~NearbyConnectionsManagerImpl() override;
|
||||
NearbyConnectionsManagerImpl(const NearbyConnectionsManagerImpl&) = delete;
|
||||
@@ -146,7 +146,7 @@ class NearbyConnectionsManagerImpl : public NearbyConnectionsManager {
|
||||
nearby::TaskRunner* const connections_callback_task_runner_;
|
||||
Context* const context_;
|
||||
nearby::ConnectivityManager& connectivity_manager_;
|
||||
nearby::DeviceInfo& device_info_;
|
||||
nearby::api::DeviceInfo& device_info_;
|
||||
|
||||
// Nearby Connections Manager is called from different threads and may have
|
||||
// multiple calls to the class from one thread. To avoid deadlock and access
|
||||
|
||||
@@ -49,7 +49,6 @@
|
||||
#include "internal/flags/nearby_flags.h"
|
||||
#include "internal/network/url.h"
|
||||
#include "internal/platform/clock.h"
|
||||
#include "internal/platform/device_info.h"
|
||||
#include "internal/platform/implementation/device_info.h"
|
||||
#include "internal/platform/task_runner.h"
|
||||
#include "proto/sharing_enums.pb.h"
|
||||
@@ -281,7 +280,7 @@ NearbySharingServiceImpl::NearbySharingServiceImpl(
|
||||
|
||||
is_shutting_down_ = std::make_unique<bool>(false);
|
||||
FilePath profile_path =
|
||||
device_info_.GetAppDataPath().append(FilePath(kProfileRelativePath));
|
||||
device_info_.GetLocalAppDataPath(FilePath(kProfileRelativePath));
|
||||
|
||||
certificate_manager_ = NearbyShareCertificateManagerImpl::Factory::Create(
|
||||
context_, sharing_platform, local_device_data_manager_.get(),
|
||||
@@ -2692,15 +2691,16 @@ void NearbySharingServiceImpl::OnReceivedIntroduction(
|
||||
session.session_id(), session.share_target(),
|
||||
/*referrer_package=*/std::nullopt, session.os_type());
|
||||
|
||||
if (IsOutOfStorage(device_info_, save_path,
|
||||
session.attachment_container().GetStorageSize())) {
|
||||
std::optional<size_t> available_storage =
|
||||
device_info_.GetAvailableDiskSpaceInBytes(save_path);
|
||||
if (available_storage.has_value() &&
|
||||
*available_storage <= session.attachment_container().GetStorageSize()) {
|
||||
Fail(session, TransferMetadata::Status::kNotEnoughSpace);
|
||||
LOG(WARNING) << __func__
|
||||
<< ": Not enough space on the receiver. We have informed "
|
||||
<< session.share_target().id;
|
||||
return;
|
||||
}
|
||||
|
||||
OnStorageCheckCompleted(session);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
#include "absl/time/time.h"
|
||||
#include "absl/types/span.h"
|
||||
#include "internal/platform/clock.h"
|
||||
#include "internal/platform/device_info.h"
|
||||
#include "internal/platform/implementation/device_info.h"
|
||||
#include "internal/platform/task_runner.h"
|
||||
#include "proto/sharing_enums.pb.h"
|
||||
#include "sharing/advertisement.h"
|
||||
@@ -425,7 +425,7 @@ class NearbySharingServiceImpl
|
||||
// Used to run nearby sharing service APIs.
|
||||
std::unique_ptr<TaskRunner> service_thread_;
|
||||
Context* const context_;
|
||||
nearby::DeviceInfo& device_info_;
|
||||
nearby::api::DeviceInfo& device_info_;
|
||||
nearby::sharing::api::PreferenceManager& preference_manager_;
|
||||
AccountManager& account_manager_;
|
||||
// Used to create analytics events.
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "internal/platform/clock.h"
|
||||
#include "internal/platform/device_info.h"
|
||||
#include "internal/platform/implementation/device_info.h"
|
||||
#include "proto/sharing_enums.pb.h"
|
||||
#include "sharing/analytics/analytics_recorder.h"
|
||||
#include "sharing/common/nearby_share_enums.h"
|
||||
@@ -69,8 +69,8 @@ ShowNotificationStatus GetNotificationStatus(
|
||||
} // namespace
|
||||
|
||||
NearbyShareSettings::NearbyShareSettings(
|
||||
Context* context, nearby::Clock* clock, nearby::DeviceInfo& device_info,
|
||||
PreferenceManager& preference_manager,
|
||||
Context* context, nearby::Clock* clock,
|
||||
nearby::api::DeviceInfo& device_info, PreferenceManager& preference_manager,
|
||||
NearbyShareLocalDeviceDataManager* local_device_data_manager,
|
||||
analytics::AnalyticsRecorder* analytics_recorder)
|
||||
: context_(context),
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include "absl/time/time.h"
|
||||
#include "internal/base/observer_list.h"
|
||||
#include "internal/platform/clock.h"
|
||||
#include "internal/platform/device_info.h"
|
||||
#include "internal/platform/implementation/device_info.h"
|
||||
#include "proto/sharing_enums.pb.h"
|
||||
#include "sharing/analytics/analytics_recorder.h"
|
||||
#include "sharing/common/nearby_share_enums.h"
|
||||
@@ -138,7 +138,8 @@ class NearbyShareSettings
|
||||
};
|
||||
|
||||
NearbyShareSettings(
|
||||
Context* context, nearby::Clock* clock, nearby::DeviceInfo& device_info,
|
||||
Context* context, nearby::Clock* clock,
|
||||
nearby::api::DeviceInfo& device_info,
|
||||
nearby::sharing::api::PreferenceManager& preference_manager,
|
||||
NearbyShareLocalDeviceDataManager* local_device_data_manager,
|
||||
analytics::AnalyticsRecorder* analytics_recorder = nullptr);
|
||||
@@ -220,7 +221,7 @@ class NearbyShareSettings
|
||||
mutable absl::Mutex mutex_;
|
||||
Context* context_;
|
||||
nearby::Clock* const clock_;
|
||||
nearby::DeviceInfo& device_info_;
|
||||
nearby::api::DeviceInfo& device_info_;
|
||||
nearby::sharing::api::PreferenceManager& preference_manager_;
|
||||
NearbyShareLocalDeviceDataManager* const local_device_data_manager_;
|
||||
// Used to create analytics events.
|
||||
|
||||
@@ -14,10 +14,7 @@
|
||||
|
||||
#include "sharing/nearby_sharing_util.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -26,8 +23,6 @@
|
||||
#include "absl/strings/escaping.h"
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/base/file_path.h"
|
||||
#include "internal/platform/device_info.h"
|
||||
#include "proto/sharing_enums.pb.h"
|
||||
#include "sharing/advertisement.h"
|
||||
#include "sharing/certificates/nearby_share_decrypted_public_certificate.h"
|
||||
@@ -115,16 +110,4 @@ std::string GetDeviceId(
|
||||
return std::string(endpoint_id);
|
||||
}
|
||||
|
||||
bool IsOutOfStorage(DeviceInfo& device_info, FilePath file_path,
|
||||
int64_t storage_required) {
|
||||
std::optional<size_t> available_storage =
|
||||
device_info.GetAvailableDiskSpaceInBytes(file_path);
|
||||
|
||||
if (!available_storage.has_value()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return *available_storage <= storage_required;
|
||||
}
|
||||
|
||||
} // namespace nearby::sharing
|
||||
|
||||
@@ -21,23 +21,13 @@
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/platform/device_info.h"
|
||||
#include "proto/sharing_enums.pb.h"
|
||||
#include "internal/base/file_path.h"
|
||||
#include "sharing/advertisement.h"
|
||||
#include "sharing/certificates/nearby_share_decrypted_public_certificate.h"
|
||||
#include "sharing/common/nearby_share_enums.h"
|
||||
|
||||
namespace nearby::sharing {
|
||||
|
||||
// Checks whether having enough disk space for required storage.
|
||||
//
|
||||
// device_info - Nearby Share DeviceInfo
|
||||
// file_path - The path is to store sharing contents.
|
||||
// storage_required - required storage space.
|
||||
bool IsOutOfStorage(nearby::DeviceInfo& device_info, FilePath file_path,
|
||||
int64_t storage_required);
|
||||
|
||||
// Decodes certificate to find MAC address encoded in it.
|
||||
std::optional<std::vector<uint8_t>> GetBluetoothMacAddressFromCertificate(
|
||||
const NearbyShareDecryptedPublicCertificate& certificate);
|
||||
|
||||
Reference in New Issue
Block a user