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

Commit d8119dab authored by Mark Wheatley's avatar Mark Wheatley
Browse files

Send wake event to ISensorHalWrapper fmq when switching to Hal Bypass Mode

When switching from NORMAL to HAL_BYPASS_REPLAY_DATA_INJECTION mode, the
ISensorHalWrapper::pollFmq() method continues to wait for sensor events.
Since the sensors are disabled when switching to Hal Bypass mode, the
polling thread may continue to wait on the fmq indefinitely.

Send an internal wake event to the fmq when switching to Hal Bypass
mode so that the thread drops out of pollFmq() and enters the branch for
accepting injected replay data.

Bug: 326433087
Test: manual
Change-Id: I984e55f64469cfac1c9156ea4660fc1dc4818695
parent 611a65d5
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -178,6 +178,11 @@ ssize_t AidlSensorHalWrapper::pollFmq(sensors_event_t *buffer, size_t maxNumEven
        if ((eventFlagState & asBaseType(INTERNAL_WAKE)) && mReconnecting) {
            ALOGD("Event FMQ internal wake, returning from poll with no events");
            return DEAD_OBJECT;
        } else if ((eventFlagState & asBaseType(INTERNAL_WAKE)) && mInHalBypassMode &&
                   availableEvents == 0) {
            ALOGD("Event FMQ internal wake due to HAL Bypass Mode, returning from poll with no "
                  "events");
            return OK;
        }
    }

@@ -221,6 +226,17 @@ std::vector<sensor_t> AidlSensorHalWrapper::getSensorsList() {

status_t AidlSensorHalWrapper::setOperationMode(SensorService::Mode mode) {
    if (mSensors == nullptr) return NO_INIT;
    if (mode == SensorService::Mode::HAL_BYPASS_REPLAY_DATA_INJECTION) {
        if (!mInHalBypassMode) {
            mInHalBypassMode = true;
            mEventQueueFlag->wake(asBaseType(INTERNAL_WAKE));
        }
        return OK;
    } else {
        if (mInHalBypassMode) {
            mInHalBypassMode = false;
        }
    }
    return convertToStatus(mSensors->setOperationMode(static_cast<ISensors::OperationMode>(mode)));
}

+16 −0
Original line number Diff line number Diff line
@@ -203,6 +203,11 @@ ssize_t HidlSensorHalWrapper::pollFmq(sensors_event_t* buffer, size_t maxNumEven
        if ((eventFlagState & asBaseType(INTERNAL_WAKE)) && mReconnecting) {
            ALOGD("Event FMQ internal wake, returning from poll with no events");
            return DEAD_OBJECT;
        } else if ((eventFlagState & asBaseType(INTERNAL_WAKE)) && mInHalBypassMode &&
                   availableEvents == 0) {
            ALOGD("Event FMQ internal wake due to HAL Bypass Mode, returning from poll with no "
                  "events");
            return OK;
        }
    }

@@ -251,6 +256,17 @@ std::vector<sensor_t> HidlSensorHalWrapper::getSensorsList() {

status_t HidlSensorHalWrapper::setOperationMode(SensorService::Mode mode) {
    if (mSensors == nullptr) return NO_INIT;
    if (mode == SensorService::Mode::HAL_BYPASS_REPLAY_DATA_INJECTION) {
        if (!mInHalBypassMode) {
            mInHalBypassMode = true;
            mEventQueueFlag->wake(asBaseType(INTERNAL_WAKE));
        }
        return OK;
    } else {
        if (mInHalBypassMode) {
            mInHalBypassMode = false;
        }
    }
    return checkReturnAndGetStatus(
            mSensors->setOperationMode(static_cast<hardware::sensors::V1_0::OperationMode>(mode)));
}
+2 −0
Original line number Diff line number Diff line
@@ -97,6 +97,8 @@ public:
    virtual void writeWakeLockHandled(uint32_t count) = 0;

    std::atomic_bool mReconnecting = false;

    std::atomic_bool mInHalBypassMode = false;
};

} // namespace android
+0 −1
Original line number Diff line number Diff line
@@ -812,7 +812,6 @@ status_t SensorDevice::setMode(uint32_t mode) {
            }
            mInHalBypassMode = true;
        }
        return OK;
    } else {
        if (mInHalBypassMode) {
            // We are transitioning out of HAL Bypass mode. We need to notify the reader thread