Remove unnecessary DevicInfoImpl class.

PiperOrigin-RevId: 892102193
This commit is contained in:
Francis Tsui
2026-03-30 22:18:31 -07:00
committed by Copybara-Service
parent ac70b1f91f
commit f088ef3b74
29 changed files with 107 additions and 333 deletions
-1
View File
@@ -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());