hal: correct logic to check soundcard offline status

- when SSR is triggered while pcm-offload playback
  is going on, once soundcard is online playback is
  mute

- after SSR is complete hal tries to open stream and
  it gets the error ENETRESET, as global errno is not
  updated and have a stale value which is ENETRESET

- along with errno check is_compress_ready to make
  sure stream open failed as sound card is offline

CRs-fixed: 2237234

Change-Id: I95e2631c858ac7674ba8005cee5cd4e538a3d626
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 16ac7f4..f452f99 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -2498,7 +2498,7 @@
             in->pcm = pcm_open(adev->snd_card, in->pcm_device_id,
                                flags, &config);
             ATRACE_END();
-            if (errno == ENETRESET) {
+            if (errno == ENETRESET && !pcm_is_ready(in->pcm)) {
                 ALOGE("%s: pcm_open failed errno:%d\n", __func__, errno);
                 adev->card_status = CARD_STATUS_OFFLINE;
                 in->card_status = CARD_STATUS_OFFLINE;
@@ -3092,7 +3092,7 @@
             out->pcm = pcm_open(adev->snd_card, out->pcm_device_id,
                                flags, &out->config);
             ATRACE_END();
-            if (errno == ENETRESET) {
+            if (errno == ENETRESET && !pcm_is_ready(out->pcm)) {
                 ALOGE("%s: pcm_open failed errno:%d\n", __func__, errno);
                 out->card_status = CARD_STATUS_OFFLINE;
                 adev->card_status = CARD_STATUS_OFFLINE;
@@ -3146,7 +3146,7 @@
                                    out->pcm_device_id,
                                    COMPRESS_IN, &out->compr_config);
         ATRACE_END();
-        if (errno == ENETRESET) {
+        if (errno == ENETRESET && !is_compress_ready(out->compr)) {
                 ALOGE("%s: compress_open failed errno:%d\n", __func__, errno);
                 adev->card_status = CARD_STATUS_OFFLINE;
                 out->card_status = CARD_STATUS_OFFLINE;
@@ -4970,7 +4970,7 @@
           __func__, adev->snd_card, out->pcm_device_id, out->config.channels);
     out->pcm = pcm_open(adev->snd_card, out->pcm_device_id,
                         (PCM_OUT | PCM_MMAP | PCM_NOIRQ | PCM_MONOTONIC), &out->config);
-    if (errno == ENETRESET) {
+    if (errno == ENETRESET && !pcm_is_ready(out->pcm)) {
         ALOGE("%s: pcm_open failed errno:%d\n", __func__, errno);
         out->card_status = CARD_STATUS_OFFLINE;
         adev->card_status = CARD_STATUS_OFFLINE;
@@ -5592,7 +5592,7 @@
           __func__, adev->snd_card, in->pcm_device_id, in->config.channels);
     in->pcm = pcm_open(adev->snd_card, in->pcm_device_id,
                         (PCM_IN | PCM_MMAP | PCM_NOIRQ | PCM_MONOTONIC), &in->config);
-    if (errno == ENETRESET) {
+    if (errno == ENETRESET && !pcm_is_ready(in->pcm)) {
         ALOGE("%s: pcm_open failed errno:%d\n", __func__, errno);
         in->card_status = CARD_STATUS_OFFLINE;
         adev->card_status = CARD_STATUS_OFFLINE;