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

Commit cef936d0 authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

InputDispatcher: Refactor CommandQueue to use lambdas

InputDispatcher uses a CommandQueue to post messages that should be run
later on the dispatcher thread, similar to a Handler.

Instead of using function pointers and `CommandEntry`s to enqueue messages
to the queue, we use use lambdas that also have a copy of the parameters.

Doing this reduces some redundancies and verbosity, as well as
increasing readability.

Bug: None
Test: atest inputflinger_tests
Change-Id: I330cbaed2532228e7e58b42b6ce4a079328cdd97
parent 15432b03
Loading
Loading
Loading
Loading
+0 −13
Original line number Diff line number Diff line
@@ -319,17 +319,4 @@ uint32_t DispatchEntry::nextSeq() {
    return seq;
}

// --- CommandEntry ---

CommandEntry::CommandEntry(Command command)
      : command(command),
        eventTime(0),
        keyEntry(nullptr),
        userActivityEventType(0),
        seq(0),
        handled(false),
        enabled(false) {}

CommandEntry::~CommandEntry() {}

} // namespace android::inputdispatcher
+0 −49
Original line number Diff line number Diff line
@@ -245,55 +245,6 @@ private:
VerifiedKeyEvent verifiedKeyEventFromKeyEntry(const KeyEntry& entry);
VerifiedMotionEvent verifiedMotionEventFromMotionEntry(const MotionEntry& entry);

class InputDispatcher;
// A command entry captures state and behavior for an action to be performed in the
// dispatch loop after the initial processing has taken place.  It is essentially
// a kind of continuation used to postpone sensitive policy interactions to a point
// in the dispatch loop where it is safe to release the lock (generally after finishing
// the critical parts of the dispatch cycle).
//
// The special thing about commands is that they can voluntarily release and reacquire
// the dispatcher lock at will.  Initially when the command starts running, the
// dispatcher lock is held.  However, if the command needs to call into the policy to
// do some work, it can release the lock, do the work, then reacquire the lock again
// before returning.
//
// This mechanism is a bit clunky but it helps to preserve the invariant that the dispatch
// never calls into the policy while holding its lock.
//
// Commands are implicitly 'LockedInterruptible'.
struct CommandEntry;
typedef std::function<void(InputDispatcher&, CommandEntry*)> Command;

class Connection;
struct CommandEntry {
    explicit CommandEntry(Command command);
    ~CommandEntry();

    Command command;

    // parameters for the command (usage varies by command)
    sp<Connection> connection;
    nsecs_t eventTime;
    std::shared_ptr<KeyEntry> keyEntry;
    std::shared_ptr<SensorEntry> sensorEntry;
    std::shared_ptr<InputApplicationHandle> inputApplicationHandle;
    std::string reason;
    int32_t userActivityEventType;
    uint32_t seq;
    bool handled;
    sp<IBinder> connectionToken;
    sp<IBinder> oldToken;
    sp<IBinder> newToken;
    std::string obscuringPackage;
    bool enabled;
    int32_t pid;
    nsecs_t consumeTime; // time when the event was consumed by InputConsumer
    int32_t displayId;
    float x;
    float y;
};

} // namespace android::inputdispatcher

#endif // _UI_INPUT_INPUTDISPATCHER_ENTRY_H