From 540dbaee09cd6790951576b8f3de1f85befb4524 Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Tue, 5 May 2020 18:17:17 -0700 Subject: Generate a new id for each window When input receives a list of windows from surfaceflinger, each window has a unique id. But when we run tests, all ids are the same. This causes some unexpected test failures for the cases where we have more than 1 window per display. To avoid this issue, mirror the surfaceflinger approach of generating the ids by keeping a static variable that gets incremented every time we create a new window Bug: 143459140 Test: atest inputflinger_tests Change-Id: I36731e78e16892b4bf48d6eba8db3e4c2684b54d --- services/inputflinger/tests/InputDispatcher_test.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp index e0d32a0382..365d43dd16 100644 --- a/services/inputflinger/tests/InputDispatcher_test.cpp +++ b/services/inputflinger/tests/InputDispatcher_test.cpp @@ -634,7 +634,7 @@ public: mInfo.applicationInfo = *inputApplicationHandle->getInfo(); mInfo.token = token; - mInfo.id = 0; + mInfo.id = sId++; mInfo.name = name; mInfo.layoutParamsFlags = 0; mInfo.layoutParamsType = InputWindowInfo::TYPE_APPLICATION; @@ -672,8 +672,6 @@ public: void setLayoutParamFlags(int32_t flags) { mInfo.layoutParamsFlags = flags; } - void setId(int32_t id) { mInfo.id = id; } - void setWindowScale(float xScale, float yScale) { mInfo.windowXScale = xScale; mInfo.windowYScale = yScale; @@ -755,8 +753,11 @@ public: private: const std::string mName; std::unique_ptr mInputReceiver; + static std::atomic sId; // each window gets a unique id, like in surfaceflinger }; +std::atomic FakeWindowHandle::sId{1}; + static int32_t injectKeyDown(const sp& dispatcher, int32_t displayId = ADISPLAY_ID_NONE) { KeyEvent event; @@ -1910,14 +1911,12 @@ class InputDispatcherMultiWindowSameTokenTests : public InputDispatcherTest { // We also need FLAG_SPLIT_TOUCH or we won't be able to get touches for both windows. mWindow1->setLayoutParamFlags(InputWindowInfo::FLAG_NOT_TOUCH_MODAL | InputWindowInfo::FLAG_SPLIT_TOUCH); - mWindow1->setId(0); mWindow1->setFrame(Rect(0, 0, 100, 100)); mWindow2 = new FakeWindowHandle(application, mDispatcher, "Fake Window 2", ADISPLAY_ID_DEFAULT, mWindow1->getToken()); mWindow2->setLayoutParamFlags(InputWindowInfo::FLAG_NOT_TOUCH_MODAL | InputWindowInfo::FLAG_SPLIT_TOUCH); - mWindow2->setId(1); mWindow2->setFrame(Rect(100, 100, 200, 200)); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mWindow1, mWindow2}}}); -- cgit v1.2.3-59-g8ed1b