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

Commit 21d72151 authored by Yifan Hong's avatar Yifan Hong Committed by android-build-merger
Browse files

Merge "Fix reference loop in IEventQueue implementation." into oc-dev

am: e382c188

Change-Id: Ie1c1a2d6b1820ce1a21d96ba523d904e635522ae
parents 05109d72 e382c188
Loading
Loading
Loading
Loading
+12 −7
Original line number Diff line number Diff line
@@ -27,7 +27,8 @@ namespace implementation {

class EventQueueLooperCallback : public ::android::LooperCallback {
public:
    EventQueueLooperCallback(sp<EventQueue> queue, sp<IEventQueueCallback> callback)
    EventQueueLooperCallback(sp<::android::SensorEventQueue> queue,
                             sp<IEventQueueCallback> callback)
            : mQueue(queue), mCallback(callback) {
    }

@@ -35,7 +36,11 @@ public:

        ASensorEvent event;
        ssize_t actual;
        const sp<::android::SensorEventQueue>& internalQueue = mQueue->mInternalQueue;

        auto internalQueue = mQueue.promote();
        if (internalQueue == nullptr) {
            return 1;
        }

        while ((actual = internalQueue->read(&event, 1 /* count */)) > 0) {
            internalQueue->sendAck(&event, actual);
@@ -47,7 +52,7 @@ public:
    }

private:
    sp<EventQueue> mQueue;
    wp<::android::SensorEventQueue> mQueue;
    sp<IEventQueueCallback> mCallback;
};

@@ -58,18 +63,18 @@ EventQueue::EventQueue(
            : mLooper(looper),
              mInternalQueue(internalQueue) {

    mLooper->addFd(mInternalQueue->getFd(), ALOOPER_POLL_CALLBACK, ALOOPER_EVENT_INPUT,
            new EventQueueLooperCallback(this, callback), NULL /* data */);
    mLooper->addFd(internalQueue->getFd(), ALOOPER_POLL_CALLBACK, ALOOPER_EVENT_INPUT,
            new EventQueueLooperCallback(internalQueue, callback), NULL /* data */);
}

EventQueue::~EventQueue() {
void EventQueue::onLastStrongRef(const void *id) {
    IEventQueue::onLastStrongRef(id);
    mLooper->removeFd(mInternalQueue->getFd());
}

// Methods from ::android::frameworks::sensorservice::V1_0::IEventQueue follow.
Return<Result> EventQueue::enableSensor(int32_t sensorHandle, int32_t samplingPeriodUs,
        int64_t maxBatchReportLatencyUs) {
    // TODO implement
    return convertResult(mInternalQueue->enableSensor(sensorHandle, samplingPeriodUs,
            maxBatchReportLatencyUs, 0 /* reserved flags */));
}
+1 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ struct EventQueue final : public IEventQueue {
        sp<IEventQueueCallback> callback,
        sp<::android::Looper> looper,
        sp<::android::SensorEventQueue> internalQueue);
    ~EventQueue();
    void onLastStrongRef(const void *) override;

    // Methods from ::android::frameworks::sensorservice::V1_0::IEventQueue follow.
    Return<Result> enableSensor(int32_t sensorHandle, int32_t samplingPeriodUs, int64_t maxBatchReportLatencyUs) override;