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/msm8974/platform.c b/hal/msm8974/platform.c
index ed23aca..87df8da 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -601,6 +601,7 @@
     [SND_DEVICE_OUT_BUS_NAV] = "bus-speaker",
     [SND_DEVICE_OUT_BUS_PHN] = "bus-speaker",
     [SND_DEVICE_OUT_BUS_RSE] = "bus-speaker",
+    [SND_DEVICE_OUT_CALL_PROXY] = "call-proxy",
 
     /* Capture sound devices */
     [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
@@ -740,6 +741,7 @@
     [SND_DEVICE_IN_HANDSET_QMIC_AND_EC_REF_LOOPBACK] = "handset-qmic-and-ec-ref-loopback",
     [SND_DEVICE_IN_HANDSET_6MIC_AND_EC_REF_LOOPBACK] = "handset-6mic-and-ec-ref-loopback",
     [SND_DEVICE_IN_HANDSET_8MIC_AND_EC_REF_LOOPBACK] = "handset-8mic-and-ec-ref-loopback",
+    [SND_DEVICE_IN_CALL_PROXY] = "call-proxy-in",
 };
 
 // Platform specific backend bit width table
@@ -876,6 +878,7 @@
     [SND_DEVICE_OUT_BUS_NAV] = 14,
     [SND_DEVICE_OUT_BUS_PHN] = 94,
     [SND_DEVICE_OUT_BUS_RSE] = 60,
+    [SND_DEVICE_OUT_CALL_PROXY] = 32,
     [SND_DEVICE_IN_HANDSET_MIC] = 4,
     [SND_DEVICE_IN_HANDSET_MIC_SB] = 163,
     [SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = 4,
@@ -1005,6 +1008,7 @@
     [SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = 4,
     [SND_DEVICE_IN_VOICE_HEARING_AID] = 44,
     [SND_DEVICE_IN_BUS] = 11,
+    [SND_DEVICE_IN_CALL_PROXY] = 33,
 };
 
 struct name_to_index {
@@ -1112,6 +1116,7 @@
     {TO_NAME_INDEX(SND_DEVICE_OUT_BUS_NAV)},
     {TO_NAME_INDEX(SND_DEVICE_OUT_BUS_PHN)},
     {TO_NAME_INDEX(SND_DEVICE_OUT_BUS_RSE)},
+    {TO_NAME_INDEX(SND_DEVICE_OUT_CALL_PROXY)},
     {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
     {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_SB)},
     {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_EXTERNAL)},
@@ -1248,6 +1253,7 @@
     {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AND_EC_REF_LOOPBACK)},
     {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_6MIC_AND_EC_REF_LOOPBACK)},
     {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_8MIC_AND_EC_REF_LOOPBACK)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_CALL_PROXY)},
 };
 
 static char * backend_tag_table[SND_DEVICE_MAX] = {0};
@@ -2215,6 +2221,8 @@
     backend_tag_table[SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_ANC_FB_HEADSET] = strdup("speaker-and-headphones");
     backend_tag_table[SND_DEVICE_OUT_VOICE_HEARING_AID] = strdup("hearing-aid");
     backend_tag_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP_MMSECNS] = strdup("bt-sco-mmsecns");
+    backend_tag_table[SND_DEVICE_OUT_CALL_PROXY] = strdup("call-proxy");
+    backend_tag_table[SND_DEVICE_IN_CALL_PROXY] = strdup("call-proxy-in");
 
     hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
     hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
@@ -2315,6 +2323,7 @@
     hw_interface_table[SND_DEVICE_OUT_BUS_NAV] = strdup("TERT_TDM_RX_1");
     hw_interface_table[SND_DEVICE_OUT_BUS_PHN] = strdup("TERT_TDM_RX_2");
     hw_interface_table[SND_DEVICE_OUT_BUS_RSE] = strdup("QUAT_TDM_RX_0");
+    hw_interface_table[SND_DEVICE_OUT_CALL_PROXY] = strdup("CALL_PROXY_RX");
     hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
     hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_SB] = strdup("SLIMBUS_0_TX");
     hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = strdup("SLIMBUS_0_TX");
@@ -2443,6 +2452,7 @@
     hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = strdup("SLIMBUS_0_TX");
     hw_interface_table[SND_DEVICE_IN_VOICE_HEARING_AID] = strdup("SLIMBUS_0_TX");
     hw_interface_table[SND_DEVICE_IN_BUS] = strdup("TERT_TDM_TX_0");
+    hw_interface_table[SND_DEVICE_IN_CALL_PROXY] = strdup("CALL_PROXY_TX");
     my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
 
      /*remove ALAC & APE from DSP decoder list based on software decoder availability*/
@@ -5050,6 +5060,8 @@
                 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
                            (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
                         port = USB_AUDIO_RX_BACKEND;
+                else if (strcmp(backend_tag_table[snd_device], "call-proxy") == 0)
+                        port = CALL_PROXY_RX_BACKEND;
         }
     } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
         port = DEFAULT_CODEC_TX_BACKEND;
@@ -5066,6 +5078,8 @@
                         port = HDMI_ARC_TX_BACKEND;
                 else if (strcmp(backend_tag_table[snd_device], "headset-mic") == 0)
                         port = HEADSET_TX_BACKEND;
+                else if (strcmp(backend_tag_table[snd_device], "call-proxy-in") == 0)
+                        port = CALL_PROXY_TX_BACKEND;
         }
     } else {
         ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
@@ -5089,7 +5103,7 @@
     struct audio_backend_cfg backend_cfg = {0};
     bool is_bus_dev_usecase = false;
 
-    if (voice_is_in_call(my_data->adev))
+    if (voice_is_in_call_or_call_screen(my_data->adev))
         is_incall_rec_usecase = voice_is_in_call_rec_stream(usecase->stream.in);
 
     if (compare_device_type(&usecase->device_list, AUDIO_DEVICE_OUT_BUS))
@@ -5212,7 +5226,7 @@
     int ret = 0;
 
     if (my_data->csd != NULL &&
-        voice_is_in_call(my_data->adev)) {
+        voice_is_in_call_or_call_screen(my_data->adev)) {
         /* This must be called before disabling mixer controls on APQ side */
         ret = my_data->csd->disable_device();
         if (ret < 0) {
@@ -5505,7 +5519,8 @@
                           DEFAULT_MUTE_RAMP_DURATION_MS};
 
     if (adev->mode != AUDIO_MODE_IN_CALL &&
-        adev->mode != AUDIO_MODE_IN_COMMUNICATION)
+        adev->mode != AUDIO_MODE_IN_COMMUNICATION &&
+        adev->mode != AUDIO_MODE_CALL_SCREEN)
         return 0;
 
     if (adev->enable_hfp)
@@ -5951,7 +5966,8 @@
     return disp_type;
 }
 
-snd_device_t platform_get_output_snd_device(void *platform, struct stream_out *out)
+snd_device_t platform_get_output_snd_device(void *platform, struct stream_out *out,
+                                            usecase_type_t uc_type)
 {
     struct platform_data *my_data = (struct platform_data *)platform;
     struct audio_device *adev = my_data->adev;
@@ -5990,6 +6006,15 @@
         }
     }
 
+    if (mode == AUDIO_MODE_CALL_SCREEN) {
+        if (uc_type == VOICE_CALL)
+            snd_device = SND_DEVICE_OUT_CALL_PROXY;
+        if (compare_device_type(&devices, AUDIO_DEVICE_OUT_TELEPHONY_TX))
+            snd_device = SND_DEVICE_OUT_VOICE_TX;
+        if (snd_device != SND_DEVICE_NONE)
+            goto exit;
+    }
+
     if (list_length(&devices) == 2) {
         bool is_active_voice_call = false;
 
@@ -6608,7 +6633,8 @@
 
 snd_device_t platform_get_input_snd_device(void *platform,
                                            struct stream_in *in,
-                                           struct listnode *out_devices)
+                                           struct listnode *out_devices,
+                                           usecase_type_t uc_type)
 {
     struct platform_data *my_data = (struct platform_data *)platform;
     struct audio_device *adev = my_data->adev;
@@ -6649,6 +6675,13 @@
         }
     }
 
+    if (mode == AUDIO_MODE_CALL_SCREEN) {
+        if (uc_type == VOICE_CALL)
+            snd_device = SND_DEVICE_IN_CALL_PROXY;
+        if (compare_device_type(out_devices, AUDIO_DEVICE_OUT_TELEPHONY_TX))
+            snd_device = SND_DEVICE_IN_VOICE_RX;
+    }
+
     if (snd_device != AUDIO_DEVICE_NONE)
         goto exit;
 
@@ -7672,11 +7705,12 @@
               struct listnode cal_devices;
               list_init(&cal_devices);
               update_device_list(&cal_devices, cal.dev_id, address, true);
-              cal.snd_dev_id = platform_get_input_snd_device(platform, NULL, &cal_devices);
+              cal.snd_dev_id = platform_get_input_snd_device(platform, NULL, &cal_devices,
+                                                             USECASE_TYPE_MAX);
           } else {
               reassign_device_list(&out.device_list, cal.dev_id, address);
               out.sample_rate = cal.sampling_rate;
-              cal.snd_dev_id = platform_get_output_snd_device(platform, &out);
+              cal.snd_dev_id = platform_get_output_snd_device(platform, &out, USECASE_TYPE_MAX);
           }
         }
         cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
@@ -8258,11 +8292,11 @@
         struct listnode devices;
         list_init(&devices);
         update_device_list(&devices, cal.dev_id, address, true);
-        cal.snd_dev_id = platform_get_input_snd_device(platform, NULL, &devices);
+        cal.snd_dev_id = platform_get_input_snd_device(platform, NULL, &devices, USECASE_TYPE_MAX);
     } else if (cal.dev_id) {
         reassign_device_list(&out.device_list, cal.dev_id, address);
         out.sample_rate = cal.sampling_rate;
-        cal.snd_dev_id = platform_get_output_snd_device(platform, &out);
+        cal.snd_dev_id = platform_get_output_snd_device(platform, &out, USECASE_TYPE_MAX);
     }
     cal.acdb_dev_id =  platform_get_snd_device_acdb_id(cal.snd_dev_id);
     if (cal.acdb_dev_id < 0) {
@@ -8706,7 +8740,8 @@
                (uc->type == VOICE_CALL ||
                 uc->type == VOIP_CALL ||
                 uc->id == USECASE_AUDIO_PLAYBACK_VOIP)) {
-               out_snd_device = platform_get_output_snd_device(adev->platform, uc->stream.out);
+               out_snd_device = platform_get_output_snd_device(adev->platform, uc->stream.out,
+                                                               uc->type);
                backend_idx = platform_get_backend_index(out_snd_device);
                break;
            }
@@ -11700,7 +11735,7 @@
     list_init(&devices);
 
     snd_device_t active_input_snd_device =
-            platform_get_input_snd_device(platform, usecase->stream.in, &devices);
+            platform_get_input_snd_device(platform, usecase->stream.in, &devices, USECASE_TYPE_MAX);
     if (active_input_snd_device == SND_DEVICE_NONE) {
         ALOGI("%s: No active microphones found", __func__);
         goto end;
@@ -11752,3 +11787,9 @@
     }
     return 0;
 }
+
+bool platform_is_call_proxy_snd_device(snd_device_t snd_device) {
+    if (snd_device == SND_DEVICE_IN_CALL_PROXY || snd_device == SND_DEVICE_OUT_CALL_PROXY)
+        return true;
+    return false;
+}