From aa589203e0b26ee52c3a27b6d94413b067006b6c Mon Sep 17 00:00:00 2001 From: Francis Tsui Date: Mon, 21 Oct 2024 15:36:08 -0700 Subject: [PATCH] Remove unused deviceInfo methods. PiperOrigin-RevId: 688296309 --- internal/platform/device_info.h | 3 - internal/platform/device_info_impl.cc | 12 -- internal/platform/device_info_impl.h | 3 - .../implementation/apple/device_info.h | 3 - .../implementation/apple/device_info.mm | 3 - .../platform/implementation/device_info.h | 3 - .../platform/implementation/g3/device_info.h | 9 -- .../implementation/windows/device_info.cc | 126 ------------------ .../implementation/windows/device_info.h | 3 - .../windows/device_info_test.cc | 14 -- internal/test/fake_device_info.h | 36 ----- internal/test/fake_device_info_test.cc | 24 ---- ...fake_nearby_share_profile_info_provider.cc | 5 - .../fake_nearby_share_profile_info_provider.h | 2 - .../nearby_share_profile_info_provider.h | 4 - ...nearby_share_profile_info_provider_impl.cc | 5 - .../nearby_share_profile_info_provider_impl.h | 1 - ...y_share_profile_info_provider_impl_test.cc | 24 ---- 18 files changed, 280 deletions(-) diff --git a/internal/platform/device_info.h b/internal/platform/device_info.h index c34544792a0..8e913ad2657 100644 --- a/internal/platform/device_info.h +++ b/internal/platform/device_info.h @@ -34,10 +34,7 @@ class DeviceInfo { virtual std::string GetOsDeviceName() const = 0; virtual api::DeviceInfo::DeviceType GetDeviceType() const = 0; virtual api::DeviceInfo::OsType GetOsType() const = 0; - virtual std::optional GetFullName() const = 0; virtual std::optional GetGivenName() const = 0; - virtual std::optional GetLastName() const = 0; - virtual std::optional GetProfileUserName() const = 0; virtual std::filesystem::path GetDownloadPath() const = 0; virtual std::filesystem::path GetAppDataPath() const = 0; diff --git a/internal/platform/device_info_impl.cc b/internal/platform/device_info_impl.cc index 868687d31bb..915b91a9523 100644 --- a/internal/platform/device_info_impl.cc +++ b/internal/platform/device_info_impl.cc @@ -43,22 +43,10 @@ api::DeviceInfo::OsType DeviceInfoImpl::GetOsType() const { return device_info_impl_->GetOsType(); } -std::optional DeviceInfoImpl::GetFullName() const { - return device_info_impl_->GetFullName(); -} - std::optional DeviceInfoImpl::GetGivenName() const { return device_info_impl_->GetGivenName(); } -std::optional DeviceInfoImpl::GetLastName() const { - return device_info_impl_->GetLastName(); -} - -std::optional DeviceInfoImpl::GetProfileUserName() const { - return device_info_impl_->GetProfileUserName(); -} - std::filesystem::path DeviceInfoImpl::GetDownloadPath() const { std::optional path = device_info_impl_->GetDownloadPath(); diff --git a/internal/platform/device_info_impl.h b/internal/platform/device_info_impl.h index b9401c51187..eb50f3e7092 100644 --- a/internal/platform/device_info_impl.h +++ b/internal/platform/device_info_impl.h @@ -38,10 +38,7 @@ class DeviceInfoImpl : public DeviceInfo { api::DeviceInfo::DeviceType GetDeviceType() const override; api::DeviceInfo::OsType GetOsType() const override; - std::optional GetFullName() const override; std::optional GetGivenName() const override; - std::optional GetLastName() const override; - std::optional GetProfileUserName() const override; std::filesystem::path GetDownloadPath() const override; std::filesystem::path GetAppDataPath() const override; diff --git a/internal/platform/implementation/apple/device_info.h b/internal/platform/implementation/apple/device_info.h index 753f166ac9a..2a238989853 100644 --- a/internal/platform/implementation/apple/device_info.h +++ b/internal/platform/implementation/apple/device_info.h @@ -34,10 +34,7 @@ class DeviceInfo : public api::DeviceInfo { api::DeviceInfo::OsType GetOsType() const override; - std::optional GetFullName() const override; std::optional GetGivenName() const override; - std::optional GetLastName() const override; - std::optional GetProfileUserName() const override; std::optional GetDownloadPath() const override; diff --git a/internal/platform/implementation/apple/device_info.mm b/internal/platform/implementation/apple/device_info.mm index 780dbc8fdc3..885ad93bd9c 100644 --- a/internal/platform/implementation/apple/device_info.mm +++ b/internal/platform/implementation/apple/device_info.mm @@ -78,10 +78,7 @@ #endif } -std::optional DeviceInfo::GetFullName() const { return std::nullopt; } std::optional DeviceInfo::GetGivenName() const { return std::nullopt; } -std::optional DeviceInfo::GetLastName() const { return std::nullopt; } -std::optional DeviceInfo::GetProfileUserName() const { return std::nullopt; } std::optional DeviceInfo::GetDownloadPath() const { NSFileManager *manager = [NSFileManager defaultManager]; diff --git a/internal/platform/implementation/device_info.h b/internal/platform/implementation/device_info.h index 9c529df0da1..05fc160fccf 100644 --- a/internal/platform/implementation/device_info.h +++ b/internal/platform/implementation/device_info.h @@ -46,10 +46,7 @@ class DeviceInfo { virtual OsType GetOsType() const = 0; // Gets basic information of current user. - virtual std::optional GetFullName() const = 0; virtual std::optional GetGivenName() const = 0; - virtual std::optional GetLastName() const = 0; - virtual std::optional GetProfileUserName() const = 0; // Gets known paths of current user. virtual std::optional GetDownloadPath() const = 0; diff --git a/internal/platform/implementation/g3/device_info.h b/internal/platform/implementation/g3/device_info.h index 8b865916cd6..9b2ad21b9f7 100644 --- a/internal/platform/implementation/g3/device_info.h +++ b/internal/platform/implementation/g3/device_info.h @@ -42,18 +42,9 @@ class DeviceInfo : public api::DeviceInfo { return api::DeviceInfo::OsType::kChromeOs; } - std::optional GetFullName() const override { - return "nearby"; - } std::optional GetGivenName() const override { return "nearby"; } - std::optional GetLastName() const override { - return "nearby"; - } - std::optional GetProfileUserName() const override { - return "nearby"; - } std::optional GetDownloadPath() const override { return std::filesystem::temp_directory_path(); diff --git a/internal/platform/implementation/windows/device_info.cc b/internal/platform/implementation/windows/device_info.cc index eb28fc76996..236ce63bf2d 100644 --- a/internal/platform/implementation/windows/device_info.cc +++ b/internal/platform/implementation/windows/device_info.cc @@ -84,48 +84,6 @@ api::DeviceInfo::OsType DeviceInfo::GetOsType() const { return api::DeviceInfo::OsType::kWindows; } -std::optional DeviceInfo::GetFullName() const { - // FindAllAsync finds all users that are using this app. When we "Switch User" - // on Desktop,FindAllAsync() will still return the current user instead of all - // of them because the users who are switched out are not using the apps of - // the user who is switched in, so FindAllAsync() will not find them. (Under - // the UWP application model, each process runs under its own user account. - // That user account is different from the user account of the logged-in user. - // Processes aren't owned by the logged-in user for purposes of isolation.) - IVectorView users = - User::FindAllAsync(UserType::LocalUser, - UserAuthenticationStatus::LocallyAuthenticated) - .get(); - if (users == nullptr) { - LOG(ERROR) << __func__ << ": Error retrieving locally authenticated user."; - return std::nullopt; - } - - // On Windows Desktop apps, the first Windows.System.User instance - // returned in the IVectorView is always the current user. - // https://github.com/microsoft/Windows-task-snippets/blob/master/tasks/User-info.md - User current_user = users.GetAt(0); - - // Retrieve the human-readable properties for the current user - IAsyncOperation full_name_obj_async = - current_user.GetPropertyAsync(KnownUserProperties::DisplayName()); - IInspectable full_name_obj = full_name_obj_async.get(); - if (full_name_obj == nullptr) { - LOG(ERROR) << __func__ << ": Error retrieving full name of user."; - return std::nullopt; - } - winrt::hstring full_name = full_name_obj.as(); - std::string full_name_str = winrt::to_string(full_name); - - if (full_name_str.empty()) { - LOG(ERROR) << __func__ - << ": Error unboxing string value for full name of user."; - return std::nullopt; - } - - return full_name_str; -} - std::optional DeviceInfo::GetGivenName() const { // FindAllAsync finds all users that are using this app. When we "Switch User" // on Desktop,FindAllAsync() will still return the current user instead of all @@ -168,90 +126,6 @@ std::optional DeviceInfo::GetGivenName() const { return given_name_str; } -std::optional DeviceInfo::GetLastName() const { - // FindAllAsync finds all users that are using this app. When we "Switch User" - // on Desktop,FindAllAsync() will still return the current user instead of all - // of them because the users who are switched out are not using the apps of - // the user who is switched in, so FindAllAsync() will not find them. (Under - // the UWP application model, each process runs under its own user account. - // That user account is different from the user account of the logged-in user. - // Processes aren't owned by the logged-in user for purposes of isolation.) - IVectorView users = - User::FindAllAsync(UserType::LocalUser, - UserAuthenticationStatus::LocallyAuthenticated) - .get(); - if (users == nullptr) { - LOG(ERROR) << __func__ << ": Error retrieving locally authenticated user."; - return std::nullopt; - } - - // On Windows Desktop apps, the first Windows.System.User instance - // returned in the IVectorView is always the current user. - // https://github.com/microsoft/Windows-task-snippets/blob/master/tasks/User-info.md - User current_user = users.GetAt(0); - - // Retrieve the human-readable properties for the current user - IAsyncOperation last_name_obj_async = - current_user.GetPropertyAsync(KnownUserProperties::LastName()); - IInspectable last_name_obj = last_name_obj_async.get(); - if (last_name_obj == nullptr) { - LOG(ERROR) << __func__ << ": Error retrieving last name of user."; - return std::nullopt; - } - winrt::hstring last_name = last_name_obj.as(); - std::string last_name_str = winrt::to_string(last_name); - - if (last_name_str.empty()) { - LOG(ERROR) << __func__ - << ": Error unboxing string value for last name of user."; - return std::nullopt; - } - - return last_name_str; -} - -std::optional DeviceInfo::GetProfileUserName() const { - // FindAllAsync finds all users that are using this app. When we "Switch User" - // on Desktop,FindAllAsync() will still return the current user instead of all - // of them because the users who are switched out are not using the apps of - // the user who is switched in, so FindAllAsync() will not find them. (Under - // the UWP application model, each process runs under its own user account. - // That user account is different from the user account of the logged-in user. - // Processes aren't owned by the logged-in user for purposes of isolation.) - IVectorView users = - User::FindAllAsync(UserType::LocalUser, - UserAuthenticationStatus::LocallyAuthenticated) - .get(); - if (users == nullptr) { - LOG(ERROR) << __func__ << ": Error retrieving locally authenticated user."; - return std::nullopt; - } - - // On Windows Desktop apps, the first Windows.System.User instance - // returned in the IVectorView is always the current user. - // https://github.com/microsoft/Windows-task-snippets/blob/master/tasks/User-info.md - User current_user = users.GetAt(0); - - // Retrieve the human-readable properties for the current user - IAsyncOperation account_name_obj_async = - current_user.GetPropertyAsync(KnownUserProperties::AccountName()); - IInspectable account_name_obj = account_name_obj_async.get(); - if (account_name_obj == nullptr) { - LOG(ERROR) << __func__ << ": Error retrieving account name of user."; - return std::nullopt; - } - winrt::hstring account_name = account_name_obj.as(); - std::string account_name_string = winrt::to_string(account_name); - - if (account_name_string.empty()) { - LOG(ERROR) << __func__ - << ": Error unboxing string value for profile username of user."; - return std::nullopt; - } - - return account_name_string; -} - std::optional DeviceInfo::GetDownloadPath() const { PWSTR path; HRESULT result = diff --git a/internal/platform/implementation/windows/device_info.h b/internal/platform/implementation/windows/device_info.h index ced7ddbd69a..dbd8153b45c 100644 --- a/internal/platform/implementation/windows/device_info.h +++ b/internal/platform/implementation/windows/device_info.h @@ -34,10 +34,7 @@ class DeviceInfo : public api::DeviceInfo { std::optional GetOsDeviceName() const override; api::DeviceInfo::DeviceType GetDeviceType() const override; api::DeviceInfo::OsType GetOsType() const override; - std::optional GetFullName() const override; std::optional GetGivenName() const override; - std::optional GetLastName() const override; - std::optional GetProfileUserName() const override; std::optional GetDownloadPath() const override; std::optional GetLocalAppDataPath() const override; diff --git a/internal/platform/implementation/windows/device_info_test.cc b/internal/platform/implementation/windows/device_info_test.cc index d19c4370ed6..59f344c4725 100644 --- a/internal/platform/implementation/windows/device_info_test.cc +++ b/internal/platform/implementation/windows/device_info_test.cc @@ -14,11 +14,8 @@ #include "internal/platform/implementation/windows/device_info.h" -#include -#include #include "gtest/gtest.h" -#include "absl/synchronization/notification.h" #include "internal/platform/implementation/device_info.h" namespace nearby { @@ -37,21 +34,10 @@ TEST(DeviceInfo, GetOsType) { EXPECT_EQ(DeviceInfo().GetOsType(), api::DeviceInfo::OsType::kWindows); } -TEST(DeviceInfo, DISABLED_GetFullName) { - EXPECT_TRUE(DeviceInfo().GetFullName().has_value()); -} - TEST(DeviceInfo, DISABLED_GetGivenName) { EXPECT_TRUE(DeviceInfo().GetGivenName().has_value()); } -TEST(DeviceInfo, DISABLED_GetLastName) { - EXPECT_TRUE(DeviceInfo().GetLastName().has_value()); -} - -TEST(DeviceInfo, DISABLED_GetProfileUserName) { - EXPECT_TRUE(DeviceInfo().GetProfileUserName().has_value()); -} TEST(DeviceInfo, DISABLED_GetLocalAppDataPath) { EXPECT_TRUE(DeviceInfo().GetLocalAppDataPath().has_value()); diff --git a/internal/test/fake_device_info.h b/internal/test/fake_device_info.h index 0e15a0559ad..b6975d9324d 100644 --- a/internal/test/fake_device_info.h +++ b/internal/test/fake_device_info.h @@ -40,18 +40,9 @@ class FakeDeviceInfo : public DeviceInfo { api::DeviceInfo::OsType GetOsType() const override { return os_type_; } - std::optional GetFullName() const override { - return full_name_; - } std::optional GetGivenName() const override { return given_name_; } - std::optional GetLastName() const override { - return last_name_; - } - std::optional GetProfileUserName() const override { - return profile_user_name_; - } std::filesystem::path GetDownloadPath() const override { return download_path_; @@ -105,14 +96,6 @@ class FakeDeviceInfo : public DeviceInfo { void SetOsType(api::DeviceInfo::OsType os_type) { os_type_ = os_type; } - void SetFullName(std::optional full_name) { - if (full_name.has_value() && !full_name->empty()) { - full_name_ = full_name; - } else { - full_name_ = std::nullopt; - } - } - void SetGivenName(std::optional given_name) { if (given_name.has_value() && !given_name->empty()) { given_name_ = given_name; @@ -121,22 +104,6 @@ class FakeDeviceInfo : public DeviceInfo { } } - void SetLastName(std::optional last_name) { - if (last_name.has_value() && !last_name->empty()) { - last_name_ = last_name; - } else { - last_name_ = std::nullopt; - } - } - - void SetProfileUserName(std::optional profile_user_name) { - if (profile_user_name.has_value() && !profile_user_name->empty()) { - profile_user_name_ = profile_user_name; - } else { - profile_user_name_ = std::nullopt; - } - } - void SetDownloadPath(std::filesystem::path path) { download_path_ = path; } void SetAppDataPath(std::filesystem::path path) { app_data_path_ = path; } @@ -166,10 +133,7 @@ class FakeDeviceInfo : public DeviceInfo { api::DeviceInfo::DeviceType device_type_ = api::DeviceInfo::DeviceType::kLaptop; api::DeviceInfo::OsType os_type_ = api::DeviceInfo::OsType::kWindows; - std::optional full_name_ = "Nearby"; std::optional given_name_ = "Nearby"; - std::optional last_name_ = "Nearby"; - std::optional profile_user_name_ = "nearby"; std::filesystem::path download_path_ = std::filesystem::temp_directory_path(); std::filesystem::path app_data_path_ = std::filesystem::temp_directory_path(); std::filesystem::path temp_path_ = std::filesystem::temp_directory_path(); diff --git a/internal/test/fake_device_info_test.cc b/internal/test/fake_device_info_test.cc index 1a5f120f264..05449289d42 100644 --- a/internal/test/fake_device_info_test.cc +++ b/internal/test/fake_device_info_test.cc @@ -43,14 +43,6 @@ TEST(FakeDeviceInfo, OsType) { EXPECT_EQ(device_info.GetOsType(), api::DeviceInfo::OsType::kWindows); } -TEST(FakeDeviceInfo, FullName) { - FakeDeviceInfo device_info; - device_info.SetFullName("windows"); - EXPECT_EQ(device_info.GetFullName(), "windows"); - device_info.SetFullName(std::nullopt); - EXPECT_FALSE(device_info.GetFullName().has_value()); -} - TEST(FakeDeviceInfo, GivenName) { FakeDeviceInfo device_info; device_info.SetGivenName("windows"); @@ -59,22 +51,6 @@ TEST(FakeDeviceInfo, GivenName) { EXPECT_FALSE(device_info.GetGivenName().has_value()); } -TEST(FakeDeviceInfo, LastName) { - FakeDeviceInfo device_info; - device_info.SetLastName("windows"); - EXPECT_EQ(device_info.GetLastName(), "windows"); - device_info.SetLastName(std::nullopt); - EXPECT_FALSE(device_info.GetLastName().has_value()); -} - -TEST(FakeDeviceInfo, ProfileUserName) { - FakeDeviceInfo device_info; - device_info.SetProfileUserName("windows"); - EXPECT_EQ(device_info.GetProfileUserName(), "windows"); - device_info.SetProfileUserName(std::nullopt); - EXPECT_FALSE(device_info.GetProfileUserName().has_value()); -} - TEST(FakeDeviceInfo, GetDownloadPath) { FakeDeviceInfo device_info; EXPECT_EQ(device_info.GetDownloadPath(), diff --git a/sharing/common/fake_nearby_share_profile_info_provider.cc b/sharing/common/fake_nearby_share_profile_info_provider.cc index 97abfec1d63..e0290a90e98 100644 --- a/sharing/common/fake_nearby_share_profile_info_provider.cc +++ b/sharing/common/fake_nearby_share_profile_info_provider.cc @@ -31,10 +31,5 @@ std::optional FakeNearbyShareProfileInfoProvider::GetGivenName() return given_name_; } -std::optional -FakeNearbyShareProfileInfoProvider::GetProfileUserName() const { - return profile_user_name_; -} - } // namespace sharing } // namespace nearby diff --git a/sharing/common/fake_nearby_share_profile_info_provider.h b/sharing/common/fake_nearby_share_profile_info_provider.h index b0f6ec240dd..14ba91fac15 100644 --- a/sharing/common/fake_nearby_share_profile_info_provider.h +++ b/sharing/common/fake_nearby_share_profile_info_provider.h @@ -31,7 +31,6 @@ class FakeNearbyShareProfileInfoProvider // NearbyShareProfileInfoProvider: std::optional GetGivenName() const override; - std::optional GetProfileUserName() const override; void set_given_name(const std::optional& given_name) { given_name_ = given_name; @@ -39,7 +38,6 @@ class FakeNearbyShareProfileInfoProvider private: std::optional given_name_; - std::optional profile_user_name_; }; } // namespace sharing diff --git a/sharing/common/nearby_share_profile_info_provider.h b/sharing/common/nearby_share_profile_info_provider.h index 0de5feb1bce..8cb28f179f3 100644 --- a/sharing/common/nearby_share_profile_info_provider.h +++ b/sharing/common/nearby_share_profile_info_provider.h @@ -28,10 +28,6 @@ class NearbyShareProfileInfoProvider { // Returns UTF-8 encoded given name of current account. // Returns absl::nullopt if a valid given name cannot be returned. virtual std::optional GetGivenName() const = 0; - - // Proxy for Profile::GetProfileUserName(). Returns absl::nullopt if a valid - // username cannot be returned. - virtual std::optional GetProfileUserName() const = 0; }; } // namespace sharing } // namespace nearby diff --git a/sharing/nearby_share_profile_info_provider_impl.cc b/sharing/nearby_share_profile_info_provider_impl.cc index e90d17900c3..bcace6fa633 100644 --- a/sharing/nearby_share_profile_info_provider_impl.cc +++ b/sharing/nearby_share_profile_info_provider_impl.cc @@ -43,10 +43,5 @@ std::optional NearbyShareProfileInfoProviderImpl::GetGivenName() return device_info_.GetGivenName(); } -std::optional -NearbyShareProfileInfoProviderImpl::GetProfileUserName() const { - return device_info_.GetProfileUserName(); -} - } // namespace sharing } // namespace nearby diff --git a/sharing/nearby_share_profile_info_provider_impl.h b/sharing/nearby_share_profile_info_provider_impl.h index b3133f2e84a..cbf71291963 100644 --- a/sharing/nearby_share_profile_info_provider_impl.h +++ b/sharing/nearby_share_profile_info_provider_impl.h @@ -40,7 +40,6 @@ class NearbyShareProfileInfoProviderImpl // NearbyShareProfileInfoProvider: std::optional GetGivenName() const override; - std::optional GetProfileUserName() const override; private: nearby::DeviceInfo& device_info_; diff --git a/sharing/nearby_share_profile_info_provider_impl_test.cc b/sharing/nearby_share_profile_info_provider_impl_test.cc index 5c498a9734c..39c51e64c03 100644 --- a/sharing/nearby_share_profile_info_provider_impl_test.cc +++ b/sharing/nearby_share_profile_info_provider_impl_test.cc @@ -30,7 +30,6 @@ constexpr char kTestAccountId[] = "test_account_id"; constexpr char kTestAccountGivenName[] = "given_name"; constexpr char kExpectedTestAccountGivenName[] = "given_name"; constexpr char kProfileGivenName[] = "Barack"; -constexpr char kProfileProfileUserName[] = "test@gmail.com"; } // namespace @@ -41,17 +40,12 @@ class NearbyShareProfileInfoProviderImplTest : public ::testing::Test { void SetUp() override { fake_device_info_.SetGivenName(std::nullopt); - fake_device_info_.SetProfileUserName(std::nullopt); } void SetUserGivenName(const std::string& name) { fake_device_info_.SetGivenName(name); } - void SetProfileUserName(const std::string& profile_user_name) { - fake_device_info_.SetProfileUserName(profile_user_name); - } - FakeDeviceInfo& fake_device_info() { return fake_device_info_; } @@ -64,7 +58,6 @@ class NearbyShareProfileInfoProviderImplTest : public ::testing::Test { }; TEST_F(NearbyShareProfileInfoProviderImplTest, GivenName) { - SetProfileUserName(kProfileProfileUserName); NearbyShareProfileInfoProviderImpl profile_info_provider( fake_device_info(), fake_account_manager()); @@ -79,23 +72,6 @@ TEST_F(NearbyShareProfileInfoProviderImplTest, GivenName) { EXPECT_EQ(profile_info_provider.GetGivenName(), kProfileGivenName); } -TEST_F(NearbyShareProfileInfoProviderImplTest, ProfileUserName) { - { - // If profile username is empty, return std::nullopt. - SetProfileUserName(std::string()); - NearbyShareProfileInfoProviderImpl profile_info_provider( - fake_device_info(), fake_account_manager()); - EXPECT_FALSE(profile_info_provider.GetProfileUserName()); - } - { - SetProfileUserName(kProfileProfileUserName); - NearbyShareProfileInfoProviderImpl profile_info_provider( - fake_device_info(), fake_account_manager()); - EXPECT_EQ(profile_info_provider.GetProfileUserName(), - kProfileProfileUserName); - } -} - TEST_F(NearbyShareProfileInfoProviderImplTest, GivenNameUseLoginAccount) { AccountManager::Account account; account.id = kTestAccountId;