diff --git a/services/implementation/include/dependency/hichain/hichain_auth_connector.h b/services/implementation/include/dependency/hichain/hichain_auth_connector.h index 8c3234d36ec9a9af73b753ddfa7d5739bbf667d0..93b92b29f425153beb17b34ae773ffb88aebbbf5 100644 --- a/services/implementation/include/dependency/hichain/hichain_auth_connector.h +++ b/services/implementation/include/dependency/hichain/hichain_auth_connector.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * 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 diff --git a/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp b/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp index 23756a20f80569f0f46a5a4dddf95d24d07ac51a..5ee041f79a3dbe82dc407234eb3c5188fa838178 100644 --- a/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp +++ b/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp @@ -27,6 +27,12 @@ namespace OHOS { namespace DistributedHardware { +namespace { + +constexpr int32_t HICHAIN_DATA_SIZE = 10240; + +} + std::shared_ptr HiChainAuthConnector::dmDeviceAuthCallback_ = nullptr; std::map> HiChainAuthConnector::dmDeviceAuthCallbackMap_; std::mutex HiChainAuthConnector::dmDeviceAuthCallbackMutex_; @@ -283,6 +289,11 @@ int32_t HiChainAuthConnector::AuthCredentialPinCode(int32_t osAccountId, int64_t bool HiChainAuthConnector::onTransmit(int64_t requestId, const uint8_t *data, uint32_t dataLen) { LOGI("AuthDevice onTransmit, requestId %{public}" PRId64, requestId); + if (dataLen > HICHAIN_DATA_SIZE) { + LOGE("dataLen = %{public}u is invalid.", dataLen); + return false; + } + CHECK_NULL_RETURN(data, false); auto dmDeviceAuthCallback = GetDeviceAuthCallback(requestId); if (dmDeviceAuthCallback == nullptr) { LOGE("HiChainAuthConnector::onTransmit dmDeviceAuthCallback_ is nullptr."); @@ -336,6 +347,11 @@ void HiChainAuthConnector::onError(int64_t requestId, int operationCode, int err void HiChainAuthConnector::onSessionKeyReturned(int64_t requestId, const uint8_t *sessionKey, uint32_t sessionKeyLen) { LOGI("start."); + if (sessionKeyLen > HICHAIN_DATA_SIZE) { + LOGE("sessionKeyLen = %{public}u is invalid.", sessionKeyLen); + return; + } + CHECK_NULL_VOID(sessionKey); auto dmDeviceAuthCallback = GetDeviceAuthCallback(requestId); if (dmDeviceAuthCallback == nullptr) { LOGE("HiChainAuthConnector::onSessionKeyReturned dmDeviceAuthCallback_ is nullptr."); diff --git a/services/service/src/pinholder/pin_holder_session.cpp b/services/service/src/pinholder/pin_holder_session.cpp index 44b8a3b8de30bb9eb9e4c1f01e25dd5fb743d681..6eb5932edcd728ff2d442bb49868b1e8d65c3490 100644 --- a/services/service/src/pinholder/pin_holder_session.cpp +++ b/services/service/src/pinholder/pin_holder_session.cpp @@ -22,6 +22,12 @@ namespace OHOS { namespace DistributedHardware { + +namespace { + +constexpr int32_t MAX_DATA_LEN = 4096000; // Maximum MTU Value for Logical Session:4M + +} std::shared_ptr PinHolderSession::pinholderSessionCallback_ = nullptr; std::mutex PinHolderSession::pinHolderSessionLock_; PinHolderSession::PinHolderSession() @@ -110,7 +116,7 @@ void PinHolderSession::OnSessionClosed(int sessionId) void PinHolderSession::OnBytesReceived(int sessionId, const void *data, unsigned int dataLen) { - if (sessionId < 0 || data == nullptr || dataLen <= 0) { + if (sessionId < 0 || data == nullptr || dataLen <= 0 || dataLen > MAX_DATA_LEN) { LOGE("[SOFTBUS]fail to receive data from softbus with sessionId: %{public}d, dataLen: %{public}d.", sessionId, dataLen); return; diff --git a/services/service/src/softbus/softbus_listener.cpp b/services/service/src/softbus/softbus_listener.cpp index 036b1e43b4720a9337a35677ce98d7075bf8f8c0..fda986130706cf756097549c0f00683cf77d237c 100644 --- a/services/service/src/softbus/softbus_listener.cpp +++ b/services/service/src/softbus/softbus_listener.cpp @@ -70,14 +70,21 @@ static std::mutex g_deviceMapMutex; static std::mutex g_lnnCbkMapMutex; static std::mutex g_radarLoadLock; static std::mutex g_onlineDeviceNumLock; + +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) +static ffrt::mutex g_lockDeviceTrustedChange; +static ffrt::mutex g_lockUserIdCheckSumChange; +static ffrt::mutex g_credentialAuthStatus; +static ffrt::mutex g_dmSoftbusEventQueueLock; +#else static std::mutex g_lockDeviceTrustedChange; -static std::mutex g_lockUserIdCheckSumChange; +static std::mutex g_credentialAuthStatus; +#endif static std::mutex g_lockDeviceOnLine; static std::mutex g_lockDeviceOffLine; static std::mutex g_lockDevInfoChange; static std::mutex g_lockDeviceIdSet; static std::mutex g_lockDevScreenStatusChange; -static std::mutex g_credentialAuthStatus; static std::map>>> discoveredDeviceMap; static std::map> lnnOpsCbkMap; @@ -90,7 +97,6 @@ static std::mutex g_hostNameMutex; std::string SoftbusListener::hostName_ = ""; int32_t g_onlineDeviceNum = 0; static std::map> g_dmSoftbusEventQueueMap; -static std::mutex g_dmSoftbusEventQueueLock; static int OnSessionOpened(int sessionId, int result) { @@ -165,14 +171,18 @@ void SoftbusListener::DeviceNameChange(DmDeviceInfo deviceInfo) void SoftbusListener::DeviceNotTrust(const std::string &msg) { +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + std::lock_guard lock(g_lockDeviceTrustedChange); +#else std::lock_guard lock(g_lockDeviceTrustedChange); +#endif DeviceManagerService::GetInstance().HandleDeviceNotTrust(msg); } void SoftbusListener::DeviceTrustedChange(const std::string &msg) { #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) - std::lock_guard lock(g_lockDeviceTrustedChange); + std::lock_guard lock(g_lockDeviceTrustedChange); DeviceManagerService::GetInstance().HandleDeviceTrustedChange(msg); #else (void)msg; @@ -182,7 +192,7 @@ void SoftbusListener::DeviceTrustedChange(const std::string &msg) void SoftbusListener::DeviceUserIdCheckSumChange(const std::string &msg) { #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) - std::lock_guard lock(g_lockUserIdCheckSumChange); + std::lock_guard lock(g_lockUserIdCheckSumChange); DeviceManagerService::GetInstance().HandleUserIdCheckSumChange(msg); #else (void)msg; @@ -197,7 +207,11 @@ void SoftbusListener::DeviceScreenStatusChange(DmDeviceInfo deviceInfo) void SoftbusListener::CredentialAuthStatusProcess(std::string deviceList, uint16_t deviceTypeId, int32_t errcode) { +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + std::lock_guard lock(g_credentialAuthStatus); +#else std::lock_guard lock(g_credentialAuthStatus); +#endif DeviceManagerService::GetInstance().HandleCredentialAuthStatus(deviceList, deviceTypeId, errcode); } @@ -267,7 +281,7 @@ void SoftbusListener::SoftbusEventQueueHandle(std::string deviceId) { std::queue eventQueue; { - std::lock_guard lock(g_dmSoftbusEventQueueLock); + std::lock_guard lock(g_dmSoftbusEventQueueLock); auto it = g_dmSoftbusEventQueueMap.find(deviceId); if (it == g_dmSoftbusEventQueueMap.end()) { return; @@ -297,7 +311,7 @@ void SoftbusListener::SoftbusEventQueueHandle(std::string deviceId) } } { - std::lock_guard lock(g_dmSoftbusEventQueueLock); + std::lock_guard lock(g_dmSoftbusEventQueueLock); auto it = g_dmSoftbusEventQueueMap.find(deviceId); if (it == g_dmSoftbusEventQueueMap.end()) { return; @@ -321,7 +335,7 @@ int32_t SoftbusListener::SoftbusEventQueueAdd(DmSoftbusEvent &dmSoftbusEventInfo std::string deviceId(dmSoftbusEventInfo.dmDeviceInfo.deviceId); LOGI("deviceIdHash:%{public}s.", GetAnonyString(deviceId).c_str()); { - std::lock_guard lock(g_dmSoftbusEventQueueLock); + std::lock_guard lock(g_dmSoftbusEventQueueLock); auto it = g_dmSoftbusEventQueueMap.find(deviceId); if (it == g_dmSoftbusEventQueueMap.end()) { std::queue eventQueue; @@ -1387,6 +1401,7 @@ int32_t SoftbusListener::SetLocalDisplayName(const std::string &displayName) int32_t ret = ::SetDisplayName(DM_PKG_NAME, displayName.c_str(), len); if (ret != DM_OK) { LOGE("SoftbusListener SetLocalDisplayName failed!"); + return ret; } return DM_OK; } diff --git a/services/softbuscache/BUILD.gn b/services/softbuscache/BUILD.gn index 49a243c36afd9896067c0f8e8a4bcd6b9336462e..47d07cf6b12dba025fbe25294c136e861c28a6e4 100644 --- a/services/softbuscache/BUILD.gn +++ b/services/softbuscache/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. +# Copyright (c) 2024-2025 Huawei Device Co., Ltd. # 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 @@ -93,6 +93,7 @@ if (defined(ohos_lite)) { external_deps = [ "bounds_checking_function:libsec_shared", "dsoftbus:softbus_client", + "ffrt:libffrt", "hilog:libhilog", ] diff --git a/services/softbuscache/include/dm_softbus_cache.h b/services/softbuscache/include/dm_softbus_cache.h index 4bf4a3f6c6a0c458036fea1e454f901a37ed2194..002650522d4382542dcd0b82c57d0a738870e36f 100644 --- a/services/softbuscache/include/dm_softbus_cache.h +++ b/services/softbuscache/include/dm_softbus_cache.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * 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 @@ -20,6 +20,9 @@ #include #include #include "dm_device_info.h" +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) +#include "ffrt.h" +#endif #include "dm_single_instance.h" #include "softbus_bus_center.h" #include "softbus_common.h" @@ -60,8 +63,13 @@ private: int32_t GetDevLevelFromBus(const char *networkId, int32_t &securityLevel); private: +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + ffrt::mutex deviceInfosMutex_; + ffrt::mutex deviceSecurityLevelMutex_; +#else std::mutex deviceInfosMutex_; std::mutex deviceSecurityLevelMutex_; +#endif std::unordered_map> deviceInfo_; std::unordered_map deviceSecurityLevel_; }; diff --git a/services/softbuscache/src/dm_softbus_cache.cpp b/services/softbuscache/src/dm_softbus_cache.cpp index 16fd352b60f63bb70ff42ad1a63dea18b309f0e0..0a6e6e5fde874d090a4f1feede3bf55a6d3061ed 100644 --- a/services/softbuscache/src/dm_softbus_cache.cpp +++ b/services/softbuscache/src/dm_softbus_cache.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * 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 @@ -26,11 +26,19 @@ DM_IMPLEMENT_SINGLE_INSTANCE(SoftbusCache); std::atomic g_online{false}; std::atomic g_getLocalDevInfo{false}; DmDeviceInfo localDeviceInfo_; +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) +ffrt::mutex localDevInfoMutex_; +#else std::mutex localDevInfoMutex_; +#endif void SoftbusCache::SaveLocalDeviceInfo() { LOGI("start"); +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + std::lock_guard mutexLock(localDevInfoMutex_); +#else std::lock_guard mutexLock(localDevInfoMutex_); +#endif if (g_online) { return; } @@ -51,7 +59,11 @@ void SoftbusCache::SaveLocalDeviceInfo() void SoftbusCache::DeleteLocalDeviceInfo() { LOGI("networkid %{public}s.", GetAnonyString(std::string(localDeviceInfo_.networkId)).c_str()); +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + std::lock_guard mutexLock(localDevInfoMutex_); +#else std::lock_guard mutexLock(localDevInfoMutex_); +#endif g_online = false; g_getLocalDevInfo = false; if (memset_s(&localDeviceInfo_, sizeof(DmDeviceInfo), 0, sizeof(DmDeviceInfo)) != DM_OK) { @@ -62,7 +74,11 @@ void SoftbusCache::DeleteLocalDeviceInfo() int32_t SoftbusCache::GetLocalDeviceInfo(DmDeviceInfo &nodeInfo) { +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + std::lock_guard mutexLock(localDevInfoMutex_); +#else std::lock_guard mutexLock(localDevInfoMutex_); +#endif if (g_getLocalDevInfo) { nodeInfo = localDeviceInfo_; LOGD("dm cache success."); @@ -92,7 +108,11 @@ void SoftbusCache::UpDataLocalDevInfo() LOGE("[SOFTBUS]GetLocalNodeDeviceInfo failed, ret: %{public}d.", ret); return; } +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + std::lock_guard mutexLock(localDevInfoMutex_); +#else std::lock_guard mutexLock(localDevInfoMutex_); +#endif ConvertNodeBasicInfoToDmDevice(nodeBasicInfo, localDeviceInfo_); ChangeDeviceInfo(localDeviceInfo_); } @@ -146,7 +166,11 @@ void SoftbusCache::SaveDeviceInfo(DmDeviceInfo deviceInfo) LOGE("SaveDeviceInfo copy deviceId failed."); return; } +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + std::lock_guard mutexLock(deviceInfosMutex_); +#else std::lock_guard mutexLock(deviceInfosMutex_); +#endif CHECK_SIZE_VOID(deviceInfo_); deviceInfo_[udid] = std::pair(uuid, deviceInfo); LOGI("success udid %{public}s, networkId %{public}s", @@ -156,7 +180,11 @@ void SoftbusCache::SaveDeviceInfo(DmDeviceInfo deviceInfo) void SoftbusCache::DeleteDeviceInfo(const DmDeviceInfo &nodeInfo) { LOGI("networkId %{public}s", GetAnonyString(std::string(nodeInfo.networkId)).c_str()); +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + std::lock_guard mutexLock(deviceInfosMutex_); +#else std::lock_guard mutexLock(deviceInfosMutex_); +#endif for (const auto &item : deviceInfo_) { if (std::string(item.second.second.networkId) == std::string(nodeInfo.networkId)) { LOGI("success udid %{public}s", GetAnonyString(item.first).c_str()); @@ -168,7 +196,11 @@ void SoftbusCache::DeleteDeviceInfo(const DmDeviceInfo &nodeInfo) void SoftbusCache::DeleteDeviceInfo() { +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + std::lock_guard mutexLock(deviceInfosMutex_); +#else std::lock_guard mutexLock(deviceInfosMutex_); +#endif deviceInfo_.clear(); } @@ -177,7 +209,11 @@ void SoftbusCache::ChangeDeviceInfo(const DmDeviceInfo deviceInfo) LOGI("start"); std::string udid = ""; GetUdidByNetworkId(deviceInfo.networkId, udid); +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + std::lock_guard mutexLock(deviceInfosMutex_); +#else std::lock_guard mutexLock(deviceInfosMutex_); +#endif if (deviceInfo_.find(udid) != deviceInfo_.end()) { if (memcpy_s(deviceInfo_[udid].second.deviceName, sizeof(deviceInfo_[udid].second.deviceName), deviceInfo.deviceName, sizeof(deviceInfo.deviceName)) != DM_OK) { @@ -200,7 +236,11 @@ void SoftbusCache::ChangeDeviceInfo(const DmDeviceInfo deviceInfo) int32_t SoftbusCache::GetDeviceInfoFromCache(std::vector &deviceInfoList) { +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + std::lock_guard mutexLock(deviceInfosMutex_); +#else std::lock_guard mutexLock(deviceInfosMutex_); +#endif for (const auto &item : deviceInfo_) { if (std::string(item.second.second.networkId) == std::string(localDeviceInfo_.networkId)) { continue; @@ -234,7 +274,11 @@ void SoftbusCache::UpdateDeviceInfoCache() int32_t SoftbusCache::GetUdidFromCache(const char *networkId, std::string &udid) { +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + std::lock_guard mutexLock(deviceInfosMutex_); +#else std::lock_guard mutexLock(deviceInfosMutex_); +#endif for (const auto &item : deviceInfo_) { if (std::string(item.second.second.networkId) == std::string(networkId)) { udid = item.first; @@ -254,7 +298,11 @@ int32_t SoftbusCache::GetUdidFromCache(const char *networkId, std::string &udid) int32_t SoftbusCache::GetUuidFromCache(const char *networkId, std::string &uuid) { +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + std::lock_guard mutexLock(deviceInfosMutex_); +#else std::lock_guard mutexLock(deviceInfosMutex_); +#endif for (const auto &item : deviceInfo_) { if (std::string(item.second.second.networkId) == std::string(networkId)) { uuid = item.second.first; @@ -302,7 +350,11 @@ int32_t SoftbusCache::ConvertNodeBasicInfoToDmDevice(const NodeBasicInfo &nodeIn void SoftbusCache::SaveDeviceSecurityLevel(const char *networkId) { LOGI("networkId %{public}s.", GetAnonyString(std::string(networkId)).c_str()); +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + std::lock_guard mutexLock(deviceSecurityLevelMutex_); +#else std::lock_guard mutexLock(deviceSecurityLevelMutex_); +#endif if (deviceSecurityLevel_.find(std::string(networkId)) != deviceSecurityLevel_.end()) { return; } @@ -319,7 +371,11 @@ void SoftbusCache::SaveDeviceSecurityLevel(const char *networkId) void SoftbusCache::DeleteDeviceSecurityLevel(const char *networkId) { LOGI("networkId %{public}s.", GetAnonyString(std::string(networkId)).c_str()); +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + std::lock_guard mutexLock(deviceSecurityLevelMutex_); +#else std::lock_guard mutexLock(deviceSecurityLevelMutex_); +#endif if (deviceSecurityLevel_.find(std::string(networkId)) != deviceSecurityLevel_.end()) { deviceSecurityLevel_.erase(std::string(networkId)); } @@ -327,7 +383,11 @@ void SoftbusCache::DeleteDeviceSecurityLevel(const char *networkId) int32_t SoftbusCache::GetSecurityDeviceLevel(const char *networkId, int32_t &securityLevel) { +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + std::lock_guard mutexLock(deviceSecurityLevelMutex_); +#else std::lock_guard mutexLock(deviceSecurityLevelMutex_); +#endif for (const auto &item : deviceSecurityLevel_) { if (item.first == std::string(networkId)) { securityLevel = item.second; @@ -363,7 +423,11 @@ int32_t SoftbusCache::GetDevLevelFromBus(const char *networkId, int32_t &securit int32_t SoftbusCache::GetDevInfoByNetworkId(const std::string &networkId, DmDeviceInfo &nodeInfo) { { +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + std::lock_guard mutexLock(deviceInfosMutex_); +#else std::lock_guard mutexLock(deviceInfosMutex_); +#endif for (const auto &item : deviceInfo_) { if (std::string(item.second.second.networkId) == networkId) { nodeInfo = item.second.second; @@ -407,7 +471,11 @@ int32_t SoftbusCache::GetDevInfoFromBus(const std::string &networkId, DmDeviceIn int32_t SoftbusCache::GetUdidByUdidHash(const std::string &udidHash, std::string &udid) { { +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + std::lock_guard mutexLock(deviceInfosMutex_); +#else std::lock_guard mutexLock(deviceInfosMutex_); +#endif for (const auto &item : deviceInfo_) { if (std::string(item.second.second.deviceId) == udidHash) { udid = item.first; @@ -423,7 +491,11 @@ int32_t SoftbusCache::GetUdidByUdidHash(const std::string &udidHash, std::string int32_t SoftbusCache::GetUuidByUdid(const std::string &udid, std::string &uuid) { { +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + std::lock_guard mutexLock(deviceInfosMutex_); +#else std::lock_guard mutexLock(deviceInfosMutex_); +#endif if (deviceInfo_.find(udid) != deviceInfo_.end()) { uuid = deviceInfo_[udid].first; LOGI("success uuid %{public}s.", GetAnonyString(uuid).c_str()); @@ -437,7 +509,11 @@ int32_t SoftbusCache::GetUuidByUdid(const std::string &udid, std::string &uuid) int32_t SoftbusCache::GetNetworkIdFromCache(const std::string &udid, std::string &networkId) { { +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + std::lock_guard mutexLock(deviceInfosMutex_); +#else std::lock_guard mutexLock(deviceInfosMutex_); +#endif if (deviceInfo_.find(udid) != deviceInfo_.end()) { networkId = deviceInfo_[udid].second.networkId; LOGI("success networkId %{public}s, udid %{public}s.", @@ -452,7 +528,11 @@ int32_t SoftbusCache::GetNetworkIdFromCache(const std::string &udid, std::string int32_t SoftbusCache::GetDeviceNameFromCache(const std::string &udid, std::string &deviceName) { { +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + std::lock_guard mutexLock(deviceInfosMutex_); +#else std::lock_guard mutexLock(deviceInfosMutex_); +#endif if (deviceInfo_.find(udid) != deviceInfo_.end()) { deviceName = deviceInfo_[udid].second.deviceName; LOGI("success deviceName: %{public}s, udid: %{public}s.", @@ -467,7 +547,11 @@ int32_t SoftbusCache::GetDeviceNameFromCache(const std::string &udid, std::strin bool SoftbusCache::CheckIsOnline(const std::string &udidHash) { { +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + std::lock_guard mutexLock(deviceInfosMutex_); +#else std::lock_guard mutexLock(deviceInfosMutex_); +#endif for (const auto &item : deviceInfo_) { LOGI("deviceId %{public}s, cache udidHash %{public}s.", GetAnonyString(udidHash).c_str(), GetAnonyString(std::string(item.second.second.deviceId)).c_str()); @@ -483,7 +567,11 @@ bool SoftbusCache::CheckIsOnline(const std::string &udidHash) bool SoftbusCache::CheckIsOnlineByPeerUdid(const std::string &peerUdid) { { +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + std::lock_guard mutexLock(deviceInfosMutex_); +#else std::lock_guard mutexLock(deviceInfosMutex_); +#endif if (deviceInfo_.find(peerUdid) != deviceInfo_.end()) { LOGI("peerUdid %{public}s is online.", GetAnonyString(peerUdid).c_str()); return true; diff --git a/test/commonunittest/UTTest_hichain_auth_connector.cpp b/test/commonunittest/UTTest_hichain_auth_connector.cpp index fe744fcccb7eb713282950b54c610d72f08ad623..50bcad8ccd10933aab60a9c52e67bb16c5750ecd 100644 --- a/test/commonunittest/UTTest_hichain_auth_connector.cpp +++ b/test/commonunittest/UTTest_hichain_auth_connector.cpp @@ -121,7 +121,7 @@ HWTEST_F(HiChainAuthConnectorTest, onTransmit_002, testing::ext::TestSize.Level1 uint32_t dataLen = 0; hiChain_->dmDeviceAuthCallback_ = std::make_shared(); bool ret = hiChain_->onTransmit(requestId, data, dataLen); - EXPECT_EQ(ret, true); + EXPECT_EQ(ret, false); } HWTEST_F(HiChainAuthConnectorTest, onRequest_001, testing::ext::TestSize.Level1) diff --git a/test/softbusunittest/UTTest_softbus_listener.cpp b/test/softbusunittest/UTTest_softbus_listener.cpp index b68adb9009a20b6800cabcdacb1a2ca4b98e94dc..3131b49c6cc02ab021b017fda3d2e662b32f15ea 100644 --- a/test/softbusunittest/UTTest_softbus_listener.cpp +++ b/test/softbusunittest/UTTest_softbus_listener.cpp @@ -1303,7 +1303,7 @@ HWTEST_F(SoftbusListenerTest, SetLocalDisplayName_001, testing::ext::TestSize.Le softbusListener = std::make_shared(); } int32_t ret = softbusListener->SetLocalDisplayName(displayName); - EXPECT_EQ(ret, DM_OK); + EXPECT_NE(ret, DM_OK); std::vector onlineDevInfoVec; EXPECT_CALL(*softbusCacheMock_, GetDeviceInfoFromCache(_)).Times(::testing::AtLeast(1)) .WillOnce(DoAll(SetArgReferee<0>(onlineDevInfoVec), Return(DM_OK))); diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 02d5243d7e47e5d24349ce822911061599f15593..6fce5adccfe977b7e9f5966814ffcc2cb1cc4e1a 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -1456,6 +1456,7 @@ ohos_unittest("UTTest_device_manager_service_listener") { "device_info_manager:distributed_device_profile_common", "device_info_manager:distributed_device_profile_sdk", "dsoftbus:softbus_client", + "ffrt:libffrt", "eventhandler:libeventhandler", "googletest:gmock", "googletest:gmock_main", diff --git a/test/unittest/UTTest_dm_softbus_cache.cpp b/test/unittest/UTTest_dm_softbus_cache.cpp index 8f35ee46649861a76af1f1b685a667d7a257539c..346c552234dafc68d4544caf2f07fed0a5f02cf5 100644 --- a/test/unittest/UTTest_dm_softbus_cache.cpp +++ b/test/unittest/UTTest_dm_softbus_cache.cpp @@ -84,7 +84,7 @@ HWTEST_F(DMSoftbusCacheTest, GetDeviceInfoFromCache_001, testing::ext::TestSize. .deviceTypeId = 1 }; { - std::lock_guard mutexLock(SoftbusCache::GetInstance().deviceInfosMutex_); + std::lock_guard mutexLock(SoftbusCache::GetInstance().deviceInfosMutex_); SoftbusCache::GetInstance().deviceInfo_.clear(); SoftbusCache::GetInstance().deviceInfo_["udid"] = std::pair("uuid", deviceInfo); } @@ -105,7 +105,7 @@ HWTEST_F(DMSoftbusCacheTest, CheckIsOnline_001, testing::ext::TestSize.Level1) .deviceTypeId = 1, }; { - std::lock_guard mutexLock(SoftbusCache::GetInstance().deviceInfosMutex_); + std::lock_guard mutexLock(SoftbusCache::GetInstance().deviceInfosMutex_); SoftbusCache::GetInstance().deviceInfo_.clear(); SoftbusCache::GetInstance().deviceInfo_["udid"] = std::pair("uuid", deviceInfo); } @@ -123,7 +123,7 @@ HWTEST_F(DMSoftbusCacheTest, GetUuidByUdid_001, testing::ext::TestSize.Level1) .networkId = "networkid" }; { - std::lock_guard mutexLock(SoftbusCache::GetInstance().deviceInfosMutex_); + std::lock_guard mutexLock(SoftbusCache::GetInstance().deviceInfosMutex_); SoftbusCache::GetInstance().deviceInfo_.clear(); SoftbusCache::GetInstance().deviceInfo_["udid"] = std::pair("uuid", deviceInfo); } @@ -145,7 +145,7 @@ HWTEST_F(DMSoftbusCacheTest, GetNetworkIdFromCache_001, testing::ext::TestSize.L .networkId = "networkid" }; { - std::lock_guard mutexLock(SoftbusCache::GetInstance().deviceInfosMutex_); + std::lock_guard mutexLock(SoftbusCache::GetInstance().deviceInfosMutex_); SoftbusCache::GetInstance().deviceInfo_.clear(); SoftbusCache::GetInstance().deviceInfo_["udid"] = std::pair("uuid", deviceInfo); } @@ -168,7 +168,7 @@ HWTEST_F(DMSoftbusCacheTest, GetUdidByUdidHash_001, testing::ext::TestSize.Level }; { - std::lock_guard mutexLock(SoftbusCache::GetInstance().deviceInfosMutex_); + std::lock_guard mutexLock(SoftbusCache::GetInstance().deviceInfosMutex_); SoftbusCache::GetInstance().deviceInfo_.clear(); SoftbusCache::GetInstance().deviceInfo_["udid"] = std::pair("uuid", deviceInfo); } @@ -190,7 +190,7 @@ HWTEST_F(DMSoftbusCacheTest, GetDevInfoByNetworkId_001, testing::ext::TestSize.L .networkId = "networkid" }; { - std::lock_guard mutexLock(SoftbusCache::GetInstance().deviceInfosMutex_); + std::lock_guard mutexLock(SoftbusCache::GetInstance().deviceInfosMutex_); SoftbusCache::GetInstance().deviceInfo_.clear(); SoftbusCache::GetInstance().deviceInfo_["udid"] = std::pair("uuid", deviceInfo); } @@ -205,7 +205,7 @@ HWTEST_F(DMSoftbusCacheTest, GetDevInfoByNetworkId_001, testing::ext::TestSize.L HWTEST_F(DMSoftbusCacheTest, GetSecurityDeviceLevel_001, testing::ext::TestSize.Level1) { { - std::lock_guard mutexLock(SoftbusCache::GetInstance().deviceSecurityLevelMutex_); + std::lock_guard mutexLock(SoftbusCache::GetInstance().deviceSecurityLevelMutex_); SoftbusCache::GetInstance().deviceSecurityLevel_.clear(); SoftbusCache::GetInstance().deviceSecurityLevel_["networkid"] = 1; } @@ -216,7 +216,7 @@ HWTEST_F(DMSoftbusCacheTest, GetSecurityDeviceLevel_001, testing::ext::TestSize. .WillOnce(Return(ERR_DM_FAILED)); EXPECT_NE(SoftbusCache::GetInstance().GetSecurityDeviceLevel("test", securityLevel), DM_OK); { - std::lock_guard mutexLock(SoftbusCache::GetInstance().deviceSecurityLevelMutex_); + std::lock_guard mutexLock(SoftbusCache::GetInstance().deviceSecurityLevelMutex_); SoftbusCache::GetInstance().deviceSecurityLevel_.clear(); } } @@ -241,7 +241,7 @@ HWTEST_F(DMSoftbusCacheTest, GetUuidFromCache_001, testing::ext::TestSize.Level1 }; { - std::lock_guard mutexLock(SoftbusCache::GetInstance().deviceInfosMutex_); + std::lock_guard mutexLock(SoftbusCache::GetInstance().deviceInfosMutex_); SoftbusCache::GetInstance().deviceInfo_["udid"] = std::pair("uuid", deviceInfo); } std::string uuid = ""; @@ -260,7 +260,7 @@ HWTEST_F(DMSoftbusCacheTest, GetUdidFromCache_001, testing::ext::TestSize.Level1 }; { - std::lock_guard mutexLock(SoftbusCache::GetInstance().deviceInfosMutex_); + std::lock_guard mutexLock(SoftbusCache::GetInstance().deviceInfosMutex_); SoftbusCache::GetInstance().deviceInfo_.clear(); SoftbusCache::GetInstance().deviceInfo_["udid"] = std::pair("uuid", deviceInfo); }