diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn index fcc2a5f1e232a0f43a02bded4b535401b7be33c5..23f55ba2dae64523ef2e63d3f7f97d8d1f425097 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn @@ -37,6 +37,8 @@ group("fuzztest") { "${services_path}/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sinkservicedump_fuzzer:fuzztest", "${services_path}/common/test/fuzztest/audiodatasetinit64_fuzzer:fuzztest", + "${services_path}/audiotransport/test/fuzztest/sinkctrltransonchannelevent_fuzzer:fuzztest", + "${services_path}/audiotransport/test/fuzztest/sourcectrltransonchannelevent_fuzzer:fuzztest", "onremotesinksvrdied_fuzzer:fuzztest", "onremotesourcesvrdied_fuzzer:fuzztest", "sinkhandlerfinishstartsa_fuzzer:fuzztest", diff --git a/services/audiomanager/managersink/include/daudio_sink_manager.h b/services/audiomanager/managersink/include/daudio_sink_manager.h deleted file mode 100644 index 439b5f0b35c6a0c87be9725cd682735d2b6cba74..0000000000000000000000000000000000000000 --- a/services/audiomanager/managersink/include/daudio_sink_manager.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_DAUDIO_SINK_MANAGER_H -#define OHOS_DAUDIO_SINK_MANAGER_H - -#include -#include - -#include "single_instance.h" -#include "device_manager.h" -#include "device_manager_callback.h" -#ifdef DEVICE_SECURITY_LEVEL_ENABLE -#include "device_security_defines.h" -#include "device_security_info.h" -#endif - -#include "daudio_ctrl_channel_listener.h" -#include "daudio_sink_dev.h" -#include "idaudio_source.h" -#include "idaudio_sink_ipc_callback.h" -#include "i_av_engine_provider_callback.h" - -namespace OHOS { -namespace DistributedHardware { -class EngineProviderListener : public IAVEngineProviderCallback { -public: - EngineProviderListener() {}; - ~EngineProviderListener() override {}; - - int32_t OnProviderEvent(const AVTransEvent &event) override; -}; - -class CtrlChannelListener : public CtrlChannelListenerCallback { -public: - CtrlChannelListener() {}; - ~CtrlChannelListener() override {}; - - void OnCtrlChannelEvent(const AVTransEvent &event) override; -}; - -class DeviceInitCallback : public DmInitCallback { - void OnRemoteDied() override; -}; - -class DAudioSinkManager { -DECLARE_SINGLE_INSTANCE_BASE(DAudioSinkManager); -public: - int32_t Init(const sptr &sinkCallback); - int32_t UnInit(); - int32_t HandleDAudioNotify(const std::string &devId, const std::string &dhId, const int32_t eventType, - const std::string &eventContent); - int32_t DAudioNotify(const std::string &devId, const std::string &dhId, const int32_t eventType, - const std::string &eventContent); - void OnSinkDevReleased(const std::string &devId); - void NotifyEvent(const std::string &devId, const int32_t eventType, const std::string &eventContent); - void ClearAudioDev(const std::string &devId); - int32_t CreateAudioDevice(const std::string &devId); - void SetChannelState(const std::string &content); - int32_t PauseDistributedHardware(const std::string &networkId); - int32_t ResumeDistributedHardware(const std::string &networkId); - int32_t StopDistributedHardware(const std::string &networkId); - void SetCallerTokenId(uint64_t tokenId); - -private: - DAudioSinkManager(); - ~DAudioSinkManager(); - int32_t LoadAVSenderEngineProvider(); - int32_t UnloadAVSenderEngineProvider(); - int32_t LoadAVReceiverEngineProvider(); - int32_t UnloadAVReceiverEngineProvider(); - bool CheckDeviceSecurityLevel(const std::string &srcDeviceId, const std::string &dstDeviceId); - int32_t GetDeviceSecurityLevel(const std::string &udid); - std::string GetUdidByNetworkId(const std::string &networkId); - int32_t VerifySecurityLevel(const std::string &devId); - int32_t InitAudioDevice(std::shared_ptr dev, const std::string &devId, bool isSpkOrMic); - -private: - static constexpr const char* DEVCLEAR_THREAD = "sinkClearTh"; - std::mutex devMapMutex_; - std::unordered_map> audioDevMap_; - std::mutex remoteSvrMutex_; - std::mutex ipcCallbackMutex_; - std::map> sourceServiceMap_; - std::thread devClearThread_; - std::string localNetworkId_; - ChannelState channelState_ = ChannelState::UNKNOWN; - - std::shared_ptr providerListener_; - std::shared_ptr ctrlListenerCallback_ = nullptr; - std::shared_ptr ctrlListener_ = nullptr; - IAVEngineProvider *sendProviderPtr_ = nullptr; - IAVEngineProvider *rcvProviderPtr_ = nullptr; - void *pSHandler_ = nullptr; - void *pRHandler_ = nullptr; - bool isSensitive_ = false; - bool isSameAccount_ = false; - bool isCheckSecLevel_ = false; - sptr ipcSinkCallback_ = nullptr; - std::shared_ptr initCallback_; - uint64_t callerTokenId_; -}; -} // DistributedHardware -} // OHOS -#endif // OHOS_DAUDIO_SINK_MANAGER_H diff --git a/services/audiomanager/managersource/include/daudio_source_manager.h b/services/audiomanager/managersource/include/daudio_source_manager.h index 53b1d3b93111d79336835db02f66b86d30f1aec4..d4dbda941af9e7505e0c1b27e448f25b4fa8215f 100644 --- a/services/audiomanager/managersource/include/daudio_source_manager.h +++ b/services/audiomanager/managersource/include/daudio_source_manager.h @@ -96,7 +96,7 @@ private: void *pSHandler_ = nullptr; void *pRHandler_ = nullptr; std::atomic isHicollieRunning_ = true; - uint64_t callerTokenId_; + uint64_t callerTokenId_ = 0; class SourceManagerHandler : public AppExecFwk::EventHandler { public: diff --git a/services/audiomanager/servicesink/BUILD.gn b/services/audiomanager/servicesink/BUILD.gn index 2b097064eaf304d5a0a9732926968296a867b641..d638cc47afbe37cb781633f9c6edd73d262d30c1 100755 --- a/services/audiomanager/servicesink/BUILD.gn +++ b/services/audiomanager/servicesink/BUILD.gn @@ -101,8 +101,6 @@ ohos_shared_library("distributed_audio_sink") { "hisysevent:libhisysevent", "hitrace:hitrace_meter", "ipc:ipc_core", - "os_account:libaccountkits", - "os_account:os_account_innerkits", "safwk:system_ability_fwk", "samgr:samgr_proxy", ] diff --git a/services/audiotransport/test/fuzztest/sinkctrltransonchannelevent_fuzzer/BUILD.gn b/services/audiotransport/test/fuzztest/sinkctrltransonchannelevent_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..60d4d41641943736bd39b4d10d8ece915cd666aa --- /dev/null +++ b/services/audiotransport/test/fuzztest/sinkctrltransonchannelevent_fuzzer/BUILD.gn @@ -0,0 +1,82 @@ +# Copyright (c) 2022 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../distributedaudio.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SinkCtrlTransOnChannelEventFuzzTest") { + module_out_path = "${distributedaudio_fuzz_path}/sinkctrltransonchannelevent_fuzzer" + fuzz_config_file = + "${services_path}/audiotransport/test/fuzztest/sinkctrltransonchannelevent_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "sinkctrltransonchannelevent_fuzzer.cpp" ] + + include_dirs = [ + "include", + "${audio_client_path}/interface", + "${audio_client_path}/micclient/include", + "${audio_client_path}/spkclient/include", + "${audio_control_path}/controlsink/include", + "${audio_processor_path}/interface", + "${audio_transport_path}/interface", + "${audio_transport_path}/audioctrltransport/include", + "${audio_transport_path}/receiverengine/include", + "${audio_transport_path}/senderengine/include", + "${common_path}/dfx_utils/include", + "${common_path}/include", + "${innerkits_path}/native_cpp/audio_sink/include", + "${innerkits_path}/native_cpp/audio_source/include", + "${services_path}/audiomanager/managersink/include", + "${services_path}/common/audioeventcallback", + "${services_path}/common/audiodata/include", + "${services_path}/common/audioparam", + ] + + deps =[ + "${services_path}/audiomanager/servicesink:distributed_audio_sink", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkServiceDumpFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] + + external_deps = [ + "c_utils:utils", + "cJSON:cjson", + "distributed_hardware_fwk:distributed_av_sender", + "distributed_hardware_fwk:distributedhardwareutils", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkCtrlTransOnChannelEventFuzzTest" ] +} +############################################################################### diff --git a/services/audiotransport/test/fuzztest/sinkctrltransonchannelevent_fuzzer/corpus/init b/services/audiotransport/test/fuzztest/sinkctrltransonchannelevent_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..8eb5a7d6eb6b7d71f0c70c244e5768d62bee6ac5 --- /dev/null +++ b/services/audiotransport/test/fuzztest/sinkctrltransonchannelevent_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2022 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/services/audiotransport/test/fuzztest/sinkctrltransonchannelevent_fuzzer/project.xml b/services/audiotransport/test/fuzztest/sinkctrltransonchannelevent_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/services/audiotransport/test/fuzztest/sinkctrltransonchannelevent_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiotransport/test/fuzztest/sinkctrltransonchannelevent_fuzzer/sinkservicedump_fuzzer.cpp b/services/audiotransport/test/fuzztest/sinkctrltransonchannelevent_fuzzer/sinkservicedump_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cc472e72320fa207c31bf9237f7f2692fc439adf --- /dev/null +++ b/services/audiotransport/test/fuzztest/sinkctrltransonchannelevent_fuzzer/sinkservicedump_fuzzer.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2022 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + #include + #include + + #include "av_trans_message.h" + #include "av_trans_types.h" + + #include + #include "daudio_sink_ctrl_trans.h" + #include "sinkctrltransonchannelevent.h" + + #include "dlfcn.h" + + #include "daudio_constants.h" + #include "daudio_errorcode.h" + #include "daudio_log.h" + #include "daudio_util.h" + +namespace OHOS { +namespace DistributedHardware { +void SinkCtrlTransOnChannelEventFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr || size == 0) { + return; + } + std::string devId = "devId"; + std::string sessionName = "sessionName"; + std::string peerSessName = "peerSessName"; + auto sinkCtrlTransCb = std::make_shared(); + auto ctrlTrans = DaudioSinkCtrlTrans(devId, sessionName, peerSessName, sinkCtrlTransCb); + FuzzedDataProvider fdp(data, size); + AVTransEvent event; + event.content = fdp.ConsumeRandomLengthString(); + event.peerDevId = fdp.ConsumeRandomLengthString(); + event.type = static_cast(fdp.ConsumeIntegral &message) override + { + (void)message; + } +}; +} +} +#endif \ No newline at end of file diff --git a/services/audiotransport/test/fuzztest/sourcectrltransonchannelevent_fuzzer/BUILD.gn b/services/audiotransport/test/fuzztest/sourcectrltransonchannelevent_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e5d21f1646c415580768dd255b2d51b606193ee8 --- /dev/null +++ b/services/audiotransport/test/fuzztest/sourcectrltransonchannelevent_fuzzer/BUILD.gn @@ -0,0 +1,82 @@ +# Copyright (c) 2022 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../distributedaudio.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SourceCtrlTransOnChannelEventFuzzTest") { + module_out_path = "${distributedaudio_fuzz_path}/sourcectrltransonchannelevent_fuzzer" + fuzz_config_file = + "${services_path}/audiotransport/test/fuzztest/sourcectrltransonchannelevent_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "sourcectrltransonchannelevent_fuzzer.cpp" ] + + include_dirs = [ + "include", + "${audio_client_path}/interface", + "${audio_client_path}/micclient/include", + "${audio_client_path}/spkclient/include", + "${audio_control_path}/controlsink/include", + "${audio_processor_path}/interface", + "${audio_transport_path}/interface", + "${audio_transport_path}/audioctrltransport/include", + "${audio_transport_path}/receiverengine/include", + "${audio_transport_path}/senderengine/include", + "${common_path}/dfx_utils/include", + "${common_path}/include", + "${innerkits_path}/native_cpp/audio_sink/include", + "${innerkits_path}/native_cpp/audio_source/include", + "${services_path}/audiomanager/managersink/include", + "${services_path}/common/audioeventcallback", + "${services_path}/common/audiodata/include", + "${services_path}/common/audioparam", + ] + + deps =[ + "${services_path}/audiomanager/servicesink:distributed_audio_sink", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkServiceDumpFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] + + external_deps = [ + "c_utils:utils", + "cJSON:cjson", + "distributed_hardware_fwk:distributed_av_sender", + "distributed_hardware_fwk:distributedhardwareutils", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SourceCtrlTransOnChannelEventFuzzTest" ] +} +############################################################################### diff --git a/services/audiotransport/test/fuzztest/sourcectrltransonchannelevent_fuzzer/corpus/init b/services/audiotransport/test/fuzztest/sourcectrltransonchannelevent_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..8eb5a7d6eb6b7d71f0c70c244e5768d62bee6ac5 --- /dev/null +++ b/services/audiotransport/test/fuzztest/sourcectrltransonchannelevent_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2022 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/services/audiotransport/test/fuzztest/sourcectrltransonchannelevent_fuzzer/project.xml b/services/audiotransport/test/fuzztest/sourcectrltransonchannelevent_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/services/audiotransport/test/fuzztest/sourcectrltransonchannelevent_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiotransport/test/fuzztest/sourcectrltransonchannelevent_fuzzer/sinkservicedump_fuzzer.cpp b/services/audiotransport/test/fuzztest/sourcectrltransonchannelevent_fuzzer/sinkservicedump_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3aa0f656d24f08cff29ea484eddff4d3e9fda7c0 --- /dev/null +++ b/services/audiotransport/test/fuzztest/sourcectrltransonchannelevent_fuzzer/sinkservicedump_fuzzer.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2022 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + #include + #include + + #include "av_trans_message.h" + #include "av_trans_types.h" + + #include + #include "daudio_sink_ctrl_trans.h" + #include "sourcectrltransonchannelevent.h" + + #include "dlfcn.h" + + #include "daudio_constants.h" + #include "daudio_errorcode.h" + #include "daudio_log.h" + #include "daudio_util.h" + +namespace OHOS { +namespace DistributedHardware { +void SourceCtrlTransOnChannelEventFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr || size == 0) { + return; + } + std::string devId = "devId"; + std::string sessionName = "sessionName"; + std::string peerSessName = "peerSessName"; + auto sinkCtrlTransCb = std::make_shared(); + auto ctrlTrans = DaudioSourceCtrlTrans(devId, sessionName, peerSessName, sinkCtrlTransCb); + FuzzedDataProvider fdp(data, size); + AVTransEvent event; + event.content = fdp.ConsumeRandomLengthString(); + event.peerDevId = fdp.ConsumeRandomLengthString(); + event.type = static_cast(fdp.ConsumeIntegral &message) override + { + (void)message; + } +}; +} +} +#endif \ No newline at end of file