diff --git a/services/service/include/devicenamemgr/device_name_manager.h b/services/service/include/devicenamemgr/device_name_manager.h index 20aa157bcd851f7e44fc9471ff9439045b59f375..20b3018bf29290be8008788ef64807fcdef54990 100644 --- a/services/service/include/devicenamemgr/device_name_manager.h +++ b/services/service/include/devicenamemgr/device_name_manager.h @@ -54,8 +54,8 @@ private: void RegisterDeviceNameChangeMonitor(int32_t curUserId, int32_t preUserId); void UnRegisterDeviceNameChangeMonitor(int32_t userId); void InitDeviceName(int32_t userId); - void InitDeviceNameToSoftBus(const std::string &prefixName, const std::string &subffixName); - std::string GetLocalDisplayDeviceName(const std::string &prefixName, const std::string &subffixName, + void InitDeviceNameToSoftBus(const std::string &prefixName, const std::string &suffixName); + std::string GetLocalDisplayDeviceName(const std::string &prefixName, const std::string &suffixName, int32_t maxNamelength); std::string SubstrByBytes(const std::string &str, int32_t maxNumBytes); diff --git a/services/service/src/devicenamemgr/device_name_manager.cpp b/services/service/src/devicenamemgr/device_name_manager.cpp index 59b30fab41e17a82f73e20c503edb5acd34bd658..fa0ced63ec41867e28379509a245bddd70b9109d 100644 --- a/services/service/src/devicenamemgr/device_name_manager.cpp +++ b/services/service/src/devicenamemgr/device_name_manager.cpp @@ -302,14 +302,14 @@ void DeviceNameManager::InitDeviceName(int32_t userId) InitDisplayDeviceNameToSettingsData(nickName, deviceName, userId); } -void DeviceNameManager::InitDeviceNameToSoftBus(const std::string &prefixName, const std::string &subffixName) -{ - LOGI("In prefixName:%{public}s, subffixName:%{public}s", - GetAnonyString(prefixName).c_str(), GetAnonyString(subffixName).c_str()); - std::string raw = GetLocalDisplayDeviceName(prefixName, subffixName, 0); - std::string name18 = GetLocalDisplayDeviceName(prefixName, subffixName, NUM18); - std::string name21 = GetLocalDisplayDeviceName(prefixName, subffixName, NUM21); - std::string name24 = GetLocalDisplayDeviceName(prefixName, subffixName, NUM24); +void DeviceNameManager::InitDeviceNameToSoftBus(const std::string &prefixName, const std::string &suffixName) +{ + LOGI("In prefixName:%{public}s, suffixName:%{public}s", + GetAnonyString(prefixName).c_str(), GetAnonyString(suffixName).c_str()); + std::string raw = GetLocalDisplayDeviceName(prefixName, suffixName, 0); + std::string name18 = GetLocalDisplayDeviceName(prefixName, suffixName, NUM18); + std::string name21 = GetLocalDisplayDeviceName(prefixName, suffixName, NUM21); + std::string name24 = GetLocalDisplayDeviceName(prefixName, suffixName, NUM24); cJSON *root = cJSON_CreateObject(); if (root == NULL) { LOGE("cJSON_CreateObject fail!"); @@ -351,14 +351,14 @@ int32_t DeviceNameManager::GetLocalDisplayDeviceName(int32_t maxNamelength, std: return DM_OK; } -std::string DeviceNameManager::GetLocalDisplayDeviceName(const std::string &prefixName, const std::string &subffixName, +std::string DeviceNameManager::GetLocalDisplayDeviceName(const std::string &prefixName, const std::string &suffixName, int32_t maxNameLength) { if (prefixName.empty()) { - if (maxNameLength == 0 || static_cast(subffixName.size()) <= maxNameLength) { - return subffixName; + if (maxNameLength == 0 || static_cast(suffixName.size()) <= maxNameLength) { + return suffixName; } - return SubstrByBytes(subffixName, maxNameLength - NUM3) + DEFAULT_CONCATENATION_CHARACTER; + return SubstrByBytes(suffixName, maxNameLength - NUM3) + DEFAULT_CONCATENATION_CHARACTER; } int32_t defaultNameMaxLength = DEFAULT_DEVICE_NAME_MAX_LENGTH; if (maxNameLength >= NUM21) { @@ -368,13 +368,13 @@ std::string DeviceNameManager::GetLocalDisplayDeviceName(const std::string &pref if (GetSystemLanguage() != LANGUAGE_ZH_HANS || GetSystemRegion() != LOCAL_ZH_HANS_CN) { nameSeparator = NAME_SEPARATOR_OTHER; } - std::string displayName = prefixName + nameSeparator + subffixName; + std::string displayName = prefixName + nameSeparator + suffixName; if (maxNameLength == 0 || static_cast(displayName.size()) <= maxNameLength) { return displayName; } - std::string subffix = subffixName; - if (static_cast(subffixName.size()) > defaultNameMaxLength) { - subffix = SubstrByBytes(subffixName, defaultNameMaxLength - NUM3) + DEFAULT_CONCATENATION_CHARACTER; + std::string subffix = suffixName; + if (static_cast(suffixName.size()) > defaultNameMaxLength) { + subffix = SubstrByBytes(suffixName, defaultNameMaxLength - NUM3) + DEFAULT_CONCATENATION_CHARACTER; } int32_t remainingLen = maxNameLength - static_cast(subffix.size()); if (remainingLen <= 0) { diff --git a/test/servicesfuzztest/devicenamemanager_fuzzer/device_name_manager_fuzzer.cpp b/test/servicesfuzztest/devicenamemanager_fuzzer/device_name_manager_fuzzer.cpp index c0092282cb6a3b91b8dce0cee8ae5d4449a18378..e10fbb06463fbec81ef89389ef66a3f53317b910 100644 --- a/test/servicesfuzztest/devicenamemanager_fuzzer/device_name_manager_fuzzer.cpp +++ b/test/servicesfuzztest/devicenamemanager_fuzzer/device_name_manager_fuzzer.cpp @@ -56,8 +56,8 @@ void DeviceNameManagerFuzzTest(const uint8_t* data, size_t size) deviceNameMgr_->InitDeviceName(-1); std::string prefixName(reinterpret_cast(data), size); - std::string subffixName(reinterpret_cast(data), size); - deviceNameMgr_->InitDeviceNameToSoftBus(prefixName, subffixName); + std::string suffixName(reinterpret_cast(data), size); + deviceNameMgr_->InitDeviceNameToSoftBus(prefixName, suffixName); int32_t maxNamelength = fdp.ConsumeIntegral(); std::string displayName(reinterpret_cast(data), size); diff --git a/test/unittest/UTTest_device_name_manager.cpp b/test/unittest/UTTest_device_name_manager.cpp index 4351f7513c40f9ac03db02c640599c605bdb0ab9..abe29b3bfcfc491d29f485fe22a69dc7debcfd36 100644 --- a/test/unittest/UTTest_device_name_manager.cpp +++ b/test/unittest/UTTest_device_name_manager.cpp @@ -64,7 +64,7 @@ HWTEST_F(DeviceNameManagerTest, Init_001, testing::ext::TestSize.Level1) ASSERT_TRUE(multipleUserConnector_ != nullptr); ASSERT_TRUE(helper_ != nullptr); - std::string subffixName = "手机"; + std::string suffixName = "手机"; auto bundleMgr = sptr(new (std::nothrow) BundleMgrMock()); auto systemAbilityManager = sptr(new (std::nothrow) SystemAbilityManagerMock()); EXPECT_CALL(*systemAbilityManager, GetSystemAbility(_)) @@ -78,7 +78,7 @@ HWTEST_F(DeviceNameManagerTest, Init_001, testing::ext::TestSize.Level1) EXPECT_CALL(*resultSet, GetRowCount(_)).WillRepeatedly(DoAll(SetArgReferee<0>(1), Return(DataShare::E_OK))); EXPECT_CALL(*resultSet, GetString(_, _)).WillRepeatedly( - DoAll(SetArgReferee<1>(subffixName), Return(DataShare::E_OK))); + DoAll(SetArgReferee<1>(suffixName), Return(DataShare::E_OK))); DeviceNameManager::GetInstance().InitDeviceNameWhenSoftBusReady(); DeviceNameManager::GetInstance().UnInit(); @@ -94,7 +94,7 @@ HWTEST_F(DeviceNameManagerTest, InitDeviceNameWhenUserSwitch_001, testing::ext:: ASSERT_TRUE(multipleUserConnector_ != nullptr); ASSERT_TRUE(helper_ != nullptr); - std::string subffixName = "手机"; + std::string suffixName = "手机"; int32_t curUserId = DEFAULT_VALUABLE_USER_ID + 1; int32_t preUserId = DEFAULT_VALUABLE_USER_ID; auto bundleMgr = sptr(new (std::nothrow) BundleMgrMock()); @@ -110,7 +110,7 @@ HWTEST_F(DeviceNameManagerTest, InitDeviceNameWhenUserSwitch_001, testing::ext:: EXPECT_CALL(*resultSet, GetRowCount(_)).WillRepeatedly(DoAll(SetArgReferee<0>(1), Return(DataShare::E_OK))); EXPECT_CALL(*resultSet, GetString(_, _)).WillRepeatedly( - DoAll(SetArgReferee<1>(subffixName), Return(DataShare::E_OK))); + DoAll(SetArgReferee<1>(suffixName), Return(DataShare::E_OK))); DeviceNameManager::GetInstance().InitDeviceNameWhenSoftBusReady(); DeviceNameManager::GetInstance().InitDeviceNameWhenUserSwitch(curUserId, preUserId); @@ -126,7 +126,7 @@ HWTEST_F(DeviceNameManagerTest, InitDeviceNameWhenUserSwitch_002, testing::ext:: ASSERT_TRUE(client_ != nullptr); ASSERT_TRUE(helper_ != nullptr); - std::string subffixName = "手机"; + std::string suffixName = "手机"; int32_t curUserId = DEFAULT_USER_ID; int32_t preUserId = DEFAULT_USER_ID; @@ -142,7 +142,7 @@ HWTEST_F(DeviceNameManagerTest, InitDeviceNameWhenUserSwitch_002, testing::ext:: EXPECT_CALL(*resultSet, GetRowCount(_)).WillRepeatedly(DoAll(SetArgReferee<0>(1), Return(DataShare::E_OK))); EXPECT_CALL(*resultSet, GetString(_, _)).WillRepeatedly( - DoAll(SetArgReferee<1>(subffixName), Return(DataShare::E_OK))); + DoAll(SetArgReferee<1>(suffixName), Return(DataShare::E_OK))); DeviceNameManager::GetInstance().InitDeviceNameWhenUserSwitch(curUserId, preUserId); DeviceNameManager::GetInstance().UnInit(); @@ -158,7 +158,7 @@ HWTEST_F(DeviceNameManagerTest, InitDeviceNameWhenLogout_001, testing::ext::Test ASSERT_TRUE(multipleUserConnector_ != nullptr); ASSERT_TRUE(helper_ != nullptr); - std::string subffixName = "手机"; + std::string suffixName = "手机"; auto bundleMgr = sptr(new (std::nothrow) BundleMgrMock()); auto systemAbilityManager = sptr(new (std::nothrow) SystemAbilityManagerMock()); EXPECT_CALL(*systemAbilityManager, GetSystemAbility(_)) @@ -172,7 +172,7 @@ HWTEST_F(DeviceNameManagerTest, InitDeviceNameWhenLogout_001, testing::ext::Test EXPECT_CALL(*resultSet, GetRowCount(_)).WillRepeatedly(DoAll(SetArgReferee<0>(1), Return(DataShare::E_OK))); EXPECT_CALL(*resultSet, GetString(_, _)).WillRepeatedly( - DoAll(SetArgReferee<1>(subffixName), Return(DataShare::E_OK))); + DoAll(SetArgReferee<1>(suffixName), Return(DataShare::E_OK))); DeviceNameManager::GetInstance().InitDeviceNameWhenLogout(); DeviceNameManager::GetInstance().UnInit(); @@ -188,7 +188,7 @@ HWTEST_F(DeviceNameManagerTest, InitDeviceNameWhenLogin_001, testing::ext::TestS ASSERT_TRUE(multipleUserConnector_ != nullptr); ASSERT_TRUE(helper_ != nullptr); - std::string subffixName = "手机"; + std::string suffixName = "手机"; auto bundleMgr = sptr(new (std::nothrow) BundleMgrMock()); auto systemAbilityManager = sptr(new (std::nothrow) SystemAbilityManagerMock()); EXPECT_CALL(*systemAbilityManager, GetSystemAbility(_)) @@ -202,7 +202,7 @@ HWTEST_F(DeviceNameManagerTest, InitDeviceNameWhenLogin_001, testing::ext::TestS EXPECT_CALL(*resultSet, GetRowCount(_)).WillRepeatedly(DoAll(SetArgReferee<0>(1), Return(DataShare::E_OK))); EXPECT_CALL(*resultSet, GetString(_, _)).WillRepeatedly( - DoAll(SetArgReferee<1>(subffixName), Return(DataShare::E_OK))); + DoAll(SetArgReferee<1>(suffixName), Return(DataShare::E_OK))); DeviceNameManager::GetInstance().InitDeviceNameWhenLogin(); DeviceNameManager::GetInstance().UnInit(); @@ -218,7 +218,7 @@ HWTEST_F(DeviceNameManagerTest, InitDeviceNameWhenNickChange_001, testing::ext:: ASSERT_TRUE(multipleUserConnector_ != nullptr); ASSERT_TRUE(helper_ != nullptr); - std::string subffixName = "手机"; + std::string suffixName = "手机"; auto bundleMgr = sptr(new (std::nothrow) BundleMgrMock()); auto systemAbilityManager = sptr(new (std::nothrow) SystemAbilityManagerMock()); EXPECT_CALL(*systemAbilityManager, GetSystemAbility(_)) @@ -232,7 +232,7 @@ HWTEST_F(DeviceNameManagerTest, InitDeviceNameWhenNickChange_001, testing::ext:: EXPECT_CALL(*resultSet, GetRowCount(_)).WillRepeatedly(DoAll(SetArgReferee<0>(1), Return(DataShare::E_OK))); EXPECT_CALL(*resultSet, GetString(_, _)).WillRepeatedly( - DoAll(SetArgReferee<1>(subffixName), Return(DataShare::E_OK))); + DoAll(SetArgReferee<1>(suffixName), Return(DataShare::E_OK))); DeviceNameManager::GetInstance().InitDeviceNameWhenNickChange(); DeviceNameManager::GetInstance().UnInit(); @@ -288,9 +288,9 @@ HWTEST_F(DeviceNameManagerTest, GetLocalDisplayDeviceName_001, testing::ext::Tes EXPECT_CALL(*resultSet, GetRowCount(_)).WillRepeatedly(DoAll(SetArgReferee<0>(1), Return(DataShare::E_OK))); EXPECT_CALL(*resultSet, GoToRow(_)).Times(AtLeast(1)); EXPECT_CALL(*resultSet, GetString(_, _)).WillRepeatedly(Invoke([&getStringInvokeCount](int, std::string &output) { - std::string subffixName = "OH-3.2"; + std::string suffixName = "OH-3.2"; if (getStringInvokeCount++ > 0) { - output = subffixName; + output = suffixName; } return DM_OK; })); @@ -616,60 +616,60 @@ HWTEST_F(DeviceNameManagerTest, GetUserDefinedDeviceName_001, testing::ext::Test HWTEST_F(DeviceNameManagerTest, GetLocalDisplayDeviceName_003, testing::ext::TestSize.Level1) { std::string prefixName = "My"; - std::string subffixName = "Device"; + std::string suffixName = "Device"; int32_t maxNameLength = 20; std::string result = DeviceNameManager::GetInstance().GetLocalDisplayDeviceName(prefixName, - subffixName, maxNameLength); + suffixName, maxNameLength); EXPECT_EQ(result, "My的Device"); } HWTEST_F(DeviceNameManagerTest, GetLocalDisplayDeviceName_004, testing::ext::TestSize.Level1) { std::string prefixName = "MyVeryLong"; - std::string subffixName = "DeviceName"; + std::string suffixName = "DeviceName"; int32_t maxNameLength = 15; std::string result = DeviceNameManager::GetInstance().GetLocalDisplayDeviceName(prefixName, - subffixName, maxNameLength); + suffixName, maxNameLength); EXPECT_EQ(result, "My...DeviceName"); } HWTEST_F(DeviceNameManagerTest, GetLocalDisplayDeviceName_005, testing::ext::TestSize.Level1) { std::string prefixName = "My"; - std::string subffixName = "Device"; + std::string suffixName = "Device"; int32_t maxNameLength = 0; std::string result = DeviceNameManager::GetInstance().GetLocalDisplayDeviceName(prefixName, - subffixName, maxNameLength); + suffixName, maxNameLength); EXPECT_EQ(result, "My的Device"); } HWTEST_F(DeviceNameManagerTest, GetLocalDisplayDeviceName_006, testing::ext::TestSize.Level1) { std::string prefixName = "My"; - std::string subffixName = "VeryLongDeviceNameThatExceedsLimit"; + std::string suffixName = "VeryLongDeviceNameThatExceedsLimit"; int32_t maxNameLength = 30; std::string result = DeviceNameManager::GetInstance().GetLocalDisplayDeviceName(prefixName, - subffixName, maxNameLength); + suffixName, maxNameLength); EXPECT_EQ(result, "My的VeryLongDevi..."); } HWTEST_F(DeviceNameManagerTest, GetLocalDisplayDeviceName_007, testing::ext::TestSize.Level1) { std::string prefixName = ""; - std::string subffixName = "Device"; + std::string suffixName = "Device"; int32_t maxNameLength = 10; std::string result = DeviceNameManager::GetInstance().GetLocalDisplayDeviceName(prefixName, - subffixName, maxNameLength); + suffixName, maxNameLength); EXPECT_EQ(result, "Device"); } HWTEST_F(DeviceNameManagerTest, GetLocalDisplayDeviceName_008, testing::ext::TestSize.Level1) { std::string prefixName = ""; - std::string subffixName = "VeryLongDeviceName"; + std::string suffixName = "VeryLongDeviceName"; int32_t maxNameLength = 10; std::string result = DeviceNameManager::GetInstance().GetLocalDisplayDeviceName(prefixName, - subffixName, maxNameLength); + suffixName, maxNameLength); EXPECT_EQ(result, "VeryLon..."); }