hal: avoid echo reference is disabled when closing input stream

When voip runs in background, there is a recording wants to start,
due to APM forbid two input stream are active at same time, the
recording starts failure. And echo reference is disabled when
closing the input stream even if voip is still active in background.

Fix it by avoiding disable echo reference when there are no active
input and hfp call.

CRs-Fixed: 2357317
Change-Id: Ib36ec449fac41f3ed4147660dafbb60c3eb82f67
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index e49782f..133939f 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -7428,8 +7428,10 @@
     // between the callback and close_stream
     audio_extn_snd_mon_unregister_listener(stream);
 
-    /* Disable echo reference while closing input stream */
-    platform_set_echo_reference(adev, false, AUDIO_DEVICE_NONE);
+    // Disable echo reference if there are no active input and hfp call
+    // while closing input stream
+    if (!adev->active_input && !audio_extn_hfp_is_active(adev))
+        platform_set_echo_reference(adev, false, AUDIO_DEVICE_NONE);
 
     if (in == NULL) {
         ALOGE("%s: audio_stream_in ptr is NULL", __func__);