From afcd711635644521ee07e63ff04f653bc7d60a46 Mon Sep 17 00:00:00 2001 From: gaoqiang_strong Date: Mon, 26 May 2025 19:09:05 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8D=E6=80=BB=E7=BA=BF=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gaoqiang_strong --- .../include/i_dm_service_impl_ext.h | 1 + .../include/i_dm_service_impl_ext_resident.h | 1 + .../idevice_manager_service_listener.h | 1 + .../dependency/softbus/softbus_session.h | 7 ----- .../src/authentication/dm_auth_manager.cpp | 3 ++- .../dependency/softbus/softbus_session.cpp | 26 ------------------- .../src/device_manager_service_impl.cpp | 3 ++- .../service/include/device_manager_service.h | 1 + .../include/device_manager_service_listener.h | 1 + .../service/src/device_manager_service.cpp | 9 +++++++ .../src/device_manager_service_listener.cpp | 7 +++++ test/unittest/UTTest_dm_pin_holder.h | 8 ++++++ test/unittest/mock/softbus_session_mock.cpp | 5 ---- test/unittest/mock/softbus_session_mock.h | 2 -- 14 files changed, 33 insertions(+), 42 deletions(-) diff --git a/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext.h b/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext.h index b93d073e4..cb4bb85bc 100644 --- a/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext.h +++ b/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext.h @@ -106,6 +106,7 @@ public: virtual void OnSessionOpened(int32_t sessionId, int32_t sessionSide, int32_t result) = 0; virtual void OnSessionClosed(const int32_t sessionId) = 0; virtual void OnBytesReceived(const int32_t sessionId, const std::string message) = 0; + virtual int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) = 0; }; using CreateDMServiceImplExtFuncPtr = IDMServiceImplExt *(*)(void); diff --git a/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext_resident.h b/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext_resident.h index cfe782f52..06224da01 100644 --- a/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext_resident.h +++ b/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext_resident.h @@ -110,6 +110,7 @@ public: std::vector &dmDeviceProfileInfos) = 0; virtual int32_t RestoreLocalDeviceName() = 0; virtual void ClearCacheWhenLogout(int32_t userId, const std::string &oldAccountId) = 0; + virtual int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) = 0; }; using CreateDMServiceExtResidentFuncPtr = IDMServiceImplExtResident *(*)(void); diff --git a/interfaces/inner_kits/native_cpp/include/idevice_manager_service_listener.h b/interfaces/inner_kits/native_cpp/include/idevice_manager_service_listener.h index 5fc5b0a45..e85db7292 100644 --- a/interfaces/inner_kits/native_cpp/include/idevice_manager_service_listener.h +++ b/interfaces/inner_kits/native_cpp/include/idevice_manager_service_listener.h @@ -178,6 +178,7 @@ public: * @return std::string the name without privacy info */ virtual std::string GetLocalDisplayDeviceNameForPrivacy() = 0; + virtual int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/implementation/include/dependency/softbus/softbus_session.h b/services/implementation/include/dependency/softbus/softbus_session.h index b3dfc2840..aaa548f36 100644 --- a/services/implementation/include/dependency/softbus/softbus_session.h +++ b/services/implementation/include/dependency/softbus/softbus_session.h @@ -59,13 +59,6 @@ public: */ int32_t OpenAuthSession(const std::string &deviceId); - /** - * @tc.name: SoftbusSession::OpenAuthSessionWithPara - * @tc.desc: Open HML AuthSession of the Softbus Session - * @tc.type: FUNC - */ - int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m); - /** * @tc.name: SoftbusSession::CloseAuthSession * @tc.desc: Close AuthSession of the Softbus Session diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 5e3b692e1..9a113786c 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -867,10 +867,11 @@ int32_t DmAuthManager::EstablishAuthChannel(const std::string &deviceId) int32_t sessionId = 0; if (IsHmlSessionType()) { CHECK_NULL_RETURN(authRequestContext_, ERR_DM_FAILED); + CHECK_NULL_RETURN(listener_, ERR_DM_FAILED); LOGI("hmlActionId %{public}d, hmlReleaseTime %{public}d, hmlEnable160M %{public}d", authRequestContext_->hmlActionId, authRequestContext_->closeSessionDelaySeconds, authRequestContext_->hmlEnable160M); - sessionId = softbusConnector_->GetSoftbusSession()->OpenAuthSessionWithPara(deviceId, + sessionId = listener_->OpenAuthSessionWithPara(deviceId, authRequestContext_->hmlActionId, authRequestContext_->hmlEnable160M); } else { sessionId = softbusConnector_->GetSoftbusSession()->OpenAuthSession(deviceId); diff --git a/services/implementation/src/dependency/softbus/softbus_session.cpp b/services/implementation/src/dependency/softbus/softbus_session.cpp index 056eb4044..1563f8b86 100644 --- a/services/implementation/src/dependency/softbus/softbus_session.cpp +++ b/services/implementation/src/dependency/softbus/softbus_session.cpp @@ -23,9 +23,6 @@ #include "json_object.h" #include "softbus_connector.h" #include "softbus_error_code.h" -#ifndef DEVICE_MANAGER_COMMON_FLAG -#include "session_ex.h" -#endif namespace OHOS { namespace DistributedHardware { @@ -75,29 +72,6 @@ int32_t SoftbusSession::OpenAuthSession(const std::string &deviceId) return sessionId; } -int32_t SoftbusSession::OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) -{ -#ifdef DEVICE_MANAGER_COMMON_FLAG - LOGE("[SOFTBUS] OpenAuthSessionWithPara no implement"); - return SOFTBUS_NOT_IMPLEMENT; -#else - DmTraceStart(std::string(DM_HITRACE_AUTH_TO_OPPEN_SESSION)); - LinkPara para; - para.type = PARA_ACTION; - para.action.actionId = static_cast(actionId); - para.enable160M = isEnable160m; - para.accountInfo = false; - int32_t sessionId = ::OpenAuthSessionWithPara(DM_SESSION_NAME, ¶); - if (sessionId < 0) { - LOGE("[SOFTBUS]open session error, sessionId: %{public}d.", sessionId); - return sessionId; - } - DmTraceEnd(); - LOGI("OpenAuthSessionWithPara success. sessionId: %{public}d.", sessionId); - return sessionId; -#endif -} - int32_t SoftbusSession::CloseAuthSession(int32_t sessionId) { LOGI("CloseAuthSession."); diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 314cdf47b..d06579822 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -1469,7 +1469,8 @@ int DeviceManagerServiceImpl::OpenAuthSession(const std::string& deviceId, return ret; } LOGI("hmlActionId %{public}d, hmlEnable160M %{public}d", hmlActionId, hmlEnable160M); - return softbusConnector_->GetSoftbusSession()->OpenAuthSessionWithPara(deviceId, + CHECK_NULL_RETURN(listener_, ERR_DM_FAILED); + return listener_->GetSoftbusSession()->OpenAuthSessionWithPara(deviceId, hmlActionId, hmlEnable160M); } else { return softbusConnector_->GetSoftbusSession()->OpenAuthSession(deviceId); diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index bd88a76f2..89ceb226b 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -253,6 +253,7 @@ public: 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); + int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m); int32_t UnRegisterPinHolderCallback(const std::string &pkgName); void ProcessReceiveRspAppUninstall(const std::string &remoteUdid); void ProcessReceiveRspAppUnbind(const std::string &remoteUdid); diff --git a/services/service/include/device_manager_service_listener.h b/services/service/include/device_manager_service_listener.h index f4780273b..fbf03d22a 100644 --- a/services/service/include/device_manager_service_listener.h +++ b/services/service/include/device_manager_service_listener.h @@ -91,6 +91,7 @@ public: const std::string &deviceName, int32_t code) override; std::string GetLocalDisplayDeviceNameForPrivacy() override; + int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) override; private: void ConvertDeviceInfoToDeviceBasicInfo(const std::string &pkgName, diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 9daf9e13f..802f57940 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -4149,6 +4149,15 @@ void DeviceManagerService::ProcessSyncAccountLogout(const std::string &accountId dmServiceImpl_->HandleAccountLogoutEvent(userId, accountId, peerUdid); } +int32_t DeviceManagerService::OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) +{ + if (!IsDMServiceAdapterResidentLoad()) { + LOGE("failed, adapter instance not init or init failed."); + return ERR_DM_UNSUPPORTED_METHOD; + } + return dmServiceImplExtResident_->OpenAuthSessionWithPara(deviceId, actionId, isEnable160m); +} + int32_t DeviceManagerService::UnRegisterPinHolderCallback(const std::string &pkgName) { if (!PermissionManager::GetInstance().CheckPermission()) { diff --git a/services/service/src/device_manager_service_listener.cpp b/services/service/src/device_manager_service_listener.cpp index 2fa0fe73b..65593a53e 100644 --- a/services/service/src/device_manager_service_listener.cpp +++ b/services/service/src/device_manager_service_listener.cpp @@ -45,6 +45,7 @@ #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) #include "datetime_ex.h" #include "device_name_manager.h" +#include "device_manager_service.h" #include "kv_adapter_manager.h" #include "multiple_user_connector.h" #endif @@ -1018,5 +1019,11 @@ std::string DeviceManagerServiceListener::GetLocalDisplayDeviceNameForPrivacy() return ""; #endif } + +int32_t DeviceManagerServiceListener::OpenAuthSessionWithPara(const std::string &deviceId, + int32_t actionId, bool isEnable160m) +{ + return DeviceManagerService::GetInstance().OpenAuthSessionWithPara(deviceId, actionId, isEnable160m); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_dm_pin_holder.h b/test/unittest/UTTest_dm_pin_holder.h index 3b3746bab..0c1106b04 100644 --- a/test/unittest/UTTest_dm_pin_holder.h +++ b/test/unittest/UTTest_dm_pin_holder.h @@ -260,6 +260,14 @@ public: { return ""; } + + virtual int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) + { + (void)deviceId; + (void)actionId; + (void)isEnable160m; + return 0; + } }; } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/mock/softbus_session_mock.cpp b/test/unittest/mock/softbus_session_mock.cpp index c85d7045d..331e0e2cb 100644 --- a/test/unittest/mock/softbus_session_mock.cpp +++ b/test/unittest/mock/softbus_session_mock.cpp @@ -30,11 +30,6 @@ int32_t SoftbusSession::SendData(int32_t sessionId, std::string &message) return DmSoftbusSession::dmSoftbusSession->SendData(sessionId, message); } -int32_t SoftbusSession::OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) -{ - return DmSoftbusSession::dmSoftbusSession->OpenAuthSessionWithPara(deviceId, actionId, isEnable160m); -} - int32_t SoftbusSession::OpenAuthSession(const std::string &deviceId) { return DmSoftbusSession::dmSoftbusSession->OpenAuthSession(deviceId); diff --git a/test/unittest/mock/softbus_session_mock.h b/test/unittest/mock/softbus_session_mock.h index 9f386d183..bdb1ad0f5 100644 --- a/test/unittest/mock/softbus_session_mock.h +++ b/test/unittest/mock/softbus_session_mock.h @@ -28,7 +28,6 @@ public: public: virtual int32_t GetPeerDeviceId(int32_t sessionId, std::string &peerDevId) = 0; virtual int32_t SendData(int32_t sessionId, std::string &message) = 0; - virtual int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) = 0; virtual int32_t OpenAuthSession(const std::string &deviceId) = 0; public: @@ -39,7 +38,6 @@ class SoftbusSessionMock : public DmSoftbusSession { public: MOCK_METHOD(int32_t, GetPeerDeviceId, (int32_t, std::string &)); MOCK_METHOD(int32_t, SendData, (int32_t, std::string &)); - MOCK_METHOD(int32_t, OpenAuthSessionWithPara, (const std::string &, int32_t, bool)); MOCK_METHOD(int32_t, OpenAuthSession, (const std::string &)); }; } -- Gitee