Version 1.9.5

- Fix occasional 100 ms stall in HIDL code.
- Perform recovery when read operations fail in VFS.
- Fix issue where a failed open() call in VFS locked the stack in
  ENABLING state.
- Fix VFS behavior when enable()/disable() called while already
  in desired state.
diff --git a/src/common/inc/ant_version.h b/src/common/inc/ant_version.h
index 02b2a0a..0a18c35 100644
--- a/src/common/inc/ant_version.h
+++ b/src/common/inc/ant_version.h
@@ -21,7 +21,7 @@
 

 #define LIBANT_STACK_MAJOR "1"

 #define LIBANT_STACK_MINOR "9"

-#define LIBANT_STACK_INCRE "4"

+#define LIBANT_STACK_INCRE "5"

 

 #endif // __ANT_VERSION_H

 

diff --git a/src/qcomm-hidl/AntHidlClient.cpp b/src/qcomm-hidl/AntHidlClient.cpp
index 50e03ba..b5cf618 100644
--- a/src/qcomm-hidl/AntHidlClient.cpp
+++ b/src/qcomm-hidl/AntHidlClient.cpp
@@ -227,13 +227,9 @@
 ANTStatus ant_rx_check()
 {
    ALOGV("%s: start", __func__);
-   if (ant_hci.rx_processing)
-   {
-      return ANT_STATUS_SUCCESS;
-   }
+   Lock lock(ant_hci.data_mtx);
    while (ant_hci.rx_processing == 0)
    {
-      std::unique_lock< std::mutex> lock(ant_hci.data_mtx);
       ant_hci.data_cond.wait_for(lock,std::chrono::milliseconds(POLL_TIMEOUT_MS));
       if (ant_hci.state != ANT_RADIO_ENABLED)
       {
diff --git a/src/vfs/ant_native_chardev.c b/src/vfs/ant_native_chardev.c
index 982fdf5..1ab8f29 100644
--- a/src/vfs/ant_native_chardev.c
+++ b/src/vfs/ant_native_chardev.c
@@ -174,16 +174,20 @@
 //  Psuedocode:
 /*
 LOCK enable_LOCK
-    State callback: STATE = ENABLING
-    ant enable
-    IF ant_enable success
-        State callback: STATE = ENABLED
-        RESULT = SUCCESS
-    ELSE
-        ant disable
-        State callback: STATE = Current state
-        RESULT = FAILURE
-    ENDIF
+   IF current_state != ENABLED
+      State callback: STATE = ENABLING
+      ant enable
+      IF ant_enable success
+         State callback: STATE = ENABLED
+         RESULT = SUCCESS
+      ELSE
+         ant disable
+         State callback: STATE = Current state
+         RESULT = FAILURE
+      ENDIF
+   ELSE
+      RESULT = SUCCESS
+   ENDIF
 UNLOCK
 */
 ////////////////////////////////////////////////////////////////////
@@ -201,23 +205,28 @@
    }
    ANT_DEBUG_V("got stEnabledStatusLock in %s", __FUNCTION__);
 
-   if (g_fnStateCallback) {
-      g_fnStateCallback(RADIO_STATUS_ENABLING);
-   }
-
-   if (ant_enable() < 0) {
-      ANT_ERROR("ant enable failed: %s", strerror(errno));
-
-      ant_disable();
-
+   if (ant_radio_enabled_status() != RADIO_STATUS_ENABLED) {
       if (g_fnStateCallback) {
-         g_fnStateCallback(ant_radio_enabled_status());
+         g_fnStateCallback(RADIO_STATUS_ENABLING);
+      }
+
+      if (ant_enable() < 0) {
+         ANT_ERROR("ant enable failed: %s", strerror(errno));
+
+         ant_disable();
+
+         if (g_fnStateCallback) {
+            g_fnStateCallback(ant_radio_enabled_status());
+         }
+      } else {
+         if (g_fnStateCallback) {
+            g_fnStateCallback(RADIO_STATUS_ENABLED);
+         }
+
+         result_status = ANT_STATUS_SUCCESS;
       }
    } else {
-      if (g_fnStateCallback) {
-         g_fnStateCallback(RADIO_STATUS_ENABLED);
-      }
-
+      ANT_DEBUG_D("Ignoring redundant enable call.");
       result_status = ANT_STATUS_SUCCESS;
    }
 
@@ -340,10 +349,12 @@
 //  Psuedocode:
 /*
 LOCK enable_LOCK
-    State callback: STATE = DISABLING
-    ant disable
-    State callback: STATE = Current state
-    RESULT = SUCCESS
+   IF current_state != DISABLED
+      State callback: STATE = DISABLING
+      ant disable
+      State callback: STATE = Current state
+   ENDIF
+   RESULT = SUCCESS
 UNLOCK
 */
 ////////////////////////////////////////////////////////////////////
@@ -361,14 +372,18 @@
    }
    ANT_DEBUG_V("got stEnabledStatusLock in %s", __FUNCTION__);
 
-   if (g_fnStateCallback) {
-      g_fnStateCallback(RADIO_STATUS_DISABLING);
-   }
+   if (ant_radio_enabled_status() != RADIO_STATUS_DISABLED) {
+      if (g_fnStateCallback) {
+         g_fnStateCallback(RADIO_STATUS_DISABLING);
+      }
 
-   ant_disable();
+      ant_disable();
 
-   if (g_fnStateCallback) {
-      g_fnStateCallback(ant_radio_enabled_status());
+      if (g_fnStateCallback) {
+         g_fnStateCallback(ant_radio_enabled_status());
+      }
+   } else {
+      ANT_DEBUG_D("Ignoring redundant disable call.");
    }
 
    ret = ANT_STATUS_SUCCESS;
@@ -934,6 +949,9 @@
    iRet = 0;
 
 out:
+   if (stRxThreadInfo.stRxThread == 0) {
+      stRxThreadInfo.ucRunThread = 0;
+   }
    ANT_FUNC_END();
    return iRet;
 }
diff --git a/src/vfs/ant_rx_chardev.c b/src/vfs/ant_rx_chardev.c
index 3f2718c..c1027d5 100644
--- a/src/vfs/ant_rx_chardev.c
+++ b/src/vfs/ant_rx_chardev.c
@@ -162,7 +162,8 @@
             } else if (areAllFlagsSet(astPollFd[eChannel].revents, EVENT_CHIP_SHUTDOWN)) {
                /* chip reported it was unexpectedly disabled */
                ANT_DEBUG_D(
-                     "poll hang-up from %s. exiting rx thread", stRxThreadInfo->astChannels[eChannel].pcDevicePath);
+                     "poll hang-up from %s. Attempting recovery.",
+                     stRxThreadInfo->astChannels[eChannel].pcDevicePath);
 
                doReset(stRxThreadInfo);
                goto out;
@@ -174,8 +175,9 @@
                stRxThreadInfo->bWaitingForKeepaliveResponse = ANT_FALSE;
 
                if (readChannelMsg(eChannel, &stRxThreadInfo->astChannels[eChannel]) < 0) {
-                  // set flag to exit out of Rx Loop
-                  stRxThreadInfo->ucRunThread = 0;
+                  ANT_ERROR("Read of data failed. Attempting recovery.");
+                  doReset(stRxThreadInfo);
+                  goto out;
                }
             } else if (areAllFlagsSet(astPollFd[eChannel].revents, POLLNVAL)) {
                ANT_ERROR("poll was called on invalid file descriptor %s. Attempting recovery.",
@@ -360,7 +362,7 @@
 
    if (iRxLenRead < 0) {
       if (errno == ENODEV) {
-         ANT_ERROR("%s not enabled, exiting rx thread",
+         ANT_ERROR("%s not enabled",
                pstChnlInfo->pcDevicePath);
 
          goto out;
@@ -370,7 +372,7 @@
 
          goto out;
       } else {
-         ANT_ERROR("%s read thread exiting, unhandled error: %s",
+         ANT_ERROR("%s: unhandled error: %s",
                pstChnlInfo->pcDevicePath, strerror(errno));
 
          goto out;