diff --git a/common/include/dinput_errcode.h b/common/include/dinput_errcode.h index 8cfa95cb87153174debac12608b5f812ecddc5f7..a950bf09029b51a49a2d67c2fa62038d79d31ec9 100644 --- a/common/include/dinput_errcode.h +++ b/common/include/dinput_errcode.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -176,6 +176,9 @@ namespace DistributedInput { constexpr int32_t ERR_DH_INPUT_SRC_ENABLE_PERMISSION_CHECK_FAIL = -67061; constexpr int32_t ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL = -67062; constexpr int32_t ERR_DH_INPUT_SINK_ENABLE_PERMISSION_CHECK_FAIL = -67063; + constexpr int32_t ERR_DH_INPUT_SINK_PROXY_DH_LISTENER_IS_NULL = -67064; + constexpr int32_t ERR_DH_INPUT_SRC_PROXY_CALLBACK_IS_NULL = -67065; + constexpr int32_t ERR_DH_INPUT_SRC_PROXY_EVENT_LISTENER_IS_NULL = -67066; // Hidump Helper error code constexpr int32_t ERR_DH_INPUT_HIDUMP_INVALID_ARGS = -68000; diff --git a/inputdevicehandler/include/distributed_input_handler.h b/inputdevicehandler/include/distributed_input_handler.h index 3ec7e17b9b0ff491d33232570874b7b4acf93574..5914ceb52f472ee692530f0e6c16d685025fb7e2 100644 --- a/inputdevicehandler/include/distributed_input_handler.h +++ b/inputdevicehandler/include/distributed_input_handler.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -20,7 +20,6 @@ #include #include #include - #include #include @@ -54,20 +53,20 @@ private: DistributedInputHandler(); ~DistributedInputHandler(); void StructTransJson(const InputDevice &pBuf, std::string &strDescriptor); - std::shared_ptr m_listener; + std::shared_ptr listener_; bool InitCollectEventsThread(); void NotifyHardWare(int iCnt); pthread_t collectThreadID_; bool isCollectingEvents_; - bool isStartCollectEventThread; + bool isStartCollectEventThread_; static void *CollectEventsThread(void *param); void StartInputMonitorDeviceThread(); void StopInputMonitorDeviceThread(); // The event queue. - static const int inputDeviceBufferSize = 32; - InputDeviceEvent mEventBuffer[inputDeviceBufferSize] = {}; + static const int inputDeviceBufferSize_ = 32; + InputDeviceEvent eventBuffer_[inputDeviceBufferSize_] = {}; std::mutex operationMutex_; std::unique_ptr inputHub_; }; diff --git a/inputdevicehandler/src/distributed_input_handler.cpp b/inputdevicehandler/src/distributed_input_handler.cpp index 3beb13768a2b0a400664792b8aad0897a60bdd06..ec9536d1c665567123782d254d00873c657e7ed8 100644 --- a/inputdevicehandler/src/distributed_input_handler.cpp +++ b/inputdevicehandler/src/distributed_input_handler.cpp @@ -42,10 +42,10 @@ namespace DistributedHardware { namespace DistributedInput { IMPLEMENT_SINGLE_INSTANCE(DistributedInputHandler); DistributedInputHandler::DistributedInputHandler() - : collectThreadID_(-1), isCollectingEvents_(false), isStartCollectEventThread(false) + : collectThreadID_(-1), isCollectingEvents_(false), isStartCollectEventThread_(false) { inputHub_ = std::make_unique(true); - this->m_listener = nullptr; + this->listener_ = nullptr; } DistributedInputHandler::~DistributedInputHandler() @@ -88,9 +88,9 @@ void DistributedInputHandler::StructTransJson(const InputDevice &pBuf, std::stri int32_t DistributedInputHandler::Initialize() { - if (!isStartCollectEventThread) { + if (!isStartCollectEventThread_) { InitCollectEventsThread(); - isStartCollectEventThread = true; + isStartCollectEventThread_ = true; } return DH_SUCCESS; } @@ -146,12 +146,12 @@ bool DistributedInputHandler::IsSupportPlugin() void DistributedInputHandler::RegisterPluginListener(std::shared_ptr listener) { - this->m_listener = listener; + this->listener_ = listener; } void DistributedInputHandler::UnRegisterPluginListener() { - this->m_listener = nullptr; + this->listener_ = nullptr; } bool DistributedInputHandler::InitCollectEventsThread() @@ -180,6 +180,10 @@ void *DistributedInputHandler::CollectEventsThread(void *param) DHLOGE("CollectEventsThread setname failed."); } DistributedInputHandler *pThis = reinterpret_cast(param); + if (pThis == nullptr) { + DHLOGE("pThis is null."); + return nullptr; + } pThis->StartInputMonitorDeviceThread(); DHLOGI("DistributedInputHandler::CollectEventsThread exist!"); return nullptr; @@ -192,7 +196,7 @@ void DistributedInputHandler::StartInputMonitorDeviceThread() return; } while (isCollectingEvents_) { - size_t count = inputHub_->StartCollectInputHandler(mEventBuffer, inputDeviceBufferSize); + size_t count = inputHub_->StartCollectInputHandler(eventBuffer_, inputDeviceBufferSize_); if (count > 0) { DHLOGI("Count: %{public}zu", count); for (size_t iCnt = 0; iCnt < count; iCnt++) { @@ -208,18 +212,18 @@ void DistributedInputHandler::StartInputMonitorDeviceThread() void DistributedInputHandler::NotifyHardWare(int iCnt) { - switch (mEventBuffer[iCnt].type) { + switch (eventBuffer_[iCnt].type) { case DeviceType::DEVICE_ADDED: - if (this->m_listener != nullptr) { + if (this->listener_ != nullptr) { std::string hdInfo; - StructTransJson(mEventBuffer[iCnt].deviceInfo, hdInfo); + StructTransJson(eventBuffer_[iCnt].deviceInfo, hdInfo); std::string subtype = "input"; - this->m_listener->PluginHardware(mEventBuffer[iCnt].deviceInfo.descriptor, hdInfo, subtype); + this->listener_->PluginHardware(eventBuffer_[iCnt].deviceInfo.descriptor, hdInfo, subtype); } break; case DeviceType::DEVICE_REMOVED: - if (this->m_listener != nullptr) { - this->m_listener->UnPluginHardware(mEventBuffer[iCnt].deviceInfo.descriptor); + if (this->listener_ != nullptr) { + this->listener_->UnPluginHardware(eventBuffer_[iCnt].deviceInfo.descriptor); } break; default: @@ -230,14 +234,16 @@ void DistributedInputHandler::NotifyHardWare(int iCnt) void DistributedInputHandler::StopInputMonitorDeviceThread() { isCollectingEvents_ = false; - isStartCollectEventThread = false; - inputHub_->StopCollectInputHandler(); - if (collectThreadID_ != (pthread_t)(-1)) { - DHLOGI("DistributedInputHandler::Wait collect thread exit"); - pthread_join(collectThreadID_, NULL); - collectThreadID_ = (pthread_t)(-1); + isStartCollectEventThread_ = false; + if (inputHub_ != nullptr) { + inputHub_->StopCollectInputHandler(); + if (collectThreadID_ != (pthread_t)(-1)) { + DHLOGI("DistributedInputHandler::Wait collect thread exit"); + pthread_join(collectThreadID_, NULL); + collectThreadID_ = (pthread_t)(-1); + } + DHLOGI("DistributedInputHandler::StopInputMonitorDeviceThread exit!"); } - DHLOGI("DistributedInputHandler::StopInputMonitorDeviceThread exit!"); } IHardwareHandler* GetHardwareHandler() diff --git a/inputdevicehandler/test/inputhandlertest/distributed_input_handler_test.cpp b/inputdevicehandler/test/inputhandlertest/distributed_input_handler_test.cpp index 47765dc141da3858fe673b52bf711a502c13bd22..21eaa07981bd6c8fe0d41a13a402047d1fede0ea 100644 --- a/inputdevicehandler/test/inputhandlertest/distributed_input_handler_test.cpp +++ b/inputdevicehandler/test/inputhandlertest/distributed_input_handler_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -64,14 +64,14 @@ HWTEST_F(DInputHandlerTest, FindDevicesInfoByType_001, testing::ext::TestSize.Le dInputHandler.StartInputMonitorDeviceThread(); InputDevice inputDevice; - dInputHandler.mEventBuffer[0].type = DeviceType::DEVICE_ADDED; - dInputHandler.mEventBuffer[0].deviceInfo = inputDevice; + dInputHandler.eventBuffer_[0].type = DeviceType::DEVICE_ADDED; + dInputHandler.eventBuffer_[0].deviceInfo = inputDevice; dInputHandler.NotifyHardWare(0); - dInputHandler.mEventBuffer[1].type = DeviceType::DEVICE_REMOVED; - dInputHandler.mEventBuffer[1].deviceInfo = inputDevice; + dInputHandler.eventBuffer_[1].type = DeviceType::DEVICE_REMOVED; + dInputHandler.eventBuffer_[1].deviceInfo = inputDevice; dInputHandler.NotifyHardWare(1); - dInputHandler.mEventBuffer[2].type = DeviceType::FINISHED_DEVICE_SCAN; - dInputHandler.mEventBuffer[2].deviceInfo = inputDevice; + dInputHandler.eventBuffer_[2].type = DeviceType::FINISHED_DEVICE_SCAN; + dInputHandler.eventBuffer_[2].deviceInfo = inputDevice; dInputHandler.NotifyHardWare(2); std::map ret = dInputHandler.QueryExtraInfo(); EXPECT_EQ(0, ret.size()); diff --git a/interfaces/inner_kits/test/unittest/mock/mock_distributed_input_client.cpp b/interfaces/inner_kits/test/unittest/mock/mock_distributed_input_client.cpp index a466428ec33d46d47b81ce525d56373ac8da76f3..6f08b93883193bbeaa8215a2d5ec4340feb4a007 100644 --- a/interfaces/inner_kits/test/unittest/mock/mock_distributed_input_client.cpp +++ b/interfaces/inner_kits/test/unittest/mock/mock_distributed_input_client.cpp @@ -38,11 +38,11 @@ DistributedInputClient &DistributedInputClient::GetInstance() void DistributedInputClient::RegisterDInputCb::OnResult( const std::string &devId, const std::string &dhId, const int32_t &status) { - auto iter = DistributedInputClient::GetInstance().dHardWareFwkRstInfos.begin(); - for (; iter != DistributedInputClient::GetInstance().dHardWareFwkRstInfos.end(); ++iter) { + auto iter = DistributedInputClient::GetInstance().dHardWareFwkRstInfos_.begin(); + for (; iter != DistributedInputClient::GetInstance().dHardWareFwkRstInfos_.end(); ++iter) { if (iter->devId == devId && iter->dhId == dhId) { iter->callback->OnRegisterResult(devId, dhId, status, ""); - DistributedInputClient::GetInstance().dHardWareFwkRstInfos.erase(iter); + DistributedInputClient::GetInstance().dHardWareFwkRstInfos_.erase(iter); return; } } @@ -51,11 +51,11 @@ void DistributedInputClient::RegisterDInputCb::OnResult( void DistributedInputClient::UnregisterDInputCb::OnResult( const std::string &devId, const std::string &dhId, const int32_t &status) { - auto iter = DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos.begin(); - for (; iter != DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos.end(); ++iter) { + auto iter = DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos_.begin(); + for (; iter != DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos_.end(); ++iter) { if (iter->devId == devId && iter->dhId == dhId) { iter->callback->OnUnregisterResult(devId, dhId, status, ""); - DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos.erase(iter); + DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos_.erase(iter); return; } } diff --git a/interfaces/ipc/include/dinput_sa_manager.h b/interfaces/ipc/include/dinput_sa_manager.h index 6792393451a12a637d97543cccb58d100791c660..977421a6e32e69ee104d650f2e1d6fbb3b6d8399 100644 --- a/interfaces/ipc/include/dinput_sa_manager.h +++ b/interfaces/ipc/include/dinput_sa_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -71,17 +71,17 @@ private: ~DInputSAManager() = default; public: - std::atomic dInputSourceSAOnline = false; - std::atomic dInputSinkSAOnline = false; - std::atomic isSubscribeSrcSAChangeListener = false; - std::atomic isSubscribeSinkSAChangeListener = false; + std::atomic dInputSourceSAOnline_ = false; + std::atomic dInputSinkSAOnline_ = false; + std::atomic isSubscribeSrcSAChangeListener_ = false; + std::atomic isSubscribeSinkSAChangeListener_ = false; std::mutex sinkMutex_; std::mutex sourceMutex_; std::mutex handlerMutex_; sptr dInputSourceProxy_ = nullptr; sptr dInputSinkProxy_ = nullptr; - sptr saListenerCallback = nullptr; + sptr saListenerCallback_ = nullptr; std::shared_ptr eventHandler_; }; diff --git a/interfaces/ipc/include/distributed_input_client.h b/interfaces/ipc/include/distributed_input_client.h index 6fe7865e44e89485f7f52eb69e6f6202a31dcf63..92360b7f70d49e25c0152eb3d499dfdcb0451c49 100644 --- a/interfaces/ipc/include/distributed_input_client.h +++ b/interfaces/ipc/include/distributed_input_client.h @@ -26,18 +26,17 @@ #include "add_white_list_infos_call_back_stub.h" #include "del_white_list_infos_call_back_stub.h" +#include "dinput_sa_manager.h" #include "get_sink_screen_infos_call_back_stub.h" #include "i_distributed_source_input.h" #include "i_distributed_sink_input.h" #include "i_sharing_dhid_listener.h" +#include "idistributed_hardware_source.h" +#include "idistributed_hardware_sink.h" #include "register_d_input_call_back_stub.h" -#include "unregister_d_input_call_back_stub.h" #include "sharing_dhid_listener_stub.h" #include "start_stop_d_inputs_call_back_stub.h" - -#include "dinput_sa_manager.h" -#include "idistributed_hardware_source.h" -#include "idistributed_hardware_sink.h" +#include "unregister_d_input_call_back_stub.h" namespace OHOS { namespace DistributedHardware { @@ -179,7 +178,7 @@ private: private: static std::shared_ptr instance; - DInputServerType serverType = DInputServerType::NULL_SERVER_TYPE; + DInputServerType serverType_ = DInputServerType::NULL_SERVER_TYPE; DInputDeviceType inputTypes_ = DInputDeviceType::NONE; std::set> addWhiteListCallbacks_; @@ -193,12 +192,12 @@ private: std::shared_ptr eventHandler_; - std::atomic isAddWhiteListCbReg; - std::atomic isDelWhiteListCbReg; - std::atomic isNodeMonitorCbReg; - std::atomic isSimulationEventCbReg; - std::atomic isSharingDhIdsReg; - std::atomic isGetSinkScreenInfosCbReg; + std::atomic isAddWhiteListCbReg_; + std::atomic isDelWhiteListCbReg_; + std::atomic isNodeMonitorCbReg_; + std::atomic isSimulationEventCbReg_; + std::atomic isSharingDhIdsReg_; + std::atomic isGetSinkScreenInfosCbReg_; struct DHardWareFwkRegistInfo { std::string devId; @@ -212,9 +211,9 @@ private: std::shared_ptr callback = nullptr; }; - std::vector dHardWareFwkRstInfos; - std::vector dHardWareFwkUnRstInfos; - std::vector screenTransInfos; + std::vector dHardWareFwkRstInfos_; + std::vector dHardWareFwkUnRstInfos_; + std::vector screenTransInfos_; std::mutex operationMutex_; std::mutex sharingDhIdsMtx_; diff --git a/interfaces/ipc/src/dinput_sa_manager.cpp b/interfaces/ipc/src/dinput_sa_manager.cpp index 9f03e486f51a3b73144a30f42576e22255f101f1..95c093622d42375844e40da4a14b06ac6421fc3a 100644 --- a/interfaces/ipc/src/dinput_sa_manager.cpp +++ b/interfaces/ipc/src/dinput_sa_manager.cpp @@ -30,7 +30,7 @@ const uint32_t DINPUT_CLIENT_HANDLER_MSG_DELAY_TIME = 100; // million seconds void DInputSAManager::SystemAbilityListener::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) { if (systemAbilityId == DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID) { - DInputSAManager::GetInstance().dInputSourceSAOnline.store(false); + DInputSAManager::GetInstance().dInputSourceSAOnline_.store(false); { std::lock_guard lock(DInputSAManager::GetInstance().sourceMutex_); DInputSAManager::GetInstance().dInputSourceProxy_ = nullptr; @@ -48,7 +48,7 @@ void DInputSAManager::SystemAbilityListener::OnRemoveSystemAbility(int32_t syste } if (systemAbilityId == DISTRIBUTED_HARDWARE_INPUT_SINK_SA_ID) { - DInputSAManager::GetInstance().dInputSinkSAOnline.store(false); + DInputSAManager::GetInstance().dInputSinkSAOnline_.store(false); { std::lock_guard lock(DInputSAManager::GetInstance().sinkMutex_); DInputSAManager::GetInstance().dInputSinkProxy_ = nullptr; @@ -70,7 +70,7 @@ void DInputSAManager::SystemAbilityListener::OnRemoveSystemAbility(int32_t syste void DInputSAManager::SystemAbilityListener::OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) { if (systemAbilityId == DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID) { - DInputSAManager::GetInstance().dInputSourceSAOnline.store(true); + DInputSAManager::GetInstance().dInputSourceSAOnline_.store(true); std::lock_guard lock(DInputSAManager::GetInstance().handlerMutex_); if (DInputSAManager::GetInstance().eventHandler_ != nullptr) { DHLOGI("SendEvent DINPUT_CLIENT_CHECK_SOURCE_CALLBACK_REGISTER_MSG"); @@ -82,7 +82,7 @@ void DInputSAManager::SystemAbilityListener::OnAddSystemAbility(int32_t systemAb } if (systemAbilityId == DISTRIBUTED_HARDWARE_INPUT_SINK_SA_ID) { - DInputSAManager::GetInstance().dInputSinkSAOnline.store(true); + DInputSAManager::GetInstance().dInputSinkSAOnline_.store(true); std::lock_guard lock(DInputSAManager::GetInstance().handlerMutex_); if (DInputSAManager::GetInstance().eventHandler_ != nullptr) { DHLOGI("SendEvent DINPUT_CLIENT_CHECK_SINK_CALLBACK_REGISTER_MSG"); @@ -97,7 +97,7 @@ void DInputSAManager::SystemAbilityListener::OnAddSystemAbility(int32_t systemAb void DInputSAManager::Init() { - saListenerCallback = new(std::nothrow) SystemAbilityListener(); + saListenerCallback_ = new(std::nothrow) SystemAbilityListener(); sptr systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); @@ -106,26 +106,26 @@ void DInputSAManager::Init() return; } - if (!isSubscribeSrcSAChangeListener.load()) { + if (!isSubscribeSrcSAChangeListener_.load()) { DHLOGI("try subscribe source sa change listener, saId:%{public}d", DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID); int32_t ret = systemAbilityManager->SubscribeSystemAbility(DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID, - saListenerCallback); + saListenerCallback_); if (ret != DH_SUCCESS) { DHLOGE("subscribe source sa change failed: %{public}d", ret); return; } - isSubscribeSrcSAChangeListener.store(true); + isSubscribeSrcSAChangeListener_.store(true); } - if (!isSubscribeSinkSAChangeListener.load()) { + if (!isSubscribeSinkSAChangeListener_.load()) { DHLOGI("try subscribe sink sa change listener, saId:%{public}d", DISTRIBUTED_HARDWARE_INPUT_SINK_SA_ID); int32_t ret = systemAbilityManager->SubscribeSystemAbility(DISTRIBUTED_HARDWARE_INPUT_SINK_SA_ID, - saListenerCallback); + saListenerCallback_); if (ret != DH_SUCCESS) { DHLOGE("subscribe sink sa change failed: %{public}d", ret); return; } - isSubscribeSinkSAChangeListener.store(true); + isSubscribeSinkSAChangeListener_.store(true); } } @@ -137,9 +137,9 @@ void DInputSAManager::RegisterEventHandler(std::shared_ptr lock(DInputSAManager::GetInstance().sourceMutex_); - if (!isSubscribeSrcSAChangeListener.load()) { + if (!isSubscribeSrcSAChangeListener_.load()) { sptr systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (!systemAbilityManager) { @@ -149,16 +149,16 @@ bool DInputSAManager::GetDInputSourceProxy() DHLOGI("try subscribe source sa change listener, saId:%{public}d", DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID); int32_t ret = systemAbilityManager->SubscribeSystemAbility(DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID, - saListenerCallback); + saListenerCallback_); if (ret != DH_SUCCESS) { DHLOGE("subscribe source sa change failed: %{public}d", ret); return false; } - isSubscribeSrcSAChangeListener.store(true); + isSubscribeSrcSAChangeListener_.store(true); } } - if (dInputSourceSAOnline.load() && !dInputSourceProxy_) { + if (dInputSourceSAOnline_.load() && !dInputSourceProxy_) { std::lock_guard lock(DInputSAManager::GetInstance().sourceMutex_); if (dInputSourceProxy_ != nullptr) { DHLOGI("dinput source proxy has already got."); @@ -208,9 +208,9 @@ bool DInputSAManager::SetDInputSourceProxy(const sptr &remoteObje bool DInputSAManager::GetDInputSinkProxy() { - if (!isSubscribeSinkSAChangeListener.load()) { + if (!isSubscribeSinkSAChangeListener_.load()) { std::lock_guard lock(DInputSAManager::GetInstance().sinkMutex_); - if (!isSubscribeSinkSAChangeListener.load()) { + if (!isSubscribeSinkSAChangeListener_.load()) { sptr systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (!systemAbilityManager) { @@ -220,16 +220,16 @@ bool DInputSAManager::GetDInputSinkProxy() DHLOGI("try subscribe sink sa change listener, sa id: %{public}d", DISTRIBUTED_HARDWARE_INPUT_SINK_SA_ID); int32_t ret = systemAbilityManager->SubscribeSystemAbility(DISTRIBUTED_HARDWARE_INPUT_SINK_SA_ID, - saListenerCallback); + saListenerCallback_); if (ret != DH_SUCCESS) { DHLOGE("subscribe sink sa change failed: %{public}d", ret); return false; } - isSubscribeSinkSAChangeListener.store(true); + isSubscribeSinkSAChangeListener_.store(true); } } - if (dInputSinkSAOnline.load() && !dInputSinkProxy_) { + if (dInputSinkSAOnline_.load() && !dInputSinkProxy_) { std::lock_guard lock(DInputSAManager::GetInstance().sinkMutex_); if (dInputSinkProxy_ != nullptr) { DHLOGI("dinput sink proxy has already got."); diff --git a/interfaces/ipc/src/distributed_input_client.cpp b/interfaces/ipc/src/distributed_input_client.cpp index 280a68c6475cf52d14bd4284681702cacf0e87db..750c0d9939f43d4bc64791aa77c16cdfa00fa506 100644 --- a/interfaces/ipc/src/distributed_input_client.cpp +++ b/interfaces/ipc/src/distributed_input_client.cpp @@ -34,8 +34,9 @@ namespace OHOS { namespace DistributedHardware { namespace DistributedInput { std::shared_ptr DistributedInputClient::instance = std::make_shared(); -DistributedInputClient::DistributedInputClient() : isAddWhiteListCbReg(false), isDelWhiteListCbReg(false), - isNodeMonitorCbReg(false), isSimulationEventCbReg(false), isSharingDhIdsReg(false), isGetSinkScreenInfosCbReg(false) +DistributedInputClient::DistributedInputClient() : isAddWhiteListCbReg_(false), isDelWhiteListCbReg_(false), + isNodeMonitorCbReg_(false), isSimulationEventCbReg_(false), isSharingDhIdsReg_(false), + isGetSinkScreenInfosCbReg_(false) { DHLOGI("DistributedInputClient init start"); std::shared_ptr runner = AppExecFwk::EventRunner::Create(true); @@ -54,14 +55,15 @@ void DistributedInputClient::RegisterDInputCb::OnResult( const std::string &devId, const std::string &dhId, const int32_t &status) { std::lock_guard lock(DistributedInputClient::GetInstance().operationMutex_); - for (std::vector::iterator iter = - DistributedInputClient::GetInstance().dHardWareFwkRstInfos.begin(); - iter != DistributedInputClient::GetInstance().dHardWareFwkRstInfos.end(); + for (auto iter = DistributedInputClient::GetInstance().dHardWareFwkRstInfos_.begin(); + iter != DistributedInputClient::GetInstance().dHardWareFwkRstInfos_.end(); ++iter) { if (iter->devId == devId && iter->dhId == dhId) { - iter->callback->OnRegisterResult(devId, dhId, status, ""); - DistributedInputClient::GetInstance().dHardWareFwkRstInfos.erase(iter); - return; + if (iter->callback != nullptr) { + iter->callback->OnRegisterResult(devId, dhId, status, ""); + DistributedInputClient::GetInstance().dHardWareFwkRstInfos_.erase(iter); + return; + } } } } @@ -70,14 +72,15 @@ void DistributedInputClient::UnregisterDInputCb::OnResult( const std::string &devId, const std::string &dhId, const int32_t &status) { std::lock_guard lock(DistributedInputClient::GetInstance().operationMutex_); - for (std::vector::iterator iter = - DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos.begin(); - iter != DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos.end(); + for (auto iter = DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos_.begin(); + iter != DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos_.end(); ++iter) { if (iter->devId == devId && iter->dhId == dhId) { - iter->callback->OnUnregisterResult(devId, dhId, status, ""); - DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos.erase(iter); - return; + if (iter->callback != nullptr) { + iter->callback->OnUnregisterResult(devId, dhId, status, ""); + DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos_.erase(iter); + return; + } } } } @@ -125,6 +128,10 @@ DistributedInputClient::DInputClientEventHandler::DInputClientEventHandler( void DistributedInputClient::DInputClientEventHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) { + if (event == nullptr) { + DHLOGE("Event is nullptr"); + return; + } uint32_t eventId = event->GetInnerEventId(); DHLOGI("DInputClientEventHandler ProcessEvent start eventId:%{public}d.", eventId); if (eventId == DINPUT_CLIENT_CHECK_SOURCE_CALLBACK_REGISTER_MSG) { @@ -143,26 +150,26 @@ void DistributedInputClient::DInputClientEventHandler::ProcessEvent(const AppExe if (eventId == DINPUT_CLIENT_CLEAR_SOURCE_CALLBACK_REGISTER_MSG) { DHLOGI("Source SA exit, clear callback flag"); - DistributedInputClient::GetInstance().isAddWhiteListCbReg = false; - DistributedInputClient::GetInstance().isDelWhiteListCbReg = false; - DistributedInputClient::GetInstance().isNodeMonitorCbReg = false; - DistributedInputClient::GetInstance().isSimulationEventCbReg = false; + DistributedInputClient::GetInstance().isAddWhiteListCbReg_ = false; + DistributedInputClient::GetInstance().isDelWhiteListCbReg_ = false; + DistributedInputClient::GetInstance().isNodeMonitorCbReg_ = false; + DistributedInputClient::GetInstance().isSimulationEventCbReg_ = false; return; } if (eventId == DINPUT_CLIENT_CLEAR_SINK_CALLBACK_REGISTER_MSG) { DHLOGI("Sink SA exit, clear callback flag"); - DistributedInputClient::GetInstance().isSharingDhIdsReg = false; + DistributedInputClient::GetInstance().isSharingDhIdsReg_ = false; return; } } void DistributedInputClient::CheckSourceRegisterCallback() { - DHLOGI("CheckSourceRegisterCallback called, isAddWhiteListCbReg[%{public}d], isDelWhiteListCbReg[%{public}d], " - "isNodeMonitorCbReg[%{public}d], isSimulationEventCbReg[%{public}d]", - isAddWhiteListCbReg.load(), isDelWhiteListCbReg.load(), isNodeMonitorCbReg.load(), - isSimulationEventCbReg.load()); + DHLOGI("CheckSourceRegisterCallback called, isAddWhiteListCbReg_[%{public}d], isDelWhiteListCbReg_[%{public}d], " + "isNodeMonitorCbReg_[%{public}d], isSimulationEventCbReg_[%{public}d]", + isAddWhiteListCbReg_.load(), isDelWhiteListCbReg_.load(), isNodeMonitorCbReg_.load(), + isSimulationEventCbReg_.load()); CheckWhiteListCallback(); CheckKeyStateCallback(); @@ -170,7 +177,7 @@ void DistributedInputClient::CheckSourceRegisterCallback() void DistributedInputClient::CheckSinkRegisterCallback() { - DHLOGI("CheckSinkRegisterCallback called, isSharingDhIdsReg[%{public}d]", isSharingDhIdsReg.load()); + DHLOGI("CheckSinkRegisterCallback called, isSharingDhIdsReg_[%{public}d]", isSharingDhIdsReg_.load()); CheckSharingDhIdsCallback(); CheckSinkScreenInfoCallback(); } @@ -182,12 +189,12 @@ void DistributedInputClient::CheckSharingDhIdsCallback() return; } std::lock_guard lock(DInputSAManager::GetInstance().sinkMutex_); - if (!isSharingDhIdsReg) { + if (!isSharingDhIdsReg_) { sptr listener(new (std::nothrow) SharingDhIdListenerCb()); int32_t ret = DInputSAManager::GetInstance().dInputSinkProxy_->RegisterSharingDhIdListener(listener); if (ret == DH_SUCCESS) { - isSharingDhIdsReg = true; + isSharingDhIdsReg_ = true; std::lock_guard lock(operationMutex_); sharingDhIdListeners_.insert(listener); } else { @@ -203,24 +210,24 @@ void DistributedInputClient::CheckWhiteListCallback() return; } std::lock_guard lock(DInputSAManager::GetInstance().sourceMutex_); - if (!isAddWhiteListCbReg) { + if (!isAddWhiteListCbReg_) { sptr addCallback(new (std::nothrow) AddWhiteListInfosCb()); int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->RegisterAddWhiteListCallback(addCallback); if (ret == DH_SUCCESS) { - isAddWhiteListCbReg = true; + isAddWhiteListCbReg_ = true; std::lock_guard lock(operationMutex_); addWhiteListCallbacks_.insert(addCallback); } else { DHLOGE("CheckWhiteListCallback client RegisterAddWhiteListCallback fail"); } } - if (!isDelWhiteListCbReg) { + if (!isDelWhiteListCbReg_) { sptr delCallback(new (std::nothrow) DelWhiteListInfosCb()); int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->RegisterDelWhiteListCallback(delCallback); if (ret == DH_SUCCESS) { - isDelWhiteListCbReg = true; + isDelWhiteListCbReg_ = true; std::lock_guard lock(operationMutex_); delWhiteListCallbacks_.insert(delCallback); } else { @@ -236,9 +243,9 @@ void DistributedInputClient::CheckKeyStateCallback() return; } std::lock_guard lock(DInputSAManager::GetInstance().sourceMutex_); - if (!isSimulationEventCbReg && regSimulationEventListener_ != nullptr) { + if (!isSimulationEventCbReg_ && regSimulationEventListener_ != nullptr) { DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSimulationEventListener(regSimulationEventListener_); - isSimulationEventCbReg = true; + isSimulationEventCbReg_ = true; } } @@ -249,12 +256,12 @@ void DistributedInputClient::CheckSinkScreenInfoCallback() return; } std::lock_guard lock(DInputSAManager::GetInstance().sinkMutex_); - if (!isGetSinkScreenInfosCbReg) { + if (!isGetSinkScreenInfosCbReg_) { sptr callback(new (std::nothrow) GetSinkScreenInfosCb()); int32_t ret = DInputSAManager::GetInstance().dInputSinkProxy_->RegisterGetSinkScreenInfosCallback(callback); if (ret == DH_SUCCESS) { - isGetSinkScreenInfosCbReg = true; + isGetSinkScreenInfosCbReg_ = true; std::lock_guard lock(operationMutex_); getSinkScreenInfosCallbacks_.insert(callback); } else { @@ -287,7 +294,7 @@ int32_t DistributedInputClient::ReleaseSource() return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; } - serverType = DInputServerType::NULL_SERVER_TYPE; + serverType_ = DInputServerType::NULL_SERVER_TYPE; inputTypes_ = DInputDeviceType::NONE; regNodeListener_ = nullptr; unregNodeListener_ = nullptr; @@ -308,7 +315,7 @@ int32_t DistributedInputClient::ReleaseSink() if (!DInputSAManager::GetInstance().GetDInputSinkProxy()) { return ERR_DH_INPUT_CLIENT_GET_SINK_PROXY_FAIL; } - serverType = DInputServerType::NULL_SERVER_TYPE; + serverType_ = DInputServerType::NULL_SERVER_TYPE; inputTypes_ = DInputDeviceType::NONE; { std::lock_guard lock(operationMutex_); @@ -334,13 +341,13 @@ int32_t DistributedInputClient::RegisterDistributedHardware(const std::string &d } { std::lock_guard lock(DistributedInputClient::GetInstance().operationMutex_); - for (auto iter : dHardWareFwkRstInfos) { + for (auto iter : dHardWareFwkRstInfos_) { if (iter.devId == devId && iter.dhId == dhId) { return ERR_DH_INPUT_CLIENT_REGISTER_FAIL; } } DHardWareFwkRegistInfo info {devId, dhId, callback}; - dHardWareFwkRstInfos.push_back(info); + dHardWareFwkRstInfos_.push_back(info); } std::lock_guard lock(DInputSAManager::GetInstance().sourceMutex_); return DInputSAManager::GetInstance().dInputSourceProxy_->RegisterDistributedHardware(devId, dhId, parameters, @@ -361,13 +368,13 @@ int32_t DistributedInputClient::UnregisterDistributedHardware(const std::string } { std::lock_guard lock(DistributedInputClient::GetInstance().operationMutex_); - for (auto iter : dHardWareFwkUnRstInfos) { + for (auto iter : dHardWareFwkUnRstInfos_) { if (iter.devId == devId && iter.dhId == dhId) { return ERR_DH_INPUT_CLIENT_UNREGISTER_FAIL; } } DHardWareFwkUnRegistInfo info {devId, dhId, callback}; - dHardWareFwkUnRstInfos.push_back(info); + dHardWareFwkUnRstInfos_.push_back(info); } std::lock_guard lock(DInputSAManager::GetInstance().sourceMutex_); return DInputSAManager::GetInstance().dInputSourceProxy_->UnregisterDistributedHardware(devId, dhId, @@ -575,7 +582,7 @@ bool DistributedInputClient::IsNeedFilterOut(const std::string &deviceId, const bool DistributedInputClient::IsTouchEventNeedFilterOut(const TouchScreenEvent &event) { std::lock_guard lock(operationMutex_); - for (const auto &info : screenTransInfos) { + for (const auto &info : screenTransInfos_) { DHLOGI("sinkProjPhyWidth: %{public}d sinkProjPhyHeight: %{public}d", info.sinkProjPhyWidth, info.sinkProjPhyHeight); if ((event.absX >= info.sinkWinPhyX) && (event.absX <= (info.sinkWinPhyX + info.sinkProjPhyWidth)) @@ -605,17 +612,17 @@ int32_t DistributedInputClient::RegisterSimulationEventListener(sptr lock(DInputSAManager::GetInstance().sourceMutex_); int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSimulationEventListener(listener); if (ret == DH_SUCCESS) { - isSimulationEventCbReg = true; + isSimulationEventCbReg_ = true; DInputSAManager::GetInstance().AddSimEventListenerToCache(listener); } else { - isSimulationEventCbReg = false; + isSimulationEventCbReg_ = false; regSimulationEventListener_ = listener; DHLOGE("RegisterSimulationEventListener Failed, ret = %{public}d", ret); } @@ -689,7 +696,7 @@ void DistributedInputClient::DelWhiteListInfos(const std::string &deviceId) cons void DistributedInputClient::UpdateSinkScreenInfos(const std::string &strJson) { std::lock_guard lock(operationMutex_); - screenTransInfos.clear(); + screenTransInfos_.clear(); nlohmann::json inputData = nlohmann::json::parse(strJson, nullptr, false); if (inputData.is_discarded()) { DHLOGE("InputData parse failed!"); @@ -708,8 +715,8 @@ void DistributedInputClient::UpdateSinkScreenInfos(const std::string &strJson) continue; } TransformInfo tmp{info[0], info[1], info[2], info[3]}; - screenTransInfos.emplace_back(tmp); - DHLOGI("screenTransInfos size %{public}zu", screenTransInfos.size()); + screenTransInfos_.emplace_back(tmp); + DHLOGI("screenTransInfos_ size %{public}zu", screenTransInfos_.size()); } } diff --git a/interfaces/ipc/src/distributed_input_sink_proxy.cpp b/interfaces/ipc/src/distributed_input_sink_proxy.cpp index 6af28e2a3d9229a42a8ed5575b17646fefc84418..12bebb26e7d733a61f9f60f8e4237ea4e74c0c62 100644 --- a/interfaces/ipc/src/distributed_input_sink_proxy.cpp +++ b/interfaces/ipc/src/distributed_input_sink_proxy.cpp @@ -147,6 +147,10 @@ int32_t DistributedInputSinkProxy::NotifyStopDScreen(const std::string &srcScree int32_t DistributedInputSinkProxy::RegisterSharingDhIdListener(sptr sharingDhIdListener) { + if (sharingDhIdListener == nullptr) { + DHLOGE("sharingDhIdListener is nullptr"); + return ERR_DH_INPUT_SINK_PROXY_DH_LISTENER_IS_NULL; + } MessageParcel data; if (!data.WriteInterfaceToken(GetDescriptor())) { DHLOGE("RegisterSharingDhIdListener write token valid failed"); diff --git a/interfaces/ipc/src/distributed_input_source_proxy.cpp b/interfaces/ipc/src/distributed_input_source_proxy.cpp index 8a848e98b8b13514972305028455640e7b6a16a8..ccd0aa1041bd02bc0bbb7a50e24f2a40a7dc6fae 100644 --- a/interfaces/ipc/src/distributed_input_source_proxy.cpp +++ b/interfaces/ipc/src/distributed_input_source_proxy.cpp @@ -97,6 +97,10 @@ int32_t DistributedInputSourceProxy::RegisterDistributedHardware(const std::stri int32_t DistributedInputSourceProxy::UnregisterDistributedHardware(const std::string &devId, const std::string &dhId, sptr callback) { + if (callback == nullptr) { + DHLOGE("callback is nullptr"); + return ERR_DH_INPUT_SRC_PROXY_CALLBACK_IS_NULL; + } MessageParcel data; if (!data.WriteInterfaceToken(GetDescriptor())) { DHLOGE("DistributedInputSourceProxy write token valid failed"); @@ -126,6 +130,10 @@ int32_t DistributedInputSourceProxy::UnregisterDistributedHardware(const std::st int32_t DistributedInputSourceProxy::PrepareRemoteInput( const std::string &deviceId, sptr callback) { + if (callback == nullptr) { + DHLOGE("callback is nullptr"); + return ERR_DH_INPUT_SRC_PROXY_CALLBACK_IS_NULL; + } MessageParcel data; if (!data.WriteInterfaceToken(GetDescriptor())) { DHLOGE("DistributedInputSourceProxy write token valid failed"); @@ -153,6 +161,10 @@ int32_t DistributedInputSourceProxy::PrepareRemoteInput( int32_t DistributedInputSourceProxy::UnprepareRemoteInput(const std::string &deviceId, sptr callback) { + if (callback == nullptr) { + DHLOGE("callback is nullptr"); + return ERR_DH_INPUT_SRC_PROXY_CALLBACK_IS_NULL; + } MessageParcel data; if (!data.WriteInterfaceToken(GetDescriptor())) { DHLOGE("DistributedInputSourceProxy write token valid failed"); @@ -179,6 +191,10 @@ int32_t DistributedInputSourceProxy::UnprepareRemoteInput(const std::string &dev int32_t DistributedInputSourceProxy::StartRemoteInput( const std::string &deviceId, const uint32_t &inputTypes, sptr callback) { + if (callback == nullptr) { + DHLOGE("callback is nullptr"); + return ERR_DH_INPUT_SRC_PROXY_CALLBACK_IS_NULL; + } DHLOGI("source proxy StartRemoteInput start"); MessageParcel data; if (!data.WriteInterfaceToken(GetDescriptor())) { @@ -210,6 +226,10 @@ int32_t DistributedInputSourceProxy::StartRemoteInput( int32_t DistributedInputSourceProxy::StopRemoteInput( const std::string &deviceId, const uint32_t &inputTypes, sptr callback) { + if (callback == nullptr) { + DHLOGE("callback is nullptr"); + return ERR_DH_INPUT_SRC_PROXY_CALLBACK_IS_NULL; + } MessageParcel data; if (!data.WriteInterfaceToken(GetDescriptor())) { DHLOGE("DistributedInputSourceProxy write token valid failed"); @@ -239,6 +259,10 @@ int32_t DistributedInputSourceProxy::StopRemoteInput( int32_t DistributedInputSourceProxy::StartRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, sptr callback) { + if (callback == nullptr) { + DHLOGE("callback is nullptr"); + return ERR_DH_INPUT_SRC_PROXY_CALLBACK_IS_NULL; + } DHLOGI("source proxy StartRemoteInput start"); MessageParcel data; if (!data.WriteInterfaceToken(GetDescriptor())) { @@ -275,6 +299,10 @@ int32_t DistributedInputSourceProxy::StartRemoteInput(const std::string &srcId, int32_t DistributedInputSourceProxy::StopRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, sptr callback) { + if (callback == nullptr) { + DHLOGE("callback is nullptr"); + return ERR_DH_INPUT_SRC_PROXY_CALLBACK_IS_NULL; + } MessageParcel data; if (!data.WriteInterfaceToken(GetDescriptor())) { DHLOGE("DistributedInputSourceProxy write token valid failed"); @@ -309,6 +337,10 @@ int32_t DistributedInputSourceProxy::StopRemoteInput(const std::string &srcId, c int32_t DistributedInputSourceProxy::PrepareRemoteInput(const std::string &srcId, const std::string &sinkId, sptr callback) { + if (callback == nullptr) { + DHLOGE("callback is nullptr"); + return ERR_DH_INPUT_SRC_PROXY_CALLBACK_IS_NULL; + } MessageParcel data; if (!data.WriteInterfaceToken(GetDescriptor())) { DHLOGE("DistributedInputSourceProxy write token valid failed"); @@ -340,6 +372,10 @@ int32_t DistributedInputSourceProxy::PrepareRemoteInput(const std::string &srcId int32_t DistributedInputSourceProxy::UnprepareRemoteInput(const std::string &srcId, const std::string &sinkId, sptr callback) { + if (callback == nullptr) { + DHLOGE("callback is nullptr"); + return ERR_DH_INPUT_SRC_PROXY_CALLBACK_IS_NULL; + } MessageParcel data; if (!data.WriteInterfaceToken(GetDescriptor())) { DHLOGE("DistributedInputSourceProxy write token valid failed"); @@ -371,6 +407,10 @@ int32_t DistributedInputSourceProxy::UnprepareRemoteInput(const std::string &src int32_t DistributedInputSourceProxy::StartRemoteInput(const std::string &sinkId, const std::vector &dhIds, sptr callback) { + if (callback == nullptr) { + DHLOGE("callback is nullptr"); + return ERR_DH_INPUT_SRC_PROXY_CALLBACK_IS_NULL; + } MessageParcel data; if (!data.WriteInterfaceToken(GetDescriptor())) { DHLOGE("DistributedInputSourceProxy write token valid failed"); @@ -409,6 +449,10 @@ int32_t DistributedInputSourceProxy::StartRemoteInput(const std::string &sinkId, int32_t DistributedInputSourceProxy::StopRemoteInput(const std::string &sinkId, const std::vector &dhIds, sptr callback) { + if (callback == nullptr) { + DHLOGE("callback is nullptr"); + return ERR_DH_INPUT_SRC_PROXY_CALLBACK_IS_NULL; + } MessageParcel data; if (!data.WriteInterfaceToken(GetDescriptor())) { DHLOGE("DistributedInputSourceProxy write token valid failed"); @@ -447,6 +491,10 @@ int32_t DistributedInputSourceProxy::StopRemoteInput(const std::string &sinkId, int32_t DistributedInputSourceProxy::StartRemoteInput(const std::string &srcId, const std::string &sinkId, const std::vector &dhIds, sptr callback) { + if (callback == nullptr) { + DHLOGE("callback is nullptr"); + return ERR_DH_INPUT_SRC_PROXY_CALLBACK_IS_NULL; + } MessageParcel data; if (!data.WriteInterfaceToken(GetDescriptor())) { DHLOGE("DistributedInputSourceProxy relay dhid write token valid failed"); @@ -490,6 +538,10 @@ int32_t DistributedInputSourceProxy::StartRemoteInput(const std::string &srcId, int32_t DistributedInputSourceProxy::StopRemoteInput(const std::string &srcId, const std::string &sinkId, const std::vector &dhIds, sptr callback) { + if (callback == nullptr) { + DHLOGE("callback is nullptr"); + return ERR_DH_INPUT_SRC_PROXY_CALLBACK_IS_NULL; + } MessageParcel data; if (!data.WriteInterfaceToken(GetDescriptor())) { DHLOGE("DistributedInputSourceProxy write token valid failed"); @@ -583,6 +635,10 @@ int32_t DistributedInputSourceProxy::RegisterDelWhiteListCallback(sptr listener) { + if (listener == nullptr) { + DHLOGE("callback is nullptr"); + return ERR_DH_INPUT_SRC_PROXY_EVENT_LISTENER_IS_NULL; + } MessageParcel data; if (!data.WriteInterfaceToken(GetDescriptor())) { DHLOGE("RegisterSimulationEventListener write token valid failed"); @@ -606,6 +662,10 @@ int32_t DistributedInputSourceProxy::RegisterSimulationEventListener(sptr listener) { + if (listener == nullptr) { + DHLOGE("callback is nullptr"); + return ERR_DH_INPUT_SRC_PROXY_EVENT_LISTENER_IS_NULL; + } MessageParcel data; if (!data.WriteInterfaceToken(GetDescriptor())) { DHLOGE("UnregisterSimulationEventListener write token valid failed"); @@ -629,6 +689,10 @@ int32_t DistributedInputSourceProxy::UnregisterSimulationEventListener(sptr callback) { + if (callback == nullptr) { + DHLOGE("callback is nullptr"); + return ERR_DH_INPUT_SRC_PROXY_CALLBACK_IS_NULL; + } MessageParcel data; if (!data.WriteInterfaceToken(GetDescriptor())) { DHLOGE("RegisterSessionStateCb write token valid failed"); diff --git a/interfaces/ipc/test/addwhitelistinfoscallbackunittest/add_white_list_infos_call_back_test.cpp b/interfaces/ipc/test/addwhitelistinfoscallbackunittest/add_white_list_infos_call_back_test.cpp index 744d50eb6faf4fedcc97b4d4302a8f0b7776af05..b0615aab465a08f10a1a3954affe50b04192d7f3 100644 --- a/interfaces/ipc/test/addwhitelistinfoscallbackunittest/add_white_list_infos_call_back_test.cpp +++ b/interfaces/ipc/test/addwhitelistinfoscallbackunittest/add_white_list_infos_call_back_test.cpp @@ -208,6 +208,7 @@ int32_t AddWhiteListInfosCallbackTest::TestDistributedInputSinkStub::RegisterSha HWTEST_F(AddWhiteListInfosCallbackTest, AddWhiteListInfosCallback01, testing::ext::TestSize.Level1) { sptr callBackStubPtr(new TestAddWhiteListInfosCallbackStub()); + ASSERT_NE(nullptr, callBackStubPtr); AddWhiteListInfosCallbackProxy callBackProxy(callBackStubPtr); std::string deviceId = "deviceId0"; std::string json = "json0"; @@ -219,6 +220,7 @@ HWTEST_F(AddWhiteListInfosCallbackTest, AddWhiteListInfosCallback01, testing::ex HWTEST_F(AddWhiteListInfosCallbackTest, GetSinkScreenInfosCallback01, testing::ext::TestSize.Level1) { sptr callBackStubPtr(new TestGetSinkScreenInfosCallbackStub()); + ASSERT_NE(nullptr, callBackStubPtr); GetSinkScreenInfosCallbackProxy callBackProxy(callBackStubPtr); std::string json = "json0"; callBackProxy.OnResult(json); @@ -228,6 +230,7 @@ HWTEST_F(AddWhiteListInfosCallbackTest, GetSinkScreenInfosCallback01, testing::e HWTEST_F(AddWhiteListInfosCallbackTest, InputNodeListenerStub01, testing::ext::TestSize.Level1) { sptr nodeListener(new TestInputNodeListenerStub()); + ASSERT_NE(nullptr, nodeListener); InputNodeListenerProxy nodeListenerProxy(nodeListener); std::string srcDevId = "srcDevId_test"; std::string sinkDevId = "sinkDevId_test"; @@ -243,6 +246,7 @@ HWTEST_F(AddWhiteListInfosCallbackTest, InputNodeListenerStub01, testing::ext::T HWTEST_F(AddWhiteListInfosCallbackTest, InputNodeListenerStub02, testing::ext::TestSize.Level1) { sptr nodeListener(new TestInputNodeListenerStub()); + ASSERT_NE(nullptr, nodeListener); InputNodeListenerProxy nodeListenerProxy(nodeListener); std::string srcDevId = "srcDevId_test"; std::string sinkDevId = "sinkDevId_test"; @@ -256,6 +260,7 @@ HWTEST_F(AddWhiteListInfosCallbackTest, InputNodeListenerStub02, testing::ext::T HWTEST_F(AddWhiteListInfosCallbackTest, PrepareDInputCallback01, testing::ext::TestSize.Level1) { sptr callBackStubPtr(new TestPrepareDInputCallbackStub()); + ASSERT_NE(nullptr, callBackStubPtr); PrepareDInputCallbackProxy callBackProxy(callBackStubPtr); std::string devId = "devId_test"; int32_t status = 0; @@ -266,6 +271,7 @@ HWTEST_F(AddWhiteListInfosCallbackTest, PrepareDInputCallback01, testing::ext::T HWTEST_F(AddWhiteListInfosCallbackTest, RegisterDInputCallback01, testing::ext::TestSize.Level1) { sptr callBackStubPtr(new TestRegisterDInputCallbackStub()); + ASSERT_NE(nullptr, callBackStubPtr); RegisterDInputCallbackProxy callBackProxy(callBackStubPtr); std::string devId = "devId_test"; std::string dhId = "dhId_test"; @@ -307,6 +313,7 @@ HWTEST_F(AddWhiteListInfosCallbackTest, SimulationEventListenerStub01, testing:: HWTEST_F(AddWhiteListInfosCallbackTest, StartDInputCallbackStub01, testing::ext::TestSize.Level1) { sptr callBackStubPtr(new TestStartDInputCallbackStub()); + ASSERT_NE(nullptr, callBackStubPtr); StartDInputCallbackProxy callBackProxy(callBackStubPtr); std::string devId = "devId_test"; uint32_t inputTypes = static_cast(DInputDeviceType::ALL); @@ -318,6 +325,7 @@ HWTEST_F(AddWhiteListInfosCallbackTest, StartDInputCallbackStub01, testing::ext: HWTEST_F(AddWhiteListInfosCallbackTest, StartStopDInputsCallbackStub01, testing::ext::TestSize.Level1) { sptr callBackStubPtr(new TestStartStopDInputsCallbackStub()); + ASSERT_NE(nullptr, callBackStubPtr); StartStopDInputsCallbackProxy callBackProxy(callBackStubPtr); std::string devId = "devId_test"; int32_t status = 1; @@ -329,6 +337,7 @@ HWTEST_F(AddWhiteListInfosCallbackTest, StartStopDInputsCallbackStub01, testing: HWTEST_F(AddWhiteListInfosCallbackTest, StartStopResultCallbackStub01, testing::ext::TestSize.Level1) { sptr callBackStubPtr(new TestStartStopResultCallbackStub()); + ASSERT_NE(nullptr, callBackStubPtr); StartStopResultCallbackProxy callBackProxy(callBackStubPtr); std::string srcId = "srcId_test"; std::string sinkId = "sinkId_test"; @@ -342,6 +351,7 @@ HWTEST_F(AddWhiteListInfosCallbackTest, StartStopResultCallbackStub01, testing:: HWTEST_F(AddWhiteListInfosCallbackTest, StartStopResultCallbackStub02, testing::ext::TestSize.Level1) { sptr callBackStubPtr(new TestStartStopResultCallbackStub()); + ASSERT_NE(nullptr, callBackStubPtr); StartStopResultCallbackProxy callBackProxy(callBackStubPtr); std::string srcId = "srcId_test"; std::string sinkId = "sinkId_test"; @@ -355,6 +365,7 @@ HWTEST_F(AddWhiteListInfosCallbackTest, StartStopResultCallbackStub02, testing:: HWTEST_F(AddWhiteListInfosCallbackTest, StopDInputCallbackStub01, testing::ext::TestSize.Level1) { sptr callBackStubPtr(new TestStopDInputCallbackStub()); + ASSERT_NE(nullptr, callBackStubPtr); StopDInputCallbackProxy callBackProxy(callBackStubPtr); std::string devId = "devId_test"; uint32_t inputTypes = static_cast(DInputDeviceType::ALL); diff --git a/interfaces/ipc/test/clientunittest/distributed_input_client_test.cpp b/interfaces/ipc/test/clientunittest/distributed_input_client_test.cpp index b1391ee4325899dd88fb382886e61bb7df4d5d8a..a98d36061f006dddc97187fecc48f721ea954f1a 100644 --- a/interfaces/ipc/test/clientunittest/distributed_input_client_test.cpp +++ b/interfaces/ipc/test/clientunittest/distributed_input_client_test.cpp @@ -434,6 +434,7 @@ HWTEST_F(DistributedInputClientTest, ProcessEvent01, testing::ext::TestSize.Leve DistributedInputClient::DInputClientEventHandler eventHandler(runner); AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(DINPUT_CLIENT_CHECK_SOURCE_CALLBACK_REGISTER_MSG, 4809); + ASSERT_NE(nullptr, event); eventHandler.ProcessEvent(event); EXPECT_EQ(event->GetInnerEventId(), DINPUT_CLIENT_CHECK_SOURCE_CALLBACK_REGISTER_MSG); } @@ -444,6 +445,7 @@ HWTEST_F(DistributedInputClientTest, ProcessEvent02, testing::ext::TestSize.Leve DistributedInputClient::DInputClientEventHandler eventHandler(runner); AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(DINPUT_CLIENT_CHECK_SINK_CALLBACK_REGISTER_MSG, 4809); + ASSERT_NE(nullptr, event); eventHandler.ProcessEvent(event); EXPECT_EQ(event->GetInnerEventId(), DINPUT_CLIENT_CHECK_SINK_CALLBACK_REGISTER_MSG); } @@ -454,6 +456,7 @@ HWTEST_F(DistributedInputClientTest, ProcessEvent03, testing::ext::TestSize.Leve DistributedInputClient::DInputClientEventHandler eventHandler(runner); AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(DINPUT_CLIENT_CLEAR_SOURCE_CALLBACK_REGISTER_MSG, 4809); + ASSERT_NE(nullptr, event); eventHandler.ProcessEvent(event); EXPECT_EQ(event->GetInnerEventId(), DINPUT_CLIENT_CLEAR_SOURCE_CALLBACK_REGISTER_MSG); } @@ -464,6 +467,7 @@ HWTEST_F(DistributedInputClientTest, ProcessEvent04, testing::ext::TestSize.Leve DistributedInputClient::DInputClientEventHandler eventHandler(runner); AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(DINPUT_CLIENT_CLEAR_SINK_CALLBACK_REGISTER_MSG, 4809); + ASSERT_NE(nullptr, event); eventHandler.ProcessEvent(event); EXPECT_EQ(event->GetInnerEventId(), DINPUT_CLIENT_CLEAR_SINK_CALLBACK_REGISTER_MSG); } diff --git a/interfaces/ipc/test/delwhitelistinfoscallbackunittest/del_white_list_infos_call_back_test.cpp b/interfaces/ipc/test/delwhitelistinfoscallbackunittest/del_white_list_infos_call_back_test.cpp index 383919de79e6d259309660317c6dbbda7731b962..1c75cc7dd95290ef400778aba43bb93db9282ab8 100644 --- a/interfaces/ipc/test/delwhitelistinfoscallbackunittest/del_white_list_infos_call_back_test.cpp +++ b/interfaces/ipc/test/delwhitelistinfoscallbackunittest/del_white_list_infos_call_back_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -42,6 +42,7 @@ void DelWhiteListInfosCallbackTest::TestDelWhiteListInfosCallbackStub::OnResult( HWTEST_F(DelWhiteListInfosCallbackTest, DelWhiteListInfosCallback01, testing::ext::TestSize.Level1) { sptr callBackStubPtr(new TestDelWhiteListInfosCallbackStub()); + ASSERT_NE(nullptr, callBackStubPtr); DelWhiteListInfosCallbackProxy callBackProxy(callBackStubPtr); std::string deviceId = "deviceId0"; callBackProxy.OnResult(deviceId); diff --git a/interfaces/ipc/test/fuzztest/distributedinputstub_fuzzer/distributedinputstub_fuzzer.cpp b/interfaces/ipc/test/fuzztest/distributedinputstub_fuzzer/distributedinputstub_fuzzer.cpp index c87492cb02a1243579e864655d1bc22412ba8c61..d1f7e8f008cd914c7a3c01223baf9154d124d63b 100644 --- a/interfaces/ipc/test/fuzztest/distributedinputstub_fuzzer/distributedinputstub_fuzzer.cpp +++ b/interfaces/ipc/test/fuzztest/distributedinputstub_fuzzer/distributedinputstub_fuzzer.cpp @@ -67,6 +67,9 @@ void AddWhiteListInfosCallbackStubFuzzTest(const uint8_t *data, size_t size) } sptr addWhiteListInfos(new (std::nothrow) MyAddWhiteListInfosCallbackStub()); + if (addWhiteListInfos == nullptr) { + return; + } addWhiteListInfos->OnRemoteRequest(code, pdata, reply, option); } @@ -104,6 +107,9 @@ void DelWhiteListInfosCallbackStubFuzzTest(const uint8_t *data, size_t size) sptr delWhiteListInfos(new (std::nothrow) MyDelWhiteListInfosCallbackStub()); + if (delWhiteListInfos == nullptr) { + return; + } delWhiteListInfos->OnRemoteRequest(code, pdata, reply, option); } @@ -164,6 +170,9 @@ void DistributedInputSinkStubFuzzTest(const uint8_t *data, size_t size) sptr distributedInputSinkStub(new (std::nothrow) DistributedInputSinkStubFuzz()); + if (distributedInputSinkStub == nullptr) { + return; + } distributedInputSinkStub->HasEnableDHPermission(); distributedInputSinkStub->OnRemoteRequest(code, pdata, reply, option); distributedInputSinkStub->InitInner(pdata, reply, option); @@ -389,6 +398,9 @@ void DistributedInputSourceStubFuzzTest(const uint8_t *data, size_t size) sptr distributedInputSourceStub(new (std::nothrow) DInputSourceCallBackStubFuzz()); + if (distributedInputSourceStub == nullptr) { + return; + } distributedInputSourceStub->HasEnableDHPermission(); distributedInputSourceStub->HasAccessDHPermission(); distributedInputSourceStub->HandleInitDistributedHardware(reply); @@ -450,6 +462,9 @@ void GetSinkScreenInfosCallbackStubFuzzTest(const uint8_t *data, size_t size) sptr getSinkScreenInfosCbStub(new (std::nothrow) MyGetSinkScreenInfosCallbackStub()); + if (getSinkScreenInfosCbStub == nullptr) { + return; + } getSinkScreenInfosCbStub->OnRemoteRequest(code, pdata, reply, option); } @@ -508,6 +523,9 @@ void InputNodeListenerStubFuzzTest(const uint8_t *data, size_t size) sptr inputNodeListenerStub(new (std::nothrow) MyInputNodeListenerStub()); + if (inputNodeListenerStub == nullptr) { + return; + } inputNodeListenerStub->OnRemoteRequest(code, pdata, reply, option); } @@ -544,6 +562,9 @@ void PrepareDInputCallbackStubFuzzTest(const uint8_t *data, size_t size) } sptr prepareDInputCallbackStub(new (std::nothrow) MyPrepareDInputCallbackStub()); + if (prepareDInputCallbackStub == nullptr) { + return; + } prepareDInputCallbackStub->OnRemoteRequest(code, pdata, reply, option); } @@ -580,6 +601,9 @@ void RegisterDInputCallbackStubFuzzTest(const uint8_t *data, size_t size) } sptr registerDInputCallbackStub(new (std::nothrow) MyRegisterDInputCallbackStub()); + if (registerDInputCallbackStub == nullptr) { + return; + } registerDInputCallbackStub->OnRemoteRequest(code, pdata, reply, option); } @@ -616,6 +640,9 @@ void RegisterSessionStateCallbackStubFuzzTest(const uint8_t *data, size_t size) } sptr registerSessionStateCbkStub(new (std::nothrow) MyRegisterSessionStateCallbackStub()); + if (registerSessionStateCbkStub == nullptr) { + return; + } registerSessionStateCbkStub->OnRemoteRequest(code, pdata, reply, option); } @@ -666,6 +693,9 @@ void SharingDhIdListenerStubFuzzTest(const uint8_t *data, size_t size) } sptr sharingDhIdListenerStub(new (std::nothrow) MySharingDhIdListenerStub()); + if (sharingDhIdListenerStub == nullptr) { + return; + } sharingDhIdListenerStub->OnRemoteRequest(code, pdata, reply, option); } @@ -702,6 +732,9 @@ void SimulationEventListenerStubFuzzTest(const uint8_t *data, size_t size) } sptr simulationEventListenerStub(new (std::nothrow) MySimulationEventListenerStub()); + if (simulationEventListenerStub == nullptr) { + return; + } simulationEventListenerStub->OnRemoteRequest(code, pdata, reply, option); } @@ -738,6 +771,9 @@ void StartDInputCallbackStubFuzzTest(const uint8_t *data, size_t size) } sptr startDInputCallbackStub(new (std::nothrow) MyStartDInputCallbackStub()); + if (startDInputCallbackStub == nullptr) { + return; + } startDInputCallbackStub->OnRemoteRequest(code, pdata, reply, option); } @@ -774,6 +810,9 @@ void StartStopDInputsCallbackStubFuzzTest(const uint8_t *data, size_t size) } sptr startStopDInputsCallbackStub(new (std::nothrow) MyStartStopDInputsCallbackStub()); + if (startStopDInputsCallbackStub == nullptr) { + return; + } startStopDInputsCallbackStub->OnRemoteRequest(code, pdata, reply, option); } @@ -823,6 +862,9 @@ void StartStopResultCallbackStubFuzzTest(const uint8_t *data, size_t size) } sptr startStopResultCallbackStub(new (std::nothrow) MyStartStopResultCallbackStub()); + if (startStopResultCallbackStub == nullptr) { + return; + } startStopResultCallbackStub->OnRemoteRequest(code, pdata, reply, option); } @@ -859,6 +901,9 @@ void StopDInputCallbackStubFuzzTest(const uint8_t *data, size_t size) } sptr stopDInputCallbackStub(new (std::nothrow) MyStopDInputCallbackStub()); + if (stopDInputCallbackStub == nullptr) { + return; + } stopDInputCallbackStub->OnRemoteRequest(code, pdata, reply, option); } @@ -895,6 +940,9 @@ void UnprepareDInputCallbackStubFuzzTest(const uint8_t *data, size_t size) } sptr unprepareDInputCallbackStub(new (std::nothrow) MyUnprepareDInputCallbackStub()); + if (unprepareDInputCallbackStub == nullptr) { + return; + } unprepareDInputCallbackStub->OnRemoteRequest(code, pdata, reply, option); } @@ -931,6 +979,9 @@ void UnregisterDInputCallbackStubFuzzTest(const uint8_t *data, size_t size) } sptr unregisterDInputCallbackStub(new (std::nothrow) MyUnregisterDInputCallbackStub()); + if (unregisterDInputCallbackStub == nullptr) { + return; + } unregisterDInputCallbackStub->OnRemoteRequest(code, pdata, reply, option); } } // namespace DistributedHardware diff --git a/interfaces/ipc/test/unpreparedinputcallbackunittest/unprepare_d_input_call_back_test.cpp b/interfaces/ipc/test/unpreparedinputcallbackunittest/unprepare_d_input_call_back_test.cpp index 8b00d2e930f9269909f50d179087da88223a0870..b9d8127f9434e630cfb7edc4d114582cc296885b 100644 --- a/interfaces/ipc/test/unpreparedinputcallbackunittest/unprepare_d_input_call_back_test.cpp +++ b/interfaces/ipc/test/unpreparedinputcallbackunittest/unprepare_d_input_call_back_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -44,6 +44,7 @@ void UnprepareDInputCallbackTest::TestUnprepareDInputCallbackStub::OnResult(cons HWTEST_F(UnprepareDInputCallbackTest, UnprepareDInputCallback01, testing::ext::TestSize.Level1) { sptr callBackStubPtr(new TestUnprepareDInputCallbackStub()); + ASSERT_NE(nullptr, callBackStubPtr); UnprepareDInputCallbackProxy callBackProxy(callBackStubPtr); std::string deviceId = "deviceId0"; int32_t status = 0; diff --git a/interfaces/ipc/test/unregisterdinputcallbackunittest/unregister_d_input_call_back_test.cpp b/interfaces/ipc/test/unregisterdinputcallbackunittest/unregister_d_input_call_back_test.cpp index 01c4e21e974e2eebb599097d9bac7198387079d0..9782677ad95d56e9d84188665308df965ac97b87 100644 --- a/interfaces/ipc/test/unregisterdinputcallbackunittest/unregister_d_input_call_back_test.cpp +++ b/interfaces/ipc/test/unregisterdinputcallbackunittest/unregister_d_input_call_back_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -45,6 +45,7 @@ void UnregisterDInputCallbackTest::TestUnregisterDInputCallbackStub::OnResult(co HWTEST_F(UnregisterDInputCallbackTest, UnregisterDInputCallback01, testing::ext::TestSize.Level1) { sptr callBackStubPtr(new TestUnregisterDInputCallbackStub()); + ASSERT_NE(nullptr, callBackStubPtr); UnregisterDInputCallbackProxy callBackProxy(callBackStubPtr); std::string deviceId = "deviceId0"; std::string dhId = "dhId0"; diff --git a/services/sink/inputcollector/include/distributed_input_collector.h b/services/sink/inputcollector/include/distributed_input_collector.h index c49b722237741f3b14e407b8bf47328f909fe360..6ccd4d5fc0d3775d1ea033a0325a1d80fe58fac3 100644 --- a/services/sink/inputcollector/include/distributed_input_collector.h +++ b/services/sink/inputcollector/include/distributed_input_collector.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -69,7 +69,7 @@ private: RawEvent mEventBuffer[INPUT_EVENT_BUFFER_SIZE]; pthread_t collectThreadID_; bool isCollectingEvents_; - bool isStartGetDeviceHandlerThread; + bool isStartGetDeviceHandlerThread_; std::unique_ptr inputHub_; std::shared_ptr sinkHandler_; uint32_t inputTypes_; diff --git a/services/sink/inputcollector/src/distributed_input_collector.cpp b/services/sink/inputcollector/src/distributed_input_collector.cpp index 3e0eaa6b71c63a8c3665f07bf1dc1bd5190555a5..0c4a2a47ab2d2239c522e911c1029f3b114f0bd1 100644 --- a/services/sink/inputcollector/src/distributed_input_collector.cpp +++ b/services/sink/inputcollector/src/distributed_input_collector.cpp @@ -37,7 +37,7 @@ namespace OHOS { namespace DistributedHardware { namespace DistributedInput { DistributedInputCollector::DistributedInputCollector() : mEventBuffer{}, collectThreadID_(-1), - isCollectingEvents_(false), isStartGetDeviceHandlerThread(false), inputTypes_(0) + isCollectingEvents_(false), isStartGetDeviceHandlerThread_(false), inputTypes_(0) { inputHub_ = std::make_unique(false); } @@ -56,7 +56,9 @@ DistributedInputCollector &DistributedInputCollector::GetInstance() void DistributedInputCollector::PreInit() { DHLOGI("PreInit for record local device infos"); - inputHub_->RecordDeviceStates(); + if (inputHub_ != nullptr) { + inputHub_->RecordDeviceStates(); + } } int32_t DistributedInputCollector::StartCollectionThread(std::shared_ptr sinkHandler) @@ -68,9 +70,9 @@ int32_t DistributedInputCollector::StartCollectionThread(std::shared_ptr(param); + if (pThis == nullptr) { + DHLOGE("pThis is null."); + return nullptr; + } pThis->StartCollectEventsThread(); DHLOGW("DistributedInputCollector::CollectEventsThread exist!"); return nullptr; @@ -146,7 +152,7 @@ void DistributedInputCollector::StartCollectEventsThread() void DistributedInputCollector::StopCollectEventsThread() { isCollectingEvents_ = false; - isStartGetDeviceHandlerThread = false; + isStartGetDeviceHandlerThread_ = false; if (inputHub_ == nullptr) { DHLOGI("inputHub is nullptr!"); return; diff --git a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp index 8df911964633b66d844a7623fdee643901effea5..7436c927ffcc127579c04a1920d11dc8b1ba6078 100644 --- a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp +++ b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp @@ -86,14 +86,18 @@ void DistributedInputSinkManager::DInputSinkMgrListener::ResetSinkMgrResStatus() DistributedInputSinkManager::DInputSinkListener::DInputSinkListener(DistributedInputSinkManager *manager) { sinkManagerObj_ = manager; - sinkManagerObj_->SetInputTypes(static_cast(DInputDeviceType::NONE)); + if (sinkManagerObj_ != nullptr) { + sinkManagerObj_->SetInputTypes(static_cast(DInputDeviceType::NONE)); + } DHLOGI("DInputSinkListener init."); } DistributedInputSinkManager::DInputSinkListener::~DInputSinkListener() { - sinkManagerObj_->SetInputTypes(static_cast(DInputDeviceType::NONE)); - sinkManagerObj_ = nullptr; + if (sinkManagerObj_ != nullptr) { + sinkManagerObj_->SetInputTypes(static_cast(DInputDeviceType::NONE)); + sinkManagerObj_ = nullptr; + } DHLOGI("DInputSinkListener destory."); } @@ -134,7 +138,10 @@ void DistributedInputSinkManager::DInputSinkListener::OnPrepareRemoteInput( nlohmann::json jsonStr; jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ONPREPARE; std::string smsg = ""; - + if (sinkManagerObj_ == nullptr) { + DHLOGE("sinkManagerObj is null."); + return; + } DistributedInputSinkSwitch::GetInstance().AddSession(sessionId); sinkManagerObj_->QueryLocalWhiteList(jsonStr); jsonStr[DINPUT_SOFTBUS_KEY_RESP_VALUE] = true; @@ -167,7 +174,10 @@ void DistributedInputSinkManager::DInputSinkListener::OnRelayPrepareRemoteInput( jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ON_RELAY_PREPARE; jsonStr[DINPUT_SOFTBUS_KEY_SESSION_ID] = toSrcSessionId; std::string smsg = ""; - + if (sinkManagerObj_ == nullptr) { + DHLOGE("sinkManagerObj is null."); + return; + } DistributedInputSinkSwitch::GetInstance().AddSession(toSinkSessionId); sinkManagerObj_->QueryLocalWhiteList(jsonStr); jsonStr[DINPUT_SOFTBUS_KEY_RESP_VALUE] = true; @@ -198,9 +208,12 @@ void DistributedInputSinkManager::DInputSinkListener::OnStartRemoteInput( const int32_t &sessionId, const uint32_t &inputTypes) { DHLOGI("OnStartRemoteInput called, sessionId: %{public}d, inputTypes: %{public}u.", sessionId, inputTypes); + if (sinkManagerObj_ == nullptr) { + DHLOGE("sinkManagerObj is null."); + return; + } // set new session int32_t startRes = DistributedInputSinkSwitch::GetInstance().StartSwitch(sessionId); - sinkManagerObj_->SetStartTransFlag((startRes == DH_SUCCESS) ? DInputServerType::SINK_SERVER_TYPE : DInputServerType::NULL_SERVER_TYPE); @@ -237,6 +250,10 @@ void DistributedInputSinkManager::DInputSinkListener::OnStartRemoteInput( void DistributedInputSinkManager::DInputSinkListener::OnStopRemoteInput( const int32_t &sessionId, const uint32_t &inputTypes) { + if (sinkManagerObj_ == nullptr) { + DHLOGE("sinkManagerObj is null."); + return; + } DHLOGI("OnStopRemoteInput called, sessionId: %{public}d, inputTypes: %{public}d, curInputTypes: %{public}d", sessionId, inputTypes, sinkManagerObj_->GetInputTypes()); @@ -286,7 +303,10 @@ void DistributedInputSinkManager::DInputSinkListener::OnStartRemoteInputDhid(con DHLOGE("StartSwitch error."); return; } - + if (sinkManagerObj_ == nullptr) { + DHLOGE("sinkManagerObj is null."); + return; + } std::vector devDhIds; SplitStringToVector(strDhids, INPUT_STRING_SPLIT_POINT, devDhIds); DInputSinkState::GetInstance().RecordDhIds(devDhIds, DhIdState::THROUGH_OUT, sessionId); @@ -299,6 +319,10 @@ void DistributedInputSinkManager::DInputSinkListener::OnStopRemoteInputDhid(cons const std::string &strDhids) { DHLOGI("OnStopRemoteInputDhid called, sessionId: %{public}d", sessionId); + if (sinkManagerObj_ == nullptr) { + DHLOGE("sinkManagerObj is null."); + return; + } std::vector stopIndeedDhIds; std::vector stopOnCmdDhIds; SplitStringToVector(strDhids, INPUT_STRING_SPLIT_POINT, stopOnCmdDhIds); @@ -353,7 +377,10 @@ void DistributedInputSinkManager::DInputSinkListener::OnRelayStartDhidRemoteInpu DHLOGE("StartSwitch error."); return; } - + if (sinkManagerObj_ == nullptr) { + DHLOGE("sinkManagerObj is null."); + return; + } std::vector devDhIds; SplitStringToVector(strDhids, INPUT_STRING_SPLIT_POINT, devDhIds); DInputSinkState::GetInstance().RecordDhIds(devDhIds, DhIdState::THROUGH_OUT, toSinkSessionId); @@ -366,6 +393,10 @@ void DistributedInputSinkManager::DInputSinkListener::OnRelayStopDhidRemoteInput const int32_t &toSinkSessionId, const std::string &deviceId, const std::string &strDhids) { DHLOGI("onRelayStopDhidRemoteInput called, toSinkSessionId: %{public}d", toSinkSessionId); + if (sinkManagerObj_ == nullptr) { + DHLOGE("sinkManagerObj is null."); + return; + } std::vector stopIndeedDhIds; std::vector stopOnCmdDhIds; SplitStringToVector(strDhids, INPUT_STRING_SPLIT_POINT, stopOnCmdDhIds); @@ -408,6 +439,10 @@ void DistributedInputSinkManager::DInputSinkListener::OnRelayStartTypeRemoteInpu const int32_t &toSinkSessionId, const std::string &deviceId, uint32_t inputTypes) { DHLOGI("OnRelayStartTypeRemoteInput called, toSinkSessionId: %{public}d", toSinkSessionId); + if (sinkManagerObj_ == nullptr) { + DHLOGE("sinkManagerObj is null."); + return; + } // set new session int32_t startRes = DistributedInputSinkSwitch::GetInstance().StartSwitch(toSinkSessionId); @@ -457,6 +492,10 @@ void DistributedInputSinkManager::DInputSinkListener::OnRelayStartTypeRemoteInpu void DistributedInputSinkManager::DInputSinkListener::OnRelayStopTypeRemoteInput(const int32_t &toSrcSessionId, const int32_t &toSinkSessionId, const std::string &deviceId, uint32_t inputTypes) { + if (sinkManagerObj_ == nullptr) { + DHLOGE("sinkManagerObj is null."); + return; + } DHLOGI("OnRelayStopTypeRemoteInput called, sessionId: %{public}d, inputTypes: %{public}d, curInputType: %{public}d", toSinkSessionId, inputTypes, sinkManagerObj_->GetInputTypes()); @@ -545,6 +584,10 @@ void DistributedInputSinkManager::OnStart() DHLOGE("failed to init service."); return; } + if (runner_ == nullptr) { + DHLOGE("runner_ is nullptr."); + return; + } serviceRunningState_ = ServiceSinkRunningState::STATE_RUNNING; runner_->Run(); @@ -762,6 +805,10 @@ void DistributedInputSinkManager::ProjectWindowListener::OnMessage(const DHTopic } sptr dScreenSinkSA = DInputContext::GetInstance().GetRemoteObject( DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID); + if (dScreenSinkSA == nullptr) { + DHLOGE("dScreenSinkSA is nullptr"); + return; + } sptr dScreenSinkDeathRecipient(new(std::nothrow) DScreenSinkSvrRecipient(srcDeviceId, srcWinId)); dScreenSinkSA->AddDeathRecipient(dScreenSinkDeathRecipient); @@ -837,7 +884,7 @@ int32_t DistributedInputSinkManager::ProjectWindowListener::UpdateSinkScreenInfo sinkScreenInfo.sinkPhyWidth, sinkScreenInfo.sinkPhyHeight); int32_t ret = DInputContext::GetInstance().UpdateSinkScreenInfo(srcScreenInfoKey, sinkScreenInfo); std::lock_guard lock(sinkManagerObj_->mutex_); - if ((ret == DH_SUCCESS) && (sinkManagerObj_->GetSinkScreenInfosCbackSize() > 0)) { + if ((ret == DH_SUCCESS) && (sinkManagerObj_ != nullptr) && (sinkManagerObj_->GetSinkScreenInfosCbackSize() > 0)) { sinkManagerObj_->CallBackScreenInfoChange(); } return ret; @@ -964,7 +1011,8 @@ void DistributedInputSinkManager::CleanExceptionalInfo(const SrcScreenInfo &srcS auto srcInfo = sinkInfo.srcScreenInfo; if ((std::strcmp(srcInfo.uuid.c_str(), uuid.c_str()) == 0) && (srcInfo.sessionId != sessionId)) { DInputContext::GetInstance().RemoveSinkScreenInfo(id); - DHLOGI("CleanExceptionalInfo screenInfoKey: %{public}s, sessionId: %{public}d", id.c_str(), sessionId); + DHLOGI("CleanExceptionalInfo screenInfoKey: %{public}s, sessionId: %{public}d", + GetAnonyString(id).c_str(), sessionId); } } } @@ -997,7 +1045,7 @@ int32_t DistributedInputSinkManager::Dump(int32_t fd, const std::vectorInit(); uint64_t tokenId; const char *perms[2]; @@ -88,18 +89,21 @@ int32_t DistributedInputSinkManagerTest::TestSharingDhIdListenerStub::OnNoSharin HWTEST_F(DistributedInputSinkManagerTest, InitAuto, testing::ext::TestSize.Level0) { + ASSERT_NE(nullptr, sinkManager_); bool ret = sinkManager_->InitAuto(); EXPECT_EQ(true, ret); } HWTEST_F(DistributedInputSinkManagerTest, Init, testing::ext::TestSize.Level0) { + ASSERT_NE(nullptr, sinkManager_); int32_t ret = sinkManager_->Init(); EXPECT_EQ(DH_SUCCESS, ret); } HWTEST_F(DistributedInputSinkManagerTest, Release, testing::ext::TestSize.Level0) { + ASSERT_NE(nullptr, sinkManager_); MockProcess::MockDinputProcess("dinput"); int32_t ret = sinkManager_->Release(); EXPECT_EQ(DH_SUCCESS, ret); @@ -107,6 +111,7 @@ HWTEST_F(DistributedInputSinkManagerTest, Release, testing::ext::TestSize.Level0 HWTEST_F(DistributedInputSinkManagerTest, GetStartTransFlag, testing::ext::TestSize.Level0) { + ASSERT_NE(nullptr, sinkManager_); DInputServerType flag = DInputServerType::SINK_SERVER_TYPE; sinkManager_->SetStartTransFlag(flag); DInputServerType retFlag = sinkManager_->GetStartTransFlag(); @@ -115,6 +120,7 @@ HWTEST_F(DistributedInputSinkManagerTest, GetStartTransFlag, testing::ext::TestS HWTEST_F(DistributedInputSinkManagerTest, GetInputTypes, testing::ext::TestSize.Level0) { + ASSERT_NE(nullptr, sinkManager_); uint32_t inputTypes = static_cast(DInputDeviceType::MOUSE); sinkManager_->SetInputTypes(inputTypes); uint32_t retType = sinkManager_->GetInputTypes(); @@ -123,6 +129,7 @@ HWTEST_F(DistributedInputSinkManagerTest, GetInputTypes, testing::ext::TestSize. HWTEST_F(DistributedInputSinkManagerTest, DeleteStopDhids01, testing::ext::TestSize.Level0) { + ASSERT_NE(nullptr, sinkManager_); int32_t sessionId = 1; std::vector stopDhIds; std::vector stopIndeedDhIds; @@ -138,12 +145,14 @@ HWTEST_F(DistributedInputSinkManagerTest, DeleteStopDhids01, testing::ext::TestS HWTEST_F(DistributedInputSinkManagerTest, GetSinkScreenInfosCbackSize01, testing::ext::TestSize.Level0) { + ASSERT_NE(nullptr, sinkManager_); uint32_t ret = sinkManager_->GetSinkScreenInfosCbackSize(); EXPECT_EQ(0, ret); } HWTEST_F(DistributedInputSinkManagerTest, RegisterGetSinkScreenInfosCallback_01, testing::ext::TestSize.Level1) { + ASSERT_NE(nullptr, sinkManager_); sptr callback(new TestGetSinkScreenInfosCb()); int32_t ret = sinkManager_->RegisterGetSinkScreenInfosCallback(callback); EXPECT_EQ(DH_SUCCESS, ret); @@ -151,6 +160,7 @@ HWTEST_F(DistributedInputSinkManagerTest, RegisterGetSinkScreenInfosCallback_01, HWTEST_F(DistributedInputSinkManagerTest, RegisterGetSinkScreenInfosCallback_02, testing::ext::TestSize.Level1) { + ASSERT_NE(nullptr, sinkManager_); sptr callback = nullptr; int32_t ret = sinkManager_->RegisterGetSinkScreenInfosCallback(callback); EXPECT_EQ(DH_SUCCESS, ret); @@ -158,6 +168,7 @@ HWTEST_F(DistributedInputSinkManagerTest, RegisterGetSinkScreenInfosCallback_02, HWTEST_F(DistributedInputSinkManagerTest, OnMessage_01, testing::ext::TestSize.Level1) { + ASSERT_NE(nullptr, sinkManager_); int32_t fd = 1; std::vector args; int32_t ret = sinkManager_->Dump(fd, args); @@ -171,6 +182,7 @@ HWTEST_F(DistributedInputSinkManagerTest, OnMessage_01, testing::ext::TestSize.L HWTEST_F(DistributedInputSinkManagerTest, ParseMessage_01, testing::ext::TestSize.Level1) { + ASSERT_NE(nullptr, sinkManager_); std::string message = ""; std::string srcDeviceId = ""; uint64_t srcWinId = 0; @@ -181,6 +193,7 @@ HWTEST_F(DistributedInputSinkManagerTest, ParseMessage_01, testing::ext::TestSiz HWTEST_F(DistributedInputSinkManagerTest, ParseMessage_02, testing::ext::TestSize.Level1) { + ASSERT_NE(nullptr, sinkManager_); std::string srcDevId = "umkyu1b165e1be98151891erbe8r91ev"; uint64_t srcWinId = 1; uint64_t sinkShowWinId = 1; @@ -204,6 +217,7 @@ HWTEST_F(DistributedInputSinkManagerTest, ParseMessage_02, testing::ext::TestSiz HWTEST_F(DistributedInputSinkManagerTest, ParseMessage_04, testing::ext::TestSize.Level1) { + ASSERT_NE(nullptr, sinkManager_); std::string srcDevId = "umkyu1b165e1be98151891erbe8r91ev"; SinkScreenInfo sinkScreenInfo; uint64_t srcWinId = 1; @@ -256,6 +270,7 @@ HWTEST_F(DistributedInputSinkManagerTest, ParseMessage_04, testing::ext::TestSiz HWTEST_F(DistributedInputSinkManagerTest, UpdateSinkScreenInfoCache_01, testing::ext::TestSize.Level1) { + ASSERT_NE(nullptr, sinkManager_); std::string srcDevId = "umkyu1b165e1be98151891erbe8r91ev"; uint64_t srcWinId = 1; SinkScreenInfo sinkScreenInfoTmp {2, 1860, 980, 200, 200}; @@ -265,6 +280,7 @@ HWTEST_F(DistributedInputSinkManagerTest, UpdateSinkScreenInfoCache_01, testing: HWTEST_F(DistributedInputSinkManagerTest, NotifyStopDScreen_01, testing::ext::TestSize.Level1) { + ASSERT_NE(nullptr, sinkManager_); std::string srcScreenInfoKey = ""; int32_t ret = sinkManager_->NotifyStopDScreen(srcScreenInfoKey); EXPECT_EQ(ERR_DH_INPUT_SERVER_SINK_SCREEN_INFO_IS_EMPTY, ret); @@ -272,6 +288,7 @@ HWTEST_F(DistributedInputSinkManagerTest, NotifyStopDScreen_01, testing::ext::Te HWTEST_F(DistributedInputSinkManagerTest, NotifyStopDScreen_02, testing::ext::TestSize.Level1) { + ASSERT_NE(nullptr, sinkManager_); std::string srcScreenInfoKey = "srcScreenInfoKey_test"; int32_t ret = sinkManager_->NotifyStopDScreen(srcScreenInfoKey); EXPECT_EQ(DH_SUCCESS, ret); @@ -279,6 +296,7 @@ HWTEST_F(DistributedInputSinkManagerTest, NotifyStopDScreen_02, testing::ext::Te HWTEST_F(DistributedInputSinkManagerTest, RegisterSharingDhIdListener_01, testing::ext::TestSize.Level1) { + ASSERT_NE(nullptr, sinkManager_); sptr sharingDhIdListener = new TestSharingDhIdListenerStub(); int32_t ret = sinkManager_->RegisterSharingDhIdListener(sharingDhIdListener); EXPECT_EQ(DH_SUCCESS, ret); @@ -286,6 +304,7 @@ HWTEST_F(DistributedInputSinkManagerTest, RegisterSharingDhIdListener_01, testin HWTEST_F(DistributedInputSinkManagerTest, Dump_01, testing::ext::TestSize.Level1) { + ASSERT_NE(nullptr, sinkManager_); int32_t fd = 1; std::vector args; int32_t ret = sinkManager_->Dump(fd, args); diff --git a/services/sink/transport/src/distributed_input_sink_transport.cpp b/services/sink/transport/src/distributed_input_sink_transport.cpp index 17c560026c6c59d334fcc409d38b941348236b3e..5b5374937f2a65c8087a2f0a556d0ade443e04fc 100644 --- a/services/sink/transport/src/distributed_input_sink_transport.cpp +++ b/services/sink/transport/src/distributed_input_sink_transport.cpp @@ -71,6 +71,10 @@ DistributedInputSinkTransport &DistributedInputSinkTransport::GetInstance() void DistributedInputSinkTransport::DInputSinkEventHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) { + if (event == nullptr) { + DHLOGE("event is nullptr."); + return; + } EHandlerMsgType eventId = static_cast(event->GetInnerEventId()); switch (eventId) { case EHandlerMsgType::DINPUT_SINK_EVENT_HANDLER_MSG: { @@ -333,6 +337,10 @@ void DistributedInputSinkTransport::NotifyPrepareRemoteInput(int32_t sessionId, std::string deviceId = recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID]; DHLOGI("OnBytesReceived cmdType is TRANS_SOURCE_MSG_PREPARE deviceId:%{public}s.", GetAnonyString(deviceId).c_str()); + if (callback_ == nullptr) { + DHLOGE("callback_ is nullptr."); + return; + } callback_->OnPrepareRemoteInput(sessionId, deviceId); } @@ -345,6 +353,10 @@ void DistributedInputSinkTransport::NotifyUnprepareRemoteInput(int32_t sessionId std::string deviceId = recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID]; DHLOGI("OnBytesReceived cmdType TRANS_SOURCE_MSG_UNPREPARE deviceId:%{public}s.", GetAnonyString(deviceId).c_str()); + if (callback_ == nullptr) { + DHLOGE("callback_ is nullptr."); + return; + } callback_->OnUnprepareRemoteInput(sessionId); } @@ -359,6 +371,10 @@ void DistributedInputSinkTransport::NotifyStartRemoteInput(int32_t sessionId, co uint32_t inputTypes = recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE]; DHLOGI("OnBytesRecei,ved cmdType is TRANS_SOURCE_MSG_START_TYPE deviceId:%{public}s inputTypes:%{public}d .", GetAnonyString(deviceId).c_str(), inputTypes); + if (callback_ == nullptr) { + DHLOGE("callback_ is nullptr."); + return; + } callback_->OnStartRemoteInput(sessionId, inputTypes); } @@ -373,6 +389,10 @@ void DistributedInputSinkTransport::NotifyStopRemoteInput(int32_t sessionId, con uint32_t inputTypes = recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE]; DHLOGI("OnBytesReceived cmdType is TRANS_SOURCE_MSG_STOP_TYPE deviceId:%{public}s.", GetAnonyString(deviceId).c_str()); + if (callback_ == nullptr) { + DHLOGE("callback_ is nullptr."); + return; + } callback_->OnStopRemoteInput(sessionId, inputTypes); } @@ -401,6 +421,10 @@ void DistributedInputSinkTransport::NotifyStartRemoteInputDhid(int32_t sessionId std::string strTmp = recMsg[DINPUT_SOFTBUS_KEY_VECTOR_DHID]; DHLOGI("OnBytesReceived cmdType is TRANS_SOURCE_MSG_START_DHID deviceId:%{public}s .", GetAnonyString(deviceId).c_str()); + if (callback_ == nullptr) { + DHLOGE("callback_ is nullptr."); + return; + } callback_->OnStartRemoteInputDhid(sessionId, strTmp); } @@ -415,6 +439,10 @@ void DistributedInputSinkTransport::NotifyStopRemoteInputDhid(int32_t sessionId, std::string strTmp = recMsg[DINPUT_SOFTBUS_KEY_VECTOR_DHID]; DHLOGE("OnBytesReceived cmdType is TRANS_SOURCE_MSG_STOP_DHID deviceId:%{public}s.", GetAnonyString(deviceId).c_str()); + if (callback_ == nullptr) { + DHLOGE("callback_ is nullptr."); + return; + } callback_->OnStopRemoteInputDhid(sessionId, strTmp); } @@ -429,6 +457,10 @@ void DistributedInputSinkTransport::NotifyRelayPrepareRemoteInput(int32_t sessio int32_t toSrcSessionId = recMsg[DINPUT_SOFTBUS_KEY_SESSION_ID]; DHLOGI("OnBytesReceived cmdType is TRANS_SOURCE_MSG_PREPARE_FOR_REL deviceId:%{public}s.", GetAnonyString(deviceId).c_str()); + if (callback_ == nullptr) { + DHLOGE("callback_ is nullptr."); + return; + } callback_->OnRelayPrepareRemoteInput(toSrcSessionId, sessionId, deviceId); } @@ -443,6 +475,10 @@ void DistributedInputSinkTransport::NotifyRelayUnprepareRemoteInput(int32_t sess int32_t toSrcSessionId = recMsg[DINPUT_SOFTBUS_KEY_SESSION_ID]; DHLOGI("OnBytesReceived cmdType is TRANS_SOURCE_MSG_UNPREPARE_FOR_REL deviceId:%{public}s.", GetAnonyString(deviceId).c_str()); + if (callback_ == nullptr) { + DHLOGE("callback_ is nullptr."); + return; + } callback_->OnRelayUnprepareRemoteInput(toSrcSessionId, sessionId, deviceId); } @@ -459,6 +495,10 @@ void DistributedInputSinkTransport::NotifyRelayStartDhidRemoteInput(int32_t sess std::string dhids = recMsg[DINPUT_SOFTBUS_KEY_VECTOR_DHID]; DHLOGI("OnBytesReceived cmdType is TRANS_SOURCE_MSG_START_DHID_FOR_REL deviceId:%{public}s.", GetAnonyString(deviceId).c_str()); + if (callback_ == nullptr) { + DHLOGE("callback_ is nullptr."); + return; + } callback_->OnRelayStartDhidRemoteInput(toSrcSessionId, sessionId, deviceId, dhids); } @@ -475,6 +515,10 @@ void DistributedInputSinkTransport::NotifyRelayStopDhidRemoteInput(int32_t sessi std::string dhids = recMsg[DINPUT_SOFTBUS_KEY_VECTOR_DHID]; DHLOGI("OnBytesReceived cmdType is TRANS_SOURCE_MSG_STOP_DHID_FOR_REL deviceId:%{public}s.", GetAnonyString(deviceId).c_str()); + if (callback_ == nullptr) { + DHLOGE("callback_ is nullptr."); + return; + } callback_->OnRelayStopDhidRemoteInput(toSrcSessionId, sessionId, deviceId, dhids); } @@ -491,6 +535,10 @@ void DistributedInputSinkTransport::NotifyRelayStartTypeRemoteInput(int32_t sess uint32_t inputTypes = recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE]; DHLOGI("OnBytesReceived cmdType is TRANS_SOURCE_MSG_START_TYPE_FOR_REL deviceId:%{public}s.", GetAnonyString(deviceId).c_str()); + if (callback_ == nullptr) { + DHLOGE("callback_ is nullptr."); + return; + } callback_->OnRelayStartTypeRemoteInput(toSrcSessionId, sessionId, deviceId, inputTypes); } @@ -507,6 +555,10 @@ void DistributedInputSinkTransport::NotifyRelayStopTypeRemoteInput(int32_t sessi uint32_t inputTypes = recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE]; DHLOGI("OnBytesReceived cmdType is TRANS_SOURCE_MSG_STOP_TYPE_FOR_REL deviceId:%{public}s.", GetAnonyString(deviceId).c_str()); + if (callback_ == nullptr) { + DHLOGE("callback_ is nullptr."); + return; + } callback_->OnRelayStopTypeRemoteInput(toSrcSessionId, sessionId, deviceId, inputTypes); } diff --git a/services/transportbase/src/distributed_input_transport_base.cpp b/services/transportbase/src/distributed_input_transport_base.cpp index ad8a335471226f235cfdfdb62effb286879e57e3..3b841fdb7f7339b52ca54496ce9ec3233112607d 100644 --- a/services/transportbase/src/distributed_input_transport_base.cpp +++ b/services/transportbase/src/distributed_input_transport_base.cpp @@ -31,7 +31,6 @@ #include "dinput_softbus_define.h" #include "dinput_utils_tool.h" #include "hidumper.h" - #include "softbus_common.h" namespace OHOS { diff --git a/sinkhandler/test/unittest/mock/mock_distributed_input_client.cpp b/sinkhandler/test/unittest/mock/mock_distributed_input_client.cpp index df24e9e67a4115df6254267683111f786c6f365f..44a15efdef56176bea1c27074e7490068878dd5a 100644 --- a/sinkhandler/test/unittest/mock/mock_distributed_input_client.cpp +++ b/sinkhandler/test/unittest/mock/mock_distributed_input_client.cpp @@ -33,11 +33,11 @@ DistributedInputClient &DistributedInputClient::GetInstance() void DistributedInputClient::RegisterDInputCb::OnResult( const std::string &devId, const std::string &dhId, const int32_t &status) { - auto iter = DistributedInputClient::GetInstance().dHardWareFwkRstInfos.begin(); - for (; iter != DistributedInputClient::GetInstance().dHardWareFwkRstInfos.end(); ++iter) { + auto iter = DistributedInputClient::GetInstance().dHardWareFwkRstInfos_.begin(); + for (; iter != DistributedInputClient::GetInstance().dHardWareFwkRstInfos_.end(); ++iter) { if (iter->devId == devId && iter->dhId == dhId) { iter->callback->OnRegisterResult(devId, dhId, status, ""); - DistributedInputClient::GetInstance().dHardWareFwkRstInfos.erase(iter); + DistributedInputClient::GetInstance().dHardWareFwkRstInfos_.erase(iter); return; } } @@ -46,11 +46,11 @@ void DistributedInputClient::RegisterDInputCb::OnResult( void DistributedInputClient::UnregisterDInputCb::OnResult( const std::string &devId, const std::string &dhId, const int32_t &status) { - auto iter = DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos.begin(); - for (; iter != DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos.end(); ++iter) { + auto iter = DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos_.begin(); + for (; iter != DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos_.end(); ++iter) { if (iter->devId == devId && iter->dhId == dhId) { iter->callback->OnUnregisterResult(devId, dhId, status, ""); - DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos.erase(iter); + DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos_.erase(iter); return; } } diff --git a/sourcehandler/test/unittest/mock/mock_distributed_input_client.cpp b/sourcehandler/test/unittest/mock/mock_distributed_input_client.cpp index ecf6c162a51ce8fa15f2f629efaf3c1986dffeee..7d97f9d10cca149920079577d57cbd22afeee0be 100644 --- a/sourcehandler/test/unittest/mock/mock_distributed_input_client.cpp +++ b/sourcehandler/test/unittest/mock/mock_distributed_input_client.cpp @@ -34,11 +34,11 @@ DistributedInputClient &DistributedInputClient::GetInstance() void DistributedInputClient::RegisterDInputCb::OnResult( const std::string &devId, const std::string &dhId, const int32_t &status) { - auto iter = DistributedInputClient::GetInstance().dHardWareFwkRstInfos.begin(); - for (; iter != DistributedInputClient::GetInstance().dHardWareFwkRstInfos.end(); ++iter) { + auto iter = DistributedInputClient::GetInstance().dHardWareFwkRstInfos_.begin(); + for (; iter != DistributedInputClient::GetInstance().dHardWareFwkRstInfos_.end(); ++iter) { if (iter->devId == devId && iter->dhId == dhId) { iter->callback->OnRegisterResult(devId, dhId, status, ""); - DistributedInputClient::GetInstance().dHardWareFwkRstInfos.erase(iter); + DistributedInputClient::GetInstance().dHardWareFwkRstInfos_.erase(iter); return; } } @@ -47,11 +47,11 @@ void DistributedInputClient::RegisterDInputCb::OnResult( void DistributedInputClient::UnregisterDInputCb::OnResult( const std::string &devId, const std::string &dhId, const int32_t &status) { - auto iter = DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos.begin(); - for (; iter != DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos.end(); ++iter) { + auto iter = DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos_.begin(); + for (; iter != DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos_.end(); ++iter) { if (iter->devId == devId && iter->dhId == dhId) { iter->callback->OnUnregisterResult(devId, dhId, status, ""); - DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos.erase(iter); + DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos_.erase(iter); return; } }