From 6995ad152071a753f2bb6e859f1846483a707a68 Mon Sep 17 00:00:00 2001 From: BrainL Date: Thu, 27 Feb 2025 11:06:23 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=88=86=E4=BA=AB=E7=9B=91=E5=90=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: BrainL --- .../include/deviceprofile_connector.h | 10 +- .../src/deviceprofile_connector.cpp | 33 +++++- .../native_cpp/include/dm_device_info.h | 4 + .../include/device_manager_service_impl.h | 6 ++ .../device_manager_service_impl_lite.h | 1 + .../src/device_manager_service_impl.cpp | 100 +++++++++++++++++- .../src/device_manager_service_impl_lite.cpp | 8 ++ .../service/include/device_manager_service.h | 1 + .../include/idevice_manager_service_impl.h | 1 + .../service/src/device_manager_service.cpp | 17 +++ 10 files changed, 171 insertions(+), 10 deletions(-) diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index 664c0ecfe..43ecf6c84 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 9dfe1985a..60241579c 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 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..ed7863d63 100644 --- a/services/implementation/include/device_manager_service_impl.h +++ b/services/implementation/include/device_manager_service_impl.h @@ -134,14 +134,19 @@ public: void HandleDeviceUnBind(int32_t bindType, const std::string &peerUdid, const std::string &localUdid, int32_t localUserId, const std::string &localAccountId); int32_t RegisterAuthenticationType(int32_t authenticationType); + void HandleCredentialDeleted(const char *credId, const char *credInfo, const std::string &localUdid); void DeleteAlwaysAllowTimeOut(); void CheckDeleteCredential(const std::string &remoteUdid); int32_t CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId); 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); @@ -168,6 +173,7 @@ private: std::shared_ptr listener_; std::atomic isCredentialType_ = false; sptr dpInitedCallback_ = nullptr; + std::vector deletedShareProfiles_; }; using CreateDMServiceFuncPtr = IDeviceManagerServiceImpl *(*)(void); diff --git a/services/implementation/include/device_manager_service_impl_lite.h b/services/implementation/include/device_manager_service_impl_lite.h index 6d05f91e9..63e9c8bcf 100644 --- a/services/implementation/include/device_manager_service_impl_lite.h +++ b/services/implementation/include/device_manager_service_impl_lite.h @@ -156,6 +156,7 @@ public: void HandleDeviceUnBind(int32_t bindType, const std::string &peerUdid, const std::string &localUdid, int32_t localUserId, const std::string &localAccountId); int32_t RegisterAuthenticationType(int32_t authenticationType); + void HandleCredentialDeleted(const char *credId, const char *credInfo, const std::string &localUdid); void DeleteAlwaysAllowTimeOut(); void CheckDeleteCredential(const std::string &remoteUdid); int32_t CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId); diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 0a0898740..97e445de3 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -191,7 +191,19 @@ void DeviceManagerServiceImpl::HandleOffline(DmDeviceState devState, DmDeviceInf softbusConnector_->SetProcessInfo(processInfo); } else if (item.second == DEVICE) { LOGI("The offline device is device bind type."); - devInfo.authForm = DmAuthForm::PEER_TO_PEER; + uint32_t bindType = DeviceProfileConnector::GetInstance().CheckBindType(trustDeviceId, requestDeviceId); + if (bindType == SHARE_TYPE) { + bool peerIsSrc = false; + CheckSharePeerSrc(deletedShareProfiles_, trustDeviceId, peerIsSrc); + if (peerIsSrc) { + LOGI("HandleOffline bindType is share type, peer is src."); + return; + } else { + devInfo.authForm = DmAuthForm::SHARE_TYPE; + } + } else { + devInfo.authForm = DmAuthForm::PEER_TO_PEER; + } processInfo.userId = item.first; softbusConnector_->SetProcessInfo(processInfo); } else if (item.second == SERVICE || item.second == APP) { @@ -226,6 +238,19 @@ void DeviceManagerServiceImpl::HandleOnline(DmDeviceState devState, DmDeviceInfo ProcessInfo processInfo; processInfo.pkgName = std::string(DM_PKG_NAME); processInfo.userId = MultipleUserConnector::GetFirstForegroundUserId(); + 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 == INVALIED_TYPE && isCredentialType_.load()) { PutIdenticalAccountToAcl(requestDeviceId, trustDeviceId); devInfo.authForm = DmAuthForm::IDENTICAL_ACCOUNT; @@ -252,9 +277,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("CheckShareType 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) @@ -1044,6 +1102,42 @@ void DeviceManagerServiceImpl::DeleteAlwaysAllowTimeOut() } } +void DeviceManagerServiceImpl::HandleCredentialDeleted(const char *credId, const char *credInfo, const std::string &localUdid) +{ + std::vector profiles = + DeviceProfileConnector::GetInstance().GetAccessControlProfile(); + nlohmann::json jsonObject = nlohmann::json::parse(std::string(credInfo), nullptr, false); + if (jsonObject.is_discarded()) { + LOGE("HandleCredentialDeleted prase error."); + return; + } + std::string deviceIdTag = "deviceId"; + std::string userIdTag = "userId"; + std::string remoteUdid = ""; + int32_t userId = 0; + if (IsString(jsonObject, deviceIdTag)) { + remoteUdid = jsonObject[deviceIdTag].get(); + } + if (IsInt32(jsonObject, userIdTag)) { + userId = jsonObject[userIdTag].get(); + } + for (const auto &item : profiles) { + if ((item.GetAccesser().GetAccesserCredentialId() == credId && + item.GetAccesser().GetAccesserDeviceId() == localUdid && + item.GetAccesser().GetAccesserUserId() == userId && + item.GetAccessee().GetAccesseeDeviceId() == remoteUdid) || + (item.GetAccessee().GetAccesseeCredentialId() == credId && + item.GetAccessee().GetAccesseeDeviceId() == localUdid && + item.GetAccessee().GetAccesseeUserId() == userId && + item.GetAccesser().GetAccesserDeviceId() == remoteUdid)) { + if (item.GetBindType() == DM_SHARE_TYPE) { + deletedShareProfiles_.push_back(item); + } + DeviceProfileConnector::GetInstance().DeleteAccessControlById(item.GetAccessControlId()); + } + } +} + void DeviceManagerServiceImpl::CheckDeleteCredential(const std::string &remoteUdid) { std::vector profiles = diff --git a/services/implementation/src/device_manager_service_impl_lite.cpp b/services/implementation/src/device_manager_service_impl_lite.cpp index 07abe0cde..cd4652e97 100644 --- a/services/implementation/src/device_manager_service_impl_lite.cpp +++ b/services/implementation/src/device_manager_service_impl_lite.cpp @@ -598,6 +598,14 @@ void DeviceManagerServiceImpl::DeleteAlwaysAllowTimeOut() return; } +void DeviceManagerServiceImpl::HandleCredentialDeleted(const char *credId, const char *credInfo, const std::string &localUdid) +{ + (void)credId; + (void)credInfo; + (void)localUdid; + return; +} + void DeviceManagerServiceImpl::CheckDeleteCredential(const std::string &remoteUdid) { (void)remoteUdid; diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index b4ad67f6a..491fb45be 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -194,6 +194,7 @@ public: bool CheckAccessControl(const DmAccessCaller &caller, const DmAccessCallee &callee); bool CheckIsSameAccount(const DmAccessCaller &caller, const DmAccessCallee &callee); void HandleDeviceNotTrust(const std::string &msg); + void HandleCredentialDeleted(const char *credId, const char *credInfo); #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) void HandleDeviceTrustedChange(const std::string &msg); void HandleUserIdCheckSumChange(const std::string &msg); diff --git a/services/service/include/idevice_manager_service_impl.h b/services/service/include/idevice_manager_service_impl.h index 7df04af0a..400bbb291 100644 --- a/services/service/include/idevice_manager_service_impl.h +++ b/services/service/include/idevice_manager_service_impl.h @@ -257,6 +257,7 @@ public: virtual void HandleDeviceUnBind(int32_t bindType, const std::string &peerUdid, const std::string &localUdid, int32_t localUserId, const std::string &localAccountId) = 0; virtual int32_t RegisterAuthenticationType(int32_t authenticationType) = 0; + virtual void HandleCredentialDeleted(const char *credId, const char *credInfo, const std::string &localUdid) = 0; virtual void DeleteAlwaysAllowTimeOut() = 0; virtual void CheckDeleteCredential(const std::string &remoteUdid) = 0; virtual int32_t CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId) = 0; diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index e60267060..ded19eb80 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; @@ -2209,6 +2210,22 @@ void DeviceManagerService::HandleDeviceNotTrust(const std::string &msg) return; } +void DeviceManagerService::HandleCredentialDeleted(const char *credId, const char *credInfo) +{ + LOGI("HandleCredentialDeleted start."); + if (credId == nullptr || credInfo == nullptr) { + LOGE("HandleCredentialDeleted failed, credId or credInfo is null."); + return; + } + char localUdidTemp[DEVICE_UUID_LENGTH] = {0}; + GetDevUdid(localUdidTemp, DEVICE_UUID_LENGTH); + std::string localUdid = std::string(localUdidTemp); + if (IsDMServiceImplReady()) { + dmServiceImpl_->HandleCredentialDeleted(credId, credInfo, localUdid); + } + return; +} + int32_t DeviceManagerService::SetDnPolicy(const std::string &pkgName, std::map &policy) { if (!PermissionManager::GetInstance().CheckPermission()) { -- Gitee From 52fbc25fa3371225dd06bdb42638fa85fdd3a4bd Mon Sep 17 00:00:00 2001 From: BrainL Date: Mon, 3 Mar 2025 14:16:01 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E7=9B=91=E5=90=AC=E5=88=86=E4=BA=AB?= =?UTF-8?q?=E4=B8=8A=E4=B8=8B=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: BrainL --- commondependency/include/deviceprofile_connector.h | 2 ++ commondependency/src/deviceprofile_connector.cpp | 8 +++++--- .../implementation/src/device_manager_service_impl.cpp | 7 ++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index 30869a252..64795a1c8 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -33,12 +33,14 @@ enum AllowAuthType { extern const uint32_t INVALIED_TYPE; extern const uint32_t APP_PEER_TO_PEER_TYPE; extern const uint32_t APP_ACROSS_ACCOUNT_TYPE; +extern const uint32_t SHARE_TYPE; extern const uint32_t DEVICE_PEER_TO_PEER_TYPE; extern const uint32_t DEVICE_ACROSS_ACCOUNT_TYPE; extern const uint32_t IDENTICAL_ACCOUNT_TYPE; extern const uint32_t DM_IDENTICAL_ACCOUNT; extern const uint32_t DM_POINT_TO_POINT; +extern const uint32_t DM_SHARE_TYPE; extern const uint32_t DM_ACROSS_ACCOUNT; extern const uint32_t DM_INVALIED_BINDTYPE; extern const uint32_t DEVICE; diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 3e8ce24f8..ab3569c1b 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -28,12 +28,14 @@ using namespace OHOS::DistributedDeviceProfile; const uint32_t INVALIED_TYPE = 0; const uint32_t APP_PEER_TO_PEER_TYPE = 1; const uint32_t APP_ACROSS_ACCOUNT_TYPE = 2; -const uint32_t DEVICE_PEER_TO_PEER_TYPE = 3; -const uint32_t DEVICE_ACROSS_ACCOUNT_TYPE = 4; -const uint32_t IDENTICAL_ACCOUNT_TYPE = 5; +const uint32_t SHARE_TYPE = 3; +const uint32_t DEVICE_PEER_TO_PEER_TYPE = 4; +const uint32_t DEVICE_ACROSS_ACCOUNT_TYPE = 5; +const uint32_t IDENTICAL_ACCOUNT_TYPE = 6; const uint32_t DM_IDENTICAL_ACCOUNT = 1; const uint32_t DM_POINT_TO_POINT = 256; +const uint32_t DM_SHARE_TYPE = 512; const uint32_t DM_ACROSS_ACCOUNT = 1282; const uint32_t DM_INVALIED_BINDTYPE = 2048; const uint32_t DEVICE = 1; diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 34ca0d0df..cd223e1c3 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -1105,7 +1105,8 @@ void DeviceManagerServiceImpl::DeleteAlwaysAllowTimeOut() } } -void DeviceManagerServiceImpl::HandleCredentialDeleted(const char *credId, const char *credInfo, const std::string &localUdid) +void DeviceManagerServiceImpl::HandleCredentialDeleted(const char *credId, + const char *credInfo, const std::string &localUdid) { std::vector profiles = DeviceProfileConnector::GetInstance().GetAccessControlProfile(); @@ -1125,11 +1126,11 @@ void DeviceManagerServiceImpl::HandleCredentialDeleted(const char *credId, const userId = jsonObject[userIdTag].get(); } for (const auto &item : profiles) { - if ((item.GetAccesser().GetAccesserCredentialId() == credId && + if ((item.GetAccesser().GetAccesserCredentialId() == atoi(credId) && item.GetAccesser().GetAccesserDeviceId() == localUdid && item.GetAccesser().GetAccesserUserId() == userId && item.GetAccessee().GetAccesseeDeviceId() == remoteUdid) || - (item.GetAccessee().GetAccesseeCredentialId() == credId && + (item.GetAccessee().GetAccesseeCredentialId() == atoi(credId) && item.GetAccessee().GetAccesseeDeviceId() == localUdid && item.GetAccessee().GetAccesseeUserId() == userId && item.GetAccesser().GetAccesserDeviceId() == remoteUdid)) { -- Gitee From 70d1e07e8edd27dade8362382f64082b07792625 Mon Sep 17 00:00:00 2001 From: BrainL Date: Mon, 3 Mar 2025 14:19:46 +0800 Subject: [PATCH 3/5] update format Signed-off-by: BrainL --- .../implementation/src/device_manager_service_impl_lite.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/implementation/src/device_manager_service_impl_lite.cpp b/services/implementation/src/device_manager_service_impl_lite.cpp index 01f066b39..db418bc54 100644 --- a/services/implementation/src/device_manager_service_impl_lite.cpp +++ b/services/implementation/src/device_manager_service_impl_lite.cpp @@ -598,7 +598,8 @@ void DeviceManagerServiceImpl::DeleteAlwaysAllowTimeOut() return; } -void DeviceManagerServiceImpl::HandleCredentialDeleted(const char *credId, const char *credInfo, const std::string &localUdid) +void DeviceManagerServiceImpl::HandleCredentialDeleted(const char *credId, + const char *credInfo, const std::string &localUdid) { (void)credId; (void)credInfo; -- Gitee From 671572562f1a59509e85ae0ba06462129554a9f1 Mon Sep 17 00:00:00 2001 From: BrainL Date: Mon, 3 Mar 2025 14:19:46 +0800 Subject: [PATCH 4/5] update format Signed-off-by: BrainL --- .../include/device_manager_service_impl.h | 2 ++ .../src/device_manager_service_impl.cpp | 34 +++++++++++-------- .../src/device_manager_service_impl_lite.cpp | 3 +- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/services/implementation/include/device_manager_service_impl.h b/services/implementation/include/device_manager_service_impl.h index ed7863d63..2348635de 100644 --- a/services/implementation/include/device_manager_service_impl.h +++ b/services/implementation/include/device_manager_service_impl.h @@ -143,6 +143,8 @@ private: 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 GetDeviceLevelAuthForm(const std::string &trustDeviceId, + const std::string &requestDeviceId, DmDeviceInfo &devInfo); void HandleOffline(DmDeviceState devState, DmDeviceInfo &devInfo); void HandleOnline(DmDeviceState devState, DmDeviceInfo &devInfo); void CheckSharePeerSrc(std::vector profiles, diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index cd223e1c3..2abca25c4 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -194,19 +194,7 @@ void DeviceManagerServiceImpl::HandleOffline(DmDeviceState devState, DmDeviceInf softbusConnector_->SetProcessInfo(processInfo); } else if (item.second == DEVICE) { LOGI("The offline device is device bind type."); - uint32_t bindType = DeviceProfileConnector::GetInstance().CheckBindType(trustDeviceId, requestDeviceId); - if (bindType == SHARE_TYPE) { - bool peerIsSrc = false; - CheckSharePeerSrc(deletedShareProfiles_, trustDeviceId, peerIsSrc); - if (peerIsSrc) { - LOGI("HandleOffline bindType is share type, peer is src."); - return; - } else { - devInfo.authForm = DmAuthForm::SHARE_TYPE; - } - } else { - devInfo.authForm = DmAuthForm::PEER_TO_PEER; - } + GetDeviceLevelAuthForm(trustDeviceId, requestDeviceId, devInfo); processInfo.userId = item.first; softbusConnector_->SetProcessInfo(processInfo); } else if (item.second == SERVICE || item.second == APP) { @@ -220,6 +208,24 @@ void DeviceManagerServiceImpl::HandleOffline(DmDeviceState devState, DmDeviceInf } } +void DeviceManagerServiceImpl::GetDeviceLevelAuthForm(const std::string &trustDeviceId, + const std::string &requestDeviceId, DmDeviceInfo &devInfo) +{ + uint32_t bindType = DeviceProfileConnector::GetInstance().CheckBindType(trustDeviceId, requestDeviceId); + if (bindType == SHARE_TYPE) { + bool peerIsSrc = false; + CheckSharePeerSrc(deletedShareProfiles_, trustDeviceId, peerIsSrc); + if (peerIsSrc) { + LOGI("HandleOffline bindType is share type, peer is src."); + return; + } else { + devInfo.authForm = DmAuthForm::SHARE_TYPE; + } + } else { + devInfo.authForm = DmAuthForm::PEER_TO_PEER; + } +} + void DeviceManagerServiceImpl::HandleOnline(DmDeviceState devState, DmDeviceInfo &devInfo) { LOGI("DeviceManagerServiceImpl::HandleOnline"); @@ -1134,7 +1140,7 @@ void DeviceManagerServiceImpl::HandleCredentialDeleted(const char *credId, item.GetAccessee().GetAccesseeDeviceId() == localUdid && item.GetAccessee().GetAccesseeUserId() == userId && item.GetAccesser().GetAccesserDeviceId() == remoteUdid)) { - if (item.GetBindType() == DM_SHARE_TYPE) { + if (item.GetBindType() == DM_SHARE_TYPE) { deletedShareProfiles_.push_back(item); } DeviceProfileConnector::GetInstance().DeleteAccessControlById(item.GetAccessControlId()); diff --git a/services/implementation/src/device_manager_service_impl_lite.cpp b/services/implementation/src/device_manager_service_impl_lite.cpp index 01f066b39..db418bc54 100644 --- a/services/implementation/src/device_manager_service_impl_lite.cpp +++ b/services/implementation/src/device_manager_service_impl_lite.cpp @@ -598,7 +598,8 @@ void DeviceManagerServiceImpl::DeleteAlwaysAllowTimeOut() return; } -void DeviceManagerServiceImpl::HandleCredentialDeleted(const char *credId, const char *credInfo, const std::string &localUdid) +void DeviceManagerServiceImpl::HandleCredentialDeleted(const char *credId, + const char *credInfo, const std::string &localUdid) { (void)credId; (void)credInfo; -- Gitee From 65b0a0a0b6c0d8f57bda8a31b68088ab144530fa Mon Sep 17 00:00:00 2001 From: BrainL Date: Mon, 3 Mar 2025 15:41:27 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=88=86=E4=BA=AB?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: BrainL --- commondependency/include/deviceprofile_connector.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index 64795a1c8..de95b5428 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -199,6 +199,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, -- Gitee