From 86685f56da0941027406d1ffba67bd4272faa526 Mon Sep 17 00:00:00 2001 From: Mikhail Naganov Date: Wed, 3 May 2017 16:39:28 +0000 Subject: [PATCH] Revert "audiohal: Get rid of multiple inheritance in IDevice implementation" This reverts commit e4228e7aa683044e17e6592c9014b5d4691445e7. Further analysis of the bug has shown that the problem is not related to the use of multiple inheritance. Bug: 36225019 Change-Id: Icdcaf84061c0ecf29f891521bd961c3ee89f1cfc --- audio/2.0/default/Device.cpp | 57 ++++++------------------------ audio/2.0/default/Device.h | 19 +++++----- audio/2.0/default/ParametersUtil.h | 29 ++++++++------- 3 files changed, 32 insertions(+), 73 deletions(-) diff --git a/audio/2.0/default/Device.cpp b/audio/2.0/default/Device.cpp index d12f8c0319..b696d94b8b 100644 --- a/audio/2.0/default/Device.cpp +++ b/audio/2.0/default/Device.cpp @@ -26,7 +26,6 @@ #include "Conversions.h" #include "Device.h" #include "HidlUtils.h" -#include "ParametersUtil.h" #include "StreamIn.h" #include "StreamOut.h" @@ -36,28 +35,9 @@ namespace audio { namespace V2_0 { namespace implementation { -namespace { - -class ParametersUtilImpl : public ParametersUtil { - public: - ParametersUtilImpl(audio_hw_device_t* device) : mDevice{device} {} - - char* halGetParameters(const char* keys) override { - return mDevice->get_parameters(mDevice, keys); - } - - int halSetParameters(const char* keysAndValues) override { - return mDevice->set_parameters(mDevice, keysAndValues); - } - - private: - audio_hw_device_t* mDevice; -}; - -} // namespace - Device::Device(audio_hw_device_t* device) - : mDevice{device}, mParameters{new ParametersUtilImpl(mDevice)} {} + : mDevice(device) { +} Device::~Device() { int status = audio_hw_device_close(mDevice); @@ -87,28 +67,12 @@ void Device::closeOutputStream(audio_stream_out_t* stream) { mDevice->close_output_stream(mDevice, stream); } -Result Device::getParam(const char* name, bool* value) { - return mParameters->getParam(name, value); +char* Device::halGetParameters(const char* keys) { + return mDevice->get_parameters(mDevice, keys); } -Result Device::getParam(const char* name, int* value) { - return mParameters->getParam(name, value); -} - -Result Device::getParam(const char* name, String8* value) { - return mParameters->getParam(name, value); -} - -Result Device::setParam(const char* name, bool value) { - return mParameters->setParam(name, value); -} - -Result Device::setParam(const char* name, int value) { - return mParameters->setParam(name, value); -} - -Result Device::setParam(const char* name, const char* value) { - return mParameters->setParam(name, value); +int Device::halSetParameters(const char* keysAndValues) { + return mDevice->set_parameters(mDevice, keysAndValues); } // Methods from ::android::hardware::audio::V2_0::IDevice follow. @@ -310,22 +274,21 @@ Return Device::setAudioPortConfig(const AudioPortConfig& config) { Return Device::getHwAvSync() { int halHwAvSync; - Result retval = - mParameters->getParam(AudioParameter::keyHwAvSync, &halHwAvSync); + Result retval = getParam(AudioParameter::keyHwAvSync, &halHwAvSync); return retval == Result::OK ? halHwAvSync : AUDIO_HW_SYNC_INVALID; } Return Device::setScreenState(bool turnedOn) { - return mParameters->setParam(AudioParameter::keyScreenState, turnedOn); + return setParam(AudioParameter::keyScreenState, turnedOn); } Return Device::getParameters(const hidl_vec& keys, getParameters_cb _hidl_cb) { - mParameters->getParametersImpl(keys, _hidl_cb); + getParametersImpl(keys, _hidl_cb); return Void(); } Return Device::setParameters(const hidl_vec& parameters) { - return mParameters->setParametersImpl(parameters); + return setParametersImpl(parameters); } Return Device::debugDump(const hidl_handle& fd) { diff --git a/audio/2.0/default/Device.h b/audio/2.0/default/Device.h index 748f96b773..7738361075 100644 --- a/audio/2.0/default/Device.h +++ b/audio/2.0/default/Device.h @@ -27,14 +27,14 @@ #include +#include "ParametersUtil.h" + namespace android { namespace hardware { namespace audio { namespace V2_0 { namespace implementation { -class ParametersUtil; - using ::android::hardware::audio::common::V2_0::AudioConfig; using ::android::hardware::audio::common::V2_0::AudioHwSync; using ::android::hardware::audio::common::V2_0::AudioInputFlag; @@ -55,7 +55,7 @@ using ::android::hardware::hidl_vec; using ::android::hardware::hidl_string; using ::android::sp; -struct Device : public IDevice { +struct Device : public IDevice, public ParametersUtil { explicit Device(audio_hw_device_t* device); // Methods from ::android::hardware::audio::V2_0::IDevice follow. @@ -101,19 +101,16 @@ struct Device : public IDevice { void closeInputStream(audio_stream_in_t* stream); void closeOutputStream(audio_stream_out_t* stream); audio_hw_device_t* device() const { return mDevice; } - Result getParam(const char* name, bool* value); - Result getParam(const char* name, int* value); - Result getParam(const char* name, String8* value); - Result setParam(const char* name, bool value); - Result setParam(const char* name, int value); - Result setParam(const char* name, const char* value); - private: + private: audio_hw_device_t *mDevice; - std::unique_ptr mParameters; virtual ~Device(); + // Methods from ParametersUtil. + char* halGetParameters(const char* keys) override; + int halSetParameters(const char* keysAndValues) override; + uint32_t version() const { return mDevice->common.version; } }; diff --git a/audio/2.0/default/ParametersUtil.h b/audio/2.0/default/ParametersUtil.h index 603e336079..49036dc521 100644 --- a/audio/2.0/default/ParametersUtil.h +++ b/audio/2.0/default/ParametersUtil.h @@ -37,23 +37,22 @@ using ::android::hardware::hidl_vec; class ParametersUtil { public: - virtual ~ParametersUtil() = default; - Result getParam(const char* name, bool* value); - Result getParam(const char* name, int* value); - Result getParam(const char* name, String8* value); - void getParametersImpl( - const hidl_vec& keys, - std::function& parameters)> - cb); - std::unique_ptr getParams(const AudioParameter& keys); - Result setParam(const char* name, bool value); - Result setParam(const char* name, int value); - Result setParam(const char* name, const char* value); - Result setParametersImpl(const hidl_vec& parameters); - Result setParams(const AudioParameter& param); + Result getParam(const char* name, bool* value); + Result getParam(const char* name, int* value); + Result getParam(const char* name, String8* value); + void getParametersImpl( + const hidl_vec& keys, + std::function& parameters)> cb); + std::unique_ptr getParams(const AudioParameter& keys); + Result setParam(const char* name, bool value); + Result setParam(const char* name, int value); + Result setParam(const char* name, const char* value); + Result setParametersImpl(const hidl_vec& parameters); + Result setParams(const AudioParameter& param); protected: + virtual ~ParametersUtil() {} + virtual char* halGetParameters(const char* keys) = 0; virtual int halSetParameters(const char* keysAndValues) = 0; };