Audio HAL: A speech volume outside of [0,1] is an error
Hals are supposed to received normalized volumes, between 0 and 1.
Previously volumes outside [0,1] were clamp to this range.
This clamping has the capability to hide bugs thus return an error if
such volume is received.
Test: vts-tradefed run vts --module VtsHalAudioV2_0Target
Test: call/play music/record/video...
Bug: 36311550
Change-Id: Iab70f9c651540ea2434d10939d28c1c842db19e0
Signed-off-by: Kevin Rocard <krocard@google.com>
diff --git a/audio/2.0/default/PrimaryDevice.cpp b/audio/2.0/default/PrimaryDevice.cpp
index 4e8f30f..746d873 100644
--- a/audio/2.0/default/PrimaryDevice.cpp
+++ b/audio/2.0/default/PrimaryDevice.cpp
@@ -17,6 +17,7 @@
#define LOG_TAG "PrimaryDeviceHAL"
#include "PrimaryDevice.h"
+#include "Util.h"
namespace android {
namespace hardware {
@@ -126,6 +127,10 @@
// Methods from ::android::hardware::audio::V2_0::IPrimaryDevice follow.
Return<Result> PrimaryDevice::setVoiceVolume(float volume) {
+ if (!isGainNormalized(volume)) {
+ ALOGW("Can not set a voice volume (%f) outside [0,1]", volume);
+ return Result::INVALID_ARGUMENTS;
+ }
return mDevice->analyzeStatus(
"set_voice_volume",
mDevice->device()->set_voice_volume(mDevice->device(), volume));