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

Commit bd76e88a authored by Siarhei Vishniakou's avatar Siarhei Vishniakou Committed by Automerger Merge Worker
Browse files

Ensure objects remain valid after calling policy am: f68fc4c5

parents 7b35feba f68fc4c5
Loading
Loading
Loading
Loading
+13 −6
Original line number Diff line number Diff line
@@ -6100,9 +6100,7 @@ void InputDispatcher::doDispatchCycleFinishedCommand(nsecs_t finishTime,

    bool restartEvent;
    if (dispatchEntry->eventEntry->type == EventEntry::Type::KEY) {
        KeyEntry& keyEntry = static_cast<KeyEntry&>(*(dispatchEntry->eventEntry));
        restartEvent =
                afterKeyEventLockedInterruptable(connection, dispatchEntry, keyEntry, handled);
        restartEvent = afterKeyEventLockedInterruptable(connection, dispatchEntry, handled);
    } else if (dispatchEntry->eventEntry->type == EventEntry::Type::MOTION) {
        MotionEntry& motionEntry = static_cast<MotionEntry&>(*(dispatchEntry->eventEntry));
        restartEvent = afterMotionEventLockedInterruptable(connection, dispatchEntry, motionEntry,
@@ -6320,8 +6318,17 @@ void InputDispatcher::processConnectionResponsiveLocked(const Connection& connec
}

bool InputDispatcher::afterKeyEventLockedInterruptable(
        const std::shared_ptr<Connection>& connection, DispatchEntry* dispatchEntry,
        KeyEntry& keyEntry, bool handled) {
        const std::shared_ptr<Connection>& connection, DispatchEntry* dispatchEntry, bool handled) {
    // The dispatchEntry is currently valid, but it might point to a deleted object after we release
    // the lock. For simplicity, make copies of the data of interest here and assume that
    // 'dispatchEntry' is not valid after this section.
    // Hold a strong reference to the EventEntry to ensure it's valid for the duration of this
    // function, even if the DispatchEntry gets destroyed and releases its share of the ownership.
    std::shared_ptr<EventEntry> eventEntry = dispatchEntry->eventEntry;
    const bool hasForegroundTarget = dispatchEntry->hasForegroundTarget();
    KeyEntry& keyEntry = static_cast<KeyEntry&>(*(eventEntry));
    // To prevent misuse, ensure dispatchEntry is no longer valid.
    dispatchEntry = nullptr;
    if (keyEntry.flags & AKEY_EVENT_FLAG_FALLBACK) {
        if (!handled) {
            // Report the key as unhandled, since the fallback was not handled.
@@ -6338,7 +6345,7 @@ bool InputDispatcher::afterKeyEventLockedInterruptable(
        connection->inputState.removeFallbackKey(originalKeyCode);
    }

    if (handled || !dispatchEntry->hasForegroundTarget()) {
    if (handled || !hasForegroundTarget) {
        // If the application handles the original key for which we previously
        // generated a fallback or if the window is not a foreground window,
        // then cancel the associated fallback key, if any.
+2 −2
Original line number Diff line number Diff line
@@ -684,8 +684,8 @@ private:
    void updateLastAnrStateLocked(const std::string& windowLabel, const std::string& reason)
            REQUIRES(mLock);
    bool afterKeyEventLockedInterruptable(const std::shared_ptr<Connection>& connection,
                                          DispatchEntry* dispatchEntry, KeyEntry& keyEntry,
                                          bool handled) REQUIRES(mLock);
                                          DispatchEntry* dispatchEntry, bool handled)
            REQUIRES(mLock);
    bool afterMotionEventLockedInterruptable(const std::shared_ptr<Connection>& connection,
                                             DispatchEntry* dispatchEntry, MotionEntry& motionEntry,
                                             bool handled) REQUIRES(mLock);