From 4c50f87e7174cc1701e81be930f7c0274e2383c6 Mon Sep 17 00:00:00 2001 From: q30043944 Date: Sat, 13 Sep 2025 18:36:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E5=90=8D=E7=A7=B0=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: q30043944 --- .../include/softbus/softbus_listener.h | 2 +- .../service/src/softbus/softbus_listener.cpp | 20 +++++++++---------- .../softbus_listener_fuzzer.cpp | 5 +---- .../UTTest_softbus_listener.cpp | 11 +++++----- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/services/service/include/softbus/softbus_listener.h b/services/service/include/softbus/softbus_listener.h index 0559fa581..bd027d97e 100644 --- a/services/service/include/softbus/softbus_listener.h +++ b/services/service/include/softbus/softbus_listener.h @@ -89,7 +89,7 @@ public: static std::string ConvertBytesToUpperCaseHexString(const uint8_t arr[], const size_t size); static int32_t ConvertScreenStatusToDmDevice(const NodeBasicInfo &nodeInfo, const int32_t devScreenStatus, DmDeviceInfo &devInfo); - static void UpdateDeviceName(NodeBasicInfo *info); + static void UpdateDeviceName(DmDeviceInfo &info); /** * @brief notify the received acl hash info diff --git a/services/service/src/softbus/softbus_listener.cpp b/services/service/src/softbus/softbus_listener.cpp index fda986130..5bb97e624 100644 --- a/services/service/src/softbus/softbus_listener.cpp +++ b/services/service/src/softbus/softbus_listener.cpp @@ -388,7 +388,7 @@ void SoftbusListener::OnSoftbusDeviceOnline(NodeBasicInfo *info) SoftbusCache::GetInstance().SaveDeviceInfo(dmSoftbusEventInfo.dmDeviceInfo); SoftbusCache::GetInstance().SaveDeviceSecurityLevel(dmSoftbusEventInfo.dmDeviceInfo.networkId); SoftbusCache::GetInstance().SaveLocalDeviceInfo(); - UpdateDeviceName(info); + UpdateDeviceName(dmSoftbusEventInfo.dmDeviceInfo); { std::lock_guard lock(g_onlineDeviceNumLock); g_onlineDeviceNum++; @@ -476,20 +476,20 @@ void SoftbusListener::OnSoftbusDeviceOffline(NodeBasicInfo *info) } } -void SoftbusListener::UpdateDeviceName(NodeBasicInfo *info) +void SoftbusListener::UpdateDeviceName(DmDeviceInfo &info) { #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) - if (info == nullptr) { - LOGE("NodeBasicInfo is nullptr, not update device name"); + if (info.networkId[0] == '\0') { + LOGE("networkId is empty."); return; } std::string udid = ""; - if (GetUdidByNetworkId(info->networkId, udid) != DM_OK) { + if (GetUdidByNetworkId(info.networkId, udid) != DM_OK) { LOGE("GetUdidByNetworkId failed, not update device name"); return; } - LOGI("info->deviceName: %{public}s.", GetAnonyString(info->deviceName).c_str()); - DeviceProfileConnector::GetInstance().UpdateAclDeviceName(udid, info->deviceName); + LOGI("info->deviceName: %{public}s.", GetAnonyString(info.deviceName).c_str()); + DeviceProfileConnector::GetInstance().UpdateAclDeviceName(udid, info.deviceName); #endif } @@ -510,15 +510,15 @@ void SoftbusListener::OnSoftbusDeviceInfoChanged(NodeBasicInfoType type, NodeBas } LOGI("NetworkType %{public}d.", networkType); } - if (type == NodeBasicInfoType::TYPE_DEVICE_NAME) { - UpdateDeviceName(info); - } DmSoftbusEvent dmSoftbusEventInfo; dmSoftbusEventInfo.eventType = EVENT_TYPE_CHANGED; ConvertNodeBasicInfoToDmDevice(*info, dmSoftbusEventInfo.dmDeviceInfo); LOGI("networkId: %{public}s.", GetAnonyString(dmSoftbusEventInfo.dmDeviceInfo.networkId).c_str()); dmSoftbusEventInfo.dmDeviceInfo.networkType = networkType; SoftbusCache::GetInstance().ChangeDeviceInfo(dmSoftbusEventInfo.dmDeviceInfo); + if (type == NodeBasicInfoType::TYPE_DEVICE_NAME) { + UpdateDeviceName(dmSoftbusEventInfo.dmDeviceInfo); + } #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) SoftbusEventQueueAdd(dmSoftbusEventInfo); #else diff --git a/test/softbusfuzztest/softbuslistener_fuzzer/softbus_listener_fuzzer.cpp b/test/softbusfuzztest/softbuslistener_fuzzer/softbus_listener_fuzzer.cpp index d44b25b5f..b116f503c 100644 --- a/test/softbusfuzztest/softbuslistener_fuzzer/softbus_listener_fuzzer.cpp +++ b/test/softbusfuzztest/softbuslistener_fuzzer/softbus_listener_fuzzer.cpp @@ -318,10 +318,7 @@ void SoftBusListenerFifthFuzzTest(const uint8_t* data, size_t size) deviceListLen = MAX_DEVICE_LIST_LENGTH; softbusListener_->OnCredentialAuthStatus(deviceList.data(), deviceListLen, deviceTypeId, errcode); - std::shared_ptr info = nullptr; - softbusListener_->UpdateDeviceName(info.get()); - info = std::make_shared(); - softbusListener_->UpdateDeviceName(info.get()); + softbusListener_->UpdateDeviceName(deviceInfo); int32_t publishId = fdp.ConsumeIntegral(); softbusListener_->StopPublishSoftbusLNN(publishId); std::string pkgName = fdp.ConsumeRandomLengthString(); diff --git a/test/softbusunittest/UTTest_softbus_listener.cpp b/test/softbusunittest/UTTest_softbus_listener.cpp index 3131b49c6..67616996d 100644 --- a/test/softbusunittest/UTTest_softbus_listener.cpp +++ b/test/softbusunittest/UTTest_softbus_listener.cpp @@ -1503,20 +1503,19 @@ HWTEST_F(SoftbusListenerTest, GetAttrFromCustomData_001, testing::ext::TestSize. .WillOnce(Return(DM_OK)); EXPECT_CALL(*softbusCacheMock_, GetUdidFromCache(_, _)).WillOnce(Return(DM_OK)); softbusListener->OnLocalDevInfoChange(); + DmDeviceInfo devInfo; + softbusListener->UpdateDeviceName(devInfo); - NodeBasicInfo *info = nullptr; - softbusListener->UpdateDeviceName(info); - - NodeBasicInfo nodeBasicInfo = { + devInfo = { .networkId = "123456", .deviceName = "123456", .deviceTypeId = 1 }; EXPECT_CALL(*softbusCacheMock_, GetUdidFromCache(_, _)).WillOnce(Return(DM_OK)); - softbusListener->UpdateDeviceName(&nodeBasicInfo); + softbusListener->UpdateDeviceName(devInfo); EXPECT_CALL(*softbusCacheMock_, GetUdidFromCache(_, _)).WillOnce(Return(ERR_DM_FAILED)); - softbusListener->UpdateDeviceName(&nodeBasicInfo); + softbusListener->UpdateDeviceName(devInfo); } } // namespace } // namespace DistributedHardware -- Gitee