summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Arthur Hung <arthurhung@google.com> 2019-01-09 19:17:20 +0800
committer Arthur Hung <arthurhung@google.com> 2019-01-14 10:12:03 +0800
commit7ab76b1c7d7d3f667cb58789295f62e7eb9e26c6 (patch)
tree37a99aa445770fc51ee61c302084f33f81bf7474
parente3dbb294940461cad6a04625501b93d3daf6fb0f (diff)
Fix top most focused window can't gain the focus
Pass at least two focused windows into InputDispatcher, the setInputWindow should find the top most focused window instead of the last one. Test: atest inputflinger_tests Bug: 120569355 Change-Id: Id7b08114ff4cfa76c44ccd1aa0090305c0a5aa51
-rw-r--r--services/inputflinger/InputDispatcher.cpp4
-rw-r--r--services/inputflinger/tests/InputDispatcher_test.cpp28
2 files changed, 30 insertions, 2 deletions
diff --git a/services/inputflinger/InputDispatcher.cpp b/services/inputflinger/InputDispatcher.cpp
index efea408954..9af189ae2b 100644
--- a/services/inputflinger/InputDispatcher.cpp
+++ b/services/inputflinger/InputDispatcher.cpp
@@ -3131,7 +3131,9 @@ void InputDispatcher::setInputWindows(const Vector<sp<InputWindowHandle>>& input
for (size_t i = 0; i < newHandles.size(); i++) {
const sp<InputWindowHandle>& windowHandle = newHandles.itemAt(i);
- if (windowHandle->getInfo()->hasFocus && windowHandle->getInfo()->visible) {
+ // Set newFocusedWindowHandle to the top most focused window instead of the last one
+ if (!newFocusedWindowHandle && windowHandle->getInfo()->hasFocus
+ && windowHandle->getInfo()->visible) {
newFocusedWindowHandle = windowHandle;
}
if (windowHandle == mLastHoverWindowHandle) {
diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp
index 7553a6861f..3edec40e4e 100644
--- a/services/inputflinger/tests/InputDispatcher_test.cpp
+++ b/services/inputflinger/tests/InputDispatcher_test.cpp
@@ -515,7 +515,7 @@ TEST_F(InputDispatcherTest, SetInputWindow_FocusedWindow) {
sp<FakeWindowHandle> windowSecond = new FakeWindowHandle(application, mDispatcher, "Second",
ADISPLAY_ID_DEFAULT);
- // Set focus application.
+ // Set focused application.
mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application);
// Expect one focus window exist in display.
@@ -533,6 +533,32 @@ TEST_F(InputDispatcherTest, SetInputWindow_FocusedWindow) {
windowSecond->consumeEvent(AINPUT_EVENT_TYPE_KEY, ADISPLAY_ID_NONE);
}
+TEST_F(InputDispatcherTest, SetInputWindow_FocusPriority) {
+ sp<FakeApplicationHandle> application = new FakeApplicationHandle();
+ sp<FakeWindowHandle> windowTop = new FakeWindowHandle(application, mDispatcher, "Top",
+ ADISPLAY_ID_DEFAULT);
+ sp<FakeWindowHandle> windowSecond = new FakeWindowHandle(application, mDispatcher, "Second",
+ ADISPLAY_ID_DEFAULT);
+
+ // Set focused application.
+ mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application);
+
+ // Display has two focused windows. Add them to inputWindowsHandles in z-order (top most first)
+ windowTop->setFocus();
+ windowSecond->setFocus();
+ Vector<sp<InputWindowHandle>> inputWindowHandles;
+ inputWindowHandles.add(windowTop);
+ inputWindowHandles.add(windowSecond);
+
+ mDispatcher->setInputWindows(inputWindowHandles, ADISPLAY_ID_DEFAULT);
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectKeyDown(mDispatcher))
+ << "Inject key event should return INPUT_EVENT_INJECTION_SUCCEEDED";
+
+ // Top focused window should receive event.
+ windowTop->consumeEvent(AINPUT_EVENT_TYPE_KEY, ADISPLAY_ID_NONE);
+ windowSecond->assertNoEvents();
+}
+
TEST_F(InputDispatcherTest, SetInputWindow_InputWindowInfo) {
sp<FakeApplicationHandle> application = new FakeApplicationHandle();