From f571e9023303d311e662772424bd4b1d9f3c297d Mon Sep 17 00:00:00 2001 From: BrainL Date: Tue, 25 Feb 2025 14:59:41 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=9B=91=E5=90=AC=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E4=B8=8A=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: BrainL --- .../include/deviceprofile_connector.h | 8 ++-- .../src/deviceprofile_connector.cpp | 16 +++++++ .../native_cpp/include/dm_device_info.h | 4 ++ .../include/device_manager_service_impl.h | 2 + .../src/device_manager_service_impl.cpp | 47 +++++++++++++++++-- .../service/src/device_manager_service.cpp | 1 + 6 files changed, 72 insertions(+), 6 deletions(-) diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index 664c0ecfe..b27ace8c7 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -31,12 +31,14 @@ constexpr uint32_t ALLOW_AUTH_ALWAYS = 2; constexpr uint32_t INVALIED_TYPE = 0; constexpr uint32_t APP_PEER_TO_PEER_TYPE = 1; constexpr uint32_t APP_ACROSS_ACCOUNT_TYPE = 2; -constexpr uint32_t DEVICE_PEER_TO_PEER_TYPE = 3; -constexpr uint32_t DEVICE_ACROSS_ACCOUNT_TYPE = 4; -constexpr uint32_t IDENTICAL_ACCOUNT_TYPE = 5; +constexpr uint32_t SHARE_TYPE = 3; +constexpr uint32_t DEVICE_PEER_TO_PEER_TYPE = 4; +constexpr uint32_t DEVICE_ACROSS_ACCOUNT_TYPE = 5; +constexpr uint32_t IDENTICAL_ACCOUNT_TYPE = 6; constexpr uint32_t DM_IDENTICAL_ACCOUNT = 1; constexpr uint32_t DM_POINT_TO_POINT = 256; +constexpr uint32_t DM_SHARE_TYPE = 512; constexpr uint32_t DM_ACROSS_ACCOUNT = 1282; constexpr uint32_t DM_INVALIED_BINDTYPE = 2048; constexpr uint32_t DEVICE = 1; diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 9dfe1985a..2dd270c92 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -100,6 +100,12 @@ std::unordered_map DeviceProfileConnector::GetAppTrustD continue; } if (deviceIdMap.find(trustDeviceId) == deviceIdMap.end()) { + if ((item.GetAccessee().GetAccesseeUserId() == userId || + item.GetAccessee().GetAccesseeUserId() == 0 || + item.GetAccessee().GetAccesseeUserId() == -1) && + item.GetAccessee().GetAccesseeDeviceId() == deviceId && bindType == DmAuthForm::SHARE_TYPE) { + continue; + } deviceIdMap[trustDeviceId] = static_cast(bindType); continue; } @@ -111,6 +117,10 @@ std::unordered_map DeviceProfileConnector::GetAppTrustD deviceIdMap[trustDeviceId] = DmAuthForm::IDENTICAL_ACCOUNT; continue; } + if (bindType == DmAuthForm::SHARE_TYPE) { + deviceIdMap[trustDeviceId] = DmAuthForm::SHARE_TYPE; + continue; + } if (bindType == DmAuthForm::PEER_TO_PEER && authForm == DmAuthForm::ACROSS_ACCOUNT) { deviceIdMap[trustDeviceId] = DmAuthForm::PEER_TO_PEER; continue; @@ -194,6 +204,9 @@ int32_t DeviceProfileConnector::HandleDmAuthForm(AccessControlProfile profiles, if (profiles.GetBindType() == DM_ACROSS_ACCOUNT) { return CheckAuthForm(DmAuthForm::ACROSS_ACCOUNT, profiles, discoveryInfo); } + if (profiles.GetBindType() == DM_SHARE_TYPE) { + return CheckAuthForm(DmAuthForm::DM_SHARE_TYPE, profiles, discoveryInfo); + } return DmAuthForm::INVALID_TYPE; } @@ -226,6 +239,9 @@ int32_t DeviceProfileConnector::GetAuthForm(DistributedDeviceProfile::AccessCont case DM_IDENTICAL_ACCOUNT: priority = IDENTICAL_ACCOUNT_TYPE; break; + case DM_SHARE_TYPE: + priority = SHARE_TYPE; + break; case DM_POINT_TO_POINT: if (profiles.GetBindLevel() == DEVICE) { priority = DEVICE_PEER_TO_PEER_TYPE; 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 b98d58895..5e14766f8 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -146,6 +146,10 @@ typedef enum DmAuthForm { * Across Account Device auth. */ ACROSS_ACCOUNT = 2, + /** + * Share Device Type. + */ + SHARE_TYPE = 3, } DmAuthForm; /** diff --git a/services/implementation/include/device_manager_service_impl.h b/services/implementation/include/device_manager_service_impl.h index 55e5426b0..95b6521e9 100644 --- a/services/implementation/include/device_manager_service_impl.h +++ b/services/implementation/include/device_manager_service_impl.h @@ -140,6 +140,8 @@ public: private: int32_t PraseNotifyEventJson(const std::string &event, nlohmann::json &jsonObject); std::string GetUdidHashByNetworkId(const std::string &networkId); + bool SetDevInfoByBindType(uint32_t bindType, ProcessInfo &processInfo, DmDeviceInfo &devInfo, + const std::string &requestDeviceId, const std::string &trustDeviceId); void HandleOffline(DmDeviceState devState, DmDeviceInfo &devInfo); void HandleOnline(DmDeviceState devState, DmDeviceInfo &devInfo); void PutIdenticalAccountToAcl(std::string requestDeviceId, std::string trustDeviceId); diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 0a0898740..91bdc78ff 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -231,7 +231,21 @@ void DeviceManagerServiceImpl::HandleOnline(DmDeviceState devState, DmDeviceInfo devInfo.authForm = DmAuthForm::IDENTICAL_ACCOUNT; isCredentialType_.store(false); softbusConnector_->SetProcessInfo(processInfo); - } else if (bindType == IDENTICAL_ACCOUNT_TYPE) { + } + bool ret = SetDevInfoByBindType(bindType, processInfo, devInfo, requestDeviceId, trustDeviceId); + if (ret) { + LOGI("DeviceManagerServiceImpl::HandleOnline success devInfo authForm is %{public}d.", devInfo.authForm); + deviceStateMgr_->HandleDeviceStatusChange(devState, devInfo); + } else { + LOGI("DeviceManagerServiceImpl::HandleOnline share type, local is sink."); + } +} + +bool DeviceManagerServiceImpl::SetDevInfoByBindType(uint32_t bindType, ProcessInfo &processInfo, DmDeviceInfo &devInfo, + const std::string &requestDeviceId, const std::string &trustDeviceId) +{ + bool ret = true; + if (bindType == IDENTICAL_ACCOUNT_TYPE) { devInfo.authForm = DmAuthForm::IDENTICAL_ACCOUNT; softbusConnector_->SetProcessInfo(processInfo); } else if (bindType == DEVICE_PEER_TO_PEER_TYPE) { @@ -252,9 +266,36 @@ void DeviceManagerServiceImpl::HandleOnline(DmDeviceState devState, DmDeviceInfo MultipleUserConnector::GetFirstForegroundUserId()); softbusConnector_->SetProcessInfoVec(processInfoVec); devInfo.authForm = DmAuthForm::ACROSS_ACCOUNT; + } else if (bindType == SHARE_TYPE) { + std::vector profiles = + DeviceProfileConnector::GetInstance().GetAccessControlProfile(); + std::string peerUdid = ""; + int32_t retUdid = softbusConnector_->GetUdidByNetworkId(devInfo.networkId, peerUdid); + bool peerIsSrc = false; + if (retUdid != DM_OK) { + LOGE("CheckShareTypeAccess fail to get udid by networkId."); + return false; + } + for (auto &aclItem : profiles) { + if (aclItem.GetBindType() == DM_SHARE_TYPE && aclItem.GetTrustDeviceId() == peerUdid) { + if (aclItem.GetAccesser().GetAccesserDeviceId() == peerUdid) { + peerIsSrc = true; + break; + } else { + peerIsSrc = false; + break; + } + } + } + if (peerIsSrc) { + LOGI("ProcessDeviceStateChange authForm is share, peer is src."); + ret = false; + return ret; + } + devInfo.authForm = DmAuthForm::SHARE_TYPE; + softbusConnector_->SetProcessInfo(processInfo); } - LOGI("DeviceManagerServiceImpl::HandleOnline success devInfo auform %{public}d.", devInfo.authForm); - deviceStateMgr_->HandleDeviceStatusChange(devState, devInfo); + return ret; } void DeviceManagerServiceImpl::HandleDeviceStatusChange(DmDeviceState devState, DmDeviceInfo &devInfo) diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index e60267060..247418b0d 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -78,6 +78,7 @@ namespace { constexpr const char *NETWORKID = "NETWORK_ID"; constexpr uint32_t INVALIED_BIND_LEVEL = 0; constexpr uint32_t DM_IDENTICAL_ACCOUNT = 1; + constexpr uint32_t DM_SHARE_TYPE = 512; const std::string USERID_CHECKSUM_NETWORKID_KEY = "networkId"; const std::string USERID_CHECKSUM_DISCOVER_TYPE_KEY = "discoverType"; constexpr uint32_t USERID_CHECKSUM_DISCOVERY_TYPE_WIFI_MASK = 0b0010; -- Gitee From 0077c82721819257065a29bb3eca7003a942e34b Mon Sep 17 00:00:00 2001 From: BrainL Date: Tue, 25 Feb 2025 16:44:37 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A4=8D=E6=9D=82=E5=88=86=E6=94=AF?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: BrainL --- .../include/deviceprofile_connector.h | 2 ++ .../src/deviceprofile_connector.cpp | 27 ++++++++++++------ .../include/device_manager_service_impl.h | 2 ++ .../src/device_manager_service_impl.cpp | 28 +++++++++++-------- 4 files changed, 39 insertions(+), 20 deletions(-) diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index b27ace8c7..43ecf6c84 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -195,6 +195,8 @@ private: uint32_t index, std::string targetDeviceId); bool CheckAppLevelAccess(const DistributedDeviceProfile::AccessControlProfile &profile, const DmAccessCaller &caller, const DmAccessCallee &callee); + bool CheckSinkShareType(DistributedDeviceProfile::AccessControlProfile profile, + const int32_t &userId, const std::string &deviceId, const int32_t &bindType); 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 2dd270c92..60241579c 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -100,10 +100,7 @@ std::unordered_map DeviceProfileConnector::GetAppTrustD continue; } if (deviceIdMap.find(trustDeviceId) == deviceIdMap.end()) { - if ((item.GetAccessee().GetAccesseeUserId() == userId || - item.GetAccessee().GetAccesseeUserId() == 0 || - item.GetAccessee().GetAccesseeUserId() == -1) && - item.GetAccessee().GetAccesseeDeviceId() == deviceId && bindType == DmAuthForm::SHARE_TYPE) { + if (CheckSinkShareType(item, userId, deviceId, bindType)) { continue; } deviceIdMap[trustDeviceId] = static_cast(bindType); @@ -129,6 +126,18 @@ std::unordered_map DeviceProfileConnector::GetAppTrustD return deviceIdMap; } +bool DeviceProfileConnector::CheckSinkShareType(DistributedDeviceProfile::AccessControlProfile profile, + const int32_t &userId, const std::string &deviceId, const int32_t &bindType) +{ + if ((profile.GetAccessee().GetAccesseeUserId() == userId || + profile.GetAccessee().GetAccesseeUserId() == 0 || + profile.GetAccessee().GetAccesseeUserId() == -1) && + profile.GetAccessee().GetAccesseeDeviceId() == deviceId && bindType == DmAuthForm::SHARE_TYPE) { + return true; + } + return false; +} + int32_t DeviceProfileConnector::GetDeviceAclParam(DmDiscoveryInfo discoveryInfo, bool &isOnline, int32_t &authForm) { std::vector profiles = GetAccessControlProfileByUserId(discoveryInfo.userId); @@ -205,7 +214,7 @@ int32_t DeviceProfileConnector::HandleDmAuthForm(AccessControlProfile profiles, return CheckAuthForm(DmAuthForm::ACROSS_ACCOUNT, profiles, discoveryInfo); } if (profiles.GetBindType() == DM_SHARE_TYPE) { - return CheckAuthForm(DmAuthForm::DM_SHARE_TYPE, profiles, discoveryInfo); + return CheckAuthForm(DmAuthForm::SHARE_TYPE, profiles, discoveryInfo); } return DmAuthForm::INVALID_TYPE; } @@ -1047,10 +1056,10 @@ bool DeviceProfileConnector::CheckAppLevelAccess(const DistributedDeviceProfile: 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)) { + if ((profile.GetAccesser().GetAccesserTokenId() == static_cast(caller.tokenId) && + profile.GetAccessee().GetAccesseeTokenId() == static_cast(callee.tokenId)) || + (profile.GetAccessee().GetAccesseeTokenId() == static_cast(caller.tokenId) && + profile.GetAccesser().GetAccesserTokenId() == static_cast(callee.tokenId))) { return true; } else { return false; diff --git a/services/implementation/include/device_manager_service_impl.h b/services/implementation/include/device_manager_service_impl.h index 95b6521e9..ce7ae1b54 100644 --- a/services/implementation/include/device_manager_service_impl.h +++ b/services/implementation/include/device_manager_service_impl.h @@ -144,6 +144,8 @@ private: const std::string &requestDeviceId, const std::string &trustDeviceId); void HandleOffline(DmDeviceState devState, DmDeviceInfo &devInfo); void HandleOnline(DmDeviceState devState, DmDeviceInfo &devInfo); + void CheckSharePeerSrc(std::vector profiles, + const std::string &peerUdid, bool &peerIsSrc); void PutIdenticalAccountToAcl(std::string requestDeviceId, std::string trustDeviceId); std::map GetDeviceIdAndBindLevel(int32_t userId); std::multimap GetDeviceIdAndUserId(int32_t userId, const std::string &accountId); diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 91bdc78ff..bb654ad73 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -276,17 +276,7 @@ bool DeviceManagerServiceImpl::SetDevInfoByBindType(uint32_t bindType, ProcessIn LOGE("CheckShareTypeAccess fail to get udid by networkId."); return false; } - for (auto &aclItem : profiles) { - if (aclItem.GetBindType() == DM_SHARE_TYPE && aclItem.GetTrustDeviceId() == peerUdid) { - if (aclItem.GetAccesser().GetAccesserDeviceId() == peerUdid) { - peerIsSrc = true; - break; - } else { - peerIsSrc = false; - break; - } - } - } + CheckSharePeerSrc(profiles, peerUdid, peerIsSrc); if (peerIsSrc) { LOGI("ProcessDeviceStateChange authForm is share, peer is src."); ret = false; @@ -298,6 +288,22 @@ bool DeviceManagerServiceImpl::SetDevInfoByBindType(uint32_t bindType, ProcessIn return ret; } +void DeviceManagerServiceImpl::CheckSharePeerSrc(std::vector profiles, + const std::string &peerUdid, bool &peerIsSrc) +{ + for (auto &aclItem : profiles) { + if (aclItem.GetBindType() == DM_SHARE_TYPE && aclItem.GetTrustDeviceId() == peerUdid) { + if (aclItem.GetAccesser().GetAccesserDeviceId() == peerUdid) { + peerIsSrc = true; + break; + } else { + peerIsSrc = false; + break; + } + } + } +} + void DeviceManagerServiceImpl::HandleDeviceStatusChange(DmDeviceState devState, DmDeviceInfo &devInfo) { if (deviceStateMgr_ == nullptr) { -- Gitee