Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 228bd90c authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Prevent stale event from being delivered to client" into qt-dev

parents e25f352e 26029ee2
Loading
Loading
Loading
Loading
+14 −9
Original line number Diff line number Diff line
@@ -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.