From be47dd07f7049634a3d6f738c5bad2fc680ca330 Mon Sep 17 00:00:00 2001 From: "xiaocong.ran" Date: Mon, 7 Mar 2022 09:46:01 +0800 Subject: [PATCH] bug Signed-off-by: xiaocong.ran Change-Id: I010ca25a761f2f369359c145762f19c9ffe0f327 --- .../include/authentication/dm_auth_manager.h | 2 ++ .../dependency/softbus/softbus_connector.h | 2 -- .../devicestate/dm_device_state_manager.h | 1 + .../src/authentication/dm_auth_manager.cpp | 28 +++++++++++++------ .../dependency/softbus/softbus_connector.cpp | 15 ---------- .../devicestate/dm_device_state_manager.cpp | 15 ++++------ 6 files changed, 28 insertions(+), 35 deletions(-) diff --git a/services/devicemanagerservice/include/authentication/dm_auth_manager.h b/services/devicemanagerservice/include/authentication/dm_auth_manager.h index 204ef0fe7..9e1dd3b69 100644 --- a/services/devicemanagerservice/include/authentication/dm_auth_manager.h +++ b/services/devicemanagerservice/include/authentication/dm_auth_manager.h @@ -164,6 +164,7 @@ public: int32_t OnUserOperation(int32_t action); void UserSwitchEventCallback(int32_t userId); int32_t SetPageId(int32_t pageId); + int32_t SetReason(int32_t reason, int32_t state); private: std::shared_ptr softbusConnector_; @@ -179,6 +180,7 @@ private: std::map> timerMap_; std::shared_ptr dmAbilityMgr_; bool isCryptoSupport_ = false; + bool isFinishOfLocal_ = true; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/devicemanagerservice/include/dependency/softbus/softbus_connector.h b/services/devicemanagerservice/include/dependency/softbus/softbus_connector.h index a7f5f3aa7..a957f42a8 100644 --- a/services/devicemanagerservice/include/dependency/softbus/softbus_connector.h +++ b/services/devicemanagerservice/include/dependency/softbus/softbus_connector.h @@ -48,8 +48,6 @@ public: static bool IsDeviceOnLine(const std::string &deviceId); static int32_t GetUdidByNetworkId(const char *networkId, std::string &udid); static int32_t GetUuidByNetworkId(const char *networkId, std::string &uuid); - static int32_t GetNodeKeyInfoByNetworkId(const char *networkId, NodeDeviceInfoKey key, uint8_t *info, - int32_t infoLen); public: SoftbusConnector(); diff --git a/services/devicemanagerservice/include/devicestate/dm_device_state_manager.h b/services/devicemanagerservice/include/devicestate/dm_device_state_manager.h index f34198c37..7817313fc 100755 --- a/services/devicemanagerservice/include/devicestate/dm_device_state_manager.h +++ b/services/devicemanagerservice/include/devicestate/dm_device_state_manager.h @@ -61,6 +61,7 @@ private: std::map remoteDeviceInfos_; std::map decisionInfos_; std::map> timerMap_; + std::map deviceinfoMap_; std::shared_ptr hiChainConnector_; std::string decisionSoName_; }; diff --git a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp index 359721a01..d5ad03109 100644 --- a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp +++ b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp @@ -148,14 +148,12 @@ int32_t DmAuthManager::UnAuthenticateDevice(const std::string &pkgName, const st LOGI(" DmAuthManager::UnAuthenticateDevice failed pkgName is null"); return DM_FAILED; } - uint8_t udid[UDID_BUF_LEN] = {0}; - int32_t ret = SoftbusConnector::GetNodeKeyInfoByNetworkId(deviceId.c_str(), NodeDeviceInfoKey::NODE_KEY_UDID, udid, - sizeof(udid)); + std::string deviceUdid; + int32_t ret = SoftbusConnector::GetUdidByNetworkId(deviceId.c_str(), deviceUdid); if (ret != DM_OK) { LOGE("UnAuthenticateDevice GetNodeKeyInfo failed"); return DM_FAILED; } - std::string deviceUdid = (char *)udid; std::string groupId = ""; std::vector groupList; @@ -302,9 +300,11 @@ void DmAuthManager::OnDataReceived(int32_t sessionId, std::string message) case MSG_TYPE_REQ_AUTH_TERMINATE: if (authResponseState_ != nullptr && authResponseState_->GetStateType() != AuthState::AUTH_RESPONSE_FINISH) { + isFinishOfLocal_ = false; authResponseState_->TransitionTo(std::make_shared()); } else if (authRequestState_ != nullptr && authRequestState_->GetStateType() != AuthState::AUTH_REQUEST_FINISH) { + isFinishOfLocal_ = false; authResponseContext_->state = authRequestState_->GetStateType(); authRequestState_->TransitionTo(std::make_shared()); } @@ -572,8 +572,7 @@ void DmAuthManager::AuthenticateFinish() if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_FINISH) { Ace::UIServiceMgrClient::GetInstance()->CancelDialog(authResponseContext_->pageId); } - if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_SHOW - && authResponseContext_->authType != 1) { + if (isFinishOfLocal_) { authMessageProcessor_->SetResponseContext(authResponseContext_); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_REQ_AUTH_TERMINATE); softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); @@ -584,17 +583,17 @@ void DmAuthManager::AuthenticateFinish() } timerMap_.clear(); } + isFinishOfLocal_ = true; authResponseContext_ = nullptr; authResponseState_ = nullptr; authMessageProcessor_ = nullptr; } else if (authRequestState_ != nullptr) { - if (authResponseContext_->reply != DM_AUTH_BUSINESS_BUSY) { + if (isFinishOfLocal_) { authMessageProcessor_->SetResponseContext(authResponseContext_); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_REQ_AUTH_TERMINATE); softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); } else { - authRequestContext_->reason = DM_AUTH_BUSINESS_BUSY; - authResponseContext_->state = AuthState::AUTH_REQUEST_INIT; + authRequestContext_->reason = authResponseContext_->reply; } if (authResponseContext_->state == AuthState::AUTH_REQUEST_INPUT) { @@ -612,6 +611,7 @@ void DmAuthManager::AuthenticateFinish() } timerMap_.clear(); } + isFinishOfLocal_ = true; authRequestContext_ = nullptr; authResponseContext_ = nullptr; authRequestState_ = nullptr; @@ -823,5 +823,15 @@ int32_t DmAuthManager::SetPageId(int32_t pageId) authResponseContext_->pageId = pageId; return DM_OK; } + +int32_t DmAuthManager::SetReason(int32_t reason, int32_t state) +{ + if (state < AuthState::AUTH_REQUEST_FINISH) { + authRequestContext_->reason = reason; + } + authResponseContext_->state = state; + authResponseContext_->reply = reason; + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp index f3278fe8e..a202a09d7 100644 --- a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp +++ b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp @@ -237,21 +237,6 @@ int32_t SoftbusConnector::StopDiscovery(uint16_t subscribeId) return DM_OK; } -int32_t SoftbusConnector::GetNodeKeyInfoByNetworkId(const char *networkId, NodeDeviceInfoKey key, uint8_t *info, - int32_t infoLen) -{ - LOGI("GetNodeKeyInfoByNetworkId begin"); - - int32_t ret = GetNodeKeyInfo(DM_PKG_NAME.c_str(), networkId, key, info, infoLen); - if (ret != DM_OK) { - LOGE("GetNodeKeyInfoByNetworkId GetNodeKeyInfo failed"); - return DM_FAILED; - } - - LOGI("SoftbusConnector::GetNodeKeyInfoByNetworkId completed"); - return DM_OK; -} - int32_t SoftbusConnector::GetUdidByNetworkId(const char *networkId, std::string &udid) { LOGI("GetUdidByNetworkId begin"); diff --git a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp index 8c182fa9a..003671447 100755 --- a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp +++ b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp @@ -56,9 +56,8 @@ int32_t DmDeviceStateManager::RegisterProfileListener(const std::string &pkgName DmAdapterManager &adapterMgrPtr = DmAdapterManager::GetInstance(); std::shared_ptr profileAdapter = adapterMgrPtr.GetProfileAdapter(profileSoName_); if (profileAdapter != nullptr) { - uint8_t udid[UDID_BUF_LEN + 1] = {0}; - int32_t ret = SoftbusConnector::GetNodeKeyInfoByNetworkId(info.deviceId, - NodeDeviceInfoKey::NODE_KEY_UDID, udid, sizeof(udid)); + std::string deviceUdid; + int32_t ret = SoftbusConnector::GetUdidByNetworkId(info.deviceId, deviceUdid); if (ret == DM_OK) { std::string uuid; DmDeviceInfo saveInfo = info; @@ -67,7 +66,6 @@ int32_t DmDeviceStateManager::RegisterProfileListener(const std::string &pkgName std::lock_guard mutexLock(remoteDeviceInfosMutex_); remoteDeviceInfos_[uuid] = saveInfo; } - std::string deviceUdid = (char *)udid; LOGI("RegisterProfileListener in, deviceId = %s, deviceUdid = %s, uuid = %s", info.deviceId, deviceUdid.c_str(), uuid.c_str()); profileAdapter->RegisterProfileListener(pkgName, deviceUdid, shared_from_this()); @@ -245,6 +243,7 @@ void DmDeviceStateManager::RegisterOffLineTimer(const DmDeviceInfo &deviceInfo) LOGI("Register OffLine Timer with device: %s", GetAnonyString(deviceId).c_str()); std::lock_guard mutexLock(timerMapMutex_); + deviceinfoMap_[deviceInfo.deviceId] = deviceId; auto iter = timerMap_.find(deviceId); if (iter != timerMap_.end()) { iter->second->Stop(SESSION_CANCEL_TIMEOUT); @@ -258,17 +257,15 @@ void DmDeviceStateManager::RegisterOffLineTimer(const DmDeviceInfo &deviceInfo) void DmDeviceStateManager::StartOffLineTimer(const DmDeviceInfo &deviceInfo) { - std::string deviceId; - int32_t ret = softbusConnector_->GetUdidByNetworkId(deviceInfo.deviceId, deviceId); - if (ret != DM_OK) { + if (deviceinfoMap_.find(deviceInfo.deviceId) == deviceinfoMap_.end()) { LOGE("fail to get udid by networkId"); return; } - LOGI("start offline timer with device: %s", GetAnonyString(deviceId).c_str()); + LOGI("start offline timer with device: %s", GetAnonyString(deviceinfoMap_[deviceInfo.deviceId]).c_str()); std::lock_guard mutexLock(timerMapMutex_); for (auto &iter : timerMap_) { - if (iter.first == deviceId) { + if (iter.first == deviceinfoMap_[deviceInfo.deviceId]) { iter.second->Start(OFFLINE_TIMEOUT, TimeOut, this); } } -- Gitee