diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index 664c0ecfee1438783d3b532ccda07d07a1bd9f65..43ecf6c842d58a0cc446035097df72b027cf7455 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; @@ -193,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 9dfe1985a42b85a24f4f9a2ca8fed14900958909..60241579c5653338b68c989e772563796677c930 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -100,6 +100,9 @@ std::unordered_map DeviceProfileConnector::GetAppTrustD continue; } if (deviceIdMap.find(trustDeviceId) == deviceIdMap.end()) { + if (CheckSinkShareType(item, userId, deviceId, bindType)) { + continue; + } deviceIdMap[trustDeviceId] = static_cast(bindType); continue; } @@ -111,6 +114,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; @@ -119,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); @@ -194,6 +213,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::SHARE_TYPE, profiles, discoveryInfo); + } return DmAuthForm::INVALID_TYPE; } @@ -226,6 +248,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; @@ -1031,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/interfaces/inner_kits/native_cpp/include/dm_device_info.h b/interfaces/inner_kits/native_cpp/include/dm_device_info.h index b98d588955456e1d9e538f8635dbde31194703f7..5e14766f8271bfbe94d27d945b2647fd6f44d1c0 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 55e5426b0d74072de0d67f6315933cb9d90d7d05..ce7ae1b5486af258c9ad3942e43124597cf925d5 100644 --- a/services/implementation/include/device_manager_service_impl.h +++ b/services/implementation/include/device_manager_service_impl.h @@ -140,8 +140,12 @@ 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 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 0a089874030f3d134a592cd6ecad5d7c2e49813a..bb654ad73ae19415fb736dca5c91b9cf298215a5 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,42 @@ 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; + } + CheckSharePeerSrc(profiles, peerUdid, peerIsSrc); + if (peerIsSrc) { + LOGI("ProcessDeviceStateChange authForm is share, peer is src."); + ret = false; + return ret; + } + devInfo.authForm = DmAuthForm::SHARE_TYPE; + softbusConnector_->SetProcessInfo(processInfo); + } + 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; + } + } } - LOGI("DeviceManagerServiceImpl::HandleOnline success devInfo auform %{public}d.", devInfo.authForm); - deviceStateMgr_->HandleDeviceStatusChange(devState, devInfo); } 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 e6026706056bdd0c36f44e0f0f72b5c08a621cb6..247418b0d7aabd1d70006b35e5ae0667b62fb870 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;