libaudiohal: fix get supported parameters queries in HIDL mode
Add a special case for keyStreamSupportedChannels and
keyStreamSupportedSamplingRates in ConversionHelperHidl::keysFromHal().
In this case, the query also contains a key=value pair specifying
the audio format to consider and it must be passed to the audio
HAL including the value.
Bug: 38326193
Test: verify format specifier is sent to HAL for supported sampling
rates and channels queries
Change-Id: I14ac40da920122ec0242ab027a2a4ac1d92381c8
diff --git a/media/libaudiohal/ConversionHelperHidl.cpp b/media/libaudiohal/ConversionHelperHidl.cpp
index 9f9eb75..f60bf8b 100644
--- a/media/libaudiohal/ConversionHelperHidl.cpp
+++ b/media/libaudiohal/ConversionHelperHidl.cpp
@@ -31,10 +31,24 @@
AudioParameter halKeys(keys);
if (halKeys.size() == 0) return BAD_VALUE;
hidlKeys->resize(halKeys.size());
+ //FIXME: keyStreamSupportedChannels and keyStreamSupportedSamplingRates come with a
+ // "keyFormat=<value>" pair. We need to transform it into a single key string so that it is
+ // carried over to the legacy HAL via HIDL.
+ String8 value;
+ bool keepFormatValue = halKeys.size() == 2 &&
+ (halKeys.get(String8(AudioParameter::keyStreamSupportedChannels), value) == NO_ERROR ||
+ halKeys.get(String8(AudioParameter::keyStreamSupportedSamplingRates), value) == NO_ERROR);
+
for (size_t i = 0; i < halKeys.size(); ++i) {
String8 key;
status_t status = halKeys.getAt(i, key);
if (status != OK) return status;
+ if (keepFormatValue && key == AudioParameter::keyFormat) {
+ AudioParameter formatParam;
+ halKeys.getAt(i, key, value);
+ formatParam.add(key, value);
+ key = formatParam.toString();
+ }
(*hidlKeys)[i] = key.string();
}
return OK;