hal: Mute other active streams while voice recognition is active
In order to protect voice recognition data from other clients
in audio record concurrency usecases, mute all active non voice
recognition input streams.
Change-Id: I1002726699902952c8b8568d57aa1cb6dfc2ad2b
diff --git a/hal/audio_extn/soundtrigger.c b/hal/audio_extn/soundtrigger.c
index e01b23b..6496838 100644
--- a/hal/audio_extn/soundtrigger.c
+++ b/hal/audio_extn/soundtrigger.c
@@ -358,8 +358,6 @@
ALOGE(" %s: Sound trigger is not active", __func__);
goto exit;
}
- if(in->standby)
- in->standby = false;
pthread_mutex_lock(&st_dev->lock);
st_info = get_sound_trigger_info(in->capture_handle);
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 17f838c..6c0f882 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -5608,6 +5608,7 @@
if (!in->standby && in->is_st_session) {
ALOGD("%s: sound trigger pcm stop lab", __func__);
audio_extn_sound_trigger_stop_lab(in);
+ adev->num_va_sessions--;
in->standby = 1;
}
@@ -5640,6 +5641,10 @@
platform_set_echo_reference(adev, false, AUDIO_DEVICE_NONE);
status = stop_input_stream(in);
}
+
+ if (in->source == AUDIO_SOURCE_VOICE_RECOGNITION)
+ adev->num_va_sessions--;
+
pthread_mutex_unlock(&adev->lock);
}
pthread_mutex_unlock(&in->lock);
@@ -5889,6 +5894,10 @@
ALOGVV(" %s: reading on st session bytes=%zu", __func__, bytes);
/* Read from sound trigger HAL */
audio_extn_sound_trigger_read(in, buffer, bytes);
+ if (in->standby) {
+ adev->num_va_sessions++;
+ in->standby = 0;
+ }
pthread_mutex_unlock(&in->lock);
return bytes;
}
@@ -5904,6 +5913,8 @@
ret = voice_extn_compress_voip_start_input_stream(in);
else
ret = start_input_stream(in);
+ if (!ret && in->source == AUDIO_SOURCE_VOICE_RECOGNITION)
+ adev->num_va_sessions++;
pthread_mutex_unlock(&adev->lock);
if (ret != 0) {
goto exit;
@@ -5952,11 +5963,18 @@
release_in_focus(in);
/*
- * Instead of writing zeroes here, we could trust the hardware
- * to always provide zeroes when muted.
+ * Instead of writing zeroes here, we could trust the hardware to always
+ * provide zeroes when muted. This is also muted with voice recognition
+ * usecases so that other clients do not have access to voice recognition
+ * data.
*/
- if (ret == 0 && voice_get_mic_mute(adev) && !voice_is_in_call_rec_stream(in) &&
- in->usecase != USECASE_AUDIO_RECORD_AFE_PROXY)
+ if ((ret == 0 && voice_get_mic_mute(adev) &&
+ !voice_is_in_call_rec_stream(in) &&
+ in->usecase != USECASE_AUDIO_RECORD_AFE_PROXY) ||
+ (adev->num_va_sessions &&
+ in->source != AUDIO_SOURCE_VOICE_RECOGNITION &&
+ property_get_bool("persist.vendor.audio.va_concurrency_mute_enabled",
+ false)))
memset(buffer, 0, bytes);
exit:
diff --git a/hal/audio_hw.h b/hal/audio_hw.h
index 4f93aa9..23306de 100644
--- a/hal/audio_hw.h
+++ b/hal/audio_hw.h
@@ -517,6 +517,7 @@
bool enable_hfp;
bool mic_muted;
bool enable_voicerx;
+ unsigned int num_va_sessions;
int snd_card;
card_status_t card_status;