hal: Check A2dp state before bt ipc library calls

Codec config check before a2dp has started successfully results
in failures in bt ipc library. Checking for a2dp ready
before bt state transitions to connected leads to synchronization
issues in bt ipc library. Fix these two issues by adding relevant
state checks.

CRs-Fixed: 2018123
Change-Id: Ie3fcef9b4a0e703eff6c57c857d31281611e156c
diff --git a/hal/audio_extn/a2dp.c b/hal/audio_extn/a2dp.c
index 40632bc..659d72c 100644
--- a/hal/audio_extn/a2dp.c
+++ b/hal/audio_extn/a2dp.c
@@ -808,7 +808,8 @@
 {
     bool ret = false;
 
-    if ((a2dp.is_a2dp_offload_supported) &&
+    if ((a2dp.bt_state != A2DP_STATE_DISCONNECTED) &&
+        (a2dp.is_a2dp_offload_supported) &&
         (a2dp.audio_check_a2dp_ready))
            ret = a2dp.audio_check_a2dp_ready();
     return ret;
@@ -843,7 +844,9 @@
         ALOGE(" a2dp handle is not identified");
         return latency;
     }
-    codec_info = a2dp.audio_get_codec_config(&multi_cast, &num_dev,
+
+    if (a2dp.a2dp_started)
+        codec_info = a2dp.audio_get_codec_config(&multi_cast, &num_dev,
                                &codec_type);
 
     memset(value, '\0', sizeof(char)*PROPERTY_VALUE_MAX);