Fix segfault in Primary audio hal hidl wrapper getDevice
Test: run the corresponding vts test
Test: vts-tradefed r vts-hal-hidl -m VtsHalAudioV2_0Target
Bug: 34170075
Change-Id: I0652f1bf748de99a8a2594630daf5ea2acec8934
Signed-off-by: Kevin Rocard <krocard@google.com>
diff --git a/audio/2.0/default/Stream.cpp b/audio/2.0/default/Stream.cpp
index c16a956..29946fe 100644
--- a/audio/2.0/default/Stream.cpp
+++ b/audio/2.0/default/Stream.cpp
@@ -189,7 +189,9 @@
}
Return<AudioDevice> Stream::getDevice() {
- return AudioDevice(mStream->get_device(mStream));
+ int device;
+ Result retval = getParam(AudioParameter::keyRouting, &device);
+ return retval == Result::OK ? static_cast<AudioDevice>(device) : AudioDevice::NONE;
}
Return<Result> Stream::setDevice(const DeviceAddress& address) {
diff --git a/audio/2.0/vts/functional/AudioPrimaryHidlHalTest.cpp b/audio/2.0/vts/functional/AudioPrimaryHidlHalTest.cpp
index e38bbe4..d896788 100644
--- a/audio/2.0/vts/functional/AudioPrimaryHidlHalTest.cpp
+++ b/audio/2.0/vts/functional/AudioPrimaryHidlHalTest.cpp
@@ -659,15 +659,10 @@
testGetAudioProperties(stream, audioConfig);
- // FIXME: Stream wrapper does not implement getDevice properly.
- // It needs to call getProperty({"routing"}).
- // The current implementation segfault with the default hal
- /*
- * auto ret = stream->getDevice();
- * ASSERT_TRUE(ret.isOk());
- * AudioDevice device = ret;
- * ASSERT_EQ(AudioDevice::OUT_ALL, device);
- */
+ auto ret = stream->getDevice();
+ ASSERT_TRUE(ret.isOk());
+ AudioDevice device = ret;
+ ASSERT_EQ(AudioDevice::OUT_DEFAULT, device);
}
TEST_P(InputStreamTest, GettersTest) {