audiohal: Get rid of multiple inheritance in IDevice implementation
We still not sure what causes crashes in Device::get|setParam*,
but it seems that it is somehow caused by the fact that the parameters
code is in a separate class with virtual methods, from which
Device class inherits along with IDevice interface.
The workaround is to substitute multiple inheritance with
delegation in Device class. Hopefully this will either eliminate
crashes or make the underlying reasons more clear.
Some of the code got reformatted by clang-format as a presubmit
requirement.
Bug: 36225019
Test: make
Change-Id: Id785c3565bbebd5acc26ca46472961698d9c6208
diff --git a/audio/2.0/default/Device.h b/audio/2.0/default/Device.h
index 7738361..748f96b 100644
--- a/audio/2.0/default/Device.h
+++ b/audio/2.0/default/Device.h
@@ -27,14 +27,14 @@
#include <hidl/MQDescriptor.h>
-#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_string;
using ::android::sp;
-struct Device : public IDevice, public ParametersUtil {
+struct Device : public IDevice {
explicit Device(audio_hw_device_t* device);
// Methods from ::android::hardware::audio::V2_0::IDevice follow.
@@ -101,16 +101,19 @@
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<ParametersUtil> 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; }
};