diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index 60027daf124577985e32c75bbb9e39cdfe9c334b..9aa9d977139b74a08c207c7ae88303dfefe1650a 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -205,8 +205,6 @@ public: DM_EXPORT int32_t GetBindLevel(const std::string &pkgName, const std::string &localUdid, const std::string &udid, uint64_t &tokenId); std::map GetDeviceIdAndBindLevel(std::vector userIds, const std::string &localUdid); - std::vector GetDeviceIdAndUdidListByTokenId(const std::vector &userIds, - const std::string &localUdid, int32_t tokenId); DM_EXPORT std::multimap GetDeviceIdAndUserId( int32_t userId, const std::string &accountId, const std::string &localUdid); int32_t HandleAccountLogoutEvent(int32_t remoteUserId, const std::string &remoteAccountHash, diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 861e9da02c1c186b05c05abb0973026c433a7f6e..3964b63c83a5b80014dfee6b2ba10a29c56ad827 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -1826,47 +1826,6 @@ std::map DeviceProfileConnector::GetDeviceIdAndBindLevel(s return deviceIdMap; } -std::vector DeviceProfileConnector::GetDeviceIdAndUdidListByTokenId(const std::vector &userIds, - const std::string &localUdid, int32_t tokenId) -{ - if (userIds.empty() || localUdid.empty()) { - LOGE("userIds or localUdid is empty."); - return {}; - } - std::vector profiles = GetAllAccessControlProfile(); - std::map deviceIdMap; - std::vector udidList; - - for (const auto &item : profiles) { - if (IsLnnAcl(item)) { - continue; - } - - if (find(userIds.begin(), userIds.end(), item.GetAccesser().GetAccesserUserId()) != userIds.end() && - item.GetAccesser().GetAccesserDeviceId() == localUdid && - static_cast(item.GetAccesser().GetAccesserTokenId()) == tokenId) { - LOGI("Get Device Bind type localUdid %{public}s is src, tokenId %{public}s.", - GetAnonyString(localUdid).c_str(), GetAnonyInt32(tokenId).c_str()); - UpdateBindType(item.GetTrustDeviceId(), item.GetBindLevel(), deviceIdMap); - continue; - } - - if (find(userIds.begin(), userIds.end(), item.GetAccessee().GetAccesseeUserId()) != userIds.end() && - item.GetAccessee().GetAccesseeDeviceId() == localUdid && - static_cast(item.GetAccessee().GetAccesseeTokenId()) == tokenId) { - LOGI("Get Device Bind type localUdid %{public}s is sink, tokenId %{public}s.", - GetAnonyString(localUdid).c_str(), GetAnonyInt32(tokenId).c_str()); - UpdateBindType(item.GetTrustDeviceId(), item.GetBindLevel(), deviceIdMap); - continue; - } - } - - for (const auto &item : deviceIdMap) { - udidList.push_back(item.first); - } - return udidList; -} - DM_EXPORT std::multimap DeviceProfileConnector::GetDeviceIdAndUserId( int32_t userId, const std::string &accountId, const std::string &localUdid) { diff --git a/services/implementation/include/device_manager_service_impl.h b/services/implementation/include/device_manager_service_impl.h index c69db3f78e55b2e57e5b1dad1e32d3a59072d3ae..aa12ca3bb1f8a6b327351b8549ad3e07f8b0ded2 100644 --- a/services/implementation/include/device_manager_service_impl.h +++ b/services/implementation/include/device_manager_service_impl.h @@ -165,8 +165,6 @@ public: int32_t GetAclListHash(const DevUserInfo &localDevUserInfo, const DevUserInfo &remoteDevUserInfo, std::string &aclList); int32_t ProcessAppUnintall(const std::string &appId, int32_t accessTokenId); - int32_t ProcessAppUninstall(int32_t userId, int32_t accessTokenId); - void ProcessUnBindApp(int32_t userId, int32_t accessTokenId, const std::string &extra, const std::string &udid); 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, @@ -179,7 +177,7 @@ public: void DeleteAlwaysAllowTimeOut(); void CheckDeleteCredential(const std::string &remoteUdid, int32_t remoteUserId); void HandleCredentialDeleted(const char *credId, const char *credInfo, const std::string &localUdid, - std::string &remoteUdid, bool &isShareType); + std::string &remoteUdid); void HandleShareUnbindBroadCast(const std::string &credId, const int32_t &userId, const std::string &localUdid); int32_t CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId); int32_t DeleteAcl(const std::string &sessionName, const std::string &localUdid, const std::string &remoteUdid, @@ -194,7 +192,6 @@ public: uint64_t logicalSessionId, const std::string &pkgName); void HandleCommonEventBroadCast(const std::vector &foregroundUserIds, const std::vector &backgroundUserIds, const std::string &remoteUdid); - std::vector GetDeviceIdByUserIdAndTokenId(int32_t userId, int32_t tokenId); bool CheckSrcAccessControl(const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee, const std::string &sinkUdid); bool CheckSinkAccessControl(const DmAccessCaller &caller, const std::string &srcUdid, @@ -268,13 +265,6 @@ private: std::vector &profiles, std::map &delProfileMap, std::vector> &delACLInfoVec, std::vector &userIdVec); - - void DeleteAclByTokenId(const int32_t &accessTokenId, - std::vector &profiles, - std::map &delProfileMap, - std::vector> &delACLInfoVec, std::vector &userIdVec, - const uint32_t &userId, const std::string &localUdid); - bool CheckLnnAcl(DistributedDeviceProfile::AccessControlProfile delProfile, DistributedDeviceProfile::AccessControlProfile lastprofile); void CheckIsLastLnnAcl(DistributedDeviceProfile::AccessControlProfile profile, diff --git a/services/implementation/include/device_manager_service_impl_lite.h b/services/implementation/include/device_manager_service_impl_lite.h index 08a30e5a2073adb615fd7c940a1a9230d2061424..2a9367796cef47f76a271350e9ed597fe15b58d6 100644 --- a/services/implementation/include/device_manager_service_impl_lite.h +++ b/services/implementation/include/device_manager_service_impl_lite.h @@ -151,8 +151,6 @@ public: int32_t GetAclListHash(const DevUserInfo &localDevUserInfo, const DevUserInfo &remoteDevUserInfo, std::string &aclList); int32_t ProcessAppUnintall(const std::string &appId, int32_t accessTokenId); - int32_t ProcessAppUninstall(int32_t userId, int32_t accessTokenId); - void ProcessUnBindApp(int32_t userId, int32_t accessTokenId, const std::string &extra, const std::string &udid); 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); @@ -165,14 +163,13 @@ public: void DeleteAlwaysAllowTimeOut(); void CheckDeleteCredential(const std::string &remoteUdid, int32_t remoteUserId); void HandleCredentialDeleted(const char *credId, const char *credInfo, const std::string &localUdid, - std::string &remoteUdid, bool &isShareType); + std::string &remoteUdid); void HandleShareUnbindBroadCast(const std::string &credId, const int32_t &userId, const std::string &localUdid); int32_t CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId); 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); - std::vector GetDeviceIdByUserIdAndTokenId(int32_t userId, int32_t tokenId); bool CheckSrcAccessControl(const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee, const std::string &sinkUdid); bool CheckSinkAccessControl(const DmAccessCaller &caller, const std::string &srcUdid, diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 314cdf47b98790973bb9de2b2829fcf29c0e3f5e..5d34e45bf804b4a947190b4ac628538058e2a5b3 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -1899,17 +1899,6 @@ std::map DeviceManagerServiceImpl::GetDeviceIdAndBindLevel return DeviceProfileConnector::GetInstance().GetDeviceIdAndBindLevel(userIds, localUdid); } -std::vector DeviceManagerServiceImpl::GetDeviceIdByUserIdAndTokenId(int32_t userId, - int32_t tokenId) -{ - char localUdidTemp[DEVICE_UUID_LENGTH] = {0}; - GetDevUdid(localUdidTemp, DEVICE_UUID_LENGTH); - std::string localUdid = std::string(localUdidTemp); - std::vector userIds; - userIds.push_back(userId); - return DeviceProfileConnector::GetInstance().GetDeviceIdAndUdidListByTokenId(userIds, localUdid, tokenId); -} - std::multimap DeviceManagerServiceImpl::GetDeviceIdAndUserId(int32_t userId, const std::string &accountId) { @@ -2041,9 +2030,7 @@ void DeviceManagerServiceImpl::HandleAppUnBindEvent(int32_t remoteUserId, const void DeviceManagerServiceImpl::HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId, int32_t peerTokenId) { - LOGI("DeviceManagerServiceImpl::HandleAppUnBindEvent remoteUserId: %{public}s, remoteUdid: %{public}s," - "tokenId = %{public}s, peerTokenId = %{public}s.", GetAnonyInt32(remoteUserId).c_str(), - GetAnonyString(remoteUdid).c_str(), GetAnonyInt32(tokenId).c_str(), GetAnonyInt32(peerTokenId).c_str()); + LOGI("peerTokenId = %{public}d.", peerTokenId); char localUdidTemp[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localUdidTemp, DEVICE_UUID_LENGTH); std::string localUdid = std::string(localUdidTemp); @@ -2229,64 +2216,6 @@ int32_t DeviceManagerServiceImpl::ProcessAppUnintall(const std::string &appId, i return DM_OK; } -int32_t DeviceManagerServiceImpl::ProcessAppUninstall(int32_t userId, int32_t accessTokenId) -{ - LOGE("DeviceManagerServiceImpl::ProcessAppUninstall userId = %{public}s, accessTokenId = %{public}s.", - GetAnonyInt32(userId).c_str(), GetAnonyInt32(accessTokenId).c_str()); - CHECK_NULL_RETURN(listener_, ERR_DM_POINT_NULL); - std::vector profiles = - DeviceProfileConnector::GetInstance().GetAllAclIncludeLnnAcl(); - LOGI("delete ACL size is %{public}zu", profiles.size()); - if (profiles.size() == 0) { - return DM_OK; - } - char localDeviceId[DEVICE_UUID_LENGTH] = {0}; - GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); - std::string localUdid = std::string(localDeviceId); - std::vector> delACLInfoVec; - std::vector userIdVec; - std::map delProfileMap; - DeleteAclByTokenId(accessTokenId, profiles, delProfileMap, delACLInfoVec, userIdVec, userId, localUdid); - for (auto item : delProfileMap) { - DmOfflineParam lnnAclParam; - bool isLastLnnAcl = false; - for (auto it : profiles) { - CheckIsLastLnnAcl(it, item.second, lnnAclParam, isLastLnnAcl, localUdid); - } - if (!isLastLnnAcl) { - DeleteSkCredAndAcl(lnnAclParam.needDelAclInfos); - } - } - - if (delACLInfoVec.size() == 0 || userIdVec.size() == 0) { - return DM_OK; - } - - CHECK_NULL_RETURN(hiChainConnector_, ERR_DM_POINT_NULL); - hiChainConnector_->DeleteGroupByACL(delACLInfoVec, userIdVec); - return DM_OK; -} - -void DeviceManagerServiceImpl::ProcessUnBindApp(int32_t userId, int32_t accessTokenId, - const std::string &extra, const std::string &udid) -{ - LOGI("DeviceManagerServiceImpl::ProcessUnBindApp userId = %{public}s, accessTokenId = %{public}s," - "extra = %{public}s.", GetAnonyInt32(userId).c_str(), GetAnonyInt32(accessTokenId).c_str(), - GetAnonyString(extra).c_str()); - - JsonObject extraInfoJson(extra); - if (extraInfoJson.IsDiscarded()) { - LOGE("ParseExtra extraInfoJson error"); - HandleAppUnBindEvent(userId, udid, accessTokenId); - return; - } - if (extraInfoJson.Contains(TAG_PEER_TOKENID) && extraInfoJson[TAG_PEER_TOKENID].IsNumberInteger()) { - uint64_t peerTokenId = extraInfoJson[TAG_PEER_TOKENID].Get(); - HandleAppUnBindEvent(userId, udid, accessTokenId, static_cast(peerTokenId)); - } - return; -} - void DeviceManagerServiceImpl::CheckIsLastLnnAcl(DistributedDeviceProfile::AccessControlProfile profile, DistributedDeviceProfile::AccessControlProfile delProfile, DmOfflineParam &lnnAclParam, bool &isLastLnnAcl, const std::string &localUdid) @@ -2352,59 +2281,6 @@ void DeviceManagerServiceImpl::DeleteAclByTokenId(const int32_t accessTokenId, } } -void DeviceManagerServiceImpl::DeleteAclByTokenId(const int32_t &accessTokenId, - std::vector &profiles, - std::map &delProfileMap, - std::vector> &delACLInfoVec, std::vector &userIdVec, - const uint32_t &userId, const std::string &localUdid) -{ - for (auto &item : profiles) { - int64_t accesssertokenId = item.GetAccesser().GetAccesserTokenId(); - int64_t accessseetokenId = item.GetAccessee().GetAccesseeTokenId(); - if (accessTokenId != static_cast(accesssertokenId) && - accessTokenId != static_cast(accessseetokenId)) { - continue; - } - if (accessTokenId == static_cast(accesssertokenId) && - userId == item.GetAccesser().GetAccesserUserId() && - localUdid == item.GetAccessee().GetAccesseeDeviceId()) { - DmOfflineParam offlineParam; - delProfileMap[item.GetAccessControlId()] = item; - DeviceProfileConnector::GetInstance().CacheAcerAclId(item, offlineParam.needDelAclInfos); - DeleteSkCredAndAcl(offlineParam.needDelAclInfos); - listener_->OnAppUnintall(item.GetAccesser().GetAccesserBundleName()); - if (item.GetBindLevel() == USER) { - userIdVec.push_back(item.GetAccesser().GetAccesserUserId()); - delACLInfoVec.push_back(std::pair(item.GetAccesser().GetAccesserUserId(), - item.GetAccessee().GetAccesseeDeviceId())); - } - } - if (accessTokenId == static_cast(accessseetokenId) && - userId == item.GetAccessee().GetAccesseeUserId() && - localUdid == item.GetAccesser().GetAccesserDeviceId()) { - DmOfflineParam offlineParam; - DeviceProfileConnector::GetInstance().CacheAceeAclId(item, offlineParam.needDelAclInfos); - delProfileMap[item.GetAccessControlId()] = item; - DeleteSkCredAndAcl(offlineParam.needDelAclInfos); - listener_->OnAppUnintall(item.GetAccessee().GetAccesseeBundleName()); - if (item.GetBindLevel() == USER) { - userIdVec.push_back(item.GetAccessee().GetAccesseeUserId()); - delACLInfoVec.push_back(std::pair(item.GetAccessee().GetAccesseeUserId(), - item.GetAccesser().GetAccesserDeviceId())); - } - } - } - for (auto item : delProfileMap) { - for (auto it = profiles.begin(); it != profiles.end();) { - if (item.first == it->GetAccessControlId()) { - it = profiles.erase(it); - } else { - it++; - } - } - } -} - bool DeviceManagerServiceImpl::CheckLnnAcl(DistributedDeviceProfile::AccessControlProfile delProfile, DistributedDeviceProfile::AccessControlProfile lastprofile) { @@ -2513,7 +2389,7 @@ void DeviceManagerServiceImpl::CheckDeleteCredential(const std::string &remoteUd } void DeviceManagerServiceImpl::HandleCredentialDeleted(const char *credId, const char *credInfo, - const std::string &localUdid, std::string &remoteUdid, bool &isShareType) + const std::string &localUdid, std::string &remoteUdid) { std::vector profiles = DeviceProfileConnector::GetInstance().GetAccessControlProfile(); @@ -2548,7 +2424,6 @@ void DeviceManagerServiceImpl::HandleCredentialDeleted(const char *credId, const item.GetAccessee().GetAccesseeUserId() == localUserId && item.GetAccesser().GetAccesserUserId() == userId && item.GetAccesser().GetAccesserDeviceId() == remoteUdid)) { - isShareType = true; DeviceProfileConnector::GetInstance().DeleteAccessControlById(item.GetAccessControlId()); } } diff --git a/services/implementation/src/device_manager_service_impl_lite.cpp b/services/implementation/src/device_manager_service_impl_lite.cpp index 43a2d5bd61305e7e102fc1d61a9bd7687c216a90..a6d0b502e14dc139ea02183b865b2b90c80fd96a 100644 --- a/services/implementation/src/device_manager_service_impl_lite.cpp +++ b/services/implementation/src/device_manager_service_impl_lite.cpp @@ -331,13 +331,12 @@ int32_t DeviceManagerServiceImpl::ImportAuthCode(const std::string &pkgName, con } void DeviceManagerServiceImpl::HandleCredentialDeleted(const char *credId, const char *credInfo, - const std::string &localUdid, std::string &remoteUdid, bool &isShareType) + const std::string &localUdid, std::string &remoteUdid) { (void)credId; (void)credInfo; (void)localUdid; (void)remoteUdid; - (void)isShareType; return; } @@ -407,14 +406,6 @@ int32_t DeviceManagerServiceImpl::IsSameAccount(const std::string &udid) return DM_OK; } -std::vector DeviceManagerServiceImpl::GetDeviceIdByUserIdAndTokenId(int32_t userId, int32_t tokenId) -{ - (void)userId; - (void)tokenId; - std::vector tmp; - return tmp; -} - uint64_t DeviceManagerServiceImpl::GetTokenIdByNameAndDeviceId(std::string extra, std::string requestDeviceId) { (void)extra; @@ -579,23 +570,6 @@ int32_t DeviceManagerServiceImpl::ProcessAppUnintall(const std::string &appId, i return 0; } -int32_t DeviceManagerServiceImpl::ProcessAppUninstall(int32_t userId, int32_t accessTokenId) -{ - (void)userId; - (void)accessTokenId; - return 0; -} - -void DeviceManagerServiceImpl::ProcessUnBindApp(int32_t userId, int32_t accessTokenId, const std::string &extra, - const std::string &udid) -{ - (void)userId; - (void)accessTokenId; - (void)extra; - (void)udid; - return; -} - void DeviceManagerServiceImpl::HandleSyncUserIdEvent(const std::vector &foregroundUserIds, const std::vector &backgroundUserIds, const std::string &remoteUdid, bool isCheckUserStatus) { diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index bd88a76f20335f54001762250a70c450a6e53718..8c8295dc4f928ff68a9b8ad0ab5897d72ef6aa2b 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -100,11 +100,6 @@ public: int32_t UnBindDevice(const std::string &pkgName, const std::string &udidHash, const std::string &extra); - int32_t ValidateUnBindDeviceParams(const std::string &pkgName, const std::string &udidHash); - - int32_t ValidateUnBindDeviceParams(const std::string &pkgName, const std::string &udidHash, - const std::string &extra); - int32_t SetUserOperation(std::string &pkgName, int32_t action, const std::string ¶ms); void HandleDeviceStatusChange(DmDeviceState devState, DmDeviceInfo &devInfo); @@ -220,10 +215,6 @@ public: const DevUserInfo &remoteDevUserInfo, std::string &aclList); void ProcessSyncUserIds(const std::vector &foregroundUserIds, const std::vector &backgroundUserIds, const std::string &remoteUdid); - - void ProcessUninstApp(int32_t userId, int32_t tokenId); - void ProcessUnBindApp(int32_t userId, int32_t tokenId, const std::string &extra, const std::string &udid); - int32_t SetLocalDisplayNameToSoftbus(const std::string &displayName); void RemoveNotifyRecord(const ProcessInfo &processInfo); int32_t RegDevStateCallbackToService(const std::string &pkgName); @@ -254,8 +245,6 @@ public: std::vector &networkIds); void ProcessSyncAccountLogout(const std::string &accountId, const std::string &peerUdid, int32_t userId); int32_t UnRegisterPinHolderCallback(const std::string &pkgName); - void ProcessReceiveRspAppUninstall(const std::string &remoteUdid); - void ProcessReceiveRspAppUnbind(const std::string &remoteUdid); void ProcessCommonUserStatusEvent(const std::vector &foregroundUserIds, const std::vector &backgroundUserIds, const std::string &remoteUdid); int32_t GetLocalDeviceName(std::string &deviceName); @@ -277,11 +266,8 @@ private: int32_t bindLevel, uint64_t peerTokenId); void SendDeviceUnBindBroadCast(const std::vector &peerUdids, int32_t userId); void SendAppUnBindBroadCast(const std::vector &peerUdids, int32_t userId, uint64_t tokenId); - int32_t CalculateBroadCastDelayTime(); void SendAppUnBindBroadCast(const std::vector &peerUdids, int32_t userId, uint64_t tokenId, uint64_t peerTokenId); - void SendAppUnInstallBroadCast(const std::vector &peerUdids, int32_t userId, - uint64_t tokenId); void SendServiceUnBindBroadCast(const std::vector &peerUdids, int32_t userId, uint64_t tokenId); void SendAccountLogoutBroadCast(const std::vector &peerUdids, const std::string &accountId, const std::string &accountName, int32_t userId); @@ -351,19 +337,6 @@ private: void InitServiceInfos(const std::vector &dpLocalServiceItems, std::vector &serviceInfos); void HandleUserSwitched(); - - void NotifyRemoteUninstallApp(int32_t userId, int32_t tokenId); - void NotifyRemoteUninstallAppByWifi(int32_t userId, int32_t tokenId, - const std::map &wifiDevices); - int32_t SendUninstAppByWifi(int32_t userId, int32_t tokenId, const std::string &networkId); - - void GetNotifyRemoteUnBindAppWay(int32_t userId, int32_t tokenId, - std::map &wifiDevices, bool &isBleWay); - void NotifyRemoteUnBindAppByWifi(int32_t userId, int32_t tokenId, std::string extra, - const std::map &wifiDevices); - int32_t SendUnBindAppByWifi(int32_t userId, int32_t tokenId, std::string extra, - const std::string &networkId, const std::string &udid); - void NotifyRemoteLocalUserSwitch(const std::string &localUdid, const std::vector &peerUdids, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds); void NotifyRemoteLocalUserSwitchByWifi(const std::string &localUdid, @@ -444,9 +417,6 @@ private: std::shared_ptr screenCommonEventManager_; std::vector foregroundUserVec_; std::vector backgroundUserVec_; - std::mutex broadCastLock_; - int64_t SendLastBroadCastTime_ = 0; - int64_t lastDelayTime_ = 0; #if defined(SUPPORT_BLUETOOTH) || defined(SUPPORT_WIFI) std::shared_ptr publshCommonEventManager_; #endif // SUPPORT_BLUETOOTH SUPPORT_WIFI diff --git a/services/service/include/idevice_manager_service_impl.h b/services/service/include/idevice_manager_service_impl.h index 4c3ec2d36f69e1dd845b4f4e360e0c63628e6086..0dd261dd54a4150bdb2390d451041851d979617c 100644 --- a/services/service/include/idevice_manager_service_impl.h +++ b/services/service/include/idevice_manager_service_impl.h @@ -252,15 +252,10 @@ 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 int32_t ProcessAppUninstall(int32_t userId, int32_t accessTokenId) = 0; - virtual void ProcessUnBindApp(int32_t userId, int32_t accessTokenId, const std::string &extra, - const std::string &udid) = 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::vector GetDeviceIdByUserIdAndTokenId(int32_t userId, int32_t tokenId) = 0; virtual std::multimap GetDeviceIdAndUserId(int32_t localUserId) = 0; virtual int32_t SaveOnlineDeviceInfo(const std::vector &deviceList) = 0; virtual void HandleDeviceUnBind(int32_t bindType, const std::string &peerUdid, @@ -269,7 +264,7 @@ public: virtual void DeleteAlwaysAllowTimeOut() = 0; virtual void CheckDeleteCredential(const std::string &remoteUdid, int32_t remoteUserId) = 0; virtual void HandleCredentialDeleted(const char *credId, const char *credInfo, const std::string &localUdid, - std::string &remoteUdid, bool &isShareType) = 0; + std::string &remoteUdid) = 0; virtual void HandleShareUnbindBroadCast(const std::string &credId, const int32_t &userId, const std::string &localUdid) = 0; virtual int32_t CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId) = 0; diff --git a/services/service/include/relationshipsyncmgr/dm_comm_tool.h b/services/service/include/relationshipsyncmgr/dm_comm_tool.h index ca1136c1307ee80cf48903d9ad271f31cc814a31..0ee63517b7766611d6b07b1566f6f2305e22ad65 100644 --- a/services/service/include/relationshipsyncmgr/dm_comm_tool.h +++ b/services/service/include/relationshipsyncmgr/dm_comm_tool.h @@ -36,12 +36,6 @@ public: int32_t SendUserIds(const std::string rmtNetworkId, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds); - - int32_t SendUninstAppObj(int32_t userId, int32_t tokenId, const std::string &networkId); - - int32_t SendUnBindAppObj(int32_t userId, int32_t tokenId, const std::string &extra, const std::string &networkId, - const std::string &udid); - 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); @@ -51,11 +45,6 @@ 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 RspAppUninstall(const std::string rmtNetworkId, int32_t socketId); - int32_t RspAppUnbind(const std::string rmtNetworkId, int32_t socketId); - void StopSocket(const std::string &networkId); - void ProcessReceiveRspAppUninstallEvent(const std::shared_ptr commMsg); - void ProcessReceiveRspAppUnbindEvent(const std::shared_ptr commMsg); class DMCommToolEventHandler : public AppExecFwk::EventHandler { public: @@ -63,10 +52,6 @@ public: std::shared_ptr dmCommToolPtr); ~DMCommToolEventHandler() override = default; void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; - void HandleEvent(const std::shared_ptr &dmCommToolPtr, uint32_t eventId, - const std::shared_ptr &commMsg, const UserIdsMsg &userIdsMsg); - void HandleLocalUserIdEvent(const std::shared_ptr &dmCommToolPtr, uint32_t eventId, - const std::shared_ptr &commMsg, const UserIdsMsg &userIdsMsg); private: void ParseUserIdsMsg(std::shared_ptr commMsg, UserIdsMsg &userIdsMsg); std::weak_ptr dmCommToolWPtr_; @@ -81,8 +66,6 @@ public: int32_t StartCommonEvent(std::string commonEventType, EventCallback eventCallback); void ProcessReceiveCommonEvent(const std::shared_ptr commMsg); void ProcessResponseCommonEvent(const std::shared_ptr commMsg); - void ProcessReceiveUninstAppEvent(const std::shared_ptr commMsg); - void ProcessReceiveUnBindAppEvent(const std::shared_ptr commMsg); private: std::shared_ptr dmTransportPtr_; std::shared_ptr eventHandler_; diff --git a/services/service/include/relationshipsyncmgr/dm_transport_msg.h b/services/service/include/relationshipsyncmgr/dm_transport_msg.h index c53abee8be65aeacf39d83d112323f1d5ba54abf..74230997a7666ca7f93b8d66aa6875c5859b650a 100644 --- a/services/service/include/relationshipsyncmgr/dm_transport_msg.h +++ b/services/service/include/relationshipsyncmgr/dm_transport_msg.h @@ -76,30 +76,6 @@ struct LogoutAccountMsg { void ToJson(cJSON *jsonObject, const LogoutAccountMsg &accountInfo); void FromJson(const cJSON *jsonObject, LogoutAccountMsg &accountInfo); - -struct UninstAppMsg { - int32_t userId_; - int32_t tokenId_; - UninstAppMsg() : userId_(-1), tokenId_(-1) {} - UninstAppMsg(const int32_t &userId, const int32_t &tokenId) - : userId_(userId), tokenId_(tokenId) {} -}; - -void ToJson(cJSON *jsonObject, const UninstAppMsg &uninstAppMsg); -void FromJson(const cJSON *jsonObject, UninstAppMsg &uninstAppMsg); - -struct UnBindAppMsg { - int32_t userId_; - int32_t tokenId_; - std::string extra_; - std::string udid_; - UnBindAppMsg() : userId_(-1), tokenId_(-1), extra_(""), udid_("") {} - UnBindAppMsg(const int32_t &userId, const int32_t &tokenId, const std::string &extra, const std::string &udid) - : userId_(userId), tokenId_(tokenId), extra_(extra), udid_(udid) {} -}; - -void ToJson(cJSON *jsonObject, const UnBindAppMsg &unBindAppMsg); -void FromJson(const cJSON *jsonObject, UnBindAppMsg &unBindAppMsg); } // DistributedHardware } // OHOS #endif \ No newline at end of file diff --git a/services/service/include/relationshipsyncmgr/relationship_sync_mgr.h b/services/service/include/relationshipsyncmgr/relationship_sync_mgr.h index 2d0591a97afdc016435be7a2909a66f632330d3e..1c9279a69623b11a6fd4936e99c24c54a797f3b8 100644 --- a/services/service/include/relationshipsyncmgr/relationship_sync_mgr.h +++ b/services/service/include/relationshipsyncmgr/relationship_sync_mgr.h @@ -75,7 +75,6 @@ struct RelationShipChangeMsg { void ToAccountLogoutPayLoad(uint8_t *&msg, uint32_t &len) const; void ToDeviceUnbindPayLoad(uint8_t *&msg, uint32_t &len) const; void ToAppUnbindPayLoad(uint8_t *&msg, uint32_t &len) const; - void ToAppUninstallPayLoad(uint8_t *&msg, uint32_t &len) const; 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; @@ -91,7 +90,6 @@ struct RelationShipChangeMsg { bool FromDelUserPayLoad(const cJSON *payloadJson); bool FromStopUserPayLoad(const cJSON *payloadJson); bool FromShareUnbindPayLoad(const cJSON *payloadJson); - bool FromAppUninstallPayLoad(const cJSON *payloadJson); bool GetBroadCastId(const cJSON *payloadJson, uint32_t userIdNum); std::string ToJson() const; diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 9daf9e13f0d59574e343826ac1bfae5a14048d5a..82d34c7e0b6203e31d67292869df5f9a3988659f 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -85,13 +85,8 @@ namespace { 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"; - constexpr const char* APP_UNINSTALL_BY_WIFI_TIMEOUT_TASK = "deviceManagerTimer:appUninstallByWifi"; - constexpr const char* APP_UNBIND_BY_WIFI_TIMEOUT_TASK = "deviceManagerTimer:appUnbindByWifi"; constexpr const char* ACCOUNT_COMMON_EVENT_BY_WIFI_TIMEOUT_TASK = "deviceManagerTimer:accountCommonEventByWifi"; const int32_t USER_SWITCH_BY_WIFI_TIMEOUT_S = 2; - const int32_t SEND_DELAY_MAX_TIME = 5; - const int32_t SEND_DELAY_MIN_TIME = 0; - const int32_t DELAY_TIME_SEC_CONVERSION = 1000000; // 1000*1000 #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) && !defined(DEVICE_MANAGER_COMMON_FLAG) const std::string GET_LOCAL_DEVICE_NAME_API_NAME = "GetLocalDeviceName"; #endif @@ -790,9 +785,18 @@ int32_t DeviceManagerService::BindDevice(const std::string &pkgName, int32_t aut int32_t DeviceManagerService::UnBindDevice(const std::string &pkgName, const std::string &udidHash) { - int32_t result = ValidateUnBindDeviceParams(pkgName, udidHash); - if (result != DM_OK) { - return result; + if (!PermissionManager::GetInstance().CheckNewPermission()) { + LOGE("The caller does not have permission to call UnBindDevice."); + return ERR_DM_NO_PERMISSION; + } + LOGI("Begin for pkgName = %{public}s, udidHash = %{public}s", pkgName.c_str(), GetAnonyString(udidHash).c_str()); + if (pkgName.empty() || udidHash.empty()) { + LOGE("DeviceManagerService::UnBindDevice error: Invalid parameter, pkgName: %{public}s", pkgName.c_str()); + return ERR_DM_INPUT_PARA_INVALID; + } + if (!IsDMServiceImplReady()) { + LOGE("UnBindDevice failed, instance not init or init failed."); + return ERR_DM_NOT_INIT; } std::string realDeviceId = udidHash; #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) @@ -816,33 +820,33 @@ int32_t DeviceManagerService::UnBindDevice(const std::string &pkgName, const std LOGE("UnAuthenticateDevice failed, Acl not contain the bindLevel %{public}d.", bindLevel); return ERR_DM_FAILED; } -#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) - std::vector peerUdids; - peerUdids.emplace_back(udid); - - int32_t userId = MultipleUserConnector::GetCurrentAccountUserID(); - std::map wifiDevices; - bool isBleActive = false; - GetNotifyRemoteUnBindAppWay(userId, tokenId, wifiDevices, isBleActive); - if (isBleActive) { - SendUnBindBroadCast(peerUdids, userId, tokenId, bindLevel); - } else { - NotifyRemoteUnBindAppByWifi(userId, tokenId, "", wifiDevices); - } -#endif if (dmServiceImpl_->UnBindDevice(pkgName, udid, bindLevel) != DM_OK) { LOGE("dmServiceImpl_ UnBindDevice failed."); return ERR_DM_FAILED; } +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + std::vector peerUdids; + peerUdids.emplace_back(udid); + SendUnBindBroadCast(peerUdids, MultipleUserConnector::GetCurrentAccountUserID(), tokenId, bindLevel); +#endif return DM_OK; } int32_t DeviceManagerService::UnBindDevice(const std::string &pkgName, const std::string &udidHash, const std::string &extra) { - int32_t result = ValidateUnBindDeviceParams(pkgName, udidHash, extra); - if (result != DM_OK) { - return result; + if (!PermissionManager::GetInstance().CheckNewPermission()) { + LOGE("The caller does not have permission to call UnBindDevice."); + return ERR_DM_NO_PERMISSION; + } + LOGI("Begin for pkgName = %{public}s, udidHash = %{public}s", pkgName.c_str(), GetAnonyString(udidHash).c_str()); + if (pkgName.empty() || udidHash.empty()) { + LOGE("DeviceManagerService::UnBindDevice error: Invalid parameter, pkgName: %{public}s", pkgName.c_str()); + return ERR_DM_INPUT_PARA_INVALID; + } + if (!IsDMServiceImplReady()) { + LOGE("UnBindDevice failed, instance not init or init failed."); + return ERR_DM_NOT_INIT; } std::string realDeviceId = udidHash; #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) @@ -867,64 +871,16 @@ int32_t DeviceManagerService::UnBindDevice(const std::string &pkgName, const std return ERR_DM_FAILED; } [[maybe_unused]] uint64_t peerTokenId = dmServiceImpl_->GetTokenIdByNameAndDeviceId(extra, udid); -#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) - std::vector peerUdids; - peerUdids.emplace_back(udid); - int32_t userId = MultipleUserConnector::GetCurrentAccountUserID(); - std::map wifiDevices; - bool isBleActive = false; - GetNotifyRemoteUnBindAppWay(userId, tokenId, wifiDevices, isBleActive); - if (isBleActive) { - SendUnBindBroadCast(peerUdids, MultipleUserConnector::GetCurrentAccountUserID(), tokenId, - bindLevel, peerTokenId); - } else { - NotifyRemoteUnBindAppByWifi(userId, tokenId, extra, wifiDevices); - } -#endif if (dmServiceImpl_->UnBindDevice(pkgName, udid, bindLevel, extra) != DM_OK) { LOGE("dmServiceImpl_ UnBindDevice failed."); return ERR_DM_FAILED; } - return DM_OK; -} - -int32_t DeviceManagerService::ValidateUnBindDeviceParams(const std::string &pkgName, const std::string &udidHash) -{ - LOGI("DeviceManagerService::ValidateUnBindDeviceParams pkgName: %{public}s, udidHash: %{public}s", - GetAnonyString(pkgName).c_str(), GetAnonyString(udidHash).c_str()); - if (!PermissionManager::GetInstance().CheckNewPermission()) { - LOGE("The caller does not have permission to call UnBindDevice."); - return ERR_DM_NO_PERMISSION; - } - if (pkgName.empty() || udidHash.empty()) { - LOGE("DeviceManagerService::UnBindDevice error: Invalid parameter, pkgName: %{public}s", pkgName.c_str()); - return ERR_DM_INPUT_PARA_INVALID; - } - if (!IsDMServiceImplReady()) { - LOGE("UnBindDevice failed, instance not init or init failed."); - return ERR_DM_NOT_INIT; - } - return DM_OK; -} - -int32_t DeviceManagerService::ValidateUnBindDeviceParams(const std::string &pkgName, const std::string &udidHash, - const std::string &extra) -{ - LOGI("DeviceManagerService::ValidateUnBindDeviceParams pkgName: %{public}s, udidHash: %{public}s, " - "extra: %{public}s", GetAnonyString(pkgName).c_str(), GetAnonyString(udidHash).c_str(), - GetAnonyString(extra).c_str()); - if (!PermissionManager::GetInstance().CheckNewPermission()) { - LOGE("The caller does not have permission to call UnBindDevice."); - return ERR_DM_NO_PERMISSION; - } - if (pkgName.empty() || udidHash.empty()) { - LOGE("DeviceManagerService::UnBindDevice error: Invalid parameter, pkgName: %{public}s", pkgName.c_str()); - return ERR_DM_INPUT_PARA_INVALID; - } - if (!IsDMServiceImplReady()) { - LOGE("UnBindDevice failed, instance not init or init failed."); - return ERR_DM_NOT_INIT; - } +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + std::vector peerUdids; + peerUdids.emplace_back(udid); + SendUnBindBroadCast(peerUdids, MultipleUserConnector::GetCurrentAccountUserID(), tokenId, + bindLevel, peerTokenId); +#endif return DM_OK; } @@ -1973,6 +1929,7 @@ void DeviceManagerService::SendShareTypeUnBindBroadCast(const char *credId, cons msg.credId = credId; msg.peerUdids = peerUdids; std::string broadCastMsg = ReleationShipSyncMgr::GetInstance().SyncTrustRelationShip(msg); + LOGI("broadCastMsg = %{public}s.", broadCastMsg.c_str()); CHECK_NULL_VOID(softbusListener_); softbusListener_->SendAclChangedBroadcast(broadCastMsg); } @@ -2582,25 +2539,6 @@ void DeviceManagerService::ProcessSyncUserIds(const std::vector &foreg } } -void DeviceManagerService::ProcessUninstApp(int32_t userId, int32_t tokenId) -{ - LOGI("DeviceManagerService::ProcessUninstApp userId: %{public}s, tokenId: %{public}s", - GetAnonyInt32(userId).c_str(), GetAnonyInt32(tokenId).c_str()); - if (IsDMServiceImplReady()) { - dmServiceImpl_->ProcessAppUninstall(userId, tokenId); - } -} - -void DeviceManagerService::ProcessUnBindApp(int32_t userId, int32_t tokenId, const std::string &extra, - const std::string &udid) -{ - LOGI("DeviceManagerService::ProcessUnBindApp userId: %{public}s, tokenId: %{public}s, udid: %{public}s", - GetAnonyInt32(userId).c_str(), GetAnonyInt32(tokenId).c_str(), GetAnonyString(udid).c_str()); - if (IsDMServiceImplReady()) { - dmServiceImpl_->ProcessUnBindApp(userId, tokenId, extra, udid); - } -} - void DeviceManagerService::SendCommonEventBroadCast(const std::vector &peerUdids, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds, bool isNeedResponse) { @@ -2860,81 +2798,31 @@ void DeviceManagerService::SendDeviceUnBindBroadCast(const std::vectorSendAclChangedBroadcast(broadCastMsg); } -int32_t DeviceManagerService::CalculateBroadCastDelayTime() -{ - int64_t timeDiff = 0; - int32_t delayTime = 0; - int64_t currentTime = - std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); - { - std::lock_guard lock(broadCastLock_); - if (SendLastBroadCastTime_ == 0) { - SendLastBroadCastTime_ = currentTime; - } - timeDiff = currentTime - SendLastBroadCastTime_; - delayTime = SEND_DELAY_MAX_TIME - timeDiff + lastDelayTime_; - if (delayTime < SEND_DELAY_MIN_TIME || delayTime == SEND_DELAY_MAX_TIME) { - delayTime = SEND_DELAY_MIN_TIME; - } - SendLastBroadCastTime_ = currentTime; - lastDelayTime_ = delayTime; - } - return delayTime; -} - void DeviceManagerService::SendAppUnBindBroadCast(const std::vector &peerUdids, int32_t userId, uint64_t tokenId) { - int32_t delayTime = CalculateBroadCastDelayTime(); - std::function task = [=]() { - LOGI("SendAppUnBindBroadCast Start."); - RelationShipChangeMsg msg; - msg.type = RelationShipChangeType::APP_UNBIND; - msg.userId = static_cast(userId); - msg.peerUdids = peerUdids; - msg.tokenId = tokenId; - std::string broadCastMsg = ReleationShipSyncMgr::GetInstance().SyncTrustRelationShip(msg); - CHECK_NULL_VOID(softbusListener_); - softbusListener_->SendAclChangedBroadcast(broadCastMsg); - }; - ffrt::submit(task, ffrt::task_attr().delay(delayTime * DELAY_TIME_SEC_CONVERSION)); + RelationShipChangeMsg msg; + msg.type = RelationShipChangeType::APP_UNBIND; + msg.userId = static_cast(userId); + msg.peerUdids = peerUdids; + msg.tokenId = tokenId; + std::string broadCastMsg = ReleationShipSyncMgr::GetInstance().SyncTrustRelationShip(msg); + CHECK_NULL_VOID(softbusListener_); + softbusListener_->SendAclChangedBroadcast(broadCastMsg); } void DeviceManagerService::SendAppUnBindBroadCast(const std::vector &peerUdids, int32_t userId, uint64_t tokenId, uint64_t peerTokenId) { - int32_t delayTime = CalculateBroadCastDelayTime(); - std::function task = [=]() { - LOGI("SendAppUnBindBroadCast Start."); - RelationShipChangeMsg msg; - msg.type = RelationShipChangeType::APP_UNBIND; - msg.userId = static_cast(userId); - msg.peerUdids = peerUdids; - msg.tokenId = tokenId; - msg.peerTokenId = peerTokenId; - std::string broadCastMsg = ReleationShipSyncMgr::GetInstance().SyncTrustRelationShip(msg); - CHECK_NULL_VOID(softbusListener_); - softbusListener_->SendAclChangedBroadcast(broadCastMsg); - }; - ffrt::submit(task, ffrt::task_attr().delay(delayTime * DELAY_TIME_SEC_CONVERSION)); -} - -void DeviceManagerService::SendAppUnInstallBroadCast(const std::vector &peerUdids, int32_t userId, - uint64_t tokenId) -{ - int32_t delayTime = CalculateBroadCastDelayTime(); - std::function task = [=]() { - LOGI("SendAppUnInstallBroadCast Start."); - RelationShipChangeMsg msg; - msg.type = RelationShipChangeType::APP_UNINSTALL; - msg.userId = static_cast(userId); - msg.peerUdids = peerUdids; - msg.tokenId = tokenId; - std::string broadCastMsg = ReleationShipSyncMgr::GetInstance().SyncTrustRelationShip(msg); - CHECK_NULL_VOID(softbusListener_); - softbusListener_->SendAclChangedBroadcast(broadCastMsg); - }; - ffrt::submit(task, ffrt::task_attr().delay(delayTime * DELAY_TIME_SEC_CONVERSION)); + RelationShipChangeMsg msg; + msg.type = RelationShipChangeType::APP_UNBIND; + msg.userId = static_cast(userId); + msg.peerUdids = peerUdids; + msg.tokenId = tokenId; + msg.peerTokenId = peerTokenId; + std::string broadCastMsg = ReleationShipSyncMgr::GetInstance().SyncTrustRelationShip(msg); + CHECK_NULL_VOID(softbusListener_); + softbusListener_->SendAclChangedBroadcast(broadCastMsg); } void DeviceManagerService::SendServiceUnBindBroadCast(const std::vector &peerUdids, int32_t userId, @@ -2965,16 +2853,11 @@ void DeviceManagerService::HandleCredentialDeleted(const char *credId, const cha return; } std::string remoteUdid = ""; - bool isShareType = false; - dmServiceImpl_->HandleCredentialDeleted(credId, credInfo, localUdid, remoteUdid, isShareType); + dmServiceImpl_->HandleCredentialDeleted(credId, credInfo, localUdid, remoteUdid); if (remoteUdid.empty()) { LOGE("HandleCredentialDeleted failed, remoteUdid is empty."); return; } - if (!isShareType) { - LOGE("HandleCredentialDeleted not share type."); - return; - } std::vector peerUdids; peerUdids.emplace_back(remoteUdid); SendShareTypeUnBindBroadCast(credId, MultipleUserConnector::GetCurrentAccountUserID(), peerUdids); @@ -3042,9 +2925,6 @@ bool DeviceManagerService::ParseRelationShipChangeType(const RelationShipChangeM case RelationShipChangeType::SHARE_UNBIND: HandleShareUnbindBroadCast(relationShipMsg.userId, relationShipMsg.credId); break; - case RelationShipChangeType::APP_UNINSTALL: - ProcessUninstApp(relationShipMsg.userId, static_cast(relationShipMsg.tokenId)); - break; default: LOGI("Dm have not this event type."); return false; @@ -3250,8 +3130,6 @@ void DeviceManagerService::SubscribePackageCommonEvent() packageCommonEventManager_ = std::make_shared(); } PackageEventCallback callback = [=](const auto &arg1, const auto &arg2, const auto &arg3) { - int32_t userId = MultipleUserConnector::GetCurrentAccountUserID(); - NotifyRemoteUninstallApp(userId, arg3); if (IsDMServiceImplReady()) { dmServiceImpl_->ProcessAppUnintall(arg1, arg3); } @@ -3430,184 +3308,6 @@ void DeviceManagerService::NotifyRemoteLocalUserSwitch(int32_t curUserId, int32_ } } -void DeviceManagerService::NotifyRemoteUninstallApp(int32_t userId, int32_t tokenId) -{ - LOGI("DeviceManagerService::NotifyRemoteUninstallApp userId: %{public}s, tokenId: %{public}s", - GetAnonyInt32(userId).c_str(), GetAnonyInt32(tokenId).c_str()); - std::vector peerUdids; - int32_t currentUserId = MultipleUserConnector::GetCurrentAccountUserID(); - if (IsDMServiceImplReady()) { - peerUdids = dmServiceImpl_->GetDeviceIdByUserIdAndTokenId(currentUserId, tokenId); - } - if (peerUdids.empty()) { - LOGE("peerUdids is empty"); - return; - } - if (softbusListener_ == nullptr) { - 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()) { - LOGE("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) { - LOGE("get networkType failed: %{public}s", GetAnonyString(udid).c_str()); - bleUdids.push_back(udid); - continue; - } - uint32_t addrTypeMask = 1 << NetworkType::BIT_NETWORK_TYPE_BLE; - if ((static_cast(networkType) & addrTypeMask) != 0x0) { - bleUdids.push_back(udid); - } else { - wifiDevices.insert(std::pair(udid, netWorkId)); - } - } - if (!bleUdids.empty()) { - SendAppUnInstallBroadCast(peerUdids, userId, tokenId); - } - if (!wifiDevices.empty()) { - NotifyRemoteUninstallAppByWifi(userId, tokenId, wifiDevices); - } -} - - -void DeviceManagerService::NotifyRemoteUninstallAppByWifi(int32_t userId, int32_t tokenId, - const std::map &wifiDevices) -{ - LOGI("DeviceManagerService::NotifyRemoteUninstallAppByWifi userId: %{public}s, tokenId: %{public}s", - GetAnonyInt32(userId).c_str(), GetAnonyInt32(tokenId).c_str()); - for (const auto &it : wifiDevices) { - int32_t result = SendUninstAppByWifi(userId, tokenId, it.second); - if (result != DM_OK) { - LOGE("by wifi failed: %{public}s", GetAnonyString(it.first).c_str()); - continue; - } - if (timer_ == nullptr) { - timer_ = std::make_shared(); - } - std::string udid = it.first; - std::string networkId = it.second; - timer_->StartTimer(std::string(APP_UNINSTALL_BY_WIFI_TIMEOUT_TASK) + Crypto::Sha256(udid), - USER_SWITCH_BY_WIFI_TIMEOUT_S, [this, networkId] (std::string name) { - DMCommTool::GetInstance()->StopSocket(networkId); - }); - } -} - -void DeviceManagerService::NotifyRemoteUnBindAppByWifi(int32_t userId, int32_t tokenId, std::string extra, - const std::map &wifiDevices) -{ - LOGI("DeviceManagerService::NotifyRemoteUnBindAppByWifi userId: %{public}s, tokenId: %{public}s, extra: %{public}s", - GetAnonyInt32(userId).c_str(), GetAnonyInt32(tokenId).c_str(), GetAnonyString(extra).c_str()); - for (const auto &it : wifiDevices) { - char localUdidTemp[DEVICE_UUID_LENGTH] = {0}; - GetDevUdid(localUdidTemp, DEVICE_UUID_LENGTH); - std::string localUdid = std::string(localUdidTemp); - int32_t result = SendUnBindAppByWifi(userId, tokenId, extra, it.second, localUdid); - if (result != DM_OK) { - LOGE("by wifi failed: %{public}s", GetAnonyString(it.first).c_str()); - continue; - } - if (timer_ == nullptr) { - timer_ = std::make_shared(); - } - std::string udid = it.first; - std::string networkId = it.second; - timer_->StartTimer(std::string(APP_UNBIND_BY_WIFI_TIMEOUT_TASK) + Crypto::Sha256(udid), - USER_SWITCH_BY_WIFI_TIMEOUT_S, [this, networkId] (std::string name) { - DMCommTool::GetInstance()->StopSocket(networkId); - }); - } -} - -void DeviceManagerService::ProcessReceiveRspAppUninstall(const std::string &remoteUdid) -{ - LOGI("ProcessReceiveRspAppUninstall remoteUdid: %{public}s", GetAnonyString(remoteUdid).c_str()); - if (timer_ != nullptr && remoteUdid != "") { - timer_->DeleteTimer(std::string(APP_UNINSTALL_BY_WIFI_TIMEOUT_TASK) + Crypto::Sha256(remoteUdid)); - } -} - -void DeviceManagerService::ProcessReceiveRspAppUnbind(const std::string &remoteUdid) -{ - LOGI("ProcessReceiveRspAppUnbind remoteUdid: %{public}s", GetAnonyString(remoteUdid).c_str()); - if (timer_ != nullptr && remoteUdid != "") { - timer_->DeleteTimer(std::string(APP_UNBIND_BY_WIFI_TIMEOUT_TASK) + Crypto::Sha256(remoteUdid)); - } -} - -int32_t DeviceManagerService::SendUninstAppByWifi(int32_t userId, int32_t tokenId, const std::string &networkId) -{ - LOGE("DeviceManagerService::SendUninstAppByWifi userId: %{public}s, tokenId: %{public}s", - GetAnonyInt32(userId).c_str(), GetAnonyInt32(tokenId).c_str()); - return DMCommTool::GetInstance()->SendUninstAppObj(userId, tokenId, networkId); -} - -int32_t DeviceManagerService::SendUnBindAppByWifi(int32_t userId, int32_t tokenId, std::string extra, - const std::string &networkId, const std::string &udid) -{ - LOGE("DeviceManagerService::SendUnBindAppByWifi"); - return DMCommTool::GetInstance()->SendUnBindAppObj(userId, tokenId, extra, networkId, udid); -} - -void DeviceManagerService::GetNotifyRemoteUnBindAppWay(int32_t userId, int32_t tokenId, - std::map &wifiDevices, bool &isBleWay) -{ - std::vector peerUdids; - int32_t currentUserId = MultipleUserConnector::GetCurrentAccountUserID(); - std::map deviceMap = dmServiceImpl_->GetDeviceIdAndBindLevel(currentUserId); - for (const auto &item : deviceMap) { - peerUdids.push_back(item.first); - } - if (peerUdids.empty()) { - LOGE("peerUdids is empty"); - return; - } - if (softbusListener_ == nullptr) { - LOGE("softbusListener_ is null"); - return; - } - - std::vector bleUdids; - for (const auto &udid : peerUdids) { - std::string netWorkId = ""; - SoftbusCache::GetInstance().GetNetworkIdFromCache(udid, netWorkId); - if (netWorkId.empty()) { - LOGE("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) { - LOGE("get networkType failed: %{public}s", GetAnonyString(udid).c_str()); - bleUdids.push_back(udid); - continue; - } - uint32_t addrTypeMask = 1 << NetworkType::BIT_NETWORK_TYPE_BLE; - if ((static_cast(networkType) & addrTypeMask) != 0x0) { - bleUdids.push_back(udid); - } else { - wifiDevices.insert(std::pair(udid, netWorkId)); - } - } - - if (!bleUdids.empty()) { - isBleWay = true; - } else { - isBleWay = false; - } -} - void DeviceManagerService::NotifyRemoteLocalUserSwitchByWifi(int32_t curUserId, int32_t preUserId, const std::map &wifiDevices, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds) diff --git a/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp b/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp index 77ecde4ca6772980c2df35e2d34bd60b5cb7b082..6e7f69d1cf466b22984938dc39fbc2319c8d4400 100644 --- a/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp +++ b/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp @@ -35,10 +35,6 @@ 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_LOCAL_APP_UNINSTALL = 6; -constexpr int32_t DM_COMM_SEND_LOCAL_APP_UNBIND = 7; -constexpr int32_t DM_COMM_RSP_APP_UNINSTALL = 8; -constexpr int32_t DM_COMM_RSP_APP_UNBIND = 9; constexpr const char* EVENT_TASK = "EventTask"; const char* const USER_STOP_MSG_KEY = "stopUserId"; @@ -114,156 +110,12 @@ int32_t DMCommTool::SendUserIds(const std::string rmtNetworkId, return DM_OK; } -int32_t DMCommTool::SendUninstAppObj(int32_t userId, int32_t tokenId, const std::string &networkId) -{ - LOGI("SendUninstAppObj, userId: %{public}s, tokenId: %{public}s", GetAnonyInt32(userId).c_str(), - GetAnonyInt32(tokenId).c_str()); - if (!IsIdLengthValid(networkId)) { - LOGE("param invalid, networkId: %{public}s", GetAnonyString(networkId).c_str()); - return ERR_DM_INPUT_PARA_INVALID; - } - if (dmTransportPtr_ == nullptr) { - LOGE("dmTransportPtr_ is null"); - return ERR_DM_FAILED; - } - int32_t socketId = 0; - if (dmTransportPtr_->StartSocket(networkId, socketId) != DM_OK || socketId <= 0) { - LOGE("Start socket error"); - return ERR_DM_FAILED; - } - - UninstAppMsg uninstAppMsg(userId, tokenId); - cJSON *root = cJSON_CreateObject(); - if (root == nullptr) { - LOGE("Create cJSON object failed."); - return ERR_DM_FAILED; - } - ToJson(root, uninstAppMsg); - 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_LOCAL_APP_UNINSTALL, msgStr); - std::string payload = GetCommMsgString(commMsg); - - int32_t ret = dmTransportPtr_->Send(networkId, 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::RspAppUninstall(const std::string rmtNetworkId, int32_t socketId) -{ - LOGI("RspAppUninstall Start."); - if (dmTransportPtr_ == nullptr) { - LOGE("dmTransportPtr_ is null"); - return ERR_DM_FAILED; - } - std::string msgStr(""); - CommMsg commMsg(DM_COMM_RSP_APP_UNINSTALL, msgStr); - std::string payload = GetCommMsgString(commMsg); - - if (dmTransportPtr_ == nullptr) { - LOGE("dmTransportPtr_ is null"); - return ERR_DM_FAILED; - } - int32_t ret = dmTransportPtr_->Send(rmtNetworkId, payload, socketId); - if (ret != DM_OK) { - LOGE("RspAppUninstall failed, ret: %{public}d", ret); - return ERR_DM_FAILED; - } - - LOGI("RspAppUninstall success"); - return DM_OK; -} - -int32_t DMCommTool::RspAppUnbind(const std::string rmtNetworkId, int32_t socketId) -{ - LOGI("RspAppUnbind Start."); - if (dmTransportPtr_ == nullptr) { - LOGE("dmTransportPtr_ is null"); - return ERR_DM_FAILED; - } - std::string msgStr(""); - CommMsg commMsg(DM_COMM_RSP_APP_UNBIND, msgStr); - std::string payload = GetCommMsgString(commMsg); - - if (dmTransportPtr_ == nullptr) { - LOGE("dmTransportPtr_ is null"); - return ERR_DM_FAILED; - } - int32_t ret = dmTransportPtr_->Send(rmtNetworkId, payload, socketId); - if (ret != DM_OK) { - LOGE("RspAppUnbind failed, ret: %{public}d", ret); - return ERR_DM_FAILED; - } - - LOGI("RspAppUnbind success"); - return DM_OK; -} - -int32_t DMCommTool::SendUnBindAppObj(int32_t userId, int32_t tokenId, const std::string &extra, - const std::string &networkId, const std::string &udid) -{ - LOGI("DMCommTool::SendUnBindAppObj, userId: %{public}s, tokenId: %{public}s, extra: %{public}s, udid: %{public}s", - GetAnonyInt32(userId).c_str(), GetAnonyInt32(tokenId).c_str(), GetAnonyString(extra).c_str(), - GetAnonyString(udid).c_str()); - if (!IsIdLengthValid(networkId)) { - LOGE("param invalid, networkId: %{public}s", GetAnonyString(networkId).c_str()); - return ERR_DM_INPUT_PARA_INVALID; - } - - if (dmTransportPtr_ == nullptr) { - LOGE("dmTransportPtr_ is null"); - return ERR_DM_FAILED; - } - int32_t socketId; - if (dmTransportPtr_->StartSocket(networkId, socketId) != DM_OK || socketId <= 0) { - LOGE("Start socket error"); - return ERR_DM_FAILED; - } - - UnBindAppMsg unBindAppMsg(userId, tokenId, extra, udid); - cJSON *root = cJSON_CreateObject(); - if (root == nullptr) { - LOGE("Create cJSON object failed."); - return ERR_DM_FAILED; - } - ToJson(root, unBindAppMsg); - 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_LOCAL_APP_UNBIND, msgStr); - std::string payload = GetCommMsgString(commMsg); - - int32_t ret = dmTransportPtr_->Send(networkId, 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; -} - void DMCommTool::RspLocalFrontOrBackUserIds(const std::string rmtNetworkId, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds, int32_t socketId) { UserIdsMsg userIdsMsg(foregroundUserIds, backgroundUserIds, true); cJSON *root = cJSON_CreateObject(); - if (root == nullptr || dmTransportPtr_ == nullptr) { + if (root == nullptr) { LOGE("Create cJSON object failed."); return; } @@ -313,76 +165,47 @@ void DMCommTool::DMCommToolEventHandler::ProcessEvent(const AppExecFwk::InnerEve CHECK_NULL_VOID(commMsg); UserIdsMsg userIdsMsg; ParseUserIdsMsg(commMsg, userIdsMsg); + if (dmCommToolWPtr_.expired()) { LOGE("dmCommToolWPtr_ is expired"); return; } std::shared_ptr dmCommToolPtr = dmCommToolWPtr_.lock(); - HandleEvent(dmCommToolPtr, eventId, commMsg, userIdsMsg); -} - -void DMCommTool::DMCommToolEventHandler::HandleEvent(const std::shared_ptr &dmCommToolPtr, uint32_t eventId, - const std::shared_ptr &commMsg, const UserIdsMsg &userIdsMsg) -{ - CHECK_NULL_VOID(dmCommToolPtr); - HandleLocalUserIdEvent(dmCommToolPtr, eventId, commMsg, userIdsMsg); - switch (eventId) { - case DM_COMM_SEND_USER_STOP: { - dmCommToolPtr->ProcessReceiveUserStopEvent(commMsg); - break; - } - case DM_COMM_RSP_USER_STOP: { - dmCommToolPtr->ProcessResponseUserStopEvent(commMsg); - break; - } - case DM_COMM_ACCOUNT_LOGOUT: { - dmCommToolPtr->ProcessReceiveLogoutEvent(commMsg); - break; - } - case DM_COMM_SEND_LOCAL_APP_UNINSTALL: { - dmCommToolPtr->ProcessReceiveUninstAppEvent(commMsg); - break; - } - case DM_COMM_SEND_LOCAL_APP_UNBIND: { - dmCommToolPtr->ProcessReceiveUnBindAppEvent(commMsg); - break; - } - case DM_COMM_RSP_APP_UNINSTALL: { - dmCommToolPtr->ProcessReceiveRspAppUninstallEvent(commMsg); - break; - } - case DM_COMM_RSP_APP_UNBIND: { - dmCommToolPtr->ProcessReceiveRspAppUnbindEvent(commMsg); - break; - } - default: - LOGE("event is undefined, id is %{public}d", eventId); - break; - } -} - -void DMCommTool::DMCommToolEventHandler::HandleLocalUserIdEvent(const std::shared_ptr &dmCommToolPtr, - uint32_t eventId, const std::shared_ptr &commMsg, const UserIdsMsg &userIdsMsg) -{ CHECK_NULL_VOID(dmCommToolPtr); switch (eventId) { case DM_COMM_SEND_LOCAL_USERIDS: { if (userIdsMsg.isNewEvent) { dmCommToolPtr->ProcessReceiveCommonEvent(commMsg); } else { + // Process remote foreground userids and send back local user ids dmCommToolPtr->ProcessReceiveUserIdsEvent(commMsg); } break; } case DM_COMM_RSP_LOCAL_USERIDS: { if (userIdsMsg.isNewEvent) { + // Process remote foreground userids and close session dmCommToolPtr->ProcessResponseCommonEvent(commMsg); } else { + // 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); + break; + } + case DM_COMM_ACCOUNT_LOGOUT: { + dmCommToolPtr->ProcessReceiveLogoutEvent(commMsg); + break; + } default: + LOGE("event is undefined, id is %{public}d", eventId); break; } } @@ -506,115 +329,6 @@ void DMCommTool::ProcessReceiveUserIdsEvent(const std::shared_ptr } } -void DMCommTool::ProcessReceiveUninstAppEvent(const std::shared_ptr commMsg) -{ - if (commMsg == nullptr || commMsg->commMsg == nullptr) { - LOGE("commMsg or commMsg->commMsg is null"); - return; - } - LOGI("DMCommTool::ProcessReceiveUninstAppEvent commMsg = %{public}s", - GetAnonyString(commMsg->commMsg->msg).c_str()); - std::string payload = commMsg->commMsg->msg; - cJSON *root = cJSON_Parse(payload.c_str()); - if (root == NULL) { - LOGE("the msg is not json format"); - return; - } - UninstAppMsg uninstAppMsg; - FromJson(root, uninstAppMsg); - cJSON_Delete(root); - RspAppUninstall(commMsg->remoteNetworkId, commMsg->socketId); - - if (uninstAppMsg.userId_ == -1 || uninstAppMsg.tokenId_ == -1) { - LOGE("param invalid, userId: %{public}d, tokenId: %{public}d", - uninstAppMsg.userId_, uninstAppMsg.tokenId_); - return; - } else { - DeviceManagerService::GetInstance().ProcessUninstApp(uninstAppMsg.userId_, - uninstAppMsg.tokenId_); - } -} - -void DMCommTool::ProcessReceiveUnBindAppEvent(const std::shared_ptr commMsg) -{ - if (commMsg == nullptr || commMsg->commMsg == nullptr) { - LOGE("commMsg or commMsg->commMsg is null"); - return; - } - LOGI("DMCommTool::ProcessReceiveUnBindAppEvent Receive remote uninstall app"); - std::string payload = commMsg->commMsg->msg; - cJSON *root = cJSON_Parse(payload.c_str()); - if (root == NULL) { - LOGE("the msg is not json format"); - return; - } - UnBindAppMsg unBindAppMsg; - FromJson(root, unBindAppMsg); - cJSON_Delete(root); - RspAppUnbind(commMsg->remoteNetworkId, commMsg->socketId); - - if (unBindAppMsg.userId_ == -1 || unBindAppMsg.tokenId_ == -1) { - LOGE("param invalid, userId: %{public}d, tokenId: %{public}d", - unBindAppMsg.userId_, unBindAppMsg.tokenId_); - return; - } else { - DeviceManagerService::GetInstance().ProcessUnBindApp(unBindAppMsg.userId_, - unBindAppMsg.tokenId_, unBindAppMsg.extra_, unBindAppMsg.udid_); - } -} - -void DMCommTool::StopSocket(const std::string &networkId) -{ - LOGI("DMCommTool::StopSocket, networkId = %{public}s", networkId.c_str()); - if (dmTransportPtr_ == nullptr) { - LOGE("dmTransportPtr_ is null"); - return; - } - dmTransportPtr_->StopSocket(networkId); -} - -void DMCommTool::ProcessReceiveRspAppUninstallEvent(const std::shared_ptr commMsg) -{ - if (commMsg == nullptr || commMsg->remoteNetworkId == "") { - LOGE("commMsg or commMsg->remoteNetworkId is null"); - return; - } - LOGI("DMCommTool::ProcessReceiveRspAppUninstallEvent Start."); - if (dmTransportPtr_ == nullptr) { - LOGE("dmTransportPtr_ is null"); - return; - } - 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."); - return; - } - DeviceManagerService::GetInstance().ProcessReceiveRspAppUninstall(rmtUdid); -} - -void DMCommTool::ProcessReceiveRspAppUnbindEvent(const std::shared_ptr commMsg) -{ - if (commMsg == nullptr || commMsg->remoteNetworkId == "") { - LOGE("commMsg or commMsg->remoteNetworkId is null"); - return; - } - if (dmTransportPtr_ == nullptr) { - LOGE("dmTransportPtr_ is null"); - return; - } - LOGI("DMCommTool::ProcessReceiveRspAppUnbindEvent Start."); - 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."); - return; - } - DeviceManagerService::GetInstance().ProcessReceiveRspAppUnbind(rmtUdid); -} - void DMCommTool::ProcessResponseUserIdsEvent(const std::shared_ptr commMsg) { LOGI("start"); @@ -624,7 +338,7 @@ void DMCommTool::ProcessResponseUserIdsEvent(const std::shared_ptr std::string rmtUdid = ""; SoftbusCache::GetInstance().GetUdidFromCache(commMsg->remoteNetworkId.c_str(), rmtUdid); if (rmtUdid.empty()) { - LOGE("Can not find remote udid by networkid."); + LOGE("Can not find remote udid by networkid: %{public}s", commMsg->remoteNetworkId.c_str()); return; } diff --git a/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp b/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp index 1344d1168194b9d32b583d0d24f37fa028ee39f3..3011d225ccc655fec045cdb989ece3d7adbd0012 100644 --- a/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp +++ b/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp @@ -30,9 +30,6 @@ const char* const DSOFTBUS_NOTIFY_USERIDS_UDIDKEY = "remoteUdid"; const char* const DSOFTBUS_NOTIFY_USERIDS_USERIDKEY = "foregroundUserIds"; const char* const DSOFTBUS_NOTIFY_ACCOUNTID_KEY = "accountId"; const char* const DSOFTBUS_NOTIFY_USERID_KEY = "userId"; -const char* const DSOFTBUS_NOTIFY_TOKENID_KEY = "tokenId"; -const char* const DSOFTBUS_NOTIFY_EXTRA_KEY = "extra"; -const char* const DSOFTBUS_NOTIFY_UDID_KEY = "udid"; } void ToJson(cJSON *jsonObject, const UserIdsMsg &userIdsMsg) { @@ -265,79 +262,5 @@ void FromJson(const cJSON *jsonObject, LogoutAccountMsg &accountInfo) accountInfo.userId = userIdObj->valueint; } } - -void ToJson(cJSON *jsonObject, const UninstAppMsg &uninstAppMsg) -{ - if (jsonObject == nullptr) { - LOGE("Json pointer is nullptr!"); - return; - } - - cJSON_AddNumberToObject(jsonObject, DSOFTBUS_NOTIFY_USERID_KEY, uninstAppMsg.userId_); - cJSON_AddNumberToObject(jsonObject, DSOFTBUS_NOTIFY_TOKENID_KEY, uninstAppMsg.tokenId_); -} - -void FromJson(const cJSON *jsonObject, UninstAppMsg &uninstAppMsg) -{ - if (jsonObject == nullptr) { - LOGE("Json pointer is nullptr!"); - return; - } - - cJSON *userIdObj = cJSON_GetObjectItem(jsonObject, DSOFTBUS_NOTIFY_USERID_KEY); - cJSON *tokenIdObj = cJSON_GetObjectItem(jsonObject, DSOFTBUS_NOTIFY_TOKENID_KEY); - if (userIdObj == nullptr || tokenIdObj == nullptr) { - LOGE("userIdObj or tokenIdObj is nullptr"); - return; - } - if (cJSON_IsNumber(userIdObj)) { - uninstAppMsg.userId_ = userIdObj->valueint; - } - if (cJSON_IsNumber(tokenIdObj)) { - uninstAppMsg.tokenId_ = tokenIdObj->valueint; - } -} - -void ToJson(cJSON *jsonObject, const UnBindAppMsg &unBindAppMsg) -{ - if (jsonObject == nullptr) { - LOGE("Json pointer is nullptr!"); - return; - } - - cJSON_AddNumberToObject(jsonObject, DSOFTBUS_NOTIFY_USERID_KEY, unBindAppMsg.userId_); - cJSON_AddNumberToObject(jsonObject, DSOFTBUS_NOTIFY_TOKENID_KEY, unBindAppMsg.tokenId_); - cJSON_AddStringToObject(jsonObject, DSOFTBUS_NOTIFY_EXTRA_KEY, unBindAppMsg.extra_.c_str()); - cJSON_AddStringToObject(jsonObject, DSOFTBUS_NOTIFY_UDID_KEY, unBindAppMsg.udid_.c_str()); -} - -void FromJson(const cJSON *jsonObject, UnBindAppMsg &unBindAppMsg) -{ - if (jsonObject == nullptr) { - LOGE("Json pointer is nullptr!"); - return; - } - - cJSON *userIdObj = cJSON_GetObjectItem(jsonObject, DSOFTBUS_NOTIFY_USERID_KEY); - cJSON *tokenIdObj = cJSON_GetObjectItem(jsonObject, DSOFTBUS_NOTIFY_TOKENID_KEY); - cJSON *extraObj = cJSON_GetObjectItem(jsonObject, DSOFTBUS_NOTIFY_EXTRA_KEY); - cJSON *udidObj = cJSON_GetObjectItem(jsonObject, DSOFTBUS_NOTIFY_UDID_KEY); - if (userIdObj == nullptr || tokenIdObj == nullptr || extraObj == nullptr || udidObj == nullptr) { - LOGE("userIdObj or tokenIdObj or extraObj or udidObj is nullptr"); - return; - } - if (cJSON_IsNumber(userIdObj)) { - unBindAppMsg.userId_ = userIdObj->valueint; - } - if (cJSON_IsNumber(tokenIdObj)) { - unBindAppMsg.tokenId_ = tokenIdObj->valueint; - } - if (cJSON_IsString(extraObj)) { - unBindAppMsg.extra_ = extraObj->valuestring; - } - if (cJSON_IsString(udidObj)) { - unBindAppMsg.udid_ = udidObj->valuestring; - } -} } // 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 6c2aa108e71624c4d7b5f1eb4895baf046e4156f..428531518c4ad4b158350e1ed36242d7f2b5453f 100644 --- a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp +++ b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp @@ -52,7 +52,6 @@ namespace { const int32_t STOP_USER_PAYLOAD_LEN = 3; const int32_t SHARE_UNBIND_PAYLOAD_LEN = 9; const int32_t SHARE_UNBIND_BROADCAST_LEN = 8; - const int32_t APP_UNINSTALL_PAYLOAD_LEN = 7; /** * @brief the userid payload cost 2 bytes. * @@ -148,10 +147,6 @@ bool RelationShipChangeMsg::ToBroadcastPayLoad(uint8_t *&msg, uint32_t &len) con ToShareUnbindPayLoad(msg, len); ret = true; break; - case RelationShipChangeType::APP_UNINSTALL: - ToAppUninstallPayLoad(msg, len); - ret = true; - break; default: LOGE("RelationShipChange type invalid"); break; @@ -213,9 +208,6 @@ bool RelationShipChangeMsg::FromBroadcastPayLoad(const cJSON *payloadJson, Relat case RelationShipChangeType::SHARE_UNBIND: ret = FromShareUnbindPayLoad(payloadJson); break; - case RelationShipChangeType::APP_UNINSTALL: - ret = FromAppUninstallPayLoad(payloadJson); - break; default: LOGE("RelationShipChange type invalid"); break; @@ -288,7 +280,8 @@ bool RelationShipChangeMsg::IsValid() const ret = (userId != UINT32_MAX); break; case RelationShipChangeType::APP_UNINSTALL: - ret = (userId != UINT32_MAX && tokenId != UINT64_MAX); + // current NOT support + ret = false; break; case RelationShipChangeType::SYNC_USERID: ret = (!userIdInfos.empty() && @@ -309,7 +302,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::APP_UNINSTALL); + (type == RelationShipChangeType::SERVICE_UNBIND); } bool RelationShipChangeMsg::IsChangeTypeValid(uint32_t type) @@ -321,8 +314,7 @@ bool RelationShipChangeMsg::IsChangeTypeValid(uint32_t type) (type == (uint32_t)RelationShipChangeType::DEL_USER) || (type == (uint32_t)RelationShipChangeType::STOP_USER) || (type == (uint32_t)RelationShipChangeType::SHARE_UNBIND) || - (type == (uint32_t)RelationShipChangeType::SERVICE_UNBIND) || - (type == (uint32_t)RelationShipChangeType::APP_UNINSTALL); + (type == (uint32_t)RelationShipChangeType::SERVICE_UNBIND); } void RelationShipChangeMsg::ToAccountLogoutPayLoad(uint8_t *&msg, uint32_t &len) const @@ -376,23 +368,6 @@ void RelationShipChangeMsg::ToAppUnbindPayLoad(uint8_t *&msg, uint32_t &len) con len = APP_UNBIND_PAYLOAD_LEN; } -void RelationShipChangeMsg::ToAppUninstallPayLoad(uint8_t *&msg, uint32_t &len) const -{ - msg = new uint8_t[APP_UNINSTALL_PAYLOAD_LEN](); - for (int i = 0; i < USERID_PAYLOAD_LEN; i++) { - msg[i] |= (userId >> (i * BITS_PER_BYTE)) & 0xFF; - } - - for (int i = USERID_PAYLOAD_LEN; i < TOKENID_PAYLOAD_LEN; i++) { - msg[i] |= (tokenId >> ((i - USERID_PAYLOAD_LEN) * BITS_PER_BYTE)) & 0xFF; - } - - for (int i = TOKENID_PAYLOAD_LEN; i < APP_UNINSTALL_PAYLOAD_LEN; i++) { - msg[i] |= (broadCastId >> ((i - TOKENID_PAYLOAD_LEN) * BITS_PER_BYTE)) & 0xFF; - } - len = APP_UNINSTALL_PAYLOAD_LEN; -} - void RelationShipChangeMsg::ToServiceUnbindPayLoad(uint8_t *&msg, uint32_t &len) const { ToAppUnbindPayLoad(msg, len); @@ -579,45 +554,6 @@ bool RelationShipChangeMsg::FromAppUnbindPayLoad(const cJSON *payloadJson) return true; } -bool RelationShipChangeMsg::FromAppUninstallPayLoad(const cJSON *payloadJson) -{ - if (payloadJson == NULL) { - LOGE("App unbind payloadJson is null."); - return false; - } - int32_t arraySize = cJSON_GetArraySize(payloadJson); - if (arraySize < APP_UNINSTALL_PAYLOAD_LEN || arraySize >= INVALIED_PAYLOAD_SIZE) { - LOGE("Payload invalied,the size is %{public}d.", arraySize); - return false; - } - userId = 0; - for (uint32_t i = 0; i < USERID_PAYLOAD_LEN; i++) { - cJSON *payloadItem = cJSON_GetArrayItem(payloadJson, i); - CHECK_NULL_RETURN(payloadItem, false); - if (cJSON_IsNumber(payloadItem)) { - userId |= (static_cast(payloadItem->valueint)) << (i * BITS_PER_BYTE); - } - } - tokenId = 0; - for (uint32_t j = USERID_PAYLOAD_LEN; j < TOKENID_PAYLOAD_LEN; j++) { - cJSON *payloadItem = cJSON_GetArrayItem(payloadJson, j); - CHECK_NULL_RETURN(payloadItem, false); - if (cJSON_IsNumber(payloadItem)) { - tokenId |= (static_cast(payloadItem->valueint)) << ((j - USERID_PAYLOAD_LEN) * BITS_PER_BYTE); - } - } - this->broadCastId = 0; - for (uint32_t j = TOKENID_PAYLOAD_LEN; j < APP_UNINSTALL_PAYLOAD_LEN; j++) { - cJSON *payloadItem = cJSON_GetArrayItem(payloadJson, j); - CHECK_NULL_RETURN(payloadItem, false); - if (cJSON_IsNumber(payloadItem)) { - this->broadCastId |= (static_cast(payloadItem->valueint)) << - ((j - TOKENID_PAYLOAD_LEN) * BITS_PER_BYTE); - } - } - return true; -} - bool RelationShipChangeMsg::FromServiceUnbindPayLoad(const cJSON *payloadJson) { return FromAppUnbindPayLoad(payloadJson); diff --git a/test/unittest/UTTest_device_manager_service_impl_first.cpp b/test/unittest/UTTest_device_manager_service_impl_first.cpp index b6a89fcacd61faaafeceb9a7e74d5af884286e3e..0d7ef000be23d053895f004d476ee6931c2430c7 100644 --- a/test/unittest/UTTest_device_manager_service_impl_first.cpp +++ b/test/unittest/UTTest_device_manager_service_impl_first.cpp @@ -207,7 +207,6 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, HandleCredentialDeleted_001, testing const char *credInfo = "invalid_json"; std::string localUdid = "localUdid"; std::string remoteUdid; - bool isShareType = false; std::vector profiles; @@ -216,7 +215,7 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, HandleCredentialDeleted_001, testing EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlById(_)) .Times(0); - deviceManagerServiceImpl_->HandleCredentialDeleted(credId, credInfo, localUdid, remoteUdid, isShareType); + deviceManagerServiceImpl_->HandleCredentialDeleted(credId, credInfo, localUdid, remoteUdid); } HWTEST_F(DeviceManagerServiceImplFirstTest, HandleCredentialDeleted_002, testing::ext::TestSize.Level1) @@ -225,7 +224,6 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, HandleCredentialDeleted_002, testing const char *credInfo = R"({"deviceId": "remoteUdid", "userId": 1})"; std::string localUdid = "localUdid"; std::string remoteUdid; - bool isShareType = false; std::vector profiles; AccessControlProfile profile; @@ -236,7 +234,7 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, HandleCredentialDeleted_002, testing .WillOnce(Return(profiles)); EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlById(_)).Times(0); - deviceManagerServiceImpl_->HandleCredentialDeleted(credId, credInfo, localUdid, remoteUdid, isShareType); + deviceManagerServiceImpl_->HandleCredentialDeleted(credId, credInfo, localUdid, remoteUdid); } HWTEST_F(DeviceManagerServiceImplFirstTest, HandleCredentialDeleted_003, testing::ext::TestSize.Level1) @@ -245,7 +243,6 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, HandleCredentialDeleted_003, testing const char *credInfo = R"({"deviceId": "remoteUdid", "userId": 1})"; std::string localUdid = "localUdid"; std::string remoteUdid; - bool isShareType = false; std::vector profiles; AccessControlProfile profile; @@ -263,7 +260,7 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, HandleCredentialDeleted_003, testing EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlById(_)) .Times(1); - deviceManagerServiceImpl_->HandleCredentialDeleted(credId, credInfo, localUdid, remoteUdid, isShareType); + deviceManagerServiceImpl_->HandleCredentialDeleted(credId, credInfo, localUdid, remoteUdid); } HWTEST_F(DeviceManagerServiceImplFirstTest, HandleCredentialDeleted_004, testing::ext::TestSize.Level1) @@ -272,7 +269,6 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, HandleCredentialDeleted_004, testing const char *credInfo = R"({"deviceId": "remoteUdid", "userId": 1})"; std::string localUdid = "localUdid"; std::string remoteUdid; - bool isShareType = false; std::vector profiles; AccessControlProfile profile; @@ -290,7 +286,7 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, HandleCredentialDeleted_004, testing EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlById(_)) .Times(1); - deviceManagerServiceImpl_->HandleCredentialDeleted(credId, credInfo, localUdid, remoteUdid, isShareType); + deviceManagerServiceImpl_->HandleCredentialDeleted(credId, credInfo, localUdid, remoteUdid); } HWTEST_F(DeviceManagerServiceImplFirstTest, HandleShareUnbindBroadCast_001, testing::ext::TestSize.Level1) diff --git a/test/unittest/UTTest_device_manager_service_two.cpp b/test/unittest/UTTest_device_manager_service_two.cpp index 7f15c8ffe7d1b602d0f7a5325099212452d616bc..2efbf6ccce475eeb70f4694d6999bc3d79e73bb0 100644 --- a/test/unittest/UTTest_device_manager_service_two.cpp +++ b/test/unittest/UTTest_device_manager_service_two.cpp @@ -1820,23 +1820,33 @@ HWTEST_F(DeviceManagerServiceTest, SendShareTypeUnBindBroadCast_001, testing::ex HWTEST_F(DeviceManagerServiceTest, HandleCredentialDeleted_001, testing::ext::TestSize.Level1) { + std::string remoteUdid = "remoteUdid"; + EXPECT_CALL(*deviceManagerServiceImplMock_, HandleCredentialDeleted(_, _, _, _)) + .WillOnce(SetArgReferee<3>(remoteUdid)); + EXPECT_CALL(*multipleUserConnectorMock_, GetCurrentAccountUserID()).WillOnce(Return(1001)); + EXPECT_CALL(*softbusListenerMock_, SendAclChangedBroadcast(_)).Times(::testing::AtLeast(1)); + DeviceManagerService::GetInstance().HandleCredentialDeleted("credId", "credInfo"); } HWTEST_F(DeviceManagerServiceTest, HandleCredentialDeleted_002, testing::ext::TestSize.Level1) { - EXPECT_CALL(*deviceManagerServiceImplMock_, HandleCredentialDeleted(_, _, _, _, _)).Times(0); + EXPECT_CALL(*deviceManagerServiceImplMock_, HandleCredentialDeleted(_, _, _, _)).Times(0); DeviceManagerService::GetInstance().HandleCredentialDeleted(nullptr, "credInfo"); } HWTEST_F(DeviceManagerServiceTest, HandleCredentialDeleted_003, testing::ext::TestSize.Level1) { + EXPECT_CALL(*deviceManagerServiceImplMock_, HandleCredentialDeleted(_, _, _, _)).Times(0); + DeviceManagerService::GetInstance().HandleCredentialDeleted("credId", nullptr); } HWTEST_F(DeviceManagerServiceTest, HandleCredentialDeleted_004, testing::ext::TestSize.Level1) { + EXPECT_CALL(*deviceManagerServiceImplMock_, HandleCredentialDeleted(_, _, _, _)) + .WillOnce(SetArgReferee<3>("")); EXPECT_CALL(*multipleUserConnectorMock_, GetCurrentAccountUserID()).Times(0); EXPECT_CALL(*softbusListenerMock_, SendAclChangedBroadcast(_)).Times(0); diff --git a/test/unittest/mock/device_manager_service_impl_mock.cpp b/test/unittest/mock/device_manager_service_impl_mock.cpp index d4cbeecf6646b7969c63fa78cec076ac084f7e58..5d7cbb990bec91326ad3cb4d65a64dfa94820aaf 100644 --- a/test/unittest/mock/device_manager_service_impl_mock.cpp +++ b/test/unittest/mock/device_manager_service_impl_mock.cpp @@ -73,10 +73,10 @@ bool DeviceManagerServiceImpl::CheckSharePeerSrc(const std::string &peerUdid, co } void DeviceManagerServiceImpl::HandleCredentialDeleted(const char *credId, - const char *credInfo, const std::string &localUdid, std::string &remoteUdid, bool &isShareType) + const char *credInfo, const std::string &localUdid, std::string &remoteUdid) { DmDeviceManagerServiceImpl::dmDeviceManagerServiceImpl->HandleCredentialDeleted(credId, - credInfo, localUdid, remoteUdid, isShareType); + credInfo, localUdid, remoteUdid); } void DeviceManagerServiceImpl::HandleShareUnbindBroadCast(const std::string &credId, const int32_t &userId, const std::string &localUdid) diff --git a/test/unittest/mock/device_manager_service_impl_mock.h b/test/unittest/mock/device_manager_service_impl_mock.h index 81f1a9e548f9d51df09c98adc6c019e1cadfc82a..8c3b483802a42678769b6e5624bcbb1986534f55 100644 --- a/test/unittest/mock/device_manager_service_impl_mock.h +++ b/test/unittest/mock/device_manager_service_impl_mock.h @@ -39,7 +39,7 @@ public: int32_t bindLevel, const std::string &extra) = 0; virtual bool CheckSharePeerSrc(const std::string &peerUdid, const std::string &localUdid) = 0; virtual void HandleCredentialDeleted(const char *credId, const char *credInfo, const std::string &localUdid, - std::string &remoteUdid, bool &isShareType) = 0; + std::string &remoteUdid) = 0; virtual void HandleShareUnbindBroadCast(const std::string &credId, const int32_t &userId, const std::string &localUdid) = 0; virtual int32_t CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId) = 0; @@ -59,8 +59,7 @@ public: MOCK_METHOD(int32_t, UnAuthenticateDevice, (const std::string &, const std::string &, int32_t)); MOCK_METHOD(int32_t, UnBindDevice, (const std::string &, const std::string &, int32_t, const std::string &)); MOCK_METHOD(bool, CheckSharePeerSrc, (const std::string &peerUdid, const std::string &localUdid)); - MOCK_METHOD(void, HandleCredentialDeleted, (const char *, const char *, const std::string &, - std::string &, bool &)); + MOCK_METHOD(void, HandleCredentialDeleted, (const char *, const char *, const std::string &, std::string &)); MOCK_METHOD(void, HandleShareUnbindBroadCast, (const std::string &, const int32_t &, const std::string &)); MOCK_METHOD(int32_t, CheckDeviceInfoPermission, (const std::string &, const std::string &)); };