summaryrefslogtreecommitdiffstats
path: root/libs/gui/SensorEventQueue.cpp
diff options
context:
space:
mode:
authorAravind Akella <aakella@google.com>2015-06-29 12:37:48 -0700
committerAravind Akella <aakella@google.com>2015-06-30 14:59:58 -0700
commit841a5926fc9b3f9f0e654ba3aab8e43bea7de7f1 (patch)
tree61960586e0c251477aeaa750e9ab0f3d808580ed /libs/gui/SensorEventQueue.cpp
parent3643c88f7b557e241d65c4857eaf49e28e7c03a2 (diff)
downloadframeworks_native-841a5926fc9b3f9f0e654ba3aab8e43bea7de7f1.zip
frameworks_native-841a5926fc9b3f9f0e654ba3aab8e43bea7de7f1.tar.gz
frameworks_native-841a5926fc9b3f9f0e654ba3aab8e43bea7de7f1.tar.bz2
Enable sensor data injection mode through adb.
Change-Id: I415cf8ff0871fa74babaf9b879c68f210298b472
Diffstat (limited to 'libs/gui/SensorEventQueue.cpp')
-rw-r--r--libs/gui/SensorEventQueue.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/libs/gui/SensorEventQueue.cpp b/libs/gui/SensorEventQueue.cpp
index 8b2018f..4b7986e 100644
--- a/libs/gui/SensorEventQueue.cpp
+++ b/libs/gui/SensorEventQueue.cpp
@@ -20,6 +20,7 @@
#include <stdint.h>
#include <sys/types.h>
#include <sys/socket.h>
+#include <linux/errno.h>
#include <utils/Errors.h>
#include <utils/RefBase.h>
@@ -150,13 +151,20 @@ status_t SensorEventQueue::setEventRate(Sensor const* sensor, nsecs_t ns) const
}
status_t SensorEventQueue::injectSensorEvent(const ASensorEvent& event) {
- // Blocking call.
- ssize_t size = ::send(mSensorChannel->getFd(), &event, sizeof(event), MSG_NOSIGNAL);
- if (size < 0) {
- ALOGE("injectSensorEvent failure %zd %d", size, mSensorChannel->getFd());
- return INVALID_OPERATION;
- }
- return NO_ERROR;
+ do {
+ // Blocking call.
+ ssize_t size = ::send(mSensorChannel->getFd(), &event, sizeof(event), MSG_NOSIGNAL);
+ if (size >= 0) {
+ return NO_ERROR;
+ } else if (size < 0 && errno == EAGAIN) {
+ // If send is returning a "Try again" error, sleep for 100ms and try again. In all
+ // other cases log a failure and exit.
+ usleep(100000);
+ } else {
+ ALOGE("injectSensorEvent failure %s %zd", strerror(errno), size);
+ return INVALID_OPERATION;
+ }
+ } while (true);
}
void SensorEventQueue::sendAck(const ASensorEvent* events, int count) {