From e85945190ca80585d3f32bd07317fbf0e5ed9021 Mon Sep 17 00:00:00 2001 From: li-tiangang4 Date: Wed, 24 Jul 2024 18:09:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=A3=80=E8=A7=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-tiangang4 --- common/include/dinput_errcode.h | 5 +- .../src/distributed_input_handler.cpp | 8 +++ .../ipc/src/distributed_input_client.cpp | 8 ++- .../ipc/src/distributed_input_sink_proxy.cpp | 4 ++ .../src/distributed_input_source_proxy.cpp | 64 +++++++++++++++++++ .../add_white_list_infos_call_back_test.cpp | 15 +++++ .../distributed_input_client_test.cpp | 4 ++ .../del_white_list_infos_call_back_test.cpp | 3 +- .../distributedinputstub_fuzzer.cpp | 51 +++++++++++++++ .../unprepare_d_input_call_back_test.cpp | 3 +- .../unregister_d_input_call_back_test.cpp | 3 +- .../src/distributed_input_collector.cpp | 8 +++ .../src/distributed_input_sink_manager.cpp | 62 ++++++++++++++++-- .../distributed_input_sinkmanager_test.cpp | 24 ++++++- .../src/distributed_input_sink_transport.cpp | 52 +++++++++++++++ 15 files changed, 300 insertions(+), 14 deletions(-) diff --git a/common/include/dinput_errcode.h b/common/include/dinput_errcode.h index 8cfa95c..a950bf0 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/src/distributed_input_handler.cpp b/inputdevicehandler/src/distributed_input_handler.cpp index 3beb137..7582ebc 100644 --- a/inputdevicehandler/src/distributed_input_handler.cpp +++ b/inputdevicehandler/src/distributed_input_handler.cpp @@ -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; @@ -229,6 +233,10 @@ void DistributedInputHandler::NotifyHardWare(int iCnt) void DistributedInputHandler::StopInputMonitorDeviceThread() { + if (inputHub_ == nullptr) { + DHLOGE("inputHub_ not initialized"); + return; + } isCollectingEvents_ = false; isStartCollectEventThread = false; inputHub_->StopCollectInputHandler(); diff --git a/interfaces/ipc/src/distributed_input_client.cpp b/interfaces/ipc/src/distributed_input_client.cpp index 280a68c..a1faa31 100644 --- a/interfaces/ipc/src/distributed_input_client.cpp +++ b/interfaces/ipc/src/distributed_input_client.cpp @@ -58,7 +58,7 @@ void DistributedInputClient::RegisterDInputCb::OnResult( DistributedInputClient::GetInstance().dHardWareFwkRstInfos.begin(); iter != DistributedInputClient::GetInstance().dHardWareFwkRstInfos.end(); ++iter) { - if (iter->devId == devId && iter->dhId == dhId) { + if (iter->devId == devId && iter->dhId == dhId && (iter->callback != nullptr)) { iter->callback->OnRegisterResult(devId, dhId, status, ""); DistributedInputClient::GetInstance().dHardWareFwkRstInfos.erase(iter); return; @@ -74,7 +74,7 @@ void DistributedInputClient::UnregisterDInputCb::OnResult( DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos.begin(); iter != DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos.end(); ++iter) { - if (iter->devId == devId && iter->dhId == dhId) { + if (iter->devId == devId && iter->dhId == dhId && (iter->callback != nullptr)) { iter->callback->OnUnregisterResult(devId, dhId, status, ""); DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos.erase(iter); return; @@ -125,6 +125,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) { diff --git a/interfaces/ipc/src/distributed_input_sink_proxy.cpp b/interfaces/ipc/src/distributed_input_sink_proxy.cpp index 6af28e2..12bebb2 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 8a848e9..ccd0aa1 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 744d50e..a91af41 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"; @@ -278,6 +284,7 @@ HWTEST_F(AddWhiteListInfosCallbackTest, RegisterDInputCallback01, testing::ext:: HWTEST_F(AddWhiteListInfosCallbackTest, SharingDhIdListenerStub01, testing::ext::TestSize.Level1) { sptr sharingStubPtr(new TestSharingDhIdListenerStub()); + ASSERT_NE(nullptr, sharingStubPtr); SharingDhIdListenerProxy sharingProxy(sharingStubPtr); std::string dhId = "dhId_test"; int32_t ret = sharingProxy.OnSharing(dhId); @@ -287,6 +294,7 @@ HWTEST_F(AddWhiteListInfosCallbackTest, SharingDhIdListenerStub01, testing::ext: HWTEST_F(AddWhiteListInfosCallbackTest, SharingDhIdListenerStub02, testing::ext::TestSize.Level1) { sptr sharingStubPtr(new TestSharingDhIdListenerStub()); + ASSERT_NE(nullptr, sharingStubPtr); SharingDhIdListenerProxy sharingProxy(sharingStubPtr); std::string dhId = "dhId_test"; int32_t ret = sharingProxy.OnNoSharing(dhId); @@ -296,6 +304,7 @@ HWTEST_F(AddWhiteListInfosCallbackTest, SharingDhIdListenerStub02, testing::ext: HWTEST_F(AddWhiteListInfosCallbackTest, SimulationEventListenerStub01, testing::ext::TestSize.Level1) { sptr simulationStubPtr(new TestSimulationEventListenerStub()); + ASSERT_NE(nullptr, simulationStubPtr); SimulationEventListenerProxy sharingProxy(simulationStubPtr); uint32_t type = 1; uint32_t code = 1; @@ -307,6 +316,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 +328,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 +340,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 +354,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 +368,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); @@ -366,6 +380,7 @@ HWTEST_F(AddWhiteListInfosCallbackTest, StopDInputCallbackStub01, testing::ext:: HWTEST_F(AddWhiteListInfosCallbackTest, DistributedInputSinkStub01, testing::ext::TestSize.Level1) { sptr sinkStubPtr(new TestDistributedInputSinkStub()); + ASSERT_NE(nullptr, sinkStubPtr); DistributedInputSinkProxy sinkProxy(sinkStubPtr); int32_t ret = sinkProxy.Init(); EXPECT_EQ(DH_SUCCESS, ret); diff --git a/interfaces/ipc/test/clientunittest/distributed_input_client_test.cpp b/interfaces/ipc/test/clientunittest/distributed_input_client_test.cpp index b1391ee..a98d360 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 383919d..1c75cc7 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 c87492c..d1f7e8f 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 8b00d2e..b9d8127 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 01c4e21..9782677 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/src/distributed_input_collector.cpp b/services/sink/inputcollector/src/distributed_input_collector.cpp index 3e0eaa6..c2e66c2 100644 --- a/services/sink/inputcollector/src/distributed_input_collector.cpp +++ b/services/sink/inputcollector/src/distributed_input_collector.cpp @@ -56,6 +56,10 @@ DistributedInputCollector &DistributedInputCollector::GetInstance() void DistributedInputCollector::PreInit() { DHLOGI("PreInit for record local device infos"); + if (inputHub_ == nullptr) { + DHLOGE("inputHub_ not initialized"); + return; + } inputHub_->RecordDeviceStates(); } @@ -101,6 +105,10 @@ void *DistributedInputCollector::CollectEventsThread(void *param) DHLOGE("CollectEventsThread setname failed."); } DistributedInputCollector *pThis = reinterpret_cast(param); + if (pThis == nullptr) { + DHLOGE("pThis is null."); + return nullptr; + } pThis->StartCollectEventsThread(); DHLOGW("DistributedInputCollector::CollectEventsThread exist!"); return nullptr; diff --git a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp index 8df9119..db6e65c 100644 --- a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp +++ b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp @@ -92,9 +92,11 @@ DistributedInputSinkManager::DInputSinkListener::DInputSinkListener(DistributedI DistributedInputSinkManager::DInputSinkListener::~DInputSinkListener() { - sinkManagerObj_->SetInputTypes(static_cast(DInputDeviceType::NONE)); - sinkManagerObj_ = nullptr; - DHLOGI("DInputSinkListener destory."); + if (sinkManagerObj_ != nullptr) { + sinkManagerObj_->SetInputTypes(static_cast(DInputDeviceType::NONE)); + sinkManagerObj_ = nullptr; + DHLOGI("DInputSinkListener destory."); + } } void DistributedInputSinkManager::QueryLocalWhiteList(nlohmann::json &jsonStr) @@ -129,6 +131,10 @@ void DistributedInputSinkManager::ClearResourcesStatus() void DistributedInputSinkManager::DInputSinkListener::OnPrepareRemoteInput( const int32_t &sessionId, const std::string &deviceId) { + if (sinkManagerObj_ == nullptr) { + DHLOGE("sinkManagerObj is null."); + return; + } DHLOGI("OnPrepareRemoteInput called, sessionId: %{public}d, devId: %{public}s", sessionId, GetAnonyString(deviceId).c_str()); nlohmann::json jsonStr; @@ -161,6 +167,10 @@ void DistributedInputSinkManager::DInputSinkListener::OnUnprepareRemoteInput(con void DistributedInputSinkManager::DInputSinkListener::OnRelayPrepareRemoteInput(const int32_t &toSrcSessionId, const int32_t &toSinkSessionId, const std::string &deviceId) { + if (sinkManagerObj_ == nullptr) { + DHLOGE("sinkManagerObj is null."); + return; + } DHLOGI("OnRelayPrepareRemoteInput called, toSinkSessionId: %{public}d, devId: %{public}s", toSinkSessionId, GetAnonyString(deviceId).c_str()); nlohmann::json jsonStr; @@ -197,6 +207,10 @@ void DistributedInputSinkManager::DInputSinkListener::OnRelayUnprepareRemoteInpu void DistributedInputSinkManager::DInputSinkListener::OnStartRemoteInput( const int32_t &sessionId, const uint32_t &inputTypes) { + if (sinkManagerObj_ == nullptr) { + DHLOGE("sinkManagerObj is null."); + return; + } DHLOGI("OnStartRemoteInput called, sessionId: %{public}d, inputTypes: %{public}u.", sessionId, inputTypes); // set new session int32_t startRes = DistributedInputSinkSwitch::GetInstance().StartSwitch(sessionId); @@ -237,6 +251,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 +304,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); @@ -298,6 +319,10 @@ void DistributedInputSinkManager::DInputSinkListener::OnStartRemoteInputDhid(con void DistributedInputSinkManager::DInputSinkListener::OnStopRemoteInputDhid(const int32_t &sessionId, const std::string &strDhids) { + if (sinkManagerObj_ == nullptr) { + DHLOGE("sinkManagerObj is null."); + return; + } DHLOGI("OnStopRemoteInputDhid called, sessionId: %{public}d", sessionId); std::vector stopIndeedDhIds; std::vector stopOnCmdDhIds; @@ -353,7 +378,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); @@ -395,6 +423,10 @@ void DistributedInputSinkManager::DInputSinkListener::OnRelayStopDhidRemoteInput DHLOGE("Not all devices are stopped."); return; } + if (sinkManagerObj_ == nullptr) { + DHLOGE("sinkManagerObj is null."); + return; + } DistributedInputSinkSwitch::GetInstance().StopAllSwitch(); sinkManagerObj_->SetInputTypes(static_cast(DInputDeviceType::NONE)); if (DistributedInputSinkSwitch::GetInstance().GetSwitchOpenedSession() == @@ -407,6 +439,10 @@ void DistributedInputSinkManager::DInputSinkListener::OnRelayStopDhidRemoteInput void DistributedInputSinkManager::DInputSinkListener::OnRelayStartTypeRemoteInput(const int32_t &toSrcSessionId, const int32_t &toSinkSessionId, const std::string &deviceId, uint32_t inputTypes) { + if (sinkManagerObj_ == nullptr) { + DHLOGE("sinkManagerObj is null."); + return; + } DHLOGI("OnRelayStartTypeRemoteInput called, toSinkSessionId: %{public}d", toSinkSessionId); // set new session int32_t startRes = DistributedInputSinkSwitch::GetInstance().StartSwitch(toSinkSessionId); @@ -457,6 +493,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 +585,10 @@ void DistributedInputSinkManager::OnStart() DHLOGE("failed to init service."); return; } + if (runner_ == nullptr) { + DHLOGE("runner_ is nullptr."); + return; + } serviceRunningState_ = ServiceSinkRunningState::STATE_RUNNING; runner_->Run(); @@ -764,6 +808,10 @@ void DistributedInputSinkManager::ProjectWindowListener::OnMessage(const DHTopic DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID); sptr dScreenSinkDeathRecipient(new(std::nothrow) DScreenSinkSvrRecipient(srcDeviceId, srcWinId)); + if (dScreenSinkSA == nullptr) { + DHLOGE("dScreenSinkSA is nullptr"); + return; + } dScreenSinkSA->AddDeathRecipient(dScreenSinkDeathRecipient); DInputContext::GetInstance().AddRemoteObject(DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID, dScreenSinkSA); } @@ -837,7 +885,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; @@ -997,7 +1045,7 @@ int32_t DistributedInputSinkManager::Dump(int32_t fd, const std::vectorInit(); + if (sinkManager_ != nullptr) { + sinkManager_->Init(); + } + uint64_t tokenId; const char *perms[2]; perms[0] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER; @@ -88,18 +91,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 +113,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 +122,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 +131,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 +147,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 +162,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 +170,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 +184,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 +195,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 +219,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 +272,8 @@ HWTEST_F(DistributedInputSinkManagerTest, ParseMessage_04, testing::ext::TestSiz HWTEST_F(DistributedInputSinkManagerTest, UpdateSinkScreenInfoCache_01, testing::ext::TestSize.Level1) { + ASSERT_NE(nullptr, sinkManager_); + ASSERT_NE(nullptr, sinkManager_->projectWindowListener_); std::string srcDevId = "umkyu1b165e1be98151891erbe8r91ev"; uint64_t srcWinId = 1; SinkScreenInfo sinkScreenInfoTmp {2, 1860, 980, 200, 200}; @@ -265,6 +283,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 +291,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 +299,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 +307,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 17c5600..5b53749 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); } -- Gitee