hal: check device type before handling connection/disconnection
Device is assumed to be an output device when handling connection
or disconnection. Besides the BIT_IN, as the input device could
share same bit definition with the output device, thus disconnecting
input device may cause output device disconnected unexpectly.
Check for device type to avoid mishandling.
Change-Id: Iab637220bd43d16bc2cabb53f610ed978e1e5fea
diff --git a/hal/audio_extn/qaf.c b/hal/audio_extn/qaf.c
index ca83b1d..d8a5c97 100644
--- a/hal/audio_extn/qaf.c
+++ b/hal/audio_extn/qaf.c
@@ -2770,7 +2770,6 @@
int status = 0, val = 0, k;
char *format_params, *kv_parirs;
struct str_parms *qaf_params;
- char value[32];
DEBUG_MSG("Entry");
@@ -2778,10 +2777,9 @@
return -EINVAL;
}
- status = str_parms_get_str(parms, AUDIO_PARAMETER_DEVICE_CONNECT, value, sizeof(value));
+ status = str_parms_get_int(parms, AUDIO_PARAMETER_DEVICE_CONNECT, &val);
- if (status >= 0) {
- val = atoi(value);
+ if ((status >= 0) && audio_is_output_device(val)) {
if (val & AUDIO_DEVICE_OUT_AUX_DIGITAL) { //HDMI is connected.
p_qaf->hdmi_connect = 1;
@@ -2818,9 +2816,8 @@
//TODO else if: Need to consider other devices.
}
- status = str_parms_get_str(parms, AUDIO_PARAMETER_DEVICE_DISCONNECT, value, sizeof(value));
- if (status >= 0) {
- val = atoi(value);
+ status = str_parms_get_int(parms, AUDIO_PARAMETER_DEVICE_DISCONNECT, &val);
+ if ((status >= 0) && audio_is_output_device(val)) {
if (val & AUDIO_DEVICE_OUT_AUX_DIGITAL) { //HDMI is disconnected.
qaf_params = str_parms_create();