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

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

Notify Wake Lock Queue's EventFlag after write

Signal to the Wake Lock Queue's EventFlag that data has been written
to the queue. This allows for a reader of the queue to block until
data is available.

Bug: 122528664
Test: Verified Sensors HAL 2.0 default implementation properly reads
      the Wake Lock FMQ

Change-Id: I60f76e91c5b91d97156ad0328c10beb1111ba7b5
parent a1fb7779
Loading
Loading
Loading
Loading
+21 −4
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ using namespace android::hardware::sensors::V1_0;
using namespace android::hardware::sensors::V1_0::implementation;
using android::hardware::sensors::V2_0::ISensorsCallback;
using android::hardware::sensors::V2_0::EventQueueFlagBits;
using android::hardware::sensors::V2_0::WakeLockQueueFlagBits;
using android::hardware::hidl_vec;
using android::hardware::Return;
using android::SensorDeviceUtils::HidlServiceRegistrationWaiter;
@@ -94,6 +95,8 @@ struct SensorsCallback : public ISensorsCallback {
SensorDevice::SensorDevice()
        : mHidlTransportErrors(20),
          mRestartWaiter(new HidlServiceRegistrationWaiter()),
          mEventQueueFlag(nullptr),
          mWakeLockQueueFlag(nullptr),
          mReconnecting(false) {
    if (!connectHidlService()) {
        return;
@@ -137,6 +140,11 @@ SensorDevice::~SensorDevice() {
        hardware::EventFlag::deleteEventFlag(&mEventQueueFlag);
        mEventQueueFlag = nullptr;
    }

    if (mWakeLockQueueFlag != nullptr) {
        hardware::EventFlag::deleteEventFlag(&mWakeLockQueueFlag);
        mWakeLockQueueFlag = nullptr;
    }
}

bool SensorDevice::connectHidlService() {
@@ -198,10 +206,16 @@ SensorDevice::HalConnectionStatus SensorDevice::connectHidlServiceV2_0() {
                SensorEventQueue::MAX_RECEIVE_BUFFER_EVENT_COUNT,
                true /* configureEventFlagWord */);

        hardware::EventFlag::deleteEventFlag(&mEventQueueFlag);
        hardware::EventFlag::createEventFlag(mEventQueue->getEventFlagWord(), &mEventQueueFlag);

        hardware::EventFlag::deleteEventFlag(&mWakeLockQueueFlag);
        hardware::EventFlag::createEventFlag(mWakeLockQueue->getEventFlagWord(),
                                             &mWakeLockQueueFlag);

        CHECK(mSensors != nullptr && mEventQueue != nullptr &&
                mWakeLockQueue != nullptr && mEventQueueFlag != nullptr);
                mWakeLockQueue != nullptr && mEventQueueFlag != nullptr &&
                mWakeLockQueueFlag != nullptr);

        status_t status = StatusFromResult(checkReturn(mSensors->initialize(
                *mEventQueue->getDesc(),
@@ -512,11 +526,14 @@ Return<void> SensorDevice::onDynamicSensorsDisconnected(
}

void SensorDevice::writeWakeLockHandled(uint32_t count) {
    if (mSensors != nullptr && mSensors->supportsMessageQueues() &&
            !mWakeLockQueue->write(&count)) {
    if (mSensors != nullptr && mSensors->supportsMessageQueues()) {
        if (mWakeLockQueue->write(&count)) {
            mWakeLockQueueFlag->wake(asBaseType(WakeLockQueueFlagBits::DATA_WRITTEN));
        } else {
            ALOGW("Failed to write wake lock handled");
        }
    }
}

void SensorDevice::autoDisable(void *ident, int handle) {
    Mutex::Autolock _l(mLock);
+1 −0
Original line number Diff line number Diff line
@@ -238,6 +238,7 @@ private:
    std::unique_ptr<WakeLockQueue> mWakeLockQueue;

    hardware::EventFlag* mEventQueueFlag;
    hardware::EventFlag* mWakeLockQueueFlag;

    std::array<Event, SensorEventQueue::MAX_RECEIVE_BUFFER_EVENT_COUNT> mEventBuffer;