From ca440dee928e5eb6de86a5cb1801ddf1de8088bd Mon Sep 17 00:00:00 2001 From: gaoqiang_strong Date: Sat, 7 Jun 2025 11:57:17 +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 | 4 +-- .../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 | 11 ++++++++ .../UTTest_device_manager_service.cpp | 9 +++++++ ...UTTest_device_manager_service_listener.cpp | 10 +++++++ test/unittest/UTTest_dm_pin_holder.h | 8 ++++++ test/unittest/mock/softbus_session_mock.cpp | 5 ---- test/unittest/mock/softbus_session_mock.h | 2 -- 16 files changed, 56 insertions(+), 43 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 0b9578252..b1685ebec 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; virtual void HandleScreenLockEvent(bool isLock) = 0; }; 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 4bef5ffdc..c3ef2d6b5 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 8eb9f4f7a..e4c3c183f 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -1563,8 +1563,8 @@ int DeviceManagerServiceImpl::OpenAuthSession(const std::string& deviceId, return ret; } LOGI("hmlActionId %{public}d, hmlEnable160M %{public}d", hmlActionId, hmlEnable160M); - return softbusConnector_->GetSoftbusSession()->OpenAuthSessionWithPara(deviceId, - hmlActionId, hmlEnable160M); + CHECK_NULL_RETURN(listener_, ERR_DM_FAILED); + return listener_->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 da3023d9a..d2bec5c49 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 2bcd88c8f..c32ff62d2 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -4169,6 +4169,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..d1d0a84b8 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,15 @@ std::string DeviceManagerServiceListener::GetLocalDisplayDeviceNameForPrivacy() return ""; #endif } + +int32_t DeviceManagerServiceListener::OpenAuthSessionWithPara(const std::string &deviceId, + int32_t actionId, bool isEnable160m) +{ +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + return DeviceManagerService::GetInstance().OpenAuthSessionWithPara(deviceId, actionId, isEnable160m); +#else + return DM_OK; +#endif +} } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_device_manager_service.cpp b/test/unittest/UTTest_device_manager_service.cpp index 94fe3e736..f69315e97 100644 --- a/test/unittest/UTTest_device_manager_service.cpp +++ b/test/unittest/UTTest_device_manager_service.cpp @@ -2493,6 +2493,15 @@ HWTEST_F(DeviceManagerServiceTest, GetEncryptedUuidByNetworkId_004, testing::ext EXPECT_EQ(ret, DM_OK); } +HWTEST_F(DeviceManagerServiceTest, OpenAuthSessionWithPara_001, testing::ext::TestSize.Level1) +{ + const std::string deviceId = "OpenAuthSessionWithPara"; + int32_t actionId = 0; + bool isEnable160m = false; + int32_t ret = DeviceManagerService::GetInstance().OpenAuthSessionWithPara(deviceId, actionId, isEnable160m); + EXPECT_NE(ret, DM_OK); +} + #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) HWTEST_F(DeviceManagerServiceTest, ConvertUdidHashToAnoyDeviceId_001, testing::ext::TestSize.Level1) { diff --git a/test/unittest/UTTest_device_manager_service_listener.cpp b/test/unittest/UTTest_device_manager_service_listener.cpp index a2bc5c562..4f654d2d4 100644 --- a/test/unittest/UTTest_device_manager_service_listener.cpp +++ b/test/unittest/UTTest_device_manager_service_listener.cpp @@ -1084,6 +1084,16 @@ HWTEST_F(DeviceManagerServiceListenerTest, SetDeviceInfo_001, testing::ext::Test listener_->SetDeviceInfo(pReq, processInfo, state, deviceInfo, deviceBasicInfo); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), false); } + +HWTEST_F(DeviceManagerServiceListenerTest, OpenAuthSessionWithPara_001, testing::ext::TestSize.Level1) +{ + const std::string deviceId = "OpenAuthSessionWithPara"; + int32_t actionId = 0; + bool isEnable160m = false; + std::shared_ptr listener_ = std::make_shared(); + int32_t ret = listener_->OpenAuthSessionWithPara(deviceId, actionId, isEnable160m); + EXPECT_NE(ret, DM_OK); +} } // namespace } // 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