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

Commit b7bfc0f8 authored by Brian Stack's avatar Brian Stack
Browse files

Write to Wake Lock FMQ

Write the number of WAKE_UP sensor events handled by the Sensor
Service to the Wake Lock FMQ. This allows the Sensors HAL to release
its wake lock for events once the Sensor Service holds a wake lock for
the events.

Bug: 111070257
Test: Compile, configured system to use sensors@2.0 and ensured that
      a_sns_test received events
Test: Ensured device with sensors@1.0 receives events as expected
Change-Id: Ide091012bdaeb2e6a9fc4f5a43ddbb298dbf3416
parent 7b58030e
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -361,6 +361,12 @@ Return<void> SensorDevice::onDynamicSensorsDisconnected(
    return Return<void>();
}

void SensorDevice::writeWakeLockHandled(uint32_t count) {
    if (mSensors->supportsMessageQueues() && !mWakeLockQueue->write(&count)) {
        ALOGW("Failed to write wake lock handled");
    }
}

void SensorDevice::autoDisable(void *ident, int handle) {
    Mutex::Autolock _l(mLock);
    ssize_t activationIndex = mActivationCount.indexOfKey(handle);
+1 −0
Original line number Diff line number Diff line
@@ -82,6 +82,7 @@ public:
    int getHalDeviceVersion() const;

    ssize_t poll(sensors_event_t* buffer, size_t count);
    void writeWakeLockHandled(uint32_t count);

    status_t activate(void* ident, int handle, int enabled);
    status_t batch(void* ident, int handle, int flags, int64_t samplingPeriodNs,
+7 −5
Original line number Diff line number Diff line
@@ -651,17 +651,19 @@ bool SensorService::threadLoop() {
        // sending events to clients (incrementing SensorEventConnection::mWakeLockRefCount) should
        // not be interleaved with decrementing SensorEventConnection::mWakeLockRefCount and
        // releasing the wakelock.
        bool bufferHasWakeUpEvent = false;
        uint32_t wakeEvents = 0;
        for (int i = 0; i < count; i++) {
            if (isWakeUpSensorEvent(mSensorEventBuffer[i])) {
                bufferHasWakeUpEvent = true;
                break;
                wakeEvents++;
            }
        }

        if (bufferHasWakeUpEvent && !mWakeLockAcquired) {
        if (wakeEvents > 0) {
            if (!mWakeLockAcquired) {
                setWakeLockAcquiredLocked(true);
            }
            device.writeWakeLockHandled(wakeEvents);
        }
        recordLastValueLocked(mSensorEventBuffer, count);

        // handle virtual sensors