From 7f42b7fac427c969e07c8c6f26a065351d7667b2 Mon Sep 17 00:00:00 2001 From: BrainL Date: Wed, 9 Apr 2025 15:05:14 +0800 Subject: [PATCH 01/13] add share Signed-off-by: BrainL --- .../include/deviceprofile_connector.h | 6 + .../src/deviceprofile_connector.cpp | 47 +++++- .../include/device_manager_service_impl.h | 9 + .../device_manager_service_impl_lite.h | 3 + .../src/device_manager_service_impl.cpp | 154 +++++++++++++++++- .../src/device_manager_service_impl_lite.cpp | 19 +++ .../service/include/device_manager_service.h | 4 + .../include/hichain/hichain_listener.h | 3 + .../include/idevice_manager_service_impl.h | 4 + .../relationship_sync_mgr.h | 6 +- .../service/src/device_manager_service.cpp | 63 +++++++ .../service/src/hichain/hichain_listener.cpp | 39 +++++ .../relationship_sync_mgr.cpp | 58 ++++++- test/unittest/mock/device_auth.h | 23 +++ 14 files changed, 428 insertions(+), 10 deletions(-) diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index f0f697595..7b8a016e7 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -33,12 +33,14 @@ enum AllowAuthType { EXPORT extern const uint32_t INVALIED_TYPE; EXPORT extern const uint32_t APP_PEER_TO_PEER_TYPE; EXPORT extern const uint32_t APP_ACROSS_ACCOUNT_TYPE; +EXPORT extern const uint32_t SHARE_TYPE; EXPORT extern const uint32_t DEVICE_PEER_TO_PEER_TYPE; EXPORT extern const uint32_t DEVICE_ACROSS_ACCOUNT_TYPE; EXPORT extern const uint32_t IDENTICAL_ACCOUNT_TYPE; EXPORT extern const uint32_t DM_IDENTICAL_ACCOUNT; EXPORT extern const uint32_t DM_POINT_TO_POINT; +EXPORT extern const uint32_t DM_SHARE_TYPE; EXPORT extern const uint32_t DM_ACROSS_ACCOUNT; EXPORT extern const uint32_t DM_INVALIED_BINDTYPE; EXPORT extern const uint32_t DEVICE; @@ -240,6 +242,10 @@ 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 std::string &trustDeviceId, const int32_t &bindType); + std::unordered_map GetAuthFormMap(const std::string &pkgName, const std::string &deviceId, + std::vector profilesFilter, const int32_t &userId); 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 bb48d6c15..e75532c4e 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 = 2; const uint32_t DM_ACROSS_ACCOUNT = 1282; const uint32_t DM_INVALIED_BINDTYPE = 2048; const uint32_t DEVICE = 1; @@ -104,6 +106,13 @@ EXPORT std::unordered_map DeviceProfileConnector::GetAp profilesFilter.push_back(item); } } + return GetAuthFormMap(pkgName, deviceId, profilesFilter, userId); +} + +std::unordered_map DeviceProfileConnector::GetAuthFormMap(const std::string &pkgName, + const std::string &deviceId, std::vector profilesFilter, + const int32_t &userId) +{ std::unordered_map deviceIdMap; for (auto &item : profilesFilter) { std::string trustDeviceId = item.GetTrustDeviceId(); @@ -117,6 +126,10 @@ EXPORT std::unordered_map DeviceProfileConnector::GetAp continue; } if (deviceIdMap.find(trustDeviceId) == deviceIdMap.end()) { + if (CheckSinkShareType(item, userId, deviceId, trustDeviceId, bindType)) { + LOGI("GetAuthFormMap CheckSinkShareType true."); + continue; + } deviceIdMap[trustDeviceId] = static_cast(bindType); continue; } @@ -128,6 +141,14 @@ EXPORT std::unordered_map DeviceProfileConnector::GetAp deviceIdMap[trustDeviceId] = DmAuthForm::IDENTICAL_ACCOUNT; continue; } + if (bindType == DmAuthForm::ACROSS_ACCOUNT) { + if (CheckSinkShareType(item, userId, deviceId, trustDeviceId, bindType)) { + LOGI("GetAuthFormMap CheckSinkShareType true."); + continue; + } + deviceIdMap[trustDeviceId] = DmAuthForm::ACROSS_ACCOUNT; + continue; + } if (bindType == DmAuthForm::PEER_TO_PEER && authForm == DmAuthForm::ACROSS_ACCOUNT) { deviceIdMap[trustDeviceId] = DmAuthForm::PEER_TO_PEER; continue; @@ -136,6 +157,20 @@ EXPORT std::unordered_map DeviceProfileConnector::GetAp return deviceIdMap; } +bool DeviceProfileConnector::CheckSinkShareType(DistributedDeviceProfile::AccessControlProfile profile, + const int32_t &userId, const std::string &deviceId, const std::string &trustDeviceId, const int32_t &bindType) +{ + if ((profile.GetAccessee().GetAccesseeUserId() == userId || + profile.GetAccessee().GetAccesseeUserId() == 0 || + profile.GetAccessee().GetAccesseeUserId() == -1) && + profile.GetAccessee().GetAccesseeDeviceId() == deviceId && + profile.GetAccesser().GetAccesserDeviceId() == trustDeviceId && + bindType == DmAuthForm::ACROSS_ACCOUNT) { + return true; + } + return false; +} + int32_t DeviceProfileConnector::GetDeviceAclParam(DmDiscoveryInfo discoveryInfo, bool &isOnline, int32_t &authForm) { std::vector profiles = GetAccessControlProfileByUserId(discoveryInfo.userId); @@ -211,6 +246,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::ACROSS_ACCOUNT, profiles, discoveryInfo); + } return DmAuthForm::INVALID_TYPE; } @@ -244,6 +282,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/services/implementation/include/device_manager_service_impl.h b/services/implementation/include/device_manager_service_impl.h index 423e5be0f..6ca4cadc5 100644 --- a/services/implementation/include/device_manager_service_impl.h +++ b/services/implementation/include/device_manager_service_impl.h @@ -136,12 +136,20 @@ public: int32_t RegisterAuthenticationType(int32_t authenticationType); void DeleteAlwaysAllowTimeOut(); void CheckDeleteCredential(const std::string &remoteUdid, int32_t remoteUserId); + void HandleCredentialDeleted(const char *credId, const char *credInfo, const std::string &localUdid, + std::string &remoteUdid); + void HandleShareUnbindBroadCast(const std::string &credId, const int32_t &userId, const std::string &localUdid); int32_t CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId); private: int32_t PraseNotifyEventJson(const std::string &event, JsonObject &jsonObject); std::string GetUdidHashByNetworkId(const std::string &networkId); + void SetOnlineProcessInfo(uint32_t bindType, ProcessInfo &processInfo, DmDeviceInfo &devInfo, + const std::string &requestDeviceId, const std::string &trustDeviceId, DmDeviceState devState); + void HandleDeletedAclOffline(const std::string &trustDeviceId, + const std::string &requestDeviceId, DmDeviceInfo &devInfo, ProcessInfo &processInfo, DmDeviceState &devState); void HandleOffline(DmDeviceState devState, DmDeviceInfo &devInfo); void HandleOnline(DmDeviceState devState, DmDeviceInfo &devInfo); + bool CheckSharePeerSrc(const std::string &peerUdid, const std::string &localUdid); std::map GetDeviceIdAndBindLevel(int32_t userId); std::multimap GetDeviceIdAndUserId(int32_t userId, const std::string &accountId); void HandleAccountLogoutEvent(int32_t remoteUserId, const std::string &remoteAccountHash, @@ -166,6 +174,7 @@ private: std::shared_ptr hiChainAuthConnector_; std::shared_ptr listener_; std::atomic isCredentialType_ = false; + std::map deletedShareProfiles_; sptr dpInitedCallback_ = nullptr; }; diff --git a/services/implementation/include/device_manager_service_impl_lite.h b/services/implementation/include/device_manager_service_impl_lite.h index 6cd5df070..3dd319da4 100644 --- a/services/implementation/include/device_manager_service_impl_lite.h +++ b/services/implementation/include/device_manager_service_impl_lite.h @@ -158,6 +158,9 @@ public: int32_t RegisterAuthenticationType(int32_t authenticationType); void DeleteAlwaysAllowTimeOut(); void CheckDeleteCredential(const std::string &remoteUdid, int32_t remoteUserId); + void HandleCredentialDeleted(const char *credId, const char *credInfo, const std::string &localUdid, + std::string &remoteUdid); + void HandleShareUnbindBroadCast(const std::string &credId, const int32_t &userId, const std::string &localUdid); int32_t CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId); private: std::string GetUdidHashByNetworkId(const std::string &networkId); diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 12ad2f7fd..639270c7c 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -180,11 +180,12 @@ void DeviceManagerServiceImpl::HandleOffline(DmDeviceState devState, DmDeviceInf char localUdid[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localUdid, DEVICE_UUID_LENGTH); std::string requestDeviceId = std::string(localUdid); - std::map userIdAndBindLevel = - DeviceProfileConnector::GetInstance().GetUserIdAndBindLevel(requestDeviceId, trustDeviceId); ProcessInfo processInfo; processInfo.pkgName = std::string(DM_PKG_NAME); processInfo.userId = MultipleUserConnector::GetFirstForegroundUserId(); + uint32_t bindType = DeviceProfileConnector::GetInstance().CheckBindType(trustDeviceId, requestDeviceId); + std::map userIdAndBindLevel = + DeviceProfileConnector::GetInstance().GetUserIdAndBindLevel(requestDeviceId, trustDeviceId); if (userIdAndBindLevel.empty() || userIdAndBindLevel.find(processInfo.userId) == userIdAndBindLevel.end()) { userIdAndBindLevel[processInfo.userId] = INVALIED_TYPE; } @@ -194,8 +195,12 @@ void DeviceManagerServiceImpl::HandleOffline(DmDeviceState devState, DmDeviceInf devInfo.authForm = DmAuthForm::IDENTICAL_ACCOUNT; processInfo.userId = item.first; softbusConnector_->SetProcessInfo(processInfo); - } else if (static_cast(item.second) == DEVICE) { - LOGI("The offline device is device bind type."); + } else if (item.second == DEVICE && bindType == SHARE_TYPE) { + LOGI("The offline device is device bind level and share bind type."); + devInfo.authForm = DmAuthForm::ACROSS_ACCOUNT; + processInfo.userId = item.first; + softbusConnector_->SetProcessInfo(processInfo); + } else if (item.second == DEVICE && bindType != SHARE_TYPE) { devInfo.authForm = DmAuthForm::PEER_TO_PEER; processInfo.userId = item.first; softbusConnector_->SetProcessInfo(processInfo); @@ -210,6 +215,32 @@ void DeviceManagerServiceImpl::HandleOffline(DmDeviceState devState, DmDeviceInf } } +void DeviceManagerServiceImpl::HandleDeletedAclOffline(const std::string &trustDeviceId, + const std::string &requestDeviceId, DmDeviceInfo &devInfo, ProcessInfo &processInfo, DmDeviceState &devState) +{ + int32_t userId = 0; + for (auto iter : deletedShareProfiles_) { + if (iter.second.GetAccesser().GetAccesserDeviceId() == trustDeviceId && + iter.second.GetAccessee().GetAccesseeDeviceId() == requestDeviceId) { + LOGI("HandleOffline bindType is share type, peer is src."); + deletedShareProfiles_.erase(iter.first); + return; + } + if (iter.second.GetAccesser().GetAccesserDeviceId() == requestDeviceId && + iter.second.GetAccessee().GetAccesseeDeviceId() == trustDeviceId) { + LOGI("HandleOffline bindType is share type, peer is sink."); + deletedShareProfiles_.erase(iter.first); + userId = iter.second.GetAccesser().GetAccesserUserId(); + break; + } + } + devInfo.authForm = DmAuthForm::ACROSS_ACCOUNT; + processInfo.userId = userId; + softbusConnector_->SetProcessInfo(processInfo); + deviceStateMgr_->HandleDeviceStatusChange(devState, devInfo); + return; +} + void DeviceManagerServiceImpl::HandleOnline(DmDeviceState devState, DmDeviceInfo &devInfo) { LOGI("DeviceManagerServiceImpl::HandleOnline networkId: %{public}s.", @@ -232,6 +263,12 @@ void DeviceManagerServiceImpl::HandleOnline(DmDeviceState devState, DmDeviceInfo ProcessInfo processInfo; processInfo.pkgName = std::string(DM_PKG_NAME); processInfo.userId = MultipleUserConnector::GetFirstForegroundUserId(); + SetOnlineProcessInfo(bindType, processInfo, devInfo, requestDeviceId, trustDeviceId, devState); +} + +void DeviceManagerServiceImpl::SetOnlineProcessInfo(uint32_t bindType, ProcessInfo &processInfo, DmDeviceInfo &devInfo, + const std::string &requestDeviceId, const std::string &trustDeviceId, DmDeviceState devState) +{ if (bindType == IDENTICAL_ACCOUNT_TYPE) { devInfo.authForm = DmAuthForm::IDENTICAL_ACCOUNT; softbusConnector_->SetProcessInfo(processInfo); @@ -253,9 +290,36 @@ void DeviceManagerServiceImpl::HandleOnline(DmDeviceState devState, DmDeviceInfo MultipleUserConnector::GetFirstForegroundUserId()); softbusConnector_->SetProcessInfoVec(processInfoVec); devInfo.authForm = DmAuthForm::ACROSS_ACCOUNT; + } else if (bindType == SHARE_TYPE) { + if (CheckSharePeerSrc(trustDeviceId, requestDeviceId)) { + LOGI("ProcessDeviceStateChange authForm is share, peer is src."); + return; + } + devInfo.authForm = DmAuthForm::ACROSS_ACCOUNT; + softbusConnector_->SetProcessInfo(processInfo); } - LOGI("DeviceManagerServiceImpl::HandleOnline success devInfo auform %{public}d.", devInfo.authForm); + LOGI("DeviceManagerServiceImpl::HandleOnline success devInfo authForm is %{public}d.", devInfo.authForm); deviceStateMgr_->HandleDeviceStatusChange(devState, devInfo); + return; +} + +bool DeviceManagerServiceImpl::CheckSharePeerSrc(const std::string &peerUdid, const std::string &localUdid) +{ + std::vector profiles = + DeviceProfileConnector::GetInstance().GetAccessControlProfile(); + for (auto &aclItem : profiles) { + if (aclItem.GetBindType() == DM_SHARE_TYPE && aclItem.GetTrustDeviceId() == peerUdid) { + if (aclItem.GetAccesser().GetAccesserDeviceId() == peerUdid && + aclItem.GetAccessee().GetAccesseeDeviceId() == localUdid) { + return true; + } + if (aclItem.GetAccesser().GetAccesserDeviceId() == localUdid && + aclItem.GetAccessee().GetAccesseeDeviceId() == peerUdid) { + return false; + } + } + } + return false; } void DeviceManagerServiceImpl::HandleDeviceStatusChange(DmDeviceState devState, DmDeviceInfo &devInfo) @@ -1098,6 +1162,86 @@ void DeviceManagerServiceImpl::CheckDeleteCredential(const std::string &remoteUd } } +void DeviceManagerServiceImpl::HandleCredentialDeleted(const char *credId, const char *credInfo, + const std::string &localUdid, std::string &remoteUdid) +{ + LOGI("DeviceManagerServiceImpl::HandleCredentialDeleted Start, credId = %{public}s, credInfo = %{public}s.", + credId, credInfo); + std::vector profiles = + DeviceProfileConnector::GetInstance().GetAccessControlProfile(); + nlohmann::json jsonObject = nlohmann::json::parse(std::string(credInfo), nullptr, false); + if (jsonObject.is_discarded()) { + LOGE("credInfo prase error."); + return; + } + std::string deviceIdTag = "deviceId"; + std::string userIdTag = "userId"; + int32_t userId = 0; + if (IsString(jsonObject, deviceIdTag)) { + remoteUdid = jsonObject[deviceIdTag].get(); + } + if (IsInt32(jsonObject, userIdTag)) { + userId = jsonObject[userIdTag].get(); + } + LOGI("DeviceManagerServiceImpl::HandleCredentialDeleted remoteUdid = %{public}s, userId = %{public}d.", + remoteUdid.c_str(), userId); + for (const auto &item : profiles) { + if (item.GetBindType() != DM_SHARE_TYPE) { + continue; + } + if ((item.GetAccesser().GetAccesserCredentialId() == credId && + item.GetAccesser().GetAccesserDeviceId() == localUdid && + item.GetAccessee().GetAccesseeUserId() == userId && + item.GetAccessee().GetAccesseeDeviceId() == remoteUdid) || + (item.GetAccessee().GetAccesseeCredentialId() == credId && + item.GetAccessee().GetAccesseeDeviceId() == localUdid && + item.GetAccesser().GetAccesserUserId() == userId && + item.GetAccesser().GetAccesserDeviceId() == remoteUdid)) { + deletedShareProfiles_[remoteUdid] = item; + LOGI("DM_SHARE_TYPE in, profiles_ size is %{public}zu.", deletedShareProfiles_.size()); + DeviceProfileConnector::GetInstance().DeleteAccessControlById(item.GetAccessControlId()); + } + } +} + +void DeviceManagerServiceImpl::HandleShareUnbindBroadCast(const std::string &credId, const int32_t &userId, + const std::string &localUdid) +{ + LOGI("DeviceManagerServiceImpl::HandleShareUnbindBroadCast Start, credId = %{public}s, userId = %{public}d.", + credId.c_str(), userId); + std::vector profiles = + DeviceProfileConnector::GetInstance().GetAccessControlProfile(); + for (const auto &item : profiles) { + if (item.GetBindType() != DM_SHARE_TYPE) { + continue; + } + std::string accesserCredId = ""; + std::string accesseeCredId = ""; + for (int i = 0; i < 6; i++) { + accesserCredId[i] = item.GetAccesser().GetAccesserCredentialId()[i]; + accesseeCredId[i] = item.GetAccessee().GetAccesseeCredentialId()[i]; + } + LOGI("HandleShareUnbindBroadCast accesserCredId = %{public}s, accesseeCredId = %{public}s.", + accesserCredId.c_str(), accesseeCredId.c_str()); + if (accesserCredId == credId && item.GetAccessee().GetAccesseeDeviceId() == localUdid && + item.GetAccesser().GetAccesserUserId() == userId) { + std::string remoteUdid = item.GetAccesser().GetAccesserDeviceId(); + deletedShareProfiles_[remoteUdid] = item; + LOGI("HandleShareUnbindBroadCast local is sink, profiles_ size is %{public}zu.", + deletedShareProfiles_.size()); + DeviceProfileConnector::GetInstance().DeleteAccessControlById(item.GetAccessControlId()); + } + if (accesseeCredId == credId && item.GetAccesser().GetAccesserDeviceId() == localUdid && + item.GetAccessee().GetAccesseeUserId() == userId) { + std::string remoteUdid = item.GetAccessee().GetAccesseeDeviceId(); + deletedShareProfiles_[remoteUdid] = item; + LOGI("HandleShareUnbindBroadCast local is src, profiles_ size is %{public}zu.", + deletedShareProfiles_.size()); + DeviceProfileConnector::GetInstance().DeleteAccessControlById(item.GetAccessControlId()); + } + } +} + int32_t DeviceManagerServiceImpl::CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId) { diff --git a/services/implementation/src/device_manager_service_impl_lite.cpp b/services/implementation/src/device_manager_service_impl_lite.cpp index 516b29bda..44177d2dc 100644 --- a/services/implementation/src/device_manager_service_impl_lite.cpp +++ b/services/implementation/src/device_manager_service_impl_lite.cpp @@ -330,6 +330,16 @@ int32_t DeviceManagerServiceImpl::ImportAuthCode(const std::string &pkgName, con return DM_OK; } +void DeviceManagerServiceImpl::HandleCredentialDeleted(const char *credId, const char *credInfo, + const std::string &localUdid, std::string &remoteUdid) +{ + (void)credId; + (void)credInfo; + (void)localUdid; + (void)remoteUdid; + return; +} + int32_t DeviceManagerServiceImpl::ExportAuthCode(std::string &authCode) { (void)authCode; @@ -553,6 +563,15 @@ void DeviceManagerServiceImpl::HandleSyncUserIdEvent(const std::vector return; } +void DeviceManagerServiceImpl::HandleShareUnbindBroadCast(const std::string &credId, const int32_t &userId, + const std::string &localUdid) +{ + (void)credId; + (void)userId; + (void)localUdid; + return; +} + void DeviceManagerServiceImpl::HandleRemoteUserRemoved(int32_t preUserId, const std::string &remoteUdid) { (void)preUserId; diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index 8b40da361..7e7a1f838 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -190,6 +190,7 @@ public: int32_t InitScreenLockEvent(); bool CheckAccessControl(const DmAccessCaller &caller, const DmAccessCallee &callee); bool CheckIsSameAccount(const DmAccessCaller &caller, const DmAccessCallee &callee); + void HandleCredentialDeleted(const char *credId, const char *credInfo); void HandleDeviceNotTrust(const std::string &msg); #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) void HandleDeviceTrustedChange(const std::string &msg); @@ -252,6 +253,8 @@ private: void SendAppUnBindBroadCast(const std::vector &peerUdids, int32_t userId, uint64_t tokenId); void SendAppUnBindBroadCast(const std::vector &peerUdids, int32_t userId, uint64_t tokenId, uint64_t peerTokenId); + void SendShareTypeUnBindBroadCast(const char *credId, const int32_t localUserId, + const std::vector &peerUdids); void SendServiceUnBindBroadCast(const std::vector &peerUdids, int32_t userId, uint64_t tokenId); void SendAccountLogoutBroadCast(const std::vector &peerUdids, const std::string &accountId, const std::string &accountName, int32_t userId); @@ -303,6 +306,7 @@ private: void HandleUserSwitched(int32_t curUserId, int32_t preUserId); void HandleUserIdsBroadCast(const std::vector &remoteUserIdInfos, const std::string &remoteUdid, bool isNeedResponse); + void HandleShareUnbindBroadCast(const int32_t userId, const std::string &credId); void NotifyRemoteLocalUserSwitch(int32_t curUserId, int32_t preUserId, const std::vector &peerUdids, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds); void NotifyRemoteLocalUserSwitchByWifi(int32_t curUserId, int32_t preUserId, diff --git a/services/service/include/hichain/hichain_listener.h b/services/service/include/hichain/hichain_listener.h index 07f408803..cc43346a2 100644 --- a/services/service/include/hichain/hichain_listener.h +++ b/services/service/include/hichain/hichain_listener.h @@ -58,6 +58,7 @@ public: HichainListener(); ~HichainListener(); void RegisterDataChangeCb(); + void RegisterCredentialCb(); void DeleteAllGroup(const std::string &localUdid, const std::vector &backgroundUserIds); int32_t GetRelatedGroups(int32_t userId, const std::string &deviceId, std::vector &groupList); @@ -69,9 +70,11 @@ public: int64_t GenRequestId(); static void OnHichainDeviceUnBound(const char *peerUdid, const char *groupInfo); + static void OnCredentialDeleted(const char *credId, const char *credInfo); private: const DeviceGroupManager *deviceGroupManager_ = nullptr; + const CredManager *credManager_ = nullptr; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/include/idevice_manager_service_impl.h b/services/service/include/idevice_manager_service_impl.h index 7d2e34906..596fa6935 100644 --- a/services/service/include/idevice_manager_service_impl.h +++ b/services/service/include/idevice_manager_service_impl.h @@ -259,6 +259,10 @@ public: virtual int32_t RegisterAuthenticationType(int32_t authenticationType) = 0; virtual void DeleteAlwaysAllowTimeOut() = 0; virtual void CheckDeleteCredential(const std::string &remoteUdid, int32_t remoteUserId) = 0; + virtual void HandleCredentialDeleted(const char *credId, const char *credInfo, const std::string &localUdid, + std::string &remoteUdid) = 0; + virtual void HandleShareUnbindBroadCast(const std::string &credId, const int32_t &userId, + const std::string &localUdid) = 0; virtual int32_t CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId) = 0; }; diff --git a/services/service/include/relationshipsyncmgr/relationship_sync_mgr.h b/services/service/include/relationshipsyncmgr/relationship_sync_mgr.h index d0787d446..0409dd7f6 100644 --- a/services/service/include/relationshipsyncmgr/relationship_sync_mgr.h +++ b/services/service/include/relationshipsyncmgr/relationship_sync_mgr.h @@ -30,7 +30,8 @@ enum class RelationShipChangeType : uint32_t { APP_UNINSTALL = 5, SYNC_USERID = 6, STOP_USER = 7, - TYPE_MAX = 8 + SHARE_UNBIND = 8, + TYPE_MAX = 9 }; struct UserIdInfo { @@ -58,6 +59,7 @@ struct RelationShipChangeMsg { bool syncUserIdFlag; // The foreground and background user id infos std::vector userIdInfos; + std::string credId; explicit RelationShipChangeMsg(); bool ToBroadcastPayLoad(uint8_t *&msg, uint32_t &len) const; @@ -71,6 +73,7 @@ struct RelationShipChangeMsg { bool ToSyncFrontOrBackUserIdPayLoad(uint8_t *&msg, uint32_t &len) const; void ToDelUserPayLoad(uint8_t *&msg, uint32_t &len) const; void ToStopUserPayLoad(uint8_t *&msg, uint32_t &len) const; + void ToShareUnbindPayLoad(uint8_t *&msg, uint32_t &len) const; cJSON *ToPayLoadJson() const; bool FromAccountLogoutPayLoad(const cJSON *payloadJson); @@ -79,6 +82,7 @@ struct RelationShipChangeMsg { bool FromSyncFrontOrBackUserIdPayLoad(const cJSON *payloadJson); bool FromDelUserPayLoad(const cJSON *payloadJson); bool FromStopUserPayLoad(const cJSON *payloadJson); + bool FromShareUnbindPayLoad(const cJSON *payloadJson); std::string ToJson() const; bool FromJson(const std::string &msgJson); diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index aa87475de..a1d43eece 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -73,6 +73,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 = 2; 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; @@ -132,6 +133,7 @@ void DeviceManagerService::InitHichainListener() hichainListener_ = std::make_shared(); } hichainListener_->RegisterDataChangeCb(); + hichainListener_->RegisterCredentialCb(); } #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) @@ -2313,6 +2315,48 @@ 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 credId or credInfo is nullptr."); + return; + } + char localUdidTemp[DEVICE_UUID_LENGTH] = {0}; + GetDevUdid(localUdidTemp, DEVICE_UUID_LENGTH); + std::string localUdid = std::string(localUdidTemp); + if (!IsDMServiceImplReady()) { + LOGE("HandleCredentialDeleted failed, instance not init or init failed."); + return; + } + std::string remoteUdid = ""; + dmServiceImpl_->HandleCredentialDeleted(credId, credInfo, localUdid, remoteUdid); + if (remoteUdid.empty()) { + LOGE("HandleCredentialDeleted failed, remoteUdid is empty."); + return; + } + std::vector peerUdids; + peerUdids.emplace_back(remoteUdid); + int32_t localUserId = MultipleUserConnector::GetFirstForegroundUserId(); + SendShareTypeUnBindBroadCast(credId, localUserId, peerUdids); + return; +} + +void DeviceManagerService::SendShareTypeUnBindBroadCast(const char *credId, const int32_t localUserId + const std::vector &peerUdids) +{ + LOGI("SendShareTypeUnBindBroadCast Start."); + RelationShipChangeMsg msg; + msg.type = RelationShipChangeType::SHARE_UNBIND; + msg.userId = static_cast(localUserId); + msg.credId = credId; + msg.peerUdids = peerUdids; + std::string broadCastMsg = ReleationShipSyncMgr::GetInstance().SyncTrustRelationShip(msg); + LOGI("SendShareTypeUnBindBroadCast broadCastMsg = %{public}s.", broadCastMsg.c_str()); + CHECK_NULL_VOID(softbusListener_); + softbusListener_->SendAclChangedBroadcast(broadCastMsg); +} + int32_t DeviceManagerService::SetDnPolicy(const std::string &pkgName, std::map &policy) { if (!PermissionManager::GetInstance().CheckPermission()) { @@ -2537,6 +2581,9 @@ void DeviceManagerService::HandleDeviceTrustedChange(const std::string &msg) case RelationShipChangeType::STOP_USER: HandleUserStopBroadCast(relationShipMsg.userId, relationShipMsg.peerUdid); break; + case RelationShipChangeType::SHARE_UNBIND: + HandleShareUnbindBroadCast(relationShipMsg.userId, relationShipMsg.credId); + break; default: LOGI("Dm have not this event type."); break; @@ -2544,6 +2591,22 @@ void DeviceManagerService::HandleDeviceTrustedChange(const std::string &msg) return; } +void DeviceManagerService::HandleShareUnbindBroadCast(const int32_t userId, const std::string &credId) +{ + LOGI("HandleShareUnbindBroadCast start."); + if (credId == "") { + LOGE("HandleShareUnbindBroadCast credId is null."); + return; + } + char localUdidTemp[DEVICE_UUID_LENGTH] = {0}; + GetDevUdid(localUdidTemp, DEVICE_UUID_LENGTH); + std::string localUdid = std::string(localUdidTemp); + if (IsDMServiceImplReady()) { + dmServiceImpl_->HandleShareUnbindBroadCast(credId, userId, localUdid); + } + return; +} + int32_t DeviceManagerService::ParseCheckSumMsg(const std::string &msg, std::string &networkId, uint32_t &discoveryType, bool &isChange) { diff --git a/services/service/src/hichain/hichain_listener.cpp b/services/service/src/hichain/hichain_listener.cpp index 52870f4ba..5798ba5b3 100644 --- a/services/service/src/hichain/hichain_listener.cpp +++ b/services/service/src/hichain/hichain_listener.cpp @@ -32,6 +32,10 @@ static DataChangeListener dataChangeListener_ = { .onDeviceUnBound = HichainListener::OnHichainDeviceUnBound, }; +static CredChangeListener credChangeListener_ = { + .onCredDelete = HichainListener::OnCredentialDeleted, +}; + void FromJson(const JsonItemObject &jsonObject, GroupInformation &groupInfo) { if (jsonObject.Contains(FIELD_GROUP_TYPE) && jsonObject.At(FIELD_GROUP_TYPE).IsNumberInteger()) { @@ -81,10 +85,15 @@ HichainListener::HichainListener() LOGI("HichainListener constructor start."); InitDeviceAuthService(); deviceGroupManager_ = GetGmInstance(); + credManager_ = GetCredMgrInstance(); if (deviceGroupManager_ == nullptr) { LOGE("[HICHAIN]failed to init group manager."); return; } + if (credManager_ == nullptr) { + LOGE("[HICHAIN]failed to init cred manager."); + return; + } LOGI("HichainListener::constructor success."); } @@ -109,6 +118,21 @@ void HichainListener::RegisterDataChangeCb() LOGI("RegisterDataChangeCb success!"); } +void HichainListener::RegisterCredentialCb() +{ + LOGI("HichainListener::RegisterCredentialCb start"); + if (credManager_ == nullptr) { + LOGE("credManager_ is null!"); + return; + } + int32_t ret = credManager_->registerChangeListener(DM_PKG_NAME, &credChangeListener_); + if (ret != DM_OK) { + LOGE("[HICHAIN]registerChangeListener failed with ret: %{public}d.", ret); + return; + } + LOGI("RegisterCredentialCb success!"); +} + void HichainListener::OnHichainDeviceUnBound(const char *peerUdid, const char *groupInfo) { LOGI("HichainListener::onDeviceUnBound start"); @@ -140,6 +164,21 @@ void HichainListener::OnHichainDeviceUnBound(const char *peerUdid, const char *g } } +void HichainListener::OnCredentialDeleted(const char *credId, const char *credInfo) +{ + LOGI("HichainListener::OnCredentialDeleted start"); + if (credId == nullptr || credInfo == nullptr) { + LOGE("credId or credInfo is null!"); + return; + } + if (strlen(credId) > MAX_DATA_LEN || strlen(credInfo) > MAX_DATA_LEN) { + LOGE("credId or credInfo is invalid"); + return; + } + DeviceManagerService::GetInstance().HandleCredentialDeleted(credId, credInfo); + return; +} + void HichainListener::DeleteAllGroup(const std::string &localUdid, const std::vector &backgroundUserIds) { LOGI("OnStart HichainListener::DeleteAllGroup"); diff --git a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp index 962391c13..ea368fa2b 100644 --- a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp +++ b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp @@ -46,6 +46,7 @@ namespace { */ const int32_t DEL_USER_PAYLOAD_LEN = 2; const int32_t STOP_USER_PAYLOAD_LEN = 2; + const int32_t SHARE_UNBIND_PAYLOAD_LEN = 8; /** * @brief the userid payload cost 2 bytes. * @@ -58,6 +59,7 @@ namespace { const int32_t USERID_BYTES = 2; const int32_t BITS_PER_BYTE = 8; const int32_t INVALIED_PAYLOAD_SIZE = 12; + const int32_t CREDID_PAYLOAD_LEN = 8; const char * const MSG_TYPE = "TYPE"; const char * const MSG_VALUE = "VALUE"; @@ -127,6 +129,10 @@ bool RelationShipChangeMsg::ToBroadcastPayLoad(uint8_t *&msg, uint32_t &len) con ToStopUserPayLoad(msg, len); ret = true; break; + case RelationShipChangeType::SHARE_UNBIND: + ToShareUnbindPayLoad(msg, len); + ret = true; + break; default: LOGE("RelationShipChange type invalid"); break; @@ -134,6 +140,19 @@ bool RelationShipChangeMsg::ToBroadcastPayLoad(uint8_t *&msg, uint32_t &len) con return ret; } +void RelationShipChangeMsg::ToShareUnbindPayLoad(uint8_t *&msg, uint32_t &len) const +{ + msg = new uint8_t[SHARE_UNBIND_PAYLOAD_LEN](); + for (int i = 0; i < USERID_PAYLOAD_LEN; i++) { + msg[i] |= (userId >> (i * BITS_PER_BYTE)) & 0xFF; + } + + for (int i = USERID_PAYLOAD_LEN; i < CREDID_PAYLOAD_LEN; i++) { + msg[i] = credId[i - USERID_PAYLOAD_LEN]; + } + len = SHARE_UNBIND_PAYLOAD_LEN; +} + bool RelationShipChangeMsg::FromBroadcastPayLoad(const cJSON *payloadJson, RelationShipChangeType type) { LOGI("FromBroadcastPayLoad type %{public}d.", type); @@ -161,6 +180,9 @@ bool RelationShipChangeMsg::FromBroadcastPayLoad(const cJSON *payloadJson, Relat case RelationShipChangeType::STOP_USER: ret = FromStopUserPayLoad(payloadJson); break; + case RelationShipChangeType::SHARE_UNBIND: + ret = FromShareUnbindPayLoad(payloadJson); + break; default: LOGE("RelationShipChange type invalid"); break; @@ -168,6 +190,36 @@ bool RelationShipChangeMsg::FromBroadcastPayLoad(const cJSON *payloadJson, Relat return ret; } +bool RelationShipChangeMsg::FromShareUnbindPayLoad(const cJSON *payloadJson) +{ + if (payloadJson == NULL) { + LOGE("Share unbind payloadJson is null."); + return false; + } + int32_t arraySize = cJSON_GetArraySize(payloadJson); + if (arraySize < SHARE_UNBIND_PAYLOAD_LEN || arraySize >= INVALIED_PAYLOAD_SIZE) { + LOGE("Payload invalied,the size is %{public}d.", arraySize); + return false; + } + userId = 0; + for (uint32_t i = 0; i < USERID_PAYLOAD_LEN; i++) { + cJSON *payloadItem = cJSON_GetArrayItem(payloadJson, i); + CHECK_NULL_RETURN(payloadItem, false); + if (cJSON_IsNumber(payloadItem)) { + userId |= (static_cast(payloadItem->valueint)) << (i * BITS_PER_BYTE); + } + } + credId = ""; + for (uint32_t j = USERID_PAYLOAD_LEN; j < CREDID_PAYLOAD_LEN; j++) { + cJSON *payloadItem = cJSON_GetArrayItem(payloadJson, j); + CHECK_NULL_RETURN(payloadItem, false); + if (cJSON_IsNumber(payloadItem)) { + credId += static_cast(payloadItem->valueint); + } + } + return true; +} + bool RelationShipChangeMsg::IsValid() const { bool ret = false; @@ -187,6 +239,9 @@ bool RelationShipChangeMsg::IsValid() const case RelationShipChangeType::STOP_USER: ret = (userId != UINT32_MAX); break; + case RelationShipChangeType::SHARE_UNBIND: + ret = (userId != UINT32_MAX); + break; case RelationShipChangeType::SERVICE_UNBIND: case RelationShipChangeType::APP_UNINSTALL: // current NOT support @@ -220,7 +275,8 @@ bool RelationShipChangeMsg::IsChangeTypeValid(uint32_t type) (type == (uint32_t)RelationShipChangeType::APP_UNBIND) || (type == (uint32_t)RelationShipChangeType::SYNC_USERID) || (type == (uint32_t)RelationShipChangeType::DEL_USER) || - (type == (uint32_t)RelationShipChangeType::STOP_USER); + (type == (uint32_t)RelationShipChangeType::STOP_USER) || + (type == (uint32_t)RelationShipChangeType::SHARE_UNBIND); } void RelationShipChangeMsg::ToAccountLogoutPayLoad(uint8_t *&msg, uint32_t &len) const diff --git a/test/unittest/mock/device_auth.h b/test/unittest/mock/device_auth.h index 6e520f698..0744a2bbe 100644 --- a/test/unittest/mock/device_auth.h +++ b/test/unittest/mock/device_auth.h @@ -138,6 +138,12 @@ using DataChangeListener = struct DataChangeListener { void (*onTrustedDeviceNumChanged)(int curTrustedDeviceNum); }; +using CredChangeListener = struct CredChangeListener { + void (*onCredAdd)(const char *credId, const char *credInfo); + void (*onCredDelete)(const char *credId, const char *credInfo); + void (*onCredUpdate)(const char *credId, const char *credInfo); +}; + using DeviceAuthCallback = struct DeviceAuthCallback { bool (*onTransmit)(int64_t requestId, const uint8_t *data, uint32_t dataLen); void (*onSessionKeyReturned)(int64_t requestId, const uint8_t *sessionKey, uint32_t sessionKeyLen); @@ -146,6 +152,22 @@ using DeviceAuthCallback = struct DeviceAuthCallback { char *(*onRequest)(int64_t requestId, int operationCode, const char *reqParams); }; +using CredManager = struct CredManager { + int32_t (*addCredential)(int32_t osAccountId, const char *requestParams, char **returnData); + int32_t (*exportCredential)(int32_t osAccountId, const char *credId, char **returnData); + int32_t (*queryCredentialByParams)(int32_t osAccountId, const char *requestParams, char **returnData); + int32_t (*queryCredInfoByCredId)(int32_t osAccountId, const char *credId, char **returnData); + int32_t (*deleteCredential)(int32_t osAccountId, const char *credId); + int32_t (*updateCredInfo)(int32_t osAccountId, const char *credId, const char *requestParams); + int32_t (*agreeCredential)(int32_t osAccountId, const char *selfCredId, const char *requestParams, + char **returnData); + int32_t (*registerChangeListener)(const char *appId, CredChangeListener *listener); + int32_t (*unregisterChangeListener)(const char *appId); + int32_t (*deleteCredByParams)(int32_t osAccountId, const char *requestParams, char **returnData); + int32_t (*batchUpdateCredentials)(int32_t osAccountId, const char *requestParams, char **returnData); + void (*destroyInfo)(char **returnData); +} + using GroupAuthManager = struct GroupAuthManager { int32_t (*processData)(int64_t authReqId, const uint8_t *data, uint32_t dataLen, const DeviceAuthCallback *gaCallback); @@ -214,6 +236,7 @@ DEVICE_AUTH_API_PUBLIC int InitDeviceAuthService(void); DEVICE_AUTH_API_PUBLIC void DestroyDeviceAuthService(void); DEVICE_AUTH_API_PUBLIC const GroupAuthManager *GetGaInstance(void); DEVICE_AUTH_API_PUBLIC const DeviceGroupManager *GetGmInstance(void); +DEVICE_AUTH_API_PUBLIC const CredManager *GetCredMgrInstance(void); #ifdef __cplusplus } #endif -- Gitee From c132c85231d3ee4fbee4cff1ac3955a6a16bccea Mon Sep 17 00:00:00 2001 From: BrainL Date: Wed, 9 Apr 2025 15:45:50 +0800 Subject: [PATCH 02/13] modify Signed-off-by: BrainL --- services/implementation/src/device_manager_service_impl.cpp | 3 ++- services/service/src/device_manager_service.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 639270c7c..ca1e217a9 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -37,6 +37,7 @@ namespace OHOS { namespace DistributedHardware { // One year 365 * 24 * 60 * 60 constexpr int32_t MAX_ALWAYS_ALLOW_SECONDS = 31536000; +constexpr int32_t ACL_CREDID_LENGTH = 6; DeviceManagerServiceImpl::DeviceManagerServiceImpl() { @@ -1217,7 +1218,7 @@ void DeviceManagerServiceImpl::HandleShareUnbindBroadCast(const std::string &cre } std::string accesserCredId = ""; std::string accesseeCredId = ""; - for (int i = 0; i < 6; i++) { + for (int32_t i = 0; i < ACL_CREDID_LENGTH; i++) { accesserCredId[i] = item.GetAccesser().GetAccesserCredentialId()[i]; accesseeCredId[i] = item.GetAccessee().GetAccesseeCredentialId()[i]; } diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index a1d43eece..9a065e5f7 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -2342,7 +2342,7 @@ void DeviceManagerService::HandleCredentialDeleted(const char *credId, const cha return; } -void DeviceManagerService::SendShareTypeUnBindBroadCast(const char *credId, const int32_t localUserId +void DeviceManagerService::SendShareTypeUnBindBroadCast(const char *credId, const int32_t localUserId, const std::vector &peerUdids) { LOGI("SendShareTypeUnBindBroadCast Start."); -- Gitee From bc7cdabe600de95379077a0a64e365841d24443e Mon Sep 17 00:00:00 2001 From: BrainL Date: Wed, 9 Apr 2025 17:56:03 +0800 Subject: [PATCH 03/13] modify json Signed-off-by: BrainL --- .../src/device_manager_service_impl.cpp | 17 +++++++++-------- services/service/src/device_manager_service.cpp | 3 +-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index ca1e217a9..aef0084f1 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -1170,8 +1170,9 @@ void DeviceManagerServiceImpl::HandleCredentialDeleted(const char *credId, const credId, credInfo); std::vector profiles = DeviceProfileConnector::GetInstance().GetAccessControlProfile(); - nlohmann::json jsonObject = nlohmann::json::parse(std::string(credInfo), nullptr, false); - if (jsonObject.is_discarded()) { + JsonObject jsonObject; + jsonObject.Parse(std::string(credInfo)); + if (jsonObject.IsDiscarded()) { LOGE("credInfo prase error."); return; } @@ -1179,10 +1180,10 @@ void DeviceManagerServiceImpl::HandleCredentialDeleted(const char *credId, const std::string userIdTag = "userId"; int32_t userId = 0; if (IsString(jsonObject, deviceIdTag)) { - remoteUdid = jsonObject[deviceIdTag].get(); + remoteUdid = jsonObject[deviceIdTag].Get(); } if (IsInt32(jsonObject, userIdTag)) { - userId = jsonObject[userIdTag].get(); + userId = jsonObject[userIdTag].Get(); } LOGI("DeviceManagerServiceImpl::HandleCredentialDeleted remoteUdid = %{public}s, userId = %{public}d.", remoteUdid.c_str(), userId); @@ -1190,11 +1191,11 @@ void DeviceManagerServiceImpl::HandleCredentialDeleted(const char *credId, const if (item.GetBindType() != DM_SHARE_TYPE) { continue; } - if ((item.GetAccesser().GetAccesserCredentialId() == credId && + if ((item.GetAccesser().GetAccesserCredentialId() == atoi(credId) && item.GetAccesser().GetAccesserDeviceId() == localUdid && item.GetAccessee().GetAccesseeUserId() == userId && item.GetAccessee().GetAccesseeDeviceId() == remoteUdid) || - (item.GetAccessee().GetAccesseeCredentialId() == credId && + (item.GetAccessee().GetAccesseeCredentialId() == atoi(credId) && item.GetAccessee().GetAccesseeDeviceId() == localUdid && item.GetAccesser().GetAccesserUserId() == userId && item.GetAccesser().GetAccesserDeviceId() == remoteUdid)) { @@ -1219,8 +1220,8 @@ void DeviceManagerServiceImpl::HandleShareUnbindBroadCast(const std::string &cre std::string accesserCredId = ""; std::string accesseeCredId = ""; for (int32_t i = 0; i < ACL_CREDID_LENGTH; i++) { - accesserCredId[i] = item.GetAccesser().GetAccesserCredentialId()[i]; - accesseeCredId[i] = item.GetAccessee().GetAccesseeCredentialId()[i]; + accesserCredId[i] = std::to_string(item.GetAccesser().GetAccesserCredentialId())[i]; + accesseeCredId[i] = std::to_string(item.GetAccessee().GetAccesseeCredentialId())[i]; } LOGI("HandleShareUnbindBroadCast accesserCredId = %{public}s, accesseeCredId = %{public}s.", accesserCredId.c_str(), accesseeCredId.c_str()); diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 9a065e5f7..1aa0b0ff3 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -2337,8 +2337,7 @@ void DeviceManagerService::HandleCredentialDeleted(const char *credId, const cha } std::vector peerUdids; peerUdids.emplace_back(remoteUdid); - int32_t localUserId = MultipleUserConnector::GetFirstForegroundUserId(); - SendShareTypeUnBindBroadCast(credId, localUserId, peerUdids); + SendShareTypeUnBindBroadCast(credId, MultipleUserConnector::GetCurrentAccountUserID(), peerUdids); return; } -- Gitee From 908ba5b7ba5a01bd1dd81c15d0dee4185665f186 Mon Sep 17 00:00:00 2001 From: BrainL Date: Thu, 10 Apr 2025 17:05:16 +0800 Subject: [PATCH 04/13] modify Signed-off-by: BrainL --- services/service/src/device_manager_service.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 1aa0b0ff3..7731d817f 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -2318,6 +2318,9 @@ void DeviceManagerService::HandleDeviceNotTrust(const std::string &msg) void DeviceManagerService::HandleCredentialDeleted(const char *credId, const char *credInfo) { LOGI("HandleCredentialDeleted start."); + #if (defined(__LITEOS_M__) || defined(LITE_DEVICE)) + return 0; + #endif if (credId == nullptr || credInfo == nullptr) { LOGE("HandleCredentialDeleted credId or credInfo is nullptr."); return; -- Gitee From 643c454f80fa4b2cb77c7e3db8cdd54af9a787a3 Mon Sep 17 00:00:00 2001 From: BrainL Date: Thu, 10 Apr 2025 17:06:32 +0800 Subject: [PATCH 05/13] modify Signed-off-by: BrainL --- services/service/src/device_manager_service.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 7731d817f..2660b6694 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -2319,7 +2319,7 @@ void DeviceManagerService::HandleCredentialDeleted(const char *credId, const cha { LOGI("HandleCredentialDeleted start."); #if (defined(__LITEOS_M__) || defined(LITE_DEVICE)) - return 0; + return ; #endif if (credId == nullptr || credInfo == nullptr) { LOGE("HandleCredentialDeleted credId or credInfo is nullptr."); -- Gitee From 7f70c111f9d03eaedaaed475d4805c5d0bfd2c7d Mon Sep 17 00:00:00 2001 From: BrainL Date: Thu, 10 Apr 2025 17:46:13 +0800 Subject: [PATCH 06/13] modify Signed-off-by: BrainL --- services/service/include/device_manager_service.h | 2 +- services/service/src/device_manager_service.cpp | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index 7e7a1f838..f18c21ee8 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -190,9 +190,9 @@ public: int32_t InitScreenLockEvent(); bool CheckAccessControl(const DmAccessCaller &caller, const DmAccessCallee &callee); bool CheckIsSameAccount(const DmAccessCaller &caller, const DmAccessCallee &callee); - void HandleCredentialDeleted(const char *credId, const char *credInfo); void HandleDeviceNotTrust(const std::string &msg); #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + void HandleCredentialDeleted(const char *credId, const char *credInfo); void HandleDeviceTrustedChange(const std::string &msg); void HandleUserIdCheckSumChange(const std::string &msg); void HandleUserStop(int32_t stopUserId, const std::string &stopEventUdid); diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 2660b6694..1aa0b0ff3 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -2318,9 +2318,6 @@ void DeviceManagerService::HandleDeviceNotTrust(const std::string &msg) void DeviceManagerService::HandleCredentialDeleted(const char *credId, const char *credInfo) { LOGI("HandleCredentialDeleted start."); - #if (defined(__LITEOS_M__) || defined(LITE_DEVICE)) - return ; - #endif if (credId == nullptr || credInfo == nullptr) { LOGE("HandleCredentialDeleted credId or credInfo is nullptr."); return; -- Gitee From 6a0af2c0a2c00a5ed6c485febfe12f350cb49125 Mon Sep 17 00:00:00 2001 From: BrainL Date: Thu, 10 Apr 2025 17:47:55 +0800 Subject: [PATCH 07/13] modify Signed-off-by: BrainL --- test/unittest/mock/device_auth.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/mock/device_auth.h b/test/unittest/mock/device_auth.h index 0744a2bbe..1a37168fc 100644 --- a/test/unittest/mock/device_auth.h +++ b/test/unittest/mock/device_auth.h @@ -166,7 +166,7 @@ using CredManager = struct CredManager { int32_t (*deleteCredByParams)(int32_t osAccountId, const char *requestParams, char **returnData); int32_t (*batchUpdateCredentials)(int32_t osAccountId, const char *requestParams, char **returnData); void (*destroyInfo)(char **returnData); -} +}; using GroupAuthManager = struct GroupAuthManager { int32_t (*processData)(int64_t authReqId, const uint8_t *data, uint32_t dataLen, -- Gitee From 2e45ee1f4b4da24054a63f693eceb26b9330af4c Mon Sep 17 00:00:00 2001 From: BrainL Date: Thu, 10 Apr 2025 18:11:40 +0800 Subject: [PATCH 08/13] modify Signed-off-by: BrainL --- .../service/src/device_manager_service.cpp | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 1aa0b0ff3..746704570 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -2315,32 +2315,6 @@ 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 credId or credInfo is nullptr."); - return; - } - char localUdidTemp[DEVICE_UUID_LENGTH] = {0}; - GetDevUdid(localUdidTemp, DEVICE_UUID_LENGTH); - std::string localUdid = std::string(localUdidTemp); - if (!IsDMServiceImplReady()) { - LOGE("HandleCredentialDeleted failed, instance not init or init failed."); - return; - } - std::string remoteUdid = ""; - dmServiceImpl_->HandleCredentialDeleted(credId, credInfo, localUdid, remoteUdid); - if (remoteUdid.empty()) { - LOGE("HandleCredentialDeleted failed, remoteUdid is empty."); - return; - } - std::vector peerUdids; - peerUdids.emplace_back(remoteUdid); - SendShareTypeUnBindBroadCast(credId, MultipleUserConnector::GetCurrentAccountUserID(), peerUdids); - return; -} - void DeviceManagerService::SendShareTypeUnBindBroadCast(const char *credId, const int32_t localUserId, const std::vector &peerUdids) { @@ -2539,6 +2513,32 @@ void DeviceManagerService::SendServiceUnBindBroadCast(const std::vectorSendAclChangedBroadcast(broadCastMsg); } +void DeviceManagerService::HandleCredentialDeleted(const char *credId, const char *credInfo) +{ + LOGI("HandleCredentialDeleted start."); + if (credId == nullptr || credInfo == nullptr) { + LOGE("HandleCredentialDeleted credId or credInfo is nullptr."); + return; + } + char localUdidTemp[DEVICE_UUID_LENGTH] = {0}; + GetDevUdid(localUdidTemp, DEVICE_UUID_LENGTH); + std::string localUdid = std::string(localUdidTemp); + if (!IsDMServiceImplReady()) { + LOGE("HandleCredentialDeleted failed, instance not init or init failed."); + return; + } + std::string remoteUdid = ""; + dmServiceImpl_->HandleCredentialDeleted(credId, credInfo, localUdid, remoteUdid); + if (remoteUdid.empty()) { + LOGE("HandleCredentialDeleted failed, remoteUdid is empty."); + return; + } + std::vector peerUdids; + peerUdids.emplace_back(remoteUdid); + SendShareTypeUnBindBroadCast(credId, MultipleUserConnector::GetCurrentAccountUserID(), peerUdids); + return; +} + void DeviceManagerService::HandleDeviceTrustedChange(const std::string &msg) { if (msg.empty()) { -- Gitee From ea0fd0e1afd0c501e62b172ae9584a6ab5e9671a Mon Sep 17 00:00:00 2001 From: BrainL Date: Thu, 10 Apr 2025 18:42:39 +0800 Subject: [PATCH 09/13] modify Signed-off-by: BrainL --- .../service/include/device_manager_service.h | 2 ++ .../service/src/device_manager_service.cpp | 30 +++++++++---------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index f18c21ee8..ff2b08a1c 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -286,6 +286,8 @@ private: #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) void SubscribeAccountCommonEvent(); + void SendShareTypeUnBindBroadCast(const char *credId, const int32_t localUserId, + const std::vector &peerUdids); EXPORT void AccountCommonEventCallback(const std::string commonEventType, int32_t currentUserId, int32_t beforeUserId); void SubscribeScreenLockEvent(); diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 746704570..1d46e0272 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -1869,6 +1869,21 @@ void DeviceManagerService::SubscribeAccountCommonEvent() return; } +void DeviceManagerService::SendShareTypeUnBindBroadCast(const char *credId, const int32_t localUserId, + const std::vector &peerUdids) +{ + LOGI("SendShareTypeUnBindBroadCast Start."); + RelationShipChangeMsg msg; + msg.type = RelationShipChangeType::SHARE_UNBIND; + msg.userId = static_cast(localUserId); + msg.credId = credId; + msg.peerUdids = peerUdids; + std::string broadCastMsg = ReleationShipSyncMgr::GetInstance().SyncTrustRelationShip(msg); + LOGI("SendShareTypeUnBindBroadCast broadCastMsg = %{public}s.", broadCastMsg.c_str()); + CHECK_NULL_VOID(softbusListener_); + softbusListener_->SendAclChangedBroadcast(broadCastMsg); +} + void DeviceManagerService::SubscribeScreenLockEvent() { LOGI("Start"); @@ -2315,21 +2330,6 @@ void DeviceManagerService::HandleDeviceNotTrust(const std::string &msg) return; } -void DeviceManagerService::SendShareTypeUnBindBroadCast(const char *credId, const int32_t localUserId, - const std::vector &peerUdids) -{ - LOGI("SendShareTypeUnBindBroadCast Start."); - RelationShipChangeMsg msg; - msg.type = RelationShipChangeType::SHARE_UNBIND; - msg.userId = static_cast(localUserId); - msg.credId = credId; - msg.peerUdids = peerUdids; - std::string broadCastMsg = ReleationShipSyncMgr::GetInstance().SyncTrustRelationShip(msg); - LOGI("SendShareTypeUnBindBroadCast broadCastMsg = %{public}s.", broadCastMsg.c_str()); - CHECK_NULL_VOID(softbusListener_); - softbusListener_->SendAclChangedBroadcast(broadCastMsg); -} - int32_t DeviceManagerService::SetDnPolicy(const std::string &pkgName, std::map &policy) { if (!PermissionManager::GetInstance().CheckPermission()) { -- Gitee From ca7a687632b65120b8d9f6ade826c4fd9d70d3f0 Mon Sep 17 00:00:00 2001 From: BrainL Date: Sat, 12 Apr 2025 04:50:16 +0000 Subject: [PATCH 10/13] =?UTF-8?q?=EF=BD=8D=EF=BD=8F=EF=BD=84=EF=BD=89?= =?UTF-8?q?=EF=BD=86=EF=BD=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: BrainL --- services/service/include/device_manager_service.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index ff2b08a1c..5811032c5 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -253,8 +253,6 @@ private: void SendAppUnBindBroadCast(const std::vector &peerUdids, int32_t userId, uint64_t tokenId); void SendAppUnBindBroadCast(const std::vector &peerUdids, int32_t userId, uint64_t tokenId, uint64_t peerTokenId); - void SendShareTypeUnBindBroadCast(const char *credId, const int32_t localUserId, - const std::vector &peerUdids); void SendServiceUnBindBroadCast(const std::vector &peerUdids, int32_t userId, uint64_t tokenId); void SendAccountLogoutBroadCast(const std::vector &peerUdids, const std::string &accountId, const std::string &accountName, int32_t userId); -- Gitee From 6871d721f2d2075c44cbaf64523612044a9158d4 Mon Sep 17 00:00:00 2001 From: BrainL Date: Sat, 12 Apr 2025 06:45:44 +0000 Subject: [PATCH 11/13] modify Signed-off-by: BrainL --- .../include/device_manager_service_impl.h | 1 - .../src/device_manager_service_impl.cpp | 34 ------------------- 2 files changed, 35 deletions(-) diff --git a/services/implementation/include/device_manager_service_impl.h b/services/implementation/include/device_manager_service_impl.h index 6ca4cadc5..971debc1f 100644 --- a/services/implementation/include/device_manager_service_impl.h +++ b/services/implementation/include/device_manager_service_impl.h @@ -174,7 +174,6 @@ private: std::shared_ptr hiChainAuthConnector_; std::shared_ptr listener_; std::atomic isCredentialType_ = false; - std::map deletedShareProfiles_; sptr dpInitedCallback_ = nullptr; }; diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index aef0084f1..83bb994ee 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -216,32 +216,6 @@ void DeviceManagerServiceImpl::HandleOffline(DmDeviceState devState, DmDeviceInf } } -void DeviceManagerServiceImpl::HandleDeletedAclOffline(const std::string &trustDeviceId, - const std::string &requestDeviceId, DmDeviceInfo &devInfo, ProcessInfo &processInfo, DmDeviceState &devState) -{ - int32_t userId = 0; - for (auto iter : deletedShareProfiles_) { - if (iter.second.GetAccesser().GetAccesserDeviceId() == trustDeviceId && - iter.second.GetAccessee().GetAccesseeDeviceId() == requestDeviceId) { - LOGI("HandleOffline bindType is share type, peer is src."); - deletedShareProfiles_.erase(iter.first); - return; - } - if (iter.second.GetAccesser().GetAccesserDeviceId() == requestDeviceId && - iter.second.GetAccessee().GetAccesseeDeviceId() == trustDeviceId) { - LOGI("HandleOffline bindType is share type, peer is sink."); - deletedShareProfiles_.erase(iter.first); - userId = iter.second.GetAccesser().GetAccesserUserId(); - break; - } - } - devInfo.authForm = DmAuthForm::ACROSS_ACCOUNT; - processInfo.userId = userId; - softbusConnector_->SetProcessInfo(processInfo); - deviceStateMgr_->HandleDeviceStatusChange(devState, devInfo); - return; -} - void DeviceManagerServiceImpl::HandleOnline(DmDeviceState devState, DmDeviceInfo &devInfo) { LOGI("DeviceManagerServiceImpl::HandleOnline networkId: %{public}s.", @@ -1199,8 +1173,6 @@ void DeviceManagerServiceImpl::HandleCredentialDeleted(const char *credId, const item.GetAccessee().GetAccesseeDeviceId() == localUdid && item.GetAccesser().GetAccesserUserId() == userId && item.GetAccesser().GetAccesserDeviceId() == remoteUdid)) { - deletedShareProfiles_[remoteUdid] = item; - LOGI("DM_SHARE_TYPE in, profiles_ size is %{public}zu.", deletedShareProfiles_.size()); DeviceProfileConnector::GetInstance().DeleteAccessControlById(item.GetAccessControlId()); } } @@ -1228,17 +1200,11 @@ void DeviceManagerServiceImpl::HandleShareUnbindBroadCast(const std::string &cre if (accesserCredId == credId && item.GetAccessee().GetAccesseeDeviceId() == localUdid && item.GetAccesser().GetAccesserUserId() == userId) { std::string remoteUdid = item.GetAccesser().GetAccesserDeviceId(); - deletedShareProfiles_[remoteUdid] = item; - LOGI("HandleShareUnbindBroadCast local is sink, profiles_ size is %{public}zu.", - deletedShareProfiles_.size()); DeviceProfileConnector::GetInstance().DeleteAccessControlById(item.GetAccessControlId()); } if (accesseeCredId == credId && item.GetAccesser().GetAccesserDeviceId() == localUdid && item.GetAccessee().GetAccesseeUserId() == userId) { std::string remoteUdid = item.GetAccessee().GetAccesseeDeviceId(); - deletedShareProfiles_[remoteUdid] = item; - LOGI("HandleShareUnbindBroadCast local is src, profiles_ size is %{public}zu.", - deletedShareProfiles_.size()); DeviceProfileConnector::GetInstance().DeleteAccessControlById(item.GetAccessControlId()); } } -- Gitee From 87c7b947210a75e1ba9633b39dc3a3d65965167a Mon Sep 17 00:00:00 2001 From: BrainL Date: Mon, 14 Apr 2025 10:13:36 +0800 Subject: [PATCH 12/13] modify Signed-off-by: BrainL --- services/implementation/src/device_manager_service_impl.cpp | 2 -- test/commonunittest/UTTest_dm_deviceprofile_connector.cpp | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 83bb994ee..3a79cbedf 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -1199,12 +1199,10 @@ void DeviceManagerServiceImpl::HandleShareUnbindBroadCast(const std::string &cre accesserCredId.c_str(), accesseeCredId.c_str()); if (accesserCredId == credId && item.GetAccessee().GetAccesseeDeviceId() == localUdid && item.GetAccesser().GetAccesserUserId() == userId) { - std::string remoteUdid = item.GetAccesser().GetAccesserDeviceId(); DeviceProfileConnector::GetInstance().DeleteAccessControlById(item.GetAccessControlId()); } if (accesseeCredId == credId && item.GetAccesser().GetAccesserDeviceId() == localUdid && item.GetAccessee().GetAccesseeUserId() == userId) { - std::string remoteUdid = item.GetAccessee().GetAccesseeDeviceId(); DeviceProfileConnector::GetInstance().DeleteAccessControlById(item.GetAccessControlId()); } } diff --git a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp index 9a82df953..ee730a027 100644 --- a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp +++ b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp @@ -1985,7 +1985,7 @@ HWTEST_F(DeviceProfileConnectorTest, CheckBindType_004, testing::ext::TestSize.L EXPECT_CALL(*multipleUserConnectorMock_, GetFirstForegroundUserId()).WillOnce(Return(1234)); ret = DeviceProfileConnector::GetInstance().CheckBindType(peerUdid, localUdid); - EXPECT_EQ(ret, 5); + EXPECT_EQ(ret, 6); } HWTEST_F(DeviceProfileConnectorTest, GetTokenIdByNameAndDeviceId_001, testing::ext::TestSize.Level1) -- Gitee From 013538d9be6fcbd03ab0f1fc14f4978dda15d1dd Mon Sep 17 00:00:00 2001 From: BrainL Date: Mon, 14 Apr 2025 21:45:35 +0800 Subject: [PATCH 13/13] modify Signed-off-by: BrainL --- test/unittest/UTTest_device_manager_service_impl.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/unittest/UTTest_device_manager_service_impl.cpp b/test/unittest/UTTest_device_manager_service_impl.cpp index b8b947ac7..a57d3c984 100644 --- a/test/unittest/UTTest_device_manager_service_impl.cpp +++ b/test/unittest/UTTest_device_manager_service_impl.cpp @@ -1753,6 +1753,10 @@ HWTEST_F(DeviceManagerServiceImplTest, HandleOnline_003, testing::ext::TestSize. EXPECT_CALL(*deviceProfileConnectorMock_, CheckBindType(_, _)).WillOnce(Return(DEVICE_ACROSS_ACCOUNT_TYPE)); deviceManagerServiceImpl_->HandleOnline(devState, devInfo); + EXPECT_CALL(*softbusConnectorMock_, GetUdidByNetworkId(_, _)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*deviceProfileConnectorMock_, CheckBindType(_, _)).WillOnce(Return(SHARE_TYPE)); + deviceManagerServiceImpl_->HandleOnline(devState, devInfo); + std::vector profiles; EXPECT_CALL(*softbusConnectorMock_, GetUdidByNetworkId(_, _)).WillOnce(Return(DM_OK)); EXPECT_CALL(*deviceProfileConnectorMock_, CheckBindType(_, _)).WillOnce(Return(APP_PEER_TO_PEER_TYPE)); -- Gitee