hal: notify listen while enabling/disabling snd device

Listen needs be stopped when audio capture is active. Also
Listen needs to be started again after audio capture becomes
inactive. Stop and start listen based on audio capture device.

Change-Id: I05ca7cccd59b43a163604881bd9c6ee10cc8fba3
Depends-on: 510494
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 5537115..df040e2 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -271,6 +271,9 @@
             adev->snd_dev_ref_cnt[snd_device]--;
             return -EINVAL;
         }
+        audio_extn_listen_update_status(snd_device,
+                LISTEN_EVENT_SND_DEVICE_BUSY);
+
         audio_route_apply_path(adev->audio_route, device_name);
     }
     if (update_mixer)
@@ -322,6 +325,9 @@
 
         if (update_mixer)
             audio_route_update_mixer(adev->audio_route);
+
+        audio_extn_listen_update_status(snd_device,
+                                        LISTEN_EVENT_SND_DEVICE_FREE);
     }
 
     return 0;
@@ -734,9 +740,6 @@
     /* 2. Disable the tx device */
     disable_snd_device(adev, uc_info->in_snd_device, true);
 
-    audio_extn_listen_update_status(uc_info,
-            LISTEN_EVENT_AUDIO_CAPTURE_INACTIVE);
-
     list_remove(&uc_info->list);
     free(uc_info);
 
@@ -781,9 +784,6 @@
     list_add_tail(&adev->usecase_list, &uc_info->list);
     select_devices(adev, in->usecase);
 
-    audio_extn_listen_update_status(uc_info,
-            LISTEN_EVENT_AUDIO_CAPTURE_ACTIVE);
-
     ALOGV("%s: Opening PCM device card_id(%d) device_id(%d), channels %d",
           __func__, SOUND_CARD, in->pcm_device_id, in->config.channels);
     in->pcm = pcm_open(SOUND_CARD, in->pcm_device_id,
@@ -2472,10 +2472,10 @@
     pthread_mutex_lock(&adev_init_lock);
 
     if ((--audio_device_ref_count) == 0) {
+        audio_extn_listen_deinit(adev);
         audio_route_free(adev->audio_route);
         free(adev->snd_dev_ref_cnt);
         platform_deinit(adev->platform);
-        audio_extn_listen_deinit(adev);
         free(device);
         adev = NULL;
     }
@@ -2562,7 +2562,7 @@
                                                         "visualizer_hal_stop_output");
         }
     }
-    audio_extn_listen_init(adev);
+    audio_extn_listen_init(adev, SOUND_CARD);
 
     *device = &adev->device.common;