st-hal: fix session pause and lpi switch for concurrency

-for dedicated path, even when session is allowed, still need
 to check if session should be switched between lpi and non-lpi.
-for non-dedicated path, the global flag of session allow should
 be recorded when concurrency is not allowed.
-check global flag before switching LPI mode for handling screen
 state and battery charging.

Change-Id: Ifb1c606aa218a36e45ba3f3e071828f6fe06169d
diff --git a/sound_trigger_hw.c b/sound_trigger_hw.c
index 6f9b6f1..eb22173 100644
--- a/sound_trigger_hw.c
+++ b/sound_trigger_hw.c
@@ -824,8 +824,10 @@
             } else {
                 ALOGV("%s: Ignore capture events as sva has dedicated path", __func__);
             }
-            pthread_mutex_unlock(&stdev->lock);
-            return;
+            if (!conc_allowed) {
+                pthread_mutex_unlock(&stdev->lock);
+                return;
+            }
         }
     } else {
         /*
@@ -842,8 +844,6 @@
                 p_ses = node_to_item(p_ses_node, st_session_t, list_node);
                 st_session_pause(p_ses);
             }
-            pthread_mutex_unlock(&stdev->lock);
-            return;
         } else {
             if (event_type == AUDIO_EVENT_CAPTURE_DEVICE_INACTIVE) {
                 list_for_each(p_ses_node, &stdev->sound_model_list) {
@@ -863,6 +863,10 @@
             }
         }
         stdev->session_allowed = conc_allowed;
+        if (!conc_allowed) {
+            pthread_mutex_unlock(&stdev->lock);
+            return;
+        }
     }
 
     /*
@@ -1139,7 +1143,7 @@
     st_hw_check_and_update_lpi(stdev, p_ses);
 
     if (stdev->lpi_enable != platform_get_lpi_mode(stdev->platform) &&
-        !is_any_session_buffering()) {
+        !is_any_session_buffering() && stdev->session_allowed) {
         list_for_each(p_ses_node, &stdev->sound_model_list) {
             p_ses = node_to_item(p_ses_node, st_session_t, list_node);
             if (p_ses && p_ses->exec_mode == ST_EXEC_MODE_ADSP) {
@@ -1192,7 +1196,7 @@
     stdev->vad_enable = st_hw_check_vad_support(stdev, p_ses,
         stdev->lpi_enable);
     if (stdev->lpi_enable != platform_get_lpi_mode(stdev->platform) &&
-        !is_any_session_buffering() &&
+        !is_any_session_buffering() && stdev->session_allowed &&
         stdev->transit_to_non_lpi_on_battery_charging) {
         list_for_each(p_ses_node, &stdev->sound_model_list) {
             p_ses = node_to_item(p_ses_node, st_session_t, list_node);