From 8168c35e1e224f34957c3e7420f646ff37e5ddd2 Mon Sep 17 00:00:00 2001 From: chen0088 Date: Sat, 6 Jul 2024 11:36:47 +0800 Subject: [PATCH] modify ptr Signed-off-by: chen0088 --- audiohandler/src/daudio_handler.cpp | 10 ++--- .../unittest/src/daudio_hidumper_test.cpp | 14 +++++- .../test/unittest/src/daudio_hitrace_test.cpp | 5 ++- .../audio_sink/src/daudio_sink_handler.cpp | 8 ++-- .../audio_sink/src/daudio_sink_proxy.cpp | 33 ++++++++++++++ .../audio_source/src/daudio_ipc_callback.cpp | 10 +++-- .../src/daudio_source_handler.cpp | 8 ++-- .../audio_source/src/daudio_source_proxy.cpp | 27 +++++++++++- .../src/daudio_sink_handler_test.cpp | 14 +++++- .../src/daudio_sink_proxy_test.cpp | 14 +++++- .../src/daudio_ipc_callback_test.cpp | 44 ++++++++++++++++++- .../src/daudio_source_proxy_test.cpp | 17 ++++++- .../audioclient/micclient/src/dmic_client.cpp | 1 + .../spkclient/src/dspeaker_client.cpp | 5 ++- .../micclient/src/dmic_client_test.cpp | 35 ++++++++++++++- .../spkclient/src/dspeaker_client_test.cpp | 29 +++++++++++- .../audiohdiproxy/src/daudio_hdi_handler.cpp | 13 +++--- .../src/daudio_hdi_handler_test.cpp | 21 +++++++++ .../src/daudio_manager_callback_test.cpp | 42 ++++++++++++++++++ 19 files changed, 321 insertions(+), 29 deletions(-) diff --git a/audiohandler/src/daudio_handler.cpp b/audiohandler/src/daudio_handler.cpp index 5accbe88..23220413 100644 --- a/audiohandler/src/daudio_handler.cpp +++ b/audiohandler/src/daudio_handler.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 @@ -116,12 +116,12 @@ std::vector DAudioHandler::RealQuery(const std::string &dataType) { auto audioSrv = AudioStandard::AudioSystemManager::GetInstance(); std::vector dhItemVec; - if (audioSrv == nullptr) { - DHLOGE("Unable to get audio system manager."); - return dhItemVec; - } + CHECK_AND_RETURN_RET_LOG(audioSrv == nullptr, dhItemVec, "Unable to get audio system manager."); auto audioDevices = audioSrv->GetDevices(AudioStandard::DeviceFlag::ALL_DEVICES_FLAG); for (auto dev : audioDevices) { + if (dev == nullptr) { + continue; + } auto dhId = audioSrv->GetPinValueFromType(dev->deviceType_, dev->deviceRole_); if (dhId != DEFAULT_RENDER_ID && dhId != DEFAULT_CAPTURE_ID) { continue; diff --git a/common/dfx_utils/test/unittest/src/daudio_hidumper_test.cpp b/common/dfx_utils/test/unittest/src/daudio_hidumper_test.cpp index 6fadd48b..1ae602bf 100644 --- a/common/dfx_utils/test/unittest/src/daudio_hidumper_test.cpp +++ b/common/dfx_utils/test/unittest/src/daudio_hidumper_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 @@ -42,6 +42,9 @@ void DAudioHidumperTest::TearDown() */ HWTEST_F(DAudioHidumperTest, Dump_001, TestSize.Level1) { + if (hidumper_ == nullptr) { + return; + } std::string result; std::vector args; EXPECT_EQ(true, hidumper_->Dump(args, result)); @@ -65,6 +68,9 @@ HWTEST_F(DAudioHidumperTest, Dump_001, TestSize.Level1) */ HWTEST_F(DAudioHidumperTest, GetSourceDevId_001, TestSize.Level1) { + if (hidumper_ == nullptr) { + return; + } std::string result = "123"; EXPECT_NE(HDF_SUCCESS, hidumper_->GetSourceDevId(result)); } @@ -77,6 +83,9 @@ HWTEST_F(DAudioHidumperTest, GetSourceDevId_001, TestSize.Level1) */ HWTEST_F(DAudioHidumperTest, GetSinkInfo_001, TestSize.Level1) { + if (hidumper_ == nullptr) { + return; + } std::string result = "123"; EXPECT_NE(HDF_SUCCESS, hidumper_->GetSinkInfo(result)); } @@ -89,6 +98,9 @@ HWTEST_F(DAudioHidumperTest, GetSinkInfo_001, TestSize.Level1) */ HWTEST_F(DAudioHidumperTest, StartDumpData_001, TestSize.Level1) { + if (hidumper_ == nullptr) { + return; + } std::string result = ""; EXPECT_EQ(HDF_SUCCESS, hidumper_->StartDumpData(result)); EXPECT_EQ(true, hidumper_->QueryDumpDataFlag()); diff --git a/common/dfx_utils/test/unittest/src/daudio_hitrace_test.cpp b/common/dfx_utils/test/unittest/src/daudio_hitrace_test.cpp index 53ee4722..3b06c2ef 100644 --- a/common/dfx_utils/test/unittest/src/daudio_hitrace_test.cpp +++ b/common/dfx_utils/test/unittest/src/daudio_hitrace_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 @@ -42,6 +42,9 @@ void DAudioHitraceTest::TearDown() */ HWTEST_F(DAudioHitraceTest, End_001, TestSize.Level1) { + if (hitrace_ == nullptr) { + return; + } std::string result = "123"; hitrace_->isFinished_ = false; hitrace_->End(); diff --git a/interfaces/inner_kits/native_cpp/audio_sink/src/daudio_sink_handler.cpp b/interfaces/inner_kits/native_cpp/audio_sink/src/daudio_sink_handler.cpp index d03625ab..59ec8812 100644 --- a/interfaces/inner_kits/native_cpp/audio_sink/src/daudio_sink_handler.cpp +++ b/interfaces/inner_kits/native_cpp/audio_sink/src/daudio_sink_handler.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 @@ -126,7 +126,7 @@ void DAudioSinkHandler::OnRemoteSinkSvrDied(const wptr &remote) CHECK_NULL_VOID(remoteObject); std::lock_guard lock(sinkProxyMutex_); - if (dAudioSinkProxy_ != nullptr) { + if ((dAudioSinkProxy_ != nullptr) && (dAudioSinkProxy_->AsObject() != nullptr)) { dAudioSinkProxy_->AsObject()->RemoveDeathRecipient(sinkSvrRecipient_); dAudioSinkProxy_ = nullptr; } @@ -136,7 +136,9 @@ void DAudioSinkHandler::FinishStartSA(const std::string ¶m, const sptr lock(sinkProxyMutex_); - remoteObject->AddDeathRecipient(sinkSvrRecipient_); + if (remoteObject != nullptr) { + remoteObject->AddDeathRecipient(sinkSvrRecipient_); + } dAudioSinkProxy_ = iface_cast(remoteObject); if ((dAudioSinkProxy_ == nullptr) || (!dAudioSinkProxy_->AsObject())) { DHLOGE("Failed to get daudio sink proxy."); diff --git a/interfaces/inner_kits/native_cpp/audio_sink/src/daudio_sink_proxy.cpp b/interfaces/inner_kits/native_cpp/audio_sink/src/daudio_sink_proxy.cpp index b150ebd7..b7c4bac8 100644 --- a/interfaces/inner_kits/native_cpp/audio_sink/src/daudio_sink_proxy.cpp +++ b/interfaces/inner_kits/native_cpp/audio_sink/src/daudio_sink_proxy.cpp @@ -34,6 +34,11 @@ int32_t DAudioSinkProxy::InitSink(const std::string ¶ms, const sptrAsObject())) { return ERR_DH_AUDIO_SA_WRITE_PARAM_FAIED; } @@ -52,6 +57,10 @@ int32_t DAudioSinkProxy::ReleaseSink() return ERR_DH_AUDIO_SA_WRITE_INTERFACE_TOKEN_FAILED; } + if (Remote() == nullptr) { + DHLOGE("remote service is null."); + return ERR_DH_AUDIO_NULLPTR; + } Remote()->SendRequest(static_cast(IDAudioSinkInterfaceCode::RELEASE_SINK), data, reply, option); int32_t ret = reply.ReadInt32(); return ret; @@ -72,6 +81,10 @@ int32_t DAudioSinkProxy::SubscribeLocalHardware(const std::string &dhId, const s return ERR_DH_AUDIO_SA_WRITE_PARAM_FAIED; } + if (Remote() == nullptr) { + DHLOGE("remote service is null."); + return ERR_DH_AUDIO_NULLPTR; + } Remote()->SendRequest(static_cast(IDAudioSinkInterfaceCode::SUBSCRIBE_LOCAL_HARDWARE), data, reply, option); int32_t ret = reply.ReadInt32(); @@ -93,6 +106,10 @@ int32_t DAudioSinkProxy::UnsubscribeLocalHardware(const std::string &dhId) return ERR_DH_AUDIO_SA_WRITE_PARAM_FAIED; } + if (Remote() == nullptr) { + DHLOGE("remote service is null."); + return ERR_DH_AUDIO_NULLPTR; + } Remote()->SendRequest(static_cast(IDAudioSinkInterfaceCode::UNSUBSCRIBE_LOCAL_HARDWARE), data, reply, option); int32_t ret = reply.ReadInt32(); @@ -116,6 +133,10 @@ void DAudioSinkProxy::DAudioNotify(const std::string &devId, const std::string & return; } + if (Remote() == nullptr) { + DHLOGE("remote service is null."); + return; + } Remote()->SendRequest(static_cast(IDAudioSinkInterfaceCode::DAUDIO_NOTIFY), data, reply, option); } @@ -132,6 +153,10 @@ int32_t DAudioSinkProxy::PauseDistributedHardware(const std::string &networkId) return ERR_DH_AUDIO_SA_WRITE_PARAM_FAIED; } + if (Remote() == nullptr) { + DHLOGE("remote service is null."); + return ERR_DH_AUDIO_NULLPTR; + } Remote()->SendRequest(static_cast(IDAudioSinkInterfaceCode::PAUSE_DISTRIBUTED_HARDWARE), data, reply, option); return reply.ReadInt32(); @@ -150,6 +175,10 @@ int32_t DAudioSinkProxy::ResumeDistributedHardware(const std::string &networkId) return ERR_DH_AUDIO_SA_WRITE_PARAM_FAIED; } + if (Remote() == nullptr) { + DHLOGE("remote service is null."); + return ERR_DH_AUDIO_NULLPTR; + } Remote()->SendRequest(static_cast(IDAudioSinkInterfaceCode::RESUME_DISTRIBUTED_HARDWARE), data, reply, option); return reply.ReadInt32(); @@ -168,6 +197,10 @@ int32_t DAudioSinkProxy::StopDistributedHardware(const std::string &networkId) return ERR_DH_AUDIO_SA_WRITE_PARAM_FAIED; } + if (Remote() == nullptr) { + DHLOGE("remote service is null."); + return ERR_DH_AUDIO_NULLPTR; + } Remote()->SendRequest(static_cast(IDAudioSinkInterfaceCode::STOP_DISTRIBUTED_HARDWARE), data, reply, option); return reply.ReadInt32(); diff --git a/interfaces/inner_kits/native_cpp/audio_source/src/daudio_ipc_callback.cpp b/interfaces/inner_kits/native_cpp/audio_source/src/daudio_ipc_callback.cpp index c5c86ca4..5b50e516 100644 --- a/interfaces/inner_kits/native_cpp/audio_source/src/daudio_ipc_callback.cpp +++ b/interfaces/inner_kits/native_cpp/audio_source/src/daudio_ipc_callback.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 @@ -40,7 +40,9 @@ int32_t DAudioIpcCallback::OnNotifyRegResult(const std::string &devId, const std auto iter = registerCallbackMap_.find(reqId); if (iter != registerCallbackMap_.end()) { std::string reduceDhId = AddDhIdPrefix(dhId); - iter->second->OnRegisterResult(devId, reduceDhId, status, resultData); + if (iter->second != nullptr) { + iter->second->OnRegisterResult(devId, reduceDhId, status, resultData); + } registerCallbackMap_.erase(reqId); return DH_SUCCESS; } @@ -63,7 +65,9 @@ int32_t DAudioIpcCallback::OnNotifyUnregResult(const std::string &devId, const s auto iter = unregisterCallbackMap_.find(reqId); if (iter != unregisterCallbackMap_.end()) { std::string reduceDhId = AddDhIdPrefix(dhId); - iter->second->OnUnregisterResult(devId, reduceDhId, status, resultData); + if (iter->second != nullptr) { + iter->second->OnUnregisterResult(devId, reduceDhId, status, resultData); + } unregisterCallbackMap_.erase(reqId); return DH_SUCCESS; } diff --git a/interfaces/inner_kits/native_cpp/audio_source/src/daudio_source_handler.cpp b/interfaces/inner_kits/native_cpp/audio_source/src/daudio_source_handler.cpp index d43861d1..d7a5c334 100644 --- a/interfaces/inner_kits/native_cpp/audio_source/src/daudio_source_handler.cpp +++ b/interfaces/inner_kits/native_cpp/audio_source/src/daudio_source_handler.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 @@ -178,7 +178,7 @@ void DAudioSourceHandler::OnRemoteSourceSvrDied(const wptr &remot return; } std::lock_guard lock(sourceProxyMutex_); - if (dAudioSourceProxy_ != nullptr) { + if ((dAudioSourceProxy_ != nullptr) && (dAudioSourceProxy_->AsObject() != nullptr)) { dAudioSourceProxy_->AsObject()->RemoveDeathRecipient(sourceSvrRecipient_); dAudioSourceProxy_ = nullptr; } @@ -188,7 +188,9 @@ void DAudioSourceHandler::FinishStartSA(const std::string ¶m, const sptr lock(sourceProxyMutex_); - remoteObject->AddDeathRecipient(sourceSvrRecipient_); + if (remoteObject != nullptr) { + remoteObject->AddDeathRecipient(sourceSvrRecipient_); + } dAudioSourceProxy_ = iface_cast(remoteObject); if ((dAudioSourceProxy_ == nullptr) || (!dAudioSourceProxy_->AsObject())) { DHLOGE("Failed to get daudio source proxy."); diff --git a/interfaces/inner_kits/native_cpp/audio_source/src/daudio_source_proxy.cpp b/interfaces/inner_kits/native_cpp/audio_source/src/daudio_source_proxy.cpp index 112eaec4..77fb57c8 100644 --- a/interfaces/inner_kits/native_cpp/audio_source/src/daudio_source_proxy.cpp +++ b/interfaces/inner_kits/native_cpp/audio_source/src/daudio_source_proxy.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 @@ -34,6 +34,11 @@ int32_t DAudioSourceProxy::InitSource(const std::string ¶ms, const sptrAsObject())) { return ERR_DH_AUDIO_SA_WRITE_PARAM_FAIED; } @@ -52,6 +57,10 @@ int32_t DAudioSourceProxy::ReleaseSource() return ERR_DH_AUDIO_SA_WRITE_INTERFACE_TOKEN_FAILED; } + if (Remote() == nullptr) { + DHLOGE("remote service is null."); + return ERR_DH_AUDIO_NULLPTR; + } Remote()->SendRequest(static_cast(IDAudioSourceInterfaceCode::RELEASE_SOURCE), data, reply, option); int32_t ret = reply.ReadInt32(); return ret; @@ -75,6 +84,10 @@ int32_t DAudioSourceProxy::RegisterDistributedHardware(const std::string &devId, return ERR_DH_AUDIO_SA_WRITE_PARAM_FAIED; } + if (Remote() == nullptr) { + DHLOGE("remote service is null."); + return ERR_DH_AUDIO_NULLPTR; + } Remote()->SendRequest(static_cast(IDAudioSourceInterfaceCode::REGISTER_DISTRIBUTED_HARDWARE), data, reply, option); int32_t ret = reply.ReadInt32(); @@ -98,6 +111,10 @@ int32_t DAudioSourceProxy::UnregisterDistributedHardware(const std::string &devI return ERR_DH_AUDIO_SA_WRITE_PARAM_FAIED; } + if (Remote() == nullptr) { + DHLOGE("remote service is null."); + return ERR_DH_AUDIO_NULLPTR; + } Remote()->SendRequest(static_cast(IDAudioSourceInterfaceCode::UNREGISTER_DISTRIBUTED_HARDWARE), data, reply, option); int32_t ret = reply.ReadInt32(); @@ -120,6 +137,10 @@ int32_t DAudioSourceProxy::ConfigDistributedHardware(const std::string &devId, c return ERR_DH_AUDIO_SA_WRITE_PARAM_FAIED; } + if (Remote() == nullptr) { + DHLOGE("remote service is null."); + return ERR_DH_AUDIO_NULLPTR; + } Remote()->SendRequest(static_cast(IDAudioSourceInterfaceCode::CONFIG_DISTRIBUTED_HARDWARE), data, reply, option); int32_t ret = reply.ReadInt32(); @@ -143,6 +164,10 @@ void DAudioSourceProxy::DAudioNotify(const std::string &devId, const std::string return; } + if (Remote() == nullptr) { + DHLOGE("remote service is null."); + return; + } Remote()->SendRequest(static_cast(IDAudioSourceInterfaceCode::DAUDIO_NOTIFY), data, reply, option); } diff --git a/interfaces/inner_kits/native_cpp/test/unittest/audiosinktest/src/daudio_sink_handler_test.cpp b/interfaces/inner_kits/native_cpp/test/unittest/audiosinktest/src/daudio_sink_handler_test.cpp index 9096ee44..f63ba62d 100644 --- a/interfaces/inner_kits/native_cpp/test/unittest/audiosinktest/src/daudio_sink_handler_test.cpp +++ b/interfaces/inner_kits/native_cpp/test/unittest/audiosinktest/src/daudio_sink_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 @@ -90,12 +90,18 @@ HWTEST_F(DAudioSinkHandlerTest, LocalHardware_003, TestSize.Level1) wptr remote = nullptr; DAudioSinkHandler::GetInstance().OnRemoteSinkSvrDied(remote); sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgr == nullptr) { + return; + } sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_AUDIO_SINK_SA_ID); sptr proxy(new DAudioSinkProxy(remoteObject)); wptr remoteobject (remoteObject); DAudioSinkHandler::GetInstance().OnRemoteSinkSvrDied(remoteobject); DAudioSinkHandler::GetInstance().sinkSvrRecipient_ = sptr( new DAudioSinkHandler::DAudioSinkSvrRecipient()); + if (DAudioSinkHandler::GetInstance().sinkSvrRecipient_ == nullptr) { + return; + } DAudioSinkHandler::GetInstance().sinkSvrRecipient_->OnRemoteDied(remoteobject); DAudioSinkHandler::GetInstance().sinkSvrRecipient_ = nullptr; DAudioSinkHandler::GetInstance().dAudioSinkProxy_ = proxy; @@ -132,6 +138,9 @@ HWTEST_F(DAudioSinkHandlerTest, LocalHardware_005, TestSize.Level1) int32_t ret = DAudioSinkHandler::GetInstance().PauseDistributedHardware(networkId); EXPECT_EQ(ERR_DH_AUDIO_SA_PROXY_NOT_INIT, ret); sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgr == nullptr) { + return; + } sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_AUDIO_SINK_SA_ID); sptr proxy(new DAudioSinkProxy(remoteObject)); DAudioSinkHandler::GetInstance().dAudioSinkProxy_ = proxy; @@ -153,6 +162,9 @@ HWTEST_F(DAudioSinkHandlerTest, LocalHardware_006, TestSize.Level1) EXPECT_EQ(ERR_DH_AUDIO_SA_PROXY_NOT_INIT, ret); EXPECT_EQ(ERR_DH_AUDIO_SA_PROXY_NOT_INIT, DAudioSinkHandler::GetInstance().StopDistributedHardware(networkId)); sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgr == nullptr) { + return; + } sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_AUDIO_SINK_SA_ID); sptr proxy(new DAudioSinkProxy(remoteObject)); DAudioSinkHandler::GetInstance().dAudioSinkProxy_ = proxy; diff --git a/interfaces/inner_kits/native_cpp/test/unittest/audiosinktest/src/daudio_sink_proxy_test.cpp b/interfaces/inner_kits/native_cpp/test/unittest/audiosinktest/src/daudio_sink_proxy_test.cpp index b22d2ec3..b4b7ae66 100644 --- a/interfaces/inner_kits/native_cpp/test/unittest/audiosinktest/src/daudio_sink_proxy_test.cpp +++ b/interfaces/inner_kits/native_cpp/test/unittest/audiosinktest/src/daudio_sink_proxy_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 @@ -54,6 +54,9 @@ void DAudioSinkProxyTest::TearDown(void) {} */ HWTEST_F(DAudioSinkProxyTest, SubscribeLocalHardware_001, TestSize.Level1) { + if (dAudioProxy == nullptr) { + return; + } const std::string dhId = "dhId"; const std::string param = "param"; int32_t ret = dAudioProxy->SubscribeLocalHardware(dhId, param); @@ -70,6 +73,9 @@ HWTEST_F(DAudioSinkProxyTest, SubscribeLocalHardware_001, TestSize.Level1) */ HWTEST_F(DAudioSinkProxyTest, SubscribeLocalHardware_002, TestSize.Level1) { + if (dAudioProxy == nullptr) { + return; + } size_t DAUDIO_MAX_DEVICE_ID_LEN = 101; size_t DAUDIO_LEGAL_DEVICE_ID_LEN = 10; std::string dhId; @@ -100,6 +106,9 @@ HWTEST_F(DAudioSinkProxyTest, SubscribeLocalHardware_002, TestSize.Level1) */ HWTEST_F(DAudioSinkProxyTest, InitSink_001, TestSize.Level1) { + if (dAudioProxy == nullptr) { + return; + } const std::string params = "params"; auto dAudioSinkIpcCallback = new DAudioSinkIpcCallback(); int32_t ret = dAudioProxy->InitSink(params, dAudioSinkIpcCallback); @@ -116,6 +125,9 @@ HWTEST_F(DAudioSinkProxyTest, InitSink_001, TestSize.Level1) */ HWTEST_F(DAudioSinkProxyTest, PauseDistributedHardware_001, TestSize.Level1) { + if (dAudioProxy == nullptr) { + return; + } std::string networkId = "123"; EXPECT_EQ(DH_SUCCESS, dAudioProxy->PauseDistributedHardware(networkId)); EXPECT_EQ(DH_SUCCESS, dAudioProxy->ResumeDistributedHardware(networkId)); diff --git a/interfaces/inner_kits/native_cpp/test/unittest/audiosourcetest/src/daudio_ipc_callback_test.cpp b/interfaces/inner_kits/native_cpp/test/unittest/audiosourcetest/src/daudio_ipc_callback_test.cpp index 7720407b..4d59ec80 100644 --- a/interfaces/inner_kits/native_cpp/test/unittest/audiosourcetest/src/daudio_ipc_callback_test.cpp +++ b/interfaces/inner_kits/native_cpp/test/unittest/audiosourcetest/src/daudio_ipc_callback_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 @@ -44,6 +44,9 @@ void DAudioIpcCallbackTest::TearDown(void) */ HWTEST_F(DAudioIpcCallbackTest, OnNotifyRegResult_001, TestSize.Level1) { + if (dAudioIpcCallback_ == nullptr) { + return; + } const std::string devId = "devId"; const std::string dhId = "dhId"; const std::string reqId = "reqIdReg"; @@ -64,6 +67,9 @@ HWTEST_F(DAudioIpcCallbackTest, OnNotifyRegResult_001, TestSize.Level1) */ HWTEST_F(DAudioIpcCallbackTest, OnNotifyRegResult_002, TestSize.Level1) { + if (dAudioIpcCallback_ == nullptr) { + return; + } const std::string devId = "devId"; const std::string dhId = "dhId"; const std::string reqId = "reqId"; @@ -81,6 +87,9 @@ HWTEST_F(DAudioIpcCallbackTest, OnNotifyRegResult_002, TestSize.Level1) */ HWTEST_F(DAudioIpcCallbackTest, OnNotifyRegResult_003, TestSize.Level1) { + if (dAudioIpcCallback_ == nullptr) { + return; + } size_t DAUDIO_MAX_DEVICE_ID_LEN = 101; size_t DAUDIO_LEGAL_DEVICE_ID_LEN = 10; std::string devId ; @@ -109,6 +118,9 @@ HWTEST_F(DAudioIpcCallbackTest, OnNotifyRegResult_003, TestSize.Level1) */ HWTEST_F(DAudioIpcCallbackTest, OnNotifyUnregResult_001, TestSize.Level1) { + if (dAudioIpcCallback_ == nullptr) { + return; + } const std::string devId = "devId"; const std::string dhId = "dhId"; const std::string reqId = "reqIdUnreg"; @@ -129,6 +141,9 @@ HWTEST_F(DAudioIpcCallbackTest, OnNotifyUnregResult_001, TestSize.Level1) */ HWTEST_F(DAudioIpcCallbackTest, OnNotifyUnregResult_002, TestSize.Level1) { + if (dAudioIpcCallback_ == nullptr) { + return; + } const std::string devId = "devId"; const std::string dhId = "dhId"; const std::string reqId = "reqId"; @@ -146,6 +161,9 @@ HWTEST_F(DAudioIpcCallbackTest, OnNotifyUnregResult_002, TestSize.Level1) */ HWTEST_F(DAudioIpcCallbackTest, OnNotifyUnregResult_003, TestSize.Level1) { + if (dAudioIpcCallback_ == nullptr) { + return; + } size_t DAUDIO_MAX_DEVICE_ID_LEN = 101; size_t DAUDIO_LEGAL_DEVICE_ID_LEN = 10; std::string devId ; @@ -174,6 +192,9 @@ HWTEST_F(DAudioIpcCallbackTest, OnNotifyUnregResult_003, TestSize.Level1) */ HWTEST_F(DAudioIpcCallbackTest, PushRegRegisterCallback_001, TestSize.Level1) { + if (dAudioIpcCallback_ == nullptr) { + return; + } const std::string reqId = "reqIdReg"; std::shared_ptr callback = std::make_shared(); int32_t sizeFront = dAudioIpcCallback_->registerCallbackMap_.size(); @@ -191,6 +212,9 @@ HWTEST_F(DAudioIpcCallbackTest, PushRegRegisterCallback_001, TestSize.Level1) */ HWTEST_F(DAudioIpcCallbackTest, PopRegRegisterCallback_001, TestSize.Level1) { + if (dAudioIpcCallback_ == nullptr) { + return; + } const std::string reqId = "reqId"; std::shared_ptr callback = std::make_shared(); dAudioIpcCallback_->PushRegisterCallback(reqId, callback); @@ -208,6 +232,9 @@ HWTEST_F(DAudioIpcCallbackTest, PopRegRegisterCallback_001, TestSize.Level1) */ HWTEST_F(DAudioIpcCallbackTest, PushUnregRegisterCallback_001, TestSize.Level1) { + if (dAudioIpcCallback_ == nullptr) { + return; + } const std::string reqId = "reqIdUnreg"; std::shared_ptr callback = std::make_shared(); int32_t sizeFront = dAudioIpcCallback_->unregisterCallbackMap_.size(); @@ -225,6 +252,9 @@ HWTEST_F(DAudioIpcCallbackTest, PushUnregRegisterCallback_001, TestSize.Level1) */ HWTEST_F(DAudioIpcCallbackTest, PopUnregRegisterCallback_001, TestSize.Level1) { + if (dAudioIpcCallback_ == nullptr) { + return; + } const std::string reqId = "reqId"; std::shared_ptr callback = std::make_shared(); dAudioIpcCallback_->PushUnregisterCallback(reqId, callback); @@ -242,6 +272,9 @@ HWTEST_F(DAudioIpcCallbackTest, PopUnregRegisterCallback_001, TestSize.Level1) */ HWTEST_F(DAudioIpcCallbackTest, OnHardwareStateChanged_001, TestSize.Level1) { + if (dAudioIpcCallback_ == nullptr) { + return; + } const std::string devId = "123"; const std::string dhId = "1"; int32_t status = 0; @@ -261,6 +294,9 @@ HWTEST_F(DAudioIpcCallbackTest, OnHardwareStateChanged_001, TestSize.Level1) */ HWTEST_F(DAudioIpcCallbackTest, OnHardwareStateChanged_002, TestSize.Level1) { + if (dAudioIpcCallback_ == nullptr) { + return; + } std::string devId = "123"; std::string dhId = "1"; size_t DAUDIO_MAX_DEVICE_ID_LEN = 101; @@ -285,6 +321,9 @@ HWTEST_F(DAudioIpcCallbackTest, OnHardwareStateChanged_002, TestSize.Level1) */ HWTEST_F(DAudioIpcCallbackTest, OnDataSyncTrigger_001, TestSize.Level1) { + if (dAudioIpcCallback_ == nullptr) { + return; + } const std::string devId = "123"; std::shared_ptr callback = std::make_shared(); dAudioIpcCallback_->RegisterTriggerListener(callback); @@ -301,6 +340,9 @@ HWTEST_F(DAudioIpcCallbackTest, OnDataSyncTrigger_001, TestSize.Level1) */ HWTEST_F(DAudioIpcCallbackTest, OnDataSyncTrigger_002, TestSize.Level1) { + if (dAudioIpcCallback_ == nullptr) { + return; + } size_t DAUDIO_MAX_DEVICE_ID_LEN = 101; size_t DAUDIO_LEGAL_DEVICE_ID_LEN = 10; std::string devId ; diff --git a/interfaces/inner_kits/native_cpp/test/unittest/audiosourcetest/src/daudio_source_proxy_test.cpp b/interfaces/inner_kits/native_cpp/test/unittest/audiosourcetest/src/daudio_source_proxy_test.cpp index 877dc1ef..321ef11c 100644 --- a/interfaces/inner_kits/native_cpp/test/unittest/audiosourcetest/src/daudio_source_proxy_test.cpp +++ b/interfaces/inner_kits/native_cpp/test/unittest/audiosourcetest/src/daudio_source_proxy_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 @@ -53,6 +53,9 @@ void DAudioSourceProxyTest::TearDown(void) {} */ HWTEST_F(DAudioSourceProxyTest, RegisterDistributedHardware_001, TestSize.Level1) { + if (dAudioProxy == nullptr) { + return; + } const std::string devId = "devId"; const std::string dhId = "dhId"; const std::string reqId = "reqId"; @@ -76,6 +79,9 @@ HWTEST_F(DAudioSourceProxyTest, RegisterDistributedHardware_001, TestSize.Level1 */ HWTEST_F(DAudioSourceProxyTest, RegisterDistributedHardware_002, TestSize.Level1) { + if (dAudioProxy == nullptr) { + return; + } size_t DAUDIO_MAX_DEVICE_ID_LEN = 101; std::string devId; devId.resize(DAUDIO_MAX_DEVICE_ID_LEN); @@ -99,6 +105,9 @@ HWTEST_F(DAudioSourceProxyTest, RegisterDistributedHardware_002, TestSize.Level1 */ HWTEST_F(DAudioSourceProxyTest, RegisterDistributedHardware_003, TestSize.Level1) { + if (dAudioProxy == nullptr) { + return; + } size_t DAUDIO_MAX_DEVICE_ID_LEN = 101; size_t DAUDIO_LEGAL_DEVICE_ID_LEN = 10; std::string devId; @@ -129,6 +138,9 @@ HWTEST_F(DAudioSourceProxyTest, RegisterDistributedHardware_003, TestSize.Level1 */ HWTEST_F(DAudioSourceProxyTest, ConfigDistributedHardware_001, TestSize.Level1) { + if (dAudioProxy == nullptr) { + return; + } const std::string devId = "devId"; const std::string dhId = "dhId"; const std::string key = "value"; @@ -146,6 +158,9 @@ HWTEST_F(DAudioSourceProxyTest, ConfigDistributedHardware_001, TestSize.Level1) */ HWTEST_F(DAudioSourceProxyTest, ConfigDistributedHardware_002, TestSize.Level1) { + if (dAudioProxy == nullptr) { + return; + } size_t DAUDIO_MAX_DEVICE_ID_LEN = 101; size_t DAUDIO_LEGAL_DEVICE_ID_LEN = 10; const int32_t eventType = 1; diff --git a/services/audioclient/micclient/src/dmic_client.cpp b/services/audioclient/micclient/src/dmic_client.cpp index 2e6b4137..c7a7605f 100644 --- a/services/audioclient/micclient/src/dmic_client.cpp +++ b/services/audioclient/micclient/src/dmic_client.cpp @@ -270,6 +270,7 @@ void DMicClient::AudioFwkCaptureData() } DumpFileUtil::WriteDumpFile(dumpFile_, static_cast(audioData->Data()), audioData->Size()); int64_t startTransTime = GetNowTimeUs(); + CHECK_NULL_VOID(micTrans_); int32_t ret = micTrans_->FeedAudioData(audioData); if (ret != DH_SUCCESS) { DHLOGE("Failed to send data."); diff --git a/services/audioclient/spkclient/src/dspeaker_client.cpp b/services/audioclient/spkclient/src/dspeaker_client.cpp index 8642c498..eac62d1d 100644 --- a/services/audioclient/spkclient/src/dspeaker_client.cpp +++ b/services/audioclient/spkclient/src/dspeaker_client.cpp @@ -131,7 +131,7 @@ void DSpeakerClient::OnWriteData(size_t length) DHLOGI("Pop spk data, dataQueue size: %{public}" PRIu64, queueSize); } } - if (audioData->Capacity() != bufDesc.bufLength) { + if ((audioData != nullptr) && (audioData->Capacity() != bufDesc.bufLength)) { uint64_t capacity = static_cast(audioData->Capacity()); uint64_t bufLength = static_cast(bufDesc.bufLength); DHLOGE("Audio data length is not equal to buflength. datalength: %{public}" PRIu64 @@ -287,6 +287,9 @@ void DSpeakerClient::PlayThreadRunning() uint64_t queueSize = static_cast(dataQueue_.size()); DHLOGD("Pop spk data, dataqueue size: %{public}" PRIu64, queueSize); } + if (audioData == nullptr) { + continue; + } DumpFileUtil::WriteDumpFile(dumpFile_, static_cast(audioData->Data()), audioData->Size()); int32_t writeOffSet = 0; while (writeOffSet < static_cast(audioData->Capacity())) { diff --git a/services/audioclient/test/unittest/micclient/src/dmic_client_test.cpp b/services/audioclient/test/unittest/micclient/src/dmic_client_test.cpp index 563992d9..d331540e 100644 --- a/services/audioclient/test/unittest/micclient/src/dmic_client_test.cpp +++ b/services/audioclient/test/unittest/micclient/src/dmic_client_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 @@ -54,6 +54,9 @@ void DMicClientTest::TearDown() */ HWTEST_F(DMicClientTest, InitSenderEngine_001, TestSize.Level1) { + if (micClient_ == nullptr) { + return; + } IAVEngineProvider *providerPtr = nullptr; auto message = std::make_shared(); micClient_->OnEngineTransMessage(message); @@ -68,6 +71,9 @@ HWTEST_F(DMicClientTest, InitSenderEngine_001, TestSize.Level1) */ HWTEST_F(DMicClientTest, OnStateChange_001, TestSize.Level1) { + if (micClient_ == nullptr) { + return; + } EXPECT_NE(DH_SUCCESS, micClient_->OnStateChange(AudioEventType::NOTIFY_OPEN_SPEAKER_RESULT)); } @@ -79,6 +85,9 @@ HWTEST_F(DMicClientTest, OnStateChange_001, TestSize.Level1) */ HWTEST_F(DMicClientTest, OnStateChange_002, TestSize.Level1) { + if (micClient_ == nullptr) { + return; + } EXPECT_EQ(DH_SUCCESS, micClient_->OnStateChange(AudioEventType::DATA_CLOSED)); } @@ -90,6 +99,9 @@ HWTEST_F(DMicClientTest, OnStateChange_002, TestSize.Level1) */ HWTEST_F(DMicClientTest, SetUp_001, TestSize.Level1) { + if (micClient_ == nullptr) { + return; + } std::string devId = "testID"; auto clientCallback = std::make_shared(); micClient_->SetAttrs(devId, clientCallback); @@ -106,6 +118,9 @@ HWTEST_F(DMicClientTest, SetUp_001, TestSize.Level1) */ HWTEST_F(DMicClientTest, StartCapture001, TestSize.Level1) { + if (micClient_ == nullptr) { + return; + } micClient_->CaptureThreadRunning(); EXPECT_NE(DH_SUCCESS, micClient_->StartCapture()); EXPECT_NE(DH_SUCCESS, micClient_->StopCapture()); @@ -142,6 +157,9 @@ HWTEST_F(DMicClientTest, StartCapture001, TestSize.Level1) */ HWTEST_F(DMicClientTest, StopCapture001, TestSize.Level1) { + if (micClient_ == nullptr) { + return; + } std::shared_ptr audioData = nullptr; EXPECT_NE(DH_SUCCESS, micClient_->StopCapture()); micClient_->clientStatus_ = STATUS_START; @@ -159,6 +177,9 @@ HWTEST_F(DMicClientTest, StopCapture001, TestSize.Level1) */ HWTEST_F(DMicClientTest, StopCapture002, TestSize.Level1) { + if (micClient_ == nullptr) { + return; + } micClient_->clientStatus_ = STATUS_START; EXPECT_EQ(ERR_DH_AUDIO_FAILED, micClient_->StopCapture()); micClient_->isCaptureReady_.store(true); @@ -175,6 +196,9 @@ HWTEST_F(DMicClientTest, StopCapture002, TestSize.Level1) */ HWTEST_F(DMicClientTest, Release001, TestSize.Level1) { + if (micClient_ == nullptr) { + return; + } micClient_->clientStatus_ = AudioStatus::STATUS_START; EXPECT_EQ(ERR_DH_AUDIO_SA_STATUS_ERR, micClient_->Release()); micClient_->clientStatus_ = AudioStatus::STATUS_STOP; @@ -213,6 +237,9 @@ HWTEST_F(DMicClientTest, Release001, TestSize.Level1) */ HWTEST_F(DMicClientTest, SendMessage_001, TestSize.Level1) { + if (micClient_ == nullptr) { + return; + } std::string content = "content"; std::string dstDevId = "dstDevId"; EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, micClient_->SendMessage(EVENT_UNKNOWN, content, dstDevId)); @@ -229,6 +256,9 @@ HWTEST_F(DMicClientTest, SendMessage_001, TestSize.Level1) */ HWTEST_F(DMicClientTest, AudioFwkClientSetUp_001, TestSize.Level1) { + if (micClient_ == nullptr) { + return; + } audioParam_.captureOpts.capturerFlags = MMAP_MODE; int32_t actual = micClient_->AudioFwkClientSetUp(); EXPECT_EQ(ERR_DH_AUDIO_CLIENT_CAPTURER_CREATE_FAILED, actual); @@ -245,6 +275,9 @@ HWTEST_F(DMicClientTest, AudioFwkClientSetUp_001, TestSize.Level1) */ HWTEST_F(DMicClientTest, TransSetUp_001, TestSize.Level1) { + if (micClient_ == nullptr) { + return; + } int32_t actual = micClient_->TransSetUp(); EXPECT_EQ(DH_SUCCESS, actual); micClient_->micTrans_ = nullptr; diff --git a/services/audioclient/test/unittest/spkclient/src/dspeaker_client_test.cpp b/services/audioclient/test/unittest/spkclient/src/dspeaker_client_test.cpp index 3258e9d3..61f18951 100644 --- a/services/audioclient/test/unittest/spkclient/src/dspeaker_client_test.cpp +++ b/services/audioclient/test/unittest/spkclient/src/dspeaker_client_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 @@ -58,6 +58,9 @@ void DSpeakerClientTest::TearDown() */ HWTEST_F(DSpeakerClientTest, InitReceiverEngine_001, TestSize.Level1) { + if (speakerClient_ == nullptr) { + return; + } IAVEngineProvider *providerPtr = nullptr; AVTransEvent event1 = { EventType::EVENT_START_SUCCESS, "", ""}; @@ -79,6 +82,9 @@ HWTEST_F(DSpeakerClientTest, InitReceiverEngine_001, TestSize.Level1) */ HWTEST_F(DSpeakerClientTest, OnStateChange_001, TestSize.Level1) { + if (speakerClient_ == nullptr) { + return; + } AudioStandard::VolumeEvent event; event.volume = 1; event.updateUi = 1; @@ -99,6 +105,9 @@ HWTEST_F(DSpeakerClientTest, OnStateChange_001, TestSize.Level1) */ HWTEST_F(DSpeakerClientTest, SetUp_001, TestSize.Level1) { + if (speakerClient_ == nullptr) { + return; + } AudioParam audioParam; EXPECT_EQ(DH_SUCCESS, speakerClient_->SetUp(audioParam)); EXPECT_EQ(DH_SUCCESS, speakerClient_->SetUp(audioParam_)); @@ -117,6 +126,9 @@ HWTEST_F(DSpeakerClientTest, SetUp_001, TestSize.Level1) */ HWTEST_F(DSpeakerClientTest, StartRender001, TestSize.Level1) { + if (speakerClient_ == nullptr) { + return; + } EXPECT_NE(DH_SUCCESS, speakerClient_->StartRender()); EXPECT_NE(DH_SUCCESS, speakerClient_->StopRender()); @@ -139,6 +151,9 @@ HWTEST_F(DSpeakerClientTest, StartRender001, TestSize.Level1) */ HWTEST_F(DSpeakerClientTest, StopRender001, TestSize.Level1) { + if (speakerClient_ == nullptr) { + return; + } EXPECT_NE(DH_SUCCESS, speakerClient_->StopRender()); std::string args = "args"; AudioEvent event; @@ -171,6 +186,9 @@ HWTEST_F(DSpeakerClientTest, StopRender001, TestSize.Level1) */ HWTEST_F(DSpeakerClientTest, OnDecodeTransDataDone001, TestSize.Level1) { + if (speakerClient_ == nullptr) { + return; + } std::shared_ptr audioData = nullptr; EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, speakerClient_->OnDecodeTransDataDone(audioData)); for (size_t i = 0; i < 11; i++) { @@ -189,6 +207,9 @@ HWTEST_F(DSpeakerClientTest, OnDecodeTransDataDone001, TestSize.Level1) */ HWTEST_F(DSpeakerClientTest, Release001, TestSize.Level1) { + if (speakerClient_ == nullptr) { + return; + } speakerClient_->speakerTrans_ = std::make_shared(); std::string args = "{\"ChangeType\":\"restart\"}"; speakerClient_->PlayStatusChange(args); @@ -206,6 +227,9 @@ HWTEST_F(DSpeakerClientTest, Release001, TestSize.Level1) */ HWTEST_F(DSpeakerClientTest, GetVolumeLevel_001, TestSize.Level1) { + if (speakerClient_ == nullptr) { + return; + } AudioStandard::InterruptEvent eventType = {static_cast(1), static_cast(0), static_cast(0)}; speakerClient_->OnInterrupt(eventType); @@ -222,6 +246,9 @@ HWTEST_F(DSpeakerClientTest, GetVolumeLevel_001, TestSize.Level1) */ HWTEST_F(DSpeakerClientTest, SendMessage_001, TestSize.Level1) { + if (speakerClient_ == nullptr) { + return; + } std::string content = "content"; std::string dstDevId = "dstDevId"; audioParam_.renderOpts.renderFlags = MMAP_MODE; diff --git a/services/audiohdiproxy/src/daudio_hdi_handler.cpp b/services/audiohdiproxy/src/daudio_hdi_handler.cpp index 49b46715..492cf58b 100644 --- a/services/audiohdiproxy/src/daudio_hdi_handler.cpp +++ b/services/audiohdiproxy/src/daudio_hdi_handler.cpp @@ -61,11 +61,12 @@ int32_t DAudioHdiHandler::InitHdiHandler() DHLOGE("Load hdf driver failed, ret: %{public}d", ret); return ret; } - DHLOGD("Load hdf driver end."); + DHLOGI("Load hdf driver end."); audioSrvHdf_ = IDAudioManager::Get(HDF_AUDIO_SERVICE_NAME.c_str(), false); CHECK_NULL_RETURN(audioSrvHdf_, ERR_DH_AUDIO_NULLPTR); remote_ = OHOS::HDI::hdi_objcast(audioSrvHdf_); + CHECK_NULL_RETURN(remote_, ERR_DH_AUDIO_NULLPTR); remote_->AddDeathRecipient(audioHdiRecipient_); DHLOGI("Init hdi handler success."); return DH_SUCCESS; @@ -123,10 +124,12 @@ int32_t DAudioHdiHandler::RegisterAudioDevice(const std::string &devId, const in } auto iter = mapAudioMgrCallback_.find(searchKey); - int32_t res = audioSrvHdf_->RegisterAudioDevice(devId, dhId, capability, iter->second); - if (res != HDF_SUCCESS) { - DHLOGE("Call hdf proxy register failed, res: %{public}d", res); - return ERR_DH_AUDIO_HDI_CALL_FAILED; + if (iter != mapAudioMgrCallback_.end()) { + int32_t res = audioSrvHdf_->RegisterAudioDevice(devId, dhId, capability, iter->second); + if (res != HDF_SUCCESS) { + DHLOGE("Call hdf proxy register failed, res: %{public}d", res); + return ERR_DH_AUDIO_HDI_CALL_FAILED; + } } return DH_SUCCESS; } diff --git a/services/audiohdiproxy/test/unittest/daudio_hdi_handler/src/daudio_hdi_handler_test.cpp b/services/audiohdiproxy/test/unittest/daudio_hdi_handler/src/daudio_hdi_handler_test.cpp index 4a2f6016..7c9461d4 100644 --- a/services/audiohdiproxy/test/unittest/daudio_hdi_handler/src/daudio_hdi_handler_test.cpp +++ b/services/audiohdiproxy/test/unittest/daudio_hdi_handler/src/daudio_hdi_handler_test.cpp @@ -41,6 +41,9 @@ void DAudioHdiHandlerTest::TearDown() */ HWTEST_F(DAudioHdiHandlerTest, InitHdiHandler_001, TestSize.Level1) { + if (hdiHandler_ == nullptr) { + return; + } EXPECT_EQ(HDF_SUCCESS, hdiHandler_->InitHdiHandler()); EXPECT_EQ(HDF_SUCCESS, hdiHandler_->InitHdiHandler()); // test repeated initialization } @@ -53,6 +56,9 @@ HWTEST_F(DAudioHdiHandlerTest, InitHdiHandler_001, TestSize.Level1) */ HWTEST_F(DAudioHdiHandlerTest, RegisterAudioDevice_001, TestSize.Level1) { + if (hdiHandler_ == nullptr) { + return; + } EXPECT_EQ(HDF_SUCCESS, hdiHandler_->InitHdiHandler()); hdiHandler_->audioSrvHdf_ = nullptr; std::shared_ptr callbackObjParam = std::make_shared(); @@ -74,6 +80,9 @@ HWTEST_F(DAudioHdiHandlerTest, RegisterAudioDevice_001, TestSize.Level1) */ HWTEST_F(DAudioHdiHandlerTest, RegisterAudioDevice_002, TestSize.Level1) { + if (hdiHandler_ == nullptr) { + return; + } EXPECT_EQ(HDF_SUCCESS, hdiHandler_->InitHdiHandler()); std::shared_ptr callbackObjParam = std::make_shared(); EXPECT_EQ(ERR_DH_AUDIO_HDI_CALL_FAILED, @@ -89,6 +98,9 @@ HWTEST_F(DAudioHdiHandlerTest, RegisterAudioDevice_002, TestSize.Level1) */ HWTEST_F(DAudioHdiHandlerTest, NotifyEvent_001, TestSize.Level1) { + if (hdiHandler_ == nullptr) { + return; + } EXPECT_EQ(HDF_SUCCESS, hdiHandler_->InitHdiHandler()); hdiHandler_->audioSrvHdf_ = nullptr; AudioEvent audioEvent; @@ -103,6 +115,9 @@ HWTEST_F(DAudioHdiHandlerTest, NotifyEvent_001, TestSize.Level1) */ HWTEST_F(DAudioHdiHandlerTest, NotifyEvent_002, TestSize.Level1) { + if (hdiHandler_ == nullptr) { + return; + } EXPECT_EQ(HDF_SUCCESS, hdiHandler_->InitHdiHandler()); hdiHandler_->audioSrvHdf_ = new MockIDAudioManager(); AudioEvent audioEvent1(AudioEventType::NOTIFY_OPEN_SPEAKER_RESULT, ""); @@ -135,6 +150,9 @@ HWTEST_F(DAudioHdiHandlerTest, NotifyEvent_002, TestSize.Level1) */ HWTEST_F(DAudioHdiHandlerTest, UnRegisterAudioDevice_001, TestSize.Level1) { + if (hdiHandler_ == nullptr) { + return; + } hdiHandler_->audioSrvHdf_ = nullptr; EXPECT_NE(HDF_SUCCESS, hdiHandler_->UnRegisterAudioDevice(devId_, dhId_)); } @@ -147,6 +165,9 @@ HWTEST_F(DAudioHdiHandlerTest, UnRegisterAudioDevice_001, TestSize.Level1) */ HWTEST_F(DAudioHdiHandlerTest, UnInitHdiHandler_001, TestSize.Level1) { + if (hdiHandler_ == nullptr) { + return; + } hdiHandler_->audioSrvHdf_ = nullptr; EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, hdiHandler_->UninitHdiHandler()); } diff --git a/services/audiohdiproxy/test/unittest/daudio_manager_callback/src/daudio_manager_callback_test.cpp b/services/audiohdiproxy/test/unittest/daudio_manager_callback/src/daudio_manager_callback_test.cpp index 9d0e3b38..89971f90 100644 --- a/services/audiohdiproxy/test/unittest/daudio_manager_callback/src/daudio_manager_callback_test.cpp +++ b/services/audiohdiproxy/test/unittest/daudio_manager_callback/src/daudio_manager_callback_test.cpp @@ -41,6 +41,9 @@ void DAudioManagerCallbackTest::TearDown() {} */ HWTEST_F(DAudioManagerCallbackTest, CreateStream_001, TestSize.Level1) { + if (manCallback_ == nullptr) { + return; + } manCallback_->callback_ = nullptr; EXPECT_EQ(HDF_FAILURE, manCallback_->CreateStream(streamId_)); } @@ -53,6 +56,9 @@ HWTEST_F(DAudioManagerCallbackTest, CreateStream_001, TestSize.Level1) */ HWTEST_F(DAudioManagerCallbackTest, CreateStream_002, TestSize.Level1) { + if (manCallback_ == nullptr) { + return; + } manCallback_->callback_ = std::make_shared(); EXPECT_EQ(HDF_SUCCESS, manCallback_->CreateStream(streamId_)); EXPECT_EQ(HDF_SUCCESS, manCallback_->DestroyStream(streamId_)); @@ -66,6 +72,9 @@ HWTEST_F(DAudioManagerCallbackTest, CreateStream_002, TestSize.Level1) */ HWTEST_F(DAudioManagerCallbackTest, DestroyStream_001, TestSize.Level1) { + if (manCallback_ == nullptr) { + return; + } manCallback_->callback_ = nullptr; EXPECT_EQ(HDF_FAILURE, manCallback_->DestroyStream(streamId_)); } @@ -78,6 +87,9 @@ HWTEST_F(DAudioManagerCallbackTest, DestroyStream_001, TestSize.Level1) */ HWTEST_F(DAudioManagerCallbackTest, DestroyStream_002, TestSize.Level1) { + if (manCallback_ == nullptr) { + return; + } manCallback_->callback_ = std::make_shared(); EXPECT_EQ(HDF_SUCCESS, manCallback_->CreateStream(streamId_)); EXPECT_EQ(HDF_SUCCESS, manCallback_->DestroyStream(streamId_)); @@ -91,6 +103,9 @@ HWTEST_F(DAudioManagerCallbackTest, DestroyStream_002, TestSize.Level1) */ HWTEST_F(DAudioManagerCallbackTest, SetParameters_001, TestSize.Level1) { + if (manCallback_ == nullptr) { + return; + } manCallback_->callback_ = std::make_shared(); EXPECT_EQ(HDF_SUCCESS, manCallback_->CreateStream(streamId_)); OHOS::HDI::DistributedAudio::Audioext::V2_0::AudioParameter param; @@ -107,6 +122,9 @@ HWTEST_F(DAudioManagerCallbackTest, SetParameters_001, TestSize.Level1) */ HWTEST_F(DAudioManagerCallbackTest, SetParameters_002, TestSize.Level1) { + if (manCallback_ == nullptr) { + return; + } manCallback_->callback_ = std::make_shared(); EXPECT_EQ(HDF_SUCCESS, manCallback_->CreateStream(streamId_)); OHOS::HDI::DistributedAudio::Audioext::V2_0::AudioParameter param = { @@ -160,6 +178,9 @@ HWTEST_F(DAudioManagerCallbackTest, SetParameters_002, TestSize.Level1) */ HWTEST_F(DAudioManagerCallbackTest, NotifyEvent_001, TestSize.Level1) { + if (manCallback_ == nullptr) { + return; + } manCallback_->callback_ = std::make_shared(); EXPECT_EQ(HDF_SUCCESS, manCallback_->CreateStream(streamId_)); manCallback_->callback_ = nullptr; @@ -176,6 +197,9 @@ HWTEST_F(DAudioManagerCallbackTest, NotifyEvent_001, TestSize.Level1) */ HWTEST_F(DAudioManagerCallbackTest, NotifyEvent_002, TestSize.Level1) { + if (manCallback_ == nullptr) { + return; + } manCallback_->callback_ = std::make_shared(); EXPECT_EQ(HDF_SUCCESS, manCallback_->CreateStream(streamId_)); OHOS::HDI::DistributedAudio::Audioext::V2_0::DAudioEvent event; @@ -220,6 +244,9 @@ HWTEST_F(DAudioManagerCallbackTest, NotifyEvent_002, TestSize.Level1) */ HWTEST_F(DAudioManagerCallbackTest, WriteStreamData_001, TestSize.Level1) { + if (manCallback_ == nullptr) { + return; + } manCallback_->callback_ = std::make_shared(); EXPECT_EQ(HDF_SUCCESS, manCallback_->CreateStream(streamId_)); manCallback_->callback_ = nullptr; @@ -236,6 +263,9 @@ HWTEST_F(DAudioManagerCallbackTest, WriteStreamData_001, TestSize.Level1) */ HWTEST_F(DAudioManagerCallbackTest, WriteStreamData_002, TestSize.Level1) { + if (manCallback_ == nullptr) { + return; + } manCallback_->callback_ = std::make_shared(); EXPECT_EQ(HDF_SUCCESS, manCallback_->CreateStream(streamId_)); OHOS::HDI::DistributedAudio::Audioext::V2_0::AudioData data; @@ -264,6 +294,9 @@ HWTEST_F(DAudioManagerCallbackTest, WriteStreamData_002, TestSize.Level1) */ HWTEST_F(DAudioManagerCallbackTest, ReadStreamData_001, TestSize.Level1) { + if (manCallback_ == nullptr) { + return; + } manCallback_->callback_ = std::make_shared(); EXPECT_EQ(HDF_SUCCESS, manCallback_->CreateStream(streamId_)); manCallback_->callback_ = nullptr; @@ -280,6 +313,9 @@ HWTEST_F(DAudioManagerCallbackTest, ReadStreamData_001, TestSize.Level1) */ HWTEST_F(DAudioManagerCallbackTest, ReadStreamData_002, TestSize.Level1) { + if (manCallback_ == nullptr) { + return; + } manCallback_->callback_ = std::make_shared(); EXPECT_EQ(HDF_SUCCESS, manCallback_->CreateStream(streamId_)); OHOS::HDI::DistributedAudio::Audioext::V2_0::AudioData data; @@ -305,6 +341,9 @@ HWTEST_F(DAudioManagerCallbackTest, ReadStreamData_002, TestSize.Level1) */ HWTEST_F(DAudioManagerCallbackTest, ReadMmapPosition_001, TestSize.Level1) { + if (manCallback_ == nullptr) { + return; + } int32_t streamId = 0; uint64_t frames = 1; OHOS::HDI::DistributedAudio::Audioext::V2_0::CurrentTime time; @@ -321,6 +360,9 @@ HWTEST_F(DAudioManagerCallbackTest, ReadMmapPosition_001, TestSize.Level1) */ HWTEST_F(DAudioManagerCallbackTest, RefreshAshmemInfo_001, TestSize.Level1) { + if (manCallback_ == nullptr) { + return; + } int32_t streamId = 1; int fd = 1; int32_t ashmemLength = 240; -- Gitee