diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index b69113c97f3262533dc5d5854d1cc480573f4386..fe13ee3b9e76256070fdd66acee5337ecea68df9 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -138,13 +138,10 @@ public: virtual int32_t GetDeviceAclParam(DmDiscoveryInfo discoveryInfo, bool &isOnline, int32_t &authForm) = 0; virtual std::map GetDeviceIdAndBindLevel(std::vector userIds, const std::string &localUdid) = 0; - virtual int32_t HandleUserSwitched(const std::string &localUdid, const std::vector &deviceVec, - const std::vector &foregroundUserIds, const std::vector &backgroundUserIds) = 0; virtual bool CheckAclStatusAndForegroundNotMatch(const std::string &localUdid, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds) = 0; - virtual int32_t HandleUserStop(int32_t stopUserId, const std::string &stopEventUdid) = 0; - virtual int32_t HandleUserStop(int32_t stopUserId, const std::string &localUdid, - const std::vector &acceptEventUdids) = 0; + virtual int32_t HandleAccountCommonEvent(const std::string &localUdid, const std::vector &deviceVec, + const std::vector &foregroundUserIds, const std::vector &backgroundUserIds) = 0; }; class DeviceProfileConnector : public IDeviceProfileConnector { @@ -220,16 +217,9 @@ public: GetAllAccessControlProfile(); DM_EXPORT std::vector GetAllAclIncludeLnnAcl(); DM_EXPORT void DeleteAccessControlById(int64_t accessControlId); - DM_EXPORT int32_t HandleUserSwitched(const std::string &localUdid, - const std::vector &deviceVec, int32_t currentUserId, int32_t beforeUserId); - DM_EXPORT int32_t HandleUserSwitched(const std::string &localUdid, - const std::vector &deviceVec, const std::vector &foregroundUserIds, - const std::vector &backgroundUserIds); bool CheckAclStatusAndForegroundNotMatch(const std::string &localUdid, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds); - DM_EXPORT void HandleUserSwitched( - const std::vector &activeProfiles, - const std::vector &inActiveProfiles); + DM_EXPORT void HandleSyncForegroundUserIdEvent( const std::vector &remoteUserIds, const std::string &remoteUdid, const std::vector &localUserIds, std::string &localUdid); @@ -237,9 +227,9 @@ public: const std::string &remoteUdid, const std::vector &remoteUserIds); DM_EXPORT std::map GetUserIdAndBindLevel( const std::string &localUdid, const std::string &peerUdid); - DM_EXPORT void UpdateACL(std::string &localUdid, - const std::vector &localUserIds, const std::string &remoteUdid, - const std::vector &remoteFrontUserIds, const std::vector &remoteBackUserIds); + DM_EXPORT void UpdateACL(std::string &localUdid, const std::vector &localUserIds, + const std::string &remoteUdid, const std::vector &remoteFrontUserIds, + const std::vector &remoteBackUserIds, DmOfflineParam &offlineParam); DM_EXPORT std::multimap GetDevIdAndUserIdByActHash( const std::string &localUdid, const std::string &peerUdid, int32_t peerUserId, const std::string &peerAccountHash); @@ -272,9 +262,6 @@ public: DistributedDeviceProfile::LocalServiceInfo &localServiceInfo); DM_EXPORT int32_t PutSessionKey(int32_t userId, const std::vector &sessionKeyArray, int32_t &sessionKeyId); - int32_t HandleUserStop(int32_t stopUserId, const std::string &stopEventUdid); - int32_t HandleUserStop(int32_t stopUserId, const std::string &localUdid, - const std::vector &acceptEventUdids); DM_EXPORT std::string IsAuthNewVersion(int32_t bindLevel, std::string localUdid, std::string remoteUdid, int32_t tokenId, int32_t userId); std::vector GetAclProfileByDeviceIdAndUserId( @@ -311,6 +298,8 @@ public: DM_EXPORT void AclHashVecFromJson(const JsonItemObject &itemObject, std::vector &values); void DeleteCacheAcl(std::vector delAclIdVec, std::vector &profiles); + DM_EXPORT int32_t HandleAccountCommonEvent(const std::string &localUdid, const std::vector &deviceVec, + const std::vector &foregroundUserIds, const std::vector &backgroundUserIds); private: int32_t HandleDmAuthForm(DistributedDeviceProfile::AccessControlProfile profiles, DmDiscoveryInfo discoveryInfo); void GetParamBindTypeVec(DistributedDeviceProfile::AccessControlProfile profiles, std::string requestDeviceId, @@ -342,7 +331,8 @@ private: std::vector GetAclProfileByUserId(const std::string &localUdid, int32_t userId, const std::string &remoteUdid); void DeleteSigTrustACL(DistributedDeviceProfile::AccessControlProfile profile, const std::string &remoteUdid, - const std::vector &remoteFrontUserIds, const std::vector &remoteBackUserIds); + const std::vector &remoteFrontUserIds, const std::vector &remoteBackUserIds, + DmOfflineParam &offlineParam); void UpdatePeerUserId(DistributedDeviceProfile::AccessControlProfile profile, std::string &localUdid, const std::vector &localUserIds, const std::string &remoteUdid, const std::vector &remoteFrontUserIds); diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 4f00c859db8fcba83895587b60ad5938f193b39d..1a41122e2f83fb13ee3df5060d986b43c8da4a10 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -2042,57 +2042,6 @@ DM_EXPORT void DeviceProfileConnector::DeleteAccessControlById( DistributedDeviceProfileClient::GetInstance().DeleteAccessControlProfile(accessControlId); } -DM_EXPORT int32_t DeviceProfileConnector::HandleUserSwitched( - const std::string &localUdid, const std::vector &deviceVec, int32_t currentUserId, - int32_t beforeUserId) -{ - if (deviceVec.empty()) { - LOGI("no remote device."); - return DM_OK; - } - std::vector profiles = GetAllAclIncludeLnnAcl(); - std::vector activeProfiles; - std::vector inActiveProfiles; - for (auto &item : profiles) { - if (std::find(deviceVec.begin(), deviceVec.end(), item.GetTrustDeviceId()) == deviceVec.end()) { - continue; - } - if ((item.GetAccesser().GetAccesserDeviceId() == localUdid && - item.GetAccesser().GetAccesserUserId() == beforeUserId) || - (item.GetAccessee().GetAccesseeDeviceId() == localUdid && - item.GetAccessee().GetAccesseeUserId() == beforeUserId)) { - if (item.GetStatus() == ACTIVE) { - item.SetStatus(INACTIVE); - inActiveProfiles.push_back(item); - } - continue; - } - if ((item.GetAccesser().GetAccesserDeviceId() == localUdid && - item.GetAccesser().GetAccesserUserId() == currentUserId && item.GetStatus() == INACTIVE) || ( - item.GetAccessee().GetAccesseeDeviceId() == localUdid && - item.GetAccessee().GetAccesseeUserId() == currentUserId && item.GetStatus() == INACTIVE)) { - item.SetStatus(ACTIVE); - activeProfiles.push_back(item); - continue; - } - } - HandleUserSwitched(activeProfiles, inActiveProfiles); - return DM_OK; -} - -DM_EXPORT void DeviceProfileConnector::HandleUserSwitched( - const std::vector &activeProfiles, - const std::vector &inActiveProfiles) -{ - for (auto &item : inActiveProfiles) { - DistributedDeviceProfileClient::GetInstance().UpdateAccessControlProfile(item); - } - - for (auto &item : activeProfiles) { - DistributedDeviceProfileClient::GetInstance().UpdateAccessControlProfile(item); - } -} - std::vector DeviceProfileConnector::GetAclProfileByUserId(const std::string &localUdid, int32_t userId, const std::string &remoteUdid) { @@ -2225,21 +2174,23 @@ DM_EXPORT std::map DeviceProfileConnector::GetUserIdAndBindLev DM_EXPORT void DeviceProfileConnector::UpdateACL(std::string &localUdid, const std::vector &localUserIds, const std::string &remoteUdid, - const std::vector &remoteFrontUserIds, const std::vector &remoteBackUserIds) + const std::vector &remoteFrontUserIds, const std::vector &remoteBackUserIds, + DmOfflineParam &offlineParam) { LOGI("localUdid %{public}s, remoteUdid %{public}s.", GetAnonyString(localUdid).c_str(), GetAnonyString(remoteUdid).c_str()); std::vector profiles = GetAllAclIncludeLnnAcl(); for (auto item : profiles) { // deleta signal trust acl. - DeleteSigTrustACL(item, remoteUdid, remoteFrontUserIds, remoteBackUserIds); + DeleteSigTrustACL(item, remoteUdid, remoteFrontUserIds, remoteBackUserIds, offlineParam); // update identical account userId. UpdatePeerUserId(item, localUdid, localUserIds, remoteUdid, remoteFrontUserIds); } } void DeviceProfileConnector::DeleteSigTrustACL(AccessControlProfile profile, const std::string &remoteUdid, - const std::vector &remoteFrontUserIds, const std::vector &remoteBackUserIds) + const std::vector &remoteFrontUserIds, const std::vector &remoteBackUserIds, + DmOfflineParam &offlineParam) { LOGI("start."); std::string accesserUdid = profile.GetAccesser().GetAccesserDeviceId(); @@ -2249,13 +2200,13 @@ void DeviceProfileConnector::DeleteSigTrustACL(AccessControlProfile profile, con if (accesserUdid == remoteUdid && accesserUserid != 0 && accesserUserid != -1 && find(remoteFrontUserIds.begin(), remoteFrontUserIds.end(), accesserUserid) == remoteFrontUserIds.end() && find(remoteBackUserIds.begin(), remoteBackUserIds.end(), accesserUserid) == remoteBackUserIds.end()) { - DistributedDeviceProfileClient::GetInstance().DeleteAccessControlProfile(profile.GetAccessControlId()); + CacheAcerAclId(profile, offlineParam.needDelAclInfos); return; } if (accesseeUdid == remoteUdid && accesseeUserid != 0 && accesseeUserid != -1 && find(remoteFrontUserIds.begin(), remoteFrontUserIds.end(), accesseeUserid) == remoteFrontUserIds.end() && find(remoteBackUserIds.begin(), remoteBackUserIds.end(), accesseeUserid) == remoteBackUserIds.end()) { - DistributedDeviceProfileClient::GetInstance().DeleteAccessControlProfile(profile.GetAccessControlId()); + CacheAceeAclId(profile, offlineParam.needDelAclInfos); return; } } @@ -2583,12 +2534,10 @@ bool DeviceProfileConnector::CheckAclStatusNotMatch(const DistributedDeviceProfi { if ((profile.GetAccesser().GetAccesserDeviceId() == localUdid && (find(backgroundUserIds.begin(), backgroundUserIds.end(), profile.GetAccesser().GetAccesserUserId()) != - backgroundUserIds.end()) && - (profile.GetStatus() == ACTIVE || profile.GetBindType() != DM_IDENTICAL_ACCOUNT)) || + backgroundUserIds.end()) && (profile.GetStatus() == ACTIVE)) || (profile.GetAccessee().GetAccesseeDeviceId() == localUdid && (find(backgroundUserIds.begin(), backgroundUserIds.end(), profile.GetAccessee().GetAccesseeUserId()) != - backgroundUserIds.end()) && - (profile.GetStatus() == ACTIVE || profile.GetBindType() != DM_IDENTICAL_ACCOUNT))) { + backgroundUserIds.end()) && (profile.GetStatus() == ACTIVE))) { return true; } if ((profile.GetAccesser().GetAccesserDeviceId() == localUdid && @@ -2615,11 +2564,11 @@ bool DeviceProfileConnector::CheckAclStatusAndForegroundNotMatch(const std::stri return false; } -DM_EXPORT int32_t DeviceProfileConnector::HandleUserSwitched( +DM_EXPORT int32_t DeviceProfileConnector::HandleAccountCommonEvent( const std::string &localUdid, const std::vector &deviceVec, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds) { - LOGI("OnStart HandleUserSwitched"); + LOGI("HandleAccountCommonEvent start"); if (deviceVec.empty()) { LOGI("no remote device."); return DM_OK; @@ -2633,14 +2582,12 @@ DM_EXPORT int32_t DeviceProfileConnector::HandleUserSwitched( } if ((item.GetAccesser().GetAccesserDeviceId() == localUdid && (find(backgroundUserIds.begin(), backgroundUserIds.end(), - item.GetAccesser().GetAccesserUserId()) != backgroundUserIds.end())) || + item.GetAccesser().GetAccesserUserId()) != backgroundUserIds.end()) && item.GetStatus() == ACTIVE) || (item.GetAccessee().GetAccesseeDeviceId() == localUdid && (find(backgroundUserIds.begin(), backgroundUserIds.end(), - item.GetAccessee().GetAccesseeUserId()) != backgroundUserIds.end()))) { - if (item.GetStatus() == ACTIVE) { - item.SetStatus(INACTIVE); - inActiveProfiles.push_back(item); - } + item.GetAccessee().GetAccesseeUserId()) != backgroundUserIds.end()) && item.GetStatus() == ACTIVE)) { + item.SetStatus(INACTIVE); + inActiveProfiles.push_back(item); continue; } if ((item.GetAccesser().GetAccesserDeviceId() == localUdid && @@ -2654,45 +2601,11 @@ DM_EXPORT int32_t DeviceProfileConnector::HandleUserSwitched( continue; } } - HandleUserSwitched(activeProfiles, inActiveProfiles); - return DM_OK; -} - -int32_t DeviceProfileConnector::HandleUserStop(int32_t stopUserId, const std::string &stopEventUdid) -{ - std::vector profiles = GetAllAclIncludeLnnAcl(); - for (auto &item : profiles) { - if ((item.GetAccesser().GetAccesserDeviceId() == stopEventUdid && - item.GetAccesser().GetAccesserUserId() == stopUserId && item.GetStatus() == ACTIVE) || - (item.GetAccessee().GetAccesseeDeviceId() == stopEventUdid && - item.GetAccessee().GetAccesseeUserId() == stopUserId && item.GetStatus() == ACTIVE)) { - item.SetStatus(INACTIVE); - DistributedDeviceProfileClient::GetInstance().UpdateAccessControlProfile(item); - } - } - return DM_OK; -} - -int32_t DeviceProfileConnector::HandleUserStop(int32_t stopUserId, const std::string &stopEventUdid, - const std::vector &acceptEventUdids) -{ - if (acceptEventUdids.empty()) { - LOGI("no remote device."); - return DM_OK; + for (auto &item : inActiveProfiles) { + DistributedDeviceProfileClient::GetInstance().UpdateAccessControlProfile(item); } - std::vector profiles = GetAllAclIncludeLnnAcl(); - for (auto &item : profiles) { - if (std::find(acceptEventUdids.begin(), acceptEventUdids.end(), item.GetTrustDeviceId()) == - acceptEventUdids.end()) { - continue; - } - if ((item.GetAccesser().GetAccesserDeviceId() == stopEventUdid && - item.GetAccesser().GetAccesserUserId() == stopUserId && item.GetStatus() == ACTIVE) || - (item.GetAccessee().GetAccesseeDeviceId() == stopEventUdid && - item.GetAccessee().GetAccesseeUserId() == stopUserId && item.GetStatus() == ACTIVE)) { - item.SetStatus(INACTIVE); - DistributedDeviceProfileClient::GetInstance().UpdateAccessControlProfile(item); - } + for (auto &item : activeProfiles) { + DistributedDeviceProfileClient::GetInstance().UpdateAccessControlProfile(item); } return DM_OK; } diff --git a/services/implementation/include/device_manager_service_impl.h b/services/implementation/include/device_manager_service_impl.h index 65779f7b3ffe14b0f8a83d9a9023961f01ab496d..d00f191b29f663a4e066da300b8f8f4be2021fd0 100644 --- a/services/implementation/include/device_manager_service_impl.h +++ b/services/implementation/include/device_manager_service_impl.h @@ -155,10 +155,6 @@ public: int32_t GetAclListHash(const DevUserInfo &localDevUserInfo, const DevUserInfo &remoteDevUserInfo, std::string &aclList); int32_t ProcessAppUnintall(const std::string &appId, int32_t accessTokenId); - void HandleSyncUserIdEvent(const std::vector &foregroundUserIds, - const std::vector &backgroundUserIds, const std::string &remoteUdid, bool isCheckUserStatus); - void HandleUserSwitched(const std::vector &deviceVec, int32_t currentUserId, - int32_t beforeUserId); std::multimap GetDeviceIdAndUserId(int32_t localUserId); int32_t SaveOnlineDeviceInfo(const std::vector &deviceList); void HandleDeviceUnBind(int32_t bindType, const std::string &peerUdid, @@ -177,7 +173,8 @@ public: int32_t DeleteGroup(const std::string &pkgName, const std::string &deviceId); int32_t InitAndRegisterAuthMgr(bool isSrcSide, uint64_t tokenId, std::shared_ptr session, uint64_t logicalSessionId); - + void HandleCommonEventBroadCast(const std::vector &foregroundUserIds, + const std::vector &backgroundUserIds, const std::string &remoteUdid); private: int32_t PraseNotifyEventJson(const std::string &event, JsonObject &jsonObject); std::string GetUdidHashByNetworkId(const std::string &networkId); diff --git a/services/implementation/include/device_manager_service_impl_lite.h b/services/implementation/include/device_manager_service_impl_lite.h index 30d1a279b009d7fc019b4a0243fd8158462298eb..da225137cf381855bb0dd8c1717597d8d550f4b7 100644 --- a/services/implementation/include/device_manager_service_impl_lite.h +++ b/services/implementation/include/device_manager_service_impl_lite.h @@ -142,8 +142,6 @@ public: int32_t peerUserId); void HandleUserRemoved(std::vector peerUdids, int32_t preUserId); void HandleDeviceScreenStatusChange(DmDeviceInfo &devInfo); - void HandleUserSwitched(const std::vector &deviceVec, int32_t currentUserId, - int32_t beforeUserId); int32_t StopAuthenticateDevice(const std::string &pkgName); void HandleCredentialAuthStatus(const std::string &deviceList, uint16_t deviceTypeId, int32_t errcode); int32_t SyncLocalAclListProcess(const DevUserInfo &localDevUserInfo, @@ -151,8 +149,6 @@ public: int32_t GetAclListHash(const DevUserInfo &localDevUserInfo, const DevUserInfo &remoteDevUserInfo, std::string &aclList); int32_t ProcessAppUnintall(const std::string &appId, int32_t accessTokenId); - void HandleSyncUserIdEvent(const std::vector &foregroundUserIds, - const std::vector &backgroundUserIds, const std::string &remoteUdid, bool isCheckUserStatus); void HandleRemoteUserRemoved(int32_t preUserId, const std::string &remoteUdid); std::map GetDeviceIdAndBindLevel(int32_t userId); std::multimap GetDeviceIdAndUserId(int32_t localUserId); @@ -165,6 +161,8 @@ public: int32_t CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId); void HandleServiceUnBindEvent(int32_t userId, const std::string &remoteUdid, int32_t remoteTokenId); + void HandleCommonEventBroadCast(const std::vector &foregroundUserIds, + const std::vector &backgroundUserIds, const std::string &remoteUdid); 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 11550d299176ea45d8a1706a1ef2f1b4d17e33f3..81c46db4d894af00f03c80174bd3a68271cd07f7 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -1721,17 +1721,6 @@ void DeviceManagerServiceImpl::HandleRemoteUserRemoved(int32_t userId, const std DeleteSkCredAndAcl(offlineParam.needDelAclInfos); } -void DeviceManagerServiceImpl::HandleUserSwitched(const std::vector &deviceVec, - int32_t currentUserId, int32_t beforeUserId) -{ - LOGI("currentUserId: %{public}s, beforeUserId: %{public}s", GetAnonyInt32(currentUserId).c_str(), - GetAnonyInt32(beforeUserId).c_str()); - char localDeviceId[DEVICE_UUID_LENGTH] = {0}; - GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); - std::string localUdid = static_cast(localDeviceId); - DeviceProfileConnector::GetInstance().HandleUserSwitched(localUdid, deviceVec, currentUserId, beforeUserId); -} - void DeviceManagerServiceImpl::ScreenCommonEventCallback(std::string commonEventType) { if (commonEventType == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_LOCKED) { @@ -1979,15 +1968,12 @@ void DeviceManagerServiceImpl::HandleServiceUnBindEvent(int32_t userId, const st DeleteSkCredAndAcl(offlineParam.needDelAclInfos); } -void DeviceManagerServiceImpl::HandleSyncUserIdEvent(const std::vector &foregroundUserIds, - const std::vector &backgroundUserIds, const std::string &remoteUdid, bool isCheckUserStatus) +void DeviceManagerServiceImpl::HandleCommonEventBroadCast(const std::vector &foregroundUserIds, + const std::vector &backgroundUserIds, const std::string &remoteUdid) { LOGI("remote udid: %{public}s, foregroundUserIds: %{public}s, backgroundUserIds: %{public}s", GetAnonyString(remoteUdid).c_str(), GetIntegerList(foregroundUserIds).c_str(), GetIntegerList(backgroundUserIds).c_str()); - char localUdidTemp[DEVICE_UUID_LENGTH] = {0}; - GetDevUdid(localUdidTemp, DEVICE_UUID_LENGTH); - std::string localUdid = std::string(localUdidTemp); std::vector rmtFrontUserIdsTemp(foregroundUserIds.begin(), foregroundUserIds.end()); std::vector rmtBackUserIdsTemp(backgroundUserIds.begin(), backgroundUserIds.end()); std::vector localUserIds; @@ -1996,11 +1982,14 @@ void DeviceManagerServiceImpl::HandleSyncUserIdEvent(const std::vector LOGE("Get foreground userids failed, ret: %{public}d", ret); return; } - if (isCheckUserStatus) { - MultipleUserConnector::ClearLockedUser(localUserIds); - } + char localUdidTemp[DEVICE_UUID_LENGTH] = {0}; + GetDevUdid(localUdidTemp, DEVICE_UUID_LENGTH); + std::string localUdid = std::string(localUdidTemp); + MultipleUserConnector::ClearLockedUser(localUserIds); + DmOfflineParam offlineParam; DeviceProfileConnector::GetInstance().UpdateACL(localUdid, localUserIds, remoteUdid, - rmtFrontUserIdsTemp, rmtBackUserIdsTemp); + rmtFrontUserIdsTemp, rmtBackUserIdsTemp, offlineParam); + DeleteSkCredAndAcl(offlineParam.needDelAclInfos); DeviceProfileConnector::GetInstance().HandleSyncBackgroundUserIdEvent(rmtBackUserIdsTemp, remoteUdid, localUserIds, localUdid); DeviceProfileConnector::GetInstance().HandleSyncForegroundUserIdEvent(rmtFrontUserIdsTemp, remoteUdid, diff --git a/services/implementation/src/device_manager_service_impl_lite.cpp b/services/implementation/src/device_manager_service_impl_lite.cpp index 26f39c7aa56bb3931344c9292c2a50b427433613..ae1095b86eea77496da195e605584a02445ecdc3 100644 --- a/services/implementation/src/device_manager_service_impl_lite.cpp +++ b/services/implementation/src/device_manager_service_impl_lite.cpp @@ -512,15 +512,6 @@ void DeviceManagerServiceImpl::HandleDeviceScreenStatusChange(DmDeviceInfo &devI return; } -void DeviceManagerServiceImpl::HandleUserSwitched(const std::vector &deviceVec, - int32_t currentUserId, int32_t beforeUserId) -{ - (void)deviceVec; - (void)currentUserId; - (void)beforeUserId; - return; -} - int32_t DeviceManagerServiceImpl::StopAuthenticateDevice(const std::string &pkgName) { (void)pkgName; @@ -561,16 +552,6 @@ int32_t DeviceManagerServiceImpl::ProcessAppUnintall(const std::string &appId, i return 0; } -void DeviceManagerServiceImpl::HandleSyncUserIdEvent(const std::vector &foregroundUserIds, - const std::vector &backgroundUserIds, const std::string &remoteUdid, bool isCheckUserStatus) -{ - (void)foregroundUserIds; - (void)backgroundUserIds; - (void)remoteUdid; - (void)isCheckUserStatus; - return; -} - void DeviceManagerServiceImpl::HandleRemoteUserRemoved(int32_t preUserId, const std::string &remoteUdid) { (void)preUserId; @@ -642,6 +623,15 @@ void DeviceManagerServiceImpl::HandleServiceUnBindEvent(int32_t userId, const st return; } +void DeviceManagerServiceImpl::HandleCommonEventBroadCast(const std::vector &foregroundUserIds, + const std::vector &backgroundUserIds, const std::string &remoteUdid) +{ + (void)foregroundUserIds; + (void)backgroundUserIds; + (void)remoteUdid; + return; +} + extern "C" IDeviceManagerServiceImpl *CreateDMServiceObject(void) { return new DeviceManagerServiceImpl; diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index a6f5c58c9a9cbc888cbeba225d933c6ef2bf1822..331347a471bc0c392ef2f4db8129b43a36072a1f 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -191,12 +191,12 @@ public: bool CheckAccessControl(const DmAccessCaller &caller, const DmAccessCallee &callee); bool CheckIsSameAccount(const DmAccessCaller &caller, const DmAccessCallee &callee); void HandleDeviceNotTrust(const std::string &msg); + IDeviceProfileConnector* GetCommonDependencyObj(); + bool IsCommonDependencyReady(); + bool CloseCommonDependencyObj(); #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) void HandleDeviceTrustedChange(const std::string &msg); void HandleUserIdCheckSumChange(const std::string &msg); - void HandleUserStop(int32_t stopUserId, const std::string &stopEventUdid); - void HandleUserStop(int32_t stopUserId, const std::string &stopEventUdid, - const std::vector &acceptEventUdids); #endif int32_t SetDnPolicy(const std::string &pkgName, std::map &policy); void ClearDiscoveryCache(const ProcessInfo &processInfo); @@ -210,8 +210,6 @@ public: const DevUserInfo &remoteDevUserInfo, std::string remoteAclList); int32_t GetAclListHash(const DevUserInfo &localDevUserInfo, const DevUserInfo &remoteDevUserInfo, std::string &aclList); - void ProcessSyncUserIds(const std::vector &foregroundUserIds, - const std::vector &backgroundUserIds, const std::string &remoteUdid); int32_t SetLocalDisplayNameToSoftbus(const std::string &displayName); void RemoveNotifyRecord(const ProcessInfo &processInfo); int32_t RegDevStateCallbackToService(const std::string &pkgName); @@ -241,6 +239,8 @@ public: int32_t GetDeviceNetworkIdList(const std::string &pkgName, const NetworkIdQueryFilter &queryFilter, std::vector &networkIds); void ProcessSyncAccountLogout(const std::string &accountId, const std::string &peerUdid, int32_t userId); + void ProcessCommonEvent(const std::vector &foregroundUserIds, + const std::vector &backgroundUserIds, const std::string &remoteUdid); int32_t UnRegisterPinHolderCallback(const std::string &pkgName); private: @@ -306,43 +306,31 @@ private: * @param currentUserId the user id which switched to foreground. * @param beforeUserId the user id which switched to backend. */ - void HandleUserSwitched(int32_t curUserId, int32_t preUserId); - void HandleUserIdsBroadCast(const std::vector &remoteUserIdInfos, - const std::string &remoteUdid, bool isNeedResponse); - 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, - const std::map &wifiDevices, const std::vector &foregroundUserIds, - const std::vector &backgroundUserIds); - int32_t SendUserIdsByWifi(const std::string &networkId, const std::vector &foregroundUserIds, - const std::vector &backgroundUserIds); - void HandleUserSwitchTimeout(int32_t curUserId, int32_t preUserId, const std::string &udid); bool InitDPLocalServiceInfo(const DMLocalServiceInfo &serviceInfo, DistributedDeviceProfile::LocalServiceInfo &dpLocalServiceItem); void InitServiceInfo(const DistributedDeviceProfile::LocalServiceInfo &dpLocalServiceItem, DMLocalServiceInfo &serviceInfo); void InitServiceInfos(const std::vector &dpLocalServiceItems, std::vector &serviceInfos); - void HandleUserSwitched(); - void NotifyRemoteLocalUserSwitch(const std::string &localUdid, const std::vector &peerUdids, - const std::vector &foregroundUserIds, const std::vector &backgroundUserIds); - void NotifyRemoteLocalUserSwitchByWifi(const std::string &localUdid, + void HandleAccountCommonEvent(const std::string commonEventType); + bool CheckUserIdMatch(std::vector foregroundUserVec, std::vector backgroundUserVec); + void NotifyRemoteAccountCommonEvent(const std::string commonEventType, const std::string &localUdid, + const std::vector &peerUdids, const std::vector &foregroundUserIds, + const std::vector &backgroundUserIds); + void NotifyRemoteAccountCommonEventByWifi(const std::string &localUdid, const std::map &wifiDevices, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds); - void HandleUserSwitchTimeout(const std::string &localUdid, const std::vector &foregroundUserIds, + int32_t SendAccountCommonEventByWifi(const std::string &networkId, + const std::vector &foregroundUserIds, const std::vector &backgroundUserIds); + void HandleCommonEventTimeout(const std::string &localUdid, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds, const std::string &udid); - void UpdateAclAndDeleteGroup(const std::string &localUdid, const std::vector &deviceVec, + void UpdateAcl(const std::string &localUdid, const std::vector &peerUdids, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds); - void HandleUserSwitchedEvent(int32_t currentUserId, int32_t beforeUserId); - void HandleUserStopEvent(int32_t stopUserId); - void DivideNotifyMethod(const std::vector &peerUdids, std::vector &bleUdids, - std::map &wifiDevices); - void NotifyRemoteLocalUserStop(const std::string &localUdid, - const std::vector &peerUdids, int32_t stopUserId); - void SendUserStopBroadCast(const std::vector &peerUdids, int32_t stopUserId); - void HandleUserStopBroadCast(int32_t stopUserId, const std::string &remoteUdid); - void NotifyRemoteLocalUserStopByWifi(const std::string &localUdid, - const std::map &wifiDevices, int32_t stopUserId); + void HandleCommonEventBroadCast(const std::vector &remoteUserIdInfos, + const std::string &remoteUdid, bool isNeedResponse); + void SendCommonEventBroadCast(const std::vector &peerUdids, + const std::vector &foregroundUserIds, const std::vector &backgroundUserIds, + bool isNeedResponse); #if defined(SUPPORT_BLUETOOTH) || defined(SUPPORT_WIFI) void SubscribePublishCommonEvent(); void QueryDependsSwitchState(); @@ -373,6 +361,8 @@ private: std::shared_ptr accountCommonEventManager_; std::shared_ptr packageCommonEventManager_; std::shared_ptr screenCommonEventManager_; + std::vector foregroundUserVec_; + std::vector backgroundUserVec_; #if defined(SUPPORT_BLUETOOTH) || defined(SUPPORT_WIFI) std::shared_ptr publshCommonEventManager_; #endif // SUPPORT_BLUETOOTH SUPPORT_WIFI @@ -380,6 +370,10 @@ private: #endif std::string localNetWorkId_ = ""; std::shared_ptr timer_; + bool isSoLoaded_; + void *dpConnectorHandle_; + std::mutex comDependencyLoadLock_; + IDeviceProfileConnector *dpConnector_; }; } // 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 fa2ae7ca36fc4ecce096394dc23bc97cc6f99911..9f725838214e4f16e144eb40091066e0748d4f6b 100644 --- a/services/service/include/idevice_manager_service_impl.h +++ b/services/service/include/idevice_manager_service_impl.h @@ -242,8 +242,6 @@ public: const std::string &peerUdid, int32_t peerUserId) = 0; virtual void HandleUserRemoved(std::vector peerUdids, int32_t preUserId) = 0; virtual void HandleDeviceScreenStatusChange(DmDeviceInfo &devInfo) = 0; - virtual void HandleUserSwitched(const std::vector &deviceVec, int32_t currentUserId, - int32_t beforeUserId) = 0; virtual int32_t StopAuthenticateDevice(const std::string &pkgName) = 0; virtual void HandleCredentialAuthStatus(const std::string &deviceList, uint16_t deviceTypeId, int32_t errcode) = 0; @@ -252,8 +250,6 @@ public: virtual int32_t GetAclListHash(const DevUserInfo &localDevUserInfo, const DevUserInfo &remoteDevUserInfo, std::string &aclList) = 0; virtual int32_t ProcessAppUnintall(const std::string &appId, int32_t accessTokenId) = 0; - virtual void HandleSyncUserIdEvent(const std::vector &foregroundUserIds, - const std::vector &backgroundUserIds, const std::string &remoteUdid, bool isCheckUserStatus) = 0; virtual void HandleRemoteUserRemoved(int32_t userId, const std::string &remoteUdid) = 0; virtual std::map GetDeviceIdAndBindLevel(int32_t userId) = 0; virtual std::multimap GetDeviceIdAndUserId(int32_t localUserId) = 0; @@ -266,6 +262,8 @@ public: virtual int32_t CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId) = 0; virtual void HandleServiceUnBindEvent(int32_t userId, const std::string &remoteUdid, int32_t remoteTokenId) = 0; + virtual void HandleCommonEventBroadCast(const std::vector &foregroundUserIds, + const std::vector &backgroundUserIds, const std::string &remoteUdid) = 0; }; using CreateDMServiceFuncPtr = IDeviceManagerServiceImpl *(*)(void); diff --git a/services/service/include/relationshipsyncmgr/dm_comm_tool.h b/services/service/include/relationshipsyncmgr/dm_comm_tool.h index d60b00071748ae65af440cd7d58d020a75f21c82..a0fcf73215f85cafe9e020da574620a02e347836 100644 --- a/services/service/include/relationshipsyncmgr/dm_comm_tool.h +++ b/services/service/include/relationshipsyncmgr/dm_comm_tool.h @@ -16,12 +16,16 @@ #ifndef OHOS_DM_COMM_TOOL_H #define OHOS_DM_COMM_TOOL_H +#include +#include #include "dm_transport.h" #include "dm_transport_msg.h" +#include "ffrt.h" + namespace OHOS { namespace DistributedHardware { - +using EventCallback = std::function; class DMCommTool : public std::enable_shared_from_this { public: DMCommTool(); @@ -34,14 +38,6 @@ public: const std::vector &backgroundUserIds); void RspLocalFrontOrBackUserIds(const std::string rmtNetworkId, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds, int32_t socketId); - int32_t CreateUserStopMessage(int32_t stopUserId, std::string &msgStr); - int32_t SendMsg(const std::string rmtNetworkId, int32_t msgType, const std::string &msg); - int32_t SendUserStop(const std::string rmtNetworkId, int32_t stopUserId); - int32_t ParseUserStopMessage(const std::string &msgStr, int32_t &stopUserId); - void ProcessReceiveUserStopEvent(const std::shared_ptr commMsg); - void RspUserStop(const std::string rmtNetworkId, int32_t socketId, int32_t stopUserId); - void ProcessResponseUserStopEvent(const std::shared_ptr commMsg); - class DMCommToolEventHandler : public AppExecFwk::EventHandler { public: DMCommToolEventHandler(const std::shared_ptr runner, @@ -54,13 +50,16 @@ public: std::shared_ptr GetEventHandler(); const std::shared_ptr GetDMTransportPtr(); - void ProcessReceiveUserIdsEvent(const std::shared_ptr commMsg); - void ProcessResponseUserIdsEvent(const std::shared_ptr commMsg); int32_t SendLogoutAccountInfo(const std::string &rmtNetworkId, const std::string &accountId, int32_t userId); void ProcessReceiveLogoutEvent(const std::shared_ptr commMsg); + int32_t StartCommonEvent(std::string commonEventType, EventCallback eventCallback); + void ProcessReceiveCommonEvent(const std::shared_ptr commMsg); + void ProcessResponseCommonEvent(const std::shared_ptr commMsg); private: std::shared_ptr dmTransportPtr_; std::shared_ptr eventHandler_; + mutable std::mutex eventMutex_; + std::shared_ptr eventQueue_; }; } // DistributedHardware } // OHOS diff --git a/services/service/include/relationshipsyncmgr/relationship_sync_mgr.h b/services/service/include/relationshipsyncmgr/relationship_sync_mgr.h index cc6409ce119d6d4ea1f2cdf1bcb96129cdc9ccff..870b7e318b0ed6ae2542663a79dd573743aa4784 100644 --- a/services/service/include/relationshipsyncmgr/relationship_sync_mgr.h +++ b/services/service/include/relationshipsyncmgr/relationship_sync_mgr.h @@ -71,7 +71,6 @@ struct RelationShipChangeMsg { void ToServiceUnbindPayLoad(uint8_t *&msg, uint32_t &len) const; 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; cJSON *ToPayLoadJson() const; bool FromAccountLogoutPayLoad(const cJSON *payloadJson); @@ -80,7 +79,6 @@ struct RelationShipChangeMsg { bool FromServiceUnbindPayLoad(const cJSON *payloadJson); bool FromSyncFrontOrBackUserIdPayLoad(const cJSON *payloadJson); bool FromDelUserPayLoad(const cJSON *payloadJson); - bool FromStopUserPayLoad(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 0768de61d3b0fb1c5c2b477c3b6e6aaa548c1511..25762b1b27bdf8a571758760990ebcbec10f05a9 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -62,7 +62,7 @@ constexpr const char* LIB_IMPL_NAME = "libdevicemanagerserviceimpl.so"; #endif constexpr const char* LIB_DM_ADAPTER_NAME = "libdevicemanageradapter.z.so"; constexpr const char* LIB_DM_RESIDENT_NAME = "libdevicemanagerresident.z.so"; - +constexpr const char* LIB_DM_COMDENPENDENCY_NAME = "libdevicemanagerdependency.z.so"; namespace OHOS { namespace DistributedHardware { DM_IMPLEMENT_SINGLE_INSTANCE(DeviceManagerService); @@ -83,9 +83,8 @@ namespace { constexpr uint32_t USERID_SYNC_DISCOVERY_TYPE_NCM_MASK = 0b10000000; const std::string DHARD_WARE_PKG_NAME = "ohos.dhardware"; const std::string USERID_CHECKSUM_ISCHANGE_KEY = "ischange"; - constexpr const char* USER_SWITCH_BY_WIFI_TIMEOUT_TASK = "deviceManagerTimer:userSwitchByWifi"; - constexpr const char* USER_STOP_BY_WIFI_TIMEOUT_TASK = "deviceManagerTimer:userStopByWifi"; - const int32_t USER_SWITCH_BY_WIFI_TIMEOUT_S = 2; + constexpr const char* ACCOUNT_COMMON_EVENT_BY_WIFI_TIMEOUT_TASK = "deviceManagerTimer:accountCommonEventByWifi"; + const int32_t ACCOUNT_COMMON_EVENT_BY_WIFI_TIMEOUT_S = 2; } DeviceManagerService::~DeviceManagerService() @@ -93,6 +92,7 @@ DeviceManagerService::~DeviceManagerService() LOGI("DeviceManagerService destructor"); UnloadDMServiceImplSo(); UnloadDMServiceAdapterResident(); + CloseCommonDependencyObj(); } int32_t DeviceManagerService::Init() @@ -271,9 +271,12 @@ int32_t DeviceManagerService::InitDMServiceListener() } #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) DMCommTool::GetInstance()->Init(); - int32_t currentUserId = MultipleUserConnector::GetFirstForegroundUserId(); - if (IsPC() && !MultipleUserConnector::IsUserUnlocked(currentUserId)) { - HandleUserStopEvent(currentUserId); + int32_t retFront = MultipleUserConnector::GetForegroundUserIds(foregroundUserVec_); + int32_t retBack = MultipleUserConnector::GetBackgroundUserIds(backgroundUserVec_); + MultipleUserConnector::ClearLockedUser(foregroundUserVec_, backgroundUserVec_); + if (retFront != DM_OK || retBack != DM_OK) { + LOGE("retFront: %{public}d, retBack: %{public}d, frontuserids: %{public}s, backuserids: %{public}s", + retFront, retBack, GetIntegerList(foregroundUserVec_).c_str(), GetIntegerList(backgroundUserVec_).c_str()); } #endif LOGI("Init success."); @@ -1893,13 +1896,74 @@ void DeviceManagerService::SubscribeScreenLockEvent() return; } +bool DeviceManagerService::CloseCommonDependencyObj() +{ + LOGI("DeviceManagerService::CloseCommonDependencyObj start."); + std::lock_guard lock(comDependencyLoadLock_); + if (!isSoLoaded_ && (dpConnector_ == nullptr) && (dpConnectorHandle_ == nullptr)) { + return true; + } + + int32_t ret = dlclose(dpConnectorHandle_); + if (ret != 0) { + LOGE("close libdevicemanagerdependency failed ret = %{public}d.", ret); + return false; + } + isSoLoaded_ = false; + dpConnector_ = nullptr; + dpConnectorHandle_ = nullptr; + LOGI("close libdevicemanagerdependency so success."); + return true; +} + +bool DeviceManagerService::IsCommonDependencyReady() +{ + std::lock_guard lock(comDependencyLoadLock_); + if (isSoLoaded_ && dpConnector_ != nullptr && dpConnectorHandle_ != nullptr) { + return true; + } + dpConnectorHandle_ = dlopen(LIB_DM_COMDENPENDENCY_NAME, RTLD_NOW | RTLD_NODELETE | RTLD_NOLOAD); + if (dpConnectorHandle_ == nullptr) { + dpConnectorHandle_ = dlopen(LIB_DM_COMDENPENDENCY_NAME, RTLD_NOW | RTLD_NODELETE); + } + if (dpConnectorHandle_ == nullptr) { + LOGE("load libdevicemanagerdependency so failed, errMsg: %{public}s.", dlerror()); + return false; + } + dlerror(); + auto func = (CreateDpConnectorFuncPtr)dlsym(dpConnectorHandle_, "CreateDpConnectorInstance"); + if (dlerror() != nullptr || func == nullptr) { + dlclose(dpConnectorHandle_); + LOGE("Create object function is not exist."); + return false; + } + dpConnector_ = func(); + isSoLoaded_ = true; + LOGI("IsCommonDependencyReady success."); + return true; +} + +IDeviceProfileConnector* DeviceManagerService::GetCommonDependencyObj() +{ + return dpConnector_; +} + DM_EXPORT void DeviceManagerService::AccountCommonEventCallback( const std::string commonEventType, int32_t currentUserId, int32_t beforeUserId) { LOGI("CommonEventType: %{public}s, currentUserId: %{public}d, beforeUserId: %{public}d", commonEventType.c_str(), currentUserId, beforeUserId); if (commonEventType == CommonEventSupport::COMMON_EVENT_USER_SWITCHED) { - HandleUserSwitchedEvent(currentUserId, beforeUserId); + DeviceNameManager::GetInstance().InitDeviceNameWhenUserSwitch(currentUserId, beforeUserId); + CheckRegisterInfoWithWise(currentUserId); + MultipleUserConnector::SetAccountInfo(currentUserId, MultipleUserConnector::GetCurrentDMAccountInfo()); + if (IsDMServiceAdapterResidentLoad()) { + dmServiceImplExtResident_->AccountUserSwitched(currentUserId, MultipleUserConnector::GetOhosAccountId()); + } + DMCommTool::GetInstance()->StartCommonEvent(commonEventType, + [this, commonEventType] () { + DeviceManagerService::HandleAccountCommonEvent(commonEventType); + }); } else if (commonEventType == CommonEventSupport::COMMON_EVENT_HWID_LOGIN) { DeviceNameManager::GetInstance().InitDeviceNameWhenLogin(); MultipleUserConnector::SetAccountInfo(currentUserId, MultipleUserConnector::GetCurrentDMAccountInfo()); @@ -1921,51 +1985,77 @@ DM_EXPORT void DeviceManagerService::AccountCommonEventCallback( } else if (commonEventType == CommonEventSupport::COMMON_EVENT_USER_INFO_UPDATED) { DeviceNameManager::GetInstance().InitDeviceNameWhenNickChange(); } else if (commonEventType == CommonEventSupport::COMMON_EVENT_USER_STOPPED && IsPC()) { - HandleUserStopEvent(beforeUserId); + DMCommTool::GetInstance()->StartCommonEvent(commonEventType, + [this, commonEventType] () { + DeviceManagerService::HandleAccountCommonEvent(commonEventType); + }); } else if (commonEventType == CommonEventSupport::COMMON_EVENT_USER_UNLOCKED) { DeviceNameManager::GetInstance().AccountSysReady(beforeUserId); - if (IsPC()) { - HandleUserSwitched(); - if (IsDMServiceAdapterResidentLoad()) { - dmServiceImplExtResident_->AccountUserSwitched(currentUserId, - MultipleUserConnector::GetOhosAccountId()); - } - } + DMCommTool::GetInstance()->StartCommonEvent(commonEventType, + [this, commonEventType] () { + DeviceManagerService::HandleAccountCommonEvent(commonEventType); + }); } else { LOGE("Invalied account common event."); } return; } -void DeviceManagerService::HandleUserSwitched() +bool DeviceManagerService::CheckUserIdMatch(std::vector foregroundUserVec, + std::vector backgroundUserVec) { - LOGI("onStart, HandleUserSwitched."); + LOGI("foregroundUserVec: %{public}s, backgroundUserVec: %{public}s", + GetIntegerList(foregroundUserVec).c_str(), GetIntegerList(backgroundUserVec).c_str()); + std::sort(foregroundUserVec.begin(), foregroundUserVec.end()); + std::sort(backgroundUserVec.begin(), backgroundUserVec.end()); + std::sort(foregroundUserVec_.begin(), foregroundUserVec_.end()); + std::sort(backgroundUserVec_.begin(), backgroundUserVec_.end()); + if (foregroundUserVec == foregroundUserVec_ && backgroundUserVec == backgroundUserVec_) { + LOGI("User status has not changed."); + return true; + } + LOGI("User status has changed, foregroundUserVec_: %{public}s, backgroundUserVec_: %{public}s", + GetIntegerList(foregroundUserVec_).c_str(), GetIntegerList(backgroundUserVec_).c_str()); + foregroundUserVec_.clear(); + backgroundUserVec_.clear(); + foregroundUserVec_ = foregroundUserVec; + backgroundUserVec_ = backgroundUserVec; + return false; +} + +void DeviceManagerService::HandleAccountCommonEvent(const std::string commonEventType) +{ + LOGI("HandleAccountCommonEvent commonEventType: %{public}s.", commonEventType.c_str()); std::vector foregroundUserVec; int32_t retFront = MultipleUserConnector::GetForegroundUserIds(foregroundUserVec); std::vector backgroundUserVec; int32_t retBack = MultipleUserConnector::GetBackgroundUserIds(backgroundUserVec); - if (retFront != DM_OK || retBack != DM_OK || foregroundUserVec.empty()) { - LOGE("Get userids failed, retFront: %{public}d, retBack: %{public}d, foreground user num: %{public}d", - retFront, retBack, static_cast(foregroundUserVec.size())); + MultipleUserConnector::ClearLockedUser(foregroundUserVec, backgroundUserVec); + if (retFront != DM_OK || retBack != DM_OK) { + LOGE("retFront: %{public}d, retBack: %{public}d, frontuserids: %{public}s, backuserids: %{public}s", + retFront, retBack, GetIntegerList(foregroundUserVec).c_str(), GetIntegerList(backgroundUserVec).c_str()); + return; + } + if (CheckUserIdMatch(foregroundUserVec, backgroundUserVec)) { + LOGI("User status has not changed."); return; } char localUdidTemp[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localUdidTemp, DEVICE_UUID_LENGTH); std::string localUdid = std::string(localUdidTemp); - CHECK_NULL_VOID(discoveryMgr_); - if (!discoveryMgr_->IsCommonDependencyReady() || discoveryMgr_->GetCommonDependencyObj() == nullptr) { + if (!IsCommonDependencyReady() || GetCommonDependencyObj() == nullptr) { LOGE("IsCommonDependencyReady failed or GetCommonDependencyObj() is nullptr."); return; } - if (!discoveryMgr_->GetCommonDependencyObj()->CheckAclStatusAndForegroundNotMatch(localUdid, - foregroundUserVec, backgroundUserVec)) { + if (!GetCommonDependencyObj()->CheckAclStatusAndForegroundNotMatch(localUdid, foregroundUserVec, + backgroundUserVec)) { LOGI("no unreasonable data."); return; } std::map curUserDeviceMap = - discoveryMgr_->GetCommonDependencyObj()->GetDeviceIdAndBindLevel(foregroundUserVec, localUdid); + GetCommonDependencyObj()->GetDeviceIdAndBindLevel(foregroundUserVec, localUdid); std::map preUserDeviceMap = - discoveryMgr_->GetCommonDependencyObj()->GetDeviceIdAndBindLevel(backgroundUserVec, localUdid); + GetCommonDependencyObj()->GetDeviceIdAndBindLevel(backgroundUserVec, localUdid); std::vector peerUdids; for (const auto &item : curUserDeviceMap) { peerUdids.push_back(item.first); @@ -1978,21 +2068,21 @@ void DeviceManagerService::HandleUserSwitched() if (peerUdids.empty()) { return; } - NotifyRemoteLocalUserSwitch(localUdid, peerUdids, foregroundUserVec, backgroundUserVec); + NotifyRemoteAccountCommonEvent(commonEventType, localUdid, peerUdids, foregroundUserVec, backgroundUserVec); } #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) -void DeviceManagerService::NotifyRemoteLocalUserSwitch(const std::string &localUdid, - const std::vector &peerUdids, const std::vector &foregroundUserIds, - const std::vector &backgroundUserIds) +void DeviceManagerService::NotifyRemoteAccountCommonEvent(const std::string commonEventType, + const std::string &localUdid, const std::vector &peerUdids, + const std::vector &foregroundUserIds, const std::vector &backgroundUserIds) { - LOGI("onstart UserSwitch, foregroundUserIds: %{public}s, backgroundUserIds: %{public}s", + LOGI("NotifyRemoteAccountCommonEvent, foregroundUserIds: %{public}s, backgroundUserIds: %{public}s", GetIntegerList(foregroundUserIds).c_str(), GetIntegerList(backgroundUserIds).c_str()); if (peerUdids.empty()) { return; } if (softbusListener_ == nullptr) { - UpdateAclAndDeleteGroup(localUdid, peerUdids, foregroundUserIds, backgroundUserIds); + UpdateAcl(localUdid, peerUdids, foregroundUserIds, backgroundUserIds); LOGE("softbusListener_ is null"); return; } @@ -2020,60 +2110,81 @@ void DeviceManagerService::NotifyRemoteLocalUserSwitch(const std::string &localU } } if (!bleUdids.empty()) { - UpdateAclAndDeleteGroup(localUdid, peerUdids, foregroundUserIds, backgroundUserIds); - SendUserIdsBroadCast(bleUdids, foregroundUserIds, backgroundUserIds, true); + UpdateAcl(localUdid, peerUdids, foregroundUserIds, backgroundUserIds); + if (commonEventType == CommonEventSupport::COMMON_EVENT_USER_UNLOCKED || + commonEventType == CommonEventSupport::COMMON_EVENT_USER_SWITCHED) { + SendCommonEventBroadCast(bleUdids, foregroundUserIds, backgroundUserIds, true); + } else if (commonEventType == CommonEventSupport::COMMON_EVENT_USER_STOPPED) { + SendCommonEventBroadCast(bleUdids, foregroundUserIds, backgroundUserIds, false); + } else { + LOGE("commonEventType not match"); + return; + } } if (!wifiDevices.empty()) { - NotifyRemoteLocalUserSwitchByWifi(localUdid, wifiDevices, foregroundUserIds, backgroundUserIds); + NotifyRemoteAccountCommonEventByWifi(localUdid, wifiDevices, foregroundUserIds, backgroundUserIds); } } -void DeviceManagerService::NotifyRemoteLocalUserSwitchByWifi(const std::string &localUdid, +void DeviceManagerService::NotifyRemoteAccountCommonEventByWifi(const std::string &localUdid, const std::map &wifiDevices, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds) { for (const auto &it : wifiDevices) { - int32_t result = SendUserIdsByWifi(it.second, foregroundUserIds, backgroundUserIds); + int32_t result = SendAccountCommonEventByWifi(it.second, foregroundUserIds, backgroundUserIds); if (result != DM_OK) { LOGE("by wifi failed: %{public}s", GetAnonyString(it.first).c_str()); std::vector updateUdids; updateUdids.push_back(it.first); - UpdateAclAndDeleteGroup(localUdid, updateUdids, foregroundUserIds, backgroundUserIds); + UpdateAcl(localUdid, updateUdids, foregroundUserIds, backgroundUserIds); continue; } if (timer_ == nullptr) { timer_ = std::make_shared(); } std::string udid = it.first; - timer_->StartTimer(std::string(USER_SWITCH_BY_WIFI_TIMEOUT_TASK) + Crypto::Sha256(udid), - USER_SWITCH_BY_WIFI_TIMEOUT_S, + timer_->StartTimer(std::string(ACCOUNT_COMMON_EVENT_BY_WIFI_TIMEOUT_TASK) + Crypto::Sha256(udid), + ACCOUNT_COMMON_EVENT_BY_WIFI_TIMEOUT_S, [this, localUdid, foregroundUserIds, backgroundUserIds, udid] (std::string name) { - DeviceManagerService::HandleUserSwitchTimeout(localUdid, foregroundUserIds, backgroundUserIds, udid); + DeviceManagerService::HandleCommonEventTimeout(localUdid, foregroundUserIds, backgroundUserIds, udid); }); } } -void DeviceManagerService::HandleUserSwitchTimeout(const std::string &localUdid, +int32_t DeviceManagerService::SendAccountCommonEventByWifi(const std::string &networkId, + const std::vector &foregroundUserIds, const std::vector &backgroundUserIds) +{ + LOGI("Try open softbus session to exchange foreground/background userid"); + std::vector foregroundUserIdsUInt; + for (auto const &u : foregroundUserIds) { + foregroundUserIdsUInt.push_back(static_cast(u)); + } + std::vector backgroundUserIdsUInt; + for (auto const &u : backgroundUserIds) { + backgroundUserIdsUInt.push_back(static_cast(u)); + } + return DMCommTool::GetInstance()->SendUserIds(networkId, foregroundUserIdsUInt, backgroundUserIdsUInt); +} + +void DeviceManagerService::HandleCommonEventTimeout(const std::string &localUdid, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds, const std::string &udid) { LOGI("start udid: %{public}s", GetAnonyString(udid).c_str()); std::vector updateUdids; updateUdids.push_back(udid); - UpdateAclAndDeleteGroup(localUdid, updateUdids, foregroundUserIds, backgroundUserIds); + UpdateAcl(localUdid, updateUdids, foregroundUserIds, backgroundUserIds); } -void DeviceManagerService::UpdateAclAndDeleteGroup(const std::string &localUdid, - const std::vector &deviceVec, const std::vector &foregroundUserIds, +void DeviceManagerService::UpdateAcl(const std::string &localUdid, + const std::vector &peerUdids, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds) { - CHECK_NULL_VOID(discoveryMgr_); - if (!discoveryMgr_->IsCommonDependencyReady() || discoveryMgr_->GetCommonDependencyObj() == nullptr) { + if (!IsCommonDependencyReady() || GetCommonDependencyObj() == nullptr) { LOGE("IsCommonDependencyReady failed or GetCommonDependencyObj() is nullptr."); return; } - discoveryMgr_->GetCommonDependencyObj()->HandleUserSwitched(localUdid, deviceVec, - foregroundUserIds, backgroundUserIds); + GetCommonDependencyObj()->HandleAccountCommonEvent(localUdid, peerUdids, foregroundUserIds, backgroundUserIds); } #endif @@ -2117,41 +2228,6 @@ void DeviceManagerService::HandleAccountLogout(int32_t userId, const std::string } } -void DeviceManagerService::HandleUserSwitched(int32_t curUserId, int32_t preUserId) -{ - LOGI("currentUserId: %{public}d. previousUserId: %{public}d", curUserId, preUserId); - if (!IsDMServiceImplReady()) { - LOGE("Init impl failed."); - return; - } - std::map curUserDeviceMap; - std::map preUserDeviceMap; - std::vector peerUdids; - curUserDeviceMap = dmServiceImpl_->GetDeviceIdAndBindLevel(curUserId); - preUserDeviceMap = dmServiceImpl_->GetDeviceIdAndBindLevel(preUserId); - for (const auto &item : curUserDeviceMap) { - peerUdids.push_back(item.first); - } - for (const auto &item : preUserDeviceMap) { - if (find(peerUdids.begin(), peerUdids.end(), item.first) == peerUdids.end()) { - peerUdids.push_back(item.first); - } - } - if (peerUdids.empty()) { - return; - } - std::vector foregroundUserVec; - int32_t retFront = MultipleUserConnector::GetForegroundUserIds(foregroundUserVec); - std::vector backgroundUserVec; - int32_t retBack = MultipleUserConnector::GetBackgroundUserIds(backgroundUserVec); - if (retFront != DM_OK || retBack != DM_OK || foregroundUserVec.empty()) { - LOGE("Get userids failed, retFront: %{public}d, retBack: %{public}d, foreground user num: %{public}d", - retFront, retBack, static_cast(foregroundUserVec.size())); - return; - } - NotifyRemoteLocalUserSwitch(curUserId, preUserId, peerUdids, foregroundUserVec, backgroundUserVec); -} - void DeviceManagerService::HandleUserRemoved(int32_t removedUserId) { LOGI("PreUserId %{public}d.", removedUserId); @@ -2201,7 +2277,7 @@ void DeviceManagerService::SendAccountLogoutBroadCast(const std::vectorSendAclChangedBroadcast(broadCastMsg); } -void DeviceManagerService::SendUserIdsBroadCast(const std::vector &peerUdids, +void DeviceManagerService::SendCommonEventBroadCast(const std::vector &peerUdids, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds, bool isNeedResponse) { LOGI("peerUdids: %{public}s, foregroundUserIds: %{public}s, backgroundUserIds: %{public}s, isNeedRsp: %{public}s", @@ -2222,7 +2298,7 @@ void DeviceManagerService::SendUserIdsBroadCast(const std::vector & softbusListener_->SendAclChangedBroadcast(broadCastMsg); } -void DeviceManagerService::HandleUserIdsBroadCast(const std::vector &remoteUserIdInfos, +void DeviceManagerService::HandleCommonEventBroadCast(const std::vector &remoteUserIdInfos, const std::string &remoteUdid, bool isNeedResponse) { LOGI("rmtUdid: %{public}s, rmtUserIds: %{public}s, isNeedResponse: %{public}s,", @@ -2230,21 +2306,19 @@ void DeviceManagerService::HandleUserIdsBroadCast(const std::vector isNeedResponse ? "true" : "false"); if (isNeedResponse) { std::vector foregroundUserVec; - std::vector backgroundUserVec; int32_t retFront = MultipleUserConnector::GetForegroundUserIds(foregroundUserVec); + std::vector backgroundUserVec; int32_t retBack = MultipleUserConnector::GetBackgroundUserIds(backgroundUserVec); - if (IsPC()) { - MultipleUserConnector::ClearLockedUser(foregroundUserVec, backgroundUserVec); - } + MultipleUserConnector::ClearLockedUser(foregroundUserVec, backgroundUserVec); if (retFront != DM_OK || retBack!= DM_OK) { - LOGE("Get userid failed, retFront: %{public}d, retBack: %{public}d, frontUserNum:%{public}d," - "backUserNum: %{public}d", retFront, retBack, static_cast(foregroundUserVec.size()), - static_cast(backgroundUserVec.size())); + LOGE("retFront: %{public}d, retBack: %{public}d, frontuserids: %{public}s, backuserids: %{public}s", + retFront, retBack, GetIntegerList(foregroundUserVec).c_str(), + GetIntegerList(backgroundUserVec).c_str()); } else { LOGE("Send back local frontuserids: %{public}s, backuserids: %{public}s", GetIntegerList(foregroundUserVec).c_str(), GetIntegerList(backgroundUserVec).c_str()); std::vector remoteUdids = { remoteUdid }; - SendUserIdsBroadCast(remoteUdids, foregroundUserVec, backgroundUserVec, false); + SendCommonEventBroadCast(remoteUdids, foregroundUserVec, backgroundUserVec, false); } } @@ -2261,33 +2335,47 @@ void DeviceManagerService::HandleUserIdsBroadCast(const std::vector for (const auto &u : backgroundUserIdInfos) { backgroundUserIds.push_back(static_cast(u.userId)); } - if (softbusListener_ != nullptr) { - softbusListener_->SetForegroundUserIdsToDSoftBus(remoteUdid, foregroundUserIds); - } - if (IsDMServiceImplReady()) { - dmServiceImpl_->HandleSyncUserIdEvent(foregroundUserIds, backgroundUserIds, remoteUdid, IsPC()); + dmServiceImpl_->HandleCommonEventBroadCast(foregroundUserIds, backgroundUserIds, remoteUdid); } } -void DeviceManagerService::ProcessSyncUserIds(const std::vector &foregroundUserIds, +void DeviceManagerService::ProcessCommonEvent(const std::vector &foregroundUserIds, const std::vector &backgroundUserIds, const std::string &remoteUdid) { - LOGI("process sync foregroundUserIds: %{public}s, backgroundUserIds: %{public}s, remote udid: %{public}s", + LOGI("ProcessCommonEvent foregroundUserIds: %{public}s, backgroundUserIds: %{public}s, remoteUdid: %{public}s", GetIntegerList(foregroundUserIds).c_str(), GetIntegerList(backgroundUserIds).c_str(), GetAnonyString(remoteUdid).c_str()); - if (softbusListener_ != nullptr) { - softbusListener_->SetForegroundUserIdsToDSoftBus(remoteUdid, foregroundUserIds); - } if (timer_ != nullptr) { - timer_->DeleteTimer(std::string(USER_SWITCH_BY_WIFI_TIMEOUT_TASK) + Crypto::Sha256(remoteUdid)); + timer_->DeleteTimer(std::string(ACCOUNT_COMMON_EVENT_BY_WIFI_TIMEOUT_TASK) + Crypto::Sha256(remoteUdid)); } if (IsDMServiceImplReady()) { - dmServiceImpl_->HandleSyncUserIdEvent(foregroundUserIds, backgroundUserIds, remoteUdid, IsPC()); + dmServiceImpl_->HandleCommonEventBroadCast(foregroundUserIds, backgroundUserIds, remoteUdid); } } +void DeviceManagerService::SendUserIdsBroadCast(const std::vector &peerUdids, + const std::vector &foregroundUserIds, const std::vector &backgroundUserIds, bool isNeedResponse) +{ + LOGI("peerUdids: %{public}s, foregroundUserIds: %{public}s, backgroundUserIds: %{public}s, isNeedRsp: %{public}s", + GetAnonyStringList(peerUdids).c_str(), GetIntegerList(foregroundUserIds).c_str(), + GetIntegerList(backgroundUserIds).c_str(), isNeedResponse ? "true" : "false"); + RelationShipChangeMsg msg; + msg.type = RelationShipChangeType::SYNC_USERID; + msg.peerUdids = peerUdids; + msg.syncUserIdFlag = isNeedResponse; + for (const auto &userId : foregroundUserIds) { + msg.userIdInfos.push_back({ true, static_cast(userId) }); + } + for (auto const &userId : backgroundUserIds) { + msg.userIdInfos.push_back({ false, static_cast(userId) }); + } + std::string broadCastMsg = ReleationShipSyncMgr::GetInstance().SyncTrustRelationShip(msg); + CHECK_NULL_VOID(softbusListener_); + softbusListener_->SendAclChangedBroadcast(broadCastMsg); +} + void DeviceManagerService::ScreenCommonEventCallback(std::string commonEventType) { if (!IsDMImplSoLoaded()) { @@ -2547,15 +2635,12 @@ void DeviceManagerService::HandleDeviceTrustedChange(const std::string &msg) static_cast(relationShipMsg.tokenId)); break; case RelationShipChangeType::SYNC_USERID: - HandleUserIdsBroadCast(relationShipMsg.userIdInfos, + HandleCommonEventBroadCast(relationShipMsg.userIdInfos, relationShipMsg.peerUdid, relationShipMsg.syncUserIdFlag); break; case RelationShipChangeType::DEL_USER: dmServiceImpl_->HandleRemoteUserRemoved(relationShipMsg.userId, relationShipMsg.peerUdid); break; - case RelationShipChangeType::STOP_USER: - HandleUserStopBroadCast(relationShipMsg.userId, relationShipMsg.peerUdid); - break; default: LOGI("Dm have not this event type."); break; @@ -2864,267 +2949,6 @@ int32_t DeviceManagerService::GetAnonyLocalUdid(const std::string &pkgName, std: return DM_OK; } -#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) -void DeviceManagerService::NotifyRemoteLocalUserSwitch(int32_t curUserId, int32_t preUserId, - const std::vector &peerUdids, const std::vector &foregroundUserIds, - const std::vector &backgroundUserIds) -{ - LOGI("Send local foreground and background userids"); - if (peerUdids.empty()) { - return; - } - if (softbusListener_ == nullptr) { - dmServiceImpl_->HandleUserSwitched(peerUdids, curUserId, preUserId); - LOGE("softbusListener_ is null"); - return; - } - std::vector bleUdids; - std::map wifiDevices; - for (const auto &udid : peerUdids) { - std::string netWorkId = ""; - SoftbusCache::GetInstance().GetNetworkIdFromCache(udid, netWorkId); - if (netWorkId.empty()) { - LOGI("netWorkId is empty: %{public}s", GetAnonyString(udid).c_str()); - bleUdids.push_back(udid); - continue; - } - int32_t networkType = 0; - int32_t ret = softbusListener_->GetNetworkTypeByNetworkId(netWorkId.c_str(), networkType); - if (ret != DM_OK || networkType <= 0) { - LOGI("get networkType failed: %{public}s", GetAnonyString(udid).c_str()); - bleUdids.push_back(udid); - continue; - } - if ((static_cast(networkType) & USERID_SYNC_DISCOVERY_TYPE_BLE_MASK) != 0x0) { - bleUdids.push_back(udid); - } else { - wifiDevices.insert(std::pair(udid, netWorkId)); - } - } - if (!bleUdids.empty()) { - dmServiceImpl_->HandleUserSwitched(bleUdids, curUserId, preUserId); - SendUserIdsBroadCast(bleUdids, foregroundUserIds, backgroundUserIds, true); - } - if (!wifiDevices.empty()) { - NotifyRemoteLocalUserSwitchByWifi(curUserId, preUserId, wifiDevices, foregroundUserIds, backgroundUserIds); - } -} - -void DeviceManagerService::NotifyRemoteLocalUserSwitchByWifi(int32_t curUserId, int32_t preUserId, - const std::map &wifiDevices, const std::vector &foregroundUserIds, - const std::vector &backgroundUserIds) -{ - for (const auto &it : wifiDevices) { - int32_t result = SendUserIdsByWifi(it.second, foregroundUserIds, backgroundUserIds); - if (result != DM_OK) { - LOGE("by wifi failed: %{public}s", GetAnonyString(it.first).c_str()); - std::vector updateUdids; - updateUdids.push_back(it.first); - dmServiceImpl_->HandleUserSwitched(updateUdids, curUserId, preUserId); - continue; - } - if (timer_ == nullptr) { - timer_ = std::make_shared(); - } - std::string udid = it.first; - timer_->StartTimer(std::string(USER_SWITCH_BY_WIFI_TIMEOUT_TASK) + Crypto::Sha256(udid), - USER_SWITCH_BY_WIFI_TIMEOUT_S, [this, curUserId, preUserId, udid] (std::string name) { - DeviceManagerService::HandleUserSwitchTimeout(curUserId, preUserId, udid); - }); - } -} - -int32_t DeviceManagerService::SendUserIdsByWifi(const std::string &networkId, - const std::vector &foregroundUserIds, const std::vector &backgroundUserIds) -{ - LOGI("Try open softbus session to exchange foreground/background userid"); - std::vector foregroundUserIdsUInt; - for (auto const &u : foregroundUserIds) { - foregroundUserIdsUInt.push_back(static_cast(u)); - } - std::vector backgroundUserIdsUInt; - for (auto const &u : backgroundUserIds) { - backgroundUserIdsUInt.push_back(static_cast(u)); - } - return DMCommTool::GetInstance()->SendUserIds(networkId, foregroundUserIdsUInt, backgroundUserIdsUInt); -} - -void DeviceManagerService::HandleUserSwitchTimeout(int32_t curUserId, int32_t preUserId, const std::string &udid) -{ - LOGI("start udid: %{public}s", GetAnonyString(udid).c_str()); - std::vector updateUdids; - updateUdids.push_back(udid); - dmServiceImpl_->HandleUserSwitched(updateUdids, curUserId, preUserId); -} - -void DeviceManagerService::HandleUserSwitchedEvent(int32_t currentUserId, int32_t beforeUserId) -{ - DeviceNameManager::GetInstance().InitDeviceNameWhenUserSwitch(currentUserId, beforeUserId); - MultipleUserConnector::SetAccountInfo(currentUserId, MultipleUserConnector::GetCurrentDMAccountInfo()); - if (IsPC()) { - return; - } - if (beforeUserId == -1 || currentUserId == -1) { - HandleUserSwitched(); - return; - } - if (beforeUserId != -1 && currentUserId != -1) { - HandleUserSwitched(currentUserId, beforeUserId); - } - if (IsDMServiceAdapterResidentLoad()) { - dmServiceImplExtResident_->AccountUserSwitched(currentUserId, MultipleUserConnector::GetOhosAccountId()); - } -} - -void DeviceManagerService::HandleUserStopEvent(int32_t stopUserId) -{ - LOGI("onStart, HandleUserStopEvent %{public}s.", GetAnonyInt32(stopUserId).c_str()); - std::vector stopUserVec; - stopUserVec.push_back(stopUserId); - char localUdidTemp[DEVICE_UUID_LENGTH] = {0}; - GetDevUdid(localUdidTemp, DEVICE_UUID_LENGTH); - std::string localUdid = std::string(localUdidTemp); - std::map stopUserDeviceMap; - std::vector peerUdids; - CHECK_NULL_VOID(discoveryMgr_); - if (!discoveryMgr_->IsCommonDependencyReady() || discoveryMgr_->GetCommonDependencyObj() == nullptr) { - LOGE("IsCommonDependencyReady failed or GetCommonDependencyObj() is nullptr."); - return; - } - stopUserDeviceMap = discoveryMgr_->GetCommonDependencyObj()-> - GetDeviceIdAndBindLevel(stopUserVec, localUdid); - for (const auto &item : stopUserDeviceMap) { - peerUdids.push_back(item.first); - } - if (peerUdids.empty()) { - LOGI("no data to be stoped."); - return; - } - NotifyRemoteLocalUserStop(localUdid, peerUdids, stopUserId); -} - -void DeviceManagerService::DivideNotifyMethod(const std::vector &peerUdids, - std::vector &bleUdids, std::map &wifiDevices) -{ - if (peerUdids.empty()) { - return; - } - if (softbusListener_ == nullptr) { - bleUdids = peerUdids; - LOGI("softbusListener_ is null"); - return; - } - for (const auto &udid : peerUdids) { - std::string netWorkId = ""; - SoftbusCache::GetInstance().GetNetworkIdFromCache(udid, netWorkId); - if (netWorkId.empty()) { - LOGI("netWorkId is empty: %{public}s", GetAnonyString(udid).c_str()); - bleUdids.push_back(udid); - continue; - } - int32_t networkType = 0; - int32_t ret = softbusListener_->GetNetworkTypeByNetworkId(netWorkId.c_str(), networkType); - if (ret != DM_OK || networkType <= 0) { - LOGI("get networkType failed: %{public}s", GetAnonyString(udid).c_str()); - bleUdids.push_back(udid); - continue; - } - if ((static_cast(networkType) & USERID_SYNC_DISCOVERY_TYPE_BLE_MASK) != 0x0) { - bleUdids.push_back(udid); - } else { - wifiDevices.insert(std::pair(udid, netWorkId)); - } - } -} - -void DeviceManagerService::HandleUserStop(int32_t stopUserId, const std::string &stopEventUdid, - const std::vector &acceptEventUdids) -{ - if (timer_ != nullptr) { - for (const auto &udid : acceptEventUdids) { - timer_->DeleteTimer(std::string(USER_STOP_BY_WIFI_TIMEOUT_TASK) + Crypto::Sha256(udid)); - } - } - if (MultipleUserConnector::IsUserUnlocked(stopUserId)) { - LOGE("user has unlocked %{public}s.", GetAnonyInt32(stopUserId).c_str()); - return; - } - CHECK_NULL_VOID(discoveryMgr_); - if (!discoveryMgr_->IsCommonDependencyReady() || discoveryMgr_->GetCommonDependencyObj() == nullptr) { - LOGE("IsCommonDependencyReady failed or GetCommonDependencyObj() is nullptr."); - return; - } - discoveryMgr_->GetCommonDependencyObj()->HandleUserStop(stopUserId, stopEventUdid, acceptEventUdids); -} - -void DeviceManagerService::HandleUserStop(int32_t stopUserId, const std::string &stopEventUdid) -{ - CHECK_NULL_VOID(discoveryMgr_); - if (!discoveryMgr_->IsCommonDependencyReady() || discoveryMgr_->GetCommonDependencyObj() == nullptr) { - LOGE("IsCommonDependencyReady failed or GetCommonDependencyObj() is nullptr."); - return; - } - discoveryMgr_->GetCommonDependencyObj()->HandleUserStop(stopUserId, stopEventUdid); -} - -void DeviceManagerService::NotifyRemoteLocalUserStop(const std::string &localUdid, - const std::vector &peerUdids, int32_t stopUserId) -{ - std::vector bleUdids; - std::map wifiDevices; - DivideNotifyMethod(peerUdids, bleUdids, wifiDevices); - if (!bleUdids.empty()) { - HandleUserStop(stopUserId, localUdid, bleUdids); - SendUserStopBroadCast(bleUdids, stopUserId); - } - if (!wifiDevices.empty()) { - NotifyRemoteLocalUserStopByWifi(localUdid, wifiDevices, stopUserId); - } -} - -void DeviceManagerService::SendUserStopBroadCast(const std::vector &peerUdids, int32_t stopUserId) -{ - LOGI("peerUdids: %{public}s", GetAnonyStringList(peerUdids).c_str()); - RelationShipChangeMsg msg; - msg.type = RelationShipChangeType::STOP_USER; - msg.userId = static_cast(stopUserId); - msg.peerUdids = peerUdids; - std::string broadCastMsg = ReleationShipSyncMgr::GetInstance().SyncTrustRelationShip(msg); - CHECK_NULL_VOID(softbusListener_); - softbusListener_->SendAclChangedBroadcast(broadCastMsg); -} - -void DeviceManagerService::HandleUserStopBroadCast(int32_t stopUserId, const std::string &remoteUdid) -{ - LOGI("start"); - HandleUserStop(stopUserId, remoteUdid); -} - -void DeviceManagerService::NotifyRemoteLocalUserStopByWifi(const std::string &localUdid, - const std::map &wifiDevices, int32_t stopUserId) -{ - for (const auto &it : wifiDevices) { - std::vector updateUdids; - updateUdids.push_back(it.first); - int32_t result = DMCommTool::GetInstance()->SendUserStop(it.second, stopUserId); - if (result != DM_OK) { - LOGE("by wifi failed: %{public}s", GetAnonyString(it.first).c_str()); - HandleUserStop(stopUserId, localUdid, updateUdids); - continue; - } - if (timer_ == nullptr) { - timer_ = std::make_shared(); - } - std::string udid = it.first; - timer_->StartTimer(std::string(USER_STOP_BY_WIFI_TIMEOUT_TASK) + Crypto::Sha256(udid), - USER_SWITCH_BY_WIFI_TIMEOUT_S, - [this, stopUserId, localUdid, updateUdids] (std::string name) { - DeviceManagerService::HandleUserStop(stopUserId, localUdid, updateUdids); - }); - } -} -#endif - int32_t DeviceManagerService::RegisterAuthenticationType(const std::string &pkgName, const std::map &authParam) { diff --git a/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp b/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp index 8abd91e4dfb3cf9fc68f7a8774f3740813415404..e0528abcb8ebcc69447a81c4d15acb1be9accc32 100644 --- a/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp +++ b/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp @@ -32,11 +32,8 @@ constexpr int32_t DM_COMM_SEND_LOCAL_USERIDS = 1; // if receive remote device send foreground userids, response local foreground uerids // This msg no need response constexpr int32_t DM_COMM_RSP_LOCAL_USERIDS = 2; -constexpr int32_t DM_COMM_SEND_USER_STOP = 3; -constexpr int32_t DM_COMM_RSP_USER_STOP = 4; constexpr int32_t DM_COMM_ACCOUNT_LOGOUT = 5; - -const char* const USER_STOP_MSG_KEY = "stopUserId"; +constexpr const char* EVENT_TASK = "EventTask"; DMCommTool::DMCommTool() : dmTransportPtr_(nullptr) { @@ -46,6 +43,7 @@ DMCommTool::DMCommTool() : dmTransportPtr_(nullptr) void DMCommTool::Init() { LOGI("Init DMCommTool"); + eventQueue_ = std::make_shared(EVENT_TASK); dmTransportPtr_ = std::make_shared(shared_from_this()); std::shared_ptr runner = AppExecFwk::EventRunner::Create(true); eventHandler_ = std::make_shared(runner, shared_from_this()); @@ -165,20 +163,12 @@ void DMCommTool::DMCommToolEventHandler::ProcessEvent( switch (eventId) { case DM_COMM_SEND_LOCAL_USERIDS: { // Process remote foreground userids and send back local user ids - dmCommToolPtr->ProcessReceiveUserIdsEvent(commMsg); + dmCommToolPtr->ProcessReceiveCommonEvent(commMsg); break; } case DM_COMM_RSP_LOCAL_USERIDS: { // Process remote foreground userids and close session - dmCommToolPtr->ProcessResponseUserIdsEvent(commMsg); - break; - } - case DM_COMM_SEND_USER_STOP: { - dmCommToolPtr->ProcessReceiveUserStopEvent(commMsg); - break; - } - case DM_COMM_RSP_USER_STOP: { - dmCommToolPtr->ProcessResponseUserStopEvent(commMsg); + dmCommToolPtr->ProcessResponseCommonEvent(commMsg); break; } case DM_COMM_ACCOUNT_LOGOUT: { @@ -191,9 +181,9 @@ void DMCommTool::DMCommToolEventHandler::ProcessEvent( } } -void DMCommTool::ProcessReceiveUserIdsEvent(const std::shared_ptr commMsg) +void DMCommTool::ProcessReceiveCommonEvent(const std::shared_ptr commMsg) { - LOGI("Receive remote userids, process and rsp local userid"); + LOGI("ProcessReceiveCommonEvent, process and rsp local userid"); std::string rmtUdid = ""; SoftbusCache::GetInstance().GetUdidFromCache(commMsg->remoteNetworkId.c_str(), rmtUdid); if (rmtUdid.empty()) { @@ -215,12 +205,10 @@ void DMCommTool::ProcessReceiveUserIdsEvent(const std::shared_ptr // step1: send back local userids std::vector foregroundUserIds; - std::vector backgroundUserIds; MultipleUserConnector::GetForegroundUserIds(foregroundUserIds); + std::vector backgroundUserIds; MultipleUserConnector::GetBackgroundUserIds(backgroundUserIds); - if (DeviceManagerService::GetInstance().IsPC()) { - MultipleUserConnector::ClearLockedUser(foregroundUserIds, backgroundUserIds); - } + MultipleUserConnector::ClearLockedUser(foregroundUserIds, backgroundUserIds); std::vector foregroundUserIdsU32; std::vector backgroundUserIdsU32; for (auto const &u : foregroundUserIds) { @@ -236,12 +224,12 @@ void DMCommTool::ProcessReceiveUserIdsEvent(const std::shared_ptr LOGE("Parse but get none remote foreground userids"); } else { // step2: process remote foreground/background userids - DeviceManagerService::GetInstance().ProcessSyncUserIds(userIdsMsg.foregroundUserIds, + DeviceManagerService::GetInstance().ProcessCommonEvent(userIdsMsg.foregroundUserIds, userIdsMsg.backgroundUserIds, rmtUdid); } } -void DMCommTool::ProcessResponseUserIdsEvent(const std::shared_ptr commMsg) +void DMCommTool::ProcessResponseCommonEvent(const std::shared_ptr commMsg) { LOGI("process receive remote userids response"); // step1: close socket @@ -269,7 +257,7 @@ void DMCommTool::ProcessResponseUserIdsEvent(const std::shared_ptr } // step2: process remote foreground/background userids if (!userIdsMsg.foregroundUserIds.empty()) { - DeviceManagerService::GetInstance().ProcessSyncUserIds(userIdsMsg.foregroundUserIds, + DeviceManagerService::GetInstance().ProcessCommonEvent(userIdsMsg.foregroundUserIds, userIdsMsg.backgroundUserIds, rmtUdid); } else { LOGE("Receive remote foreground userid empty"); @@ -286,145 +274,6 @@ const std::shared_ptr DMCommTool::GetDMTransportPtr() return this->dmTransportPtr_; } -int32_t DMCommTool::CreateUserStopMessage(int32_t stopUserId, std::string &msgStr) -{ - cJSON *root = cJSON_CreateObject(); - if (root == nullptr) { - LOGE("Create cJSON object failed."); - return ERR_DM_FAILED; - } - cJSON *numberObj = cJSON_CreateNumber(stopUserId); - if (numberObj == nullptr) { - cJSON_Delete(root); - return ERR_DM_FAILED; - } - cJSON_AddItemToObject(root, USER_STOP_MSG_KEY, numberObj); - char *msg = cJSON_PrintUnformatted(root); - if (msg == nullptr) { - cJSON_Delete(root); - return ERR_DM_FAILED; - } - msgStr = std::string(msg); - cJSON_free(msg); - cJSON_Delete(root); - return DM_OK; -} - -int32_t DMCommTool::ParseUserStopMessage(const std::string &msgStr, int32_t &stopUserId) -{ - cJSON *root = cJSON_Parse(msgStr.c_str()); - if (root == NULL) { - LOGE("the msg is not json format"); - return ERR_DM_FAILED; - } - cJSON *stopUserIdObj = cJSON_GetObjectItem(root, USER_STOP_MSG_KEY); - if (stopUserIdObj == NULL || !cJSON_IsNumber(stopUserIdObj)) { - LOGE("parse stopUserId id failed."); - cJSON_Delete(root); - return ERR_DM_FAILED; - } - stopUserId = static_cast(stopUserIdObj->valueint); - cJSON_Delete(root); - return DM_OK; -} - -int32_t DMCommTool::SendUserStop(const std::string rmtNetworkId, int32_t stopUserId) -{ - std::string msgStr; - int32_t ret = CreateUserStopMessage(stopUserId, msgStr); - if (ret != DM_OK) { - LOGE("error ret: %{public}d", ret); - return ret; - } - return SendMsg(rmtNetworkId, DM_COMM_SEND_USER_STOP, msgStr); -} - -int32_t DMCommTool::SendMsg(const std::string rmtNetworkId, int32_t msgType, const std::string &msg) -{ - if (!IsIdLengthValid(rmtNetworkId) || dmTransportPtr_ == nullptr) { - LOGE("param invalid, networkId: %{public}s", GetAnonyString(rmtNetworkId).c_str()); - return ERR_DM_INPUT_PARA_INVALID; - } - int32_t socketId; - if (dmTransportPtr_->StartSocket(rmtNetworkId, socketId) != DM_OK || socketId <= 0) { - LOGE("Start socket error"); - return ERR_DM_FAILED; - } - CommMsg commMsg(msgType, msg); - std::string payload = GetCommMsgString(commMsg); - int32_t ret = dmTransportPtr_->Send(rmtNetworkId, payload, socketId); - if (ret != DM_OK) { - LOGE("SendMsg failed, ret: %{public}d", ret); - return ERR_DM_FAILED; - } - LOGI("SendMsg success"); - return DM_OK; -} - -void DMCommTool::ProcessReceiveUserStopEvent(const std::shared_ptr commMsg) -{ - LOGI("start"); - CHECK_NULL_VOID(commMsg); - std::string rmtUdid = ""; - SoftbusCache::GetInstance().GetUdidFromCache(commMsg->remoteNetworkId.c_str(), rmtUdid); - if (rmtUdid.empty()) { - LOGE("Can not find remote udid by networkid: %{public}s", GetAnonyString(commMsg->remoteNetworkId).c_str()); - return; - } - int32_t stopUserId = -1; - int32_t ret = ParseUserStopMessage(commMsg->commMsg->msg, stopUserId); - if (ret != DM_OK) { - LOGE("ParseUserStopMessage error ret: %{public}d", ret); - return; - } - RspUserStop(commMsg->remoteNetworkId, commMsg->socketId, stopUserId); - DeviceManagerService::GetInstance().HandleUserStop(stopUserId, rmtUdid); -} - -void DMCommTool::RspUserStop(const std::string rmtNetworkId, int32_t socketId, int32_t stopUserId) -{ - std::string msgStr = ""; - CHECK_NULL_VOID(dmTransportPtr_); - int32_t ret = CreateUserStopMessage(stopUserId, msgStr); - if (ret != DM_OK || msgStr.empty()) { - LOGE("error ret: %{public}d", ret); - return; - } - CommMsg commMsg(DM_COMM_RSP_USER_STOP, msgStr); - std::string payload = GetCommMsgString(commMsg); - ret = dmTransportPtr_->Send(rmtNetworkId, payload, socketId); - if (ret != DM_OK) { - LOGE("failed, ret: %{public}d", ret); - return; - } - LOGI("success"); -} - -void DMCommTool::ProcessResponseUserStopEvent(const std::shared_ptr commMsg) -{ - LOGI("start"); - CHECK_NULL_VOID(commMsg); - this->dmTransportPtr_->StopSocket(commMsg->remoteNetworkId); - std::string rmtUdid = ""; - SoftbusCache::GetInstance().GetUdidFromCache(commMsg->remoteNetworkId.c_str(), rmtUdid); - if (rmtUdid.empty()) { - LOGE("Can not find remote udid by networkid: %{public}s", GetAnonyString(commMsg->remoteNetworkId).c_str()); - return; - } - int32_t stopUserId = -1; - int32_t ret = ParseUserStopMessage(commMsg->commMsg->msg, stopUserId); - if (ret != DM_OK) { - LOGE("ParseUserStopMessage error ret: %{public}d", ret); - return; - } - std::vector acceptEventUdids; - acceptEventUdids.push_back(rmtUdid); - char localDeviceId[DEVICE_UUID_LENGTH] = {0}; - GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); - std::string localUdid = static_cast(localDeviceId); - DeviceManagerService::GetInstance().HandleUserStop(stopUserId, localUdid, acceptEventUdids); -} - int32_t DMCommTool::SendLogoutAccountInfo(const std::string &rmtNetworkId, const std::string &accountId, int32_t userId) { @@ -498,5 +347,19 @@ void DMCommTool::ProcessReceiveLogoutEvent(const std::shared_ptr c rmtUdid, logoutAccountMsg.userId); LOGI("process remote logout success."); } + +int32_t DMCommTool::StartCommonEvent(std::string commonEventType, EventCallback eventCallback) +{ + if (commonEventType.empty() || eventCallback == nullptr) { + LOGE("StartCommonEvent input value invalid"); + return ERR_DM_INPUT_PARA_INVALID; + } + CHECK_NULL_RETURN(eventQueue_, ERR_DM_POINT_NULL); + LOGI("StartCommonEvent start eventType: %{public}s", commonEventType.c_str()); + std::lock_guard locker(eventMutex_); + auto taskFunc = [eventCallback] () { eventCallback(); }; + eventQueue_->submit(taskFunc); + return DM_OK; +} } // DistributedHardware } // OHOS \ No newline at end of file diff --git a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp index 823dd2a5b6e89d551284531973025c998e99b5d3..5560095c102ac678750003518cb6012b3b478ce1 100644 --- a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp +++ b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp @@ -45,7 +45,6 @@ namespace { * | userid lower 2 bytes | */ const int32_t DEL_USER_PAYLOAD_LEN = 2; - const int32_t STOP_USER_PAYLOAD_LEN = 2; /** * @brief the userid payload cost 2 bytes. * @@ -127,10 +126,6 @@ bool RelationShipChangeMsg::ToBroadcastPayLoad(uint8_t *&msg, uint32_t &len) con ToDelUserPayLoad(msg, len); ret = true; break; - case RelationShipChangeType::STOP_USER: - ToStopUserPayLoad(msg, len); - ret = true; - break; default: LOGE("RelationShipChange type invalid"); break; @@ -165,9 +160,6 @@ bool RelationShipChangeMsg::FromBroadcastPayLoad(const cJSON *payloadJson, Relat case RelationShipChangeType::DEL_USER: ret = FromDelUserPayLoad(payloadJson); break; - case RelationShipChangeType::STOP_USER: - ret = FromStopUserPayLoad(payloadJson); - break; default: LOGE("RelationShipChange type invalid"); break; @@ -191,9 +183,6 @@ bool RelationShipChangeMsg::IsValid() const case RelationShipChangeType::DEL_USER: ret = (userId != UINT32_MAX); break; - case RelationShipChangeType::STOP_USER: - ret = (userId != UINT32_MAX); - break; case RelationShipChangeType::SERVICE_UNBIND: ret = (userId != UINT32_MAX); break; @@ -219,8 +208,7 @@ bool RelationShipChangeMsg::IsChangeTypeValid() { return (type == RelationShipChangeType::ACCOUNT_LOGOUT) || (type == RelationShipChangeType::DEVICE_UNBIND) || (type == RelationShipChangeType::APP_UNBIND) || (type == RelationShipChangeType::SYNC_USERID) || - (type == RelationShipChangeType::DEL_USER) || (type == RelationShipChangeType::STOP_USER) || - (type == RelationShipChangeType::SERVICE_UNBIND); + (type == RelationShipChangeType::DEL_USER) || (type == RelationShipChangeType::SERVICE_UNBIND); } bool RelationShipChangeMsg::IsChangeTypeValid(uint32_t type) @@ -230,7 +218,6 @@ 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::SERVICE_UNBIND); } @@ -323,15 +310,6 @@ void RelationShipChangeMsg::ToDelUserPayLoad(uint8_t *&msg, uint32_t &len) const } } -void RelationShipChangeMsg::ToStopUserPayLoad(uint8_t *&msg, uint32_t &len) const -{ - len = STOP_USER_PAYLOAD_LEN; - msg = new uint8_t[STOP_USER_PAYLOAD_LEN](); - for (int i = 0; i < STOP_USER_PAYLOAD_LEN; i++) { - msg[i] |= (userId >> (i * BITS_PER_BYTE)) & 0xFF; - } -} - bool RelationShipChangeMsg::FromAccountLogoutPayLoad(const cJSON *payloadJson) { if (payloadJson == NULL) { @@ -506,29 +484,6 @@ bool RelationShipChangeMsg::FromDelUserPayLoad(const cJSON *payloadJson) return true; } -bool RelationShipChangeMsg::FromStopUserPayLoad(const cJSON *payloadJson) -{ - if (payloadJson == NULL) { - LOGE("FromStopUserPayLoad payloadJson is null."); - return false; - } - - int32_t arraySize = cJSON_GetArraySize(payloadJson); - if (arraySize < STOP_USER_PAYLOAD_LEN) { - LOGE("Payload invalid, the size is %{public}d.", arraySize); - return false; - } - this->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)) { - this->userId |= (static_cast(payloadItem->valueint)) << (i * BITS_PER_BYTE); - } - } - return true; -} - cJSON *RelationShipChangeMsg::ToPayLoadJson() const { uint8_t *payload = nullptr; diff --git a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp index 1cf70e56a91a393917d9942dc9f090b44b0348e5..67dfc4409c6879ae567e82a52e6f1a05931da5b4 100644 --- a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp +++ b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp @@ -1553,38 +1553,6 @@ HWTEST_F(DeviceProfileConnectorTest, GetDeviceIdAndUserId_001, testing::ext::Tes EXPECT_FALSE(ret.empty()); } -HWTEST_F(DeviceProfileConnectorTest, HandleUserSwitched_001, testing::ext::TestSize.Level1) -{ - int32_t currentUserId = 0; - std::string localUdid = "deviceId"; - int32_t beforeUserId = 123456; - std::vector deviceVec; - int32_t ret = DeviceProfileConnector::GetInstance().HandleUserSwitched(localUdid, deviceVec, currentUserId, - beforeUserId); - EXPECT_EQ(ret, DM_OK); - - beforeUserId = 1234; - currentUserId = 123456; - ret = DeviceProfileConnector::GetInstance().HandleUserSwitched(localUdid, deviceVec, currentUserId, beforeUserId); - EXPECT_EQ(ret, DM_OK); - - std::vector remoteUserIds; - remoteUserIds.push_back(currentUserId); - std::string remoteUdid = "deviceId"; - std::vector localUserIds; - localUserIds.push_back(currentUserId); - DeviceProfileConnector::GetInstance().HandleSyncForegroundUserIdEvent(remoteUserIds, remoteUdid, - localUserIds, localUdid); - - localUdid = "remoteDeviceId"; - remoteUdid = "localDeviceId"; - int32_t localdeviceId = 456; - remoteUserIds.push_back(localdeviceId); - localUserIds.push_back(localdeviceId); - DeviceProfileConnector::GetInstance().HandleSyncForegroundUserIdEvent(remoteUserIds, remoteUdid, - localUserIds, localUdid); -} - HWTEST_F(DeviceProfileConnectorTest, GetOfflineProcessInfo_001, testing::ext::TestSize.Level1) { std::string localUdid = "deviceId"; @@ -1633,8 +1601,9 @@ HWTEST_F(DeviceProfileConnectorTest, GetUserIdAndBindLevel_001, testing::ext::Te remoteFrontUserIds.push_back(userId); std::vector remoteBackUserIds; remoteBackUserIds.push_back(userId); + DmOfflineParam offlineParam; DeviceProfileConnector::GetInstance().UpdateACL(localUdid, localUserIds, remoteUdid, remoteFrontUserIds, - remoteBackUserIds); + remoteBackUserIds, offlineParam); localUdid = "remoteDeviceId"; remoteUdid = "localDeviceId"; @@ -1810,13 +1779,14 @@ HWTEST_F(DeviceProfileConnectorTest, CheckSrcDevIdInAclForDevBind_005, testing:: std::vector remoteFrontUserIds; std::vector remoteBackUserIds; AddAccessControlProfileFirst(profiles); + DmOfflineParam offlineParam; DeviceProfileConnector::GetInstance().DeleteSigTrustACL(profiles, remoteUdid, - remoteFrontUserIds, remoteBackUserIds); + remoteFrontUserIds, remoteBackUserIds, offlineParam); remoteUdid = "localDeviceId"; AddAccessControlProfileSeven(profiles); DeviceProfileConnector::GetInstance().DeleteSigTrustACL(profiles, remoteUdid, - remoteFrontUserIds, remoteBackUserIds); + remoteFrontUserIds, remoteBackUserIds, offlineParam); AddAccessControlProfileEight(profiles); std::string localUdid = "localDeviceId"; diff --git a/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp b/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp index 081b33071b2cec11ecf6fa9ce34d0e663fba537d..08bff7eaad0eb3e5ae5eaabff5f0735c38271be1 100644 --- a/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp +++ b/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp @@ -197,10 +197,13 @@ HWTEST_F(DeviceProfileConnectorSecondTest, CheckIdenticalAccount_201, testing::e remoteFrontUserIds.push_back(userIds); std::vector remoteBackUserIds; remoteBackUserIds.push_back(userIds); - DeviceProfileConnector::GetInstance().DeleteSigTrustACL(profile, remoteUdid, remoteFrontUserIds, remoteBackUserIds); + DmOfflineParam offlineParam; + DeviceProfileConnector::GetInstance().DeleteSigTrustACL(profile, remoteUdid, remoteFrontUserIds, remoteBackUserIds, + offlineParam); remoteUdid = "deviceIdEe"; - DeviceProfileConnector::GetInstance().DeleteSigTrustACL(profile, remoteUdid, remoteFrontUserIds, remoteBackUserIds); + DeviceProfileConnector::GetInstance().DeleteSigTrustACL(profile, remoteUdid, remoteFrontUserIds, remoteBackUserIds, + offlineParam); int32_t userIdee = 0; accessee.SetAccesseeUserId(userIdee); diff --git a/test/servicesfuzztest/dmcommtool_fuzzer/BUILD.gn b/test/servicesfuzztest/dmcommtool_fuzzer/BUILD.gn index 1b4f684c653c8b1c2afda1b5c9c85ad5eb900d3d..996046c408949617bf9eb0b3fdf7d7a1b79af265 100644 --- a/test/servicesfuzztest/dmcommtool_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/dmcommtool_fuzzer/BUILD.gn @@ -77,6 +77,7 @@ ohos_fuzztest("DmCommToolFuzzTest") { "device_auth:deviceauth_sdk", "dsoftbus:softbus_client", "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_single", "napi:ace_napi", "safwk:system_ability_fwk", diff --git a/test/servicesfuzztest/dmcommtool_fuzzer/dm_comm_tool_fuzzer.cpp b/test/servicesfuzztest/dmcommtool_fuzzer/dm_comm_tool_fuzzer.cpp index 4ab2117144813abee624cf109dfad9f10e2ba95a..ccacfaef3c005a374881cd38401abe558ef70b1a 100644 --- a/test/servicesfuzztest/dmcommtool_fuzzer/dm_comm_tool_fuzzer.cpp +++ b/test/servicesfuzztest/dmcommtool_fuzzer/dm_comm_tool_fuzzer.cpp @@ -55,8 +55,8 @@ void DmCommToolFuzzTest(const uint8_t* data, size_t size) std::string remoteNetworkId(reinterpret_cast(data), size); std::shared_ptr commMsg = std::make_shared(); std::shared_ptr innerCommMsg = std::make_shared(remoteNetworkId, commMsg, socketId); - dmCommToolPtr_->ProcessReceiveUserIdsEvent(innerCommMsg); - dmCommToolPtr_->ProcessResponseUserIdsEvent(innerCommMsg); + dmCommToolPtr_->ProcessReceiveCommonEvent(innerCommMsg); + dmCommToolPtr_->ProcessResponseCommonEvent(innerCommMsg); dmCommToolPtr_->GetDMTransportPtr(); dmCommToolPtr_->GetEventHandler(); } diff --git a/test/servicesfuzztest/dmtransport_fuzzer/BUILD.gn b/test/servicesfuzztest/dmtransport_fuzzer/BUILD.gn index d1c54b3c821a1cc69ff8c582fa899cdf0ed9f4fd..cb9f486296cf6b19a82f0ded415635120821e79e 100644 --- a/test/servicesfuzztest/dmtransport_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/dmtransport_fuzzer/BUILD.gn @@ -77,6 +77,7 @@ ohos_fuzztest("DmTransPortFuzzTest") { "device_auth:deviceauth_sdk", "dsoftbus:softbus_client", "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_single", "napi:ace_napi", "safwk:system_ability_fwk", diff --git a/test/servicesfuzztest/dmtransportmsg_fuzzer/BUILD.gn b/test/servicesfuzztest/dmtransportmsg_fuzzer/BUILD.gn index b8a68a713a75e7cf56ba0eaa3e1d3930272cea49..ae85c6248d77454d9803f6c782929f647c967f9f 100644 --- a/test/servicesfuzztest/dmtransportmsg_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/dmtransportmsg_fuzzer/BUILD.gn @@ -79,6 +79,7 @@ ohos_fuzztest("DmTransPortMsgFuzzTest") { "device_auth:deviceauth_sdk", "dsoftbus:softbus_client", "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_single", "napi:ace_napi", "safwk:system_ability_fwk", diff --git a/test/unittest/UTTest_device_manager_service_impl.cpp b/test/unittest/UTTest_device_manager_service_impl.cpp index e160833a61347e3b1d89a4cb9ea9fc6a96084433..3f1a4c4698b785e5dd40f6d479e2fd7fc522c276 100644 --- a/test/unittest/UTTest_device_manager_service_impl.cpp +++ b/test/unittest/UTTest_device_manager_service_impl.cpp @@ -1847,16 +1847,6 @@ HWTEST_F(DeviceManagerServiceImplTest, GetDeviceIdAndUserId_001, testing::ext::T deviceManagerServiceImpl_->Initialize(listener_); } deviceManagerServiceImpl_->HandleIdentAccountLogout(localUdid, localUserId, peerUdid, peerUserId); - - std::vector foregroundUserIds; - std::vector backgroundUserIds; - std::string remoteUdid = "deviceId"; - deviceManagerServiceImpl_->HandleSyncUserIdEvent(foregroundUserIds, backgroundUserIds, remoteUdid, false); - - std::vector deviceVec; - int32_t currentUserId = 1; - int32_t beforeUserId = 0; - deviceManagerServiceImpl_->HandleUserSwitched(deviceVec, currentUserId, beforeUserId); } HWTEST_F(DeviceManagerServiceImplTest, SaveOnlineDeviceInfo_001, testing::ext::TestSize.Level1) diff --git a/test/unittest/UTTest_device_manager_service_impl_first.cpp b/test/unittest/UTTest_device_manager_service_impl_first.cpp index af21d1fa71d71878a31134d17f962b20a2ef39e6..8ccaff09bb9dd9961f352c53d505d50bf5b6ac68 100644 --- a/test/unittest/UTTest_device_manager_service_impl_first.cpp +++ b/test/unittest/UTTest_device_manager_service_impl_first.cpp @@ -74,19 +74,6 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, GetDeviceIdAndUserId_101, testing::e deviceManagerServiceImpl_->Initialize(listener_); } deviceManagerServiceImpl_->HandleIdentAccountLogout(localUdid, localUserId, peerUdid, peerUserId); - - std::vector foregroundUserIds; - std::vector backgroundUserIds; - std::string remoteUdid = "deviceId"; - EXPECT_CALL(*multipleUserConnectorMock_, GetForegroundUserIds(_)).WillOnce(Return(ERR_DM_FAILED)); - deviceManagerServiceImpl_->HandleSyncUserIdEvent(foregroundUserIds, backgroundUserIds, remoteUdid, false); - - std::vector localUserIds; - localUserIds.push_back(101); - localUserIds.push_back(102); - EXPECT_CALL(*multipleUserConnectorMock_, GetForegroundUserIds(_)) - .WillOnce(DoAll(SetArgReferee<0>(localUserIds), Return(DM_OK))); - deviceManagerServiceImpl_->HandleSyncUserIdEvent(foregroundUserIds, backgroundUserIds, remoteUdid, false); } } // namespace } // namespace DistributedHardware diff --git a/test/unittest/UTTest_device_manager_service_three.cpp b/test/unittest/UTTest_device_manager_service_three.cpp index 275518afed30c7c2af898dfbc8ab66a80b82202d..224c2b5a1c33bbf1e7d788d6cabd516965f77a10 100644 --- a/test/unittest/UTTest_device_manager_service_three.cpp +++ b/test/unittest/UTTest_device_manager_service_three.cpp @@ -386,11 +386,6 @@ HWTEST_F(DeviceManagerServiceThreeTest, ExportAuthCode_301, testing::ext::TestSi EXPECT_CALL(*deviceManagerServiceMock_, IsDMServiceImplReady()).WillOnce(Return(false)); DeviceManagerService::GetInstance().HandleAccountLogout(userId, accountId, accountName); - int32_t curUserId = 0; - int32_t preUserId = 1; - EXPECT_CALL(*deviceManagerServiceMock_, IsDMServiceImplReady()).WillOnce(Return(false)); - DeviceManagerService::GetInstance().HandleUserSwitched(curUserId, preUserId); - EXPECT_CALL(*deviceManagerServiceMock_, IsDMServiceImplReady()).WillOnce(Return(false)); DeviceManagerService::GetInstance().HandleUserRemoved(preUserId); } diff --git a/test/unittest/UTTest_device_manager_service_two.cpp b/test/unittest/UTTest_device_manager_service_two.cpp index 4e3ebfea4126c4409cce0d39630bc745a8bdf1c4..e650b8cdf6b01ef6a54633e4fb30e0e8d68e5eac 100644 --- a/test/unittest/UTTest_device_manager_service_two.cpp +++ b/test/unittest/UTTest_device_manager_service_two.cpp @@ -634,8 +634,6 @@ HWTEST_F(DeviceManagerServiceTest, UnAuthenticateDevice_201, testing::ext::TestS EXPECT_CALL(*cryptoMock_, GetAccountIdHash(_, _)).WillOnce(Return(ERR_DM_FAILED)); DeviceManagerService::GetInstance().HandleAccountLogout(userId, accountId, accountName); - int32_t curUserId = 0; - int32_t preUserId = 1; std::map curUserDeviceMap; curUserDeviceMap["curUserId"] = userId; curUserDeviceMap["preUserId"] = userId; @@ -646,7 +644,6 @@ HWTEST_F(DeviceManagerServiceTest, UnAuthenticateDevice_201, testing::ext::TestS GetDeviceIdAndBindLevel(_)).WillOnce(Return(curUserDeviceMap)).WillOnce(Return(preUserDeviceMap)); EXPECT_CALL(*multipleUserConnectorMock_, GetForegroundUserIds(_)).WillOnce(Return(ERR_DM_FAILED)); EXPECT_CALL(*multipleUserConnectorMock_, GetBackgroundUserIds(_)).WillOnce(Return(ERR_DM_FAILED)); - DeviceManagerService::GetInstance().HandleUserSwitched(curUserId, preUserId); int32_t removeId = 123; deviceMap.insert(std::make_pair("removeId", removeId)); @@ -722,7 +719,6 @@ HWTEST_F(DeviceManagerServiceTest, AuthenticateDevice_205, testing::ext::TestSiz EXPECT_CALL(*multipleUserConnectorMock_, GetForegroundUserIds(_)) .WillOnce(Return(ERR_DM_FAILED)).WillOnce(Return(ERR_DM_FAILED)); EXPECT_CALL(*multipleUserConnectorMock_, GetBackgroundUserIds(_)).WillOnce(Return(ERR_DM_FAILED)); - DeviceManagerService::GetInstance().HandleUserIdsBroadCast(remoteUserIdInfos, remoteUdid, isNeedResponse); std::vector foregroundUserVec; foregroundUserVec.push_back(1); @@ -730,7 +726,6 @@ HWTEST_F(DeviceManagerServiceTest, AuthenticateDevice_205, testing::ext::TestSiz EXPECT_CALL(*multipleUserConnectorMock_, GetForegroundUserIds(_)) .WillOnce(DoAll(SetArgReferee<0>(foregroundUserVec), Return(DM_OK))).WillOnce(Return(DM_OK)); EXPECT_CALL(*multipleUserConnectorMock_, GetBackgroundUserIds(_)).WillOnce(Return(DM_OK)); - DeviceManagerService::GetInstance().HandleUserIdsBroadCast(remoteUserIdInfos, remoteUdid, isNeedResponse); DeviceManagerService::GetInstance().softbusListener_ = nullptr; } @@ -1018,8 +1013,6 @@ HWTEST_F(DeviceManagerServiceTest, UnBindDevice_205, testing::ext::TestSize.Leve EXPECT_EQ(ret, ERR_DM_FAILED); int32_t userId = 123456; - int32_t curUserId = 0; - int32_t preUserId = 1; std::map curUserDeviceMap; curUserDeviceMap["curUserId"] = userId; curUserDeviceMap["preUserId"] = userId; @@ -1033,12 +1026,6 @@ HWTEST_F(DeviceManagerServiceTest, UnBindDevice_205, testing::ext::TestSize.Leve EXPECT_CALL(*multipleUserConnectorMock_, GetForegroundUserIds(_)) .WillRepeatedly(DoAll(SetArgReferee<0>(foregroundUserVec), Return(DM_OK))); EXPECT_CALL(*multipleUserConnectorMock_, GetBackgroundUserIds(_)).WillRepeatedly(Return(DM_OK)); - DeviceManagerService::GetInstance().HandleUserSwitched(curUserId, preUserId); - - std::vector remoteUserIdInfos; - std::string remoteUdid; - bool isNeedResponse = false; - DeviceManagerService::GetInstance().HandleUserIdsBroadCast(remoteUserIdInfos, remoteUdid, isNeedResponse); std::vector peerUdids; userId = 123; @@ -1086,90 +1073,6 @@ HWTEST_F(DeviceManagerServiceTest, GetAnonyLocalUdid_202, testing::ext::TestSize EXPECT_EQ(ret, DM_OK); } -HWTEST_F(DeviceManagerServiceTest, NotifyRemoteLocalUserSwitch_201, testing::ext::TestSize.Level1) -{ - int32_t curUserId = 1; - int32_t preUserId = 1; - std::vector peerUdids; - std::vector foregroundUserIds; - std::vector backgroundUserIds; - DeviceManagerService::GetInstance().NotifyRemoteLocalUserSwitch(curUserId, preUserId, peerUdids, foregroundUserIds, - backgroundUserIds); - - peerUdids.push_back("peerUdid001"); - peerUdids.push_back("peerUdid002"); - DeviceManagerService::GetInstance().softbusListener_ = nullptr; - DeviceManagerService::GetInstance().NotifyRemoteLocalUserSwitch(curUserId, preUserId, peerUdids, foregroundUserIds, - backgroundUserIds); - EXPECT_EQ(DeviceManagerService::GetInstance().softbusListener_, nullptr); - - DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); - EXPECT_CALL(*softbusCacheMock_, GetNetworkIdFromCache(_, _)).Times(::testing::AtLeast(2)) - .WillOnce(DoAll(SetArgReferee<1>(""), Return(DM_OK))); - DeviceManagerService::GetInstance().NotifyRemoteLocalUserSwitch(curUserId, preUserId, peerUdids, foregroundUserIds, - backgroundUserIds); - EXPECT_NE(DeviceManagerService::GetInstance().softbusListener_, nullptr); - - EXPECT_CALL(*softbusCacheMock_, GetNetworkIdFromCache(_, _)).Times(::testing::AtLeast(2)) - .WillOnce(DoAll(SetArgReferee<1>("networkId"), Return(DM_OK))); - EXPECT_CALL(*softbusListenerMock_, GetNetworkTypeByNetworkId(_, _)) - .WillOnce(DoAll(SetArgReferee<1>(0), Return(ERR_DM_FAILED))); - DeviceManagerService::GetInstance().NotifyRemoteLocalUserSwitch(curUserId, preUserId, peerUdids, foregroundUserIds, - backgroundUserIds); - EXPECT_NE(DeviceManagerService::GetInstance().softbusListener_, nullptr); - - DeviceManagerService::GetInstance().timer_ = std::make_shared(); - EXPECT_CALL(*dMCommToolMock_, SendUserIds(_, _, _)).WillOnce(Return(ERR_DM_FAILED)); - EXPECT_CALL(*softbusCacheMock_, GetNetworkIdFromCache(_, _)).Times(::testing::AtLeast(2)) - .WillOnce(DoAll(SetArgReferee<1>("networkId"), Return(DM_OK))); - EXPECT_CALL(*softbusListenerMock_, GetNetworkTypeByNetworkId(_, _)) - .WillOnce(DoAll(SetArgReferee<1>(1), Return(DM_OK))); - DeviceManagerService::GetInstance().NotifyRemoteLocalUserSwitch(curUserId, preUserId, peerUdids, foregroundUserIds, - backgroundUserIds); - EXPECT_NE(DeviceManagerService::GetInstance().softbusListener_, nullptr); - - EXPECT_CALL(*softbusCacheMock_, GetNetworkIdFromCache(_, _)).Times(::testing::AtLeast(2)) - .WillOnce(DoAll(SetArgReferee<1>("networkId"), Return(DM_OK))); - EXPECT_CALL(*softbusListenerMock_, GetNetworkTypeByNetworkId(_, _)) - .WillOnce(DoAll(SetArgReferee<1>(4), Return(DM_OK))); - DeviceManagerService::GetInstance().NotifyRemoteLocalUserSwitch(curUserId, preUserId, peerUdids, foregroundUserIds, - backgroundUserIds); - EXPECT_NE(DeviceManagerService::GetInstance().softbusListener_, nullptr); -} - -HWTEST_F(DeviceManagerServiceTest, NotifyRemoteLocalUserSwitchByWifi_201, testing::ext::TestSize.Level1) -{ - DeviceManagerService::GetInstance().timer_ = std::make_shared(); - int32_t curUserId = 1; - int32_t preUserId = 1; - std::map wifiDevices; - std::vector foregroundUserIds; - std::vector backgroundUserIds; - wifiDevices.insert(std::make_pair("kdmalsalskalw002", "networkId008")); - EXPECT_CALL(*dMCommToolMock_, SendUserIds(_, _, _)).WillOnce(Return(ERR_DM_FAILED)); - DeviceManagerService::GetInstance().NotifyRemoteLocalUserSwitchByWifi(curUserId, preUserId, wifiDevices, - foregroundUserIds, backgroundUserIds); - EXPECT_NE(DeviceManagerService::GetInstance().timer_, nullptr); - - std::string udid = "udid"; - DeviceManagerService::GetInstance().HandleUserSwitchTimeout(curUserId, preUserId, udid); -} - -HWTEST_F(DeviceManagerServiceTest, SendUserIdsByWifi_201, testing::ext::TestSize.Level1) -{ - std::string networkId = "networkId001"; - std::vector foregroundUserIds; - std::vector backgroundUserIds; - foregroundUserIds.push_back(101); - foregroundUserIds.push_back(102); - backgroundUserIds.push_back(103); - backgroundUserIds.push_back(104); - EXPECT_CALL(*dMCommToolMock_, SendUserIds(_, _, _)).WillOnce(Return(ERR_DM_FAILED)); - int32_t ret = DeviceManagerService::GetInstance().SendUserIdsByWifi(networkId, foregroundUserIds, - backgroundUserIds); - EXPECT_EQ(ret, ERR_DM_FAILED); -} - HWTEST_F(DeviceManagerServiceTest, StopAuthenticateDevice_004, testing::ext::TestSize.Level1) { std::string pkgName = "pkgName_004"; @@ -1521,50 +1424,6 @@ HWTEST_F(DeviceManagerServiceTest, UpdateLocalServiceInfo_201, testing::ext::Tes EXPECT_CALL(*deviceProfileConnectorMock_, UpdateLocalServiceInfo(_)).WillOnce(Return(DM_OK)); int32_t ret = DeviceManagerService::GetInstance().UpdateLocalServiceInfo(serviceInfo); EXPECT_EQ(ret, DM_OK); - - std::string localUdid = "localUdid"; - std::vector peerUdids{"kxjasdkaj"}; - std::vector foregroundUserIds{1, 2}; - std::vector backgroundUserIds{1, 2}; - DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); - EXPECT_CALL(*softbusCacheMock_, GetNetworkIdFromCache(_, _)).WillOnce(DoAll(SetArgReferee<1>(""), Return(DM_OK))); - DeviceManagerService::GetInstance().NotifyRemoteLocalUserSwitch(localUdid, peerUdids, - foregroundUserIds, backgroundUserIds); - - EXPECT_CALL(*softbusCacheMock_, GetNetworkIdFromCache(_, _)) - .WillOnce(DoAll(SetArgReferee<1>("net*****7"), Return(DM_OK))); - EXPECT_CALL(*softbusListenerMock_, GetNetworkTypeByNetworkId(_, _)) - .WillOnce(DoAll(SetArgReferee<1>(1), Return(ERR_DM_FAILED))); - DeviceManagerService::GetInstance().NotifyRemoteLocalUserSwitch(localUdid, peerUdids, - foregroundUserIds, backgroundUserIds); - - EXPECT_CALL(*softbusCacheMock_, GetNetworkIdFromCache(_, _)) - .WillOnce(DoAll(SetArgReferee<1>("net*****7"), Return(DM_OK))); - EXPECT_CALL(*softbusListenerMock_, GetNetworkTypeByNetworkId(_, _)) - .WillOnce(DoAll(SetArgReferee<1>(1), Return(DM_OK))); - EXPECT_CALL(*dMCommToolMock_, SendUserIds(_, _, _)).WillOnce(Return(ERR_DM_FAILED)); - DeviceManagerService::GetInstance().NotifyRemoteLocalUserSwitch(localUdid, peerUdids, - foregroundUserIds, backgroundUserIds); - - EXPECT_CALL(*softbusCacheMock_, GetNetworkIdFromCache(_, _)) - .WillOnce(DoAll(SetArgReferee<1>("net*****7"), Return(DM_OK))); - EXPECT_CALL(*softbusListenerMock_, GetNetworkTypeByNetworkId(_, _)) - .WillOnce(DoAll(SetArgReferee<1>(4), Return(DM_OK))); - DeviceManagerService::GetInstance().NotifyRemoteLocalUserSwitch(localUdid, peerUdids, - foregroundUserIds, backgroundUserIds); - - std::map wifiDevices; - wifiDevices.insert(std::make_pair("deviceName", "networkwifi")); - EXPECT_CALL(*dMCommToolMock_, SendUserIds(_, _, _)).WillOnce(Return(ERR_DM_FAILED)); - DeviceManagerService::GetInstance().NotifyRemoteLocalUserSwitchByWifi(localUdid, wifiDevices, - foregroundUserIds, backgroundUserIds); - - GTEST_LOG_(INFO) << "NotifyRemoteLocalUserSwitchByWifi SendUserIds is ok" ; - EXPECT_CALL(*dMCommToolMock_, SendUserIds(_, _, _)).WillOnce(Return(DM_OK)); - DeviceManagerService::GetInstance().NotifyRemoteLocalUserSwitchByWifi(localUdid, wifiDevices, - foregroundUserIds, backgroundUserIds); - GTEST_LOG_(INFO) << "NotifyRemoteLocalUserSwitchByWifi end" ; - DeviceManagerService::GetInstance().softbusListener_ = nullptr; } HWTEST_F(DeviceManagerServiceTest, GetLocalServiceInfoByBundleNameAndPinExchangeType_201, @@ -1585,7 +1444,6 @@ HWTEST_F(DeviceManagerServiceTest, GetLocalServiceInfoByBundleNameAndPinExchange .WillOnce(DoAll(SetArgReferee<0>(foregroundUserVec), Return(DM_OK))); EXPECT_CALL(*multipleUserConnectorMock_, GetBackgroundUserIds(_)).WillOnce(Return(DM_OK)); EXPECT_CALL(*deviceProfileConnectorMock_, CheckAclStatusAndForegroundNotMatch(_, _, _)).WillOnce(Return(false)); - DeviceManagerService::GetInstance().HandleUserSwitched(); EXPECT_CALL(*multipleUserConnectorMock_, GetForegroundUserIds(_)) .WillOnce(DoAll(SetArgReferee<0>(foregroundUserVec), Return(DM_OK))); @@ -1597,20 +1455,6 @@ HWTEST_F(DeviceManagerServiceTest, GetLocalServiceInfoByBundleNameAndPinExchange preUserDeviceMap.insert(std::make_pair("preUser******info", 11)); EXPECT_CALL(*deviceProfileConnectorMock_, GetDeviceIdAndBindLevel(_, _)).WillOnce(Return(curUserDeviceMap)).WillOnce(Return(preUserDeviceMap)); - DeviceManagerService::GetInstance().HandleUserSwitched(); - - std::string localUdid = "localUdid"; - std::string udid = "u*********90"; - std::vector backgroundUserIds{1, 2, 3}; - DeviceManagerService::GetInstance().HandleUserSwitchTimeout(localUdid, foregroundUserVec, backgroundUserIds, udid); - - std::vector peerUdids; - DeviceManagerService::GetInstance().NotifyRemoteLocalUserSwitch(localUdid, peerUdids, foregroundUserVec, - backgroundUserIds); - - DeviceManagerService::GetInstance().softbusListener_ = nullptr; - DeviceManagerService::GetInstance().NotifyRemoteLocalUserSwitch(localUdid, peerUdids, foregroundUserVec, - backgroundUserIds); DeviceManagerService::GetInstance().UninitDMServiceListener(); } @@ -1749,31 +1593,6 @@ HWTEST_F(DeviceManagerServiceTest, GetDeviceNetworkIdList_201, testing::ext::Tes DeletePermission(); int32_t ret = DeviceManagerService::GetInstance().GetDeviceNetworkIdList(pkgName, queryFilter, networkIds); EXPECT_EQ(ret, ERR_DM_NO_PERMISSION); - - int32_t stopUserId = 1; - std::string stopEventUdid = "ud*********4"; - std::vector acceptEventUdids{"acc**********7"}; - DeviceManagerService::GetInstance().InitDMServiceListener(); - DeviceManagerService::GetInstance().HandleUserStop(stopUserId, stopEventUdid, acceptEventUdids); - DeviceManagerService::GetInstance().HandleUserStop(stopUserId, stopEventUdid); - - std::string localUdid = "local*******76"; - std::vector peerUdids; - DeviceManagerService::GetInstance().NotifyRemoteLocalUserStop(localUdid, peerUdids, stopUserId); - DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); - DeviceManagerService::GetInstance().SendUserStopBroadCast(peerUdids, stopUserId); - std::string remoteUdid = "re********7"; - DeviceManagerService::GetInstance().HandleUserStopBroadCast(stopUserId, remoteUdid); - - std::map wifiDevices; - wifiDevices.insert(std::make_pair("wikjdmcsk", "deviceInfowifi")); - EXPECT_CALL(*dMCommToolMock_, SendUserStop(_, _)).WillOnce(Return(ERR_DM_FAILED)); - DeviceManagerService::GetInstance().NotifyRemoteLocalUserStopByWifi(localUdid, wifiDevices, stopUserId); - - EXPECT_CALL(*dMCommToolMock_, SendUserStop(_, _)).WillOnce(Return(DM_OK)); - DeviceManagerService::GetInstance().NotifyRemoteLocalUserStopByWifi(localUdid, wifiDevices, stopUserId); - DeviceManagerService::GetInstance().UninitDMServiceListener(); - DeviceManagerService::GetInstance().softbusListener_ = nullptr; } HWTEST_F(DeviceManagerServiceTest, GetDeviceNetworkIdList_202, testing::ext::TestSize.Level1) @@ -1783,46 +1602,6 @@ HWTEST_F(DeviceManagerServiceTest, GetDeviceNetworkIdList_202, testing::ext::Tes std::vector networkIds{"uehd*****87"}; int32_t ret = DeviceManagerService::GetInstance().GetDeviceNetworkIdList(pkgName, queryFilter, networkIds); EXPECT_NE(ret, DM_OK); - - int32_t stopUserId = 1; - std::map deviceMap; - EXPECT_CALL(*deviceProfileConnectorMock_, GetDeviceIdAndBindLevel(_, _)) - .WillOnce(Return(deviceMap)); - DeviceManagerService::GetInstance().InitDMServiceListener(); - DeviceManagerService::GetInstance().HandleUserStopEvent(stopUserId); - - std::vector peerUdids; - std::vector bleUdids; - std::map wifiDevices; - DeviceManagerService::GetInstance().DivideNotifyMethod(peerUdids, bleUdids, wifiDevices); - - peerUdids.push_back("u********23"); - DeviceManagerService::GetInstance().softbusListener_ = nullptr; - DeviceManagerService::GetInstance().DivideNotifyMethod(peerUdids, bleUdids, wifiDevices); - - DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); - EXPECT_CALL(*softbusCacheMock_, GetNetworkIdFromCache(_, _)) - .WillOnce(DoAll(SetArgReferee<1>(""), Return(DM_OK))); - DeviceManagerService::GetInstance().DivideNotifyMethod(peerUdids, bleUdids, wifiDevices); - - EXPECT_CALL(*softbusCacheMock_, GetNetworkIdFromCache(_, _)) - .WillOnce(DoAll(SetArgReferee<1>("net********8"), Return(DM_OK))); - EXPECT_CALL(*softbusListenerMock_, GetNetworkTypeByNetworkId(_, _)) - .WillOnce(DoAll(SetArgReferee<1>(4), Return(ERR_DM_FAILED))); - DeviceManagerService::GetInstance().DivideNotifyMethod(peerUdids, bleUdids, wifiDevices); - - EXPECT_CALL(*softbusCacheMock_, GetNetworkIdFromCache(_, _)) - .WillOnce(DoAll(SetArgReferee<1>("net********8"), Return(DM_OK))); - EXPECT_CALL(*softbusListenerMock_, GetNetworkTypeByNetworkId(_, _)) - .WillOnce(DoAll(SetArgReferee<1>(4), Return(DM_OK))); - DeviceManagerService::GetInstance().DivideNotifyMethod(peerUdids, bleUdids, wifiDevices); - - EXPECT_CALL(*softbusCacheMock_, GetNetworkIdFromCache(_, _)) - .WillOnce(DoAll(SetArgReferee<1>("net********8"), Return(DM_OK))); - EXPECT_CALL(*softbusListenerMock_, GetNetworkTypeByNetworkId(_, _)) - .WillOnce(DoAll(SetArgReferee<1>(2), Return(DM_OK))); - DeviceManagerService::GetInstance().DivideNotifyMethod(peerUdids, bleUdids, wifiDevices); - DeviceManagerService::GetInstance().UninitDMServiceListener(); } } // namespace } // namespace DistributedHardware diff --git a/test/unittest/UTTest_dm_comm_tool.cpp b/test/unittest/UTTest_dm_comm_tool.cpp index 0f8971cf88f54a38cbf868f495d3b4c4c4216b01..61549a83ba827b80e3d37b78af74411d1f9b6a79 100644 --- a/test/unittest/UTTest_dm_comm_tool.cpp +++ b/test/unittest/UTTest_dm_comm_tool.cpp @@ -93,55 +93,10 @@ HWTEST_F(DMCommToolTest, SendUserIds_001, testing::ext::TestSize.Level1) int32_t socketId = 1; EXPECT_CALL(*dmTransportMock_, Send(_, _, _)).Times(::testing::AtLeast(2)).WillOnce(Return(ERR_DM_FAILED)); dmCommTool->RspLocalFrontOrBackUserIds(rmtNetworkId, foregroundUserIds, backgroundUserIds, socketId); - - std::string remoteNetworkId = "network******12"; - std::string strMsg = R"({ - "MsgType": "0", - "userId": "12345", - "syncUserIdFlag": 1, - "userIds": [ - {"type": 1, "userId": 111}, - {"type": 0, "userId": 222} - ] - })"; - std::shared_ptr commMsg_ = std::make_shared(1, strMsg); - socketId = 0; - std::shared_ptr InnerCommMsg_ = std::make_shared(remoteNetworkId, commMsg_, socketId); - std::string rmtUdid = ""; - EXPECT_CALL(*softbusCacheMock_, GetUdidFromCache(_, _)) - .WillOnce(DoAll(SetArgReferee<1>(rmtUdid), Return(ERR_DM_FAILED))); - dmCommTool->ProcessReceiveUserIdsEvent(InnerCommMsg_); - rmtUdid = "b*********12"; - EXPECT_CALL(*softbusCacheMock_, GetUdidFromCache(_, _)) - .WillOnce(DoAll(SetArgReferee<1>(rmtUdid), Return(ERR_DM_FAILED))); - dmCommTool->ProcessReceiveUserIdsEvent(InnerCommMsg_); } -HWTEST_F(DMCommToolTest, ProcessResponseUserIdsEvent_001, testing::ext::TestSize.Level1) +HWTEST_F(DMCommToolTest, SendUserIds_002, testing::ext::TestSize.Level1) { - std::string remoteNetworkId = "network******12"; - std::string strMsg = R"({ - "MsgType": "0", - "userId": "12345", - "syncUserIdFlag": 1, - "foregroundUserIds": [10, 11, 12], - "backgroundUserIds": [101, 112, 123], - "userIds": [ - {"type": 1, "userId": 111}, - {"type": 0, "userId": 222} - ] - })"; - std::shared_ptr commMsg_ = std::make_shared(1, strMsg); - int32_t socketId = 0; - std::shared_ptr InnerCommMsg_ = std::make_shared(remoteNetworkId, commMsg_, socketId); - EXPECT_CALL(*softbusCacheMock_, GetUdidFromCache(_, _)) - .WillOnce(DoAll(SetArgReferee<1>(""), Return(ERR_DM_FAILED))); - dmCommTool->ProcessResponseUserIdsEvent(InnerCommMsg_); - - EXPECT_CALL(*softbusCacheMock_, GetUdidFromCache(_, _)) - .WillOnce(DoAll(SetArgReferee<1>("rmtUdid"), Return(ERR_DM_FAILED))); - dmCommTool->ProcessResponseUserIdsEvent(InnerCommMsg_); - std::string rmtNetworkId = ""; std::vector foregroundUserIds; std::vector backgroundUserIds; @@ -162,311 +117,5 @@ HWTEST_F(DMCommToolTest, UnInit_002, testing::ext::TestSize.Level1) EXPECT_NO_THROW(dmCommTool->UnInit()); } - -HWTEST_F(DMCommToolTest, SendMsg_001, testing::ext::TestSize.Level1) -{ - std::string invalidNetworkId = ""; - int32_t msgType = 1; - std::string msg = "test message"; - - int32_t ret = dmCommTool->SendMsg(invalidNetworkId, msgType, msg); - EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); -} - -HWTEST_F(DMCommToolTest, SendMsg_002, testing::ext::TestSize.Level1) -{ - dmCommTool->dmTransportPtr_ = nullptr; - std::string rmtNetworkId = "validNetworkId"; - int32_t msgType = 1; - std::string msg = "test message"; - - int32_t ret = dmCommTool->SendMsg(rmtNetworkId, msgType, msg); - EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); -} - -HWTEST_F(DMCommToolTest, SendMsg_003, testing::ext::TestSize.Level1) -{ - std::string rmtNetworkId = "validNetworkId"; - int32_t msgType = 1; - std::string msg = "test message"; - - EXPECT_CALL(*dmTransportMock_, StartSocket(rmtNetworkId, _)) - .WillOnce(Return(ERR_DM_FAILED)); - - int32_t ret = dmCommTool->SendMsg(rmtNetworkId, msgType, msg); - EXPECT_EQ(ret, ERR_DM_FAILED); -} - -HWTEST_F(DMCommToolTest, SendMsg_004, testing::ext::TestSize.Level1) -{ - std::string rmtNetworkId = "validNetworkId"; - int32_t msgType = 1; - std::string msg = "test message"; - - EXPECT_CALL(*dmTransportMock_, StartSocket(rmtNetworkId, _)) - .WillOnce(DoAll(SetArgReferee<1>(-1), Return(DM_OK))); - - int32_t ret = dmCommTool->SendMsg(rmtNetworkId, msgType, msg); - EXPECT_EQ(ret, ERR_DM_FAILED); -} - -HWTEST_F(DMCommToolTest, SendMsg_005, testing::ext::TestSize.Level1) -{ - std::string rmtNetworkId = "validNetworkId"; - int32_t msgType = 1; - std::string msg = "test message"; - - EXPECT_CALL(*dmTransportMock_, StartSocket(rmtNetworkId, _)) - .WillOnce(DoAll(SetArgReferee<1>(1), Return(DM_OK))); - EXPECT_CALL(*dmTransportMock_, Send(rmtNetworkId, _, 1)) - .WillOnce(Return(ERR_DM_FAILED)); - - int32_t ret = dmCommTool->SendMsg(rmtNetworkId, msgType, msg); - EXPECT_EQ(ret, ERR_DM_FAILED); -} - -HWTEST_F(DMCommToolTest, SendMsg_006, testing::ext::TestSize.Level1) -{ - std::string rmtNetworkId = "validNetworkId"; - int32_t msgType = 1; - std::string msg = "test message"; - - EXPECT_CALL(*dmTransportMock_, StartSocket(rmtNetworkId, _)) - .WillOnce(DoAll(SetArgReferee<1>(1), Return(DM_OK))); - EXPECT_CALL(*dmTransportMock_, Send(rmtNetworkId, _, 1)) - .WillOnce(Return(DM_OK)); - - int32_t ret = dmCommTool->SendMsg(rmtNetworkId, msgType, msg); - EXPECT_EQ(ret, DM_OK); -} - -HWTEST_F(DMCommToolTest, SendUserStop_001, testing::ext::TestSize.Level1) -{ - std::string rmtNetworkId = "validNetworkId"; - int32_t stopUserId = 12345; - - EXPECT_CALL(*dmTransportMock_, StartSocket(rmtNetworkId, _)) - .Times(1).WillOnce(Return(DM_OK)); - EXPECT_CALL(*dmTransportMock_, Send(_, _, _)).Times(0); - - int32_t ret = dmCommTool->SendUserStop(rmtNetworkId, stopUserId); - EXPECT_EQ(ret, ERR_DM_FAILED); -} - -HWTEST_F(DMCommToolTest, SendUserStop_002, testing::ext::TestSize.Level1) -{ - std::string invalidNetworkId = ""; - int32_t stopUserId = 12345; - - int32_t ret = dmCommTool->SendUserStop(invalidNetworkId, stopUserId); - EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); -} - -HWTEST_F(DMCommToolTest, SendUserStop_003, testing::ext::TestSize.Level1) -{ - std::string rmtNetworkId = "validNetworkId"; - int32_t stopUserId = 12345; - - EXPECT_CALL(*dmTransportMock_, StartSocket(rmtNetworkId, _)) - .WillOnce(DoAll(SetArgReferee<1>(1), Return(DM_OK))); - EXPECT_CALL(*dmTransportMock_, Send(rmtNetworkId, _, 1)) - .WillOnce(Return(ERR_DM_FAILED)); - - int32_t ret = dmCommTool->SendUserStop(rmtNetworkId, stopUserId); - EXPECT_EQ(ret, ERR_DM_FAILED); -} - -HWTEST_F(DMCommToolTest, SendUserStop_004, testing::ext::TestSize.Level1) -{ - std::string rmtNetworkId = "validNetworkId"; - int32_t stopUserId = 12345; - - EXPECT_CALL(*dmTransportMock_, StartSocket(rmtNetworkId, _)) - .WillOnce(Return(ERR_DM_FAILED)); - - int32_t ret = dmCommTool->SendUserStop(rmtNetworkId, stopUserId); - EXPECT_EQ(ret, ERR_DM_FAILED); -} - -HWTEST_F(DMCommToolTest, SendUserStop_005, testing::ext::TestSize.Level1) -{ - std::string rmtNetworkId = "validNetworkId"; - int32_t stopUserId = 12345; - - EXPECT_CALL(*dmTransportMock_, StartSocket(rmtNetworkId, _)) - .WillOnce(DoAll(SetArgReferee<1>(1), Return(DM_OK))); - EXPECT_CALL(*dmTransportMock_, Send(rmtNetworkId, _, 1)) - .WillOnce(Return(DM_OK)); - - int32_t ret = dmCommTool->SendUserStop(rmtNetworkId, stopUserId); - EXPECT_EQ(ret, DM_OK); -} - -HWTEST_F(DMCommToolTest, ParseUserStopMessage_001, testing::ext::TestSize.Level1) -{ - std::string invalidJson = "invalid_json"; - int32_t stopUserId = -1; - - int32_t result = DMCommTool::GetInstance()->ParseUserStopMessage(invalidJson, stopUserId); - EXPECT_EQ(result, ERR_DM_FAILED); -} - -HWTEST_F(DMCommToolTest, ParseUserStopMessage_002, testing::ext::TestSize.Level1) -{ - std::string jsonWithoutKey = R"({ "otherKey": 12345 })"; - int32_t stopUserId = -1; - - int32_t result = DMCommTool::GetInstance()->ParseUserStopMessage(jsonWithoutKey, stopUserId); - EXPECT_EQ(result, ERR_DM_FAILED); -} - -HWTEST_F(DMCommToolTest, ParseUserStopMessage_003, testing::ext::TestSize.Level1) -{ - std::string jsonWithInvalidValue = R"({ "stopUserId": "not_a_number" })"; - int32_t stopUserId = -1; - - int32_t result = DMCommTool::GetInstance()->ParseUserStopMessage(jsonWithInvalidValue, stopUserId); - EXPECT_EQ(result, ERR_DM_FAILED); -} - -HWTEST_F(DMCommToolTest, ParseUserStopMessage_004, testing::ext::TestSize.Level1) -{ - std::string validJson = R"({ "stopUserId": 12345 })"; - int32_t stopUserId = -1; - - int32_t result = DMCommTool::GetInstance()->ParseUserStopMessage(validJson, stopUserId); - EXPECT_EQ(result, DM_OK); - EXPECT_EQ(stopUserId, 12345); -} - -HWTEST_F(DMCommToolTest, ProcessReceiveUserStopEvent_001, testing::ext::TestSize.Level1) -{ - std::shared_ptr commMsg = nullptr; - - EXPECT_NO_THROW(dmCommTool->ProcessReceiveUserStopEvent(commMsg)); -} - -HWTEST_F(DMCommToolTest, ProcessReceiveUserStopEvent_002, testing::ext::TestSize.Level1) -{ - std::shared_ptr commMsg_ = std::make_shared(1, "{}"); - std::shared_ptr commMsg = std::make_shared("networkId", commMsg_, 0); - - EXPECT_CALL(*softbusCacheMock_, GetUdidFromCache(_, _)) - .WillOnce(DoAll(SetArgReferee<1>(""), Return(ERR_DM_FAILED))); - - EXPECT_NO_THROW(dmCommTool->ProcessReceiveUserStopEvent(commMsg)); -} - -HWTEST_F(DMCommToolTest, ProcessReceiveUserStopEvent_003, testing::ext::TestSize.Level1) -{ - std::shared_ptr commMsg_ = std::make_shared(1, "invalid_json"); - std::shared_ptr commMsg = std::make_shared("networkId", commMsg_, 0); - - EXPECT_CALL(*softbusCacheMock_, GetUdidFromCache(_, _)) - .WillOnce(DoAll(SetArgReferee<1>("validUdid"), Return(DM_OK))); - - EXPECT_NO_THROW(dmCommTool->ProcessReceiveUserStopEvent(commMsg)); -} - -HWTEST_F(DMCommToolTest, ProcessReceiveUserStopEvent_004, testing::ext::TestSize.Level1) -{ - std::string validJson = R"({ "stopUserId": 12345 })"; - std::shared_ptr commMsg_ = std::make_shared(1, validJson); - std::shared_ptr commMsg = std::make_shared("networkId", commMsg_, 0); - - EXPECT_CALL(*softbusCacheMock_, GetUdidFromCache(_, _)) - .WillOnce(DoAll(SetArgReferee<1>("validUdid"), Return(DM_OK))); - EXPECT_CALL(*dmTransportMock_, Send(_, _, _)).Times(1); - - EXPECT_NO_THROW(dmCommTool->ProcessReceiveUserStopEvent(commMsg)); -} - -HWTEST_F(DMCommToolTest, RspUserStop_001, testing::ext::TestSize.Level1) -{ - dmCommTool->dmTransportPtr_ = nullptr; - std::string rmtNetworkId = "validNetworkId"; - int32_t socketId = 1; - int32_t stopUserId = 12345; - - EXPECT_NO_THROW(dmCommTool->RspUserStop(rmtNetworkId, socketId, stopUserId)); -} - -HWTEST_F(DMCommToolTest, RspUserStop_002, testing::ext::TestSize.Level1) -{ - std::string rmtNetworkId = "validNetworkId"; - int32_t invalidSocketId = -1; - int32_t stopUserId = 12345; - - EXPECT_CALL(*dmTransportMock_, Send(rmtNetworkId, _, invalidSocketId)) - .WillOnce(Return(ERR_DM_FAILED)); - - EXPECT_NO_THROW(dmCommTool->RspUserStop(rmtNetworkId, invalidSocketId, stopUserId)); -} - -HWTEST_F(DMCommToolTest, RspUserStop_003, testing::ext::TestSize.Level1) -{ - std::string rmtNetworkId = "validNetworkId"; - int32_t socketId = 1; - int32_t stopUserId = 12345; - - EXPECT_CALL(*dmTransportMock_, Send(rmtNetworkId, _, socketId)) - .WillOnce(Return(ERR_DM_FAILED)); - - EXPECT_NO_THROW(dmCommTool->RspUserStop(rmtNetworkId, socketId, stopUserId)); -} - -HWTEST_F(DMCommToolTest, RspUserStop_004, testing::ext::TestSize.Level1) -{ - std::string rmtNetworkId = "validNetworkId"; - int32_t socketId = 1; - int32_t stopUserId = 12345; - - EXPECT_CALL(*dmTransportMock_, Send(rmtNetworkId, _, socketId)) - .WillOnce(Return(DM_OK)); - - EXPECT_NO_THROW(dmCommTool->RspUserStop(rmtNetworkId, socketId, stopUserId)); -} - -HWTEST_F(DMCommToolTest, ProcessResponseUserStopEvent_001, testing::ext::TestSize.Level1) -{ - std::shared_ptr commMsg = nullptr; - - EXPECT_NO_THROW(dmCommTool->ProcessResponseUserStopEvent(commMsg)); -} - -HWTEST_F(DMCommToolTest, ProcessResponseUserStopEvent_002, testing::ext::TestSize.Level1) -{ - std::shared_ptr commMsg_ = std::make_shared(1, "{}"); - std::shared_ptr commMsg = std::make_shared("networkId", commMsg_, 0); - - EXPECT_CALL(*softbusCacheMock_, GetUdidFromCache(_, _)) - .WillOnce(DoAll(SetArgReferee<1>(""), Return(ERR_DM_FAILED))); - - EXPECT_NO_THROW(dmCommTool->ProcessResponseUserStopEvent(commMsg)); -} - -HWTEST_F(DMCommToolTest, ProcessResponseUserStopEvent_003, testing::ext::TestSize.Level1) -{ - std::shared_ptr commMsg_ = std::make_shared(1, "invalid_json"); - std::shared_ptr commMsg = std::make_shared("networkId", commMsg_, 0); - - EXPECT_CALL(*softbusCacheMock_, GetUdidFromCache(_, _)) - .WillOnce(DoAll(SetArgReferee<1>("validUdid"), Return(DM_OK))); - - EXPECT_NO_THROW(dmCommTool->ProcessResponseUserStopEvent(commMsg)); -} - -HWTEST_F(DMCommToolTest, ProcessResponseUserStopEvent_004, testing::ext::TestSize.Level1) -{ - std::string validJson = R"({ "stopUserId": 12345 })"; - std::shared_ptr commMsg_ = std::make_shared(1, validJson); - std::shared_ptr commMsg = std::make_shared("networkId", commMsg_, 0); - - EXPECT_CALL(*softbusCacheMock_, GetUdidFromCache(_, _)) - .WillOnce(DoAll(SetArgReferee<1>("validUdid"), Return(DM_OK))); - - EXPECT_NO_THROW(dmCommTool->ProcessResponseUserStopEvent(commMsg)); -} - } // DistributedHardware } // OHOS \ No newline at end of file diff --git a/test/unittest/mock/dm_comm_tool_mock.cpp b/test/unittest/mock/dm_comm_tool_mock.cpp index 28afdc998e2ac95d06f460877fd9509f404fe18b..5c783d5613c3648ed96515dcb1f65acf1572aa05 100644 --- a/test/unittest/mock/dm_comm_tool_mock.cpp +++ b/test/unittest/mock/dm_comm_tool_mock.cpp @@ -25,14 +25,5 @@ int32_t DMCommTool::SendUserIds(const std::string rmtNetworkId, return DmDMCommTool::dmDMCommTool->SendUserIds(rmtNetworkId, foregroundUserIds, backgroundUserIds); } -int32_t DMCommTool::SendUserStop(const std::string rmtNetworkId, int32_t stopUserId) -{ - return DmDMCommTool::dmDMCommTool->SendUserStop(rmtNetworkId, stopUserId); -} - -int32_t DMCommTool::CreateUserStopMessage(int32_t stopUserId, std::string &msgStr) -{ - return DmDMCommTool::dmDMCommTool->CreateUserStopMessage(stopUserId, msgStr); -} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/dm_comm_tool_mock.h b/test/unittest/mock/dm_comm_tool_mock.h index 735f8179c9dd4b1032e6c2543f8f3eac9116b0ea..92f7504d187dec8ab36e511597f15a9f3c94e418 100644 --- a/test/unittest/mock/dm_comm_tool_mock.h +++ b/test/unittest/mock/dm_comm_tool_mock.h @@ -28,8 +28,6 @@ public: public: virtual int32_t SendUserIds(const std::string rmtNetworkId, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds) = 0; - virtual int32_t SendUserStop(const std::string rmtNetworkId, int32_t stopUserId) = 0; - virtual int32_t CreateUserStopMessage(int32_t stopUserId, std::string &msgStr) = 0; public: static inline std::shared_ptr dmDMCommTool = nullptr; }; @@ -38,8 +36,6 @@ class DMCommToolMock : public DmDMCommTool { public: MOCK_METHOD(int32_t, SendUserIds, (const std::string, const std::vector &, const std::vector &)); - MOCK_METHOD(int32_t, SendUserStop, (const std::string, int32_t)); - MOCK_METHOD(int32_t, CreateUserStopMessage, (int32_t stopUserId, std::string &msgStr)); }; } }