diff --git a/services/devicemanagerservice/include/authentication/dm_auth_manager.h b/services/devicemanagerservice/include/authentication/dm_auth_manager.h index 204ef0fe7eeec2ac1a40d9fdd25aa51eff6c8f3f..9e1dd3b69b87226ad14636df7e4f07bcac202678 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 a7f5f3aa7a9c193955841495ec4693df583cdb06..a957f42a83d211cfe2e686401bc6fa317c027f99 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 f34198c37ab1c35c9d79dfa846e35614a385bb24..7817313fc7a3af962550f2886f9560afa8ee4cbc 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 359721a012625694e3d529ffe5d02a4862b7e301..d5ad0310940960e6ad308943e2e4d2fef55deca0 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 f3278fe8e811b45d325d7e0f0c53824a4297eced..a202a09d7773064c192ac7c0bc7bc80494bee014 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 8c182fa9af7db91c3a3e661a48446c93c744e9b0..7936159c649509517b0e3052e8faf5ad6742dbf2 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,20 +257,19 @@ 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); } } + deviceinfoMap_.erase(deviceInfo.deviceId); } void DmDeviceStateManager::DeleteTimeOutGroup(std::string deviceId)