SensorService performance improvements.

  i) Send ack for wake_up sensors on the socket connection instead of using Binder RPC.
  ii) Cache events per connection in case there are write failures. Compute cache size
      from FIFO counts of sensors.
 iii) Send FlushCompleteEvent only for apps that explicitly called flush().

Change-Id: I018969736b7794b1b930529586f2294a03ee8667
diff --git a/libs/gui/SensorEventQueue.cpp b/libs/gui/SensorEventQueue.cpp
index c2eaf4e..842502d 100644
--- a/libs/gui/SensorEventQueue.cpp
+++ b/libs/gui/SensorEventQueue.cpp
@@ -18,6 +18,7 @@
 
 #include <stdint.h>
 #include <sys/types.h>
+#include <sys/socket.h>
 
 #include <utils/Errors.h>
 #include <utils/RefBase.h>
@@ -147,7 +148,14 @@
 void SensorEventQueue::sendAck(const ASensorEvent* events, int count) {
     for (int i = 0; i < count; ++i) {
         if (events[i].flags & WAKE_UP_SENSOR_EVENT_NEEDS_ACK) {
-            mSensorEventConnection->decreaseWakeLockRefCount();
+            // Send just a byte of data to acknowledge for the wake up sensor events
+            // received
+            char buf = '1';
+            ssize_t size = ::send(mSensorChannel->getFd(), &buf, sizeof(buf),
+                                             MSG_DONTWAIT | MSG_NOSIGNAL);
+            if (size < 0) {
+                ALOGE("sendAck failure %d", size);
+            }
         }
     }
     return;