Mute RX device according to volume in set_voice_volume
Port the following change from msm8974 platform
Sends the "Rx Device Mute" mixer ctl with parameter 1
in platform_set_voice_volume when volume index matches the mute state.
Sends the same ctl with parameter 0 in case RX stream should not be
muted. Part of a change which enables apps with MODIFY_PHONE_STATE
permission to mute the (Voice Call) RX stream.
(original change id I3e0b7b0d72f5c3e7b37e8c109067818153c82947)
Change-Id: Idaf8a949733dcdc32a9b9eff0316013de6f799ce
Bug: 72278858
Test: Port of code currently used for 8974.
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index f6508c3..f7c48a5 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -1648,6 +1648,7 @@
struct audio_device *adev = my_data->adev;
struct mixer_ctl *ctl;
const char *mixer_ctl_name = "Voice Rx Gain";
+ const char *mute_mixer_ctl_name = "Voice Rx Device Mute";
int vol_index = 0, ret = 0;
uint32_t set_values[ ] = {0,
ALL_SESSION_VSID,
@@ -1658,7 +1659,6 @@
// But this values don't changed in kernel. So, below change is need.
vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
set_values[0] = vol_index;
-
ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
if (!ctl) {
ALOGE("%s: Could not get ctl for mixer cmd - %s",
@@ -1668,6 +1668,23 @@
ALOGV("Setting voice volume index: %d", set_values[0]);
ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
+ // Send mute command in case volume index is max since indexes are inverted
+ // for mixer controls.
+ if (vol_index == my_data->max_vol_index) {
+ set_values[0] = 1;
+ }
+ else {
+ set_values[0] = 0;
+ }
+
+ ctl = mixer_get_ctl_by_name(adev->mixer, mute_mixer_ctl_name);
+ if (!ctl) {
+ ALOGE("%s: Could not get ctl for mixer cmd - %s",
+ __func__, mute_mixer_ctl_name);
+ return -EINVAL;
+ }
+ ALOGV("%s: Setting RX Device Mute to: %d", __func__, set_values[0]);
+ mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
return ret;
}