summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorMathias Agopian <mathias@google.com>2010-11-10 17:50:28 -0800
committerMathias Agopian <mathias@google.com>2012-06-27 17:07:54 -0700
commit94e8f6813f3fb2beaa9bcbfb1ad9b4ae2eb46949 (patch)
tree3e914f44f392e87d17d75d946c2dae5f1e43185f /services
parent24d72350f321c17b0bfe1ef3fd52d4070a1c02c3 (diff)
downloadframeworks_native-94e8f6813f3fb2beaa9bcbfb1ad9b4ae2eb46949.zip
frameworks_native-94e8f6813f3fb2beaa9bcbfb1ad9b4ae2eb46949.tar.gz
frameworks_native-94e8f6813f3fb2beaa9bcbfb1ad9b4ae2eb46949.tar.bz2
record the last event received regardless of having clients or not
We only recorded the last received event (which is needed when a sensor is activated on a connection) when there was some connection active. This should fix an issue where sometimes the light sensor doesn't return an event whent activated. we also didn't need to hold the main lock while dispatching events to clients. Change-Id: I6c6386c040051ce205e3c0516c678e0603fa45e1
Diffstat (limited to 'services')
-rw-r--r--services/sensorservice/SensorService.cpp34
-rw-r--r--services/sensorservice/SensorService.h2
2 files changed, 22 insertions, 14 deletions
diff --git a/services/sensorservice/SensorService.cpp b/services/sensorservice/SensorService.cpp
index c9ab992..b5e73ac 100644
--- a/services/sensorservice/SensorService.cpp
+++ b/services/sensorservice/SensorService.cpp
@@ -218,25 +218,13 @@ bool SensorService::threadLoop()
break;
}
+ recordLastValue(buffer, count);
+
const SortedVector< wp<SensorEventConnection> > activeConnections(
getActiveConnections());
size_t numConnections = activeConnections.size();
if (numConnections) {
- Mutex::Autolock _l(mLock);
-
- // record the last event for each sensor
- int32_t prev = buffer[0].sensor;
- for (ssize_t i=1 ; i<count ; i++) {
- // record the last event of each sensor type in this buffer
- int32_t curr = buffer[i].sensor;
- if (curr != prev) {
- mLastEventSeen.editValueFor(prev) = buffer[i-1];
- prev = curr;
- }
- }
- mLastEventSeen.editValueFor(prev) = buffer[count-1];
-
for (size_t i=0 ; i<numConnections ; i++) {
sp<SensorEventConnection> connection(activeConnections[i].promote());
if (connection != 0) {
@@ -251,6 +239,24 @@ bool SensorService::threadLoop()
return false;
}
+void SensorService::recordLastValue(
+ sensors_event_t const * buffer, size_t count)
+{
+ Mutex::Autolock _l(mLock);
+
+ // record the last event for each sensor
+ int32_t prev = buffer[0].sensor;
+ for (size_t i=1 ; i<count ; i++) {
+ // record the last event of each sensor type in this buffer
+ int32_t curr = buffer[i].sensor;
+ if (curr != prev) {
+ mLastEventSeen.editValueFor(prev) = buffer[i-1];
+ prev = curr;
+ }
+ }
+ mLastEventSeen.editValueFor(prev) = buffer[count-1];
+}
+
SortedVector< wp<SensorService::SensorEventConnection> >
SensorService::getActiveConnections() const
{
diff --git a/services/sensorservice/SensorService.h b/services/sensorservice/SensorService.h
index dfb1c0e..b442779 100644
--- a/services/sensorservice/SensorService.h
+++ b/services/sensorservice/SensorService.h
@@ -111,6 +111,8 @@ class SensorService :
String8 getSensorName(int handle) const;
status_t recomputeEventsPeriodLocked(int32_t handle);
+ void recordLastValue(sensors_event_t const * buffer, size_t count);
+
// constants
Vector<Sensor> mSensorList;
struct sensors_poll_device_t* mSensorDevice;