From 56345e9b258f936a23580244881903a57eb8bcc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Wed, 9 Apr 2025 17:28:50 +0800 Subject: [PATCH 01/13] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E9=80=80=E5=87=BA=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- .../service/include/device_manager_service.h | 3 + .../relationshipsyncmgr/dm_comm_tool.h | 2 + .../relationshipsyncmgr/dm_transport_msg.h | 11 +++ .../service/src/device_manager_service.cpp | 46 +++++++++++- .../src/relationshipsyncmgr/dm_comm_tool.cpp | 71 +++++++++++++++++++ .../relationshipsyncmgr/dm_transport_msg.cpp | 30 ++++++++ 6 files changed, 162 insertions(+), 1 deletion(-) diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index 8b40da361..4bd96325b 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -236,6 +236,9 @@ public: bool IsPC(); int32_t GetDeviceNetworkIdList(const std::string &pkgName, const NetworkIdQueryFilter &queryFilter, std::vector &networkIds); + void NotifyRemoteLocalLogout(const std::vector &peerUdids, + const std::string &accountId, const std::string &accountName, int32_t userId); + void ProcessSyncAccountLogout(const std::string &accountId, const std::string &peerUdid, int32_t userId); private: bool IsDMServiceImplReady(); diff --git a/services/service/include/relationshipsyncmgr/dm_comm_tool.h b/services/service/include/relationshipsyncmgr/dm_comm_tool.h index a4cd2befb..d60b00071 100644 --- a/services/service/include/relationshipsyncmgr/dm_comm_tool.h +++ b/services/service/include/relationshipsyncmgr/dm_comm_tool.h @@ -56,6 +56,8 @@ public: void ProcessReceiveUserIdsEvent(const std::shared_ptr commMsg); void ProcessResponseUserIdsEvent(const std::shared_ptr commMsg); + int32_t SendLogoutAccountInfo(const std::string &rmtNetworkId, const std::string &accountId, int32_t userId); + void ProcessReceiveLogoutEvent(const std::shared_ptr commMsg); 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 a4fb17712..5c3ac7ace 100644 --- a/services/service/include/relationshipsyncmgr/dm_transport_msg.h +++ b/services/service/include/relationshipsyncmgr/dm_transport_msg.h @@ -64,6 +64,17 @@ struct NotifyUserIds { void ToJson(cJSON *jsonObject, const NotifyUserIds &userIds); void FromJson(const cJSON *jsonObject, NotifyUserIds &userIds); + +struct LogoutAccountMsg { + std::string accountId; + int32_t userId; + LogoutAccountMsg() : userId(0) {} + LogoutAccountMsg(const std::string &accountId, int32_t userId) + : accountId(accountId), userId(userId) {} +}; + +void ToJson(cJSON *jsonObject, const LogoutAccountMsg &accountInfo); +void FromJson(const cJSON *jsonObject, LogoutAccountMsg &accountInfo); } // DistributedHardware } // OHOS #endif \ No newline at end of file diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index aa87475de..a464aa22e 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -2095,7 +2095,7 @@ void DeviceManagerService::HandleAccountLogout(int32_t userId, const std::string LOGE("GetAccountHash failed."); return; } - SendAccountLogoutBroadCast(peerUdids, std::string(accountIdHash), accountName, userId); + NotifyRemoteLocalLogout(peerUdids, userId, accountId, accountName); } for (const auto &item : deviceMap) { dmServiceImpl_->HandleIdentAccountLogout(localUdid, userId, item.first, item.second); @@ -3361,5 +3361,49 @@ int32_t DeviceManagerService::GetDeviceNetworkIdList(const std::string &pkgName, } return DM_OK; } + +void DeviceManagerService::NotifyRemoteLocalLogout(const std::vector &peerUdids, + const std::string &accountId, const std::string &accountName, int32_t userId) +{ + 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()) { + SendAccountLogoutBroadCast(bleUdids, accountId, accountName, userId); + } + for (const auto &it : wifiDevices) { + DMCommTool::GetInstance()->SendLogoutAccountInfo(it.second, accountId, userId); + } +} + +void DeviceManagerService::ProcessSyncAccountLogout(const std::string &accountId, const std::string &peerUdid, + int32_t userId) +{ + if (!IsDMServiceImplReady()) { + LOGE("Imp instance not init or init failed."); + return; + } + dmServiceImpl_->HandleAccountLogoutEvent(userId, accountId, peerUdid); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp b/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp index 7047624ff..58dc75bb6 100644 --- a/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp +++ b/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp @@ -33,6 +33,7 @@ constexpr int32_t DM_COMM_SEND_LOCAL_USERIDS = 1; constexpr int32_t DM_COMM_RSP_LOCAL_USERIDS = 2; constexpr int32_t DM_COMM_SEND_USER_STOP = 3; constexpr int32_t DM_COMM_RSP_USER_STOP = 4; +constexpr int32_t DM_COMM_ACCOUNT_LOGOUT = 5; const char* const USER_STOP_MSG_KEY = "stopUserId"; @@ -179,6 +180,10 @@ void DMCommTool::DMCommToolEventHandler::ProcessEvent( dmCommToolPtr->ProcessResponseUserStopEvent(commMsg); break; } + case DM_COMM_ACCOUNT_LOGOUT: { + dmCommToolPtr->ProcessReceiveLogoutEvent(commMsg); + break; + } default: LOGE("event is undefined, id is %{public}d", eventId); break; @@ -418,5 +423,71 @@ void DMCommTool::ProcessResponseUserStopEvent(const std::shared_ptr(localDeviceId); DeviceManagerService::GetInstance().HandleUserStop(stopUserId, localUdid, acceptEventUdids); } + +int32_t DMCommTool::SendLogoutAccountInfo(const std::string &rmtNetworkId, + const std::string &accountId, int32_t userId) +{ + if (!IsIdLengthValid(rmtNetworkId) || accountId.empty() || dmTransportPtr_ == nullptr) { + LOGE("param invalid, networkId: %{public}s, userId: %{public}d", + GetAnonyString(rmtNetworkId).c_str(), userId); + return ERR_DM_INPUT_PARA_INVALID; + } + int32_t socketId = 0; + if (dmTransportPtr_->StartSocket(rmtNetworkId, socketId) != DM_OK || socketId <= 0) { + LOGE("Start socket error"); + return ERR_DM_FAILED; + } + + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + LOGE("Create cJSON object failed."); + return ERR_DM_FAILED; + } + LogoutAccountMsg LogoutAccountMsg(accountId, userId); + ToJson(root, LogoutAccountMsg); + 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_ACCOUNT_LOGOUT, msgStr); + std::string payload = GetCommMsgString(commMsg); + + int32_t ret = dmTransportPtr_->Send(rmtNetworkId, payload, socketId); + if (ret != DM_OK) { + LOGE("Send account logout failed, ret: %{public}d", ret); + return ERR_DM_FAILED; + } + LOGI("Send account logout success"); + return DM_OK; +} + +void DMCommTool::ProcessReceiveLogoutEvent(const std::shared_ptr commMsg) +{ + LOGI("Receive remote logout."); + 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; + } + LogoutAccountMsg logoutAccountMsg; + FromJson(root, logoutAccountMsg); + cJSON_Delete(root); + + // step1: send back local userids + DeviceManagerService::GetInstance().ProcessSyncAccountLogout(logoutAccountMsg.accountId, + rmtUdid, userId); +} } // DistributedHardware } // OHOS \ No newline at end of file diff --git a/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp b/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp index 1cbd08a52..42a0ae7cd 100644 --- a/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp +++ b/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp @@ -27,6 +27,8 @@ const char* const COMM_MSG_CODE_KEY = "code"; const char* const COMM_MSG_MSG_KEY = "msg"; 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_PEERUDID_KEY = "peerUdid"; } void ToJson(cJSON *jsonObject, const UserIdsMsg &userIdsMsg) { @@ -226,5 +228,33 @@ std::string NotifyUserIds::ToString() cJSON_free(retStr); return ret; } + +void ToJson(cJSON *jsonObject, const LogoutAccountMsg &accountInfo) +{ + if (jsonObject == nullptr) { + LOGE("Json pointer is nullptr!"); + return; + } + + cJSON_AddStringToObject(jsonObject, DSOFTBUS_NOTIFY_ACCOUNTID_KEY, accountInfo.accountId.c_str()); + cJSON_AddNumberToObject(jsonObject, DSOFTBUS_NOTIFY_USERIDS_USERIDKEY, accountInfo.userId); +} + +void FromJson(const cJSON *jsonObject, LogoutAccountMsg &accountInfo) +{ + if (jsonObject == nullptr) { + LOGE("Json pointer is nullptr!"); + return; + } + cJSON *accountIdObj = cJSON_GetObjectItem(jsonObject, DSOFTBUS_NOTIFY_ACCOUNTID_KEY); + if (cJSON_IsString(codeObj)) { + accountInfo.accountId = accountIdObj->valuestring; + } + + cJSON *userIdObj = cJSON_GetObjectItem(jsonObject, DSOFTBUS_NOTIFY_USERIDS_USERIDKEY); + if (cJSON_IsNumber(userIdObj)) { + accountInfo.userId = userIdObj->valueint; + } +} } // DistributedHardware } // OHOS \ No newline at end of file -- Gitee From e111f2ffbfdfadf68686804d68653839e3798346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Wed, 9 Apr 2025 17:56:06 +0800 Subject: [PATCH 02/13] =?UTF-8?q?=E4=BF=AE=E6=94=B9bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- services/service/include/device_manager_service.h | 4 ++-- services/service/src/device_manager_service.cpp | 2 +- services/service/src/relationshipsyncmgr/dm_comm_tool.cpp | 2 +- services/service/src/relationshipsyncmgr/dm_transport_msg.cpp | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index 4bd96325b..65bf19cb9 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -236,8 +236,6 @@ public: bool IsPC(); int32_t GetDeviceNetworkIdList(const std::string &pkgName, const NetworkIdQueryFilter &queryFilter, std::vector &networkIds); - void NotifyRemoteLocalLogout(const std::vector &peerUdids, - const std::string &accountId, const std::string &accountName, int32_t userId); void ProcessSyncAccountLogout(const std::string &accountId, const std::string &peerUdid, int32_t userId); private: @@ -347,6 +345,8 @@ private: EXPORT void SubscribeDataShareCommonEvent(); #endif void CheckRegisterInfoWithWise(int32_t curUserId); +void NotifyRemoteLocalLogout(const std::vector &peerUdids, + const std::string &accountId, const std::string &accountName, int32_t userId); private: bool isImplsoLoaded_ = false; diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index a464aa22e..ec0f1a5d1 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -2095,7 +2095,7 @@ void DeviceManagerService::HandleAccountLogout(int32_t userId, const std::string LOGE("GetAccountHash failed."); return; } - NotifyRemoteLocalLogout(peerUdids, userId, accountId, accountName); + NotifyRemoteLocalLogout(peerUdids, accountId, accountName, userId); } for (const auto &item : deviceMap) { dmServiceImpl_->HandleIdentAccountLogout(localUdid, userId, item.first, item.second); diff --git a/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp b/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp index 58dc75bb6..156e1767e 100644 --- a/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp +++ b/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp @@ -487,7 +487,7 @@ void DMCommTool::ProcessReceiveLogoutEvent(const std::shared_ptr c // step1: send back local userids DeviceManagerService::GetInstance().ProcessSyncAccountLogout(logoutAccountMsg.accountId, - rmtUdid, userId); + rmtUdid, logoutAccountMsg.userId); } } // DistributedHardware } // OHOS \ No newline at end of file diff --git a/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp b/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp index 42a0ae7cd..dbcfec2f6 100644 --- a/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp +++ b/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp @@ -247,7 +247,7 @@ void FromJson(const cJSON *jsonObject, LogoutAccountMsg &accountInfo) return; } cJSON *accountIdObj = cJSON_GetObjectItem(jsonObject, DSOFTBUS_NOTIFY_ACCOUNTID_KEY); - if (cJSON_IsString(codeObj)) { + if (cJSON_IsString(accountIdObj)) { accountInfo.accountId = accountIdObj->valuestring; } -- Gitee From 90a7bc0179128fcf4d4b95ccab0f95601e8ba04a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Thu, 10 Apr 2025 15:16:30 +0800 Subject: [PATCH 03/13] =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- .../implementation/src/device_manager_service_impl.cpp | 1 + services/service/include/device_manager_service.h | 2 +- services/service/src/device_manager_service.cpp | 10 ++++++---- .../service/src/relationshipsyncmgr/dm_comm_tool.cpp | 4 ++-- .../service/src/relationshipsyncmgr/dm_transport.cpp | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 12ad2f7fd..a571e7ac8 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -806,6 +806,7 @@ void DeviceManagerServiceImpl::HandleAccountLogoutEvent(int32_t remoteUserId, co SoftbusCache::GetInstance().GetUuidByUdid(remoteUdid, uuid); listener_->OnDeviceTrustChange(remoteUdid, uuid, DmAuthForm::IDENTICAL_ACCOUNT); for (const auto &item : devIdAndUserMap) { + LOGI("remoteUdid %{public}s.", GetAnonyString(remoteUdid).c_str()); bool notifyOffline = DeviceProfileConnector::GetInstance().DeleteAclForAccountLogOut(item.first, item.second, remoteUdid, remoteUserId); if (notifyOffline) { diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index 65bf19cb9..43a8d5503 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -346,7 +346,7 @@ private: #endif void CheckRegisterInfoWithWise(int32_t curUserId); void NotifyRemoteLocalLogout(const std::vector &peerUdids, - const std::string &accountId, const std::string &accountName, int32_t userId); + const std::string &accountIdHash, const std::string &accountName, int32_t userId); private: bool isImplsoLoaded_ = false; diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index ec0f1a5d1..e3e18ff47 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -2095,7 +2095,7 @@ void DeviceManagerService::HandleAccountLogout(int32_t userId, const std::string LOGE("GetAccountHash failed."); return; } - NotifyRemoteLocalLogout(peerUdids, accountId, accountName, userId); + NotifyRemoteLocalLogout(peerUdids, std::string(accountIdHash), accountName, userId); } for (const auto &item : deviceMap) { dmServiceImpl_->HandleIdentAccountLogout(localUdid, userId, item.first, item.second); @@ -3363,8 +3363,9 @@ int32_t DeviceManagerService::GetDeviceNetworkIdList(const std::string &pkgName, } void DeviceManagerService::NotifyRemoteLocalLogout(const std::vector &peerUdids, - const std::string &accountId, const std::string &accountName, int32_t userId) + const std::string &accountIdHash, const std::string &accountName, int32_t userId) { + LOGI("Start."); std::vector bleUdids; std::map wifiDevices; for (const auto &udid : peerUdids) { @@ -3389,16 +3390,17 @@ void DeviceManagerService::NotifyRemoteLocalLogout(const std::vectorSendLogoutAccountInfo(it.second, accountId, userId); + DMCommTool::GetInstance()->SendLogoutAccountInfo(it.second, accountIdHash, userId); } } void DeviceManagerService::ProcessSyncAccountLogout(const std::string &accountId, const std::string &peerUdid, int32_t userId) { + LOGI("Start. process udid: %{public}s", GetAnonyString(peerUdid).c_str()); if (!IsDMServiceImplReady()) { LOGE("Imp instance not init or init failed."); return; diff --git a/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp b/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp index 156e1767e..458d836b2 100644 --- a/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp +++ b/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp @@ -432,6 +432,7 @@ int32_t DMCommTool::SendLogoutAccountInfo(const std::string &rmtNetworkId, GetAnonyString(rmtNetworkId).c_str(), userId); return ERR_DM_INPUT_PARA_INVALID; } + LOGI("Start, send networkId: %{public}s", GetAnonyString(rmtNetworkId).c_str()); int32_t socketId = 0; if (dmTransportPtr_->StartSocket(rmtNetworkId, socketId) != DM_OK || socketId <= 0) { LOGE("Start socket error"); @@ -467,7 +468,7 @@ int32_t DMCommTool::SendLogoutAccountInfo(const std::string &rmtNetworkId, void DMCommTool::ProcessReceiveLogoutEvent(const std::shared_ptr commMsg) { - LOGI("Receive remote logout."); + LOGI("Receive remote logout, networkId: %{public}s", GetAnonyString(commMsg->remoteNetworkId).c_str()); std::string rmtUdid = ""; SoftbusCache::GetInstance().GetUdidFromCache(commMsg->remoteNetworkId.c_str(), rmtUdid); if (rmtUdid.empty()) { @@ -485,7 +486,6 @@ void DMCommTool::ProcessReceiveLogoutEvent(const std::shared_ptr c FromJson(root, logoutAccountMsg); cJSON_Delete(root); - // step1: send back local userids DeviceManagerService::GetInstance().ProcessSyncAccountLogout(logoutAccountMsg.accountId, rmtUdid, logoutAccountMsg.userId); } diff --git a/services/service/src/relationshipsyncmgr/dm_transport.cpp b/services/service/src/relationshipsyncmgr/dm_transport.cpp index 3d102b082..ba1832028 100644 --- a/services/service/src/relationshipsyncmgr/dm_transport.cpp +++ b/services/service/src/relationshipsyncmgr/dm_transport.cpp @@ -117,7 +117,7 @@ void DMTransport::HandleReceiveMessage(const int32_t socketId, const std::string LOGE("payload invalid"); return; } - LOGI("Receive msg: %{public}s", payload.c_str()); + LOGI("Receive msg: %{public}s", GetAnonyString(payload).c_str()); cJSON *root = cJSON_Parse(payload.c_str()); if (root == NULL) { LOGE("the msg is not json format"); -- Gitee From 3b62c23fffe670997046a1135cb5d5892923b40d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Thu, 10 Apr 2025 15:44:18 +0800 Subject: [PATCH 04/13] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- services/service/src/relationshipsyncmgr/dm_comm_tool.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp b/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp index 458d836b2..0fc70bd33 100644 --- a/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp +++ b/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp @@ -468,6 +468,7 @@ int32_t DMCommTool::SendLogoutAccountInfo(const std::string &rmtNetworkId, void DMCommTool::ProcessReceiveLogoutEvent(const std::shared_ptr commMsg) { + CHECK_NULL_VOID(commMsg); LOGI("Receive remote logout, networkId: %{public}s", GetAnonyString(commMsg->remoteNetworkId).c_str()); std::string rmtUdid = ""; SoftbusCache::GetInstance().GetUdidFromCache(commMsg->remoteNetworkId.c_str(), rmtUdid); -- Gitee From dc35208c0cfd2ffa12cf67c04c9e28500a3fc6a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Thu, 10 Apr 2025 16:00:06 +0800 Subject: [PATCH 05/13] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- services/service/src/relationshipsyncmgr/dm_transport_msg.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp b/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp index dbcfec2f6..010236db3 100644 --- a/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp +++ b/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp @@ -28,7 +28,6 @@ const char* const COMM_MSG_MSG_KEY = "msg"; 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_PEERUDID_KEY = "peerUdid"; } void ToJson(cJSON *jsonObject, const UserIdsMsg &userIdsMsg) { -- Gitee From aa5c097036ec92656baefd0a3227ff4b92559029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Fri, 11 Apr 2025 14:11:45 +0800 Subject: [PATCH 06/13] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- services/service/src/device_manager_service.cpp | 5 ++++- services/service/src/relationshipsyncmgr/dm_comm_tool.cpp | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index e3e18ff47..b1f0aa131 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -3393,7 +3393,10 @@ void DeviceManagerService::NotifyRemoteLocalLogout(const std::vectorSendLogoutAccountInfo(it.second, accountIdHash, userId); + ret = DMCommTool::GetInstance()->SendLogoutAccountInfo(it.second, accountIdHash, userId); + if (ret != DM_OK) { + LOGE("Send LogoutAccount Info error, ret = %{public}d", ret); + } } } diff --git a/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp b/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp index 0fc70bd33..420f413e5 100644 --- a/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp +++ b/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp @@ -487,6 +487,11 @@ void DMCommTool::ProcessReceiveLogoutEvent(const std::shared_ptr c FromJson(root, logoutAccountMsg); cJSON_Delete(root); + if (logoutAccountMsg.accountId.empty() || logoutAccountMsg.userId == -1) { + LOGE("param invalid, accountId: %{public}s, userId: %{public}d", + logoutAccountMsg.accountId, logoutAccountMsg.userId); + return; + } DeviceManagerService::GetInstance().ProcessSyncAccountLogout(logoutAccountMsg.accountId, rmtUdid, logoutAccountMsg.userId); } -- Gitee From 39e90decf78780e773a662bb3afd4cb1164c0980 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Fri, 11 Apr 2025 15:51:09 +0800 Subject: [PATCH 07/13] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- services/service/include/device_manager_service.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index 43a8d5503..98477167c 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -345,8 +345,8 @@ private: EXPORT void SubscribeDataShareCommonEvent(); #endif void CheckRegisterInfoWithWise(int32_t curUserId); -void NotifyRemoteLocalLogout(const std::vector &peerUdids, - const std::string &accountIdHash, const std::string &accountName, int32_t userId); + void NotifyRemoteLocalLogout(const std::vector &peerUdids, + const std::string &accountIdHash, const std::string &accountName, int32_t userId); private: bool isImplsoLoaded_ = false; -- Gitee From 99f11d0fa186f64051ce910f8b27ad79cbb3ad96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Fri, 11 Apr 2025 16:23:32 +0800 Subject: [PATCH 08/13] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- services/service/src/device_manager_service.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index b1f0aa131..b45b24548 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -3393,7 +3393,7 @@ void DeviceManagerService::NotifyRemoteLocalLogout(const std::vectorSendLogoutAccountInfo(it.second, accountIdHash, userId); + int32_t ret = DMCommTool::GetInstance()->SendLogoutAccountInfo(it.second, accountIdHash, userId); if (ret != DM_OK) { LOGE("Send LogoutAccount Info error, ret = %{public}d", ret); } -- Gitee From ff5dcd8e9b2d0f21c426cc6430f2a0b98d0e10c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Fri, 11 Apr 2025 16:57:38 +0800 Subject: [PATCH 09/13] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- services/service/src/relationshipsyncmgr/dm_comm_tool.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp b/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp index 420f413e5..3fad3b168 100644 --- a/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp +++ b/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp @@ -489,7 +489,7 @@ void DMCommTool::ProcessReceiveLogoutEvent(const std::shared_ptr c if (logoutAccountMsg.accountId.empty() || logoutAccountMsg.userId == -1) { LOGE("param invalid, accountId: %{public}s, userId: %{public}d", - logoutAccountMsg.accountId, logoutAccountMsg.userId); + GetAnonyString(logoutAccountMsg.accountId).c_str(), logoutAccountMsg.userId); return; } DeviceManagerService::GetInstance().ProcessSyncAccountLogout(logoutAccountMsg.accountId, -- Gitee From 4b59ff1ef281adda196e33720941effde64ef248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Fri, 11 Apr 2025 17:19:11 +0800 Subject: [PATCH 10/13] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- services/service/src/device_manager_service.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index b45b24548..c68c7e68b 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -3367,7 +3367,7 @@ void DeviceManagerService::NotifyRemoteLocalLogout(const std::vector bleUdids; - std::map wifiDevices; + std::vector wifiDevices; for (const auto &udid : peerUdids) { std::string netWorkId = ""; SoftbusCache::GetInstance().GetNetworkIdFromCache(udid, netWorkId); @@ -3386,14 +3386,14 @@ void DeviceManagerService::NotifyRemoteLocalLogout(const std::vector(networkType) & USERID_SYNC_DISCOVERY_TYPE_BLE_MASK) != 0x0) { bleUdids.push_back(udid); } else { - wifiDevices.insert(std::pair(udid, netWorkId)); + wifiDevices.push_back(netWorkId); } } if (!bleUdids.empty()) { SendAccountLogoutBroadCast(bleUdids, accountIdHash, accountName, userId); } for (const auto &it : wifiDevices) { - int32_t ret = DMCommTool::GetInstance()->SendLogoutAccountInfo(it.second, accountIdHash, userId); + int32_t ret = DMCommTool::GetInstance()->SendLogoutAccountInfo(it, accountIdHash, userId); if (ret != DM_OK) { LOGE("Send LogoutAccount Info error, ret = %{public}d", ret); } -- Gitee From 355c2a69b60c00324de2e96ee6852aa08c21fe7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Fri, 11 Apr 2025 17:31:27 +0800 Subject: [PATCH 11/13] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- services/service/src/relationshipsyncmgr/dm_comm_tool.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp b/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp index 3fad3b168..36c69cc4d 100644 --- a/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp +++ b/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp @@ -473,10 +473,11 @@ void DMCommTool::ProcessReceiveLogoutEvent(const std::shared_ptr c 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()); + LOGE("Can not find remote udid by networkid: %{public}s", GetAnonyString(commMsg->remoteNetworkId).c_str()); return; } + CHECK_NULL_VOID(commMsg->commMsg); std::string payload = commMsg->commMsg->msg; cJSON *root = cJSON_Parse(payload.c_str()); if (root == NULL) { @@ -494,6 +495,7 @@ void DMCommTool::ProcessReceiveLogoutEvent(const std::shared_ptr c } DeviceManagerService::GetInstance().ProcessSyncAccountLogout(logoutAccountMsg.accountId, rmtUdid, logoutAccountMsg.userId); + LOGI("process remote logout success."); } } // DistributedHardware } // OHOS \ No newline at end of file -- Gitee From 71290eeb01edf97b61242208086cb27179fc9de1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Fri, 11 Apr 2025 18:00:39 +0800 Subject: [PATCH 12/13] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- services/service/include/device_manager_service.h | 6 +++--- services/service/src/device_manager_service.cpp | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index 98477167c..ec1798488 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -197,6 +197,7 @@ public: void HandleUserStop(int32_t stopUserId, const std::string &stopEventUdid); void HandleUserStop(int32_t stopUserId, const std::string &stopEventUdid, const std::vector &acceptEventUdids); + void ProcessSyncAccountLogout(const std::string &accountId, const std::string &peerUdid, int32_t userId); #endif int32_t SetDnPolicy(const std::string &pkgName, std::map &policy); void ClearDiscoveryCache(const ProcessInfo &processInfo); @@ -236,7 +237,6 @@ public: bool IsPC(); 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); private: bool IsDMServiceImplReady(); @@ -343,10 +343,10 @@ private: void QueryDependsSwitchState(); #endif // SUPPORT_BLUETOOTH SUPPORT_WIFI EXPORT void SubscribeDataShareCommonEvent(); -#endif - void CheckRegisterInfoWithWise(int32_t curUserId); void NotifyRemoteLocalLogout(const std::vector &peerUdids, const std::string &accountIdHash, const std::string &accountName, int32_t userId); +#endif + void CheckRegisterInfoWithWise(int32_t curUserId); private: bool isImplsoLoaded_ = false; diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index c68c7e68b..3fd954322 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -3362,6 +3362,7 @@ int32_t DeviceManagerService::GetDeviceNetworkIdList(const std::string &pkgName, return DM_OK; } +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) void DeviceManagerService::NotifyRemoteLocalLogout(const std::vector &peerUdids, const std::string &accountIdHash, const std::string &accountName, int32_t userId) { @@ -3410,5 +3411,6 @@ void DeviceManagerService::ProcessSyncAccountLogout(const std::string &accountId } dmServiceImpl_->HandleAccountLogoutEvent(userId, accountId, peerUdid); } +#endif } // namespace DistributedHardware } // namespace OHOS -- Gitee From ad964f238c40b22bec5d5c8d7b9e5fc1fd9ee958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Fri, 11 Apr 2025 18:09:29 +0800 Subject: [PATCH 13/13] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- services/service/include/device_manager_service.h | 6 +++--- services/service/src/device_manager_service.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index ec1798488..98477167c 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -197,7 +197,6 @@ public: void HandleUserStop(int32_t stopUserId, const std::string &stopEventUdid); void HandleUserStop(int32_t stopUserId, const std::string &stopEventUdid, const std::vector &acceptEventUdids); - void ProcessSyncAccountLogout(const std::string &accountId, const std::string &peerUdid, int32_t userId); #endif int32_t SetDnPolicy(const std::string &pkgName, std::map &policy); void ClearDiscoveryCache(const ProcessInfo &processInfo); @@ -237,6 +236,7 @@ public: bool IsPC(); 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); private: bool IsDMServiceImplReady(); @@ -343,10 +343,10 @@ private: void QueryDependsSwitchState(); #endif // SUPPORT_BLUETOOTH SUPPORT_WIFI EXPORT void SubscribeDataShareCommonEvent(); - void NotifyRemoteLocalLogout(const std::vector &peerUdids, - const std::string &accountIdHash, const std::string &accountName, int32_t userId); #endif void CheckRegisterInfoWithWise(int32_t curUserId); + void NotifyRemoteLocalLogout(const std::vector &peerUdids, + const std::string &accountIdHash, const std::string &accountName, int32_t userId); private: bool isImplsoLoaded_ = false; diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 3fd954322..750dece0b 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -3362,7 +3362,6 @@ int32_t DeviceManagerService::GetDeviceNetworkIdList(const std::string &pkgName, return DM_OK; } -#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) void DeviceManagerService::NotifyRemoteLocalLogout(const std::vector &peerUdids, const std::string &accountIdHash, const std::string &accountName, int32_t userId) { @@ -3393,12 +3392,14 @@ void DeviceManagerService::NotifyRemoteLocalLogout(const std::vectorSendLogoutAccountInfo(it, accountIdHash, userId); if (ret != DM_OK) { LOGE("Send LogoutAccount Info error, ret = %{public}d", ret); } } +#endif } void DeviceManagerService::ProcessSyncAccountLogout(const std::string &accountId, const std::string &peerUdid, @@ -3411,6 +3412,5 @@ void DeviceManagerService::ProcessSyncAccountLogout(const std::string &accountId } dmServiceImpl_->HandleAccountLogoutEvent(userId, accountId, peerUdid); } -#endif } // namespace DistributedHardware } // namespace OHOS -- Gitee