From 035beba20344d267d7e48e414b952c8fe3aaa14e Mon Sep 17 00:00:00 2001 From: Shraddha Basantwani Date: Fri, 28 Jul 2023 12:55:25 +0000 Subject: [PATCH] Audio : Fix a few minor issues with stream switcher class 1. Constructor should forward variable arguments 2. mContext initialization was missing 3. Add nullptr check for addEffect and removeEffect methods Bug: 264712385 Bug: 286914845 Test: atest VtsHalAudioCoreTargetTest Change-Id: I4037292bf497be186b26508bd16846886fa4fe55 --- audio/aidl/default/StreamSwitcher.cpp | 12 +++++++++++- .../aidl/default/include/core-impl/StreamSwitcher.h | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/audio/aidl/default/StreamSwitcher.cpp b/audio/aidl/default/StreamSwitcher.cpp index 956f4138ba..e00c34b50f 100644 --- a/audio/aidl/default/StreamSwitcher.cpp +++ b/audio/aidl/default/StreamSwitcher.cpp @@ -31,7 +31,9 @@ using aidl::android::media::audio::common::AudioDevice; namespace aidl::android::hardware::audio::core { StreamSwitcher::StreamSwitcher(StreamContext* context, const Metadata& metadata) - : mMetadata(metadata), mStream(new InnerStreamWrapper(context, mMetadata)) {} + : mContext(context), + mMetadata(metadata), + mStream(new InnerStreamWrapper(context, mMetadata)) {} ndk::ScopedAStatus StreamSwitcher::closeCurrentStream(bool validateStreamState) { if (!mStream) return ndk::ScopedAStatus::ok(); @@ -100,6 +102,10 @@ ndk::ScopedAStatus StreamSwitcher::setVendorParameters( } ndk::ScopedAStatus StreamSwitcher::addEffect(const std::shared_ptr& in_effect) { + if (in_effect == nullptr) { + LOG(DEBUG) << __func__ << ": null effect"; + return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); + } if (mStream == nullptr) { LOG(ERROR) << __func__ << ": stream was closed"; return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE); @@ -112,6 +118,10 @@ ndk::ScopedAStatus StreamSwitcher::addEffect(const std::shared_ptr& in_ } ndk::ScopedAStatus StreamSwitcher::removeEffect(const std::shared_ptr& in_effect) { + if (in_effect == nullptr) { + LOG(DEBUG) << __func__ << ": null effect"; + return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); + } if (mStream == nullptr) { LOG(ERROR) << __func__ << ": stream was closed"; return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE); diff --git a/audio/aidl/default/include/core-impl/StreamSwitcher.h b/audio/aidl/default/include/core-impl/StreamSwitcher.h index e462481fc1..2cb847080c 100644 --- a/audio/aidl/default/include/core-impl/StreamSwitcher.h +++ b/audio/aidl/default/include/core-impl/StreamSwitcher.h @@ -86,7 +86,8 @@ class StreamCommonInterfaceEx : virtual public StreamCommonInterface { template class InnerStreamWrapper : public T, public StreamCommonInterfaceEx { public: - InnerStreamWrapper(StreamContext* context, const Metadata& metadata) : T(context, metadata) {} + template + InnerStreamWrapper(Args&&... args) : T(std::forward(args)...) {} StreamDescriptor::State getStatePriorToClosing() const override { return mStatePriorToClosing; } private: