From 841a5926fc9b3f9f0e654ba3aab8e43bea7de7f1 Mon Sep 17 00:00:00 2001 From: Aravind Akella Date: Mon, 29 Jun 2015 12:37:48 -0700 Subject: Enable sensor data injection mode through adb. Change-Id: I415cf8ff0871fa74babaf9b879c68f210298b472 --- libs/gui/ISensorServer.cpp | 6 ++---- libs/gui/SensorEventQueue.cpp | 22 +++++++++++++++------- libs/gui/SensorManager.cpp | 6 +++--- 3 files changed, 20 insertions(+), 14 deletions(-) (limited to 'libs') diff --git a/libs/gui/ISensorServer.cpp b/libs/gui/ISensorServer.cpp index 5dde9f9..f581b5c 100644 --- a/libs/gui/ISensorServer.cpp +++ b/libs/gui/ISensorServer.cpp @@ -77,10 +77,9 @@ public: return interface_cast(reply.readStrongBinder()); } - virtual status_t enableDataInjection(int enable) { + virtual int isDataInjectionEnabled() { Parcel data, reply; data.writeInterfaceToken(ISensorServer::getInterfaceDescriptor()); - data.writeInt32(enable); remote()->transact(ENABLE_DATA_INJECTION, data, &reply); return reply.readInt32(); } @@ -121,8 +120,7 @@ status_t BnSensorServer::onTransact( } case ENABLE_DATA_INJECTION: { CHECK_INTERFACE(ISensorServer, data, reply); - int32_t enable = data.readInt32(); - status_t ret = enableDataInjection(enable); + int32_t ret = isDataInjectionEnabled(); reply->writeInt32(static_cast(ret)); return NO_ERROR; } 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 #include #include +#include #include #include @@ -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) { diff --git a/libs/gui/SensorManager.cpp b/libs/gui/SensorManager.cpp index 8c9f95b..dd37781 100644 --- a/libs/gui/SensorManager.cpp +++ b/libs/gui/SensorManager.cpp @@ -153,12 +153,12 @@ sp SensorManager::createEventQueue(String8 packageName, int mo return queue; } -status_t SensorManager::enableDataInjection(bool enable) { +bool SensorManager::isDataInjectionEnabled() { Mutex::Autolock _l(mLock); if (assertStateLocked() == NO_ERROR) { - return mSensorServer->enableDataInjection(enable); + return mSensorServer->isDataInjectionEnabled(); } - return INVALID_OPERATION; + return false; } // ---------------------------------------------------------------------------- -- cgit v1.1