OSDN Git Service

[sensorservice] Fix on-change sensor send latest value on enable
authorPeng Xu <pengxu@google.com>
Mon, 2 May 2016 21:15:50 +0000 (14:15 -0700)
committerPeng Xu <pengxu@google.com>
Mon, 2 May 2016 21:32:59 +0000 (14:32 -0700)
This CL correct the behavior of sensorservice so that the latest
value of on-change sensor is send to client when enabling sensor.

The errornous behavior before is that sensorservice send the oldest
value in local cache.

Bug: 28480791
Change-Id: I7e0b8e52fa0be62ba95910789cff1fe0d4fbb03f

services/sensorservice/RecentEventLogger.cpp

index dba7211..754b603 100644 (file)
@@ -76,7 +76,8 @@ bool RecentEventLogger::populateLastEvent(sensors_event_t *event) const {
     std::lock_guard<std::mutex> lk(mLock);
 
     if (mRecentEvents.size()) {
-        *event = mRecentEvents[mRecentEvents.size()-1].mEvent;
+        // Index 0 contains the latest event emplace()'ed
+        *event = mRecentEvents[0].mEvent;
         return true;
     } else {
         return false;