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

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

Use sequence numbers to synchronize enabling Pointer Capture (1/2)

InputReader only processes configuration change from its main thread.
This means that if there is more than one Pointer Capture change
request when the thread is busy or sleeping, it will only process the
latest one. To ensure requests to enable Pointer Capture are synchronized
with Dispatcher, we must use sequence numbers.

Requests to enable Pointer Capture have a sequence number. Requests to
disable Pointer Capture do not have a value.

Bug: 195312888
Test: atest inputflinger_tests
Test: manual with GeforceNow app, see bug.
Merged-In: I6ae9c5498dc2f783b4c7211fa3665d42e29d2919
Change-Id: I6ae9c5498dc2f783b4c7211fa3665d42e29d2919
parent 4095348d
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -1015,6 +1015,25 @@ private:
    std::queue<std::unique_ptr<DragEvent>> mDragEventPool;
};

/*
 * Describes a unique request to enable or disable Pointer Capture.
 */
struct PointerCaptureRequest {
public:
    inline PointerCaptureRequest() : enable(false), seq(0) {}
    inline PointerCaptureRequest(bool enable, uint32_t seq) : enable(enable), seq(seq) {}
    inline bool operator==(const PointerCaptureRequest& other) const {
        return enable == other.enable && seq == other.seq;
    }
    explicit inline operator bool() const { return enable; }

    // True iff this is a request to enable Pointer Capture.
    bool enable;

    // The sequence number for the request.
    uint32_t seq;
};

} // namespace android

#endif // _LIBINPUT_INPUT_H
+5 −5
Original line number Diff line number Diff line
@@ -287,16 +287,16 @@ void NotifyDeviceResetArgs::notify(const sp<InputListenerInterface>& listener) c

// --- NotifyPointerCaptureChangedArgs ---

NotifyPointerCaptureChangedArgs::NotifyPointerCaptureChangedArgs(int32_t id, nsecs_t eventTime,
                                                                 bool enabled)
      : NotifyArgs(id, eventTime), enabled(enabled) {}
NotifyPointerCaptureChangedArgs::NotifyPointerCaptureChangedArgs(
        int32_t id, nsecs_t eventTime, const PointerCaptureRequest& request)
      : NotifyArgs(id, eventTime), request(request) {}

NotifyPointerCaptureChangedArgs::NotifyPointerCaptureChangedArgs(
        const NotifyPointerCaptureChangedArgs& other)
      : NotifyArgs(other.id, other.eventTime), enabled(other.enabled) {}
      : NotifyArgs(other.id, other.eventTime), request(other.request) {}

bool NotifyPointerCaptureChangedArgs::operator==(const NotifyPointerCaptureChangedArgs& rhs) const {
    return id == rhs.id && eventTime == rhs.eventTime && enabled == rhs.enabled;
    return id == rhs.id && eventTime == rhs.eventTime && request == rhs.request;
}

void NotifyPointerCaptureChangedArgs::notify(const sp<InputListenerInterface>& listener) const {
+3 −0
Original line number Diff line number Diff line
@@ -67,6 +67,9 @@ std::string InputReaderConfiguration::changesToString(uint32_t changes) {
    if (changes & CHANGE_EXTERNAL_STYLUS_PRESENCE) {
        result += "EXTERNAL_STYLUS_PRESENCE | ";
    }
    if (changes & CHANGE_POINTER_CAPTURE) {
        result += "POINTER_CAPTURE | ";
    }
    if (changes & CHANGE_ENABLED_STATE) {
        result += "ENABLED_STATE | ";
    }
+1 −1
Original line number Diff line number Diff line
@@ -113,7 +113,7 @@ private:

    void onPointerDownOutsideFocus(const sp<IBinder>& newToken) override {}

    void setPointerCapture(bool enabled) override {}
    void setPointerCapture(const PointerCaptureRequest&) override {}

    void notifyDropWindow(const sp<IBinder>&, float x, float y) override {}

+4 −5
Original line number Diff line number Diff line
@@ -119,15 +119,15 @@ std::string FocusEntry::getDescription() const {
// PointerCaptureChanged notifications always go to apps, so set the flag POLICY_FLAG_PASS_TO_USER
// for all entries.
PointerCaptureChangedEntry::PointerCaptureChangedEntry(int32_t id, nsecs_t eventTime,
                                                       bool hasPointerCapture)
                                                       const PointerCaptureRequest& request)
      : EventEntry(id, Type::POINTER_CAPTURE_CHANGED, eventTime, POLICY_FLAG_PASS_TO_USER),
        pointerCaptureEnabled(hasPointerCapture) {}
        pointerCaptureRequest(request) {}

PointerCaptureChangedEntry::~PointerCaptureChangedEntry() {}

std::string PointerCaptureChangedEntry::getDescription() const {
    return StringPrintf("PointerCaptureChangedEvent(pointerCaptureEnabled=%s)",
                        pointerCaptureEnabled ? "true" : "false");
                        pointerCaptureRequest.enable ? "true" : "false");
}

// --- DragEntry ---
@@ -324,8 +324,7 @@ CommandEntry::CommandEntry(Command command)
        keyEntry(nullptr),
        userActivityEventType(0),
        seq(0),
        handled(false),
        enabled(false) {}
        handled(false) {}

CommandEntry::~CommandEntry() {}

Loading