Merge "Fix the command timeout issue by set LPM idle time"
diff --git a/libbt-vendor/src/bt_vendor_qcom.c b/libbt-vendor/src/bt_vendor_qcom.c
index 0d03c85..c388d8a 100644
--- a/libbt-vendor/src/bt_vendor_qcom.c
+++ b/libbt-vendor/src/bt_vendor_qcom.c
@@ -50,7 +50,9 @@
 #endif
 
 #define CMD_TIMEOUT  0x22
-void wait_for_patch_download();
+
+static void wait_for_patch_download(bool is_ant_req);
+
 /******************************************************************************
 **  Externs
 ******************************************************************************/
@@ -238,8 +240,8 @@
         ALOGV("%s: on : value is: %d", __func__, value);
         if(value == 1)
         {
-          property_get("wc_transport.patch_dnld_inprog", inProgress, "0");
-          if((is_soc_initialized() == true) || (strcmp(inProgress,"1") == 0))
+          property_get("wc_transport.patch_dnld_inprog", inProgress, "null");
+          if((is_soc_initialized() == true) || (strcmp(inProgress,"null") != 0))
           {
             value++;
             ALOGV("%s: on : value is incremented to : %d", __func__, value);
@@ -249,15 +251,19 @@
         {
              value++;
         }
+
         if (value == 1)
            can_perform = true;
-        else if (value > 2) return false;
-    } else  {
+        else if (value > 2)
+           return false;
+    }
+    else {
         ALOGV("%s: off : value is: %d", __func__, value);
         value--;
         if (value == 0)
            can_perform = true;
-        else if (value < 0) return false;
+        else if (value < 0)
+           return false;
     }
 
     snprintf(ref_count, 3, "%d", value);
@@ -765,12 +771,14 @@
                         break;
                     case BT_SOC_ROME:
                         {
-                            wait_for_patch_download();
+                            wait_for_patch_download(is_ant_req);
                             property_get("ro.bluetooth.emb_wp_mode", emb_wp_mode, false);
                             if (!is_soc_initialized()) {
-                                if (property_set("wc_transport.patch_dnld_inprog", "1") < 0) {
-                                    ALOGE("%s: Failed to set property", __FUNCTION__);
+                                char* dlnd_inprog = is_ant_req ? "ant" : "bt";
+                                if (property_set("wc_transport.patch_dnld_inprog", dlnd_inprog) < 0) {
+                                    ALOGE("%s: Failed to set dnld_inprog %s", __FUNCTION__, dlnd_inprog);
                                 }
+
                                 fd = userial_vendor_open((tUSERIAL_CFG *) &userial_init_cfg);
                                 if (fd < 0) {
                                     ALOGE("userial_vendor_open returns err");
@@ -843,7 +851,7 @@
                                     }
                                 }
                             }
-                            if (property_set("wc_transport.patch_dnld_inprog", "0") < 0) {
+                            if (property_set("wc_transport.patch_dnld_inprog", "null") < 0) {
                                 ALOGE("%s: Failed to set property", __FUNCTION__);
                             }
 
@@ -1062,7 +1070,7 @@
     int ret;
     unsigned char trig_ssr = 0xEE;
     ALOGI("ssr_cleanup");
-    if (property_set("wc_transport.patch_dnld_inprog", "0") < 0) {
+    if (property_set("wc_transport.patch_dnld_inprog", "null") < 0) {
         ALOGE("%s: Failed to set property", __FUNCTION__);
     }
 
@@ -1116,12 +1124,18 @@
 /* Check for one of the cients ANT/BT patch download is already in
 ** progress if yes wait till complete
 */
-void wait_for_patch_download() {
+void wait_for_patch_download(bool is_ant_req) {
     ALOGV("%s:", __FUNCTION__);
     char inProgress[PROPERTY_VALUE_MAX] = {'\0'};
     while (1) {
-        property_get("wc_transport.patch_dnld_inprog", inProgress, "0");
-        if(strcmp(inProgress,"1") == 0) {
+        property_get("wc_transport.patch_dnld_inprog", inProgress, "null");
+
+        if(is_ant_req && !strcmp(inProgress,"bt") ) {
+           //ANT request, wait for BT to finish
+           usleep(50000);
+        }
+        else if(!is_ant_req && !strcmp(inProgress,"ant") ) {
+           //BT request, wait for ANT to finish
            usleep(50000);
         }
         else {