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

Commit 62683e85 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Rename functions in InputDispatcher

Some of the functions in InputDispatcher are labeled as '*Locked', when
in fact they do not need the caller to hold the lock.
Rename the functions to match the actual needs.

Also, one of the functions does nothing (just return false), but is
labeled as *LockedInterruptible. In this case, it is just done for the
consistency. Keep it and add a REQUIRES annotation.

Test: interact with booted device
Bug: 123097103
Change-Id: I946148f07def7cde35eec93290dc3d54844eef67
parent 443ad908
Loading
Loading
Loading
Loading
+22 −22
Original line number Original line Diff line number Diff line
@@ -698,7 +698,7 @@ void InputDispatcher::releaseInboundEventLocked(EventEntry* entry) {
#if DEBUG_DISPATCH_CYCLE
#if DEBUG_DISPATCH_CYCLE
        ALOGD("Injected inbound event was dropped.");
        ALOGD("Injected inbound event was dropped.");
#endif
#endif
        setInjectionResultLocked(entry, INPUT_EVENT_INJECTION_FAILED);
        setInjectionResult(entry, INPUT_EVENT_INJECTION_FAILED);
    }
    }
    if (entry == mNextUnblockedEvent) {
    if (entry == mNextUnblockedEvent) {
        mNextUnblockedEvent = nullptr;
        mNextUnblockedEvent = nullptr;
@@ -852,7 +852,7 @@ bool InputDispatcher::dispatchKeyLocked(nsecs_t currentTime, KeyEntry* entry,


    // Clean up if dropping the event.
    // Clean up if dropping the event.
    if (*dropReason != DROP_REASON_NOT_DROPPED) {
    if (*dropReason != DROP_REASON_NOT_DROPPED) {
        setInjectionResultLocked(entry, *dropReason == DROP_REASON_POLICY
        setInjectionResult(entry, *dropReason == DROP_REASON_POLICY
                ? INPUT_EVENT_INJECTION_SUCCEEDED : INPUT_EVENT_INJECTION_FAILED);
                ? INPUT_EVENT_INJECTION_SUCCEEDED : INPUT_EVENT_INJECTION_FAILED);
        mReporter->reportDroppedKey(entry->sequenceNum);
        mReporter->reportDroppedKey(entry->sequenceNum);
        return true;
        return true;
@@ -866,7 +866,7 @@ bool InputDispatcher::dispatchKeyLocked(nsecs_t currentTime, KeyEntry* entry,
        return false;
        return false;
    }
    }


    setInjectionResultLocked(entry, injectionResult);
    setInjectionResult(entry, injectionResult);
    if (injectionResult != INPUT_EVENT_INJECTION_SUCCEEDED) {
    if (injectionResult != INPUT_EVENT_INJECTION_SUCCEEDED) {
        return true;
        return true;
    }
    }
@@ -902,7 +902,7 @@ bool InputDispatcher::dispatchMotionLocked(


    // Clean up if dropping the event.
    // Clean up if dropping the event.
    if (*dropReason != DROP_REASON_NOT_DROPPED) {
    if (*dropReason != DROP_REASON_NOT_DROPPED) {
        setInjectionResultLocked(entry, *dropReason == DROP_REASON_POLICY
        setInjectionResult(entry, *dropReason == DROP_REASON_POLICY
                ? INPUT_EVENT_INJECTION_SUCCEEDED : INPUT_EVENT_INJECTION_FAILED);
                ? INPUT_EVENT_INJECTION_SUCCEEDED : INPUT_EVENT_INJECTION_FAILED);
        return true;
        return true;
    }
    }
@@ -927,7 +927,7 @@ bool InputDispatcher::dispatchMotionLocked(
        return false;
        return false;
    }
    }


    setInjectionResultLocked(entry, injectionResult);
    setInjectionResult(entry, injectionResult);
    if (injectionResult != INPUT_EVENT_INJECTION_SUCCEEDED) {
    if (injectionResult != INPUT_EVENT_INJECTION_SUCCEEDED) {
        if (injectionResult != INPUT_EVENT_INJECTION_PERMISSION_DENIED) {
        if (injectionResult != INPUT_EVENT_INJECTION_PERMISSION_DENIED) {
            CancelationOptions::Mode mode(isPointerEvent ?
            CancelationOptions::Mode mode(isPointerEvent ?
@@ -1973,17 +1973,17 @@ void InputDispatcher::enqueueDispatchEntriesLocked(nsecs_t currentTime,
    bool wasEmpty = connection->outboundQueue.isEmpty();
    bool wasEmpty = connection->outboundQueue.isEmpty();


    // Enqueue dispatch entries for the requested modes.
    // Enqueue dispatch entries for the requested modes.
    enqueueDispatchEntryLocked(connection, eventEntry, inputTarget,
    enqueueDispatchEntry(connection, eventEntry, inputTarget,
            InputTarget::FLAG_DISPATCH_AS_HOVER_EXIT);
            InputTarget::FLAG_DISPATCH_AS_HOVER_EXIT);
    enqueueDispatchEntryLocked(connection, eventEntry, inputTarget,
    enqueueDispatchEntry(connection, eventEntry, inputTarget,
            InputTarget::FLAG_DISPATCH_AS_OUTSIDE);
            InputTarget::FLAG_DISPATCH_AS_OUTSIDE);
    enqueueDispatchEntryLocked(connection, eventEntry, inputTarget,
    enqueueDispatchEntry(connection, eventEntry, inputTarget,
            InputTarget::FLAG_DISPATCH_AS_HOVER_ENTER);
            InputTarget::FLAG_DISPATCH_AS_HOVER_ENTER);
    enqueueDispatchEntryLocked(connection, eventEntry, inputTarget,
    enqueueDispatchEntry(connection, eventEntry, inputTarget,
            InputTarget::FLAG_DISPATCH_AS_IS);
            InputTarget::FLAG_DISPATCH_AS_IS);
    enqueueDispatchEntryLocked(connection, eventEntry, inputTarget,
    enqueueDispatchEntry(connection, eventEntry, inputTarget,
            InputTarget::FLAG_DISPATCH_AS_SLIPPERY_EXIT);
            InputTarget::FLAG_DISPATCH_AS_SLIPPERY_EXIT);
    enqueueDispatchEntryLocked(connection, eventEntry, inputTarget,
    enqueueDispatchEntry(connection, eventEntry, inputTarget,
            InputTarget::FLAG_DISPATCH_AS_SLIPPERY_ENTER);
            InputTarget::FLAG_DISPATCH_AS_SLIPPERY_ENTER);


    // If the outbound queue was previously empty, start the dispatch cycle going.
    // If the outbound queue was previously empty, start the dispatch cycle going.
@@ -1992,7 +1992,7 @@ void InputDispatcher::enqueueDispatchEntriesLocked(nsecs_t currentTime,
    }
    }
}
}


void InputDispatcher::enqueueDispatchEntryLocked(
void InputDispatcher::enqueueDispatchEntry(
        const sp<Connection>& connection, EventEntry* eventEntry, const InputTarget* inputTarget,
        const sp<Connection>& connection, EventEntry* eventEntry, const InputTarget* inputTarget,
        int32_t dispatchMode) {
        int32_t dispatchMode) {
    int32_t inputTargetFlags = inputTarget->flags;
    int32_t inputTargetFlags = inputTarget->flags;
@@ -2227,9 +2227,9 @@ void InputDispatcher::abortBrokenDispatchCycleLocked(nsecs_t currentTime,
#endif
#endif


    // Clear the dispatch queues.
    // Clear the dispatch queues.
    drainDispatchQueueLocked(&connection->outboundQueue);
    drainDispatchQueue(&connection->outboundQueue);
    traceOutboundQueueLength(connection);
    traceOutboundQueueLength(connection);
    drainDispatchQueueLocked(&connection->waitQueue);
    drainDispatchQueue(&connection->waitQueue);
    traceWaitQueueLength(connection);
    traceWaitQueueLength(connection);


    // The connection appears to be unrecoverably broken.
    // The connection appears to be unrecoverably broken.
@@ -2244,16 +2244,16 @@ void InputDispatcher::abortBrokenDispatchCycleLocked(nsecs_t currentTime,
    }
    }
}
}


void InputDispatcher::drainDispatchQueueLocked(Queue<DispatchEntry>* queue) {
void InputDispatcher::drainDispatchQueue(Queue<DispatchEntry>* queue) {
    while (!queue->isEmpty()) {
    while (!queue->isEmpty()) {
        DispatchEntry* dispatchEntry = queue->dequeueAtHead();
        DispatchEntry* dispatchEntry = queue->dequeueAtHead();
        releaseDispatchEntryLocked(dispatchEntry);
        releaseDispatchEntry(dispatchEntry);
    }
    }
}
}


void InputDispatcher::releaseDispatchEntryLocked(DispatchEntry* dispatchEntry) {
void InputDispatcher::releaseDispatchEntry(DispatchEntry* dispatchEntry) {
    if (dispatchEntry->hasForegroundTarget()) {
    if (dispatchEntry->hasForegroundTarget()) {
        decrementPendingForegroundDispatchesLocked(dispatchEntry->eventEntry);
        decrementPendingForegroundDispatches(dispatchEntry->eventEntry);
    }
    }
    delete dispatchEntry;
    delete dispatchEntry;
}
}
@@ -2400,7 +2400,7 @@ void InputDispatcher::synthesizeCancelationEventsForConnectionLocked(
            target.inputChannel = connection->inputChannel;
            target.inputChannel = connection->inputChannel;
            target.flags = InputTarget::FLAG_DISPATCH_AS_IS;
            target.flags = InputTarget::FLAG_DISPATCH_AS_IS;


            enqueueDispatchEntryLocked(connection, cancelationEventEntry, // increments ref
            enqueueDispatchEntry(connection, cancelationEventEntry, // increments ref
                    &target, InputTarget::FLAG_DISPATCH_AS_IS);
                    &target, InputTarget::FLAG_DISPATCH_AS_IS);


            cancelationEventEntry->release();
            cancelationEventEntry->release();
@@ -2960,7 +2960,7 @@ bool InputDispatcher::hasInjectionPermission(int32_t injectorPid, int32_t inject
            || mPolicy->checkInjectEventsPermissionNonReentrant(injectorPid, injectorUid);
            || mPolicy->checkInjectEventsPermissionNonReentrant(injectorPid, injectorUid);
}
}


void InputDispatcher::setInjectionResultLocked(EventEntry* entry, int32_t injectionResult) {
void InputDispatcher::setInjectionResult(EventEntry* entry, int32_t injectionResult) {
    InjectionState* injectionState = entry->injectionState;
    InjectionState* injectionState = entry->injectionState;
    if (injectionState) {
    if (injectionState) {
#if DEBUG_INJECTION
#if DEBUG_INJECTION
@@ -3000,7 +3000,7 @@ void InputDispatcher::incrementPendingForegroundDispatches(EventEntry* entry) {
    }
    }
}
}


void InputDispatcher::decrementPendingForegroundDispatchesLocked(EventEntry* entry) {
void InputDispatcher::decrementPendingForegroundDispatches(EventEntry* entry) {
    InjectionState* injectionState = entry->injectionState;
    InjectionState* injectionState = entry->injectionState;
    if (injectionState) {
    if (injectionState) {
        injectionState->pendingForegroundDispatches -= 1;
        injectionState->pendingForegroundDispatches -= 1;
@@ -4034,7 +4034,7 @@ void InputDispatcher::doDispatchCycleFinishedLockedInterruptible(
                connection->outboundQueue.enqueueAtHead(dispatchEntry);
                connection->outboundQueue.enqueueAtHead(dispatchEntry);
                traceOutboundQueueLength(connection);
                traceOutboundQueueLength(connection);
            } else {
            } else {
                releaseDispatchEntryLocked(dispatchEntry);
                releaseDispatchEntry(dispatchEntry);
            }
            }
        }
        }


+6 −6
Original line number Original line Diff line number Diff line
@@ -947,11 +947,11 @@ private:
    // Event injection and synchronization.
    // Event injection and synchronization.
    std::condition_variable mInjectionResultAvailable;
    std::condition_variable mInjectionResultAvailable;
    bool hasInjectionPermission(int32_t injectorPid, int32_t injectorUid);
    bool hasInjectionPermission(int32_t injectorPid, int32_t injectorUid);
    void setInjectionResultLocked(EventEntry* entry, int32_t injectionResult);
    void setInjectionResult(EventEntry* entry, int32_t injectionResult);


    std::condition_variable mInjectionSyncFinished;
    std::condition_variable mInjectionSyncFinished;
    void incrementPendingForegroundDispatches(EventEntry* entry);
    void incrementPendingForegroundDispatches(EventEntry* entry);
    void decrementPendingForegroundDispatchesLocked(EventEntry* entry);
    void decrementPendingForegroundDispatches(EventEntry* entry);


    // Key repeat tracking.
    // Key repeat tracking.
    struct KeyRepeatState {
    struct KeyRepeatState {
@@ -1137,7 +1137,7 @@ private:
            EventEntry* eventEntry, const InputTarget* inputTarget) REQUIRES(mLock);
            EventEntry* eventEntry, const InputTarget* inputTarget) REQUIRES(mLock);
    void enqueueDispatchEntriesLocked(nsecs_t currentTime, const sp<Connection>& connection,
    void enqueueDispatchEntriesLocked(nsecs_t currentTime, const sp<Connection>& connection,
            EventEntry* eventEntry, const InputTarget* inputTarget) REQUIRES(mLock);
            EventEntry* eventEntry, const InputTarget* inputTarget) REQUIRES(mLock);
    void enqueueDispatchEntryLocked(const sp<Connection>& connection,
    void enqueueDispatchEntry(const sp<Connection>& connection,
            EventEntry* eventEntry, const InputTarget* inputTarget, int32_t dispatchMode);
            EventEntry* eventEntry, const InputTarget* inputTarget, int32_t dispatchMode);
    void startDispatchCycleLocked(nsecs_t currentTime, const sp<Connection>& connection)
    void startDispatchCycleLocked(nsecs_t currentTime, const sp<Connection>& connection)
            REQUIRES(mLock);
            REQUIRES(mLock);
@@ -1145,8 +1145,8 @@ private:
            uint32_t seq, bool handled) REQUIRES(mLock);
            uint32_t seq, bool handled) REQUIRES(mLock);
    void abortBrokenDispatchCycleLocked(nsecs_t currentTime, const sp<Connection>& connection,
    void abortBrokenDispatchCycleLocked(nsecs_t currentTime, const sp<Connection>& connection,
            bool notify) REQUIRES(mLock);
            bool notify) REQUIRES(mLock);
    void drainDispatchQueueLocked(Queue<DispatchEntry>* queue);
    void drainDispatchQueue(Queue<DispatchEntry>* queue);
    void releaseDispatchEntryLocked(DispatchEntry* dispatchEntry);
    void releaseDispatchEntry(DispatchEntry* dispatchEntry);
    static int handleReceiveCallback(int fd, int events, void* data);
    static int handleReceiveCallback(int fd, int events, void* data);


    void synthesizeCancelationEventsForAllConnectionsLocked(
    void synthesizeCancelationEventsForAllConnectionsLocked(
@@ -1198,7 +1198,7 @@ private:
    bool afterKeyEventLockedInterruptible(const sp<Connection>& connection,
    bool afterKeyEventLockedInterruptible(const sp<Connection>& connection,
            DispatchEntry* dispatchEntry, KeyEntry* keyEntry, bool handled) REQUIRES(mLock);
            DispatchEntry* dispatchEntry, KeyEntry* keyEntry, bool handled) REQUIRES(mLock);
    bool afterMotionEventLockedInterruptible(const sp<Connection>& connection,
    bool afterMotionEventLockedInterruptible(const sp<Connection>& connection,
            DispatchEntry* dispatchEntry, MotionEntry* motionEntry, bool handled);
            DispatchEntry* dispatchEntry, MotionEntry* motionEntry, bool handled) REQUIRES(mLock);
    void doPokeUserActivityLockedInterruptible(CommandEntry* commandEntry) REQUIRES(mLock);
    void doPokeUserActivityLockedInterruptible(CommandEntry* commandEntry) REQUIRES(mLock);
    void initializeKeyEvent(KeyEvent* event, const KeyEntry* entry);
    void initializeKeyEvent(KeyEvent* event, const KeyEntry* entry);