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

Commit fcf7524d authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Avoid using raw pointers in QueuedInputListener

The previous code was correct, but we can simplify it by converting to
unique_ptr.
This should give us a different crash signature next time, and maybe
provide us with more clues about the cause.

Bug: 217647732
Test: atest inputflinger_tests
Change-Id: I700de2bea60a4fc1cac65e9bc6ac082d863e52b1
(cherry picked from commit 542398ea)
parent 7038a115
Loading
Loading
Loading
Loading
+9 −19
Original line number Diff line number Diff line
@@ -334,60 +334,50 @@ static inline void traceEvent(const char* functionName, int32_t id) {
QueuedInputListener::QueuedInputListener(InputListenerInterface& innerListener)
      : mInnerListener(innerListener) {}

QueuedInputListener::~QueuedInputListener() {
    size_t count = mArgsQueue.size();
    for (size_t i = 0; i < count; i++) {
        delete mArgsQueue[i];
    }
}

void QueuedInputListener::notifyConfigurationChanged(
        const NotifyConfigurationChangedArgs* args) {
    traceEvent(__func__, args->id);
    mArgsQueue.push_back(new NotifyConfigurationChangedArgs(*args));
    mArgsQueue.emplace_back(std::make_unique<NotifyConfigurationChangedArgs>(*args));
}

void QueuedInputListener::notifyKey(const NotifyKeyArgs* args) {
    traceEvent(__func__, args->id);
    mArgsQueue.push_back(new NotifyKeyArgs(*args));
    mArgsQueue.emplace_back(std::make_unique<NotifyKeyArgs>(*args));
}

void QueuedInputListener::notifyMotion(const NotifyMotionArgs* args) {
    traceEvent(__func__, args->id);
    mArgsQueue.push_back(new NotifyMotionArgs(*args));
    mArgsQueue.emplace_back(std::make_unique<NotifyMotionArgs>(*args));
}

void QueuedInputListener::notifySwitch(const NotifySwitchArgs* args) {
    traceEvent(__func__, args->id);
    mArgsQueue.push_back(new NotifySwitchArgs(*args));
    mArgsQueue.emplace_back(std::make_unique<NotifySwitchArgs>(*args));
}

void QueuedInputListener::notifySensor(const NotifySensorArgs* args) {
    traceEvent(__func__, args->id);
    mArgsQueue.push_back(new NotifySensorArgs(*args));
    mArgsQueue.emplace_back(std::make_unique<NotifySensorArgs>(*args));
}

void QueuedInputListener::notifyVibratorState(const NotifyVibratorStateArgs* args) {
    traceEvent(__func__, args->id);
    mArgsQueue.push_back(new NotifyVibratorStateArgs(*args));
    mArgsQueue.emplace_back(std::make_unique<NotifyVibratorStateArgs>(*args));
}

void QueuedInputListener::notifyDeviceReset(const NotifyDeviceResetArgs* args) {
    traceEvent(__func__, args->id);
    mArgsQueue.push_back(new NotifyDeviceResetArgs(*args));
    mArgsQueue.emplace_back(std::make_unique<NotifyDeviceResetArgs>(*args));
}

void QueuedInputListener::notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs* args) {
    traceEvent(__func__, args->id);
    mArgsQueue.push_back(new NotifyPointerCaptureChangedArgs(*args));
    mArgsQueue.emplace_back(std::make_unique<NotifyPointerCaptureChangedArgs>(*args));
}

void QueuedInputListener::flush() {
    size_t count = mArgsQueue.size();
    for (size_t i = 0; i < count; i++) {
        NotifyArgs* args = mArgsQueue[i];
    for (const std::unique_ptr<NotifyArgs>& args : mArgsQueue) {
        args->notify(mInnerListener);
        delete args;
    }
    mArgsQueue.clear();
}
+1 −2
Original line number Diff line number Diff line
@@ -274,7 +274,6 @@ class QueuedInputListener : public InputListenerInterface {

public:
    explicit QueuedInputListener(InputListenerInterface& innerListener);
    virtual ~QueuedInputListener();

    virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) override;
    virtual void notifyKey(const NotifyKeyArgs* args) override;
@@ -289,7 +288,7 @@ public:

private:
    InputListenerInterface& mInnerListener;
    std::vector<NotifyArgs*> mArgsQueue;
    std::vector<std::unique_ptr<NotifyArgs>> mArgsQueue;
};

} // namespace android