summaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
authorAravind Akella <aakella@google.com>2015-04-25 01:40:34 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-04-25 01:40:35 +0000
commitcc60dc2128a98f952beb187da22b28dcba0124ad (patch)
treedc3f49b98b22ed7e0b11dafc5d93abd12acdf937 /libs
parent0f7723f6b48e3324f6cd3fa001413b1ea5e32efb (diff)
parenta9e6cc387072e25706a6d847a97b02a6f25a918b (diff)
downloadframeworks_native-cc60dc2128a98f952beb187da22b28dcba0124ad.zip
frameworks_native-cc60dc2128a98f952beb187da22b28dcba0124ad.tar.gz
frameworks_native-cc60dc2128a98f952beb187da22b28dcba0124ad.tar.bz2
Merge "Enable data injection mode in SensorService."
Diffstat (limited to 'libs')
-rw-r--r--libs/gui/ISensorServer.cpp23
-rw-r--r--libs/gui/SensorEventQueue.cpp10
-rw-r--r--libs/gui/SensorManager.cpp21
3 files changed, 44 insertions, 10 deletions
diff --git a/libs/gui/ISensorServer.cpp b/libs/gui/ISensorServer.cpp
index 3c85ec0..140712e 100644
--- a/libs/gui/ISensorServer.cpp
+++ b/libs/gui/ISensorServer.cpp
@@ -35,6 +35,7 @@ namespace android {
enum {
GET_SENSOR_LIST = IBinder::FIRST_CALL_TRANSACTION,
CREATE_SENSOR_EVENT_CONNECTION,
+ ENABLE_DATA_INJECTION
};
class BpSensorServer : public BpInterface<ISensorServer>
@@ -63,14 +64,24 @@ public:
return v;
}
- virtual sp<ISensorEventConnection> createSensorEventConnection(const String8& packageName)
+ virtual sp<ISensorEventConnection> createSensorEventConnection(const String8& packageName,
+ int mode)
{
Parcel data, reply;
data.writeInterfaceToken(ISensorServer::getInterfaceDescriptor());
data.writeString8(packageName);
+ data.writeInt32(mode);
remote()->transact(CREATE_SENSOR_EVENT_CONNECTION, data, &reply);
return interface_cast<ISensorEventConnection>(reply.readStrongBinder());
}
+
+ virtual status_t enableDataInjection(int enable) {
+ Parcel data, reply;
+ data.writeInterfaceToken(ISensorServer::getInterfaceDescriptor());
+ data.writeInt32(enable);
+ remote()->transact(ENABLE_DATA_INJECTION, data, &reply);
+ return reply.readInt32();
+ }
};
// Out-of-line virtual method definition to trigger vtable emission in this
@@ -98,10 +109,18 @@ status_t BnSensorServer::onTransact(
case CREATE_SENSOR_EVENT_CONNECTION: {
CHECK_INTERFACE(ISensorServer, data, reply);
String8 packageName = data.readString8();
- sp<ISensorEventConnection> connection(createSensorEventConnection(packageName));
+ int32_t mode = data.readInt32();
+ sp<ISensorEventConnection> connection(createSensorEventConnection(packageName, mode));
reply->writeStrongBinder(IInterface::asBinder(connection));
return NO_ERROR;
}
+ case ENABLE_DATA_INJECTION: {
+ CHECK_INTERFACE(ISensorServer, data, reply);
+ int32_t enable = data.readInt32();
+ status_t ret = enableDataInjection(enable);
+ reply->writeInt32(static_cast<int32_t>(ret));
+ return NO_ERROR;
+ }
}
return BBinder::onTransact(code, data, reply, flags);
}
diff --git a/libs/gui/SensorEventQueue.cpp b/libs/gui/SensorEventQueue.cpp
index 76ae470..b5b5d68 100644
--- a/libs/gui/SensorEventQueue.cpp
+++ b/libs/gui/SensorEventQueue.cpp
@@ -149,6 +149,16 @@ status_t SensorEventQueue::setEventRate(Sensor const* sensor, nsecs_t ns) const
return mSensorEventConnection->setEventRate(sensor->getHandle(), ns);
}
+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 size;
+ }
+ return NO_ERROR;
+}
+
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) {
diff --git a/libs/gui/SensorManager.cpp b/libs/gui/SensorManager.cpp
index 142c6ec..cedcf56 100644
--- a/libs/gui/SensorManager.cpp
+++ b/libs/gui/SensorManager.cpp
@@ -100,8 +100,6 @@ status_t SensorManager::assertStateLocked() const {
return NO_ERROR;
}
-
-
ssize_t SensorManager::getSensorList(Sensor const* const** list) const
{
Mutex::Autolock _l(mLock);
@@ -139,18 +137,17 @@ Sensor const* SensorManager::getDefaultSensor(int type)
return NULL;
}
-sp<SensorEventQueue> SensorManager::createEventQueue(String8 packageName)
-{
+sp<SensorEventQueue> SensorManager::createEventQueue(String8 packageName, int mode) {
sp<SensorEventQueue> queue;
Mutex::Autolock _l(mLock);
while (assertStateLocked() == NO_ERROR) {
sp<ISensorEventConnection> connection =
- mSensorServer->createSensorEventConnection(packageName);
+ mSensorServer->createSensorEventConnection(packageName, mode);
if (connection == NULL) {
- // SensorService just died.
- ALOGE("createEventQueue: connection is NULL. SensorService died.");
- continue;
+ // SensorService just died or the app doesn't have required permissions.
+ ALOGE("createEventQueue: connection is NULL.");
+ return NULL;
}
queue = new SensorEventQueue(connection);
break;
@@ -158,5 +155,13 @@ sp<SensorEventQueue> SensorManager::createEventQueue(String8 packageName)
return queue;
}
+status_t SensorManager::enableDataInjection(bool enable) {
+ Mutex::Autolock _l(mLock);
+ if (assertStateLocked() == NO_ERROR) {
+ return mSensorServer->enableDataInjection(enable);
+ }
+ return INVALID_OPERATION;
+}
+
// ----------------------------------------------------------------------------
}; // namespace android