From 1f61c67ed46205016cb798dddb4027b931d9c015 Mon Sep 17 00:00:00 2001 From: BrainL Date: Mon, 17 Feb 2025 11:59:37 +0800 Subject: [PATCH 01/11] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E5=92=8C=E8=A7=A3=E7=BB=91=E8=83=BD=E5=8A=9B=E5=A2=9E=E5=BC=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: BrainL --- .../src/deviceprofile_connector.cpp | 7 -- .../authentication/auth_message_processor.h | 10 ++ .../authentication/auth_message_processor.cpp | 94 +++++++++++++++++++ .../src/authentication/dm_auth_manager.cpp | 6 ++ 4 files changed, 110 insertions(+), 7 deletions(-) diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 6ec0ef91d..630476310 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -394,18 +394,11 @@ std::vector DeviceProfileConnector::SyncAclByBindType(std::string pkgNa CompareBindType(profiles, pkgName, sinkBindType, localDeviceId, targetDeviceId); LOGI("SyncAclByBindType sinkBindType size is %{public}zu", sinkBindType.size()); for (uint32_t sinkIndex = 0; sinkIndex < sinkBindType.size(); sinkIndex++) { - bool deleteAclFlag = true; for (uint32_t srcIndex = 0; srcIndex < bindTypeVec.size(); srcIndex++) { if (sinkBindType[sinkIndex] == bindTypeVec[srcIndex]) { - deleteAclFlag = false; bindType.push_back(bindTypeVec[sinkIndex]); } } - if (deleteAclFlag) { - int32_t deleteIndex = profiles[bindTypeIndex[sinkIndex]].GetAccessControlId(); - DistributedDeviceProfileClient::GetInstance().DeleteAccessControlProfile(deleteIndex); - LOGI("SyncAclByBindType deleteAcl index is %{public}d", deleteIndex); - } } return bindType; } diff --git a/services/implementation/include/authentication/auth_message_processor.h b/services/implementation/include/authentication/auth_message_processor.h index d21279a34..5227d2891 100644 --- a/services/implementation/include/authentication/auth_message_processor.h +++ b/services/implementation/include/authentication/auth_message_processor.h @@ -77,6 +77,7 @@ constexpr const char* TAG_EDITION = "edition"; constexpr const char* TAG_BUNDLE_NAME = "bundleName"; constexpr const char* TAG_CRYPTIC_MSG = "encryptMsg"; constexpr const char* TAG_PEER_BUNDLE_NAME = "PEER_BUNDLE_NAME"; +constexpr const char* TAG_PROFILES_SIZE = "PROFILES_SIZE"; class DmAuthManager; struct DmAuthRequestContext; @@ -91,8 +92,10 @@ public: int32_t ParseMessage(const std::string &message); void SetRequestContext(std::shared_ptr authRequestContext); void SetResponseContext(std::shared_ptr authResponseContext); + void SetRequestProfiles(std::vector profiles); std::shared_ptr GetResponseContext(); std::shared_ptr GetRequestContext(); + std::vector GetRequestProfiles(); std::string CreateDeviceAuthMessage(int32_t msgType, const uint8_t *data, uint32_t dataLen); void CreateResponseAuthMessageExt(nlohmann::json &json); void ParseAuthResponseMessageExt(nlohmann::json &json); @@ -113,11 +116,17 @@ private: void ParseResponseFinishMessage(nlohmann::json &json); void GetAuthReqMessage(nlohmann::json &json); void ParsePkgNegotiateMessage(const nlohmann::json &json); + void ParseRemoteAcl(const nlohmann::json &json); void CreatePublicKeyMessageExt(nlohmann::json &json); void ParsePublicKeyMessageExt(nlohmann::json &json); void GetJsonObj(nlohmann::json &jsonObj); void CreateReqReCheckMessage(nlohmann::json &jsonObj); void ParseReqReCheckMessage(nlohmann::json &json); + void SyncAclByRemote(DistributedDeviceProfile::AccessControlProfile profile, + int32_t size, const nlohmann::json &json); + void CreateLocalAclParcel(nlohmann::json &json); + void ParseAclFromJson(const nlohmann::json &json, int32_t size, + DistributedDeviceProfile::AccessControlProfile profile, bool &isSame); private: std::weak_ptr authMgr_; @@ -128,6 +137,7 @@ private: std::mutex encryptFlagMutex_; bool encryptFlag_ = false; std::shared_ptr cryptoMgr_ = nullptr; + std::vector requestProfiles_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/implementation/src/authentication/auth_message_processor.cpp b/services/implementation/src/authentication/auth_message_processor.cpp index b67246a0b..e02f6c31d 100644 --- a/services/implementation/src/authentication/auth_message_processor.cpp +++ b/services/implementation/src/authentication/auth_message_processor.cpp @@ -219,6 +219,28 @@ void AuthMessageProcessor::CreateNegotiateMessage(nlohmann::json &json) json[TAG_EDITION] = authResponseContext_->edition; } +void AuthMessageProcessor::CreateLocalAclParcel(nlohmann::json &json) +{ + for (uint32_t item = 0; item < requestProfiles_.size(); item++) { + std::string accesserDeviceId = "accesserDeviceId" + std::to_string(item); + std::string accesserUserId = "accesserUserId" + std::to_string(item); + std::string accesserAccountId = "accesserAccountId" + std::to_string(item); + std::string accesserTokenId = "accesserTokenId" + std::to_string(item); + std::string accesseeDeviceId = "accesseeDeviceId" + std::to_string(item); + std::string accesseeUserId = "accesseeUserId" + std::to_string(item); + std::string accesseeAccountId = "accesseeAccountId" + std::to_string(item); + std::string accesseeTokenId = "accesseeTokenId" + std::to_string(item); + json[accesserDeviceId] = requestProfiles_.at(item).GetAccesser().GetAccesserDeviceId(); + json[accesserUserId] = requestProfiles_.at(item).GetAccesser().GetAccesserUserId(); + json[accesserAccountId] = requestProfiles_.at(item).GetAccesser().GetAccesserAccountId(); + json[accesserTokenId] = requestProfiles_.at(item).GetAccesser().GetAccesserTokenId(); + json[accesseeDeviceId] = requestProfiles_.at(item).GetAccessee().GetAccesseeDeviceId(); + json[accesseeUserId] = requestProfiles_.at(item).GetAccessee().GetAccesseeUserId(); + json[accesseeAccountId] = requestProfiles_.at(item).GetAccessee().GetAccesseeAccountId(); + json[accesseeTokenId] = requestProfiles_.at(item).GetAccessee().GetAccesseeTokenId(); + } +} + void AuthMessageProcessor::CreateRespNegotiateMessage(nlohmann::json &json) { if (cryptoAdapter_ == nullptr) { @@ -602,6 +624,65 @@ void AuthMessageProcessor::ParseNegotiateMessage(const nlohmann::json &json) ParsePkgNegotiateMessage(json); } +void AuthMessageProcessor::ParseRemoteAcl(const nlohmann::json &json) +{ + int32_t profilesSize = 0; + if (IsInt32(json, TAG_PROFILES_SIZE)) { + profilesSize = json[TAG_PROFILES_SIZE].get(); + } + for (uint32_t reqItem = 0; reqItem < requestProfiles_.size(); reqItem++) { + LOGI("ParseRemoteAcl SyncAclByRemote Start."); + SyncAclByRemote(requestProfiles_.at(reqItem), profilesSize, json); + } +} + +void AuthMessageProcessor::ParseAclFromJson(const nlohmann::json &jsonObject, int32_t size, + DistributedDeviceProfile::AccessControlProfile profile, bool &isSame) +{ + for (int32_t item = 0; item < size; item++) { + std::string accesserDeviceId = "accesserDeviceId" + std::to_string(item); + std::string accesserUserId = "accesserUserId" + std::to_string(item); + std::string accesserAccountId = "accesserAccountId" + std::to_string(item); + std::string accesserTokenId = "accesserTokenId" + std::to_string(item); + std::string accesseeDeviceId = "accesseeDeviceId" + std::to_string(item); + std::string accesseeUserId = "accesseeUserId" + std::to_string(item); + std::string accesseeAccountId = "accesseeAccountId" + std::to_string(item); + std::string accesseeTokenId = "accesseeTokenId" + std::to_string(item); + if (!IsString(jsonObject, accesserDeviceId) || !IsInt32(jsonObject, accesserUserId) || + !IsString(jsonObject, accesserAccountId) || !IsInt32(jsonObject, accesserTokenId) || + !IsString(jsonObject, accesseeDeviceId) || !IsInt32(jsonObject, accesseeUserId) || + !IsString(jsonObject, accesseeAccountId) || !IsInt32(jsonObject, accesseeTokenId)) { + isSame = false; + return; + } + if (profile.GetAccesser().GetAccesserDeviceId() != jsonObject[accesserDeviceId].get() || + profile.GetAccesser().GetAccesserUserId() != jsonObject[accesserUserId].get() || + profile.GetAccesser().GetAccesserAccountId() != jsonObject[accesserAccountId].get() || + profile.GetAccesser().GetAccesserTokenId() != jsonObject[accesserTokenId].get() || + profile.GetAccessee().GetAccesseeDeviceId() != jsonObject[accesseeDeviceId].get() || + profile.GetAccessee().GetAccesseeUserId() != jsonObject[accesseeUserId].get() || + profile.GetAccessee().GetAccesseeAccountId() != jsonObject[accesseeAccountId].get() || + profile.GetAccessee().GetAccesseeTokenId() != jsonObject[accesseeTokenId].get()) { + isSame = false; + return; + } + } +} + +void AuthMessageProcessor::SyncAclByRemote(DistributedDeviceProfile::AccessControlProfile profile, + int32_t size, const nlohmann::json &json) +{ + bool isSame = true; + if (size == 0) { + isSame = false; + } else { + ParseAclFromJson(json, size, profile, isSame); + } + if (!isSame) { + DeviceProfileConnector::GetInstance().DeleteAccessControlById(profile.GetAccessControlId()); + } +} + void AuthMessageProcessor::ParseRespNegotiateMessage(const nlohmann::json &json) { if (IsBool(json, TAG_IDENTICAL_ACCOUNT)) { @@ -644,6 +725,11 @@ void AuthMessageProcessor::SetResponseContext(std::shared_ptr profiles) +{ + requestProfiles_ = profiles; +} + std::shared_ptr AuthMessageProcessor::GetResponseContext() { return authResponseContext_; @@ -654,6 +740,11 @@ std::shared_ptr AuthMessageProcessor::GetRequestContext() return authRequestContext_; } +std::vector AuthMessageProcessor::GetRequestProfiles() +{ + return requestProfiles_; +} + std::string AuthMessageProcessor::CreateDeviceAuthMessage(int32_t msgType, const uint8_t *data, uint32_t dataLen) { LOGI("CreateDeviceAuthMessage start, msgType %{public}d.", msgType); @@ -675,6 +766,8 @@ void AuthMessageProcessor::CreateReqReCheckMessage(nlohmann::json &jsonObj) jsonTemp[TAG_TOKENID] = authResponseContext_->tokenId; jsonTemp[TAG_BUNDLE_NAME] = authResponseContext_->bundleName; jsonTemp[TAG_BIND_LEVEL] = authResponseContext_->bindLevel; + jsonTemp[TAG_PROFILES_SIZE] = requestProfiles_.size(); + CreateLocalAclParcel(jsonTemp); std::string strTemp = SafetyDump(jsonTemp); std::string encryptStr = ""; CHECK_NULL_VOID(cryptoMgr_); @@ -730,6 +823,7 @@ void AuthMessageProcessor::ParseReqReCheckMessage(nlohmann::json &json) if (IsInt32(jsonObject, TAG_BIND_LEVEL)) { authResponseContext_->localBindLevel = jsonObject[TAG_BIND_LEVEL].get(); } + ParseRemoteAcl(jsonObject); } int32_t AuthMessageProcessor::SaveSessionKey(const uint8_t *sessionKey, const uint32_t keyLen) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 1d284dab3..9de888780 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -863,6 +863,9 @@ void DmAuthManager::StartNegotiate(const int32_t &sessionId) authResponseContext_->isIdenticalAccount = false; authResponseContext_->edition = DM_VERSION_5_0_3; authMessageProcessor_->SetResponseContext(authResponseContext_); + std::vector profiles = + DeviceProfileConnector::GetInstance().GetAccessControlProfile(); + authMessageProcessor_->SetRequestProfiles(profiles); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_NEGOTIATE); softbusConnector_->GetSoftbusSession()->SendData(sessionId, message); if (timer_ != nullptr) { @@ -914,6 +917,9 @@ void DmAuthManager::RespNegotiate(const int32_t &sessionId) return; } LOGI("DmAuthManager::RespNegotiate sessionid %{public}d", sessionId); + std::vector profiles = + DeviceProfileConnector::GetInstance().GetAccessControlProfile(); + authMessageProcessor_->SetRequestProfiles(profiles); remoteDeviceId_ = authResponseContext_->localDeviceId; authResponseContext_->networkId = softbusConnector_->GetLocalDeviceNetworkId(); authResponseContext_->targetDeviceName = softbusConnector_->GetLocalDeviceName(); -- Gitee From 70e80d2638551296c6d194c23b580b7c70a286e7 Mon Sep 17 00:00:00 2001 From: BrainL Date: Mon, 17 Feb 2025 16:52:00 +0800 Subject: [PATCH 02/11] format the code Signed-off-by: BrainL --- .../src/authentication/auth_message_processor.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/services/implementation/src/authentication/auth_message_processor.cpp b/services/implementation/src/authentication/auth_message_processor.cpp index e02f6c31d..9e443bcbc 100644 --- a/services/implementation/src/authentication/auth_message_processor.cpp +++ b/services/implementation/src/authentication/auth_message_processor.cpp @@ -640,6 +640,7 @@ void AuthMessageProcessor::ParseAclFromJson(const nlohmann::json &jsonObject, in DistributedDeviceProfile::AccessControlProfile profile, bool &isSame) { for (int32_t item = 0; item < size; item++) { + bool needDelete = false; std::string accesserDeviceId = "accesserDeviceId" + std::to_string(item); std::string accesserUserId = "accesserUserId" + std::to_string(item); std::string accesserAccountId = "accesserAccountId" + std::to_string(item); @@ -652,7 +653,7 @@ void AuthMessageProcessor::ParseAclFromJson(const nlohmann::json &jsonObject, in !IsString(jsonObject, accesserAccountId) || !IsInt32(jsonObject, accesserTokenId) || !IsString(jsonObject, accesseeDeviceId) || !IsInt32(jsonObject, accesseeUserId) || !IsString(jsonObject, accesseeAccountId) || !IsInt32(jsonObject, accesseeTokenId)) { - isSame = false; + LOGE("ParseAclFromJson format error."); return; } if (profile.GetAccesser().GetAccesserDeviceId() != jsonObject[accesserDeviceId].get() || @@ -663,7 +664,11 @@ void AuthMessageProcessor::ParseAclFromJson(const nlohmann::json &jsonObject, in profile.GetAccessee().GetAccesseeUserId() != jsonObject[accesseeUserId].get() || profile.GetAccessee().GetAccesseeAccountId() != jsonObject[accesseeAccountId].get() || profile.GetAccessee().GetAccesseeTokenId() != jsonObject[accesseeTokenId].get()) { + needDelete = true; isSame = false; + } + if (!needDelete) { + isSame = true; return; } } -- Gitee From 5916b998b077d15e33843c0d4ef42bf9b719ed82 Mon Sep 17 00:00:00 2001 From: BrainL Date: Mon, 17 Feb 2025 17:29:11 +0800 Subject: [PATCH 03/11] update isSame logic. Signed-off-by: BrainL --- .../implementation/src/authentication/auth_message_processor.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/implementation/src/authentication/auth_message_processor.cpp b/services/implementation/src/authentication/auth_message_processor.cpp index 9e443bcbc..b23a28f87 100644 --- a/services/implementation/src/authentication/auth_message_processor.cpp +++ b/services/implementation/src/authentication/auth_message_processor.cpp @@ -654,6 +654,7 @@ void AuthMessageProcessor::ParseAclFromJson(const nlohmann::json &jsonObject, in !IsString(jsonObject, accesseeDeviceId) || !IsInt32(jsonObject, accesseeUserId) || !IsString(jsonObject, accesseeAccountId) || !IsInt32(jsonObject, accesseeTokenId)) { LOGE("ParseAclFromJson format error."); + isSame = true; return; } if (profile.GetAccesser().GetAccesserDeviceId() != jsonObject[accesserDeviceId].get() || -- Gitee From 114aedf71be03e6390a8a5b9a85f23114edc4648 Mon Sep 17 00:00:00 2001 From: BrainL Date: Sat, 22 Feb 2025 15:54:44 +0800 Subject: [PATCH 04/11] fix code error Signed-off-by: BrainL --- .../authentication/auth_message_processor.h | 2 + .../authentication/auth_message_processor.cpp | 48 ++++++++++++++----- .../src/authentication/dm_auth_manager.cpp | 20 ++++++-- 3 files changed, 54 insertions(+), 16 deletions(-) diff --git a/services/implementation/include/authentication/auth_message_processor.h b/services/implementation/include/authentication/auth_message_processor.h index 5227d2891..c1bb1c91d 100644 --- a/services/implementation/include/authentication/auth_message_processor.h +++ b/services/implementation/include/authentication/auth_message_processor.h @@ -110,6 +110,8 @@ private: void CreateResponseAuthMessage(nlohmann::json &json); void ParseAuthResponseMessage(nlohmann::json &json); int32_t ParseAuthRequestMessage(nlohmann::json &json); + void SyncIdenticalAccountAcl(DistributedDeviceProfile::AccessControlProfile profile, + const nlohmann::json &json, bool &isSame, bool &isDelete, int32_t index); void ParseNegotiateMessage(const nlohmann::json &json); void ParseRespNegotiateMessage(const nlohmann::json &json); void CreateResponseFinishMessage(nlohmann::json &json); diff --git a/services/implementation/src/authentication/auth_message_processor.cpp b/services/implementation/src/authentication/auth_message_processor.cpp index b23a28f87..cf4097671 100644 --- a/services/implementation/src/authentication/auth_message_processor.cpp +++ b/services/implementation/src/authentication/auth_message_processor.cpp @@ -230,6 +230,7 @@ void AuthMessageProcessor::CreateLocalAclParcel(nlohmann::json &json) std::string accesseeUserId = "accesseeUserId" + std::to_string(item); std::string accesseeAccountId = "accesseeAccountId" + std::to_string(item); std::string accesseeTokenId = "accesseeTokenId" + std::to_string(item); + std::string bindType = "bindType" + std::to_string(item); json[accesserDeviceId] = requestProfiles_.at(item).GetAccesser().GetAccesserDeviceId(); json[accesserUserId] = requestProfiles_.at(item).GetAccesser().GetAccesserUserId(); json[accesserAccountId] = requestProfiles_.at(item).GetAccesser().GetAccesserAccountId(); @@ -238,6 +239,7 @@ void AuthMessageProcessor::CreateLocalAclParcel(nlohmann::json &json) json[accesseeUserId] = requestProfiles_.at(item).GetAccessee().GetAccesseeUserId(); json[accesseeAccountId] = requestProfiles_.at(item).GetAccessee().GetAccesseeAccountId(); json[accesseeTokenId] = requestProfiles_.at(item).GetAccessee().GetAccesseeTokenId(); + json[bindType] = requestProfiles_.at(item).GetBindType(); } } @@ -640,7 +642,7 @@ void AuthMessageProcessor::ParseAclFromJson(const nlohmann::json &jsonObject, in DistributedDeviceProfile::AccessControlProfile profile, bool &isSame) { for (int32_t item = 0; item < size; item++) { - bool needDelete = false; + bool isDelete = false; std::string accesserDeviceId = "accesserDeviceId" + std::to_string(item); std::string accesserUserId = "accesserUserId" + std::to_string(item); std::string accesserAccountId = "accesserAccountId" + std::to_string(item); @@ -649,6 +651,7 @@ void AuthMessageProcessor::ParseAclFromJson(const nlohmann::json &jsonObject, in std::string accesseeUserId = "accesseeUserId" + std::to_string(item); std::string accesseeAccountId = "accesseeAccountId" + std::to_string(item); std::string accesseeTokenId = "accesseeTokenId" + std::to_string(item); + std::string bindType = "bindType" + std::to_string(item); if (!IsString(jsonObject, accesserDeviceId) || !IsInt32(jsonObject, accesserUserId) || !IsString(jsonObject, accesserAccountId) || !IsInt32(jsonObject, accesserTokenId) || !IsString(jsonObject, accesseeDeviceId) || !IsInt32(jsonObject, accesseeUserId) || @@ -657,24 +660,45 @@ void AuthMessageProcessor::ParseAclFromJson(const nlohmann::json &jsonObject, in isSame = true; return; } - if (profile.GetAccesser().GetAccesserDeviceId() != jsonObject[accesserDeviceId].get() || - profile.GetAccesser().GetAccesserUserId() != jsonObject[accesserUserId].get() || - profile.GetAccesser().GetAccesserAccountId() != jsonObject[accesserAccountId].get() || - profile.GetAccesser().GetAccesserTokenId() != jsonObject[accesserTokenId].get() || - profile.GetAccessee().GetAccesseeDeviceId() != jsonObject[accesseeDeviceId].get() || - profile.GetAccessee().GetAccesseeUserId() != jsonObject[accesseeUserId].get() || - profile.GetAccessee().GetAccesseeAccountId() != jsonObject[accesseeAccountId].get() || - profile.GetAccessee().GetAccesseeTokenId() != jsonObject[accesseeTokenId].get()) { - needDelete = true; - isSame = false; + if (profile.GetBindType() == DM_IDENTICAL_ACCOUNT && + jsonObject[bindType].get() == DM_IDENTICAL_ACCOUNT) { + SyncIdenticalAccountAcl(profile, jsonObject, isSame, isDelete, item); + } else { + if (profile.GetAccesser().GetAccesserDeviceId() != jsonObject[accesserDeviceId].get() || + profile.GetAccesser().GetAccesserUserId() != jsonObject[accesserUserId].get() || + profile.GetAccesser().GetAccesserAccountId() != jsonObject[accesserAccountId].get() || + profile.GetAccesser().GetAccesserTokenId() != jsonObject[accesserTokenId].get() || + profile.GetAccessee().GetAccesseeDeviceId() != jsonObject[accesseeDeviceId].get() || + profile.GetAccessee().GetAccesseeUserId() != jsonObject[accesseeUserId].get() || + profile.GetAccessee().GetAccesseeAccountId() != jsonObject[accesseeAccountId].get() || + profile.GetAccessee().GetAccesseeTokenId() != jsonObject[accesseeTokenId].get()) { + isDelete = true; + isSame = false; + } } - if (!needDelete) { + if (!isDelete) { isSame = true; return; } } } +void AuthMessageProcessor::SyncIdenticalAccountAcl(DistributedDeviceProfile::AccessControlProfile profile, + const nlohmann::json &json, bool &isSame, bool &isDelete, int32_t index) +{ + std::string accesserDeviceId = "accesserDeviceId" + std::to_string(index); + std::string accesserAccountId = "accesserAccountId" + std::to_string(index); + std::string accesseeDeviceId = "accesseeDeviceId" + std::to_string(index); + std::string accesseeAccountId = "accesseeAccountId" + std::to_string(index); + if (profile.GetAccesser().GetAccesserDeviceId() != jsonObject[accesseeDeviceId].get() || + profile.GetAccessee().GetAccesseeDeviceId() != jsonObject[accesserDeviceId].get() || + profile.GetAccesser().GetAccesserAccountId() != jsonObject[accesseeAccountId].get() || + profile.GetAccessee().GetAccesseeAccountId() != jsonObject[accesserAccountId].get()) { + isDelete = true; + isSame = false; + } +} + void AuthMessageProcessor::SyncAclByRemote(DistributedDeviceProfile::AccessControlProfile profile, int32_t size, const nlohmann::json &json) { diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 9de888780..514d64109 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -863,9 +863,6 @@ void DmAuthManager::StartNegotiate(const int32_t &sessionId) authResponseContext_->isIdenticalAccount = false; authResponseContext_->edition = DM_VERSION_5_0_3; authMessageProcessor_->SetResponseContext(authResponseContext_); - std::vector profiles = - DeviceProfileConnector::GetInstance().GetAccessControlProfile(); - authMessageProcessor_->SetRequestProfiles(profiles); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_NEGOTIATE); softbusConnector_->GetSoftbusSession()->SendData(sessionId, message); if (timer_ != nullptr) { @@ -919,7 +916,13 @@ void DmAuthManager::RespNegotiate(const int32_t &sessionId) LOGI("DmAuthManager::RespNegotiate sessionid %{public}d", sessionId); std::vector profiles = DeviceProfileConnector::GetInstance().GetAccessControlProfile(); - authMessageProcessor_->SetRequestProfiles(profiles); + std::vector profilesFilter = {}; + for (auth &item : profiles) { + if (item.GetTrustedDeviceId() == authResponseContext_->localDeviceId) { + profilesFilter.push_back(item); + } + } + authMessageProcessor_->SetRequestProfiles(profilesFilter); remoteDeviceId_ = authResponseContext_->localDeviceId; authResponseContext_->networkId = softbusConnector_->GetLocalDeviceNetworkId(); authResponseContext_->targetDeviceName = softbusConnector_->GetLocalDeviceName(); @@ -971,6 +974,15 @@ void DmAuthManager::SendAuthRequest(const int32_t &sessionId) return; } remoteDeviceId_ = authResponseContext_->localDeviceId; + std::vector profiles = + DeviceProfileConnector::GetInstance().GetAccessControlProfile(); + std::vector profilesFilter = {}; + for (auth &item : profiles) { + if (item.GetTrustedDeviceId() == remoteDeviceId_) { + profilesFilter.push_back(item); + } + } + authMessageProcessor_->SetRequestProfiles(profilesFilter); remoteVersion_ = ConvertSinkVersion(authResponseContext_->dmVersion); if (timer_ != nullptr) { timer_->DeleteTimer(std::string(NEGOTIATE_TIMEOUT_TASK)); -- Gitee From d4e40395f6fd100dbd9448627876ef70e538e69c Mon Sep 17 00:00:00 2001 From: BrainL Date: Sat, 22 Feb 2025 16:15:53 +0800 Subject: [PATCH 05/11] code format Signed-off-by: BrainL --- .../authentication/auth_message_processor.h | 2 ++ .../authentication/auth_message_processor.cpp | 36 +++++++++++++------ 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/services/implementation/include/authentication/auth_message_processor.h b/services/implementation/include/authentication/auth_message_processor.h index c1bb1c91d..dfc9a7462 100644 --- a/services/implementation/include/authentication/auth_message_processor.h +++ b/services/implementation/include/authentication/auth_message_processor.h @@ -112,6 +112,8 @@ private: int32_t ParseAuthRequestMessage(nlohmann::json &json); void SyncIdenticalAccountAcl(DistributedDeviceProfile::AccessControlProfile profile, const nlohmann::json &json, bool &isSame, bool &isDelete, int32_t index); + void SyncPointToPointAcl(DistributedDeviceProfile::AccessControlProfile profile, + const nlohmann::json &json, bool &isSame, bool &isDelete, int32_t index); void ParseNegotiateMessage(const nlohmann::json &json); void ParseRespNegotiateMessage(const nlohmann::json &json); void CreateResponseFinishMessage(nlohmann::json &json); diff --git a/services/implementation/src/authentication/auth_message_processor.cpp b/services/implementation/src/authentication/auth_message_processor.cpp index cf4097671..8ea4e7c3c 100644 --- a/services/implementation/src/authentication/auth_message_processor.cpp +++ b/services/implementation/src/authentication/auth_message_processor.cpp @@ -664,17 +664,7 @@ void AuthMessageProcessor::ParseAclFromJson(const nlohmann::json &jsonObject, in jsonObject[bindType].get() == DM_IDENTICAL_ACCOUNT) { SyncIdenticalAccountAcl(profile, jsonObject, isSame, isDelete, item); } else { - if (profile.GetAccesser().GetAccesserDeviceId() != jsonObject[accesserDeviceId].get() || - profile.GetAccesser().GetAccesserUserId() != jsonObject[accesserUserId].get() || - profile.GetAccesser().GetAccesserAccountId() != jsonObject[accesserAccountId].get() || - profile.GetAccesser().GetAccesserTokenId() != jsonObject[accesserTokenId].get() || - profile.GetAccessee().GetAccesseeDeviceId() != jsonObject[accesseeDeviceId].get() || - profile.GetAccessee().GetAccesseeUserId() != jsonObject[accesseeUserId].get() || - profile.GetAccessee().GetAccesseeAccountId() != jsonObject[accesseeAccountId].get() || - profile.GetAccessee().GetAccesseeTokenId() != jsonObject[accesseeTokenId].get()) { - isDelete = true; - isSame = false; - } + SyncPointToPointAcl(profile, jsonObject, isSame, isDelete, item); } if (!isDelete) { isSame = true; @@ -699,6 +689,30 @@ void AuthMessageProcessor::SyncIdenticalAccountAcl(DistributedDeviceProfile::Acc } } +void AuthMessageProcessor::SyncPointToPointAcl(DistributedDeviceProfile::AccessControlProfile profile, + const nlohmann::json &json, bool &isSame, bool &isDelete, int32_t index) +{ + std::string accesserDeviceId = "accesserDeviceId" + std::to_string(index); + std::string accesserUserId = "accesserUserId" + std::to_string(index); + std::string accesserAccountId = "accesserAccountId" + std::to_string(index); + std::string accesserTokenId = "accesserTokenId" + std::to_string(index); + std::string accesseeDeviceId = "accesseeDeviceId" + std::to_string(index); + std::string accesseeUserId = "accesseeUserId" + std::to_string(index); + std::string accesseeAccountId = "accesseeAccountId" + std::to_string(index); + std::string accesseeTokenId = "accesseeTokenId" + std::to_string(index); + if (profile.GetAccesser().GetAccesserDeviceId() != jsonObject[accesserDeviceId].get() || + profile.GetAccesser().GetAccesserUserId() != jsonObject[accesserUserId].get() || + profile.GetAccesser().GetAccesserAccountId() != jsonObject[accesserAccountId].get() || + profile.GetAccesser().GetAccesserTokenId() != jsonObject[accesserTokenId].get() || + profile.GetAccessee().GetAccesseeDeviceId() != jsonObject[accesseeDeviceId].get() || + profile.GetAccessee().GetAccesseeUserId() != jsonObject[accesseeUserId].get() || + profile.GetAccessee().GetAccesseeAccountId() != jsonObject[accesseeAccountId].get() || + profile.GetAccessee().GetAccesseeTokenId() != jsonObject[accesseeTokenId].get()) { + isDelete = true; + isSame = false; + } +} + void AuthMessageProcessor::SyncAclByRemote(DistributedDeviceProfile::AccessControlProfile profile, int32_t size, const nlohmann::json &json) { -- Gitee From ff046ced3cc86624511fac69de6c59684871bc9d Mon Sep 17 00:00:00 2001 From: BrainL Date: Sat, 22 Feb 2025 16:38:12 +0800 Subject: [PATCH 06/11] check parse Signed-off-by: BrainL --- .../src/authentication/auth_message_processor.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/implementation/src/authentication/auth_message_processor.cpp b/services/implementation/src/authentication/auth_message_processor.cpp index 8ea4e7c3c..ace98041a 100644 --- a/services/implementation/src/authentication/auth_message_processor.cpp +++ b/services/implementation/src/authentication/auth_message_processor.cpp @@ -655,7 +655,8 @@ void AuthMessageProcessor::ParseAclFromJson(const nlohmann::json &jsonObject, in if (!IsString(jsonObject, accesserDeviceId) || !IsInt32(jsonObject, accesserUserId) || !IsString(jsonObject, accesserAccountId) || !IsInt32(jsonObject, accesserTokenId) || !IsString(jsonObject, accesseeDeviceId) || !IsInt32(jsonObject, accesseeUserId) || - !IsString(jsonObject, accesseeAccountId) || !IsInt32(jsonObject, accesseeTokenId)) { + !IsString(jsonObject, accesseeAccountId) || !IsInt32(jsonObject, accesseeTokenId) || + !IsInt32(jsonObject, bindType)) { LOGE("ParseAclFromJson format error."); isSame = true; return; -- Gitee From 50e6dca7bf5049797a57efb32e9c778b76e35d9a Mon Sep 17 00:00:00 2001 From: BrainL Date: Sat, 22 Feb 2025 16:59:25 +0800 Subject: [PATCH 07/11] update code param Signed-off-by: BrainL --- .../src/authentication/auth_message_processor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/implementation/src/authentication/auth_message_processor.cpp b/services/implementation/src/authentication/auth_message_processor.cpp index ace98041a..bca54b3e2 100644 --- a/services/implementation/src/authentication/auth_message_processor.cpp +++ b/services/implementation/src/authentication/auth_message_processor.cpp @@ -675,7 +675,7 @@ void AuthMessageProcessor::ParseAclFromJson(const nlohmann::json &jsonObject, in } void AuthMessageProcessor::SyncIdenticalAccountAcl(DistributedDeviceProfile::AccessControlProfile profile, - const nlohmann::json &json, bool &isSame, bool &isDelete, int32_t index) + const nlohmann::json &jsonObject, bool &isSame, bool &isDelete, int32_t index) { std::string accesserDeviceId = "accesserDeviceId" + std::to_string(index); std::string accesserAccountId = "accesserAccountId" + std::to_string(index); @@ -691,7 +691,7 @@ void AuthMessageProcessor::SyncIdenticalAccountAcl(DistributedDeviceProfile::Acc } void AuthMessageProcessor::SyncPointToPointAcl(DistributedDeviceProfile::AccessControlProfile profile, - const nlohmann::json &json, bool &isSame, bool &isDelete, int32_t index) + const nlohmann::json &jsonObject, bool &isSame, bool &isDelete, int32_t index) { std::string accesserDeviceId = "accesserDeviceId" + std::to_string(index); std::string accesserUserId = "accesserUserId" + std::to_string(index); -- Gitee From 4a0c3ed3a3fdb7658a376e7a9b293f5dcb797d94 Mon Sep 17 00:00:00 2001 From: BrainL Date: Sat, 22 Feb 2025 17:08:35 +0800 Subject: [PATCH 08/11] change method parameter Signed-off-by: BrainL --- .../implementation/src/authentication/dm_auth_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 514d64109..c795f9a4b 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -917,7 +917,7 @@ void DmAuthManager::RespNegotiate(const int32_t &sessionId) std::vector profiles = DeviceProfileConnector::GetInstance().GetAccessControlProfile(); std::vector profilesFilter = {}; - for (auth &item : profiles) { + for (auto &item : profiles) { if (item.GetTrustedDeviceId() == authResponseContext_->localDeviceId) { profilesFilter.push_back(item); } @@ -977,7 +977,7 @@ void DmAuthManager::SendAuthRequest(const int32_t &sessionId) std::vector profiles = DeviceProfileConnector::GetInstance().GetAccessControlProfile(); std::vector profilesFilter = {}; - for (auth &item : profiles) { + for (auto &item : profiles) { if (item.GetTrustedDeviceId() == remoteDeviceId_) { profilesFilter.push_back(item); } -- Gitee From 42b79590d3e75c3862156e60c4b9a58783f13f90 Mon Sep 17 00:00:00 2001 From: BrainL Date: Sat, 22 Feb 2025 17:35:47 +0800 Subject: [PATCH 09/11] =?UTF-8?q?=E5=8F=97=E4=BF=A1=E4=BB=BB=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: BrainL --- .../implementation/src/authentication/dm_auth_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index c795f9a4b..cd47aa505 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -918,7 +918,7 @@ void DmAuthManager::RespNegotiate(const int32_t &sessionId) DeviceProfileConnector::GetInstance().GetAccessControlProfile(); std::vector profilesFilter = {}; for (auto &item : profiles) { - if (item.GetTrustedDeviceId() == authResponseContext_->localDeviceId) { + if (item.GetTrustDeviceId() == authResponseContext_->localDeviceId) { profilesFilter.push_back(item); } } @@ -978,7 +978,7 @@ void DmAuthManager::SendAuthRequest(const int32_t &sessionId) DeviceProfileConnector::GetInstance().GetAccessControlProfile(); std::vector profilesFilter = {}; for (auto &item : profiles) { - if (item.GetTrustedDeviceId() == remoteDeviceId_) { + if (item.GetTrustDeviceId() == remoteDeviceId_) { profilesFilter.push_back(item); } } -- Gitee From 064148dea4ee8ad2a3e7851a589a660a7db32acd Mon Sep 17 00:00:00 2001 From: BrainL Date: Sat, 22 Feb 2025 20:05:30 +0800 Subject: [PATCH 10/11] update auth message Signed-off-by: BrainL --- .../src/authentication/auth_message_processor.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/services/implementation/src/authentication/auth_message_processor.cpp b/services/implementation/src/authentication/auth_message_processor.cpp index bca54b3e2..006cc89fa 100644 --- a/services/implementation/src/authentication/auth_message_processor.cpp +++ b/services/implementation/src/authentication/auth_message_processor.cpp @@ -628,10 +628,14 @@ void AuthMessageProcessor::ParseNegotiateMessage(const nlohmann::json &json) void AuthMessageProcessor::ParseRemoteAcl(const nlohmann::json &json) { - int32_t profilesSize = 0; + int32_t profilesSize = -1; if (IsInt32(json, TAG_PROFILES_SIZE)) { profilesSize = json[TAG_PROFILES_SIZE].get(); } + if (profilesSize < 0) { + LOGI("ParseRemoteAcl profilesSize is invalid."); + return; + } for (uint32_t reqItem = 0; reqItem < requestProfiles_.size(); reqItem++) { LOGI("ParseRemoteAcl SyncAclByRemote Start."); SyncAclByRemote(requestProfiles_.at(reqItem), profilesSize, json); -- Gitee From 525ecec64037a12896cb60bb621da69fdcbf4d43 Mon Sep 17 00:00:00 2001 From: BrainL Date: Sat, 22 Feb 2025 20:13:31 +0800 Subject: [PATCH 11/11] Merge base Signed-off-by: BrainL --- .../include/deviceprofile_connector.h | 5 + .../src/deviceprofile_connector.cpp | 206 +++++++++--------- display/AppScope/app.json | 4 +- .../src/main/ets/pages/ConfirmDialog.ets | 16 +- .../entry/src/main/ets/pages/PinDialog.ets | 10 + display/entry/src/main/module.json | 5 + .../native_cpp/include/dm_device_info.h | 3 +- .../include/dm_device_profile_info.h | 90 ++++---- .../native_cpp/include/dm_publish_info.h | 4 + .../include/i_dm_service_impl_ext.h | 12 - .../native_cpp/src/device_manager_impl.cpp | 15 +- .../src/ipc/standard/ipc_cmd_parser.cpp | 15 +- .../kits/js/src/native_devicemanager_js.cpp | 5 + interfaces/kits/js4.0/src/dm_native_util.cpp | 3 - .../js4.0/src/native_devicemanager_js.cpp | 2 + .../authentication/auth_message_processor.h | 1 + .../include/authentication/dm_auth_manager.h | 2 + .../authentication/auth_message_processor.cpp | 6 + .../src/authentication/dm_auth_manager.cpp | 31 ++- .../src/cryptomgr/crypto_mgr.cpp | 2 +- .../dependency/softbus/softbus_connector.cpp | 12 +- .../src/device_manager_service_impl.cpp | 10 +- .../devicestate/dm_device_state_manager.cpp | 10 +- .../include/softbus/softbus_listener.h | 1 + .../src/advertise/advertise_manager.cpp | 7 + .../service/src/device_manager_service.cpp | 1 + .../src/device_manager_service_listener.cpp | 13 +- .../src/ipc/standard/ipc_cmd_parser.cpp | 193 ++++------------ .../service/src/softbus/softbus_listener.cpp | 70 ++++-- .../softbuscache/src/dm_softbus_cache.cpp | 10 +- .../hichain_connector_fuzzer.cpp | 38 ++++ .../UTTest_dm_auth_manager_first.cpp | 19 +- test/servicesfuzztest/BUILD.gn | 6 +- .../cryptomgr_fuzzer/BUILD.gn | 91 ++++++++ .../cryptomgr_fuzzer/corpus/init | 13 ++ .../cryptomgr_fuzzer/crypto_mgr_fuzzer.cpp | 158 ++++++++++++++ .../cryptomgr_fuzzer/crypto_mgr_fuzzer.h | 21 ++ .../cryptomgr_fuzzer/project.xml | 25 +++ .../dmcommtool_fuzzer/BUILD.gn | 91 ++++++++ .../dmcommtool_fuzzer/corpus/init | 13 ++ .../dmcommtool_fuzzer/dm_comm_tool_fuzzer.cpp | 72 ++++++ .../dmcommtool_fuzzer/dm_comm_tool_fuzzer.h | 21 ++ .../dmcommtool_fuzzer/project.xml | 25 +++ .../dmtransport_fuzzer/BUILD.gn | 91 ++++++++ .../dmtransport_fuzzer/corpus/init | 13 ++ .../dm_transport_fuzzer.cpp | 133 +++++++++++ .../dmtransport_fuzzer/dm_transport_fuzzer.h | 21 ++ .../dmtransport_fuzzer/project.xml | 25 +++ .../dpinitcallback_fuzzer/BUILD.gn | 90 ++++++++ .../dpinitcallback_fuzzer/corpus/init | 13 ++ .../dp_init_callback_fuzzer.cpp | 82 +++++++ .../dp_init_callback_fuzzer.h | 21 ++ .../dpinitcallback_fuzzer/project.xml | 25 +++ .../UTTest_softbus_listener.cpp | 113 ++++++++++ .../softbusunittest/UTTest_softbus_listener.h | 8 + test/unittest/BUILD.gn | 4 + .../UTTest_device_manager_impl_two.cpp | 48 ++++ .../UTTest_device_manager_service_two.cpp | 60 +++++ test/unittest/mock/dm_crypto_mock.cpp | 2 + test/unittest/mock/dm_softbus_cache_mock.cpp | 5 + test/unittest/mock/dm_softbus_cache_mock.h | 2 + utils/include/appInfo/standard/app_manager.h | 1 + 62 files changed, 1730 insertions(+), 384 deletions(-) create mode 100644 test/servicesfuzztest/cryptomgr_fuzzer/BUILD.gn create mode 100644 test/servicesfuzztest/cryptomgr_fuzzer/corpus/init create mode 100644 test/servicesfuzztest/cryptomgr_fuzzer/crypto_mgr_fuzzer.cpp create mode 100644 test/servicesfuzztest/cryptomgr_fuzzer/crypto_mgr_fuzzer.h create mode 100644 test/servicesfuzztest/cryptomgr_fuzzer/project.xml create mode 100644 test/servicesfuzztest/dmcommtool_fuzzer/BUILD.gn create mode 100644 test/servicesfuzztest/dmcommtool_fuzzer/corpus/init create mode 100644 test/servicesfuzztest/dmcommtool_fuzzer/dm_comm_tool_fuzzer.cpp create mode 100644 test/servicesfuzztest/dmcommtool_fuzzer/dm_comm_tool_fuzzer.h create mode 100644 test/servicesfuzztest/dmcommtool_fuzzer/project.xml create mode 100644 test/servicesfuzztest/dmtransport_fuzzer/BUILD.gn create mode 100644 test/servicesfuzztest/dmtransport_fuzzer/corpus/init create mode 100644 test/servicesfuzztest/dmtransport_fuzzer/dm_transport_fuzzer.cpp create mode 100644 test/servicesfuzztest/dmtransport_fuzzer/dm_transport_fuzzer.h create mode 100644 test/servicesfuzztest/dmtransport_fuzzer/project.xml create mode 100644 test/servicesfuzztest/dpinitcallback_fuzzer/BUILD.gn create mode 100644 test/servicesfuzztest/dpinitcallback_fuzzer/corpus/init create mode 100644 test/servicesfuzztest/dpinitcallback_fuzzer/dp_init_callback_fuzzer.cpp create mode 100644 test/servicesfuzztest/dpinitcallback_fuzzer/dp_init_callback_fuzzer.h create mode 100644 test/servicesfuzztest/dpinitcallback_fuzzer/project.xml diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index f37fc6b9b..e4e5d7038 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -68,6 +68,7 @@ typedef struct DmAccesser { std::string requestAccountId; std::string requestDeviceId; int32_t requestTargetClass; + std::string requestDeviceName; } DmAccesser; typedef struct DmAccessee { @@ -77,6 +78,7 @@ typedef struct DmAccessee { std::string trustAccountId; std::string trustDeviceId; int32_t trustTargetClass; + std::string trustDeviceName; } DmAccessee; typedef struct DmOfflineParam { @@ -168,6 +170,7 @@ public: int32_t UnSubscribeDeviceProfileInited(); int32_t PutAllTrustedDevices(const std::vector &deviceInfos); int32_t CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId); + int32_t UpdateAclDeviceName(const std::string &udid, const std::string &newDeviceName); private: int32_t HandleDmAuthForm(DistributedDeviceProfile::AccessControlProfile profiles, DmDiscoveryInfo discoveryInfo); @@ -176,6 +179,8 @@ private: void ProcessBindType(DistributedDeviceProfile::AccessControlProfile profiles, std::string localDeviceId, std::vector &sinkBindType, std::vector &bindTypeIndex, uint32_t index, std::string targetDeviceId); + bool CheckAppLevelAccess(const DistributedDeviceProfile::AccessControlProfile &profile, + const DmAccessCaller &caller, const DmAccessCallee &callee); int32_t GetAuthForm(DistributedDeviceProfile::AccessControlProfile profiles, const std::string &trustDev, const std::string &reqDev); int32_t CheckAuthForm(DmAuthForm form, DistributedDeviceProfile::AccessControlProfile profiles, diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 630476310..6e673df9d 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -249,11 +249,16 @@ int32_t DeviceProfileConnector::GetAuthForm(DistributedDeviceProfile::AccessCont std::vector DeviceProfileConnector::GetBindTypeByPkgName(std::string pkgName, std::string requestDeviceId, std::string trustUdid) { - LOGI("Start."); + LOGI("Start requestDeviceId %{public}s, trustUdid %{public}s.", GetAnonyString(requestDeviceId).c_str(), + GetAnonyString(trustUdid).c_str()); + std::vector bindTypeVec; + if (requestDeviceId.empty() || trustUdid.empty() || requestDeviceId == trustUdid) { + LOGE("Input udid param invalied."); + return bindTypeVec; + } std::vector profiles = GetAccessControlProfileByUserId(MultipleUserConnector::GetFirstForegroundUserId()); LOGI("AccessControlProfile size is %{public}zu", profiles.size()); - std::vector bindTypeVec; for (auto &item : profiles) { if (trustUdid != item.GetTrustDeviceId() || item.GetStatus() != ACTIVE) { continue; @@ -282,41 +287,40 @@ uint64_t DeviceProfileConnector::GetTokenIdByNameAndDeviceId(std::string pkgName return peerTokenId; } -void DeviceProfileConnector::GetParamBindTypeVec(AccessControlProfile profiles, std::string requestDeviceId, +void DeviceProfileConnector::GetParamBindTypeVec(AccessControlProfile profile, std::string requestDeviceId, std::vector &bindTypeVec, std::string trustUdid) { - if (profiles.GetBindType() == DM_IDENTICAL_ACCOUNT) { - bindTypeVec.push_back(IDENTICAL_ACCOUNT_TYPE); + if (!(profile.GetAccesser().GetAccesserDeviceId() == trustUdid && + profile.GetAccessee().GetAccesseeDeviceId() == requestDeviceId) && + !(profile.GetAccessee().GetAccesseeDeviceId() == trustUdid && + profile.GetAccesser().GetAccesserDeviceId() == requestDeviceId)) { + LOGE("input udid param invalied."); + return; } - if (profiles.GetBindType() == DM_POINT_TO_POINT) { - if (profiles.GetBindLevel() == DEVICE) { - bindTypeVec.push_back(DEVICE_PEER_TO_PEER_TYPE); - } - if (profiles.GetBindLevel() == APP) { - if (profiles.GetAccesser().GetAccesserDeviceId() == trustUdid && - profiles.GetAccessee().GetAccesseeDeviceId() == requestDeviceId) { - bindTypeVec.push_back(APP_PEER_TO_PEER_TYPE); + uint32_t bindType = profile.GetBindType(); + switch (bindType) { + case DM_IDENTICAL_ACCOUNT: + bindTypeVec.push_back(IDENTICAL_ACCOUNT_TYPE); + break; + case DM_POINT_TO_POINT: + if (profile.GetBindLevel() == DEVICE) { + bindTypeVec.push_back(DEVICE_PEER_TO_PEER_TYPE); } - if (profiles.GetAccessee().GetAccesseeDeviceId() == trustUdid && - profiles.GetAccesser().GetAccesserDeviceId() == requestDeviceId) { + if (profile.GetBindLevel() == APP) { bindTypeVec.push_back(APP_PEER_TO_PEER_TYPE); } - } - } - if (profiles.GetBindType() == DM_ACROSS_ACCOUNT) { - if (profiles.GetBindLevel() == DEVICE) { - bindTypeVec.push_back(DEVICE_ACROSS_ACCOUNT_TYPE); - } - if (profiles.GetBindLevel() == APP) { - if (profiles.GetAccesser().GetAccesserDeviceId() == trustUdid && - profiles.GetAccessee().GetAccesseeDeviceId() == requestDeviceId) { - bindTypeVec.push_back(APP_ACROSS_ACCOUNT_TYPE); + break; + case DM_ACROSS_ACCOUNT: + if (profile.GetBindLevel() == DEVICE) { + bindTypeVec.push_back(DEVICE_ACROSS_ACCOUNT_TYPE); } - if (profiles.GetAccessee().GetAccesseeDeviceId() == trustUdid && - profiles.GetAccesser().GetAccesserDeviceId() == requestDeviceId) { + if (profile.GetBindLevel() == APP) { bindTypeVec.push_back(APP_ACROSS_ACCOUNT_TYPE); } - } + break; + default: + LOGE("unknown bind type %{public}d.", bindType); + break; } } @@ -442,12 +446,14 @@ int32_t DeviceProfileConnector::PutAccessControlList(DmAclInfo aclInfo, DmAccess accesser.SetAccesserAccountId(dmAccesser.requestAccountId); accesser.SetAccesserTokenId(dmAccesser.requestTokenId); accesser.SetAccesserBundleName(dmAccesser.requestBundleName); + accesser.SetAccesserDeviceName(dmAccesser.requestDeviceName); Accessee accessee; accessee.SetAccesseeDeviceId(dmAccessee.trustDeviceId); accessee.SetAccesseeUserId(dmAccessee.trustUserId); accessee.SetAccesseeAccountId(dmAccessee.trustAccountId); accessee.SetAccesseeTokenId(dmAccessee.trustTokenId); accessee.SetAccesseeBundleName(dmAccessee.trustBundleName); + accessee.SetAccesseeDeviceName(dmAccessee.trustDeviceName); AccessControlProfile profile; profile.SetBindType(aclInfo.bindType); profile.SetBindLevel(aclInfo.bindLevel); @@ -882,22 +888,18 @@ int32_t DeviceProfileConnector::IsSameAccount(const std::string &udid) bool checkAccesserACL(AccessControlProfile& profile, const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee, const std::string &sinkUdid) { - // the device is accesser - if (profile.GetAccesser().GetAccesserUserId() != 0 && - profile.GetAccesser().GetAccesserUserId() != -1 && - (profile.GetAccessee().GetAccesseeUserId() == 0 || profile.GetAccessee().GetAccesseeUserId() == -1)) { - // caller is accesser, callee is accessee - if (profile.GetAccesser().GetAccesserDeviceId() == srcUdid && - profile.GetAccesser().GetAccesserUserId() == caller.userId && - profile.GetAccessee().GetAccesseeDeviceId() == sinkUdid) { - LOGI("old version, the device is accesser, caller is accesser, callee is accessee"); + if ((profile.GetAccesser().GetAccesserUserId() == caller.userId || + profile.GetAccesser().GetAccesserUserId() == 0 || + profile.GetAccesser().GetAccesserUserId() == -1) && + profile.GetAccesser().GetAccesserDeviceId() == srcUdid && + profile.GetAccessee().GetAccesseeDeviceId() == sinkUdid) { + if (callee.userId != 0 && callee.userId == profile.GetAccessee().GetAccesseeUserId()) { + LOGI("accesser success add, callee userId not null!"); return true; - } - // caller is accessee, callee is accesser - if (profile.GetAccesser().GetAccesserDeviceId() == sinkUdid && - profile.GetAccesser().GetAccesserUserId() == callee.userId && - profile.GetAccessee().GetAccesseeDeviceId() == srcUdid) { - LOGI("old version, the device is accesser, caller is accessee, callee is accesser"); + } else if (callee.userId == 0 || + profile.GetAccessee().GetAccesseeUserId() == -1 || + profile.GetAccessee().GetAccesseeUserId() == 0) { + LOGI("accesser success add!"); return true; } } @@ -907,71 +909,35 @@ bool checkAccesserACL(AccessControlProfile& profile, const DmAccessCaller &calle bool checkAccesseeACL(AccessControlProfile& profile, const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee, const std::string &sinkUdid) { - // the device is accessee - if ((profile.GetAccesser().GetAccesserUserId() == 0 || profile.GetAccesser().GetAccesserUserId() == -1) && - profile.GetAccessee().GetAccesseeUserId() != 0 && - profile.GetAccessee().GetAccesseeUserId() != -1) { - // caller is accesser, callee is accessee - if (profile.GetAccesser().GetAccesserDeviceId() == srcUdid && - profile.GetAccessee().GetAccesseeDeviceId() == sinkUdid && - profile.GetAccessee().GetAccesseeUserId() == callee.userId) { - LOGI("old version, the device is accessee, caller is accesser, callee is accessee"); + if ((profile.GetAccessee().GetAccesseeUserId() == caller.userId || + profile.GetAccessee().GetAccesseeUserId() == 0 || + profile.GetAccessee().GetAccesseeUserId() == -1) && + profile.GetAccessee().GetAccesseeDeviceId() == srcUdid && + profile.GetAccesser().GetAccesserDeviceId() == sinkUdid) { + if (callee.userId != 0 && callee.userId == profile.GetAccesser().GetAccesserUserId()) { + LOGI("accessee success add, callee userId not null!"); return true; - } - // caller is accessee, callee is accesser - if (profile.GetAccesser().GetAccesserDeviceId() == sinkUdid && - profile.GetAccessee().GetAccesseeDeviceId() == srcUdid && - profile.GetAccessee().GetAccesseeUserId() == caller.userId) { - LOGI("old version, the device is accessee, caller is accessee, callee is accesser"); + } else if (callee.userId == 0 || + profile.GetAccesser().GetAccesserUserId() == -1 || + profile.GetAccesser().GetAccesserUserId() == 0) { + LOGI("accessee success add!"); return true; } } return false; } -bool checkACLInOldVersion(AccessControlProfile& profile, const DmAccessCaller &caller, - const std::string &srcUdid, const DmAccessCallee &callee, const std::string &sinkUdid) -{ - // cannot consider multi-user for old version - if (checkAccesserACL(profile, caller, srcUdid, callee, sinkUdid) || - checkAccesseeACL(profile, caller, srcUdid, callee, sinkUdid)) { - return true; - } - return false; -} - -bool checkACLInNewVersion(AccessControlProfile& profile, const DmAccessCaller &caller, - const std::string &srcUdid, const DmAccessCallee &callee, const std::string &sinkUdid) -{ - // consider multi-user for new version - // caller is accesser, callee is accessee - if (profile.GetAccesser().GetAccesserDeviceId() == srcUdid && - profile.GetAccesser().GetAccesserUserId() == caller.userId && - profile.GetAccessee().GetAccesseeDeviceId() == sinkUdid && - profile.GetAccessee().GetAccesseeUserId() == callee.userId) { - LOGI("new version, caller is accesser, callee is accessee"); - return true; - } - // caller is accessee, callee is accesser - if (profile.GetAccesser().GetAccesserDeviceId() == sinkUdid && - profile.GetAccesser().GetAccesserUserId() == callee.userId && - profile.GetAccessee().GetAccesseeDeviceId() == srcUdid && - profile.GetAccessee().GetAccesseeUserId() == caller.userId) { - LOGI("new version, caller is accessee, callee is accesser"); - return true; - } - return false; -} - std::vector GetACLByDeviceIdAndUserId(std::vector profiles, const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee, const std::string &sinkUdid) { + LOGI("srcUdid = %{public}s, caller.userId = %{public}s, sinkUdid = %{public}s, callee.userId = %{public}s", + GetAnonyString(srcUdid).c_str(), GetAnonyInt32(caller.userId).c_str(), + GetAnonyString(sinkUdid).c_str(), GetAnonyInt32(callee.userId).c_str()); std::vector profilesFilter; - for (int32_t i = 0; i < profiles.size(); i++) { - AccessControlProfile profile = profiles[i]; - if (checkACLInOldVersion(profile, caller, srcUdid, callee, sinkUdid) || - checkACLInNewVersion(profile, caller, srcUdid, callee, sinkUdid)) { - profilesFilter.push_back(profile); + for (auto &item : profiles) { + if (checkAccesserACL(item, caller, srcUdid, callee, sinkUdid) || + checkAccesseeACL(item, caller, srcUdid, callee, sinkUdid)) { + profilesFilter.push_back(item); } } return profilesFilter; @@ -980,7 +946,7 @@ std::vector GetACLByDeviceIdAndUserId(std::vector profiles = GetAllAccessControlProfile(); std::vector profilesFilter = @@ -1032,7 +998,7 @@ bool DeviceProfileConnector::SingleUserProcess(const DistributedDeviceProfile::A } else if (profile.GetBindLevel() == APP && (profile.GetAccesser().GetAccesserBundleName() == caller.pkgName || profile.GetAccessee().GetAccesseeBundleName() == caller.pkgName)) { - ret = true; + ret = CheckAppLevelAccess(profile, caller, callee); } break; case DM_ACROSS_ACCOUNT: @@ -1041,7 +1007,7 @@ bool DeviceProfileConnector::SingleUserProcess(const DistributedDeviceProfile::A } else if (profile.GetBindLevel() == APP && (profile.GetAccesser().GetAccesserBundleName() == caller.pkgName || profile.GetAccessee().GetAccesseeBundleName() == caller.pkgName)) { - ret = true; + ret = CheckAppLevelAccess(profile, caller, callee); } break; default: @@ -1051,6 +1017,23 @@ bool DeviceProfileConnector::SingleUserProcess(const DistributedDeviceProfile::A return ret; } +bool DeviceProfileConnector::CheckAppLevelAccess(const DistributedDeviceProfile::AccessControlProfile &profile, + const DmAccessCaller &caller, const DmAccessCallee &callee) +{ + if (caller.tokenId == 0 || callee.tokenId == 0) { + return true; + } else { + if ((profile.GetAccesser().GetAccesserTokenId() == caller.tokenId && + profile.GetAccessee().GetAccesseeTokenId() == callee.tokenId) || + (profile.GetAccesser().GetAccesserTokenId() == callee.tokenId && + profile.GetAccessee().GetAccesseeTokenId() == caller.tokenId)) { + return true; + } else { + return false; + } + } +} + int32_t DeviceProfileConnector::CheckIsSameAccount(const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee, const std::string &sinkUdid) { @@ -1726,6 +1709,29 @@ int32_t DeviceProfileConnector::CheckDeviceInfoPermission(const std::string &loc return ERR_DM_NO_PERMISSION; } +int32_t DeviceProfileConnector::UpdateAclDeviceName(const std::string &udid, const std::string &newDeviceName) +{ + std::vector allProfile = + DeviceProfileConnector::GetInstance().GetAllAccessControlProfile(); + for (AccessControlProfile profile : allProfile) { + Accessee acee = profile.GetAccessee(); + if (acee.GetAccesseeDeviceId() == udid) { + acee.SetAccesseeDeviceName(newDeviceName); + profile.SetAccessee(acee); + DistributedDeviceProfileClient::GetInstance().UpdateAccessControlProfile(profile); + return DM_OK; + } + Accesser acer = profile.GetAccesser(); + if (acer.GetAccesserDeviceId() == udid) { + acer.SetAccesserDeviceName(newDeviceName); + profile.SetAccesser(acer); + DistributedDeviceProfileClient::GetInstance().UpdateAccessControlProfile(profile); + return DM_OK; + } + } + return ERR_DM_FAILED; +} + IDeviceProfileConnector *CreateDpConnectorInstance() { return &DeviceProfileConnector::GetInstance(); diff --git a/display/AppScope/app.json b/display/AppScope/app.json index d69b34263..ab9abd159 100644 --- a/display/AppScope/app.json +++ b/display/AppScope/app.json @@ -2,8 +2,8 @@ "app": { "bundleName": "com.ohos.devicemanagerui", "vendor": "example", - "versionCode": 1000032, - "versionName": "1.0.32", + "versionCode": 1000033, + "versionName": "1.0.33", "icon": "$media:app_icon", "label": "$string:app_name", "minAPIVersion": 10, diff --git a/display/entry/src/main/ets/pages/ConfirmDialog.ets b/display/entry/src/main/ets/pages/ConfirmDialog.ets index 598b966e3..47cd31ca0 100644 --- a/display/entry/src/main/ets/pages/ConfirmDialog.ets +++ b/display/entry/src/main/ets/pages/ConfirmDialog.ets @@ -19,6 +19,7 @@ import Constant from '../common/constant'; import common from '@ohos.app.ability.common'; import display from '@ohos.display'; import mediaQuery from '@ohos.mediaquery'; +import i18n from '@ohos.i18n'; let dmClass: deviceManager.DeviceManager | null; let TAG = '[DeviceManagerUI:ConfirmDialog]==>'; @@ -196,6 +197,13 @@ struct ConfirmCustomDialog { .margin({ bottom: 16, top: 24 }) } + private isTibetanLanguages(): boolean { + console.info(`${TAG} isTibetanLanguages in`); + let locale = new Intl.Locale(i18n.System.getSystemLanguage()).toString(); + console.info(`${TAG} isTibetanLanguages: ${locale}`); + return Constant.TIBETAN_LANGUAGES.includes(locale); + } + build() { GridRow({ columns: { xs: 4, sm: 8, md: this.isPC ? 24 : 12 }, @@ -214,6 +222,7 @@ struct ConfirmCustomDialog { .minFontSize(12) .maxFontSize($r('sys.float.ohos_id_text_size_dialog_tittle')) .heightAdaptivePolicy(TextHeightAdaptivePolicy.LAYOUT_CONSTRAINT_FIRST) + .lineHeight(this.isTibetanLanguages() ? 22 : 0) .textOverflow({ overflow: TextOverflow.Ellipsis }) .width('auto') .maxLines(2) @@ -225,6 +234,7 @@ struct ConfirmCustomDialog { .fontSize($r('sys.float.ohos_id_text_size_body2')) .maxLines(2) .width('auto') + .lineHeight(this.isTibetanLanguages() ? 22 : 0) .margin({ top: 8 }) .visibility(this.peerCustomDescription === '' ? Visibility.None : Visibility.Visible) }.margin({ @@ -238,7 +248,7 @@ struct ConfirmCustomDialog { this.onAllowAlways(); }) .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) - .height(40) + .height(this.isTibetanLanguages() ? 'auto' : 40) .width(this.isPC ? 250 : '100%') .backgroundColor(this.btnColor) .onHover((isHover?: boolean, event?: HoverEvent): void => { @@ -262,7 +272,7 @@ struct ConfirmCustomDialog { this.onAllowOnce(); }) .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) - .height(40) + .height(this.isTibetanLanguages() ? 'auto' : 40) .width(this.isPC ? 250 : '100%') .backgroundColor(this.btnColor) .onHover((isHover?: boolean, event?: HoverEvent): void => { @@ -286,7 +296,7 @@ struct ConfirmCustomDialog { .onClick(() => { this.onCancel(); }) - .height(40) + .height(this.isTibetanLanguages() ? 'auto' : 40) .width(this.isPC ? 250 : '100%') .backgroundColor(this.btnColor) .onHover((isHover?: boolean, event?: HoverEvent): void => { diff --git a/display/entry/src/main/ets/pages/PinDialog.ets b/display/entry/src/main/ets/pages/PinDialog.ets index d3ab8eb5d..0a7dcc25c 100644 --- a/display/entry/src/main/ets/pages/PinDialog.ets +++ b/display/entry/src/main/ets/pages/PinDialog.ets @@ -17,6 +17,7 @@ import { BusinessError } from '@ohos.base'; import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; import deviceInfo from '@ohos.deviceInfo'; import Constant from '../common/constant'; +import i18n from '@ohos.i18n'; let dmClass: deviceManager.DeviceManager | null; let TAG = '[DeviceManagerUI:PinDialog]==>'; @@ -66,6 +67,13 @@ struct PinCustomDialog { } } + private isTibetanLanguages(): boolean { + console.info(`${TAG} isTibetanLanguages in`); + let locale = new Intl.Locale(i18n.System.getSystemLanguage()).toString(); + console.info(`${TAG} isTibetanLanguages: ${locale}`); + return Constant.TIBETAN_LANGUAGES.includes(locale); + } + build() { GridRow({ columns: { xs: 4, sm: 8, md: this.isPC ? 24 : 12 }, @@ -79,6 +87,7 @@ struct PinCustomDialog { .fontSize($r('sys.float.ohos_id_text_size_dialog_tittle')) .fontColor($r('sys.color.ohos_id_color_text_primary')) .fontWeight(FontWeight.Bold) + .lineHeight(this.isTibetanLanguages() ? 32.5 : 0) .margin({ left: 24, right: 24 @@ -110,6 +119,7 @@ struct PinCustomDialog { .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) .constraintSize({ minHeight: 40 }) .width('100%') + .height(57) .backgroundColor(this.btnColor) .onClick(() => { if (this.controller) { diff --git a/display/entry/src/main/module.json b/display/entry/src/main/module.json index 0c27af8a5..a1e04e78e 100644 --- a/display/entry/src/main/module.json +++ b/display/entry/src/main/module.json @@ -79,6 +79,11 @@ { "name": "ohos.permission.PRIVACY_WINDOW" } + ], + "metadata": [ + { + "name": "ohos.graphics2d.text.adapter_text_height" + } ] } } \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/include/dm_device_info.h b/interfaces/inner_kits/native_cpp/include/dm_device_info.h index 00d087fcb..e6d3c26ae 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -363,7 +363,7 @@ typedef struct DmAccessCaller { std::string pkgName; std::string networkId; int32_t userId; - uint64_t tokenId; + uint64_t tokenId = 0; std::string extra; } DmAccessCaller; @@ -372,6 +372,7 @@ typedef struct DmAccessCallee { std::string networkId; std::string peerId; int32_t userId; + uint64_t tokenId = 0; std::string extra; } DmAccessCallee; diff --git a/interfaces/inner_kits/native_cpp/include/dm_device_profile_info.h b/interfaces/inner_kits/native_cpp/include/dm_device_profile_info.h index aed31d3df..2f3f01433 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_profile_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_profile_info.h @@ -24,69 +24,69 @@ namespace OHOS { namespace DistributedHardware { typedef struct DmProductInfo { - std::string prodId; - std::string model; - std::string prodName; - std::string prodShortName; - std::string imageVersion; + std::string prodId = ""; + std::string model = ""; + std::string prodName = ""; + std::string prodShortName = ""; + std::string imageVersion = ""; } DmProductInfo; typedef struct DmDeviceIconInfo { - std::string productId; - std::string subProductId; - std::string imageType; - std::string specName; - std::string wiseVersion; - std::string version; - std::string url; + std::string productId = ""; + std::string subProductId = ""; + std::string imageType = ""; + std::string specName = ""; + std::string wiseVersion = ""; + std::string version = ""; + std::string url = ""; std::vector icon = {}; } DmDeviceIconInfo; typedef struct DmServiceProfileInfo { - std::string deviceId; - std::string serviceId; - std::string serviceType; + std::string deviceId = ""; + std::string serviceId = ""; + std::string serviceType = ""; std::map data = {}; } DmServiceProfileInfo; typedef struct DmDeviceProfileInfoFilterOptions { - bool isCloud; + bool isCloud = true; std::vector deviceIdList = {}; } DmDeviceProfileInfoFilterOptions; typedef struct DmDeviceIconInfoFilterOptions { - std::string productId; - std::string subProductId; - std::string imageType; - std::string specName; + std::string productId = ""; + std::string subProductId = ""; + std::string imageType = ""; + std::string specName = ""; } DmDeviceIconInfoFilterOptions; typedef struct DmDeviceProfileInfo { - std::string deviceId; - std::string deviceSn; - std::string mac; - std::string model; - std::string innerModel; - std::string deviceType; - std::string manufacturer; - std::string deviceName; - std::string productId; - std::string subProductId; - std::string sdkVersion; - std::string bleMac; - std::string brMac; - std::string sleMac; - std::string firmwareVersion; - std::string hardwareVersion; - std::string softwareVersion; - int32_t protocolType; - int32_t setupType; - std::string wiseDeviceId; - std::string wiseUserId; - std::string registerTime; - std::string modifyTime; - std::string shareTime; - bool isLocalDevice; + std::string deviceId = ""; + std::string deviceSn = ""; + std::string mac = ""; + std::string model = ""; + std::string innerModel = ""; + std::string deviceType = ""; + std::string manufacturer = ""; + std::string deviceName = ""; + std::string productId = ""; + std::string subProductId = ""; + std::string sdkVersion = ""; + std::string bleMac = ""; + std::string brMac = ""; + std::string sleMac = ""; + std::string firmwareVersion = ""; + std::string hardwareVersion = ""; + std::string softwareVersion = ""; + int32_t protocolType = 0; + int32_t setupType = 0; + std::string wiseDeviceId = ""; + std::string wiseUserId = ""; + std::string registerTime = ""; + std::string modifyTime = ""; + std::string shareTime = ""; + bool isLocalDevice = false; std::vector services = {}; } DmDeviceProfileInfo; diff --git a/interfaces/inner_kits/native_cpp/include/dm_publish_info.h b/interfaces/inner_kits/native_cpp/include/dm_publish_info.h index b003475a7..bb3a48775 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_publish_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_publish_info.h @@ -42,6 +42,10 @@ typedef struct { * Discovery ranging. For details, see {@link PublishInfo}. */ bool ranging; + /** + * Service subscription medium. For details, see {@link DmExchangeMedium}. + */ + DmExchangeMedium medium; } DmPublishInfo; } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext.h b/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext.h index d8629a1df..e67d2a896 100644 --- a/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext.h +++ b/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext.h @@ -105,21 +105,9 @@ public: const std::shared_ptr &listener) = 0; virtual void OnResidentBytesReceived(const int32_t sessionId, const std::string &message) = 0; - /** - * @tc.name: IDMServiceImplExt::GetDeviceProfileInfos - * @tc.desc: GetDeviceProfileInfos - * @tc.type: FUNC - */ - virtual int32_t GetDeviceProfileInfoList(const std::string &pkgName, - const DmDeviceProfileInfoFilterOptions &filterOptions) = 0; - virtual int32_t GetDeviceIconInfo(const std::string &pkgName, - const DmDeviceIconInfoFilterOptions &filterOptions) = 0; virtual void OnSessionOpened(int32_t sessionId, int32_t sessionSide, int32_t result) = 0; virtual void OnSessionClosed(const int32_t sessionId) = 0; virtual void OnBytesReceived(const int32_t sessionId, const std::string message) = 0; - virtual int32_t PutDeviceProfileInfoList(const std::string &pkgName, - const std::vector &deviceProfileInfoList) = 0; - virtual std::vector GetDeviceNamePrefixs() = 0; }; using CreateDMServiceImplExtFuncPtr = IDMServiceImplExt *(*)(void); diff --git a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp index 5ec3166ea..1ae5013f3 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -100,7 +100,8 @@ constexpr const char* DM_HITRACE_INIT = "DM_HITRACE_INIT"; const uint16_t DM_MIN_RANDOM = 1; const uint16_t DM_MAX_RANDOM = 65535; const uint16_t DM_INVALID_FLAG_ID = 0; -const uint16_t DM_IMPORT_AUTH_CODE_LENGTH = 6; +const uint16_t DM_IMPORT_AUTH_CODE_MIN_LENGTH = 6; +const uint16_t DM_IMPORT_AUTH_CODE_MAX_LENGTH = 1024; const int32_t NORMAL = 0; const int32_t SYSTEM_BASIC = 1; const int32_t SYSTEM_CORE = 2; @@ -197,23 +198,23 @@ void DeviceManagerImpl::ConvertDeviceInfoToDeviceBasicInfo(const DmDeviceInfo &i } if (memcpy_s(deviceBasicInfo.deviceName, sizeof(deviceBasicInfo.deviceName), info.deviceName, - std::min(sizeof(deviceBasicInfo.deviceName), sizeof(info.deviceName))) != DM_OK) { + std::min(sizeof(deviceBasicInfo.deviceName), sizeof(info.deviceName))) != DM_OK) { LOGE("ConvertDeviceInfoToDmDevice copy deviceName data failed."); return; } if (memcpy_s(deviceBasicInfo.networkId, sizeof(deviceBasicInfo.networkId), info.networkId, - std::min(sizeof(deviceBasicInfo.networkId), sizeof(info.networkId))) != DM_OK) { + std::min(sizeof(deviceBasicInfo.networkId), sizeof(info.networkId))) != DM_OK) { LOGE("ConvertNodeBasicInfoToDmDevice copy networkId data failed."); return; } - + if (memcpy_s(deviceBasicInfo.deviceId, sizeof(deviceBasicInfo.deviceId), info.deviceId, - std::min(sizeof(deviceBasicInfo.deviceId), sizeof(info.deviceId))) != DM_OK) { + std::min(sizeof(deviceBasicInfo.deviceId), sizeof(info.deviceId))) != DM_OK) { LOGE("ConvertNodeBasicInfoToDmDevice copy deviceId data failed."); return; } - + deviceBasicInfo.deviceTypeId = info.deviceTypeId; } @@ -1644,7 +1645,7 @@ int32_t DeviceManagerImpl::ImportAuthCode(const std::string &pkgName, const std: } LOGI("Start, authCode: %{public}s", GetAnonyString(authCode).c_str()); int32_t length = static_cast(authCode.length()); - if (length != DM_IMPORT_AUTH_CODE_LENGTH) { + if (length < DM_IMPORT_AUTH_CODE_MIN_LENGTH || length > DM_IMPORT_AUTH_CODE_MAX_LENGTH) { LOGE("ImportAuthCode error: Invalid para, authCode size error."); return ERR_DM_INPUT_PARA_INVALID; } diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp index 71606ae4d..db851e355 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp @@ -971,10 +971,7 @@ ON_IPC_READ_RESPONSE(EXPORT_AUTH_CODE, MessageParcel &reply, std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); - if (pRsp == nullptr) { - LOGE("IpcExportAuthCodeRsp pRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pRsp, ERR_DM_FAILED); std::string authCode = reply.ReadString(); pRsp->SetAuthCode(authCode); pRsp->SetErrCode(reply.ReadInt32()); @@ -1467,10 +1464,7 @@ ON_IPC_READ_RESPONSE(IS_SAME_ACCOUNT, MessageParcel &reply, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is nullptr"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); if (!data.WriteInt32(pReq->GetPermissionLevel())) { LOGE("write permissionLevel failed"); @@ -1481,10 +1475,7 @@ ON_IPC_SET_REQUEST(CHECK_API_PERMISSION, std::shared_ptr pBaseReq, Messa ON_IPC_READ_RESPONSE(CHECK_API_PERMISSION, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is nullptr"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index 410ae5b50..d5c2fbcff 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -899,6 +899,7 @@ void DeviceManagerNapi::OnAuthResult(const std::string &deviceId, const std::str } else { napi_call_function(env_, nullptr, handler, DM_NAPI_ARGS_TWO, &result[0], &callResult); napi_delete_reference(env_, authAsyncCallbackInfo_.callback); + authAsyncCallbackInfo_.callback = nullptr; } } else { LOGE("handler is nullptr"); @@ -1668,6 +1669,7 @@ void DeviceManagerNapi::CallGetTrustedDeviceListStatus(napi_env env, napi_status if (handler != nullptr) { NAPI_CALL_RETURN_VOID(env, napi_call_function(env, nullptr, handler, DM_NAPI_ARGS_TWO, &array[0], &callResult)); NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, deviceInfoListAsyncCallbackInfo->callback)); + deviceInfoListAsyncCallbackInfo->callback = nullptr; } else { LOGE("handler is nullptr"); } @@ -1695,6 +1697,7 @@ void DeviceManagerNapi::CallRequestCreInfoStatus(napi_env env, napi_status &stat if (handler != nullptr) { napi_call_function(env, nullptr, handler, DM_NAPI_ARGS_ONE, &result, &callResult); napi_delete_reference(env, creAsyncCallbackInfo->callback); + creAsyncCallbackInfo->callback = nullptr; } else { LOGE("handler is nullptr"); } @@ -1741,6 +1744,7 @@ void DeviceManagerNapi::CallGetLocalDeviceInfo(napi_env env, napi_status &status NAPI_CALL_RETURN_VOID(env, napi_call_function(env, nullptr, handler, DM_NAPI_ARGS_TWO, &result[0], &callResult)); NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, deviceInfoAsyncCallbackInfo->callback)); + deviceInfoAsyncCallbackInfo->callback = nullptr; } else { LOGE("handler is nullptr"); } @@ -3074,6 +3078,7 @@ void DeviceManagerNapi::CallGetDeviceInfoCB(napi_env env, napi_status &status, if (handler != nullptr) { napi_call_function(env, nullptr, handler, DM_NAPI_ARGS_TWO, &result[0], &callResult); napi_delete_reference(env, networkIdAsyncCallbackInfo->callback); + networkIdAsyncCallbackInfo->callback = nullptr; } else { LOGE("handler is nullptr"); } diff --git a/interfaces/kits/js4.0/src/dm_native_util.cpp b/interfaces/kits/js4.0/src/dm_native_util.cpp index 8b08c668a..711ebe4c5 100644 --- a/interfaces/kits/js4.0/src/dm_native_util.cpp +++ b/interfaces/kits/js4.0/src/dm_native_util.cpp @@ -327,8 +327,6 @@ void JsToBindParam(const napi_env &env, const napi_value &object, std::string &b JsObjectToString(env, object, "targetPkgName", targetPkgName, sizeof(targetPkgName)); char metaType[DM_NAPI_BUF_LENGTH] = ""; JsObjectToString(env, object, "metaType", metaType, sizeof(metaType)); - char peerBundleName[DM_NAPI_BUF_LENGTH] = ""; - JsObjectToString(env, object, "peerBundleName", peerBundleName, sizeof(peerBundleName)); std::string metaTypeStr = metaType; isMetaType = !metaTypeStr.empty(); @@ -356,7 +354,6 @@ void JsToBindParam(const napi_env &env, const napi_value &object, std::string &b jsonObj[CUSTOM_DESCRIPTION] = std::string(customDescription); jsonObj[PARAM_KEY_TARGET_PKG_NAME] = std::string(targetPkgName); jsonObj[PARAM_KEY_META_TYPE] = metaTypeStr; - jsonObj[PARAM_KEY_PEER_BUNDLE_NAME] = std::string(peerBundleName); jsonObj[PARAM_KEY_PIN_CODE] = std::string(pinCode); jsonObj[PARAM_KEY_AUTH_TOKEN] = std::string(authToken); jsonObj[PARAM_KEY_IS_SHOW_TRUST_DIALOG] = std::string(isShowTrustDialog); diff --git a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp index eae6007c0..ed6317237 100644 --- a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp @@ -713,6 +713,7 @@ void DeviceManagerNapi::OnAuthResult(const std::string &deviceId, const std::str if (handler != nullptr) { napi_call_function(env_, nullptr, handler, DM_NAPI_ARGS_TWO, &result[0], &callResult); napi_delete_reference(env_, authAsyncCallbackInfo_.callback); + authAsyncCallbackInfo_.callback = nullptr; } else { LOGE("handler is nullptr"); } @@ -1146,6 +1147,7 @@ void DeviceManagerNapi::CallGetAvailableDeviceListStatus(napi_env env, napi_stat NAPI_CALL_RETURN_VOID(env, napi_call_function(env, nullptr, handler, DM_NAPI_ARGS_TWO, &array[0], &callResult)); NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, deviceBasicInfoListAsyncCallbackInfo->callback)); + deviceBasicInfoListAsyncCallbackInfo->callback = nullptr; } else { LOGE("handler is nullptr"); } diff --git a/services/implementation/include/authentication/auth_message_processor.h b/services/implementation/include/authentication/auth_message_processor.h index dfc9a7462..ed2ec831f 100644 --- a/services/implementation/include/authentication/auth_message_processor.h +++ b/services/implementation/include/authentication/auth_message_processor.h @@ -78,6 +78,7 @@ constexpr const char* TAG_BUNDLE_NAME = "bundleName"; constexpr const char* TAG_CRYPTIC_MSG = "encryptMsg"; constexpr const char* TAG_PEER_BUNDLE_NAME = "PEER_BUNDLE_NAME"; constexpr const char* TAG_PROFILES_SIZE = "PROFILES_SIZE"; +constexpr const char* TAG_REMOTE_DEVICE_NAME = "REMOTE_DEVICE_NAME"; class DmAuthManager; struct DmAuthRequestContext; diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index 760000cb4..4c21a9d25 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -134,6 +134,7 @@ typedef struct DmAuthRequestContext { std::string addr; std::string hostPkgLabel; int32_t closeSessionDelaySeconds = 0; + std::string remoteDeviceName; } DmAuthRequestContext; typedef struct DmAuthResponseContext { @@ -191,6 +192,7 @@ typedef struct DmAuthResponseContext { bool isFinish = false; std::string edition; int32_t localBindLevel; + std::string remoteDeviceName; } DmAuthResponseContext; class AuthMessageProcessor; diff --git a/services/implementation/src/authentication/auth_message_processor.cpp b/services/implementation/src/authentication/auth_message_processor.cpp index 006cc89fa..0c7ac9dd8 100644 --- a/services/implementation/src/authentication/auth_message_processor.cpp +++ b/services/implementation/src/authentication/auth_message_processor.cpp @@ -217,6 +217,7 @@ void AuthMessageProcessor::CreateNegotiateMessage(nlohmann::json &json) json[TAG_HAVE_CREDENTIAL] = authResponseContext_->haveCredential; json[TAG_HOST_PKGLABEL] = authResponseContext_->hostPkgLabel; json[TAG_EDITION] = authResponseContext_->edition; + json[TAG_REMOTE_DEVICE_NAME] = authResponseContext_->remoteDeviceName; } void AuthMessageProcessor::CreateLocalAclParcel(nlohmann::json &json) @@ -425,6 +426,8 @@ void AuthMessageProcessor::ParseResponseFinishMessage(nlohmann::json &json) void AuthMessageProcessor::GetAuthReqMessage(nlohmann::json &json) { + authResponseContext_->localDeviceId = ""; + authResponseContext_->deviceId = ""; if (IsInt32(json, TAG_AUTH_TYPE)) { authResponseContext_->authType = json[TAG_AUTH_TYPE].get(); } @@ -623,6 +626,9 @@ void AuthMessageProcessor::ParseNegotiateMessage(const nlohmann::json &json) } else { authResponseContext_->peerBundleName = authResponseContext_->hostPkgName; } + if (IsString(json, TAG_REMOTE_DEVICE_NAME)) { + authResponseContext_->remoteDeviceName = json[TAG_REMOTE_DEVICE_NAME].get(); + } ParsePkgNegotiateMessage(json); } diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index cd47aa505..2df07bc31 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -21,6 +21,7 @@ #include #include "bundle_mgr_interface.h" +#include "bundle_mgr_proxy.h" #include "iservice_registry.h" #if defined(SUPPORT_SCREENLOCK) #include "screenlock_manager.h" @@ -104,6 +105,7 @@ constexpr const char* DM_VERSION_4_1_5_1 = "4.1.5.1"; constexpr const char* DM_VERSION_5_0_1 = "5.0.1"; constexpr const char* DM_VERSION_5_0_2 = "5.0.2"; constexpr const char* DM_VERSION_5_0_3 = "5.0.3"; +constexpr const char* DM_VERSION_5_0_4 = "5.0.4"; std::mutex g_authFinishLock; DmAuthManager::DmAuthManager(std::shared_ptr softbusConnector, @@ -119,7 +121,7 @@ DmAuthManager::DmAuthManager(std::shared_ptr softbusConnector, authUiStateMgr_ = std::make_shared(listener_); authenticationMap_[AUTH_TYPE_IMPORT_AUTH_CODE] = nullptr; authenticationMap_[AUTH_TYPE_CRE] = nullptr; - dmVersion_ = DM_VERSION_5_0_3; + dmVersion_ = DM_VERSION_5_0_4; } DmAuthManager::~DmAuthManager() @@ -230,7 +232,7 @@ void DmAuthManager::GetAuthParam(const std::string &pkgName, int32_t authType, authRequestContext_->localDeviceId = localUdid; authRequestContext_->deviceId = deviceId; authRequestContext_->addr = deviceId; - authRequestContext_->dmVersion = DM_VERSION_5_0_3; + authRequestContext_->dmVersion = DM_VERSION_5_0_4; uint32_t tokenId = 0 ; MultipleUserConnector::GetTokenIdAndForegroundUserId(tokenId, authRequestContext_->localUserId); authRequestContext_->tokenId = static_cast(tokenId); @@ -861,7 +863,8 @@ void DmAuthManager::StartNegotiate(const int32_t &sessionId) authResponseContext_->localAccountId = authRequestContext_->localAccountId; authResponseContext_->localUserId = authRequestContext_->localUserId; authResponseContext_->isIdenticalAccount = false; - authResponseContext_->edition = DM_VERSION_5_0_3; + authResponseContext_->edition = DM_VERSION_5_0_4; + authResponseContext_->remoteDeviceName = authRequestContext_->localDeviceName; authMessageProcessor_->SetResponseContext(authResponseContext_); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_NEGOTIATE); softbusConnector_->GetSoftbusSession()->SendData(sessionId, message); @@ -885,7 +888,8 @@ void DmAuthManager::AbilityNegotiate() CompatiblePutAcl(); } authResponseContext_->reply = ERR_DM_AUTH_PEER_REJECT; - if (authResponseContext_->authType == AUTH_TYPE_IMPORT_AUTH_CODE && !importAuthCode_.empty()) { + if (!CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_3)) && + authResponseContext_->authType == AUTH_TYPE_IMPORT_AUTH_CODE && !importAuthCode_.empty()) { authResponseContext_->importAuthCode = Crypto::Sha256(importAuthCode_); } } else { @@ -974,6 +978,7 @@ void DmAuthManager::SendAuthRequest(const int32_t &sessionId) return; } remoteDeviceId_ = authResponseContext_->localDeviceId; + authRequestContext_->remoteDeviceName = authResponseContext_->targetDeviceName; std::vector profiles = DeviceProfileConnector::GetInstance().GetAccessControlProfile(); std::vector profilesFilter = {}; @@ -1061,7 +1066,8 @@ void DmAuthManager::GetAuthRequestContext() void DmAuthManager::ProcessAuthRequestExt(const int32_t &sessionId) { LOGI("ProcessAuthRequestExt start."); - if (authResponseContext_->authType == AUTH_TYPE_IMPORT_AUTH_CODE && + if (!CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_3)) && + authResponseContext_->authType == AUTH_TYPE_IMPORT_AUTH_CODE && !authResponseContext_->importAuthCode.empty() && !importAuthCode_.empty()) { if (authResponseContext_->importAuthCode != Crypto::Sha256(importAuthCode_)) { SetReasonAndFinish(ERR_DM_AUTH_CODE_INCORRECT, AuthState::AUTH_REQUEST_FINISH); @@ -1074,7 +1080,8 @@ void DmAuthManager::ProcessAuthRequestExt(const int32_t &sessionId) DeviceProfileConnector::GetInstance().SyncAclByBindType(authResponseContext_->hostPkgName, authResponseContext_->bindType, authResponseContext_->localDeviceId, authResponseContext_->deviceId); authResponseContext_->authed = !bindType.empty(); - if (authResponseContext_->isOnline && authResponseContext_->authed && + if (!CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_3)) && + authResponseContext_->isOnline && authResponseContext_->authed && authResponseContext_->authType == AUTH_TYPE_IMPORT_AUTH_CODE && (authResponseContext_->importAuthCode.empty() || importAuthCode_.empty())) { SetReasonAndFinish(ERR_DM_AUTH_CODE_INCORRECT, AuthState::AUTH_REQUEST_FINISH); @@ -2344,7 +2351,7 @@ void DmAuthManager::ProcRespNegotiateExt(const int32_t &sessionId) authResponseContext_->localDeviceId, authResponseContext_->deviceId); authResponseContext_->authed = !authResponseContext_->bindType.empty(); if (authResponseContext_->authed && authResponseContext_->authType == AUTH_TYPE_IMPORT_AUTH_CODE && - !importAuthCode_.empty()) { + !importAuthCode_.empty() && !CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_3))) { authResponseContext_->importAuthCode = Crypto::Sha256(importAuthCode_); } @@ -2518,19 +2525,23 @@ void DmAuthManager::PutAccessControlList() accesser.requestUserId = authRequestContext_->localUserId; accesser.requestAccountId = authRequestContext_->localAccountId; accesser.requestDeviceId = authRequestContext_->localDeviceId; + accesser.requestDeviceName = authRequestContext_->localDeviceName; accessee.trustTokenId = static_cast(authResponseContext_->remoteTokenId); accessee.trustUserId = authRequestContext_->remoteUserId; accessee.trustAccountId = authRequestContext_->remoteAccountId; accessee.trustDeviceId = remoteDeviceId_; + accessee.trustDeviceName = authRequestContext_->remoteDeviceName; } else if (authRequestState_ == nullptr && authResponseState_ != nullptr) { accesser.requestTokenId = static_cast(authResponseContext_->remoteTokenId); accesser.requestUserId = authResponseContext_->remoteUserId; accesser.requestAccountId = authResponseContext_->remoteAccountId; accesser.requestDeviceId = remoteDeviceId_; + accesser.requestDeviceName = authResponseContext_->remoteDeviceName; accessee.trustTokenId = static_cast(authResponseContext_->tokenId); accessee.trustUserId = authResponseContext_->localUserId; accessee.trustAccountId = authResponseContext_->localAccountId; accessee.trustDeviceId = localUdid; + accessee.trustDeviceName = authResponseContext_->targetDeviceName; } DeviceProfileConnector::GetInstance().PutAccessControlList(aclInfo, accesser, accessee); } @@ -2839,14 +2850,14 @@ void DmAuthManager::ConverToFinish() void DmAuthManager::RequestReCheckMsg() { - LOGI("dmVersion %{public}s.", DM_VERSION_5_0_3); + LOGI("dmVersion %{public}s.", DM_VERSION_5_0_4); char localDeviceId[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); uint32_t tokenId = 0; int32_t localUserId = 0; MultipleUserConnector::GetTokenIdAndForegroundUserId(tokenId, localUserId); std::string localAccountId = MultipleUserConnector::GetOhosAccountIdByUserId(localUserId); - authResponseContext_->edition = DM_VERSION_5_0_3; + authResponseContext_->edition = DM_VERSION_5_0_4; authResponseContext_->localDeviceId = static_cast(localDeviceId); authResponseContext_->localUserId = localUserId; authResponseContext_->localAccountId = localAccountId; @@ -2873,7 +2884,7 @@ void DmAuthManager::ResponseReCheckMsg() } char localDeviceId[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); - authResponseContext_->edition = DM_VERSION_5_0_3; + authResponseContext_->edition = DM_VERSION_5_0_4; authResponseContext_->localDeviceId = std::string(localDeviceId); authResponseContext_->localUserId = MultipleUserConnector::GetFirstForegroundUserId(); authResponseContext_->localAccountId = diff --git a/services/implementation/src/cryptomgr/crypto_mgr.cpp b/services/implementation/src/cryptomgr/crypto_mgr.cpp index 8e4e82b95..441e9e606 100644 --- a/services/implementation/src/cryptomgr/crypto_mgr.cpp +++ b/services/implementation/src/cryptomgr/crypto_mgr.cpp @@ -148,7 +148,7 @@ int32_t CryptoMgr::MbedAesGcmEncrypt(const AesGcmCipherKey *cipherKey, const uns } if (memcpy_s(cipherText + GCM_IV_LEN + plainTextSize, cipherTextLen - GCM_IV_LEN - plainTextSize, tagBuf, - TAG_LEN) != 0) { + TAG_LEN) != 0) { mbedtls_gcm_free(&aesContext); return ERR_DM_CRYPTO_OPT_FAILED; } diff --git a/services/implementation/src/dependency/softbus/softbus_connector.cpp b/services/implementation/src/dependency/softbus/softbus_connector.cpp index cf4eeb5d3..d6debe90f 100644 --- a/services/implementation/src/dependency/softbus/softbus_connector.cpp +++ b/services/implementation/src/dependency/softbus/softbus_connector.cpp @@ -197,13 +197,13 @@ void SoftbusConnector::ConvertDeviceInfoToDmDevice(const DeviceInfo &deviceInfo, } if (memcpy_s(dmDeviceInfo.deviceId, sizeof(dmDeviceInfo.deviceId), deviceInfo.devId, - std::min(sizeof(dmDeviceInfo.deviceId), sizeof(deviceInfo.devId))) != EOK) { + std::min(sizeof(dmDeviceInfo.deviceId), sizeof(deviceInfo.devId))) != EOK) { LOGE("ConvertDeviceInfoToDmDevice copy deviceId data failed."); return; } if (memcpy_s(dmDeviceInfo.deviceName, sizeof(dmDeviceInfo.deviceName), deviceInfo.devName, - std::min(sizeof(dmDeviceInfo.deviceName), sizeof(deviceInfo.devName))) != EOK) { + std::min(sizeof(dmDeviceInfo.deviceName), sizeof(deviceInfo.devName))) != EOK) { LOGE("ConvertDeviceInfoToDmDevice copy deviceName data failed."); return; } @@ -220,13 +220,13 @@ void SoftbusConnector::ConvertDeviceInfoToDmDevice(const DeviceInfo &deviceInfo, } if (memcpy_s(dmDeviceBasicInfo.deviceId, sizeof(dmDeviceBasicInfo.deviceId), deviceInfo.devId, - std::min(sizeof(dmDeviceBasicInfo.deviceId), sizeof(deviceInfo.devId))) != EOK) { + std::min(sizeof(dmDeviceBasicInfo.deviceId), sizeof(deviceInfo.devId))) != EOK) { LOGE("ConvertDeviceInfoToDmDevice copy deviceId data failed."); return; } if (memcpy_s(dmDeviceBasicInfo.deviceName, sizeof(dmDeviceBasicInfo.deviceName), deviceInfo.devName, - std::min(sizeof(dmDeviceBasicInfo.deviceName), sizeof(deviceInfo.devName))) != EOK) { + std::min(sizeof(dmDeviceBasicInfo.deviceName), sizeof(deviceInfo.devName))) != EOK) { LOGE("ConvertDeviceInfoToDmDevice copy deviceName data failed."); return; } @@ -485,13 +485,13 @@ void SoftbusConnector::ConvertNodeBasicInfoToDmDevice(const NodeBasicInfo &nodeB } if (memcpy_s(dmDeviceInfo.networkId, sizeof(dmDeviceInfo.networkId), nodeBasicInfo.networkId, - std::min(sizeof(dmDeviceInfo.networkId), sizeof(nodeBasicInfo.networkId))) != EOK) { + std::min(sizeof(dmDeviceInfo.networkId), sizeof(nodeBasicInfo.networkId))) != EOK) { LOGE("ConvertNodeBasicInfoToDmDevice copy deviceId data failed."); return; } if (memcpy_s(dmDeviceInfo.deviceName, sizeof(dmDeviceInfo.deviceName), nodeBasicInfo.deviceName, - std::min(sizeof(dmDeviceInfo.deviceName), sizeof(nodeBasicInfo.deviceName))) != EOK) { + std::min(sizeof(dmDeviceInfo.deviceName), sizeof(nodeBasicInfo.deviceName))) != EOK) { LOGE("ConvertDeviceInfoToDmDevice copy deviceName data failed."); return; } diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 37e4207c6..0a0898740 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -746,7 +746,15 @@ int32_t DeviceManagerServiceImpl::CheckIsSameAccount(const DmAccessCaller &calle int32_t DeviceManagerServiceImpl::CheckAccessControl(const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee, const std::string &sinkUdid) { - return DeviceProfileConnector::GetInstance().CheckAccessControl(caller, srcUdid, callee, sinkUdid); + CHECK_NULL_RETURN(hiChainConnector_, ERR_DM_POINT_NULL); + bool ret = hiChainConnector_->IsDevicesInP2PGroup(srcUdid, sinkUdid); + if (!ret) { + int32_t checkRet = DeviceProfileConnector::GetInstance().CheckAccessControl(caller, + srcUdid, callee, sinkUdid); + return checkRet; + } else { + return DM_OK; + } } void DeviceManagerServiceImpl::HandleDeviceNotTrust(const std::string &udid) diff --git a/services/implementation/src/devicestate/dm_device_state_manager.cpp b/services/implementation/src/devicestate/dm_device_state_manager.cpp index dad3d24d4..3c2b2a350 100644 --- a/services/implementation/src/devicestate/dm_device_state_manager.cpp +++ b/services/implementation/src/devicestate/dm_device_state_manager.cpp @@ -170,11 +170,13 @@ void DmDeviceStateManager::HandleDeviceStatusChange(DmDeviceState devState, DmDe void DmDeviceStateManager::ProcessDeviceStateChange(const DmDeviceState devState, const DmDeviceInfo &devInfo) { + LOGI("ProcessDeviceStateChange begin, devState = %{public}d", devState); CHECK_NULL_VOID(softbusConnector_); CHECK_NULL_VOID(listener_); std::vector processInfoVec = softbusConnector_->GetProcessInfo(); for (const auto &item : processInfoVec) { if (!item.pkgName.empty()) { + LOGI("ProcessDeviceStateChange, pkgName = %{public}s", item.pkgName.c_str()); listener_->OnDeviceStateChange(item, devState, devInfo); } } @@ -418,12 +420,12 @@ void DmDeviceStateManager::ChangeDeviceInfo(const DmDeviceInfo &info) for (auto iter : remoteDeviceInfos_) { if (std::string(iter.second.deviceId) == std::string(info.deviceId)) { if (memcpy_s(iter.second.deviceName, sizeof(iter.second.deviceName), info.deviceName, - sizeof(info.deviceName)) != DM_OK) { + sizeof(info.deviceName)) != DM_OK) { LOGE("ChangeDeviceInfo remoteDeviceInfos copy deviceName failed"); return; } if (memcpy_s(iter.second.networkId, sizeof(iter.second.networkId), info.networkId, - sizeof(info.networkId)) != DM_OK) { + sizeof(info.networkId)) != DM_OK) { LOGE("ChangeDeviceInfo remoteDeviceInfos copy networkId failed"); return; } @@ -435,12 +437,12 @@ void DmDeviceStateManager::ChangeDeviceInfo(const DmDeviceInfo &info) for (auto iter : stateDeviceInfos_) { if (std::string(iter.second.deviceId) == std::string(info.deviceId)) { if (memcpy_s(iter.second.deviceName, sizeof(iter.second.deviceName), info.deviceName, - sizeof(info.deviceName)) != DM_OK) { + sizeof(info.deviceName)) != DM_OK) { LOGE("ChangeDeviceInfo stateDeviceInfos copy deviceName failed"); return; } if (memcpy_s(iter.second.networkId, sizeof(iter.second.networkId), info.networkId, - sizeof(info.networkId)) != DM_OK) { + sizeof(info.networkId)) != DM_OK) { LOGE("ChangeDeviceInfo stateDeviceInfos copy networkId failed"); return; } diff --git a/services/service/include/softbus/softbus_listener.h b/services/service/include/softbus/softbus_listener.h index b0d13359f..9745804c1 100644 --- a/services/service/include/softbus/softbus_listener.h +++ b/services/service/include/softbus/softbus_listener.h @@ -77,6 +77,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); int32_t InitSoftbusListener(); int32_t GetTrustedDeviceList(std::vector &deviceInfoList); diff --git a/services/service/src/advertise/advertise_manager.cpp b/services/service/src/advertise/advertise_manager.cpp index 263203e85..172f0565b 100644 --- a/services/service/src/advertise/advertise_manager.cpp +++ b/services/service/src/advertise/advertise_manager.cpp @@ -91,6 +91,7 @@ void AdvertiseManager::ConfigAdvParam(const std::map & dmPubInfo->mode = DmDiscoverMode::DM_DISCOVER_MODE_PASSIVE; dmPubInfo->freq = DmExchangeFreq::DM_LOW; dmPubInfo->ranging = true; + dmPubInfo->medium = DmExchangeMedium::DM_AUTO; if (advertiseParam.find(PARAM_KEY_META_TYPE) != advertiseParam.end()) { LOGI("StartAdvertising input MetaType=%{public}s", (advertiseParam.find(PARAM_KEY_META_TYPE)->second).c_str()); @@ -106,6 +107,12 @@ void AdvertiseManager::ConfigAdvParam(const std::map & dmPubInfo->freq = static_cast(std::atoi((advertiseParam.find(PARAM_KEY_DISC_FREQ)->second).c_str())); } + if (advertiseParam.find(PARAM_KEY_DISC_MEDIUM) != advertiseParam.end()) { + if (IsNumberString(advertiseParam.find(PARAM_KEY_DISC_MEDIUM)->second)) { + dmPubInfo->medium = + static_cast(std::atoi((advertiseParam.find(PARAM_KEY_DISC_MEDIUM)->second).c_str())); + } + } } int32_t AdvertiseManager::StopAdvertising(const std::string &pkgName, int32_t publishId) diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 7c0745e07..9b78f1d5f 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -780,6 +780,7 @@ int32_t DeviceManagerService::SetUserOperation(std::string &pkgName, int32_t act void DeviceManagerService::HandleDeviceStatusChange(DmDeviceState devState, DmDeviceInfo &devInfo) { + LOGI("DeviceManagerService::HandleDeviceStatusChange start, devState = %{public}d", devState); if (IsDMServiceImplReady()) { dmServiceImpl_->HandleDeviceStatusChange(devState, devInfo); } diff --git a/services/service/src/device_manager_service_listener.cpp b/services/service/src/device_manager_service_listener.cpp index 97a788511..6b48b0d93 100644 --- a/services/service/src/device_manager_service_listener.cpp +++ b/services/service/src/device_manager_service_listener.cpp @@ -65,19 +65,19 @@ void DeviceManagerServiceListener::ConvertDeviceInfoToDeviceBasicInfo(const std: } if (memcpy_s(deviceBasicInfo.deviceName, sizeof(deviceBasicInfo.deviceName), info.deviceName, - std::min(sizeof(deviceBasicInfo.deviceName), sizeof(info.deviceName))) != DM_OK) { + std::min(sizeof(deviceBasicInfo.deviceName), sizeof(info.deviceName))) != DM_OK) { LOGE("ConvertDeviceInfoToDmDevice copy deviceName data failed."); return; } if (memcpy_s(deviceBasicInfo.networkId, sizeof(deviceBasicInfo.networkId), info.networkId, - std::min(sizeof(deviceBasicInfo.networkId), sizeof(info.networkId))) != DM_OK) { + std::min(sizeof(deviceBasicInfo.networkId), sizeof(info.networkId))) != DM_OK) { LOGE("ConvertNodeBasicInfoToDmDevice copy networkId data failed."); return; } if (memcpy_s(deviceBasicInfo.deviceId, sizeof(deviceBasicInfo.deviceId), info.deviceId, - std::min(sizeof(deviceBasicInfo.deviceId), sizeof(info.deviceId))) != DM_OK) { + std::min(sizeof(deviceBasicInfo.deviceId), sizeof(info.deviceId))) != DM_OK) { LOGE("ConvertNodeBasicInfoToDmDevice copy deviceId data failed."); return; } @@ -108,7 +108,7 @@ void DeviceManagerServiceListener::SetDeviceInfo(std::shared_ptr processInfoVec = GetNotifyProcessInfoByUserId(processInfo.userId, DmCommonNotifyEvent::REG_DEVICE_STATE); std::vector hpProcessInfoVec; @@ -468,7 +468,7 @@ int32_t DeviceManagerServiceListener::ConvertUdidHashToAnoyAndSave(const std::st return ERR_DM_FAILED; } if (memcpy_s(deviceInfo.deviceId, sizeof(deviceInfo.deviceId), kvValue.anoyDeviceId.c_str(), - std::min(sizeof(deviceInfo.deviceId), kvValue.anoyDeviceId.length())) != DM_OK) { + std::min(sizeof(deviceInfo.deviceId), kvValue.anoyDeviceId.length())) != DM_OK) { LOGE("copy deviceId data failed."); return ERR_DM_FAILED; } @@ -803,6 +803,7 @@ void DeviceManagerServiceListener::ProcessAppOnline(const std::vector pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } - + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); int32_t deviceState = pReq->GetDeviceState(); @@ -158,20 +155,14 @@ ON_IPC_SET_REQUEST(SERVER_DEVICE_STATE_NOTIFY, std::shared_ptr pBaseReq, ON_IPC_READ_RESPONSE(SERVER_DEVICE_STATE_NOTIFY, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } ON_IPC_SET_REQUEST(SERVER_DEVICE_FOUND, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } - + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); uint16_t subscribeId = pReq->GetSubscribeId(); @@ -198,20 +189,14 @@ ON_IPC_SET_REQUEST(SERVER_DEVICE_FOUND, std::shared_ptr pBaseReq, Messag ON_IPC_READ_RESPONSE(SERVER_DEVICE_FOUND, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } ON_IPC_SET_REQUEST(SERVER_DEVICE_DISCOVERY, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } - + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); uint16_t subscribeId = pReq->GetSubscribeId(); @@ -233,19 +218,14 @@ ON_IPC_SET_REQUEST(SERVER_DEVICE_DISCOVERY, std::shared_ptr pBaseReq, Me ON_IPC_READ_RESPONSE(SERVER_DEVICE_DISCOVERY, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } ON_IPC_SET_REQUEST(SERVER_DISCOVER_FINISH, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); uint16_t subscribeId = pReq->GetSubscribeId(); @@ -267,19 +247,14 @@ ON_IPC_SET_REQUEST(SERVER_DISCOVER_FINISH, std::shared_ptr pBaseReq, Mes ON_IPC_READ_RESPONSE(SERVER_DISCOVER_FINISH, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } ON_IPC_SET_REQUEST(SERVER_PUBLISH_FINISH, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); int32_t publishId = pReq->GetPublishId(); @@ -301,19 +276,14 @@ ON_IPC_SET_REQUEST(SERVER_PUBLISH_FINISH, std::shared_ptr pBaseReq, Mess ON_IPC_READ_RESPONSE(SERVER_PUBLISH_FINISH, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } ON_IPC_SET_REQUEST(SERVER_AUTH_RESULT, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); @@ -346,20 +316,14 @@ ON_IPC_SET_REQUEST(SERVER_AUTH_RESULT, std::shared_ptr pBaseReq, Message ON_IPC_READ_RESPONSE(SERVER_AUTH_RESULT, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } ON_IPC_SET_REQUEST(SERVER_DEVICE_FA_NOTIFY, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } - + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string packagname = pReq->GetPkgName(); @@ -377,10 +341,7 @@ ON_IPC_SET_REQUEST(SERVER_DEVICE_FA_NOTIFY, std::shared_ptr pBaseReq, Me ON_IPC_READ_RESPONSE(SERVER_DEVICE_FA_NOTIFY, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } @@ -769,9 +730,7 @@ ON_IPC_CMD(NOTIFY_EVENT, MessageParcel &data, MessageParcel &reply) ON_IPC_SET_REQUEST(SERVER_CREDENTIAL_RESULT, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); int32_t action = pReq->GetCredentialAction(); @@ -794,10 +753,7 @@ ON_IPC_SET_REQUEST(SERVER_CREDENTIAL_RESULT, std::shared_ptr pBaseReq, M ON_IPC_READ_RESPONSE(SERVER_CREDENTIAL_RESULT, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } @@ -1062,9 +1018,7 @@ ON_IPC_CMD(UNBIND_TARGET, MessageParcel &data, MessageParcel &reply) ON_IPC_SET_REQUEST(BIND_TARGET_RESULT, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); PeerTargetId targetId = pReq->GetPeerTargetId(); @@ -1097,19 +1051,14 @@ ON_IPC_SET_REQUEST(BIND_TARGET_RESULT, std::shared_ptr pBaseReq, Message ON_IPC_READ_RESPONSE(BIND_TARGET_RESULT, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } ON_IPC_SET_REQUEST(SINK_BIND_TARGET_RESULT, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); PeerTargetId targetId = pReq->GetPeerTargetId(); @@ -1142,19 +1091,14 @@ ON_IPC_SET_REQUEST(SINK_BIND_TARGET_RESULT, std::shared_ptr pBaseReq, Me ON_IPC_READ_RESPONSE(SINK_BIND_TARGET_RESULT, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } ON_IPC_SET_REQUEST(UNBIND_TARGET_RESULT, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); PeerTargetId targetId = pReq->GetPeerTargetId(); @@ -1182,10 +1126,7 @@ ON_IPC_SET_REQUEST(UNBIND_TARGET_RESULT, std::shared_ptr pBaseReq, Messa ON_IPC_READ_RESPONSE(UNBIND_TARGET_RESULT, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } @@ -1233,9 +1174,7 @@ ON_IPC_CMD(DESTROY_PIN_HOLDER, MessageParcel &data, MessageParcel &reply) ON_IPC_SET_REQUEST(SERVER_CREATE_PIN_HOLDER, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); std::string deviceId = pReq->GetDeviceId(); @@ -1263,19 +1202,14 @@ ON_IPC_SET_REQUEST(SERVER_CREATE_PIN_HOLDER, std::shared_ptr pBaseReq, M ON_IPC_READ_RESPONSE(SERVER_CREATE_PIN_HOLDER, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } ON_IPC_SET_REQUEST(SERVER_DESTROY_PIN_HOLDER, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); int32_t pinType = pReq->GetPinType(); @@ -1298,19 +1232,14 @@ ON_IPC_SET_REQUEST(SERVER_DESTROY_PIN_HOLDER, std::shared_ptr pBaseReq, ON_IPC_READ_RESPONSE(SERVER_DESTROY_PIN_HOLDER, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } ON_IPC_SET_REQUEST(SERVER_CREATE_PIN_HOLDER_RESULT, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); int32_t result = pReq->GetResult(); @@ -1328,19 +1257,14 @@ ON_IPC_SET_REQUEST(SERVER_CREATE_PIN_HOLDER_RESULT, std::shared_ptr pBas ON_IPC_READ_RESPONSE(SERVER_CREATE_PIN_HOLDER_RESULT, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } ON_IPC_SET_REQUEST(SERVER_DESTROY_PIN_HOLDER_RESULT, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); int32_t result = pReq->GetResult(); @@ -1358,10 +1282,7 @@ ON_IPC_SET_REQUEST(SERVER_DESTROY_PIN_HOLDER_RESULT, std::shared_ptr pBa ON_IPC_READ_RESPONSE(SERVER_DESTROY_PIN_HOLDER_RESULT, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } @@ -1394,9 +1315,7 @@ ON_IPC_CMD(GET_SECURITY_LEVEL, MessageParcel &data, MessageParcel &reply) ON_IPC_SET_REQUEST(SERVER_ON_PIN_HOLDER_EVENT, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); int32_t pinHolderEvent = pReq->GetPinHolderEvent(); @@ -1424,10 +1343,7 @@ ON_IPC_SET_REQUEST(SERVER_ON_PIN_HOLDER_EVENT, std::shared_ptr pBaseReq, ON_IPC_READ_RESPONSE(SERVER_ON_PIN_HOLDER_EVENT, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } @@ -1521,9 +1437,7 @@ ON_IPC_CMD(STOP_AUTHENTICATE_DEVICE, MessageParcel &data, MessageParcel &reply) ON_IPC_SET_REQUEST(REMOTE_DEVICE_TRUST_CHANGE, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); std::string udid = pReq->GetUdid(); @@ -1550,19 +1464,14 @@ ON_IPC_SET_REQUEST(REMOTE_DEVICE_TRUST_CHANGE, std::shared_ptr pBaseReq, ON_IPC_READ_RESPONSE(REMOTE_DEVICE_TRUST_CHANGE, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } ON_IPC_SET_REQUEST(SERVER_DEVICE_SCREEN_STATE_NOTIFY, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); DmDeviceInfo deviceInfo = pReq->GetDeviceInfo(); @@ -1580,10 +1489,7 @@ ON_IPC_SET_REQUEST(SERVER_DEVICE_SCREEN_STATE_NOTIFY, std::shared_ptr pB ON_IPC_READ_RESPONSE(SERVER_DEVICE_SCREEN_STATE_NOTIFY, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } @@ -1637,9 +1543,7 @@ ON_IPC_CMD(GET_ANONY_LOCAL_UDID, MessageParcel &data, MessageParcel &reply) ON_IPC_SET_REQUEST(SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); @@ -1668,10 +1572,7 @@ ON_IPC_SET_REQUEST(SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } @@ -1727,9 +1628,7 @@ ON_IPC_CMD(GET_DEVICE_PROFILE_INFO_LIST, MessageParcel &data, MessageParcel &rep ON_IPC_SET_REQUEST(GET_DEVICE_PROFILE_INFO_LIST_RESULT, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); @@ -1758,10 +1657,7 @@ ON_IPC_SET_REQUEST(GET_DEVICE_PROFILE_INFO_LIST_RESULT, std::shared_ptr ON_IPC_READ_RESPONSE(GET_DEVICE_PROFILE_INFO_LIST_RESULT, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } @@ -1801,9 +1697,7 @@ ON_IPC_CMD(GET_DEVICE_ICON_INFO, MessageParcel &data, MessageParcel &reply) ON_IPC_SET_REQUEST(GET_DEVICE_ICON_INFO_RESULT, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); @@ -1825,10 +1719,7 @@ ON_IPC_SET_REQUEST(GET_DEVICE_ICON_INFO_RESULT, std::shared_ptr pBaseReq ON_IPC_READ_RESPONSE(GET_DEVICE_ICON_INFO_RESULT, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } diff --git a/services/service/src/softbus/softbus_listener.cpp b/services/service/src/softbus/softbus_listener.cpp index 3f7cf1343..6876a5b3c 100644 --- a/services/service/src/softbus/softbus_listener.cpp +++ b/services/service/src/softbus/softbus_listener.cpp @@ -250,6 +250,7 @@ void SoftbusListener::OnSoftbusDeviceOnline(NodeBasicInfo *info) SoftbusCache::GetInstance().SaveDeviceInfo(dmDeviceInfo); SoftbusCache::GetInstance().SaveDeviceSecurityLevel(dmDeviceInfo.networkId); SoftbusCache::GetInstance().SaveLocalDeviceInfo(); + UpdateDeviceName(info); { std::lock_guard lock(g_onlineDeviceNumLock); g_onlineDeviceNum++; @@ -330,6 +331,23 @@ void SoftbusListener::OnSoftbusDeviceOffline(NodeBasicInfo *info) } } +void SoftbusListener::UpdateDeviceName(NodeBasicInfo *info) +{ +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + if (info == nullptr) { + LOGE("NodeBasicInfo is nullptr, not update device name"); + return; + } + std::string udid = ""; + if (GetUdidByNetworkId(info->networkId, udid) != DM_OK) { + LOGE("GetUdidByNetworkId failed, not update device name"); + return; + } + LOGI("UpdateDeviceName, info->deviceName: %{public}s.", GetAnonyString(info->deviceName).c_str()); + DeviceProfileConnector::GetInstance().UpdateAclDeviceName(udid, info->deviceName); +#endif +} + void SoftbusListener::OnSoftbusDeviceInfoChanged(NodeBasicInfoType type, NodeBasicInfo *info) { LOGI("received device info change from softbus."); @@ -349,6 +367,9 @@ void SoftbusListener::OnSoftbusDeviceInfoChanged(NodeBasicInfoType type, NodeBas } LOGI("OnSoftbusDeviceInfoChanged NetworkType %{public}d.", networkType); } + if (type == NodeBasicInfoType::TYPE_DEVICE_NAME) { + UpdateDeviceName(info); + } ConvertNodeBasicInfoToDmDevice(*info, dmDeviceInfo); LOGI("device changed networkId: %{public}s.", GetAnonyString(dmDeviceInfo.networkId).c_str()); dmDeviceInfo.networkType = networkType; @@ -369,6 +390,21 @@ void SoftbusListener::OnLocalDevInfoChange() { LOGI("SoftbusListener::OnLocalDevInfoChange"); SoftbusCache::GetInstance().UpDataLocalDevInfo(); +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + NodeBasicInfo nodeBasicInfo; + int32_t ret = GetLocalNodeDeviceInfo(DM_PKG_NAME, &nodeBasicInfo); + if (ret != DM_OK) { + LOGE("[SOFTBUS]GetLocalNodeDeviceInfo failed, not update deviceName ret: %{public}d.", ret); + return; + } + std::string udid = ""; + ret = GetUdidByNetworkId(nodeBasicInfo.networkId, udid); + if (ret != DM_OK) { + LOGE("GetUdidByNetworkId failed, not update deviceName ret: %{public}d.", ret); + return; + } + DeviceProfileConnector::GetInstance().UpdateAclDeviceName(udid, nodeBasicInfo.deviceName); +#endif } void SoftbusListener::OnDeviceTrustedChange(TrustChangeType type, const char *msg, uint32_t msgLen) @@ -631,7 +667,11 @@ int32_t SoftbusListener::PublishSoftbusLNN(const DmPublishInfo &dmPubInfo, const PublishInfo publishInfo; publishInfo.publishId = dmPubInfo.publishId; publishInfo.mode = static_cast(dmPubInfo.mode); - publishInfo.medium = (capability == DM_CAPABILITY_APPROACH) ? ExchangeMedium::BLE : ExchangeMedium::AUTO; + if (capability == DM_CAPABILITY_APPROACH) { + publishInfo.medium = ExchangeMedium::BLE; + } else { + publishInfo.medium = static_cast(dmPubInfo.medium); + } publishInfo.freq = static_cast(dmPubInfo.freq); publishInfo.capability = capability.c_str(); publishInfo.capabilityData = const_cast(reinterpret_cast(customData.c_str())); @@ -747,13 +787,13 @@ int32_t SoftbusListener::ConvertScreenStatusToDmDevice(const NodeBasicInfo &node return ERR_DM_FAILED; } if (memcpy_s(devInfo.networkId, sizeof(devInfo.networkId), nodeInfo.networkId, - std::min(sizeof(devInfo.networkId), sizeof(nodeInfo.networkId))) != DM_OK) { + std::min(sizeof(devInfo.networkId), sizeof(nodeInfo.networkId))) != DM_OK) { LOGE("ConvertNodeBasicInfoToDmDevice copy networkId data failed."); return ERR_DM_FAILED; } if (memcpy_s(devInfo.deviceName, sizeof(devInfo.deviceName), nodeInfo.deviceName, - std::min(sizeof(devInfo.deviceName), sizeof(nodeInfo.deviceName))) != DM_OK) { + std::min(sizeof(devInfo.deviceName), sizeof(nodeInfo.deviceName))) != DM_OK) { LOGE("ConvertNodeBasicInfoToDmDevice copy deviceName data failed."); return ERR_DM_FAILED; } @@ -774,13 +814,13 @@ int32_t SoftbusListener::ConvertNodeBasicInfoToDmDevice(const NodeBasicInfo &nod return ERR_DM_FAILED; } if (memcpy_s(devInfo.networkId, sizeof(devInfo.networkId), nodeInfo.networkId, - std::min(sizeof(devInfo.networkId), sizeof(nodeInfo.networkId))) != EOK) { + std::min(sizeof(devInfo.networkId), sizeof(nodeInfo.networkId))) != EOK) { LOGE("ConvertNodeBasicInfoToDmDevice copy networkId data failed."); return ERR_DM_FAILED; } if (memcpy_s(devInfo.deviceName, sizeof(devInfo.deviceName), nodeInfo.deviceName, - std::min(sizeof(devInfo.deviceName), sizeof(nodeInfo.deviceName))) != EOK) { + std::min(sizeof(devInfo.deviceName), sizeof(nodeInfo.deviceName))) != EOK) { LOGE("ConvertNodeBasicInfoToDmDevice copy deviceName data failed."); return ERR_DM_FAILED; } @@ -800,13 +840,13 @@ int32_t SoftbusListener::ConvertNodeBasicInfoToDmDevice(const NodeBasicInfo &nod } if (memcpy_s(devInfo.networkId, sizeof(devInfo.networkId), nodeInfo.networkId, - std::min(sizeof(devInfo.networkId), sizeof(nodeInfo.networkId))) != EOK) { + std::min(sizeof(devInfo.networkId), sizeof(nodeInfo.networkId))) != EOK) { LOGE("ConvertNodeBasicInfoToDmDevice copy networkId data failed."); return ERR_DM_FAILED; } if (memcpy_s(devInfo.deviceName, sizeof(devInfo.deviceName), nodeInfo.deviceName, - std::min(sizeof(devInfo.deviceName), sizeof(nodeInfo.deviceName))) != EOK) { + std::min(sizeof(devInfo.deviceName), sizeof(nodeInfo.deviceName))) != EOK) { LOGE("ConvertNodeBasicInfoToDmDevice copy deviceName data failed."); return ERR_DM_FAILED; } @@ -836,13 +876,13 @@ int32_t SoftbusListener::FillDeviceInfo(const DeviceInfo &device, DmDeviceInfo & } if (memcpy_s(dmDevice.deviceId, sizeof(dmDevice.deviceId), device.devId, - std::min(sizeof(dmDevice.deviceId), sizeof(device.devId))) != DM_OK) { + std::min(sizeof(dmDevice.deviceId), sizeof(device.devId))) != DM_OK) { LOGE("ConvertDeviceInfoToDmDevice: copy device id failed."); return ERR_DM_FAILED; } if (memcpy_s(dmDevice.deviceName, sizeof(dmDevice.deviceName), device.devName, - std::min(sizeof(dmDevice.deviceName), sizeof(device.devName))) != DM_OK) { + std::min(sizeof(dmDevice.deviceName), sizeof(device.devName))) != DM_OK) { LOGE("ConvertDeviceInfoToDmDevice: copy device name failed."); return ERR_DM_FAILED; } @@ -1225,10 +1265,14 @@ void SoftbusListener::ConvertAclToDeviceInfo(DistributedDeviceProfile::AccessCon return; } } else { - if (memcpy_s(deviceInfo.deviceName, sizeof(deviceInfo.deviceName), udidHash, - std::min(sizeof(deviceInfo.deviceName), sizeof(udidHash))) != DM_OK) { - LOGE("GetAllTrustedDeviceList copy deviceName data failed."); - return; + if (profile.GetTrustDeviceId() == profile.GetAccessee().GetAccesseeDeviceId()) { + deviceName = profile.GetAccessee().GetAccesseeDeviceName(); + } else if (profile.GetTrustDeviceId() == profile.GetAccesser().GetAccesserDeviceId()) { + deviceName = profile.GetAccesser().GetAccesserDeviceName(); + } + if (memcpy_s(deviceInfo.deviceName, sizeof(deviceInfo.deviceName), deviceName.c_str(), + std::min(sizeof(deviceInfo.deviceName), deviceName.size())) != DM_OK) { + LOGE("GetAllTrustedDeviceList copy deviceName data from dp failed."); } } } diff --git a/services/softbuscache/src/dm_softbus_cache.cpp b/services/softbuscache/src/dm_softbus_cache.cpp index 574145824..35dd50a82 100644 --- a/services/softbuscache/src/dm_softbus_cache.cpp +++ b/services/softbuscache/src/dm_softbus_cache.cpp @@ -140,7 +140,7 @@ void SoftbusCache::SaveDeviceInfo(DmDeviceInfo deviceInfo) return; } if (memcpy_s(deviceInfo.deviceId, sizeof(deviceInfo.deviceId), udidHash, - std::min(sizeof(deviceInfo.deviceId), sizeof(udidHash))) != DM_OK) { + std::min(sizeof(deviceInfo.deviceId), sizeof(udidHash))) != DM_OK) { LOGE("SaveDeviceInfo copy deviceId failed."); return; } @@ -178,12 +178,12 @@ void SoftbusCache::ChangeDeviceInfo(const DmDeviceInfo deviceInfo) std::lock_guard mutexLock(deviceInfosMutex_); 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) { + deviceInfo.deviceName, sizeof(deviceInfo.deviceName)) != DM_OK) { LOGE("ChangeDeviceInfo deviceInfo copy deviceName failed"); return; } if (memcpy_s(deviceInfo_[udid].second.networkId, sizeof(deviceInfo_[udid].second.networkId), - deviceInfo.networkId, sizeof(deviceInfo.networkId)) != DM_OK) { + deviceInfo.networkId, sizeof(deviceInfo.networkId)) != DM_OK) { LOGE("ChangeDeviceInfo deviceInfo copy networkId failed"); return; } @@ -278,13 +278,13 @@ int32_t SoftbusCache::ConvertNodeBasicInfoToDmDevice(const NodeBasicInfo &nodeIn } if (memcpy_s(devInfo.networkId, sizeof(devInfo.networkId), nodeInfo.networkId, - std::min(sizeof(devInfo.networkId), sizeof(nodeInfo.networkId))) != DM_OK) { + std::min(sizeof(devInfo.networkId), sizeof(nodeInfo.networkId))) != DM_OK) { LOGE("ConvertNodeBasicInfoToDmDevice copy networkId data failed."); return ERR_DM_FAILED; } if (memcpy_s(devInfo.deviceName, sizeof(devInfo.deviceName), nodeInfo.deviceName, - std::min(sizeof(devInfo.deviceName), sizeof(nodeInfo.deviceName))) != DM_OK) { + std::min(sizeof(devInfo.deviceName), sizeof(nodeInfo.deviceName))) != DM_OK) { LOGE("ConvertNodeBasicInfoToDmDevice copy deviceName data failed."); return ERR_DM_FAILED; } diff --git a/test/commonfuzztest/hichainconnector_fuzzer/hichain_connector_fuzzer.cpp b/test/commonfuzztest/hichainconnector_fuzzer/hichain_connector_fuzzer.cpp index fe38c9695..7a042ca54 100644 --- a/test/commonfuzztest/hichainconnector_fuzzer/hichain_connector_fuzzer.cpp +++ b/test/commonfuzztest/hichainconnector_fuzzer/hichain_connector_fuzzer.cpp @@ -345,6 +345,43 @@ void HiChainConnectorSixthFuzzTest(const uint8_t* data, size_t size) jsonDeviceList[FIELD_DEVICE_LIST] = "deviceList"; hichainConnector->ParseRemoteCredential(groupType, userId, jsonDeviceList, params, osAccountUserId); } + +void HiChainConnectorSevenhFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t) + sizeof(int32_t))) { + return; + } + + std::shared_ptr hichainConnector = std::make_shared(); + hichainConnector->RegisterHiChainCallback(std::make_shared()); + std::vector> delACLInfoVec; + delACLInfoVec.push_back(std::make_pair(1, "aclinfo_001")); + std::vector userIdVec; + hichainConnector->DeleteGroupByACL(delACLInfoVec, userIdVec); + std::string groupName = ""; + FuzzedDataProvider fdp(data, size); + int32_t userId = fdp.ConsumeIntegral(); + hichainConnector->IsNeedDelete(groupName, userId, delACLInfoVec); + userId = 1; + groupName = "aclinfo_001"; + hichainConnector->IsNeedDelete(groupName, userId, delACLInfoVec); + std::vector udidList; + nlohmann::json jsonObject; + std::string jsonStr = "dkocosdpa"; + hichainConnector->GetTrustedDevicesUdid(jsonStr.data(), udidList); + jsonObject["authId"] = 1; + jsonStr = jsonObject.dump(); + hichainConnector->GetTrustedDevicesUdid(jsonStr.data(), udidList); + + jsonObject["authId"] = "authInfoId"; + jsonStr = jsonObject.dump(); + hichainConnector->GetTrustedDevicesUdid(jsonStr.data(), udidList); + hichainConnector->deviceGroupManager_ = nullptr; + int32_t groupType = fdp.ConsumeIntegral(); + std::string usersId(reinterpret_cast(data), size); + nlohmann::json jsonDeviceList; + hichainConnector->deleteMultiMembers(groupType, usersId, jsonDeviceList); +} } } @@ -358,5 +395,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) OHOS::DistributedHardware::HiChainConnectorForthFuzzTest(data, size); OHOS::DistributedHardware::HiChainConnectorFifthFuzzTest(data, size); OHOS::DistributedHardware::HiChainConnectorSixthFuzzTest(data, size); + OHOS::DistributedHardware::HiChainConnectorSevenhFuzzTest(data, size); return 0; } \ No newline at end of file diff --git a/test/commonunittest/UTTest_dm_auth_manager_first.cpp b/test/commonunittest/UTTest_dm_auth_manager_first.cpp index b9afe71af..7c563bde9 100644 --- a/test/commonunittest/UTTest_dm_auth_manager_first.cpp +++ b/test/commonunittest/UTTest_dm_auth_manager_first.cpp @@ -776,7 +776,7 @@ HWTEST_F(DmAuthManagerTest, ResponseCredential001, testing::ext::TestSize.Level0 authManager_->ResponseCredential(); ASSERT_EQ(authManager_->isAuthDevice_, false); - authManager_->authResponseContext_->publicKey == "publicKey"; + authManager_->authResponseContext_->publicKey = "publicKey"; EXPECT_CALL(*hiChainAuthConnectorMock_, ImportCredential(_, _, _)).WillOnce(Return(ERR_DM_FAILED)); ASSERT_EQ(authManager_->isAuthDevice_, false); @@ -1944,6 +1944,23 @@ HWTEST_F(DmAuthManagerTest, RegisterAuthenticationType_001, testing::ext::TestSi authManager_->authResponseState_ = std::make_shared(); authManager_->ProcessReqPublicKey(); } + +HWTEST_F(DmAuthManagerTest, CheckProcessNameInWhiteList_001, testing::ext::TestSize.Level0) +{ + std::string processName = ""; + bool ret = authManager_->CheckProcessNameInWhiteList(processName); + ASSERT_FALSE(ret); + + processName = "processName"; + ret = authManager_->CheckProcessNameInWhiteList(processName); + ASSERT_FALSE(ret); + + processName = "com.example.myapplication"; + ret = authManager_->CheckProcessNameInWhiteList(processName); + ASSERT_TRUE(ret); +} + + } // namespace } // namespace DistributedHardware } // namespace OHOS diff --git a/test/servicesfuzztest/BUILD.gn b/test/servicesfuzztest/BUILD.gn index 21cdc8580..72098e145 100644 --- a/test/servicesfuzztest/BUILD.gn +++ b/test/servicesfuzztest/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2024 Huawei Device Co., Ltd. +# Copyright (c) 2022-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 @@ -15,6 +15,7 @@ group("fuzztest") { testonly = true deps = [ + "cryptomgr_fuzzer:fuzztest", "devicediscovery_fuzzer:fuzztest", "devicelist_fuzzer:fuzztest", "devicelistrefresh_fuzzer:fuzztest", @@ -22,6 +23,9 @@ group("fuzztest") { "devicemanagerservice_fuzzer:fuzztest", "deviceprofileconnector_fuzzer:fuzztest", "devicepublish_fuzzer:fuzztest", + "dmcommtool_fuzzer:fuzztest", + "dmtransport_fuzzer:fuzztest", + "dpinitcallback_fuzzer:fuzztest", "getlocaldeviceinfo_fuzzer:fuzztest", "gettrusteddevicelistservice_fuzzer:fuzztest", "getudidbynetworkid_fuzzer:fuzztest", diff --git a/test/servicesfuzztest/cryptomgr_fuzzer/BUILD.gn b/test/servicesfuzztest/cryptomgr_fuzzer/BUILD.gn new file mode 100644 index 000000000..f27dcb737 --- /dev/null +++ b/test/servicesfuzztest/cryptomgr_fuzzer/BUILD.gn @@ -0,0 +1,91 @@ +# Copyright (c) 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/distributedhardware/device_manager/device_manager.gni") + +##############################fuzztest########################################## +ohos_fuzztest("CryptoMgrFuzzTest") { + module_out_path = fuzz_test_output_path + fuzz_config_file = + "${devicemanager_path}/test/servicesfuzztest/cryptomgr_fuzzer" + + include_dirs = [ + "${utils_path}/include", + "${innerkits_path}/native_cpp/include", + "${innerkits_path}/native_cpp/include/ipc/standard", + "${innerkits_path}/native_cpp/include/ipc", + "${innerkits_path}/native_cpp/include/notify", + "${common_path}/include", + "${common_path}/include/ipc", + "${common_path}/include/ipc/model", + "${utils_path}/include/ipc/standard", + "${servicesimpl_path}/include", + "${servicesimpl_path}/include/dependency/timer", + "${servicesimpl_path}/include/discovery", + "${servicesimpl_path}/include/dependency/softbus", + "${servicesimpl_path}/include/authentication", + "${servicesimpl_path}/include/adapter", + "${servicesimpl_path}/include/ipc/standard", + "${servicesimpl_path}/include/publish", + "${servicesimpl_path}/include/dependency/cryptomgr", + "${servicesimpl_path}/include/dependency/deviceprofile", + "${servicesimpl_path}/include/dependency/hichain", + "${servicesimpl_path}/include/devicestate", + "${devicemanager_path}/interfaces/kits/js/include", + "${devicemanager_path}/test/unittest/mock", + "${servicesimpl_path}/include/ability", + "${servicesimpl_path}/include/config", + ] + + cflags = [ + "-g", + "-O0", + "-Dprivate=public", + "-Dprotected=public", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "crypto_mgr_fuzzer.cpp" ] + + deps = [ + "${devicemanager_path}/services/implementation:devicemanagerserviceimpl", + "${utils_path}:devicemanagerutils", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"CryptoMgrFuzzTest\"", + "LOG_DOMAIN=0xD004110", + ] + + external_deps = [ + "device_auth:deviceauth_sdk", + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", + "ipc:ipc_single", + "napi:ace_napi", + "safwk:system_ability_fwk", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":CryptoMgrFuzzTest" ] +} +############################################################################### diff --git a/test/servicesfuzztest/cryptomgr_fuzzer/corpus/init b/test/servicesfuzztest/cryptomgr_fuzzer/corpus/init new file mode 100644 index 000000000..9c560fe89 --- /dev/null +++ b/test/servicesfuzztest/cryptomgr_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/test/servicesfuzztest/cryptomgr_fuzzer/crypto_mgr_fuzzer.cpp b/test/servicesfuzztest/cryptomgr_fuzzer/crypto_mgr_fuzzer.cpp new file mode 100644 index 000000000..ff619f352 --- /dev/null +++ b/test/servicesfuzztest/cryptomgr_fuzzer/crypto_mgr_fuzzer.cpp @@ -0,0 +1,158 @@ +/* + * Copyright (c) 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "crypto_mgr.h" +#include "crypto_mgr_fuzzer.h" +#include "dm_constants.h" +#include "nlohmann/json.hpp" + + +namespace OHOS { +namespace DistributedHardware { + +namespace { + constexpr uint32_t CIPHER_TEXT_LEN = 128; + constexpr uint32_t PLAIN_TEXT_SIZE = 5; + constexpr uint32_t PLAIN_LEN = 10; + constexpr uint32_t CIPHER_TEXT_SIZE = 12; + constexpr uint32_t KEY_LEN = 1024; +} + +std::shared_ptr cryproMgr_ = std::make_shared(); +void CryptoMgrFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string inputMsg(reinterpret_cast(data), size); + std::string outputMsg(reinterpret_cast(data), size); + cryproMgr_->EncryptMessage(inputMsg, outputMsg); + cryproMgr_->DecryptMessage(inputMsg, outputMsg); + + AesGcmCipherKey *cipherKey = nullptr; + unsigned char *input = nullptr; + uint32_t inLen = 0; + unsigned char *encryptData = nullptr; + uint32_t *encryptLen = nullptr; + cryproMgr_->DoEncryptData(cipherKey, input, inLen, encryptData, encryptLen); + + AesGcmCipherKey cipherKeyPro; + cipherKey = &cipherKeyPro; + std::string cipherStr(reinterpret_cast(data), size); + input = reinterpret_cast(cipherStr.data()); + inLen = static_cast(cipherStr.length()); + std::string encryStr(reinterpret_cast(data), size); + encryptData = reinterpret_cast(encryStr.data()); + uint32_t encryNum = static_cast(encryStr.length()); + encryptLen = &encryNum; + cryproMgr_->DoEncryptData(cipherKey, input, inLen, encryptData, encryptLen); + + unsigned char *randStr = nullptr; + uint32_t len = 0; + cryproMgr_->GenerateRandomArray(randStr, len); + std::string randStrTemp(reinterpret_cast(data), size); + randStr = reinterpret_cast(randStrTemp.data()); + len = static_cast(randStrTemp.length()); + cryproMgr_->GenerateRandomArray(randStr, len); +} + +void CryptoMgrFirstFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + AesGcmCipherKey *cipherKey = nullptr; + unsigned char *plainText = nullptr; + uint32_t plainTextSize = 0; + unsigned char *cipherText = nullptr; + uint32_t cipherTextLen = 0; + uint32_t cipherTextSize = 0; + unsigned char *plain = nullptr; + uint32_t plainLen = 0; + cryproMgr_->MbedAesGcmEncrypt(cipherKey, plainText, plainTextSize, cipherText, cipherTextLen); + cryproMgr_->MbedAesGcmDecrypt(cipherKey, cipherText, cipherTextSize, plain, plainLen); + AesGcmCipherKey cipherKeyPro; + cipherKey = &cipherKeyPro; + char plainTextTemp[PLAIN_TEXT_SIZE] = {1}; + plainText = reinterpret_cast(plainTextTemp); + plainTextSize = PLAIN_TEXT_SIZE; + char cipherTextTemp[CIPHER_TEXT_LEN] = {11}; + cipherText = reinterpret_cast(cipherTextTemp); + cipherTextLen = CIPHER_TEXT_LEN; + cryproMgr_->MbedAesGcmEncrypt(cipherKey, plainText, plainTextSize, cipherText, cipherTextLen); + + char cipherTextInfo[CIPHER_TEXT_SIZE] = {10}; + cipherText = reinterpret_cast(cipherTextInfo); + cipherTextSize = CIPHER_TEXT_SIZE; + char plainTemp[PLAIN_LEN] = {12}; + plain = reinterpret_cast(plainTemp); + plainLen = PLAIN_LEN; + cryproMgr_->MbedAesGcmDecrypt(cipherKey, cipherText, cipherTextSize, plain, plainLen); +} + + +void CryptoMgrSecondFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + + AesGcmCipherKey *cipherKey = nullptr; + unsigned char *input = nullptr; + uint32_t inLen = 0; + unsigned char *decryptData = nullptr; + uint32_t *decryptLen = nullptr; + cryproMgr_->DoDecryptData(cipherKey, input, inLen, decryptData, decryptLen); + + AesGcmCipherKey cipherKeyPro; + cipherKey = &cipherKeyPro; + std::string inputTemp(reinterpret_cast(data), size); + input = reinterpret_cast(inputTemp.data()); + inLen = static_cast(inputTemp.length()); + std::string decryInfo(reinterpret_cast(data), size); + decryptData = reinterpret_cast(decryInfo.data()); + uint32_t decryNum = static_cast(decryInfo.length()); + decryptLen = &decryNum; + cryproMgr_->DoDecryptData(cipherKey, input, inLen, decryptData, decryptLen); + + std::string sessionInfo(reinterpret_cast(data), size); + uint8_t *sessionKey = reinterpret_cast(sessionInfo.data()); + uint32_t keyLen = static_cast(sessionInfo.length()); + cryproMgr_->SaveSessionKey(sessionKey, keyLen); + cryproMgr_->ClearSessionKey(); + keyLen = KEY_LEN; + cryproMgr_->SaveSessionKey(sessionKey, keyLen); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::CryptoMgrFuzzTest(data, size); + OHOS::DistributedHardware::CryptoMgrFirstFuzzTest(data, size); + OHOS::DistributedHardware::CryptoMgrSecondFuzzTest(data, size); + return 0; +} diff --git a/test/servicesfuzztest/cryptomgr_fuzzer/crypto_mgr_fuzzer.h b/test/servicesfuzztest/cryptomgr_fuzzer/crypto_mgr_fuzzer.h new file mode 100644 index 000000000..f9f02cc07 --- /dev/null +++ b/test/servicesfuzztest/cryptomgr_fuzzer/crypto_mgr_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CRYPTO_MGR_FUZZER_TEST_H +#define CRYPTO_MGR_FUZZER_TEST_H + +#define FUZZ_PROJECT_NAME "cryptomgr_fuzzer" + +#endif // CRYPTO_MGR_FUZZER_TEST_H diff --git a/test/servicesfuzztest/cryptomgr_fuzzer/project.xml b/test/servicesfuzztest/cryptomgr_fuzzer/project.xml new file mode 100644 index 000000000..66e1dcac4 --- /dev/null +++ b/test/servicesfuzztest/cryptomgr_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/servicesfuzztest/dmcommtool_fuzzer/BUILD.gn b/test/servicesfuzztest/dmcommtool_fuzzer/BUILD.gn new file mode 100644 index 000000000..df8e45c1f --- /dev/null +++ b/test/servicesfuzztest/dmcommtool_fuzzer/BUILD.gn @@ -0,0 +1,91 @@ +# Copyright (c) 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/distributedhardware/device_manager/device_manager.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DmCommToolFuzzTest") { + module_out_path = fuzz_test_output_path + fuzz_config_file = + "${devicemanager_path}/test/servicesfuzztest/dmcommtool_fuzzer" + + include_dirs = [ + "${utils_path}/include", + "${innerkits_path}/native_cpp/include", + "${innerkits_path}/native_cpp/include/ipc/standard", + "${innerkits_path}/native_cpp/include/ipc", + "${innerkits_path}/native_cpp/include/notify", + "${common_path}/include", + "${common_path}/include/ipc", + "${common_path}/include/ipc/model", + "${utils_path}/include/ipc/standard", + "${servicesimpl_path}/include", + "${servicesimpl_path}/include/dependency/timer", + "${servicesimpl_path}/include/discovery", + "${servicesimpl_path}/include/dependency/softbus", + "${servicesimpl_path}/include/authentication", + "${servicesimpl_path}/include/adapter", + "${servicesimpl_path}/include/ipc/standard", + "${servicesimpl_path}/include/publish", + "${servicesimpl_path}/include/dependency/deviceprofile", + "${servicesimpl_path}/include/dependency/hichain", + "${servicesimpl_path}/include/devicestate", + "${devicemanager_path}/interfaces/kits/js/include", + "${devicemanager_path}/services/service/include/relationshipsyncmgr", + "${devicemanager_path}/test/unittest/mock", + "${servicesimpl_path}/include/ability", + "${servicesimpl_path}/include/config", + ] + + cflags = [ + "-g", + "-O0", + "-Dprivate=public", + "-Dprotected=public", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "dm_comm_tool_fuzzer.cpp" ] + + deps = [ + "${devicemanager_path}/services/service:devicemanagerservice", + "${utils_path}:devicemanagerutils", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DmCommToolFuzzTest\"", + "LOG_DOMAIN=0xD004110", + ] + + external_deps = [ + "cJSON:cjson", + "device_auth:deviceauth_sdk", + "dsoftbus:softbus_client", + "ipc:ipc_single", + "napi:ace_napi", + "safwk:system_ability_fwk", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":DmCommToolFuzzTest" ] +} +############################################################################### diff --git a/test/servicesfuzztest/dmcommtool_fuzzer/corpus/init b/test/servicesfuzztest/dmcommtool_fuzzer/corpus/init new file mode 100644 index 000000000..9c560fe89 --- /dev/null +++ b/test/servicesfuzztest/dmcommtool_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/test/servicesfuzztest/dmcommtool_fuzzer/dm_comm_tool_fuzzer.cpp b/test/servicesfuzztest/dmcommtool_fuzzer/dm_comm_tool_fuzzer.cpp new file mode 100644 index 000000000..4ab211714 --- /dev/null +++ b/test/servicesfuzztest/dmcommtool_fuzzer/dm_comm_tool_fuzzer.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (c) 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "dm_comm_tool_fuzzer.h" +#include "dm_comm_tool.h" + + +namespace OHOS { +namespace DistributedHardware { + +namespace { + constexpr uint32_t DATA_LEN = 10; +} + +std::shared_ptr dmCommToolPtr_ = std::make_shared(); + +void DmCommToolFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + int32_t socketId = fdp.ConsumeIntegral(); + std::string rmtNetworkId(reinterpret_cast(data), size); + dmCommToolPtr_->Init(); + dmCommToolPtr_->GetInstance(); + dmCommToolPtr_->UnInit(); + std::vector foregroundUserIds; + foregroundUserIds.push_back(DATA_LEN); + std::vector backgroundUserIds; + dmCommToolPtr_->SendUserIds(rmtNetworkId, foregroundUserIds, backgroundUserIds); + dmCommToolPtr_->RspLocalFrontOrBackUserIds(rmtNetworkId, foregroundUserIds, backgroundUserIds, socketId); + rmtNetworkId = ""; + dmCommToolPtr_->SendUserIds(rmtNetworkId, foregroundUserIds, backgroundUserIds); + std::string remoteNetworkId(reinterpret_cast(data), size); + std::shared_ptr commMsg = std::make_shared(); + std::shared_ptr innerCommMsg = std::make_shared(remoteNetworkId, commMsg, socketId); + dmCommToolPtr_->ProcessReceiveUserIdsEvent(innerCommMsg); + dmCommToolPtr_->ProcessResponseUserIdsEvent(innerCommMsg); + dmCommToolPtr_->GetDMTransportPtr(); + dmCommToolPtr_->GetEventHandler(); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DmCommToolFuzzTest(data, size); + return 0; +} diff --git a/test/servicesfuzztest/dmcommtool_fuzzer/dm_comm_tool_fuzzer.h b/test/servicesfuzztest/dmcommtool_fuzzer/dm_comm_tool_fuzzer.h new file mode 100644 index 000000000..a0bf70575 --- /dev/null +++ b/test/servicesfuzztest/dmcommtool_fuzzer/dm_comm_tool_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DM_COMM_TOOL_FUZZER_TEST_H +#define DM_COMM_TOOL_FUZZER_TEST_H + +#define FUZZ_PROJECT_NAME "dmcommtool_fuzzer" + +#endif // DM_COMM_TOOL_FUZZER_TEST_H diff --git a/test/servicesfuzztest/dmcommtool_fuzzer/project.xml b/test/servicesfuzztest/dmcommtool_fuzzer/project.xml new file mode 100644 index 000000000..66e1dcac4 --- /dev/null +++ b/test/servicesfuzztest/dmcommtool_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/servicesfuzztest/dmtransport_fuzzer/BUILD.gn b/test/servicesfuzztest/dmtransport_fuzzer/BUILD.gn new file mode 100644 index 000000000..26f5b665d --- /dev/null +++ b/test/servicesfuzztest/dmtransport_fuzzer/BUILD.gn @@ -0,0 +1,91 @@ +# Copyright (c) 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/distributedhardware/device_manager/device_manager.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DmTransPortFuzzTest") { + module_out_path = fuzz_test_output_path + fuzz_config_file = + "${devicemanager_path}/test/servicesfuzztest/dmtransport_fuzzer" + + include_dirs = [ + "${utils_path}/include", + "${innerkits_path}/native_cpp/include", + "${innerkits_path}/native_cpp/include/ipc/standard", + "${innerkits_path}/native_cpp/include/ipc", + "${innerkits_path}/native_cpp/include/notify", + "${common_path}/include", + "${common_path}/include/ipc", + "${common_path}/include/ipc/model", + "${utils_path}/include/ipc/standard", + "${servicesimpl_path}/include", + "${servicesimpl_path}/include/dependency/timer", + "${servicesimpl_path}/include/discovery", + "${servicesimpl_path}/include/dependency/softbus", + "${servicesimpl_path}/include/authentication", + "${servicesimpl_path}/include/adapter", + "${servicesimpl_path}/include/ipc/standard", + "${servicesimpl_path}/include/publish", + "${servicesimpl_path}/include/dependency/deviceprofile", + "${servicesimpl_path}/include/dependency/hichain", + "${servicesimpl_path}/include/devicestate", + "${devicemanager_path}/interfaces/kits/js/include", + "${devicemanager_path}/services/service/include/relationshipsyncmgr", + "${devicemanager_path}/test/unittest/mock", + "${servicesimpl_path}/include/ability", + "${servicesimpl_path}/include/config", + ] + + cflags = [ + "-g", + "-O0", + "-Dprivate=public", + "-Dprotected=public", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "dm_transport_fuzzer.cpp" ] + + deps = [ + "${devicemanager_path}/services/service:devicemanagerservice", + "${utils_path}:devicemanagerutils", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DmTransPortFuzzTest\"", + "LOG_DOMAIN=0xD004110", + ] + + external_deps = [ + "cJSON:cjson", + "device_auth:deviceauth_sdk", + "dsoftbus:softbus_client", + "ipc:ipc_single", + "napi:ace_napi", + "safwk:system_ability_fwk", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":DmTransPortFuzzTest" ] +} +############################################################################### diff --git a/test/servicesfuzztest/dmtransport_fuzzer/corpus/init b/test/servicesfuzztest/dmtransport_fuzzer/corpus/init new file mode 100644 index 000000000..9c560fe89 --- /dev/null +++ b/test/servicesfuzztest/dmtransport_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/test/servicesfuzztest/dmtransport_fuzzer/dm_transport_fuzzer.cpp b/test/servicesfuzztest/dmtransport_fuzzer/dm_transport_fuzzer.cpp new file mode 100644 index 000000000..684e60ddd --- /dev/null +++ b/test/servicesfuzztest/dmtransport_fuzzer/dm_transport_fuzzer.cpp @@ -0,0 +1,133 @@ +/* + * Copyright (c) 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +#include "dm_transport.h" +#include "dm_transport_fuzzer.h" +#include "dm_comm_tool.h" + + +namespace OHOS { +namespace DistributedHardware { + +std::shared_ptr dmCommToolPtr_ = std::make_shared(); +std::shared_ptr dmTransPortPtr_ = std::make_shared(dmCommToolPtr_); + + +void DmTransPortFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + int32_t socketId = fdp.ConsumeIntegral(); + std::string rmtNetworkId(reinterpret_cast(data), size); + std::string dmPkgName(reinterpret_cast(data), size); + std::string peerSocketName(reinterpret_cast(data), size); + PeerSocketInfo info = { + .name = const_cast(peerSocketName.c_str()), + .networkId = const_cast(rmtNetworkId.c_str()), + .pkgName = const_cast(dmPkgName.c_str()), + .dataType = DATA_TYPE_BYTES + }; + dmTransPortPtr_->OnSocketOpened(socketId, info); + dmTransPortPtr_->OnSocketOpened(socketId, info); + ShutdownReason reason = ShutdownReason::SHUTDOWN_REASON_LNN_CHANGED; + dmTransPortPtr_->OnSocketClosed(socketId, reason); + + void *dataInfo = nullptr; + uint32_t dataLen = 0; + dmTransPortPtr_->OnBytesReceived(socketId, dataInfo, dataLen); + + std::string dataStr(reinterpret_cast(data), size); + dataInfo = reinterpret_cast(dataStr.data()); + dataLen = static_cast(dataStr.length()); + dmTransPortPtr_->OnBytesReceived(socketId, dataInfo, dataLen); + + std::string payload(reinterpret_cast(data), size); + dmTransPortPtr_->HandleReceiveMessage(socketId, payload); + + payload = ""; + dmTransPortPtr_->HandleReceiveMessage(socketId, payload); +} + +void DmTransPortFirstFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + + const char* jsonString = R"({ + "MsgType": "0", + "userId": "12345", + "accountId": "a******3", + "peerUdids": ["u******1", "u******2"], + "peerUdid": "p******d", + "accountName": "t******t", + "syncUserIdFlag": 1, + "userIds": [ + {"type": 1, "userId": 111}, + {"type": 0, "userId": 222} + ] + })"; + + std::string payload(jsonString); + FuzzedDataProvider fdp(data, size); + int32_t socketId = fdp.ConsumeIntegral(); + std::string rmtNetworkId(reinterpret_cast(data), size); + std::string dmPkgName(reinterpret_cast(data), size); + std::string peerSocketName(reinterpret_cast(data), size); + PeerSocketInfo info = { + .name = const_cast(peerSocketName.c_str()), + .networkId = const_cast(rmtNetworkId.c_str()), + .pkgName = const_cast(dmPkgName.c_str()), + .dataType = DATA_TYPE_BYTES + }; + dmTransPortPtr_->OnSocketOpened(socketId, info); + dmTransPortPtr_->HandleReceiveMessage(socketId, payload); + dmTransPortPtr_->CreateClientSocket(rmtNetworkId); + dmTransPortPtr_->IsDeviceSessionOpened(rmtNetworkId, socketId); + dmTransPortPtr_->StartSocket(rmtNetworkId, socketId); + dmTransPortPtr_->StopSocket(rmtNetworkId); + dmTransPortPtr_->Send(rmtNetworkId, payload, socketId); + rmtNetworkId = ""; + dmTransPortPtr_->CreateClientSocket(rmtNetworkId); + dmTransPortPtr_->StartSocket(rmtNetworkId, socketId); + dmTransPortPtr_->StopSocket(rmtNetworkId); + dmTransPortPtr_->Send(rmtNetworkId, payload, socketId); + rmtNetworkId = "rmtNetworkId"; + dmTransPortPtr_->CreateClientSocket(rmtNetworkId); + dmTransPortPtr_->UnInit(); + dmTransPortPtr_->IsDeviceSessionOpened(rmtNetworkId, socketId); + std::string remoteDevId(reinterpret_cast(data), size); + dmTransPortPtr_->ClearDeviceSocketOpened(remoteDevId, socketId); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DmTransPortFuzzTest(data, size); + OHOS::DistributedHardware::DmTransPortFirstFuzzTest(data, size); + return 0; +} diff --git a/test/servicesfuzztest/dmtransport_fuzzer/dm_transport_fuzzer.h b/test/servicesfuzztest/dmtransport_fuzzer/dm_transport_fuzzer.h new file mode 100644 index 000000000..972228e62 --- /dev/null +++ b/test/servicesfuzztest/dmtransport_fuzzer/dm_transport_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DM_TRANSPORT_FUZZER_TEST_H +#define DM_TRANSPORT_FUZZER_TEST_H + +#define FUZZ_PROJECT_NAME "dmtransport_fuzzer" + +#endif // DM_TRANSPORT_FUZZER_TEST_H diff --git a/test/servicesfuzztest/dmtransport_fuzzer/project.xml b/test/servicesfuzztest/dmtransport_fuzzer/project.xml new file mode 100644 index 000000000..66e1dcac4 --- /dev/null +++ b/test/servicesfuzztest/dmtransport_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/servicesfuzztest/dpinitcallback_fuzzer/BUILD.gn b/test/servicesfuzztest/dpinitcallback_fuzzer/BUILD.gn new file mode 100644 index 000000000..9a102149f --- /dev/null +++ b/test/servicesfuzztest/dpinitcallback_fuzzer/BUILD.gn @@ -0,0 +1,90 @@ +# Copyright (c) 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/distributedhardware/device_manager/device_manager.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DpInitCallbackFuzzTest") { + module_out_path = fuzz_test_output_path + fuzz_config_file = + "${devicemanager_path}/test/servicesfuzztest/dpinitcallback_fuzzer" + + include_dirs = [ + "${utils_path}/include", + "${innerkits_path}/native_cpp/include", + "${innerkits_path}/native_cpp/include/ipc/standard", + "${innerkits_path}/native_cpp/include/ipc", + "${innerkits_path}/native_cpp/include/notify", + "${common_path}/include", + "${common_path}/include/ipc", + "${common_path}/include/ipc/model", + "${utils_path}/include/ipc/standard", + "${servicesimpl_path}/include", + "${servicesimpl_path}/include/dependency/timer", + "${servicesimpl_path}/include/discovery", + "${servicesimpl_path}/include/dependency/softbus", + "${servicesimpl_path}/include/authentication", + "${servicesimpl_path}/include/adapter", + "${servicesimpl_path}/include/ipc/standard", + "${servicesimpl_path}/include/publish", + "${servicesimpl_path}/include/dependency/deviceprofile", + "${servicesimpl_path}/include/dependency/hichain", + "${servicesimpl_path}/include/devicestate", + "${devicemanager_path}/interfaces/kits/js/include", + "${devicemanager_path}/test/unittest/mock", + "${servicesimpl_path}/include/ability", + "${servicesimpl_path}/include/config", + ] + + cflags = [ + "-g", + "-O0", + "-Dprivate=public", + "-Dprotected=public", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "dp_init_callback_fuzzer.cpp" ] + + deps = [ + "${devicemanager_path}/services/implementation:devicemanagerserviceimpl", + "${utils_path}:devicemanagerutils", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DpInitCallbackFuzzTest\"", + "LOG_DOMAIN=0xD004110", + ] + + external_deps = [ + "device_auth:deviceauth_sdk", + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", + "ipc:ipc_single", + "napi:ace_napi", + "safwk:system_ability_fwk", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":DpInitCallbackFuzzTest" ] +} +############################################################################### diff --git a/test/servicesfuzztest/dpinitcallback_fuzzer/corpus/init b/test/servicesfuzztest/dpinitcallback_fuzzer/corpus/init new file mode 100644 index 000000000..9c560fe89 --- /dev/null +++ b/test/servicesfuzztest/dpinitcallback_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/test/servicesfuzztest/dpinitcallback_fuzzer/dp_init_callback_fuzzer.cpp b/test/servicesfuzztest/dpinitcallback_fuzzer/dp_init_callback_fuzzer.cpp new file mode 100644 index 000000000..c12c99ab1 --- /dev/null +++ b/test/servicesfuzztest/dpinitcallback_fuzzer/dp_init_callback_fuzzer.cpp @@ -0,0 +1,82 @@ +/* + * Copyright (c) 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include "dp_inited_callback.h" +#include "dp_init_callback_fuzzer.h" +#include "dm_constants.h" +#include "nlohmann/json.hpp" + + +namespace OHOS { +namespace DistributedHardware { + +namespace { + constexpr uint32_t DATA_LEN = 10; +} +void DpInitedCallbackFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + DpInitedCallback dpInitedCallback; + dpInitedCallback.PutAllTrustedDevices(); +} + +void DpInitedCallbackFirstFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + DpInitedCallback dpInitedCallback; + std::unordered_map authFormMap; + DmDeviceInfo deviceInfo; + deviceInfo.extraData = ""; + DistributedDeviceProfile::TrustedDeviceInfo trustedDeviceInfo; + dpInitedCallback.ConvertToTrustedDeviceInfo(authFormMap, deviceInfo, trustedDeviceInfo); + + deviceInfo.extraData = "extraInfo"; + dpInitedCallback.ConvertToTrustedDeviceInfo(authFormMap, deviceInfo, trustedDeviceInfo); + + nlohmann::json extraJson; + extraJson[PARAM_KEY_OS_VERSION] = 1; + deviceInfo.extraData = extraJson.dump(); + dpInitedCallback.ConvertToTrustedDeviceInfo(authFormMap, deviceInfo, trustedDeviceInfo); + + extraJson[PARAM_KEY_OS_VERSION] = "os_version"; + extraJson[PARAM_KEY_OS_TYPE] = "os_type"; + deviceInfo.extraData = extraJson.dump(); + dpInitedCallback.ConvertToTrustedDeviceInfo(authFormMap, deviceInfo, trustedDeviceInfo); + + extraJson[PARAM_KEY_OS_TYPE] = DATA_LEN; + deviceInfo.extraData = extraJson.dump(); + dpInitedCallback.ConvertToTrustedDeviceInfo(authFormMap, deviceInfo, trustedDeviceInfo); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DpInitedCallbackFuzzTest(data, size); + OHOS::DistributedHardware::DpInitedCallbackFirstFuzzTest(data, size); + return 0; +} diff --git a/test/servicesfuzztest/dpinitcallback_fuzzer/dp_init_callback_fuzzer.h b/test/servicesfuzztest/dpinitcallback_fuzzer/dp_init_callback_fuzzer.h new file mode 100644 index 000000000..bc9cc3df1 --- /dev/null +++ b/test/servicesfuzztest/dpinitcallback_fuzzer/dp_init_callback_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DP_INIT_CALLBACK_FUZZER_TEST_H +#define DP_INIT_CALLBACK_FUZZER_TEST_H + +#define FUZZ_PROJECT_NAME "dpinitcallback_fuzzer" + +#endif // DP_INIT_CALLBACK_FUZZER_TEST_H diff --git a/test/servicesfuzztest/dpinitcallback_fuzzer/project.xml b/test/servicesfuzztest/dpinitcallback_fuzzer/project.xml new file mode 100644 index 000000000..66e1dcac4 --- /dev/null +++ b/test/servicesfuzztest/dpinitcallback_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/softbusunittest/UTTest_softbus_listener.cpp b/test/softbusunittest/UTTest_softbus_listener.cpp index 4607adbde..12b9bb8d3 100644 --- a/test/softbusunittest/UTTest_softbus_listener.cpp +++ b/test/softbusunittest/UTTest_softbus_listener.cpp @@ -30,6 +30,8 @@ #include "softbus_listener.cpp" #include "softbus_error_code.h" +using namespace testing; +using namespace testing::ext; namespace OHOS { namespace DistributedHardware { void SoftbusListenerTest::SetUp() @@ -40,9 +42,19 @@ void SoftbusListenerTest::TearDown() } void SoftbusListenerTest::SetUpTestCase() { + DistributedDeviceProfile::DpDistributedDeviceProfileClient::dpDistributedDeviceProfileClient = + distributedDeviceProfileClientMock_; + DmCrypto::dmCrypto = cryptoMock_; + DmSoftbusCache::dmSoftbusCache = softbusCacheMock_; } void SoftbusListenerTest::TearDownTestCase() { + DistributedDeviceProfile::DpDistributedDeviceProfileClient::dpDistributedDeviceProfileClient = nullptr; + distributedDeviceProfileClientMock_ = nullptr; + DmCrypto::dmCrypto = nullptr; + cryptoMock_ = nullptr; + DmSoftbusCache::dmSoftbusCache = nullptr; + softbusCacheMock_ = nullptr; } namespace { @@ -314,6 +326,7 @@ HWTEST_F(SoftbusListenerTest, GetUdidByNetworkId_001, testing::ext::TestSize.Lev if (softbusListener == nullptr) { softbusListener = std::make_shared(); } + EXPECT_CALL(*softbusCacheMock_, GetUdidFromCache(_, _)).WillOnce(Return(SOFTBUS_INVALID_PARAM)); int32_t ret = softbusListener->GetUdidByNetworkId(networkId.c_str(), udid); EXPECT_EQ(true, checkSoftbusRes(ret)); } @@ -325,6 +338,7 @@ HWTEST_F(SoftbusListenerTest, GetUuidByNetworkId_001, testing::ext::TestSize.Lev if (softbusListener == nullptr) { softbusListener = std::make_shared(); } + EXPECT_CALL(*softbusCacheMock_, GetUuidFromCache(_, _)).WillOnce(Return(SOFTBUS_INVALID_PARAM)); int32_t ret = softbusListener->GetUuidByNetworkId(networkId.c_str(), udid); EXPECT_EQ(true, checkSoftbusRes(ret)); } @@ -798,6 +812,7 @@ HWTEST_F(SoftbusListenerTest, GetLocalDeviceInfo_001, testing::ext::TestSize.Lev if (softbusListener == nullptr) { softbusListener = std::make_shared(); } + EXPECT_CALL(*softbusCacheMock_, GetLocalDeviceInfo(_)).WillOnce(Return(SOFTBUS_INVALID_PARAM)); int32_t ret = softbusListener->GetLocalDeviceInfo(info); EXPECT_EQ(true, checkSoftbusRes(ret)); } @@ -1040,6 +1055,7 @@ HWTEST_F(SoftbusListenerTest, GetNetworkIdByUdid_001, testing::ext::TestSize.Lev if (softbusListener == nullptr) { softbusListener = std::make_shared(); } + EXPECT_CALL(*softbusCacheMock_, GetNetworkIdFromCache(_, _)).WillOnce(Return(ERR_DM_FAILED)); int32_t ret = softbusListener->GetNetworkIdByUdid(udid, networkId); EXPECT_EQ(ret, ERR_DM_FAILED); } @@ -1073,6 +1089,103 @@ HWTEST_F(SoftbusListenerTest, SetForegroundUserIdsToDSoftBus_001, testing::ext:: softbusListener->OnCredentialAuthStatus(devicelist, deviceListLen, deviceTypeId, errcode); softbusListener = nullptr; } + +HWTEST_F(SoftbusListenerTest, GetUdidFromDp_001, testing::ext::TestSize.Level0) +{ + std::string udidHash = "udidHash"; + std::string udid = "udid"; + if (softbusListener == nullptr) { + softbusListener = std::make_shared(); + } + EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(ERR_DM_FAILED)); + int32_t ret = softbusListener->GetUdidFromDp(udidHash, udid); + EXPECT_EQ(ret, ERR_DM_FAILED); + + std::vector allProfile; + DistributedDeviceProfile::AccessControlProfile profile; + profile.SetBindType(1); + allProfile.push_back(profile); + EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)) + .WillOnce(DoAll(SetArgReferee<0>(allProfile), Return(DM_OK))); + ret = softbusListener->GetUdidFromDp(udidHash, udid); + EXPECT_EQ(ret, ERR_DM_FAILED); + + profile.SetBindType(2); + profile.SetTrustDeviceId("trustDeviceId"); + allProfile.push_back(profile); + EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)) + .WillOnce(DoAll(SetArgReferee<0>(allProfile), Return(DM_OK))); + EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).Times(::testing::AtLeast(1)).WillOnce(Return(ERR_DM_FAILED)); + ret = softbusListener->GetUdidFromDp(udidHash, udid); + EXPECT_EQ(ret, ERR_DM_FAILED); + + EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)) + .WillOnce(DoAll(SetArgReferee<0>(allProfile), Return(DM_OK))); + EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).Times(::testing::AtLeast(1)).WillOnce(Return(DM_OK)); + ret = softbusListener->GetUdidFromDp(udidHash, udid); + EXPECT_EQ(ret, ERR_DM_FAILED); +} + +HWTEST_F(SoftbusListenerTest, SetLocalDisplayName_001, testing::ext::TestSize.Level0) +{ + std::string displayName = "displayName"; + if (softbusListener == nullptr) { + softbusListener = std::make_shared(); + } + int32_t ret = softbusListener->SetLocalDisplayName(displayName); + EXPECT_EQ(ret, DM_OK); + std::vector onlineDevInfoVec; + EXPECT_CALL(*softbusCacheMock_, GetDeviceInfoFromCache(_)).Times(::testing::AtLeast(1)) + .WillOnce(DoAll(SetArgReferee<0>(onlineDevInfoVec), Return(DM_OK))); + softbusListener->DeleteCacheDeviceInfo(); + + DmDeviceInfo dmDeviceInfo; + dmDeviceInfo.authForm = DmAuthForm::ACROSS_ACCOUNT; + dmDeviceInfo.deviceTypeId = 1; + onlineDevInfoVec.push_back(dmDeviceInfo); + EXPECT_CALL(*softbusCacheMock_, GetDeviceInfoFromCache(_)).Times(::testing::AtLeast(1)) + .WillOnce(DoAll(SetArgReferee<0>(onlineDevInfoVec), Return(DM_OK))); + softbusListener->DeleteCacheDeviceInfo(); + + DistributedDeviceProfile::AccessControlProfile profile; + DmDeviceInfo deviceInfo; + EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).Times(::testing::AtLeast(1)).WillOnce(Return(ERR_DM_FAILED)); + softbusListener->ConvertAclToDeviceInfo(profile, deviceInfo); + + EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).Times(::testing::AtLeast(1)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*softbusCacheMock_, GetNetworkIdFromCache(_, _)).Times(::testing::AtLeast(1)).WillOnce(Return(DM_OK)); + softbusListener->ConvertAclToDeviceInfo(profile, deviceInfo); + + EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).Times(::testing::AtLeast(1)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*softbusCacheMock_, GetNetworkIdFromCache(_, _)).WillOnce(Return(ERR_DM_FAILED)); + EXPECT_CALL(*softbusCacheMock_, GetDeviceNameFromCache(_, _)).WillOnce(Return(DM_OK)); + softbusListener->ConvertAclToDeviceInfo(profile, deviceInfo); + + EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).Times(::testing::AtLeast(1)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*softbusCacheMock_, GetNetworkIdFromCache(_, _)).WillOnce(Return(ERR_DM_FAILED)); + EXPECT_CALL(*softbusCacheMock_, GetDeviceNameFromCache(_, _)).WillOnce(Return(ERR_DM_FAILED)); + softbusListener->ConvertAclToDeviceInfo(profile, deviceInfo); + softbusListener = nullptr; +} + +HWTEST_F(SoftbusListenerTest, GetAllTrustedDeviceList_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "pkgName"; + std::string extra = "extra"; + std::vector deviceList; + if (softbusListener == nullptr) { + softbusListener = std::make_shared(); + } + std::vector allProfile; + DistributedDeviceProfile::AccessControlProfile profile; + profile.SetBindType(1); + allProfile.push_back(profile); + EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)) + .WillOnce(DoAll(SetArgReferee<0>(allProfile), Return(DM_OK))); + int32_t ret = softbusListener->GetAllTrustedDeviceList(pkgName, extra, deviceList); + EXPECT_EQ(ret, DM_OK); + softbusListener = nullptr; +} } // namespace } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/softbusunittest/UTTest_softbus_listener.h b/test/softbusunittest/UTTest_softbus_listener.h index f840ea9e7..59fa7a976 100644 --- a/test/softbusunittest/UTTest_softbus_listener.h +++ b/test/softbusunittest/UTTest_softbus_listener.h @@ -29,6 +29,9 @@ #include "dm_subscribe_info.h" #include "inner_session.h" #include "session.h" +#include "distributed_device_profile_client_mock.h" +#include "dm_crypto_mock.h" +#include "dm_softbus_cache_mock.h" namespace OHOS { namespace DistributedHardware { @@ -38,6 +41,11 @@ public: static void TearDownTestCase(); void SetUp(); void TearDown(); + static inline std::shared_ptr + distributedDeviceProfileClientMock_ = + std::make_shared(); + static inline std::shared_ptr cryptoMock_ = std::make_shared(); + static inline std::shared_ptr softbusCacheMock_ = std::make_shared(); }; class ISoftbusDiscoveringCallbackTest : public ISoftbusDiscoveringCallback { diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index d47d3f153..258dc2528 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -589,6 +589,9 @@ ohos_unittest("UTTest_softbus_listener") { sources = [ "${devicemanager_path}/test/softbusunittest/UTTest_softbus_listener.cpp", "${devicemanager_path}/test/unittest/mock/parameter.cpp", + "mock/distributed_device_profile_client_mock.cpp", + "mock/dm_crypto_mock.cpp", + "mock/dm_softbus_cache_mock.cpp", ] deps = [ ":device_manager_test_common" ] @@ -601,6 +604,7 @@ ohos_unittest("UTTest_softbus_listener") { "dsoftbus:softbus_client", "ffrt:libffrt", "googletest:gmock", + "googletest:gmock_main", "hisysevent:libhisysevent", "hitrace:hitrace_meter", ] diff --git a/test/unittest/UTTest_device_manager_impl_two.cpp b/test/unittest/UTTest_device_manager_impl_two.cpp index c28495417..ea0aa57f4 100644 --- a/test/unittest/UTTest_device_manager_impl_two.cpp +++ b/test/unittest/UTTest_device_manager_impl_two.cpp @@ -2296,6 +2296,54 @@ HWTEST_F(DeviceManagerImplTest, GetNetworkIdByUdid_202, testing::ext::TestSize.L callbackMap[DmCommonNotifyEvent::REG_DEVICE_SCREEN_STATE] = strSet; DeviceManagerImpl::GetInstance().SyncCallbacksToService(callbackMap); } + +HWTEST_F(DeviceManagerImplTest, PutDeviceProfileInfoList_201, testing::ext::TestSize.Level0) +{ + std::string pkgName = "pkgName"; + std::vector deviceProfileInfoList; + std::shared_ptr mockInstance = std::make_shared(); + std::shared_ptr ipcClientProxy = DeviceManagerImpl::GetInstance().ipcClientProxy_; + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) + .Times(1).WillOnce(testing::Return(ERR_DM_IPC_SEND_REQUEST_FAILED)); + int32_t ret = DeviceManager::GetInstance().PutDeviceProfileInfoList(pkgName, deviceProfileInfoList); + ASSERT_EQ(ret, ERR_DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = ipcClientProxy; +} + +HWTEST_F(DeviceManagerImplTest, PutDeviceProfileInfoList_202, testing::ext::TestSize.Level0) +{ + std::string pkgName = "pkgName"; + std::vector deviceProfileInfoList; + std::shared_ptr mockInstance = std::make_shared(); + std::shared_ptr ipcClientProxy = DeviceManagerImpl::GetInstance().ipcClientProxy_; + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) + .Times(1).WillOnce(testing::Return(DM_OK)); + int32_t ret = DeviceManager::GetInstance().PutDeviceProfileInfoList(pkgName, deviceProfileInfoList); + ASSERT_EQ(ret, DM_OK); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = ipcClientProxy; +} + +HWTEST_F(DeviceManagerImplTest, GetLocalDisplayDeviceName_201, testing::ext::TestSize.Level0) +{ + std::string pkgName = "pkgName"; + int32_t maxNameLength = 1; + std::string displayName = "displayName"; + std::shared_ptr mockInstance = std::make_shared(); + std::shared_ptr ipcClientProxy = DeviceManagerImpl::GetInstance().ipcClientProxy_; + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) + .Times(1).WillOnce(testing::Return(ERR_DM_IPC_SEND_REQUEST_FAILED)); + int32_t ret = DeviceManager::GetInstance().GetLocalDisplayDeviceName(pkgName, maxNameLength, displayName); + ASSERT_EQ(ret, ERR_DM_IPC_SEND_REQUEST_FAILED); + + EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) + .Times(1).WillOnce(testing::Return(DM_OK)); + ret = DeviceManager::GetInstance().GetLocalDisplayDeviceName(pkgName, maxNameLength, displayName); + ASSERT_EQ(ret, DM_OK); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = ipcClientProxy; +} } // namespace } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_device_manager_service_two.cpp b/test/unittest/UTTest_device_manager_service_two.cpp index 56e8d168d..7e4fb020f 100644 --- a/test/unittest/UTTest_device_manager_service_two.cpp +++ b/test/unittest/UTTest_device_manager_service_two.cpp @@ -1288,6 +1288,66 @@ HWTEST_F(DeviceManagerServiceTest, GetDeviceIconInfo_202, testing::ext::TestSize int32_t ret = DeviceManagerService::GetInstance().GetDeviceIconInfo(pkgName, filterOptions); EXPECT_EQ(ret, ERR_DM_UNSUPPORTED_METHOD); } + +HWTEST_F(DeviceManagerServiceTest, PutDeviceProfileInfoList_201, testing::ext::TestSize.Level0) +{ + DeletePermission(); + std::string pkgName = "pkgName"; + std::vector deviceProfileInfoList; + int32_t ret = DeviceManagerService::GetInstance().PutDeviceProfileInfoList(pkgName, deviceProfileInfoList); + EXPECT_EQ(ret, ERR_DM_NO_PERMISSION); +} + +HWTEST_F(DeviceManagerServiceTest, PutDeviceProfileInfoList_202, testing::ext::TestSize.Level0) +{ + std::string pkgName = "pkgName"; + std::vector deviceProfileInfoList; + int32_t ret = DeviceManagerService::GetInstance().PutDeviceProfileInfoList(pkgName, deviceProfileInfoList); + EXPECT_EQ(ret, ERR_DM_UNSUPPORTED_METHOD); +} + +HWTEST_F(DeviceManagerServiceTest, SetLocalDisplayNameToSoftbus_201, testing::ext::TestSize.Level0) +{ + std::string displayName = "displayName"; + DeviceManagerService::GetInstance().softbusListener_ = nullptr; + int32_t ret = DeviceManagerService::GetInstance().SetLocalDisplayNameToSoftbus(displayName); + EXPECT_EQ(ret, ERR_DM_POINT_NULL); + + DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); + EXPECT_CALL(*softbusListenerMock_, SetLocalDisplayName(_)).WillOnce(Return(DM_OK)); + ret = DeviceManagerService::GetInstance().SetLocalDisplayNameToSoftbus(displayName); + EXPECT_EQ(ret, DM_OK); + + EXPECT_CALL(*softbusListenerMock_, SetLocalDisplayName(_)).WillOnce(Return(ERR_DM_NO_PERMISSION)); + ret = DeviceManagerService::GetInstance().SetLocalDisplayNameToSoftbus(displayName); + EXPECT_EQ(ret, ERR_DM_NO_PERMISSION); + DeviceManagerService::GetInstance().softbusListener_ = nullptr; +} + +HWTEST_F(DeviceManagerServiceTest, GetLocalDisplayDeviceName_201, testing::ext::TestSize.Level0) +{ + DeletePermission(); + std::string pkgName = "packName"; + int32_t maxNameLength = 1; + std::string displayName = "displayName"; + int32_t ret = DeviceManagerService::GetInstance().GetLocalDisplayDeviceName(pkgName, maxNameLength, displayName); + EXPECT_EQ(ret, ERR_DM_NO_PERMISSION); +} + +HWTEST_F(DeviceManagerServiceTest, GetLocalDisplayDeviceName_202, testing::ext::TestSize.Level0) +{ + std::string pkgName = "packName"; + int32_t maxNameLength = 1; + std::string displayName = "displayName"; + int32_t ret = DeviceManagerService::GetInstance().GetLocalDisplayDeviceName(pkgName, maxNameLength, displayName); + EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); +} + +HWTEST_F(DeviceManagerServiceTest, GetDeviceNamePrefixs_201, testing::ext::TestSize.Level0) +{ + auto ret = DeviceManagerService::GetInstance().GetDeviceNamePrefixs(); + EXPECT_EQ(ret.empty(), true); +} } // namespace } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/mock/dm_crypto_mock.cpp b/test/unittest/mock/dm_crypto_mock.cpp index f6cf4713d..a559c2d01 100644 --- a/test/unittest/mock/dm_crypto_mock.cpp +++ b/test/unittest/mock/dm_crypto_mock.cpp @@ -19,6 +19,8 @@ namespace OHOS { namespace DistributedHardware { + + int32_t Crypto::GetAccountIdHash(const std::string &accountId, unsigned char *accountIdHash) { return DmCrypto::dmCrypto->GetAccountIdHash(accountId, accountIdHash); diff --git a/test/unittest/mock/dm_softbus_cache_mock.cpp b/test/unittest/mock/dm_softbus_cache_mock.cpp index ca401d4f5..322fa9499 100644 --- a/test/unittest/mock/dm_softbus_cache_mock.cpp +++ b/test/unittest/mock/dm_softbus_cache_mock.cpp @@ -54,5 +54,10 @@ int32_t SoftbusCache::GetDeviceInfoFromCache(std::vector &deviceIn { return DmSoftbusCache::dmSoftbusCache->GetDeviceInfoFromCache(deviceInfoList); } + +int32_t SoftbusCache::GetDeviceNameFromCache(const std::string &udid, std::string &deviceName) +{ + return DmSoftbusCache::dmSoftbusCache->GetDeviceNameFromCache(udid, deviceName); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/dm_softbus_cache_mock.h b/test/unittest/mock/dm_softbus_cache_mock.h index adf41876d..1a519e53d 100644 --- a/test/unittest/mock/dm_softbus_cache_mock.h +++ b/test/unittest/mock/dm_softbus_cache_mock.h @@ -33,6 +33,7 @@ public: virtual int32_t GetUuidFromCache(const char *networkId, std::string &uuid) = 0; virtual bool CheckIsOnline(const std::string &deviceId) = 0; virtual int32_t GetDeviceInfoFromCache(std::vector &deviceInfoList) = 0; + virtual int32_t GetDeviceNameFromCache(const std::string &udid, std::string &deviceName) = 0; public: static inline std::shared_ptr dmSoftbusCache = nullptr; }; @@ -46,6 +47,7 @@ public: MOCK_METHOD(int32_t, GetUuidFromCache, (const char *, std::string &)); MOCK_METHOD(bool, CheckIsOnline, (const std::string &)); MOCK_METHOD(int32_t, GetDeviceInfoFromCache, (std::vector &)); + MOCK_METHOD(int32_t, GetDeviceNameFromCache, (const std::string &, std::string &)); }; } } diff --git a/utils/include/appInfo/standard/app_manager.h b/utils/include/appInfo/standard/app_manager.h index 0a56a4d6c..1819c906a 100644 --- a/utils/include/appInfo/standard/app_manager.h +++ b/utils/include/appInfo/standard/app_manager.h @@ -21,6 +21,7 @@ #include #include "bundle_mgr_interface.h" +#include "bundle_mgr_proxy.h" #include "event_handler.h" #include "dm_single_instance.h" -- Gitee