hal: add support for callscreening.

handle newly added callscreening mode, provide support for device selection
as per this new mode.

Change-Id: I3c57c9edd38cf4347d11c871e1878a4536936edc
diff --git a/hal/voice.c b/hal/voice.c
index 818eb94..72c3372 100644
--- a/hal/voice.c
+++ b/hal/voice.c
@@ -167,11 +167,11 @@
     session->state.current = CALL_INACTIVE;
 
     /* Disable sidetone only when no calls are active */
-    if (!voice_is_call_state_active(adev))
+    if (!voice_is_call_state_active_in_call(adev))
         voice_set_sidetone(adev, uc_info->out_snd_device, false);
 
     /* Disable aanc only when no calls are active */
-    if (!voice_is_call_state_active(adev))
+    if (!voice_is_call_state_active_in_call(adev))
         voice_check_and_update_aanc_path(adev, uc_info->out_snd_device, false);
 
     ret = platform_stop_voice_call(adev->platform, session->vsid);
@@ -221,6 +221,7 @@
     uint32_t sample_rate = 8000;
     struct voice_session *session = NULL;
     struct pcm_config voice_config = pcm_config_voice_call;
+    bool is_in_call = (AUDIO_MODE_IN_CALL == adev->mode);
 
     ALOGD("%s: enter usecase:%s", __func__, use_case_table[usecase_id]);
 
@@ -242,7 +243,7 @@
     list_init(&uc_info->device_list);
     assign_devices(&uc_info->device_list, &adev->current_call_output->device_list);
 
-    if (list_length(&uc_info->device_list) == 2) {
+    if (is_in_call && list_length(&uc_info->device_list) == 2) {
         ALOGE("%s: Invalid combo device(%#x) for voice call", __func__,
               get_device_types(&uc_info->device_list));
         ret = -EIO;
@@ -361,11 +362,11 @@
 #endif
 
     /* Enable aanc only when no calls are active */
-    if (!voice_is_call_state_active(adev))
+    if (!voice_is_call_state_active_in_call(adev))
         voice_check_and_update_aanc_path(adev, uc_info->out_snd_device, true);
 
     /* Enable sidetone only when no calls are already active */
-    if (!voice_is_call_state_active(adev))
+    if (!voice_is_call_state_active_in_call(adev))
         voice_set_sidetone(adev, uc_info->out_snd_device, true);
 
     voice_set_volume(adev, adev->voice.volume);
@@ -387,8 +388,10 @@
     return ret;
 }
 
-bool voice_is_call_state_active(struct audio_device *adev)
-{
+/*
+* helper function to check whether call is active or not.
+*/
+static inline bool voice_is_active(struct audio_device *adev) {
     bool call_state = false;
     int ret = 0;
 
@@ -400,8 +403,30 @@
     return call_state;
 }
 
+/*
+* checks if call is active and in IN_CALL mode.
+*/
+bool voice_is_call_state_active_in_call(struct audio_device *adev)
+{
+    bool call_state = voice_is_active(adev);
+    return call_state && adev->mode == AUDIO_MODE_IN_CALL;
+}
+
+/*
+* returns true if call is active no matter what mode is.
+*/
+bool voice_is_call_state_active(struct audio_device *adev)
+{
+    return voice_is_active(adev);
+}
+
 bool voice_is_in_call(const struct audio_device *adev)
 {
+    return adev->voice.in_call && adev->mode == AUDIO_MODE_IN_CALL;
+}
+
+bool voice_is_in_call_or_call_screen(const struct audio_device *adev)
+{
     return adev->voice.in_call;
 }
 
@@ -442,7 +467,7 @@
 
     list_for_each(node, &adev->usecase_list) {
         usecase = node_to_item(node, struct audio_usecase, list);
-        if (usecase->type == VOICE_CALL) {
+        if (usecase->type == VOICE_CALL && adev->mode != AUDIO_MODE_CALL_SCREEN) {
             ALOGV("%s: voice usecase:%s is active", __func__,
                    use_case_table[usecase->id]);
             return true;
@@ -748,7 +773,7 @@
         if (tty_mode != adev->voice.tty_mode) {
             adev->voice.tty_mode = tty_mode;
             adev->acdb_settings = (adev->acdb_settings & TTY_MODE_CLEAR) | tty_mode;
-            if (voice_is_call_state_active(adev))
+            if (voice_is_call_state_active_in_call(adev))
                voice_update_devices_for_all_voice_usecases(adev);
         }
     }