summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2019-04-23 18:35:27 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2019-04-23 18:35:27 +0000
commit228bd90c176839ad337507fe5a5c98b4cd68bfdd (patch)
tree976c72605fa167fe26422b06db5512d02376bf41
parente25f352e8ba3a1da597b2a9bcb3d1b7905be4465 (diff)
parent26029ee232500a3a58464465319e61eb79b79c6f (diff)
Merge "Prevent stale event from being delivered to client" into qt-dev
-rw-r--r--services/sensorservice/SensorService.cpp23
1 files changed, 14 insertions, 9 deletions
diff --git a/services/sensorservice/SensorService.cpp b/services/sensorservice/SensorService.cpp
index cbdd4739a3..02699906ed 100644
--- a/services/sensorservice/SensorService.cpp
+++ b/services/sensorservice/SensorService.cpp
@@ -1381,15 +1381,6 @@ void SensorService::cleanupConnection(SensorEventConnection* c) {
ALOGD_IF(DEBUG_CONNECTIONS, "... and it was the last connection");
mActiveSensors.removeItemsAt(i, 1);
mActiveVirtualSensors.erase(handle);
-
- // If this is the last connection, then mark the RecentEventLogger as stale. This is
- // critical for on-change events since the previous event is sent to a client if the
- // sensor is already active. If two clients request the sensor at the same time, one
- // of the clients would receive a stale event.
- auto logger = mRecentEvent.find(handle);
- if (logger != mRecentEvent.end()) {
- logger->second->setLastEventStale();
- }
delete rec;
size--;
} else {
@@ -1444,6 +1435,20 @@ status_t SensorService::enable(const sp<SensorEventConnection>& connection,
if (sensor->isVirtual()) {
mActiveVirtualSensors.emplace(handle);
}
+
+ // There was no SensorRecord for this sensor which means it was previously disabled. Mark
+ // the recent event as stale to ensure that the previous event is not sent to a client. This
+ // ensures on-change events that were generated during a previous sensor activation are not
+ // erroneously sent to newly connected clients, especially if a second client registers for
+ // an on-change sensor before the first client receives the updated event. Once an updated
+ // event is received, the recent events will be marked as current, and any new clients will
+ // immediately receive the most recent event.
+ if (sensor->getSensor().getReportingMode() == AREPORTING_MODE_ON_CHANGE) {
+ auto logger = mRecentEvent.find(handle);
+ if (logger != mRecentEvent.end()) {
+ logger->second->setLastEventStale();
+ }
+ }
} else {
if (rec->addConnection(connection)) {
// this sensor is already activated, but we are adding a connection that uses it.