diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index b69113c97f3262533dc5d5854d1cc480573f4386..35551f9ae12de62e2f4b73ff7bb24f9d67ba38d8 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -145,6 +145,8 @@ public: 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 HandleUserUnlocked(const std::string &localUdid, const std::vector &deviceVec, + const std::vector &foregroundUserIds, const std::vector &backgroundUserIds) = 0; }; class DeviceProfileConnector : public IDeviceProfileConnector { @@ -239,7 +241,8 @@ public: 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); + 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); @@ -311,6 +314,8 @@ public: DM_EXPORT void AclHashVecFromJson(const JsonItemObject &itemObject, std::vector &values); void DeleteCacheAcl(std::vector delAclIdVec, std::vector &profiles); + DM_EXPORT int32_t HandleUserUnlocked(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 +347,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); @@ -376,7 +382,7 @@ private: DmOfflineParam &offlineParam, std::vector &profiles); }; -extern "C" IDeviceProfileConnector *CreateDpConnectorInstance(); +DM_EXPORT extern "C" IDeviceProfileConnector *CreateDpConnectorInstance(); using CreateDpConnectorFuncPtr = IDeviceProfileConnector *(*)(void); } // namespace DistributedHardware } // namespace OHOS diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 4f00c859db8fcba83895587b60ad5938f193b39d..19d35b600722cfe8670cb8b3f157465b3fc6e2b6 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -2225,21 +2225,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 +2251,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; } } @@ -2584,11 +2586,11 @@ 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)) || + 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))) { + profile.GetStatus() == ACTIVE)) { return true; } if ((profile.GetAccesser().GetAccesserDeviceId() == localUdid && @@ -2615,6 +2617,47 @@ bool DeviceProfileConnector::CheckAclStatusAndForegroundNotMatch(const std::stri return false; } +DM_EXPORT int32_t DeviceProfileConnector::HandleUserUnlocked( + const std::string &localUdid, const std::vector &deviceVec, + const std::vector &foregroundUserIds, const std::vector &backgroundUserIds) +{ + LOGI("HandleUserUnlocked start"); + 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 && + (find(backgroundUserIds.begin(), backgroundUserIds.end(), + item.GetAccesser().GetAccesserUserId()) != backgroundUserIds.end()) && item.GetStatus() == ACTIVE) || + (item.GetAccessee().GetAccesseeDeviceId() == localUdid && + (find(backgroundUserIds.begin(), backgroundUserIds.end(), + item.GetAccessee().GetAccesseeUserId()) != backgroundUserIds.end()) && item.GetStatus() == ACTIVE)) { + item.SetStatus(INACTIVE); + inActiveProfiles.push_back(item); + continue; + } + if ((item.GetAccesser().GetAccesserDeviceId() == localUdid && + (find(foregroundUserIds.begin(), foregroundUserIds.end(), + item.GetAccesser().GetAccesserUserId()) != foregroundUserIds.end()) && item.GetStatus() == INACTIVE) || ( + item.GetAccessee().GetAccesseeDeviceId() == localUdid && + (find(foregroundUserIds.begin(), foregroundUserIds.end(), + item.GetAccessee().GetAccesseeUserId()) != foregroundUserIds.end()) && item.GetStatus() == INACTIVE)) { + item.SetStatus(ACTIVE); + activeProfiles.push_back(item); + continue; + } + } + HandleUserSwitched(activeProfiles, inActiveProfiles); + return DM_OK; +} + DM_EXPORT int32_t DeviceProfileConnector::HandleUserSwitched( const std::string &localUdid, const std::vector &deviceVec, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds) @@ -2633,14 +2676,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 && @@ -2738,7 +2779,7 @@ DM_EXPORT void DeviceProfileConnector::CacheAceeAclId(const DistributedDevicePro aclInfos.push_back(dmAclIdParam); } -IDeviceProfileConnector *CreateDpConnectorInstance() +DM_EXPORT IDeviceProfileConnector *CreateDpConnectorInstance() { return &DeviceProfileConnector::GetInstance(); } diff --git a/services/implementation/include/device_manager_service_impl.h b/services/implementation/include/device_manager_service_impl.h index 37f9557c127255960df8c1951f8fc68e9dcd8423..92adc52d8a96b8cd3721ed3801f9443a9c6142be 100644 --- a/services/implementation/include/device_manager_service_impl.h +++ b/services/implementation/include/device_manager_service_impl.h @@ -156,7 +156,7 @@ public: 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); + const std::vector &backgroundUserIds, const std::string &remoteUdid); void HandleUserSwitched(const std::vector &deviceVec, int32_t currentUserId, int32_t beforeUserId); std::multimap GetDeviceIdAndUserId(int32_t localUserId); diff --git a/services/implementation/include/device_manager_service_impl_lite.h b/services/implementation/include/device_manager_service_impl_lite.h index 30d1a279b009d7fc019b4a0243fd8158462298eb..1fa76e966628a90c623bb4b0a925b4ffe44e13a4 100644 --- a/services/implementation/include/device_manager_service_impl_lite.h +++ b/services/implementation/include/device_manager_service_impl_lite.h @@ -152,7 +152,7 @@ public: 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); + const std::vector &backgroundUserIds, const std::string &remoteUdid); void HandleRemoteUserRemoved(int32_t preUserId, const std::string &remoteUdid); std::map GetDeviceIdAndBindLevel(int32_t userId); std::multimap GetDeviceIdAndUserId(int32_t localUserId); diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 395e37b25b243c02910c3971f09fda02a91f42ee..bce8d8c6479da48848cdfba18c2ca73a85f5bb63 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -1953,7 +1953,7 @@ void DeviceManagerServiceImpl::HandleServiceUnBindEvent(int32_t userId, const st } void DeviceManagerServiceImpl::HandleSyncUserIdEvent(const std::vector &foregroundUserIds, - const std::vector &backgroundUserIds, const std::string &remoteUdid, bool isCheckUserStatus) + 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(), @@ -1969,11 +1969,11 @@ void DeviceManagerServiceImpl::HandleSyncUserIdEvent(const std::vector LOGE("Get foreground userids failed, ret: %{public}d", ret); return; } - if (isCheckUserStatus) { - MultipleUserConnector::ClearLockedUser(localUserIds); - } + 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..d8c6001fadaf490e7ca24c7520d030bbc7bdbb3f 100644 --- a/services/implementation/src/device_manager_service_impl_lite.cpp +++ b/services/implementation/src/device_manager_service_impl_lite.cpp @@ -562,12 +562,11 @@ int32_t DeviceManagerServiceImpl::ProcessAppUnintall(const std::string &appId, i } void DeviceManagerServiceImpl::HandleSyncUserIdEvent(const std::vector &foregroundUserIds, - const std::vector &backgroundUserIds, const std::string &remoteUdid, bool isCheckUserStatus) + const std::vector &backgroundUserIds, const std::string &remoteUdid) { (void)foregroundUserIds; (void)backgroundUserIds; (void)remoteUdid; - (void)isCheckUserStatus; return; } diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index 86914ea72d7c6deb8a57d7d4caddb20398a87d6a..dec52c8f777a9585c9cb0777863155fa1c325c49 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -241,7 +241,10 @@ 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 ProcessSyncUserUnlocked(const std::vector &foregroundUserIds, + const std::vector &backgroundUserIds, const std::string &remoteUdid); + void DelTimerAndEventTypeSyncUserIds(const std::string &remoteUdid); + void DelTimerAndEventTypeSyncUserUnlocked(const std::string &remoteUdid); private: bool IsDMServiceImplReady(); bool IsDMImplSoLoaded(); @@ -271,6 +274,9 @@ private: const std::vector &foregroundUserIds, const std::vector &backgroundUserIds, bool isNeedResponse); void SendUserRemovedBroadCast(const std::vector &peerUdids, int32_t userId); + void SendUserUnlockedBroadCast(const std::vector &peerUdids, + const std::vector &foregroundUserIds, const std::vector &backgroundUserIds, + bool isNeedResponse); /** * @brief parse dsoftbus checksum msg * @@ -333,7 +339,7 @@ private: void UpdateAclAndDeleteGroup(const std::string &localUdid, const std::vector &deviceVec, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds); void HandleUserSwitchedEvent(int32_t currentUserId, int32_t beforeUserId); - void HandleUserStopEvent(int32_t stopUserId); + void HandleUserStopEvent(int32_t currentUserId, int32_t stopUserId); void DivideNotifyMethod(const std::vector &peerUdids, std::vector &bleUdids, std::map &wifiDevices); void NotifyRemoteLocalUserStop(const std::string &localUdid, @@ -342,6 +348,20 @@ private: void HandleUserStopBroadCast(int32_t stopUserId, const std::string &remoteUdid); void NotifyRemoteLocalUserStopByWifi(const std::string &localUdid, const std::map &wifiDevices, int32_t stopUserId); + void HandleUserUnlocked(int32_t currentUserId, int32_t beforeUserId); + void NotifyRemoteLocalUserUnlocked(const std::string &localUdid, const std::vector &peerUdids, + const std::vector &foregroundUserIds, const std::vector &backgroundUserIds); + void HandleUserUnlockedBroadCast(const std::vector &remoteUserIdInfos, const std::string &remoteUdid, + bool isNeedResponse); + void HandleUserUnlockedTimeout(const std::string &localUdid, const std::vector &foregroundUserIds, + const std::vector &backgroundUserIds, const std::string &udid); + void UpdateAclUserUnlocked(const std::string &localUdid, const std::vector &deviceVec, + const std::vector &foregroundUserIds, const std::vector &backgroundUserIds); + void NotifyRemoteLocalUserUnlockedByWifi(const std::string &localUdid, + const std::map &wifiDevices, const std::vector &foregroundUserIds, + const std::vector &backgroundUserIds); + int32_t SendUserUnlockedByWifi(const std::string &networkId, + const std::vector &foregroundUserIds, const std::vector &backgroundUserIds); #if defined(SUPPORT_BLUETOOTH) || defined(SUPPORT_WIFI) void SubscribePublishCommonEvent(); void QueryDependsSwitchState(); diff --git a/services/service/include/idevice_manager_service_impl.h b/services/service/include/idevice_manager_service_impl.h index fa2ae7ca36fc4ecce096394dc23bc97cc6f99911..814b89ae8318f923ae54d3ba16999ea18aff7cbd 100644 --- a/services/service/include/idevice_manager_service_impl.h +++ b/services/service/include/idevice_manager_service_impl.h @@ -253,7 +253,7 @@ public: 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; + const std::vector &backgroundUserIds, const std::string &remoteUdid) = 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; diff --git a/services/service/include/relationshipsyncmgr/dm_comm_tool.h b/services/service/include/relationshipsyncmgr/dm_comm_tool.h index d60b00071748ae65af440cd7d58d020a75f21c82..76af3d1065034ac14b59586d43c6a1ef3c29ee7d 100644 --- a/services/service/include/relationshipsyncmgr/dm_comm_tool.h +++ b/services/service/include/relationshipsyncmgr/dm_comm_tool.h @@ -16,11 +16,17 @@ #ifndef OHOS_DM_COMM_TOOL_H #define OHOS_DM_COMM_TOOL_H +#include +#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: @@ -41,7 +47,8 @@ public: 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); - + int32_t SendUserUnlocked(const std::string rmtNetworkId, + const std::vector &foregroundUserIds, const std::vector &backgroundUserIds); class DMCommToolEventHandler : public AppExecFwk::EventHandler { public: DMCommToolEventHandler(const std::shared_ptr runner, @@ -58,9 +65,20 @@ public: 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); + void ProcessReceiveUserUnLockedEvent(const std::shared_ptr commMsg); + void RspUserUnLocked(const std::string rmtNetworkId, const std::vector &foregroundUserIds, + const std::vector &backgroundUserIds, int32_t socketId); + void ProcessResponseUserUnLockedEvent(const std::shared_ptr commMsg); + + int32_t StartCommonEvent(std::string commonEventType, EventCallback eventCallback); + int32_t DeleteCommonEvent(std::string commonEventType); + private: std::shared_ptr dmTransportPtr_; std::shared_ptr eventHandler_; + mutable std::mutex eventMutex_; + std::shared_ptr eventQueue_; + std::unordered_map eventVec_ = {}; }; } // DistributedHardware } // OHOS diff --git a/services/service/include/relationshipsyncmgr/relationship_sync_mgr.h b/services/service/include/relationshipsyncmgr/relationship_sync_mgr.h index cc6409ce119d6d4ea1f2cdf1bcb96129cdc9ccff..4d77ab302394124a96764b3198d9db779758386b 100644 --- a/services/service/include/relationshipsyncmgr/relationship_sync_mgr.h +++ b/services/service/include/relationshipsyncmgr/relationship_sync_mgr.h @@ -30,7 +30,8 @@ enum class RelationShipChangeType : uint32_t { APP_UNINSTALL = 5, SYNC_USERID = 6, STOP_USER = 7, - TYPE_MAX = 8 + UNLOCKED_USER = 8, + TYPE_MAX = 9 }; struct UserIdInfo { diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 0a08623d3cb91a0b1135fd3802a16f9ec7df56eb..104cdcdef5c70221a1c4455cf150ed2d3fae440c 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -81,6 +81,7 @@ namespace { 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_UNLOCKED_BY_WIFI_TIMEOUT_TASK = "deviceManagerTimer:userUnlockedByWifi"; constexpr const char* USER_STOP_BY_WIFI_TIMEOUT_TASK = "deviceManagerTimer:userStopByWifi"; const int32_t USER_SWITCH_BY_WIFI_TIMEOUT_S = 2; } @@ -265,10 +266,6 @@ 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); - } #endif LOGI("Init success."); return DM_OK; @@ -1893,7 +1890,13 @@ DM_EXPORT void DeviceManagerService::AccountCommonEventCallback( 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()); + DMCommTool::GetInstance()->StartCommonEvent(commonEventType, + [this, currentUserId, beforeUserId] () { + DeviceManagerService::HandleUserSwitchedEvent(currentUserId, beforeUserId); + }); } else if (commonEventType == CommonEventSupport::COMMON_EVENT_HWID_LOGIN) { DeviceNameManager::GetInstance().InitDeviceNameWhenLogin(); MultipleUserConnector::SetAccountInfo(currentUserId, MultipleUserConnector::GetCurrentDMAccountInfo()); @@ -1915,22 +1918,74 @@ 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, currentUserId, beforeUserId] () { + DeviceManagerService::HandleUserStopEvent(currentUserId, beforeUserId); + }); } 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, currentUserId, beforeUserId] () { + DeviceManagerService::HandleUserUnlocked(currentUserId, beforeUserId); + }); } else { LOGE("Invalied account common event."); } return; } +void DeviceManagerService::HandleUserUnlocked(int32_t currentUserId, int32_t beforeUserId) +{ + LOGI("HandleUserUnlocked start"); + (void)currentUserId; + 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())); + DMCommTool::GetInstance()->DeleteCommonEvent(CommonEventSupport::COMMON_EVENT_USER_UNLOCKED); + return; + } + if (find(foregroundUserVec.begin(), foregroundUserVec.end(), beforeUserId) == foregroundUserVec.end()) { + 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) { + LOGE("IsCommonDependencyReady failed or GetCommonDependencyObj() is nullptr."); + DMCommTool::GetInstance()->DeleteCommonEvent(CommonEventSupport::COMMON_EVENT_USER_UNLOCKED); + return; + } + if (!discoveryMgr_->GetCommonDependencyObj()->CheckAclStatusAndForegroundNotMatch(localUdid, + foregroundUserVec, backgroundUserVec)) { + LOGI("no unreasonable data."); + DMCommTool::GetInstance()->DeleteCommonEvent(CommonEventSupport::COMMON_EVENT_USER_UNLOCKED); + return; + } + std::map curUserDeviceMap = + discoveryMgr_->GetCommonDependencyObj()->GetDeviceIdAndBindLevel(foregroundUserVec, localUdid); + std::map preUserDeviceMap = + discoveryMgr_->GetCommonDependencyObj()->GetDeviceIdAndBindLevel(backgroundUserVec, localUdid); + std::vector peerUdids; + 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()) { + DMCommTool::GetInstance()->DeleteCommonEvent(CommonEventSupport::COMMON_EVENT_USER_UNLOCKED); + return; + } + NotifyRemoteLocalUserUnlocked(localUdid, peerUdids, foregroundUserVec, backgroundUserVec); +} + void DeviceManagerService::HandleUserSwitched() { LOGI("onStart, HandleUserSwitched."); @@ -1941,6 +1996,12 @@ void DeviceManagerService::HandleUserSwitched() 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())); + DMCommTool::GetInstance()->DeleteCommonEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED); + return; + } + MultipleUserConnector::ClearLockedUser(foregroundUserVec, backgroundUserVec); + if (foregroundUserVec.empty()) { + DMCommTool::GetInstance()->DeleteCommonEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED); return; } char localUdidTemp[DEVICE_UUID_LENGTH] = {0}; @@ -1948,12 +2009,13 @@ void DeviceManagerService::HandleUserSwitched() std::string localUdid = std::string(localUdidTemp); CHECK_NULL_VOID(discoveryMgr_); if (!discoveryMgr_->IsCommonDependencyReady() || discoveryMgr_->GetCommonDependencyObj() == nullptr) { - LOGE("IsCommonDependencyReady failed or GetCommonDependencyObj() is nullptr."); + DMCommTool::GetInstance()->DeleteCommonEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED); return; } if (!discoveryMgr_->GetCommonDependencyObj()->CheckAclStatusAndForegroundNotMatch(localUdid, foregroundUserVec, backgroundUserVec)) { LOGI("no unreasonable data."); + DMCommTool::GetInstance()->DeleteCommonEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED); return; } std::map curUserDeviceMap = @@ -1970,12 +2032,61 @@ void DeviceManagerService::HandleUserSwitched() } } if (peerUdids.empty()) { + DMCommTool::GetInstance()->DeleteCommonEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED); return; } NotifyRemoteLocalUserSwitch(localUdid, peerUdids, foregroundUserVec, backgroundUserVec); } #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) +void DeviceManagerService::NotifyRemoteLocalUserUnlocked(const std::string &localUdid, + const std::vector &peerUdids, const std::vector &foregroundUserIds, + const std::vector &backgroundUserIds) +{ + LOGI("NotifyRemoteLocalUserUnlocked, foregroundUserIds: %{public}s, backgroundUserIds: %{public}s", + GetIntegerList(foregroundUserIds).c_str(), GetIntegerList(backgroundUserIds).c_str()); + if (peerUdids.empty()) { + DMCommTool::GetInstance()->DeleteCommonEvent(CommonEventSupport::COMMON_EVENT_USER_UNLOCKED); + return; + } + if (softbusListener_ == nullptr) { + UpdateAclUserUnlocked(localUdid, peerUdids, foregroundUserIds, backgroundUserIds); + LOGE("softbusListener_ is null"); + DMCommTool::GetInstance()->DeleteCommonEvent(CommonEventSupport::COMMON_EVENT_USER_UNLOCKED); + 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()) { + UpdateAclUserUnlocked(localUdid, peerUdids, foregroundUserIds, backgroundUserIds); + SendUserUnlockedBroadCast(bleUdids, foregroundUserIds, backgroundUserIds, true); + } + if (!wifiDevices.empty()) { + NotifyRemoteLocalUserUnlockedByWifi(localUdid, wifiDevices, foregroundUserIds, backgroundUserIds); + } +} + void DeviceManagerService::NotifyRemoteLocalUserSwitch(const std::string &localUdid, const std::vector &peerUdids, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds) @@ -1983,11 +2094,13 @@ void DeviceManagerService::NotifyRemoteLocalUserSwitch(const std::string &localU LOGI("onstart UserSwitch, foregroundUserIds: %{public}s, backgroundUserIds: %{public}s", GetIntegerList(foregroundUserIds).c_str(), GetIntegerList(backgroundUserIds).c_str()); if (peerUdids.empty()) { + DMCommTool::GetInstance()->DeleteCommonEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED); return; } if (softbusListener_ == nullptr) { UpdateAclAndDeleteGroup(localUdid, peerUdids, foregroundUserIds, backgroundUserIds); LOGE("softbusListener_ is null"); + DMCommTool::GetInstance()->DeleteCommonEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED); return; } std::vector bleUdids; @@ -2022,6 +2135,60 @@ void DeviceManagerService::NotifyRemoteLocalUserSwitch(const std::string &localU } } +void DeviceManagerService::NotifyRemoteLocalUserUnlockedByWifi(const std::string &localUdid, + const std::map &wifiDevices, const std::vector &foregroundUserIds, + const std::vector &backgroundUserIds) +{ + for (const auto &it : wifiDevices) { + int32_t result = SendUserUnlockedByWifi(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); + UpdateAclUserUnlocked(localUdid, updateUdids, foregroundUserIds, backgroundUserIds); + continue; + } + if (timer_ == nullptr) { + timer_ = std::make_shared(); + } + std::string udid = it.first; + timer_->StartTimer(std::string(USER_UNLOCKED_BY_WIFI_TIMEOUT_TASK) + Crypto::Sha256(udid), + USER_SWITCH_BY_WIFI_TIMEOUT_S, + [this, localUdid, foregroundUserIds, backgroundUserIds, udid] (std::string name) { + DeviceManagerService::HandleUserUnlockedTimeout(localUdid, foregroundUserIds, backgroundUserIds, udid); + }); + } +} + +void DeviceManagerService::HandleUserUnlockedTimeout(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); + UpdateAclUserUnlocked(localUdid, updateUdids, foregroundUserIds, backgroundUserIds); + DMCommTool::GetInstance()->DeleteCommonEvent(CommonEventSupport::COMMON_EVENT_USER_UNLOCKED); +} + +void DeviceManagerService::ProcessSyncUserUnlocked(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", + 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_UNLOCKED_BY_WIFI_TIMEOUT_TASK) + Crypto::Sha256(remoteUdid)); + } + if (IsDMServiceImplReady()) { + dmServiceImpl_->HandleSyncUserIdEvent(foregroundUserIds, backgroundUserIds, remoteUdid); + } +} + void DeviceManagerService::NotifyRemoteLocalUserSwitchByWifi(const std::string &localUdid, const std::map &wifiDevices, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds) @@ -2055,6 +2222,7 @@ void DeviceManagerService::HandleUserSwitchTimeout(const std::string &localUdid, std::vector updateUdids; updateUdids.push_back(udid); UpdateAclAndDeleteGroup(localUdid, updateUdids, foregroundUserIds, backgroundUserIds); + DMCommTool::GetInstance()->DeleteCommonEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED); } void DeviceManagerService::UpdateAclAndDeleteGroup(const std::string &localUdid, @@ -2069,6 +2237,19 @@ void DeviceManagerService::UpdateAclAndDeleteGroup(const std::string &localUdid, discoveryMgr_->GetCommonDependencyObj()->HandleUserSwitched(localUdid, deviceVec, foregroundUserIds, backgroundUserIds); } + +void DeviceManagerService::UpdateAclUserUnlocked(const std::string &localUdid, + const std::vector &deviceVec, const std::vector &foregroundUserIds, + const std::vector &backgroundUserIds) +{ + CHECK_NULL_VOID(discoveryMgr_); + if (!discoveryMgr_->IsCommonDependencyReady() || discoveryMgr_->GetCommonDependencyObj() == nullptr) { + LOGE("IsCommonDependencyReady failed or GetCommonDependencyObj() is nullptr."); + return; + } + discoveryMgr_->GetCommonDependencyObj()->HandleUserUnlocked(localUdid, deviceVec, + foregroundUserIds, backgroundUserIds); +} #endif void DeviceManagerService::HandleAccountLogout(int32_t userId, const std::string &accountId, @@ -2114,8 +2295,14 @@ 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 (!MultipleUserConnector::IsUserUnlocked(curUserId)) { + LOGE("curUserId has not unlocked"); + DMCommTool::GetInstance()->DeleteCommonEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED); + return; + } if (!IsDMServiceImplReady()) { LOGE("Init impl failed."); + DMCommTool::GetInstance()->DeleteCommonEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED); return; } std::map curUserDeviceMap; @@ -2132,6 +2319,7 @@ void DeviceManagerService::HandleUserSwitched(int32_t curUserId, int32_t preUser } } if (peerUdids.empty()) { + DMCommTool::GetInstance()->DeleteCommonEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED); return; } std::vector foregroundUserVec; @@ -2141,6 +2329,12 @@ void DeviceManagerService::HandleUserSwitched(int32_t curUserId, int32_t preUser 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())); + DMCommTool::GetInstance()->DeleteCommonEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED); + return; + } + if (find(foregroundUserVec.begin(), foregroundUserVec.end(), curUserId) == foregroundUserVec.end()) { + LOGE("foregroundUserVec has not contain curUserId"); + DMCommTool::GetInstance()->DeleteCommonEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED); return; } NotifyRemoteLocalUserSwitch(curUserId, preUserId, peerUdids, foregroundUserVec, backgroundUserVec); @@ -2216,7 +2410,28 @@ void DeviceManagerService::SendUserIdsBroadCast(const std::vector & softbusListener_->SendAclChangedBroadcast(broadCastMsg); } -void DeviceManagerService::HandleUserIdsBroadCast(const std::vector &remoteUserIdInfos, +void DeviceManagerService::SendUserUnlockedBroadCast(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::UNLOCKED_USER; + 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::HandleUserUnlockedBroadCast(const std::vector &remoteUserIdInfos, const std::string &remoteUdid, bool isNeedResponse) { LOGI("rmtUdid: %{public}s, rmtUserIds: %{public}s, isNeedResponse: %{public}s,", @@ -2227,9 +2442,54 @@ void DeviceManagerService::HandleUserIdsBroadCast(const std::vector std::vector backgroundUserVec; int32_t retFront = MultipleUserConnector::GetForegroundUserIds(foregroundUserVec); 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())); + } else { + LOGE("Send back local frontuserids: %{public}s, backuserids: %{public}s", + GetIntegerList(foregroundUserVec).c_str(), GetIntegerList(backgroundUserVec).c_str()); + std::vector remoteUdids = { remoteUdid }; + SendUserUnlockedBroadCast(remoteUdids, foregroundUserVec, backgroundUserVec, false); } + } + + std::vector foregroundUserIdInfos; + std::vector backgroundUserIdInfos; + GetFrontAndBackUserIdInfos(remoteUserIdInfos, foregroundUserIdInfos, backgroundUserIdInfos); + LOGI("process foreground and background userids"); + // Notify received remote foreground userids to dsoftbus + std::vector foregroundUserIds; + for (const auto &u : foregroundUserIdInfos) { + foregroundUserIds.push_back(static_cast(u.userId)); + } + std::vector backgroundUserIds; + 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); + } + DMCommTool::GetInstance()->DeleteCommonEvent(CommonEventSupport::COMMON_EVENT_USER_UNLOCKED); +} + +void DeviceManagerService::HandleUserIdsBroadCast(const std::vector &remoteUserIdInfos, + const std::string &remoteUdid, bool isNeedResponse) +{ + LOGI("rmtUdid: %{public}s, rmtUserIds: %{public}s, isNeedResponse: %{public}s,", + GetAnonyString(remoteUdid).c_str(), GetUserIdInfoList(remoteUserIdInfos).c_str(), + isNeedResponse ? "true" : "false"); + if (isNeedResponse) { + std::vector foregroundUserVec; + std::vector backgroundUserVec; + int32_t retFront = MultipleUserConnector::GetForegroundUserIds(foregroundUserVec); + int32_t retBack = MultipleUserConnector::GetBackgroundUserIds(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()), @@ -2260,8 +2520,9 @@ void DeviceManagerService::HandleUserIdsBroadCast(const std::vector } if (IsDMServiceImplReady()) { - dmServiceImpl_->HandleSyncUserIdEvent(foregroundUserIds, backgroundUserIds, remoteUdid, IsPC()); + dmServiceImpl_->HandleSyncUserIdEvent(foregroundUserIds, backgroundUserIds, remoteUdid); } + DMCommTool::GetInstance()->DeleteCommonEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED); } void DeviceManagerService::ProcessSyncUserIds(const std::vector &foregroundUserIds, @@ -2278,8 +2539,25 @@ void DeviceManagerService::ProcessSyncUserIds(const std::vector &foreg timer_->DeleteTimer(std::string(USER_SWITCH_BY_WIFI_TIMEOUT_TASK) + Crypto::Sha256(remoteUdid)); } if (IsDMServiceImplReady()) { - dmServiceImpl_->HandleSyncUserIdEvent(foregroundUserIds, backgroundUserIds, remoteUdid, IsPC()); + dmServiceImpl_->HandleSyncUserIdEvent(foregroundUserIds, backgroundUserIds, remoteUdid); + } + DMCommTool::GetInstance()->DeleteCommonEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED); +} + +void DeviceManagerService::DelTimerAndEventTypeSyncUserIds(const std::string &remoteUdid) +{ + if (timer_ != nullptr) { + timer_->DeleteTimer(std::string(USER_SWITCH_BY_WIFI_TIMEOUT_TASK) + Crypto::Sha256(remoteUdid)); } + DMCommTool::GetInstance()->DeleteCommonEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED); +} + +void DeviceManagerService::DelTimerAndEventTypeSyncUserUnlocked(const std::string &remoteUdid) +{ + if (timer_ != nullptr) { + timer_->DeleteTimer(std::string(USER_UNLOCKED_BY_WIFI_TIMEOUT_TASK) + Crypto::Sha256(remoteUdid)); + } + DMCommTool::GetInstance()->DeleteCommonEvent(CommonEventSupport::COMMON_EVENT_USER_UNLOCKED); } void DeviceManagerService::ScreenCommonEventCallback(std::string commonEventType) @@ -2508,14 +2786,11 @@ void DeviceManagerService::SendServiceUnBindBroadCast(const std::vectorDeleteCommonEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED); return; } if (softbusListener_ == nullptr) { dmServiceImpl_->HandleUserSwitched(peerUdids, curUserId, preUserId); LOGE("softbusListener_ is null"); + DMCommTool::GetInstance()->DeleteCommonEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED); return; } std::vector bleUdids; @@ -2928,6 +3208,21 @@ void DeviceManagerService::NotifyRemoteLocalUserSwitchByWifi(int32_t curUserId, } } +int32_t DeviceManagerService::SendUserUnlockedByWifi(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()->SendUserUnlocked(networkId, foregroundUserIdsUInt, backgroundUserIdsUInt); +} + int32_t DeviceManagerService::SendUserIdsByWifi(const std::string &networkId, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds) { @@ -2953,12 +3248,6 @@ void DeviceManagerService::HandleUserSwitchTimeout(int32_t curUserId, int32_t pr void DeviceManagerService::HandleUserSwitchedEvent(int32_t currentUserId, int32_t beforeUserId) { - DeviceNameManager::GetInstance().InitDeviceNameWhenUserSwitch(currentUserId, beforeUserId); - CheckRegisterInfoWithWise(currentUserId); - MultipleUserConnector::SetAccountInfo(currentUserId, MultipleUserConnector::GetCurrentDMAccountInfo()); - if (IsPC()) { - return; - } if (beforeUserId == -1 || currentUserId == -1) { HandleUserSwitched(); return; @@ -2971,31 +3260,34 @@ void DeviceManagerService::HandleUserSwitchedEvent(int32_t currentUserId, int32_ } } -void DeviceManagerService::HandleUserStopEvent(int32_t stopUserId) +void DeviceManagerService::HandleUserStopEvent(int32_t currentUserId, int32_t stopUserId) { LOGI("onStart, HandleUserStopEvent %{public}s.", GetAnonyInt32(stopUserId).c_str()); + (void)currentUserId; 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."); + DMCommTool::GetInstance()->DeleteCommonEvent(CommonEventSupport::COMMON_EVENT_USER_STOPPED); return; } - stopUserDeviceMap = discoveryMgr_->GetCommonDependencyObj()-> - GetDeviceIdAndBindLevel(stopUserVec, localUdid); + std::map stopUserDeviceMap = + discoveryMgr_->GetCommonDependencyObj()->GetDeviceIdAndBindLevel(stopUserVec, localUdid); + std::vector peerUdids; for (const auto &item : stopUserDeviceMap) { peerUdids.push_back(item.first); } if (peerUdids.empty()) { LOGI("no data to be stoped."); + DMCommTool::GetInstance()->DeleteCommonEvent(CommonEventSupport::COMMON_EVENT_USER_STOPPED); return; } NotifyRemoteLocalUserStop(localUdid, peerUdids, stopUserId); + DMCommTool::GetInstance()->DeleteCommonEvent(CommonEventSupport::COMMON_EVENT_USER_STOPPED); } void DeviceManagerService::DivideNotifyMethod(const std::vector &peerUdids, diff --git a/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp b/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp index 8abd91e4dfb3cf9fc68f7a8774f3740813415404..746b1d250b71d80b8103a1a780163b664a2b6626 100644 --- a/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp +++ b/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp @@ -35,9 +35,11 @@ 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; - +constexpr int32_t DM_COMM_SEND_USER_UNLOCKED = 6; +constexpr int32_t DM_COMM_RSP_USER_UNLOCKED = 7; +const int64_t MICROSECOND_TO_SECOND = 1000000L; const char* const USER_STOP_MSG_KEY = "stopUserId"; - +constexpr const char* EVENT_TASK = "EventTask"; DMCommTool::DMCommTool() : dmTransportPtr_(nullptr) { LOGI("Ctor DMCommTool"); @@ -46,6 +48,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()); @@ -68,6 +71,47 @@ std::shared_ptr DMCommTool::GetInstance() return instance; } +int32_t DMCommTool::SendUserUnlocked(const std::string rmtNetworkId, + const std::vector &foregroundUserIds, const std::vector &backgroundUserIds) +{ + if (!IsIdLengthValid(rmtNetworkId) || foregroundUserIds.empty() || dmTransportPtr_ == nullptr) { + LOGE("param invalid, networkId: %{public}s, foreground userids size: %{public}d", + GetAnonyString(rmtNetworkId).c_str(), static_cast(foregroundUserIds.size())); + 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; + } + + UserIdsMsg userIdsMsg(foregroundUserIds, backgroundUserIds); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + LOGE("Create cJSON object failed."); + return ERR_DM_FAILED; + } + ToJson(root, userIdsMsg); + char *msg = cJSON_PrintUnformatted(root); + if (msg == nullptr) { + cJSON_Delete(root); + return ERR_DM_FAILED; + } + std::string msgStr(msg); + cJSON_Delete(root); + cJSON_free(msg); + CommMsg commMsg(DM_COMM_SEND_USER_UNLOCKED, msgStr); + std::string payload = GetCommMsgString(commMsg); + + int32_t ret = dmTransportPtr_->Send(rmtNetworkId, payload, socketId); + if (ret != DM_OK) { + LOGE("Send local foreground userids failed, ret: %{public}d", ret); + return ERR_DM_FAILED; + } + LOGI("Send local foreground userids success"); + return DM_OK; +} + int32_t DMCommTool::SendUserIds(const std::string rmtNetworkId, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds) { @@ -76,6 +120,7 @@ int32_t DMCommTool::SendUserIds(const std::string rmtNetworkId, GetAnonyString(rmtNetworkId).c_str(), static_cast(foregroundUserIds.size())); return ERR_DM_INPUT_PARA_INVALID; } + int32_t socketId; if (dmTransportPtr_->StartSocket(rmtNetworkId, socketId) != DM_OK || socketId <= 0) { LOGE("Start socket error"); @@ -109,6 +154,35 @@ int32_t DMCommTool::SendUserIds(const std::string rmtNetworkId, return DM_OK; } +void DMCommTool::RspUserUnLocked(const std::string rmtNetworkId, + const std::vector &foregroundUserIds, const std::vector &backgroundUserIds, int32_t socketId) +{ + UserIdsMsg userIdsMsg(foregroundUserIds, backgroundUserIds); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + LOGE("Create cJSON object failed."); + return; + } + ToJson(root, userIdsMsg); + char *msg = cJSON_PrintUnformatted(root); + if (msg == nullptr) { + cJSON_Delete(root); + return; + } + std::string msgStr(msg); + cJSON_Delete(root); + cJSON_free(msg); + CommMsg commMsg(DM_COMM_RSP_USER_UNLOCKED, msgStr); + std::string payload = GetCommMsgString(commMsg); + + int32_t ret = dmTransportPtr_->Send(rmtNetworkId, payload, socketId); + if (ret != DM_OK) { + LOGE("Response local foreground userids failed, ret: %{public}d", ret); + return; + } + LOGI("Response local foreground userids success"); +} + void DMCommTool::RspLocalFrontOrBackUserIds(const std::string rmtNetworkId, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds, int32_t socketId) { @@ -144,8 +218,7 @@ DMCommTool::DMCommToolEventHandler::DMCommToolEventHandler(const std::shared_ptr LOGI("Ctor DMCommToolEventHandler"); } -void DMCommTool::DMCommToolEventHandler::ProcessEvent( - const AppExecFwk::InnerEvent::Pointer &event) +void DMCommTool::DMCommToolEventHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) { uint32_t eventId = event->GetInnerEventId(); std::shared_ptr commMsg = event->GetSharedObject(); @@ -185,13 +258,21 @@ void DMCommTool::DMCommToolEventHandler::ProcessEvent( dmCommToolPtr->ProcessReceiveLogoutEvent(commMsg); break; } + case DM_COMM_SEND_USER_UNLOCKED: { + dmCommToolPtr->ProcessReceiveUserUnLockedEvent(commMsg); + break; + } + case DM_COMM_RSP_USER_UNLOCKED: { + dmCommToolPtr->ProcessResponseUserUnLockedEvent(commMsg); + break; + } default: LOGE("event is undefined, id is %{public}d", eventId); break; } } -void DMCommTool::ProcessReceiveUserIdsEvent(const std::shared_ptr commMsg) +void DMCommTool::ProcessReceiveUserUnLockedEvent(const std::shared_ptr commMsg) { LOGI("Receive remote userids, process and rsp local userid"); std::string rmtUdid = ""; @@ -218,9 +299,90 @@ void DMCommTool::ProcessReceiveUserIdsEvent(const std::shared_ptr std::vector backgroundUserIds; MultipleUserConnector::GetForegroundUserIds(foregroundUserIds); 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) { + foregroundUserIdsU32.push_back(static_cast(u)); + } + for (auto const &u : backgroundUserIds) { + backgroundUserIdsU32.push_back(static_cast(u)); + } + RspUserUnLocked(commMsg->remoteNetworkId, foregroundUserIdsU32, backgroundUserIdsU32, + commMsg->socketId); + + if (userIdsMsg.foregroundUserIds.empty()) { + LOGE("Parse but get none remote foreground userids"); + } else { + DeviceManagerService::GetInstance().ProcessSyncUserUnlocked(userIdsMsg.foregroundUserIds, + userIdsMsg.backgroundUserIds, rmtUdid); + } +} + +void DMCommTool::ProcessResponseUserUnLockedEvent(const std::shared_ptr commMsg) +{ + LOGI("process receive remote userids response"); + // step1: close socket + 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", commMsg->remoteNetworkId.c_str()); + return; } + + std::string payload = commMsg->commMsg->msg; + cJSON *root = cJSON_Parse(payload.c_str()); + if (root == NULL) { + LOGE("the msg is not json format"); + return; + } + UserIdsMsg userIdsMsg; + FromJson(root, userIdsMsg); + cJSON_Delete(root); + if (userIdsMsg.foregroundUserIds.empty()) { + LOGE("Parse but get none remote userids"); + return; + } + // step2: process remote foreground/background userids + if (!userIdsMsg.foregroundUserIds.empty()) { + DeviceManagerService::GetInstance().ProcessSyncUserUnlocked(userIdsMsg.foregroundUserIds, + userIdsMsg.backgroundUserIds, rmtUdid); + } else { + DeviceManagerService::GetInstance().DelTimerAndEventTypeSyncUserUnlocked(rmtUdid); + LOGE("Receive remote foreground userid empty"); + } +} + +void DMCommTool::ProcessReceiveUserIdsEvent(const std::shared_ptr commMsg) +{ + LOGI("Receive remote userids, process and rsp local userid"); + std::string rmtUdid = ""; + SoftbusCache::GetInstance().GetUdidFromCache(commMsg->remoteNetworkId.c_str(), rmtUdid); + if (rmtUdid.empty()) { + LOGE("Can not find remote udid by networkid: %{public}s", commMsg->remoteNetworkId.c_str()); + return; + } + + std::string payload = commMsg->commMsg->msg; + cJSON *root = cJSON_Parse(payload.c_str()); + if (root == NULL) { + LOGE("the msg is not json format"); + return; + } + UserIdsMsg userIdsMsg; + FromJson(root, userIdsMsg); + cJSON_Delete(root); + uint32_t totalUserNum = static_cast(userIdsMsg.foregroundUserIds.size()) + + static_cast(userIdsMsg.backgroundUserIds.size()); + + // step1: send back local userids + std::vector foregroundUserIds; + std::vector backgroundUserIds; + MultipleUserConnector::GetForegroundUserIds(foregroundUserIds); + MultipleUserConnector::GetBackgroundUserIds(backgroundUserIds); + MultipleUserConnector::ClearLockedUser(foregroundUserIds, backgroundUserIds); std::vector foregroundUserIdsU32; std::vector backgroundUserIdsU32; for (auto const &u : foregroundUserIds) { @@ -272,6 +434,7 @@ void DMCommTool::ProcessResponseUserIdsEvent(const std::shared_ptr DeviceManagerService::GetInstance().ProcessSyncUserIds(userIdsMsg.foregroundUserIds, userIdsMsg.backgroundUserIds, rmtUdid); } else { + DeviceManagerService::GetInstance().DelTimerAndEventTypeSyncUserIds(rmtUdid); LOGE("Receive remote foreground userid empty"); } } @@ -498,5 +661,50 @@ 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(); }; + ffrt::task_handle handle = + eventQueue_->submit_h(taskFunc, ffrt::task_attr().delay(0)); + if (handle == nullptr) { + LOGE("handle is nullptr."); + return ERR_DM_FAILED; + } + eventVec_[commonEventType] = std::move(handle); + return DM_OK; +} + +int32_t DMCommTool::DeleteCommonEvent(std::string commonEventType) +{ + if (commonEventType.empty()) { + LOGE("DmTimer DeleteTimer timer is null"); + return ERR_DM_INPUT_PARA_INVALID; + } + LOGI("DeleteCommonEvent start eventType: %{public}s", commonEventType.c_str()); + std::lock_guard locker(eventMutex_); + auto item = eventVec_.find(commonEventType); + if (item == eventVec_.end()) { + LOGI("Invalid task."); + return ERR_DM_FAILED; + } + if (item->second != nullptr && eventQueue_ != nullptr) { + int32_t ret = eventQueue_->cancel(item->second); + if (ret != 0) { + LOGE("Cancel failed, errCode: %{public}d.", ret); + } + } + eventVec_.erase(commonEventType); + 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..8beb041910ccb30f0456f123540f153335f3e2a8 100644 --- a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp +++ b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp @@ -131,6 +131,9 @@ bool RelationShipChangeMsg::ToBroadcastPayLoad(uint8_t *&msg, uint32_t &len) con ToStopUserPayLoad(msg, len); ret = true; break; + case RelationShipChangeType::UNLOCKED_USER: + ret = ToSyncFrontOrBackUserIdPayLoad(msg, len); + break; default: LOGE("RelationShipChange type invalid"); break; @@ -168,6 +171,9 @@ bool RelationShipChangeMsg::FromBroadcastPayLoad(const cJSON *payloadJson, Relat case RelationShipChangeType::STOP_USER: ret = FromStopUserPayLoad(payloadJson); break; + case RelationShipChangeType::UNLOCKED_USER: + ret = FromSyncFrontOrBackUserIdPayLoad(payloadJson); + break; default: LOGE("RelationShipChange type invalid"); break; @@ -205,6 +211,10 @@ bool RelationShipChangeMsg::IsValid() const ret = (!userIdInfos.empty() && (static_cast(userIdInfos.size()) <= MAX_USER_ID_NUM)); break; + case RelationShipChangeType::UNLOCKED_USER: + ret = (!userIdInfos.empty() && + (static_cast(userIdInfos.size()) <= MAX_USER_ID_NUM)); + break; case RelationShipChangeType::TYPE_MAX: ret = false; break; @@ -220,7 +230,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::SERVICE_UNBIND) || (type == RelationShipChangeType::UNLOCKED_USER); } bool RelationShipChangeMsg::IsChangeTypeValid(uint32_t type) @@ -231,7 +241,8 @@ bool RelationShipChangeMsg::IsChangeTypeValid(uint32_t type) (type == (uint32_t)RelationShipChangeType::SYNC_USERID) || (type == (uint32_t)RelationShipChangeType::DEL_USER) || (type == (uint32_t)RelationShipChangeType::STOP_USER) || - (type == (uint32_t)RelationShipChangeType::SERVICE_UNBIND); + (type == (uint32_t)RelationShipChangeType::SERVICE_UNBIND) || + (type == (uint32_t)RelationShipChangeType::UNLOCKED_USER); } void RelationShipChangeMsg::ToAccountLogoutPayLoad(uint8_t *&msg, uint32_t &len) const diff --git a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp index 1cf70e56a91a393917d9942dc9f090b44b0348e5..95e939a7f26a42beade42d5b31adc5e96b15bedf 100644 --- a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp +++ b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp @@ -1633,8 +1633,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 +1811,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/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/BUILD.gn b/test/unittest/BUILD.gn index 2ec361727581300d33f4d1f6beba8d904291bc42..73d3b10f4a5ad6808268d1b5285b34593a7c372d 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -822,6 +822,7 @@ ohos_unittest("UTTest_dm_transport") { "cJSON:cjson", "dsoftbus:softbus_client", "eventhandler:libeventhandler", + "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", ] @@ -1677,6 +1678,7 @@ ohos_unittest("UTTest_dm_comm_tool") { "cJSON:cjson", "dsoftbus:softbus_client", "eventhandler:libeventhandler", + "ffrt:libffrt", "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", diff --git a/test/unittest/UTTest_device_manager_service_impl.cpp b/test/unittest/UTTest_device_manager_service_impl.cpp index e160833a61347e3b1d89a4cb9ea9fc6a96084433..62c30ab4ae738f7bce3e4a521ae43f6fba3dbeb5 100644 --- a/test/unittest/UTTest_device_manager_service_impl.cpp +++ b/test/unittest/UTTest_device_manager_service_impl.cpp @@ -1851,7 +1851,7 @@ HWTEST_F(DeviceManagerServiceImplTest, GetDeviceIdAndUserId_001, testing::ext::T std::vector foregroundUserIds; std::vector backgroundUserIds; std::string remoteUdid = "deviceId"; - deviceManagerServiceImpl_->HandleSyncUserIdEvent(foregroundUserIds, backgroundUserIds, remoteUdid, false); + deviceManagerServiceImpl_->HandleSyncUserIdEvent(foregroundUserIds, backgroundUserIds, remoteUdid); std::vector deviceVec; int32_t currentUserId = 1; diff --git a/test/unittest/UTTest_device_manager_service_impl_first.cpp b/test/unittest/UTTest_device_manager_service_impl_first.cpp index af21d1fa71d71878a31134d17f962b20a2ef39e6..759050f29cf7be97377e9a3a7c1d0e8369637688 100644 --- a/test/unittest/UTTest_device_manager_service_impl_first.cpp +++ b/test/unittest/UTTest_device_manager_service_impl_first.cpp @@ -79,14 +79,14 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, GetDeviceIdAndUserId_101, testing::e std::vector backgroundUserIds; std::string remoteUdid = "deviceId"; EXPECT_CALL(*multipleUserConnectorMock_, GetForegroundUserIds(_)).WillOnce(Return(ERR_DM_FAILED)); - deviceManagerServiceImpl_->HandleSyncUserIdEvent(foregroundUserIds, backgroundUserIds, remoteUdid, false); + deviceManagerServiceImpl_->HandleSyncUserIdEvent(foregroundUserIds, backgroundUserIds, remoteUdid); 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); + deviceManagerServiceImpl_->HandleSyncUserIdEvent(foregroundUserIds, backgroundUserIds, remoteUdid); } } // namespace } // namespace DistributedHardware diff --git a/test/unittest/UTTest_device_manager_service_two.cpp b/test/unittest/UTTest_device_manager_service_two.cpp index a6704b1b6d83816216557a3c3d42e3b0dc1e3625..5bfea1ac06ee998845b2dc61de538dc99e3330f9 100644 --- a/test/unittest/UTTest_device_manager_service_two.cpp +++ b/test/unittest/UTTest_device_manager_service_two.cpp @@ -1788,11 +1788,12 @@ HWTEST_F(DeviceManagerServiceTest, GetDeviceNetworkIdList_202, testing::ext::Tes EXPECT_NE(ret, DM_OK); int32_t stopUserId = 1; + int32_t currentUserId = -1; std::map deviceMap; EXPECT_CALL(*deviceProfileConnectorMock_, GetDeviceIdAndBindLevel(_, _)) .WillOnce(Return(deviceMap)); DeviceManagerService::GetInstance().InitDMServiceListener(); - DeviceManagerService::GetInstance().HandleUserStopEvent(stopUserId); + DeviceManagerService::GetInstance().HandleUserStopEvent(currentUserId, stopUserId); std::vector peerUdids; std::vector bleUdids;