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 ce68d631402b4e2a78bdce0dd0004129535c2444..a147742fdb390d5d4180172f7ec831d38ead88e9 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 @@ -25,6 +25,10 @@ namespace OHOS { namespace DistributedHardware { +namespace { +constexpr uint32_t DUAIO_IPC_CALLBACK_MAX_ALLOW_SIZE = 64; +} + int32_t DAudioIpcCallback::OnNotifyRegResult(const std::string &devId, const std::string &dhId, const std::string &reqId, int32_t status, const std::string &resultData) { @@ -113,6 +117,10 @@ void DAudioIpcCallback::PushRegisterCallback(const std::string &reqId, { DHLOGD("Push register callback, reqId: %{public}s", reqId.c_str()); std::lock_guard registerLck(registerMapMtx_); + if (registerCallbackMap_.size() >= DUAIO_IPC_CALLBACK_MAX_ALLOW_SIZE) { + DHLOGE("Callback map is full, not allow to insert anymore."); + return; + } registerCallbackMap_.emplace(reqId, callback); } diff --git a/services/audiomanager/managersink/src/daudio_sink_manager.cpp b/services/audiomanager/managersink/src/daudio_sink_manager.cpp index 172b9129629350f516d6362e7e29badfe63645fa..449f58610f93a8d63e7349ca5eb5c75ceae60e0d 100644 --- a/services/audiomanager/managersink/src/daudio_sink_manager.cpp +++ b/services/audiomanager/managersink/src/daudio_sink_manager.cpp @@ -29,11 +29,15 @@ namespace OHOS { namespace DistributedHardware { -static const std::string PARAM_CLOSE_SPEAKER = "{\"audioParam\":null,\"dhId\":\"" + +namespace { +const std::string PARAM_CLOSE_SPEAKER = "{\"audioParam\":null,\"dhId\":\"" + std::to_string(PIN_OUT_SPEAKER) + "\",\"eventType\":12}"; -static const std::string PARAM_CLOSE_MIC = "{\"audioParam\":null,\"dhId\":\"" + +const std::string PARAM_CLOSE_MIC = "{\"audioParam\":null,\"dhId\":\"" + std::to_string(PIN_IN_MIC) + "\",\"eventType\":22}"; const int DEFAULT_DEVICE_SECURITY_LEVEL = -1; +constexpr uint32_t DAUDIO_SOURCE_SERVICE_MAX_SIZE = 64; +} + IMPLEMENT_SINGLE_INSTANCE(DAudioSinkManager); using AVTransProviderClass = IAVEngineProvider *(*)(const std::string &); @@ -76,7 +80,7 @@ int32_t DAudioSinkManager::Init(const sptr &sinkCallback DHLOGI("Load av receiver engine success."); if (LoadAVSenderEngineProvider() != DH_SUCCESS) { - DHLOGI("Load av sender engine provider failed."); + DHLOGE("Load av sender engine provider failed."); return ERR_DH_AUDIO_FAILED; } CHECK_NULL_RETURN(sendProviderPtr_, ERR_DH_AUDIO_FAILED); @@ -275,6 +279,10 @@ int32_t DAudioSinkManager::DAudioNotify(const std::string &devId, const std::str CHECK_NULL_RETURN(remoteSvrProxy, ERR_DH_AUDIO_NULLPTR); { std::lock_guard lck(remoteSvrMutex_); + if (sourceServiceMap_.size() >= DAUDIO_SOURCE_SERVICE_MAX_SIZE) { + DHLOGE("Source service map is full, not allow to insert anymore."); + return ERR_DH_AUDIO_FAILED; + } sourceServiceMap_[devId] = remoteSvrProxy; remoteSvrProxy->DAudioNotify(localNetworkId_, dhId, eventType, eventContent); } diff --git a/services/audiomanager/managersource/src/daudio_source_manager.cpp b/services/audiomanager/managersource/src/daudio_source_manager.cpp index 41a7e146eb26f5107b440f585f178259e15ed698..e7a3a46f8f0e285a35a76f5cfe005414cb235d3e 100644 --- a/services/audiomanager/managersource/src/daudio_source_manager.cpp +++ b/services/audiomanager/managersource/src/daudio_source_manager.cpp @@ -35,6 +35,7 @@ constexpr uint32_t MAX_DEVICE_ID_LENGTH = 200; constexpr uint32_t MAX_DISTRIBUTED_HARDWARE_ID_LENGTH = 100; constexpr uint32_t EVENT_MANAGER_ENABLE_DAUDIO = 11; constexpr uint32_t EVENT_MANAGER_DISABLE_DAUDIO = 12; +constexpr uint32_t DAUDIO_SINK_SERVICE_MAX_SIZE = 64; } IMPLEMENT_SINGLE_INSTANCE(DAudioSourceManager); using AVTransProviderClass = IAVEngineProvider *(*)(const std::string &); @@ -340,6 +341,10 @@ int32_t DAudioSourceManager::DAudioNotify(const std::string &devId, const std::s CHECK_NULL_RETURN(remoteSvrProxy, ERR_DH_AUDIO_NULLPTR); { std::lock_guard lck(remoteSvrMutex_); + if (sinkServiceMap_.size() >= DAUDIO_SINK_SERVICE_MAX_SIZE) { + DHLOGE("Sink service map is full, not allow to insert anymore."); + return ERR_DH_AUDIO_FAILED; + } sinkServiceMap_[devId] = remoteSvrProxy; remoteSvrProxy->DAudioNotify(localDevId_, dhId, eventType, eventContent); }