From 80d685aef18683ed175e0a3fddbd8f55a83c788d Mon Sep 17 00:00:00 2001 From: arthurhung Date: Fri, 19 Jun 2020 23:35:28 +0800 Subject: Clear spam log for INPUT_FEATURE_NO_INPUT_CHANNEL window Currently, in order to detect occlusion input, all buffered layers would update input info into InputFlinger, so the window may contain null token, we should check if id is also identical to prevent get the wrong result. Bug: 159349058 Test: Enable show tap, open bubble and watch logs. Change-Id: Ia1841ba51bce00fc9901fdf7324e8e31d9737082 --- .../inputflinger/dispatcher/InputDispatcher.cpp | 33 +++++++++++++--------- services/inputflinger/dispatcher/InputDispatcher.h | 3 +- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp index f011992daa..cb68355e91 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.cpp +++ b/services/inputflinger/dispatcher/InputDispatcher.cpp @@ -3569,6 +3569,10 @@ std::vector> InputDispatcher::getWindowHandlesLocked( sp InputDispatcher::getWindowHandleLocked( const sp& windowHandleToken) const { + if (windowHandleToken == nullptr) { + return nullptr; + } + for (auto& it : mWindowHandlesByDisplay) { const std::vector> windowHandles = it.second; for (const sp& windowHandle : windowHandles) { @@ -3580,21 +3584,22 @@ sp InputDispatcher::getWindowHandleLocked( return nullptr; } -bool InputDispatcher::hasWindowHandleLocked(const sp& windowHandle) const { - for (auto& it : mWindowHandlesByDisplay) { - const std::vector> windowHandles = it.second; - for (const sp& handle : windowHandles) { - if (handle->getToken() == windowHandle->getToken()) { - if (windowHandle->getInfo()->displayId != it.first) { - ALOGE("Found window %s in display %" PRId32 - ", but it should belong to display %" PRId32, - windowHandle->getName().c_str(), it.first, - windowHandle->getInfo()->displayId); - } - return true; +bool InputDispatcher::hasWindowHandleLocked(const sp& windowHandle, + int32_t displayId) const { + const std::vector> windowHandles = getWindowHandlesLocked(displayId); + for (const sp& handle : windowHandles) { + if (handle->getId() == windowHandle->getId() && + handle->getToken() == windowHandle->getToken()) { + if (handle->getInfo()->displayId != displayId) { + ALOGE("Found window %s in display %" PRId32 + ", but it should belong to display %" PRId32, + windowHandle->getName().c_str(), displayId, + windowHandle->getInfo()->displayId); } + return true; } } + return false; } @@ -3754,7 +3759,7 @@ void InputDispatcher::setInputWindowsLocked( TouchState& state = stateIt->second; for (size_t i = 0; i < state.windows.size();) { TouchedWindow& touchedWindow = state.windows[i]; - if (!hasWindowHandleLocked(touchedWindow.windowHandle)) { + if (!hasWindowHandleLocked(touchedWindow.windowHandle, displayId)) { if (DEBUG_FOCUS) { ALOGD("Touched window was removed: %s in display %" PRId32, touchedWindow.windowHandle->getName().c_str(), displayId); @@ -3778,7 +3783,7 @@ void InputDispatcher::setInputWindowsLocked( // Otherwise, they might stick around until the window handle is destroyed // which might not happen until the next GC. for (const sp& oldWindowHandle : oldWindowHandles) { - if (!hasWindowHandleLocked(oldWindowHandle)) { + if (!hasWindowHandleLocked(oldWindowHandle, displayId)) { if (DEBUG_FOCUS) { ALOGD("Window went away: %s", oldWindowHandle->getName().c_str()); } diff --git a/services/inputflinger/dispatcher/InputDispatcher.h b/services/inputflinger/dispatcher/InputDispatcher.h index e679c6b06f..0f558b4e73 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.h +++ b/services/inputflinger/dispatcher/InputDispatcher.h @@ -301,7 +301,8 @@ private: sp getWindowHandleLocked(const sp& windowHandleToken) const REQUIRES(mLock); sp getInputChannelLocked(const sp& windowToken) const REQUIRES(mLock); - bool hasWindowHandleLocked(const sp& windowHandle) const REQUIRES(mLock); + bool hasWindowHandleLocked(const sp& windowHandle, int32_t displayId) const + REQUIRES(mLock); /* * Validate and update InputWindowHandles for a given display. -- cgit v1.2.3-59-g8ed1b