From 29812a548aea71cdfb6e05874a447eec5d78252d Mon Sep 17 00:00:00 2001 From: puhui Date: Tue, 18 Jan 2022 20:47:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AE=A4=E8=AF=81=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: puhui --- .../native_cpp/src/device_manager_impl.cpp | 4 ++-- .../include/authentication/dm_auth_manager.h | 4 ++-- .../include/device_manager_service.h | 1 + .../src/authentication/dm_auth_manager.cpp | 16 +++------------- .../src/device_manager_service.cpp | 14 ++++++++++++-- .../src/devicestate/dm_device_state_manager.cpp | 2 +- 6 files changed, 21 insertions(+), 20 deletions(-) diff --git a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp index 417bd62c6..31107e981 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -258,7 +258,7 @@ int32_t DeviceManagerImpl::StartDeviceDiscovery(const std::string &pkgName, cons ret = rsp->GetErrCode(); if (ret != DM_OK) { LOGE("StartDeviceDiscovery error: Failed with ret %d", ret); - return DM_IPC_RESPOND_ERROR; + return ret; } LOGI("StartDeviceDiscovery completed, pkgName: %s", pkgName.c_str()); @@ -292,7 +292,7 @@ int32_t DeviceManagerImpl::StopDeviceDiscovery(const std::string &pkgName, uint1 ret = rsp->GetErrCode(); if (ret != DM_OK) { LOGE("StopDeviceDiscovery error: Failed with ret %d", ret); - return DM_IPC_RESPOND_ERROR; + return ret; } DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(pkgName, subscribeId); diff --git a/services/devicemanagerservice/include/authentication/dm_auth_manager.h b/services/devicemanagerservice/include/authentication/dm_auth_manager.h index b727f8f01..054ffe072 100644 --- a/services/devicemanagerservice/include/authentication/dm_auth_manager.h +++ b/services/devicemanagerservice/include/authentication/dm_auth_manager.h @@ -122,7 +122,8 @@ class DmAuthManager final : public ISoftbusSessionCallback, public std::enable_shared_from_this { public: DmAuthManager(std::shared_ptr softbusConnector, - std::shared_ptr listener); + std::shared_ptr listener, + std::shared_ptr hiChainConnector_); ~DmAuthManager(); int32_t AuthenticateDevice(const std::string &pkgName, int32_t authType, const std::string &deviceId, const std::string &extra); @@ -158,7 +159,6 @@ public: void ShowAuthInfoDialog(); void ShowStartAuthDialog(); int32_t GetAuthenticationParam(DmAuthParam &authParam); - int32_t RegisterCallback(); int32_t OnUserOperation(int32_t action); void UserSwitchEventCallback(void); diff --git a/services/devicemanagerservice/include/device_manager_service.h b/services/devicemanagerservice/include/device_manager_service.h index 8c54e9f3a..aedfc875d 100644 --- a/services/devicemanagerservice/include/device_manager_service.h +++ b/services/devicemanagerservice/include/device_manager_service.h @@ -59,6 +59,7 @@ private: std::shared_ptr softbusConnector_; std::shared_ptr listener_; std::shared_ptr abilityMgr_; + std::shared_ptr hiChainConnector_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp index 6b3fcae09..dbf9ae8ea 100644 --- a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp +++ b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp @@ -59,20 +59,17 @@ static void TimeOut(void *data) } DmAuthManager::DmAuthManager(std::shared_ptr softbusConnector, - std::shared_ptr listener) - : softbusConnector_(softbusConnector), listener_(listener) + std::shared_ptr listener, + std::shared_ptr hiChainConnector) + : softbusConnector_(softbusConnector), hiChainConnector_(hiChainConnector), listener_(listener) { LOGI("DmAuthManager constructor"); - hiChainConnector_ = std::make_shared(); - DmConfigManager &dmConfigManager = DmConfigManager::GetInstance(); dmConfigManager.GetAuthAdapter(authenticationMap_); } DmAuthManager::~DmAuthManager() { - softbusConnector_->GetSoftbusSession()->UnRegisterSessionCallback(); - hiChainConnector_->UnRegisterHiChainCallback(); LOGI("DmAuthManager destructor"); } @@ -697,13 +694,6 @@ int32_t DmAuthManager::GetAuthenticationParam(DmAuthParam &authParam) return DM_OK; } -int32_t DmAuthManager::RegisterCallback() -{ - softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(shared_from_this()); - hiChainConnector_->RegisterHiChainCallback(shared_from_this()); - return DM_OK; -} - int32_t DmAuthManager::OnUserOperation(int32_t action) { switch (action) { diff --git a/services/devicemanagerservice/src/device_manager_service.cpp b/services/devicemanagerservice/src/device_manager_service.cpp index 5faa4cca6..7c1fae22c 100644 --- a/services/devicemanagerservice/src/device_manager_service.cpp +++ b/services/devicemanagerservice/src/device_manager_service.cpp @@ -37,6 +37,8 @@ DeviceManagerService::~DeviceManagerService() if (dmCommonEventManager.UnsubscribeServiceEvent(CommonEventSupport::COMMON_EVENT_USER_STOPPED)) { LOGI("subscribe service event success"); } + softbusConnector_->GetSoftbusSession()->UnRegisterSessionCallback(); + hiChainConnector_->UnRegisterHiChainCallback(); } int32_t DeviceManagerService::Init() @@ -59,6 +61,13 @@ int32_t DeviceManagerService::Init() return DM_MAKE_SHARED_FAIL; } } + if (hiChainConnector_ == nullptr) { + hiChainConnector_ = std::make_shared(); + if (hiChainConnector_ == nullptr) { + LOGE("Init failed, hiChainConnector_ apply for failure"); + return DM_MAKE_SHARED_FAIL; + } + } if (deviceInfoMgr_ == nullptr) { deviceInfoMgr_ = std::make_shared(softbusConnector_); if (deviceInfoMgr_ == nullptr) { @@ -82,12 +91,13 @@ int32_t DeviceManagerService::Init() } } if (authMgr_ == nullptr) { - authMgr_ = std::make_shared(softbusConnector_, listener_); + authMgr_ = std::make_shared(softbusConnector_, listener_, hiChainConnector_); if (authMgr_ == nullptr) { LOGE("Init failed, authMgr_ apply for failure"); return DM_MAKE_SHARED_FAIL; } - authMgr_->RegisterCallback(); + softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(authMgr_); + hiChainConnector_->RegisterHiChainCallback(authMgr_); } DmCommonEventManager &dmCommonEventManager = DmCommonEventManager::GetInstance(); CommomEventCallback callback = std::bind(&DmAuthManager::UserSwitchEventCallback, *authMgr_.get()); diff --git a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp index fc63c20a3..5cf62a062 100644 --- a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp +++ b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp @@ -31,7 +31,7 @@ DmDeviceStateManager::DmDeviceStateManager(std::shared_ptr sof DmDeviceStateManager::~DmDeviceStateManager() { LOGI("DmDeviceStateManager destructor"); - softbusConnector_->UnRegisterSoftbusStateCallback(""); + softbusConnector_->UnRegisterSoftbusStateCallback("DM_PKG_NAME"); } void DmDeviceStateManager::OnDeviceOnline(const std::string &pkgName, const DmDeviceInfo &info) -- Gitee