From bf7a38c14dcf71839298786cedd7849de6cdb91c Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Tue, 8 Mar 2022 14:14:54 +0800 Subject: [PATCH 1/2] =?UTF-8?q?bug:=E6=89=AB=E7=A2=B0=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=A0=81/=E9=87=8D=E5=A4=8D=E5=8A=9F=E8=83=BD=E4=BB=A3?= =?UTF-8?q?=E7=A0=81/=E8=AE=BE=E5=A4=87=E4=B8=8B=E7=BA=BF=E4=B8=8D?= =?UTF-8?q?=E5=85=B7=E5=A4=87=E9=80=9A=E8=BF=87networkid=E6=9F=A5=E5=AF=BB?= =?UTF-8?q?=E6=89=80=E6=96=B0=E5=A2=9E=E7=9A=84map/pin=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- ext/pin_auth/src/pin_auth.cpp | 13 +++++---- .../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 | 17 ++++++----- 7 files changed, 37 insertions(+), 41 deletions(-) diff --git a/ext/pin_auth/src/pin_auth.cpp b/ext/pin_auth/src/pin_auth.cpp index 15c52772c..a971791db 100644 --- a/ext/pin_auth/src/pin_auth.cpp +++ b/ext/pin_auth/src/pin_auth.cpp @@ -66,18 +66,19 @@ int32_t PinAuth::VerifyAuthentication(std::string &authToken, const std::string times_ += 1; nlohmann::json authParamJson = nlohmann::json::parse(authParam, nullptr, false); if (authParamJson.is_discarded()) { - LOGE("DecodeRequestAuth jsonStr error"); + if (authParam == "0") { + return DM_OK; + } + LOGE("Peer rejection"); return DM_FAILED; } nlohmann::json authTokenJson = nlohmann::json::parse(authToken, nullptr, false); - if (authParamJson.is_discarded()) { + if (authTokenJson.is_discarded()) { LOGE("DecodeRequestAuth jsonStr error"); return DM_FAILED; } - if (!authParamJson.contains(PIN_CODE_KEY) && !authParamJson.contains(PIN_TOKEN)) { - if (authParam == "0") { - return DM_OK; - } + if (!authParamJson.contains(PIN_CODE_KEY) || !authParamJson.contains(PIN_TOKEN) + || !authTokenJson.contains(PIN_CODE_KEY) || !authTokenJson.contains(PIN_TOKEN)) { LOGE("err json string, first time"); return DM_FAILED; } 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..503150e10 100755 --- a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp +++ b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp @@ -40,6 +40,7 @@ DmDeviceStateManager::DmDeviceStateManager(std::shared_ptr sof : softbusConnector_(softbusConnector), listener_(listener), hiChainConnector_(hiChainConnector) { profileSoName_ = "libdevicemanagerext_profile.z.so"; + decisionSoName_ = "libdevicemanagerext_decision.z.so"; LOGI("DmDeviceStateManager constructor"); } @@ -56,9 +57,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 +67,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 +244,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 +258,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) -- Gitee From 38a7e212d89e82ab985ffc27ad69ec6b0634f419 Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Tue, 8 Mar 2022 15:20:54 +0800 Subject: [PATCH 2/2] =?UTF-8?q?bug:=E6=89=AB=E7=A2=B0=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=A0=81/=E9=87=8D=E5=A4=8D=E5=8A=9F=E8=83=BD=E4=BB=A3?= =?UTF-8?q?=E7=A0=81/=E8=AE=BE=E5=A4=87=E4=B8=8B=E7=BA=BF=E4=B8=8D?= =?UTF-8?q?=E5=85=B7=E5=A4=87=E9=80=9A=E8=BF=87networkid=E6=9F=A5=E5=AF=BB?= =?UTF-8?q?=E6=89=80=E6=96=B0=E5=A2=9E=E7=9A=84map/pin=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- .../src/devicestate/dm_device_state_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp index 503150e10..1cef6db56 100755 --- a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp +++ b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp @@ -40,7 +40,7 @@ DmDeviceStateManager::DmDeviceStateManager(std::shared_ptr sof : softbusConnector_(softbusConnector), listener_(listener), hiChainConnector_(hiChainConnector) { profileSoName_ = "libdevicemanagerext_profile.z.so"; - decisionSoName_ = "libdevicemanagerext_decision.z.so"; + decisionSoName_ = "libdevicemanagerext_decision.z.so"; LOGI("DmDeviceStateManager constructor"); } -- Gitee