diff --git a/include/ui/InputDispatcher.h b/include/ui/InputDispatcher.h index 738f62a28..a5591ba92 100644 --- a/include/ui/InputDispatcher.h +++ b/include/ui/InputDispatcher.h @@ -1046,6 +1046,9 @@ private: // Splitting motion events across windows. MotionEntry* splitMotionEvent(const MotionEntry* originalMotionEntry, BitSet32 pointerIds); + // Reset and drop everything the dispatcher is doing. + void resetAndDropEverythingLocked(const char* reason); + // Dump state. void dumpDispatchStateLocked(String8& dump); void logDispatchStateLocked(); diff --git a/libs/ui/InputDispatcher.cpp b/libs/ui/InputDispatcher.cpp index 4c86ebe0f..b936c4d47 100644 --- a/libs/ui/InputDispatcher.cpp +++ b/libs/ui/InputDispatcher.cpp @@ -1305,6 +1305,9 @@ Failed: } Unresponsive: + // Reset temporary touch state to ensure we release unnecessary references to input channels. + mTempTouchState.reset(); + nsecs_t timeSpentWaitingForApplication = getTimeSpentWaitingForApplicationLocked(currentTime); updateDispatchStatisticsLocked(currentTime, entry, injectionResult, timeSpentWaitingForApplication); @@ -2589,10 +2592,14 @@ void InputDispatcher::setInputDispatchMode(bool enabled, bool frozen) { AutoMutex _l(mLock); if (mDispatchEnabled != enabled || mDispatchFrozen != frozen) { - if (mDispatchFrozen && ! frozen) { + if (mDispatchFrozen && !frozen) { resetANRTimeoutsLocked(); } + if (mDispatchEnabled && !enabled) { + resetAndDropEverythingLocked("dispatcher is being disabled"); + } + mDispatchEnabled = enabled; mDispatchFrozen = frozen; changed = true; @@ -2687,6 +2694,21 @@ bool InputDispatcher::transferTouchFocus(const sp& fromChannel, return true; } +void InputDispatcher::resetAndDropEverythingLocked(const char* reason) { +#if DEBUG_FOCUS + LOGD("Resetting and dropping all events (%s).", reason); +#endif + + synthesizeCancelationEventsForAllConnectionsLocked(InputState::CANCEL_ALL_EVENTS, reason); + + resetKeyRepeatLocked(); + releasePendingEventLocked(); + drainInboundQueueLocked(); + resetTargetsLocked(); + + mTouchState.reset(); +} + void InputDispatcher::logDispatchStateLocked() { String8 dump; dumpDispatchStateLocked(dump);