Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 17 | #include "../dispatcher/InputDispatcher.h" |
Siarhei Vishniakou | 2defec0 | 2023-06-08 17:24:44 -0700 | [diff] [blame] | 18 | #include "FakeApplicationHandle.h" |
Prabir Pradhan | 81e89fe | 2024-03-20 21:17:09 +0000 | [diff] [blame] | 19 | #include "FakeInputDispatcherPolicy.h" |
Prabir Pradhan | dc3a2ad | 2024-02-05 19:03:51 +0000 | [diff] [blame] | 20 | #include "FakeInputTracingBackend.h" |
Prabir Pradhan | c534073 | 2024-03-20 22:53:52 +0000 | [diff] [blame] | 21 | #include "FakeWindows.h" |
Prabir Pradhan | e3b28dd | 2023-10-06 04:19:29 +0000 | [diff] [blame] | 22 | #include "TestEventMatchers.h" |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 23 | |
Cody Heiner | 166a5af | 2023-07-07 12:25:00 -0700 | [diff] [blame] | 24 | #include <NotifyArgsBuilders.h> |
Prabir Pradhan | 5893d36 | 2023-11-17 04:30:40 +0000 | [diff] [blame] | 25 | #include <android-base/logging.h> |
Siarhei Vishniakou | 1c494c5 | 2021-08-11 20:25:01 -0700 | [diff] [blame] | 26 | #include <android-base/properties.h> |
Prabir Pradhan | a3ab87a | 2022-01-27 10:00:21 -0800 | [diff] [blame] | 27 | #include <android-base/silent_death_test.h> |
Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 28 | #include <android-base/stringprintf.h> |
Siarhei Vishniakou | 4cb50ca | 2020-05-26 21:43:02 -0700 | [diff] [blame] | 29 | #include <android-base/thread_annotations.h> |
Robert Carr | 803535b | 2018-08-02 16:38:15 -0700 | [diff] [blame] | 30 | #include <binder/Binder.h> |
Ameer Armaly | cff4fa5 | 2023-10-04 23:45:11 +0000 | [diff] [blame] | 31 | #include <com_android_input_flags.h> |
Michael Wright | 8e9a856 | 2022-02-09 13:44:29 +0000 | [diff] [blame] | 32 | #include <fcntl.h> |
Ameer Armaly | cff4fa5 | 2023-10-04 23:45:11 +0000 | [diff] [blame] | 33 | #include <flag_macros.h> |
Siarhei Vishniakou | 0b0374d | 2022-11-17 17:40:53 -0800 | [diff] [blame] | 34 | #include <gmock/gmock.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 35 | #include <gtest/gtest.h> |
Siarhei Vishniakou | 3782af6 | 2024-03-07 21:56:39 -0800 | [diff] [blame] | 36 | #include <input/BlockingQueue.h> |
Siarhei Vishniakou | 870ecec | 2020-12-09 08:07:46 -1000 | [diff] [blame] | 37 | #include <input/Input.h> |
Siarhei Vishniakou | 0438ca8 | 2024-03-12 14:27:25 -0700 | [diff] [blame] | 38 | #include <input/InputConsumer.h> |
Siarhei Vishniakou | f404321 | 2023-09-18 19:33:03 -0700 | [diff] [blame] | 39 | #include <input/PrintTools.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 40 | #include <linux/input.h> |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 41 | #include <sys/epoll.h> |
Siarhei Vishniakou | 870ecec | 2020-12-09 08:07:46 -1000 | [diff] [blame] | 42 | |
Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 43 | #include <cinttypes> |
Siarhei Vishniakou | 487c49b | 2022-12-02 15:48:57 -0800 | [diff] [blame] | 44 | #include <compare> |
Siarhei Vishniakou | 4cb50ca | 2020-05-26 21:43:02 -0700 | [diff] [blame] | 45 | #include <thread> |
Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 46 | #include <unordered_set> |
chaviw | d1c2318 | 2019-12-20 18:44:56 -0800 | [diff] [blame] | 47 | #include <vector> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 48 | |
Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 49 | using android::base::StringPrintf; |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 50 | using android::gui::FocusRequest; |
| 51 | using android::gui::TouchOcclusionMode; |
| 52 | using android::gui::WindowInfo; |
| 53 | using android::gui::WindowInfoHandle; |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 54 | using android::os::InputEventInjectionResult; |
| 55 | using android::os::InputEventInjectionSync; |
Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 56 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 57 | namespace android::inputdispatcher { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 58 | |
Dominik Laskowski | 2f01d77 | 2022-03-23 16:01:29 -0700 | [diff] [blame] | 59 | using namespace ftl::flag_operators; |
Siarhei Vishniakou | 0b0374d | 2022-11-17 17:40:53 -0800 | [diff] [blame] | 60 | using testing::AllOf; |
Prabir Pradhan | 5893d36 | 2023-11-17 04:30:40 +0000 | [diff] [blame] | 61 | using testing::Not; |
Siarhei Vishniakou | 85eb580 | 2024-04-01 11:40:59 -0700 | [diff] [blame] | 62 | using testing::Pointee; |
| 63 | using testing::UnorderedElementsAre; |
Dominik Laskowski | 2f01d77 | 2022-03-23 16:01:29 -0700 | [diff] [blame] | 64 | |
Siarhei Vishniakou | f404321 | 2023-09-18 19:33:03 -0700 | [diff] [blame] | 65 | namespace { |
| 66 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 67 | // An arbitrary time value. |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 68 | static constexpr nsecs_t ARBITRARY_TIME = 1234; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 69 | |
| 70 | // An arbitrary device id. |
Prabir Pradhan | 9205e42 | 2023-05-16 20:06:13 +0000 | [diff] [blame] | 71 | static constexpr int32_t DEVICE_ID = DEFAULT_DEVICE_ID; |
Siarhei Vishniakou | 060f82b | 2023-01-27 06:39:14 -0800 | [diff] [blame] | 72 | static constexpr int32_t SECOND_DEVICE_ID = 2; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 73 | |
Jeff Brown | f086ddb | 2014-02-11 14:28:48 -0800 | [diff] [blame] | 74 | // An arbitrary display id. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 75 | constexpr ui::LogicalDisplayId DISPLAY_ID = ui::LogicalDisplayId::DEFAULT; |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 76 | constexpr ui::LogicalDisplayId SECOND_DISPLAY_ID = ui::LogicalDisplayId{1}; |
Jeff Brown | f086ddb | 2014-02-11 14:28:48 -0800 | [diff] [blame] | 77 | |
Prabir Pradhan | 8ede1d1 | 2023-05-08 19:37:44 +0000 | [diff] [blame] | 78 | // Ensure common actions are interchangeable between keys and motions for convenience. |
| 79 | static_assert(AMOTION_EVENT_ACTION_DOWN == AKEY_EVENT_ACTION_DOWN); |
| 80 | static_assert(AMOTION_EVENT_ACTION_UP == AKEY_EVENT_ACTION_UP); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 81 | static constexpr int32_t ACTION_DOWN = AMOTION_EVENT_ACTION_DOWN; |
| 82 | static constexpr int32_t ACTION_MOVE = AMOTION_EVENT_ACTION_MOVE; |
| 83 | static constexpr int32_t ACTION_UP = AMOTION_EVENT_ACTION_UP; |
| 84 | static constexpr int32_t ACTION_HOVER_ENTER = AMOTION_EVENT_ACTION_HOVER_ENTER; |
Siarhei Vishniakou | a235c04 | 2023-05-02 09:59:09 -0700 | [diff] [blame] | 85 | static constexpr int32_t ACTION_HOVER_MOVE = AMOTION_EVENT_ACTION_HOVER_MOVE; |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 86 | static constexpr int32_t ACTION_HOVER_EXIT = AMOTION_EVENT_ACTION_HOVER_EXIT; |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 87 | static constexpr int32_t ACTION_SCROLL = AMOTION_EVENT_ACTION_SCROLL; |
Siarhei Vishniakou | 487c49b | 2022-12-02 15:48:57 -0800 | [diff] [blame] | 88 | static constexpr int32_t ACTION_OUTSIDE = AMOTION_EVENT_ACTION_OUTSIDE; |
Siarhei Vishniakou | 1ae72f1 | 2023-01-29 12:55:30 -0800 | [diff] [blame] | 89 | static constexpr int32_t ACTION_CANCEL = AMOTION_EVENT_ACTION_CANCEL; |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 90 | /** |
| 91 | * The POINTER_DOWN(0) is an unusual, but valid, action. It just means that the new pointer in the |
| 92 | * MotionEvent is at the index 0 rather than 1 (or later). That is, the pointer id=0 (which is at |
| 93 | * index 0) is the new pointer going down. The same pointer could have been placed at a different |
| 94 | * index, and the action would become POINTER_1_DOWN, 2, etc..; these would all be valid. In |
| 95 | * general, we try to place pointer id = 0 at the index 0. Of course, this is not possible if |
| 96 | * pointer id=0 leaves but the pointer id=1 remains. |
| 97 | */ |
| 98 | static constexpr int32_t POINTER_0_DOWN = |
| 99 | AMOTION_EVENT_ACTION_POINTER_DOWN | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT); |
Siarhei Vishniakou | a16e3a2 | 2022-03-02 15:26:40 -0800 | [diff] [blame] | 100 | static constexpr int32_t POINTER_1_DOWN = |
| 101 | AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT); |
Prabir Pradhan | b60b1dc | 2022-03-15 14:02:35 +0000 | [diff] [blame] | 102 | static constexpr int32_t POINTER_2_DOWN = |
| 103 | AMOTION_EVENT_ACTION_POINTER_DOWN | (2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT); |
Vaibhav Devmurari | 882bd9b | 2022-06-23 14:54:54 +0000 | [diff] [blame] | 104 | static constexpr int32_t POINTER_3_DOWN = |
| 105 | AMOTION_EVENT_ACTION_POINTER_DOWN | (3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT); |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 106 | static constexpr int32_t POINTER_0_UP = |
| 107 | AMOTION_EVENT_ACTION_POINTER_UP | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT); |
Siarhei Vishniakou | a16e3a2 | 2022-03-02 15:26:40 -0800 | [diff] [blame] | 108 | static constexpr int32_t POINTER_1_UP = |
| 109 | AMOTION_EVENT_ACTION_POINTER_UP | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT); |
Harry Cutts | b166c00 | 2023-05-09 13:06:05 +0000 | [diff] [blame] | 110 | static constexpr int32_t POINTER_2_UP = |
| 111 | AMOTION_EVENT_ACTION_POINTER_UP | (2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT); |
Siarhei Vishniakou | a16e3a2 | 2022-03-02 15:26:40 -0800 | [diff] [blame] | 112 | |
Antonio Kantek | 15beb51 | 2022-06-13 22:35:41 +0000 | [diff] [blame] | 113 | // The default pid and uid for the windows created on the secondary display by the test. |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 114 | static constexpr gui::Pid SECONDARY_WINDOW_PID{1010}; |
Prabir Pradhan | 8a5c41d | 2023-06-08 19:13:46 +0000 | [diff] [blame] | 115 | static constexpr gui::Uid SECONDARY_WINDOW_UID{1012}; |
Antonio Kantek | 15beb51 | 2022-06-13 22:35:41 +0000 | [diff] [blame] | 116 | |
Siarhei Vishniakou | 58cfc60 | 2020-12-14 23:21:30 +0000 | [diff] [blame] | 117 | // An arbitrary pid of the gesture monitor window |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 118 | static constexpr gui::Pid MONITOR_PID{2001}; |
Siarhei Vishniakou | 58cfc60 | 2020-12-14 23:21:30 +0000 | [diff] [blame] | 119 | |
Linnan Li | 7235222 | 2024-04-12 18:55:57 +0800 | [diff] [blame] | 120 | static constexpr int EXPECTED_WALLPAPER_FLAGS = |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 121 | AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED | AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED; |
| 122 | |
Siarhei Vishniakou | 56e7909 | 2023-02-21 19:13:16 -0800 | [diff] [blame] | 123 | using ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID; |
| 124 | |
Gang Wang | 342c927 | 2020-01-13 13:15:04 -0500 | [diff] [blame] | 125 | /** |
| 126 | * Return a DOWN key event with KEYCODE_A. |
| 127 | */ |
| 128 | static KeyEvent getTestKeyEvent() { |
| 129 | KeyEvent event; |
| 130 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 131 | event.initialize(InputEvent::nextId(), DEVICE_ID, AINPUT_SOURCE_KEYBOARD, |
| 132 | ui::LogicalDisplayId::INVALID, INVALID_HMAC, AKEY_EVENT_ACTION_DOWN, 0, |
| 133 | AKEYCODE_A, KEY_A, AMETA_NONE, 0, ARBITRARY_TIME, ARBITRARY_TIME); |
Gang Wang | 342c927 | 2020-01-13 13:15:04 -0500 | [diff] [blame] | 134 | return event; |
| 135 | } |
| 136 | |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 137 | /** |
| 138 | * Provide a local override for a flag value. The value is restored when the object of this class |
| 139 | * goes out of scope. |
| 140 | * This class is not intended to be used directly, because its usage is cumbersome. |
| 141 | * Instead, a wrapper macro SCOPED_FLAG_OVERRIDE is provided. |
| 142 | */ |
| 143 | class ScopedFlagOverride { |
| 144 | public: |
| 145 | ScopedFlagOverride(std::function<bool()> read, std::function<void(bool)> write, bool value) |
| 146 | : mInitialValue(read()), mWriteValue(write) { |
| 147 | mWriteValue(value); |
| 148 | } |
| 149 | ~ScopedFlagOverride() { mWriteValue(mInitialValue); } |
| 150 | |
| 151 | private: |
| 152 | const bool mInitialValue; |
| 153 | std::function<void(bool)> mWriteValue; |
| 154 | }; |
| 155 | |
| 156 | typedef bool (*readFlagValueFunction)(); |
| 157 | typedef void (*writeFlagValueFunction)(bool); |
| 158 | |
| 159 | /** |
| 160 | * Use this macro to locally override a flag value. |
| 161 | * Example usage: |
| 162 | * SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); |
| 163 | * Note: this works by creating a local variable in your current scope. Don't call this twice for |
| 164 | * the same flag, because the variable names will clash! |
| 165 | */ |
| 166 | #define SCOPED_FLAG_OVERRIDE(NAME, VALUE) \ |
| 167 | readFlagValueFunction read##NAME = com::android::input::flags::NAME; \ |
| 168 | writeFlagValueFunction write##NAME = com::android::input::flags::NAME; \ |
| 169 | ScopedFlagOverride override##NAME(read##NAME, write##NAME, (VALUE)) |
| 170 | |
Siarhei Vishniakou | f404321 | 2023-09-18 19:33:03 -0700 | [diff] [blame] | 171 | } // namespace |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 172 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 173 | // --- InputDispatcherTest --- |
| 174 | |
| 175 | class InputDispatcherTest : public testing::Test { |
| 176 | protected: |
Prabir Pradhan | a41d244 | 2023-04-20 21:30:40 +0000 | [diff] [blame] | 177 | std::unique_ptr<FakeInputDispatcherPolicy> mFakePolicy; |
Siarhei Vishniakou | 1805009 | 2021-09-01 13:32:49 -0700 | [diff] [blame] | 178 | std::unique_ptr<InputDispatcher> mDispatcher; |
Prabir Pradhan | c534073 | 2024-03-20 22:53:52 +0000 | [diff] [blame] | 179 | std::shared_ptr<VerifyingTrace> mVerifyingTrace; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 180 | |
Siarhei Vishniakou | f265212 | 2021-03-05 21:39:46 +0000 | [diff] [blame] | 181 | void SetUp() override { |
Prabir Pradhan | c534073 | 2024-03-20 22:53:52 +0000 | [diff] [blame] | 182 | mVerifyingTrace = std::make_shared<VerifyingTrace>(); |
| 183 | FakeWindowHandle::sOnEventReceivedCallback = [this](const auto& _1, const auto& _2) { |
| 184 | handleEventReceivedByWindow(_1, _2); |
| 185 | }; |
| 186 | |
Prabir Pradhan | a41d244 | 2023-04-20 21:30:40 +0000 | [diff] [blame] | 187 | mFakePolicy = std::make_unique<FakeInputDispatcherPolicy>(); |
Prabir Pradhan | dc3a2ad | 2024-02-05 19:03:51 +0000 | [diff] [blame] | 188 | mDispatcher = std::make_unique<InputDispatcher>(*mFakePolicy, |
| 189 | std::make_unique<FakeInputTracingBackend>( |
Prabir Pradhan | c534073 | 2024-03-20 22:53:52 +0000 | [diff] [blame] | 190 | mVerifyingTrace)); |
Siarhei Vishniakou | a733311 | 2023-10-27 13:33:29 -0700 | [diff] [blame] | 191 | |
Harry Cutts | 101ee9b | 2023-07-06 18:04:14 +0000 | [diff] [blame] | 192 | mDispatcher->setInputDispatchMode(/*enabled=*/true, /*frozen=*/false); |
Siarhei Vishniakou | 870ecec | 2020-12-09 08:07:46 -1000 | [diff] [blame] | 193 | // Start InputDispatcher thread |
Prabir Pradhan | 3608aad | 2019-10-02 17:08:26 -0700 | [diff] [blame] | 194 | ASSERT_EQ(OK, mDispatcher->start()); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 195 | } |
| 196 | |
Siarhei Vishniakou | f265212 | 2021-03-05 21:39:46 +0000 | [diff] [blame] | 197 | void TearDown() override { |
Prabir Pradhan | c534073 | 2024-03-20 22:53:52 +0000 | [diff] [blame] | 198 | ASSERT_NO_FATAL_FAILURE(mVerifyingTrace->verifyExpectedEventsTraced()); |
| 199 | FakeWindowHandle::sOnEventReceivedCallback = nullptr; |
| 200 | |
Prabir Pradhan | 3608aad | 2019-10-02 17:08:26 -0700 | [diff] [blame] | 201 | ASSERT_EQ(OK, mDispatcher->stop()); |
Prabir Pradhan | a41d244 | 2023-04-20 21:30:40 +0000 | [diff] [blame] | 202 | mFakePolicy.reset(); |
Siarhei Vishniakou | 1805009 | 2021-09-01 13:32:49 -0700 | [diff] [blame] | 203 | mDispatcher.reset(); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 204 | } |
Siarhei Vishniakou | 4cb50ca | 2020-05-26 21:43:02 -0700 | [diff] [blame] | 205 | |
Prabir Pradhan | c534073 | 2024-03-20 22:53:52 +0000 | [diff] [blame] | 206 | void handleEventReceivedByWindow(const std::unique_ptr<InputEvent>& event, |
| 207 | const gui::WindowInfo& info) { |
| 208 | if (!event) { |
| 209 | return; |
| 210 | } |
| 211 | |
| 212 | switch (event->getType()) { |
| 213 | case InputEventType::KEY: { |
| 214 | mVerifyingTrace->expectKeyDispatchTraced(static_cast<KeyEvent&>(*event), info.id); |
| 215 | break; |
| 216 | } |
| 217 | case InputEventType::MOTION: { |
| 218 | mVerifyingTrace->expectMotionDispatchTraced(static_cast<MotionEvent&>(*event), |
| 219 | info.id); |
| 220 | break; |
| 221 | } |
| 222 | default: |
| 223 | break; |
| 224 | } |
| 225 | } |
| 226 | |
Siarhei Vishniakou | 4cb50ca | 2020-05-26 21:43:02 -0700 | [diff] [blame] | 227 | /** |
| 228 | * Used for debugging when writing the test |
| 229 | */ |
| 230 | void dumpDispatcherState() { |
| 231 | std::string dump; |
| 232 | mDispatcher->dump(dump); |
| 233 | std::stringstream ss(dump); |
| 234 | std::string to; |
| 235 | |
| 236 | while (std::getline(ss, to, '\n')) { |
| 237 | ALOGE("%s", to.c_str()); |
| 238 | } |
| 239 | } |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 240 | |
Chavi Weingarten | 847e851 | 2023-03-29 00:26:09 +0000 | [diff] [blame] | 241 | void setFocusedWindow(const sp<WindowInfoHandle>& window) { |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 242 | FocusRequest request; |
| 243 | request.token = window->getToken(); |
Siarhei Vishniakou | 5d552c4 | 2021-05-21 05:02:22 +0000 | [diff] [blame] | 244 | request.windowName = window->getName(); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 245 | request.timestamp = systemTime(SYSTEM_TIME_MONOTONIC); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 246 | request.displayId = window->getInfo()->displayId.val(); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 247 | mDispatcher->setFocusedWindow(request); |
| 248 | } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 249 | }; |
| 250 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 251 | TEST_F(InputDispatcherTest, InjectInputEvent_ValidatesKeyEvents) { |
| 252 | KeyEvent event; |
| 253 | |
| 254 | // Rejects undefined key actions. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 255 | event.initialize(InputEvent::nextId(), DEVICE_ID, AINPUT_SOURCE_KEYBOARD, |
| 256 | ui::LogicalDisplayId::INVALID, INVALID_HMAC, |
Harry Cutts | 101ee9b | 2023-07-06 18:04:14 +0000 | [diff] [blame] | 257 | /*action=*/-1, 0, AKEYCODE_A, KEY_A, AMETA_NONE, 0, ARBITRARY_TIME, |
Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 258 | ARBITRARY_TIME); |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 259 | ASSERT_EQ(InputEventInjectionResult::FAILED, |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 260 | mDispatcher->injectInputEvent(&event, /*targetUid=*/{}, InputEventInjectionSync::NONE, |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 261 | 0ms, 0)) |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 262 | << "Should reject key events with undefined action."; |
| 263 | |
| 264 | // Rejects ACTION_MULTIPLE since it is not supported despite being defined in the API. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 265 | event.initialize(InputEvent::nextId(), DEVICE_ID, AINPUT_SOURCE_KEYBOARD, |
| 266 | ui::LogicalDisplayId::INVALID, INVALID_HMAC, AKEY_EVENT_ACTION_MULTIPLE, 0, |
| 267 | AKEYCODE_A, KEY_A, AMETA_NONE, 0, ARBITRARY_TIME, ARBITRARY_TIME); |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 268 | ASSERT_EQ(InputEventInjectionResult::FAILED, |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 269 | mDispatcher->injectInputEvent(&event, /*targetUid=*/{}, InputEventInjectionSync::NONE, |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 270 | 0ms, 0)) |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 271 | << "Should reject key events with ACTION_MULTIPLE."; |
| 272 | } |
| 273 | |
| 274 | TEST_F(InputDispatcherTest, InjectInputEvent_ValidatesMotionEvents) { |
| 275 | MotionEvent event; |
| 276 | PointerProperties pointerProperties[MAX_POINTERS + 1]; |
| 277 | PointerCoords pointerCoords[MAX_POINTERS + 1]; |
Siarhei Vishniakou | 0174738 | 2022-01-20 13:23:27 -0800 | [diff] [blame] | 278 | for (size_t i = 0; i <= MAX_POINTERS; i++) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 279 | pointerProperties[i].clear(); |
| 280 | pointerProperties[i].id = i; |
| 281 | pointerCoords[i].clear(); |
| 282 | } |
| 283 | |
Siarhei Vishniakou | 49e5922 | 2018-12-28 18:17:15 -0800 | [diff] [blame] | 284 | // Some constants commonly used below |
| 285 | constexpr int32_t source = AINPUT_SOURCE_TOUCHSCREEN; |
| 286 | constexpr int32_t edgeFlags = AMOTION_EVENT_EDGE_FLAG_NONE; |
| 287 | constexpr int32_t metaState = AMETA_NONE; |
| 288 | constexpr MotionClassification classification = MotionClassification::NONE; |
| 289 | |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 290 | ui::Transform identityTransform; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 291 | // Rejects undefined motion actions. |
Garfield Tan | fbe732e | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 292 | event.initialize(InputEvent::nextId(), DEVICE_ID, source, DISPLAY_ID, INVALID_HMAC, |
Harry Cutts | 101ee9b | 2023-07-06 18:04:14 +0000 | [diff] [blame] | 293 | /*action=*/-1, 0, 0, edgeFlags, metaState, 0, classification, |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 294 | identityTransform, 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION, |
Prabir Pradhan | b9b1850 | 2021-08-26 12:30:32 -0700 | [diff] [blame] | 295 | AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform, ARBITRARY_TIME, |
| 296 | ARBITRARY_TIME, |
Harry Cutts | 101ee9b | 2023-07-06 18:04:14 +0000 | [diff] [blame] | 297 | /*pointerCount=*/1, pointerProperties, pointerCoords); |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 298 | ASSERT_EQ(InputEventInjectionResult::FAILED, |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 299 | mDispatcher->injectInputEvent(&event, /*targetUid=*/{}, InputEventInjectionSync::NONE, |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 300 | 0ms, 0)) |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 301 | << "Should reject motion events with undefined action."; |
| 302 | |
| 303 | // Rejects pointer down with invalid index. |
Garfield Tan | fbe732e | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 304 | event.initialize(InputEvent::nextId(), DEVICE_ID, source, DISPLAY_ID, INVALID_HMAC, |
Siarhei Vishniakou | a16e3a2 | 2022-03-02 15:26:40 -0800 | [diff] [blame] | 305 | POINTER_1_DOWN, 0, 0, edgeFlags, metaState, 0, classification, |
| 306 | identityTransform, 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION, |
| 307 | AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform, ARBITRARY_TIME, |
| 308 | ARBITRARY_TIME, |
Harry Cutts | 101ee9b | 2023-07-06 18:04:14 +0000 | [diff] [blame] | 309 | /*pointerCount=*/1, pointerProperties, pointerCoords); |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 310 | ASSERT_EQ(InputEventInjectionResult::FAILED, |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 311 | mDispatcher->injectInputEvent(&event, /*targetUid=*/{}, InputEventInjectionSync::NONE, |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 312 | 0ms, 0)) |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 313 | << "Should reject motion events with pointer down index too large."; |
| 314 | |
Garfield Tan | fbe732e | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 315 | event.initialize(InputEvent::nextId(), DEVICE_ID, source, DISPLAY_ID, INVALID_HMAC, |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 316 | AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 317 | (~0U << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 318 | 0, 0, edgeFlags, metaState, 0, classification, identityTransform, 0, 0, |
| 319 | AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION, |
Prabir Pradhan | b9b1850 | 2021-08-26 12:30:32 -0700 | [diff] [blame] | 320 | identityTransform, ARBITRARY_TIME, ARBITRARY_TIME, |
Harry Cutts | 101ee9b | 2023-07-06 18:04:14 +0000 | [diff] [blame] | 321 | /*pointerCount=*/1, pointerProperties, pointerCoords); |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 322 | ASSERT_EQ(InputEventInjectionResult::FAILED, |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 323 | mDispatcher->injectInputEvent(&event, /*targetUid=*/{}, InputEventInjectionSync::NONE, |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 324 | 0ms, 0)) |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 325 | << "Should reject motion events with pointer down index too small."; |
| 326 | |
| 327 | // Rejects pointer up with invalid index. |
Garfield Tan | fbe732e | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 328 | event.initialize(InputEvent::nextId(), DEVICE_ID, source, DISPLAY_ID, INVALID_HMAC, |
Siarhei Vishniakou | a16e3a2 | 2022-03-02 15:26:40 -0800 | [diff] [blame] | 329 | POINTER_1_UP, 0, 0, edgeFlags, metaState, 0, classification, identityTransform, |
| 330 | 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION, |
| 331 | AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform, ARBITRARY_TIME, |
| 332 | ARBITRARY_TIME, |
Harry Cutts | 101ee9b | 2023-07-06 18:04:14 +0000 | [diff] [blame] | 333 | /*pointerCount=*/1, pointerProperties, pointerCoords); |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 334 | ASSERT_EQ(InputEventInjectionResult::FAILED, |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 335 | mDispatcher->injectInputEvent(&event, /*targetUid=*/{}, InputEventInjectionSync::NONE, |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 336 | 0ms, 0)) |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 337 | << "Should reject motion events with pointer up index too large."; |
| 338 | |
Garfield Tan | fbe732e | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 339 | event.initialize(InputEvent::nextId(), DEVICE_ID, source, DISPLAY_ID, INVALID_HMAC, |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 340 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 341 | (~0U << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 342 | 0, 0, edgeFlags, metaState, 0, classification, identityTransform, 0, 0, |
| 343 | AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION, |
Prabir Pradhan | b9b1850 | 2021-08-26 12:30:32 -0700 | [diff] [blame] | 344 | identityTransform, ARBITRARY_TIME, ARBITRARY_TIME, |
Harry Cutts | 101ee9b | 2023-07-06 18:04:14 +0000 | [diff] [blame] | 345 | /*pointerCount=*/1, pointerProperties, pointerCoords); |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 346 | ASSERT_EQ(InputEventInjectionResult::FAILED, |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 347 | mDispatcher->injectInputEvent(&event, /*targetUid=*/{}, InputEventInjectionSync::NONE, |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 348 | 0ms, 0)) |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 349 | << "Should reject motion events with pointer up index too small."; |
| 350 | |
| 351 | // Rejects motion events with invalid number of pointers. |
Garfield Tan | fbe732e | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 352 | event.initialize(InputEvent::nextId(), DEVICE_ID, source, DISPLAY_ID, INVALID_HMAC, |
| 353 | AMOTION_EVENT_ACTION_DOWN, 0, 0, edgeFlags, metaState, 0, classification, |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 354 | identityTransform, 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION, |
Prabir Pradhan | b9b1850 | 2021-08-26 12:30:32 -0700 | [diff] [blame] | 355 | AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform, ARBITRARY_TIME, |
| 356 | ARBITRARY_TIME, |
Harry Cutts | 101ee9b | 2023-07-06 18:04:14 +0000 | [diff] [blame] | 357 | /*pointerCount=*/0, pointerProperties, pointerCoords); |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 358 | ASSERT_EQ(InputEventInjectionResult::FAILED, |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 359 | mDispatcher->injectInputEvent(&event, /*targetUid=*/{}, InputEventInjectionSync::NONE, |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 360 | 0ms, 0)) |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 361 | << "Should reject motion events with 0 pointers."; |
| 362 | |
Garfield Tan | fbe732e | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 363 | event.initialize(InputEvent::nextId(), DEVICE_ID, source, DISPLAY_ID, INVALID_HMAC, |
| 364 | AMOTION_EVENT_ACTION_DOWN, 0, 0, edgeFlags, metaState, 0, classification, |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 365 | identityTransform, 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION, |
Prabir Pradhan | b9b1850 | 2021-08-26 12:30:32 -0700 | [diff] [blame] | 366 | AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform, ARBITRARY_TIME, |
| 367 | ARBITRARY_TIME, |
Harry Cutts | 101ee9b | 2023-07-06 18:04:14 +0000 | [diff] [blame] | 368 | /*pointerCount=*/MAX_POINTERS + 1, pointerProperties, pointerCoords); |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 369 | ASSERT_EQ(InputEventInjectionResult::FAILED, |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 370 | mDispatcher->injectInputEvent(&event, /*targetUid=*/{}, InputEventInjectionSync::NONE, |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 371 | 0ms, 0)) |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 372 | << "Should reject motion events with more than MAX_POINTERS pointers."; |
| 373 | |
| 374 | // Rejects motion events with invalid pointer ids. |
| 375 | pointerProperties[0].id = -1; |
Garfield Tan | fbe732e | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 376 | event.initialize(InputEvent::nextId(), DEVICE_ID, source, DISPLAY_ID, INVALID_HMAC, |
| 377 | AMOTION_EVENT_ACTION_DOWN, 0, 0, edgeFlags, metaState, 0, classification, |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 378 | identityTransform, 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION, |
Prabir Pradhan | b9b1850 | 2021-08-26 12:30:32 -0700 | [diff] [blame] | 379 | AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform, ARBITRARY_TIME, |
| 380 | ARBITRARY_TIME, |
Harry Cutts | 101ee9b | 2023-07-06 18:04:14 +0000 | [diff] [blame] | 381 | /*pointerCount=*/1, pointerProperties, pointerCoords); |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 382 | ASSERT_EQ(InputEventInjectionResult::FAILED, |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 383 | mDispatcher->injectInputEvent(&event, /*targetUid=*/{}, InputEventInjectionSync::NONE, |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 384 | 0ms, 0)) |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 385 | << "Should reject motion events with pointer ids less than 0."; |
| 386 | |
| 387 | pointerProperties[0].id = MAX_POINTER_ID + 1; |
Garfield Tan | fbe732e | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 388 | event.initialize(InputEvent::nextId(), DEVICE_ID, source, DISPLAY_ID, INVALID_HMAC, |
| 389 | AMOTION_EVENT_ACTION_DOWN, 0, 0, edgeFlags, metaState, 0, classification, |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 390 | identityTransform, 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION, |
Prabir Pradhan | b9b1850 | 2021-08-26 12:30:32 -0700 | [diff] [blame] | 391 | AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform, ARBITRARY_TIME, |
| 392 | ARBITRARY_TIME, |
Harry Cutts | 101ee9b | 2023-07-06 18:04:14 +0000 | [diff] [blame] | 393 | /*pointerCount=*/1, pointerProperties, pointerCoords); |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 394 | ASSERT_EQ(InputEventInjectionResult::FAILED, |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 395 | mDispatcher->injectInputEvent(&event, /*targetUid=*/{}, InputEventInjectionSync::NONE, |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 396 | 0ms, 0)) |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 397 | << "Should reject motion events with pointer ids greater than MAX_POINTER_ID."; |
| 398 | |
| 399 | // Rejects motion events with duplicate pointer ids. |
| 400 | pointerProperties[0].id = 1; |
| 401 | pointerProperties[1].id = 1; |
Garfield Tan | fbe732e | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 402 | event.initialize(InputEvent::nextId(), DEVICE_ID, source, DISPLAY_ID, INVALID_HMAC, |
| 403 | AMOTION_EVENT_ACTION_DOWN, 0, 0, edgeFlags, metaState, 0, classification, |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 404 | identityTransform, 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION, |
Prabir Pradhan | b9b1850 | 2021-08-26 12:30:32 -0700 | [diff] [blame] | 405 | AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform, ARBITRARY_TIME, |
| 406 | ARBITRARY_TIME, |
Harry Cutts | 101ee9b | 2023-07-06 18:04:14 +0000 | [diff] [blame] | 407 | /*pointerCount=*/2, pointerProperties, pointerCoords); |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 408 | ASSERT_EQ(InputEventInjectionResult::FAILED, |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 409 | mDispatcher->injectInputEvent(&event, /*targetUid=*/{}, InputEventInjectionSync::NONE, |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 410 | 0ms, 0)) |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 411 | << "Should reject motion events with duplicate pointer ids."; |
| 412 | } |
| 413 | |
Siarhei Vishniakou | 2bfa905 | 2019-11-21 18:10:54 -0800 | [diff] [blame] | 414 | /* Test InputDispatcher for notifyConfigurationChanged and notifySwitch events */ |
| 415 | |
Siarhei Vishniakou | 2bfa905 | 2019-11-21 18:10:54 -0800 | [diff] [blame] | 416 | TEST_F(InputDispatcherTest, NotifySwitch_CallsPolicy) { |
Prabir Pradhan | a8fe7c5 | 2023-12-14 22:07:23 +0000 | [diff] [blame] | 417 | NotifySwitchArgs args(InputEvent::nextId(), /*eventTime=*/20, /*policyFlags=*/0, |
| 418 | /*switchValues=*/1, |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 419 | /*switchMask=*/2); |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 420 | mDispatcher->notifySwitch(args); |
Siarhei Vishniakou | 2bfa905 | 2019-11-21 18:10:54 -0800 | [diff] [blame] | 421 | |
| 422 | // InputDispatcher adds POLICY_FLAG_TRUSTED because the event went through InputListener |
| 423 | args.policyFlags |= POLICY_FLAG_TRUSTED; |
| 424 | mFakePolicy->assertNotifySwitchWasCalled(args); |
| 425 | } |
| 426 | |
Siarhei Vishniakou | adeb6fa | 2023-05-26 09:11:06 -0700 | [diff] [blame] | 427 | namespace { |
| 428 | |
Siarhei Vishniakou | 097c3db | 2020-05-06 14:18:38 -0700 | [diff] [blame] | 429 | static constexpr std::chrono::duration INJECT_EVENT_TIMEOUT = 500ms; |
Siarhei Vishniakou | 540dbae | 2020-05-05 18:17:17 -0700 | [diff] [blame] | 430 | |
Prabir Pradhan | 112b1ad | 2023-09-21 09:53:53 +0000 | [diff] [blame] | 431 | class FakeMonitorReceiver { |
| 432 | public: |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 433 | FakeMonitorReceiver(InputDispatcher& dispatcher, const std::string name, |
| 434 | ui::LogicalDisplayId displayId) |
Siarhei Vishniakou | 2defec0 | 2023-06-08 17:24:44 -0700 | [diff] [blame] | 435 | : mInputReceiver(*dispatcher.createInputMonitor(displayId, name, MONITOR_PID), name) {} |
Prabir Pradhan | 112b1ad | 2023-09-21 09:53:53 +0000 | [diff] [blame] | 436 | |
Siarhei Vishniakou | 2defec0 | 2023-06-08 17:24:44 -0700 | [diff] [blame] | 437 | sp<IBinder> getToken() { return mInputReceiver.getToken(); } |
Prabir Pradhan | 112b1ad | 2023-09-21 09:53:53 +0000 | [diff] [blame] | 438 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 439 | void consumeKeyDown(ui::LogicalDisplayId expectedDisplayId, int32_t expectedFlags = 0) { |
Siarhei Vishniakou | 2defec0 | 2023-06-08 17:24:44 -0700 | [diff] [blame] | 440 | mInputReceiver.consumeEvent(InputEventType::KEY, AKEY_EVENT_ACTION_DOWN, expectedDisplayId, |
| 441 | expectedFlags); |
Prabir Pradhan | 112b1ad | 2023-09-21 09:53:53 +0000 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | std::optional<int32_t> receiveEvent() { |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 445 | const auto [sequenceNum, _] = mInputReceiver.receiveEvent(CONSUME_TIMEOUT_EVENT_EXPECTED); |
| 446 | return sequenceNum; |
Prabir Pradhan | 112b1ad | 2023-09-21 09:53:53 +0000 | [diff] [blame] | 447 | } |
| 448 | |
Siarhei Vishniakou | 2defec0 | 2023-06-08 17:24:44 -0700 | [diff] [blame] | 449 | void finishEvent(uint32_t consumeSeq) { return mInputReceiver.finishEvent(consumeSeq); } |
Prabir Pradhan | 112b1ad | 2023-09-21 09:53:53 +0000 | [diff] [blame] | 450 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 451 | void consumeMotionDown(ui::LogicalDisplayId expectedDisplayId, int32_t expectedFlags = 0) { |
Siarhei Vishniakou | 2defec0 | 2023-06-08 17:24:44 -0700 | [diff] [blame] | 452 | mInputReceiver.consumeEvent(InputEventType::MOTION, AMOTION_EVENT_ACTION_DOWN, |
| 453 | expectedDisplayId, expectedFlags); |
Prabir Pradhan | 112b1ad | 2023-09-21 09:53:53 +0000 | [diff] [blame] | 454 | } |
| 455 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 456 | void consumeMotionMove(ui::LogicalDisplayId expectedDisplayId, int32_t expectedFlags = 0) { |
Siarhei Vishniakou | 2defec0 | 2023-06-08 17:24:44 -0700 | [diff] [blame] | 457 | mInputReceiver.consumeEvent(InputEventType::MOTION, AMOTION_EVENT_ACTION_MOVE, |
| 458 | expectedDisplayId, expectedFlags); |
Prabir Pradhan | 112b1ad | 2023-09-21 09:53:53 +0000 | [diff] [blame] | 459 | } |
| 460 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 461 | void consumeMotionUp(ui::LogicalDisplayId expectedDisplayId, int32_t expectedFlags = 0) { |
Siarhei Vishniakou | 2defec0 | 2023-06-08 17:24:44 -0700 | [diff] [blame] | 462 | mInputReceiver.consumeEvent(InputEventType::MOTION, AMOTION_EVENT_ACTION_UP, |
| 463 | expectedDisplayId, expectedFlags); |
Prabir Pradhan | 112b1ad | 2023-09-21 09:53:53 +0000 | [diff] [blame] | 464 | } |
| 465 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 466 | void consumeMotionCancel(ui::LogicalDisplayId expectedDisplayId, int32_t expectedFlags = 0) { |
Siarhei Vishniakou | 2defec0 | 2023-06-08 17:24:44 -0700 | [diff] [blame] | 467 | mInputReceiver.consumeMotionEvent( |
Prabir Pradhan | 112b1ad | 2023-09-21 09:53:53 +0000 | [diff] [blame] | 468 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_CANCEL), |
| 469 | WithDisplayId(expectedDisplayId), |
| 470 | WithFlags(expectedFlags | AMOTION_EVENT_FLAG_CANCELED))); |
| 471 | } |
| 472 | |
| 473 | void consumeMotionPointerDown(int32_t pointerIdx) { |
| 474 | int32_t action = AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 475 | (pointerIdx << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 476 | mInputReceiver.consumeEvent(InputEventType::MOTION, action, ui::LogicalDisplayId::DEFAULT, |
Siarhei Vishniakou | 2defec0 | 2023-06-08 17:24:44 -0700 | [diff] [blame] | 477 | /*expectedFlags=*/0); |
Prabir Pradhan | 112b1ad | 2023-09-21 09:53:53 +0000 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | void consumeMotionEvent(const ::testing::Matcher<MotionEvent>& matcher) { |
Siarhei Vishniakou | 2defec0 | 2023-06-08 17:24:44 -0700 | [diff] [blame] | 481 | mInputReceiver.consumeMotionEvent(matcher); |
Prabir Pradhan | 112b1ad | 2023-09-21 09:53:53 +0000 | [diff] [blame] | 482 | } |
| 483 | |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 484 | std::unique_ptr<MotionEvent> consumeMotion() { return mInputReceiver.consumeMotion(); } |
Prabir Pradhan | 112b1ad | 2023-09-21 09:53:53 +0000 | [diff] [blame] | 485 | |
Siarhei Vishniakou | ef2b450 | 2023-12-28 11:51:47 -0800 | [diff] [blame] | 486 | void assertNoEvents() { mInputReceiver.assertNoEvents(CONSUME_TIMEOUT_NO_EVENT_EXPECTED); } |
Prabir Pradhan | 112b1ad | 2023-09-21 09:53:53 +0000 | [diff] [blame] | 487 | |
| 488 | private: |
Siarhei Vishniakou | 2defec0 | 2023-06-08 17:24:44 -0700 | [diff] [blame] | 489 | FakeInputReceiver mInputReceiver; |
Prabir Pradhan | 112b1ad | 2023-09-21 09:53:53 +0000 | [diff] [blame] | 490 | }; |
| 491 | |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 492 | static InputEventInjectionResult injectKey( |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 493 | InputDispatcher& dispatcher, int32_t action, int32_t repeatCount, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 494 | ui::LogicalDisplayId displayId = ui::LogicalDisplayId::INVALID, |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 495 | InputEventInjectionSync syncMode = InputEventInjectionSync::WAIT_FOR_RESULT, |
Prabir Pradhan | 93f342c | 2021-03-11 15:05:30 -0800 | [diff] [blame] | 496 | std::chrono::milliseconds injectionTimeout = INJECT_EVENT_TIMEOUT, |
Prabir Pradhan | 8a5c41d | 2023-06-08 19:13:46 +0000 | [diff] [blame] | 497 | bool allowKeyRepeat = true, std::optional<gui::Uid> targetUid = {}, |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 498 | uint32_t policyFlags = DEFAULT_POLICY_FLAGS) { |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 499 | KeyEvent event; |
| 500 | nsecs_t currentTime = systemTime(SYSTEM_TIME_MONOTONIC); |
| 501 | |
| 502 | // Define a valid key down event. |
Garfield Tan | fbe732e | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 503 | event.initialize(InputEvent::nextId(), DEVICE_ID, AINPUT_SOURCE_KEYBOARD, displayId, |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 504 | INVALID_HMAC, action, /*flags=*/0, AKEYCODE_A, KEY_A, AMETA_NONE, repeatCount, |
| 505 | currentTime, currentTime); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 506 | |
Prabir Pradhan | 93f342c | 2021-03-11 15:05:30 -0800 | [diff] [blame] | 507 | if (!allowKeyRepeat) { |
| 508 | policyFlags |= POLICY_FLAG_DISABLE_KEY_REPEAT; |
| 509 | } |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 510 | // Inject event until dispatch out. |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 511 | return dispatcher.injectInputEvent(&event, targetUid, syncMode, injectionTimeout, policyFlags); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 512 | } |
| 513 | |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 514 | static void assertInjectedKeyTimesOut(InputDispatcher& dispatcher) { |
| 515 | InputEventInjectionResult result = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 516 | injectKey(dispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, |
| 517 | ui::LogicalDisplayId::INVALID, InputEventInjectionSync::WAIT_FOR_RESULT, |
| 518 | CONSUME_TIMEOUT_NO_EVENT_EXPECTED); |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 519 | if (result != InputEventInjectionResult::TIMED_OUT) { |
| 520 | FAIL() << "Injection should have timed out, but got " << ftl::enum_string(result); |
| 521 | } |
| 522 | } |
| 523 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 524 | static InputEventInjectionResult injectKeyDown( |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 525 | InputDispatcher& dispatcher, |
| 526 | ui::LogicalDisplayId displayId = ui::LogicalDisplayId::INVALID) { |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 527 | return injectKey(dispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, displayId); |
Siarhei Vishniakou | 4cb50ca | 2020-05-26 21:43:02 -0700 | [diff] [blame] | 528 | } |
| 529 | |
Prabir Pradhan | 93f342c | 2021-03-11 15:05:30 -0800 | [diff] [blame] | 530 | // Inject a down event that has key repeat disabled. This allows InputDispatcher to idle without |
| 531 | // sending a subsequent key up. When key repeat is enabled, the dispatcher cannot idle because it |
| 532 | // has to be woken up to process the repeating key. |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 533 | static InputEventInjectionResult injectKeyDownNoRepeat( |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 534 | InputDispatcher& dispatcher, |
| 535 | ui::LogicalDisplayId displayId = ui::LogicalDisplayId::INVALID) { |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 536 | return injectKey(dispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, displayId, |
Prabir Pradhan | 93f342c | 2021-03-11 15:05:30 -0800 | [diff] [blame] | 537 | InputEventInjectionSync::WAIT_FOR_RESULT, INJECT_EVENT_TIMEOUT, |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 538 | /*allowKeyRepeat=*/false); |
Prabir Pradhan | 93f342c | 2021-03-11 15:05:30 -0800 | [diff] [blame] | 539 | } |
| 540 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 541 | static InputEventInjectionResult injectKeyUp( |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 542 | InputDispatcher& dispatcher, |
| 543 | ui::LogicalDisplayId displayId = ui::LogicalDisplayId::INVALID) { |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 544 | return injectKey(dispatcher, AKEY_EVENT_ACTION_UP, /*repeatCount=*/0, displayId); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 545 | } |
| 546 | |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 547 | static InputEventInjectionResult injectMotionEvent( |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 548 | InputDispatcher& dispatcher, const MotionEvent& event, |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 549 | std::chrono::milliseconds injectionTimeout = INJECT_EVENT_TIMEOUT, |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 550 | InputEventInjectionSync injectionMode = InputEventInjectionSync::WAIT_FOR_RESULT, |
Prabir Pradhan | 8a5c41d | 2023-06-08 19:13:46 +0000 | [diff] [blame] | 551 | std::optional<gui::Uid> targetUid = {}, uint32_t policyFlags = DEFAULT_POLICY_FLAGS) { |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 552 | return dispatcher.injectInputEvent(&event, targetUid, injectionMode, injectionTimeout, |
| 553 | policyFlags); |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 554 | } |
| 555 | |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 556 | static InputEventInjectionResult injectMotionEvent( |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 557 | InputDispatcher& dispatcher, int32_t action, int32_t source, ui::LogicalDisplayId displayId, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 558 | const PointF& position = {100, 200}, |
Siarhei Vishniakou | 4cb50ca | 2020-05-26 21:43:02 -0700 | [diff] [blame] | 559 | const PointF& cursorPosition = {AMOTION_EVENT_INVALID_CURSOR_POSITION, |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 560 | AMOTION_EVENT_INVALID_CURSOR_POSITION}, |
| 561 | std::chrono::milliseconds injectionTimeout = INJECT_EVENT_TIMEOUT, |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 562 | InputEventInjectionSync injectionMode = InputEventInjectionSync::WAIT_FOR_RESULT, |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 563 | nsecs_t eventTime = systemTime(SYSTEM_TIME_MONOTONIC), |
Prabir Pradhan | 8a5c41d | 2023-06-08 19:13:46 +0000 | [diff] [blame] | 564 | std::optional<gui::Uid> targetUid = {}, uint32_t policyFlags = DEFAULT_POLICY_FLAGS) { |
Siarhei Vishniakou | 90ee478 | 2023-05-08 11:57:24 -0700 | [diff] [blame] | 565 | MotionEventBuilder motionBuilder = |
| 566 | MotionEventBuilder(action, source) |
| 567 | .displayId(displayId) |
| 568 | .eventTime(eventTime) |
| 569 | .rawXCursorPosition(cursorPosition.x) |
| 570 | .rawYCursorPosition(cursorPosition.y) |
| 571 | .pointer( |
| 572 | PointerBuilder(/*id=*/0, ToolType::FINGER).x(position.x).y(position.y)); |
| 573 | if (MotionEvent::getActionMasked(action) == ACTION_DOWN) { |
| 574 | motionBuilder.downTime(eventTime); |
| 575 | } |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 576 | |
| 577 | // Inject event until dispatch out. |
Siarhei Vishniakou | 90ee478 | 2023-05-08 11:57:24 -0700 | [diff] [blame] | 578 | return injectMotionEvent(dispatcher, motionBuilder.build(), injectionTimeout, injectionMode, |
| 579 | targetUid, policyFlags); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 580 | } |
| 581 | |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 582 | static InputEventInjectionResult injectMotionDown(InputDispatcher& dispatcher, int32_t source, |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 583 | ui::LogicalDisplayId displayId, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 584 | const PointF& location = {100, 200}) { |
Siarhei Vishniakou | 4cb50ca | 2020-05-26 21:43:02 -0700 | [diff] [blame] | 585 | return injectMotionEvent(dispatcher, AMOTION_EVENT_ACTION_DOWN, source, displayId, location); |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 586 | } |
| 587 | |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 588 | static InputEventInjectionResult injectMotionUp(InputDispatcher& dispatcher, int32_t source, |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 589 | ui::LogicalDisplayId displayId, |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 590 | const PointF& location = {100, 200}) { |
Siarhei Vishniakou | 4cb50ca | 2020-05-26 21:43:02 -0700 | [diff] [blame] | 591 | return injectMotionEvent(dispatcher, AMOTION_EVENT_ACTION_UP, source, displayId, location); |
Michael Wright | 3a240c4 | 2019-12-10 20:53:41 +0000 | [diff] [blame] | 592 | } |
| 593 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 594 | static NotifyKeyArgs generateKeyArgs( |
| 595 | int32_t action, ui::LogicalDisplayId displayId = ui::LogicalDisplayId::INVALID) { |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 596 | nsecs_t currentTime = systemTime(SYSTEM_TIME_MONOTONIC); |
| 597 | // Define a valid key event. |
Prabir Pradhan | a8fe7c5 | 2023-12-14 22:07:23 +0000 | [diff] [blame] | 598 | NotifyKeyArgs args(InputEvent::nextId(), currentTime, /*readTime=*/0, DEVICE_ID, |
| 599 | AINPUT_SOURCE_KEYBOARD, displayId, POLICY_FLAG_PASS_TO_USER, action, |
| 600 | /*flags=*/0, AKEYCODE_A, KEY_A, AMETA_NONE, currentTime); |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 601 | |
| 602 | return args; |
| 603 | } |
| 604 | |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 605 | [[nodiscard]] static NotifyMotionArgs generateMotionArgs(int32_t action, int32_t source, |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 606 | ui::LogicalDisplayId displayId, |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 607 | const std::vector<PointF>& points) { |
chaviw | d1c2318 | 2019-12-20 18:44:56 -0800 | [diff] [blame] | 608 | size_t pointerCount = points.size(); |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 609 | if (action == AMOTION_EVENT_ACTION_DOWN || action == AMOTION_EVENT_ACTION_UP) { |
| 610 | EXPECT_EQ(1U, pointerCount) << "Actions DOWN and UP can only contain a single pointer"; |
| 611 | } |
| 612 | |
chaviw | d1c2318 | 2019-12-20 18:44:56 -0800 | [diff] [blame] | 613 | PointerProperties pointerProperties[pointerCount]; |
| 614 | PointerCoords pointerCoords[pointerCount]; |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 615 | |
chaviw | d1c2318 | 2019-12-20 18:44:56 -0800 | [diff] [blame] | 616 | for (size_t i = 0; i < pointerCount; i++) { |
| 617 | pointerProperties[i].clear(); |
| 618 | pointerProperties[i].id = i; |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 619 | pointerProperties[i].toolType = ToolType::FINGER; |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 620 | |
chaviw | d1c2318 | 2019-12-20 18:44:56 -0800 | [diff] [blame] | 621 | pointerCoords[i].clear(); |
| 622 | pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_X, points[i].x); |
| 623 | pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_Y, points[i].y); |
| 624 | } |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 625 | |
| 626 | nsecs_t currentTime = systemTime(SYSTEM_TIME_MONOTONIC); |
| 627 | // Define a valid motion event. |
Prabir Pradhan | a8fe7c5 | 2023-12-14 22:07:23 +0000 | [diff] [blame] | 628 | NotifyMotionArgs args(InputEvent::nextId(), currentTime, /*readTime=*/0, DEVICE_ID, source, |
| 629 | displayId, POLICY_FLAG_PASS_TO_USER, action, /*actionButton=*/0, |
| 630 | /*flags=*/0, AMETA_NONE, /*buttonState=*/0, MotionClassification::NONE, |
chaviw | d1c2318 | 2019-12-20 18:44:56 -0800 | [diff] [blame] | 631 | AMOTION_EVENT_EDGE_FLAG_NONE, pointerCount, pointerProperties, |
Harry Cutts | 101ee9b | 2023-07-06 18:04:14 +0000 | [diff] [blame] | 632 | pointerCoords, /*xPrecision=*/0, /*yPrecision=*/0, |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 633 | AMOTION_EVENT_INVALID_CURSOR_POSITION, |
Harry Cutts | 101ee9b | 2023-07-06 18:04:14 +0000 | [diff] [blame] | 634 | AMOTION_EVENT_INVALID_CURSOR_POSITION, currentTime, /*videoFrames=*/{}); |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 635 | |
| 636 | return args; |
| 637 | } |
| 638 | |
Siarhei Vishniakou | a16e3a2 | 2022-03-02 15:26:40 -0800 | [diff] [blame] | 639 | static NotifyMotionArgs generateTouchArgs(int32_t action, const std::vector<PointF>& points) { |
| 640 | return generateMotionArgs(action, AINPUT_SOURCE_TOUCHSCREEN, DISPLAY_ID, points); |
| 641 | } |
| 642 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 643 | static NotifyMotionArgs generateMotionArgs(int32_t action, int32_t source, |
| 644 | ui::LogicalDisplayId displayId) { |
chaviw | d1c2318 | 2019-12-20 18:44:56 -0800 | [diff] [blame] | 645 | return generateMotionArgs(action, source, displayId, {PointF{100, 200}}); |
| 646 | } |
| 647 | |
Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 648 | static NotifyPointerCaptureChangedArgs generatePointerCaptureChangedArgs( |
| 649 | const PointerCaptureRequest& request) { |
Prabir Pradhan | a8fe7c5 | 2023-12-14 22:07:23 +0000 | [diff] [blame] | 650 | return NotifyPointerCaptureChangedArgs(InputEvent::nextId(), systemTime(SYSTEM_TIME_MONOTONIC), |
| 651 | request); |
Prabir Pradhan | 9998771 | 2020-11-10 18:43:05 -0800 | [diff] [blame] | 652 | } |
| 653 | |
Siarhei Vishniakou | adeb6fa | 2023-05-26 09:11:06 -0700 | [diff] [blame] | 654 | } // namespace |
| 655 | |
Siarhei Vishniakou | 7aa3e94 | 2021-11-18 09:49:11 -0800 | [diff] [blame] | 656 | /** |
| 657 | * When a window unexpectedly disposes of its input channel, policy should be notified about the |
| 658 | * broken channel. |
| 659 | */ |
| 660 | TEST_F(InputDispatcherTest, WhenInputChannelBreaks_PolicyIsNotified) { |
| 661 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 662 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, |
| 663 | "Window that breaks its input channel", |
| 664 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 7aa3e94 | 2021-11-18 09:49:11 -0800 | [diff] [blame] | 665 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 666 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | 7aa3e94 | 2021-11-18 09:49:11 -0800 | [diff] [blame] | 667 | |
| 668 | // Window closes its channel, but the window remains. |
| 669 | window->destroyReceiver(); |
| 670 | mFakePolicy->assertNotifyInputChannelBrokenWasCalled(window->getInfo()->token); |
| 671 | } |
| 672 | |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 673 | TEST_F(InputDispatcherTest, SetInputWindow_SingleWindowTouch) { |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 674 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 675 | sp<FakeWindowHandle> window = |
| 676 | sp<FakeWindowHandle>::make(application, mDispatcher, "Fake Window", |
| 677 | ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 678 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 679 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 680 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 681 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 682 | ui::LogicalDisplayId::DEFAULT)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 683 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 684 | |
| 685 | // Window should receive motion event. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 686 | window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 687 | } |
| 688 | |
Siarhei Vishniakou | aeed0da | 2024-01-09 08:57:13 -0800 | [diff] [blame] | 689 | using InputDispatcherDeathTest = InputDispatcherTest; |
| 690 | |
| 691 | /** |
| 692 | * When 'onWindowInfosChanged' arguments contain a duplicate entry for the same window, dispatcher |
| 693 | * should crash. |
| 694 | */ |
| 695 | TEST_F(InputDispatcherDeathTest, DuplicateWindowInfosAbortDispatcher) { |
| 696 | testing::GTEST_FLAG(death_test_style) = "threadsafe"; |
| 697 | ScopedSilentDeath _silentDeath; |
| 698 | |
| 699 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 700 | sp<FakeWindowHandle> window = |
| 701 | sp<FakeWindowHandle>::make(application, mDispatcher, "Fake Window", |
| 702 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | aeed0da | 2024-01-09 08:57:13 -0800 | [diff] [blame] | 703 | ASSERT_DEATH(mDispatcher->onWindowInfosChanged( |
| 704 | {{*window->getInfo(), *window->getInfo()}, {}, 0, 0}), |
| 705 | "Incorrect WindowInfosUpdate provided"); |
| 706 | } |
| 707 | |
Prabir Pradhan | c44ce4d | 2021-10-05 05:26:29 -0700 | [diff] [blame] | 708 | TEST_F(InputDispatcherTest, WhenDisplayNotSpecified_InjectMotionToDefaultDisplay) { |
| 709 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 710 | sp<FakeWindowHandle> window = |
| 711 | sp<FakeWindowHandle>::make(application, mDispatcher, "Fake Window", |
| 712 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | c44ce4d | 2021-10-05 05:26:29 -0700 | [diff] [blame] | 713 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 714 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Prabir Pradhan | c44ce4d | 2021-10-05 05:26:29 -0700 | [diff] [blame] | 715 | // Inject a MotionEvent to an unknown display. |
| 716 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 717 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 718 | ui::LogicalDisplayId::INVALID)) |
Prabir Pradhan | c44ce4d | 2021-10-05 05:26:29 -0700 | [diff] [blame] | 719 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 720 | |
| 721 | // Window should receive motion event. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 722 | window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | c44ce4d | 2021-10-05 05:26:29 -0700 | [diff] [blame] | 723 | } |
| 724 | |
Siarhei Vishniakou | fb9fcda | 2020-05-04 14:59:19 -0700 | [diff] [blame] | 725 | /** |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 726 | * Calling onWindowInfosChanged once should not cause any issues. |
| 727 | * This test serves as a sanity check for the next test, where onWindowInfosChanged is |
Siarhei Vishniakou | fb9fcda | 2020-05-04 14:59:19 -0700 | [diff] [blame] | 728 | * called twice. |
| 729 | */ |
Prabir Pradhan | 76bdecb | 2022-01-31 11:14:15 -0800 | [diff] [blame] | 730 | TEST_F(InputDispatcherTest, SetInputWindowOnceWithSingleTouchWindow) { |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 731 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 732 | sp<FakeWindowHandle> window = |
| 733 | sp<FakeWindowHandle>::make(application, mDispatcher, "Fake Window", |
| 734 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | fb9fcda | 2020-05-04 14:59:19 -0700 | [diff] [blame] | 735 | window->setFrame(Rect(0, 0, 100, 100)); |
Siarhei Vishniakou | fb9fcda | 2020-05-04 14:59:19 -0700 | [diff] [blame] | 736 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 737 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 738 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 739 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 740 | ui::LogicalDisplayId::DEFAULT, {50, 50})) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 741 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | fb9fcda | 2020-05-04 14:59:19 -0700 | [diff] [blame] | 742 | |
| 743 | // Window should receive motion event. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 744 | window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | fb9fcda | 2020-05-04 14:59:19 -0700 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | /** |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 748 | * Calling onWindowInfosChanged twice, with the same info, should not cause any issues. |
Siarhei Vishniakou | fb9fcda | 2020-05-04 14:59:19 -0700 | [diff] [blame] | 749 | */ |
| 750 | TEST_F(InputDispatcherTest, SetInputWindowTwice_SingleWindowTouch) { |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 751 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 752 | sp<FakeWindowHandle> window = |
| 753 | sp<FakeWindowHandle>::make(application, mDispatcher, "Fake Window", |
| 754 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | fb9fcda | 2020-05-04 14:59:19 -0700 | [diff] [blame] | 755 | window->setFrame(Rect(0, 0, 100, 100)); |
Siarhei Vishniakou | fb9fcda | 2020-05-04 14:59:19 -0700 | [diff] [blame] | 756 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 757 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
| 758 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 759 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 760 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 761 | ui::LogicalDisplayId::DEFAULT, {50, 50})) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 762 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | fb9fcda | 2020-05-04 14:59:19 -0700 | [diff] [blame] | 763 | |
| 764 | // Window should receive motion event. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 765 | window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | fb9fcda | 2020-05-04 14:59:19 -0700 | [diff] [blame] | 766 | } |
| 767 | |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 768 | // The foreground window should receive the first touch down event. |
| 769 | TEST_F(InputDispatcherTest, SetInputWindow_MultiWindowsTouch) { |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 770 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 771 | sp<FakeWindowHandle> windowTop = sp<FakeWindowHandle>::make(application, mDispatcher, "Top", |
| 772 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 870ecec | 2020-12-09 08:07:46 -1000 | [diff] [blame] | 773 | sp<FakeWindowHandle> windowSecond = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 774 | sp<FakeWindowHandle>::make(application, mDispatcher, "Second", |
| 775 | ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 776 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 777 | mDispatcher->onWindowInfosChanged( |
| 778 | {{*windowTop->getInfo(), *windowSecond->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 779 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 780 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 781 | ui::LogicalDisplayId::DEFAULT)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 782 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 783 | |
| 784 | // Top window should receive the touch down event. Second window should not receive anything. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 785 | windowTop->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 786 | windowSecond->assertNoEvents(); |
| 787 | } |
| 788 | |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 789 | /** |
| 790 | * Two windows: A top window, and a wallpaper behind the window. |
| 791 | * Touch goes to the top window, and then top window disappears. Ensure that wallpaper window |
| 792 | * gets ACTION_CANCEL. |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 793 | * 1. foregroundWindow <-- dup touch to wallpaper |
| 794 | * 2. wallpaperWindow <-- is wallpaper |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 795 | */ |
| 796 | TEST_F(InputDispatcherTest, WhenForegroundWindowDisappears_WallpaperTouchIsCanceled) { |
| 797 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 798 | sp<FakeWindowHandle> foregroundWindow = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 799 | sp<FakeWindowHandle>::make(application, mDispatcher, "Foreground", |
| 800 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 801 | foregroundWindow->setDupTouchToWallpaper(true); |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 802 | sp<FakeWindowHandle> wallpaperWindow = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 803 | sp<FakeWindowHandle>::make(application, mDispatcher, "Wallpaper", |
| 804 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 805 | wallpaperWindow->setIsWallpaper(true); |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 806 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 807 | mDispatcher->onWindowInfosChanged( |
| 808 | {{*foregroundWindow->getInfo(), *wallpaperWindow->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 809 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | d908f5a | 2023-11-16 10:25:12 -0800 | [diff] [blame] | 810 | injectMotionEvent(*mDispatcher, |
| 811 | MotionEventBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 812 | .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(200)) |
| 813 | .build())) |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 814 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 815 | |
| 816 | // Both foreground window and its wallpaper should receive the touch down |
| 817 | foregroundWindow->consumeMotionDown(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 818 | wallpaperWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 819 | |
| 820 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | d908f5a | 2023-11-16 10:25:12 -0800 | [diff] [blame] | 821 | injectMotionEvent(*mDispatcher, |
| 822 | MotionEventBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 823 | .pointer(PointerBuilder(0, ToolType::FINGER).x(110).y(200)) |
| 824 | .build())) |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 825 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 826 | |
Siarhei Vishniakou | d908f5a | 2023-11-16 10:25:12 -0800 | [diff] [blame] | 827 | foregroundWindow->consumeMotionEvent(WithMotionAction(ACTION_MOVE)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 828 | wallpaperWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 829 | |
| 830 | // Now the foreground window goes away, but the wallpaper stays |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 831 | mDispatcher->onWindowInfosChanged({{*wallpaperWindow->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 832 | foregroundWindow->consumeMotionCancel(); |
| 833 | // Since the "parent" window of the wallpaper is gone, wallpaper should receive cancel, too. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 834 | wallpaperWindow->consumeMotionCancel(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | /** |
Siarhei Vishniakou | 82dc042 | 2023-02-17 23:12:52 -0800 | [diff] [blame] | 838 | * Two fingers down on the window, and lift off the first finger. |
| 839 | * Next, cancel the gesture to the window by removing the window. Make sure that the CANCEL event |
| 840 | * contains a single pointer. |
| 841 | */ |
| 842 | TEST_F(InputDispatcherTest, CancelAfterPointer0Up) { |
| 843 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 844 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 845 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 82dc042 | 2023-02-17 23:12:52 -0800 | [diff] [blame] | 846 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 847 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | 82dc042 | 2023-02-17 23:12:52 -0800 | [diff] [blame] | 848 | // First touch pointer down on right window |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 849 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 850 | .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) |
| 851 | .build()); |
Siarhei Vishniakou | 82dc042 | 2023-02-17 23:12:52 -0800 | [diff] [blame] | 852 | // Second touch pointer down |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 853 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 854 | .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) |
| 855 | .pointer(PointerBuilder(1, ToolType::FINGER).x(110).y(100)) |
| 856 | .build()); |
Siarhei Vishniakou | 82dc042 | 2023-02-17 23:12:52 -0800 | [diff] [blame] | 857 | // First touch pointer lifts. The second one remains down |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 858 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_0_UP, AINPUT_SOURCE_TOUCHSCREEN) |
| 859 | .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) |
| 860 | .pointer(PointerBuilder(1, ToolType::FINGER).x(110).y(100)) |
| 861 | .build()); |
Siarhei Vishniakou | 82dc042 | 2023-02-17 23:12:52 -0800 | [diff] [blame] | 862 | window->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); |
| 863 | window->consumeMotionEvent(WithMotionAction(POINTER_1_DOWN)); |
| 864 | window->consumeMotionEvent(WithMotionAction(POINTER_0_UP)); |
| 865 | |
| 866 | // Remove the window. The gesture should be canceled |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 867 | mDispatcher->onWindowInfosChanged({{}, {}, 0, 0}); |
Siarhei Vishniakou | 82dc042 | 2023-02-17 23:12:52 -0800 | [diff] [blame] | 868 | const std::map<int32_t, PointF> expectedPointers{{1, PointF{110, 100}}}; |
| 869 | window->consumeMotionEvent( |
| 870 | AllOf(WithMotionAction(ACTION_CANCEL), WithPointers(expectedPointers))); |
| 871 | } |
| 872 | |
| 873 | /** |
Siarhei Vishniakou | 2b03097 | 2021-11-18 10:01:27 -0800 | [diff] [blame] | 874 | * Same test as WhenForegroundWindowDisappears_WallpaperTouchIsCanceled above, |
| 875 | * with the following differences: |
| 876 | * After ACTION_DOWN, Wallpaper window hangs up its channel, which forces the dispatcher to |
| 877 | * clean up the connection. |
| 878 | * This later may crash dispatcher during ACTION_CANCEL synthesis, if the dispatcher is not careful. |
| 879 | * Ensure that there's no crash in the dispatcher. |
| 880 | */ |
| 881 | TEST_F(InputDispatcherTest, WhenWallpaperDisappears_NoCrash) { |
| 882 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 883 | sp<FakeWindowHandle> foregroundWindow = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 884 | sp<FakeWindowHandle>::make(application, mDispatcher, "Foreground", |
| 885 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 886 | foregroundWindow->setDupTouchToWallpaper(true); |
Siarhei Vishniakou | 2b03097 | 2021-11-18 10:01:27 -0800 | [diff] [blame] | 887 | sp<FakeWindowHandle> wallpaperWindow = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 888 | sp<FakeWindowHandle>::make(application, mDispatcher, "Wallpaper", |
| 889 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 890 | wallpaperWindow->setIsWallpaper(true); |
Siarhei Vishniakou | 2b03097 | 2021-11-18 10:01:27 -0800 | [diff] [blame] | 891 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 892 | mDispatcher->onWindowInfosChanged( |
| 893 | {{*foregroundWindow->getInfo(), *wallpaperWindow->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | 2b03097 | 2021-11-18 10:01:27 -0800 | [diff] [blame] | 894 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 895 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 896 | ui::LogicalDisplayId::DEFAULT, {100, 200})) |
Siarhei Vishniakou | 2b03097 | 2021-11-18 10:01:27 -0800 | [diff] [blame] | 897 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 898 | |
| 899 | // Both foreground window and its wallpaper should receive the touch down |
| 900 | foregroundWindow->consumeMotionDown(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 901 | wallpaperWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); |
Siarhei Vishniakou | 2b03097 | 2021-11-18 10:01:27 -0800 | [diff] [blame] | 902 | |
| 903 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 904 | injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 905 | ui::LogicalDisplayId::DEFAULT, {110, 200})) |
Siarhei Vishniakou | 2b03097 | 2021-11-18 10:01:27 -0800 | [diff] [blame] | 906 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 907 | |
| 908 | foregroundWindow->consumeMotionMove(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 909 | wallpaperWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); |
Siarhei Vishniakou | 2b03097 | 2021-11-18 10:01:27 -0800 | [diff] [blame] | 910 | |
| 911 | // Wallpaper closes its channel, but the window remains. |
| 912 | wallpaperWindow->destroyReceiver(); |
| 913 | mFakePolicy->assertNotifyInputChannelBrokenWasCalled(wallpaperWindow->getInfo()->token); |
| 914 | |
| 915 | // Now the foreground window goes away, but the wallpaper stays, even though its channel |
| 916 | // is no longer valid. |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 917 | mDispatcher->onWindowInfosChanged({{*wallpaperWindow->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | 2b03097 | 2021-11-18 10:01:27 -0800 | [diff] [blame] | 918 | foregroundWindow->consumeMotionCancel(); |
| 919 | } |
| 920 | |
Linnan Li | 7235222 | 2024-04-12 18:55:57 +0800 | [diff] [blame] | 921 | /** |
| 922 | * Two windows: left and right, and a separate wallpaper window underneath each. Device A sends a |
| 923 | * down event to the left window. Device B sends a down event to the right window. Next, the right |
| 924 | * window disappears. Both the right window and its wallpaper window should receive cancel event. |
| 925 | * The left window and its wallpaper window should not receive any events. |
| 926 | */ |
| 927 | TEST_F(InputDispatcherTest, MultiDeviceDisappearingWindowWithWallpaperWindows) { |
| 928 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 929 | sp<FakeWindowHandle> leftForegroundWindow = |
| 930 | sp<FakeWindowHandle>::make(application, mDispatcher, "Left foreground window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 931 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | 7235222 | 2024-04-12 18:55:57 +0800 | [diff] [blame] | 932 | leftForegroundWindow->setFrame(Rect(0, 0, 100, 100)); |
| 933 | leftForegroundWindow->setDupTouchToWallpaper(true); |
| 934 | sp<FakeWindowHandle> leftWallpaperWindow = |
| 935 | sp<FakeWindowHandle>::make(application, mDispatcher, "Left wallpaper window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 936 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | 7235222 | 2024-04-12 18:55:57 +0800 | [diff] [blame] | 937 | leftWallpaperWindow->setFrame(Rect(0, 0, 100, 100)); |
| 938 | leftWallpaperWindow->setIsWallpaper(true); |
| 939 | |
| 940 | sp<FakeWindowHandle> rightForegroundWindow = |
| 941 | sp<FakeWindowHandle>::make(application, mDispatcher, "Right foreground window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 942 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | 7235222 | 2024-04-12 18:55:57 +0800 | [diff] [blame] | 943 | rightForegroundWindow->setFrame(Rect(100, 0, 200, 100)); |
| 944 | rightForegroundWindow->setDupTouchToWallpaper(true); |
| 945 | sp<FakeWindowHandle> rightWallpaperWindow = |
| 946 | sp<FakeWindowHandle>::make(application, mDispatcher, "Right wallpaper window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 947 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | 7235222 | 2024-04-12 18:55:57 +0800 | [diff] [blame] | 948 | rightWallpaperWindow->setFrame(Rect(100, 0, 200, 100)); |
| 949 | rightWallpaperWindow->setIsWallpaper(true); |
| 950 | |
| 951 | mDispatcher->onWindowInfosChanged( |
| 952 | {{*leftForegroundWindow->getInfo(), *leftWallpaperWindow->getInfo(), |
| 953 | *rightForegroundWindow->getInfo(), *rightWallpaperWindow->getInfo()}, |
| 954 | {}, |
| 955 | 0, |
| 956 | 0}); |
| 957 | |
| 958 | const DeviceId deviceA = 9; |
| 959 | const DeviceId deviceB = 3; |
| 960 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 961 | .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) |
| 962 | .deviceId(deviceA) |
| 963 | .build()); |
| 964 | leftForegroundWindow->consumeMotionEvent( |
| 965 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(deviceA))); |
| 966 | leftWallpaperWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), |
| 967 | WithDeviceId(deviceA), |
| 968 | WithFlags(EXPECTED_WALLPAPER_FLAGS))); |
| 969 | |
| 970 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 971 | .pointer(PointerBuilder(0, ToolType::FINGER).x(150).y(50)) |
| 972 | .deviceId(deviceB) |
| 973 | .build()); |
| 974 | rightForegroundWindow->consumeMotionEvent( |
| 975 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(deviceB))); |
| 976 | rightWallpaperWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), |
| 977 | WithDeviceId(deviceB), |
| 978 | WithFlags(EXPECTED_WALLPAPER_FLAGS))); |
| 979 | |
| 980 | // Now right foreground window disappears, but right wallpaper window remains. |
| 981 | mDispatcher->onWindowInfosChanged( |
| 982 | {{*leftForegroundWindow->getInfo(), *leftWallpaperWindow->getInfo(), |
| 983 | *rightWallpaperWindow->getInfo()}, |
| 984 | {}, |
| 985 | 0, |
| 986 | 0}); |
| 987 | |
| 988 | // Left foreground window and left wallpaper window still exist, and should not receive any |
| 989 | // events. |
| 990 | leftForegroundWindow->assertNoEvents(); |
| 991 | leftWallpaperWindow->assertNoEvents(); |
| 992 | // Since right foreground window disappeared, right wallpaper window and right foreground window |
| 993 | // should receive cancel events. |
| 994 | rightForegroundWindow->consumeMotionEvent( |
| 995 | AllOf(WithMotionAction(ACTION_CANCEL), WithDeviceId(deviceB))); |
| 996 | rightWallpaperWindow->consumeMotionEvent( |
| 997 | AllOf(WithMotionAction(ACTION_CANCEL), WithDeviceId(deviceB), |
| 998 | WithFlags(EXPECTED_WALLPAPER_FLAGS | AMOTION_EVENT_FLAG_CANCELED))); |
| 999 | } |
| 1000 | |
| 1001 | /** |
| 1002 | * Three windows arranged horizontally and without any overlap. Every window has a |
| 1003 | * wallpaper window underneath. The middle window also has SLIPPERY flag. |
| 1004 | * Device A sends a down event to the left window. Device B sends a down event to the middle window. |
| 1005 | * Next, device B sends move event to the right window. Touch for device B should slip from the |
| 1006 | * middle window to the right window. Also, the right wallpaper window should receive a down event. |
| 1007 | * The middle window and its wallpaper window should receive a cancel event. The left window should |
| 1008 | * not receive any events. If device B continues to report events, the right window and its |
| 1009 | * wallpaper window should receive remaining events. |
| 1010 | */ |
| 1011 | TEST_F(InputDispatcherTest, MultiDeviceSlipperyTouchWithWallpaperWindow) { |
| 1012 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 1013 | sp<FakeWindowHandle> leftForegroundWindow = |
| 1014 | sp<FakeWindowHandle>::make(application, mDispatcher, "Left foreground window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1015 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | 7235222 | 2024-04-12 18:55:57 +0800 | [diff] [blame] | 1016 | leftForegroundWindow->setFrame(Rect(0, 0, 100, 100)); |
| 1017 | leftForegroundWindow->setDupTouchToWallpaper(true); |
| 1018 | sp<FakeWindowHandle> leftWallpaperWindow = |
| 1019 | sp<FakeWindowHandle>::make(application, mDispatcher, "Left wallpaper window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1020 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | 7235222 | 2024-04-12 18:55:57 +0800 | [diff] [blame] | 1021 | leftWallpaperWindow->setFrame(Rect(0, 0, 100, 100)); |
| 1022 | leftWallpaperWindow->setIsWallpaper(true); |
| 1023 | |
| 1024 | sp<FakeWindowHandle> middleForegroundWindow = |
| 1025 | sp<FakeWindowHandle>::make(application, mDispatcher, "Middle foreground window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1026 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | 7235222 | 2024-04-12 18:55:57 +0800 | [diff] [blame] | 1027 | middleForegroundWindow->setFrame(Rect(100, 0, 200, 100)); |
| 1028 | middleForegroundWindow->setDupTouchToWallpaper(true); |
| 1029 | middleForegroundWindow->setSlippery(true); |
| 1030 | sp<FakeWindowHandle> middleWallpaperWindow = |
| 1031 | sp<FakeWindowHandle>::make(application, mDispatcher, "Middle wallpaper window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1032 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | 7235222 | 2024-04-12 18:55:57 +0800 | [diff] [blame] | 1033 | middleWallpaperWindow->setFrame(Rect(100, 0, 200, 100)); |
| 1034 | middleWallpaperWindow->setIsWallpaper(true); |
| 1035 | |
| 1036 | sp<FakeWindowHandle> rightForegroundWindow = |
| 1037 | sp<FakeWindowHandle>::make(application, mDispatcher, "Right foreground window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1038 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | 7235222 | 2024-04-12 18:55:57 +0800 | [diff] [blame] | 1039 | rightForegroundWindow->setFrame(Rect(200, 0, 300, 100)); |
| 1040 | rightForegroundWindow->setDupTouchToWallpaper(true); |
| 1041 | sp<FakeWindowHandle> rightWallpaperWindow = |
| 1042 | sp<FakeWindowHandle>::make(application, mDispatcher, "Right wallpaper window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1043 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | 7235222 | 2024-04-12 18:55:57 +0800 | [diff] [blame] | 1044 | rightWallpaperWindow->setFrame(Rect(200, 0, 300, 100)); |
| 1045 | rightWallpaperWindow->setIsWallpaper(true); |
| 1046 | |
| 1047 | mDispatcher->onWindowInfosChanged( |
| 1048 | {{*leftForegroundWindow->getInfo(), *leftWallpaperWindow->getInfo(), |
| 1049 | *middleForegroundWindow->getInfo(), *middleWallpaperWindow->getInfo(), |
| 1050 | *rightForegroundWindow->getInfo(), *rightWallpaperWindow->getInfo()}, |
| 1051 | {}, |
| 1052 | 0, |
| 1053 | 0}); |
| 1054 | |
| 1055 | const DeviceId deviceA = 9; |
| 1056 | const DeviceId deviceB = 3; |
| 1057 | // Device A sends a DOWN event to the left window |
| 1058 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 1059 | .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) |
| 1060 | .deviceId(deviceA) |
| 1061 | .build()); |
| 1062 | leftForegroundWindow->consumeMotionEvent( |
| 1063 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(deviceA))); |
| 1064 | leftWallpaperWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), |
| 1065 | WithDeviceId(deviceA), |
| 1066 | WithFlags(EXPECTED_WALLPAPER_FLAGS))); |
| 1067 | // Device B sends a DOWN event to the middle window |
| 1068 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 1069 | .pointer(PointerBuilder(0, ToolType::FINGER).x(150).y(50)) |
| 1070 | .deviceId(deviceB) |
| 1071 | .build()); |
| 1072 | middleForegroundWindow->consumeMotionEvent( |
| 1073 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(deviceB))); |
| 1074 | middleWallpaperWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), |
| 1075 | WithDeviceId(deviceB), |
| 1076 | WithFlags(EXPECTED_WALLPAPER_FLAGS))); |
| 1077 | // Move the events of device B to the top of the right window. |
| 1078 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 1079 | .pointer(PointerBuilder(0, ToolType::FINGER).x(250).y(50)) |
| 1080 | .deviceId(deviceB) |
| 1081 | .build()); |
| 1082 | middleForegroundWindow->consumeMotionEvent( |
| 1083 | AllOf(WithMotionAction(ACTION_CANCEL), WithDeviceId(deviceB))); |
| 1084 | middleWallpaperWindow->consumeMotionEvent( |
| 1085 | AllOf(WithMotionAction(ACTION_CANCEL), WithDeviceId(deviceB), |
| 1086 | WithFlags(EXPECTED_WALLPAPER_FLAGS | AMOTION_EVENT_FLAG_CANCELED))); |
| 1087 | rightForegroundWindow->consumeMotionEvent( |
| 1088 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(deviceB))); |
| 1089 | rightWallpaperWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), |
| 1090 | WithDeviceId(deviceB), |
| 1091 | WithFlags(EXPECTED_WALLPAPER_FLAGS))); |
| 1092 | // Make sure the window on the right can receive the remaining events. |
| 1093 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 1094 | .pointer(PointerBuilder(0, ToolType::FINGER).x(251).y(51)) |
| 1095 | .deviceId(deviceB) |
| 1096 | .build()); |
| 1097 | leftForegroundWindow->assertNoEvents(); |
| 1098 | leftWallpaperWindow->assertNoEvents(); |
| 1099 | middleForegroundWindow->assertNoEvents(); |
| 1100 | middleWallpaperWindow->assertNoEvents(); |
| 1101 | rightForegroundWindow->consumeMotionEvent( |
| 1102 | AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(deviceB))); |
| 1103 | rightWallpaperWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), |
| 1104 | WithDeviceId(deviceB), |
| 1105 | WithFlags(EXPECTED_WALLPAPER_FLAGS))); |
| 1106 | } |
| 1107 | |
| 1108 | /** |
| 1109 | * Similar to the test above, we have three windows, they are arranged horizontally and without any |
| 1110 | * overlap, and every window has a wallpaper window. The middle window is a simple window, without |
| 1111 | * any special flags. Device A reports a down event that lands in left window. Device B sends a down |
| 1112 | * event to the middle window and then touch is transferred from the middle window to the right |
| 1113 | * window. The right window and its wallpaper window should receive a down event. The middle window |
| 1114 | * and its wallpaper window should receive a cancel event. The left window should not receive any |
| 1115 | * events. Subsequent events reported by device B should go to the right window and its wallpaper. |
| 1116 | */ |
| 1117 | TEST_F(InputDispatcherTest, MultiDeviceTouchTransferWithWallpaperWindows) { |
| 1118 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 1119 | sp<FakeWindowHandle> leftForegroundWindow = |
| 1120 | sp<FakeWindowHandle>::make(application, mDispatcher, "Left foreground window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1121 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | 7235222 | 2024-04-12 18:55:57 +0800 | [diff] [blame] | 1122 | leftForegroundWindow->setFrame(Rect(0, 0, 100, 100)); |
| 1123 | leftForegroundWindow->setDupTouchToWallpaper(true); |
| 1124 | sp<FakeWindowHandle> leftWallpaperWindow = |
| 1125 | sp<FakeWindowHandle>::make(application, mDispatcher, "Left wallpaper window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1126 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | 7235222 | 2024-04-12 18:55:57 +0800 | [diff] [blame] | 1127 | leftWallpaperWindow->setFrame(Rect(0, 0, 100, 100)); |
| 1128 | leftWallpaperWindow->setIsWallpaper(true); |
| 1129 | |
| 1130 | sp<FakeWindowHandle> middleForegroundWindow = |
| 1131 | sp<FakeWindowHandle>::make(application, mDispatcher, "Middle foreground window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1132 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | 7235222 | 2024-04-12 18:55:57 +0800 | [diff] [blame] | 1133 | middleForegroundWindow->setFrame(Rect(100, 0, 200, 100)); |
| 1134 | middleForegroundWindow->setDupTouchToWallpaper(true); |
| 1135 | sp<FakeWindowHandle> middleWallpaperWindow = |
| 1136 | sp<FakeWindowHandle>::make(application, mDispatcher, "Middle wallpaper window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1137 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | 7235222 | 2024-04-12 18:55:57 +0800 | [diff] [blame] | 1138 | middleWallpaperWindow->setFrame(Rect(100, 0, 200, 100)); |
| 1139 | middleWallpaperWindow->setIsWallpaper(true); |
| 1140 | |
| 1141 | sp<FakeWindowHandle> rightForegroundWindow = |
| 1142 | sp<FakeWindowHandle>::make(application, mDispatcher, "Right foreground window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1143 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | 7235222 | 2024-04-12 18:55:57 +0800 | [diff] [blame] | 1144 | rightForegroundWindow->setFrame(Rect(200, 0, 300, 100)); |
| 1145 | rightForegroundWindow->setDupTouchToWallpaper(true); |
| 1146 | sp<FakeWindowHandle> rightWallpaperWindow = |
| 1147 | sp<FakeWindowHandle>::make(application, mDispatcher, "Right wallpaper window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1148 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | 7235222 | 2024-04-12 18:55:57 +0800 | [diff] [blame] | 1149 | rightWallpaperWindow->setFrame(Rect(200, 0, 300, 100)); |
| 1150 | rightWallpaperWindow->setIsWallpaper(true); |
| 1151 | |
| 1152 | mDispatcher->onWindowInfosChanged( |
| 1153 | {{*leftForegroundWindow->getInfo(), *leftWallpaperWindow->getInfo(), |
| 1154 | *middleForegroundWindow->getInfo(), *middleWallpaperWindow->getInfo(), |
| 1155 | *rightForegroundWindow->getInfo(), *rightWallpaperWindow->getInfo()}, |
| 1156 | {}, |
| 1157 | 0, |
| 1158 | 0}); |
| 1159 | |
| 1160 | const DeviceId deviceA = 9; |
| 1161 | const DeviceId deviceB = 3; |
| 1162 | // Device A touch down on the left window |
| 1163 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 1164 | .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) |
| 1165 | .deviceId(deviceA) |
| 1166 | .build()); |
| 1167 | leftForegroundWindow->consumeMotionEvent( |
| 1168 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(deviceA))); |
| 1169 | leftWallpaperWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), |
| 1170 | WithDeviceId(deviceA), |
| 1171 | WithFlags(EXPECTED_WALLPAPER_FLAGS))); |
| 1172 | // Device B touch down on the middle window |
| 1173 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 1174 | .pointer(PointerBuilder(0, ToolType::FINGER).x(150).y(50)) |
| 1175 | .deviceId(deviceB) |
| 1176 | .build()); |
| 1177 | middleForegroundWindow->consumeMotionEvent( |
| 1178 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(deviceB))); |
| 1179 | middleWallpaperWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), |
| 1180 | WithDeviceId(deviceB), |
| 1181 | WithFlags(EXPECTED_WALLPAPER_FLAGS))); |
| 1182 | |
| 1183 | // Transfer touch from the middle window to the right window. |
| 1184 | ASSERT_TRUE(mDispatcher->transferTouchGesture(middleForegroundWindow->getToken(), |
| 1185 | rightForegroundWindow->getToken())); |
| 1186 | |
| 1187 | middleForegroundWindow->consumeMotionEvent( |
| 1188 | AllOf(WithMotionAction(ACTION_CANCEL), WithDeviceId(deviceB))); |
| 1189 | middleWallpaperWindow->consumeMotionEvent( |
| 1190 | AllOf(WithMotionAction(ACTION_CANCEL), WithDeviceId(deviceB), |
| 1191 | WithFlags(EXPECTED_WALLPAPER_FLAGS | AMOTION_EVENT_FLAG_CANCELED))); |
| 1192 | rightForegroundWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), |
| 1193 | WithDeviceId(deviceB), |
| 1194 | WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))); |
| 1195 | rightWallpaperWindow->consumeMotionEvent( |
| 1196 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(deviceB), |
| 1197 | WithFlags(EXPECTED_WALLPAPER_FLAGS | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))); |
| 1198 | |
| 1199 | // Make sure the right window can receive the remaining events. |
| 1200 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 1201 | .pointer(PointerBuilder(0, ToolType::FINGER).x(251).y(51)) |
| 1202 | .deviceId(deviceB) |
| 1203 | .build()); |
| 1204 | leftForegroundWindow->assertNoEvents(); |
| 1205 | leftWallpaperWindow->assertNoEvents(); |
| 1206 | middleForegroundWindow->assertNoEvents(); |
| 1207 | middleWallpaperWindow->assertNoEvents(); |
| 1208 | rightForegroundWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), |
| 1209 | WithDeviceId(deviceB), |
| 1210 | WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))); |
| 1211 | rightWallpaperWindow->consumeMotionEvent( |
| 1212 | AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(deviceB), |
| 1213 | WithFlags(EXPECTED_WALLPAPER_FLAGS | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))); |
| 1214 | } |
| 1215 | |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 1216 | class ShouldSplitTouchFixture : public InputDispatcherTest, |
| 1217 | public ::testing::WithParamInterface<bool> {}; |
| 1218 | INSTANTIATE_TEST_SUITE_P(InputDispatcherTest, ShouldSplitTouchFixture, |
| 1219 | ::testing::Values(true, false)); |
Siarhei Vishniakou | 2b03097 | 2021-11-18 10:01:27 -0800 | [diff] [blame] | 1220 | /** |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 1221 | * A single window that receives touch (on top), and a wallpaper window underneath it. |
| 1222 | * The top window gets a multitouch gesture. |
| 1223 | * Ensure that wallpaper gets the same gesture. |
| 1224 | */ |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 1225 | TEST_P(ShouldSplitTouchFixture, WallpaperWindowReceivesMultiTouch) { |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 1226 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 1227 | sp<FakeWindowHandle> foregroundWindow = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1228 | sp<FakeWindowHandle>::make(application, mDispatcher, "Foreground", |
| 1229 | ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 1230 | foregroundWindow->setDupTouchToWallpaper(true); |
| 1231 | foregroundWindow->setPreventSplitting(GetParam()); |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 1232 | |
| 1233 | sp<FakeWindowHandle> wallpaperWindow = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1234 | sp<FakeWindowHandle>::make(application, mDispatcher, "Wallpaper", |
| 1235 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 1236 | wallpaperWindow->setIsWallpaper(true); |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 1237 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 1238 | mDispatcher->onWindowInfosChanged( |
| 1239 | {{*foregroundWindow->getInfo(), *wallpaperWindow->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 1240 | |
| 1241 | // Touch down on top window |
| 1242 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1243 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 1244 | ui::LogicalDisplayId::DEFAULT, {100, 100})) |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 1245 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 1246 | |
| 1247 | // Both top window and its wallpaper should receive the touch down |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 1248 | foregroundWindow->consumeMotionDown(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1249 | wallpaperWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 1250 | |
| 1251 | // Second finger down on the top window |
| 1252 | const MotionEvent secondFingerDownEvent = |
Siarhei Vishniakou | a16e3a2 | 2022-03-02 15:26:40 -0800 | [diff] [blame] | 1253 | MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 1254 | .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 1255 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(100)) |
| 1256 | .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(150).y(150)) |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 1257 | .build(); |
| 1258 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 1259 | injectMotionEvent(*mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 1260 | InputEventInjectionSync::WAIT_FOR_RESULT)) |
| 1261 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 1262 | foregroundWindow->consumeMotionPointerDown(/*pointerIndex=*/1); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1263 | wallpaperWindow->consumeMotionPointerDown(/*pointerIndex=*/1, ui::LogicalDisplayId::DEFAULT, |
Linnan Li | 7235222 | 2024-04-12 18:55:57 +0800 | [diff] [blame] | 1264 | EXPECTED_WALLPAPER_FLAGS); |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 1265 | |
| 1266 | const MotionEvent secondFingerUpEvent = |
| 1267 | MotionEventBuilder(POINTER_0_UP, AINPUT_SOURCE_TOUCHSCREEN) |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1268 | .displayId(ui::LogicalDisplayId::DEFAULT) |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 1269 | .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 1270 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(100)) |
| 1271 | .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(150).y(150)) |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 1272 | .build(); |
| 1273 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 1274 | injectMotionEvent(*mDispatcher, secondFingerUpEvent, INJECT_EVENT_TIMEOUT, |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 1275 | InputEventInjectionSync::WAIT_FOR_RESULT)) |
| 1276 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Prabir Pradhan | 33cfc6d | 2024-06-11 20:17:44 +0000 | [diff] [blame] | 1277 | foregroundWindow->consumeMotionPointerUp(/*pointerIdx=*/0, |
| 1278 | WithDisplayId(ui::LogicalDisplayId::DEFAULT)); |
| 1279 | wallpaperWindow->consumeMotionPointerUp(/*pointerIdx=*/0, |
| 1280 | AllOf(WithDisplayId(ui::LogicalDisplayId::DEFAULT), |
| 1281 | WithFlags(EXPECTED_WALLPAPER_FLAGS))); |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 1282 | |
| 1283 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 1284 | injectMotionEvent(*mDispatcher, |
Siarhei Vishniakou | 92c8fd5 | 2023-01-29 14:57:43 -0800 | [diff] [blame] | 1285 | MotionEventBuilder(AMOTION_EVENT_ACTION_UP, |
| 1286 | AINPUT_SOURCE_TOUCHSCREEN) |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1287 | .displayId(ui::LogicalDisplayId::DEFAULT) |
Siarhei Vishniakou | 92c8fd5 | 2023-01-29 14:57:43 -0800 | [diff] [blame] | 1288 | .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) |
Harry Cutts | 101ee9b | 2023-07-06 18:04:14 +0000 | [diff] [blame] | 1289 | .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER) |
Siarhei Vishniakou | 92c8fd5 | 2023-01-29 14:57:43 -0800 | [diff] [blame] | 1290 | .x(100) |
| 1291 | .y(100)) |
| 1292 | .build(), |
| 1293 | INJECT_EVENT_TIMEOUT, InputEventInjectionSync::WAIT_FOR_RESULT)) |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 1294 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1295 | foregroundWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT); |
| 1296 | wallpaperWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 1297 | } |
| 1298 | |
| 1299 | /** |
| 1300 | * Two windows: a window on the left and window on the right. |
| 1301 | * A third window, wallpaper, is behind both windows, and spans both top windows. |
| 1302 | * The first touch down goes to the left window. A second pointer touches down on the right window. |
| 1303 | * The touch is split, so both left and right windows should receive ACTION_DOWN. |
| 1304 | * The wallpaper will get the full event, so it should receive ACTION_DOWN followed by |
| 1305 | * ACTION_POINTER_DOWN(1). |
| 1306 | */ |
| 1307 | TEST_F(InputDispatcherTest, TwoWindows_SplitWallpaperTouch) { |
| 1308 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1309 | sp<FakeWindowHandle> leftWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Left", |
| 1310 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 1311 | leftWindow->setFrame(Rect(0, 0, 200, 200)); |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 1312 | leftWindow->setDupTouchToWallpaper(true); |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 1313 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1314 | sp<FakeWindowHandle> rightWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Right", |
| 1315 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 1316 | rightWindow->setFrame(Rect(200, 0, 400, 200)); |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 1317 | rightWindow->setDupTouchToWallpaper(true); |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 1318 | |
| 1319 | sp<FakeWindowHandle> wallpaperWindow = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1320 | sp<FakeWindowHandle>::make(application, mDispatcher, "Wallpaper", |
| 1321 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 1322 | wallpaperWindow->setFrame(Rect(0, 0, 400, 200)); |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 1323 | wallpaperWindow->setIsWallpaper(true); |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 1324 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 1325 | mDispatcher->onWindowInfosChanged( |
| 1326 | {{*leftWindow->getInfo(), *rightWindow->getInfo(), *wallpaperWindow->getInfo()}, |
| 1327 | {}, |
| 1328 | 0, |
| 1329 | 0}); |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 1330 | |
| 1331 | // Touch down on left window |
| 1332 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1333 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 1334 | ui::LogicalDisplayId::DEFAULT, {100, 100})) |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 1335 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 1336 | |
| 1337 | // Both foreground window and its wallpaper should receive the touch down |
| 1338 | leftWindow->consumeMotionDown(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1339 | wallpaperWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 1340 | |
| 1341 | // Second finger down on the right window |
| 1342 | const MotionEvent secondFingerDownEvent = |
Siarhei Vishniakou | a16e3a2 | 2022-03-02 15:26:40 -0800 | [diff] [blame] | 1343 | MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 1344 | .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 1345 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(100)) |
| 1346 | .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(300).y(100)) |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 1347 | .build(); |
| 1348 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 1349 | injectMotionEvent(*mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 1350 | InputEventInjectionSync::WAIT_FOR_RESULT)) |
| 1351 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 1352 | |
| 1353 | leftWindow->consumeMotionMove(); |
| 1354 | // Since the touch is split, right window gets ACTION_DOWN |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1355 | rightWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
| 1356 | wallpaperWindow->consumeMotionPointerDown(/*pointerIndex=*/1, ui::LogicalDisplayId::DEFAULT, |
Linnan Li | 7235222 | 2024-04-12 18:55:57 +0800 | [diff] [blame] | 1357 | EXPECTED_WALLPAPER_FLAGS); |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 1358 | |
| 1359 | // Now, leftWindow, which received the first finger, disappears. |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 1360 | mDispatcher->onWindowInfosChanged( |
| 1361 | {{*rightWindow->getInfo(), *wallpaperWindow->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 1362 | leftWindow->consumeMotionCancel(); |
| 1363 | // Since a "parent" window of the wallpaper is gone, wallpaper should receive cancel, too. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1364 | wallpaperWindow->consumeMotionCancel(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 1365 | |
| 1366 | // The pointer that's still down on the right window moves, and goes to the right window only. |
| 1367 | // As far as the dispatcher's concerned though, both pointers are still present. |
| 1368 | const MotionEvent secondFingerMoveEvent = |
| 1369 | MotionEventBuilder(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 1370 | .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 1371 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(100)) |
| 1372 | .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(310).y(110)) |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 1373 | .build(); |
| 1374 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 1375 | injectMotionEvent(*mDispatcher, secondFingerMoveEvent, INJECT_EVENT_TIMEOUT, |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 1376 | InputEventInjectionSync::WAIT_FOR_RESULT)); |
| 1377 | rightWindow->consumeMotionMove(); |
| 1378 | |
| 1379 | leftWindow->assertNoEvents(); |
| 1380 | rightWindow->assertNoEvents(); |
| 1381 | wallpaperWindow->assertNoEvents(); |
| 1382 | } |
| 1383 | |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 1384 | /** |
| 1385 | * Two windows: a window on the left with dup touch to wallpaper and window on the right without it. |
| 1386 | * The touch slips to the right window. so left window and wallpaper should receive ACTION_CANCEL |
| 1387 | * The right window should receive ACTION_DOWN. |
| 1388 | */ |
| 1389 | TEST_F(InputDispatcherTest, WallpaperWindowWhenSlippery) { |
Arthur Hung | 74c248d | 2022-11-23 07:09:59 +0000 | [diff] [blame] | 1390 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1391 | sp<FakeWindowHandle> leftWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Left", |
| 1392 | ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 1393 | leftWindow->setFrame(Rect(0, 0, 200, 200)); |
| 1394 | leftWindow->setDupTouchToWallpaper(true); |
| 1395 | leftWindow->setSlippery(true); |
| 1396 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1397 | sp<FakeWindowHandle> rightWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Right", |
| 1398 | ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 1399 | rightWindow->setFrame(Rect(200, 0, 400, 200)); |
Arthur Hung | 74c248d | 2022-11-23 07:09:59 +0000 | [diff] [blame] | 1400 | |
| 1401 | sp<FakeWindowHandle> wallpaperWindow = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1402 | sp<FakeWindowHandle>::make(application, mDispatcher, "Wallpaper", |
| 1403 | ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | 74c248d | 2022-11-23 07:09:59 +0000 | [diff] [blame] | 1404 | wallpaperWindow->setIsWallpaper(true); |
Arthur Hung | 74c248d | 2022-11-23 07:09:59 +0000 | [diff] [blame] | 1405 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 1406 | mDispatcher->onWindowInfosChanged( |
| 1407 | {{*leftWindow->getInfo(), *rightWindow->getInfo(), *wallpaperWindow->getInfo()}, |
| 1408 | {}, |
| 1409 | 0, |
| 1410 | 0}); |
Arthur Hung | 74c248d | 2022-11-23 07:09:59 +0000 | [diff] [blame] | 1411 | |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 1412 | // Touch down on left window |
Arthur Hung | 74c248d | 2022-11-23 07:09:59 +0000 | [diff] [blame] | 1413 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1414 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 1415 | ui::LogicalDisplayId::DEFAULT, {100, 100})) |
Arthur Hung | 74c248d | 2022-11-23 07:09:59 +0000 | [diff] [blame] | 1416 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 1417 | |
| 1418 | // Both foreground window and its wallpaper should receive the touch down |
| 1419 | leftWindow->consumeMotionDown(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1420 | wallpaperWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); |
Arthur Hung | 74c248d | 2022-11-23 07:09:59 +0000 | [diff] [blame] | 1421 | |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 1422 | // Move to right window, the left window should receive cancel. |
Arthur Hung | 74c248d | 2022-11-23 07:09:59 +0000 | [diff] [blame] | 1423 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 1424 | injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1425 | ui::LogicalDisplayId::DEFAULT, {201, 100})) |
Arthur Hung | 74c248d | 2022-11-23 07:09:59 +0000 | [diff] [blame] | 1426 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 1427 | |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 1428 | leftWindow->consumeMotionCancel(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1429 | rightWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
| 1430 | wallpaperWindow->consumeMotionCancel(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); |
Arthur Hung | 74c248d | 2022-11-23 07:09:59 +0000 | [diff] [blame] | 1431 | } |
| 1432 | |
Siarhei Vishniakou | a16e3a2 | 2022-03-02 15:26:40 -0800 | [diff] [blame] | 1433 | /** |
Siarhei Vishniakou | 5bf25d9 | 2023-02-08 15:43:38 -0800 | [diff] [blame] | 1434 | * The policy typically sets POLICY_FLAG_PASS_TO_USER to the events. But when the display is not |
| 1435 | * interactive, it might stop sending this flag. |
| 1436 | * In this test, we check that if the policy stops sending this flag mid-gesture, we still ensure |
| 1437 | * to have a consistent input stream. |
| 1438 | * |
| 1439 | * Test procedure: |
| 1440 | * DOWN -> POINTER_DOWN -> (stop sending POLICY_FLAG_PASS_TO_USER) -> CANCEL. |
| 1441 | * DOWN (new gesture). |
| 1442 | * |
| 1443 | * In the bad implementation, we could potentially drop the CANCEL event, and get an inconsistent |
| 1444 | * state in the dispatcher. This would cause the final DOWN event to not be delivered to the app. |
| 1445 | * |
| 1446 | * We technically just need a single window here, but we are using two windows (spy on top and a |
| 1447 | * regular window below) to emulate the actual situation where it happens on the device. |
| 1448 | */ |
| 1449 | TEST_F(InputDispatcherTest, TwoPointerCancelInconsistentPolicy) { |
| 1450 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1451 | sp<FakeWindowHandle> spyWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Spy", |
| 1452 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 5bf25d9 | 2023-02-08 15:43:38 -0800 | [diff] [blame] | 1453 | spyWindow->setFrame(Rect(0, 0, 200, 200)); |
| 1454 | spyWindow->setTrustedOverlay(true); |
| 1455 | spyWindow->setSpy(true); |
| 1456 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1457 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 1458 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 5bf25d9 | 2023-02-08 15:43:38 -0800 | [diff] [blame] | 1459 | window->setFrame(Rect(0, 0, 200, 200)); |
| 1460 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 1461 | mDispatcher->onWindowInfosChanged({{*spyWindow->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | 5bf25d9 | 2023-02-08 15:43:38 -0800 | [diff] [blame] | 1462 | const int32_t touchDeviceId = 4; |
Siarhei Vishniakou | 5bf25d9 | 2023-02-08 15:43:38 -0800 | [diff] [blame] | 1463 | |
| 1464 | // Two pointers down |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 1465 | mDispatcher->notifyMotion( |
| 1466 | MotionArgsBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 1467 | .deviceId(touchDeviceId) |
| 1468 | .policyFlags(DEFAULT_POLICY_FLAGS) |
| 1469 | .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) |
| 1470 | .build()); |
Siarhei Vishniakou | 5bf25d9 | 2023-02-08 15:43:38 -0800 | [diff] [blame] | 1471 | |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 1472 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 1473 | .deviceId(touchDeviceId) |
| 1474 | .policyFlags(DEFAULT_POLICY_FLAGS) |
| 1475 | .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) |
| 1476 | .pointer(PointerBuilder(1, ToolType::FINGER).x(120).y(120)) |
| 1477 | .build()); |
Siarhei Vishniakou | 5bf25d9 | 2023-02-08 15:43:38 -0800 | [diff] [blame] | 1478 | spyWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_DOWN)); |
| 1479 | spyWindow->consumeMotionEvent(WithMotionAction(POINTER_1_DOWN)); |
| 1480 | window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_DOWN)); |
| 1481 | window->consumeMotionEvent(WithMotionAction(POINTER_1_DOWN)); |
| 1482 | |
| 1483 | // Cancel the current gesture. Send the cancel without the default policy flags. |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 1484 | mDispatcher->notifyMotion( |
| 1485 | MotionArgsBuilder(AMOTION_EVENT_ACTION_CANCEL, AINPUT_SOURCE_TOUCHSCREEN) |
| 1486 | .deviceId(touchDeviceId) |
| 1487 | .policyFlags(0) |
| 1488 | .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) |
| 1489 | .pointer(PointerBuilder(1, ToolType::FINGER).x(120).y(120)) |
| 1490 | .build()); |
Siarhei Vishniakou | 5bf25d9 | 2023-02-08 15:43:38 -0800 | [diff] [blame] | 1491 | spyWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_CANCEL)); |
| 1492 | window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_CANCEL)); |
| 1493 | |
| 1494 | // We don't need to reset the device to reproduce the issue, but the reset event typically |
| 1495 | // follows, so we keep it here to model the actual listener behaviour more closely. |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 1496 | mDispatcher->notifyDeviceReset({/*id=*/1, systemTime(SYSTEM_TIME_MONOTONIC), touchDeviceId}); |
Siarhei Vishniakou | 5bf25d9 | 2023-02-08 15:43:38 -0800 | [diff] [blame] | 1497 | |
| 1498 | // Start new gesture |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 1499 | mDispatcher->notifyMotion( |
| 1500 | MotionArgsBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 1501 | .deviceId(touchDeviceId) |
| 1502 | .policyFlags(DEFAULT_POLICY_FLAGS) |
| 1503 | .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) |
| 1504 | .build()); |
Siarhei Vishniakou | 5bf25d9 | 2023-02-08 15:43:38 -0800 | [diff] [blame] | 1505 | spyWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_DOWN)); |
| 1506 | window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_DOWN)); |
| 1507 | |
| 1508 | // No more events |
| 1509 | spyWindow->assertNoEvents(); |
| 1510 | window->assertNoEvents(); |
| 1511 | } |
| 1512 | |
| 1513 | /** |
Linnan Li | 907ae73 | 2023-09-05 17:14:21 +0800 | [diff] [blame] | 1514 | * Same as the above 'TwoPointerCancelInconsistentPolicy' test, but for hovers. |
| 1515 | * The policy typically sets POLICY_FLAG_PASS_TO_USER to the events. But when the display is not |
| 1516 | * interactive, it might stop sending this flag. |
| 1517 | * We've already ensured the consistency of the touch event in this case, and we should also ensure |
| 1518 | * the consistency of the hover event in this case. |
| 1519 | * |
| 1520 | * Test procedure: |
| 1521 | * HOVER_ENTER -> HOVER_MOVE -> (stop sending POLICY_FLAG_PASS_TO_USER) -> HOVER_EXIT |
| 1522 | * HOVER_ENTER -> HOVER_MOVE -> HOVER_EXIT |
| 1523 | * |
| 1524 | * We expect to receive two full streams of hover events. |
| 1525 | */ |
| 1526 | TEST_F(InputDispatcherTest, HoverEventInconsistentPolicy) { |
| 1527 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 1528 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1529 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 1530 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | 907ae73 | 2023-09-05 17:14:21 +0800 | [diff] [blame] | 1531 | window->setFrame(Rect(0, 0, 300, 300)); |
| 1532 | |
| 1533 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
| 1534 | |
| 1535 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS) |
| 1536 | .policyFlags(DEFAULT_POLICY_FLAGS) |
| 1537 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(100).y(101)) |
| 1538 | .build()); |
| 1539 | window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); |
| 1540 | |
| 1541 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_MOVE, AINPUT_SOURCE_STYLUS) |
| 1542 | .policyFlags(DEFAULT_POLICY_FLAGS) |
| 1543 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(101).y(102)) |
| 1544 | .build()); |
| 1545 | window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_MOVE)); |
| 1546 | |
| 1547 | // Send hover exit without the default policy flags. |
| 1548 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_EXIT, AINPUT_SOURCE_STYLUS) |
| 1549 | .policyFlags(0) |
| 1550 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(101).y(102)) |
| 1551 | .build()); |
| 1552 | |
| 1553 | window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); |
| 1554 | |
| 1555 | // Send a simple hover event stream, ensure dispatcher not crashed and window can receive |
| 1556 | // right event. |
| 1557 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS) |
| 1558 | .policyFlags(DEFAULT_POLICY_FLAGS) |
| 1559 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(200).y(201)) |
| 1560 | .build()); |
| 1561 | window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); |
| 1562 | |
| 1563 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_MOVE, AINPUT_SOURCE_STYLUS) |
| 1564 | .policyFlags(DEFAULT_POLICY_FLAGS) |
| 1565 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(201).y(202)) |
| 1566 | .build()); |
| 1567 | window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_MOVE)); |
| 1568 | |
| 1569 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_EXIT, AINPUT_SOURCE_STYLUS) |
| 1570 | .policyFlags(DEFAULT_POLICY_FLAGS) |
| 1571 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(201).y(202)) |
| 1572 | .build()); |
| 1573 | window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); |
| 1574 | } |
| 1575 | |
| 1576 | /** |
Siarhei Vishniakou | e0431e4 | 2023-01-28 17:01:39 -0800 | [diff] [blame] | 1577 | * Two windows: a window on the left and a window on the right. |
| 1578 | * Mouse is hovered from the right window into the left window. |
| 1579 | * Next, we tap on the left window, where the cursor was last seen. |
| 1580 | * The second tap is done onto the right window. |
| 1581 | * The mouse and tap are from two different devices. |
| 1582 | * We technically don't need to set the downtime / eventtime for these events, but setting these |
| 1583 | * explicitly helps during debugging. |
| 1584 | * This test reproduces a crash where there is a mismatch between the downTime and eventTime. |
| 1585 | * In the buggy implementation, a tap on the right window would cause a crash. |
| 1586 | */ |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 1587 | TEST_F(InputDispatcherTest, HoverFromLeftToRightAndTap_legacy) { |
| 1588 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); |
| 1589 | |
Siarhei Vishniakou | e0431e4 | 2023-01-28 17:01:39 -0800 | [diff] [blame] | 1590 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1591 | sp<FakeWindowHandle> leftWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Left", |
| 1592 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | e0431e4 | 2023-01-28 17:01:39 -0800 | [diff] [blame] | 1593 | leftWindow->setFrame(Rect(0, 0, 200, 200)); |
| 1594 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1595 | sp<FakeWindowHandle> rightWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Right", |
| 1596 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | e0431e4 | 2023-01-28 17:01:39 -0800 | [diff] [blame] | 1597 | rightWindow->setFrame(Rect(200, 0, 400, 200)); |
| 1598 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 1599 | mDispatcher->onWindowInfosChanged( |
| 1600 | {{*leftWindow->getInfo(), *rightWindow->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | e0431e4 | 2023-01-28 17:01:39 -0800 | [diff] [blame] | 1601 | // All times need to start at the current time, otherwise the dispatcher will drop the events as |
| 1602 | // stale. |
| 1603 | const nsecs_t baseTime = systemTime(SYSTEM_TIME_MONOTONIC); |
| 1604 | const int32_t mouseDeviceId = 6; |
| 1605 | const int32_t touchDeviceId = 4; |
| 1606 | // Move the cursor from right |
| 1607 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 1608 | injectMotionEvent(*mDispatcher, |
Siarhei Vishniakou | e0431e4 | 2023-01-28 17:01:39 -0800 | [diff] [blame] | 1609 | MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, |
| 1610 | AINPUT_SOURCE_MOUSE) |
| 1611 | .deviceId(mouseDeviceId) |
| 1612 | .downTime(baseTime + 10) |
| 1613 | .eventTime(baseTime + 20) |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 1614 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(100)) |
Siarhei Vishniakou | e0431e4 | 2023-01-28 17:01:39 -0800 | [diff] [blame] | 1615 | .build())); |
| 1616 | rightWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)); |
| 1617 | |
| 1618 | // .. to the left window |
| 1619 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 1620 | injectMotionEvent(*mDispatcher, |
Siarhei Vishniakou | e0431e4 | 2023-01-28 17:01:39 -0800 | [diff] [blame] | 1621 | MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, |
| 1622 | AINPUT_SOURCE_MOUSE) |
| 1623 | .deviceId(mouseDeviceId) |
| 1624 | .downTime(baseTime + 10) |
| 1625 | .eventTime(baseTime + 30) |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 1626 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(110).y(100)) |
Siarhei Vishniakou | e0431e4 | 2023-01-28 17:01:39 -0800 | [diff] [blame] | 1627 | .build())); |
| 1628 | rightWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)); |
| 1629 | leftWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)); |
| 1630 | // Now tap the left window |
| 1631 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 1632 | injectMotionEvent(*mDispatcher, |
Siarhei Vishniakou | e0431e4 | 2023-01-28 17:01:39 -0800 | [diff] [blame] | 1633 | MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, |
| 1634 | AINPUT_SOURCE_TOUCHSCREEN) |
| 1635 | .deviceId(touchDeviceId) |
| 1636 | .downTime(baseTime + 40) |
| 1637 | .eventTime(baseTime + 40) |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 1638 | .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) |
Siarhei Vishniakou | e0431e4 | 2023-01-28 17:01:39 -0800 | [diff] [blame] | 1639 | .build())); |
| 1640 | leftWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)); |
| 1641 | leftWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_DOWN)); |
| 1642 | |
| 1643 | // release tap |
| 1644 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 1645 | injectMotionEvent(*mDispatcher, |
Siarhei Vishniakou | e0431e4 | 2023-01-28 17:01:39 -0800 | [diff] [blame] | 1646 | MotionEventBuilder(AMOTION_EVENT_ACTION_UP, |
| 1647 | AINPUT_SOURCE_TOUCHSCREEN) |
| 1648 | .deviceId(touchDeviceId) |
| 1649 | .downTime(baseTime + 40) |
| 1650 | .eventTime(baseTime + 50) |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 1651 | .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) |
Siarhei Vishniakou | e0431e4 | 2023-01-28 17:01:39 -0800 | [diff] [blame] | 1652 | .build())); |
| 1653 | leftWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_UP)); |
| 1654 | |
| 1655 | // Tap the window on the right |
| 1656 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 1657 | injectMotionEvent(*mDispatcher, |
Siarhei Vishniakou | e0431e4 | 2023-01-28 17:01:39 -0800 | [diff] [blame] | 1658 | MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, |
| 1659 | AINPUT_SOURCE_TOUCHSCREEN) |
| 1660 | .deviceId(touchDeviceId) |
| 1661 | .downTime(baseTime + 60) |
| 1662 | .eventTime(baseTime + 60) |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 1663 | .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) |
Siarhei Vishniakou | e0431e4 | 2023-01-28 17:01:39 -0800 | [diff] [blame] | 1664 | .build())); |
| 1665 | rightWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_DOWN)); |
| 1666 | |
| 1667 | // release tap |
| 1668 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 1669 | injectMotionEvent(*mDispatcher, |
Siarhei Vishniakou | e0431e4 | 2023-01-28 17:01:39 -0800 | [diff] [blame] | 1670 | MotionEventBuilder(AMOTION_EVENT_ACTION_UP, |
| 1671 | AINPUT_SOURCE_TOUCHSCREEN) |
| 1672 | .deviceId(touchDeviceId) |
| 1673 | .downTime(baseTime + 60) |
| 1674 | .eventTime(baseTime + 70) |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 1675 | .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) |
Siarhei Vishniakou | e0431e4 | 2023-01-28 17:01:39 -0800 | [diff] [blame] | 1676 | .build())); |
| 1677 | rightWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_UP)); |
| 1678 | |
| 1679 | // No more events |
| 1680 | leftWindow->assertNoEvents(); |
| 1681 | rightWindow->assertNoEvents(); |
| 1682 | } |
| 1683 | |
| 1684 | /** |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 1685 | * Two windows: a window on the left and a window on the right. |
| 1686 | * Mouse is hovered from the right window into the left window. |
| 1687 | * Next, we tap on the left window, where the cursor was last seen. |
| 1688 | * The second tap is done onto the right window. |
| 1689 | * The mouse and tap are from two different devices. |
| 1690 | * We technically don't need to set the downtime / eventtime for these events, but setting these |
| 1691 | * explicitly helps during debugging. |
| 1692 | * This test reproduces a crash where there is a mismatch between the downTime and eventTime. |
| 1693 | * In the buggy implementation, a tap on the right window would cause a crash. |
| 1694 | */ |
| 1695 | TEST_F(InputDispatcherTest, HoverFromLeftToRightAndTap) { |
| 1696 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); |
| 1697 | |
| 1698 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1699 | sp<FakeWindowHandle> leftWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Left", |
| 1700 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 1701 | leftWindow->setFrame(Rect(0, 0, 200, 200)); |
| 1702 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1703 | sp<FakeWindowHandle> rightWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Right", |
| 1704 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 1705 | rightWindow->setFrame(Rect(200, 0, 400, 200)); |
| 1706 | |
| 1707 | mDispatcher->onWindowInfosChanged( |
| 1708 | {{*leftWindow->getInfo(), *rightWindow->getInfo()}, {}, 0, 0}); |
| 1709 | // All times need to start at the current time, otherwise the dispatcher will drop the events as |
| 1710 | // stale. |
| 1711 | const nsecs_t baseTime = systemTime(SYSTEM_TIME_MONOTONIC); |
| 1712 | const int32_t mouseDeviceId = 6; |
| 1713 | const int32_t touchDeviceId = 4; |
| 1714 | // Move the cursor from right |
| 1715 | mDispatcher->notifyMotion( |
| 1716 | MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) |
| 1717 | .deviceId(mouseDeviceId) |
| 1718 | .downTime(baseTime + 10) |
| 1719 | .eventTime(baseTime + 20) |
| 1720 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(100)) |
| 1721 | .build()); |
| 1722 | rightWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)); |
| 1723 | |
| 1724 | // .. to the left window |
| 1725 | mDispatcher->notifyMotion( |
| 1726 | MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) |
| 1727 | .deviceId(mouseDeviceId) |
| 1728 | .downTime(baseTime + 10) |
| 1729 | .eventTime(baseTime + 30) |
| 1730 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(110).y(100)) |
| 1731 | .build()); |
| 1732 | rightWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)); |
| 1733 | leftWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)); |
| 1734 | // Now tap the left window |
| 1735 | mDispatcher->notifyMotion( |
| 1736 | MotionArgsBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 1737 | .deviceId(touchDeviceId) |
| 1738 | .downTime(baseTime + 40) |
| 1739 | .eventTime(baseTime + 40) |
| 1740 | .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) |
| 1741 | .build()); |
| 1742 | leftWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_DOWN)); |
| 1743 | |
| 1744 | // release tap |
| 1745 | mDispatcher->notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN) |
| 1746 | .deviceId(touchDeviceId) |
| 1747 | .downTime(baseTime + 40) |
| 1748 | .eventTime(baseTime + 50) |
| 1749 | .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) |
| 1750 | .build()); |
| 1751 | leftWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_UP)); |
| 1752 | |
| 1753 | // Tap the window on the right |
| 1754 | mDispatcher->notifyMotion( |
| 1755 | MotionArgsBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 1756 | .deviceId(touchDeviceId) |
| 1757 | .downTime(baseTime + 60) |
| 1758 | .eventTime(baseTime + 60) |
| 1759 | .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) |
| 1760 | .build()); |
| 1761 | rightWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_DOWN)); |
| 1762 | |
| 1763 | // release tap |
| 1764 | mDispatcher->notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN) |
| 1765 | .deviceId(touchDeviceId) |
| 1766 | .downTime(baseTime + 60) |
| 1767 | .eventTime(baseTime + 70) |
| 1768 | .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) |
| 1769 | .build()); |
| 1770 | rightWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_UP)); |
| 1771 | |
| 1772 | // No more events |
| 1773 | leftWindow->assertNoEvents(); |
| 1774 | rightWindow->assertNoEvents(); |
| 1775 | } |
| 1776 | |
| 1777 | /** |
Siarhei Vishniakou | a235c04 | 2023-05-02 09:59:09 -0700 | [diff] [blame] | 1778 | * Start hovering in a window. While this hover is still active, make another window appear on top. |
| 1779 | * The top, obstructing window has no input channel, so it's not supposed to receive input. |
| 1780 | * While the top window is present, the hovering is stopped. |
| 1781 | * Later, hovering gets resumed again. |
| 1782 | * Ensure that new hover gesture is handled correctly. |
| 1783 | * This test reproduces a crash where the HOVER_EXIT event wasn't getting dispatched correctly |
| 1784 | * to the window that's currently being hovered over. |
| 1785 | */ |
| 1786 | TEST_F(InputDispatcherTest, HoverWhileWindowAppears) { |
| 1787 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1788 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 1789 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | a235c04 | 2023-05-02 09:59:09 -0700 | [diff] [blame] | 1790 | window->setFrame(Rect(0, 0, 200, 200)); |
| 1791 | |
| 1792 | // Only a single window is present at first |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 1793 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | a235c04 | 2023-05-02 09:59:09 -0700 | [diff] [blame] | 1794 | |
| 1795 | // Start hovering in the window |
| 1796 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS) |
| 1797 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(100).y(100)) |
| 1798 | .build()); |
| 1799 | window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); |
| 1800 | |
| 1801 | // Now, an obscuring window appears! |
| 1802 | sp<FakeWindowHandle> obscuringWindow = |
| 1803 | sp<FakeWindowHandle>::make(application, mDispatcher, "Obscuring window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1804 | ui::LogicalDisplayId::DEFAULT, |
Prabir Pradhan | e7cc69c | 2024-01-05 21:35:28 +0000 | [diff] [blame] | 1805 | /*createInputChannel=*/false); |
Siarhei Vishniakou | a235c04 | 2023-05-02 09:59:09 -0700 | [diff] [blame] | 1806 | obscuringWindow->setFrame(Rect(0, 0, 200, 200)); |
| 1807 | obscuringWindow->setTouchOcclusionMode(TouchOcclusionMode::BLOCK_UNTRUSTED); |
| 1808 | obscuringWindow->setOwnerInfo(SECONDARY_WINDOW_PID, SECONDARY_WINDOW_UID); |
| 1809 | obscuringWindow->setNoInputChannel(true); |
| 1810 | obscuringWindow->setFocusable(false); |
| 1811 | obscuringWindow->setAlpha(1.0); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 1812 | mDispatcher->onWindowInfosChanged( |
| 1813 | {{*obscuringWindow->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | a235c04 | 2023-05-02 09:59:09 -0700 | [diff] [blame] | 1814 | |
| 1815 | // While this new obscuring window is present, the hovering is stopped |
| 1816 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_EXIT, AINPUT_SOURCE_STYLUS) |
| 1817 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(100).y(100)) |
| 1818 | .build()); |
| 1819 | window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); |
| 1820 | |
| 1821 | // Now the obscuring window goes away. |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 1822 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | a235c04 | 2023-05-02 09:59:09 -0700 | [diff] [blame] | 1823 | |
| 1824 | // And a new hover gesture starts. |
| 1825 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS) |
| 1826 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(100).y(100)) |
| 1827 | .build()); |
| 1828 | window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); |
| 1829 | } |
| 1830 | |
| 1831 | /** |
| 1832 | * Same test as 'HoverWhileWindowAppears' above, but here, we also send some HOVER_MOVE events to |
| 1833 | * the obscuring window. |
| 1834 | */ |
| 1835 | TEST_F(InputDispatcherTest, HoverMoveWhileWindowAppears) { |
| 1836 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1837 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 1838 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | a235c04 | 2023-05-02 09:59:09 -0700 | [diff] [blame] | 1839 | window->setFrame(Rect(0, 0, 200, 200)); |
| 1840 | |
| 1841 | // Only a single window is present at first |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 1842 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | a235c04 | 2023-05-02 09:59:09 -0700 | [diff] [blame] | 1843 | |
| 1844 | // Start hovering in the window |
| 1845 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS) |
| 1846 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(100).y(100)) |
| 1847 | .build()); |
| 1848 | window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); |
| 1849 | |
| 1850 | // Now, an obscuring window appears! |
| 1851 | sp<FakeWindowHandle> obscuringWindow = |
| 1852 | sp<FakeWindowHandle>::make(application, mDispatcher, "Obscuring window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1853 | ui::LogicalDisplayId::DEFAULT, |
Prabir Pradhan | e7cc69c | 2024-01-05 21:35:28 +0000 | [diff] [blame] | 1854 | /*createInputChannel=*/false); |
Siarhei Vishniakou | a235c04 | 2023-05-02 09:59:09 -0700 | [diff] [blame] | 1855 | obscuringWindow->setFrame(Rect(0, 0, 200, 200)); |
| 1856 | obscuringWindow->setTouchOcclusionMode(TouchOcclusionMode::BLOCK_UNTRUSTED); |
| 1857 | obscuringWindow->setOwnerInfo(SECONDARY_WINDOW_PID, SECONDARY_WINDOW_UID); |
| 1858 | obscuringWindow->setNoInputChannel(true); |
| 1859 | obscuringWindow->setFocusable(false); |
| 1860 | obscuringWindow->setAlpha(1.0); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 1861 | mDispatcher->onWindowInfosChanged( |
| 1862 | {{*obscuringWindow->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | a235c04 | 2023-05-02 09:59:09 -0700 | [diff] [blame] | 1863 | |
| 1864 | // While this new obscuring window is present, the hovering continues. The event can't go to the |
| 1865 | // bottom window due to obstructed touches, so it should generate HOVER_EXIT for that window. |
| 1866 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_MOVE, AINPUT_SOURCE_STYLUS) |
| 1867 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(100).y(100)) |
| 1868 | .build()); |
| 1869 | obscuringWindow->assertNoEvents(); |
| 1870 | window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); |
| 1871 | |
| 1872 | // Now the obscuring window goes away. |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 1873 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | a235c04 | 2023-05-02 09:59:09 -0700 | [diff] [blame] | 1874 | |
| 1875 | // Hovering continues in the same position. The hovering pointer re-enters the bottom window, |
| 1876 | // so it should generate a HOVER_ENTER |
| 1877 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_MOVE, AINPUT_SOURCE_STYLUS) |
| 1878 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(100).y(100)) |
| 1879 | .build()); |
| 1880 | window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); |
| 1881 | |
| 1882 | // Now the MOVE should be getting dispatched normally |
| 1883 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_MOVE, AINPUT_SOURCE_STYLUS) |
| 1884 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(110).y(110)) |
| 1885 | .build()); |
| 1886 | window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_MOVE)); |
| 1887 | } |
| 1888 | |
| 1889 | /** |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 1890 | * Hover mouse over a window, and then send ACTION_SCROLL. Ensure both the hover and the scroll |
| 1891 | * events are delivered to the window. |
| 1892 | */ |
| 1893 | TEST_F(InputDispatcherTest, HoverMoveAndScroll) { |
| 1894 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1895 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 1896 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 1897 | window->setFrame(Rect(0, 0, 200, 200)); |
| 1898 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
| 1899 | |
| 1900 | // Start hovering in the window |
| 1901 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE) |
| 1902 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(110)) |
| 1903 | .build()); |
| 1904 | window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); |
| 1905 | |
| 1906 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) |
| 1907 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(110).y(120)) |
| 1908 | .build()); |
| 1909 | window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_MOVE)); |
| 1910 | |
| 1911 | // Scroll with the mouse |
| 1912 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_SCROLL, AINPUT_SOURCE_MOUSE) |
| 1913 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(110).y(120)) |
| 1914 | .build()); |
| 1915 | window->consumeMotionEvent(WithMotionAction(ACTION_SCROLL)); |
| 1916 | } |
| 1917 | |
| 1918 | using InputDispatcherMultiDeviceTest = InputDispatcherTest; |
| 1919 | |
| 1920 | /** |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 1921 | * One window. Stylus down on the window. Next, touch from another device goes down. Ensure that |
| 1922 | * touch is dropped, because stylus should be preferred over touch. |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 1923 | */ |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 1924 | TEST_F(InputDispatcherMultiDeviceTest, StylusDownBlocksTouchDown) { |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 1925 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 1926 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1927 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 1928 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 1929 | window->setFrame(Rect(0, 0, 200, 200)); |
| 1930 | |
| 1931 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
| 1932 | |
| 1933 | constexpr int32_t touchDeviceId = 4; |
| 1934 | constexpr int32_t stylusDeviceId = 2; |
| 1935 | |
| 1936 | // Stylus down |
| 1937 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_STYLUS) |
| 1938 | .deviceId(stylusDeviceId) |
| 1939 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(100).y(110)) |
| 1940 | .build()); |
| 1941 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(stylusDeviceId))); |
| 1942 | |
| 1943 | // Touch down |
| 1944 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 1945 | .deviceId(touchDeviceId) |
| 1946 | .pointer(PointerBuilder(0, ToolType::FINGER).x(140).y(145)) |
| 1947 | .build()); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 1948 | |
| 1949 | // Touch move |
| 1950 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 1951 | .deviceId(touchDeviceId) |
| 1952 | .pointer(PointerBuilder(0, ToolType::FINGER).x(141).y(146)) |
| 1953 | .build()); |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 1954 | // Touch is ignored because stylus is already down |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 1955 | |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 1956 | // Subsequent stylus movements are delivered correctly |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 1957 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_STYLUS) |
| 1958 | .deviceId(stylusDeviceId) |
| 1959 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(101).y(111)) |
| 1960 | .build()); |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 1961 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(stylusDeviceId), |
| 1962 | WithCoords(101, 111))); |
| 1963 | |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 1964 | window->assertNoEvents(); |
| 1965 | } |
| 1966 | |
| 1967 | /** |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 1968 | * One window. Stylus down on the window. Next, touch from another device goes down. Ensure that |
| 1969 | * touch is not dropped, because multiple devices are allowed to be active in the same window. |
| 1970 | */ |
| 1971 | TEST_F(InputDispatcherMultiDeviceTest, StylusDownDoesNotBlockTouchDown) { |
| 1972 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); |
| 1973 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1974 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 1975 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 1976 | window->setFrame(Rect(0, 0, 200, 200)); |
| 1977 | |
| 1978 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
| 1979 | |
| 1980 | constexpr int32_t touchDeviceId = 4; |
| 1981 | constexpr int32_t stylusDeviceId = 2; |
| 1982 | |
| 1983 | // Stylus down |
| 1984 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_STYLUS) |
| 1985 | .deviceId(stylusDeviceId) |
| 1986 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(100).y(110)) |
| 1987 | .build()); |
| 1988 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(stylusDeviceId))); |
| 1989 | |
| 1990 | // Touch down |
| 1991 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 1992 | .deviceId(touchDeviceId) |
| 1993 | .pointer(PointerBuilder(0, ToolType::FINGER).x(140).y(145)) |
| 1994 | .build()); |
| 1995 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(touchDeviceId))); |
| 1996 | |
| 1997 | // Touch move |
| 1998 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 1999 | .deviceId(touchDeviceId) |
| 2000 | .pointer(PointerBuilder(0, ToolType::FINGER).x(141).y(146)) |
| 2001 | .build()); |
| 2002 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(touchDeviceId))); |
| 2003 | |
| 2004 | // Stylus move |
| 2005 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_STYLUS) |
| 2006 | .deviceId(stylusDeviceId) |
| 2007 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(101).y(111)) |
| 2008 | .build()); |
| 2009 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(stylusDeviceId), |
| 2010 | WithCoords(101, 111))); |
| 2011 | |
| 2012 | window->assertNoEvents(); |
| 2013 | } |
| 2014 | |
| 2015 | /** |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2016 | * One window and one spy window. Stylus down on the window. Next, touch from another device goes |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2017 | * down. Ensure that touch is dropped, because stylus should be preferred over touch. |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2018 | * Similar test as above, but with added SPY window. |
| 2019 | */ |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2020 | TEST_F(InputDispatcherMultiDeviceTest, StylusDownWithSpyBlocksTouchDown) { |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 2021 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2022 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 2023 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 2024 | ui::LogicalDisplayId::DEFAULT); |
| 2025 | sp<FakeWindowHandle> spyWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Spy", |
| 2026 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2027 | spyWindow->setFrame(Rect(0, 0, 200, 200)); |
| 2028 | spyWindow->setTrustedOverlay(true); |
| 2029 | spyWindow->setSpy(true); |
| 2030 | window->setFrame(Rect(0, 0, 200, 200)); |
| 2031 | |
| 2032 | mDispatcher->onWindowInfosChanged({{*spyWindow->getInfo(), *window->getInfo()}, {}, 0, 0}); |
| 2033 | |
| 2034 | constexpr int32_t touchDeviceId = 4; |
| 2035 | constexpr int32_t stylusDeviceId = 2; |
| 2036 | |
| 2037 | // Stylus down |
| 2038 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_STYLUS) |
| 2039 | .deviceId(stylusDeviceId) |
| 2040 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(100).y(110)) |
| 2041 | .build()); |
| 2042 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(stylusDeviceId))); |
| 2043 | spyWindow->consumeMotionEvent( |
| 2044 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(stylusDeviceId))); |
| 2045 | |
| 2046 | // Touch down |
| 2047 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 2048 | .deviceId(touchDeviceId) |
| 2049 | .pointer(PointerBuilder(0, ToolType::FINGER).x(140).y(145)) |
| 2050 | .build()); |
| 2051 | |
| 2052 | // Touch move |
| 2053 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 2054 | .deviceId(touchDeviceId) |
| 2055 | .pointer(PointerBuilder(0, ToolType::FINGER).x(141).y(146)) |
| 2056 | .build()); |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2057 | |
| 2058 | // Touch is ignored because stylus is already down |
| 2059 | |
| 2060 | // Subsequent stylus movements are delivered correctly |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2061 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_STYLUS) |
| 2062 | .deviceId(stylusDeviceId) |
| 2063 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(101).y(111)) |
| 2064 | .build()); |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2065 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(stylusDeviceId), |
| 2066 | WithCoords(101, 111))); |
| 2067 | spyWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(stylusDeviceId), |
| 2068 | WithCoords(101, 111))); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2069 | |
| 2070 | window->assertNoEvents(); |
| 2071 | spyWindow->assertNoEvents(); |
| 2072 | } |
| 2073 | |
| 2074 | /** |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 2075 | * One window and one spy window. Stylus down on the window. Next, touch from another device goes |
| 2076 | * down. Ensure that touch is not dropped, because multiple devices can be active at the same time. |
| 2077 | * Similar test as above, but with added SPY window. |
| 2078 | */ |
| 2079 | TEST_F(InputDispatcherMultiDeviceTest, StylusDownWithSpyDoesNotBlockTouchDown) { |
| 2080 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); |
| 2081 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 2082 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 2083 | ui::LogicalDisplayId::DEFAULT); |
| 2084 | sp<FakeWindowHandle> spyWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Spy", |
| 2085 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 2086 | spyWindow->setFrame(Rect(0, 0, 200, 200)); |
| 2087 | spyWindow->setTrustedOverlay(true); |
| 2088 | spyWindow->setSpy(true); |
| 2089 | window->setFrame(Rect(0, 0, 200, 200)); |
| 2090 | |
| 2091 | mDispatcher->onWindowInfosChanged({{*spyWindow->getInfo(), *window->getInfo()}, {}, 0, 0}); |
| 2092 | |
| 2093 | constexpr int32_t touchDeviceId = 4; |
| 2094 | constexpr int32_t stylusDeviceId = 2; |
| 2095 | |
| 2096 | // Stylus down |
| 2097 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_STYLUS) |
| 2098 | .deviceId(stylusDeviceId) |
| 2099 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(100).y(110)) |
| 2100 | .build()); |
| 2101 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(stylusDeviceId))); |
| 2102 | spyWindow->consumeMotionEvent( |
| 2103 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(stylusDeviceId))); |
| 2104 | |
| 2105 | // Touch down |
| 2106 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 2107 | .deviceId(touchDeviceId) |
| 2108 | .pointer(PointerBuilder(0, ToolType::FINGER).x(140).y(145)) |
| 2109 | .build()); |
| 2110 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(touchDeviceId))); |
| 2111 | spyWindow->consumeMotionEvent( |
| 2112 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(touchDeviceId))); |
| 2113 | |
| 2114 | // Touch move |
| 2115 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 2116 | .deviceId(touchDeviceId) |
| 2117 | .pointer(PointerBuilder(0, ToolType::FINGER).x(141).y(146)) |
| 2118 | .build()); |
| 2119 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(touchDeviceId))); |
| 2120 | spyWindow->consumeMotionEvent( |
| 2121 | AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(touchDeviceId))); |
| 2122 | |
| 2123 | // Subsequent stylus movements are delivered correctly |
| 2124 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_STYLUS) |
| 2125 | .deviceId(stylusDeviceId) |
| 2126 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(101).y(111)) |
| 2127 | .build()); |
| 2128 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(stylusDeviceId), |
| 2129 | WithCoords(101, 111))); |
| 2130 | spyWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(stylusDeviceId), |
| 2131 | WithCoords(101, 111))); |
| 2132 | |
| 2133 | window->assertNoEvents(); |
| 2134 | spyWindow->assertNoEvents(); |
| 2135 | } |
| 2136 | |
| 2137 | /** |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2138 | * One window. Stylus hover on the window. Next, touch from another device goes down. Ensure that |
Siarhei Vishniakou | 3ad54f5 | 2023-11-02 16:54:40 -0700 | [diff] [blame] | 2139 | * touch is dropped, because stylus hover takes precedence. |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2140 | */ |
Siarhei Vishniakou | 3ad54f5 | 2023-11-02 16:54:40 -0700 | [diff] [blame] | 2141 | TEST_F(InputDispatcherMultiDeviceTest, StylusHoverBlocksTouchDown) { |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 2142 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2143 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 2144 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 2145 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2146 | window->setFrame(Rect(0, 0, 200, 200)); |
| 2147 | |
| 2148 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
| 2149 | |
| 2150 | constexpr int32_t touchDeviceId = 4; |
| 2151 | constexpr int32_t stylusDeviceId = 2; |
| 2152 | |
| 2153 | // Stylus down on the window |
| 2154 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS) |
| 2155 | .deviceId(stylusDeviceId) |
| 2156 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(100).y(110)) |
| 2157 | .build()); |
| 2158 | window->consumeMotionEvent( |
| 2159 | AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithDeviceId(stylusDeviceId))); |
| 2160 | |
| 2161 | // Touch down on window |
| 2162 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 2163 | .deviceId(touchDeviceId) |
| 2164 | .pointer(PointerBuilder(0, ToolType::FINGER).x(140).y(145)) |
| 2165 | .build()); |
| 2166 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 2167 | .deviceId(touchDeviceId) |
| 2168 | .pointer(PointerBuilder(0, ToolType::FINGER).x(141).y(146)) |
| 2169 | .build()); |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2170 | |
Siarhei Vishniakou | 3ad54f5 | 2023-11-02 16:54:40 -0700 | [diff] [blame] | 2171 | // Touch is ignored because stylus is hovering |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2172 | |
Siarhei Vishniakou | 3ad54f5 | 2023-11-02 16:54:40 -0700 | [diff] [blame] | 2173 | // Subsequent stylus movements are delivered correctly |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2174 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_MOVE, AINPUT_SOURCE_STYLUS) |
| 2175 | .deviceId(stylusDeviceId) |
| 2176 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(101).y(111)) |
| 2177 | .build()); |
Siarhei Vishniakou | 3ad54f5 | 2023-11-02 16:54:40 -0700 | [diff] [blame] | 2178 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_HOVER_MOVE), |
| 2179 | WithDeviceId(stylusDeviceId), WithCoords(101, 111))); |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2180 | |
Siarhei Vishniakou | 3ad54f5 | 2023-11-02 16:54:40 -0700 | [diff] [blame] | 2181 | // and subsequent touches continue to be ignored |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2182 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 2183 | .deviceId(touchDeviceId) |
| 2184 | .pointer(PointerBuilder(0, ToolType::FINGER).x(142).y(147)) |
| 2185 | .build()); |
Siarhei Vishniakou | 3ad54f5 | 2023-11-02 16:54:40 -0700 | [diff] [blame] | 2186 | window->assertNoEvents(); |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2187 | } |
| 2188 | |
| 2189 | /** |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 2190 | * One window. Stylus hover on the window. Next, touch from another device goes down. Ensure that |
| 2191 | * touch is not dropped, because stylus hover and touch can be both active at the same time. |
| 2192 | */ |
| 2193 | TEST_F(InputDispatcherMultiDeviceTest, StylusHoverDoesNotBlockTouchDown) { |
| 2194 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); |
| 2195 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 2196 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 2197 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 2198 | window->setFrame(Rect(0, 0, 200, 200)); |
| 2199 | |
| 2200 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
| 2201 | |
| 2202 | constexpr int32_t touchDeviceId = 4; |
| 2203 | constexpr int32_t stylusDeviceId = 2; |
| 2204 | |
| 2205 | // Stylus down on the window |
| 2206 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS) |
| 2207 | .deviceId(stylusDeviceId) |
| 2208 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(100).y(110)) |
| 2209 | .build()); |
| 2210 | window->consumeMotionEvent( |
| 2211 | AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithDeviceId(stylusDeviceId))); |
| 2212 | |
| 2213 | // Touch down on window |
| 2214 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 2215 | .deviceId(touchDeviceId) |
| 2216 | .pointer(PointerBuilder(0, ToolType::FINGER).x(140).y(145)) |
| 2217 | .build()); |
| 2218 | // Touch move on window |
| 2219 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(touchDeviceId))); |
| 2220 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 2221 | .deviceId(touchDeviceId) |
| 2222 | .pointer(PointerBuilder(0, ToolType::FINGER).x(141).y(146)) |
| 2223 | .build()); |
| 2224 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(touchDeviceId))); |
| 2225 | |
| 2226 | // Subsequent stylus movements are delivered correctly |
| 2227 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_MOVE, AINPUT_SOURCE_STYLUS) |
| 2228 | .deviceId(stylusDeviceId) |
| 2229 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(101).y(111)) |
| 2230 | .build()); |
| 2231 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_HOVER_MOVE), |
| 2232 | WithDeviceId(stylusDeviceId), WithCoords(101, 111))); |
| 2233 | |
| 2234 | // and subsequent touches continue to work |
| 2235 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 2236 | .deviceId(touchDeviceId) |
| 2237 | .pointer(PointerBuilder(0, ToolType::FINGER).x(142).y(147)) |
| 2238 | .build()); |
| 2239 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(touchDeviceId))); |
| 2240 | window->assertNoEvents(); |
| 2241 | } |
| 2242 | |
| 2243 | /** |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2244 | * One window. Touch down on the window. Then, stylus hover on the window from another device. |
Siarhei Vishniakou | 3ad54f5 | 2023-11-02 16:54:40 -0700 | [diff] [blame] | 2245 | * Ensure that touch is canceled, because stylus hover should take precedence. |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2246 | */ |
Siarhei Vishniakou | 3ad54f5 | 2023-11-02 16:54:40 -0700 | [diff] [blame] | 2247 | TEST_F(InputDispatcherMultiDeviceTest, TouchIsCanceledByStylusHover) { |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 2248 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2249 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 2250 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 2251 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2252 | window->setFrame(Rect(0, 0, 200, 200)); |
| 2253 | |
| 2254 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
| 2255 | |
| 2256 | constexpr int32_t touchDeviceId = 4; |
| 2257 | constexpr int32_t stylusDeviceId = 2; |
| 2258 | |
| 2259 | // Touch down on window |
| 2260 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 2261 | .deviceId(touchDeviceId) |
| 2262 | .pointer(PointerBuilder(0, ToolType::FINGER).x(140).y(145)) |
| 2263 | .build()); |
| 2264 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 2265 | .deviceId(touchDeviceId) |
| 2266 | .pointer(PointerBuilder(0, ToolType::FINGER).x(141).y(146)) |
| 2267 | .build()); |
| 2268 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(touchDeviceId))); |
| 2269 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(touchDeviceId))); |
| 2270 | |
| 2271 | // Stylus hover on the window |
| 2272 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS) |
| 2273 | .deviceId(stylusDeviceId) |
| 2274 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(100).y(110)) |
| 2275 | .build()); |
| 2276 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_MOVE, AINPUT_SOURCE_STYLUS) |
| 2277 | .deviceId(stylusDeviceId) |
| 2278 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(101).y(111)) |
| 2279 | .build()); |
Siarhei Vishniakou | 3ad54f5 | 2023-11-02 16:54:40 -0700 | [diff] [blame] | 2280 | // Stylus hover movement causes touch to be canceled |
| 2281 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_CANCEL), WithDeviceId(touchDeviceId), |
| 2282 | WithCoords(141, 146))); |
| 2283 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_HOVER_ENTER), |
| 2284 | WithDeviceId(stylusDeviceId), WithCoords(100, 110))); |
| 2285 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_HOVER_MOVE), |
| 2286 | WithDeviceId(stylusDeviceId), WithCoords(101, 111))); |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2287 | |
Siarhei Vishniakou | 3ad54f5 | 2023-11-02 16:54:40 -0700 | [diff] [blame] | 2288 | // Subsequent touch movements are ignored |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2289 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 2290 | .deviceId(touchDeviceId) |
| 2291 | .pointer(PointerBuilder(0, ToolType::FINGER).x(142).y(147)) |
| 2292 | .build()); |
Siarhei Vishniakou | 3ad54f5 | 2023-11-02 16:54:40 -0700 | [diff] [blame] | 2293 | |
| 2294 | window->assertNoEvents(); |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2295 | } |
| 2296 | |
| 2297 | /** |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 2298 | * One window. Touch down on the window. Then, stylus hover on the window from another device. |
| 2299 | * Ensure that touch is not canceled, because stylus hover can be active at the same time as touch. |
| 2300 | */ |
| 2301 | TEST_F(InputDispatcherMultiDeviceTest, TouchIsNotCanceledByStylusHover) { |
| 2302 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); |
| 2303 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 2304 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 2305 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 2306 | window->setFrame(Rect(0, 0, 200, 200)); |
| 2307 | |
| 2308 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
| 2309 | |
| 2310 | constexpr int32_t touchDeviceId = 4; |
| 2311 | constexpr int32_t stylusDeviceId = 2; |
| 2312 | |
| 2313 | // Touch down on window |
| 2314 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 2315 | .deviceId(touchDeviceId) |
| 2316 | .pointer(PointerBuilder(0, ToolType::FINGER).x(140).y(145)) |
| 2317 | .build()); |
| 2318 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 2319 | .deviceId(touchDeviceId) |
| 2320 | .pointer(PointerBuilder(0, ToolType::FINGER).x(141).y(146)) |
| 2321 | .build()); |
| 2322 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(touchDeviceId))); |
| 2323 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(touchDeviceId))); |
| 2324 | |
| 2325 | // Stylus hover on the window |
| 2326 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS) |
| 2327 | .deviceId(stylusDeviceId) |
| 2328 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(100).y(110)) |
| 2329 | .build()); |
| 2330 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_MOVE, AINPUT_SOURCE_STYLUS) |
| 2331 | .deviceId(stylusDeviceId) |
| 2332 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(101).y(111)) |
| 2333 | .build()); |
| 2334 | // Stylus hover movement is received normally |
| 2335 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_HOVER_ENTER), |
| 2336 | WithDeviceId(stylusDeviceId), WithCoords(100, 110))); |
| 2337 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_HOVER_MOVE), |
| 2338 | WithDeviceId(stylusDeviceId), WithCoords(101, 111))); |
| 2339 | |
| 2340 | // Subsequent touch movements also work |
| 2341 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 2342 | .deviceId(touchDeviceId) |
| 2343 | .pointer(PointerBuilder(0, ToolType::FINGER).x(142).y(147)) |
| 2344 | .build()); |
| 2345 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(touchDeviceId), |
| 2346 | WithCoords(142, 147))); |
| 2347 | |
| 2348 | window->assertNoEvents(); |
| 2349 | } |
| 2350 | |
| 2351 | /** |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2352 | * One window. Stylus down on the window. Then, stylus from another device goes down. Ensure that |
| 2353 | * the latest stylus takes over. That is, old stylus should be canceled and the new stylus should |
| 2354 | * become active. |
| 2355 | */ |
| 2356 | TEST_F(InputDispatcherMultiDeviceTest, LatestStylusWins) { |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 2357 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2358 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 2359 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 2360 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2361 | window->setFrame(Rect(0, 0, 200, 200)); |
| 2362 | |
| 2363 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
| 2364 | |
| 2365 | constexpr int32_t stylusDeviceId1 = 3; |
| 2366 | constexpr int32_t stylusDeviceId2 = 5; |
| 2367 | |
| 2368 | // Touch down on window |
| 2369 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_STYLUS) |
| 2370 | .deviceId(stylusDeviceId1) |
| 2371 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(99).y(100)) |
| 2372 | .build()); |
| 2373 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_STYLUS) |
| 2374 | .deviceId(stylusDeviceId1) |
| 2375 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(100).y(101)) |
| 2376 | .build()); |
| 2377 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(stylusDeviceId1))); |
| 2378 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(stylusDeviceId1))); |
| 2379 | |
| 2380 | // Second stylus down |
| 2381 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_STYLUS) |
| 2382 | .deviceId(stylusDeviceId2) |
| 2383 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(9).y(10)) |
| 2384 | .build()); |
| 2385 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_STYLUS) |
| 2386 | .deviceId(stylusDeviceId2) |
| 2387 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(10).y(11)) |
| 2388 | .build()); |
| 2389 | |
| 2390 | // First stylus is canceled, second one takes over. |
| 2391 | window->consumeMotionEvent( |
| 2392 | AllOf(WithMotionAction(ACTION_CANCEL), WithDeviceId(stylusDeviceId1))); |
| 2393 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(stylusDeviceId2))); |
| 2394 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(stylusDeviceId2))); |
| 2395 | |
| 2396 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_STYLUS) |
| 2397 | .deviceId(stylusDeviceId1) |
| 2398 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(101).y(102)) |
| 2399 | .build()); |
| 2400 | // Subsequent stylus movements are delivered correctly |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2401 | window->assertNoEvents(); |
| 2402 | } |
| 2403 | |
| 2404 | /** |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 2405 | * One window. Stylus down on the window. Then, stylus from another device goes down. Ensure that |
| 2406 | * both stylus devices can function simultaneously. |
| 2407 | */ |
| 2408 | TEST_F(InputDispatcherMultiDeviceTest, TwoStylusDevicesActiveAtTheSameTime) { |
| 2409 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); |
| 2410 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 2411 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 2412 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 2413 | window->setFrame(Rect(0, 0, 200, 200)); |
| 2414 | |
| 2415 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
| 2416 | |
| 2417 | constexpr int32_t stylusDeviceId1 = 3; |
| 2418 | constexpr int32_t stylusDeviceId2 = 5; |
| 2419 | |
| 2420 | // Touch down on window |
| 2421 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_STYLUS) |
| 2422 | .deviceId(stylusDeviceId1) |
| 2423 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(99).y(100)) |
| 2424 | .build()); |
| 2425 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_STYLUS) |
| 2426 | .deviceId(stylusDeviceId1) |
| 2427 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(100).y(101)) |
| 2428 | .build()); |
| 2429 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(stylusDeviceId1))); |
| 2430 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(stylusDeviceId1))); |
| 2431 | |
| 2432 | // Second stylus down |
| 2433 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_STYLUS) |
| 2434 | .deviceId(stylusDeviceId2) |
| 2435 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(9).y(10)) |
| 2436 | .build()); |
| 2437 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_STYLUS) |
| 2438 | .deviceId(stylusDeviceId2) |
| 2439 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(10).y(11)) |
| 2440 | .build()); |
| 2441 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(stylusDeviceId2))); |
| 2442 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(stylusDeviceId2))); |
| 2443 | |
| 2444 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_STYLUS) |
| 2445 | .deviceId(stylusDeviceId1) |
| 2446 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(101).y(102)) |
| 2447 | .build()); |
| 2448 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(stylusDeviceId1))); |
| 2449 | window->assertNoEvents(); |
| 2450 | } |
| 2451 | |
| 2452 | /** |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2453 | * One window. Touch down on the window. Then, stylus down on the window from another device. |
| 2454 | * Ensure that is canceled, because stylus down should be preferred over touch. |
| 2455 | */ |
| 2456 | TEST_F(InputDispatcherMultiDeviceTest, TouchIsCanceledByStylusDown) { |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 2457 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2458 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 2459 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 2460 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2461 | window->setFrame(Rect(0, 0, 200, 200)); |
| 2462 | |
| 2463 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
| 2464 | |
| 2465 | constexpr int32_t touchDeviceId = 4; |
| 2466 | constexpr int32_t stylusDeviceId = 2; |
| 2467 | |
| 2468 | // Touch down on window |
| 2469 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 2470 | .deviceId(touchDeviceId) |
| 2471 | .pointer(PointerBuilder(0, ToolType::FINGER).x(140).y(145)) |
| 2472 | .build()); |
| 2473 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 2474 | .deviceId(touchDeviceId) |
| 2475 | .pointer(PointerBuilder(0, ToolType::FINGER).x(141).y(146)) |
| 2476 | .build()); |
| 2477 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(touchDeviceId))); |
| 2478 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(touchDeviceId))); |
| 2479 | |
| 2480 | // Stylus down on the window |
| 2481 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_STYLUS) |
| 2482 | .deviceId(stylusDeviceId) |
| 2483 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(100).y(110)) |
| 2484 | .build()); |
| 2485 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_CANCEL), WithDeviceId(touchDeviceId))); |
| 2486 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(stylusDeviceId))); |
| 2487 | |
| 2488 | // Subsequent stylus movements are delivered correctly |
| 2489 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_STYLUS) |
| 2490 | .deviceId(stylusDeviceId) |
| 2491 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(101).y(111)) |
| 2492 | .build()); |
| 2493 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(stylusDeviceId), |
| 2494 | WithCoords(101, 111))); |
| 2495 | } |
| 2496 | |
| 2497 | /** |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 2498 | * One window. Touch down on the window. Then, stylus down on the window from another device. |
| 2499 | * Ensure that both touch and stylus are functioning independently. |
| 2500 | */ |
| 2501 | TEST_F(InputDispatcherMultiDeviceTest, TouchIsNotCanceledByStylusDown) { |
| 2502 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); |
| 2503 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 2504 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 2505 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 2506 | window->setFrame(Rect(0, 0, 200, 200)); |
| 2507 | |
| 2508 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
| 2509 | |
| 2510 | constexpr int32_t touchDeviceId = 4; |
| 2511 | constexpr int32_t stylusDeviceId = 2; |
| 2512 | |
| 2513 | // Touch down on window |
| 2514 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 2515 | .deviceId(touchDeviceId) |
| 2516 | .pointer(PointerBuilder(0, ToolType::FINGER).x(140).y(145)) |
| 2517 | .build()); |
| 2518 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 2519 | .deviceId(touchDeviceId) |
| 2520 | .pointer(PointerBuilder(0, ToolType::FINGER).x(141).y(146)) |
| 2521 | .build()); |
| 2522 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(touchDeviceId))); |
| 2523 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(touchDeviceId))); |
| 2524 | |
| 2525 | // Stylus down on the window |
| 2526 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_STYLUS) |
| 2527 | .deviceId(stylusDeviceId) |
| 2528 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(100).y(110)) |
| 2529 | .build()); |
| 2530 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(stylusDeviceId))); |
| 2531 | |
| 2532 | // Subsequent stylus movements are delivered correctly |
| 2533 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_STYLUS) |
| 2534 | .deviceId(stylusDeviceId) |
| 2535 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(101).y(111)) |
| 2536 | .build()); |
| 2537 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(stylusDeviceId), |
| 2538 | WithCoords(101, 111))); |
| 2539 | |
| 2540 | // Touch continues to work too |
| 2541 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 2542 | .deviceId(touchDeviceId) |
| 2543 | .pointer(PointerBuilder(0, ToolType::FINGER).x(148).y(149)) |
| 2544 | .build()); |
| 2545 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(touchDeviceId))); |
| 2546 | } |
| 2547 | |
| 2548 | /** |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 2549 | * Two windows: a window on the left and a window on the right. |
| 2550 | * Mouse is clicked on the left window and remains down. Touch is touched on the right and remains |
| 2551 | * down. Then, on the left window, also place second touch pointer down. |
| 2552 | * This test tries to reproduce a crash. |
| 2553 | * In the buggy implementation, second pointer down on the left window would cause a crash. |
| 2554 | */ |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 2555 | TEST_F(InputDispatcherMultiDeviceTest, MultiDeviceSplitTouch_legacy) { |
| 2556 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 2557 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 2558 | sp<FakeWindowHandle> leftWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Left", |
| 2559 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 2560 | leftWindow->setFrame(Rect(0, 0, 200, 200)); |
| 2561 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 2562 | sp<FakeWindowHandle> rightWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Right", |
| 2563 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 2564 | rightWindow->setFrame(Rect(200, 0, 400, 200)); |
| 2565 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 2566 | mDispatcher->onWindowInfosChanged( |
| 2567 | {{*leftWindow->getInfo(), *rightWindow->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 2568 | |
| 2569 | const int32_t touchDeviceId = 4; |
| 2570 | const int32_t mouseDeviceId = 6; |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 2571 | |
| 2572 | // Start hovering over the left window |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 2573 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE) |
| 2574 | .deviceId(mouseDeviceId) |
| 2575 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100)) |
| 2576 | .build()); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 2577 | leftWindow->consumeMotionEvent( |
| 2578 | AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithDeviceId(mouseDeviceId))); |
| 2579 | |
| 2580 | // Mouse down on left window |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 2581 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_MOUSE) |
| 2582 | .deviceId(mouseDeviceId) |
| 2583 | .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) |
| 2584 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100)) |
| 2585 | .build()); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 2586 | |
| 2587 | leftWindow->consumeMotionEvent( |
| 2588 | AllOf(WithMotionAction(ACTION_HOVER_EXIT), WithDeviceId(mouseDeviceId))); |
| 2589 | leftWindow->consumeMotionEvent( |
| 2590 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(mouseDeviceId))); |
| 2591 | |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 2592 | mDispatcher->notifyMotion( |
| 2593 | MotionArgsBuilder(AMOTION_EVENT_ACTION_BUTTON_PRESS, AINPUT_SOURCE_MOUSE) |
| 2594 | .deviceId(mouseDeviceId) |
| 2595 | .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) |
| 2596 | .actionButton(AMOTION_EVENT_BUTTON_PRIMARY) |
| 2597 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100)) |
| 2598 | .build()); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 2599 | leftWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS)); |
| 2600 | |
| 2601 | // First touch pointer down on right window |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 2602 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 2603 | .deviceId(touchDeviceId) |
| 2604 | .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) |
| 2605 | .build()); |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2606 | leftWindow->assertNoEvents(); |
| 2607 | |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 2608 | rightWindow->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); |
| 2609 | |
| 2610 | // Second touch pointer down on left window |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 2611 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 2612 | .deviceId(touchDeviceId) |
| 2613 | .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) |
| 2614 | .pointer(PointerBuilder(1, ToolType::FINGER).x(100).y(100)) |
| 2615 | .build()); |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2616 | // Since this is now a new splittable pointer going down on the left window, and it's coming |
| 2617 | // from a different device, the current gesture in the left window (pointer down) should first |
| 2618 | // be canceled. |
| 2619 | leftWindow->consumeMotionEvent( |
| 2620 | AllOf(WithMotionAction(ACTION_CANCEL), WithDeviceId(mouseDeviceId))); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 2621 | leftWindow->consumeMotionEvent( |
| 2622 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(touchDeviceId))); |
| 2623 | // This MOVE event is not necessary (doesn't carry any new information), but it's there in the |
| 2624 | // current implementation. |
| 2625 | const std::map<int32_t, PointF> expectedPointers{{0, PointF{100, 100}}}; |
| 2626 | rightWindow->consumeMotionEvent( |
| 2627 | AllOf(WithMotionAction(ACTION_MOVE), WithPointers(expectedPointers))); |
| 2628 | |
| 2629 | leftWindow->assertNoEvents(); |
| 2630 | rightWindow->assertNoEvents(); |
| 2631 | } |
| 2632 | |
| 2633 | /** |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2634 | * Two windows: a window on the left and a window on the right. |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 2635 | * Mouse is clicked on the left window and remains down. Touch is touched on the right and remains |
| 2636 | * down. Then, on the left window, also place second touch pointer down. |
| 2637 | * This test tries to reproduce a crash. |
| 2638 | * In the buggy implementation, second pointer down on the left window would cause a crash. |
| 2639 | */ |
| 2640 | TEST_F(InputDispatcherMultiDeviceTest, MultiDeviceSplitTouch) { |
| 2641 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); |
| 2642 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 2643 | sp<FakeWindowHandle> leftWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Left", |
| 2644 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 2645 | leftWindow->setFrame(Rect(0, 0, 200, 200)); |
| 2646 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 2647 | sp<FakeWindowHandle> rightWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Right", |
| 2648 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 2649 | rightWindow->setFrame(Rect(200, 0, 400, 200)); |
| 2650 | |
| 2651 | mDispatcher->onWindowInfosChanged( |
| 2652 | {{*leftWindow->getInfo(), *rightWindow->getInfo()}, {}, 0, 0}); |
| 2653 | |
| 2654 | const int32_t touchDeviceId = 4; |
| 2655 | const int32_t mouseDeviceId = 6; |
| 2656 | |
| 2657 | // Start hovering over the left window |
| 2658 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE) |
| 2659 | .deviceId(mouseDeviceId) |
| 2660 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100)) |
| 2661 | .build()); |
| 2662 | leftWindow->consumeMotionEvent( |
| 2663 | AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithDeviceId(mouseDeviceId))); |
| 2664 | |
| 2665 | // Mouse down on left window |
| 2666 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_MOUSE) |
| 2667 | .deviceId(mouseDeviceId) |
| 2668 | .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) |
| 2669 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100)) |
| 2670 | .build()); |
| 2671 | |
| 2672 | leftWindow->consumeMotionEvent( |
| 2673 | AllOf(WithMotionAction(ACTION_HOVER_EXIT), WithDeviceId(mouseDeviceId))); |
| 2674 | leftWindow->consumeMotionEvent( |
| 2675 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(mouseDeviceId))); |
| 2676 | |
| 2677 | mDispatcher->notifyMotion( |
| 2678 | MotionArgsBuilder(AMOTION_EVENT_ACTION_BUTTON_PRESS, AINPUT_SOURCE_MOUSE) |
| 2679 | .deviceId(mouseDeviceId) |
| 2680 | .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) |
| 2681 | .actionButton(AMOTION_EVENT_BUTTON_PRIMARY) |
| 2682 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100)) |
| 2683 | .build()); |
| 2684 | leftWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS)); |
| 2685 | |
| 2686 | // First touch pointer down on right window |
| 2687 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 2688 | .deviceId(touchDeviceId) |
| 2689 | .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) |
| 2690 | .build()); |
| 2691 | leftWindow->assertNoEvents(); |
| 2692 | |
| 2693 | rightWindow->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); |
| 2694 | |
| 2695 | // Second touch pointer down on left window |
| 2696 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 2697 | .deviceId(touchDeviceId) |
| 2698 | .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) |
| 2699 | .pointer(PointerBuilder(1, ToolType::FINGER).x(100).y(100)) |
| 2700 | .build()); |
| 2701 | // Since this is now a new splittable pointer going down on the left window, and it's coming |
| 2702 | // from a different device, it will be split and delivered to left window separately. |
| 2703 | leftWindow->consumeMotionEvent( |
| 2704 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(touchDeviceId))); |
| 2705 | // This MOVE event is not necessary (doesn't carry any new information), but it's there in the |
| 2706 | // current implementation. |
| 2707 | const std::map<int32_t, PointF> expectedPointers{{0, PointF{100, 100}}}; |
| 2708 | rightWindow->consumeMotionEvent( |
| 2709 | AllOf(WithMotionAction(ACTION_MOVE), WithPointers(expectedPointers))); |
| 2710 | |
| 2711 | leftWindow->assertNoEvents(); |
| 2712 | rightWindow->assertNoEvents(); |
| 2713 | } |
| 2714 | |
| 2715 | /** |
| 2716 | * Two windows: a window on the left and a window on the right. |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2717 | * Mouse is hovered on the left window and stylus is hovered on the right window. |
| 2718 | */ |
| 2719 | TEST_F(InputDispatcherMultiDeviceTest, MultiDeviceHover) { |
| 2720 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 2721 | sp<FakeWindowHandle> leftWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Left", |
| 2722 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2723 | leftWindow->setFrame(Rect(0, 0, 200, 200)); |
| 2724 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 2725 | sp<FakeWindowHandle> rightWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Right", |
| 2726 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2727 | rightWindow->setFrame(Rect(200, 0, 400, 200)); |
| 2728 | |
| 2729 | mDispatcher->onWindowInfosChanged( |
| 2730 | {{*leftWindow->getInfo(), *rightWindow->getInfo()}, {}, 0, 0}); |
| 2731 | |
| 2732 | const int32_t stylusDeviceId = 3; |
| 2733 | const int32_t mouseDeviceId = 6; |
| 2734 | |
| 2735 | // Start hovering over the left window |
| 2736 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE) |
| 2737 | .deviceId(mouseDeviceId) |
| 2738 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(110)) |
| 2739 | .build()); |
| 2740 | leftWindow->consumeMotionEvent( |
| 2741 | AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithDeviceId(mouseDeviceId))); |
| 2742 | |
| 2743 | // Stylus hovered on right window |
| 2744 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS) |
| 2745 | .deviceId(stylusDeviceId) |
| 2746 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(300).y(100)) |
| 2747 | .build()); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2748 | rightWindow->consumeMotionEvent( |
| 2749 | AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithDeviceId(stylusDeviceId))); |
| 2750 | |
| 2751 | // Subsequent HOVER_MOVE events are dispatched correctly. |
| 2752 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) |
| 2753 | .deviceId(mouseDeviceId) |
| 2754 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(110).y(120)) |
| 2755 | .build()); |
| 2756 | leftWindow->consumeMotionEvent( |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2757 | AllOf(WithMotionAction(ACTION_HOVER_MOVE), WithDeviceId(mouseDeviceId))); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2758 | |
| 2759 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_MOVE, AINPUT_SOURCE_STYLUS) |
| 2760 | .deviceId(stylusDeviceId) |
| 2761 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(310).y(110)) |
| 2762 | .build()); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2763 | rightWindow->consumeMotionEvent( |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2764 | AllOf(WithMotionAction(ACTION_HOVER_MOVE), WithDeviceId(stylusDeviceId))); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2765 | |
| 2766 | leftWindow->assertNoEvents(); |
| 2767 | rightWindow->assertNoEvents(); |
| 2768 | } |
| 2769 | |
| 2770 | /** |
| 2771 | * Three windows: a window on the left and a window on the right. |
| 2772 | * And a spy window that's positioned above all of them. |
| 2773 | * Stylus down on the left window and remains down. Touch goes down on the right and remains down. |
| 2774 | * Check the stream that's received by the spy. |
| 2775 | */ |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 2776 | TEST_F(InputDispatcherMultiDeviceTest, MultiDeviceWithSpy_legacy) { |
| 2777 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2778 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 2779 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 2780 | sp<FakeWindowHandle> spyWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Spy", |
| 2781 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2782 | spyWindow->setFrame(Rect(0, 0, 400, 400)); |
| 2783 | spyWindow->setTrustedOverlay(true); |
| 2784 | spyWindow->setSpy(true); |
| 2785 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 2786 | sp<FakeWindowHandle> leftWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Left", |
| 2787 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2788 | leftWindow->setFrame(Rect(0, 0, 200, 200)); |
| 2789 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 2790 | sp<FakeWindowHandle> rightWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Right", |
| 2791 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2792 | |
| 2793 | rightWindow->setFrame(Rect(200, 0, 400, 200)); |
| 2794 | |
| 2795 | mDispatcher->onWindowInfosChanged( |
| 2796 | {{*spyWindow->getInfo(), *leftWindow->getInfo(), *rightWindow->getInfo()}, {}, 0, 0}); |
| 2797 | |
| 2798 | const int32_t stylusDeviceId = 1; |
| 2799 | const int32_t touchDeviceId = 2; |
| 2800 | |
| 2801 | // Stylus down on the left window |
| 2802 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_STYLUS) |
| 2803 | .deviceId(stylusDeviceId) |
| 2804 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(100).y(100)) |
| 2805 | .build()); |
| 2806 | leftWindow->consumeMotionEvent( |
| 2807 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(stylusDeviceId))); |
| 2808 | spyWindow->consumeMotionEvent( |
| 2809 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(stylusDeviceId))); |
| 2810 | |
| 2811 | // Touch down on the right window |
| 2812 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 2813 | .deviceId(touchDeviceId) |
| 2814 | .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) |
| 2815 | .build()); |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2816 | leftWindow->assertNoEvents(); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2817 | rightWindow->consumeMotionEvent( |
| 2818 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(touchDeviceId))); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2819 | |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2820 | // Spy window does not receive touch events, because stylus events take precedence, and it |
| 2821 | // already has an active stylus gesture. |
| 2822 | |
| 2823 | // Stylus movements continue. They should be delivered to the left window and to the spy window |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2824 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_STYLUS) |
| 2825 | .deviceId(stylusDeviceId) |
| 2826 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(110).y(110)) |
| 2827 | .build()); |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2828 | leftWindow->consumeMotionEvent( |
| 2829 | AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(stylusDeviceId))); |
| 2830 | spyWindow->consumeMotionEvent( |
| 2831 | AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(stylusDeviceId))); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2832 | |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2833 | // Further MOVE events keep going to the right window only |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2834 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 2835 | .deviceId(touchDeviceId) |
| 2836 | .pointer(PointerBuilder(0, ToolType::FINGER).x(310).y(110)) |
| 2837 | .build()); |
| 2838 | rightWindow->consumeMotionEvent( |
| 2839 | AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(touchDeviceId))); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2840 | |
| 2841 | spyWindow->assertNoEvents(); |
| 2842 | leftWindow->assertNoEvents(); |
| 2843 | rightWindow->assertNoEvents(); |
| 2844 | } |
| 2845 | |
| 2846 | /** |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 2847 | * Three windows: a window on the left and a window on the right. |
| 2848 | * And a spy window that's positioned above all of them. |
| 2849 | * Stylus down on the left window and remains down. Touch goes down on the right and remains down. |
| 2850 | * Check the stream that's received by the spy. |
| 2851 | */ |
| 2852 | TEST_F(InputDispatcherMultiDeviceTest, MultiDeviceWithSpy) { |
| 2853 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); |
| 2854 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 2855 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 2856 | sp<FakeWindowHandle> spyWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Spy", |
| 2857 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 2858 | spyWindow->setFrame(Rect(0, 0, 400, 400)); |
| 2859 | spyWindow->setTrustedOverlay(true); |
| 2860 | spyWindow->setSpy(true); |
| 2861 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 2862 | sp<FakeWindowHandle> leftWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Left", |
| 2863 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 2864 | leftWindow->setFrame(Rect(0, 0, 200, 200)); |
| 2865 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 2866 | sp<FakeWindowHandle> rightWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Right", |
| 2867 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 2868 | |
| 2869 | rightWindow->setFrame(Rect(200, 0, 400, 200)); |
| 2870 | |
| 2871 | mDispatcher->onWindowInfosChanged( |
| 2872 | {{*spyWindow->getInfo(), *leftWindow->getInfo(), *rightWindow->getInfo()}, {}, 0, 0}); |
| 2873 | |
| 2874 | const int32_t stylusDeviceId = 1; |
| 2875 | const int32_t touchDeviceId = 2; |
| 2876 | |
| 2877 | // Stylus down on the left window |
| 2878 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_STYLUS) |
| 2879 | .deviceId(stylusDeviceId) |
| 2880 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(100).y(100)) |
| 2881 | .build()); |
| 2882 | leftWindow->consumeMotionEvent( |
| 2883 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(stylusDeviceId))); |
| 2884 | spyWindow->consumeMotionEvent( |
| 2885 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(stylusDeviceId))); |
| 2886 | |
| 2887 | // Touch down on the right window |
| 2888 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 2889 | .deviceId(touchDeviceId) |
| 2890 | .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) |
| 2891 | .build()); |
| 2892 | leftWindow->assertNoEvents(); |
| 2893 | rightWindow->consumeMotionEvent( |
| 2894 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(touchDeviceId))); |
| 2895 | spyWindow->consumeMotionEvent( |
| 2896 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(touchDeviceId))); |
| 2897 | |
| 2898 | // Stylus movements continue. They should be delivered to the left window and to the spy window |
| 2899 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_STYLUS) |
| 2900 | .deviceId(stylusDeviceId) |
| 2901 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(110).y(110)) |
| 2902 | .build()); |
| 2903 | leftWindow->consumeMotionEvent( |
| 2904 | AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(stylusDeviceId))); |
| 2905 | spyWindow->consumeMotionEvent( |
| 2906 | AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(stylusDeviceId))); |
| 2907 | |
| 2908 | // Further touch MOVE events keep going to the right window and to the spy |
| 2909 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 2910 | .deviceId(touchDeviceId) |
| 2911 | .pointer(PointerBuilder(0, ToolType::FINGER).x(310).y(110)) |
| 2912 | .build()); |
| 2913 | rightWindow->consumeMotionEvent( |
| 2914 | AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(touchDeviceId))); |
| 2915 | spyWindow->consumeMotionEvent( |
| 2916 | AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(touchDeviceId))); |
| 2917 | |
| 2918 | spyWindow->assertNoEvents(); |
| 2919 | leftWindow->assertNoEvents(); |
| 2920 | rightWindow->assertNoEvents(); |
| 2921 | } |
| 2922 | |
| 2923 | /** |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2924 | * Three windows: a window on the left, a window on the right, and a spy window positioned above |
| 2925 | * both. |
| 2926 | * Check hover in left window and touch down in the right window. |
Siarhei Vishniakou | 3ad54f5 | 2023-11-02 16:54:40 -0700 | [diff] [blame] | 2927 | * At first, spy should receive hover. Spy shouldn't receive touch while stylus is hovering. |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2928 | * At the same time, left and right should be getting independent streams of hovering and touch, |
| 2929 | * respectively. |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2930 | */ |
Siarhei Vishniakou | 3ad54f5 | 2023-11-02 16:54:40 -0700 | [diff] [blame] | 2931 | TEST_F(InputDispatcherMultiDeviceTest, MultiDeviceHoverBlocksTouchWithSpy) { |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 2932 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2933 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 2934 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 2935 | sp<FakeWindowHandle> spyWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Spy", |
| 2936 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2937 | spyWindow->setFrame(Rect(0, 0, 400, 400)); |
| 2938 | spyWindow->setTrustedOverlay(true); |
| 2939 | spyWindow->setSpy(true); |
| 2940 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 2941 | sp<FakeWindowHandle> leftWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Left", |
| 2942 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2943 | leftWindow->setFrame(Rect(0, 0, 200, 200)); |
| 2944 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 2945 | sp<FakeWindowHandle> rightWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Right", |
| 2946 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2947 | rightWindow->setFrame(Rect(200, 0, 400, 200)); |
| 2948 | |
| 2949 | mDispatcher->onWindowInfosChanged( |
| 2950 | {{*spyWindow->getInfo(), *leftWindow->getInfo(), *rightWindow->getInfo()}, {}, 0, 0}); |
| 2951 | |
| 2952 | const int32_t stylusDeviceId = 1; |
| 2953 | const int32_t touchDeviceId = 2; |
| 2954 | |
| 2955 | // Stylus hover on the left window |
| 2956 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS) |
| 2957 | .deviceId(stylusDeviceId) |
| 2958 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(100).y(100)) |
| 2959 | .build()); |
| 2960 | leftWindow->consumeMotionEvent( |
| 2961 | AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithDeviceId(stylusDeviceId))); |
| 2962 | spyWindow->consumeMotionEvent( |
| 2963 | AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithDeviceId(stylusDeviceId))); |
| 2964 | |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2965 | // Touch down on the right window. Spy doesn't receive this touch because it already has |
| 2966 | // stylus hovering there. |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2967 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 2968 | .deviceId(touchDeviceId) |
| 2969 | .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) |
| 2970 | .build()); |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2971 | leftWindow->assertNoEvents(); |
Siarhei Vishniakou | 3ad54f5 | 2023-11-02 16:54:40 -0700 | [diff] [blame] | 2972 | spyWindow->assertNoEvents(); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2973 | rightWindow->consumeMotionEvent( |
| 2974 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(touchDeviceId))); |
| 2975 | |
Siarhei Vishniakou | 3ad54f5 | 2023-11-02 16:54:40 -0700 | [diff] [blame] | 2976 | // Stylus movements continue. They should be delivered to the left window and the spy. |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2977 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_MOVE, AINPUT_SOURCE_STYLUS) |
| 2978 | .deviceId(stylusDeviceId) |
| 2979 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(110).y(110)) |
| 2980 | .build()); |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 2981 | leftWindow->consumeMotionEvent( |
| 2982 | AllOf(WithMotionAction(ACTION_HOVER_MOVE), WithDeviceId(stylusDeviceId))); |
Siarhei Vishniakou | 3ad54f5 | 2023-11-02 16:54:40 -0700 | [diff] [blame] | 2983 | spyWindow->consumeMotionEvent( |
| 2984 | AllOf(WithMotionAction(ACTION_HOVER_MOVE), WithDeviceId(stylusDeviceId))); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2985 | |
Siarhei Vishniakou | 3ad54f5 | 2023-11-02 16:54:40 -0700 | [diff] [blame] | 2986 | // Touch movements continue. They should be delivered to the right window only |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2987 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 2988 | .deviceId(touchDeviceId) |
| 2989 | .pointer(PointerBuilder(0, ToolType::FINGER).x(301).y(101)) |
| 2990 | .build()); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 2991 | rightWindow->consumeMotionEvent( |
| 2992 | AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(touchDeviceId))); |
| 2993 | |
| 2994 | spyWindow->assertNoEvents(); |
| 2995 | leftWindow->assertNoEvents(); |
| 2996 | rightWindow->assertNoEvents(); |
| 2997 | } |
| 2998 | |
| 2999 | /** |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 3000 | * Three windows: a window on the left, a window on the right, and a spy window positioned above |
| 3001 | * both. |
| 3002 | * Check hover in left window and touch down in the right window. |
| 3003 | * At first, spy should receive hover. Next, spy should receive touch. |
| 3004 | * At the same time, left and right should be getting independent streams of hovering and touch, |
| 3005 | * respectively. |
| 3006 | */ |
| 3007 | TEST_F(InputDispatcherMultiDeviceTest, MultiDeviceHoverDoesNotBlockTouchWithSpy) { |
| 3008 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); |
| 3009 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 3010 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 3011 | sp<FakeWindowHandle> spyWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Spy", |
| 3012 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 3013 | spyWindow->setFrame(Rect(0, 0, 400, 400)); |
| 3014 | spyWindow->setTrustedOverlay(true); |
| 3015 | spyWindow->setSpy(true); |
| 3016 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 3017 | sp<FakeWindowHandle> leftWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Left", |
| 3018 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 3019 | leftWindow->setFrame(Rect(0, 0, 200, 200)); |
| 3020 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 3021 | sp<FakeWindowHandle> rightWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Right", |
| 3022 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 3023 | rightWindow->setFrame(Rect(200, 0, 400, 200)); |
| 3024 | |
| 3025 | mDispatcher->onWindowInfosChanged( |
| 3026 | {{*spyWindow->getInfo(), *leftWindow->getInfo(), *rightWindow->getInfo()}, {}, 0, 0}); |
| 3027 | |
| 3028 | const int32_t stylusDeviceId = 1; |
| 3029 | const int32_t touchDeviceId = 2; |
| 3030 | |
| 3031 | // Stylus hover on the left window |
| 3032 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS) |
| 3033 | .deviceId(stylusDeviceId) |
| 3034 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(100).y(100)) |
| 3035 | .build()); |
| 3036 | leftWindow->consumeMotionEvent( |
| 3037 | AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithDeviceId(stylusDeviceId))); |
| 3038 | spyWindow->consumeMotionEvent( |
| 3039 | AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithDeviceId(stylusDeviceId))); |
| 3040 | |
| 3041 | // Touch down on the right window. |
| 3042 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 3043 | .deviceId(touchDeviceId) |
| 3044 | .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) |
| 3045 | .build()); |
| 3046 | leftWindow->assertNoEvents(); |
| 3047 | spyWindow->consumeMotionEvent( |
| 3048 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(touchDeviceId))); |
| 3049 | rightWindow->consumeMotionEvent( |
| 3050 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(touchDeviceId))); |
| 3051 | |
| 3052 | // Stylus movements continue. They should be delivered to the left window and the spy. |
| 3053 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_MOVE, AINPUT_SOURCE_STYLUS) |
| 3054 | .deviceId(stylusDeviceId) |
| 3055 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(110).y(110)) |
| 3056 | .build()); |
| 3057 | leftWindow->consumeMotionEvent( |
| 3058 | AllOf(WithMotionAction(ACTION_HOVER_MOVE), WithDeviceId(stylusDeviceId))); |
| 3059 | spyWindow->consumeMotionEvent( |
| 3060 | AllOf(WithMotionAction(ACTION_HOVER_MOVE), WithDeviceId(stylusDeviceId))); |
| 3061 | |
| 3062 | // Touch movements continue. They should be delivered to the right window and the spy |
| 3063 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 3064 | .deviceId(touchDeviceId) |
| 3065 | .pointer(PointerBuilder(0, ToolType::FINGER).x(301).y(101)) |
| 3066 | .build()); |
| 3067 | rightWindow->consumeMotionEvent( |
| 3068 | AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(touchDeviceId))); |
| 3069 | spyWindow->consumeMotionEvent( |
| 3070 | AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(touchDeviceId))); |
| 3071 | |
| 3072 | spyWindow->assertNoEvents(); |
| 3073 | leftWindow->assertNoEvents(); |
| 3074 | rightWindow->assertNoEvents(); |
| 3075 | } |
| 3076 | |
| 3077 | /** |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3078 | * On a single window, use two different devices: mouse and touch. |
| 3079 | * Touch happens first, with two pointers going down, and then the first pointer leaving. |
| 3080 | * Mouse is clicked next, which causes the touch stream to be aborted with ACTION_CANCEL. |
| 3081 | * Finally, a second touch pointer goes down again. Ensure the second touch pointer is ignored, |
| 3082 | * because the mouse is currently down, and a POINTER_DOWN event from the touchscreen does not |
| 3083 | * represent a new gesture. |
| 3084 | */ |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 3085 | TEST_F(InputDispatcherMultiDeviceTest, MixedTouchAndMouseWithPointerDown_legacy) { |
| 3086 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3087 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 3088 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 3089 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3090 | window->setFrame(Rect(0, 0, 400, 400)); |
| 3091 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 3092 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3093 | |
| 3094 | const int32_t touchDeviceId = 4; |
| 3095 | const int32_t mouseDeviceId = 6; |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3096 | |
Siarhei Vishniakou | 4e1ffa5 | 2023-02-21 11:50:34 -0800 | [diff] [blame] | 3097 | // First touch pointer down |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 3098 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 3099 | .deviceId(touchDeviceId) |
| 3100 | .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) |
| 3101 | .build()); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3102 | // Second touch pointer down |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 3103 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 3104 | .deviceId(touchDeviceId) |
| 3105 | .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) |
| 3106 | .pointer(PointerBuilder(1, ToolType::FINGER).x(350).y(100)) |
| 3107 | .build()); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3108 | // First touch pointer lifts. The second one remains down |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 3109 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_0_UP, AINPUT_SOURCE_TOUCHSCREEN) |
| 3110 | .deviceId(touchDeviceId) |
| 3111 | .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) |
| 3112 | .pointer(PointerBuilder(1, ToolType::FINGER).x(350).y(100)) |
| 3113 | .build()); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3114 | window->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); |
| 3115 | window->consumeMotionEvent(WithMotionAction(POINTER_1_DOWN)); |
| 3116 | window->consumeMotionEvent(WithMotionAction(POINTER_0_UP)); |
| 3117 | |
| 3118 | // Mouse down. The touch should be canceled |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 3119 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_MOUSE) |
| 3120 | .deviceId(mouseDeviceId) |
| 3121 | .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) |
| 3122 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(320).y(100)) |
| 3123 | .build()); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3124 | |
| 3125 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_CANCEL), WithDeviceId(touchDeviceId), |
Siarhei Vishniakou | 82dc042 | 2023-02-17 23:12:52 -0800 | [diff] [blame] | 3126 | WithPointerCount(1u))); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3127 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(mouseDeviceId))); |
| 3128 | |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 3129 | mDispatcher->notifyMotion( |
| 3130 | MotionArgsBuilder(AMOTION_EVENT_ACTION_BUTTON_PRESS, AINPUT_SOURCE_MOUSE) |
| 3131 | .deviceId(mouseDeviceId) |
| 3132 | .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) |
| 3133 | .actionButton(AMOTION_EVENT_BUTTON_PRIMARY) |
| 3134 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(320).y(100)) |
| 3135 | .build()); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3136 | window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS)); |
| 3137 | |
| 3138 | // Second touch pointer down. |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 3139 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_0_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 3140 | .deviceId(touchDeviceId) |
| 3141 | .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) |
| 3142 | .pointer(PointerBuilder(1, ToolType::FINGER).x(350).y(100)) |
| 3143 | .build()); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 3144 | // Since we already canceled this touch gesture, it will be ignored until a completely new |
| 3145 | // gesture is started. This is easier to implement than trying to keep track of the new pointer |
| 3146 | // and generating an ACTION_DOWN instead of ACTION_POINTER_DOWN. |
| 3147 | // However, mouse movements should continue to work. |
| 3148 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_MOUSE) |
| 3149 | .deviceId(mouseDeviceId) |
| 3150 | .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) |
| 3151 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(330).y(110)) |
| 3152 | .build()); |
| 3153 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(mouseDeviceId))); |
| 3154 | |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3155 | window->assertNoEvents(); |
| 3156 | } |
| 3157 | |
| 3158 | /** |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 3159 | * On a single window, use two different devices: mouse and touch. |
| 3160 | * Touch happens first, with two pointers going down, and then the first pointer leaving. |
| 3161 | * Mouse is clicked next, which should not interfere with the touch stream. |
| 3162 | * Finally, a second touch pointer goes down again. Ensure the second touch pointer is also |
| 3163 | * delivered correctly. |
| 3164 | */ |
| 3165 | TEST_F(InputDispatcherMultiDeviceTest, MixedTouchAndMouseWithPointerDown) { |
| 3166 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); |
| 3167 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 3168 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 3169 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 3170 | window->setFrame(Rect(0, 0, 400, 400)); |
| 3171 | |
| 3172 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
| 3173 | |
| 3174 | const int32_t touchDeviceId = 4; |
| 3175 | const int32_t mouseDeviceId = 6; |
| 3176 | |
| 3177 | // First touch pointer down |
| 3178 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 3179 | .deviceId(touchDeviceId) |
| 3180 | .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) |
| 3181 | .build()); |
| 3182 | // Second touch pointer down |
| 3183 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 3184 | .deviceId(touchDeviceId) |
| 3185 | .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) |
| 3186 | .pointer(PointerBuilder(1, ToolType::FINGER).x(350).y(100)) |
| 3187 | .build()); |
| 3188 | // First touch pointer lifts. The second one remains down |
| 3189 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_0_UP, AINPUT_SOURCE_TOUCHSCREEN) |
| 3190 | .deviceId(touchDeviceId) |
| 3191 | .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) |
| 3192 | .pointer(PointerBuilder(1, ToolType::FINGER).x(350).y(100)) |
| 3193 | .build()); |
| 3194 | window->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); |
| 3195 | window->consumeMotionEvent(WithMotionAction(POINTER_1_DOWN)); |
| 3196 | window->consumeMotionEvent(WithMotionAction(POINTER_0_UP)); |
| 3197 | |
| 3198 | // Mouse down |
| 3199 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_MOUSE) |
| 3200 | .deviceId(mouseDeviceId) |
| 3201 | .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) |
| 3202 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(320).y(100)) |
| 3203 | .build()); |
| 3204 | |
| 3205 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(mouseDeviceId))); |
| 3206 | |
| 3207 | mDispatcher->notifyMotion( |
| 3208 | MotionArgsBuilder(AMOTION_EVENT_ACTION_BUTTON_PRESS, AINPUT_SOURCE_MOUSE) |
| 3209 | .deviceId(mouseDeviceId) |
| 3210 | .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) |
| 3211 | .actionButton(AMOTION_EVENT_BUTTON_PRIMARY) |
| 3212 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(320).y(100)) |
| 3213 | .build()); |
| 3214 | window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS)); |
| 3215 | |
| 3216 | // Second touch pointer down. |
| 3217 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_0_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 3218 | .deviceId(touchDeviceId) |
| 3219 | .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) |
| 3220 | .pointer(PointerBuilder(1, ToolType::FINGER).x(350).y(100)) |
| 3221 | .build()); |
| 3222 | window->consumeMotionEvent(AllOf(WithMotionAction(POINTER_0_DOWN), WithDeviceId(touchDeviceId), |
| 3223 | WithPointerCount(2u))); |
| 3224 | |
| 3225 | // Mouse movements should continue to work |
| 3226 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_MOUSE) |
| 3227 | .deviceId(mouseDeviceId) |
| 3228 | .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) |
| 3229 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(330).y(110)) |
| 3230 | .build()); |
| 3231 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(mouseDeviceId))); |
| 3232 | |
| 3233 | window->assertNoEvents(); |
| 3234 | } |
| 3235 | |
| 3236 | /** |
Siarhei Vishniakou | 56e7909 | 2023-02-21 19:13:16 -0800 | [diff] [blame] | 3237 | * Inject a touch down and then send a new event via 'notifyMotion'. Ensure the new event cancels |
| 3238 | * the injected event. |
| 3239 | */ |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 3240 | TEST_F(InputDispatcherMultiDeviceTest, UnfinishedInjectedEvent_legacy) { |
| 3241 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); |
Siarhei Vishniakou | 56e7909 | 2023-02-21 19:13:16 -0800 | [diff] [blame] | 3242 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 3243 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 3244 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 56e7909 | 2023-02-21 19:13:16 -0800 | [diff] [blame] | 3245 | window->setFrame(Rect(0, 0, 400, 400)); |
| 3246 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 3247 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | 56e7909 | 2023-02-21 19:13:16 -0800 | [diff] [blame] | 3248 | |
| 3249 | const int32_t touchDeviceId = 4; |
Siarhei Vishniakou | 56e7909 | 2023-02-21 19:13:16 -0800 | [diff] [blame] | 3250 | // Pretend a test injects an ACTION_DOWN mouse event, but forgets to lift up the touch after |
| 3251 | // completion. |
| 3252 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 3253 | injectMotionEvent(*mDispatcher, |
Siarhei Vishniakou | 56e7909 | 2023-02-21 19:13:16 -0800 | [diff] [blame] | 3254 | MotionEventBuilder(ACTION_DOWN, AINPUT_SOURCE_MOUSE) |
| 3255 | .deviceId(ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID) |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 3256 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(50).y(50)) |
Siarhei Vishniakou | 56e7909 | 2023-02-21 19:13:16 -0800 | [diff] [blame] | 3257 | .build())); |
| 3258 | window->consumeMotionEvent( |
| 3259 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(VIRTUAL_KEYBOARD_ID))); |
| 3260 | |
| 3261 | // Now a real touch comes. Rather than crashing or dropping the real event, the injected pointer |
| 3262 | // should be canceled and the new gesture should take over. |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 3263 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 3264 | .deviceId(touchDeviceId) |
| 3265 | .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) |
| 3266 | .build()); |
Siarhei Vishniakou | 56e7909 | 2023-02-21 19:13:16 -0800 | [diff] [blame] | 3267 | |
| 3268 | window->consumeMotionEvent( |
| 3269 | AllOf(WithMotionAction(ACTION_CANCEL), WithDeviceId(VIRTUAL_KEYBOARD_ID))); |
| 3270 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(touchDeviceId))); |
| 3271 | } |
| 3272 | |
| 3273 | /** |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 3274 | * Inject a touch down and then send a new event via 'notifyMotion'. Ensure the new event runs |
| 3275 | * parallel to the injected event. |
| 3276 | */ |
| 3277 | TEST_F(InputDispatcherMultiDeviceTest, UnfinishedInjectedEvent) { |
| 3278 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); |
| 3279 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 3280 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 3281 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 3282 | window->setFrame(Rect(0, 0, 400, 400)); |
| 3283 | |
| 3284 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
| 3285 | |
| 3286 | const int32_t touchDeviceId = 4; |
| 3287 | // Pretend a test injects an ACTION_DOWN mouse event, but forgets to lift up the touch after |
| 3288 | // completion. |
| 3289 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
| 3290 | injectMotionEvent(*mDispatcher, |
| 3291 | MotionEventBuilder(ACTION_DOWN, AINPUT_SOURCE_MOUSE) |
| 3292 | .deviceId(ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID) |
| 3293 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(50).y(50)) |
| 3294 | .build())); |
| 3295 | window->consumeMotionEvent( |
| 3296 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(VIRTUAL_KEYBOARD_ID))); |
| 3297 | |
| 3298 | // Now a real touch comes. The injected pointer will remain, and the new gesture will also be |
| 3299 | // allowed through. |
| 3300 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 3301 | .deviceId(touchDeviceId) |
| 3302 | .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) |
| 3303 | .build()); |
| 3304 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(touchDeviceId))); |
| 3305 | } |
| 3306 | |
| 3307 | /** |
Siarhei Vishniakou | 6464e46 | 2023-02-06 18:57:59 -0800 | [diff] [blame] | 3308 | * This test is similar to the test above, but the sequence of injected events is different. |
| 3309 | * |
| 3310 | * Two windows: a window on the left and a window on the right. |
| 3311 | * Mouse is hovered over the left window. |
| 3312 | * Next, we tap on the left window, where the cursor was last seen. |
| 3313 | * |
| 3314 | * After that, we inject one finger down onto the right window, and then a second finger down onto |
| 3315 | * the left window. |
| 3316 | * The touch is split, so this last gesture should cause 2 ACTION_DOWN events, one in the right |
| 3317 | * window (first), and then another on the left window (second). |
| 3318 | * This test reproduces a crash where there is a mismatch between the downTime and eventTime. |
| 3319 | * In the buggy implementation, second finger down on the left window would cause a crash. |
| 3320 | */ |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 3321 | TEST_F(InputDispatcherMultiDeviceTest, HoverTapAndSplitTouch_legacy) { |
| 3322 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); |
Siarhei Vishniakou | 6464e46 | 2023-02-06 18:57:59 -0800 | [diff] [blame] | 3323 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 3324 | sp<FakeWindowHandle> leftWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Left", |
| 3325 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 6464e46 | 2023-02-06 18:57:59 -0800 | [diff] [blame] | 3326 | leftWindow->setFrame(Rect(0, 0, 200, 200)); |
| 3327 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 3328 | sp<FakeWindowHandle> rightWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Right", |
| 3329 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 6464e46 | 2023-02-06 18:57:59 -0800 | [diff] [blame] | 3330 | rightWindow->setFrame(Rect(200, 0, 400, 200)); |
| 3331 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 3332 | mDispatcher->onWindowInfosChanged( |
| 3333 | {{*leftWindow->getInfo(), *rightWindow->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | 6464e46 | 2023-02-06 18:57:59 -0800 | [diff] [blame] | 3334 | |
| 3335 | const int32_t mouseDeviceId = 6; |
| 3336 | const int32_t touchDeviceId = 4; |
| 3337 | // Hover over the left window. Keep the cursor there. |
| 3338 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 3339 | injectMotionEvent(*mDispatcher, |
Siarhei Vishniakou | 6464e46 | 2023-02-06 18:57:59 -0800 | [diff] [blame] | 3340 | MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_ENTER, |
| 3341 | AINPUT_SOURCE_MOUSE) |
| 3342 | .deviceId(mouseDeviceId) |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 3343 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(50).y(50)) |
Siarhei Vishniakou | 6464e46 | 2023-02-06 18:57:59 -0800 | [diff] [blame] | 3344 | .build())); |
| 3345 | leftWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)); |
| 3346 | |
| 3347 | // Tap on left window |
| 3348 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 3349 | injectMotionEvent(*mDispatcher, |
Siarhei Vishniakou | 6464e46 | 2023-02-06 18:57:59 -0800 | [diff] [blame] | 3350 | MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, |
| 3351 | AINPUT_SOURCE_TOUCHSCREEN) |
| 3352 | .deviceId(touchDeviceId) |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 3353 | .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) |
Siarhei Vishniakou | 6464e46 | 2023-02-06 18:57:59 -0800 | [diff] [blame] | 3354 | .build())); |
| 3355 | |
| 3356 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 3357 | injectMotionEvent(*mDispatcher, |
Siarhei Vishniakou | 6464e46 | 2023-02-06 18:57:59 -0800 | [diff] [blame] | 3358 | MotionEventBuilder(AMOTION_EVENT_ACTION_UP, |
| 3359 | AINPUT_SOURCE_TOUCHSCREEN) |
| 3360 | .deviceId(touchDeviceId) |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 3361 | .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) |
Siarhei Vishniakou | 6464e46 | 2023-02-06 18:57:59 -0800 | [diff] [blame] | 3362 | .build())); |
| 3363 | leftWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)); |
| 3364 | leftWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_DOWN)); |
| 3365 | leftWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_UP)); |
| 3366 | |
| 3367 | // First finger down on right window |
| 3368 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 3369 | injectMotionEvent(*mDispatcher, |
Siarhei Vishniakou | 6464e46 | 2023-02-06 18:57:59 -0800 | [diff] [blame] | 3370 | MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, |
| 3371 | AINPUT_SOURCE_TOUCHSCREEN) |
| 3372 | .deviceId(touchDeviceId) |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 3373 | .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) |
Siarhei Vishniakou | 6464e46 | 2023-02-06 18:57:59 -0800 | [diff] [blame] | 3374 | .build())); |
| 3375 | rightWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_DOWN)); |
| 3376 | |
| 3377 | // Second finger down on the left window |
| 3378 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 3379 | injectMotionEvent(*mDispatcher, |
Siarhei Vishniakou | 6464e46 | 2023-02-06 18:57:59 -0800 | [diff] [blame] | 3380 | MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 3381 | .deviceId(touchDeviceId) |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 3382 | .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) |
| 3383 | .pointer(PointerBuilder(1, ToolType::FINGER).x(100).y(100)) |
Siarhei Vishniakou | 6464e46 | 2023-02-06 18:57:59 -0800 | [diff] [blame] | 3384 | .build())); |
| 3385 | leftWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_DOWN)); |
| 3386 | rightWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_MOVE)); |
| 3387 | |
| 3388 | // No more events |
| 3389 | leftWindow->assertNoEvents(); |
| 3390 | rightWindow->assertNoEvents(); |
| 3391 | } |
| 3392 | |
| 3393 | /** |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 3394 | * This test is similar to the test above, but the sequence of injected events is different. |
| 3395 | * |
| 3396 | * Two windows: a window on the left and a window on the right. |
| 3397 | * Mouse is hovered over the left window. |
| 3398 | * Next, we tap on the left window, where the cursor was last seen. |
| 3399 | * |
| 3400 | * After that, we send one finger down onto the right window, and then a second finger down onto |
| 3401 | * the left window. |
| 3402 | * The touch is split, so this last gesture should cause 2 ACTION_DOWN events, one in the right |
| 3403 | * window (first), and then another on the left window (second). |
| 3404 | * This test reproduces a crash where there is a mismatch between the downTime and eventTime. |
| 3405 | * In the buggy implementation, second finger down on the left window would cause a crash. |
| 3406 | */ |
| 3407 | TEST_F(InputDispatcherMultiDeviceTest, HoverTapAndSplitTouch) { |
| 3408 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); |
| 3409 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 3410 | sp<FakeWindowHandle> leftWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Left", |
| 3411 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 3412 | leftWindow->setFrame(Rect(0, 0, 200, 200)); |
| 3413 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 3414 | sp<FakeWindowHandle> rightWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Right", |
| 3415 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 3416 | rightWindow->setFrame(Rect(200, 0, 400, 200)); |
| 3417 | |
| 3418 | mDispatcher->onWindowInfosChanged( |
| 3419 | {{*leftWindow->getInfo(), *rightWindow->getInfo()}, {}, 0, 0}); |
| 3420 | |
| 3421 | const int32_t mouseDeviceId = 6; |
| 3422 | const int32_t touchDeviceId = 4; |
| 3423 | // Hover over the left window. Keep the cursor there. |
| 3424 | mDispatcher->notifyMotion( |
| 3425 | MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE) |
| 3426 | .deviceId(mouseDeviceId) |
| 3427 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(50).y(50)) |
| 3428 | .build()); |
| 3429 | leftWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)); |
| 3430 | |
| 3431 | // Tap on left window |
| 3432 | mDispatcher->notifyMotion( |
| 3433 | MotionArgsBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 3434 | .deviceId(touchDeviceId) |
| 3435 | .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) |
| 3436 | .build()); |
| 3437 | |
| 3438 | mDispatcher->notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN) |
| 3439 | .deviceId(touchDeviceId) |
| 3440 | .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) |
| 3441 | .build()); |
| 3442 | leftWindow->consumeMotionEvent( |
| 3443 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithDeviceId(touchDeviceId))); |
| 3444 | leftWindow->consumeMotionEvent( |
| 3445 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithDeviceId(touchDeviceId))); |
| 3446 | |
| 3447 | // First finger down on right window |
| 3448 | mDispatcher->notifyMotion( |
| 3449 | MotionArgsBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 3450 | .deviceId(touchDeviceId) |
| 3451 | .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) |
| 3452 | .build()); |
| 3453 | rightWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_DOWN)); |
| 3454 | |
| 3455 | // Second finger down on the left window |
| 3456 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 3457 | .deviceId(touchDeviceId) |
| 3458 | .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) |
| 3459 | .pointer(PointerBuilder(1, ToolType::FINGER).x(100).y(100)) |
| 3460 | .build()); |
| 3461 | leftWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_DOWN)); |
| 3462 | rightWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_MOVE)); |
| 3463 | |
| 3464 | // No more events |
| 3465 | leftWindow->assertNoEvents(); |
| 3466 | rightWindow->assertNoEvents(); |
| 3467 | } |
| 3468 | |
| 3469 | /** |
Siarhei Vishniakou | 2e3e443 | 2023-02-09 18:34:11 -0800 | [diff] [blame] | 3470 | * Start hovering with a stylus device, and then tap with a touch device. Ensure no crash occurs. |
| 3471 | * While the touch is down, new hover events from the stylus device should be ignored. After the |
| 3472 | * touch is gone, stylus hovering should start working again. |
| 3473 | */ |
Siarhei Vishniakou | 3ad54f5 | 2023-11-02 16:54:40 -0700 | [diff] [blame] | 3474 | TEST_F(InputDispatcherMultiDeviceTest, StylusHoverIgnoresTouchTap) { |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 3475 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); |
Siarhei Vishniakou | 2e3e443 | 2023-02-09 18:34:11 -0800 | [diff] [blame] | 3476 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 3477 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 3478 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 2e3e443 | 2023-02-09 18:34:11 -0800 | [diff] [blame] | 3479 | window->setFrame(Rect(0, 0, 200, 200)); |
| 3480 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 3481 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | 2e3e443 | 2023-02-09 18:34:11 -0800 | [diff] [blame] | 3482 | |
| 3483 | const int32_t stylusDeviceId = 5; |
| 3484 | const int32_t touchDeviceId = 4; |
| 3485 | // Start hovering with stylus |
| 3486 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 3487 | injectMotionEvent(*mDispatcher, |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 3488 | MotionEventBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS) |
Siarhei Vishniakou | 2e3e443 | 2023-02-09 18:34:11 -0800 | [diff] [blame] | 3489 | .deviceId(stylusDeviceId) |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 3490 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50)) |
Siarhei Vishniakou | 2e3e443 | 2023-02-09 18:34:11 -0800 | [diff] [blame] | 3491 | .build())); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 3492 | window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); |
Siarhei Vishniakou | 2e3e443 | 2023-02-09 18:34:11 -0800 | [diff] [blame] | 3493 | |
| 3494 | // Finger down on the window |
| 3495 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 3496 | injectMotionEvent(*mDispatcher, |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 3497 | MotionEventBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
Siarhei Vishniakou | 2e3e443 | 2023-02-09 18:34:11 -0800 | [diff] [blame] | 3498 | .deviceId(touchDeviceId) |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 3499 | .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) |
Siarhei Vishniakou | 2e3e443 | 2023-02-09 18:34:11 -0800 | [diff] [blame] | 3500 | .build())); |
Siarhei Vishniakou | 3ad54f5 | 2023-11-02 16:54:40 -0700 | [diff] [blame] | 3501 | // The touch device should be ignored! |
Siarhei Vishniakou | 2e3e443 | 2023-02-09 18:34:11 -0800 | [diff] [blame] | 3502 | |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 3503 | // Continue hovering with stylus. |
| 3504 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 3505 | injectMotionEvent(*mDispatcher, |
Siarhei Vishniakou | 2e3e443 | 2023-02-09 18:34:11 -0800 | [diff] [blame] | 3506 | MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, |
| 3507 | AINPUT_SOURCE_STYLUS) |
| 3508 | .deviceId(stylusDeviceId) |
Siarhei Vishniakou | 25537f8 | 2023-07-18 14:35:47 -0700 | [diff] [blame] | 3509 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(60).y(60)) |
Siarhei Vishniakou | 2e3e443 | 2023-02-09 18:34:11 -0800 | [diff] [blame] | 3510 | .build())); |
Siarhei Vishniakou | 3ad54f5 | 2023-11-02 16:54:40 -0700 | [diff] [blame] | 3511 | // Hovers continue to work |
| 3512 | window->consumeMotionEvent( |
| 3513 | AllOf(WithMotionAction(ACTION_HOVER_MOVE), WithDeviceId(stylusDeviceId))); |
Siarhei Vishniakou | 2e3e443 | 2023-02-09 18:34:11 -0800 | [diff] [blame] | 3514 | |
| 3515 | // Lift up the finger |
| 3516 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 3517 | injectMotionEvent(*mDispatcher, |
Siarhei Vishniakou | 2e3e443 | 2023-02-09 18:34:11 -0800 | [diff] [blame] | 3518 | MotionEventBuilder(AMOTION_EVENT_ACTION_UP, |
| 3519 | AINPUT_SOURCE_TOUCHSCREEN) |
| 3520 | .deviceId(touchDeviceId) |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 3521 | .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) |
Siarhei Vishniakou | 2e3e443 | 2023-02-09 18:34:11 -0800 | [diff] [blame] | 3522 | .build())); |
Siarhei Vishniakou | 2e3e443 | 2023-02-09 18:34:11 -0800 | [diff] [blame] | 3523 | |
Siarhei Vishniakou | 2e3e443 | 2023-02-09 18:34:11 -0800 | [diff] [blame] | 3524 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 3525 | injectMotionEvent(*mDispatcher, |
Siarhei Vishniakou | 2e3e443 | 2023-02-09 18:34:11 -0800 | [diff] [blame] | 3526 | MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, |
| 3527 | AINPUT_SOURCE_STYLUS) |
| 3528 | .deviceId(stylusDeviceId) |
Siarhei Vishniakou | 25537f8 | 2023-07-18 14:35:47 -0700 | [diff] [blame] | 3529 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(70).y(70)) |
Siarhei Vishniakou | 2e3e443 | 2023-02-09 18:34:11 -0800 | [diff] [blame] | 3530 | .build())); |
Siarhei Vishniakou | 3ad54f5 | 2023-11-02 16:54:40 -0700 | [diff] [blame] | 3531 | window->consumeMotionEvent( |
| 3532 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithDeviceId(stylusDeviceId))); |
Siarhei Vishniakou | 2e3e443 | 2023-02-09 18:34:11 -0800 | [diff] [blame] | 3533 | window->assertNoEvents(); |
| 3534 | } |
| 3535 | |
| 3536 | /** |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 3537 | * Start hovering with a stylus device, and then tap with a touch device. Ensure no crash occurs. |
| 3538 | * While the touch is down, hovering from the stylus is not affected. After the touch is gone, |
| 3539 | * check that the stylus hovering continues to work. |
| 3540 | */ |
| 3541 | TEST_F(InputDispatcherMultiDeviceTest, StylusHoverWithTouchTap) { |
| 3542 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); |
| 3543 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 3544 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 3545 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 3546 | window->setFrame(Rect(0, 0, 200, 200)); |
| 3547 | |
| 3548 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
| 3549 | |
| 3550 | const int32_t stylusDeviceId = 5; |
| 3551 | const int32_t touchDeviceId = 4; |
| 3552 | // Start hovering with stylus |
| 3553 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS) |
| 3554 | .deviceId(stylusDeviceId) |
| 3555 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50)) |
| 3556 | .build()); |
| 3557 | window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); |
| 3558 | |
| 3559 | // Finger down on the window |
| 3560 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 3561 | .deviceId(touchDeviceId) |
| 3562 | .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) |
| 3563 | .build()); |
| 3564 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(touchDeviceId))); |
| 3565 | |
| 3566 | // Continue hovering with stylus. |
| 3567 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_MOVE, AINPUT_SOURCE_STYLUS) |
| 3568 | .deviceId(stylusDeviceId) |
| 3569 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(60).y(60)) |
| 3570 | .build()); |
| 3571 | // Hovers continue to work |
| 3572 | window->consumeMotionEvent( |
| 3573 | AllOf(WithMotionAction(ACTION_HOVER_MOVE), WithDeviceId(stylusDeviceId))); |
| 3574 | |
| 3575 | // Lift up the finger |
| 3576 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN) |
| 3577 | .deviceId(touchDeviceId) |
| 3578 | .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) |
| 3579 | .build()); |
| 3580 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_UP), WithDeviceId(touchDeviceId))); |
| 3581 | |
| 3582 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_MOVE, AINPUT_SOURCE_STYLUS) |
| 3583 | .deviceId(stylusDeviceId) |
| 3584 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(70).y(70)) |
| 3585 | .build()); |
| 3586 | window->consumeMotionEvent( |
| 3587 | AllOf(WithMotionAction(ACTION_HOVER_MOVE), WithDeviceId(stylusDeviceId))); |
| 3588 | window->assertNoEvents(); |
| 3589 | } |
| 3590 | |
| 3591 | /** |
Siarhei Vishniakou | f77f60a | 2023-10-23 17:26:05 -0700 | [diff] [blame] | 3592 | * If stylus is down anywhere on the screen, then touches should not be delivered to windows that |
| 3593 | * have InputConfig::GLOBAL_STYLUS_BLOCKS_TOUCH. |
| 3594 | * |
| 3595 | * Two windows: one on the left and one on the right. |
| 3596 | * The window on the right has GLOBAL_STYLUS_BLOCKS_TOUCH config. |
| 3597 | * Stylus down on the left window, and then touch down on the right window. |
| 3598 | * Check that the right window doesn't get touches while the stylus is down on the left window. |
| 3599 | */ |
| 3600 | TEST_F(InputDispatcherMultiDeviceTest, GlobalStylusDownBlocksTouch) { |
| 3601 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 3602 | sp<FakeWindowHandle> leftWindow = |
| 3603 | sp<FakeWindowHandle>::make(application, mDispatcher, "Left window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 3604 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | f77f60a | 2023-10-23 17:26:05 -0700 | [diff] [blame] | 3605 | leftWindow->setFrame(Rect(0, 0, 100, 100)); |
| 3606 | |
| 3607 | sp<FakeWindowHandle> sbtRightWindow = |
| 3608 | sp<FakeWindowHandle>::make(application, mDispatcher, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 3609 | "Stylus blocks touch (right) window", |
| 3610 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | f77f60a | 2023-10-23 17:26:05 -0700 | [diff] [blame] | 3611 | sbtRightWindow->setFrame(Rect(100, 100, 200, 200)); |
| 3612 | sbtRightWindow->setGlobalStylusBlocksTouch(true); |
| 3613 | |
| 3614 | mDispatcher->onWindowInfosChanged( |
| 3615 | {{*leftWindow->getInfo(), *sbtRightWindow->getInfo()}, {}, 0, 0}); |
| 3616 | |
| 3617 | const int32_t stylusDeviceId = 5; |
| 3618 | const int32_t touchDeviceId = 4; |
| 3619 | |
| 3620 | // Stylus down in the left window |
| 3621 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_STYLUS) |
| 3622 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(52)) |
| 3623 | .deviceId(stylusDeviceId) |
| 3624 | .build()); |
| 3625 | leftWindow->consumeMotionEvent( |
| 3626 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(stylusDeviceId))); |
| 3627 | |
| 3628 | // Finger tap on the right window |
| 3629 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 3630 | .pointer(PointerBuilder(0, ToolType::FINGER).x(150).y(151)) |
| 3631 | .deviceId(touchDeviceId) |
| 3632 | .build()); |
| 3633 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN) |
| 3634 | .pointer(PointerBuilder(0, ToolType::FINGER).x(150).y(151)) |
| 3635 | .deviceId(touchDeviceId) |
| 3636 | .build()); |
| 3637 | |
| 3638 | // The touch should be blocked, because stylus is down somewhere else on screen! |
| 3639 | sbtRightWindow->assertNoEvents(); |
| 3640 | |
| 3641 | // Continue stylus motion, and ensure it's not impacted. |
| 3642 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_STYLUS) |
| 3643 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(51).y(53)) |
| 3644 | .deviceId(stylusDeviceId) |
| 3645 | .build()); |
| 3646 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_UP, AINPUT_SOURCE_STYLUS) |
| 3647 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(51).y(53)) |
| 3648 | .deviceId(stylusDeviceId) |
| 3649 | .build()); |
| 3650 | leftWindow->consumeMotionEvent( |
| 3651 | AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(stylusDeviceId))); |
| 3652 | leftWindow->consumeMotionEvent( |
| 3653 | AllOf(WithMotionAction(ACTION_UP), WithDeviceId(stylusDeviceId))); |
| 3654 | |
| 3655 | // Now that the stylus gesture is done, touches should be getting delivered correctly. |
| 3656 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 3657 | .pointer(PointerBuilder(0, ToolType::FINGER).x(151).y(153)) |
| 3658 | .deviceId(touchDeviceId) |
| 3659 | .build()); |
| 3660 | sbtRightWindow->consumeMotionEvent( |
| 3661 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(touchDeviceId))); |
| 3662 | } |
| 3663 | |
| 3664 | /** |
| 3665 | * If stylus is hovering anywhere on the screen, then touches should not be delivered to windows |
| 3666 | * that have InputConfig::GLOBAL_STYLUS_BLOCKS_TOUCH. |
| 3667 | * |
| 3668 | * Two windows: one on the left and one on the right. |
| 3669 | * The window on the right has GLOBAL_STYLUS_BLOCKS_TOUCH config. |
| 3670 | * Stylus hover on the left window, and then touch down on the right window. |
| 3671 | * Check that the right window doesn't get touches while the stylus is hovering on the left window. |
| 3672 | */ |
| 3673 | TEST_F(InputDispatcherMultiDeviceTest, GlobalStylusHoverBlocksTouch) { |
| 3674 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 3675 | sp<FakeWindowHandle> leftWindow = |
| 3676 | sp<FakeWindowHandle>::make(application, mDispatcher, "Left window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 3677 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | f77f60a | 2023-10-23 17:26:05 -0700 | [diff] [blame] | 3678 | leftWindow->setFrame(Rect(0, 0, 100, 100)); |
| 3679 | |
| 3680 | sp<FakeWindowHandle> sbtRightWindow = |
| 3681 | sp<FakeWindowHandle>::make(application, mDispatcher, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 3682 | "Stylus blocks touch (right) window", |
| 3683 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | f77f60a | 2023-10-23 17:26:05 -0700 | [diff] [blame] | 3684 | sbtRightWindow->setFrame(Rect(100, 100, 200, 200)); |
| 3685 | sbtRightWindow->setGlobalStylusBlocksTouch(true); |
| 3686 | |
| 3687 | mDispatcher->onWindowInfosChanged( |
| 3688 | {{*leftWindow->getInfo(), *sbtRightWindow->getInfo()}, {}, 0, 0}); |
| 3689 | |
| 3690 | const int32_t stylusDeviceId = 5; |
| 3691 | const int32_t touchDeviceId = 4; |
| 3692 | |
| 3693 | // Stylus hover in the left window |
| 3694 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS) |
| 3695 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(52)) |
| 3696 | .deviceId(stylusDeviceId) |
| 3697 | .build()); |
| 3698 | leftWindow->consumeMotionEvent( |
| 3699 | AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithDeviceId(stylusDeviceId))); |
| 3700 | |
| 3701 | // Finger tap on the right window |
| 3702 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 3703 | .pointer(PointerBuilder(0, ToolType::FINGER).x(150).y(151)) |
| 3704 | .deviceId(touchDeviceId) |
| 3705 | .build()); |
| 3706 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN) |
| 3707 | .pointer(PointerBuilder(0, ToolType::FINGER).x(150).y(151)) |
| 3708 | .deviceId(touchDeviceId) |
| 3709 | .build()); |
| 3710 | |
| 3711 | // The touch should be blocked, because stylus is hovering somewhere else on screen! |
| 3712 | sbtRightWindow->assertNoEvents(); |
| 3713 | |
| 3714 | // Continue stylus motion, and ensure it's not impacted. |
| 3715 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_MOVE, AINPUT_SOURCE_STYLUS) |
| 3716 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(51).y(53)) |
| 3717 | .deviceId(stylusDeviceId) |
| 3718 | .build()); |
| 3719 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_EXIT, AINPUT_SOURCE_STYLUS) |
| 3720 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(51).y(53)) |
| 3721 | .deviceId(stylusDeviceId) |
| 3722 | .build()); |
| 3723 | leftWindow->consumeMotionEvent( |
| 3724 | AllOf(WithMotionAction(ACTION_HOVER_MOVE), WithDeviceId(stylusDeviceId))); |
| 3725 | leftWindow->consumeMotionEvent( |
| 3726 | AllOf(WithMotionAction(ACTION_HOVER_EXIT), WithDeviceId(stylusDeviceId))); |
| 3727 | |
| 3728 | // Now that the stylus gesture is done, touches should be getting delivered correctly. |
| 3729 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 3730 | .pointer(PointerBuilder(0, ToolType::FINGER).x(151).y(153)) |
| 3731 | .deviceId(touchDeviceId) |
| 3732 | .build()); |
| 3733 | sbtRightWindow->consumeMotionEvent( |
| 3734 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(touchDeviceId))); |
| 3735 | } |
| 3736 | |
| 3737 | /** |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3738 | * A spy window above a window with no input channel. |
| 3739 | * Start hovering with a stylus device, and then tap with it. |
| 3740 | * Ensure spy window receives the entire sequence. |
| 3741 | */ |
| 3742 | TEST_F(InputDispatcherTest, StylusHoverAndDownNoInputChannel) { |
| 3743 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 3744 | sp<FakeWindowHandle> spyWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Spy", |
| 3745 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3746 | spyWindow->setFrame(Rect(0, 0, 200, 200)); |
| 3747 | spyWindow->setTrustedOverlay(true); |
| 3748 | spyWindow->setSpy(true); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 3749 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 3750 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3751 | window->setNoInputChannel(true); |
| 3752 | window->setFrame(Rect(0, 0, 200, 200)); |
| 3753 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 3754 | mDispatcher->onWindowInfosChanged({{*spyWindow->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3755 | |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3756 | // Start hovering with stylus |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 3757 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS) |
| 3758 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50)) |
| 3759 | .build()); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3760 | spyWindow->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); |
| 3761 | // Stop hovering |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 3762 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_EXIT, AINPUT_SOURCE_STYLUS) |
| 3763 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50)) |
| 3764 | .build()); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3765 | spyWindow->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); |
| 3766 | |
| 3767 | // Stylus touches down |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 3768 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_STYLUS) |
| 3769 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50)) |
| 3770 | .build()); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3771 | spyWindow->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); |
| 3772 | |
| 3773 | // Stylus goes up |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 3774 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_UP, AINPUT_SOURCE_STYLUS) |
| 3775 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50)) |
| 3776 | .build()); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3777 | spyWindow->consumeMotionEvent(WithMotionAction(ACTION_UP)); |
| 3778 | |
| 3779 | // Again hover |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 3780 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS) |
| 3781 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50)) |
| 3782 | .build()); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3783 | spyWindow->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); |
| 3784 | // Stop hovering |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 3785 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_EXIT, AINPUT_SOURCE_STYLUS) |
| 3786 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50)) |
| 3787 | .build()); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3788 | spyWindow->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); |
| 3789 | |
| 3790 | // No more events |
| 3791 | spyWindow->assertNoEvents(); |
| 3792 | window->assertNoEvents(); |
| 3793 | } |
| 3794 | |
| 3795 | /** |
Siarhei Vishniakou | 6b71b63 | 2023-10-27 21:34:46 -0700 | [diff] [blame] | 3796 | * A stale stylus HOVER_EXIT event is injected. Since it's a stale event, it should generally be |
| 3797 | * rejected. But since we already have an ongoing gesture, this event should be processed. |
| 3798 | * This prevents inconsistent events being handled inside the dispatcher. |
| 3799 | */ |
| 3800 | TEST_F(InputDispatcherTest, StaleStylusHoverGestureIsComplete) { |
| 3801 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 3802 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 3803 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 3804 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 6b71b63 | 2023-10-27 21:34:46 -0700 | [diff] [blame] | 3805 | window->setFrame(Rect(0, 0, 200, 200)); |
| 3806 | |
| 3807 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
| 3808 | |
| 3809 | // Start hovering with stylus |
| 3810 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS) |
| 3811 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50)) |
| 3812 | .build()); |
| 3813 | window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); |
| 3814 | |
| 3815 | NotifyMotionArgs hoverExit = MotionArgsBuilder(ACTION_HOVER_EXIT, AINPUT_SOURCE_STYLUS) |
| 3816 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50)) |
| 3817 | .build(); |
| 3818 | // Make this 'hoverExit' event stale |
| 3819 | mFakePolicy->setStaleEventTimeout(100ms); |
| 3820 | std::this_thread::sleep_for(100ms); |
| 3821 | |
| 3822 | // It shouldn't be dropped by the dispatcher, even though it's stale. |
| 3823 | mDispatcher->notifyMotion(hoverExit); |
| 3824 | window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); |
| 3825 | |
| 3826 | // Stylus starts hovering again! There should be no crash. |
| 3827 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS) |
| 3828 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(51).y(51)) |
| 3829 | .build()); |
| 3830 | window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); |
| 3831 | } |
| 3832 | |
| 3833 | /** |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3834 | * Start hovering with a mouse, and then tap with a touch device. Pilfer the touch stream. |
| 3835 | * Next, click with the mouse device. Both windows (spy and regular) should receive the new mouse |
| 3836 | * ACTION_DOWN event because that's a new gesture, and pilfering should no longer be active. |
| 3837 | * While the mouse is down, new move events from the touch device should be ignored. |
| 3838 | */ |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 3839 | TEST_F(InputDispatcherTest, TouchPilferAndMouseMove_legacy) { |
| 3840 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3841 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 3842 | sp<FakeWindowHandle> spyWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Spy", |
| 3843 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3844 | spyWindow->setFrame(Rect(0, 0, 200, 200)); |
| 3845 | spyWindow->setTrustedOverlay(true); |
| 3846 | spyWindow->setSpy(true); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 3847 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 3848 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3849 | window->setFrame(Rect(0, 0, 200, 200)); |
| 3850 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 3851 | mDispatcher->onWindowInfosChanged({{*spyWindow->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3852 | |
| 3853 | const int32_t mouseDeviceId = 7; |
| 3854 | const int32_t touchDeviceId = 4; |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3855 | |
| 3856 | // Hover a bit with mouse first |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 3857 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE) |
| 3858 | .deviceId(mouseDeviceId) |
| 3859 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100)) |
| 3860 | .build()); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3861 | spyWindow->consumeMotionEvent( |
| 3862 | AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithDeviceId(mouseDeviceId))); |
| 3863 | window->consumeMotionEvent( |
| 3864 | AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithDeviceId(mouseDeviceId))); |
| 3865 | |
| 3866 | // Start touching |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 3867 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 3868 | .deviceId(touchDeviceId) |
| 3869 | .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) |
| 3870 | .build()); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3871 | spyWindow->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); |
| 3872 | window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); |
| 3873 | spyWindow->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); |
| 3874 | window->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); |
| 3875 | |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 3876 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 3877 | .deviceId(touchDeviceId) |
| 3878 | .pointer(PointerBuilder(0, ToolType::FINGER).x(55).y(55)) |
| 3879 | .build()); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3880 | spyWindow->consumeMotionEvent(WithMotionAction(ACTION_MOVE)); |
| 3881 | window->consumeMotionEvent(WithMotionAction(ACTION_MOVE)); |
| 3882 | |
| 3883 | // Pilfer the stream |
| 3884 | EXPECT_EQ(OK, mDispatcher->pilferPointers(spyWindow->getToken())); |
| 3885 | window->consumeMotionEvent(WithMotionAction(ACTION_CANCEL)); |
| 3886 | |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 3887 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 3888 | .deviceId(touchDeviceId) |
| 3889 | .pointer(PointerBuilder(0, ToolType::FINGER).x(60).y(60)) |
| 3890 | .build()); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3891 | spyWindow->consumeMotionEvent(WithMotionAction(ACTION_MOVE)); |
| 3892 | |
| 3893 | // Mouse down |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 3894 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_MOUSE) |
| 3895 | .deviceId(mouseDeviceId) |
| 3896 | .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) |
| 3897 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100)) |
| 3898 | .build()); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3899 | |
| 3900 | spyWindow->consumeMotionEvent( |
| 3901 | AllOf(WithMotionAction(ACTION_CANCEL), WithDeviceId(touchDeviceId))); |
| 3902 | spyWindow->consumeMotionEvent( |
| 3903 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(mouseDeviceId))); |
| 3904 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(mouseDeviceId))); |
| 3905 | |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 3906 | mDispatcher->notifyMotion( |
| 3907 | MotionArgsBuilder(AMOTION_EVENT_ACTION_BUTTON_PRESS, AINPUT_SOURCE_MOUSE) |
| 3908 | .deviceId(mouseDeviceId) |
| 3909 | .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) |
| 3910 | .actionButton(AMOTION_EVENT_BUTTON_PRIMARY) |
| 3911 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100)) |
| 3912 | .build()); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3913 | spyWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS)); |
| 3914 | window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS)); |
| 3915 | |
| 3916 | // Mouse move! |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 3917 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_MOUSE) |
| 3918 | .deviceId(mouseDeviceId) |
| 3919 | .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) |
| 3920 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(110).y(110)) |
| 3921 | .build()); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3922 | spyWindow->consumeMotionEvent(WithMotionAction(ACTION_MOVE)); |
| 3923 | window->consumeMotionEvent(WithMotionAction(ACTION_MOVE)); |
| 3924 | |
| 3925 | // Touch move! |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 3926 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 3927 | .deviceId(touchDeviceId) |
| 3928 | .pointer(PointerBuilder(0, ToolType::FINGER).x(65).y(65)) |
| 3929 | .build()); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 3930 | |
| 3931 | // No more events |
| 3932 | spyWindow->assertNoEvents(); |
| 3933 | window->assertNoEvents(); |
| 3934 | } |
| 3935 | |
| 3936 | /** |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 3937 | * Start hovering with a mouse, and then tap with a touch device. Pilfer the touch stream. |
| 3938 | * Next, click with the mouse device. Both windows (spy and regular) should receive the new mouse |
| 3939 | * ACTION_DOWN event because that's a new gesture, and pilfering should no longer be active. |
| 3940 | * While the mouse is down, new move events from the touch device should continue to work. |
| 3941 | */ |
| 3942 | TEST_F(InputDispatcherTest, TouchPilferAndMouseMove) { |
| 3943 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); |
| 3944 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 3945 | sp<FakeWindowHandle> spyWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Spy", |
| 3946 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 3947 | spyWindow->setFrame(Rect(0, 0, 200, 200)); |
| 3948 | spyWindow->setTrustedOverlay(true); |
| 3949 | spyWindow->setSpy(true); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 3950 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 3951 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 3952 | window->setFrame(Rect(0, 0, 200, 200)); |
| 3953 | |
| 3954 | mDispatcher->onWindowInfosChanged({{*spyWindow->getInfo(), *window->getInfo()}, {}, 0, 0}); |
| 3955 | |
| 3956 | const int32_t mouseDeviceId = 7; |
| 3957 | const int32_t touchDeviceId = 4; |
| 3958 | |
| 3959 | // Hover a bit with mouse first |
| 3960 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE) |
| 3961 | .deviceId(mouseDeviceId) |
| 3962 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100)) |
| 3963 | .build()); |
| 3964 | spyWindow->consumeMotionEvent( |
| 3965 | AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithDeviceId(mouseDeviceId))); |
| 3966 | window->consumeMotionEvent( |
| 3967 | AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithDeviceId(mouseDeviceId))); |
| 3968 | |
| 3969 | // Start touching |
| 3970 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 3971 | .deviceId(touchDeviceId) |
| 3972 | .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) |
| 3973 | .build()); |
| 3974 | |
| 3975 | spyWindow->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); |
| 3976 | window->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); |
| 3977 | |
| 3978 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 3979 | .deviceId(touchDeviceId) |
| 3980 | .pointer(PointerBuilder(0, ToolType::FINGER).x(55).y(55)) |
| 3981 | .build()); |
| 3982 | spyWindow->consumeMotionEvent(WithMotionAction(ACTION_MOVE)); |
| 3983 | window->consumeMotionEvent(WithMotionAction(ACTION_MOVE)); |
| 3984 | |
| 3985 | // Pilfer the stream |
| 3986 | EXPECT_EQ(OK, mDispatcher->pilferPointers(spyWindow->getToken())); |
| 3987 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_CANCEL), WithDeviceId(touchDeviceId))); |
| 3988 | // Hover is not pilfered! Only touch. |
| 3989 | |
| 3990 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 3991 | .deviceId(touchDeviceId) |
| 3992 | .pointer(PointerBuilder(0, ToolType::FINGER).x(60).y(60)) |
| 3993 | .build()); |
| 3994 | spyWindow->consumeMotionEvent(WithMotionAction(ACTION_MOVE)); |
| 3995 | |
| 3996 | // Mouse down |
| 3997 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_MOUSE) |
| 3998 | .deviceId(mouseDeviceId) |
| 3999 | .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) |
| 4000 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100)) |
| 4001 | .build()); |
| 4002 | |
| 4003 | spyWindow->consumeMotionEvent( |
| 4004 | AllOf(WithMotionAction(ACTION_HOVER_EXIT), WithDeviceId(mouseDeviceId))); |
| 4005 | spyWindow->consumeMotionEvent( |
| 4006 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(mouseDeviceId))); |
| 4007 | window->consumeMotionEvent( |
| 4008 | AllOf(WithMotionAction(ACTION_HOVER_EXIT), WithDeviceId(mouseDeviceId))); |
| 4009 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(mouseDeviceId))); |
| 4010 | |
| 4011 | mDispatcher->notifyMotion( |
| 4012 | MotionArgsBuilder(AMOTION_EVENT_ACTION_BUTTON_PRESS, AINPUT_SOURCE_MOUSE) |
| 4013 | .deviceId(mouseDeviceId) |
| 4014 | .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) |
| 4015 | .actionButton(AMOTION_EVENT_BUTTON_PRIMARY) |
| 4016 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100)) |
| 4017 | .build()); |
| 4018 | spyWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS)); |
| 4019 | window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS)); |
| 4020 | |
| 4021 | // Mouse move! |
| 4022 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_MOUSE) |
| 4023 | .deviceId(mouseDeviceId) |
| 4024 | .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) |
| 4025 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(110).y(110)) |
| 4026 | .build()); |
| 4027 | spyWindow->consumeMotionEvent( |
| 4028 | AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(mouseDeviceId))); |
| 4029 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(mouseDeviceId))); |
| 4030 | |
| 4031 | // Touch move! |
| 4032 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 4033 | .deviceId(touchDeviceId) |
| 4034 | .pointer(PointerBuilder(0, ToolType::FINGER).x(65).y(65)) |
| 4035 | .build()); |
| 4036 | spyWindow->consumeMotionEvent( |
| 4037 | AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(touchDeviceId))); |
| 4038 | |
| 4039 | // No more events |
| 4040 | spyWindow->assertNoEvents(); |
| 4041 | window->assertNoEvents(); |
| 4042 | } |
| 4043 | |
| 4044 | /** |
Siarhei Vishniakou | a16e3a2 | 2022-03-02 15:26:40 -0800 | [diff] [blame] | 4045 | * On the display, have a single window, and also an area where there's no window. |
| 4046 | * First pointer touches the "no window" area of the screen. Second pointer touches the window. |
| 4047 | * Make sure that the window receives the second pointer, and first pointer is simply ignored. |
| 4048 | */ |
| 4049 | TEST_F(InputDispatcherTest, SplitWorksWhenEmptyAreaIsTouched) { |
| 4050 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 4051 | sp<FakeWindowHandle> window = |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 4052 | sp<FakeWindowHandle>::make(application, mDispatcher, "Window", DISPLAY_ID); |
Siarhei Vishniakou | a16e3a2 | 2022-03-02 15:26:40 -0800 | [diff] [blame] | 4053 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 4054 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | a16e3a2 | 2022-03-02 15:26:40 -0800 | [diff] [blame] | 4055 | |
| 4056 | // Touch down on the empty space |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 4057 | mDispatcher->notifyMotion(generateTouchArgs(AMOTION_EVENT_ACTION_DOWN, {{-1, -1}})); |
Siarhei Vishniakou | a16e3a2 | 2022-03-02 15:26:40 -0800 | [diff] [blame] | 4058 | |
| 4059 | mDispatcher->waitForIdle(); |
| 4060 | window->assertNoEvents(); |
| 4061 | |
| 4062 | // Now touch down on the window with another pointer |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 4063 | mDispatcher->notifyMotion(generateTouchArgs(POINTER_1_DOWN, {{-1, -1}, {10, 10}})); |
Siarhei Vishniakou | a16e3a2 | 2022-03-02 15:26:40 -0800 | [diff] [blame] | 4064 | mDispatcher->waitForIdle(); |
| 4065 | window->consumeMotionDown(); |
| 4066 | } |
| 4067 | |
| 4068 | /** |
| 4069 | * Same test as above, but instead of touching the empty space, the first touch goes to |
| 4070 | * non-touchable window. |
| 4071 | */ |
| 4072 | TEST_F(InputDispatcherTest, SplitWorksWhenNonTouchableWindowIsTouched) { |
| 4073 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 4074 | sp<FakeWindowHandle> window1 = |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 4075 | sp<FakeWindowHandle>::make(application, mDispatcher, "Window1", DISPLAY_ID); |
Siarhei Vishniakou | a16e3a2 | 2022-03-02 15:26:40 -0800 | [diff] [blame] | 4076 | window1->setTouchableRegion(Region{{0, 0, 100, 100}}); |
| 4077 | window1->setTouchable(false); |
| 4078 | sp<FakeWindowHandle> window2 = |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 4079 | sp<FakeWindowHandle>::make(application, mDispatcher, "Window2", DISPLAY_ID); |
Siarhei Vishniakou | a16e3a2 | 2022-03-02 15:26:40 -0800 | [diff] [blame] | 4080 | window2->setTouchableRegion(Region{{100, 0, 200, 100}}); |
| 4081 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 4082 | mDispatcher->onWindowInfosChanged({{*window1->getInfo(), *window2->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | a16e3a2 | 2022-03-02 15:26:40 -0800 | [diff] [blame] | 4083 | |
Siarhei Vishniakou | a16e3a2 | 2022-03-02 15:26:40 -0800 | [diff] [blame] | 4084 | // Touch down on the non-touchable window |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 4085 | mDispatcher->notifyMotion(generateTouchArgs(AMOTION_EVENT_ACTION_DOWN, {{50, 50}})); |
Siarhei Vishniakou | a16e3a2 | 2022-03-02 15:26:40 -0800 | [diff] [blame] | 4086 | |
| 4087 | mDispatcher->waitForIdle(); |
| 4088 | window1->assertNoEvents(); |
| 4089 | window2->assertNoEvents(); |
| 4090 | |
| 4091 | // Now touch down on the window with another pointer |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 4092 | mDispatcher->notifyMotion(generateTouchArgs(POINTER_1_DOWN, {{50, 50}, {150, 50}})); |
Siarhei Vishniakou | a16e3a2 | 2022-03-02 15:26:40 -0800 | [diff] [blame] | 4093 | mDispatcher->waitForIdle(); |
| 4094 | window2->consumeMotionDown(); |
| 4095 | } |
| 4096 | |
Vaibhav Devmurari | 882bd9b | 2022-06-23 14:54:54 +0000 | [diff] [blame] | 4097 | /** |
| 4098 | * When splitting touch events the downTime should be adjusted such that the downTime corresponds |
| 4099 | * to the event time of the first ACTION_DOWN sent to the particular window. |
| 4100 | */ |
| 4101 | TEST_F(InputDispatcherTest, SplitTouchesSendCorrectActionDownTime) { |
| 4102 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 4103 | sp<FakeWindowHandle> window1 = |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 4104 | sp<FakeWindowHandle>::make(application, mDispatcher, "Window1", DISPLAY_ID); |
Vaibhav Devmurari | 882bd9b | 2022-06-23 14:54:54 +0000 | [diff] [blame] | 4105 | window1->setTouchableRegion(Region{{0, 0, 100, 100}}); |
| 4106 | sp<FakeWindowHandle> window2 = |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 4107 | sp<FakeWindowHandle>::make(application, mDispatcher, "Window2", DISPLAY_ID); |
Vaibhav Devmurari | 882bd9b | 2022-06-23 14:54:54 +0000 | [diff] [blame] | 4108 | window2->setTouchableRegion(Region{{100, 0, 200, 100}}); |
| 4109 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 4110 | mDispatcher->onWindowInfosChanged({{*window1->getInfo(), *window2->getInfo()}, {}, 0, 0}); |
Vaibhav Devmurari | 882bd9b | 2022-06-23 14:54:54 +0000 | [diff] [blame] | 4111 | |
Vaibhav Devmurari | 882bd9b | 2022-06-23 14:54:54 +0000 | [diff] [blame] | 4112 | // Touch down on the first window |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 4113 | mDispatcher->notifyMotion(generateTouchArgs(AMOTION_EVENT_ACTION_DOWN, {{50, 50}})); |
Vaibhav Devmurari | 882bd9b | 2022-06-23 14:54:54 +0000 | [diff] [blame] | 4114 | mDispatcher->waitForIdle(); |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 4115 | |
Prabir Pradhan | 9d5f9ce | 2024-01-24 00:03:41 +0000 | [diff] [blame] | 4116 | const std::unique_ptr<MotionEvent> firstDown = |
| 4117 | window1->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN))); |
| 4118 | ASSERT_EQ(firstDown->getDownTime(), firstDown->getEventTime()); |
Vaibhav Devmurari | 882bd9b | 2022-06-23 14:54:54 +0000 | [diff] [blame] | 4119 | window2->assertNoEvents(); |
Vaibhav Devmurari | 882bd9b | 2022-06-23 14:54:54 +0000 | [diff] [blame] | 4120 | |
| 4121 | // Now touch down on the window with another pointer |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 4122 | mDispatcher->notifyMotion(generateTouchArgs(POINTER_1_DOWN, {{50, 50}, {150, 50}})); |
Vaibhav Devmurari | 882bd9b | 2022-06-23 14:54:54 +0000 | [diff] [blame] | 4123 | mDispatcher->waitForIdle(); |
Prabir Pradhan | 9d5f9ce | 2024-01-24 00:03:41 +0000 | [diff] [blame] | 4124 | |
| 4125 | const std::unique_ptr<MotionEvent> secondDown = |
| 4126 | window2->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN))); |
| 4127 | ASSERT_EQ(secondDown->getDownTime(), secondDown->getEventTime()); |
| 4128 | ASSERT_NE(firstDown->getDownTime(), secondDown->getDownTime()); |
| 4129 | // We currently send MOVE events to all windows receiving a split touch when there is any change |
| 4130 | // in the touch state, even when none of the pointers in the split window actually moved. |
| 4131 | // Document this behavior in the test. |
| 4132 | window1->consumeMotionMove(); |
Vaibhav Devmurari | 882bd9b | 2022-06-23 14:54:54 +0000 | [diff] [blame] | 4133 | |
| 4134 | // Now move the pointer on the second window |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 4135 | mDispatcher->notifyMotion(generateTouchArgs(AMOTION_EVENT_ACTION_MOVE, {{50, 50}, {151, 51}})); |
Vaibhav Devmurari | 882bd9b | 2022-06-23 14:54:54 +0000 | [diff] [blame] | 4136 | mDispatcher->waitForIdle(); |
Prabir Pradhan | 9d5f9ce | 2024-01-24 00:03:41 +0000 | [diff] [blame] | 4137 | |
| 4138 | window2->consumeMotionEvent(WithDownTime(secondDown->getDownTime())); |
| 4139 | window1->consumeMotionEvent(WithDownTime(firstDown->getDownTime())); |
Vaibhav Devmurari | 882bd9b | 2022-06-23 14:54:54 +0000 | [diff] [blame] | 4140 | |
| 4141 | // Now add new touch down on the second window |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 4142 | mDispatcher->notifyMotion(generateTouchArgs(POINTER_2_DOWN, {{50, 50}, {151, 51}, {150, 50}})); |
Vaibhav Devmurari | 882bd9b | 2022-06-23 14:54:54 +0000 | [diff] [blame] | 4143 | mDispatcher->waitForIdle(); |
Vaibhav Devmurari | 882bd9b | 2022-06-23 14:54:54 +0000 | [diff] [blame] | 4144 | |
Prabir Pradhan | 9d5f9ce | 2024-01-24 00:03:41 +0000 | [diff] [blame] | 4145 | window2->consumeMotionEvent( |
| 4146 | AllOf(WithMotionAction(POINTER_1_DOWN), WithDownTime(secondDown->getDownTime()))); |
| 4147 | window1->consumeMotionEvent(WithDownTime(firstDown->getDownTime())); |
Vaibhav Devmurari | 882bd9b | 2022-06-23 14:54:54 +0000 | [diff] [blame] | 4148 | |
| 4149 | // Now move the pointer on the first window |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 4150 | mDispatcher->notifyMotion( |
| 4151 | generateTouchArgs(AMOTION_EVENT_ACTION_MOVE, {{51, 51}, {151, 51}, {150, 50}})); |
Vaibhav Devmurari | 882bd9b | 2022-06-23 14:54:54 +0000 | [diff] [blame] | 4152 | mDispatcher->waitForIdle(); |
Vaibhav Devmurari | 882bd9b | 2022-06-23 14:54:54 +0000 | [diff] [blame] | 4153 | |
Prabir Pradhan | 9d5f9ce | 2024-01-24 00:03:41 +0000 | [diff] [blame] | 4154 | window1->consumeMotionEvent(WithDownTime(firstDown->getDownTime())); |
| 4155 | window2->consumeMotionEvent(WithDownTime(secondDown->getDownTime())); |
| 4156 | |
| 4157 | // Now add new touch down on the first window |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 4158 | mDispatcher->notifyMotion( |
| 4159 | generateTouchArgs(POINTER_3_DOWN, {{51, 51}, {151, 51}, {150, 50}, {50, 50}})); |
Vaibhav Devmurari | 882bd9b | 2022-06-23 14:54:54 +0000 | [diff] [blame] | 4160 | mDispatcher->waitForIdle(); |
Prabir Pradhan | 9d5f9ce | 2024-01-24 00:03:41 +0000 | [diff] [blame] | 4161 | |
| 4162 | window1->consumeMotionEvent( |
| 4163 | AllOf(WithMotionAction(POINTER_1_DOWN), WithDownTime(firstDown->getDownTime()))); |
| 4164 | window2->consumeMotionEvent(WithDownTime(secondDown->getDownTime())); |
Vaibhav Devmurari | 882bd9b | 2022-06-23 14:54:54 +0000 | [diff] [blame] | 4165 | } |
| 4166 | |
Siarhei Vishniakou | ac42d24 | 2024-06-28 10:43:53 -0700 | [diff] [blame] | 4167 | /** |
| 4168 | * When events are not split, the downTime should be adjusted such that the downTime corresponds |
| 4169 | * to the event time of the first ACTION_DOWN. If a new window appears, it should not affect |
| 4170 | * the event routing because the first window prevents splitting. |
| 4171 | */ |
| 4172 | TEST_F(InputDispatcherTest, SplitTouchesSendCorrectActionDownTimeForNewWindow) { |
| 4173 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 4174 | sp<FakeWindowHandle> window1 = |
| 4175 | sp<FakeWindowHandle>::make(application, mDispatcher, "Window1", DISPLAY_ID); |
| 4176 | window1->setTouchableRegion(Region{{0, 0, 100, 100}}); |
| 4177 | window1->setPreventSplitting(true); |
| 4178 | |
| 4179 | sp<FakeWindowHandle> window2 = |
| 4180 | sp<FakeWindowHandle>::make(application, mDispatcher, "Window2", DISPLAY_ID); |
| 4181 | window2->setTouchableRegion(Region{{100, 0, 200, 100}}); |
| 4182 | |
| 4183 | mDispatcher->onWindowInfosChanged({{*window1->getInfo()}, {}, 0, 0}); |
| 4184 | |
| 4185 | // Touch down on the first window |
| 4186 | NotifyMotionArgs downArgs = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 4187 | .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) |
| 4188 | .build(); |
| 4189 | mDispatcher->notifyMotion(downArgs); |
| 4190 | |
| 4191 | window1->consumeMotionEvent( |
| 4192 | AllOf(WithMotionAction(ACTION_DOWN), WithDownTime(downArgs.downTime))); |
| 4193 | |
| 4194 | // Second window is added |
| 4195 | mDispatcher->onWindowInfosChanged({{*window1->getInfo(), *window2->getInfo()}, {}, 0, 0}); |
| 4196 | |
| 4197 | // Now touch down on the window with another pointer |
| 4198 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 4199 | .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) |
| 4200 | .pointer(PointerBuilder(1, ToolType::FINGER).x(150).y(50)) |
| 4201 | .downTime(downArgs.downTime) |
| 4202 | .build()); |
| 4203 | window1->consumeMotionPointerDown(1, AllOf(WithDownTime(downArgs.downTime))); |
| 4204 | |
| 4205 | // Finish the gesture |
| 4206 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_UP, AINPUT_SOURCE_TOUCHSCREEN) |
| 4207 | .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) |
| 4208 | .pointer(PointerBuilder(1, ToolType::FINGER).x(150).y(50)) |
| 4209 | .downTime(downArgs.downTime) |
| 4210 | .build()); |
| 4211 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN) |
| 4212 | .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) |
| 4213 | .downTime(downArgs.downTime) |
| 4214 | .build()); |
| 4215 | window1->consumeMotionPointerUp(1, AllOf(WithDownTime(downArgs.downTime))); |
| 4216 | window1->consumeMotionEvent( |
| 4217 | AllOf(WithMotionAction(ACTION_UP), WithDownTime(downArgs.downTime))); |
| 4218 | window2->assertNoEvents(); |
| 4219 | } |
| 4220 | |
| 4221 | /** |
| 4222 | * When splitting touch events, the downTime should be adjusted such that the downTime corresponds |
| 4223 | * to the event time of the first ACTION_DOWN sent to the new window. |
| 4224 | * If a new window that does not support split appears on the screen and gets touched with the |
| 4225 | * second finger, it should not get any events because it doesn't want split touches. At the same |
| 4226 | * time, the first window should not get the pointer_down event because it supports split touches |
| 4227 | * (and the touch occurred outside of the bounds of window1). |
| 4228 | */ |
| 4229 | TEST_F(InputDispatcherTest, SplitTouchesDropsEventForNonSplittableSecondWindow) { |
| 4230 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 4231 | sp<FakeWindowHandle> window1 = |
| 4232 | sp<FakeWindowHandle>::make(application, mDispatcher, "Window1", DISPLAY_ID); |
| 4233 | window1->setTouchableRegion(Region{{0, 0, 100, 100}}); |
| 4234 | |
| 4235 | sp<FakeWindowHandle> window2 = |
| 4236 | sp<FakeWindowHandle>::make(application, mDispatcher, "Window2", DISPLAY_ID); |
| 4237 | window2->setTouchableRegion(Region{{100, 0, 200, 100}}); |
| 4238 | |
| 4239 | mDispatcher->onWindowInfosChanged({{*window1->getInfo()}, {}, 0, 0}); |
| 4240 | |
| 4241 | // Touch down on the first window |
| 4242 | NotifyMotionArgs downArgs = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 4243 | .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) |
| 4244 | .build(); |
| 4245 | mDispatcher->notifyMotion(downArgs); |
| 4246 | |
| 4247 | window1->consumeMotionEvent( |
| 4248 | AllOf(WithMotionAction(ACTION_DOWN), WithDownTime(downArgs.downTime))); |
| 4249 | |
| 4250 | // Second window is added |
| 4251 | window2->setPreventSplitting(true); |
| 4252 | mDispatcher->onWindowInfosChanged({{*window1->getInfo(), *window2->getInfo()}, {}, 0, 0}); |
| 4253 | |
| 4254 | // Now touch down on the window with another pointer |
| 4255 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 4256 | .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) |
| 4257 | .pointer(PointerBuilder(1, ToolType::FINGER).x(150).y(50)) |
| 4258 | .downTime(downArgs.downTime) |
| 4259 | .build()); |
| 4260 | // Event is dropped because window2 doesn't support split touch, and window1 does. |
| 4261 | |
| 4262 | // Complete the gesture |
| 4263 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_UP, AINPUT_SOURCE_TOUCHSCREEN) |
| 4264 | .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) |
| 4265 | .pointer(PointerBuilder(1, ToolType::FINGER).x(150).y(50)) |
| 4266 | .downTime(downArgs.downTime) |
| 4267 | .build()); |
| 4268 | // A redundant MOVE event is generated that doesn't carry any new information |
| 4269 | window1->consumeMotionEvent( |
| 4270 | AllOf(WithMotionAction(ACTION_MOVE), WithDownTime(downArgs.downTime))); |
| 4271 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN) |
| 4272 | .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) |
| 4273 | .downTime(downArgs.downTime) |
| 4274 | .build()); |
| 4275 | |
| 4276 | window1->consumeMotionEvent( |
| 4277 | AllOf(WithMotionAction(ACTION_UP), WithDownTime(downArgs.downTime))); |
| 4278 | window1->assertNoEvents(); |
| 4279 | window2->assertNoEvents(); |
| 4280 | } |
| 4281 | |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4282 | TEST_F(InputDispatcherTest, HoverMoveEnterMouseClickAndHoverMoveExit) { |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 4283 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 4284 | sp<FakeWindowHandle> windowLeft = sp<FakeWindowHandle>::make(application, mDispatcher, "Left", |
| 4285 | ui::LogicalDisplayId::DEFAULT); |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4286 | windowLeft->setFrame(Rect(0, 0, 600, 800)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 4287 | sp<FakeWindowHandle> windowRight = sp<FakeWindowHandle>::make(application, mDispatcher, "Right", |
| 4288 | ui::LogicalDisplayId::DEFAULT); |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4289 | windowRight->setFrame(Rect(600, 0, 1200, 800)); |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4290 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 4291 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4292 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 4293 | mDispatcher->onWindowInfosChanged( |
| 4294 | {{*windowLeft->getInfo(), *windowRight->getInfo()}, {}, 0, 0}); |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4295 | |
| 4296 | // Start cursor position in right window so that we can move the cursor to left window. |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 4297 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 4298 | injectMotionEvent(*mDispatcher, |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4299 | MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, |
| 4300 | AINPUT_SOURCE_MOUSE) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 4301 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(900).y(400)) |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4302 | .build())); |
Siarhei Vishniakou | 5cee1e3 | 2022-11-29 12:35:39 -0800 | [diff] [blame] | 4303 | windowRight->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)); |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4304 | |
| 4305 | // Move cursor into left window |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 4306 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 4307 | injectMotionEvent(*mDispatcher, |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4308 | MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, |
| 4309 | AINPUT_SOURCE_MOUSE) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 4310 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4311 | .build())); |
Siarhei Vishniakou | 5cee1e3 | 2022-11-29 12:35:39 -0800 | [diff] [blame] | 4312 | windowRight->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)); |
| 4313 | windowLeft->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)); |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4314 | |
| 4315 | // Inject a series of mouse events for a mouse click |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 4316 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 4317 | injectMotionEvent(*mDispatcher, |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4318 | MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_MOUSE) |
| 4319 | .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 4320 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4321 | .build())); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 4322 | windowLeft->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); |
| 4323 | windowLeft->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4324 | |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 4325 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 4326 | injectMotionEvent(*mDispatcher, |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4327 | MotionEventBuilder(AMOTION_EVENT_ACTION_BUTTON_PRESS, |
| 4328 | AINPUT_SOURCE_MOUSE) |
| 4329 | .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) |
| 4330 | .actionButton(AMOTION_EVENT_BUTTON_PRIMARY) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 4331 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4332 | .build())); |
Siarhei Vishniakou | 5cee1e3 | 2022-11-29 12:35:39 -0800 | [diff] [blame] | 4333 | windowLeft->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS)); |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4334 | |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 4335 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 4336 | injectMotionEvent(*mDispatcher, |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4337 | MotionEventBuilder(AMOTION_EVENT_ACTION_BUTTON_RELEASE, |
| 4338 | AINPUT_SOURCE_MOUSE) |
| 4339 | .buttonState(0) |
| 4340 | .actionButton(AMOTION_EVENT_BUTTON_PRIMARY) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 4341 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4342 | .build())); |
Siarhei Vishniakou | 5cee1e3 | 2022-11-29 12:35:39 -0800 | [diff] [blame] | 4343 | windowLeft->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE)); |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4344 | |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 4345 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 4346 | injectMotionEvent(*mDispatcher, |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4347 | MotionEventBuilder(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_MOUSE) |
| 4348 | .buttonState(0) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 4349 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4350 | .build())); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 4351 | windowLeft->consumeMotionUp(ui::LogicalDisplayId::DEFAULT); |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4352 | |
| 4353 | // Move mouse cursor back to right window |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 4354 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 4355 | injectMotionEvent(*mDispatcher, |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4356 | MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, |
| 4357 | AINPUT_SOURCE_MOUSE) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 4358 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(900).y(400)) |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4359 | .build())); |
Siarhei Vishniakou | 5cee1e3 | 2022-11-29 12:35:39 -0800 | [diff] [blame] | 4360 | windowRight->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)); |
Siarhei Vishniakou | 5cee1e3 | 2022-11-29 12:35:39 -0800 | [diff] [blame] | 4361 | |
| 4362 | // No more events |
| 4363 | windowLeft->assertNoEvents(); |
| 4364 | windowRight->assertNoEvents(); |
| 4365 | } |
| 4366 | |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 4367 | /** |
| 4368 | * Put two fingers down (and don't release them) and click the mouse button. |
| 4369 | * The clicking of mouse is a new ACTION_DOWN event. Since it's from a different device, the |
| 4370 | * currently active gesture should be canceled, and the new one should proceed. |
| 4371 | */ |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 4372 | TEST_F(InputDispatcherTest, TwoPointersDownMouseClick_legacy) { |
| 4373 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 4374 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 4375 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 4376 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 4377 | window->setFrame(Rect(0, 0, 600, 800)); |
| 4378 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 4379 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 4380 | |
| 4381 | const int32_t touchDeviceId = 4; |
| 4382 | const int32_t mouseDeviceId = 6; |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 4383 | |
| 4384 | // Two pointers down |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 4385 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 4386 | .deviceId(touchDeviceId) |
| 4387 | .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) |
| 4388 | .build()); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 4389 | |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 4390 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 4391 | .deviceId(touchDeviceId) |
| 4392 | .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) |
| 4393 | .pointer(PointerBuilder(1, ToolType::FINGER).x(120).y(120)) |
| 4394 | .build()); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 4395 | window->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); |
| 4396 | window->consumeMotionEvent(WithMotionAction(POINTER_1_DOWN)); |
| 4397 | |
| 4398 | // Inject a series of mouse events for a mouse click |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 4399 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_MOUSE) |
| 4400 | .deviceId(mouseDeviceId) |
| 4401 | .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) |
| 4402 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) |
| 4403 | .build()); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 4404 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_CANCEL), WithDeviceId(touchDeviceId), |
| 4405 | WithPointerCount(2u))); |
| 4406 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(mouseDeviceId))); |
| 4407 | |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 4408 | mDispatcher->notifyMotion( |
| 4409 | MotionArgsBuilder(AMOTION_EVENT_ACTION_BUTTON_PRESS, AINPUT_SOURCE_MOUSE) |
| 4410 | .deviceId(mouseDeviceId) |
| 4411 | .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) |
| 4412 | .actionButton(AMOTION_EVENT_BUTTON_PRIMARY) |
| 4413 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) |
| 4414 | .build()); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 4415 | window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS)); |
| 4416 | |
| 4417 | // Try to send more touch events while the mouse is down. Since it's a continuation of an |
| 4418 | // already canceled gesture, it should be ignored. |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 4419 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 4420 | .deviceId(touchDeviceId) |
| 4421 | .pointer(PointerBuilder(0, ToolType::FINGER).x(101).y(101)) |
| 4422 | .pointer(PointerBuilder(1, ToolType::FINGER).x(121).y(121)) |
| 4423 | .build()); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 4424 | window->assertNoEvents(); |
| 4425 | } |
| 4426 | |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 4427 | /** |
| 4428 | * Put two fingers down (and don't release them) and click the mouse button. |
| 4429 | * The clicking of mouse is a new ACTION_DOWN event. Since it's from a different device, the |
| 4430 | * currently active gesture should not be canceled, and the new one should proceed in parallel. |
| 4431 | */ |
| 4432 | TEST_F(InputDispatcherTest, TwoPointersDownMouseClick) { |
| 4433 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); |
| 4434 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 4435 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 4436 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 4437 | window->setFrame(Rect(0, 0, 600, 800)); |
| 4438 | |
| 4439 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
| 4440 | |
| 4441 | const int32_t touchDeviceId = 4; |
| 4442 | const int32_t mouseDeviceId = 6; |
| 4443 | |
| 4444 | // Two pointers down |
| 4445 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 4446 | .deviceId(touchDeviceId) |
| 4447 | .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) |
| 4448 | .build()); |
| 4449 | |
| 4450 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 4451 | .deviceId(touchDeviceId) |
| 4452 | .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) |
| 4453 | .pointer(PointerBuilder(1, ToolType::FINGER).x(120).y(120)) |
| 4454 | .build()); |
| 4455 | window->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); |
| 4456 | window->consumeMotionEvent(WithMotionAction(POINTER_1_DOWN)); |
| 4457 | |
| 4458 | // Send a series of mouse events for a mouse click |
| 4459 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_MOUSE) |
| 4460 | .deviceId(mouseDeviceId) |
| 4461 | .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) |
| 4462 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) |
| 4463 | .build()); |
| 4464 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(mouseDeviceId))); |
| 4465 | |
| 4466 | mDispatcher->notifyMotion( |
| 4467 | MotionArgsBuilder(AMOTION_EVENT_ACTION_BUTTON_PRESS, AINPUT_SOURCE_MOUSE) |
| 4468 | .deviceId(mouseDeviceId) |
| 4469 | .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) |
| 4470 | .actionButton(AMOTION_EVENT_BUTTON_PRIMARY) |
| 4471 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) |
| 4472 | .build()); |
| 4473 | window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS)); |
| 4474 | |
| 4475 | // Try to send more touch events while the mouse is down. Since it's a continuation of an |
| 4476 | // already active gesture, it should be sent normally. |
| 4477 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 4478 | .deviceId(touchDeviceId) |
| 4479 | .pointer(PointerBuilder(0, ToolType::FINGER).x(101).y(101)) |
| 4480 | .pointer(PointerBuilder(1, ToolType::FINGER).x(121).y(121)) |
| 4481 | .build()); |
| 4482 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(touchDeviceId))); |
| 4483 | window->assertNoEvents(); |
| 4484 | } |
| 4485 | |
Siarhei Vishniakou | 5cee1e3 | 2022-11-29 12:35:39 -0800 | [diff] [blame] | 4486 | TEST_F(InputDispatcherTest, HoverWithSpyWindows) { |
| 4487 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 4488 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 4489 | sp<FakeWindowHandle> spyWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Spy", |
| 4490 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 5cee1e3 | 2022-11-29 12:35:39 -0800 | [diff] [blame] | 4491 | spyWindow->setFrame(Rect(0, 0, 600, 800)); |
| 4492 | spyWindow->setTrustedOverlay(true); |
| 4493 | spyWindow->setSpy(true); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 4494 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 4495 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 5cee1e3 | 2022-11-29 12:35:39 -0800 | [diff] [blame] | 4496 | window->setFrame(Rect(0, 0, 600, 800)); |
| 4497 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 4498 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 4499 | mDispatcher->onWindowInfosChanged({{*spyWindow->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | 5cee1e3 | 2022-11-29 12:35:39 -0800 | [diff] [blame] | 4500 | |
| 4501 | // Send mouse cursor to the window |
| 4502 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 4503 | injectMotionEvent(*mDispatcher, |
Siarhei Vishniakou | 5cee1e3 | 2022-11-29 12:35:39 -0800 | [diff] [blame] | 4504 | MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_ENTER, |
| 4505 | AINPUT_SOURCE_MOUSE) |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 4506 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100)) |
Siarhei Vishniakou | 5cee1e3 | 2022-11-29 12:35:39 -0800 | [diff] [blame] | 4507 | .build())); |
| 4508 | |
| 4509 | window->consumeMotionEvent(AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 4510 | WithSource(AINPUT_SOURCE_MOUSE))); |
| 4511 | spyWindow->consumeMotionEvent(AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 4512 | WithSource(AINPUT_SOURCE_MOUSE))); |
| 4513 | |
| 4514 | window->assertNoEvents(); |
| 4515 | spyWindow->assertNoEvents(); |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4516 | } |
| 4517 | |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 4518 | TEST_F(InputDispatcherTest, MouseAndTouchWithSpyWindows_legacy) { |
| 4519 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); |
Siarhei Vishniakou | 060f82b | 2023-01-27 06:39:14 -0800 | [diff] [blame] | 4520 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 4521 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 4522 | sp<FakeWindowHandle> spyWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Spy", |
| 4523 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 060f82b | 2023-01-27 06:39:14 -0800 | [diff] [blame] | 4524 | spyWindow->setFrame(Rect(0, 0, 600, 800)); |
| 4525 | spyWindow->setTrustedOverlay(true); |
| 4526 | spyWindow->setSpy(true); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 4527 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 4528 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 060f82b | 2023-01-27 06:39:14 -0800 | [diff] [blame] | 4529 | window->setFrame(Rect(0, 0, 600, 800)); |
| 4530 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 4531 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 4532 | mDispatcher->onWindowInfosChanged({{*spyWindow->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | 060f82b | 2023-01-27 06:39:14 -0800 | [diff] [blame] | 4533 | |
| 4534 | // Send mouse cursor to the window |
| 4535 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 4536 | injectMotionEvent(*mDispatcher, |
Siarhei Vishniakou | 060f82b | 2023-01-27 06:39:14 -0800 | [diff] [blame] | 4537 | MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_ENTER, |
| 4538 | AINPUT_SOURCE_MOUSE) |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 4539 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100)) |
Siarhei Vishniakou | 060f82b | 2023-01-27 06:39:14 -0800 | [diff] [blame] | 4540 | .build())); |
| 4541 | |
| 4542 | // Move mouse cursor |
| 4543 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 4544 | injectMotionEvent(*mDispatcher, |
Siarhei Vishniakou | 060f82b | 2023-01-27 06:39:14 -0800 | [diff] [blame] | 4545 | MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, |
| 4546 | AINPUT_SOURCE_MOUSE) |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 4547 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(110).y(110)) |
Siarhei Vishniakou | 060f82b | 2023-01-27 06:39:14 -0800 | [diff] [blame] | 4548 | .build())); |
| 4549 | |
| 4550 | window->consumeMotionEvent(AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 4551 | WithSource(AINPUT_SOURCE_MOUSE))); |
| 4552 | spyWindow->consumeMotionEvent(AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 4553 | WithSource(AINPUT_SOURCE_MOUSE))); |
| 4554 | window->consumeMotionEvent(AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), |
| 4555 | WithSource(AINPUT_SOURCE_MOUSE))); |
| 4556 | spyWindow->consumeMotionEvent(AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), |
| 4557 | WithSource(AINPUT_SOURCE_MOUSE))); |
| 4558 | // Touch down on the window |
| 4559 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 4560 | injectMotionEvent(*mDispatcher, |
Siarhei Vishniakou | 060f82b | 2023-01-27 06:39:14 -0800 | [diff] [blame] | 4561 | MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, |
| 4562 | AINPUT_SOURCE_TOUCHSCREEN) |
| 4563 | .deviceId(SECOND_DEVICE_ID) |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 4564 | .pointer(PointerBuilder(0, ToolType::FINGER).x(200).y(200)) |
Siarhei Vishniakou | 060f82b | 2023-01-27 06:39:14 -0800 | [diff] [blame] | 4565 | .build())); |
| 4566 | window->consumeMotionEvent(AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), |
| 4567 | WithSource(AINPUT_SOURCE_MOUSE))); |
| 4568 | spyWindow->consumeMotionEvent(AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), |
| 4569 | WithSource(AINPUT_SOURCE_MOUSE))); |
| 4570 | window->consumeMotionEvent(AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 4571 | WithSource(AINPUT_SOURCE_TOUCHSCREEN))); |
| 4572 | spyWindow->consumeMotionEvent(AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 4573 | WithSource(AINPUT_SOURCE_TOUCHSCREEN))); |
| 4574 | |
| 4575 | // pilfer the motion, retaining the gesture on the spy window. |
| 4576 | EXPECT_EQ(OK, mDispatcher->pilferPointers(spyWindow->getToken())); |
| 4577 | window->consumeMotionEvent(AllOf(WithMotionAction(AMOTION_EVENT_ACTION_CANCEL), |
| 4578 | WithSource(AINPUT_SOURCE_TOUCHSCREEN))); |
| 4579 | |
| 4580 | // Touch UP on the window |
| 4581 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 4582 | injectMotionEvent(*mDispatcher, |
Siarhei Vishniakou | 060f82b | 2023-01-27 06:39:14 -0800 | [diff] [blame] | 4583 | MotionEventBuilder(AMOTION_EVENT_ACTION_UP, |
| 4584 | AINPUT_SOURCE_TOUCHSCREEN) |
| 4585 | .deviceId(SECOND_DEVICE_ID) |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 4586 | .pointer(PointerBuilder(0, ToolType::FINGER).x(200).y(200)) |
Siarhei Vishniakou | 060f82b | 2023-01-27 06:39:14 -0800 | [diff] [blame] | 4587 | .build())); |
| 4588 | spyWindow->consumeMotionEvent(AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 4589 | WithSource(AINPUT_SOURCE_TOUCHSCREEN))); |
| 4590 | |
| 4591 | // Previously, a touch was pilfered. However, that gesture was just finished. Now, we are going |
| 4592 | // to send a new gesture. It should again go to both windows (spy and the window below), just |
| 4593 | // like the first gesture did, before pilfering. The window configuration has not changed. |
| 4594 | |
| 4595 | // One more tap - DOWN |
| 4596 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 4597 | injectMotionEvent(*mDispatcher, |
Siarhei Vishniakou | 060f82b | 2023-01-27 06:39:14 -0800 | [diff] [blame] | 4598 | MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, |
| 4599 | AINPUT_SOURCE_TOUCHSCREEN) |
| 4600 | .deviceId(SECOND_DEVICE_ID) |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 4601 | .pointer(PointerBuilder(0, ToolType::FINGER).x(250).y(250)) |
Siarhei Vishniakou | 060f82b | 2023-01-27 06:39:14 -0800 | [diff] [blame] | 4602 | .build())); |
| 4603 | window->consumeMotionEvent(AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 4604 | WithSource(AINPUT_SOURCE_TOUCHSCREEN))); |
| 4605 | spyWindow->consumeMotionEvent(AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 4606 | WithSource(AINPUT_SOURCE_TOUCHSCREEN))); |
| 4607 | |
| 4608 | // Touch UP on the window |
| 4609 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 4610 | injectMotionEvent(*mDispatcher, |
Siarhei Vishniakou | 060f82b | 2023-01-27 06:39:14 -0800 | [diff] [blame] | 4611 | MotionEventBuilder(AMOTION_EVENT_ACTION_UP, |
| 4612 | AINPUT_SOURCE_TOUCHSCREEN) |
| 4613 | .deviceId(SECOND_DEVICE_ID) |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 4614 | .pointer(PointerBuilder(0, ToolType::FINGER).x(250).y(250)) |
Siarhei Vishniakou | 060f82b | 2023-01-27 06:39:14 -0800 | [diff] [blame] | 4615 | .build())); |
| 4616 | window->consumeMotionEvent(AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 4617 | WithSource(AINPUT_SOURCE_TOUCHSCREEN))); |
| 4618 | spyWindow->consumeMotionEvent(AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 4619 | WithSource(AINPUT_SOURCE_TOUCHSCREEN))); |
| 4620 | |
| 4621 | window->assertNoEvents(); |
| 4622 | spyWindow->assertNoEvents(); |
| 4623 | } |
| 4624 | |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 4625 | TEST_F(InputDispatcherTest, MouseAndTouchWithSpyWindows) { |
| 4626 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); |
| 4627 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 4628 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 4629 | sp<FakeWindowHandle> spyWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Spy", |
| 4630 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 4631 | spyWindow->setFrame(Rect(0, 0, 600, 800)); |
| 4632 | spyWindow->setTrustedOverlay(true); |
| 4633 | spyWindow->setSpy(true); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 4634 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 4635 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 4636 | window->setFrame(Rect(0, 0, 600, 800)); |
| 4637 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 4638 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 4639 | mDispatcher->onWindowInfosChanged({{*spyWindow->getInfo(), *window->getInfo()}, {}, 0, 0}); |
| 4640 | |
| 4641 | // Send mouse cursor to the window |
| 4642 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE) |
| 4643 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100)) |
| 4644 | .build()); |
| 4645 | |
| 4646 | // Move mouse cursor |
| 4647 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) |
| 4648 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(110).y(110)) |
| 4649 | .build()); |
| 4650 | |
| 4651 | window->consumeMotionEvent( |
| 4652 | AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithSource(AINPUT_SOURCE_MOUSE))); |
| 4653 | spyWindow->consumeMotionEvent( |
| 4654 | AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithSource(AINPUT_SOURCE_MOUSE))); |
| 4655 | window->consumeMotionEvent( |
| 4656 | AllOf(WithMotionAction(ACTION_HOVER_MOVE), WithSource(AINPUT_SOURCE_MOUSE))); |
| 4657 | spyWindow->consumeMotionEvent( |
| 4658 | AllOf(WithMotionAction(ACTION_HOVER_MOVE), WithSource(AINPUT_SOURCE_MOUSE))); |
| 4659 | // Touch down on the window |
| 4660 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 4661 | .deviceId(SECOND_DEVICE_ID) |
| 4662 | .pointer(PointerBuilder(0, ToolType::FINGER).x(200).y(200)) |
| 4663 | .build()); |
| 4664 | window->consumeMotionEvent( |
| 4665 | AllOf(WithMotionAction(ACTION_DOWN), WithSource(AINPUT_SOURCE_TOUCHSCREEN))); |
| 4666 | spyWindow->consumeMotionEvent( |
| 4667 | AllOf(WithMotionAction(ACTION_DOWN), WithSource(AINPUT_SOURCE_TOUCHSCREEN))); |
| 4668 | |
| 4669 | // pilfer the motion, retaining the gesture on the spy window. |
| 4670 | EXPECT_EQ(OK, mDispatcher->pilferPointers(spyWindow->getToken())); |
| 4671 | window->consumeMotionEvent( |
| 4672 | AllOf(WithMotionAction(ACTION_CANCEL), WithSource(AINPUT_SOURCE_TOUCHSCREEN))); |
| 4673 | // Mouse hover is not pilfered |
| 4674 | |
| 4675 | // Touch UP on the window |
| 4676 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN) |
| 4677 | .deviceId(SECOND_DEVICE_ID) |
| 4678 | .pointer(PointerBuilder(0, ToolType::FINGER).x(200).y(200)) |
| 4679 | .build()); |
| 4680 | spyWindow->consumeMotionEvent( |
| 4681 | AllOf(WithMotionAction(ACTION_UP), WithSource(AINPUT_SOURCE_TOUCHSCREEN))); |
| 4682 | |
| 4683 | // Previously, a touch was pilfered. However, that gesture was just finished. Now, we are going |
| 4684 | // to send a new gesture. It should again go to both windows (spy and the window below), just |
| 4685 | // like the first gesture did, before pilfering. The window configuration has not changed. |
| 4686 | |
| 4687 | // One more tap - DOWN |
| 4688 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 4689 | .deviceId(SECOND_DEVICE_ID) |
| 4690 | .pointer(PointerBuilder(0, ToolType::FINGER).x(250).y(250)) |
| 4691 | .build()); |
| 4692 | window->consumeMotionEvent( |
| 4693 | AllOf(WithMotionAction(ACTION_DOWN), WithSource(AINPUT_SOURCE_TOUCHSCREEN))); |
| 4694 | spyWindow->consumeMotionEvent( |
| 4695 | AllOf(WithMotionAction(ACTION_DOWN), WithSource(AINPUT_SOURCE_TOUCHSCREEN))); |
| 4696 | |
| 4697 | // Touch UP on the window |
| 4698 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN) |
| 4699 | .deviceId(SECOND_DEVICE_ID) |
| 4700 | .pointer(PointerBuilder(0, ToolType::FINGER).x(250).y(250)) |
| 4701 | .build()); |
| 4702 | window->consumeMotionEvent( |
| 4703 | AllOf(WithMotionAction(ACTION_UP), WithSource(AINPUT_SOURCE_TOUCHSCREEN))); |
| 4704 | spyWindow->consumeMotionEvent( |
| 4705 | AllOf(WithMotionAction(ACTION_UP), WithSource(AINPUT_SOURCE_TOUCHSCREEN))); |
| 4706 | |
| 4707 | // Mouse movement continues normally as well |
| 4708 | // Move mouse cursor |
| 4709 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) |
| 4710 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(120).y(130)) |
| 4711 | .build()); |
| 4712 | window->consumeMotionEvent( |
| 4713 | AllOf(WithMotionAction(ACTION_HOVER_MOVE), WithSource(AINPUT_SOURCE_MOUSE))); |
| 4714 | spyWindow->consumeMotionEvent( |
| 4715 | AllOf(WithMotionAction(ACTION_HOVER_MOVE), WithSource(AINPUT_SOURCE_MOUSE))); |
| 4716 | |
| 4717 | window->assertNoEvents(); |
| 4718 | spyWindow->assertNoEvents(); |
| 4719 | } |
| 4720 | |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4721 | // This test is different from the test above that HOVER_ENTER and HOVER_EXIT events are injected |
| 4722 | // directly in this test. |
| 4723 | TEST_F(InputDispatcherTest, HoverEnterMouseClickAndHoverExit) { |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 4724 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 4725 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 4726 | ui::LogicalDisplayId::DEFAULT); |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4727 | window->setFrame(Rect(0, 0, 1200, 800)); |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4728 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 4729 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4730 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 4731 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4732 | |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 4733 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 4734 | injectMotionEvent(*mDispatcher, |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4735 | MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_ENTER, |
| 4736 | AINPUT_SOURCE_MOUSE) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 4737 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4738 | .build())); |
Siarhei Vishniakou | 5cee1e3 | 2022-11-29 12:35:39 -0800 | [diff] [blame] | 4739 | window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)); |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4740 | // Inject a series of mouse events for a mouse click |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 4741 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 4742 | injectMotionEvent(*mDispatcher, |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4743 | MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_MOUSE) |
| 4744 | .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 4745 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4746 | .build())); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 4747 | window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); |
| 4748 | window->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4749 | |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 4750 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 4751 | injectMotionEvent(*mDispatcher, |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4752 | MotionEventBuilder(AMOTION_EVENT_ACTION_BUTTON_PRESS, |
| 4753 | AINPUT_SOURCE_MOUSE) |
| 4754 | .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) |
| 4755 | .actionButton(AMOTION_EVENT_BUTTON_PRIMARY) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 4756 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4757 | .build())); |
Siarhei Vishniakou | 5cee1e3 | 2022-11-29 12:35:39 -0800 | [diff] [blame] | 4758 | window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS)); |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4759 | |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 4760 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 4761 | injectMotionEvent(*mDispatcher, |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4762 | MotionEventBuilder(AMOTION_EVENT_ACTION_BUTTON_RELEASE, |
| 4763 | AINPUT_SOURCE_MOUSE) |
| 4764 | .buttonState(0) |
| 4765 | .actionButton(AMOTION_EVENT_BUTTON_PRIMARY) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 4766 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4767 | .build())); |
Siarhei Vishniakou | 5cee1e3 | 2022-11-29 12:35:39 -0800 | [diff] [blame] | 4768 | window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE)); |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4769 | |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 4770 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 4771 | injectMotionEvent(*mDispatcher, |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4772 | MotionEventBuilder(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_MOUSE) |
| 4773 | .buttonState(0) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 4774 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4775 | .build())); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 4776 | window->consumeMotionUp(ui::LogicalDisplayId::DEFAULT); |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4777 | |
Siarhei Vishniakou | a235c04 | 2023-05-02 09:59:09 -0700 | [diff] [blame] | 4778 | // We already canceled the hovering implicitly by injecting the "DOWN" event without lifting the |
| 4779 | // hover first. Therefore, injection of HOVER_EXIT is inconsistent, and should fail. |
| 4780 | ASSERT_EQ(InputEventInjectionResult::FAILED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 4781 | injectMotionEvent(*mDispatcher, |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4782 | MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_EXIT, |
| 4783 | AINPUT_SOURCE_MOUSE) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 4784 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4785 | .build())); |
Siarhei Vishniakou | f372b81 | 2023-02-14 18:06:51 -0800 | [diff] [blame] | 4786 | window->assertNoEvents(); |
Garfield Tan | df26e86 | 2020-07-01 20:18:19 -0700 | [diff] [blame] | 4787 | } |
| 4788 | |
Siarhei Vishniakou | 0b0374d | 2022-11-17 17:40:53 -0800 | [diff] [blame] | 4789 | /** |
Siarhei Vishniakou | b581f7f | 2022-12-07 20:23:06 +0000 | [diff] [blame] | 4790 | * Hover over a window, and then remove that window. Make sure that HOVER_EXIT for that event |
| 4791 | * is generated. |
| 4792 | */ |
| 4793 | TEST_F(InputDispatcherTest, HoverExitIsSentToRemovedWindow) { |
| 4794 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 4795 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 4796 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | b581f7f | 2022-12-07 20:23:06 +0000 | [diff] [blame] | 4797 | window->setFrame(Rect(0, 0, 1200, 800)); |
| 4798 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 4799 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); |
Siarhei Vishniakou | b581f7f | 2022-12-07 20:23:06 +0000 | [diff] [blame] | 4800 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 4801 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | b581f7f | 2022-12-07 20:23:06 +0000 | [diff] [blame] | 4802 | |
| 4803 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 4804 | injectMotionEvent(*mDispatcher, |
Siarhei Vishniakou | b581f7f | 2022-12-07 20:23:06 +0000 | [diff] [blame] | 4805 | MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_ENTER, |
| 4806 | AINPUT_SOURCE_MOUSE) |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 4807 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) |
Siarhei Vishniakou | b581f7f | 2022-12-07 20:23:06 +0000 | [diff] [blame] | 4808 | .build())); |
| 4809 | window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)); |
| 4810 | |
| 4811 | // Remove the window, but keep the channel. |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 4812 | mDispatcher->onWindowInfosChanged({{}, {}, 0, 0}); |
Siarhei Vishniakou | b581f7f | 2022-12-07 20:23:06 +0000 | [diff] [blame] | 4813 | window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)); |
| 4814 | } |
| 4815 | |
| 4816 | /** |
Daniel Norman | 7487dfa | 2023-08-02 16:39:45 -0700 | [diff] [blame] | 4817 | * Test that invalid HOVER events sent by accessibility do not cause a fatal crash. |
| 4818 | */ |
Ameer Armaly | cff4fa5 | 2023-10-04 23:45:11 +0000 | [diff] [blame] | 4819 | TEST_F_WITH_FLAGS(InputDispatcherTest, InvalidA11yHoverStreamDoesNotCrash, |
| 4820 | REQUIRES_FLAGS_DISABLED(ACONFIG_FLAG(com::android::input::flags, |
| 4821 | a11y_crash_on_inconsistent_event_stream))) { |
Daniel Norman | 7487dfa | 2023-08-02 16:39:45 -0700 | [diff] [blame] | 4822 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 4823 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 4824 | ui::LogicalDisplayId::DEFAULT); |
Daniel Norman | 7487dfa | 2023-08-02 16:39:45 -0700 | [diff] [blame] | 4825 | window->setFrame(Rect(0, 0, 1200, 800)); |
| 4826 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 4827 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); |
Daniel Norman | 7487dfa | 2023-08-02 16:39:45 -0700 | [diff] [blame] | 4828 | |
| 4829 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
| 4830 | |
| 4831 | MotionEventBuilder hoverEnterBuilder = |
| 4832 | MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE) |
| 4833 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) |
| 4834 | .addFlag(AMOTION_EVENT_FLAG_IS_ACCESSIBILITY_EVENT); |
| 4835 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
| 4836 | injectMotionEvent(*mDispatcher, hoverEnterBuilder.build())); |
| 4837 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
| 4838 | injectMotionEvent(*mDispatcher, hoverEnterBuilder.build())); |
| 4839 | window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)); |
| 4840 | window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)); |
| 4841 | } |
| 4842 | |
| 4843 | /** |
Siarhei Vishniakou | 4e1ffa5 | 2023-02-21 11:50:34 -0800 | [diff] [blame] | 4844 | * If mouse is hovering when the touch goes down, the hovering should be stopped via HOVER_EXIT. |
| 4845 | */ |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 4846 | TEST_F(InputDispatcherTest, TouchDownAfterMouseHover_legacy) { |
| 4847 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); |
Siarhei Vishniakou | 4e1ffa5 | 2023-02-21 11:50:34 -0800 | [diff] [blame] | 4848 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 4849 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 4850 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 4e1ffa5 | 2023-02-21 11:50:34 -0800 | [diff] [blame] | 4851 | window->setFrame(Rect(0, 0, 100, 100)); |
| 4852 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 4853 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | 4e1ffa5 | 2023-02-21 11:50:34 -0800 | [diff] [blame] | 4854 | |
| 4855 | const int32_t mouseDeviceId = 7; |
| 4856 | const int32_t touchDeviceId = 4; |
Siarhei Vishniakou | 4e1ffa5 | 2023-02-21 11:50:34 -0800 | [diff] [blame] | 4857 | |
| 4858 | // Start hovering with the mouse |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 4859 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE) |
| 4860 | .deviceId(mouseDeviceId) |
| 4861 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(10).y(10)) |
| 4862 | .build()); |
Siarhei Vishniakou | 4e1ffa5 | 2023-02-21 11:50:34 -0800 | [diff] [blame] | 4863 | window->consumeMotionEvent( |
| 4864 | AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithDeviceId(mouseDeviceId))); |
| 4865 | |
| 4866 | // Touch goes down |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 4867 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 4868 | .deviceId(touchDeviceId) |
| 4869 | .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) |
| 4870 | .build()); |
Siarhei Vishniakou | 4e1ffa5 | 2023-02-21 11:50:34 -0800 | [diff] [blame] | 4871 | |
| 4872 | window->consumeMotionEvent( |
| 4873 | AllOf(WithMotionAction(ACTION_HOVER_EXIT), WithDeviceId(mouseDeviceId))); |
| 4874 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(touchDeviceId))); |
| 4875 | } |
| 4876 | |
| 4877 | /** |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 4878 | * If mouse is hovering when the touch goes down, the hovering should not be stopped. |
| 4879 | */ |
| 4880 | TEST_F(InputDispatcherTest, TouchDownAfterMouseHover) { |
| 4881 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); |
| 4882 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 4883 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 4884 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 4885 | window->setFrame(Rect(0, 0, 100, 100)); |
| 4886 | |
| 4887 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
| 4888 | |
| 4889 | const int32_t mouseDeviceId = 7; |
| 4890 | const int32_t touchDeviceId = 4; |
| 4891 | |
| 4892 | // Start hovering with the mouse |
| 4893 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE) |
| 4894 | .deviceId(mouseDeviceId) |
| 4895 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(10).y(10)) |
| 4896 | .build()); |
| 4897 | window->consumeMotionEvent( |
| 4898 | AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithDeviceId(mouseDeviceId))); |
| 4899 | |
| 4900 | // Touch goes down |
| 4901 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 4902 | .deviceId(touchDeviceId) |
| 4903 | .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) |
| 4904 | .build()); |
| 4905 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(touchDeviceId))); |
| 4906 | } |
| 4907 | |
| 4908 | /** |
Siarhei Vishniakou | 0b0374d | 2022-11-17 17:40:53 -0800 | [diff] [blame] | 4909 | * Inject a mouse hover event followed by a tap from touchscreen. |
Siarhei Vishniakou | b581f7f | 2022-12-07 20:23:06 +0000 | [diff] [blame] | 4910 | * The tap causes a HOVER_EXIT event to be generated because the current event |
| 4911 | * stream's source has been switched. |
Siarhei Vishniakou | 0b0374d | 2022-11-17 17:40:53 -0800 | [diff] [blame] | 4912 | */ |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 4913 | TEST_F(InputDispatcherTest, MouseHoverAndTouchTap_legacy) { |
| 4914 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); |
Siarhei Vishniakou | 0b0374d | 2022-11-17 17:40:53 -0800 | [diff] [blame] | 4915 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 4916 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 4917 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 0b0374d | 2022-11-17 17:40:53 -0800 | [diff] [blame] | 4918 | window->setFrame(Rect(0, 0, 100, 100)); |
| 4919 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 4920 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 4921 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) |
| 4922 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(50).y(50)) |
| 4923 | .build()); |
Siarhei Vishniakou | 0b0374d | 2022-11-17 17:40:53 -0800 | [diff] [blame] | 4924 | ASSERT_NO_FATAL_FAILURE( |
| 4925 | window->consumeMotionEvent(AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 4926 | WithSource(AINPUT_SOURCE_MOUSE)))); |
Siarhei Vishniakou | 0b0374d | 2022-11-17 17:40:53 -0800 | [diff] [blame] | 4927 | |
| 4928 | // Tap on the window |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 4929 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 4930 | .pointer(PointerBuilder(0, ToolType::FINGER).x(10).y(10)) |
| 4931 | .build()); |
Siarhei Vishniakou | 0b0374d | 2022-11-17 17:40:53 -0800 | [diff] [blame] | 4932 | ASSERT_NO_FATAL_FAILURE( |
Siarhei Vishniakou | b581f7f | 2022-12-07 20:23:06 +0000 | [diff] [blame] | 4933 | window->consumeMotionEvent(AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), |
| 4934 | WithSource(AINPUT_SOURCE_MOUSE)))); |
| 4935 | |
| 4936 | ASSERT_NO_FATAL_FAILURE( |
Siarhei Vishniakou | 0b0374d | 2022-11-17 17:40:53 -0800 | [diff] [blame] | 4937 | window->consumeMotionEvent(AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 4938 | WithSource(AINPUT_SOURCE_TOUCHSCREEN)))); |
| 4939 | |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 4940 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN) |
| 4941 | .pointer(PointerBuilder(0, ToolType::FINGER).x(10).y(10)) |
| 4942 | .build()); |
Siarhei Vishniakou | 0b0374d | 2022-11-17 17:40:53 -0800 | [diff] [blame] | 4943 | ASSERT_NO_FATAL_FAILURE( |
| 4944 | window->consumeMotionEvent(AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 4945 | WithSource(AINPUT_SOURCE_TOUCHSCREEN)))); |
| 4946 | } |
| 4947 | |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 4948 | /** |
| 4949 | * Send a mouse hover event followed by a tap from touchscreen. |
| 4950 | * The tap causes a HOVER_EXIT event to be generated because the current event |
| 4951 | * stream's source has been switched. |
| 4952 | */ |
| 4953 | TEST_F(InputDispatcherTest, MouseHoverAndTouchTap) { |
| 4954 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); |
| 4955 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 4956 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 4957 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 4958 | window->setFrame(Rect(0, 0, 100, 100)); |
| 4959 | |
| 4960 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
| 4961 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) |
| 4962 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(50).y(50)) |
| 4963 | .build()); |
| 4964 | |
| 4965 | window->consumeMotionEvent(AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 4966 | WithSource(AINPUT_SOURCE_MOUSE))); |
| 4967 | |
| 4968 | // Tap on the window |
| 4969 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 4970 | .pointer(PointerBuilder(0, ToolType::FINGER).x(10).y(10)) |
| 4971 | .build()); |
| 4972 | |
| 4973 | window->consumeMotionEvent(AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), |
| 4974 | WithSource(AINPUT_SOURCE_MOUSE))); |
| 4975 | |
| 4976 | window->consumeMotionEvent(AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 4977 | WithSource(AINPUT_SOURCE_TOUCHSCREEN))); |
| 4978 | |
| 4979 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN) |
| 4980 | .pointer(PointerBuilder(0, ToolType::FINGER).x(10).y(10)) |
| 4981 | .build()); |
| 4982 | |
| 4983 | window->consumeMotionEvent(AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 4984 | WithSource(AINPUT_SOURCE_TOUCHSCREEN))); |
| 4985 | } |
| 4986 | |
Tommy Nordgren | dae9dfc | 2022-10-13 11:25:57 +0200 | [diff] [blame] | 4987 | TEST_F(InputDispatcherTest, HoverEnterMoveRemoveWindowsInSecondDisplay) { |
| 4988 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 4989 | sp<FakeWindowHandle> windowDefaultDisplay = |
| 4990 | sp<FakeWindowHandle>::make(application, mDispatcher, "DefaultDisplay", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 4991 | ui::LogicalDisplayId::DEFAULT); |
Tommy Nordgren | dae9dfc | 2022-10-13 11:25:57 +0200 | [diff] [blame] | 4992 | windowDefaultDisplay->setFrame(Rect(0, 0, 600, 800)); |
| 4993 | sp<FakeWindowHandle> windowSecondDisplay = |
| 4994 | sp<FakeWindowHandle>::make(application, mDispatcher, "SecondDisplay", |
| 4995 | SECOND_DISPLAY_ID); |
| 4996 | windowSecondDisplay->setFrame(Rect(0, 0, 600, 800)); |
| 4997 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 4998 | mDispatcher->onWindowInfosChanged( |
| 4999 | {{*windowDefaultDisplay->getInfo(), *windowSecondDisplay->getInfo()}, {}, 0, 0}); |
Tommy Nordgren | dae9dfc | 2022-10-13 11:25:57 +0200 | [diff] [blame] | 5000 | |
| 5001 | // Set cursor position in window in default display and check that hover enter and move |
| 5002 | // events are generated. |
| 5003 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 5004 | injectMotionEvent(*mDispatcher, |
Tommy Nordgren | dae9dfc | 2022-10-13 11:25:57 +0200 | [diff] [blame] | 5005 | MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, |
| 5006 | AINPUT_SOURCE_MOUSE) |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5007 | .displayId(ui::LogicalDisplayId::DEFAULT) |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 5008 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(600)) |
Tommy Nordgren | dae9dfc | 2022-10-13 11:25:57 +0200 | [diff] [blame] | 5009 | .build())); |
Siarhei Vishniakou | 5cee1e3 | 2022-11-29 12:35:39 -0800 | [diff] [blame] | 5010 | windowDefaultDisplay->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)); |
Tommy Nordgren | dae9dfc | 2022-10-13 11:25:57 +0200 | [diff] [blame] | 5011 | |
| 5012 | // Remove all windows in secondary display and check that no event happens on window in |
| 5013 | // primary display. |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 5014 | mDispatcher->onWindowInfosChanged({{*windowDefaultDisplay->getInfo()}, {}, 0, 0}); |
| 5015 | |
Tommy Nordgren | dae9dfc | 2022-10-13 11:25:57 +0200 | [diff] [blame] | 5016 | windowDefaultDisplay->assertNoEvents(); |
| 5017 | |
| 5018 | // Move cursor position in window in default display and check that only hover move |
| 5019 | // event is generated and not hover enter event. |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 5020 | mDispatcher->onWindowInfosChanged( |
| 5021 | {{*windowDefaultDisplay->getInfo(), *windowSecondDisplay->getInfo()}, {}, 0, 0}); |
Tommy Nordgren | dae9dfc | 2022-10-13 11:25:57 +0200 | [diff] [blame] | 5022 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 5023 | injectMotionEvent(*mDispatcher, |
Tommy Nordgren | dae9dfc | 2022-10-13 11:25:57 +0200 | [diff] [blame] | 5024 | MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, |
| 5025 | AINPUT_SOURCE_MOUSE) |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5026 | .displayId(ui::LogicalDisplayId::DEFAULT) |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 5027 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(400).y(700)) |
Tommy Nordgren | dae9dfc | 2022-10-13 11:25:57 +0200 | [diff] [blame] | 5028 | .build())); |
Siarhei Vishniakou | 5cee1e3 | 2022-11-29 12:35:39 -0800 | [diff] [blame] | 5029 | windowDefaultDisplay->consumeMotionEvent( |
| 5030 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), |
| 5031 | WithSource(AINPUT_SOURCE_MOUSE))); |
Tommy Nordgren | dae9dfc | 2022-10-13 11:25:57 +0200 | [diff] [blame] | 5032 | windowDefaultDisplay->assertNoEvents(); |
| 5033 | } |
| 5034 | |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 5035 | TEST_F(InputDispatcherTest, DispatchMouseEventsUnderCursor) { |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 5036 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 5037 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5038 | sp<FakeWindowHandle> windowLeft = sp<FakeWindowHandle>::make(application, mDispatcher, "Left", |
| 5039 | ui::LogicalDisplayId::DEFAULT); |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 5040 | windowLeft->setFrame(Rect(0, 0, 600, 800)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5041 | sp<FakeWindowHandle> windowRight = sp<FakeWindowHandle>::make(application, mDispatcher, "Right", |
| 5042 | ui::LogicalDisplayId::DEFAULT); |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 5043 | windowRight->setFrame(Rect(600, 0, 1200, 800)); |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 5044 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5045 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 5046 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 5047 | mDispatcher->onWindowInfosChanged( |
| 5048 | {{*windowLeft->getInfo(), *windowRight->getInfo()}, {}, 0, 0}); |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 5049 | |
| 5050 | // Inject an event with coordinate in the area of right window, with mouse cursor in the area of |
| 5051 | // left window. This event should be dispatched to the left window. |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 5052 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 5053 | injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_MOUSE, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5054 | ui::LogicalDisplayId::DEFAULT, {610, 400}, {599, 400})); |
| 5055 | windowLeft->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 5056 | windowRight->assertNoEvents(); |
| 5057 | } |
| 5058 | |
Siarhei Vishniakou | 2bfa905 | 2019-11-21 18:10:54 -0800 | [diff] [blame] | 5059 | TEST_F(InputDispatcherTest, NotifyDeviceReset_CancelsKeyStream) { |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 5060 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5061 | sp<FakeWindowHandle> window = |
| 5062 | sp<FakeWindowHandle>::make(application, mDispatcher, "Fake Window", |
| 5063 | ui::LogicalDisplayId::DEFAULT); |
Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 5064 | window->setFocusable(true); |
Siarhei Vishniakou | 2bfa905 | 2019-11-21 18:10:54 -0800 | [diff] [blame] | 5065 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 5066 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 5067 | setFocusedWindow(window); |
| 5068 | |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 5069 | window->consumeFocusEvent(true); |
Siarhei Vishniakou | 2bfa905 | 2019-11-21 18:10:54 -0800 | [diff] [blame] | 5070 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5071 | mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ui::LogicalDisplayId::DEFAULT)); |
Siarhei Vishniakou | 2bfa905 | 2019-11-21 18:10:54 -0800 | [diff] [blame] | 5072 | |
| 5073 | // Window should receive key down event. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5074 | window->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 2bfa905 | 2019-11-21 18:10:54 -0800 | [diff] [blame] | 5075 | |
| 5076 | // When device reset happens, that key stream should be terminated with FLAG_CANCELED |
| 5077 | // on the app side. |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 5078 | mDispatcher->notifyDeviceReset({/*id=*/10, /*eventTime=*/20, DEVICE_ID}); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5079 | window->consumeKeyUp(ui::LogicalDisplayId::DEFAULT, AKEY_EVENT_FLAG_CANCELED); |
Siarhei Vishniakou | 2bfa905 | 2019-11-21 18:10:54 -0800 | [diff] [blame] | 5080 | } |
| 5081 | |
| 5082 | TEST_F(InputDispatcherTest, NotifyDeviceReset_CancelsMotionStream) { |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 5083 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5084 | sp<FakeWindowHandle> window = |
| 5085 | sp<FakeWindowHandle>::make(application, mDispatcher, "Fake Window", |
| 5086 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 2bfa905 | 2019-11-21 18:10:54 -0800 | [diff] [blame] | 5087 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 5088 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | 2bfa905 | 2019-11-21 18:10:54 -0800 | [diff] [blame] | 5089 | |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 5090 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5091 | AINPUT_SOURCE_TOUCHSCREEN, |
| 5092 | ui::LogicalDisplayId::DEFAULT)); |
Siarhei Vishniakou | 2bfa905 | 2019-11-21 18:10:54 -0800 | [diff] [blame] | 5093 | |
| 5094 | // Window should receive motion down event. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5095 | window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 2bfa905 | 2019-11-21 18:10:54 -0800 | [diff] [blame] | 5096 | |
| 5097 | // When device reset happens, that motion stream should be terminated with ACTION_CANCEL |
| 5098 | // on the app side. |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 5099 | mDispatcher->notifyDeviceReset({/*id=*/10, /*eventTime=*/20, DEVICE_ID}); |
Siarhei Vishniakou | 1ae72f1 | 2023-01-29 12:55:30 -0800 | [diff] [blame] | 5100 | window->consumeMotionEvent( |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5101 | AllOf(WithMotionAction(ACTION_CANCEL), WithDisplayId(ui::LogicalDisplayId::DEFAULT))); |
Siarhei Vishniakou | 2bfa905 | 2019-11-21 18:10:54 -0800 | [diff] [blame] | 5102 | } |
| 5103 | |
Siarhei Vishniakou | 0686f0c | 2023-05-02 11:56:15 -0700 | [diff] [blame] | 5104 | TEST_F(InputDispatcherTest, NotifyDeviceResetCancelsHoveringStream) { |
| 5105 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5106 | sp<FakeWindowHandle> window = |
| 5107 | sp<FakeWindowHandle>::make(application, mDispatcher, "Fake Window", |
| 5108 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 0686f0c | 2023-05-02 11:56:15 -0700 | [diff] [blame] | 5109 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 5110 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | 0686f0c | 2023-05-02 11:56:15 -0700 | [diff] [blame] | 5111 | |
| 5112 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS) |
| 5113 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(10).y(10)) |
| 5114 | .build()); |
| 5115 | |
| 5116 | window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); |
| 5117 | |
| 5118 | // When device reset happens, that hover stream should be terminated with ACTION_HOVER_EXIT |
| 5119 | mDispatcher->notifyDeviceReset({/*id=*/10, /*eventTime=*/20, DEVICE_ID}); |
| 5120 | window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); |
| 5121 | |
| 5122 | // After the device has been reset, a new hovering stream can be sent to the window |
| 5123 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS) |
| 5124 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(15).y(15)) |
| 5125 | .build()); |
| 5126 | window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); |
| 5127 | } |
| 5128 | |
Arthur Hung | 2ee6d0b | 2022-03-03 20:19:38 +0800 | [diff] [blame] | 5129 | TEST_F(InputDispatcherTest, InterceptKeyByPolicy) { |
| 5130 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5131 | sp<FakeWindowHandle> window = |
| 5132 | sp<FakeWindowHandle>::make(application, mDispatcher, "Fake Window", |
| 5133 | ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | 2ee6d0b | 2022-03-03 20:19:38 +0800 | [diff] [blame] | 5134 | window->setFocusable(true); |
| 5135 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 5136 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Arthur Hung | 2ee6d0b | 2022-03-03 20:19:38 +0800 | [diff] [blame] | 5137 | setFocusedWindow(window); |
| 5138 | |
| 5139 | window->consumeFocusEvent(true); |
| 5140 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5141 | const NotifyKeyArgs keyArgs = |
| 5142 | generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | 2ee6d0b | 2022-03-03 20:19:38 +0800 | [diff] [blame] | 5143 | const std::chrono::milliseconds interceptKeyTimeout = 50ms; |
| 5144 | const nsecs_t injectTime = keyArgs.eventTime; |
| 5145 | mFakePolicy->setInterceptKeyTimeout(interceptKeyTimeout); |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 5146 | mDispatcher->notifyKey(keyArgs); |
Arthur Hung | 2ee6d0b | 2022-03-03 20:19:38 +0800 | [diff] [blame] | 5147 | // The dispatching time should be always greater than or equal to intercept key timeout. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5148 | window->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | 2ee6d0b | 2022-03-03 20:19:38 +0800 | [diff] [blame] | 5149 | ASSERT_TRUE((systemTime(SYSTEM_TIME_MONOTONIC) - injectTime) >= |
| 5150 | std::chrono::nanoseconds(interceptKeyTimeout).count()); |
| 5151 | } |
| 5152 | |
Siarhei Vishniakou | f54d2ab | 2023-06-09 13:23:53 -0700 | [diff] [blame] | 5153 | /** |
| 5154 | * Keys with ACTION_UP are delivered immediately, even if a long 'intercept key timeout' is set. |
| 5155 | */ |
Arthur Hung | 2ee6d0b | 2022-03-03 20:19:38 +0800 | [diff] [blame] | 5156 | TEST_F(InputDispatcherTest, InterceptKeyIfKeyUp) { |
| 5157 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5158 | sp<FakeWindowHandle> window = |
| 5159 | sp<FakeWindowHandle>::make(application, mDispatcher, "Fake Window", |
| 5160 | ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | 2ee6d0b | 2022-03-03 20:19:38 +0800 | [diff] [blame] | 5161 | window->setFocusable(true); |
| 5162 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 5163 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Arthur Hung | 2ee6d0b | 2022-03-03 20:19:38 +0800 | [diff] [blame] | 5164 | setFocusedWindow(window); |
| 5165 | |
| 5166 | window->consumeFocusEvent(true); |
| 5167 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5168 | mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ui::LogicalDisplayId::DEFAULT)); |
| 5169 | window->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | f54d2ab | 2023-06-09 13:23:53 -0700 | [diff] [blame] | 5170 | |
| 5171 | // Set a value that's significantly larger than the default consumption timeout. If the |
| 5172 | // implementation is correct, the actual value doesn't matter; it won't slow down the test. |
| 5173 | mFakePolicy->setInterceptKeyTimeout(600ms); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5174 | mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_UP, ui::LogicalDisplayId::DEFAULT)); |
Siarhei Vishniakou | f54d2ab | 2023-06-09 13:23:53 -0700 | [diff] [blame] | 5175 | // Window should receive key event immediately when same key up. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5176 | window->consumeKeyUp(ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | 2ee6d0b | 2022-03-03 20:19:38 +0800 | [diff] [blame] | 5177 | } |
| 5178 | |
Prabir Pradhan | c44ce4d | 2021-10-05 05:26:29 -0700 | [diff] [blame] | 5179 | /** |
Siarhei Vishniakou | 487c49b | 2022-12-02 15:48:57 -0800 | [diff] [blame] | 5180 | * Two windows. First is a regular window. Second does not overlap with the first, and has |
| 5181 | * WATCH_OUTSIDE_TOUCH. |
| 5182 | * Both windows are owned by the same UID. |
| 5183 | * Tap first window. Make sure that the second window receives ACTION_OUTSIDE with correct, non-zero |
| 5184 | * coordinates. The coordinates are not zeroed out because both windows are owned by the same UID. |
| 5185 | */ |
| 5186 | TEST_F(InputDispatcherTest, ActionOutsideForOwnedWindowHasValidCoordinates) { |
| 5187 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5188 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 5189 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 487c49b | 2022-12-02 15:48:57 -0800 | [diff] [blame] | 5190 | window->setFrame(Rect{0, 0, 100, 100}); |
| 5191 | |
| 5192 | sp<FakeWindowHandle> outsideWindow = |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 5193 | sp<FakeWindowHandle>::make(application, mDispatcher, "Outside Window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5194 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 487c49b | 2022-12-02 15:48:57 -0800 | [diff] [blame] | 5195 | outsideWindow->setFrame(Rect{100, 100, 200, 200}); |
| 5196 | outsideWindow->setWatchOutsideTouch(true); |
| 5197 | // outsideWindow must be above 'window' to receive ACTION_OUTSIDE events when 'window' is tapped |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 5198 | mDispatcher->onWindowInfosChanged({{*outsideWindow->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | 487c49b | 2022-12-02 15:48:57 -0800 | [diff] [blame] | 5199 | |
| 5200 | // Tap on first window. |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 5201 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5202 | AINPUT_SOURCE_TOUCHSCREEN, |
| 5203 | ui::LogicalDisplayId::DEFAULT, {PointF{50, 50}})); |
Siarhei Vishniakou | 487c49b | 2022-12-02 15:48:57 -0800 | [diff] [blame] | 5204 | window->consumeMotionDown(); |
| 5205 | // The coordinates of the tap in 'outsideWindow' are relative to its top left corner. |
| 5206 | // Therefore, we should offset them by (100, 100) relative to the screen's top left corner. |
| 5207 | outsideWindow->consumeMotionEvent( |
| 5208 | AllOf(WithMotionAction(ACTION_OUTSIDE), WithCoords(-50, -50))); |
Prabir Pradhan | 502a725 | 2023-12-01 16:11:24 +0000 | [diff] [blame] | 5209 | |
| 5210 | // Ensure outsideWindow doesn't get any more events for the gesture. |
| 5211 | mDispatcher->notifyMotion(generateMotionArgs(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5212 | ui::LogicalDisplayId::DEFAULT, {PointF{51, 51}})); |
Prabir Pradhan | 502a725 | 2023-12-01 16:11:24 +0000 | [diff] [blame] | 5213 | window->consumeMotionMove(); |
| 5214 | outsideWindow->assertNoEvents(); |
Siarhei Vishniakou | 487c49b | 2022-12-02 15:48:57 -0800 | [diff] [blame] | 5215 | } |
| 5216 | |
| 5217 | /** |
Linnan Li | ccf6ce3 | 2024-04-11 20:32:13 +0800 | [diff] [blame] | 5218 | * Three windows: |
| 5219 | * - Left window |
| 5220 | * - Right window |
| 5221 | * - Outside window(watch for ACTION_OUTSIDE events) |
| 5222 | * The windows "left" and "outside" share the same owner, the window "right" has a different owner, |
| 5223 | * In order to allow the outside window can receive the ACTION_OUTSIDE events, the outside window is |
| 5224 | * positioned above the "left" and "right" windows, and it doesn't overlap with them. |
| 5225 | * |
| 5226 | * First, device A report a down event landed in the right window, the outside window can receive |
| 5227 | * an ACTION_OUTSIDE event that with zeroed coordinates, the device B report a down event landed |
| 5228 | * in the left window, the outside window can receive an ACTION_OUTSIDE event the with valid |
| 5229 | * coordinates, after these, device A and device B continue report MOVE event, the right and left |
| 5230 | * window can receive it, but outside window event can't receive it. |
| 5231 | */ |
| 5232 | TEST_F(InputDispatcherTest, ActionOutsideForOwnedWindowHasValidCoordinatesWhenMultiDevice) { |
| 5233 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 5234 | sp<FakeWindowHandle> leftWindow = |
| 5235 | sp<FakeWindowHandle>::make(application, mDispatcher, "Left Window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5236 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | ccf6ce3 | 2024-04-11 20:32:13 +0800 | [diff] [blame] | 5237 | leftWindow->setFrame(Rect{0, 0, 100, 100}); |
| 5238 | leftWindow->setOwnerInfo(gui::Pid{1}, gui::Uid{101}); |
| 5239 | |
| 5240 | sp<FakeWindowHandle> outsideWindow = |
| 5241 | sp<FakeWindowHandle>::make(application, mDispatcher, "Outside Window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5242 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | ccf6ce3 | 2024-04-11 20:32:13 +0800 | [diff] [blame] | 5243 | outsideWindow->setFrame(Rect{100, 100, 200, 200}); |
| 5244 | outsideWindow->setOwnerInfo(gui::Pid{1}, gui::Uid{101}); |
| 5245 | outsideWindow->setWatchOutsideTouch(true); |
| 5246 | |
| 5247 | std::shared_ptr<FakeApplicationHandle> anotherApplication = |
| 5248 | std::make_shared<FakeApplicationHandle>(); |
| 5249 | sp<FakeWindowHandle> rightWindow = |
| 5250 | sp<FakeWindowHandle>::make(anotherApplication, mDispatcher, "Right Window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5251 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | ccf6ce3 | 2024-04-11 20:32:13 +0800 | [diff] [blame] | 5252 | rightWindow->setFrame(Rect{100, 0, 200, 100}); |
| 5253 | rightWindow->setOwnerInfo(gui::Pid{2}, gui::Uid{202}); |
| 5254 | |
| 5255 | // OutsideWindow must be above left window and right window to receive ACTION_OUTSIDE events |
| 5256 | // when left window or right window is tapped |
| 5257 | mDispatcher->onWindowInfosChanged( |
| 5258 | {{*outsideWindow->getInfo(), *leftWindow->getInfo(), *rightWindow->getInfo()}, |
| 5259 | {}, |
| 5260 | 0, |
| 5261 | 0}); |
| 5262 | |
| 5263 | const DeviceId deviceA = 9; |
| 5264 | const DeviceId deviceB = 3; |
| 5265 | |
| 5266 | // Tap on right window use device A |
| 5267 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 5268 | .pointer(PointerBuilder(0, ToolType::FINGER).x(150).y(50)) |
| 5269 | .deviceId(deviceA) |
| 5270 | .build()); |
| 5271 | leftWindow->assertNoEvents(); |
| 5272 | rightWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(deviceA))); |
| 5273 | // Right window is belonged to another owner, so outsideWindow should receive ACTION_OUTSIDE |
| 5274 | // with zeroed coords. |
| 5275 | outsideWindow->consumeMotionEvent( |
| 5276 | AllOf(WithMotionAction(ACTION_OUTSIDE), WithDeviceId(deviceA), WithCoords(0, 0))); |
| 5277 | |
| 5278 | // Tap on left window use device B |
| 5279 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 5280 | .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) |
| 5281 | .deviceId(deviceB) |
| 5282 | .build()); |
| 5283 | leftWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(deviceB))); |
| 5284 | rightWindow->assertNoEvents(); |
| 5285 | // Because new gesture down on the left window that has the same owner with outside Window, the |
| 5286 | // outside Window should receive the ACTION_OUTSIDE with coords. |
| 5287 | outsideWindow->consumeMotionEvent( |
| 5288 | AllOf(WithMotionAction(ACTION_OUTSIDE), WithDeviceId(deviceB), WithCoords(-50, -50))); |
| 5289 | |
| 5290 | // Ensure that windows that can only accept outside do not receive remaining gestures |
| 5291 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 5292 | .pointer(PointerBuilder(0, ToolType::FINGER).x(151).y(51)) |
| 5293 | .deviceId(deviceA) |
| 5294 | .build()); |
| 5295 | leftWindow->assertNoEvents(); |
| 5296 | rightWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(deviceA))); |
| 5297 | |
| 5298 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 5299 | .pointer(PointerBuilder(0, ToolType::FINGER).x(51).y(51)) |
| 5300 | .deviceId(deviceB) |
| 5301 | .build()); |
| 5302 | leftWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(deviceB))); |
| 5303 | rightWindow->assertNoEvents(); |
| 5304 | outsideWindow->assertNoEvents(); |
| 5305 | } |
| 5306 | |
| 5307 | /** |
Prabir Pradhan | b60b1dc | 2022-03-15 14:02:35 +0000 | [diff] [blame] | 5308 | * This test documents the behavior of WATCH_OUTSIDE_TOUCH. The window will get ACTION_OUTSIDE when |
| 5309 | * a another pointer causes ACTION_DOWN to be sent to another window for the first time. Only one |
| 5310 | * ACTION_OUTSIDE event is sent per gesture. |
| 5311 | */ |
| 5312 | TEST_F(InputDispatcherTest, ActionOutsideSentOnlyWhenAWindowIsTouched) { |
| 5313 | // There are three windows that do not overlap. `window` wants to WATCH_OUTSIDE_TOUCH. |
| 5314 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5315 | sp<FakeWindowHandle> window = |
| 5316 | sp<FakeWindowHandle>::make(application, mDispatcher, "First Window", |
| 5317 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | b60b1dc | 2022-03-15 14:02:35 +0000 | [diff] [blame] | 5318 | window->setWatchOutsideTouch(true); |
| 5319 | window->setFrame(Rect{0, 0, 100, 100}); |
| 5320 | sp<FakeWindowHandle> secondWindow = |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 5321 | sp<FakeWindowHandle>::make(application, mDispatcher, "Second Window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5322 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | b60b1dc | 2022-03-15 14:02:35 +0000 | [diff] [blame] | 5323 | secondWindow->setFrame(Rect{100, 100, 200, 200}); |
| 5324 | sp<FakeWindowHandle> thirdWindow = |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 5325 | sp<FakeWindowHandle>::make(application, mDispatcher, "Third Window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5326 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | b60b1dc | 2022-03-15 14:02:35 +0000 | [diff] [blame] | 5327 | thirdWindow->setFrame(Rect{200, 200, 300, 300}); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 5328 | mDispatcher->onWindowInfosChanged( |
| 5329 | {{*window->getInfo(), *secondWindow->getInfo(), *thirdWindow->getInfo()}, {}, 0, 0}); |
Prabir Pradhan | b60b1dc | 2022-03-15 14:02:35 +0000 | [diff] [blame] | 5330 | |
| 5331 | // First pointer lands outside all windows. `window` does not get ACTION_OUTSIDE. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5332 | mDispatcher->notifyMotion( |
| 5333 | generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, |
| 5334 | ui::LogicalDisplayId::DEFAULT, {PointF{-10, -10}})); |
Prabir Pradhan | b60b1dc | 2022-03-15 14:02:35 +0000 | [diff] [blame] | 5335 | window->assertNoEvents(); |
| 5336 | secondWindow->assertNoEvents(); |
| 5337 | |
| 5338 | // The second pointer lands inside `secondWindow`, which should receive a DOWN event. |
| 5339 | // Now, `window` should get ACTION_OUTSIDE. |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 5340 | mDispatcher->notifyMotion(generateMotionArgs(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5341 | ui::LogicalDisplayId::DEFAULT, |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 5342 | {PointF{-10, -10}, PointF{105, 105}})); |
Siarhei Vishniakou | 487c49b | 2022-12-02 15:48:57 -0800 | [diff] [blame] | 5343 | const std::map<int32_t, PointF> expectedPointers{{0, PointF{-10, -10}}, {1, PointF{105, 105}}}; |
| 5344 | window->consumeMotionEvent( |
| 5345 | AllOf(WithMotionAction(ACTION_OUTSIDE), WithPointers(expectedPointers))); |
Prabir Pradhan | b60b1dc | 2022-03-15 14:02:35 +0000 | [diff] [blame] | 5346 | secondWindow->consumeMotionDown(); |
| 5347 | thirdWindow->assertNoEvents(); |
| 5348 | |
| 5349 | // The third pointer lands inside `thirdWindow`, which should receive a DOWN event. There is |
| 5350 | // no ACTION_OUTSIDE sent to `window` because one has already been sent for this gesture. |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 5351 | mDispatcher->notifyMotion( |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5352 | generateMotionArgs(POINTER_2_DOWN, AINPUT_SOURCE_TOUCHSCREEN, |
| 5353 | ui::LogicalDisplayId::DEFAULT, |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 5354 | {PointF{-10, -10}, PointF{105, 105}, PointF{205, 205}})); |
Prabir Pradhan | b60b1dc | 2022-03-15 14:02:35 +0000 | [diff] [blame] | 5355 | window->assertNoEvents(); |
| 5356 | secondWindow->consumeMotionMove(); |
| 5357 | thirdWindow->consumeMotionDown(); |
| 5358 | } |
| 5359 | |
Prabir Pradhan | 814fe08 | 2022-07-22 20:22:18 +0000 | [diff] [blame] | 5360 | TEST_F(InputDispatcherTest, OnWindowInfosChanged_RemoveAllWindowsOnDisplay) { |
| 5361 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5362 | sp<FakeWindowHandle> window = |
| 5363 | sp<FakeWindowHandle>::make(application, mDispatcher, "Fake Window", |
| 5364 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 814fe08 | 2022-07-22 20:22:18 +0000 | [diff] [blame] | 5365 | window->setFocusable(true); |
| 5366 | |
Patrick Williams | d828f30 | 2023-04-28 17:52:08 -0500 | [diff] [blame] | 5367 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Prabir Pradhan | 814fe08 | 2022-07-22 20:22:18 +0000 | [diff] [blame] | 5368 | setFocusedWindow(window); |
| 5369 | |
| 5370 | window->consumeFocusEvent(true); |
| 5371 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5372 | const NotifyKeyArgs keyDown = |
| 5373 | generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ui::LogicalDisplayId::DEFAULT); |
| 5374 | const NotifyKeyArgs keyUp = |
| 5375 | generateKeyArgs(AKEY_EVENT_ACTION_UP, ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 5376 | mDispatcher->notifyKey(keyDown); |
| 5377 | mDispatcher->notifyKey(keyUp); |
Prabir Pradhan | 814fe08 | 2022-07-22 20:22:18 +0000 | [diff] [blame] | 5378 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5379 | window->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); |
| 5380 | window->consumeKeyUp(ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 814fe08 | 2022-07-22 20:22:18 +0000 | [diff] [blame] | 5381 | |
| 5382 | // All windows are removed from the display. Ensure that we can no longer dispatch to it. |
Patrick Williams | d828f30 | 2023-04-28 17:52:08 -0500 | [diff] [blame] | 5383 | mDispatcher->onWindowInfosChanged({{}, {}, 0, 0}); |
Prabir Pradhan | 814fe08 | 2022-07-22 20:22:18 +0000 | [diff] [blame] | 5384 | |
| 5385 | window->consumeFocusEvent(false); |
| 5386 | |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 5387 | mDispatcher->notifyKey(keyDown); |
| 5388 | mDispatcher->notifyKey(keyUp); |
Prabir Pradhan | 814fe08 | 2022-07-22 20:22:18 +0000 | [diff] [blame] | 5389 | window->assertNoEvents(); |
| 5390 | } |
| 5391 | |
Arthur Hung | 9648374 | 2022-11-15 03:30:48 +0000 | [diff] [blame] | 5392 | TEST_F(InputDispatcherTest, NonSplitTouchableWindowReceivesMultiTouch) { |
| 5393 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5394 | sp<FakeWindowHandle> window = |
| 5395 | sp<FakeWindowHandle>::make(application, mDispatcher, "Fake Window", |
| 5396 | ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | 9648374 | 2022-11-15 03:30:48 +0000 | [diff] [blame] | 5397 | // Ensure window is non-split and have some transform. |
| 5398 | window->setPreventSplitting(true); |
| 5399 | window->setWindowOffset(20, 40); |
Patrick Williams | d828f30 | 2023-04-28 17:52:08 -0500 | [diff] [blame] | 5400 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Arthur Hung | 9648374 | 2022-11-15 03:30:48 +0000 | [diff] [blame] | 5401 | |
| 5402 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5403 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 5404 | ui::LogicalDisplayId::DEFAULT, {50, 50})) |
Arthur Hung | 9648374 | 2022-11-15 03:30:48 +0000 | [diff] [blame] | 5405 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5406 | window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | 9648374 | 2022-11-15 03:30:48 +0000 | [diff] [blame] | 5407 | |
| 5408 | const MotionEvent secondFingerDownEvent = |
| 5409 | MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5410 | .displayId(ui::LogicalDisplayId::DEFAULT) |
Arthur Hung | 9648374 | 2022-11-15 03:30:48 +0000 | [diff] [blame] | 5411 | .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 5412 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(50).y(50)) |
| 5413 | .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(-30).y(-50)) |
Arthur Hung | 9648374 | 2022-11-15 03:30:48 +0000 | [diff] [blame] | 5414 | .build(); |
| 5415 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 5416 | injectMotionEvent(*mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, |
Arthur Hung | 9648374 | 2022-11-15 03:30:48 +0000 | [diff] [blame] | 5417 | InputEventInjectionSync::WAIT_FOR_RESULT)) |
| 5418 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 5419 | |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 5420 | std::unique_ptr<MotionEvent> event = window->consumeMotionEvent(); |
| 5421 | ASSERT_NE(nullptr, event); |
| 5422 | EXPECT_EQ(POINTER_1_DOWN, event->getAction()); |
| 5423 | EXPECT_EQ(70, event->getX(0)); // 50 + 20 |
| 5424 | EXPECT_EQ(90, event->getY(0)); // 50 + 40 |
| 5425 | EXPECT_EQ(-10, event->getX(1)); // -30 + 20 |
| 5426 | EXPECT_EQ(-10, event->getY(1)); // -50 + 40 |
Arthur Hung | 9648374 | 2022-11-15 03:30:48 +0000 | [diff] [blame] | 5427 | } |
| 5428 | |
Siarhei Vishniakou | 25537f8 | 2023-07-18 14:35:47 -0700 | [diff] [blame] | 5429 | /** |
| 5430 | * Two windows: a splittable and a non-splittable. |
| 5431 | * The non-splittable window shouldn't receive any "incomplete" gestures. |
| 5432 | * Send the first pointer to the splittable window, and then touch the non-splittable window. |
| 5433 | * The second pointer should be dropped because the initial window is splittable, so it won't get |
| 5434 | * any pointers outside of it, and the second window is non-splittable, so it shouldn't get any |
| 5435 | * "incomplete" gestures. |
| 5436 | */ |
| 5437 | TEST_F(InputDispatcherTest, SplittableAndNonSplittableWindows) { |
| 5438 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 5439 | sp<FakeWindowHandle> leftWindow = |
| 5440 | sp<FakeWindowHandle>::make(application, mDispatcher, "Left splittable Window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5441 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 25537f8 | 2023-07-18 14:35:47 -0700 | [diff] [blame] | 5442 | leftWindow->setPreventSplitting(false); |
| 5443 | leftWindow->setFrame(Rect(0, 0, 100, 100)); |
| 5444 | sp<FakeWindowHandle> rightWindow = |
| 5445 | sp<FakeWindowHandle>::make(application, mDispatcher, "Right non-splittable Window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5446 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 25537f8 | 2023-07-18 14:35:47 -0700 | [diff] [blame] | 5447 | rightWindow->setPreventSplitting(true); |
| 5448 | rightWindow->setFrame(Rect(100, 100, 200, 200)); |
| 5449 | mDispatcher->onWindowInfosChanged( |
| 5450 | {{*leftWindow->getInfo(), *rightWindow->getInfo()}, {}, 0, 0}); |
| 5451 | |
| 5452 | // Touch down on left, splittable window |
| 5453 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 5454 | .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) |
| 5455 | .build()); |
| 5456 | leftWindow->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); |
| 5457 | |
| 5458 | mDispatcher->notifyMotion( |
| 5459 | MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 5460 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(50).y(50)) |
| 5461 | .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(150).y(150)) |
| 5462 | .build()); |
| 5463 | leftWindow->assertNoEvents(); |
| 5464 | rightWindow->assertNoEvents(); |
| 5465 | } |
| 5466 | |
Harry Cutts | b166c00 | 2023-05-09 13:06:05 +0000 | [diff] [blame] | 5467 | TEST_F(InputDispatcherTest, TouchpadThreeFingerSwipeOnlySentToTrustedOverlays) { |
| 5468 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5469 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 5470 | ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | b166c00 | 2023-05-09 13:06:05 +0000 | [diff] [blame] | 5471 | window->setFrame(Rect(0, 0, 400, 400)); |
| 5472 | sp<FakeWindowHandle> trustedOverlay = |
| 5473 | sp<FakeWindowHandle>::make(application, mDispatcher, "Trusted Overlay", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5474 | ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | b166c00 | 2023-05-09 13:06:05 +0000 | [diff] [blame] | 5475 | trustedOverlay->setSpy(true); |
| 5476 | trustedOverlay->setTrustedOverlay(true); |
| 5477 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 5478 | mDispatcher->onWindowInfosChanged({{*trustedOverlay->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Harry Cutts | b166c00 | 2023-05-09 13:06:05 +0000 | [diff] [blame] | 5479 | |
| 5480 | // Start a three-finger touchpad swipe |
| 5481 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_MOUSE) |
| 5482 | .pointer(PointerBuilder(0, ToolType::FINGER).x(200).y(100)) |
| 5483 | .classification(MotionClassification::MULTI_FINGER_SWIPE) |
| 5484 | .build()); |
| 5485 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_MOUSE) |
| 5486 | .pointer(PointerBuilder(0, ToolType::FINGER).x(200).y(100)) |
| 5487 | .pointer(PointerBuilder(1, ToolType::FINGER).x(250).y(100)) |
| 5488 | .classification(MotionClassification::MULTI_FINGER_SWIPE) |
| 5489 | .build()); |
| 5490 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_2_DOWN, AINPUT_SOURCE_MOUSE) |
| 5491 | .pointer(PointerBuilder(0, ToolType::FINGER).x(200).y(100)) |
| 5492 | .pointer(PointerBuilder(1, ToolType::FINGER).x(250).y(100)) |
| 5493 | .pointer(PointerBuilder(2, ToolType::FINGER).x(300).y(100)) |
| 5494 | .classification(MotionClassification::MULTI_FINGER_SWIPE) |
| 5495 | .build()); |
| 5496 | |
| 5497 | trustedOverlay->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); |
| 5498 | trustedOverlay->consumeMotionEvent(WithMotionAction(POINTER_1_DOWN)); |
| 5499 | trustedOverlay->consumeMotionEvent(WithMotionAction(POINTER_2_DOWN)); |
| 5500 | |
| 5501 | // Move the swipe a bit |
| 5502 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_MOUSE) |
| 5503 | .pointer(PointerBuilder(0, ToolType::FINGER).x(200).y(105)) |
| 5504 | .pointer(PointerBuilder(1, ToolType::FINGER).x(250).y(105)) |
| 5505 | .pointer(PointerBuilder(2, ToolType::FINGER).x(300).y(105)) |
| 5506 | .classification(MotionClassification::MULTI_FINGER_SWIPE) |
| 5507 | .build()); |
| 5508 | |
| 5509 | trustedOverlay->consumeMotionEvent(WithMotionAction(ACTION_MOVE)); |
| 5510 | |
| 5511 | // End the swipe |
| 5512 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_2_UP, AINPUT_SOURCE_MOUSE) |
| 5513 | .pointer(PointerBuilder(0, ToolType::FINGER).x(200).y(105)) |
| 5514 | .pointer(PointerBuilder(1, ToolType::FINGER).x(250).y(105)) |
| 5515 | .pointer(PointerBuilder(2, ToolType::FINGER).x(300).y(105)) |
| 5516 | .classification(MotionClassification::MULTI_FINGER_SWIPE) |
| 5517 | .build()); |
| 5518 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_UP, AINPUT_SOURCE_MOUSE) |
| 5519 | .pointer(PointerBuilder(0, ToolType::FINGER).x(200).y(105)) |
| 5520 | .pointer(PointerBuilder(1, ToolType::FINGER).x(250).y(105)) |
| 5521 | .classification(MotionClassification::MULTI_FINGER_SWIPE) |
| 5522 | .build()); |
| 5523 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_UP, AINPUT_SOURCE_MOUSE) |
| 5524 | .pointer(PointerBuilder(0, ToolType::FINGER).x(200).y(105)) |
| 5525 | .classification(MotionClassification::MULTI_FINGER_SWIPE) |
| 5526 | .build()); |
| 5527 | |
| 5528 | trustedOverlay->consumeMotionEvent(WithMotionAction(POINTER_2_UP)); |
| 5529 | trustedOverlay->consumeMotionEvent(WithMotionAction(POINTER_1_UP)); |
| 5530 | trustedOverlay->consumeMotionEvent(WithMotionAction(ACTION_UP)); |
| 5531 | |
| 5532 | window->assertNoEvents(); |
| 5533 | } |
| 5534 | |
| 5535 | TEST_F(InputDispatcherTest, TouchpadThreeFingerSwipeNotSentToSingleWindow) { |
| 5536 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5537 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 5538 | ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | b166c00 | 2023-05-09 13:06:05 +0000 | [diff] [blame] | 5539 | window->setFrame(Rect(0, 0, 400, 400)); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 5540 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Harry Cutts | b166c00 | 2023-05-09 13:06:05 +0000 | [diff] [blame] | 5541 | |
| 5542 | // Start a three-finger touchpad swipe |
| 5543 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_MOUSE) |
| 5544 | .pointer(PointerBuilder(0, ToolType::FINGER).x(200).y(100)) |
| 5545 | .classification(MotionClassification::MULTI_FINGER_SWIPE) |
| 5546 | .build()); |
| 5547 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_MOUSE) |
| 5548 | .pointer(PointerBuilder(0, ToolType::FINGER).x(200).y(100)) |
| 5549 | .pointer(PointerBuilder(1, ToolType::FINGER).x(250).y(100)) |
| 5550 | .classification(MotionClassification::MULTI_FINGER_SWIPE) |
| 5551 | .build()); |
| 5552 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_2_DOWN, AINPUT_SOURCE_MOUSE) |
| 5553 | .pointer(PointerBuilder(0, ToolType::FINGER).x(200).y(100)) |
| 5554 | .pointer(PointerBuilder(1, ToolType::FINGER).x(250).y(100)) |
| 5555 | .pointer(PointerBuilder(2, ToolType::FINGER).x(300).y(100)) |
| 5556 | .classification(MotionClassification::MULTI_FINGER_SWIPE) |
| 5557 | .build()); |
| 5558 | |
| 5559 | // Move the swipe a bit |
| 5560 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_MOUSE) |
| 5561 | .pointer(PointerBuilder(0, ToolType::FINGER).x(200).y(105)) |
| 5562 | .pointer(PointerBuilder(1, ToolType::FINGER).x(250).y(105)) |
| 5563 | .pointer(PointerBuilder(2, ToolType::FINGER).x(300).y(105)) |
| 5564 | .classification(MotionClassification::MULTI_FINGER_SWIPE) |
| 5565 | .build()); |
| 5566 | |
| 5567 | // End the swipe |
| 5568 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_2_UP, AINPUT_SOURCE_MOUSE) |
| 5569 | .pointer(PointerBuilder(0, ToolType::FINGER).x(200).y(105)) |
| 5570 | .pointer(PointerBuilder(1, ToolType::FINGER).x(250).y(105)) |
| 5571 | .pointer(PointerBuilder(2, ToolType::FINGER).x(300).y(105)) |
| 5572 | .classification(MotionClassification::MULTI_FINGER_SWIPE) |
| 5573 | .build()); |
| 5574 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_UP, AINPUT_SOURCE_MOUSE) |
| 5575 | .pointer(PointerBuilder(0, ToolType::FINGER).x(200).y(105)) |
| 5576 | .pointer(PointerBuilder(1, ToolType::FINGER).x(250).y(105)) |
| 5577 | .classification(MotionClassification::MULTI_FINGER_SWIPE) |
| 5578 | .build()); |
| 5579 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_UP, AINPUT_SOURCE_MOUSE) |
| 5580 | .pointer(PointerBuilder(0, ToolType::FINGER).x(200).y(105)) |
| 5581 | .classification(MotionClassification::MULTI_FINGER_SWIPE) |
| 5582 | .build()); |
| 5583 | |
| 5584 | window->assertNoEvents(); |
| 5585 | } |
| 5586 | |
Prabir Pradhan | b60b1dc | 2022-03-15 14:02:35 +0000 | [diff] [blame] | 5587 | /** |
Siarhei Vishniakou | adb9fc9 | 2023-05-26 10:46:09 -0700 | [diff] [blame] | 5588 | * Send a two-pointer gesture to a single window. The window's orientation changes in response to |
| 5589 | * the first pointer. |
Prabir Pradhan | 69d00bf | 2023-06-23 19:55:18 +0000 | [diff] [blame] | 5590 | * Ensure that the second pointer and the subsequent gesture is correctly delivered to the window. |
Siarhei Vishniakou | adb9fc9 | 2023-05-26 10:46:09 -0700 | [diff] [blame] | 5591 | */ |
| 5592 | TEST_F(InputDispatcherTest, MultiplePointersWithRotatingWindow) { |
| 5593 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5594 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 5595 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | adb9fc9 | 2023-05-26 10:46:09 -0700 | [diff] [blame] | 5596 | window->setFrame(Rect(0, 0, 400, 400)); |
Siarhei Vishniakou | 700424c | 2023-07-18 17:18:42 -0700 | [diff] [blame] | 5597 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | adb9fc9 | 2023-05-26 10:46:09 -0700 | [diff] [blame] | 5598 | |
| 5599 | const nsecs_t baseTime = systemTime(SYSTEM_TIME_MONOTONIC); |
| 5600 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 5601 | .downTime(baseTime + 10) |
| 5602 | .eventTime(baseTime + 10) |
| 5603 | .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) |
| 5604 | .build()); |
| 5605 | |
| 5606 | window->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); |
| 5607 | |
Siarhei Vishniakou | adb9fc9 | 2023-05-26 10:46:09 -0700 | [diff] [blame] | 5608 | // Change the transform so that the orientation is now different from original. |
Siarhei Vishniakou | 700424c | 2023-07-18 17:18:42 -0700 | [diff] [blame] | 5609 | window->setWindowTransform(0, -1, 1, 0); |
Siarhei Vishniakou | adb9fc9 | 2023-05-26 10:46:09 -0700 | [diff] [blame] | 5610 | |
Siarhei Vishniakou | 700424c | 2023-07-18 17:18:42 -0700 | [diff] [blame] | 5611 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | adb9fc9 | 2023-05-26 10:46:09 -0700 | [diff] [blame] | 5612 | |
Siarhei Vishniakou | adb9fc9 | 2023-05-26 10:46:09 -0700 | [diff] [blame] | 5613 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 5614 | .downTime(baseTime + 10) |
| 5615 | .eventTime(baseTime + 30) |
| 5616 | .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) |
| 5617 | .pointer(PointerBuilder(1, ToolType::FINGER).x(200).y(200)) |
| 5618 | .build()); |
| 5619 | |
Prabir Pradhan | 69d00bf | 2023-06-23 19:55:18 +0000 | [diff] [blame] | 5620 | window->consumeMotionEvent(WithMotionAction(POINTER_1_DOWN)); |
| 5621 | |
| 5622 | // Finish the gesture and start a new one. Ensure all events are sent to the window. |
Siarhei Vishniakou | adb9fc9 | 2023-05-26 10:46:09 -0700 | [diff] [blame] | 5623 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_UP, AINPUT_SOURCE_TOUCHSCREEN) |
| 5624 | .downTime(baseTime + 10) |
| 5625 | .eventTime(baseTime + 40) |
| 5626 | .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) |
| 5627 | .pointer(PointerBuilder(1, ToolType::FINGER).x(200).y(200)) |
| 5628 | .build()); |
Prabir Pradhan | 69d00bf | 2023-06-23 19:55:18 +0000 | [diff] [blame] | 5629 | |
| 5630 | window->consumeMotionEvent(WithMotionAction(POINTER_1_UP)); |
| 5631 | |
Siarhei Vishniakou | adb9fc9 | 2023-05-26 10:46:09 -0700 | [diff] [blame] | 5632 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN) |
| 5633 | .downTime(baseTime + 10) |
| 5634 | .eventTime(baseTime + 50) |
| 5635 | .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) |
| 5636 | .build()); |
| 5637 | |
Prabir Pradhan | 69d00bf | 2023-06-23 19:55:18 +0000 | [diff] [blame] | 5638 | window->consumeMotionEvent(WithMotionAction(ACTION_UP)); |
| 5639 | |
Siarhei Vishniakou | adb9fc9 | 2023-05-26 10:46:09 -0700 | [diff] [blame] | 5640 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 5641 | .downTime(baseTime + 60) |
| 5642 | .eventTime(baseTime + 60) |
| 5643 | .pointer(PointerBuilder(0, ToolType::FINGER).x(40).y(40)) |
| 5644 | .build()); |
| 5645 | |
Siarhei Vishniakou | 700424c | 2023-07-18 17:18:42 -0700 | [diff] [blame] | 5646 | window->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); |
Siarhei Vishniakou | adb9fc9 | 2023-05-26 10:46:09 -0700 | [diff] [blame] | 5647 | } |
| 5648 | |
| 5649 | /** |
Hu Guo | 771a769 | 2023-09-17 20:51:08 +0800 | [diff] [blame] | 5650 | * When there are multiple screens, such as screen projection to TV or screen recording, if the |
| 5651 | * cancel event occurs, the coordinates of the cancel event should be sent to the target screen, and |
| 5652 | * its coordinates should be converted by the transform of the windows of target screen. |
| 5653 | */ |
| 5654 | TEST_F(InputDispatcherTest, WhenMultiDisplayWindowSameToken_DispatchCancelToTargetDisplay) { |
| 5655 | // This case will create a window and a spy window on the default display and mirror |
| 5656 | // window on the second display. cancel event is sent through spy window pilferPointers |
| 5657 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 5658 | |
| 5659 | sp<FakeWindowHandle> spyWindowDefaultDisplay = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5660 | sp<FakeWindowHandle>::make(application, mDispatcher, "Spy", |
| 5661 | ui::LogicalDisplayId::DEFAULT); |
Hu Guo | 771a769 | 2023-09-17 20:51:08 +0800 | [diff] [blame] | 5662 | spyWindowDefaultDisplay->setTrustedOverlay(true); |
| 5663 | spyWindowDefaultDisplay->setSpy(true); |
| 5664 | |
| 5665 | sp<FakeWindowHandle> windowDefaultDisplay = |
| 5666 | sp<FakeWindowHandle>::make(application, mDispatcher, "DefaultDisplay", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5667 | ui::LogicalDisplayId::DEFAULT); |
Hu Guo | 771a769 | 2023-09-17 20:51:08 +0800 | [diff] [blame] | 5668 | windowDefaultDisplay->setWindowTransform(1, 0, 0, 1); |
| 5669 | |
| 5670 | sp<FakeWindowHandle> windowSecondDisplay = windowDefaultDisplay->clone(SECOND_DISPLAY_ID); |
| 5671 | windowSecondDisplay->setWindowTransform(2, 0, 0, 2); |
| 5672 | |
| 5673 | // Add the windows to the dispatcher |
| 5674 | mDispatcher->onWindowInfosChanged( |
| 5675 | {{*spyWindowDefaultDisplay->getInfo(), *windowDefaultDisplay->getInfo(), |
| 5676 | *windowSecondDisplay->getInfo()}, |
| 5677 | {}, |
| 5678 | 0, |
| 5679 | 0}); |
| 5680 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5681 | // Send down to ui::LogicalDisplayId::DEFAULT |
Hu Guo | 771a769 | 2023-09-17 20:51:08 +0800 | [diff] [blame] | 5682 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5683 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 5684 | ui::LogicalDisplayId::DEFAULT, {100, 100})) |
Hu Guo | 771a769 | 2023-09-17 20:51:08 +0800 | [diff] [blame] | 5685 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 5686 | |
| 5687 | spyWindowDefaultDisplay->consumeMotionDown(); |
| 5688 | windowDefaultDisplay->consumeMotionDown(); |
| 5689 | |
| 5690 | EXPECT_EQ(OK, mDispatcher->pilferPointers(spyWindowDefaultDisplay->getToken())); |
| 5691 | |
| 5692 | // windowDefaultDisplay gets cancel |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 5693 | std::unique_ptr<MotionEvent> event = windowDefaultDisplay->consumeMotionEvent(); |
| 5694 | ASSERT_NE(nullptr, event); |
| 5695 | EXPECT_EQ(AMOTION_EVENT_ACTION_CANCEL, event->getAction()); |
Hu Guo | 771a769 | 2023-09-17 20:51:08 +0800 | [diff] [blame] | 5696 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5697 | // The cancel event is sent to windowDefaultDisplay of the ui::LogicalDisplayId::DEFAULT |
| 5698 | // display, so the coordinates of the cancel are converted by windowDefaultDisplay's transform, |
| 5699 | // the x and y coordinates are both 100, otherwise if the cancel event is sent to |
| 5700 | // windowSecondDisplay of SECOND_DISPLAY_ID, the x and y coordinates are 200 |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 5701 | EXPECT_EQ(100, event->getX(0)); |
| 5702 | EXPECT_EQ(100, event->getY(0)); |
Hu Guo | 771a769 | 2023-09-17 20:51:08 +0800 | [diff] [blame] | 5703 | } |
| 5704 | |
| 5705 | /** |
Prabir Pradhan | c44ce4d | 2021-10-05 05:26:29 -0700 | [diff] [blame] | 5706 | * Ensure the correct coordinate spaces are used by InputDispatcher. |
| 5707 | * |
| 5708 | * InputDispatcher works in the display space, so its coordinate system is relative to the display |
| 5709 | * panel. Windows get events in the window space, and get raw coordinates in the logical display |
| 5710 | * space. |
| 5711 | */ |
| 5712 | class InputDispatcherDisplayProjectionTest : public InputDispatcherTest { |
| 5713 | public: |
| 5714 | void SetUp() override { |
| 5715 | InputDispatcherTest::SetUp(); |
Prabir Pradhan | 33e3baa | 2022-12-06 20:30:22 +0000 | [diff] [blame] | 5716 | removeAllWindowsAndDisplays(); |
Prabir Pradhan | c44ce4d | 2021-10-05 05:26:29 -0700 | [diff] [blame] | 5717 | } |
| 5718 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 5719 | void addDisplayInfo(ui::LogicalDisplayId displayId, const ui::Transform& transform) { |
Prabir Pradhan | c44ce4d | 2021-10-05 05:26:29 -0700 | [diff] [blame] | 5720 | gui::DisplayInfo info; |
| 5721 | info.displayId = displayId; |
| 5722 | info.transform = transform; |
| 5723 | mDisplayInfos.push_back(std::move(info)); |
Patrick Williams | d828f30 | 2023-04-28 17:52:08 -0500 | [diff] [blame] | 5724 | mDispatcher->onWindowInfosChanged({mWindowInfos, mDisplayInfos, 0, 0}); |
Prabir Pradhan | c44ce4d | 2021-10-05 05:26:29 -0700 | [diff] [blame] | 5725 | } |
| 5726 | |
| 5727 | void addWindow(const sp<WindowInfoHandle>& windowHandle) { |
| 5728 | mWindowInfos.push_back(*windowHandle->getInfo()); |
Patrick Williams | d828f30 | 2023-04-28 17:52:08 -0500 | [diff] [blame] | 5729 | mDispatcher->onWindowInfosChanged({mWindowInfos, mDisplayInfos, 0, 0}); |
Prabir Pradhan | c44ce4d | 2021-10-05 05:26:29 -0700 | [diff] [blame] | 5730 | } |
| 5731 | |
Prabir Pradhan | 33e3baa | 2022-12-06 20:30:22 +0000 | [diff] [blame] | 5732 | void removeAllWindowsAndDisplays() { |
| 5733 | mDisplayInfos.clear(); |
| 5734 | mWindowInfos.clear(); |
| 5735 | } |
| 5736 | |
Prabir Pradhan | c44ce4d | 2021-10-05 05:26:29 -0700 | [diff] [blame] | 5737 | // Set up a test scenario where the display has a scaled projection and there are two windows |
| 5738 | // on the display. |
| 5739 | std::pair<sp<FakeWindowHandle>, sp<FakeWindowHandle>> setupScaledDisplayScenario() { |
| 5740 | // The display has a projection that has a scale factor of 2 and 4 in the x and y directions |
| 5741 | // respectively. |
| 5742 | ui::Transform displayTransform; |
| 5743 | displayTransform.set(2, 0, 0, 4); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5744 | addDisplayInfo(ui::LogicalDisplayId::DEFAULT, displayTransform); |
Prabir Pradhan | c44ce4d | 2021-10-05 05:26:29 -0700 | [diff] [blame] | 5745 | |
| 5746 | std::shared_ptr<FakeApplicationHandle> application = |
| 5747 | std::make_shared<FakeApplicationHandle>(); |
| 5748 | |
| 5749 | // Add two windows to the display. Their frames are represented in the display space. |
| 5750 | sp<FakeWindowHandle> firstWindow = |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 5751 | sp<FakeWindowHandle>::make(application, mDispatcher, "First Window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5752 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | c44ce4d | 2021-10-05 05:26:29 -0700 | [diff] [blame] | 5753 | firstWindow->setFrame(Rect(0, 0, 100, 200), displayTransform); |
| 5754 | addWindow(firstWindow); |
| 5755 | |
| 5756 | sp<FakeWindowHandle> secondWindow = |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 5757 | sp<FakeWindowHandle>::make(application, mDispatcher, "Second Window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5758 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | c44ce4d | 2021-10-05 05:26:29 -0700 | [diff] [blame] | 5759 | secondWindow->setFrame(Rect(100, 200, 200, 400), displayTransform); |
| 5760 | addWindow(secondWindow); |
| 5761 | return {std::move(firstWindow), std::move(secondWindow)}; |
| 5762 | } |
| 5763 | |
| 5764 | private: |
| 5765 | std::vector<gui::DisplayInfo> mDisplayInfos; |
| 5766 | std::vector<gui::WindowInfo> mWindowInfos; |
| 5767 | }; |
| 5768 | |
Prabir Pradhan | 33e3baa | 2022-12-06 20:30:22 +0000 | [diff] [blame] | 5769 | TEST_F(InputDispatcherDisplayProjectionTest, HitTestCoordinateSpaceConsistency) { |
Prabir Pradhan | c44ce4d | 2021-10-05 05:26:29 -0700 | [diff] [blame] | 5770 | auto [firstWindow, secondWindow] = setupScaledDisplayScenario(); |
| 5771 | // Send down to the first window. The point is represented in the display space. The point is |
Prabir Pradhan | 33e3baa | 2022-12-06 20:30:22 +0000 | [diff] [blame] | 5772 | // selected so that if the hit test was performed with the point and the bounds being in |
| 5773 | // different coordinate spaces, the event would end up in the incorrect window. |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 5774 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5775 | AINPUT_SOURCE_TOUCHSCREEN, |
| 5776 | ui::LogicalDisplayId::DEFAULT, {PointF{75, 55}})); |
Prabir Pradhan | c44ce4d | 2021-10-05 05:26:29 -0700 | [diff] [blame] | 5777 | |
| 5778 | firstWindow->consumeMotionDown(); |
| 5779 | secondWindow->assertNoEvents(); |
| 5780 | } |
| 5781 | |
| 5782 | // Ensure that when a MotionEvent is injected through the InputDispatcher::injectInputEvent() API, |
| 5783 | // the event should be treated as being in the logical display space. |
| 5784 | TEST_F(InputDispatcherDisplayProjectionTest, InjectionInLogicalDisplaySpace) { |
| 5785 | auto [firstWindow, secondWindow] = setupScaledDisplayScenario(); |
| 5786 | // Send down to the first window. The point is represented in the logical display space. The |
| 5787 | // point is selected so that if the hit test was done in logical display space, then it would |
| 5788 | // end up in the incorrect window. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5789 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, |
Prabir Pradhan | c44ce4d | 2021-10-05 05:26:29 -0700 | [diff] [blame] | 5790 | PointF{75 * 2, 55 * 4}); |
| 5791 | |
| 5792 | firstWindow->consumeMotionDown(); |
| 5793 | secondWindow->assertNoEvents(); |
| 5794 | } |
| 5795 | |
Prabir Pradhan | daa2f14 | 2021-12-10 09:30:08 +0000 | [diff] [blame] | 5796 | // Ensure that when a MotionEvent that has a custom transform is injected, the post-transformed |
| 5797 | // event should be treated as being in the logical display space. |
| 5798 | TEST_F(InputDispatcherDisplayProjectionTest, InjectionWithTransformInLogicalDisplaySpace) { |
| 5799 | auto [firstWindow, secondWindow] = setupScaledDisplayScenario(); |
| 5800 | |
| 5801 | const std::array<float, 9> matrix = {1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 0.0, 0.0, 1.0}; |
| 5802 | ui::Transform injectedEventTransform; |
| 5803 | injectedEventTransform.set(matrix); |
| 5804 | const vec2 expectedPoint{75, 55}; // The injected point in the logical display space. |
| 5805 | const vec2 untransformedPoint = injectedEventTransform.inverse().transform(expectedPoint); |
| 5806 | |
| 5807 | MotionEvent event = MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5808 | .displayId(ui::LogicalDisplayId::DEFAULT) |
Prabir Pradhan | daa2f14 | 2021-12-10 09:30:08 +0000 | [diff] [blame] | 5809 | .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 5810 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER) |
Prabir Pradhan | daa2f14 | 2021-12-10 09:30:08 +0000 | [diff] [blame] | 5811 | .x(untransformedPoint.x) |
| 5812 | .y(untransformedPoint.y)) |
| 5813 | .build(); |
| 5814 | event.transform(matrix); |
| 5815 | |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 5816 | injectMotionEvent(*mDispatcher, event, INJECT_EVENT_TIMEOUT, |
Prabir Pradhan | daa2f14 | 2021-12-10 09:30:08 +0000 | [diff] [blame] | 5817 | InputEventInjectionSync::WAIT_FOR_RESULT); |
| 5818 | |
| 5819 | firstWindow->consumeMotionDown(); |
| 5820 | secondWindow->assertNoEvents(); |
| 5821 | } |
| 5822 | |
Prabir Pradhan | c44ce4d | 2021-10-05 05:26:29 -0700 | [diff] [blame] | 5823 | TEST_F(InputDispatcherDisplayProjectionTest, WindowGetsEventsInCorrectCoordinateSpace) { |
| 5824 | auto [firstWindow, secondWindow] = setupScaledDisplayScenario(); |
| 5825 | |
| 5826 | // Send down to the second window. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5827 | mDispatcher->notifyMotion( |
| 5828 | generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, |
| 5829 | ui::LogicalDisplayId::DEFAULT, {PointF{150, 220}})); |
Prabir Pradhan | c44ce4d | 2021-10-05 05:26:29 -0700 | [diff] [blame] | 5830 | |
| 5831 | firstWindow->assertNoEvents(); |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 5832 | std::unique_ptr<MotionEvent> event = secondWindow->consumeMotionEvent(); |
| 5833 | ASSERT_NE(nullptr, event); |
| 5834 | EXPECT_EQ(AMOTION_EVENT_ACTION_DOWN, event->getAction()); |
Prabir Pradhan | c44ce4d | 2021-10-05 05:26:29 -0700 | [diff] [blame] | 5835 | |
| 5836 | // Ensure that the events from the "getRaw" API are in logical display coordinates. |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 5837 | EXPECT_EQ(300, event->getRawX(0)); |
| 5838 | EXPECT_EQ(880, event->getRawY(0)); |
Prabir Pradhan | c44ce4d | 2021-10-05 05:26:29 -0700 | [diff] [blame] | 5839 | |
| 5840 | // Ensure that the x and y values are in the window's coordinate space. |
| 5841 | // The left-top of the second window is at (100, 200) in display space, which is (200, 800) in |
| 5842 | // the logical display space. This will be the origin of the window space. |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 5843 | EXPECT_EQ(100, event->getX(0)); |
| 5844 | EXPECT_EQ(80, event->getY(0)); |
Prabir Pradhan | c44ce4d | 2021-10-05 05:26:29 -0700 | [diff] [blame] | 5845 | } |
| 5846 | |
Prabir Pradhan | 112b1ad | 2023-09-21 09:53:53 +0000 | [diff] [blame] | 5847 | TEST_F(InputDispatcherDisplayProjectionTest, CancelMotionWithCorrectCoordinates) { |
| 5848 | auto [firstWindow, secondWindow] = setupScaledDisplayScenario(); |
| 5849 | // The monitor will always receive events in the logical display's coordinate space, because |
| 5850 | // it does not have a window. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5851 | FakeMonitorReceiver monitor{*mDispatcher, "Monitor", ui::LogicalDisplayId::DEFAULT}; |
Prabir Pradhan | 112b1ad | 2023-09-21 09:53:53 +0000 | [diff] [blame] | 5852 | |
| 5853 | // Send down to the first window. |
| 5854 | mDispatcher->notifyMotion(generateMotionArgs(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5855 | ui::LogicalDisplayId::DEFAULT, {PointF{50, 100}})); |
Prabir Pradhan | 112b1ad | 2023-09-21 09:53:53 +0000 | [diff] [blame] | 5856 | firstWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithCoords(100, 400))); |
| 5857 | monitor.consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithCoords(100, 400))); |
| 5858 | |
| 5859 | // Second pointer goes down on second window. |
| 5860 | mDispatcher->notifyMotion(generateMotionArgs(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5861 | ui::LogicalDisplayId::DEFAULT, |
Prabir Pradhan | 112b1ad | 2023-09-21 09:53:53 +0000 | [diff] [blame] | 5862 | {PointF{50, 100}, PointF{150, 220}})); |
| 5863 | secondWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithCoords(100, 80))); |
| 5864 | const std::map<int32_t, PointF> expectedMonitorPointers{{0, PointF{100, 400}}, |
| 5865 | {1, PointF{300, 880}}}; |
| 5866 | monitor.consumeMotionEvent( |
| 5867 | AllOf(WithMotionAction(POINTER_1_DOWN), WithPointers(expectedMonitorPointers))); |
| 5868 | |
| 5869 | mDispatcher->cancelCurrentTouch(); |
| 5870 | |
| 5871 | firstWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_CANCEL), WithCoords(100, 400))); |
| 5872 | secondWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_CANCEL), WithCoords(100, 80))); |
| 5873 | monitor.consumeMotionEvent( |
| 5874 | AllOf(WithMotionAction(ACTION_CANCEL), WithPointers(expectedMonitorPointers))); |
| 5875 | } |
| 5876 | |
Prabir Pradhan | 1c29a09 | 2023-09-21 10:29:29 +0000 | [diff] [blame] | 5877 | TEST_F(InputDispatcherDisplayProjectionTest, SynthesizeDownWithCorrectCoordinates) { |
| 5878 | auto [firstWindow, secondWindow] = setupScaledDisplayScenario(); |
| 5879 | |
| 5880 | // Send down to the first window. |
| 5881 | mDispatcher->notifyMotion(generateMotionArgs(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5882 | ui::LogicalDisplayId::DEFAULT, {PointF{50, 100}})); |
Prabir Pradhan | 1c29a09 | 2023-09-21 10:29:29 +0000 | [diff] [blame] | 5883 | firstWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithCoords(100, 400))); |
| 5884 | |
| 5885 | // The pointer is transferred to the second window, and the second window receives it in the |
| 5886 | // correct coordinate space. |
Prabir Pradhan | 367f343 | 2024-02-13 23:05:58 +0000 | [diff] [blame] | 5887 | mDispatcher->transferTouchGesture(firstWindow->getToken(), secondWindow->getToken()); |
Prabir Pradhan | 1c29a09 | 2023-09-21 10:29:29 +0000 | [diff] [blame] | 5888 | firstWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_CANCEL), WithCoords(100, 400))); |
| 5889 | secondWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithCoords(-100, -400))); |
| 5890 | } |
| 5891 | |
Prabir Pradhan | 0dfcac7 | 2023-10-05 20:04:21 +0000 | [diff] [blame] | 5892 | TEST_F(InputDispatcherDisplayProjectionTest, SynthesizeHoverEnterExitWithCorrectCoordinates) { |
| 5893 | auto [firstWindow, secondWindow] = setupScaledDisplayScenario(); |
| 5894 | |
| 5895 | // Send hover move to the second window, and ensure it shows up as hover enter. |
| 5896 | mDispatcher->notifyMotion(generateMotionArgs(ACTION_HOVER_MOVE, AINPUT_SOURCE_STYLUS, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5897 | ui::LogicalDisplayId::DEFAULT, |
| 5898 | {PointF{150, 220}})); |
Prabir Pradhan | 0dfcac7 | 2023-10-05 20:04:21 +0000 | [diff] [blame] | 5899 | secondWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_HOVER_ENTER), |
| 5900 | WithCoords(100, 80), WithRawCoords(300, 880))); |
| 5901 | |
| 5902 | // Touch down at the same location and ensure a hover exit is synthesized. |
| 5903 | mDispatcher->notifyMotion(generateMotionArgs(ACTION_DOWN, AINPUT_SOURCE_STYLUS, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5904 | ui::LogicalDisplayId::DEFAULT, |
| 5905 | {PointF{150, 220}})); |
Prabir Pradhan | 0dfcac7 | 2023-10-05 20:04:21 +0000 | [diff] [blame] | 5906 | secondWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_HOVER_EXIT), WithCoords(100, 80), |
| 5907 | WithRawCoords(300, 880))); |
| 5908 | secondWindow->consumeMotionEvent( |
| 5909 | AllOf(WithMotionAction(ACTION_DOWN), WithCoords(100, 80), WithRawCoords(300, 880))); |
| 5910 | secondWindow->assertNoEvents(); |
| 5911 | firstWindow->assertNoEvents(); |
| 5912 | } |
| 5913 | |
Prabir Pradhan | 453ae73 | 2023-10-13 14:30:14 +0000 | [diff] [blame] | 5914 | // Same as above, but while the window is being mirrored. |
| 5915 | TEST_F(InputDispatcherDisplayProjectionTest, |
| 5916 | SynthesizeHoverEnterExitWithCorrectCoordinatesWhenMirrored) { |
| 5917 | auto [firstWindow, secondWindow] = setupScaledDisplayScenario(); |
| 5918 | |
| 5919 | const std::array<float, 9> matrix = {1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 0.0, 0.0, 1.0}; |
| 5920 | ui::Transform secondDisplayTransform; |
| 5921 | secondDisplayTransform.set(matrix); |
| 5922 | addDisplayInfo(SECOND_DISPLAY_ID, secondDisplayTransform); |
| 5923 | |
| 5924 | sp<FakeWindowHandle> secondWindowClone = secondWindow->clone(SECOND_DISPLAY_ID); |
| 5925 | secondWindowClone->setWindowTransform(1.1, 2.2, 3.3, 4.4); |
| 5926 | addWindow(secondWindowClone); |
| 5927 | |
| 5928 | // Send hover move to the second window, and ensure it shows up as hover enter. |
| 5929 | mDispatcher->notifyMotion(generateMotionArgs(ACTION_HOVER_MOVE, AINPUT_SOURCE_STYLUS, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5930 | ui::LogicalDisplayId::DEFAULT, |
| 5931 | {PointF{150, 220}})); |
Prabir Pradhan | 453ae73 | 2023-10-13 14:30:14 +0000 | [diff] [blame] | 5932 | secondWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_HOVER_ENTER), |
| 5933 | WithCoords(100, 80), WithRawCoords(300, 880))); |
| 5934 | |
| 5935 | // Touch down at the same location and ensure a hover exit is synthesized for the correct |
| 5936 | // display. |
| 5937 | mDispatcher->notifyMotion(generateMotionArgs(ACTION_DOWN, AINPUT_SOURCE_STYLUS, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5938 | ui::LogicalDisplayId::DEFAULT, |
| 5939 | {PointF{150, 220}})); |
Prabir Pradhan | 453ae73 | 2023-10-13 14:30:14 +0000 | [diff] [blame] | 5940 | secondWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_HOVER_EXIT), WithCoords(100, 80), |
| 5941 | WithRawCoords(300, 880))); |
| 5942 | secondWindow->consumeMotionEvent( |
| 5943 | AllOf(WithMotionAction(ACTION_DOWN), WithCoords(100, 80), WithRawCoords(300, 880))); |
| 5944 | secondWindow->assertNoEvents(); |
| 5945 | firstWindow->assertNoEvents(); |
| 5946 | } |
| 5947 | |
Prabir Pradhan | 0dfcac7 | 2023-10-05 20:04:21 +0000 | [diff] [blame] | 5948 | TEST_F(InputDispatcherDisplayProjectionTest, SynthesizeHoverCancelationWithCorrectCoordinates) { |
| 5949 | auto [firstWindow, secondWindow] = setupScaledDisplayScenario(); |
| 5950 | |
| 5951 | // Send hover enter to second window |
| 5952 | mDispatcher->notifyMotion(generateMotionArgs(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5953 | ui::LogicalDisplayId::DEFAULT, |
| 5954 | {PointF{150, 220}})); |
Prabir Pradhan | 0dfcac7 | 2023-10-05 20:04:21 +0000 | [diff] [blame] | 5955 | secondWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_HOVER_ENTER), |
| 5956 | WithCoords(100, 80), WithRawCoords(300, 880))); |
| 5957 | |
| 5958 | mDispatcher->cancelCurrentTouch(); |
| 5959 | |
| 5960 | secondWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_HOVER_EXIT), WithCoords(100, 80), |
| 5961 | WithRawCoords(300, 880))); |
| 5962 | secondWindow->assertNoEvents(); |
| 5963 | firstWindow->assertNoEvents(); |
| 5964 | } |
| 5965 | |
Prabir Pradhan | 453ae73 | 2023-10-13 14:30:14 +0000 | [diff] [blame] | 5966 | // Same as above, but while the window is being mirrored. |
Prabir Pradhan | 1646338 | 2023-10-12 23:03:19 +0000 | [diff] [blame] | 5967 | TEST_F(InputDispatcherDisplayProjectionTest, |
| 5968 | SynthesizeHoverCancelationWithCorrectCoordinatesWhenMirrored) { |
| 5969 | auto [firstWindow, secondWindow] = setupScaledDisplayScenario(); |
| 5970 | |
| 5971 | const std::array<float, 9> matrix = {1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 0.0, 0.0, 1.0}; |
| 5972 | ui::Transform secondDisplayTransform; |
| 5973 | secondDisplayTransform.set(matrix); |
| 5974 | addDisplayInfo(SECOND_DISPLAY_ID, secondDisplayTransform); |
| 5975 | |
| 5976 | sp<FakeWindowHandle> secondWindowClone = secondWindow->clone(SECOND_DISPLAY_ID); |
| 5977 | secondWindowClone->setWindowTransform(1.1, 2.2, 3.3, 4.4); |
| 5978 | addWindow(secondWindowClone); |
| 5979 | |
| 5980 | // Send hover enter to second window |
| 5981 | mDispatcher->notifyMotion(generateMotionArgs(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5982 | ui::LogicalDisplayId::DEFAULT, |
| 5983 | {PointF{150, 220}})); |
Prabir Pradhan | 1646338 | 2023-10-12 23:03:19 +0000 | [diff] [blame] | 5984 | secondWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_HOVER_ENTER), |
| 5985 | WithCoords(100, 80), WithRawCoords(300, 880), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5986 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))); |
Prabir Pradhan | 1646338 | 2023-10-12 23:03:19 +0000 | [diff] [blame] | 5987 | |
| 5988 | mDispatcher->cancelCurrentTouch(); |
| 5989 | |
| 5990 | // Ensure the cancelation happens with the correct displayId and the correct coordinates. |
| 5991 | secondWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_HOVER_EXIT), WithCoords(100, 80), |
| 5992 | WithRawCoords(300, 880), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 5993 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))); |
Prabir Pradhan | 1646338 | 2023-10-12 23:03:19 +0000 | [diff] [blame] | 5994 | secondWindow->assertNoEvents(); |
| 5995 | firstWindow->assertNoEvents(); |
| 5996 | } |
| 5997 | |
Prabir Pradhan | 33e3baa | 2022-12-06 20:30:22 +0000 | [diff] [blame] | 5998 | /** Ensure consistent behavior of InputDispatcher in all orientations. */ |
| 5999 | class InputDispatcherDisplayOrientationFixture |
| 6000 | : public InputDispatcherDisplayProjectionTest, |
| 6001 | public ::testing::WithParamInterface<ui::Rotation> {}; |
| 6002 | |
| 6003 | // This test verifies the touchable region of a window for all rotations of the display by tapping |
| 6004 | // in different locations on the display, specifically points close to the four corners of a |
| 6005 | // window. |
| 6006 | TEST_P(InputDispatcherDisplayOrientationFixture, HitTestInDifferentOrientations) { |
| 6007 | constexpr static int32_t displayWidth = 400; |
| 6008 | constexpr static int32_t displayHeight = 800; |
| 6009 | |
| 6010 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 6011 | |
| 6012 | const auto rotation = GetParam(); |
| 6013 | |
| 6014 | // Set up the display with the specified rotation. |
| 6015 | const bool isRotated = rotation == ui::ROTATION_90 || rotation == ui::ROTATION_270; |
| 6016 | const int32_t logicalDisplayWidth = isRotated ? displayHeight : displayWidth; |
| 6017 | const int32_t logicalDisplayHeight = isRotated ? displayWidth : displayHeight; |
| 6018 | const ui::Transform displayTransform(ui::Transform::toRotationFlags(rotation), |
| 6019 | logicalDisplayWidth, logicalDisplayHeight); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6020 | addDisplayInfo(ui::LogicalDisplayId::DEFAULT, displayTransform); |
Prabir Pradhan | 33e3baa | 2022-12-06 20:30:22 +0000 | [diff] [blame] | 6021 | |
| 6022 | // Create a window with its bounds determined in the logical display. |
| 6023 | const Rect frameInLogicalDisplay(100, 100, 200, 300); |
| 6024 | const Rect frameInDisplay = displayTransform.inverse().transform(frameInLogicalDisplay); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6025 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 6026 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 33e3baa | 2022-12-06 20:30:22 +0000 | [diff] [blame] | 6027 | window->setFrame(frameInDisplay, displayTransform); |
| 6028 | addWindow(window); |
| 6029 | |
| 6030 | // The following points in logical display space should be inside the window. |
| 6031 | static const std::array<vec2, 4> insidePoints{ |
| 6032 | {{100, 100}, {199.99, 100}, {100, 299.99}, {199.99, 299.99}}}; |
| 6033 | for (const auto pointInsideWindow : insidePoints) { |
| 6034 | const vec2 p = displayTransform.inverse().transform(pointInsideWindow); |
| 6035 | const PointF pointInDisplaySpace{p.x, p.y}; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6036 | mDispatcher->notifyMotion( |
| 6037 | generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, |
| 6038 | ui::LogicalDisplayId::DEFAULT, {pointInDisplaySpace})); |
Prabir Pradhan | 33e3baa | 2022-12-06 20:30:22 +0000 | [diff] [blame] | 6039 | window->consumeMotionDown(); |
| 6040 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6041 | mDispatcher->notifyMotion( |
| 6042 | generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, |
| 6043 | ui::LogicalDisplayId::DEFAULT, {pointInDisplaySpace})); |
Prabir Pradhan | 33e3baa | 2022-12-06 20:30:22 +0000 | [diff] [blame] | 6044 | window->consumeMotionUp(); |
| 6045 | } |
| 6046 | |
| 6047 | // The following points in logical display space should be outside the window. |
| 6048 | static const std::array<vec2, 5> outsidePoints{ |
| 6049 | {{200, 100}, {100, 300}, {200, 300}, {100, 99.99}, {99.99, 100}}}; |
| 6050 | for (const auto pointOutsideWindow : outsidePoints) { |
| 6051 | const vec2 p = displayTransform.inverse().transform(pointOutsideWindow); |
| 6052 | const PointF pointInDisplaySpace{p.x, p.y}; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6053 | mDispatcher->notifyMotion( |
| 6054 | generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, |
| 6055 | ui::LogicalDisplayId::DEFAULT, {pointInDisplaySpace})); |
Prabir Pradhan | 33e3baa | 2022-12-06 20:30:22 +0000 | [diff] [blame] | 6056 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6057 | mDispatcher->notifyMotion( |
| 6058 | generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, |
| 6059 | ui::LogicalDisplayId::DEFAULT, {pointInDisplaySpace})); |
Prabir Pradhan | 33e3baa | 2022-12-06 20:30:22 +0000 | [diff] [blame] | 6060 | } |
| 6061 | window->assertNoEvents(); |
| 6062 | } |
| 6063 | |
Linnan Li | 5e5645e | 2024-03-05 14:43:05 +0000 | [diff] [blame] | 6064 | // This test verifies the occlusion detection for all rotations of the display by tapping |
| 6065 | // in different locations on the display, specifically points close to the four corners of a |
| 6066 | // window. |
| 6067 | TEST_P(InputDispatcherDisplayOrientationFixture, BlockUntrustClickInDifferentOrientations) { |
| 6068 | constexpr static int32_t displayWidth = 400; |
| 6069 | constexpr static int32_t displayHeight = 800; |
| 6070 | |
| 6071 | std::shared_ptr<FakeApplicationHandle> untrustedWindowApplication = |
| 6072 | std::make_shared<FakeApplicationHandle>(); |
| 6073 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 6074 | |
| 6075 | const auto rotation = GetParam(); |
| 6076 | |
| 6077 | // Set up the display with the specified rotation. |
| 6078 | const bool isRotated = rotation == ui::ROTATION_90 || rotation == ui::ROTATION_270; |
| 6079 | const int32_t logicalDisplayWidth = isRotated ? displayHeight : displayWidth; |
| 6080 | const int32_t logicalDisplayHeight = isRotated ? displayWidth : displayHeight; |
| 6081 | const ui::Transform displayTransform(ui::Transform::toRotationFlags(rotation), |
| 6082 | logicalDisplayWidth, logicalDisplayHeight); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6083 | addDisplayInfo(ui::LogicalDisplayId::DEFAULT, displayTransform); |
Linnan Li | 5e5645e | 2024-03-05 14:43:05 +0000 | [diff] [blame] | 6084 | |
| 6085 | // Create a window that not trusted. |
| 6086 | const Rect untrustedWindowFrameInLogicalDisplay(100, 100, 200, 300); |
| 6087 | |
| 6088 | const Rect untrustedWindowFrameInDisplay = |
| 6089 | displayTransform.inverse().transform(untrustedWindowFrameInLogicalDisplay); |
| 6090 | |
| 6091 | sp<FakeWindowHandle> untrustedWindow = |
| 6092 | sp<FakeWindowHandle>::make(untrustedWindowApplication, mDispatcher, "UntrustedWindow", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6093 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | 5e5645e | 2024-03-05 14:43:05 +0000 | [diff] [blame] | 6094 | untrustedWindow->setFrame(untrustedWindowFrameInDisplay, displayTransform); |
| 6095 | untrustedWindow->setTrustedOverlay(false); |
| 6096 | untrustedWindow->setTouchOcclusionMode(TouchOcclusionMode::BLOCK_UNTRUSTED); |
| 6097 | untrustedWindow->setTouchable(false); |
| 6098 | untrustedWindow->setAlpha(1.0f); |
| 6099 | untrustedWindow->setOwnerInfo(gui::Pid{1}, gui::Uid{101}); |
| 6100 | addWindow(untrustedWindow); |
| 6101 | |
| 6102 | // Create a simple app window below the untrusted window. |
| 6103 | const Rect simpleAppWindowFrameInLogicalDisplay(0, 0, 300, 600); |
| 6104 | const Rect simpleAppWindowFrameInDisplay = |
| 6105 | displayTransform.inverse().transform(simpleAppWindowFrameInLogicalDisplay); |
| 6106 | |
| 6107 | sp<FakeWindowHandle> simpleAppWindow = |
| 6108 | sp<FakeWindowHandle>::make(application, mDispatcher, "SimpleAppWindow", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6109 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | 5e5645e | 2024-03-05 14:43:05 +0000 | [diff] [blame] | 6110 | simpleAppWindow->setFrame(simpleAppWindowFrameInDisplay, displayTransform); |
| 6111 | simpleAppWindow->setOwnerInfo(gui::Pid{2}, gui::Uid{202}); |
| 6112 | addWindow(simpleAppWindow); |
| 6113 | |
| 6114 | // The following points in logical display space should be inside the untrusted window, so |
| 6115 | // the simple window could not receive events that coordinate is these point. |
| 6116 | static const std::array<vec2, 4> untrustedPoints{ |
| 6117 | {{100, 100}, {199.99, 100}, {100, 299.99}, {199.99, 299.99}}}; |
| 6118 | |
| 6119 | for (const auto untrustedPoint : untrustedPoints) { |
| 6120 | const vec2 p = displayTransform.inverse().transform(untrustedPoint); |
| 6121 | const PointF pointInDisplaySpace{p.x, p.y}; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6122 | mDispatcher->notifyMotion( |
| 6123 | generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, |
| 6124 | ui::LogicalDisplayId::DEFAULT, {pointInDisplaySpace})); |
| 6125 | mDispatcher->notifyMotion( |
| 6126 | generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, |
| 6127 | ui::LogicalDisplayId::DEFAULT, {pointInDisplaySpace})); |
Linnan Li | 5e5645e | 2024-03-05 14:43:05 +0000 | [diff] [blame] | 6128 | } |
| 6129 | untrustedWindow->assertNoEvents(); |
| 6130 | simpleAppWindow->assertNoEvents(); |
| 6131 | // The following points in logical display space should be outside the untrusted window, so |
| 6132 | // the simple window should receive events that coordinate is these point. |
| 6133 | static const std::array<vec2, 5> trustedPoints{ |
| 6134 | {{200, 100}, {100, 300}, {200, 300}, {100, 99.99}, {99.99, 100}}}; |
| 6135 | for (const auto trustedPoint : trustedPoints) { |
| 6136 | const vec2 p = displayTransform.inverse().transform(trustedPoint); |
| 6137 | const PointF pointInDisplaySpace{p.x, p.y}; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6138 | mDispatcher->notifyMotion( |
| 6139 | generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, |
| 6140 | ui::LogicalDisplayId::DEFAULT, {pointInDisplaySpace})); |
| 6141 | simpleAppWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, |
Linnan Li | 5e5645e | 2024-03-05 14:43:05 +0000 | [diff] [blame] | 6142 | AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6143 | mDispatcher->notifyMotion( |
| 6144 | generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, |
| 6145 | ui::LogicalDisplayId::DEFAULT, {pointInDisplaySpace})); |
| 6146 | simpleAppWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, |
Linnan Li | 5e5645e | 2024-03-05 14:43:05 +0000 | [diff] [blame] | 6147 | AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED); |
| 6148 | } |
| 6149 | untrustedWindow->assertNoEvents(); |
| 6150 | } |
| 6151 | |
Prabir Pradhan | 33e3baa | 2022-12-06 20:30:22 +0000 | [diff] [blame] | 6152 | // Run the precision tests for all rotations. |
| 6153 | INSTANTIATE_TEST_SUITE_P(InputDispatcherDisplayOrientationTests, |
| 6154 | InputDispatcherDisplayOrientationFixture, |
| 6155 | ::testing::Values(ui::ROTATION_0, ui::ROTATION_90, ui::ROTATION_180, |
| 6156 | ui::ROTATION_270), |
| 6157 | [](const testing::TestParamInfo<ui::Rotation>& testParamInfo) { |
| 6158 | return ftl::enum_string(testParamInfo.param); |
| 6159 | }); |
| 6160 | |
Siarhei Vishniakou | 1805009 | 2021-09-01 13:32:49 -0700 | [diff] [blame] | 6161 | using TransferFunction = std::function<bool(const std::unique_ptr<InputDispatcher>& dispatcher, |
| 6162 | sp<IBinder>, sp<IBinder>)>; |
Siarhei Vishniakou | d0c6bc8 | 2021-03-13 03:14:52 +0000 | [diff] [blame] | 6163 | |
| 6164 | class TransferTouchFixture : public InputDispatcherTest, |
| 6165 | public ::testing::WithParamInterface<TransferFunction> {}; |
| 6166 | |
| 6167 | TEST_P(TransferTouchFixture, TransferTouch_OnePointer) { |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 6168 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6169 | |
| 6170 | // Create a couple of windows |
Siarhei Vishniakou | 870ecec | 2020-12-09 08:07:46 -1000 | [diff] [blame] | 6171 | sp<FakeWindowHandle> firstWindow = |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 6172 | sp<FakeWindowHandle>::make(application, mDispatcher, "First Window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6173 | ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 6174 | firstWindow->setDupTouchToWallpaper(true); |
Siarhei Vishniakou | 870ecec | 2020-12-09 08:07:46 -1000 | [diff] [blame] | 6175 | sp<FakeWindowHandle> secondWindow = |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 6176 | sp<FakeWindowHandle>::make(application, mDispatcher, "Second Window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6177 | ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 6178 | sp<FakeWindowHandle> wallpaper = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6179 | sp<FakeWindowHandle>::make(application, mDispatcher, "Wallpaper", |
| 6180 | ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 6181 | wallpaper->setIsWallpaper(true); |
Prabir Pradhan | 65455c7 | 2024-02-13 21:46:41 +0000 | [diff] [blame] | 6182 | // Add the windows to the dispatcher, and ensure the first window is focused |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 6183 | mDispatcher->onWindowInfosChanged( |
| 6184 | {{*firstWindow->getInfo(), *secondWindow->getInfo(), *wallpaper->getInfo()}, {}, 0, 0}); |
Prabir Pradhan | 65455c7 | 2024-02-13 21:46:41 +0000 | [diff] [blame] | 6185 | setFocusedWindow(firstWindow); |
| 6186 | firstWindow->consumeFocusEvent(true); |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6187 | |
| 6188 | // Send down to the first window |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 6189 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6190 | AINPUT_SOURCE_TOUCHSCREEN, |
| 6191 | ui::LogicalDisplayId::DEFAULT)); |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 6192 | |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6193 | // Only the first window should get the down event |
| 6194 | firstWindow->consumeMotionDown(); |
| 6195 | secondWindow->assertNoEvents(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6196 | wallpaper->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); |
Prabir Pradhan | 65455c7 | 2024-02-13 21:46:41 +0000 | [diff] [blame] | 6197 | // Dispatcher reports pointer down outside focus for the wallpaper |
| 6198 | mFakePolicy->assertOnPointerDownEquals(wallpaper->getToken()); |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6199 | |
Siarhei Vishniakou | d0c6bc8 | 2021-03-13 03:14:52 +0000 | [diff] [blame] | 6200 | // Transfer touch to the second window |
| 6201 | TransferFunction f = GetParam(); |
| 6202 | const bool success = f(mDispatcher, firstWindow->getToken(), secondWindow->getToken()); |
| 6203 | ASSERT_TRUE(success); |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6204 | // The first window gets cancel and the second gets down |
| 6205 | firstWindow->consumeMotionCancel(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6206 | secondWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, |
| 6207 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
| 6208 | wallpaper->consumeMotionCancel(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); |
Prabir Pradhan | 65455c7 | 2024-02-13 21:46:41 +0000 | [diff] [blame] | 6209 | // There should not be any changes to the focused window when transferring touch |
| 6210 | ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertOnPointerDownWasNotCalled()); |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6211 | |
| 6212 | // Send up event to the second window |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 6213 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6214 | ui::LogicalDisplayId::DEFAULT)); |
Prabir Pradhan | 65455c7 | 2024-02-13 21:46:41 +0000 | [diff] [blame] | 6215 | // The first window gets no events and the second gets up |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6216 | firstWindow->assertNoEvents(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6217 | secondWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, |
| 6218 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 6219 | wallpaper->assertNoEvents(); |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6220 | } |
| 6221 | |
Siarhei Vishniakou | 7ae7afd | 2022-03-31 15:26:13 -0700 | [diff] [blame] | 6222 | /** |
Prabir Pradhan | 367f343 | 2024-02-13 23:05:58 +0000 | [diff] [blame] | 6223 | * When 'transferTouchGesture' API is invoked, dispatcher needs to find the "best" window to take |
| 6224 | * touch from. When we have spy windows, there are several windows to choose from: either spy, or |
| 6225 | * the 'real' (non-spy) window. Always prefer the 'real' window because that's what would be most |
Siarhei Vishniakou | 7ae7afd | 2022-03-31 15:26:13 -0700 | [diff] [blame] | 6226 | * natural to the user. |
| 6227 | * In this test, we are sending a pointer to both spy window and first window. We then try to |
| 6228 | * transfer touch to the second window. The dispatcher should identify the first window as the |
| 6229 | * one that should lose the gesture, and therefore the action should be to move the gesture from |
| 6230 | * the first window to the second. |
Prabir Pradhan | 367f343 | 2024-02-13 23:05:58 +0000 | [diff] [blame] | 6231 | * The main goal here is to test the behaviour of 'transferTouchGesture' API, but it's still valid |
| 6232 | * to test the other API, as well. |
Siarhei Vishniakou | 7ae7afd | 2022-03-31 15:26:13 -0700 | [diff] [blame] | 6233 | */ |
| 6234 | TEST_P(TransferTouchFixture, TransferTouch_MultipleWindowsWithSpy) { |
| 6235 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 6236 | |
| 6237 | // Create a couple of windows + a spy window |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6238 | sp<FakeWindowHandle> spyWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Spy", |
| 6239 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 7ae7afd | 2022-03-31 15:26:13 -0700 | [diff] [blame] | 6240 | spyWindow->setTrustedOverlay(true); |
| 6241 | spyWindow->setSpy(true); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6242 | sp<FakeWindowHandle> firstWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "First", |
| 6243 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 7ae7afd | 2022-03-31 15:26:13 -0700 | [diff] [blame] | 6244 | sp<FakeWindowHandle> secondWindow = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6245 | sp<FakeWindowHandle>::make(application, mDispatcher, "Second", |
| 6246 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 7ae7afd | 2022-03-31 15:26:13 -0700 | [diff] [blame] | 6247 | |
| 6248 | // Add the windows to the dispatcher |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 6249 | mDispatcher->onWindowInfosChanged( |
| 6250 | {{*spyWindow->getInfo(), *firstWindow->getInfo(), *secondWindow->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | 7ae7afd | 2022-03-31 15:26:13 -0700 | [diff] [blame] | 6251 | |
| 6252 | // Send down to the first window |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 6253 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6254 | AINPUT_SOURCE_TOUCHSCREEN, |
| 6255 | ui::LogicalDisplayId::DEFAULT)); |
Siarhei Vishniakou | 7ae7afd | 2022-03-31 15:26:13 -0700 | [diff] [blame] | 6256 | // Only the first window and spy should get the down event |
| 6257 | spyWindow->consumeMotionDown(); |
| 6258 | firstWindow->consumeMotionDown(); |
| 6259 | |
| 6260 | // Transfer touch to the second window. Non-spy window should be preferred over the spy window |
Prabir Pradhan | 367f343 | 2024-02-13 23:05:58 +0000 | [diff] [blame] | 6261 | // if f === 'transferTouchGesture'. |
Siarhei Vishniakou | 7ae7afd | 2022-03-31 15:26:13 -0700 | [diff] [blame] | 6262 | TransferFunction f = GetParam(); |
| 6263 | const bool success = f(mDispatcher, firstWindow->getToken(), secondWindow->getToken()); |
| 6264 | ASSERT_TRUE(success); |
| 6265 | // The first window gets cancel and the second gets down |
| 6266 | firstWindow->consumeMotionCancel(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6267 | secondWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, |
| 6268 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
Siarhei Vishniakou | 7ae7afd | 2022-03-31 15:26:13 -0700 | [diff] [blame] | 6269 | |
| 6270 | // Send up event to the second window |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 6271 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6272 | ui::LogicalDisplayId::DEFAULT)); |
Siarhei Vishniakou | 7ae7afd | 2022-03-31 15:26:13 -0700 | [diff] [blame] | 6273 | // The first window gets no events and the second+spy get up |
| 6274 | firstWindow->assertNoEvents(); |
| 6275 | spyWindow->consumeMotionUp(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6276 | secondWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, |
| 6277 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
Siarhei Vishniakou | 7ae7afd | 2022-03-31 15:26:13 -0700 | [diff] [blame] | 6278 | } |
| 6279 | |
Siarhei Vishniakou | d0c6bc8 | 2021-03-13 03:14:52 +0000 | [diff] [blame] | 6280 | TEST_P(TransferTouchFixture, TransferTouch_TwoPointersNonSplitTouch) { |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 6281 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6282 | |
| 6283 | PointF touchPoint = {10, 10}; |
| 6284 | |
| 6285 | // Create a couple of windows |
Siarhei Vishniakou | 870ecec | 2020-12-09 08:07:46 -1000 | [diff] [blame] | 6286 | sp<FakeWindowHandle> firstWindow = |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 6287 | sp<FakeWindowHandle>::make(application, mDispatcher, "First Window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6288 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 76bdecb | 2022-01-31 11:14:15 -0800 | [diff] [blame] | 6289 | firstWindow->setPreventSplitting(true); |
Siarhei Vishniakou | 870ecec | 2020-12-09 08:07:46 -1000 | [diff] [blame] | 6290 | sp<FakeWindowHandle> secondWindow = |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 6291 | sp<FakeWindowHandle>::make(application, mDispatcher, "Second Window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6292 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 76bdecb | 2022-01-31 11:14:15 -0800 | [diff] [blame] | 6293 | secondWindow->setPreventSplitting(true); |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6294 | |
| 6295 | // Add the windows to the dispatcher |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 6296 | mDispatcher->onWindowInfosChanged( |
| 6297 | {{*firstWindow->getInfo(), *secondWindow->getInfo()}, {}, 0, 0}); |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6298 | |
| 6299 | // Send down to the first window |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 6300 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6301 | AINPUT_SOURCE_TOUCHSCREEN, |
| 6302 | ui::LogicalDisplayId::DEFAULT, {touchPoint})); |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6303 | // Only the first window should get the down event |
| 6304 | firstWindow->consumeMotionDown(); |
| 6305 | secondWindow->assertNoEvents(); |
| 6306 | |
| 6307 | // Send pointer down to the first window |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 6308 | mDispatcher->notifyMotion(generateMotionArgs(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6309 | ui::LogicalDisplayId::DEFAULT, |
| 6310 | {touchPoint, touchPoint})); |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6311 | // Only the first window should get the pointer down event |
| 6312 | firstWindow->consumeMotionPointerDown(1); |
| 6313 | secondWindow->assertNoEvents(); |
| 6314 | |
| 6315 | // Transfer touch focus to the second window |
Siarhei Vishniakou | d0c6bc8 | 2021-03-13 03:14:52 +0000 | [diff] [blame] | 6316 | TransferFunction f = GetParam(); |
| 6317 | bool success = f(mDispatcher, firstWindow->getToken(), secondWindow->getToken()); |
| 6318 | ASSERT_TRUE(success); |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6319 | // The first window gets cancel and the second gets down and pointer down |
| 6320 | firstWindow->consumeMotionCancel(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6321 | secondWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, |
| 6322 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
| 6323 | secondWindow->consumeMotionPointerDown(1, ui::LogicalDisplayId::DEFAULT, |
Prabir Pradhan | 65455c7 | 2024-02-13 21:46:41 +0000 | [diff] [blame] | 6324 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6325 | |
| 6326 | // Send pointer up to the second window |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 6327 | mDispatcher->notifyMotion(generateMotionArgs(POINTER_1_UP, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6328 | ui::LogicalDisplayId::DEFAULT, |
| 6329 | {touchPoint, touchPoint})); |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6330 | // The first window gets nothing and the second gets pointer up |
| 6331 | firstWindow->assertNoEvents(); |
Prabir Pradhan | 33cfc6d | 2024-06-11 20:17:44 +0000 | [diff] [blame] | 6332 | secondWindow->consumeMotionPointerUp(/*pointerIdx=*/1, |
| 6333 | AllOf(WithDisplayId(ui::LogicalDisplayId::DEFAULT), |
| 6334 | WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE), |
| 6335 | WithPointerCount(2))); |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6336 | |
| 6337 | // Send up event to the second window |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 6338 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6339 | ui::LogicalDisplayId::DEFAULT)); |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6340 | // The first window gets nothing and the second gets up |
| 6341 | firstWindow->assertNoEvents(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6342 | secondWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, |
| 6343 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6344 | } |
| 6345 | |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 6346 | TEST_P(TransferTouchFixture, TransferTouch_MultipleWallpapers) { |
| 6347 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 6348 | |
| 6349 | // Create a couple of windows |
| 6350 | sp<FakeWindowHandle> firstWindow = |
| 6351 | sp<FakeWindowHandle>::make(application, mDispatcher, "First Window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6352 | ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 6353 | firstWindow->setDupTouchToWallpaper(true); |
| 6354 | sp<FakeWindowHandle> secondWindow = |
| 6355 | sp<FakeWindowHandle>::make(application, mDispatcher, "Second Window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6356 | ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 6357 | secondWindow->setDupTouchToWallpaper(true); |
| 6358 | |
| 6359 | sp<FakeWindowHandle> wallpaper1 = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6360 | sp<FakeWindowHandle>::make(application, mDispatcher, "Wallpaper1", |
| 6361 | ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 6362 | wallpaper1->setIsWallpaper(true); |
| 6363 | |
| 6364 | sp<FakeWindowHandle> wallpaper2 = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6365 | sp<FakeWindowHandle>::make(application, mDispatcher, "Wallpaper2", |
| 6366 | ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 6367 | wallpaper2->setIsWallpaper(true); |
| 6368 | // Add the windows to the dispatcher |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 6369 | mDispatcher->onWindowInfosChanged({{*firstWindow->getInfo(), *wallpaper1->getInfo(), |
| 6370 | *secondWindow->getInfo(), *wallpaper2->getInfo()}, |
| 6371 | {}, |
| 6372 | 0, |
| 6373 | 0}); |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 6374 | |
| 6375 | // Send down to the first window |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 6376 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6377 | AINPUT_SOURCE_TOUCHSCREEN, |
| 6378 | ui::LogicalDisplayId::DEFAULT)); |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 6379 | |
| 6380 | // Only the first window should get the down event |
| 6381 | firstWindow->consumeMotionDown(); |
| 6382 | secondWindow->assertNoEvents(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6383 | wallpaper1->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 6384 | wallpaper2->assertNoEvents(); |
| 6385 | |
| 6386 | // Transfer touch focus to the second window |
| 6387 | TransferFunction f = GetParam(); |
| 6388 | bool success = f(mDispatcher, firstWindow->getToken(), secondWindow->getToken()); |
| 6389 | ASSERT_TRUE(success); |
| 6390 | |
| 6391 | // The first window gets cancel and the second gets down |
| 6392 | firstWindow->consumeMotionCancel(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6393 | secondWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, |
| 6394 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
| 6395 | wallpaper1->consumeMotionCancel(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); |
| 6396 | wallpaper2->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, |
Linnan Li | 7235222 | 2024-04-12 18:55:57 +0800 | [diff] [blame] | 6397 | EXPECTED_WALLPAPER_FLAGS | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 6398 | |
| 6399 | // Send up event to the second window |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 6400 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6401 | ui::LogicalDisplayId::DEFAULT)); |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 6402 | // The first window gets no events and the second gets up |
| 6403 | firstWindow->assertNoEvents(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6404 | secondWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, |
| 6405 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 6406 | wallpaper1->assertNoEvents(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6407 | wallpaper2->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, |
Linnan Li | 7235222 | 2024-04-12 18:55:57 +0800 | [diff] [blame] | 6408 | EXPECTED_WALLPAPER_FLAGS | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
Arthur Hung | c539dbb | 2022-12-08 07:45:36 +0000 | [diff] [blame] | 6409 | } |
| 6410 | |
Siarhei Vishniakou | d0c6bc8 | 2021-03-13 03:14:52 +0000 | [diff] [blame] | 6411 | // For the cases of single pointer touch and two pointers non-split touch, the api's |
Prabir Pradhan | 367f343 | 2024-02-13 23:05:58 +0000 | [diff] [blame] | 6412 | // 'transferTouchGesture' and 'transferTouchOnDisplay' are equivalent in behaviour. They only differ |
Siarhei Vishniakou | d0c6bc8 | 2021-03-13 03:14:52 +0000 | [diff] [blame] | 6413 | // for the case where there are multiple pointers split across several windows. |
Prabir Pradhan | 367f343 | 2024-02-13 23:05:58 +0000 | [diff] [blame] | 6414 | INSTANTIATE_TEST_SUITE_P( |
| 6415 | InputDispatcherTransferFunctionTests, TransferTouchFixture, |
| 6416 | ::testing::Values( |
| 6417 | [&](const std::unique_ptr<InputDispatcher>& dispatcher, sp<IBinder> /*ignored*/, |
| 6418 | sp<IBinder> destChannelToken) { |
| 6419 | return dispatcher->transferTouchOnDisplay(destChannelToken, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6420 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 367f343 | 2024-02-13 23:05:58 +0000 | [diff] [blame] | 6421 | }, |
| 6422 | [&](const std::unique_ptr<InputDispatcher>& dispatcher, sp<IBinder> from, |
| 6423 | sp<IBinder> to) { |
| 6424 | return dispatcher->transferTouchGesture(from, to, |
| 6425 | /*isDragAndDrop=*/false); |
| 6426 | })); |
Siarhei Vishniakou | d0c6bc8 | 2021-03-13 03:14:52 +0000 | [diff] [blame] | 6427 | |
Prabir Pradhan | 367f343 | 2024-02-13 23:05:58 +0000 | [diff] [blame] | 6428 | TEST_F(InputDispatcherTest, TransferTouch_TwoPointersSplitTouch) { |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 6429 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6430 | |
Siarhei Vishniakou | 870ecec | 2020-12-09 08:07:46 -1000 | [diff] [blame] | 6431 | sp<FakeWindowHandle> firstWindow = |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 6432 | sp<FakeWindowHandle>::make(application, mDispatcher, "First Window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6433 | ui::LogicalDisplayId::DEFAULT); |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6434 | firstWindow->setFrame(Rect(0, 0, 600, 400)); |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6435 | |
Siarhei Vishniakou | 870ecec | 2020-12-09 08:07:46 -1000 | [diff] [blame] | 6436 | sp<FakeWindowHandle> secondWindow = |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 6437 | sp<FakeWindowHandle>::make(application, mDispatcher, "Second Window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6438 | ui::LogicalDisplayId::DEFAULT); |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6439 | secondWindow->setFrame(Rect(0, 400, 600, 800)); |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6440 | |
| 6441 | // Add the windows to the dispatcher |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 6442 | mDispatcher->onWindowInfosChanged( |
| 6443 | {{*firstWindow->getInfo(), *secondWindow->getInfo()}, {}, 0, 0}); |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6444 | |
| 6445 | PointF pointInFirst = {300, 200}; |
| 6446 | PointF pointInSecond = {300, 600}; |
| 6447 | |
| 6448 | // Send down to the first window |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 6449 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6450 | AINPUT_SOURCE_TOUCHSCREEN, |
| 6451 | ui::LogicalDisplayId::DEFAULT, {pointInFirst})); |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6452 | // Only the first window should get the down event |
| 6453 | firstWindow->consumeMotionDown(); |
| 6454 | secondWindow->assertNoEvents(); |
| 6455 | |
| 6456 | // Send down to the second window |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 6457 | mDispatcher->notifyMotion(generateMotionArgs(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6458 | ui::LogicalDisplayId::DEFAULT, |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 6459 | {pointInFirst, pointInSecond})); |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6460 | // The first window gets a move and the second a down |
| 6461 | firstWindow->consumeMotionMove(); |
| 6462 | secondWindow->consumeMotionDown(); |
| 6463 | |
Prabir Pradhan | 367f343 | 2024-02-13 23:05:58 +0000 | [diff] [blame] | 6464 | // Transfer touch to the second window |
| 6465 | mDispatcher->transferTouchGesture(firstWindow->getToken(), secondWindow->getToken()); |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6466 | // The first window gets cancel and the new gets pointer down (it already saw down) |
| 6467 | firstWindow->consumeMotionCancel(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6468 | secondWindow->consumeMotionPointerDown(1, ui::LogicalDisplayId::DEFAULT, |
Prabir Pradhan | 65455c7 | 2024-02-13 21:46:41 +0000 | [diff] [blame] | 6469 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6470 | |
| 6471 | // Send pointer up to the second window |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 6472 | mDispatcher->notifyMotion(generateMotionArgs(POINTER_1_UP, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6473 | ui::LogicalDisplayId::DEFAULT, |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 6474 | {pointInFirst, pointInSecond})); |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6475 | // The first window gets nothing and the second gets pointer up |
| 6476 | firstWindow->assertNoEvents(); |
Prabir Pradhan | 33cfc6d | 2024-06-11 20:17:44 +0000 | [diff] [blame] | 6477 | secondWindow->consumeMotionPointerUp(/*pointerIdx=*/1, |
| 6478 | AllOf(WithDisplayId(ui::LogicalDisplayId::DEFAULT), |
| 6479 | WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE), |
| 6480 | WithPointerCount(2))); |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6481 | |
| 6482 | // Send up event to the second window |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 6483 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6484 | ui::LogicalDisplayId::DEFAULT)); |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6485 | // The first window gets nothing and the second gets up |
| 6486 | firstWindow->assertNoEvents(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6487 | secondWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, |
| 6488 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
Svet Ganov | 5d3bc37 | 2020-01-26 23:11:07 -0800 | [diff] [blame] | 6489 | } |
| 6490 | |
Prabir Pradhan | 367f343 | 2024-02-13 23:05:58 +0000 | [diff] [blame] | 6491 | // Same as TransferTouch_TwoPointersSplitTouch, but using 'transferTouchOnDisplay' api. |
| 6492 | // Unlike 'transferTouchGesture', calling 'transferTouchOnDisplay' when there are two windows |
| 6493 | // receiving touch is not supported, so the touch should continue on those windows and the |
| 6494 | // transferred-to window should get nothing. |
| 6495 | TEST_F(InputDispatcherTest, TransferTouchOnDisplay_TwoPointersSplitTouch) { |
Siarhei Vishniakou | d0c6bc8 | 2021-03-13 03:14:52 +0000 | [diff] [blame] | 6496 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 6497 | |
Siarhei Vishniakou | d0c6bc8 | 2021-03-13 03:14:52 +0000 | [diff] [blame] | 6498 | sp<FakeWindowHandle> firstWindow = |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 6499 | sp<FakeWindowHandle>::make(application, mDispatcher, "First Window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6500 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | d0c6bc8 | 2021-03-13 03:14:52 +0000 | [diff] [blame] | 6501 | firstWindow->setFrame(Rect(0, 0, 600, 400)); |
Siarhei Vishniakou | d0c6bc8 | 2021-03-13 03:14:52 +0000 | [diff] [blame] | 6502 | |
Siarhei Vishniakou | d0c6bc8 | 2021-03-13 03:14:52 +0000 | [diff] [blame] | 6503 | sp<FakeWindowHandle> secondWindow = |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 6504 | sp<FakeWindowHandle>::make(application, mDispatcher, "Second Window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6505 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | d0c6bc8 | 2021-03-13 03:14:52 +0000 | [diff] [blame] | 6506 | secondWindow->setFrame(Rect(0, 400, 600, 800)); |
Siarhei Vishniakou | d0c6bc8 | 2021-03-13 03:14:52 +0000 | [diff] [blame] | 6507 | |
| 6508 | // Add the windows to the dispatcher |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 6509 | mDispatcher->onWindowInfosChanged( |
| 6510 | {{*firstWindow->getInfo(), *secondWindow->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | d0c6bc8 | 2021-03-13 03:14:52 +0000 | [diff] [blame] | 6511 | |
| 6512 | PointF pointInFirst = {300, 200}; |
| 6513 | PointF pointInSecond = {300, 600}; |
| 6514 | |
| 6515 | // Send down to the first window |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 6516 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6517 | AINPUT_SOURCE_TOUCHSCREEN, |
| 6518 | ui::LogicalDisplayId::DEFAULT, {pointInFirst})); |
Siarhei Vishniakou | d0c6bc8 | 2021-03-13 03:14:52 +0000 | [diff] [blame] | 6519 | // Only the first window should get the down event |
| 6520 | firstWindow->consumeMotionDown(); |
| 6521 | secondWindow->assertNoEvents(); |
| 6522 | |
| 6523 | // Send down to the second window |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 6524 | mDispatcher->notifyMotion(generateMotionArgs(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6525 | ui::LogicalDisplayId::DEFAULT, |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 6526 | {pointInFirst, pointInSecond})); |
Siarhei Vishniakou | d0c6bc8 | 2021-03-13 03:14:52 +0000 | [diff] [blame] | 6527 | // The first window gets a move and the second a down |
| 6528 | firstWindow->consumeMotionMove(); |
| 6529 | secondWindow->consumeMotionDown(); |
| 6530 | |
| 6531 | // Transfer touch focus to the second window |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6532 | const bool transferred = mDispatcher->transferTouchOnDisplay(secondWindow->getToken(), |
| 6533 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 367f343 | 2024-02-13 23:05:58 +0000 | [diff] [blame] | 6534 | // The 'transferTouchOnDisplay' call should not succeed, because there are 2 touched windows |
Siarhei Vishniakou | d0c6bc8 | 2021-03-13 03:14:52 +0000 | [diff] [blame] | 6535 | ASSERT_FALSE(transferred); |
| 6536 | firstWindow->assertNoEvents(); |
| 6537 | secondWindow->assertNoEvents(); |
| 6538 | |
| 6539 | // The rest of the dispatch should proceed as normal |
| 6540 | // Send pointer up to the second window |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 6541 | mDispatcher->notifyMotion(generateMotionArgs(POINTER_1_UP, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6542 | ui::LogicalDisplayId::DEFAULT, |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 6543 | {pointInFirst, pointInSecond})); |
Siarhei Vishniakou | d0c6bc8 | 2021-03-13 03:14:52 +0000 | [diff] [blame] | 6544 | // The first window gets MOVE and the second gets pointer up |
| 6545 | firstWindow->consumeMotionMove(); |
| 6546 | secondWindow->consumeMotionUp(); |
| 6547 | |
| 6548 | // Send up event to the first window |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 6549 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6550 | ui::LogicalDisplayId::DEFAULT)); |
Siarhei Vishniakou | d0c6bc8 | 2021-03-13 03:14:52 +0000 | [diff] [blame] | 6551 | // The first window gets nothing and the second gets up |
| 6552 | firstWindow->consumeMotionUp(); |
| 6553 | secondWindow->assertNoEvents(); |
| 6554 | } |
| 6555 | |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6556 | // This case will create two windows and one mirrored window on the default display and mirror |
Prabir Pradhan | 367f343 | 2024-02-13 23:05:58 +0000 | [diff] [blame] | 6557 | // two windows on the second display. It will test if 'transferTouchGesture' works fine if we put |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6558 | // the windows info of second display before default display. |
Prabir Pradhan | 367f343 | 2024-02-13 23:05:58 +0000 | [diff] [blame] | 6559 | TEST_F(InputDispatcherTest, TransferTouch_CloneSurface) { |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6560 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 6561 | sp<FakeWindowHandle> firstWindowInPrimary = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6562 | sp<FakeWindowHandle>::make(application, mDispatcher, "D_1_W1", |
| 6563 | ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6564 | firstWindowInPrimary->setFrame(Rect(0, 0, 100, 100)); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6565 | sp<FakeWindowHandle> secondWindowInPrimary = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6566 | sp<FakeWindowHandle>::make(application, mDispatcher, "D_1_W2", |
| 6567 | ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6568 | secondWindowInPrimary->setFrame(Rect(100, 0, 200, 100)); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6569 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6570 | sp<FakeWindowHandle> mirrorWindowInPrimary = |
| 6571 | firstWindowInPrimary->clone(ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6572 | mirrorWindowInPrimary->setFrame(Rect(0, 100, 100, 200)); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6573 | |
Siarhei Vishniakou | adb9fc9 | 2023-05-26 10:46:09 -0700 | [diff] [blame] | 6574 | sp<FakeWindowHandle> firstWindowInSecondary = firstWindowInPrimary->clone(SECOND_DISPLAY_ID); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6575 | firstWindowInSecondary->setFrame(Rect(0, 0, 100, 100)); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6576 | |
Siarhei Vishniakou | adb9fc9 | 2023-05-26 10:46:09 -0700 | [diff] [blame] | 6577 | sp<FakeWindowHandle> secondWindowInSecondary = secondWindowInPrimary->clone(SECOND_DISPLAY_ID); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6578 | secondWindowInPrimary->setFrame(Rect(100, 0, 200, 100)); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6579 | |
| 6580 | // Update window info, let it find window handle of second display first. |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 6581 | mDispatcher->onWindowInfosChanged( |
| 6582 | {{*firstWindowInSecondary->getInfo(), *secondWindowInSecondary->getInfo(), |
| 6583 | *mirrorWindowInPrimary->getInfo(), *firstWindowInPrimary->getInfo(), |
| 6584 | *secondWindowInPrimary->getInfo()}, |
| 6585 | {}, |
| 6586 | 0, |
| 6587 | 0}); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6588 | |
| 6589 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6590 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 6591 | ui::LogicalDisplayId::DEFAULT, {50, 50})) |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6592 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 6593 | |
| 6594 | // Window should receive motion event. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6595 | firstWindowInPrimary->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6596 | |
Prabir Pradhan | 367f343 | 2024-02-13 23:05:58 +0000 | [diff] [blame] | 6597 | // Transfer touch |
| 6598 | ASSERT_TRUE(mDispatcher->transferTouchGesture(firstWindowInPrimary->getToken(), |
| 6599 | secondWindowInPrimary->getToken())); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6600 | // The first window gets cancel. |
| 6601 | firstWindowInPrimary->consumeMotionCancel(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6602 | secondWindowInPrimary->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, |
Prabir Pradhan | 65455c7 | 2024-02-13 21:46:41 +0000 | [diff] [blame] | 6603 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6604 | |
| 6605 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 6606 | injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6607 | ui::LogicalDisplayId::DEFAULT, {150, 50})) |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6608 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 6609 | firstWindowInPrimary->assertNoEvents(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6610 | secondWindowInPrimary->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, |
Prabir Pradhan | 65455c7 | 2024-02-13 21:46:41 +0000 | [diff] [blame] | 6611 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6612 | |
| 6613 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6614 | injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6615 | {150, 50})) |
| 6616 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 6617 | firstWindowInPrimary->assertNoEvents(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6618 | secondWindowInPrimary->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, |
| 6619 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6620 | } |
| 6621 | |
Prabir Pradhan | 367f343 | 2024-02-13 23:05:58 +0000 | [diff] [blame] | 6622 | // Same as TransferTouch_CloneSurface, but this touch on the secondary display and use |
| 6623 | // 'transferTouchOnDisplay' api. |
| 6624 | TEST_F(InputDispatcherTest, TransferTouchOnDisplay_CloneSurface) { |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6625 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 6626 | sp<FakeWindowHandle> firstWindowInPrimary = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6627 | sp<FakeWindowHandle>::make(application, mDispatcher, "D_1_W1", |
| 6628 | ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6629 | firstWindowInPrimary->setFrame(Rect(0, 0, 100, 100)); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6630 | sp<FakeWindowHandle> secondWindowInPrimary = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6631 | sp<FakeWindowHandle>::make(application, mDispatcher, "D_1_W2", |
| 6632 | ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6633 | secondWindowInPrimary->setFrame(Rect(100, 0, 200, 100)); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6634 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6635 | sp<FakeWindowHandle> mirrorWindowInPrimary = |
| 6636 | firstWindowInPrimary->clone(ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6637 | mirrorWindowInPrimary->setFrame(Rect(0, 100, 100, 200)); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6638 | |
Siarhei Vishniakou | adb9fc9 | 2023-05-26 10:46:09 -0700 | [diff] [blame] | 6639 | sp<FakeWindowHandle> firstWindowInSecondary = firstWindowInPrimary->clone(SECOND_DISPLAY_ID); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6640 | firstWindowInSecondary->setFrame(Rect(0, 0, 100, 100)); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6641 | |
Siarhei Vishniakou | adb9fc9 | 2023-05-26 10:46:09 -0700 | [diff] [blame] | 6642 | sp<FakeWindowHandle> secondWindowInSecondary = secondWindowInPrimary->clone(SECOND_DISPLAY_ID); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6643 | secondWindowInPrimary->setFrame(Rect(100, 0, 200, 100)); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6644 | |
| 6645 | // Update window info, let it find window handle of second display first. |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 6646 | mDispatcher->onWindowInfosChanged( |
| 6647 | {{*firstWindowInSecondary->getInfo(), *secondWindowInSecondary->getInfo(), |
| 6648 | *mirrorWindowInPrimary->getInfo(), *firstWindowInPrimary->getInfo(), |
| 6649 | *secondWindowInPrimary->getInfo()}, |
| 6650 | {}, |
| 6651 | 0, |
| 6652 | 0}); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6653 | |
| 6654 | // Touch on second display. |
| 6655 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 6656 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, SECOND_DISPLAY_ID, |
| 6657 | {50, 50})) |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6658 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 6659 | |
| 6660 | // Window should receive motion event. |
Prabir Pradhan | bb3f1c0 | 2024-01-04 20:17:14 +0000 | [diff] [blame] | 6661 | firstWindowInSecondary->consumeMotionDown(SECOND_DISPLAY_ID); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6662 | |
| 6663 | // Transfer touch focus |
Prabir Pradhan | 367f343 | 2024-02-13 23:05:58 +0000 | [diff] [blame] | 6664 | ASSERT_TRUE(mDispatcher->transferTouchOnDisplay(secondWindowInSecondary->getToken(), |
| 6665 | SECOND_DISPLAY_ID)); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6666 | |
| 6667 | // The first window gets cancel. |
Prabir Pradhan | bb3f1c0 | 2024-01-04 20:17:14 +0000 | [diff] [blame] | 6668 | firstWindowInSecondary->consumeMotionCancel(SECOND_DISPLAY_ID); |
Prabir Pradhan | 65455c7 | 2024-02-13 21:46:41 +0000 | [diff] [blame] | 6669 | secondWindowInSecondary->consumeMotionDown(SECOND_DISPLAY_ID, |
| 6670 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6671 | |
| 6672 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 6673 | injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6674 | SECOND_DISPLAY_ID, {150, 50})) |
| 6675 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Prabir Pradhan | bb3f1c0 | 2024-01-04 20:17:14 +0000 | [diff] [blame] | 6676 | firstWindowInSecondary->assertNoEvents(); |
Prabir Pradhan | 65455c7 | 2024-02-13 21:46:41 +0000 | [diff] [blame] | 6677 | secondWindowInSecondary->consumeMotionMove(SECOND_DISPLAY_ID, |
| 6678 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6679 | |
| 6680 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 6681 | injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, SECOND_DISPLAY_ID, {150, 50})) |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6682 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Prabir Pradhan | bb3f1c0 | 2024-01-04 20:17:14 +0000 | [diff] [blame] | 6683 | firstWindowInSecondary->assertNoEvents(); |
Prabir Pradhan | 65455c7 | 2024-02-13 21:46:41 +0000 | [diff] [blame] | 6684 | secondWindowInSecondary->consumeMotionUp(SECOND_DISPLAY_ID, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
Arthur Hung | abbb9d8 | 2021-09-01 14:52:30 +0000 | [diff] [blame] | 6685 | } |
| 6686 | |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 6687 | TEST_F(InputDispatcherTest, FocusedWindow_ReceivesFocusEventAndKeyEvent) { |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 6688 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6689 | sp<FakeWindowHandle> window = |
| 6690 | sp<FakeWindowHandle>::make(application, mDispatcher, "Fake Window", |
| 6691 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 6692 | |
Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 6693 | window->setFocusable(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 6694 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 6695 | setFocusedWindow(window); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 6696 | |
| 6697 | window->consumeFocusEvent(true); |
| 6698 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6699 | mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ui::LogicalDisplayId::DEFAULT)); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 6700 | |
| 6701 | // Window should receive key down event. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6702 | window->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); |
Josep del Rio | b398162 | 2023-04-18 15:49:45 +0000 | [diff] [blame] | 6703 | |
| 6704 | // Should have poked user activity |
Siarhei Vishniakou | 4fd8673 | 2023-05-24 17:33:01 +0000 | [diff] [blame] | 6705 | mDispatcher->waitForIdle(); |
Josep del Rio | b398162 | 2023-04-18 15:49:45 +0000 | [diff] [blame] | 6706 | mFakePolicy->assertUserActivityPoked(); |
| 6707 | } |
| 6708 | |
| 6709 | TEST_F(InputDispatcherTest, FocusedWindow_DisableUserActivity) { |
| 6710 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6711 | sp<FakeWindowHandle> window = |
| 6712 | sp<FakeWindowHandle>::make(application, mDispatcher, "Fake Window", |
| 6713 | ui::LogicalDisplayId::DEFAULT); |
Josep del Rio | b398162 | 2023-04-18 15:49:45 +0000 | [diff] [blame] | 6714 | |
| 6715 | window->setDisableUserActivity(true); |
| 6716 | window->setFocusable(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 6717 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Josep del Rio | b398162 | 2023-04-18 15:49:45 +0000 | [diff] [blame] | 6718 | setFocusedWindow(window); |
| 6719 | |
| 6720 | window->consumeFocusEvent(true); |
| 6721 | |
Josep del Rio | c8fdedb | 2024-05-21 13:32:43 +0000 | [diff] [blame] | 6722 | mDispatcher->notifyKey( |
| 6723 | KeyArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_KEYBOARD).keyCode(AKEYCODE_A).build()); |
Josep del Rio | b398162 | 2023-04-18 15:49:45 +0000 | [diff] [blame] | 6724 | |
| 6725 | // Window should receive key down event. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6726 | window->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); |
Josep del Rio | b398162 | 2023-04-18 15:49:45 +0000 | [diff] [blame] | 6727 | |
Josep del Rio | c8fdedb | 2024-05-21 13:32:43 +0000 | [diff] [blame] | 6728 | // Should have not poked user activity |
Siarhei Vishniakou | 4fd8673 | 2023-05-24 17:33:01 +0000 | [diff] [blame] | 6729 | mDispatcher->waitForIdle(); |
Josep del Rio | b398162 | 2023-04-18 15:49:45 +0000 | [diff] [blame] | 6730 | mFakePolicy->assertUserActivityNotPoked(); |
| 6731 | } |
| 6732 | |
Josep del Rio | c8fdedb | 2024-05-21 13:32:43 +0000 | [diff] [blame] | 6733 | TEST_F(InputDispatcherTest, FocusedWindow_DoesNotReceivePolicyConsumedKey) { |
Josep del Rio | b398162 | 2023-04-18 15:49:45 +0000 | [diff] [blame] | 6734 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6735 | sp<FakeWindowHandle> window = |
| 6736 | sp<FakeWindowHandle>::make(application, mDispatcher, "Fake Window", |
| 6737 | ui::LogicalDisplayId::DEFAULT); |
Josep del Rio | b398162 | 2023-04-18 15:49:45 +0000 | [diff] [blame] | 6738 | |
| 6739 | window->setFocusable(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 6740 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Josep del Rio | b398162 | 2023-04-18 15:49:45 +0000 | [diff] [blame] | 6741 | setFocusedWindow(window); |
| 6742 | |
| 6743 | window->consumeFocusEvent(true); |
| 6744 | |
Josep del Rio | c8fdedb | 2024-05-21 13:32:43 +0000 | [diff] [blame] | 6745 | mFakePolicy->setConsumeKeyBeforeDispatching(true); |
| 6746 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6747 | mDispatcher->notifyKey( |
Josep del Rio | c8fdedb | 2024-05-21 13:32:43 +0000 | [diff] [blame] | 6748 | KeyArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_KEYBOARD).keyCode(AKEYCODE_A).build()); |
Josep del Rio | b398162 | 2023-04-18 15:49:45 +0000 | [diff] [blame] | 6749 | mDispatcher->waitForIdle(); |
| 6750 | |
Josep del Rio | c8fdedb | 2024-05-21 13:32:43 +0000 | [diff] [blame] | 6751 | // Key is not passed down |
Josep del Rio | b398162 | 2023-04-18 15:49:45 +0000 | [diff] [blame] | 6752 | window->assertNoEvents(); |
| 6753 | |
| 6754 | // Should have poked user activity |
| 6755 | mFakePolicy->assertUserActivityPoked(); |
| 6756 | } |
| 6757 | |
Josep del Rio | c8fdedb | 2024-05-21 13:32:43 +0000 | [diff] [blame] | 6758 | TEST_F(InputDispatcherTest, FocusedWindow_PolicyConsumedKeyIgnoresDisableUserActivity) { |
Josep del Rio | b398162 | 2023-04-18 15:49:45 +0000 | [diff] [blame] | 6759 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6760 | sp<FakeWindowHandle> window = |
| 6761 | sp<FakeWindowHandle>::make(application, mDispatcher, "Fake Window", |
| 6762 | ui::LogicalDisplayId::DEFAULT); |
Josep del Rio | b398162 | 2023-04-18 15:49:45 +0000 | [diff] [blame] | 6763 | |
| 6764 | window->setDisableUserActivity(true); |
| 6765 | window->setFocusable(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 6766 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Josep del Rio | b398162 | 2023-04-18 15:49:45 +0000 | [diff] [blame] | 6767 | setFocusedWindow(window); |
| 6768 | |
| 6769 | window->consumeFocusEvent(true); |
| 6770 | |
Josep del Rio | c8fdedb | 2024-05-21 13:32:43 +0000 | [diff] [blame] | 6771 | mFakePolicy->setConsumeKeyBeforeDispatching(true); |
| 6772 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6773 | mDispatcher->notifyKey( |
Josep del Rio | c8fdedb | 2024-05-21 13:32:43 +0000 | [diff] [blame] | 6774 | KeyArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_KEYBOARD).keyCode(AKEYCODE_A).build()); |
Josep del Rio | b398162 | 2023-04-18 15:49:45 +0000 | [diff] [blame] | 6775 | mDispatcher->waitForIdle(); |
| 6776 | |
| 6777 | // System key is not passed down |
| 6778 | window->assertNoEvents(); |
| 6779 | |
| 6780 | // Should have poked user activity |
| 6781 | mFakePolicy->assertUserActivityPoked(); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 6782 | } |
| 6783 | |
Josep del Rio | c8fdedb | 2024-05-21 13:32:43 +0000 | [diff] [blame] | 6784 | class DisableUserActivityInputDispatcherTest : public InputDispatcherTest, |
| 6785 | public ::testing::WithParamInterface<bool> {}; |
| 6786 | |
| 6787 | TEST_P(DisableUserActivityInputDispatcherTest, NotPassedToUserUserActivity) { |
| 6788 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 6789 | sp<FakeWindowHandle> window = |
| 6790 | sp<FakeWindowHandle>::make(application, mDispatcher, "Fake Window", |
| 6791 | ui::LogicalDisplayId::DEFAULT); |
| 6792 | |
| 6793 | window->setDisableUserActivity(GetParam()); |
| 6794 | |
| 6795 | window->setFocusable(true); |
| 6796 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
| 6797 | setFocusedWindow(window); |
| 6798 | |
| 6799 | window->consumeFocusEvent(true); |
| 6800 | |
| 6801 | mDispatcher->notifyKey(KeyArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_KEYBOARD) |
| 6802 | .keyCode(AKEYCODE_A) |
| 6803 | .policyFlags(0) |
| 6804 | .build()); |
| 6805 | mDispatcher->waitForIdle(); |
| 6806 | |
| 6807 | // Key is not passed down |
| 6808 | window->assertNoEvents(); |
| 6809 | |
| 6810 | // Should not have poked user activity |
| 6811 | mFakePolicy->assertUserActivityNotPoked(); |
| 6812 | } |
| 6813 | |
| 6814 | INSTANTIATE_TEST_CASE_P(DisableUserActivity, DisableUserActivityInputDispatcherTest, |
| 6815 | ::testing::Bool()); |
| 6816 | |
Siarhei Vishniakou | 90ee478 | 2023-05-08 11:57:24 -0700 | [diff] [blame] | 6817 | TEST_F(InputDispatcherTest, InjectedTouchesPokeUserActivity) { |
| 6818 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6819 | sp<FakeWindowHandle> window = |
| 6820 | sp<FakeWindowHandle>::make(application, mDispatcher, "Fake Window", |
| 6821 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 90ee478 | 2023-05-08 11:57:24 -0700 | [diff] [blame] | 6822 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 6823 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | 90ee478 | 2023-05-08 11:57:24 -0700 | [diff] [blame] | 6824 | |
| 6825 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 6826 | injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6827 | ui::LogicalDisplayId::DEFAULT, {100, 100})) |
Siarhei Vishniakou | 90ee478 | 2023-05-08 11:57:24 -0700 | [diff] [blame] | 6828 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 6829 | |
| 6830 | window->consumeMotionEvent( |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6831 | AllOf(WithMotionAction(ACTION_DOWN), WithDisplayId(ui::LogicalDisplayId::DEFAULT))); |
Siarhei Vishniakou | 90ee478 | 2023-05-08 11:57:24 -0700 | [diff] [blame] | 6832 | |
| 6833 | // Should have poked user activity |
Siarhei Vishniakou | 4fd8673 | 2023-05-24 17:33:01 +0000 | [diff] [blame] | 6834 | mDispatcher->waitForIdle(); |
Siarhei Vishniakou | 90ee478 | 2023-05-08 11:57:24 -0700 | [diff] [blame] | 6835 | mFakePolicy->assertUserActivityPoked(); |
| 6836 | } |
| 6837 | |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 6838 | TEST_F(InputDispatcherTest, UnfocusedWindow_DoesNotReceiveFocusEventOrKeyEvent) { |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 6839 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6840 | sp<FakeWindowHandle> window = |
| 6841 | sp<FakeWindowHandle>::make(application, mDispatcher, "Fake Window", |
| 6842 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 6843 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 6844 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 6845 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6846 | mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ui::LogicalDisplayId::DEFAULT)); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 6847 | mDispatcher->waitForIdle(); |
| 6848 | |
| 6849 | window->assertNoEvents(); |
| 6850 | } |
| 6851 | |
| 6852 | // If a window is touchable, but does not have focus, it should receive motion events, but not keys |
| 6853 | TEST_F(InputDispatcherTest, UnfocusedWindow_ReceivesMotionsButNotKeys) { |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 6854 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6855 | sp<FakeWindowHandle> window = |
| 6856 | sp<FakeWindowHandle>::make(application, mDispatcher, "Fake Window", |
| 6857 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 6858 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 6859 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 6860 | |
| 6861 | // Send key |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6862 | mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ui::LogicalDisplayId::DEFAULT)); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 6863 | // Send motion |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 6864 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6865 | AINPUT_SOURCE_TOUCHSCREEN, |
| 6866 | ui::LogicalDisplayId::DEFAULT)); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 6867 | |
| 6868 | // Window should receive only the motion event |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6869 | window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 6870 | window->assertNoEvents(); // Key event or focus event will not be received |
| 6871 | } |
| 6872 | |
arthurhung | ea3f4fc | 2020-12-21 23:18:53 +0800 | [diff] [blame] | 6873 | TEST_F(InputDispatcherTest, PointerCancel_SendCancelWhenSplitTouch) { |
| 6874 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 6875 | |
arthurhung | ea3f4fc | 2020-12-21 23:18:53 +0800 | [diff] [blame] | 6876 | sp<FakeWindowHandle> firstWindow = |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 6877 | sp<FakeWindowHandle>::make(application, mDispatcher, "First Window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6878 | ui::LogicalDisplayId::DEFAULT); |
arthurhung | ea3f4fc | 2020-12-21 23:18:53 +0800 | [diff] [blame] | 6879 | firstWindow->setFrame(Rect(0, 0, 600, 400)); |
arthurhung | ea3f4fc | 2020-12-21 23:18:53 +0800 | [diff] [blame] | 6880 | |
arthurhung | ea3f4fc | 2020-12-21 23:18:53 +0800 | [diff] [blame] | 6881 | sp<FakeWindowHandle> secondWindow = |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 6882 | sp<FakeWindowHandle>::make(application, mDispatcher, "Second Window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6883 | ui::LogicalDisplayId::DEFAULT); |
arthurhung | ea3f4fc | 2020-12-21 23:18:53 +0800 | [diff] [blame] | 6884 | secondWindow->setFrame(Rect(0, 400, 600, 800)); |
arthurhung | ea3f4fc | 2020-12-21 23:18:53 +0800 | [diff] [blame] | 6885 | |
| 6886 | // Add the windows to the dispatcher |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 6887 | mDispatcher->onWindowInfosChanged( |
| 6888 | {{*firstWindow->getInfo(), *secondWindow->getInfo()}, {}, 0, 0}); |
arthurhung | ea3f4fc | 2020-12-21 23:18:53 +0800 | [diff] [blame] | 6889 | |
| 6890 | PointF pointInFirst = {300, 200}; |
| 6891 | PointF pointInSecond = {300, 600}; |
| 6892 | |
| 6893 | // Send down to the first window |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 6894 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6895 | AINPUT_SOURCE_TOUCHSCREEN, |
| 6896 | ui::LogicalDisplayId::DEFAULT, {pointInFirst})); |
arthurhung | ea3f4fc | 2020-12-21 23:18:53 +0800 | [diff] [blame] | 6897 | // Only the first window should get the down event |
| 6898 | firstWindow->consumeMotionDown(); |
| 6899 | secondWindow->assertNoEvents(); |
| 6900 | |
| 6901 | // Send down to the second window |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 6902 | mDispatcher->notifyMotion(generateMotionArgs(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6903 | ui::LogicalDisplayId::DEFAULT, |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 6904 | {pointInFirst, pointInSecond})); |
arthurhung | ea3f4fc | 2020-12-21 23:18:53 +0800 | [diff] [blame] | 6905 | // The first window gets a move and the second a down |
| 6906 | firstWindow->consumeMotionMove(); |
| 6907 | secondWindow->consumeMotionDown(); |
| 6908 | |
| 6909 | // Send pointer cancel to the second window |
| 6910 | NotifyMotionArgs pointerUpMotionArgs = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6911 | generateMotionArgs(POINTER_1_UP, AINPUT_SOURCE_TOUCHSCREEN, |
| 6912 | ui::LogicalDisplayId::DEFAULT, {pointInFirst, pointInSecond}); |
arthurhung | ea3f4fc | 2020-12-21 23:18:53 +0800 | [diff] [blame] | 6913 | pointerUpMotionArgs.flags |= AMOTION_EVENT_FLAG_CANCELED; |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 6914 | mDispatcher->notifyMotion(pointerUpMotionArgs); |
arthurhung | ea3f4fc | 2020-12-21 23:18:53 +0800 | [diff] [blame] | 6915 | // The first window gets move and the second gets cancel. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6916 | firstWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, AMOTION_EVENT_FLAG_CANCELED); |
| 6917 | secondWindow->consumeMotionCancel(ui::LogicalDisplayId::DEFAULT, AMOTION_EVENT_FLAG_CANCELED); |
arthurhung | ea3f4fc | 2020-12-21 23:18:53 +0800 | [diff] [blame] | 6918 | |
| 6919 | // Send up event. |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 6920 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6921 | ui::LogicalDisplayId::DEFAULT)); |
arthurhung | ea3f4fc | 2020-12-21 23:18:53 +0800 | [diff] [blame] | 6922 | // The first window gets up and the second gets nothing. |
| 6923 | firstWindow->consumeMotionUp(); |
| 6924 | secondWindow->assertNoEvents(); |
| 6925 | } |
| 6926 | |
Siarhei Vishniakou | f94ae02 | 2021-02-04 01:23:17 +0000 | [diff] [blame] | 6927 | TEST_F(InputDispatcherTest, SendTimeline_DoesNotCrashDispatcher) { |
| 6928 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 6929 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6930 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 6931 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 6932 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | f94ae02 | 2021-02-04 01:23:17 +0000 | [diff] [blame] | 6933 | std::array<nsecs_t, GraphicsTimeline::SIZE> graphicsTimeline; |
| 6934 | graphicsTimeline[GraphicsTimeline::GPU_COMPLETED_TIME] = 2; |
| 6935 | graphicsTimeline[GraphicsTimeline::PRESENT_TIME] = 3; |
| 6936 | |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 6937 | window->sendTimeline(/*inputEventId=*/1, graphicsTimeline); |
Siarhei Vishniakou | f94ae02 | 2021-02-04 01:23:17 +0000 | [diff] [blame] | 6938 | window->assertNoEvents(); |
| 6939 | mDispatcher->waitForIdle(); |
| 6940 | } |
| 6941 | |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 6942 | using InputDispatcherMonitorTest = InputDispatcherTest; |
| 6943 | |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 6944 | /** |
| 6945 | * Two entities that receive touch: A window, and a global monitor. |
| 6946 | * The touch goes to the window, and then the window disappears. |
| 6947 | * The monitor does not get cancel right away. But if more events come in, the touch gets canceled |
| 6948 | * for the monitor, as well. |
| 6949 | * 1. foregroundWindow |
| 6950 | * 2. monitor <-- global monitor (doesn't observe z order, receives all events) |
| 6951 | */ |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 6952 | TEST_F(InputDispatcherMonitorTest, MonitorTouchIsCanceledWhenForegroundWindowDisappears) { |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 6953 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6954 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Foreground", |
| 6955 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 6956 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6957 | FakeMonitorReceiver monitor = |
| 6958 | FakeMonitorReceiver(*mDispatcher, "M_1", ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 6959 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 6960 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 6961 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6962 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 6963 | ui::LogicalDisplayId::DEFAULT, {100, 200})) |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 6964 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 6965 | |
| 6966 | // Both the foreground window and the global monitor should receive the touch down |
| 6967 | window->consumeMotionDown(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6968 | monitor.consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 6969 | |
| 6970 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 6971 | injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6972 | ui::LogicalDisplayId::DEFAULT, {110, 200})) |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 6973 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 6974 | |
| 6975 | window->consumeMotionMove(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6976 | monitor.consumeMotionMove(ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 6977 | |
| 6978 | // Now the foreground window goes away |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 6979 | mDispatcher->onWindowInfosChanged({{}, {}, 0, 0}); |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 6980 | window->consumeMotionCancel(); |
| 6981 | monitor.assertNoEvents(); // Global monitor does not get a cancel yet |
| 6982 | |
| 6983 | // If more events come in, there will be no more foreground window to send them to. This will |
| 6984 | // cause a cancel for the monitor, as well. |
| 6985 | ASSERT_EQ(InputEventInjectionResult::FAILED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 6986 | injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6987 | ui::LogicalDisplayId::DEFAULT, {120, 200})) |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 6988 | << "Injection should fail because the window was removed"; |
| 6989 | window->assertNoEvents(); |
| 6990 | // Global monitor now gets the cancel |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6991 | monitor.consumeMotionCancel(ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 6992 | } |
| 6993 | |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 6994 | TEST_F(InputDispatcherMonitorTest, ReceivesMotionEvents) { |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 6995 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 6996 | sp<FakeWindowHandle> window = |
| 6997 | sp<FakeWindowHandle>::make(application, mDispatcher, "Fake Window", |
| 6998 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 6999 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Michael Wright | 3a240c4 | 2019-12-10 20:53:41 +0000 | [diff] [blame] | 7000 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7001 | FakeMonitorReceiver monitor = |
| 7002 | FakeMonitorReceiver(*mDispatcher, "M_1", ui::LogicalDisplayId::DEFAULT); |
Michael Wright | 3a240c4 | 2019-12-10 20:53:41 +0000 | [diff] [blame] | 7003 | |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 7004 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7005 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 7006 | ui::LogicalDisplayId::DEFAULT)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 7007 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7008 | window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
| 7009 | monitor.consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Michael Wright | 3a240c4 | 2019-12-10 20:53:41 +0000 | [diff] [blame] | 7010 | } |
| 7011 | |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 7012 | TEST_F(InputDispatcherMonitorTest, MonitorCannotPilferPointers) { |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7013 | FakeMonitorReceiver monitor = |
| 7014 | FakeMonitorReceiver(*mDispatcher, "M_1", ui::LogicalDisplayId::DEFAULT); |
Michael Wright | 3a240c4 | 2019-12-10 20:53:41 +0000 | [diff] [blame] | 7015 | |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 7016 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7017 | sp<FakeWindowHandle> window = |
| 7018 | sp<FakeWindowHandle>::make(application, mDispatcher, "Fake Window", |
| 7019 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 7020 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Michael Wright | 3a240c4 | 2019-12-10 20:53:41 +0000 | [diff] [blame] | 7021 | |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 7022 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7023 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 7024 | ui::LogicalDisplayId::DEFAULT)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 7025 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7026 | monitor.consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
| 7027 | window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Michael Wright | 3a240c4 | 2019-12-10 20:53:41 +0000 | [diff] [blame] | 7028 | |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 7029 | // Pilfer pointers from the monitor. |
| 7030 | // This should not do anything and the window should continue to receive events. |
| 7031 | EXPECT_NE(OK, mDispatcher->pilferPointers(monitor.getToken())); |
Michael Wright | 3a240c4 | 2019-12-10 20:53:41 +0000 | [diff] [blame] | 7032 | |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 7033 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 7034 | injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7035 | ui::LogicalDisplayId::DEFAULT)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 7036 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 7037 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7038 | monitor.consumeMotionMove(ui::LogicalDisplayId::DEFAULT); |
| 7039 | window->consumeMotionMove(ui::LogicalDisplayId::DEFAULT); |
Michael Wright | 3a240c4 | 2019-12-10 20:53:41 +0000 | [diff] [blame] | 7040 | } |
| 7041 | |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 7042 | TEST_F(InputDispatcherMonitorTest, NoWindowTransform) { |
Evan Rosky | 84f07f0 | 2021-04-16 10:42:42 -0700 | [diff] [blame] | 7043 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7044 | sp<FakeWindowHandle> window = |
| 7045 | sp<FakeWindowHandle>::make(application, mDispatcher, "Fake Window", |
| 7046 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 7047 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Evan Rosky | 84f07f0 | 2021-04-16 10:42:42 -0700 | [diff] [blame] | 7048 | window->setWindowOffset(20, 40); |
| 7049 | window->setWindowTransform(0, 1, -1, 0); |
| 7050 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7051 | FakeMonitorReceiver monitor = |
| 7052 | FakeMonitorReceiver(*mDispatcher, "M_1", ui::LogicalDisplayId::DEFAULT); |
Evan Rosky | 84f07f0 | 2021-04-16 10:42:42 -0700 | [diff] [blame] | 7053 | |
| 7054 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7055 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 7056 | ui::LogicalDisplayId::DEFAULT)) |
Evan Rosky | 84f07f0 | 2021-04-16 10:42:42 -0700 | [diff] [blame] | 7057 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7058 | window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 7059 | std::unique_ptr<MotionEvent> event = monitor.consumeMotion(); |
| 7060 | ASSERT_NE(nullptr, event); |
Evan Rosky | 84f07f0 | 2021-04-16 10:42:42 -0700 | [diff] [blame] | 7061 | // Even though window has transform, gesture monitor must not. |
| 7062 | ASSERT_EQ(ui::Transform(), event->getTransform()); |
| 7063 | } |
| 7064 | |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 7065 | TEST_F(InputDispatcherMonitorTest, InjectionFailsWithNoWindow) { |
Arthur Hung | b3307ee | 2021-10-14 10:57:37 +0000 | [diff] [blame] | 7066 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7067 | FakeMonitorReceiver monitor = |
| 7068 | FakeMonitorReceiver(*mDispatcher, "M_1", ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | b3307ee | 2021-10-14 10:57:37 +0000 | [diff] [blame] | 7069 | |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 7070 | ASSERT_EQ(InputEventInjectionResult::FAILED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7071 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 7072 | ui::LogicalDisplayId::DEFAULT)) |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 7073 | << "Injection should fail if there is a monitor, but no touchable window"; |
| 7074 | monitor.assertNoEvents(); |
Arthur Hung | b3307ee | 2021-10-14 10:57:37 +0000 | [diff] [blame] | 7075 | } |
| 7076 | |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7077 | /** |
| 7078 | * Two displays |
| 7079 | * The first monitor has a foreground window, a monitor |
| 7080 | * The second window has only one monitor. |
| 7081 | * We first inject a Down event into the first display, this injection should succeed and both |
| 7082 | * the foreground window and monitor should receive a down event, then inject a Down event into |
| 7083 | * the second display as well, this injection should fail, at this point, the first display |
| 7084 | * window and monitor should not receive a cancel or any other event. |
| 7085 | * Continue to inject Move and UP events to the first display, the events should be received |
| 7086 | * normally by the foreground window and monitor. |
| 7087 | */ |
| 7088 | TEST_F(InputDispatcherMonitorTest, MonitorTouchIsNotCanceledWhenAnotherEmptyDisplayReceiveEvents) { |
| 7089 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7090 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Foreground", |
| 7091 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7092 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7093 | FakeMonitorReceiver monitor = |
| 7094 | FakeMonitorReceiver(*mDispatcher, "M_1", ui::LogicalDisplayId::DEFAULT); |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7095 | FakeMonitorReceiver secondMonitor = FakeMonitorReceiver(*mDispatcher, "M_2", SECOND_DISPLAY_ID); |
| 7096 | |
| 7097 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
| 7098 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7099 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 7100 | ui::LogicalDisplayId::DEFAULT, {100, 200})) |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7101 | << "The down event injected into the first display should succeed"; |
| 7102 | |
| 7103 | window->consumeMotionDown(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7104 | monitor.consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7105 | |
| 7106 | ASSERT_EQ(InputEventInjectionResult::FAILED, |
| 7107 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, SECOND_DISPLAY_ID, |
| 7108 | {100, 200})) |
Prabir Pradhan | a0d43d4 | 2024-01-30 00:27:08 +0000 | [diff] [blame] | 7109 | << "The down event injected into the second display should fail since there's no " |
| 7110 | "touchable window"; |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7111 | |
| 7112 | // Continue to inject event to first display. |
| 7113 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
| 7114 | injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7115 | ui::LogicalDisplayId::DEFAULT, {110, 220})) |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7116 | << "The move event injected into the first display should succeed"; |
| 7117 | |
| 7118 | window->consumeMotionMove(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7119 | monitor.consumeMotionMove(ui::LogicalDisplayId::DEFAULT); |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7120 | |
| 7121 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7122 | injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7123 | {110, 220})) |
| 7124 | << "The up event injected into the first display should succeed"; |
| 7125 | |
| 7126 | window->consumeMotionUp(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7127 | monitor.consumeMotionUp(ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | a0d43d4 | 2024-01-30 00:27:08 +0000 | [diff] [blame] | 7128 | |
| 7129 | window->assertNoEvents(); |
| 7130 | monitor.assertNoEvents(); |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7131 | secondMonitor.assertNoEvents(); |
| 7132 | } |
| 7133 | |
| 7134 | /** |
| 7135 | * Two displays |
| 7136 | * There is a monitor and foreground window on each display. |
| 7137 | * First, we inject down events into each of the two displays, at this point, the foreground windows |
| 7138 | * and monitors on both displays should receive down events. |
| 7139 | * At this point, the foreground window of the second display goes away, the gone window should |
| 7140 | * receive the cancel event, and the other windows and monitors should not receive any events. |
| 7141 | * Inject a move event into the second display. At this point, the injection should fail because |
| 7142 | * the second display no longer has a foreground window. At this point, the monitor on the second |
| 7143 | * display should receive a cancel event, and any windows or monitors on the first display should |
| 7144 | * not receive any events, and any subsequent injection of events into the second display should |
| 7145 | * also fail. |
| 7146 | * Continue to inject events into the first display, and the events should all be injected |
| 7147 | * successfully and received normally. |
| 7148 | */ |
| 7149 | TEST_F(InputDispatcherMonitorTest, MonitorTouchIsNotCancelWhenAnotherDisplayMonitorTouchCanceled) { |
| 7150 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7151 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Foreground", |
| 7152 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7153 | sp<FakeWindowHandle> secondWindow = |
| 7154 | sp<FakeWindowHandle>::make(application, mDispatcher, "SecondForeground", |
| 7155 | SECOND_DISPLAY_ID); |
| 7156 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7157 | FakeMonitorReceiver monitor = |
| 7158 | FakeMonitorReceiver(*mDispatcher, "M_1", ui::LogicalDisplayId::DEFAULT); |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7159 | FakeMonitorReceiver secondMonitor = FakeMonitorReceiver(*mDispatcher, "M_2", SECOND_DISPLAY_ID); |
| 7160 | |
| 7161 | // There is a foreground window on both displays. |
| 7162 | mDispatcher->onWindowInfosChanged({{*window->getInfo(), *secondWindow->getInfo()}, {}, 0, 0}); |
| 7163 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7164 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 7165 | ui::LogicalDisplayId::DEFAULT, {100, 200})) |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7166 | << "The down event injected into the first display should succeed"; |
| 7167 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7168 | window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
| 7169 | monitor.consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7170 | |
| 7171 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
| 7172 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, SECOND_DISPLAY_ID, |
| 7173 | {100, 200})) |
| 7174 | << "The down event injected into the second display should succeed"; |
| 7175 | |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7176 | secondWindow->consumeMotionDown(SECOND_DISPLAY_ID); |
| 7177 | secondMonitor.consumeMotionDown(SECOND_DISPLAY_ID); |
| 7178 | |
| 7179 | // Now second window is gone away. |
| 7180 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
| 7181 | |
| 7182 | // The gone window should receive a cancel, and the monitor on the second display should not |
| 7183 | // receive any events. |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7184 | secondWindow->consumeMotionCancel(SECOND_DISPLAY_ID); |
| 7185 | secondMonitor.assertNoEvents(); |
| 7186 | |
| 7187 | ASSERT_EQ(InputEventInjectionResult::FAILED, |
| 7188 | injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, |
| 7189 | SECOND_DISPLAY_ID, {110, 220})) |
Prabir Pradhan | a0d43d4 | 2024-01-30 00:27:08 +0000 | [diff] [blame] | 7190 | << "The move event injected into the second display should fail because there's no " |
| 7191 | "touchable window"; |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7192 | // Now the monitor on the second display should receive a cancel event. |
| 7193 | secondMonitor.consumeMotionCancel(SECOND_DISPLAY_ID); |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7194 | |
| 7195 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
| 7196 | injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7197 | ui::LogicalDisplayId::DEFAULT, {110, 200})) |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7198 | << "The move event injected into the first display should succeed"; |
| 7199 | |
| 7200 | window->consumeMotionMove(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7201 | monitor.consumeMotionMove(ui::LogicalDisplayId::DEFAULT); |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7202 | |
| 7203 | ASSERT_EQ(InputEventInjectionResult::FAILED, |
Prabir Pradhan | a0d43d4 | 2024-01-30 00:27:08 +0000 | [diff] [blame] | 7204 | injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, SECOND_DISPLAY_ID, |
| 7205 | {110, 220})) |
| 7206 | << "The up event injected into the second display should fail because there's no " |
| 7207 | "touchable window"; |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7208 | |
| 7209 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7210 | injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7211 | {110, 220})) |
| 7212 | << "The up event injected into the first display should succeed"; |
| 7213 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7214 | window->consumeMotionUp(ui::LogicalDisplayId::DEFAULT); |
| 7215 | monitor.consumeMotionUp(ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | a0d43d4 | 2024-01-30 00:27:08 +0000 | [diff] [blame] | 7216 | |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7217 | window->assertNoEvents(); |
| 7218 | monitor.assertNoEvents(); |
Prabir Pradhan | a0d43d4 | 2024-01-30 00:27:08 +0000 | [diff] [blame] | 7219 | secondWindow->assertNoEvents(); |
| 7220 | secondMonitor.assertNoEvents(); |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7221 | } |
| 7222 | |
| 7223 | /** |
| 7224 | * One display with transform |
| 7225 | * There is a foreground window and a monitor on the display |
| 7226 | * Inject down event and move event sequentially, the foreground window and monitor can receive down |
| 7227 | * event and move event, then let the foreground window go away, the foreground window receives |
| 7228 | * cancel event, inject move event again, the monitor receives cancel event, all the events received |
| 7229 | * by the monitor should be with the same transform as the display |
| 7230 | */ |
| 7231 | TEST_F(InputDispatcherMonitorTest, MonitorTouchCancelEventWithDisplayTransform) { |
| 7232 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7233 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Foreground", |
| 7234 | ui::LogicalDisplayId::DEFAULT); |
| 7235 | FakeMonitorReceiver monitor = |
| 7236 | FakeMonitorReceiver(*mDispatcher, "M_1", ui::LogicalDisplayId::DEFAULT); |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7237 | |
| 7238 | ui::Transform transform; |
| 7239 | transform.set({1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 0, 0, 1}); |
| 7240 | |
| 7241 | gui::DisplayInfo displayInfo; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7242 | displayInfo.displayId = ui::LogicalDisplayId::DEFAULT; |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7243 | displayInfo.transform = transform; |
| 7244 | |
| 7245 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {displayInfo}, 0, 0}); |
| 7246 | |
| 7247 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7248 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 7249 | ui::LogicalDisplayId::DEFAULT, {100, 200})) |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7250 | << "The down event injected should succeed"; |
| 7251 | |
| 7252 | window->consumeMotionDown(); |
| 7253 | std::unique_ptr<MotionEvent> downMotionEvent = monitor.consumeMotion(); |
| 7254 | EXPECT_EQ(transform, downMotionEvent->getTransform()); |
| 7255 | EXPECT_EQ(AMOTION_EVENT_ACTION_DOWN, downMotionEvent->getAction()); |
| 7256 | |
| 7257 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
| 7258 | injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7259 | ui::LogicalDisplayId::DEFAULT, {110, 220})) |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7260 | << "The move event injected should succeed"; |
| 7261 | |
| 7262 | window->consumeMotionMove(); |
| 7263 | std::unique_ptr<MotionEvent> moveMotionEvent = monitor.consumeMotion(); |
| 7264 | EXPECT_EQ(transform, moveMotionEvent->getTransform()); |
| 7265 | EXPECT_EQ(AMOTION_EVENT_ACTION_MOVE, moveMotionEvent->getAction()); |
| 7266 | |
| 7267 | // Let foreground window gone |
| 7268 | mDispatcher->onWindowInfosChanged({{}, {displayInfo}, 0, 0}); |
| 7269 | |
Prabir Pradhan | a0d43d4 | 2024-01-30 00:27:08 +0000 | [diff] [blame] | 7270 | // Foreground window should receive a cancel event, but not the monitor. |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7271 | window->consumeMotionCancel(); |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7272 | |
| 7273 | ASSERT_EQ(InputEventInjectionResult::FAILED, |
| 7274 | injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7275 | ui::LogicalDisplayId::DEFAULT, {110, 220})) |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7276 | << "The move event injected should failed"; |
| 7277 | // Now foreground should not receive any events, but monitor should receive a cancel event |
| 7278 | // with transform that same as display's display. |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7279 | std::unique_ptr<MotionEvent> cancelMotionEvent = monitor.consumeMotion(); |
| 7280 | EXPECT_EQ(transform, cancelMotionEvent->getTransform()); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7281 | EXPECT_EQ(ui::LogicalDisplayId::DEFAULT, cancelMotionEvent->getDisplayId()); |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7282 | EXPECT_EQ(AMOTION_EVENT_ACTION_CANCEL, cancelMotionEvent->getAction()); |
| 7283 | |
| 7284 | // Other event inject to this display should fail. |
| 7285 | ASSERT_EQ(InputEventInjectionResult::FAILED, |
| 7286 | injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7287 | ui::LogicalDisplayId::DEFAULT, {110, 220})) |
Prabir Pradhan | a0d43d4 | 2024-01-30 00:27:08 +0000 | [diff] [blame] | 7288 | << "The up event injected should fail because the touched window was removed"; |
Linnan Li | d815095 | 2024-01-26 18:07:17 +0000 | [diff] [blame] | 7289 | window->assertNoEvents(); |
| 7290 | monitor.assertNoEvents(); |
| 7291 | } |
| 7292 | |
chaviw | 81e2bb9 | 2019-12-18 15:03:51 -0800 | [diff] [blame] | 7293 | TEST_F(InputDispatcherTest, TestMoveEvent) { |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 7294 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7295 | sp<FakeWindowHandle> window = |
| 7296 | sp<FakeWindowHandle>::make(application, mDispatcher, "Fake Window", |
| 7297 | ui::LogicalDisplayId::DEFAULT); |
chaviw | 81e2bb9 | 2019-12-18 15:03:51 -0800 | [diff] [blame] | 7298 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 7299 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
chaviw | 81e2bb9 | 2019-12-18 15:03:51 -0800 | [diff] [blame] | 7300 | |
| 7301 | NotifyMotionArgs motionArgs = |
| 7302 | generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7303 | ui::LogicalDisplayId::DEFAULT); |
chaviw | 81e2bb9 | 2019-12-18 15:03:51 -0800 | [diff] [blame] | 7304 | |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 7305 | mDispatcher->notifyMotion(motionArgs); |
chaviw | 81e2bb9 | 2019-12-18 15:03:51 -0800 | [diff] [blame] | 7306 | // Window should receive motion down event. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7307 | window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
chaviw | 81e2bb9 | 2019-12-18 15:03:51 -0800 | [diff] [blame] | 7308 | |
| 7309 | motionArgs.action = AMOTION_EVENT_ACTION_MOVE; |
Garfield Tan | c51d1ba | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 7310 | motionArgs.id += 1; |
chaviw | 81e2bb9 | 2019-12-18 15:03:51 -0800 | [diff] [blame] | 7311 | motionArgs.eventTime = systemTime(SYSTEM_TIME_MONOTONIC); |
| 7312 | motionArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, |
| 7313 | motionArgs.pointerCoords[0].getX() - 10); |
| 7314 | |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 7315 | mDispatcher->notifyMotion(motionArgs); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7316 | window->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, /*expectedFlags=*/0); |
chaviw | 81e2bb9 | 2019-12-18 15:03:51 -0800 | [diff] [blame] | 7317 | } |
| 7318 | |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 7319 | /** |
| 7320 | * Dispatcher has touch mode enabled by default. Typically, the policy overrides that value to |
| 7321 | * the device default right away. In the test scenario, we check both the default value, |
| 7322 | * and the action of enabling / disabling. |
| 7323 | */ |
| 7324 | TEST_F(InputDispatcherTest, TouchModeState_IsSentToApps) { |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 7325 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7326 | sp<FakeWindowHandle> window = |
| 7327 | sp<FakeWindowHandle>::make(application, mDispatcher, "Test window", |
| 7328 | ui::LogicalDisplayId::DEFAULT); |
Antonio Kantek | ea47acb | 2021-12-23 12:41:25 -0800 | [diff] [blame] | 7329 | const WindowInfo& windowInfo = *window->getInfo(); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 7330 | |
| 7331 | // Set focused application. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7332 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); |
Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 7333 | window->setFocusable(true); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 7334 | |
| 7335 | SCOPED_TRACE("Check default value of touch mode"); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 7336 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7337 | setFocusedWindow(window); |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 7338 | window->consumeFocusEvent(/*hasFocus=*/true, /*inTouchMode=*/true); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 7339 | |
| 7340 | SCOPED_TRACE("Remove the window to trigger focus loss"); |
Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 7341 | window->setFocusable(false); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 7342 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 7343 | window->consumeFocusEvent(/*hasFocus=*/false, /*inTouchMode=*/true); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 7344 | |
| 7345 | SCOPED_TRACE("Disable touch mode"); |
Antonio Kantek | ea47acb | 2021-12-23 12:41:25 -0800 | [diff] [blame] | 7346 | mDispatcher->setInTouchMode(false, windowInfo.ownerPid, windowInfo.ownerUid, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7347 | /*hasPermission=*/true, ui::LogicalDisplayId::DEFAULT); |
Antonio Kantek | f16f283 | 2021-09-28 04:39:20 +0000 | [diff] [blame] | 7348 | window->consumeTouchModeEvent(false); |
Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 7349 | window->setFocusable(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 7350 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7351 | setFocusedWindow(window); |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 7352 | window->consumeFocusEvent(/*hasFocus=*/true, /*inTouchMode=*/false); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 7353 | |
| 7354 | SCOPED_TRACE("Remove the window to trigger focus loss"); |
Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 7355 | window->setFocusable(false); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 7356 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 7357 | window->consumeFocusEvent(/*hasFocus=*/false, /*inTouchMode=*/false); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 7358 | |
| 7359 | SCOPED_TRACE("Enable touch mode again"); |
Antonio Kantek | ea47acb | 2021-12-23 12:41:25 -0800 | [diff] [blame] | 7360 | mDispatcher->setInTouchMode(true, windowInfo.ownerPid, windowInfo.ownerUid, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7361 | /*hasPermission=*/true, ui::LogicalDisplayId::DEFAULT); |
Antonio Kantek | f16f283 | 2021-09-28 04:39:20 +0000 | [diff] [blame] | 7362 | window->consumeTouchModeEvent(true); |
Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 7363 | window->setFocusable(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 7364 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7365 | setFocusedWindow(window); |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 7366 | window->consumeFocusEvent(/*hasFocus=*/true, /*inTouchMode=*/true); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 7367 | |
| 7368 | window->assertNoEvents(); |
| 7369 | } |
| 7370 | |
Gang Wang | e908789 | 2020-01-07 12:17:14 -0500 | [diff] [blame] | 7371 | TEST_F(InputDispatcherTest, VerifyInputEvent_KeyEvent) { |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 7372 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7373 | sp<FakeWindowHandle> window = |
| 7374 | sp<FakeWindowHandle>::make(application, mDispatcher, "Test window", |
| 7375 | ui::LogicalDisplayId::DEFAULT); |
Gang Wang | e908789 | 2020-01-07 12:17:14 -0500 | [diff] [blame] | 7376 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7377 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); |
Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 7378 | window->setFocusable(true); |
Gang Wang | e908789 | 2020-01-07 12:17:14 -0500 | [diff] [blame] | 7379 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 7380 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7381 | setFocusedWindow(window); |
| 7382 | |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 7383 | window->consumeFocusEvent(/*hasFocus=*/true, /*inTouchMode=*/true); |
Gang Wang | e908789 | 2020-01-07 12:17:14 -0500 | [diff] [blame] | 7384 | |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 7385 | const NotifyKeyArgs keyArgs = generateKeyArgs(AKEY_EVENT_ACTION_DOWN); |
| 7386 | mDispatcher->notifyKey(keyArgs); |
Gang Wang | e908789 | 2020-01-07 12:17:14 -0500 | [diff] [blame] | 7387 | |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 7388 | std::unique_ptr<KeyEvent> event = window->consumeKey(); |
| 7389 | ASSERT_NE(event, nullptr); |
| 7390 | std::unique_ptr<VerifiedInputEvent> verified = mDispatcher->verifyInputEvent(*event); |
Gang Wang | e908789 | 2020-01-07 12:17:14 -0500 | [diff] [blame] | 7391 | ASSERT_NE(verified, nullptr); |
| 7392 | ASSERT_EQ(verified->type, VerifiedInputEvent::Type::KEY); |
| 7393 | |
| 7394 | ASSERT_EQ(keyArgs.eventTime, verified->eventTimeNanos); |
| 7395 | ASSERT_EQ(keyArgs.deviceId, verified->deviceId); |
| 7396 | ASSERT_EQ(keyArgs.source, verified->source); |
| 7397 | ASSERT_EQ(keyArgs.displayId, verified->displayId); |
| 7398 | |
| 7399 | const VerifiedKeyEvent& verifiedKey = static_cast<const VerifiedKeyEvent&>(*verified); |
| 7400 | |
| 7401 | ASSERT_EQ(keyArgs.action, verifiedKey.action); |
Gang Wang | e908789 | 2020-01-07 12:17:14 -0500 | [diff] [blame] | 7402 | ASSERT_EQ(keyArgs.flags & VERIFIED_KEY_EVENT_FLAGS, verifiedKey.flags); |
Siarhei Vishniakou | f355bf9 | 2021-12-09 10:43:21 -0800 | [diff] [blame] | 7403 | ASSERT_EQ(keyArgs.downTime, verifiedKey.downTimeNanos); |
Gang Wang | e908789 | 2020-01-07 12:17:14 -0500 | [diff] [blame] | 7404 | ASSERT_EQ(keyArgs.keyCode, verifiedKey.keyCode); |
| 7405 | ASSERT_EQ(keyArgs.scanCode, verifiedKey.scanCode); |
| 7406 | ASSERT_EQ(keyArgs.metaState, verifiedKey.metaState); |
| 7407 | ASSERT_EQ(0, verifiedKey.repeatCount); |
| 7408 | } |
| 7409 | |
Siarhei Vishniakou | 47040bf | 2020-02-28 15:03:13 -0800 | [diff] [blame] | 7410 | TEST_F(InputDispatcherTest, VerifyInputEvent_MotionEvent) { |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 7411 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7412 | sp<FakeWindowHandle> window = |
| 7413 | sp<FakeWindowHandle>::make(application, mDispatcher, "Test window", |
| 7414 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 47040bf | 2020-02-28 15:03:13 -0800 | [diff] [blame] | 7415 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7416 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); |
Siarhei Vishniakou | 47040bf | 2020-02-28 15:03:13 -0800 | [diff] [blame] | 7417 | |
Prabir Pradhan | b5cb957 | 2021-09-24 06:35:16 -0700 | [diff] [blame] | 7418 | ui::Transform transform; |
| 7419 | transform.set({1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 0, 0, 1}); |
| 7420 | |
| 7421 | gui::DisplayInfo displayInfo; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7422 | displayInfo.displayId = ui::LogicalDisplayId::DEFAULT; |
Prabir Pradhan | b5cb957 | 2021-09-24 06:35:16 -0700 | [diff] [blame] | 7423 | displayInfo.transform = transform; |
| 7424 | |
Patrick Williams | d828f30 | 2023-04-28 17:52:08 -0500 | [diff] [blame] | 7425 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {displayInfo}, 0, 0}); |
Siarhei Vishniakou | 47040bf | 2020-02-28 15:03:13 -0800 | [diff] [blame] | 7426 | |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 7427 | const NotifyMotionArgs motionArgs = |
Siarhei Vishniakou | 47040bf | 2020-02-28 15:03:13 -0800 | [diff] [blame] | 7428 | generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7429 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 7430 | mDispatcher->notifyMotion(motionArgs); |
Siarhei Vishniakou | 47040bf | 2020-02-28 15:03:13 -0800 | [diff] [blame] | 7431 | |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 7432 | std::unique_ptr<MotionEvent> event = window->consumeMotionEvent(); |
| 7433 | ASSERT_NE(nullptr, event); |
| 7434 | std::unique_ptr<VerifiedInputEvent> verified = mDispatcher->verifyInputEvent(*event); |
Siarhei Vishniakou | 47040bf | 2020-02-28 15:03:13 -0800 | [diff] [blame] | 7435 | ASSERT_NE(verified, nullptr); |
| 7436 | ASSERT_EQ(verified->type, VerifiedInputEvent::Type::MOTION); |
| 7437 | |
| 7438 | EXPECT_EQ(motionArgs.eventTime, verified->eventTimeNanos); |
| 7439 | EXPECT_EQ(motionArgs.deviceId, verified->deviceId); |
| 7440 | EXPECT_EQ(motionArgs.source, verified->source); |
| 7441 | EXPECT_EQ(motionArgs.displayId, verified->displayId); |
| 7442 | |
| 7443 | const VerifiedMotionEvent& verifiedMotion = static_cast<const VerifiedMotionEvent&>(*verified); |
| 7444 | |
Prabir Pradhan | b5cb957 | 2021-09-24 06:35:16 -0700 | [diff] [blame] | 7445 | const vec2 rawXY = |
| 7446 | MotionEvent::calculateTransformedXY(motionArgs.source, transform, |
| 7447 | motionArgs.pointerCoords[0].getXYValue()); |
| 7448 | EXPECT_EQ(rawXY.x, verifiedMotion.rawX); |
| 7449 | EXPECT_EQ(rawXY.y, verifiedMotion.rawY); |
Siarhei Vishniakou | 47040bf | 2020-02-28 15:03:13 -0800 | [diff] [blame] | 7450 | EXPECT_EQ(motionArgs.action & AMOTION_EVENT_ACTION_MASK, verifiedMotion.actionMasked); |
Siarhei Vishniakou | 47040bf | 2020-02-28 15:03:13 -0800 | [diff] [blame] | 7451 | EXPECT_EQ(motionArgs.flags & VERIFIED_MOTION_EVENT_FLAGS, verifiedMotion.flags); |
Siarhei Vishniakou | f355bf9 | 2021-12-09 10:43:21 -0800 | [diff] [blame] | 7452 | EXPECT_EQ(motionArgs.downTime, verifiedMotion.downTimeNanos); |
Siarhei Vishniakou | 47040bf | 2020-02-28 15:03:13 -0800 | [diff] [blame] | 7453 | EXPECT_EQ(motionArgs.metaState, verifiedMotion.metaState); |
| 7454 | EXPECT_EQ(motionArgs.buttonState, verifiedMotion.buttonState); |
| 7455 | } |
| 7456 | |
chaviw | 09c8d2d | 2020-08-24 15:48:26 -0700 | [diff] [blame] | 7457 | /** |
| 7458 | * Ensure that separate calls to sign the same data are generating the same key. |
| 7459 | * We avoid asserting against INVALID_HMAC. Since the key is random, there is a non-zero chance |
| 7460 | * that a specific key and data combination would produce INVALID_HMAC, which would cause flaky |
| 7461 | * tests. |
| 7462 | */ |
| 7463 | TEST_F(InputDispatcherTest, GeneratedHmac_IsConsistent) { |
| 7464 | KeyEvent event = getTestKeyEvent(); |
| 7465 | VerifiedKeyEvent verifiedEvent = verifiedKeyEventFromKeyEvent(event); |
| 7466 | |
| 7467 | std::array<uint8_t, 32> hmac1 = mDispatcher->sign(verifiedEvent); |
| 7468 | std::array<uint8_t, 32> hmac2 = mDispatcher->sign(verifiedEvent); |
| 7469 | ASSERT_EQ(hmac1, hmac2); |
| 7470 | } |
| 7471 | |
| 7472 | /** |
| 7473 | * Ensure that changes in VerifiedKeyEvent produce a different hmac. |
| 7474 | */ |
| 7475 | TEST_F(InputDispatcherTest, GeneratedHmac_ChangesWhenFieldsChange) { |
| 7476 | KeyEvent event = getTestKeyEvent(); |
| 7477 | VerifiedKeyEvent verifiedEvent = verifiedKeyEventFromKeyEvent(event); |
| 7478 | std::array<uint8_t, 32> initialHmac = mDispatcher->sign(verifiedEvent); |
| 7479 | |
| 7480 | verifiedEvent.deviceId += 1; |
| 7481 | ASSERT_NE(initialHmac, mDispatcher->sign(verifiedEvent)); |
| 7482 | |
| 7483 | verifiedEvent.source += 1; |
| 7484 | ASSERT_NE(initialHmac, mDispatcher->sign(verifiedEvent)); |
| 7485 | |
| 7486 | verifiedEvent.eventTimeNanos += 1; |
| 7487 | ASSERT_NE(initialHmac, mDispatcher->sign(verifiedEvent)); |
| 7488 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 7489 | verifiedEvent.displayId = ui::LogicalDisplayId{verifiedEvent.displayId.val() + 1}; |
chaviw | 09c8d2d | 2020-08-24 15:48:26 -0700 | [diff] [blame] | 7490 | ASSERT_NE(initialHmac, mDispatcher->sign(verifiedEvent)); |
| 7491 | |
| 7492 | verifiedEvent.action += 1; |
| 7493 | ASSERT_NE(initialHmac, mDispatcher->sign(verifiedEvent)); |
| 7494 | |
| 7495 | verifiedEvent.downTimeNanos += 1; |
| 7496 | ASSERT_NE(initialHmac, mDispatcher->sign(verifiedEvent)); |
| 7497 | |
| 7498 | verifiedEvent.flags += 1; |
| 7499 | ASSERT_NE(initialHmac, mDispatcher->sign(verifiedEvent)); |
| 7500 | |
| 7501 | verifiedEvent.keyCode += 1; |
| 7502 | ASSERT_NE(initialHmac, mDispatcher->sign(verifiedEvent)); |
| 7503 | |
| 7504 | verifiedEvent.scanCode += 1; |
| 7505 | ASSERT_NE(initialHmac, mDispatcher->sign(verifiedEvent)); |
| 7506 | |
| 7507 | verifiedEvent.metaState += 1; |
| 7508 | ASSERT_NE(initialHmac, mDispatcher->sign(verifiedEvent)); |
| 7509 | |
| 7510 | verifiedEvent.repeatCount += 1; |
| 7511 | ASSERT_NE(initialHmac, mDispatcher->sign(verifiedEvent)); |
| 7512 | } |
| 7513 | |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7514 | TEST_F(InputDispatcherTest, SetFocusedWindow) { |
| 7515 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7516 | sp<FakeWindowHandle> windowTop = sp<FakeWindowHandle>::make(application, mDispatcher, "Top", |
| 7517 | ui::LogicalDisplayId::DEFAULT); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7518 | sp<FakeWindowHandle> windowSecond = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7519 | sp<FakeWindowHandle>::make(application, mDispatcher, "Second", |
| 7520 | ui::LogicalDisplayId::DEFAULT); |
| 7521 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7522 | |
| 7523 | // Top window is also focusable but is not granted focus. |
| 7524 | windowTop->setFocusable(true); |
| 7525 | windowSecond->setFocusable(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 7526 | mDispatcher->onWindowInfosChanged( |
| 7527 | {{*windowTop->getInfo(), *windowSecond->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7528 | setFocusedWindow(windowSecond); |
| 7529 | |
| 7530 | windowSecond->consumeFocusEvent(true); |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 7531 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(*mDispatcher)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 7532 | << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7533 | |
| 7534 | // Focused window should receive event. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7535 | windowSecond->consumeKeyDown(ui::LogicalDisplayId::INVALID); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7536 | windowTop->assertNoEvents(); |
| 7537 | } |
| 7538 | |
| 7539 | TEST_F(InputDispatcherTest, SetFocusedWindow_DropRequestInvalidChannel) { |
| 7540 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7541 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "TestWindow", |
| 7542 | ui::LogicalDisplayId::DEFAULT); |
| 7543 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7544 | |
| 7545 | window->setFocusable(true); |
| 7546 | // Release channel for window is no longer valid. |
| 7547 | window->releaseChannel(); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 7548 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7549 | setFocusedWindow(window); |
| 7550 | |
| 7551 | // Test inject a key down, should timeout. |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 7552 | ASSERT_NO_FATAL_FAILURE(assertInjectedKeyTimesOut(*mDispatcher)); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7553 | |
| 7554 | // window channel is invalid, so it should not receive any input event. |
| 7555 | window->assertNoEvents(); |
| 7556 | } |
| 7557 | |
| 7558 | TEST_F(InputDispatcherTest, SetFocusedWindow_DropRequestNoFocusableWindow) { |
| 7559 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7560 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "TestWindow", |
| 7561 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 76bdecb | 2022-01-31 11:14:15 -0800 | [diff] [blame] | 7562 | window->setFocusable(false); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7563 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7564 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 7565 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7566 | setFocusedWindow(window); |
| 7567 | |
| 7568 | // Test inject a key down, should timeout. |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 7569 | ASSERT_NO_FATAL_FAILURE(assertInjectedKeyTimesOut(*mDispatcher)); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7570 | |
Prabir Pradhan | 76bdecb | 2022-01-31 11:14:15 -0800 | [diff] [blame] | 7571 | // window is not focusable, so it should not receive any input event. |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7572 | window->assertNoEvents(); |
| 7573 | } |
| 7574 | |
| 7575 | TEST_F(InputDispatcherTest, SetFocusedWindow_CheckFocusedToken) { |
| 7576 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7577 | sp<FakeWindowHandle> windowTop = sp<FakeWindowHandle>::make(application, mDispatcher, "Top", |
| 7578 | ui::LogicalDisplayId::DEFAULT); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7579 | sp<FakeWindowHandle> windowSecond = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7580 | sp<FakeWindowHandle>::make(application, mDispatcher, "Second", |
| 7581 | ui::LogicalDisplayId::DEFAULT); |
| 7582 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7583 | |
| 7584 | windowTop->setFocusable(true); |
| 7585 | windowSecond->setFocusable(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 7586 | mDispatcher->onWindowInfosChanged( |
| 7587 | {{*windowTop->getInfo(), *windowSecond->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7588 | setFocusedWindow(windowTop); |
| 7589 | windowTop->consumeFocusEvent(true); |
| 7590 | |
Chavi Weingarten | 847e851 | 2023-03-29 00:26:09 +0000 | [diff] [blame] | 7591 | windowTop->editInfo()->focusTransferTarget = windowSecond->getToken(); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 7592 | mDispatcher->onWindowInfosChanged( |
| 7593 | {{*windowTop->getInfo(), *windowSecond->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7594 | windowSecond->consumeFocusEvent(true); |
| 7595 | windowTop->consumeFocusEvent(false); |
| 7596 | |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 7597 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(*mDispatcher)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 7598 | << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7599 | |
| 7600 | // Focused window should receive event. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7601 | windowSecond->consumeKeyDown(ui::LogicalDisplayId::INVALID); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7602 | } |
| 7603 | |
Chavi Weingarten | 847e851 | 2023-03-29 00:26:09 +0000 | [diff] [blame] | 7604 | TEST_F(InputDispatcherTest, SetFocusedWindow_TransferFocusTokenNotFocusable) { |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7605 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7606 | sp<FakeWindowHandle> windowTop = sp<FakeWindowHandle>::make(application, mDispatcher, "Top", |
| 7607 | ui::LogicalDisplayId::DEFAULT); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7608 | sp<FakeWindowHandle> windowSecond = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7609 | sp<FakeWindowHandle>::make(application, mDispatcher, "Second", |
| 7610 | ui::LogicalDisplayId::DEFAULT); |
| 7611 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7612 | |
| 7613 | windowTop->setFocusable(true); |
Chavi Weingarten | 847e851 | 2023-03-29 00:26:09 +0000 | [diff] [blame] | 7614 | windowSecond->setFocusable(false); |
| 7615 | windowTop->editInfo()->focusTransferTarget = windowSecond->getToken(); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 7616 | mDispatcher->onWindowInfosChanged( |
| 7617 | {{*windowTop->getInfo(), *windowSecond->getInfo()}, {}, 0, 0}); |
Chavi Weingarten | 847e851 | 2023-03-29 00:26:09 +0000 | [diff] [blame] | 7618 | setFocusedWindow(windowTop); |
| 7619 | windowTop->consumeFocusEvent(true); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7620 | |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 7621 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(*mDispatcher)) |
Chavi Weingarten | 847e851 | 2023-03-29 00:26:09 +0000 | [diff] [blame] | 7622 | << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7623 | |
| 7624 | // Event should be dropped. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7625 | windowTop->consumeKeyDown(ui::LogicalDisplayId::INVALID); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7626 | windowSecond->assertNoEvents(); |
| 7627 | } |
| 7628 | |
| 7629 | TEST_F(InputDispatcherTest, SetFocusedWindow_DeferInvisibleWindow) { |
| 7630 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7631 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "TestWindow", |
| 7632 | ui::LogicalDisplayId::DEFAULT); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7633 | sp<FakeWindowHandle> previousFocusedWindow = |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 7634 | sp<FakeWindowHandle>::make(application, mDispatcher, "previousFocusedWindow", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7635 | ui::LogicalDisplayId::DEFAULT); |
| 7636 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7637 | |
| 7638 | window->setFocusable(true); |
| 7639 | previousFocusedWindow->setFocusable(true); |
| 7640 | window->setVisible(false); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 7641 | mDispatcher->onWindowInfosChanged( |
| 7642 | {{*window->getInfo(), *previousFocusedWindow->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7643 | setFocusedWindow(previousFocusedWindow); |
| 7644 | previousFocusedWindow->consumeFocusEvent(true); |
| 7645 | |
| 7646 | // Requesting focus on invisible window takes focus from currently focused window. |
| 7647 | setFocusedWindow(window); |
| 7648 | previousFocusedWindow->consumeFocusEvent(false); |
| 7649 | |
| 7650 | // Injected key goes to pending queue. |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 7651 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 7652 | injectKey(*mDispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7653 | ui::LogicalDisplayId::DEFAULT, InputEventInjectionSync::NONE)); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7654 | |
| 7655 | // Window does not get focus event or key down. |
| 7656 | window->assertNoEvents(); |
| 7657 | |
| 7658 | // Window becomes visible. |
| 7659 | window->setVisible(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 7660 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7661 | |
| 7662 | // Window receives focus event. |
| 7663 | window->consumeFocusEvent(true); |
| 7664 | // Focused window receives key down. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7665 | window->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 7666 | } |
| 7667 | |
Vishnu Nair | 599f141 | 2021-06-21 10:39:58 -0700 | [diff] [blame] | 7668 | TEST_F(InputDispatcherTest, DisplayRemoved) { |
| 7669 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7670 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "window", |
| 7671 | ui::LogicalDisplayId::DEFAULT); |
| 7672 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); |
Vishnu Nair | 599f141 | 2021-06-21 10:39:58 -0700 | [diff] [blame] | 7673 | |
| 7674 | // window is granted focus. |
| 7675 | window->setFocusable(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 7676 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 599f141 | 2021-06-21 10:39:58 -0700 | [diff] [blame] | 7677 | setFocusedWindow(window); |
| 7678 | window->consumeFocusEvent(true); |
| 7679 | |
| 7680 | // When a display is removed window loses focus. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7681 | mDispatcher->displayRemoved(ui::LogicalDisplayId::DEFAULT); |
Vishnu Nair | 599f141 | 2021-06-21 10:39:58 -0700 | [diff] [blame] | 7682 | window->consumeFocusEvent(false); |
| 7683 | } |
| 7684 | |
Siarhei Vishniakou | 870ecec | 2020-12-09 08:07:46 -1000 | [diff] [blame] | 7685 | /** |
| 7686 | * Launch two windows, with different owners. One window (slipperyExitWindow) has Flag::SLIPPERY, |
| 7687 | * and overlaps the other window, slipperyEnterWindow. The window 'slipperyExitWindow' is on top |
| 7688 | * of the 'slipperyEnterWindow'. |
| 7689 | * |
| 7690 | * Inject touch down into the top window. Upon receipt of the DOWN event, move the window in such |
| 7691 | * a way so that the touched location is no longer covered by the top window. |
| 7692 | * |
| 7693 | * Next, inject a MOVE event. Because the top window already moved earlier, this event is now |
| 7694 | * positioned over the bottom (slipperyEnterWindow) only. And because the top window had |
| 7695 | * Flag::SLIPPERY, this will cause the top window to lose the touch event (it will receive |
| 7696 | * ACTION_CANCEL instead), and the bottom window will receive a newly generated gesture (starting |
| 7697 | * with ACTION_DOWN). |
| 7698 | * Thus, the touch has been transferred from the top window into the bottom window, because the top |
| 7699 | * window moved itself away from the touched location and had Flag::SLIPPERY. |
| 7700 | * |
| 7701 | * Even though the top window moved away from the touched location, it is still obscuring the bottom |
| 7702 | * window. It's just not obscuring it at the touched location. That means, FLAG_WINDOW_IS_PARTIALLY_ |
| 7703 | * OBSCURED should be set for the MotionEvent that reaches the bottom window. |
| 7704 | * |
| 7705 | * In this test, we ensure that the event received by the bottom window has |
| 7706 | * FLAG_WINDOW_IS_PARTIALLY_OBSCURED. |
| 7707 | */ |
| 7708 | TEST_F(InputDispatcherTest, SlipperyWindow_SetsFlagPartiallyObscured) { |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 7709 | constexpr gui::Pid SLIPPERY_PID{WINDOW_PID.val() + 1}; |
Prabir Pradhan | 8a5c41d | 2023-06-08 19:13:46 +0000 | [diff] [blame] | 7710 | constexpr gui::Uid SLIPPERY_UID{WINDOW_UID.val() + 1}; |
Siarhei Vishniakou | 870ecec | 2020-12-09 08:07:46 -1000 | [diff] [blame] | 7711 | |
| 7712 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7713 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); |
Siarhei Vishniakou | 870ecec | 2020-12-09 08:07:46 -1000 | [diff] [blame] | 7714 | |
| 7715 | sp<FakeWindowHandle> slipperyExitWindow = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7716 | sp<FakeWindowHandle>::make(application, mDispatcher, "Top", |
| 7717 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 7718 | slipperyExitWindow->setSlippery(true); |
Siarhei Vishniakou | 870ecec | 2020-12-09 08:07:46 -1000 | [diff] [blame] | 7719 | // Make sure this one overlaps the bottom window |
| 7720 | slipperyExitWindow->setFrame(Rect(25, 25, 75, 75)); |
| 7721 | // Change the owner uid/pid of the window so that it is considered to be occluding the bottom |
| 7722 | // one. Windows with the same owner are not considered to be occluding each other. |
| 7723 | slipperyExitWindow->setOwnerInfo(SLIPPERY_PID, SLIPPERY_UID); |
| 7724 | |
| 7725 | sp<FakeWindowHandle> slipperyEnterWindow = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7726 | sp<FakeWindowHandle>::make(application, mDispatcher, "Second", |
| 7727 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 870ecec | 2020-12-09 08:07:46 -1000 | [diff] [blame] | 7728 | slipperyExitWindow->setFrame(Rect(0, 0, 100, 100)); |
| 7729 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 7730 | mDispatcher->onWindowInfosChanged( |
| 7731 | {{*slipperyExitWindow->getInfo(), *slipperyEnterWindow->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | 870ecec | 2020-12-09 08:07:46 -1000 | [diff] [blame] | 7732 | |
| 7733 | // Use notifyMotion instead of injecting to avoid dealing with injection permissions |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 7734 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7735 | AINPUT_SOURCE_TOUCHSCREEN, |
| 7736 | ui::LogicalDisplayId::DEFAULT, {{50, 50}})); |
Siarhei Vishniakou | 870ecec | 2020-12-09 08:07:46 -1000 | [diff] [blame] | 7737 | slipperyExitWindow->consumeMotionDown(); |
| 7738 | slipperyExitWindow->setFrame(Rect(70, 70, 100, 100)); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 7739 | mDispatcher->onWindowInfosChanged( |
| 7740 | {{*slipperyExitWindow->getInfo(), *slipperyEnterWindow->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | 870ecec | 2020-12-09 08:07:46 -1000 | [diff] [blame] | 7741 | |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 7742 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_MOVE, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7743 | AINPUT_SOURCE_TOUCHSCREEN, |
| 7744 | ui::LogicalDisplayId::DEFAULT, {{51, 51}})); |
Siarhei Vishniakou | 870ecec | 2020-12-09 08:07:46 -1000 | [diff] [blame] | 7745 | |
| 7746 | slipperyExitWindow->consumeMotionCancel(); |
| 7747 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7748 | slipperyEnterWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, |
Siarhei Vishniakou | 870ecec | 2020-12-09 08:07:46 -1000 | [diff] [blame] | 7749 | AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED); |
| 7750 | } |
| 7751 | |
Siarhei Vishniakou | afa08cc | 2023-05-08 22:35:50 -0700 | [diff] [blame] | 7752 | /** |
| 7753 | * Two windows, one on the left and another on the right. The left window is slippery. The right |
| 7754 | * window isn't eligible to receive touch because it specifies InputConfig::DROP_INPUT. When the |
| 7755 | * touch moves from the left window into the right window, the gesture should continue to go to the |
| 7756 | * left window. Touch shouldn't slip because the right window can't receive touches. This test |
| 7757 | * reproduces a crash. |
| 7758 | */ |
| 7759 | TEST_F(InputDispatcherTest, TouchSlippingIntoWindowThatDropsTouches) { |
| 7760 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 7761 | |
| 7762 | sp<FakeWindowHandle> leftSlipperyWindow = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7763 | sp<FakeWindowHandle>::make(application, mDispatcher, "Left", |
| 7764 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | afa08cc | 2023-05-08 22:35:50 -0700 | [diff] [blame] | 7765 | leftSlipperyWindow->setSlippery(true); |
| 7766 | leftSlipperyWindow->setFrame(Rect(0, 0, 100, 100)); |
| 7767 | |
| 7768 | sp<FakeWindowHandle> rightDropTouchesWindow = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7769 | sp<FakeWindowHandle>::make(application, mDispatcher, "Right", |
| 7770 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | afa08cc | 2023-05-08 22:35:50 -0700 | [diff] [blame] | 7771 | rightDropTouchesWindow->setFrame(Rect(100, 0, 200, 100)); |
| 7772 | rightDropTouchesWindow->setDropInput(true); |
| 7773 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 7774 | mDispatcher->onWindowInfosChanged( |
| 7775 | {{*leftSlipperyWindow->getInfo(), *rightDropTouchesWindow->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | afa08cc | 2023-05-08 22:35:50 -0700 | [diff] [blame] | 7776 | |
| 7777 | // Start touch in the left window |
| 7778 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 7779 | .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) |
| 7780 | .build()); |
| 7781 | leftSlipperyWindow->consumeMotionDown(); |
| 7782 | |
| 7783 | // And move it into the right window |
| 7784 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 7785 | .pointer(PointerBuilder(0, ToolType::FINGER).x(150).y(50)) |
| 7786 | .build()); |
| 7787 | |
| 7788 | // Since the right window isn't eligible to receive input, touch does not slip. |
| 7789 | // The left window continues to receive the gesture. |
| 7790 | leftSlipperyWindow->consumeMotionEvent(WithMotionAction(ACTION_MOVE)); |
| 7791 | rightDropTouchesWindow->assertNoEvents(); |
| 7792 | } |
| 7793 | |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 7794 | /** |
| 7795 | * A single window is on screen first. Touch is injected into that window. Next, a second window |
| 7796 | * appears. Since the first window is slippery, touch will move from the first window to the second. |
| 7797 | */ |
| 7798 | TEST_F(InputDispatcherTest, InjectedTouchSlips) { |
| 7799 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 7800 | sp<FakeWindowHandle> originalWindow = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7801 | sp<FakeWindowHandle>::make(application, mDispatcher, "Original", |
| 7802 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 7803 | originalWindow->setFrame(Rect(0, 0, 200, 200)); |
| 7804 | originalWindow->setSlippery(true); |
| 7805 | |
| 7806 | sp<FakeWindowHandle> appearingWindow = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7807 | sp<FakeWindowHandle>::make(application, mDispatcher, "Appearing", |
| 7808 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 7809 | appearingWindow->setFrame(Rect(0, 0, 200, 200)); |
| 7810 | |
| 7811 | mDispatcher->onWindowInfosChanged({{*originalWindow->getInfo()}, {}, 0, 0}); |
| 7812 | |
| 7813 | // Touch down on the original window |
| 7814 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
| 7815 | injectMotionEvent(*mDispatcher, |
| 7816 | MotionEventBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 7817 | .pointer(PointerBuilder(1, ToolType::FINGER).x(100).y(100)) |
| 7818 | .build())); |
| 7819 | originalWindow->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); |
| 7820 | |
| 7821 | // Now, a new window appears. This could be, for example, a notification shade that appears |
| 7822 | // after user starts to drag down on the launcher window. |
| 7823 | mDispatcher->onWindowInfosChanged( |
| 7824 | {{*appearingWindow->getInfo(), *originalWindow->getInfo()}, {}, 0, 0}); |
| 7825 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
| 7826 | injectMotionEvent(*mDispatcher, |
| 7827 | MotionEventBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 7828 | .pointer(PointerBuilder(1, ToolType::FINGER).x(110).y(110)) |
| 7829 | .build())); |
| 7830 | originalWindow->consumeMotionEvent(WithMotionAction(ACTION_CANCEL)); |
| 7831 | appearingWindow->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); |
| 7832 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
| 7833 | injectMotionEvent(*mDispatcher, |
| 7834 | MotionEventBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 7835 | .pointer(PointerBuilder(1, ToolType::FINGER).x(120).y(120)) |
| 7836 | .build())); |
| 7837 | appearingWindow->consumeMotionEvent(WithMotionAction(ACTION_MOVE)); |
| 7838 | |
| 7839 | originalWindow->assertNoEvents(); |
| 7840 | appearingWindow->assertNoEvents(); |
| 7841 | } |
| 7842 | |
Linnan Li | 49b2b20 | 2024-04-12 12:46:40 +0800 | [diff] [blame] | 7843 | /** |
| 7844 | * Three windows: |
| 7845 | * - left window, which has FLAG_SLIPPERY, so it supports slippery exit |
| 7846 | * - right window |
| 7847 | * - spy window |
| 7848 | * The three windows do not overlap. |
| 7849 | * |
| 7850 | * We have two devices reporting events: |
| 7851 | * - Device A reports ACTION_DOWN, which lands in the left window |
| 7852 | * - Device B reports ACTION_DOWN, which lands in the spy window. |
| 7853 | * - Now, device B reports ACTION_MOVE events which move to the right window. |
| 7854 | * |
| 7855 | * The right window should not receive any events because the spy window is not a foreground window, |
| 7856 | * and also it does not support slippery touches. |
| 7857 | */ |
| 7858 | TEST_F(InputDispatcherTest, MultiDeviceSpyWindowSlipTest) { |
| 7859 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 7860 | sp<FakeWindowHandle> leftWindow = |
| 7861 | sp<FakeWindowHandle>::make(application, mDispatcher, "Left window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7862 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | 49b2b20 | 2024-04-12 12:46:40 +0800 | [diff] [blame] | 7863 | leftWindow->setFrame(Rect(0, 0, 100, 100)); |
| 7864 | leftWindow->setSlippery(true); |
| 7865 | |
| 7866 | sp<FakeWindowHandle> rightWindow = |
| 7867 | sp<FakeWindowHandle>::make(application, mDispatcher, "Right window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7868 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | 49b2b20 | 2024-04-12 12:46:40 +0800 | [diff] [blame] | 7869 | rightWindow->setFrame(Rect(100, 0, 200, 100)); |
| 7870 | |
| 7871 | sp<FakeWindowHandle> spyWindow = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7872 | sp<FakeWindowHandle>::make(application, mDispatcher, "Spy Window", |
| 7873 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | 49b2b20 | 2024-04-12 12:46:40 +0800 | [diff] [blame] | 7874 | spyWindow->setFrame(Rect(200, 0, 300, 100)); |
| 7875 | spyWindow->setSpy(true); |
| 7876 | spyWindow->setTrustedOverlay(true); |
| 7877 | |
| 7878 | mDispatcher->onWindowInfosChanged( |
| 7879 | {{*leftWindow->getInfo(), *rightWindow->getInfo(), *spyWindow->getInfo()}, {}, 0, 0}); |
| 7880 | |
| 7881 | const DeviceId deviceA = 9; |
| 7882 | const DeviceId deviceB = 3; |
| 7883 | |
| 7884 | // Tap on left window with device A |
| 7885 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 7886 | .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) |
| 7887 | .deviceId(deviceA) |
| 7888 | .build()); |
| 7889 | leftWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(deviceA))); |
| 7890 | |
| 7891 | // Tap on spy window with device B |
| 7892 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 7893 | .pointer(PointerBuilder(0, ToolType::FINGER).x(250).y(50)) |
| 7894 | .deviceId(deviceB) |
| 7895 | .build()); |
| 7896 | spyWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(deviceB))); |
| 7897 | |
| 7898 | // Move to right window with device B. Touches should not slip to the right window, because spy |
| 7899 | // window is not a foreground window, and it does not have FLAG_SLIPPERY |
| 7900 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 7901 | .pointer(PointerBuilder(0, ToolType::FINGER).x(150).y(50)) |
| 7902 | .deviceId(deviceB) |
| 7903 | .build()); |
| 7904 | leftWindow->assertNoEvents(); |
| 7905 | rightWindow->assertNoEvents(); |
| 7906 | spyWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(deviceB))); |
| 7907 | } |
| 7908 | |
| 7909 | /** |
| 7910 | * Three windows arranged horizontally and without any overlap. |
| 7911 | * The left and right windows have FLAG_SLIPPERY. The middle window does not have any special flags. |
| 7912 | * |
| 7913 | * We have two devices reporting events: |
| 7914 | * - Device A reports ACTION_DOWN which lands in the left window |
| 7915 | * - Device B reports ACTION_DOWN which lands in the right window |
| 7916 | * - Device B reports ACTION_MOVE that shifts to the middle window. |
| 7917 | * This should cause touches for Device B to slip from the right window to the middle window. |
| 7918 | * The right window should receive ACTION_CANCEL for device B and the |
| 7919 | * middle window should receive down event for Device B. |
| 7920 | * If device B reports more ACTION_MOVE events, the middle window should receive remaining events. |
| 7921 | */ |
| 7922 | TEST_F(InputDispatcherTest, MultiDeviceSlipperyWindowTest) { |
Siarhei Vishniakou | dd56df1 | 2024-05-20 14:56:38 -0700 | [diff] [blame] | 7923 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); |
Linnan Li | 49b2b20 | 2024-04-12 12:46:40 +0800 | [diff] [blame] | 7924 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 7925 | sp<FakeWindowHandle> leftWindow = |
| 7926 | sp<FakeWindowHandle>::make(application, mDispatcher, "Left window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7927 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | 49b2b20 | 2024-04-12 12:46:40 +0800 | [diff] [blame] | 7928 | leftWindow->setFrame(Rect(0, 0, 100, 100)); |
| 7929 | leftWindow->setSlippery(true); |
| 7930 | |
| 7931 | sp<FakeWindowHandle> middleWindow = |
| 7932 | sp<FakeWindowHandle>::make(application, mDispatcher, "middle window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7933 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | 49b2b20 | 2024-04-12 12:46:40 +0800 | [diff] [blame] | 7934 | middleWindow->setFrame(Rect(100, 0, 200, 100)); |
| 7935 | |
| 7936 | sp<FakeWindowHandle> rightWindow = |
| 7937 | sp<FakeWindowHandle>::make(application, mDispatcher, "Right window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7938 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | 49b2b20 | 2024-04-12 12:46:40 +0800 | [diff] [blame] | 7939 | rightWindow->setFrame(Rect(200, 0, 300, 100)); |
| 7940 | rightWindow->setSlippery(true); |
| 7941 | |
| 7942 | mDispatcher->onWindowInfosChanged( |
| 7943 | {{*leftWindow->getInfo(), *middleWindow->getInfo(), *rightWindow->getInfo()}, |
| 7944 | {}, |
| 7945 | 0, |
| 7946 | 0}); |
| 7947 | |
| 7948 | const DeviceId deviceA = 9; |
| 7949 | const DeviceId deviceB = 3; |
| 7950 | |
| 7951 | // Tap on left window with device A |
| 7952 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 7953 | .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) |
| 7954 | .deviceId(deviceA) |
| 7955 | .build()); |
| 7956 | leftWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(deviceA))); |
| 7957 | |
| 7958 | // Tap on right window with device B |
| 7959 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 7960 | .pointer(PointerBuilder(0, ToolType::FINGER).x(250).y(50)) |
| 7961 | .deviceId(deviceB) |
| 7962 | .build()); |
| 7963 | rightWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(deviceB))); |
| 7964 | |
| 7965 | // Move to middle window with device B. Touches should slip to middle window, because right |
| 7966 | // window is a foreground window that's associated with device B and has FLAG_SLIPPERY. |
| 7967 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 7968 | .pointer(PointerBuilder(0, ToolType::FINGER).x(150).y(50)) |
| 7969 | .deviceId(deviceB) |
| 7970 | .build()); |
| 7971 | rightWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_CANCEL), WithDeviceId(deviceB))); |
| 7972 | middleWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(deviceB))); |
| 7973 | |
| 7974 | // Move to middle window with device A. Touches should slip to middle window, because left |
| 7975 | // window is a foreground window that's associated with device A and has FLAG_SLIPPERY. |
| 7976 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 7977 | .pointer(PointerBuilder(0, ToolType::FINGER).x(150).y(50)) |
| 7978 | .deviceId(deviceA) |
| 7979 | .build()); |
| 7980 | leftWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_CANCEL), WithDeviceId(deviceA))); |
| 7981 | middleWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(deviceA))); |
| 7982 | |
| 7983 | // Ensure that middle window can receive the remaining move events. |
| 7984 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 7985 | .pointer(PointerBuilder(0, ToolType::FINGER).x(151).y(51)) |
| 7986 | .deviceId(deviceB) |
| 7987 | .build()); |
| 7988 | leftWindow->assertNoEvents(); |
| 7989 | middleWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(deviceB))); |
| 7990 | rightWindow->assertNoEvents(); |
| 7991 | } |
| 7992 | |
Prabir Pradhan | 8ede1d1 | 2023-05-08 19:37:44 +0000 | [diff] [blame] | 7993 | TEST_F(InputDispatcherTest, NotifiesDeviceInteractionsWithMotions) { |
Prabir Pradhan | 8a5c41d | 2023-06-08 19:13:46 +0000 | [diff] [blame] | 7994 | using Uid = gui::Uid; |
Prabir Pradhan | 8ede1d1 | 2023-05-08 19:37:44 +0000 | [diff] [blame] | 7995 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 7996 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 7997 | sp<FakeWindowHandle> leftWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Left", |
| 7998 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 8ede1d1 | 2023-05-08 19:37:44 +0000 | [diff] [blame] | 7999 | leftWindow->setFrame(Rect(0, 0, 100, 100)); |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 8000 | leftWindow->setOwnerInfo(gui::Pid{1}, Uid{101}); |
Prabir Pradhan | 8ede1d1 | 2023-05-08 19:37:44 +0000 | [diff] [blame] | 8001 | |
| 8002 | sp<FakeWindowHandle> rightSpy = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8003 | sp<FakeWindowHandle>::make(application, mDispatcher, "Right spy", |
| 8004 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 8ede1d1 | 2023-05-08 19:37:44 +0000 | [diff] [blame] | 8005 | rightSpy->setFrame(Rect(100, 0, 200, 100)); |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 8006 | rightSpy->setOwnerInfo(gui::Pid{2}, Uid{102}); |
Prabir Pradhan | 8ede1d1 | 2023-05-08 19:37:44 +0000 | [diff] [blame] | 8007 | rightSpy->setSpy(true); |
| 8008 | rightSpy->setTrustedOverlay(true); |
| 8009 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8010 | sp<FakeWindowHandle> rightWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Right", |
| 8011 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 8ede1d1 | 2023-05-08 19:37:44 +0000 | [diff] [blame] | 8012 | rightWindow->setFrame(Rect(100, 0, 200, 100)); |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 8013 | rightWindow->setOwnerInfo(gui::Pid{3}, Uid{103}); |
Prabir Pradhan | 8ede1d1 | 2023-05-08 19:37:44 +0000 | [diff] [blame] | 8014 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 8015 | mDispatcher->onWindowInfosChanged( |
| 8016 | {{*rightSpy->getInfo(), *rightWindow->getInfo(), *leftWindow->getInfo()}, {}, 0, 0}); |
Prabir Pradhan | 8ede1d1 | 2023-05-08 19:37:44 +0000 | [diff] [blame] | 8017 | |
| 8018 | // Touch in the left window |
| 8019 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 8020 | .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) |
| 8021 | .build()); |
| 8022 | ASSERT_NO_FATAL_FAILURE(leftWindow->consumeMotionDown()); |
| 8023 | mDispatcher->waitForIdle(); |
Prabir Pradhan | 8a5c41d | 2023-06-08 19:13:46 +0000 | [diff] [blame] | 8024 | ASSERT_NO_FATAL_FAILURE( |
| 8025 | mFakePolicy->assertNotifyDeviceInteractionWasCalled(DEVICE_ID, {Uid{101}})); |
Prabir Pradhan | 8ede1d1 | 2023-05-08 19:37:44 +0000 | [diff] [blame] | 8026 | |
| 8027 | // Touch another finger over the right windows |
| 8028 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 8029 | .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) |
| 8030 | .pointer(PointerBuilder(1, ToolType::FINGER).x(150).y(50)) |
| 8031 | .build()); |
| 8032 | ASSERT_NO_FATAL_FAILURE(rightSpy->consumeMotionDown()); |
| 8033 | ASSERT_NO_FATAL_FAILURE(rightWindow->consumeMotionDown()); |
| 8034 | ASSERT_NO_FATAL_FAILURE(leftWindow->consumeMotionMove()); |
| 8035 | mDispatcher->waitForIdle(); |
| 8036 | ASSERT_NO_FATAL_FAILURE( |
Prabir Pradhan | 8a5c41d | 2023-06-08 19:13:46 +0000 | [diff] [blame] | 8037 | mFakePolicy->assertNotifyDeviceInteractionWasCalled(DEVICE_ID, |
| 8038 | {Uid{101}, Uid{102}, Uid{103}})); |
Prabir Pradhan | 8ede1d1 | 2023-05-08 19:37:44 +0000 | [diff] [blame] | 8039 | |
| 8040 | // Release finger over left window. The UP actions are not treated as device interaction. |
| 8041 | // The windows that did not receive the UP pointer will receive MOVE events, but since this |
| 8042 | // is part of the UP action, we do not treat this as device interaction. |
| 8043 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_0_UP, AINPUT_SOURCE_TOUCHSCREEN) |
| 8044 | .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) |
| 8045 | .pointer(PointerBuilder(1, ToolType::FINGER).x(150).y(50)) |
| 8046 | .build()); |
| 8047 | ASSERT_NO_FATAL_FAILURE(leftWindow->consumeMotionUp()); |
| 8048 | ASSERT_NO_FATAL_FAILURE(rightSpy->consumeMotionMove()); |
| 8049 | ASSERT_NO_FATAL_FAILURE(rightWindow->consumeMotionMove()); |
| 8050 | mDispatcher->waitForIdle(); |
| 8051 | ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertNotifyDeviceInteractionWasNotCalled()); |
| 8052 | |
| 8053 | // Move remaining finger |
| 8054 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 8055 | .pointer(PointerBuilder(1, ToolType::FINGER).x(150).y(50)) |
| 8056 | .build()); |
| 8057 | ASSERT_NO_FATAL_FAILURE(rightSpy->consumeMotionMove()); |
| 8058 | ASSERT_NO_FATAL_FAILURE(rightWindow->consumeMotionMove()); |
| 8059 | mDispatcher->waitForIdle(); |
| 8060 | ASSERT_NO_FATAL_FAILURE( |
Prabir Pradhan | 8a5c41d | 2023-06-08 19:13:46 +0000 | [diff] [blame] | 8061 | mFakePolicy->assertNotifyDeviceInteractionWasCalled(DEVICE_ID, {Uid{102}, Uid{103}})); |
Prabir Pradhan | 8ede1d1 | 2023-05-08 19:37:44 +0000 | [diff] [blame] | 8062 | |
| 8063 | // Release all fingers |
| 8064 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN) |
| 8065 | .pointer(PointerBuilder(1, ToolType::FINGER).x(150).y(50)) |
| 8066 | .build()); |
| 8067 | ASSERT_NO_FATAL_FAILURE(rightSpy->consumeMotionUp()); |
| 8068 | ASSERT_NO_FATAL_FAILURE(rightWindow->consumeMotionUp()); |
| 8069 | mDispatcher->waitForIdle(); |
| 8070 | ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertNotifyDeviceInteractionWasNotCalled()); |
| 8071 | } |
| 8072 | |
| 8073 | TEST_F(InputDispatcherTest, NotifiesDeviceInteractionsWithKeys) { |
| 8074 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 8075 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8076 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 8077 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 8ede1d1 | 2023-05-08 19:37:44 +0000 | [diff] [blame] | 8078 | window->setFrame(Rect(0, 0, 100, 100)); |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 8079 | window->setOwnerInfo(gui::Pid{1}, gui::Uid{101}); |
Prabir Pradhan | 8ede1d1 | 2023-05-08 19:37:44 +0000 | [diff] [blame] | 8080 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 8081 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Prabir Pradhan | 8ede1d1 | 2023-05-08 19:37:44 +0000 | [diff] [blame] | 8082 | setFocusedWindow(window); |
| 8083 | ASSERT_NO_FATAL_FAILURE(window->consumeFocusEvent(true)); |
| 8084 | |
| 8085 | mDispatcher->notifyKey(KeyArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_KEYBOARD).build()); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8086 | ASSERT_NO_FATAL_FAILURE(window->consumeKeyDown(ui::LogicalDisplayId::DEFAULT)); |
Prabir Pradhan | 8ede1d1 | 2023-05-08 19:37:44 +0000 | [diff] [blame] | 8087 | mDispatcher->waitForIdle(); |
Prabir Pradhan | 8a5c41d | 2023-06-08 19:13:46 +0000 | [diff] [blame] | 8088 | ASSERT_NO_FATAL_FAILURE( |
| 8089 | mFakePolicy->assertNotifyDeviceInteractionWasCalled(DEVICE_ID, {gui::Uid{101}})); |
Prabir Pradhan | 8ede1d1 | 2023-05-08 19:37:44 +0000 | [diff] [blame] | 8090 | |
| 8091 | // The UP actions are not treated as device interaction. |
| 8092 | mDispatcher->notifyKey(KeyArgsBuilder(ACTION_UP, AINPUT_SOURCE_KEYBOARD).build()); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8093 | ASSERT_NO_FATAL_FAILURE(window->consumeKeyUp(ui::LogicalDisplayId::DEFAULT)); |
Prabir Pradhan | 8ede1d1 | 2023-05-08 19:37:44 +0000 | [diff] [blame] | 8094 | mDispatcher->waitForIdle(); |
| 8095 | ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertNotifyDeviceInteractionWasNotCalled()); |
| 8096 | } |
| 8097 | |
Prabir Pradhan | 5893d36 | 2023-11-17 04:30:40 +0000 | [diff] [blame] | 8098 | TEST_F(InputDispatcherTest, HoverEnterExitSynthesisUsesNewEventId) { |
| 8099 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 8100 | |
| 8101 | sp<FakeWindowHandle> left = sp<FakeWindowHandle>::make(application, mDispatcher, "Left Window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8102 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 5893d36 | 2023-11-17 04:30:40 +0000 | [diff] [blame] | 8103 | left->setFrame(Rect(0, 0, 100, 100)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8104 | sp<FakeWindowHandle> right = |
| 8105 | sp<FakeWindowHandle>::make(application, mDispatcher, "Right Window", |
| 8106 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 5893d36 | 2023-11-17 04:30:40 +0000 | [diff] [blame] | 8107 | right->setFrame(Rect(100, 0, 200, 100)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8108 | sp<FakeWindowHandle> spy = sp<FakeWindowHandle>::make(application, mDispatcher, "Spy Window", |
| 8109 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 5893d36 | 2023-11-17 04:30:40 +0000 | [diff] [blame] | 8110 | spy->setFrame(Rect(0, 0, 200, 100)); |
| 8111 | spy->setTrustedOverlay(true); |
| 8112 | spy->setSpy(true); |
| 8113 | |
| 8114 | mDispatcher->onWindowInfosChanged( |
| 8115 | {{*spy->getInfo(), *left->getInfo(), *right->getInfo()}, {}, 0, 0}); |
| 8116 | |
| 8117 | // Send hover move to the left window, and ensure hover enter is synthesized with a new eventId. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8118 | NotifyMotionArgs notifyArgs = |
| 8119 | generateMotionArgs(ACTION_HOVER_MOVE, AINPUT_SOURCE_STYLUS, |
| 8120 | ui::LogicalDisplayId::DEFAULT, {PointF{50, 50}}); |
Prabir Pradhan | 5893d36 | 2023-11-17 04:30:40 +0000 | [diff] [blame] | 8121 | mDispatcher->notifyMotion(notifyArgs); |
| 8122 | |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 8123 | std::unique_ptr<MotionEvent> leftEnter = left->consumeMotionEvent( |
Prabir Pradhan | 5893d36 | 2023-11-17 04:30:40 +0000 | [diff] [blame] | 8124 | AllOf(WithMotionAction(ACTION_HOVER_ENTER), Not(WithEventId(notifyArgs.id)), |
| 8125 | WithEventIdSource(IdGenerator::Source::INPUT_DISPATCHER))); |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 8126 | ASSERT_NE(nullptr, leftEnter); |
Prabir Pradhan | 5893d36 | 2023-11-17 04:30:40 +0000 | [diff] [blame] | 8127 | spy->consumeMotionEvent(AllOf(WithMotionAction(ACTION_HOVER_ENTER), |
| 8128 | Not(WithEventId(notifyArgs.id)), |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 8129 | Not(WithEventId(leftEnter->getId())), |
Prabir Pradhan | 5893d36 | 2023-11-17 04:30:40 +0000 | [diff] [blame] | 8130 | WithEventIdSource(IdGenerator::Source::INPUT_DISPATCHER))); |
| 8131 | |
| 8132 | // Send move to the right window, and ensure hover exit and enter are synthesized with new ids. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8133 | notifyArgs = generateMotionArgs(ACTION_HOVER_MOVE, AINPUT_SOURCE_STYLUS, |
| 8134 | ui::LogicalDisplayId::DEFAULT, {PointF{150, 50}}); |
Prabir Pradhan | 5893d36 | 2023-11-17 04:30:40 +0000 | [diff] [blame] | 8135 | mDispatcher->notifyMotion(notifyArgs); |
| 8136 | |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 8137 | std::unique_ptr<MotionEvent> leftExit = left->consumeMotionEvent( |
Prabir Pradhan | 5893d36 | 2023-11-17 04:30:40 +0000 | [diff] [blame] | 8138 | AllOf(WithMotionAction(ACTION_HOVER_EXIT), Not(WithEventId(notifyArgs.id)), |
| 8139 | WithEventIdSource(IdGenerator::Source::INPUT_DISPATCHER))); |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 8140 | ASSERT_NE(nullptr, leftExit); |
Prabir Pradhan | 5893d36 | 2023-11-17 04:30:40 +0000 | [diff] [blame] | 8141 | right->consumeMotionEvent(AllOf(WithMotionAction(ACTION_HOVER_ENTER), |
| 8142 | Not(WithEventId(notifyArgs.id)), |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 8143 | Not(WithEventId(leftExit->getId())), |
Prabir Pradhan | 5893d36 | 2023-11-17 04:30:40 +0000 | [diff] [blame] | 8144 | WithEventIdSource(IdGenerator::Source::INPUT_DISPATCHER))); |
| 8145 | |
| 8146 | spy->consumeMotionEvent(AllOf(WithMotionAction(ACTION_HOVER_MOVE), WithEventId(notifyArgs.id))); |
| 8147 | } |
| 8148 | |
Linnan Li | ccf6ce3 | 2024-04-11 20:32:13 +0800 | [diff] [blame] | 8149 | /** |
| 8150 | * When a device reports a DOWN event, which lands in a window that supports splits, and then the |
| 8151 | * device then reports a POINTER_DOWN, which lands in the location of a non-existing window, then |
| 8152 | * the previous window should receive this event and not be dropped. |
| 8153 | */ |
| 8154 | TEST_F(InputDispatcherMultiDeviceTest, SingleDevicePointerDownEventRetentionWithoutWindowTarget) { |
| 8155 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8156 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 8157 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | ccf6ce3 | 2024-04-11 20:32:13 +0800 | [diff] [blame] | 8158 | window->setFrame(Rect(0, 0, 100, 100)); |
| 8159 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
| 8160 | |
| 8161 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 8162 | .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) |
| 8163 | .build()); |
| 8164 | |
| 8165 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN))); |
| 8166 | |
| 8167 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 8168 | .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) |
| 8169 | .pointer(PointerBuilder(1, ToolType::FINGER).x(200).y(200)) |
| 8170 | .build()); |
| 8171 | |
| 8172 | window->consumeMotionEvent(AllOf(WithMotionAction(POINTER_1_DOWN))); |
| 8173 | } |
| 8174 | |
| 8175 | /** |
| 8176 | * When deviceA reports a DOWN event, which lands in a window that supports splits, and then deviceB |
| 8177 | * also reports a DOWN event, which lands in the location of a non-existing window, then the |
| 8178 | * previous window should receive deviceB's event and it should be dropped. |
| 8179 | */ |
| 8180 | TEST_F(InputDispatcherMultiDeviceTest, SecondDeviceDownEventDroppedWithoutWindowTarget) { |
| 8181 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8182 | sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", |
| 8183 | ui::LogicalDisplayId::DEFAULT); |
Linnan Li | ccf6ce3 | 2024-04-11 20:32:13 +0800 | [diff] [blame] | 8184 | window->setFrame(Rect(0, 0, 100, 100)); |
| 8185 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
| 8186 | |
| 8187 | const DeviceId deviceA = 9; |
| 8188 | const DeviceId deviceB = 3; |
| 8189 | |
| 8190 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 8191 | .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) |
| 8192 | .deviceId(deviceA) |
| 8193 | .build()); |
| 8194 | window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(deviceA))); |
| 8195 | |
| 8196 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 8197 | .pointer(PointerBuilder(0, ToolType::FINGER).x(200).y(200)) |
| 8198 | .deviceId(deviceB) |
| 8199 | .build()); |
| 8200 | window->assertNoEvents(); |
| 8201 | } |
| 8202 | |
Prabir Pradhan | b0dad3a | 2023-11-02 20:52:47 +0000 | [diff] [blame] | 8203 | class InputDispatcherFallbackKeyTest : public InputDispatcherTest { |
| 8204 | protected: |
| 8205 | std::shared_ptr<FakeApplicationHandle> mApp; |
| 8206 | sp<FakeWindowHandle> mWindow; |
| 8207 | |
| 8208 | virtual void SetUp() override { |
| 8209 | InputDispatcherTest::SetUp(); |
| 8210 | |
| 8211 | mApp = std::make_shared<FakeApplicationHandle>(); |
| 8212 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8213 | mWindow = sp<FakeWindowHandle>::make(mApp, mDispatcher, "Window", |
| 8214 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | b0dad3a | 2023-11-02 20:52:47 +0000 | [diff] [blame] | 8215 | mWindow->setFrame(Rect(0, 0, 100, 100)); |
| 8216 | |
| 8217 | mDispatcher->onWindowInfosChanged({{*mWindow->getInfo()}, {}, 0, 0}); |
| 8218 | setFocusedWindow(mWindow); |
| 8219 | ASSERT_NO_FATAL_FAILURE(mWindow->consumeFocusEvent(/*hasFocus=*/true)); |
| 8220 | } |
| 8221 | |
| 8222 | void setFallback(int32_t keycode) { |
| 8223 | mFakePolicy->setUnhandledKeyHandler([keycode](const KeyEvent& event) { |
| 8224 | return KeyEventBuilder(event).keyCode(keycode).build(); |
| 8225 | }); |
| 8226 | } |
| 8227 | |
| 8228 | void consumeKey(bool handled, const ::testing::Matcher<KeyEvent>& matcher) { |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 8229 | std::unique_ptr<KeyEvent> event = mWindow->consumeKey(handled); |
| 8230 | ASSERT_NE(nullptr, event); |
| 8231 | ASSERT_THAT(*event, matcher); |
Prabir Pradhan | b0dad3a | 2023-11-02 20:52:47 +0000 | [diff] [blame] | 8232 | } |
| 8233 | }; |
| 8234 | |
| 8235 | TEST_F(InputDispatcherFallbackKeyTest, PolicyNotNotifiedForHandledKey) { |
| 8236 | mDispatcher->notifyKey( |
| 8237 | KeyArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_KEYBOARD).keyCode(AKEYCODE_A).build()); |
| 8238 | consumeKey(/*handled=*/true, AllOf(WithKeyAction(ACTION_DOWN), WithKeyCode(AKEYCODE_A))); |
| 8239 | ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertUnhandledKeyNotReported()); |
| 8240 | } |
| 8241 | |
| 8242 | TEST_F(InputDispatcherFallbackKeyTest, PolicyNotifiedForUnhandledKey) { |
| 8243 | mDispatcher->notifyKey( |
| 8244 | KeyArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_KEYBOARD).keyCode(AKEYCODE_A).build()); |
| 8245 | consumeKey(/*handled=*/false, AllOf(WithKeyAction(ACTION_DOWN), WithKeyCode(AKEYCODE_A))); |
| 8246 | ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertUnhandledKeyReported(AKEYCODE_A)); |
| 8247 | } |
| 8248 | |
| 8249 | TEST_F(InputDispatcherFallbackKeyTest, NoFallbackRequestedByPolicy) { |
| 8250 | mDispatcher->notifyKey( |
| 8251 | KeyArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_KEYBOARD).keyCode(AKEYCODE_A).build()); |
| 8252 | |
| 8253 | // Do not handle this key event. |
| 8254 | consumeKey(/*handled=*/false, |
| 8255 | AllOf(WithKeyAction(ACTION_DOWN), WithKeyCode(AKEYCODE_A), WithFlags(0))); |
| 8256 | ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertUnhandledKeyReported(AKEYCODE_A)); |
| 8257 | |
| 8258 | // Since the policy did not request any fallback to be generated, ensure there are no events. |
| 8259 | ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertUnhandledKeyNotReported()); |
| 8260 | } |
| 8261 | |
| 8262 | TEST_F(InputDispatcherFallbackKeyTest, FallbackDispatchForUnhandledKey) { |
| 8263 | setFallback(AKEYCODE_B); |
| 8264 | mDispatcher->notifyKey( |
| 8265 | KeyArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_KEYBOARD).keyCode(AKEYCODE_A).build()); |
| 8266 | |
| 8267 | // Do not handle this key event. |
| 8268 | consumeKey(/*handled=*/false, |
| 8269 | AllOf(WithKeyAction(ACTION_DOWN), WithKeyCode(AKEYCODE_A), WithFlags(0))); |
| 8270 | |
| 8271 | // Since the key was not handled, ensure the fallback event was dispatched instead. |
| 8272 | ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertUnhandledKeyReported(AKEYCODE_A)); |
| 8273 | consumeKey(/*handled=*/true, |
| 8274 | AllOf(WithKeyAction(ACTION_DOWN), WithKeyCode(AKEYCODE_B), |
| 8275 | WithFlags(AKEY_EVENT_FLAG_FALLBACK))); |
| 8276 | |
| 8277 | // Release the original key, and ensure the fallback key is also released. |
| 8278 | mDispatcher->notifyKey( |
| 8279 | KeyArgsBuilder(ACTION_UP, AINPUT_SOURCE_KEYBOARD).keyCode(AKEYCODE_A).build()); |
| 8280 | consumeKey(/*handled=*/false, |
| 8281 | AllOf(WithKeyAction(ACTION_UP), WithKeyCode(AKEYCODE_A), WithFlags(0))); |
| 8282 | ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertUnhandledKeyReported(AKEYCODE_A)); |
| 8283 | consumeKey(/*handled=*/true, |
| 8284 | AllOf(WithKeyAction(ACTION_UP), WithKeyCode(AKEYCODE_B), |
| 8285 | WithFlags(AKEY_EVENT_FLAG_FALLBACK))); |
| 8286 | |
| 8287 | ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertUnhandledKeyNotReported()); |
| 8288 | mWindow->assertNoEvents(); |
| 8289 | } |
| 8290 | |
| 8291 | TEST_F(InputDispatcherFallbackKeyTest, AppHandlesPreviouslyUnhandledKey) { |
| 8292 | setFallback(AKEYCODE_B); |
| 8293 | mDispatcher->notifyKey( |
| 8294 | KeyArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_KEYBOARD).keyCode(AKEYCODE_A).build()); |
| 8295 | |
| 8296 | // Do not handle this key event, but handle the fallback. |
| 8297 | consumeKey(/*handled=*/false, |
| 8298 | AllOf(WithKeyAction(ACTION_DOWN), WithKeyCode(AKEYCODE_A), WithFlags(0))); |
| 8299 | ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertUnhandledKeyReported(AKEYCODE_A)); |
| 8300 | consumeKey(/*handled=*/true, |
| 8301 | AllOf(WithKeyAction(ACTION_DOWN), WithKeyCode(AKEYCODE_B), |
| 8302 | WithFlags(AKEY_EVENT_FLAG_FALLBACK))); |
| 8303 | |
| 8304 | // Release the original key, and ensure the fallback key is also released. |
| 8305 | mDispatcher->notifyKey( |
| 8306 | KeyArgsBuilder(ACTION_UP, AINPUT_SOURCE_KEYBOARD).keyCode(AKEYCODE_A).build()); |
| 8307 | // But this time, the app handles the original key. |
| 8308 | consumeKey(/*handled=*/true, |
| 8309 | AllOf(WithKeyAction(ACTION_UP), WithKeyCode(AKEYCODE_A), WithFlags(0))); |
| 8310 | ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertUnhandledKeyReported(AKEYCODE_A)); |
| 8311 | // Ensure the fallback key is canceled. |
| 8312 | consumeKey(/*handled=*/true, |
| 8313 | AllOf(WithKeyAction(ACTION_UP), WithKeyCode(AKEYCODE_B), |
| 8314 | WithFlags(AKEY_EVENT_FLAG_FALLBACK | AKEY_EVENT_FLAG_CANCELED))); |
| 8315 | |
| 8316 | ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertUnhandledKeyNotReported()); |
| 8317 | mWindow->assertNoEvents(); |
| 8318 | } |
| 8319 | |
| 8320 | TEST_F(InputDispatcherFallbackKeyTest, AppDoesNotHandleFallback) { |
| 8321 | setFallback(AKEYCODE_B); |
| 8322 | mDispatcher->notifyKey( |
| 8323 | KeyArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_KEYBOARD).keyCode(AKEYCODE_A).build()); |
| 8324 | |
| 8325 | // Do not handle this key event. |
| 8326 | consumeKey(/*handled=*/false, |
| 8327 | AllOf(WithKeyAction(ACTION_DOWN), WithKeyCode(AKEYCODE_A), WithFlags(0))); |
| 8328 | ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertUnhandledKeyReported(AKEYCODE_A)); |
| 8329 | // App does not handle the fallback either, so ensure another fallback is not generated. |
| 8330 | setFallback(AKEYCODE_C); |
| 8331 | consumeKey(/*handled=*/false, |
| 8332 | AllOf(WithKeyAction(ACTION_DOWN), WithKeyCode(AKEYCODE_B), |
| 8333 | WithFlags(AKEY_EVENT_FLAG_FALLBACK))); |
| 8334 | |
| 8335 | // Release the original key, and ensure the fallback key is also released. |
| 8336 | setFallback(AKEYCODE_B); |
| 8337 | mDispatcher->notifyKey( |
| 8338 | KeyArgsBuilder(ACTION_UP, AINPUT_SOURCE_KEYBOARD).keyCode(AKEYCODE_A).build()); |
| 8339 | consumeKey(/*handled=*/false, |
| 8340 | AllOf(WithKeyAction(ACTION_UP), WithKeyCode(AKEYCODE_A), WithFlags(0))); |
| 8341 | ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertUnhandledKeyReported(AKEYCODE_A)); |
| 8342 | consumeKey(/*handled=*/false, |
| 8343 | AllOf(WithKeyAction(ACTION_UP), WithKeyCode(AKEYCODE_B), |
| 8344 | WithFlags(AKEY_EVENT_FLAG_FALLBACK))); |
| 8345 | |
| 8346 | ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertUnhandledKeyNotReported()); |
| 8347 | mWindow->assertNoEvents(); |
| 8348 | } |
| 8349 | |
| 8350 | TEST_F(InputDispatcherFallbackKeyTest, InconsistentPolicyCancelsFallback) { |
| 8351 | setFallback(AKEYCODE_B); |
| 8352 | mDispatcher->notifyKey( |
| 8353 | KeyArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_KEYBOARD).keyCode(AKEYCODE_A).build()); |
| 8354 | |
| 8355 | // Do not handle this key event, so fallback is generated. |
| 8356 | consumeKey(/*handled=*/false, |
| 8357 | AllOf(WithKeyAction(ACTION_DOWN), WithKeyCode(AKEYCODE_A), WithFlags(0))); |
| 8358 | ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertUnhandledKeyReported(AKEYCODE_A)); |
| 8359 | consumeKey(/*handled=*/true, |
| 8360 | AllOf(WithKeyAction(ACTION_DOWN), WithKeyCode(AKEYCODE_B), |
| 8361 | WithFlags(AKEY_EVENT_FLAG_FALLBACK))); |
| 8362 | |
| 8363 | // Release the original key, but assume the policy is misbehaving and it |
| 8364 | // generates an inconsistent fallback to the one from the DOWN event. |
| 8365 | setFallback(AKEYCODE_C); |
| 8366 | mDispatcher->notifyKey( |
| 8367 | KeyArgsBuilder(ACTION_UP, AINPUT_SOURCE_KEYBOARD).keyCode(AKEYCODE_A).build()); |
| 8368 | consumeKey(/*handled=*/false, |
| 8369 | AllOf(WithKeyAction(ACTION_UP), WithKeyCode(AKEYCODE_A), WithFlags(0))); |
| 8370 | ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertUnhandledKeyReported(AKEYCODE_A)); |
| 8371 | // Ensure the fallback key reported before as DOWN is canceled due to the inconsistency. |
| 8372 | consumeKey(/*handled=*/true, |
| 8373 | AllOf(WithKeyAction(ACTION_UP), WithKeyCode(AKEYCODE_B), |
| 8374 | WithFlags(AKEY_EVENT_FLAG_FALLBACK | AKEY_EVENT_FLAG_CANCELED))); |
| 8375 | |
| 8376 | ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertUnhandledKeyNotReported()); |
| 8377 | mWindow->assertNoEvents(); |
| 8378 | } |
| 8379 | |
| 8380 | TEST_F(InputDispatcherFallbackKeyTest, CanceledKeyCancelsFallback) { |
| 8381 | setFallback(AKEYCODE_B); |
| 8382 | mDispatcher->notifyKey( |
| 8383 | KeyArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_KEYBOARD).keyCode(AKEYCODE_A).build()); |
| 8384 | |
| 8385 | // Do not handle this key event, so fallback is generated. |
| 8386 | consumeKey(/*handled=*/false, |
| 8387 | AllOf(WithKeyAction(ACTION_DOWN), WithKeyCode(AKEYCODE_A), WithFlags(0))); |
| 8388 | ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertUnhandledKeyReported(AKEYCODE_A)); |
| 8389 | consumeKey(/*handled=*/true, |
| 8390 | AllOf(WithKeyAction(ACTION_DOWN), WithKeyCode(AKEYCODE_B), |
| 8391 | WithFlags(AKEY_EVENT_FLAG_FALLBACK))); |
| 8392 | |
| 8393 | // The original key is canceled. |
| 8394 | mDispatcher->notifyKey(KeyArgsBuilder(ACTION_UP, AINPUT_SOURCE_KEYBOARD) |
| 8395 | .keyCode(AKEYCODE_A) |
| 8396 | .addFlag(AKEY_EVENT_FLAG_CANCELED) |
| 8397 | .build()); |
| 8398 | consumeKey(/*handled=*/false, |
| 8399 | AllOf(WithKeyAction(ACTION_UP), WithKeyCode(AKEYCODE_A), |
| 8400 | WithFlags(AKEY_EVENT_FLAG_CANCELED))); |
| 8401 | ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertUnhandledKeyReported(AKEYCODE_A)); |
| 8402 | // Ensure the fallback key is also canceled due to the original key being canceled. |
| 8403 | consumeKey(/*handled=*/true, |
| 8404 | AllOf(WithKeyAction(ACTION_UP), WithKeyCode(AKEYCODE_B), |
| 8405 | WithFlags(AKEY_EVENT_FLAG_FALLBACK | AKEY_EVENT_FLAG_CANCELED))); |
| 8406 | |
| 8407 | ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertUnhandledKeyNotReported()); |
| 8408 | mWindow->assertNoEvents(); |
| 8409 | } |
| 8410 | |
Prabir Pradhan | fa2c69f | 2024-02-01 20:31:34 +0000 | [diff] [blame] | 8411 | TEST_F(InputDispatcherFallbackKeyTest, InputChannelRemovedDuringPolicyCall) { |
Prabir Pradhan | b13da8f | 2024-01-09 23:10:13 +0000 | [diff] [blame] | 8412 | setFallback(AKEYCODE_B); |
| 8413 | mDispatcher->notifyKey( |
| 8414 | KeyArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_KEYBOARD).keyCode(AKEYCODE_A).build()); |
| 8415 | |
| 8416 | // Do not handle this key event. |
| 8417 | consumeKey(/*handled=*/false, |
| 8418 | AllOf(WithKeyAction(ACTION_DOWN), WithKeyCode(AKEYCODE_A), WithFlags(0))); |
| 8419 | ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertUnhandledKeyReported(AKEYCODE_A)); |
| 8420 | consumeKey(/*handled=*/true, |
| 8421 | AllOf(WithKeyAction(ACTION_DOWN), WithKeyCode(AKEYCODE_B), |
| 8422 | WithFlags(AKEY_EVENT_FLAG_FALLBACK))); |
| 8423 | |
| 8424 | mFakePolicy->setUnhandledKeyHandler([&](const KeyEvent& event) { |
| 8425 | // When the unhandled key is reported to the policy next, remove the input channel. |
| 8426 | mDispatcher->removeInputChannel(mWindow->getToken()); |
| 8427 | return KeyEventBuilder(event).keyCode(AKEYCODE_B).build(); |
| 8428 | }); |
| 8429 | // Release the original key, and let the app now handle the previously unhandled key. |
| 8430 | // This should result in the previously generated fallback key to be cancelled. |
| 8431 | // Since the policy was notified of the unhandled DOWN event earlier, it will also be notified |
| 8432 | // of the UP event for consistency. The Dispatcher calls into the policy from its own thread |
| 8433 | // without holding the lock, because it need to synchronously fetch the fallback key. While in |
| 8434 | // the policy call, we will now remove the input channel. Once the policy call returns, the |
| 8435 | // Dispatcher will no longer have a channel to send cancellation events to. Ensure this does |
| 8436 | // not cause any crashes. |
| 8437 | mDispatcher->notifyKey( |
| 8438 | KeyArgsBuilder(ACTION_UP, AINPUT_SOURCE_KEYBOARD).keyCode(AKEYCODE_A).build()); |
| 8439 | consumeKey(/*handled=*/true, |
| 8440 | AllOf(WithKeyAction(ACTION_UP), WithKeyCode(AKEYCODE_A), WithFlags(0))); |
| 8441 | ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertUnhandledKeyReported(AKEYCODE_A)); |
| 8442 | } |
| 8443 | |
Prabir Pradhan | fa2c69f | 2024-02-01 20:31:34 +0000 | [diff] [blame] | 8444 | TEST_F(InputDispatcherFallbackKeyTest, WindowRemovedDuringPolicyCall) { |
| 8445 | setFallback(AKEYCODE_B); |
| 8446 | mDispatcher->notifyKey( |
| 8447 | KeyArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_KEYBOARD).keyCode(AKEYCODE_A).build()); |
| 8448 | |
| 8449 | // Do not handle this key event. |
| 8450 | consumeKey(/*handled=*/false, |
| 8451 | AllOf(WithKeyAction(ACTION_DOWN), WithKeyCode(AKEYCODE_A), WithFlags(0))); |
| 8452 | ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertUnhandledKeyReported(AKEYCODE_A)); |
| 8453 | consumeKey(/*handled=*/true, |
| 8454 | AllOf(WithKeyAction(ACTION_DOWN), WithKeyCode(AKEYCODE_B), |
| 8455 | WithFlags(AKEY_EVENT_FLAG_FALLBACK))); |
| 8456 | |
| 8457 | mFakePolicy->setUnhandledKeyHandler([&](const KeyEvent& event) { |
| 8458 | // When the unhandled key is reported to the policy next, remove the window. |
| 8459 | mDispatcher->onWindowInfosChanged({{}, {}, 0, 0}); |
| 8460 | return KeyEventBuilder(event).keyCode(AKEYCODE_B).build(); |
| 8461 | }); |
| 8462 | // Release the original key, which the app will not handle. When this unhandled key is reported |
| 8463 | // to the policy, the window will be removed. |
| 8464 | mDispatcher->notifyKey( |
| 8465 | KeyArgsBuilder(ACTION_UP, AINPUT_SOURCE_KEYBOARD).keyCode(AKEYCODE_A).build()); |
| 8466 | consumeKey(/*handled=*/false, |
| 8467 | AllOf(WithKeyAction(ACTION_UP), WithKeyCode(AKEYCODE_A), WithFlags(0))); |
| 8468 | ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertUnhandledKeyReported(AKEYCODE_A)); |
| 8469 | |
| 8470 | // Since the window was removed, it loses focus, and the channel state will be reset. |
| 8471 | consumeKey(/*handled=*/true, |
| 8472 | AllOf(WithKeyAction(ACTION_UP), WithKeyCode(AKEYCODE_B), |
| 8473 | WithFlags(AKEY_EVENT_FLAG_FALLBACK | AKEY_EVENT_FLAG_CANCELED))); |
| 8474 | mWindow->consumeFocusEvent(false); |
| 8475 | mWindow->assertNoEvents(); |
| 8476 | } |
| 8477 | |
| 8478 | TEST_F(InputDispatcherFallbackKeyTest, WindowRemovedWhileAwaitingFinishedSignal) { |
| 8479 | setFallback(AKEYCODE_B); |
| 8480 | mDispatcher->notifyKey( |
| 8481 | KeyArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_KEYBOARD).keyCode(AKEYCODE_A).build()); |
| 8482 | |
| 8483 | // Do not handle this key event. |
| 8484 | consumeKey(/*handled=*/false, |
| 8485 | AllOf(WithKeyAction(ACTION_DOWN), WithKeyCode(AKEYCODE_A), WithFlags(0))); |
| 8486 | ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertUnhandledKeyReported(AKEYCODE_A)); |
| 8487 | const auto [seq, event] = mWindow->receiveEvent(); |
| 8488 | ASSERT_TRUE(seq.has_value() && event != nullptr) << "Failed to receive fallback event"; |
| 8489 | ASSERT_EQ(event->getType(), InputEventType::KEY); |
| 8490 | ASSERT_THAT(static_cast<const KeyEvent&>(*event), |
| 8491 | AllOf(WithKeyAction(ACTION_DOWN), WithKeyCode(AKEYCODE_B), |
| 8492 | WithFlags(AKEY_EVENT_FLAG_FALLBACK))); |
| 8493 | |
| 8494 | // Remove the window now, which should generate a cancellations and make the window lose focus. |
| 8495 | mDispatcher->onWindowInfosChanged({{}, {}, 0, 0}); |
| 8496 | consumeKey(/*handled=*/true, |
| 8497 | AllOf(WithKeyAction(ACTION_UP), WithKeyCode(AKEYCODE_A), |
| 8498 | WithFlags(AKEY_EVENT_FLAG_CANCELED))); |
| 8499 | consumeKey(/*handled=*/true, |
| 8500 | AllOf(WithKeyAction(ACTION_UP), WithKeyCode(AKEYCODE_B), |
| 8501 | WithFlags(AKEY_EVENT_FLAG_FALLBACK | AKEY_EVENT_FLAG_CANCELED))); |
| 8502 | mWindow->consumeFocusEvent(false); |
| 8503 | |
| 8504 | // Finish the event by reporting it as handled. |
| 8505 | mWindow->finishEvent(*seq); |
| 8506 | mWindow->assertNoEvents(); |
| 8507 | } |
| 8508 | |
Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 8509 | class InputDispatcherKeyRepeatTest : public InputDispatcherTest { |
| 8510 | protected: |
Siarhei Vishniakou | fa2a049 | 2023-11-14 13:13:18 -0800 | [diff] [blame] | 8511 | static constexpr std::chrono::nanoseconds KEY_REPEAT_TIMEOUT = 40ms; |
| 8512 | static constexpr std::chrono::nanoseconds KEY_REPEAT_DELAY = 40ms; |
Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 8513 | |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 8514 | std::shared_ptr<FakeApplicationHandle> mApp; |
Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 8515 | sp<FakeWindowHandle> mWindow; |
| 8516 | |
| 8517 | virtual void SetUp() override { |
Prabir Pradhan | dae5279 | 2023-12-15 07:36:40 +0000 | [diff] [blame] | 8518 | InputDispatcherTest::SetUp(); |
Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 8519 | |
Prabir Pradhan | dae5279 | 2023-12-15 07:36:40 +0000 | [diff] [blame] | 8520 | mDispatcher->setKeyRepeatConfiguration(KEY_REPEAT_TIMEOUT, KEY_REPEAT_DELAY); |
Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 8521 | setUpWindow(); |
| 8522 | } |
| 8523 | |
| 8524 | void setUpWindow() { |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 8525 | mApp = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8526 | mWindow = sp<FakeWindowHandle>::make(mApp, mDispatcher, "Fake Window", |
| 8527 | ui::LogicalDisplayId::DEFAULT); |
Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 8528 | |
Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 8529 | mWindow->setFocusable(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 8530 | mDispatcher->onWindowInfosChanged({{*mWindow->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 8531 | setFocusedWindow(mWindow); |
Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 8532 | mWindow->consumeFocusEvent(true); |
| 8533 | } |
| 8534 | |
Chris Ye | 2ad9539 | 2020-09-01 13:44:44 -0700 | [diff] [blame] | 8535 | void sendAndConsumeKeyDown(int32_t deviceId) { |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8536 | NotifyKeyArgs keyArgs = |
| 8537 | generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ui::LogicalDisplayId::DEFAULT); |
Chris Ye | 2ad9539 | 2020-09-01 13:44:44 -0700 | [diff] [blame] | 8538 | keyArgs.deviceId = deviceId; |
Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 8539 | keyArgs.policyFlags |= POLICY_FLAG_TRUSTED; // Otherwise it won't generate repeat event |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 8540 | mDispatcher->notifyKey(keyArgs); |
Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 8541 | |
| 8542 | // Window should receive key down event. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8543 | mWindow->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); |
Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 8544 | } |
| 8545 | |
| 8546 | void expectKeyRepeatOnce(int32_t repeatCount) { |
| 8547 | SCOPED_TRACE(StringPrintf("Checking event with repeat count %" PRId32, repeatCount)); |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 8548 | mWindow->consumeKeyEvent( |
| 8549 | AllOf(WithKeyAction(AKEY_EVENT_ACTION_DOWN), WithRepeatCount(repeatCount))); |
Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 8550 | } |
| 8551 | |
Chris Ye | 2ad9539 | 2020-09-01 13:44:44 -0700 | [diff] [blame] | 8552 | void sendAndConsumeKeyUp(int32_t deviceId) { |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8553 | NotifyKeyArgs keyArgs = |
| 8554 | generateKeyArgs(AKEY_EVENT_ACTION_UP, ui::LogicalDisplayId::DEFAULT); |
Chris Ye | 2ad9539 | 2020-09-01 13:44:44 -0700 | [diff] [blame] | 8555 | keyArgs.deviceId = deviceId; |
Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 8556 | keyArgs.policyFlags |= POLICY_FLAG_TRUSTED; // Unless it won't generate repeat event |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 8557 | mDispatcher->notifyKey(keyArgs); |
Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 8558 | |
| 8559 | // Window should receive key down event. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8560 | mWindow->consumeKeyUp(ui::LogicalDisplayId::DEFAULT, |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 8561 | /*expectedFlags=*/0); |
Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 8562 | } |
Hu Guo | fe3c8f1 | 2023-09-22 17:20:15 +0800 | [diff] [blame] | 8563 | |
| 8564 | void injectKeyRepeat(int32_t repeatCount) { |
| 8565 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8566 | injectKey(*mDispatcher, AKEY_EVENT_ACTION_DOWN, repeatCount, |
| 8567 | ui::LogicalDisplayId::DEFAULT)) |
Hu Guo | fe3c8f1 | 2023-09-22 17:20:15 +0800 | [diff] [blame] | 8568 | << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; |
| 8569 | } |
Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 8570 | }; |
| 8571 | |
| 8572 | TEST_F(InputDispatcherKeyRepeatTest, FocusedWindow_ReceivesKeyRepeat) { |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 8573 | sendAndConsumeKeyDown(/*deviceId=*/1); |
Chris Ye | 2ad9539 | 2020-09-01 13:44:44 -0700 | [diff] [blame] | 8574 | for (int32_t repeatCount = 1; repeatCount <= 10; ++repeatCount) { |
| 8575 | expectKeyRepeatOnce(repeatCount); |
| 8576 | } |
| 8577 | } |
| 8578 | |
| 8579 | TEST_F(InputDispatcherKeyRepeatTest, FocusedWindow_ReceivesKeyRepeatFromTwoDevices) { |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 8580 | sendAndConsumeKeyDown(/*deviceId=*/1); |
Chris Ye | 2ad9539 | 2020-09-01 13:44:44 -0700 | [diff] [blame] | 8581 | for (int32_t repeatCount = 1; repeatCount <= 10; ++repeatCount) { |
| 8582 | expectKeyRepeatOnce(repeatCount); |
| 8583 | } |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 8584 | sendAndConsumeKeyDown(/*deviceId=*/2); |
Chris Ye | 2ad9539 | 2020-09-01 13:44:44 -0700 | [diff] [blame] | 8585 | /* repeatCount will start from 1 for deviceId 2 */ |
Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 8586 | for (int32_t repeatCount = 1; repeatCount <= 10; ++repeatCount) { |
| 8587 | expectKeyRepeatOnce(repeatCount); |
| 8588 | } |
| 8589 | } |
| 8590 | |
| 8591 | TEST_F(InputDispatcherKeyRepeatTest, FocusedWindow_StopsKeyRepeatAfterUp) { |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 8592 | sendAndConsumeKeyDown(/*deviceId=*/1); |
| 8593 | expectKeyRepeatOnce(/*repeatCount=*/1); |
| 8594 | sendAndConsumeKeyUp(/*deviceId=*/1); |
Chris Ye | 2ad9539 | 2020-09-01 13:44:44 -0700 | [diff] [blame] | 8595 | mWindow->assertNoEvents(); |
| 8596 | } |
| 8597 | |
| 8598 | TEST_F(InputDispatcherKeyRepeatTest, FocusedWindow_KeyRepeatAfterStaleDeviceKeyUp) { |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 8599 | sendAndConsumeKeyDown(/*deviceId=*/1); |
| 8600 | expectKeyRepeatOnce(/*repeatCount=*/1); |
| 8601 | sendAndConsumeKeyDown(/*deviceId=*/2); |
| 8602 | expectKeyRepeatOnce(/*repeatCount=*/1); |
Chris Ye | 2ad9539 | 2020-09-01 13:44:44 -0700 | [diff] [blame] | 8603 | // Stale key up from device 1. |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 8604 | sendAndConsumeKeyUp(/*deviceId=*/1); |
Chris Ye | 2ad9539 | 2020-09-01 13:44:44 -0700 | [diff] [blame] | 8605 | // Device 2 is still down, keep repeating |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 8606 | expectKeyRepeatOnce(/*repeatCount=*/2); |
| 8607 | expectKeyRepeatOnce(/*repeatCount=*/3); |
Chris Ye | 2ad9539 | 2020-09-01 13:44:44 -0700 | [diff] [blame] | 8608 | // Device 2 key up |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 8609 | sendAndConsumeKeyUp(/*deviceId=*/2); |
Chris Ye | 2ad9539 | 2020-09-01 13:44:44 -0700 | [diff] [blame] | 8610 | mWindow->assertNoEvents(); |
| 8611 | } |
| 8612 | |
| 8613 | TEST_F(InputDispatcherKeyRepeatTest, FocusedWindow_KeyRepeatStopsAfterRepeatingKeyUp) { |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 8614 | sendAndConsumeKeyDown(/*deviceId=*/1); |
| 8615 | expectKeyRepeatOnce(/*repeatCount=*/1); |
| 8616 | sendAndConsumeKeyDown(/*deviceId=*/2); |
| 8617 | expectKeyRepeatOnce(/*repeatCount=*/1); |
Chris Ye | 2ad9539 | 2020-09-01 13:44:44 -0700 | [diff] [blame] | 8618 | // Device 2 which holds the key repeating goes up, expect the repeating to stop. |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 8619 | sendAndConsumeKeyUp(/*deviceId=*/2); |
Chris Ye | 2ad9539 | 2020-09-01 13:44:44 -0700 | [diff] [blame] | 8620 | // Device 1 still holds key down, but the repeating was already stopped |
Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 8621 | mWindow->assertNoEvents(); |
| 8622 | } |
| 8623 | |
liushenxiang | 4223291 | 2021-05-21 20:24:09 +0800 | [diff] [blame] | 8624 | TEST_F(InputDispatcherKeyRepeatTest, FocusedWindow_StopsKeyRepeatAfterDisableInputDevice) { |
| 8625 | sendAndConsumeKeyDown(DEVICE_ID); |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 8626 | expectKeyRepeatOnce(/*repeatCount=*/1); |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 8627 | mDispatcher->notifyDeviceReset({/*id=*/10, /*eventTime=*/20, DEVICE_ID}); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8628 | mWindow->consumeKeyUp(ui::LogicalDisplayId::DEFAULT, |
liushenxiang | 4223291 | 2021-05-21 20:24:09 +0800 | [diff] [blame] | 8629 | AKEY_EVENT_FLAG_CANCELED | AKEY_EVENT_FLAG_LONG_PRESS); |
| 8630 | mWindow->assertNoEvents(); |
| 8631 | } |
| 8632 | |
Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 8633 | TEST_F(InputDispatcherKeyRepeatTest, FocusedWindow_RepeatKeyEventsUseEventIdFromInputDispatcher) { |
Michael Wright | e1cbbd6 | 2023-02-22 19:32:13 +0000 | [diff] [blame] | 8634 | GTEST_SKIP() << "Flaky test (b/270393106)"; |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 8635 | sendAndConsumeKeyDown(/*deviceId=*/1); |
Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 8636 | for (int32_t repeatCount = 1; repeatCount <= 10; ++repeatCount) { |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 8637 | std::unique_ptr<KeyEvent> repeatEvent = mWindow->consumeKey(); |
| 8638 | ASSERT_NE(nullptr, repeatEvent); |
Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 8639 | EXPECT_EQ(IdGenerator::Source::INPUT_DISPATCHER, |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 8640 | IdGenerator::getSource(repeatEvent->getId())); |
Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 8641 | } |
| 8642 | } |
| 8643 | |
| 8644 | TEST_F(InputDispatcherKeyRepeatTest, FocusedWindow_RepeatKeyEventsUseUniqueEventId) { |
Michael Wright | e1cbbd6 | 2023-02-22 19:32:13 +0000 | [diff] [blame] | 8645 | GTEST_SKIP() << "Flaky test (b/270393106)"; |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 8646 | sendAndConsumeKeyDown(/*deviceId=*/1); |
Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 8647 | |
| 8648 | std::unordered_set<int32_t> idSet; |
| 8649 | for (int32_t repeatCount = 1; repeatCount <= 10; ++repeatCount) { |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 8650 | std::unique_ptr<KeyEvent> repeatEvent = mWindow->consumeKey(); |
| 8651 | ASSERT_NE(nullptr, repeatEvent); |
| 8652 | int32_t id = repeatEvent->getId(); |
Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 8653 | EXPECT_EQ(idSet.end(), idSet.find(id)); |
| 8654 | idSet.insert(id); |
| 8655 | } |
| 8656 | } |
| 8657 | |
Hu Guo | fe3c8f1 | 2023-09-22 17:20:15 +0800 | [diff] [blame] | 8658 | TEST_F(InputDispatcherKeyRepeatTest, FocusedWindow_CorrectRepeatCountWhenInjectKeyRepeat) { |
| 8659 | injectKeyRepeat(0); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8660 | mWindow->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); |
Hu Guo | fe3c8f1 | 2023-09-22 17:20:15 +0800 | [diff] [blame] | 8661 | for (int32_t repeatCount = 1; repeatCount <= 2; ++repeatCount) { |
| 8662 | expectKeyRepeatOnce(repeatCount); |
| 8663 | } |
| 8664 | injectKeyRepeat(1); |
| 8665 | // Expect repeatCount to be 3 instead of 1 |
| 8666 | expectKeyRepeatOnce(3); |
| 8667 | } |
| 8668 | |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 8669 | /* Test InputDispatcher for MultiDisplay */ |
| 8670 | class InputDispatcherFocusOnTwoDisplaysTest : public InputDispatcherTest { |
| 8671 | public: |
Prabir Pradhan | 3608aad | 2019-10-02 17:08:26 -0700 | [diff] [blame] | 8672 | virtual void SetUp() override { |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 8673 | InputDispatcherTest::SetUp(); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 8674 | |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 8675 | application1 = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8676 | windowInPrimary = sp<FakeWindowHandle>::make(application1, mDispatcher, "D_1", |
| 8677 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | b9b1535 | 2019-11-26 13:19:26 -0800 | [diff] [blame] | 8678 | |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 8679 | // Set focus window for primary display, but focused display would be second one. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8680 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application1); |
Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 8681 | windowInPrimary->setFocusable(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 8682 | mDispatcher->onWindowInfosChanged({{*windowInPrimary->getInfo()}, {}, 0, 0}); |
| 8683 | |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 8684 | setFocusedWindow(windowInPrimary); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 8685 | windowInPrimary->consumeFocusEvent(true); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 8686 | |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 8687 | application2 = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | 870ecec | 2020-12-09 08:07:46 -1000 | [diff] [blame] | 8688 | windowInSecondary = |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 8689 | sp<FakeWindowHandle>::make(application2, mDispatcher, "D_2", SECOND_DISPLAY_ID); |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 8690 | // Set focus to second display window. |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 8691 | // Set focus display to second one. |
| 8692 | mDispatcher->setFocusedDisplay(SECOND_DISPLAY_ID); |
Arpit Singh | b65e2bd | 2024-06-03 09:48:16 +0000 | [diff] [blame] | 8693 | mFakePolicy->assertFocusedDisplayNotified(SECOND_DISPLAY_ID); |
| 8694 | |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 8695 | // Set focus window for second display. |
| 8696 | mDispatcher->setFocusedApplication(SECOND_DISPLAY_ID, application2); |
Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 8697 | windowInSecondary->setFocusable(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 8698 | mDispatcher->onWindowInfosChanged( |
| 8699 | {{*windowInPrimary->getInfo(), *windowInSecondary->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 8700 | setFocusedWindow(windowInSecondary); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 8701 | windowInSecondary->consumeFocusEvent(true); |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 8702 | } |
| 8703 | |
Prabir Pradhan | 3608aad | 2019-10-02 17:08:26 -0700 | [diff] [blame] | 8704 | virtual void TearDown() override { |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 8705 | InputDispatcherTest::TearDown(); |
| 8706 | |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 8707 | application1.reset(); |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 8708 | windowInPrimary.clear(); |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 8709 | application2.reset(); |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 8710 | windowInSecondary.clear(); |
| 8711 | } |
| 8712 | |
| 8713 | protected: |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 8714 | std::shared_ptr<FakeApplicationHandle> application1; |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 8715 | sp<FakeWindowHandle> windowInPrimary; |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 8716 | std::shared_ptr<FakeApplicationHandle> application2; |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 8717 | sp<FakeWindowHandle> windowInSecondary; |
| 8718 | }; |
| 8719 | |
| 8720 | TEST_F(InputDispatcherFocusOnTwoDisplaysTest, SetInputWindow_MultiDisplayTouch) { |
| 8721 | // Test touch down on primary display. |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 8722 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8723 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 8724 | ui::LogicalDisplayId::DEFAULT)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 8725 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8726 | windowInPrimary->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 8727 | windowInSecondary->assertNoEvents(); |
| 8728 | |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 8729 | // Test touch down on second display. |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 8730 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 8731 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, SECOND_DISPLAY_ID)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 8732 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 8733 | windowInPrimary->assertNoEvents(); |
Siarhei Vishniakou | c5ca85c | 2019-11-15 17:20:00 -0800 | [diff] [blame] | 8734 | windowInSecondary->consumeMotionDown(SECOND_DISPLAY_ID); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 8735 | } |
| 8736 | |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 8737 | TEST_F(InputDispatcherFocusOnTwoDisplaysTest, SetInputWindow_MultiDisplayFocus) { |
Tiger Huang | 721e26f | 2018-07-24 22:26:19 +0800 | [diff] [blame] | 8738 | // Test inject a key down with display id specified. |
Prabir Pradhan | 93f342c | 2021-03-11 15:05:30 -0800 | [diff] [blame] | 8739 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8740 | injectKeyDownNoRepeat(*mDispatcher, ui::LogicalDisplayId::DEFAULT)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 8741 | << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8742 | windowInPrimary->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); |
Tiger Huang | 721e26f | 2018-07-24 22:26:19 +0800 | [diff] [blame] | 8743 | windowInSecondary->assertNoEvents(); |
| 8744 | |
| 8745 | // Test inject a key down without display id specified. |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 8746 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDownNoRepeat(*mDispatcher)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 8747 | << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 8748 | windowInPrimary->assertNoEvents(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8749 | windowInSecondary->consumeKeyDown(ui::LogicalDisplayId::INVALID); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 8750 | |
Siarhei Vishniakou | b9b1535 | 2019-11-26 13:19:26 -0800 | [diff] [blame] | 8751 | // Remove all windows in secondary display. |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 8752 | mDispatcher->onWindowInfosChanged({{*windowInPrimary->getInfo()}, {}, 0, 0}); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 8753 | |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 8754 | // Old focus should receive a cancel event. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8755 | windowInSecondary->consumeKeyUp(ui::LogicalDisplayId::INVALID, AKEY_EVENT_FLAG_CANCELED); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 8756 | |
| 8757 | // Test inject a key down, should timeout because of no target window. |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 8758 | ASSERT_NO_FATAL_FAILURE(assertInjectedKeyTimesOut(*mDispatcher)); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 8759 | windowInPrimary->assertNoEvents(); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 8760 | windowInSecondary->consumeFocusEvent(false); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 8761 | windowInSecondary->assertNoEvents(); |
| 8762 | } |
| 8763 | |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 8764 | // Test per-display input monitors for motion event. |
| 8765 | TEST_F(InputDispatcherFocusOnTwoDisplaysTest, MonitorMotionEvent_MultiDisplay) { |
chaviw | d1c2318 | 2019-12-20 18:44:56 -0800 | [diff] [blame] | 8766 | FakeMonitorReceiver monitorInPrimary = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8767 | FakeMonitorReceiver(*mDispatcher, "M_1", ui::LogicalDisplayId::DEFAULT); |
chaviw | d1c2318 | 2019-12-20 18:44:56 -0800 | [diff] [blame] | 8768 | FakeMonitorReceiver monitorInSecondary = |
Prabir Pradhan | fb54907 | 2023-10-05 19:17:36 +0000 | [diff] [blame] | 8769 | FakeMonitorReceiver(*mDispatcher, "M_2", SECOND_DISPLAY_ID); |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 8770 | |
| 8771 | // Test touch down on primary display. |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 8772 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8773 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 8774 | ui::LogicalDisplayId::DEFAULT)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 8775 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8776 | windowInPrimary->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
| 8777 | monitorInPrimary.consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 8778 | windowInSecondary->assertNoEvents(); |
chaviw | d1c2318 | 2019-12-20 18:44:56 -0800 | [diff] [blame] | 8779 | monitorInSecondary.assertNoEvents(); |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 8780 | |
| 8781 | // Test touch down on second display. |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 8782 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 8783 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, SECOND_DISPLAY_ID)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 8784 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 8785 | windowInPrimary->assertNoEvents(); |
chaviw | d1c2318 | 2019-12-20 18:44:56 -0800 | [diff] [blame] | 8786 | monitorInPrimary.assertNoEvents(); |
Siarhei Vishniakou | c5ca85c | 2019-11-15 17:20:00 -0800 | [diff] [blame] | 8787 | windowInSecondary->consumeMotionDown(SECOND_DISPLAY_ID); |
chaviw | d1c2318 | 2019-12-20 18:44:56 -0800 | [diff] [blame] | 8788 | monitorInSecondary.consumeMotionDown(SECOND_DISPLAY_ID); |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 8789 | |
Siarhei Vishniakou | 92c8fd5 | 2023-01-29 14:57:43 -0800 | [diff] [blame] | 8790 | // Lift up the touch from the second display |
| 8791 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 8792 | injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, SECOND_DISPLAY_ID)) |
Siarhei Vishniakou | 92c8fd5 | 2023-01-29 14:57:43 -0800 | [diff] [blame] | 8793 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 8794 | windowInSecondary->consumeMotionUp(SECOND_DISPLAY_ID); |
| 8795 | monitorInSecondary.consumeMotionUp(SECOND_DISPLAY_ID); |
| 8796 | |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 8797 | // Test inject a non-pointer motion event. |
| 8798 | // If specific a display, it will dispatch to the focused window of particular display, |
| 8799 | // or it will dispatch to the focused window of focused display. |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 8800 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8801 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TRACKBALL, |
| 8802 | ui::LogicalDisplayId::INVALID)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 8803 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 8804 | windowInPrimary->assertNoEvents(); |
chaviw | d1c2318 | 2019-12-20 18:44:56 -0800 | [diff] [blame] | 8805 | monitorInPrimary.assertNoEvents(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8806 | windowInSecondary->consumeMotionDown(ui::LogicalDisplayId::INVALID); |
| 8807 | monitorInSecondary.consumeMotionDown(ui::LogicalDisplayId::INVALID); |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 8808 | } |
| 8809 | |
| 8810 | // Test per-display input monitors for key event. |
| 8811 | TEST_F(InputDispatcherFocusOnTwoDisplaysTest, MonitorKeyEvent_MultiDisplay) { |
Siarhei Vishniakou | 870ecec | 2020-12-09 08:07:46 -1000 | [diff] [blame] | 8812 | // Input monitor per display. |
chaviw | d1c2318 | 2019-12-20 18:44:56 -0800 | [diff] [blame] | 8813 | FakeMonitorReceiver monitorInPrimary = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8814 | FakeMonitorReceiver(*mDispatcher, "M_1", ui::LogicalDisplayId::DEFAULT); |
chaviw | d1c2318 | 2019-12-20 18:44:56 -0800 | [diff] [blame] | 8815 | FakeMonitorReceiver monitorInSecondary = |
Prabir Pradhan | fb54907 | 2023-10-05 19:17:36 +0000 | [diff] [blame] | 8816 | FakeMonitorReceiver(*mDispatcher, "M_2", SECOND_DISPLAY_ID); |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 8817 | |
| 8818 | // Test inject a key down. |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 8819 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(*mDispatcher)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 8820 | << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 8821 | windowInPrimary->assertNoEvents(); |
chaviw | d1c2318 | 2019-12-20 18:44:56 -0800 | [diff] [blame] | 8822 | monitorInPrimary.assertNoEvents(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8823 | windowInSecondary->consumeKeyDown(ui::LogicalDisplayId::INVALID); |
| 8824 | monitorInSecondary.consumeKeyDown(ui::LogicalDisplayId::INVALID); |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 8825 | } |
| 8826 | |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 8827 | TEST_F(InputDispatcherFocusOnTwoDisplaysTest, CanFocusWindowOnUnfocusedDisplay) { |
| 8828 | sp<FakeWindowHandle> secondWindowInPrimary = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8829 | sp<FakeWindowHandle>::make(application1, mDispatcher, "D_1_W2", |
| 8830 | ui::LogicalDisplayId::DEFAULT); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 8831 | secondWindowInPrimary->setFocusable(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 8832 | mDispatcher->onWindowInfosChanged( |
| 8833 | {{*windowInPrimary->getInfo(), *secondWindowInPrimary->getInfo(), |
| 8834 | *windowInSecondary->getInfo()}, |
| 8835 | {}, |
| 8836 | 0, |
| 8837 | 0}); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 8838 | setFocusedWindow(secondWindowInPrimary); |
| 8839 | windowInPrimary->consumeFocusEvent(false); |
| 8840 | secondWindowInPrimary->consumeFocusEvent(true); |
| 8841 | |
| 8842 | // Test inject a key down. |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 8843 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8844 | injectKeyDown(*mDispatcher, ui::LogicalDisplayId::DEFAULT)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 8845 | << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 8846 | windowInPrimary->assertNoEvents(); |
| 8847 | windowInSecondary->assertNoEvents(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8848 | secondWindowInPrimary->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 8849 | } |
| 8850 | |
Arthur Hung | dfd528e | 2021-12-08 13:23:04 +0000 | [diff] [blame] | 8851 | TEST_F(InputDispatcherFocusOnTwoDisplaysTest, CancelTouch_MultiDisplay) { |
| 8852 | FakeMonitorReceiver monitorInPrimary = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8853 | FakeMonitorReceiver(*mDispatcher, "M_1", ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | dfd528e | 2021-12-08 13:23:04 +0000 | [diff] [blame] | 8854 | FakeMonitorReceiver monitorInSecondary = |
Prabir Pradhan | fb54907 | 2023-10-05 19:17:36 +0000 | [diff] [blame] | 8855 | FakeMonitorReceiver(*mDispatcher, "M_2", SECOND_DISPLAY_ID); |
Arthur Hung | dfd528e | 2021-12-08 13:23:04 +0000 | [diff] [blame] | 8856 | |
| 8857 | // Test touch down on primary display. |
| 8858 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8859 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 8860 | ui::LogicalDisplayId::DEFAULT)) |
Arthur Hung | dfd528e | 2021-12-08 13:23:04 +0000 | [diff] [blame] | 8861 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8862 | windowInPrimary->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
| 8863 | monitorInPrimary.consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | dfd528e | 2021-12-08 13:23:04 +0000 | [diff] [blame] | 8864 | |
| 8865 | // Test touch down on second display. |
| 8866 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 8867 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, SECOND_DISPLAY_ID)) |
Arthur Hung | dfd528e | 2021-12-08 13:23:04 +0000 | [diff] [blame] | 8868 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 8869 | windowInSecondary->consumeMotionDown(SECOND_DISPLAY_ID); |
| 8870 | monitorInSecondary.consumeMotionDown(SECOND_DISPLAY_ID); |
| 8871 | |
| 8872 | // Trigger cancel touch. |
| 8873 | mDispatcher->cancelCurrentTouch(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8874 | windowInPrimary->consumeMotionCancel(ui::LogicalDisplayId::DEFAULT); |
| 8875 | monitorInPrimary.consumeMotionCancel(ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | dfd528e | 2021-12-08 13:23:04 +0000 | [diff] [blame] | 8876 | windowInSecondary->consumeMotionCancel(SECOND_DISPLAY_ID); |
| 8877 | monitorInSecondary.consumeMotionCancel(SECOND_DISPLAY_ID); |
| 8878 | |
| 8879 | // Test inject a move motion event, no window/monitor should receive the event. |
| 8880 | ASSERT_EQ(InputEventInjectionResult::FAILED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 8881 | injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8882 | ui::LogicalDisplayId::DEFAULT, {110, 200})) |
Arthur Hung | dfd528e | 2021-12-08 13:23:04 +0000 | [diff] [blame] | 8883 | << "Inject motion event should return InputEventInjectionResult::FAILED"; |
| 8884 | windowInPrimary->assertNoEvents(); |
| 8885 | monitorInPrimary.assertNoEvents(); |
| 8886 | |
| 8887 | ASSERT_EQ(InputEventInjectionResult::FAILED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 8888 | injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, |
Arthur Hung | dfd528e | 2021-12-08 13:23:04 +0000 | [diff] [blame] | 8889 | SECOND_DISPLAY_ID, {110, 200})) |
| 8890 | << "Inject motion event should return InputEventInjectionResult::FAILED"; |
| 8891 | windowInSecondary->assertNoEvents(); |
| 8892 | monitorInSecondary.assertNoEvents(); |
| 8893 | } |
| 8894 | |
Hu Guo | cb134f1 | 2023-12-23 13:42:44 +0000 | [diff] [blame] | 8895 | /** |
| 8896 | * Send a key to the primary display and to the secondary display. |
| 8897 | * Then cause the key on the primary display to be canceled by sending in a stale key. |
| 8898 | * Ensure that the key on the primary display is canceled, and that the key on the secondary display |
| 8899 | * does not get canceled. |
| 8900 | */ |
| 8901 | TEST_F(InputDispatcherFocusOnTwoDisplaysTest, WhenDropKeyEvent_OnlyCancelCorrespondingKeyGesture) { |
| 8902 | // Send a key down on primary display |
| 8903 | mDispatcher->notifyKey( |
| 8904 | KeyArgsBuilder(AKEY_EVENT_ACTION_DOWN, AINPUT_SOURCE_KEYBOARD) |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8905 | .displayId(ui::LogicalDisplayId::DEFAULT) |
Hu Guo | cb134f1 | 2023-12-23 13:42:44 +0000 | [diff] [blame] | 8906 | .policyFlags(DEFAULT_POLICY_FLAGS | POLICY_FLAG_DISABLE_KEY_REPEAT) |
| 8907 | .build()); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8908 | windowInPrimary->consumeKeyEvent(AllOf(WithKeyAction(AKEY_EVENT_ACTION_DOWN), |
| 8909 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))); |
Hu Guo | cb134f1 | 2023-12-23 13:42:44 +0000 | [diff] [blame] | 8910 | windowInSecondary->assertNoEvents(); |
| 8911 | |
| 8912 | // Send a key down on second display |
| 8913 | mDispatcher->notifyKey( |
| 8914 | KeyArgsBuilder(AKEY_EVENT_ACTION_DOWN, AINPUT_SOURCE_KEYBOARD) |
| 8915 | .displayId(SECOND_DISPLAY_ID) |
| 8916 | .policyFlags(DEFAULT_POLICY_FLAGS | POLICY_FLAG_DISABLE_KEY_REPEAT) |
| 8917 | .build()); |
| 8918 | windowInSecondary->consumeKeyEvent( |
| 8919 | AllOf(WithKeyAction(AKEY_EVENT_ACTION_DOWN), WithDisplayId(SECOND_DISPLAY_ID))); |
| 8920 | windowInPrimary->assertNoEvents(); |
| 8921 | |
| 8922 | // Send a valid key up event on primary display that will be dropped because it is stale |
| 8923 | NotifyKeyArgs staleKeyUp = |
| 8924 | KeyArgsBuilder(AKEY_EVENT_ACTION_UP, AINPUT_SOURCE_KEYBOARD) |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8925 | .displayId(ui::LogicalDisplayId::DEFAULT) |
Hu Guo | cb134f1 | 2023-12-23 13:42:44 +0000 | [diff] [blame] | 8926 | .policyFlags(DEFAULT_POLICY_FLAGS | POLICY_FLAG_DISABLE_KEY_REPEAT) |
| 8927 | .build(); |
| 8928 | static constexpr std::chrono::duration STALE_EVENT_TIMEOUT = 10ms; |
| 8929 | mFakePolicy->setStaleEventTimeout(STALE_EVENT_TIMEOUT); |
| 8930 | std::this_thread::sleep_for(STALE_EVENT_TIMEOUT); |
| 8931 | mDispatcher->notifyKey(staleKeyUp); |
| 8932 | |
| 8933 | // Only the key gesture corresponding to the dropped event should receive the cancel event. |
| 8934 | // Therefore, windowInPrimary should get the cancel event and windowInSecondary should not |
| 8935 | // receive any events. |
| 8936 | windowInPrimary->consumeKeyEvent(AllOf(WithKeyAction(AKEY_EVENT_ACTION_UP), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8937 | WithDisplayId(ui::LogicalDisplayId::DEFAULT), |
Hu Guo | cb134f1 | 2023-12-23 13:42:44 +0000 | [diff] [blame] | 8938 | WithFlags(AKEY_EVENT_FLAG_CANCELED))); |
| 8939 | windowInSecondary->assertNoEvents(); |
| 8940 | } |
| 8941 | |
| 8942 | /** |
| 8943 | * Similar to 'WhenDropKeyEvent_OnlyCancelCorrespondingKeyGesture' but for motion events. |
| 8944 | */ |
| 8945 | TEST_F(InputDispatcherFocusOnTwoDisplaysTest, WhenDropMotionEvent_OnlyCancelCorrespondingGesture) { |
| 8946 | // Send touch down on primary display. |
| 8947 | mDispatcher->notifyMotion( |
| 8948 | MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 8949 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(200)) |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8950 | .displayId(ui::LogicalDisplayId::DEFAULT) |
Hu Guo | cb134f1 | 2023-12-23 13:42:44 +0000 | [diff] [blame] | 8951 | .build()); |
| 8952 | windowInPrimary->consumeMotionEvent( |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8953 | AllOf(WithMotionAction(ACTION_DOWN), WithDisplayId(ui::LogicalDisplayId::DEFAULT))); |
Hu Guo | cb134f1 | 2023-12-23 13:42:44 +0000 | [diff] [blame] | 8954 | windowInSecondary->assertNoEvents(); |
| 8955 | |
| 8956 | // Send touch down on second display. |
| 8957 | mDispatcher->notifyMotion( |
| 8958 | MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 8959 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(200)) |
| 8960 | .displayId(SECOND_DISPLAY_ID) |
| 8961 | .build()); |
| 8962 | windowInPrimary->assertNoEvents(); |
| 8963 | windowInSecondary->consumeMotionEvent( |
| 8964 | AllOf(WithMotionAction(ACTION_DOWN), WithDisplayId(SECOND_DISPLAY_ID))); |
| 8965 | |
| 8966 | // inject a valid MotionEvent on primary display that will be stale when it arrives. |
| 8967 | NotifyMotionArgs staleMotionUp = |
| 8968 | MotionArgsBuilder(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN) |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 8969 | .displayId(ui::LogicalDisplayId::DEFAULT) |
Hu Guo | cb134f1 | 2023-12-23 13:42:44 +0000 | [diff] [blame] | 8970 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(200)) |
| 8971 | .build(); |
| 8972 | static constexpr std::chrono::duration STALE_EVENT_TIMEOUT = 10ms; |
| 8973 | mFakePolicy->setStaleEventTimeout(STALE_EVENT_TIMEOUT); |
| 8974 | std::this_thread::sleep_for(STALE_EVENT_TIMEOUT); |
| 8975 | mDispatcher->notifyMotion(staleMotionUp); |
| 8976 | |
| 8977 | // For stale motion events, we let the gesture to complete. This behaviour is different from key |
| 8978 | // events, where we would cancel the current keys instead. |
| 8979 | windowInPrimary->consumeMotionEvent(WithMotionAction(ACTION_UP)); |
| 8980 | windowInSecondary->assertNoEvents(); |
| 8981 | } |
| 8982 | |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 8983 | class InputFilterTest : public InputDispatcherTest { |
| 8984 | protected: |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 8985 | void testNotifyMotion(ui::LogicalDisplayId displayId, bool expectToBeFiltered, |
Prabir Pradhan | 81420cc | 2021-09-06 10:28:50 -0700 | [diff] [blame] | 8986 | const ui::Transform& transform = ui::Transform()) { |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 8987 | NotifyMotionArgs motionArgs; |
| 8988 | |
Siarhei Vishniakou | 870ecec | 2020-12-09 08:07:46 -1000 | [diff] [blame] | 8989 | motionArgs = |
| 8990 | generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, displayId); |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 8991 | mDispatcher->notifyMotion(motionArgs); |
Siarhei Vishniakou | 870ecec | 2020-12-09 08:07:46 -1000 | [diff] [blame] | 8992 | motionArgs = |
| 8993 | generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, displayId); |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 8994 | mDispatcher->notifyMotion(motionArgs); |
Siarhei Vishniakou | 2bfa905 | 2019-11-21 18:10:54 -0800 | [diff] [blame] | 8995 | ASSERT_TRUE(mDispatcher->waitForIdle()); |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 8996 | if (expectToBeFiltered) { |
Siarhei Vishniakou | 3218fc0 | 2023-06-15 20:41:02 -0700 | [diff] [blame] | 8997 | const auto xy = transform.transform(motionArgs.pointerCoords[0].getXYValue()); |
Prabir Pradhan | 81420cc | 2021-09-06 10:28:50 -0700 | [diff] [blame] | 8998 | mFakePolicy->assertFilterInputEventWasCalled(motionArgs, xy); |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 8999 | } else { |
| 9000 | mFakePolicy->assertFilterInputEventWasNotCalled(); |
| 9001 | } |
| 9002 | } |
| 9003 | |
| 9004 | void testNotifyKey(bool expectToBeFiltered) { |
| 9005 | NotifyKeyArgs keyArgs; |
| 9006 | |
| 9007 | keyArgs = generateKeyArgs(AKEY_EVENT_ACTION_DOWN); |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 9008 | mDispatcher->notifyKey(keyArgs); |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 9009 | keyArgs = generateKeyArgs(AKEY_EVENT_ACTION_UP); |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 9010 | mDispatcher->notifyKey(keyArgs); |
Siarhei Vishniakou | 2bfa905 | 2019-11-21 18:10:54 -0800 | [diff] [blame] | 9011 | ASSERT_TRUE(mDispatcher->waitForIdle()); |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 9012 | |
| 9013 | if (expectToBeFiltered) { |
Siarhei Vishniakou | 8935a80 | 2019-11-15 16:41:44 -0800 | [diff] [blame] | 9014 | mFakePolicy->assertFilterInputEventWasCalled(keyArgs); |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 9015 | } else { |
| 9016 | mFakePolicy->assertFilterInputEventWasNotCalled(); |
| 9017 | } |
| 9018 | } |
| 9019 | }; |
| 9020 | |
| 9021 | // Test InputFilter for MotionEvent |
| 9022 | TEST_F(InputFilterTest, MotionEvent_InputFilter) { |
| 9023 | // Since the InputFilter is disabled by default, check if touch events aren't filtered. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9024 | testNotifyMotion(ui::LogicalDisplayId::DEFAULT, /*expectToBeFiltered=*/false); |
Harry Cutts | 101ee9b | 2023-07-06 18:04:14 +0000 | [diff] [blame] | 9025 | testNotifyMotion(SECOND_DISPLAY_ID, /*expectToBeFiltered=*/false); |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 9026 | |
| 9027 | // Enable InputFilter |
| 9028 | mDispatcher->setInputFilterEnabled(true); |
| 9029 | // Test touch on both primary and second display, and check if both events are filtered. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9030 | testNotifyMotion(ui::LogicalDisplayId::DEFAULT, /*expectToBeFiltered=*/true); |
Harry Cutts | 101ee9b | 2023-07-06 18:04:14 +0000 | [diff] [blame] | 9031 | testNotifyMotion(SECOND_DISPLAY_ID, /*expectToBeFiltered=*/true); |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 9032 | |
| 9033 | // Disable InputFilter |
| 9034 | mDispatcher->setInputFilterEnabled(false); |
| 9035 | // Test touch on both primary and second display, and check if both events aren't filtered. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9036 | testNotifyMotion(ui::LogicalDisplayId::DEFAULT, /*expectToBeFiltered=*/false); |
Harry Cutts | 101ee9b | 2023-07-06 18:04:14 +0000 | [diff] [blame] | 9037 | testNotifyMotion(SECOND_DISPLAY_ID, /*expectToBeFiltered=*/false); |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 9038 | } |
| 9039 | |
| 9040 | // Test InputFilter for KeyEvent |
| 9041 | TEST_F(InputFilterTest, KeyEvent_InputFilter) { |
| 9042 | // Since the InputFilter is disabled by default, check if key event aren't filtered. |
Harry Cutts | 101ee9b | 2023-07-06 18:04:14 +0000 | [diff] [blame] | 9043 | testNotifyKey(/*expectToBeFiltered=*/false); |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 9044 | |
| 9045 | // Enable InputFilter |
| 9046 | mDispatcher->setInputFilterEnabled(true); |
| 9047 | // Send a key event, and check if it is filtered. |
Harry Cutts | 101ee9b | 2023-07-06 18:04:14 +0000 | [diff] [blame] | 9048 | testNotifyKey(/*expectToBeFiltered=*/true); |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 9049 | |
| 9050 | // Disable InputFilter |
| 9051 | mDispatcher->setInputFilterEnabled(false); |
| 9052 | // Send a key event, and check if it isn't filtered. |
Harry Cutts | 101ee9b | 2023-07-06 18:04:14 +0000 | [diff] [blame] | 9053 | testNotifyKey(/*expectToBeFiltered=*/false); |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 9054 | } |
| 9055 | |
Prabir Pradhan | 81420cc | 2021-09-06 10:28:50 -0700 | [diff] [blame] | 9056 | // Ensure that MotionEvents sent to the InputFilter through InputListener are converted to the |
| 9057 | // logical display coordinate space. |
| 9058 | TEST_F(InputFilterTest, MotionEvent_UsesLogicalDisplayCoordinates_notifyMotion) { |
| 9059 | ui::Transform firstDisplayTransform; |
| 9060 | firstDisplayTransform.set({1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 0, 0, 1}); |
| 9061 | ui::Transform secondDisplayTransform; |
| 9062 | secondDisplayTransform.set({-6.6, -5.5, -4.4, -3.3, -2.2, -1.1, 0, 0, 1}); |
| 9063 | |
| 9064 | std::vector<gui::DisplayInfo> displayInfos(2); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9065 | displayInfos[0].displayId = ui::LogicalDisplayId::DEFAULT; |
Prabir Pradhan | 81420cc | 2021-09-06 10:28:50 -0700 | [diff] [blame] | 9066 | displayInfos[0].transform = firstDisplayTransform; |
| 9067 | displayInfos[1].displayId = SECOND_DISPLAY_ID; |
| 9068 | displayInfos[1].transform = secondDisplayTransform; |
| 9069 | |
Patrick Williams | d828f30 | 2023-04-28 17:52:08 -0500 | [diff] [blame] | 9070 | mDispatcher->onWindowInfosChanged({{}, displayInfos, 0, 0}); |
Prabir Pradhan | 81420cc | 2021-09-06 10:28:50 -0700 | [diff] [blame] | 9071 | |
| 9072 | // Enable InputFilter |
| 9073 | mDispatcher->setInputFilterEnabled(true); |
| 9074 | |
| 9075 | // Ensure the correct transforms are used for the displays. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9076 | testNotifyMotion(ui::LogicalDisplayId::DEFAULT, /*expectToBeFiltered=*/true, |
| 9077 | firstDisplayTransform); |
Harry Cutts | 101ee9b | 2023-07-06 18:04:14 +0000 | [diff] [blame] | 9078 | testNotifyMotion(SECOND_DISPLAY_ID, /*expectToBeFiltered=*/true, secondDisplayTransform); |
Prabir Pradhan | 81420cc | 2021-09-06 10:28:50 -0700 | [diff] [blame] | 9079 | } |
| 9080 | |
Siarhei Vishniakou | 5d552c4 | 2021-05-21 05:02:22 +0000 | [diff] [blame] | 9081 | class InputFilterInjectionPolicyTest : public InputDispatcherTest { |
| 9082 | protected: |
| 9083 | virtual void SetUp() override { |
| 9084 | InputDispatcherTest::SetUp(); |
| 9085 | |
| 9086 | /** |
| 9087 | * We don't need to enable input filter to test the injected event policy, but we enabled it |
| 9088 | * here to make the tests more realistic, since this policy only matters when inputfilter is |
| 9089 | * on. |
| 9090 | */ |
| 9091 | mDispatcher->setInputFilterEnabled(true); |
| 9092 | |
| 9093 | std::shared_ptr<InputApplicationHandle> application = |
| 9094 | std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 9095 | mWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Test Window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9096 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 5d552c4 | 2021-05-21 05:02:22 +0000 | [diff] [blame] | 9097 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9098 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); |
Siarhei Vishniakou | 5d552c4 | 2021-05-21 05:02:22 +0000 | [diff] [blame] | 9099 | mWindow->setFocusable(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 9100 | mDispatcher->onWindowInfosChanged({{*mWindow->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | 5d552c4 | 2021-05-21 05:02:22 +0000 | [diff] [blame] | 9101 | setFocusedWindow(mWindow); |
| 9102 | mWindow->consumeFocusEvent(true); |
| 9103 | } |
| 9104 | |
Siarhei Vishniakou | f00a4ec | 2021-06-16 03:55:32 +0000 | [diff] [blame] | 9105 | void testInjectedKey(int32_t policyFlags, int32_t injectedDeviceId, int32_t resolvedDeviceId, |
| 9106 | int32_t flags) { |
Siarhei Vishniakou | 5d552c4 | 2021-05-21 05:02:22 +0000 | [diff] [blame] | 9107 | KeyEvent event; |
| 9108 | |
| 9109 | const nsecs_t eventTime = systemTime(SYSTEM_TIME_MONOTONIC); |
| 9110 | event.initialize(InputEvent::nextId(), injectedDeviceId, AINPUT_SOURCE_KEYBOARD, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9111 | ui::LogicalDisplayId::INVALID, INVALID_HMAC, AKEY_EVENT_ACTION_DOWN, 0, |
| 9112 | AKEYCODE_A, KEY_A, AMETA_NONE, /*repeatCount=*/0, eventTime, eventTime); |
Siarhei Vishniakou | 5d552c4 | 2021-05-21 05:02:22 +0000 | [diff] [blame] | 9113 | const int32_t additionalPolicyFlags = |
| 9114 | POLICY_FLAG_PASS_TO_USER | POLICY_FLAG_DISABLE_KEY_REPEAT; |
| 9115 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 9116 | mDispatcher->injectInputEvent(&event, /*targetUid=*/{}, |
Siarhei Vishniakou | 4648fea | 2023-06-27 01:00:12 +0000 | [diff] [blame] | 9117 | InputEventInjectionSync::WAIT_FOR_RESULT, 100ms, |
Siarhei Vishniakou | 5d552c4 | 2021-05-21 05:02:22 +0000 | [diff] [blame] | 9118 | policyFlags | additionalPolicyFlags)); |
| 9119 | |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 9120 | mWindow->consumeKeyEvent(AllOf(WithDeviceId(resolvedDeviceId), WithFlags(flags))); |
Siarhei Vishniakou | f00a4ec | 2021-06-16 03:55:32 +0000 | [diff] [blame] | 9121 | } |
| 9122 | |
| 9123 | void testInjectedMotion(int32_t policyFlags, int32_t injectedDeviceId, int32_t resolvedDeviceId, |
| 9124 | int32_t flags) { |
| 9125 | MotionEvent event; |
| 9126 | PointerProperties pointerProperties[1]; |
| 9127 | PointerCoords pointerCoords[1]; |
| 9128 | pointerProperties[0].clear(); |
| 9129 | pointerProperties[0].id = 0; |
| 9130 | pointerCoords[0].clear(); |
| 9131 | pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, 300); |
| 9132 | pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, 400); |
| 9133 | |
| 9134 | ui::Transform identityTransform; |
| 9135 | const nsecs_t eventTime = systemTime(SYSTEM_TIME_MONOTONIC); |
| 9136 | event.initialize(InputEvent::nextId(), injectedDeviceId, AINPUT_SOURCE_TOUCHSCREEN, |
| 9137 | DISPLAY_ID, INVALID_HMAC, AMOTION_EVENT_ACTION_DOWN, 0, 0, |
| 9138 | AMOTION_EVENT_EDGE_FLAG_NONE, AMETA_NONE, 0, MotionClassification::NONE, |
| 9139 | identityTransform, 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION, |
Prabir Pradhan | b9b1850 | 2021-08-26 12:30:32 -0700 | [diff] [blame] | 9140 | AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform, eventTime, |
Evan Rosky | 0957669 | 2021-07-01 12:22:09 -0700 | [diff] [blame] | 9141 | eventTime, |
Harry Cutts | 101ee9b | 2023-07-06 18:04:14 +0000 | [diff] [blame] | 9142 | /*pointerCount=*/1, pointerProperties, pointerCoords); |
Siarhei Vishniakou | f00a4ec | 2021-06-16 03:55:32 +0000 | [diff] [blame] | 9143 | |
| 9144 | const int32_t additionalPolicyFlags = POLICY_FLAG_PASS_TO_USER; |
| 9145 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 9146 | mDispatcher->injectInputEvent(&event, /*targetUid=*/{}, |
Siarhei Vishniakou | 4648fea | 2023-06-27 01:00:12 +0000 | [diff] [blame] | 9147 | InputEventInjectionSync::WAIT_FOR_RESULT, 100ms, |
Siarhei Vishniakou | f00a4ec | 2021-06-16 03:55:32 +0000 | [diff] [blame] | 9148 | policyFlags | additionalPolicyFlags)); |
| 9149 | |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 9150 | mWindow->consumeMotionEvent(AllOf(WithFlags(flags), WithDeviceId(resolvedDeviceId))); |
Siarhei Vishniakou | 5d552c4 | 2021-05-21 05:02:22 +0000 | [diff] [blame] | 9151 | } |
| 9152 | |
| 9153 | private: |
| 9154 | sp<FakeWindowHandle> mWindow; |
| 9155 | }; |
| 9156 | |
| 9157 | TEST_F(InputFilterInjectionPolicyTest, TrustedFilteredEvents_KeepOriginalDeviceId) { |
Siarhei Vishniakou | f00a4ec | 2021-06-16 03:55:32 +0000 | [diff] [blame] | 9158 | // Must have POLICY_FLAG_FILTERED here to indicate that the event has gone through the input |
| 9159 | // filter. Without it, the event will no different from a regularly injected event, and the |
| 9160 | // injected device id will be overwritten. |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 9161 | testInjectedKey(POLICY_FLAG_FILTERED, /*injectedDeviceId=*/3, /*resolvedDeviceId=*/3, |
| 9162 | /*flags=*/0); |
Siarhei Vishniakou | 5d552c4 | 2021-05-21 05:02:22 +0000 | [diff] [blame] | 9163 | } |
| 9164 | |
Siarhei Vishniakou | f00a4ec | 2021-06-16 03:55:32 +0000 | [diff] [blame] | 9165 | TEST_F(InputFilterInjectionPolicyTest, KeyEventsInjectedFromAccessibility_HaveAccessibilityFlag) { |
Siarhei Vishniakou | 5d552c4 | 2021-05-21 05:02:22 +0000 | [diff] [blame] | 9166 | testInjectedKey(POLICY_FLAG_FILTERED | POLICY_FLAG_INJECTED_FROM_ACCESSIBILITY, |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 9167 | /*injectedDeviceId=*/3, /*resolvedDeviceId=*/3, |
Siarhei Vishniakou | f00a4ec | 2021-06-16 03:55:32 +0000 | [diff] [blame] | 9168 | AKEY_EVENT_FLAG_IS_ACCESSIBILITY_EVENT); |
| 9169 | } |
| 9170 | |
| 9171 | TEST_F(InputFilterInjectionPolicyTest, |
| 9172 | MotionEventsInjectedFromAccessibility_HaveAccessibilityFlag) { |
| 9173 | testInjectedMotion(POLICY_FLAG_FILTERED | POLICY_FLAG_INJECTED_FROM_ACCESSIBILITY, |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 9174 | /*injectedDeviceId=*/3, /*resolvedDeviceId=*/3, |
Siarhei Vishniakou | f00a4ec | 2021-06-16 03:55:32 +0000 | [diff] [blame] | 9175 | AMOTION_EVENT_FLAG_IS_ACCESSIBILITY_EVENT); |
Siarhei Vishniakou | 5d552c4 | 2021-05-21 05:02:22 +0000 | [diff] [blame] | 9176 | } |
| 9177 | |
| 9178 | TEST_F(InputFilterInjectionPolicyTest, RegularInjectedEvents_ReceiveVirtualDeviceId) { |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 9179 | testInjectedKey(/*policyFlags=*/0, /*injectedDeviceId=*/3, |
| 9180 | /*resolvedDeviceId=*/VIRTUAL_KEYBOARD_ID, /*flags=*/0); |
Siarhei Vishniakou | 5d552c4 | 2021-05-21 05:02:22 +0000 | [diff] [blame] | 9181 | } |
| 9182 | |
Yeabkal Wubshit | b8aadfa | 2024-01-17 17:03:42 -0800 | [diff] [blame] | 9183 | class InputDispatcherUserActivityPokeTests : public InputDispatcherTest { |
| 9184 | protected: |
| 9185 | virtual void SetUp() override { |
| 9186 | InputDispatcherTest::SetUp(); |
| 9187 | |
| 9188 | std::shared_ptr<FakeApplicationHandle> application = |
| 9189 | std::make_shared<FakeApplicationHandle>(); |
| 9190 | application->setDispatchingTimeout(100ms); |
| 9191 | mWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "TestWindow", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9192 | ui::LogicalDisplayId::DEFAULT); |
Yeabkal Wubshit | 222d83d | 2024-01-24 18:00:09 +0000 | [diff] [blame] | 9193 | mWindow->setFrame(Rect(0, 0, 100, 100)); |
Yeabkal Wubshit | b8aadfa | 2024-01-17 17:03:42 -0800 | [diff] [blame] | 9194 | mWindow->setDispatchingTimeout(100ms); |
| 9195 | mWindow->setFocusable(true); |
| 9196 | |
| 9197 | // Set focused application. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9198 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); |
Yeabkal Wubshit | b8aadfa | 2024-01-17 17:03:42 -0800 | [diff] [blame] | 9199 | |
| 9200 | mDispatcher->onWindowInfosChanged({{*mWindow->getInfo()}, {}, 0, 0}); |
| 9201 | setFocusedWindow(mWindow); |
| 9202 | mWindow->consumeFocusEvent(true); |
| 9203 | } |
| 9204 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 9205 | void notifyAndConsumeMotion(int32_t action, uint32_t source, ui::LogicalDisplayId displayId, |
Yeabkal Wubshit | b8aadfa | 2024-01-17 17:03:42 -0800 | [diff] [blame] | 9206 | nsecs_t eventTime) { |
| 9207 | mDispatcher->notifyMotion(MotionArgsBuilder(action, source) |
| 9208 | .displayId(displayId) |
| 9209 | .eventTime(eventTime) |
| 9210 | .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) |
| 9211 | .build()); |
| 9212 | mWindow->consumeMotionEvent(WithMotionAction(action)); |
| 9213 | } |
| 9214 | |
| 9215 | private: |
| 9216 | sp<FakeWindowHandle> mWindow; |
| 9217 | }; |
| 9218 | |
| 9219 | TEST_F_WITH_FLAGS( |
| 9220 | InputDispatcherUserActivityPokeTests, MinPokeTimeObserved, |
| 9221 | REQUIRES_FLAGS_ENABLED(ACONFIG_FLAG(com::android::input::flags, |
| 9222 | rate_limit_user_activity_poke_in_dispatcher))) { |
| 9223 | mDispatcher->setMinTimeBetweenUserActivityPokes(50ms); |
| 9224 | |
| 9225 | // First event of type TOUCH. Should poke. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9226 | notifyAndConsumeMotion(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, |
Yeabkal Wubshit | b8aadfa | 2024-01-17 17:03:42 -0800 | [diff] [blame] | 9227 | milliseconds_to_nanoseconds(50)); |
| 9228 | mFakePolicy->assertUserActivityPoked( |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9229 | {{milliseconds_to_nanoseconds(50), USER_ACTIVITY_EVENT_TOUCH, |
| 9230 | ui::LogicalDisplayId::DEFAULT}}); |
Yeabkal Wubshit | b8aadfa | 2024-01-17 17:03:42 -0800 | [diff] [blame] | 9231 | |
| 9232 | // 80ns > 50ns has passed since previous TOUCH event. Should poke. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9233 | notifyAndConsumeMotion(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, |
Yeabkal Wubshit | b8aadfa | 2024-01-17 17:03:42 -0800 | [diff] [blame] | 9234 | milliseconds_to_nanoseconds(130)); |
| 9235 | mFakePolicy->assertUserActivityPoked( |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9236 | {{milliseconds_to_nanoseconds(130), USER_ACTIVITY_EVENT_TOUCH, |
| 9237 | ui::LogicalDisplayId::DEFAULT}}); |
Yeabkal Wubshit | b8aadfa | 2024-01-17 17:03:42 -0800 | [diff] [blame] | 9238 | |
| 9239 | // First event of type OTHER. Should poke (despite being within 50ns of previous TOUCH event). |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9240 | notifyAndConsumeMotion(ACTION_SCROLL, AINPUT_SOURCE_ROTARY_ENCODER, |
| 9241 | ui::LogicalDisplayId::DEFAULT, milliseconds_to_nanoseconds(135)); |
Yeabkal Wubshit | b8aadfa | 2024-01-17 17:03:42 -0800 | [diff] [blame] | 9242 | mFakePolicy->assertUserActivityPoked( |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9243 | {{milliseconds_to_nanoseconds(135), USER_ACTIVITY_EVENT_OTHER, |
| 9244 | ui::LogicalDisplayId::DEFAULT}}); |
Yeabkal Wubshit | b8aadfa | 2024-01-17 17:03:42 -0800 | [diff] [blame] | 9245 | |
| 9246 | // Within 50ns of previous TOUCH event. Should NOT poke. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9247 | notifyAndConsumeMotion(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, |
Yeabkal Wubshit | b8aadfa | 2024-01-17 17:03:42 -0800 | [diff] [blame] | 9248 | milliseconds_to_nanoseconds(140)); |
| 9249 | mFakePolicy->assertUserActivityNotPoked(); |
| 9250 | |
| 9251 | // Within 50ns of previous OTHER event. Should NOT poke. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9252 | notifyAndConsumeMotion(ACTION_SCROLL, AINPUT_SOURCE_ROTARY_ENCODER, |
| 9253 | ui::LogicalDisplayId::DEFAULT, milliseconds_to_nanoseconds(150)); |
Yeabkal Wubshit | b8aadfa | 2024-01-17 17:03:42 -0800 | [diff] [blame] | 9254 | mFakePolicy->assertUserActivityNotPoked(); |
| 9255 | |
| 9256 | // Within 50ns of previous TOUCH event (which was at time 130). Should NOT poke. |
| 9257 | // Note that STYLUS is mapped to TOUCH user activity, since it's a pointer-type source. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9258 | notifyAndConsumeMotion(ACTION_DOWN, AINPUT_SOURCE_STYLUS, ui::LogicalDisplayId::DEFAULT, |
Yeabkal Wubshit | b8aadfa | 2024-01-17 17:03:42 -0800 | [diff] [blame] | 9259 | milliseconds_to_nanoseconds(160)); |
| 9260 | mFakePolicy->assertUserActivityNotPoked(); |
| 9261 | |
| 9262 | // 65ns > 50ns has passed since previous OTHER event. Should poke. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9263 | notifyAndConsumeMotion(ACTION_SCROLL, AINPUT_SOURCE_ROTARY_ENCODER, |
| 9264 | ui::LogicalDisplayId::DEFAULT, milliseconds_to_nanoseconds(200)); |
Yeabkal Wubshit | b8aadfa | 2024-01-17 17:03:42 -0800 | [diff] [blame] | 9265 | mFakePolicy->assertUserActivityPoked( |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9266 | {{milliseconds_to_nanoseconds(200), USER_ACTIVITY_EVENT_OTHER, |
| 9267 | ui::LogicalDisplayId::DEFAULT}}); |
Yeabkal Wubshit | b8aadfa | 2024-01-17 17:03:42 -0800 | [diff] [blame] | 9268 | |
| 9269 | // 170ns > 50ns has passed since previous TOUCH event. Should poke. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9270 | notifyAndConsumeMotion(ACTION_UP, AINPUT_SOURCE_STYLUS, ui::LogicalDisplayId::DEFAULT, |
Yeabkal Wubshit | b8aadfa | 2024-01-17 17:03:42 -0800 | [diff] [blame] | 9271 | milliseconds_to_nanoseconds(300)); |
| 9272 | mFakePolicy->assertUserActivityPoked( |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9273 | {{milliseconds_to_nanoseconds(300), USER_ACTIVITY_EVENT_TOUCH, |
| 9274 | ui::LogicalDisplayId::DEFAULT}}); |
Yeabkal Wubshit | b8aadfa | 2024-01-17 17:03:42 -0800 | [diff] [blame] | 9275 | |
| 9276 | // Assert that there's no more user activity poke event. |
| 9277 | mFakePolicy->assertUserActivityNotPoked(); |
| 9278 | } |
| 9279 | |
| 9280 | TEST_F_WITH_FLAGS( |
| 9281 | InputDispatcherUserActivityPokeTests, DefaultMinPokeTimeOf100MsUsed, |
| 9282 | REQUIRES_FLAGS_ENABLED(ACONFIG_FLAG(com::android::input::flags, |
| 9283 | rate_limit_user_activity_poke_in_dispatcher))) { |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9284 | notifyAndConsumeMotion(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, |
Yeabkal Wubshit | b8aadfa | 2024-01-17 17:03:42 -0800 | [diff] [blame] | 9285 | milliseconds_to_nanoseconds(200)); |
| 9286 | mFakePolicy->assertUserActivityPoked( |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9287 | {{milliseconds_to_nanoseconds(200), USER_ACTIVITY_EVENT_TOUCH, |
| 9288 | ui::LogicalDisplayId::DEFAULT}}); |
Yeabkal Wubshit | b8aadfa | 2024-01-17 17:03:42 -0800 | [diff] [blame] | 9289 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9290 | notifyAndConsumeMotion(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, |
Yeabkal Wubshit | b8aadfa | 2024-01-17 17:03:42 -0800 | [diff] [blame] | 9291 | milliseconds_to_nanoseconds(280)); |
| 9292 | mFakePolicy->assertUserActivityNotPoked(); |
| 9293 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9294 | notifyAndConsumeMotion(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, |
Yeabkal Wubshit | b8aadfa | 2024-01-17 17:03:42 -0800 | [diff] [blame] | 9295 | milliseconds_to_nanoseconds(340)); |
| 9296 | mFakePolicy->assertUserActivityPoked( |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9297 | {{milliseconds_to_nanoseconds(340), USER_ACTIVITY_EVENT_TOUCH, |
| 9298 | ui::LogicalDisplayId::DEFAULT}}); |
Yeabkal Wubshit | b8aadfa | 2024-01-17 17:03:42 -0800 | [diff] [blame] | 9299 | } |
| 9300 | |
| 9301 | TEST_F_WITH_FLAGS( |
| 9302 | InputDispatcherUserActivityPokeTests, ZeroMinPokeTimeDisablesRateLimiting, |
| 9303 | REQUIRES_FLAGS_ENABLED(ACONFIG_FLAG(com::android::input::flags, |
| 9304 | rate_limit_user_activity_poke_in_dispatcher))) { |
| 9305 | mDispatcher->setMinTimeBetweenUserActivityPokes(0ms); |
| 9306 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9307 | notifyAndConsumeMotion(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, |
| 9308 | 20); |
Yeabkal Wubshit | b8aadfa | 2024-01-17 17:03:42 -0800 | [diff] [blame] | 9309 | mFakePolicy->assertUserActivityPoked(); |
| 9310 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9311 | notifyAndConsumeMotion(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, |
| 9312 | 30); |
Yeabkal Wubshit | b8aadfa | 2024-01-17 17:03:42 -0800 | [diff] [blame] | 9313 | mFakePolicy->assertUserActivityPoked(); |
| 9314 | } |
| 9315 | |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 9316 | class InputDispatcherOnPointerDownOutsideFocus : public InputDispatcherTest { |
Prabir Pradhan | 3608aad | 2019-10-02 17:08:26 -0700 | [diff] [blame] | 9317 | virtual void SetUp() override { |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 9318 | InputDispatcherTest::SetUp(); |
| 9319 | |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 9320 | std::shared_ptr<FakeApplicationHandle> application = |
| 9321 | std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9322 | mUnfocusedWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Top", |
| 9323 | ui::LogicalDisplayId::DEFAULT); |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 9324 | mUnfocusedWindow->setFrame(Rect(0, 0, 30, 30)); |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 9325 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9326 | mFocusedWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Second", |
| 9327 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | b9b1535 | 2019-11-26 13:19:26 -0800 | [diff] [blame] | 9328 | mFocusedWindow->setFrame(Rect(50, 50, 100, 100)); |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 9329 | |
| 9330 | // Set focused application. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9331 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); |
Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 9332 | mFocusedWindow->setFocusable(true); |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 9333 | |
| 9334 | // Expect one focus window exist in display. |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 9335 | mDispatcher->onWindowInfosChanged( |
| 9336 | {{*mUnfocusedWindow->getInfo(), *mFocusedWindow->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 9337 | setFocusedWindow(mFocusedWindow); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 9338 | mFocusedWindow->consumeFocusEvent(true); |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 9339 | } |
| 9340 | |
Prabir Pradhan | 3608aad | 2019-10-02 17:08:26 -0700 | [diff] [blame] | 9341 | virtual void TearDown() override { |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 9342 | InputDispatcherTest::TearDown(); |
| 9343 | |
| 9344 | mUnfocusedWindow.clear(); |
Siarhei Vishniakou | b9b1535 | 2019-11-26 13:19:26 -0800 | [diff] [blame] | 9345 | mFocusedWindow.clear(); |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 9346 | } |
| 9347 | |
| 9348 | protected: |
| 9349 | sp<FakeWindowHandle> mUnfocusedWindow; |
Siarhei Vishniakou | b9b1535 | 2019-11-26 13:19:26 -0800 | [diff] [blame] | 9350 | sp<FakeWindowHandle> mFocusedWindow; |
Siarhei Vishniakou | fb9fcda | 2020-05-04 14:59:19 -0700 | [diff] [blame] | 9351 | static constexpr PointF FOCUSED_WINDOW_TOUCH_POINT = {60, 60}; |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 9352 | }; |
| 9353 | |
| 9354 | // Have two windows, one with focus. Inject MotionEvent with source TOUCHSCREEN and action |
| 9355 | // DOWN on the window that doesn't have focus. Ensure the window that didn't have focus received |
| 9356 | // the onPointerDownOutsideFocus callback. |
| 9357 | TEST_F(InputDispatcherOnPointerDownOutsideFocus, OnPointerDownOutsideFocus_Success) { |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 9358 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9359 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 9360 | ui::LogicalDisplayId::DEFAULT, {20, 20})) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 9361 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | 03aee2a | 2020-04-13 20:44:54 -0700 | [diff] [blame] | 9362 | mUnfocusedWindow->consumeMotionDown(); |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 9363 | |
Siarhei Vishniakou | 2bfa905 | 2019-11-21 18:10:54 -0800 | [diff] [blame] | 9364 | ASSERT_TRUE(mDispatcher->waitForIdle()); |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 9365 | mFakePolicy->assertOnPointerDownEquals(mUnfocusedWindow->getToken()); |
| 9366 | } |
| 9367 | |
| 9368 | // Have two windows, one with focus. Inject MotionEvent with source TRACKBALL and action |
| 9369 | // DOWN on the window that doesn't have focus. Ensure no window received the |
| 9370 | // onPointerDownOutsideFocus callback. |
| 9371 | TEST_F(InputDispatcherOnPointerDownOutsideFocus, OnPointerDownOutsideFocus_NonPointerSource) { |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 9372 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9373 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TRACKBALL, ui::LogicalDisplayId::DEFAULT, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 9374 | {20, 20})) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 9375 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | 03aee2a | 2020-04-13 20:44:54 -0700 | [diff] [blame] | 9376 | mFocusedWindow->consumeMotionDown(); |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 9377 | |
Siarhei Vishniakou | 2bfa905 | 2019-11-21 18:10:54 -0800 | [diff] [blame] | 9378 | ASSERT_TRUE(mDispatcher->waitForIdle()); |
| 9379 | mFakePolicy->assertOnPointerDownWasNotCalled(); |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 9380 | } |
| 9381 | |
| 9382 | // Have two windows, one with focus. Inject KeyEvent with action DOWN on the window that doesn't |
| 9383 | // have focus. Ensure no window received the onPointerDownOutsideFocus callback. |
| 9384 | TEST_F(InputDispatcherOnPointerDownOutsideFocus, OnPointerDownOutsideFocus_NonMotionFailure) { |
Prabir Pradhan | 93f342c | 2021-03-11 15:05:30 -0800 | [diff] [blame] | 9385 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9386 | injectKeyDownNoRepeat(*mDispatcher, ui::LogicalDisplayId::DEFAULT)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 9387 | << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9388 | mFocusedWindow->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 9389 | |
Siarhei Vishniakou | 2bfa905 | 2019-11-21 18:10:54 -0800 | [diff] [blame] | 9390 | ASSERT_TRUE(mDispatcher->waitForIdle()); |
| 9391 | mFakePolicy->assertOnPointerDownWasNotCalled(); |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 9392 | } |
| 9393 | |
| 9394 | // Have two windows, one with focus. Inject MotionEvent with source TOUCHSCREEN and action |
| 9395 | // DOWN on the window that already has focus. Ensure no window received the |
| 9396 | // onPointerDownOutsideFocus callback. |
Siarhei Vishniakou | 870ecec | 2020-12-09 08:07:46 -1000 | [diff] [blame] | 9397 | TEST_F(InputDispatcherOnPointerDownOutsideFocus, OnPointerDownOutsideFocus_OnAlreadyFocusedWindow) { |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 9398 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9399 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 9400 | ui::LogicalDisplayId::DEFAULT, FOCUSED_WINDOW_TOUCH_POINT)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 9401 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | 03aee2a | 2020-04-13 20:44:54 -0700 | [diff] [blame] | 9402 | mFocusedWindow->consumeMotionDown(); |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 9403 | |
Siarhei Vishniakou | 2bfa905 | 2019-11-21 18:10:54 -0800 | [diff] [blame] | 9404 | ASSERT_TRUE(mDispatcher->waitForIdle()); |
| 9405 | mFakePolicy->assertOnPointerDownWasNotCalled(); |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 9406 | } |
| 9407 | |
Prabir Pradhan | 47cf0a0 | 2021-03-11 20:30:57 -0800 | [diff] [blame] | 9408 | // Have two windows, one with focus. Injecting a trusted DOWN MotionEvent with the flag |
| 9409 | // NO_FOCUS_CHANGE on the unfocused window should not call the onPointerDownOutsideFocus callback. |
| 9410 | TEST_F(InputDispatcherOnPointerDownOutsideFocus, NoFocusChangeFlag) { |
| 9411 | const MotionEvent event = |
| 9412 | MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_MOUSE) |
| 9413 | .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 9414 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(20).y(20)) |
Prabir Pradhan | 47cf0a0 | 2021-03-11 20:30:57 -0800 | [diff] [blame] | 9415 | .addFlag(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE) |
| 9416 | .build(); |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 9417 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(*mDispatcher, event)) |
Prabir Pradhan | 47cf0a0 | 2021-03-11 20:30:57 -0800 | [diff] [blame] | 9418 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9419 | mUnfocusedWindow->consumeAnyMotionDown(ui::LogicalDisplayId::DEFAULT, |
| 9420 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
Prabir Pradhan | 47cf0a0 | 2021-03-11 20:30:57 -0800 | [diff] [blame] | 9421 | |
| 9422 | ASSERT_TRUE(mDispatcher->waitForIdle()); |
| 9423 | mFakePolicy->assertOnPointerDownWasNotCalled(); |
| 9424 | // Ensure that the unfocused window did not receive any FOCUS events. |
| 9425 | mUnfocusedWindow->assertNoEvents(); |
| 9426 | } |
| 9427 | |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 9428 | // These tests ensures we can send touch events to a single client when there are multiple input |
| 9429 | // windows that point to the same client token. |
| 9430 | class InputDispatcherMultiWindowSameTokenTests : public InputDispatcherTest { |
| 9431 | virtual void SetUp() override { |
| 9432 | InputDispatcherTest::SetUp(); |
| 9433 | |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 9434 | std::shared_ptr<FakeApplicationHandle> application = |
| 9435 | std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 9436 | mWindow1 = sp<FakeWindowHandle>::make(application, mDispatcher, "Fake Window 1", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9437 | ui::LogicalDisplayId::DEFAULT); |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 9438 | mWindow1->setFrame(Rect(0, 0, 100, 100)); |
| 9439 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9440 | mWindow2 = mWindow1->clone(ui::LogicalDisplayId::DEFAULT); |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 9441 | mWindow2->setFrame(Rect(100, 100, 200, 200)); |
| 9442 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 9443 | mDispatcher->onWindowInfosChanged({{*mWindow1->getInfo(), *mWindow2->getInfo()}, {}, 0, 0}); |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 9444 | } |
| 9445 | |
| 9446 | protected: |
| 9447 | sp<FakeWindowHandle> mWindow1; |
| 9448 | sp<FakeWindowHandle> mWindow2; |
| 9449 | |
| 9450 | // Helper function to convert the point from screen coordinates into the window's space |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 9451 | static PointF getPointInWindow(const WindowInfo* windowInfo, const PointF& point) { |
chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 9452 | vec2 vals = windowInfo->transform.transform(point.x, point.y); |
| 9453 | return {vals.x, vals.y}; |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 9454 | } |
| 9455 | |
| 9456 | void consumeMotionEvent(const sp<FakeWindowHandle>& window, int32_t expectedAction, |
| 9457 | const std::vector<PointF>& points) { |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 9458 | const std::string name = window->getName(); |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 9459 | std::unique_ptr<MotionEvent> motionEvent = |
Prabir Pradhan | 7662a8d | 2023-12-15 01:58:14 +0000 | [diff] [blame] | 9460 | window->consumeMotionEvent(WithMotionAction(expectedAction)); |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 9461 | ASSERT_NE(nullptr, motionEvent); |
| 9462 | ASSERT_EQ(points.size(), motionEvent->getPointerCount()); |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 9463 | |
| 9464 | for (size_t i = 0; i < points.size(); i++) { |
| 9465 | float expectedX = points[i].x; |
| 9466 | float expectedY = points[i].y; |
| 9467 | |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 9468 | EXPECT_EQ(expectedX, motionEvent->getX(i)) |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 9469 | << "expected " << expectedX << " for x[" << i << "] coord of " << name.c_str() |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 9470 | << ", got " << motionEvent->getX(i); |
| 9471 | EXPECT_EQ(expectedY, motionEvent->getY(i)) |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 9472 | << "expected " << expectedY << " for y[" << i << "] coord of " << name.c_str() |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 9473 | << ", got " << motionEvent->getY(i); |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 9474 | } |
| 9475 | } |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 9476 | |
Prabir Pradhan | bb3f1c0 | 2024-01-04 20:17:14 +0000 | [diff] [blame] | 9477 | void touchAndAssertPositions(sp<FakeWindowHandle> touchedWindow, int32_t action, |
| 9478 | const std::vector<PointF>& touchedPoints, |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 9479 | std::vector<PointF> expectedPoints) { |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 9480 | mDispatcher->notifyMotion(generateMotionArgs(action, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9481 | ui::LogicalDisplayId::DEFAULT, touchedPoints)); |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 9482 | |
Prabir Pradhan | bb3f1c0 | 2024-01-04 20:17:14 +0000 | [diff] [blame] | 9483 | consumeMotionEvent(touchedWindow, action, expectedPoints); |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 9484 | } |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 9485 | }; |
| 9486 | |
| 9487 | TEST_F(InputDispatcherMultiWindowSameTokenTests, SingleTouchSameScale) { |
| 9488 | // Touch Window 1 |
| 9489 | PointF touchedPoint = {10, 10}; |
| 9490 | PointF expectedPoint = getPointInWindow(mWindow1->getInfo(), touchedPoint); |
Prabir Pradhan | bb3f1c0 | 2024-01-04 20:17:14 +0000 | [diff] [blame] | 9491 | touchAndAssertPositions(mWindow1, AMOTION_EVENT_ACTION_DOWN, {touchedPoint}, {expectedPoint}); |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 9492 | |
| 9493 | // Release touch on Window 1 |
Prabir Pradhan | bb3f1c0 | 2024-01-04 20:17:14 +0000 | [diff] [blame] | 9494 | touchAndAssertPositions(mWindow1, AMOTION_EVENT_ACTION_UP, {touchedPoint}, {expectedPoint}); |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 9495 | |
| 9496 | // Touch Window 2 |
| 9497 | touchedPoint = {150, 150}; |
| 9498 | expectedPoint = getPointInWindow(mWindow2->getInfo(), touchedPoint); |
Prabir Pradhan | bb3f1c0 | 2024-01-04 20:17:14 +0000 | [diff] [blame] | 9499 | touchAndAssertPositions(mWindow2, AMOTION_EVENT_ACTION_DOWN, {touchedPoint}, {expectedPoint}); |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 9500 | } |
| 9501 | |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 9502 | TEST_F(InputDispatcherMultiWindowSameTokenTests, SingleTouchDifferentTransform) { |
| 9503 | // Set scale value for window2 |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 9504 | mWindow2->setWindowScale(0.5f, 0.5f); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 9505 | mDispatcher->onWindowInfosChanged({{*mWindow1->getInfo(), *mWindow2->getInfo()}, {}, 0, 0}); |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 9506 | |
| 9507 | // Touch Window 1 |
| 9508 | PointF touchedPoint = {10, 10}; |
| 9509 | PointF expectedPoint = getPointInWindow(mWindow1->getInfo(), touchedPoint); |
Prabir Pradhan | bb3f1c0 | 2024-01-04 20:17:14 +0000 | [diff] [blame] | 9510 | touchAndAssertPositions(mWindow1, AMOTION_EVENT_ACTION_DOWN, {touchedPoint}, {expectedPoint}); |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 9511 | // Release touch on Window 1 |
Prabir Pradhan | bb3f1c0 | 2024-01-04 20:17:14 +0000 | [diff] [blame] | 9512 | touchAndAssertPositions(mWindow1, AMOTION_EVENT_ACTION_UP, {touchedPoint}, {expectedPoint}); |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 9513 | |
| 9514 | // Touch Window 2 |
| 9515 | touchedPoint = {150, 150}; |
| 9516 | expectedPoint = getPointInWindow(mWindow2->getInfo(), touchedPoint); |
Prabir Pradhan | bb3f1c0 | 2024-01-04 20:17:14 +0000 | [diff] [blame] | 9517 | touchAndAssertPositions(mWindow2, AMOTION_EVENT_ACTION_DOWN, {touchedPoint}, {expectedPoint}); |
| 9518 | touchAndAssertPositions(mWindow2, AMOTION_EVENT_ACTION_UP, {touchedPoint}, {expectedPoint}); |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 9519 | |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 9520 | // Update the transform so rotation is set |
| 9521 | mWindow2->setWindowTransform(0, -1, 1, 0); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 9522 | mDispatcher->onWindowInfosChanged({{*mWindow1->getInfo(), *mWindow2->getInfo()}, {}, 0, 0}); |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 9523 | expectedPoint = getPointInWindow(mWindow2->getInfo(), touchedPoint); |
Prabir Pradhan | bb3f1c0 | 2024-01-04 20:17:14 +0000 | [diff] [blame] | 9524 | touchAndAssertPositions(mWindow2, AMOTION_EVENT_ACTION_DOWN, {touchedPoint}, {expectedPoint}); |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 9525 | } |
| 9526 | |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 9527 | TEST_F(InputDispatcherMultiWindowSameTokenTests, MultipleTouchDifferentTransform) { |
Chavi Weingarten | 65f98b8 | 2020-01-16 18:56:50 +0000 | [diff] [blame] | 9528 | mWindow2->setWindowScale(0.5f, 0.5f); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 9529 | mDispatcher->onWindowInfosChanged({{*mWindow1->getInfo(), *mWindow2->getInfo()}, {}, 0, 0}); |
Chavi Weingarten | 65f98b8 | 2020-01-16 18:56:50 +0000 | [diff] [blame] | 9530 | |
| 9531 | // Touch Window 1 |
| 9532 | std::vector<PointF> touchedPoints = {PointF{10, 10}}; |
| 9533 | std::vector<PointF> expectedPoints = {getPointInWindow(mWindow1->getInfo(), touchedPoints[0])}; |
Prabir Pradhan | bb3f1c0 | 2024-01-04 20:17:14 +0000 | [diff] [blame] | 9534 | touchAndAssertPositions(mWindow1, AMOTION_EVENT_ACTION_DOWN, touchedPoints, expectedPoints); |
Chavi Weingarten | 65f98b8 | 2020-01-16 18:56:50 +0000 | [diff] [blame] | 9535 | |
| 9536 | // Touch Window 2 |
Prabir Pradhan | bb3f1c0 | 2024-01-04 20:17:14 +0000 | [diff] [blame] | 9537 | // Since this is part of the same touch gesture that has already been dispatched to Window 1, |
| 9538 | // the touch stream from Window 2 will be merged with the stream in Window 1. The merged stream |
| 9539 | // will continue to be dispatched through Window 1. |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 9540 | touchedPoints.push_back(PointF{150, 150}); |
| 9541 | expectedPoints.push_back(getPointInWindow(mWindow2->getInfo(), touchedPoints[1])); |
Prabir Pradhan | bb3f1c0 | 2024-01-04 20:17:14 +0000 | [diff] [blame] | 9542 | touchAndAssertPositions(mWindow1, POINTER_1_DOWN, touchedPoints, expectedPoints); |
Chavi Weingarten | 65f98b8 | 2020-01-16 18:56:50 +0000 | [diff] [blame] | 9543 | |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 9544 | // Release Window 2 |
Prabir Pradhan | bb3f1c0 | 2024-01-04 20:17:14 +0000 | [diff] [blame] | 9545 | touchAndAssertPositions(mWindow1, POINTER_1_UP, touchedPoints, expectedPoints); |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 9546 | expectedPoints.pop_back(); |
Chavi Weingarten | 65f98b8 | 2020-01-16 18:56:50 +0000 | [diff] [blame] | 9547 | |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 9548 | // Update the transform so rotation is set for Window 2 |
| 9549 | mWindow2->setWindowTransform(0, -1, 1, 0); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 9550 | mDispatcher->onWindowInfosChanged({{*mWindow1->getInfo(), *mWindow2->getInfo()}, {}, 0, 0}); |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 9551 | expectedPoints.push_back(getPointInWindow(mWindow2->getInfo(), touchedPoints[1])); |
Prabir Pradhan | bb3f1c0 | 2024-01-04 20:17:14 +0000 | [diff] [blame] | 9552 | touchAndAssertPositions(mWindow1, POINTER_1_DOWN, touchedPoints, expectedPoints); |
Chavi Weingarten | 65f98b8 | 2020-01-16 18:56:50 +0000 | [diff] [blame] | 9553 | } |
| 9554 | |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 9555 | TEST_F(InputDispatcherMultiWindowSameTokenTests, MultipleTouchMoveDifferentTransform) { |
Chavi Weingarten | 65f98b8 | 2020-01-16 18:56:50 +0000 | [diff] [blame] | 9556 | mWindow2->setWindowScale(0.5f, 0.5f); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 9557 | mDispatcher->onWindowInfosChanged({{*mWindow1->getInfo(), *mWindow2->getInfo()}, {}, 0, 0}); |
Chavi Weingarten | 65f98b8 | 2020-01-16 18:56:50 +0000 | [diff] [blame] | 9558 | |
| 9559 | // Touch Window 1 |
| 9560 | std::vector<PointF> touchedPoints = {PointF{10, 10}}; |
| 9561 | std::vector<PointF> expectedPoints = {getPointInWindow(mWindow1->getInfo(), touchedPoints[0])}; |
Prabir Pradhan | bb3f1c0 | 2024-01-04 20:17:14 +0000 | [diff] [blame] | 9562 | touchAndAssertPositions(mWindow1, AMOTION_EVENT_ACTION_DOWN, touchedPoints, expectedPoints); |
Chavi Weingarten | 65f98b8 | 2020-01-16 18:56:50 +0000 | [diff] [blame] | 9563 | |
| 9564 | // Touch Window 2 |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 9565 | touchedPoints.push_back(PointF{150, 150}); |
| 9566 | expectedPoints.push_back(getPointInWindow(mWindow2->getInfo(), touchedPoints[1])); |
Chavi Weingarten | 65f98b8 | 2020-01-16 18:56:50 +0000 | [diff] [blame] | 9567 | |
Prabir Pradhan | bb3f1c0 | 2024-01-04 20:17:14 +0000 | [diff] [blame] | 9568 | touchAndAssertPositions(mWindow1, POINTER_1_DOWN, touchedPoints, expectedPoints); |
Chavi Weingarten | 65f98b8 | 2020-01-16 18:56:50 +0000 | [diff] [blame] | 9569 | |
| 9570 | // Move both windows |
| 9571 | touchedPoints = {{20, 20}, {175, 175}}; |
| 9572 | expectedPoints = {getPointInWindow(mWindow1->getInfo(), touchedPoints[0]), |
| 9573 | getPointInWindow(mWindow2->getInfo(), touchedPoints[1])}; |
| 9574 | |
Prabir Pradhan | bb3f1c0 | 2024-01-04 20:17:14 +0000 | [diff] [blame] | 9575 | touchAndAssertPositions(mWindow1, AMOTION_EVENT_ACTION_MOVE, touchedPoints, expectedPoints); |
Chavi Weingarten | 65f98b8 | 2020-01-16 18:56:50 +0000 | [diff] [blame] | 9576 | |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 9577 | // Release Window 2 |
Prabir Pradhan | bb3f1c0 | 2024-01-04 20:17:14 +0000 | [diff] [blame] | 9578 | touchAndAssertPositions(mWindow1, POINTER_1_UP, touchedPoints, expectedPoints); |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 9579 | expectedPoints.pop_back(); |
| 9580 | |
| 9581 | // Touch Window 2 |
| 9582 | mWindow2->setWindowTransform(0, -1, 1, 0); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 9583 | mDispatcher->onWindowInfosChanged({{*mWindow1->getInfo(), *mWindow2->getInfo()}, {}, 0, 0}); |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 9584 | expectedPoints.push_back(getPointInWindow(mWindow2->getInfo(), touchedPoints[1])); |
Prabir Pradhan | bb3f1c0 | 2024-01-04 20:17:14 +0000 | [diff] [blame] | 9585 | touchAndAssertPositions(mWindow1, POINTER_1_DOWN, touchedPoints, expectedPoints); |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 9586 | |
| 9587 | // Move both windows |
| 9588 | touchedPoints = {{20, 20}, {175, 175}}; |
| 9589 | expectedPoints = {getPointInWindow(mWindow1->getInfo(), touchedPoints[0]), |
| 9590 | getPointInWindow(mWindow2->getInfo(), touchedPoints[1])}; |
| 9591 | |
Prabir Pradhan | bb3f1c0 | 2024-01-04 20:17:14 +0000 | [diff] [blame] | 9592 | touchAndAssertPositions(mWindow1, AMOTION_EVENT_ACTION_MOVE, touchedPoints, expectedPoints); |
Chavi Weingarten | 65f98b8 | 2020-01-16 18:56:50 +0000 | [diff] [blame] | 9593 | } |
| 9594 | |
| 9595 | TEST_F(InputDispatcherMultiWindowSameTokenTests, MultipleWindowsFirstTouchWithScale) { |
| 9596 | mWindow1->setWindowScale(0.5f, 0.5f); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 9597 | mDispatcher->onWindowInfosChanged({{*mWindow1->getInfo(), *mWindow2->getInfo()}, {}, 0, 0}); |
Chavi Weingarten | 65f98b8 | 2020-01-16 18:56:50 +0000 | [diff] [blame] | 9598 | |
| 9599 | // Touch Window 1 |
| 9600 | std::vector<PointF> touchedPoints = {PointF{10, 10}}; |
| 9601 | std::vector<PointF> expectedPoints = {getPointInWindow(mWindow1->getInfo(), touchedPoints[0])}; |
Prabir Pradhan | bb3f1c0 | 2024-01-04 20:17:14 +0000 | [diff] [blame] | 9602 | touchAndAssertPositions(mWindow1, AMOTION_EVENT_ACTION_DOWN, touchedPoints, expectedPoints); |
Chavi Weingarten | 65f98b8 | 2020-01-16 18:56:50 +0000 | [diff] [blame] | 9603 | |
| 9604 | // Touch Window 2 |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 9605 | touchedPoints.push_back(PointF{150, 150}); |
| 9606 | expectedPoints.push_back(getPointInWindow(mWindow2->getInfo(), touchedPoints[1])); |
Chavi Weingarten | 65f98b8 | 2020-01-16 18:56:50 +0000 | [diff] [blame] | 9607 | |
Prabir Pradhan | bb3f1c0 | 2024-01-04 20:17:14 +0000 | [diff] [blame] | 9608 | touchAndAssertPositions(mWindow1, POINTER_1_DOWN, touchedPoints, expectedPoints); |
Chavi Weingarten | 65f98b8 | 2020-01-16 18:56:50 +0000 | [diff] [blame] | 9609 | |
| 9610 | // Move both windows |
| 9611 | touchedPoints = {{20, 20}, {175, 175}}; |
| 9612 | expectedPoints = {getPointInWindow(mWindow1->getInfo(), touchedPoints[0]), |
| 9613 | getPointInWindow(mWindow2->getInfo(), touchedPoints[1])}; |
| 9614 | |
Prabir Pradhan | bb3f1c0 | 2024-01-04 20:17:14 +0000 | [diff] [blame] | 9615 | touchAndAssertPositions(mWindow1, AMOTION_EVENT_ACTION_MOVE, touchedPoints, expectedPoints); |
Chavi Weingarten | 65f98b8 | 2020-01-16 18:56:50 +0000 | [diff] [blame] | 9616 | } |
| 9617 | |
Siarhei Vishniakou | 0f6558d | 2023-04-21 12:05:13 -0700 | [diff] [blame] | 9618 | /** |
| 9619 | * When one of the windows is slippery, the touch should not slip into the other window with the |
| 9620 | * same input channel. |
| 9621 | */ |
| 9622 | TEST_F(InputDispatcherMultiWindowSameTokenTests, TouchDoesNotSlipEvenIfSlippery) { |
| 9623 | mWindow1->setSlippery(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 9624 | mDispatcher->onWindowInfosChanged({{*mWindow1->getInfo(), *mWindow2->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | 0f6558d | 2023-04-21 12:05:13 -0700 | [diff] [blame] | 9625 | |
| 9626 | // Touch down in window 1 |
| 9627 | mDispatcher->notifyMotion(generateMotionArgs(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9628 | ui::LogicalDisplayId::DEFAULT, {{50, 50}})); |
Siarhei Vishniakou | 0f6558d | 2023-04-21 12:05:13 -0700 | [diff] [blame] | 9629 | consumeMotionEvent(mWindow1, ACTION_DOWN, {{50, 50}}); |
| 9630 | |
| 9631 | // Move touch to be above window 2. Even though window 1 is slippery, touch should not slip. |
| 9632 | // That means the gesture should continue normally, without any ACTION_CANCEL or ACTION_DOWN |
| 9633 | // getting generated. |
| 9634 | mDispatcher->notifyMotion(generateMotionArgs(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9635 | ui::LogicalDisplayId::DEFAULT, {{150, 150}})); |
Siarhei Vishniakou | 0f6558d | 2023-04-21 12:05:13 -0700 | [diff] [blame] | 9636 | |
| 9637 | consumeMotionEvent(mWindow1, ACTION_MOVE, {{150, 150}}); |
| 9638 | } |
| 9639 | |
Siarhei Vishniakou | d5876ba | 2023-05-15 17:58:34 -0700 | [diff] [blame] | 9640 | /** |
| 9641 | * When hover starts in one window and continues into the other, there should be a HOVER_EXIT and |
| 9642 | * a HOVER_ENTER generated, even if the windows have the same token. This is because the new window |
| 9643 | * that the pointer is hovering over may have a different transform. |
| 9644 | */ |
| 9645 | TEST_F(InputDispatcherMultiWindowSameTokenTests, HoverIntoClone) { |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 9646 | mDispatcher->onWindowInfosChanged({{*mWindow1->getInfo(), *mWindow2->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | d5876ba | 2023-05-15 17:58:34 -0700 | [diff] [blame] | 9647 | |
| 9648 | // Start hover in window 1 |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 9649 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_TOUCHSCREEN) |
| 9650 | .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) |
| 9651 | .build()); |
Siarhei Vishniakou | d5876ba | 2023-05-15 17:58:34 -0700 | [diff] [blame] | 9652 | consumeMotionEvent(mWindow1, ACTION_HOVER_ENTER, |
| 9653 | {getPointInWindow(mWindow1->getInfo(), PointF{50, 50})}); |
Siarhei Vishniakou | d5876ba | 2023-05-15 17:58:34 -0700 | [diff] [blame] | 9654 | // Move hover to window 2. |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 9655 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 9656 | .pointer(PointerBuilder(0, ToolType::FINGER).x(150).y(150)) |
| 9657 | .build()); |
Siarhei Vishniakou | d5876ba | 2023-05-15 17:58:34 -0700 | [diff] [blame] | 9658 | consumeMotionEvent(mWindow1, ACTION_HOVER_EXIT, {{50, 50}}); |
Prabir Pradhan | bb3f1c0 | 2024-01-04 20:17:14 +0000 | [diff] [blame] | 9659 | consumeMotionEvent(mWindow2, ACTION_HOVER_ENTER, |
Siarhei Vishniakou | d5876ba | 2023-05-15 17:58:34 -0700 | [diff] [blame] | 9660 | {getPointInWindow(mWindow2->getInfo(), PointF{150, 150})}); |
| 9661 | } |
| 9662 | |
Siarhei Vishniakou | 4cb50ca | 2020-05-26 21:43:02 -0700 | [diff] [blame] | 9663 | class InputDispatcherSingleWindowAnr : public InputDispatcherTest { |
| 9664 | virtual void SetUp() override { |
| 9665 | InputDispatcherTest::SetUp(); |
| 9666 | |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 9667 | mApplication = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | f83c693 | 2023-07-07 17:48:10 -0700 | [diff] [blame] | 9668 | mApplication->setDispatchingTimeout(100ms); |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 9669 | mWindow = sp<FakeWindowHandle>::make(mApplication, mDispatcher, "TestWindow", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9670 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 4cb50ca | 2020-05-26 21:43:02 -0700 | [diff] [blame] | 9671 | mWindow->setFrame(Rect(0, 0, 30, 30)); |
Siarhei Vishniakou | f83c693 | 2023-07-07 17:48:10 -0700 | [diff] [blame] | 9672 | mWindow->setDispatchingTimeout(100ms); |
Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 9673 | mWindow->setFocusable(true); |
Siarhei Vishniakou | 4cb50ca | 2020-05-26 21:43:02 -0700 | [diff] [blame] | 9674 | |
| 9675 | // Set focused application. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9676 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, mApplication); |
Siarhei Vishniakou | 4cb50ca | 2020-05-26 21:43:02 -0700 | [diff] [blame] | 9677 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 9678 | mDispatcher->onWindowInfosChanged({{*mWindow->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 9679 | setFocusedWindow(mWindow); |
Siarhei Vishniakou | 4cb50ca | 2020-05-26 21:43:02 -0700 | [diff] [blame] | 9680 | mWindow->consumeFocusEvent(true); |
| 9681 | } |
| 9682 | |
| 9683 | virtual void TearDown() override { |
| 9684 | InputDispatcherTest::TearDown(); |
| 9685 | mWindow.clear(); |
| 9686 | } |
| 9687 | |
| 9688 | protected: |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 9689 | static constexpr std::chrono::duration SPY_TIMEOUT = 200ms; |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 9690 | std::shared_ptr<FakeApplicationHandle> mApplication; |
Siarhei Vishniakou | 4cb50ca | 2020-05-26 21:43:02 -0700 | [diff] [blame] | 9691 | sp<FakeWindowHandle> mWindow; |
| 9692 | static constexpr PointF WINDOW_LOCATION = {20, 20}; |
| 9693 | |
| 9694 | void tapOnWindow() { |
Siarhei Vishniakou | 67bf216 | 2023-11-16 13:29:50 -0800 | [diff] [blame] | 9695 | const auto touchingPointer = PointerBuilder(/*id=*/0, ToolType::FINGER) |
| 9696 | .x(WINDOW_LOCATION.x) |
| 9697 | .y(WINDOW_LOCATION.y); |
| 9698 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 9699 | .pointer(touchingPointer) |
| 9700 | .build()); |
| 9701 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN) |
| 9702 | .pointer(touchingPointer) |
| 9703 | .build()); |
Siarhei Vishniakou | 4cb50ca | 2020-05-26 21:43:02 -0700 | [diff] [blame] | 9704 | } |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 9705 | |
| 9706 | sp<FakeWindowHandle> addSpyWindow() { |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9707 | sp<FakeWindowHandle> spy = sp<FakeWindowHandle>::make(mApplication, mDispatcher, "Spy", |
| 9708 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 9709 | spy->setTrustedOverlay(true); |
| 9710 | spy->setFocusable(false); |
Prabir Pradhan | 51e7db0 | 2022-02-07 06:02:57 -0800 | [diff] [blame] | 9711 | spy->setSpy(true); |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 9712 | spy->setDispatchingTimeout(SPY_TIMEOUT); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 9713 | mDispatcher->onWindowInfosChanged({{*spy->getInfo(), *mWindow->getInfo()}, {}, 0, 0}); |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 9714 | return spy; |
| 9715 | } |
Siarhei Vishniakou | 4cb50ca | 2020-05-26 21:43:02 -0700 | [diff] [blame] | 9716 | }; |
| 9717 | |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9718 | // Send a tap and respond, which should not cause an ANR. |
| 9719 | TEST_F(InputDispatcherSingleWindowAnr, WhenTouchIsConsumed_NoAnr) { |
| 9720 | tapOnWindow(); |
| 9721 | mWindow->consumeMotionDown(); |
| 9722 | mWindow->consumeMotionUp(); |
| 9723 | ASSERT_TRUE(mDispatcher->waitForIdle()); |
| 9724 | mFakePolicy->assertNotifyAnrWasNotCalled(); |
| 9725 | } |
| 9726 | |
| 9727 | // Send a regular key and respond, which should not cause an ANR. |
| 9728 | TEST_F(InputDispatcherSingleWindowAnr, WhenKeyIsConsumed_NoAnr) { |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 9729 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDownNoRepeat(*mDispatcher)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9730 | mWindow->consumeKeyDown(ui::LogicalDisplayId::INVALID); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9731 | ASSERT_TRUE(mDispatcher->waitForIdle()); |
| 9732 | mFakePolicy->assertNotifyAnrWasNotCalled(); |
| 9733 | } |
| 9734 | |
Siarhei Vishniakou | e41c451 | 2020-09-08 19:35:58 -0500 | [diff] [blame] | 9735 | TEST_F(InputDispatcherSingleWindowAnr, WhenFocusedApplicationChanges_NoAnr) { |
| 9736 | mWindow->setFocusable(false); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 9737 | mDispatcher->onWindowInfosChanged({{*mWindow->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | e41c451 | 2020-09-08 19:35:58 -0500 | [diff] [blame] | 9738 | mWindow->consumeFocusEvent(false); |
| 9739 | |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 9740 | InputEventInjectionResult result = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9741 | injectKey(*mDispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, |
| 9742 | ui::LogicalDisplayId::DEFAULT, InputEventInjectionSync::NONE, |
| 9743 | CONSUME_TIMEOUT_EVENT_EXPECTED, |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 9744 | /*allowKeyRepeat=*/false); |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 9745 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, result); |
Siarhei Vishniakou | e41c451 | 2020-09-08 19:35:58 -0500 | [diff] [blame] | 9746 | // Key will not go to window because we have no focused window. |
| 9747 | // The 'no focused window' ANR timer should start instead. |
| 9748 | |
| 9749 | // Now, the focused application goes away. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9750 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, nullptr); |
Siarhei Vishniakou | e41c451 | 2020-09-08 19:35:58 -0500 | [diff] [blame] | 9751 | // The key should get dropped and there should be no ANR. |
| 9752 | |
| 9753 | ASSERT_TRUE(mDispatcher->waitForIdle()); |
| 9754 | mFakePolicy->assertNotifyAnrWasNotCalled(); |
| 9755 | } |
| 9756 | |
Siarhei Vishniakou | 4cb50ca | 2020-05-26 21:43:02 -0700 | [diff] [blame] | 9757 | // Send an event to the app and have the app not respond right away. |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9758 | // When ANR is raised, policy will tell the dispatcher to cancel the events for that window. |
| 9759 | // So InputDispatcher will enqueue ACTION_CANCEL event as well. |
Siarhei Vishniakou | 4cb50ca | 2020-05-26 21:43:02 -0700 | [diff] [blame] | 9760 | TEST_F(InputDispatcherSingleWindowAnr, OnPointerDown_BasicAnr) { |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 9761 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9762 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 9763 | ui::LogicalDisplayId::DEFAULT, WINDOW_LOCATION)); |
Siarhei Vishniakou | 4cb50ca | 2020-05-26 21:43:02 -0700 | [diff] [blame] | 9764 | |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 9765 | const auto [sequenceNum, _] = mWindow->receiveEvent(); // ACTION_DOWN |
Siarhei Vishniakou | 4cb50ca | 2020-05-26 21:43:02 -0700 | [diff] [blame] | 9766 | ASSERT_TRUE(sequenceNum); |
| 9767 | const std::chrono::duration timeout = mWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT); |
Prabir Pradhan | edd9640 | 2022-02-15 01:46:16 -0800 | [diff] [blame] | 9768 | mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(timeout, mWindow); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9769 | |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9770 | mWindow->finishEvent(*sequenceNum); |
Siarhei Vishniakou | 1ae72f1 | 2023-01-29 12:55:30 -0800 | [diff] [blame] | 9771 | mWindow->consumeMotionEvent( |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9772 | AllOf(WithMotionAction(ACTION_CANCEL), WithDisplayId(ui::LogicalDisplayId::DEFAULT))); |
Siarhei Vishniakou | 4cb50ca | 2020-05-26 21:43:02 -0700 | [diff] [blame] | 9773 | ASSERT_TRUE(mDispatcher->waitForIdle()); |
Prabir Pradhan | edd9640 | 2022-02-15 01:46:16 -0800 | [diff] [blame] | 9774 | mFakePolicy->assertNotifyWindowResponsiveWasCalled(mWindow->getToken(), mWindow->getPid()); |
Siarhei Vishniakou | 4cb50ca | 2020-05-26 21:43:02 -0700 | [diff] [blame] | 9775 | } |
| 9776 | |
| 9777 | // Send a key to the app and have the app not respond right away. |
| 9778 | TEST_F(InputDispatcherSingleWindowAnr, OnKeyDown_BasicAnr) { |
| 9779 | // Inject a key, and don't respond - expect that ANR is called. |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 9780 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDownNoRepeat(*mDispatcher)); |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 9781 | const auto [sequenceNum, _] = mWindow->receiveEvent(); |
Siarhei Vishniakou | 4cb50ca | 2020-05-26 21:43:02 -0700 | [diff] [blame] | 9782 | ASSERT_TRUE(sequenceNum); |
Siarhei Vishniakou | 4cb50ca | 2020-05-26 21:43:02 -0700 | [diff] [blame] | 9783 | const std::chrono::duration timeout = mWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT); |
Prabir Pradhan | edd9640 | 2022-02-15 01:46:16 -0800 | [diff] [blame] | 9784 | mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(timeout, mWindow); |
Siarhei Vishniakou | 4cb50ca | 2020-05-26 21:43:02 -0700 | [diff] [blame] | 9785 | ASSERT_TRUE(mDispatcher->waitForIdle()); |
| 9786 | } |
| 9787 | |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9788 | // We have a focused application, but no focused window |
| 9789 | TEST_F(InputDispatcherSingleWindowAnr, FocusedApplication_NoFocusedWindow) { |
Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 9790 | mWindow->setFocusable(false); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 9791 | mDispatcher->onWindowInfosChanged({{*mWindow->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9792 | mWindow->consumeFocusEvent(false); |
| 9793 | |
| 9794 | // taps on the window work as normal |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 9795 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9796 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 9797 | ui::LogicalDisplayId::DEFAULT, WINDOW_LOCATION)); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9798 | ASSERT_NO_FATAL_FAILURE(mWindow->consumeMotionDown()); |
| 9799 | mDispatcher->waitForIdle(); |
| 9800 | mFakePolicy->assertNotifyAnrWasNotCalled(); |
| 9801 | |
| 9802 | // Once a focused event arrives, we get an ANR for this application |
| 9803 | // We specify the injection timeout to be smaller than the application timeout, to ensure that |
| 9804 | // injection times out (instead of failing). |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 9805 | const InputEventInjectionResult result = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9806 | injectKey(*mDispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, |
| 9807 | ui::LogicalDisplayId::DEFAULT, InputEventInjectionSync::WAIT_FOR_RESULT, 50ms, |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 9808 | /*allowKeyRepeat=*/false); |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 9809 | ASSERT_EQ(InputEventInjectionResult::TIMED_OUT, result); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9810 | const std::chrono::duration timeout = mApplication->getDispatchingTimeout(DISPATCHING_TIMEOUT); |
Vishnu Nair | e4df875 | 2022-09-08 09:17:55 -0700 | [diff] [blame] | 9811 | mFakePolicy->assertNotifyNoFocusedWindowAnrWasCalled(timeout, mApplication); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9812 | ASSERT_TRUE(mDispatcher->waitForIdle()); |
| 9813 | } |
| 9814 | |
Siarhei Vishniakou | 289e924 | 2022-02-15 14:50:16 -0800 | [diff] [blame] | 9815 | /** |
| 9816 | * Make sure the stale key is dropped before causing an ANR. So even if there's no focused window, |
| 9817 | * there will not be an ANR. |
| 9818 | */ |
| 9819 | TEST_F(InputDispatcherSingleWindowAnr, StaleKeyEventDoesNotAnr) { |
| 9820 | mWindow->setFocusable(false); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 9821 | mDispatcher->onWindowInfosChanged({{*mWindow->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | 289e924 | 2022-02-15 14:50:16 -0800 | [diff] [blame] | 9822 | mWindow->consumeFocusEvent(false); |
| 9823 | |
| 9824 | KeyEvent event; |
Siarhei Vishniakou | a733311 | 2023-10-27 13:33:29 -0700 | [diff] [blame] | 9825 | static constexpr std::chrono::duration STALE_EVENT_TIMEOUT = 1000ms; |
| 9826 | mFakePolicy->setStaleEventTimeout(STALE_EVENT_TIMEOUT); |
Siarhei Vishniakou | 289e924 | 2022-02-15 14:50:16 -0800 | [diff] [blame] | 9827 | const nsecs_t eventTime = systemTime(SYSTEM_TIME_MONOTONIC) - |
| 9828 | std::chrono::nanoseconds(STALE_EVENT_TIMEOUT).count(); |
| 9829 | |
| 9830 | // Define a valid key down event that is stale (too old). |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9831 | event.initialize(InputEvent::nextId(), DEVICE_ID, AINPUT_SOURCE_KEYBOARD, |
| 9832 | ui::LogicalDisplayId::INVALID, INVALID_HMAC, AKEY_EVENT_ACTION_DOWN, |
| 9833 | /*flags=*/0, AKEYCODE_A, KEY_A, AMETA_NONE, /*repeatCount=*/0, eventTime, |
| 9834 | eventTime); |
Siarhei Vishniakou | 289e924 | 2022-02-15 14:50:16 -0800 | [diff] [blame] | 9835 | |
Hu Guo | fe3c8f1 | 2023-09-22 17:20:15 +0800 | [diff] [blame] | 9836 | const int32_t policyFlags = |
| 9837 | POLICY_FLAG_FILTERED | POLICY_FLAG_PASS_TO_USER | POLICY_FLAG_DISABLE_KEY_REPEAT; |
Siarhei Vishniakou | 289e924 | 2022-02-15 14:50:16 -0800 | [diff] [blame] | 9838 | |
| 9839 | InputEventInjectionResult result = |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 9840 | mDispatcher->injectInputEvent(&event, /*targetUid=*/{}, |
Siarhei Vishniakou | 289e924 | 2022-02-15 14:50:16 -0800 | [diff] [blame] | 9841 | InputEventInjectionSync::WAIT_FOR_RESULT, |
| 9842 | INJECT_EVENT_TIMEOUT, policyFlags); |
| 9843 | ASSERT_EQ(InputEventInjectionResult::FAILED, result) |
| 9844 | << "Injection should fail because the event is stale"; |
| 9845 | |
| 9846 | ASSERT_TRUE(mDispatcher->waitForIdle()); |
| 9847 | mFakePolicy->assertNotifyAnrWasNotCalled(); |
| 9848 | mWindow->assertNoEvents(); |
| 9849 | } |
| 9850 | |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9851 | // We have a focused application, but no focused window |
Siarhei Vishniakou | 234129c | 2020-10-22 22:28:12 -0500 | [diff] [blame] | 9852 | // Make sure that we don't notify policy twice about the same ANR. |
| 9853 | TEST_F(InputDispatcherSingleWindowAnr, NoFocusedWindow_DoesNotSendDuplicateAnr) { |
Siarhei Vishniakou | 06405fc | 2023-09-22 13:40:51 -0700 | [diff] [blame] | 9854 | const std::chrono::duration appTimeout = 400ms; |
| 9855 | mApplication->setDispatchingTimeout(appTimeout); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9856 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, mApplication); |
Siarhei Vishniakou | 06405fc | 2023-09-22 13:40:51 -0700 | [diff] [blame] | 9857 | |
Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 9858 | mWindow->setFocusable(false); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 9859 | mDispatcher->onWindowInfosChanged({{*mWindow->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9860 | mWindow->consumeFocusEvent(false); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9861 | |
| 9862 | // Once a focused event arrives, we get an ANR for this application |
| 9863 | // We specify the injection timeout to be smaller than the application timeout, to ensure that |
| 9864 | // injection times out (instead of failing). |
Siarhei Vishniakou | 06405fc | 2023-09-22 13:40:51 -0700 | [diff] [blame] | 9865 | const std::chrono::duration eventInjectionTimeout = 100ms; |
| 9866 | ASSERT_LT(eventInjectionTimeout, appTimeout); |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 9867 | const InputEventInjectionResult result = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9868 | injectKey(*mDispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, |
| 9869 | ui::LogicalDisplayId::DEFAULT, InputEventInjectionSync::WAIT_FOR_RESULT, |
| 9870 | eventInjectionTimeout, |
Siarhei Vishniakou | 06405fc | 2023-09-22 13:40:51 -0700 | [diff] [blame] | 9871 | /*allowKeyRepeat=*/false); |
| 9872 | ASSERT_EQ(InputEventInjectionResult::TIMED_OUT, result) |
| 9873 | << "result=" << ftl::enum_string(result); |
| 9874 | // We already waited for 'eventInjectionTimeout`, because the countdown started when the event |
| 9875 | // was first injected. So now we have (appTimeout - eventInjectionTimeout) left to wait. |
| 9876 | std::chrono::duration remainingWaitTime = appTimeout - eventInjectionTimeout; |
| 9877 | mFakePolicy->assertNotifyNoFocusedWindowAnrWasCalled(remainingWaitTime, mApplication); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9878 | |
Vishnu Nair | e4df875 | 2022-09-08 09:17:55 -0700 | [diff] [blame] | 9879 | std::this_thread::sleep_for(appTimeout); |
Siarhei Vishniakou | 234129c | 2020-10-22 22:28:12 -0500 | [diff] [blame] | 9880 | // ANR should not be raised again. It is up to policy to do that if it desires. |
| 9881 | mFakePolicy->assertNotifyAnrWasNotCalled(); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9882 | |
Siarhei Vishniakou | 234129c | 2020-10-22 22:28:12 -0500 | [diff] [blame] | 9883 | // If we now get a focused window, the ANR should stop, but the policy handles that via |
| 9884 | // 'notifyFocusChanged' callback. This is implemented in the policy so we can't test it here. |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9885 | ASSERT_TRUE(mDispatcher->waitForIdle()); |
| 9886 | } |
| 9887 | |
| 9888 | // We have a focused application, but no focused window |
| 9889 | TEST_F(InputDispatcherSingleWindowAnr, NoFocusedWindow_DropsFocusedEvents) { |
Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 9890 | mWindow->setFocusable(false); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 9891 | mDispatcher->onWindowInfosChanged({{*mWindow->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9892 | mWindow->consumeFocusEvent(false); |
| 9893 | |
| 9894 | // Once a focused event arrives, we get an ANR for this application |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 9895 | ASSERT_NO_FATAL_FAILURE(assertInjectedKeyTimesOut(*mDispatcher)); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9896 | |
Vishnu Nair | e4df875 | 2022-09-08 09:17:55 -0700 | [diff] [blame] | 9897 | const std::chrono::duration timeout = mApplication->getDispatchingTimeout(DISPATCHING_TIMEOUT); |
| 9898 | mFakePolicy->assertNotifyNoFocusedWindowAnrWasCalled(timeout, mApplication); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9899 | |
| 9900 | // Future focused events get dropped right away |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 9901 | ASSERT_EQ(InputEventInjectionResult::FAILED, injectKeyDown(*mDispatcher)); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9902 | ASSERT_TRUE(mDispatcher->waitForIdle()); |
| 9903 | mWindow->assertNoEvents(); |
| 9904 | } |
| 9905 | |
| 9906 | /** |
| 9907 | * Ensure that the implementation is valid. Since we are using multiset to keep track of the |
| 9908 | * ANR timeouts, we are allowing entries with identical timestamps in the same connection. |
| 9909 | * If we process 1 of the events, but ANR on the second event with the same timestamp, |
| 9910 | * the ANR mechanism should still work. |
| 9911 | * |
| 9912 | * In this test, we are injecting DOWN and UP events with the same timestamps, and acknowledging the |
| 9913 | * DOWN event, while not responding on the second one. |
| 9914 | */ |
| 9915 | TEST_F(InputDispatcherSingleWindowAnr, Anr_HandlesEventsWithIdenticalTimestamps) { |
| 9916 | nsecs_t currentTime = systemTime(SYSTEM_TIME_MONOTONIC); |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 9917 | injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9918 | ui::LogicalDisplayId::DEFAULT, WINDOW_LOCATION, |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9919 | {AMOTION_EVENT_INVALID_CURSOR_POSITION, |
| 9920 | AMOTION_EVENT_INVALID_CURSOR_POSITION}, |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 9921 | 500ms, InputEventInjectionSync::WAIT_FOR_RESULT, currentTime); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9922 | |
| 9923 | // Now send ACTION_UP, with identical timestamp |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 9924 | injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9925 | ui::LogicalDisplayId::DEFAULT, WINDOW_LOCATION, |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9926 | {AMOTION_EVENT_INVALID_CURSOR_POSITION, |
| 9927 | AMOTION_EVENT_INVALID_CURSOR_POSITION}, |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 9928 | 500ms, InputEventInjectionSync::WAIT_FOR_RESULT, currentTime); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9929 | |
| 9930 | // We have now sent down and up. Let's consume first event and then ANR on the second. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9931 | mWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9932 | const std::chrono::duration timeout = mWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT); |
Prabir Pradhan | edd9640 | 2022-02-15 01:46:16 -0800 | [diff] [blame] | 9933 | mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(timeout, mWindow); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9934 | } |
| 9935 | |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 9936 | // A spy window can receive an ANR |
| 9937 | TEST_F(InputDispatcherSingleWindowAnr, SpyWindowAnr) { |
| 9938 | sp<FakeWindowHandle> spy = addSpyWindow(); |
| 9939 | |
| 9940 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9941 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 9942 | ui::LogicalDisplayId::DEFAULT, WINDOW_LOCATION)); |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 9943 | mWindow->consumeMotionDown(); |
| 9944 | |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 9945 | const auto [sequenceNum, _] = spy->receiveEvent(); // ACTION_DOWN |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 9946 | ASSERT_TRUE(sequenceNum); |
| 9947 | const std::chrono::duration timeout = spy->getDispatchingTimeout(DISPATCHING_TIMEOUT); |
Prabir Pradhan | edd9640 | 2022-02-15 01:46:16 -0800 | [diff] [blame] | 9948 | mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(timeout, spy); |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 9949 | |
| 9950 | spy->finishEvent(*sequenceNum); |
Siarhei Vishniakou | 1ae72f1 | 2023-01-29 12:55:30 -0800 | [diff] [blame] | 9951 | spy->consumeMotionEvent( |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9952 | AllOf(WithMotionAction(ACTION_CANCEL), WithDisplayId(ui::LogicalDisplayId::DEFAULT))); |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 9953 | ASSERT_TRUE(mDispatcher->waitForIdle()); |
Prabir Pradhan | edd9640 | 2022-02-15 01:46:16 -0800 | [diff] [blame] | 9954 | mFakePolicy->assertNotifyWindowResponsiveWasCalled(spy->getToken(), mWindow->getPid()); |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 9955 | } |
| 9956 | |
| 9957 | // If an app is not responding to a key event, spy windows should continue to receive |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9958 | // new motion events |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 9959 | TEST_F(InputDispatcherSingleWindowAnr, SpyWindowReceivesEventsDuringAppAnrOnKey) { |
| 9960 | sp<FakeWindowHandle> spy = addSpyWindow(); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9961 | |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 9962 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9963 | injectKeyDown(*mDispatcher, ui::LogicalDisplayId::DEFAULT)); |
| 9964 | mWindow->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); |
| 9965 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
| 9966 | injectKeyUp(*mDispatcher, ui::LogicalDisplayId::DEFAULT)); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9967 | |
| 9968 | // Stuck on the ACTION_UP |
| 9969 | const std::chrono::duration timeout = mWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT); |
Prabir Pradhan | edd9640 | 2022-02-15 01:46:16 -0800 | [diff] [blame] | 9970 | mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(timeout, mWindow); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9971 | |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 9972 | // New tap will go to the spy window, but not to the window |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9973 | tapOnWindow(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9974 | spy->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
| 9975 | spy->consumeMotionUp(ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9976 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9977 | mWindow->consumeKeyUp(ui::LogicalDisplayId::DEFAULT); // still the previous motion |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9978 | mDispatcher->waitForIdle(); |
Prabir Pradhan | edd9640 | 2022-02-15 01:46:16 -0800 | [diff] [blame] | 9979 | mFakePolicy->assertNotifyWindowResponsiveWasCalled(mWindow->getToken(), mWindow->getPid()); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9980 | mWindow->assertNoEvents(); |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 9981 | spy->assertNoEvents(); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9982 | } |
| 9983 | |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 9984 | // If an app is not responding to a motion event, spy windows should continue to receive |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9985 | // new motion events |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 9986 | TEST_F(InputDispatcherSingleWindowAnr, SpyWindowReceivesEventsDuringAppAnrOnMotion) { |
| 9987 | sp<FakeWindowHandle> spy = addSpyWindow(); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9988 | |
| 9989 | tapOnWindow(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 9990 | spy->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
| 9991 | spy->consumeMotionUp(ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9992 | |
| 9993 | mWindow->consumeMotionDown(); |
| 9994 | // Stuck on the ACTION_UP |
| 9995 | const std::chrono::duration timeout = mWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT); |
Prabir Pradhan | edd9640 | 2022-02-15 01:46:16 -0800 | [diff] [blame] | 9996 | mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(timeout, mWindow); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9997 | |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 9998 | // New tap will go to the spy window, but not to the window |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 9999 | tapOnWindow(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10000 | spy->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
| 10001 | spy->consumeMotionUp(ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10002 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10003 | mWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT); // still the previous motion |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10004 | mDispatcher->waitForIdle(); |
Prabir Pradhan | edd9640 | 2022-02-15 01:46:16 -0800 | [diff] [blame] | 10005 | mFakePolicy->assertNotifyWindowResponsiveWasCalled(mWindow->getToken(), mWindow->getPid()); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10006 | mWindow->assertNoEvents(); |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 10007 | spy->assertNoEvents(); |
| 10008 | } |
| 10009 | |
| 10010 | TEST_F(InputDispatcherSingleWindowAnr, UnresponsiveMonitorAnr) { |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 10011 | mDispatcher->setMonitorDispatchingTimeoutForTest(SPY_TIMEOUT); |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 10012 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10013 | FakeMonitorReceiver monitor = |
| 10014 | FakeMonitorReceiver(*mDispatcher, "M_1", ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 10015 | |
| 10016 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10017 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 10018 | ui::LogicalDisplayId::DEFAULT, WINDOW_LOCATION)); |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 10019 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10020 | mWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 10021 | const std::optional<uint32_t> consumeSeq = monitor.receiveEvent(); |
| 10022 | ASSERT_TRUE(consumeSeq); |
| 10023 | |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 10024 | mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(SPY_TIMEOUT, monitor.getToken(), |
| 10025 | MONITOR_PID); |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 10026 | |
| 10027 | monitor.finishEvent(*consumeSeq); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10028 | monitor.consumeMotionCancel(ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 10029 | |
| 10030 | ASSERT_TRUE(mDispatcher->waitForIdle()); |
Prabir Pradhan | edd9640 | 2022-02-15 01:46:16 -0800 | [diff] [blame] | 10031 | mFakePolicy->assertNotifyWindowResponsiveWasCalled(monitor.getToken(), MONITOR_PID); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10032 | } |
| 10033 | |
| 10034 | // If a window is unresponsive, then you get anr. if the window later catches up and starts to |
| 10035 | // process events, you don't get an anr. When the window later becomes unresponsive again, you |
| 10036 | // get an ANR again. |
| 10037 | // 1. tap -> block on ACTION_UP -> receive ANR |
| 10038 | // 2. consume all pending events (= queue becomes healthy again) |
| 10039 | // 3. tap again -> block on ACTION_UP again -> receive ANR second time |
| 10040 | TEST_F(InputDispatcherSingleWindowAnr, SameWindow_CanReceiveAnrTwice) { |
| 10041 | tapOnWindow(); |
| 10042 | |
| 10043 | mWindow->consumeMotionDown(); |
| 10044 | // Block on ACTION_UP |
| 10045 | const std::chrono::duration timeout = mWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT); |
Prabir Pradhan | edd9640 | 2022-02-15 01:46:16 -0800 | [diff] [blame] | 10046 | mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(timeout, mWindow); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10047 | mWindow->consumeMotionUp(); // Now the connection should be healthy again |
| 10048 | mDispatcher->waitForIdle(); |
Prabir Pradhan | edd9640 | 2022-02-15 01:46:16 -0800 | [diff] [blame] | 10049 | mFakePolicy->assertNotifyWindowResponsiveWasCalled(mWindow->getToken(), mWindow->getPid()); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10050 | mWindow->assertNoEvents(); |
| 10051 | |
| 10052 | tapOnWindow(); |
| 10053 | mWindow->consumeMotionDown(); |
Prabir Pradhan | edd9640 | 2022-02-15 01:46:16 -0800 | [diff] [blame] | 10054 | mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(timeout, mWindow); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10055 | mWindow->consumeMotionUp(); |
| 10056 | |
| 10057 | mDispatcher->waitForIdle(); |
Prabir Pradhan | edd9640 | 2022-02-15 01:46:16 -0800 | [diff] [blame] | 10058 | mFakePolicy->assertNotifyWindowResponsiveWasCalled(mWindow->getToken(), mWindow->getPid()); |
Siarhei Vishniakou | 234129c | 2020-10-22 22:28:12 -0500 | [diff] [blame] | 10059 | mFakePolicy->assertNotifyAnrWasNotCalled(); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10060 | mWindow->assertNoEvents(); |
| 10061 | } |
| 10062 | |
Siarhei Vishniakou | 234129c | 2020-10-22 22:28:12 -0500 | [diff] [blame] | 10063 | // If a connection remains unresponsive for a while, make sure policy is only notified once about |
| 10064 | // it. |
| 10065 | TEST_F(InputDispatcherSingleWindowAnr, Policy_DoesNotGetDuplicateAnr) { |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 10066 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10067 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 10068 | ui::LogicalDisplayId::DEFAULT, WINDOW_LOCATION)); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10069 | |
| 10070 | const std::chrono::duration windowTimeout = mWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT); |
Prabir Pradhan | edd9640 | 2022-02-15 01:46:16 -0800 | [diff] [blame] | 10071 | mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(windowTimeout, mWindow); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10072 | std::this_thread::sleep_for(windowTimeout); |
Siarhei Vishniakou | 234129c | 2020-10-22 22:28:12 -0500 | [diff] [blame] | 10073 | // 'notifyConnectionUnresponsive' should only be called once per connection |
| 10074 | mFakePolicy->assertNotifyAnrWasNotCalled(); |
| 10075 | // When the ANR happened, dispatcher should abort the current event stream via ACTION_CANCEL |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10076 | mWindow->consumeMotionDown(); |
Siarhei Vishniakou | 1ae72f1 | 2023-01-29 12:55:30 -0800 | [diff] [blame] | 10077 | mWindow->consumeMotionEvent( |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10078 | AllOf(WithMotionAction(ACTION_CANCEL), WithDisplayId(ui::LogicalDisplayId::DEFAULT))); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10079 | mWindow->assertNoEvents(); |
Siarhei Vishniakou | 234129c | 2020-10-22 22:28:12 -0500 | [diff] [blame] | 10080 | mDispatcher->waitForIdle(); |
Prabir Pradhan | edd9640 | 2022-02-15 01:46:16 -0800 | [diff] [blame] | 10081 | mFakePolicy->assertNotifyWindowResponsiveWasCalled(mWindow->getToken(), mWindow->getPid()); |
Siarhei Vishniakou | 234129c | 2020-10-22 22:28:12 -0500 | [diff] [blame] | 10082 | mFakePolicy->assertNotifyAnrWasNotCalled(); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10083 | } |
| 10084 | |
| 10085 | /** |
| 10086 | * If a window is processing a motion event, and then a key event comes in, the key event should |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 10087 | * not get delivered to the focused window until the motion is processed. |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10088 | */ |
| 10089 | TEST_F(InputDispatcherSingleWindowAnr, Key_StaysPendingWhileMotionIsProcessed) { |
Siarhei Vishniakou | ef2b450 | 2023-12-28 11:51:47 -0800 | [diff] [blame] | 10090 | // The timeouts in this test are established by relying on the fact that the "key waiting for |
| 10091 | // events timeout" is equal to 500ms. |
| 10092 | ASSERT_EQ(mFakePolicy->getKeyWaitingForEventsTimeout(), 500ms); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10093 | mWindow->setDispatchingTimeout(2s); // Set a long ANR timeout to prevent it from triggering |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 10094 | mDispatcher->onWindowInfosChanged({{*mWindow->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10095 | |
| 10096 | tapOnWindow(); |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 10097 | const auto& [downSequenceNum, downEvent] = mWindow->receiveEvent(); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10098 | ASSERT_TRUE(downSequenceNum); |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 10099 | const auto& [upSequenceNum, upEvent] = mWindow->receiveEvent(); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10100 | ASSERT_TRUE(upSequenceNum); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10101 | |
Siarhei Vishniakou | ef2b450 | 2023-12-28 11:51:47 -0800 | [diff] [blame] | 10102 | // Don't finish the events yet, and send a key |
| 10103 | mDispatcher->notifyKey( |
| 10104 | KeyArgsBuilder(AKEY_EVENT_ACTION_DOWN, AINPUT_SOURCE_KEYBOARD) |
| 10105 | .policyFlags(DEFAULT_POLICY_FLAGS | POLICY_FLAG_DISABLE_KEY_REPEAT) |
| 10106 | .build()); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10107 | // Key will not be sent to the window, yet, because the window is still processing events |
| 10108 | // and the key remains pending, waiting for the touch events to be processed |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 10109 | // Make sure that `assertNoEvents` doesn't wait too long, because it could cause an ANR. |
Siarhei Vishniakou | ef2b450 | 2023-12-28 11:51:47 -0800 | [diff] [blame] | 10110 | mWindow->assertNoEvents(100ms); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10111 | |
Siarhei Vishniakou | ef2b450 | 2023-12-28 11:51:47 -0800 | [diff] [blame] | 10112 | std::this_thread::sleep_for(400ms); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10113 | // if we wait long enough though, dispatcher will give up, and still send the key |
| 10114 | // to the focused window, even though we have not yet finished the motion event |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10115 | mWindow->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10116 | mWindow->finishEvent(*downSequenceNum); |
| 10117 | mWindow->finishEvent(*upSequenceNum); |
| 10118 | } |
| 10119 | |
| 10120 | /** |
| 10121 | * If a window is processing a motion event, and then a key event comes in, the key event should |
| 10122 | * not go to the focused window until the motion is processed. |
| 10123 | * If then a new motion comes in, then the pending key event should be going to the currently |
| 10124 | * focused window right away. |
| 10125 | */ |
| 10126 | TEST_F(InputDispatcherSingleWindowAnr, |
Siarhei Vishniakou | ef2b450 | 2023-12-28 11:51:47 -0800 | [diff] [blame] | 10127 | PendingKey_IsDeliveredWhileMotionIsProcessingAndNewTouchComesIn) { |
| 10128 | // The timeouts in this test are established by relying on the fact that the "key waiting for |
| 10129 | // events timeout" is equal to 500ms. |
| 10130 | ASSERT_EQ(mFakePolicy->getKeyWaitingForEventsTimeout(), 500ms); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10131 | mWindow->setDispatchingTimeout(2s); // Set a long ANR timeout to prevent it from triggering |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 10132 | mDispatcher->onWindowInfosChanged({{*mWindow->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10133 | |
| 10134 | tapOnWindow(); |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 10135 | const auto& [downSequenceNum, _] = mWindow->receiveEvent(); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10136 | ASSERT_TRUE(downSequenceNum); |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 10137 | const auto& [upSequenceNum, upEvent] = mWindow->receiveEvent(); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10138 | ASSERT_TRUE(upSequenceNum); |
| 10139 | // Don't finish the events yet, and send a key |
Siarhei Vishniakou | 67bf216 | 2023-11-16 13:29:50 -0800 | [diff] [blame] | 10140 | mDispatcher->notifyKey( |
| 10141 | KeyArgsBuilder(AKEY_EVENT_ACTION_DOWN, AINPUT_SOURCE_KEYBOARD) |
| 10142 | .policyFlags(DEFAULT_POLICY_FLAGS | POLICY_FLAG_DISABLE_KEY_REPEAT) |
| 10143 | .build()); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10144 | // At this point, key is still pending, and should not be sent to the application yet. |
Siarhei Vishniakou | ef2b450 | 2023-12-28 11:51:47 -0800 | [diff] [blame] | 10145 | mWindow->assertNoEvents(100ms); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10146 | |
| 10147 | // Now tap down again. It should cause the pending key to go to the focused window right away. |
| 10148 | tapOnWindow(); |
Siarhei Vishniakou | ef2b450 | 2023-12-28 11:51:47 -0800 | [diff] [blame] | 10149 | // Now that we tapped, we should receive the key immediately. |
| 10150 | // Since there's still room for slowness, we use 200ms, which is much less than |
| 10151 | // the "key waiting for events' timeout of 500ms minus the already waited 100ms duration. |
| 10152 | std::unique_ptr<InputEvent> keyEvent = mWindow->consume(200ms); |
| 10153 | ASSERT_NE(nullptr, keyEvent); |
| 10154 | ASSERT_EQ(InputEventType::KEY, keyEvent->getType()); |
| 10155 | ASSERT_THAT(static_cast<KeyEvent&>(*keyEvent), WithKeyAction(AKEY_EVENT_ACTION_DOWN)); |
| 10156 | // it doesn't matter that we haven't ack'd the other events yet. We can finish events in any |
| 10157 | // order. |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10158 | mWindow->finishEvent(*downSequenceNum); // first tap's ACTION_DOWN |
| 10159 | mWindow->finishEvent(*upSequenceNum); // first tap's ACTION_UP |
Siarhei Vishniakou | 67bf216 | 2023-11-16 13:29:50 -0800 | [diff] [blame] | 10160 | mWindow->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); |
| 10161 | mWindow->consumeMotionEvent(WithMotionAction(ACTION_UP)); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10162 | mWindow->assertNoEvents(); |
| 10163 | } |
| 10164 | |
Siarhei Vishniakou | adb9fc9 | 2023-05-26 10:46:09 -0700 | [diff] [blame] | 10165 | /** |
| 10166 | * Send an event to the app and have the app not respond right away. |
| 10167 | * When ANR is raised, policy will tell the dispatcher to cancel the events for that window. |
| 10168 | * So InputDispatcher will enqueue ACTION_CANCEL event as well. |
| 10169 | * At some point, the window becomes responsive again. |
| 10170 | * Ensure that subsequent events get dropped, and the next gesture is delivered. |
| 10171 | */ |
| 10172 | TEST_F(InputDispatcherSingleWindowAnr, TwoGesturesWithAnr) { |
| 10173 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 10174 | .pointer(PointerBuilder(0, ToolType::FINGER).x(10).y(10)) |
| 10175 | .build()); |
| 10176 | |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 10177 | const auto [sequenceNum, _] = mWindow->receiveEvent(); // ACTION_DOWN |
Siarhei Vishniakou | adb9fc9 | 2023-05-26 10:46:09 -0700 | [diff] [blame] | 10178 | ASSERT_TRUE(sequenceNum); |
| 10179 | const std::chrono::duration timeout = mWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT); |
| 10180 | mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(timeout, mWindow); |
| 10181 | |
| 10182 | mWindow->finishEvent(*sequenceNum); |
| 10183 | mWindow->consumeMotionEvent(WithMotionAction(ACTION_CANCEL)); |
| 10184 | ASSERT_TRUE(mDispatcher->waitForIdle()); |
| 10185 | mFakePolicy->assertNotifyWindowResponsiveWasCalled(mWindow->getToken(), mWindow->getPid()); |
| 10186 | |
| 10187 | // Now that the window is responsive, let's continue the gesture. |
| 10188 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 10189 | .pointer(PointerBuilder(0, ToolType::FINGER).x(11).y(11)) |
| 10190 | .build()); |
| 10191 | |
| 10192 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 10193 | .pointer(PointerBuilder(0, ToolType::FINGER).x(11).y(11)) |
| 10194 | .pointer(PointerBuilder(1, ToolType::FINGER).x(3).y(3)) |
| 10195 | .build()); |
| 10196 | |
| 10197 | mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_UP, AINPUT_SOURCE_TOUCHSCREEN) |
| 10198 | .pointer(PointerBuilder(0, ToolType::FINGER).x(11).y(11)) |
| 10199 | .pointer(PointerBuilder(1, ToolType::FINGER).x(3).y(3)) |
| 10200 | .build()); |
| 10201 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN) |
| 10202 | .pointer(PointerBuilder(0, ToolType::FINGER).x(11).y(11)) |
| 10203 | .build()); |
| 10204 | // We already canceled this pointer, so the window shouldn't get any new events. |
| 10205 | mWindow->assertNoEvents(); |
| 10206 | |
| 10207 | // Start another one. |
| 10208 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 10209 | .pointer(PointerBuilder(0, ToolType::FINGER).x(15).y(15)) |
| 10210 | .build()); |
| 10211 | mWindow->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); |
| 10212 | } |
| 10213 | |
Prabir Pradhan | fc36472 | 2024-02-08 17:51:20 +0000 | [diff] [blame] | 10214 | // Send an event to the app and have the app not respond right away. Then remove the app window. |
| 10215 | // When the window is removed, the dispatcher will cancel the events for that window. |
| 10216 | // So InputDispatcher will enqueue ACTION_CANCEL event as well. |
| 10217 | TEST_F(InputDispatcherSingleWindowAnr, AnrAfterWindowRemoval) { |
| 10218 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10219 | AINPUT_SOURCE_TOUCHSCREEN, |
| 10220 | ui::LogicalDisplayId::DEFAULT, {WINDOW_LOCATION})); |
Prabir Pradhan | fc36472 | 2024-02-08 17:51:20 +0000 | [diff] [blame] | 10221 | |
| 10222 | const auto [sequenceNum, _] = mWindow->receiveEvent(); // ACTION_DOWN |
| 10223 | ASSERT_TRUE(sequenceNum); |
| 10224 | |
| 10225 | // Remove the window, but the input channel should remain alive. |
| 10226 | mDispatcher->onWindowInfosChanged({{}, {}, 0, 0}); |
| 10227 | |
| 10228 | const std::chrono::duration timeout = mWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT); |
| 10229 | // Since the window was removed, Dispatcher does not know the PID associated with the window |
| 10230 | // anymore, so the policy is notified without the PID. |
| 10231 | mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(timeout, mWindow->getToken(), |
| 10232 | /*pid=*/std::nullopt); |
| 10233 | |
| 10234 | mWindow->finishEvent(*sequenceNum); |
| 10235 | // The cancellation was generated when the window was removed, along with the focus event. |
| 10236 | mWindow->consumeMotionEvent( |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10237 | AllOf(WithMotionAction(ACTION_CANCEL), WithDisplayId(ui::LogicalDisplayId::DEFAULT))); |
Prabir Pradhan | fc36472 | 2024-02-08 17:51:20 +0000 | [diff] [blame] | 10238 | mWindow->consumeFocusEvent(false); |
| 10239 | ASSERT_TRUE(mDispatcher->waitForIdle()); |
| 10240 | mFakePolicy->assertNotifyWindowResponsiveWasCalled(mWindow->getToken(), /*pid=*/std::nullopt); |
| 10241 | } |
| 10242 | |
| 10243 | // Send an event to the app and have the app not respond right away. Wait for the policy to be |
| 10244 | // notified of the unresponsive window, then remove the app window. |
| 10245 | TEST_F(InputDispatcherSingleWindowAnr, AnrFollowedByWindowRemoval) { |
| 10246 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10247 | AINPUT_SOURCE_TOUCHSCREEN, |
| 10248 | ui::LogicalDisplayId::DEFAULT, {WINDOW_LOCATION})); |
Prabir Pradhan | fc36472 | 2024-02-08 17:51:20 +0000 | [diff] [blame] | 10249 | |
| 10250 | const auto [sequenceNum, _] = mWindow->receiveEvent(); // ACTION_DOWN |
| 10251 | ASSERT_TRUE(sequenceNum); |
| 10252 | const std::chrono::duration timeout = mWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT); |
| 10253 | mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(timeout, mWindow); |
| 10254 | |
| 10255 | // Remove the window, but the input channel should remain alive. |
| 10256 | mDispatcher->onWindowInfosChanged({{}, {}, 0, 0}); |
| 10257 | |
| 10258 | mWindow->finishEvent(*sequenceNum); |
| 10259 | // The cancellation was generated during the ANR, and the window lost focus when it was removed. |
| 10260 | mWindow->consumeMotionEvent( |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10261 | AllOf(WithMotionAction(ACTION_CANCEL), WithDisplayId(ui::LogicalDisplayId::DEFAULT))); |
Prabir Pradhan | fc36472 | 2024-02-08 17:51:20 +0000 | [diff] [blame] | 10262 | mWindow->consumeFocusEvent(false); |
| 10263 | ASSERT_TRUE(mDispatcher->waitForIdle()); |
| 10264 | // Since the window was removed, Dispatcher does not know the PID associated with the window |
| 10265 | // becoming responsive, so the policy is notified without the PID. |
| 10266 | mFakePolicy->assertNotifyWindowResponsiveWasCalled(mWindow->getToken(), /*pid=*/std::nullopt); |
| 10267 | } |
| 10268 | |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10269 | class InputDispatcherMultiWindowAnr : public InputDispatcherTest { |
| 10270 | virtual void SetUp() override { |
| 10271 | InputDispatcherTest::SetUp(); |
| 10272 | |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 10273 | mApplication = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | f83c693 | 2023-07-07 17:48:10 -0700 | [diff] [blame] | 10274 | mApplication->setDispatchingTimeout(100ms); |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 10275 | mUnfocusedWindow = sp<FakeWindowHandle>::make(mApplication, mDispatcher, "Unfocused", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10276 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10277 | mUnfocusedWindow->setFrame(Rect(0, 0, 30, 30)); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10278 | // Adding FLAG_WATCH_OUTSIDE_TOUCH to receive ACTION_OUTSIDE when another window is tapped |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 10279 | mUnfocusedWindow->setWatchOutsideTouch(true); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10280 | |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 10281 | mFocusedWindow = sp<FakeWindowHandle>::make(mApplication, mDispatcher, "Focused", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10282 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | f83c693 | 2023-07-07 17:48:10 -0700 | [diff] [blame] | 10283 | mFocusedWindow->setDispatchingTimeout(100ms); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10284 | mFocusedWindow->setFrame(Rect(50, 50, 100, 100)); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10285 | |
| 10286 | // Set focused application. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10287 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, mApplication); |
Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 10288 | mFocusedWindow->setFocusable(true); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10289 | |
| 10290 | // Expect one focus window exist in display. |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 10291 | mDispatcher->onWindowInfosChanged( |
| 10292 | {{*mUnfocusedWindow->getInfo(), *mFocusedWindow->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 10293 | setFocusedWindow(mFocusedWindow); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10294 | mFocusedWindow->consumeFocusEvent(true); |
| 10295 | } |
| 10296 | |
| 10297 | virtual void TearDown() override { |
| 10298 | InputDispatcherTest::TearDown(); |
| 10299 | |
| 10300 | mUnfocusedWindow.clear(); |
| 10301 | mFocusedWindow.clear(); |
| 10302 | } |
| 10303 | |
| 10304 | protected: |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 10305 | std::shared_ptr<FakeApplicationHandle> mApplication; |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10306 | sp<FakeWindowHandle> mUnfocusedWindow; |
| 10307 | sp<FakeWindowHandle> mFocusedWindow; |
| 10308 | static constexpr PointF UNFOCUSED_WINDOW_LOCATION = {20, 20}; |
| 10309 | static constexpr PointF FOCUSED_WINDOW_LOCATION = {75, 75}; |
| 10310 | static constexpr PointF LOCATION_OUTSIDE_ALL_WINDOWS = {40, 40}; |
| 10311 | |
| 10312 | void tapOnFocusedWindow() { tap(FOCUSED_WINDOW_LOCATION); } |
| 10313 | |
| 10314 | void tapOnUnfocusedWindow() { tap(UNFOCUSED_WINDOW_LOCATION); } |
| 10315 | |
| 10316 | private: |
| 10317 | void tap(const PointF& location) { |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 10318 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10319 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 10320 | ui::LogicalDisplayId::DEFAULT, location)); |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 10321 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10322 | injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 10323 | ui::LogicalDisplayId::DEFAULT, location)); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10324 | } |
| 10325 | }; |
| 10326 | |
| 10327 | // If we have 2 windows that are both unresponsive, the one with the shortest timeout |
| 10328 | // should be ANR'd first. |
| 10329 | TEST_F(InputDispatcherMultiWindowAnr, TwoWindows_BothUnresponsive) { |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 10330 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 10331 | injectMotionEvent(*mDispatcher, |
| 10332 | MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, |
| 10333 | AINPUT_SOURCE_TOUCHSCREEN) |
| 10334 | .pointer(PointerBuilder(0, ToolType::FINGER) |
| 10335 | .x(FOCUSED_WINDOW_LOCATION.x) |
| 10336 | .y(FOCUSED_WINDOW_LOCATION.y)) |
| 10337 | .build())); |
| 10338 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
| 10339 | injectMotionEvent(*mDispatcher, |
| 10340 | MotionEventBuilder(AMOTION_EVENT_ACTION_UP, |
| 10341 | AINPUT_SOURCE_TOUCHSCREEN) |
| 10342 | .pointer(PointerBuilder(0, ToolType::FINGER) |
| 10343 | .x(FOCUSED_WINDOW_LOCATION.x) |
| 10344 | .y(FOCUSED_WINDOW_LOCATION.y)) |
| 10345 | .build())); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10346 | mFocusedWindow->consumeMotionDown(); |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 10347 | mFocusedWindow->consumeMotionUp(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10348 | mUnfocusedWindow->consumeMotionOutside(ui::LogicalDisplayId::DEFAULT, /*flags=*/0); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10349 | // We consumed all events, so no ANR |
| 10350 | ASSERT_TRUE(mDispatcher->waitForIdle()); |
| 10351 | mFakePolicy->assertNotifyAnrWasNotCalled(); |
| 10352 | |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 10353 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 10354 | injectMotionEvent(*mDispatcher, |
| 10355 | MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, |
| 10356 | AINPUT_SOURCE_TOUCHSCREEN) |
| 10357 | .pointer(PointerBuilder(0, ToolType::FINGER) |
| 10358 | .x(FOCUSED_WINDOW_LOCATION.x) |
| 10359 | .y(FOCUSED_WINDOW_LOCATION.y)) |
| 10360 | .build())); |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 10361 | const auto [unfocusedSequenceNum, _] = mUnfocusedWindow->receiveEvent(); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10362 | ASSERT_TRUE(unfocusedSequenceNum); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10363 | |
| 10364 | const std::chrono::duration timeout = |
| 10365 | mFocusedWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT); |
Prabir Pradhan | edd9640 | 2022-02-15 01:46:16 -0800 | [diff] [blame] | 10366 | mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(timeout, mFocusedWindow); |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 10367 | |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10368 | mUnfocusedWindow->finishEvent(*unfocusedSequenceNum); |
Siarhei Vishniakou | 234129c | 2020-10-22 22:28:12 -0500 | [diff] [blame] | 10369 | mFocusedWindow->consumeMotionDown(); |
| 10370 | // This cancel is generated because the connection was unresponsive |
| 10371 | mFocusedWindow->consumeMotionCancel(); |
| 10372 | mFocusedWindow->assertNoEvents(); |
| 10373 | mUnfocusedWindow->assertNoEvents(); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10374 | ASSERT_TRUE(mDispatcher->waitForIdle()); |
Prabir Pradhan | edd9640 | 2022-02-15 01:46:16 -0800 | [diff] [blame] | 10375 | mFakePolicy->assertNotifyWindowResponsiveWasCalled(mFocusedWindow->getToken(), |
| 10376 | mFocusedWindow->getPid()); |
Siarhei Vishniakou | 234129c | 2020-10-22 22:28:12 -0500 | [diff] [blame] | 10377 | mFakePolicy->assertNotifyAnrWasNotCalled(); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10378 | } |
| 10379 | |
| 10380 | // If we have 2 windows with identical timeouts that are both unresponsive, |
| 10381 | // it doesn't matter which order they should have ANR. |
| 10382 | // But we should receive ANR for both. |
| 10383 | TEST_F(InputDispatcherMultiWindowAnr, TwoWindows_BothUnresponsiveWithSameTimeout) { |
| 10384 | // Set the timeout for unfocused window to match the focused window |
Siarhei Vishniakou | f83c693 | 2023-07-07 17:48:10 -0700 | [diff] [blame] | 10385 | mUnfocusedWindow->setDispatchingTimeout( |
| 10386 | mFocusedWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT)); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 10387 | mDispatcher->onWindowInfosChanged( |
| 10388 | {{*mUnfocusedWindow->getInfo(), *mFocusedWindow->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10389 | |
| 10390 | tapOnFocusedWindow(); |
| 10391 | // we should have ACTION_DOWN/ACTION_UP on focused window and ACTION_OUTSIDE on unfocused window |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10392 | // We don't know which window will ANR first. But both of them should happen eventually. |
Siarhei Vishniakou | f83c693 | 2023-07-07 17:48:10 -0700 | [diff] [blame] | 10393 | std::array<sp<IBinder>, 2> anrConnectionTokens = {mFakePolicy->getUnresponsiveWindowToken( |
| 10394 | mFocusedWindow->getDispatchingTimeout( |
| 10395 | DISPATCHING_TIMEOUT)), |
| 10396 | mFakePolicy->getUnresponsiveWindowToken(0ms)}; |
| 10397 | |
| 10398 | ASSERT_THAT(anrConnectionTokens, |
| 10399 | ::testing::UnorderedElementsAre(testing::Eq(mFocusedWindow->getToken()), |
| 10400 | testing::Eq(mUnfocusedWindow->getToken()))); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10401 | |
| 10402 | ASSERT_TRUE(mDispatcher->waitForIdle()); |
| 10403 | mFakePolicy->assertNotifyAnrWasNotCalled(); |
Siarhei Vishniakou | 234129c | 2020-10-22 22:28:12 -0500 | [diff] [blame] | 10404 | |
| 10405 | mFocusedWindow->consumeMotionDown(); |
| 10406 | mFocusedWindow->consumeMotionUp(); |
| 10407 | mUnfocusedWindow->consumeMotionOutside(); |
| 10408 | |
Siarhei Vishniakou | f83c693 | 2023-07-07 17:48:10 -0700 | [diff] [blame] | 10409 | std::array<sp<IBinder>, 2> responsiveTokens = {mFakePolicy->getResponsiveWindowToken(), |
| 10410 | mFakePolicy->getResponsiveWindowToken()}; |
Siarhei Vishniakou | 234129c | 2020-10-22 22:28:12 -0500 | [diff] [blame] | 10411 | |
| 10412 | // Both applications should be marked as responsive, in any order |
Siarhei Vishniakou | f83c693 | 2023-07-07 17:48:10 -0700 | [diff] [blame] | 10413 | ASSERT_THAT(responsiveTokens, |
| 10414 | ::testing::UnorderedElementsAre(testing::Eq(mFocusedWindow->getToken()), |
| 10415 | testing::Eq(mUnfocusedWindow->getToken()))); |
Siarhei Vishniakou | 234129c | 2020-10-22 22:28:12 -0500 | [diff] [blame] | 10416 | mFakePolicy->assertNotifyAnrWasNotCalled(); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10417 | } |
| 10418 | |
| 10419 | // If a window is already not responding, the second tap on the same window should be ignored. |
| 10420 | // We should also log an error to account for the dropped event (not tested here). |
| 10421 | // At the same time, FLAG_WATCH_OUTSIDE_TOUCH targets should not receive any events. |
| 10422 | TEST_F(InputDispatcherMultiWindowAnr, DuringAnr_SecondTapIsIgnored) { |
| 10423 | tapOnFocusedWindow(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10424 | mUnfocusedWindow->consumeMotionOutside(ui::LogicalDisplayId::DEFAULT, /*flags=*/0); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10425 | // Receive the events, but don't respond |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 10426 | const auto [downEventSequenceNum, downEvent] = mFocusedWindow->receiveEvent(); // ACTION_DOWN |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10427 | ASSERT_TRUE(downEventSequenceNum); |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 10428 | const auto [upEventSequenceNum, upEvent] = mFocusedWindow->receiveEvent(); // ACTION_UP |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10429 | ASSERT_TRUE(upEventSequenceNum); |
| 10430 | const std::chrono::duration timeout = |
| 10431 | mFocusedWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT); |
Prabir Pradhan | edd9640 | 2022-02-15 01:46:16 -0800 | [diff] [blame] | 10432 | mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(timeout, mFocusedWindow); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10433 | |
| 10434 | // Tap once again |
| 10435 | // We cannot use "tapOnFocusedWindow" because it asserts the injection result to be success |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 10436 | ASSERT_EQ(InputEventInjectionResult::FAILED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10437 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 10438 | ui::LogicalDisplayId::DEFAULT, FOCUSED_WINDOW_LOCATION)); |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 10439 | ASSERT_EQ(InputEventInjectionResult::FAILED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10440 | injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10441 | FOCUSED_WINDOW_LOCATION)); |
| 10442 | // Unfocused window does not receive ACTION_OUTSIDE because the tapped window is not a |
| 10443 | // valid touch target |
| 10444 | mUnfocusedWindow->assertNoEvents(); |
| 10445 | |
| 10446 | // Consume the first tap |
| 10447 | mFocusedWindow->finishEvent(*downEventSequenceNum); |
| 10448 | mFocusedWindow->finishEvent(*upEventSequenceNum); |
| 10449 | ASSERT_TRUE(mDispatcher->waitForIdle()); |
| 10450 | // The second tap did not go to the focused window |
| 10451 | mFocusedWindow->assertNoEvents(); |
Siarhei Vishniakou | 234129c | 2020-10-22 22:28:12 -0500 | [diff] [blame] | 10452 | // Since all events are finished, connection should be deemed healthy again |
Prabir Pradhan | edd9640 | 2022-02-15 01:46:16 -0800 | [diff] [blame] | 10453 | mFakePolicy->assertNotifyWindowResponsiveWasCalled(mFocusedWindow->getToken(), |
| 10454 | mFocusedWindow->getPid()); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10455 | mFakePolicy->assertNotifyAnrWasNotCalled(); |
| 10456 | } |
| 10457 | |
| 10458 | // If you tap outside of all windows, there will not be ANR |
| 10459 | TEST_F(InputDispatcherMultiWindowAnr, TapOutsideAllWindows_DoesNotAnr) { |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 10460 | ASSERT_EQ(InputEventInjectionResult::FAILED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10461 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 10462 | ui::LogicalDisplayId::DEFAULT, LOCATION_OUTSIDE_ALL_WINDOWS)); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10463 | ASSERT_TRUE(mDispatcher->waitForIdle()); |
| 10464 | mFakePolicy->assertNotifyAnrWasNotCalled(); |
| 10465 | } |
| 10466 | |
| 10467 | // Since the focused window is paused, tapping on it should not produce any events |
| 10468 | TEST_F(InputDispatcherMultiWindowAnr, Window_CanBePaused) { |
| 10469 | mFocusedWindow->setPaused(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 10470 | mDispatcher->onWindowInfosChanged( |
| 10471 | {{*mUnfocusedWindow->getInfo(), *mFocusedWindow->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10472 | |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 10473 | ASSERT_EQ(InputEventInjectionResult::FAILED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10474 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 10475 | ui::LogicalDisplayId::DEFAULT, FOCUSED_WINDOW_LOCATION)); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10476 | |
| 10477 | std::this_thread::sleep_for(mFocusedWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT)); |
| 10478 | ASSERT_TRUE(mDispatcher->waitForIdle()); |
| 10479 | // Should not ANR because the window is paused, and touches shouldn't go to it |
| 10480 | mFakePolicy->assertNotifyAnrWasNotCalled(); |
| 10481 | |
| 10482 | mFocusedWindow->assertNoEvents(); |
| 10483 | mUnfocusedWindow->assertNoEvents(); |
| 10484 | } |
| 10485 | |
| 10486 | /** |
| 10487 | * If a window is processing a motion event, and then a key event comes in, the key event should |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 10488 | * not get delivered to the focused window until the motion is processed. |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10489 | * If a different window becomes focused at this time, the key should go to that window instead. |
| 10490 | * |
| 10491 | * Warning!!! |
| 10492 | * This test depends on the value of android::inputdispatcher::KEY_WAITING_FOR_MOTION_TIMEOUT |
| 10493 | * and the injection timeout that we specify when injecting the key. |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 10494 | * We must have the injection timeout (100ms) be smaller than |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10495 | * KEY_WAITING_FOR_MOTION_TIMEOUT (currently 500ms). |
| 10496 | * |
| 10497 | * If that value changes, this test should also change. |
| 10498 | */ |
| 10499 | TEST_F(InputDispatcherMultiWindowAnr, PendingKey_GoesToNewlyFocusedWindow) { |
| 10500 | // Set a long ANR timeout to prevent it from triggering |
| 10501 | mFocusedWindow->setDispatchingTimeout(2s); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 10502 | mDispatcher->onWindowInfosChanged( |
| 10503 | {{*mFocusedWindow->getInfo(), *mUnfocusedWindow->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10504 | |
| 10505 | tapOnUnfocusedWindow(); |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 10506 | const auto [downSequenceNum, downEvent] = mUnfocusedWindow->receiveEvent(); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10507 | ASSERT_TRUE(downSequenceNum); |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 10508 | const auto [upSequenceNum, upEvent] = mUnfocusedWindow->receiveEvent(); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10509 | ASSERT_TRUE(upSequenceNum); |
| 10510 | // Don't finish the events yet, and send a key |
| 10511 | // Injection will succeed because we will eventually give up and send the key to the focused |
| 10512 | // window even if motions are still being processed. |
| 10513 | |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 10514 | InputEventInjectionResult result = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10515 | injectKey(*mDispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, |
| 10516 | ui::LogicalDisplayId::DEFAULT, InputEventInjectionSync::NONE, |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 10517 | /*injectionTimeout=*/100ms); |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 10518 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, result); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10519 | // Key will not be sent to the window, yet, because the window is still processing events |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 10520 | // and the key remains pending, waiting for the touch events to be processed. |
| 10521 | // Make sure `assertNoEvents` doesn't take too long. It uses CONSUME_TIMEOUT_NO_EVENT_EXPECTED |
| 10522 | // under the hood. |
| 10523 | static_assert(CONSUME_TIMEOUT_NO_EVENT_EXPECTED < 100ms); |
| 10524 | mFocusedWindow->assertNoEvents(); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10525 | |
| 10526 | // Switch the focus to the "unfocused" window that we tapped. Expect the key to go there |
Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 10527 | mFocusedWindow->setFocusable(false); |
| 10528 | mUnfocusedWindow->setFocusable(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 10529 | mDispatcher->onWindowInfosChanged( |
| 10530 | {{*mFocusedWindow->getInfo(), *mUnfocusedWindow->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 10531 | setFocusedWindow(mUnfocusedWindow); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10532 | |
| 10533 | // Focus events should precede the key events |
| 10534 | mUnfocusedWindow->consumeFocusEvent(true); |
| 10535 | mFocusedWindow->consumeFocusEvent(false); |
| 10536 | |
| 10537 | // Finish the tap events, which should unblock dispatcher |
| 10538 | mUnfocusedWindow->finishEvent(*downSequenceNum); |
| 10539 | mUnfocusedWindow->finishEvent(*upSequenceNum); |
| 10540 | |
| 10541 | // Now that all queues are cleared and no backlog in the connections, the key event |
| 10542 | // can finally go to the newly focused "mUnfocusedWindow". |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10543 | mUnfocusedWindow->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10544 | mFocusedWindow->assertNoEvents(); |
| 10545 | mUnfocusedWindow->assertNoEvents(); |
Siarhei Vishniakou | 234129c | 2020-10-22 22:28:12 -0500 | [diff] [blame] | 10546 | mFakePolicy->assertNotifyAnrWasNotCalled(); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10547 | } |
| 10548 | |
| 10549 | // When the touch stream is split across 2 windows, and one of them does not respond, |
| 10550 | // then ANR should be raised and the touch should be canceled for the unresponsive window. |
| 10551 | // The other window should not be affected by that. |
| 10552 | TEST_F(InputDispatcherMultiWindowAnr, SplitTouch_SingleWindowAnr) { |
| 10553 | // Touch Window 1 |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10554 | mDispatcher->notifyMotion( |
| 10555 | generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, |
| 10556 | ui::LogicalDisplayId::DEFAULT, {FOCUSED_WINDOW_LOCATION})); |
| 10557 | mUnfocusedWindow->consumeMotionOutside(ui::LogicalDisplayId::DEFAULT, /*flags=*/0); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10558 | |
| 10559 | // Touch Window 2 |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 10560 | mDispatcher->notifyMotion( |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10561 | generateMotionArgs(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN, |
| 10562 | ui::LogicalDisplayId::DEFAULT, |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 10563 | {FOCUSED_WINDOW_LOCATION, UNFOCUSED_WINDOW_LOCATION})); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10564 | |
| 10565 | const std::chrono::duration timeout = |
| 10566 | mFocusedWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT); |
Prabir Pradhan | edd9640 | 2022-02-15 01:46:16 -0800 | [diff] [blame] | 10567 | mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(timeout, mFocusedWindow); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10568 | |
| 10569 | mUnfocusedWindow->consumeMotionDown(); |
| 10570 | mFocusedWindow->consumeMotionDown(); |
| 10571 | // Focused window may or may not receive ACTION_MOVE |
| 10572 | // But it should definitely receive ACTION_CANCEL due to the ANR |
Siarhei Vishniakou | d3061ab | 2023-12-18 20:41:08 -0800 | [diff] [blame] | 10573 | const auto [moveOrCancelSequenceNum, event] = mFocusedWindow->receiveEvent(); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10574 | ASSERT_TRUE(moveOrCancelSequenceNum); |
| 10575 | mFocusedWindow->finishEvent(*moveOrCancelSequenceNum); |
| 10576 | ASSERT_NE(nullptr, event); |
Siarhei Vishniakou | 63b6361 | 2023-04-12 11:00:23 -0700 | [diff] [blame] | 10577 | ASSERT_EQ(event->getType(), InputEventType::MOTION); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10578 | MotionEvent& motionEvent = static_cast<MotionEvent&>(*event); |
| 10579 | if (motionEvent.getAction() == AMOTION_EVENT_ACTION_MOVE) { |
| 10580 | mFocusedWindow->consumeMotionCancel(); |
| 10581 | } else { |
| 10582 | ASSERT_EQ(AMOTION_EVENT_ACTION_CANCEL, motionEvent.getAction()); |
| 10583 | } |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10584 | ASSERT_TRUE(mDispatcher->waitForIdle()); |
Prabir Pradhan | edd9640 | 2022-02-15 01:46:16 -0800 | [diff] [blame] | 10585 | mFakePolicy->assertNotifyWindowResponsiveWasCalled(mFocusedWindow->getToken(), |
| 10586 | mFocusedWindow->getPid()); |
Siarhei Vishniakou | 234129c | 2020-10-22 22:28:12 -0500 | [diff] [blame] | 10587 | |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10588 | mUnfocusedWindow->assertNoEvents(); |
| 10589 | mFocusedWindow->assertNoEvents(); |
Siarhei Vishniakou | 234129c | 2020-10-22 22:28:12 -0500 | [diff] [blame] | 10590 | mFakePolicy->assertNotifyAnrWasNotCalled(); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 10591 | } |
| 10592 | |
Siarhei Vishniakou | f56b269 | 2020-09-08 19:43:33 -0500 | [diff] [blame] | 10593 | /** |
| 10594 | * If we have no focused window, and a key comes in, we start the ANR timer. |
| 10595 | * The focused application should add a focused window before the timer runs out to prevent ANR. |
| 10596 | * |
| 10597 | * If the user touches another application during this time, the key should be dropped. |
| 10598 | * Next, if a new focused window comes in, without toggling the focused application, |
| 10599 | * then no ANR should occur. |
| 10600 | * |
| 10601 | * Normally, we would expect the new focused window to be accompanied by 'setFocusedApplication', |
| 10602 | * but in some cases the policy may not update the focused application. |
| 10603 | */ |
| 10604 | TEST_F(InputDispatcherMultiWindowAnr, FocusedWindowWithoutSetFocusedApplication_NoAnr) { |
| 10605 | std::shared_ptr<FakeApplicationHandle> focusedApplication = |
| 10606 | std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | c033dfb | 2023-10-03 10:45:16 -0700 | [diff] [blame] | 10607 | focusedApplication->setDispatchingTimeout(300ms); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10608 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, focusedApplication); |
Siarhei Vishniakou | f56b269 | 2020-09-08 19:43:33 -0500 | [diff] [blame] | 10609 | // The application that owns 'mFocusedWindow' and 'mUnfocusedWindow' is not focused. |
| 10610 | mFocusedWindow->setFocusable(false); |
| 10611 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 10612 | mDispatcher->onWindowInfosChanged( |
| 10613 | {{*mFocusedWindow->getInfo(), *mUnfocusedWindow->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | f56b269 | 2020-09-08 19:43:33 -0500 | [diff] [blame] | 10614 | mFocusedWindow->consumeFocusEvent(false); |
| 10615 | |
| 10616 | // Send a key. The ANR timer should start because there is no focused window. |
| 10617 | // 'focusedApplication' will get blamed if this timer completes. |
| 10618 | // Key will not be sent anywhere because we have no focused window. It will remain pending. |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 10619 | InputEventInjectionResult result = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10620 | injectKey(*mDispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, |
| 10621 | ui::LogicalDisplayId::DEFAULT, InputEventInjectionSync::NONE, |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 10622 | /*injectionTimeout=*/100ms, |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 10623 | /*allowKeyRepeat=*/false); |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 10624 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, result); |
Siarhei Vishniakou | f56b269 | 2020-09-08 19:43:33 -0500 | [diff] [blame] | 10625 | |
| 10626 | // Wait until dispatcher starts the "no focused window" timer. If we don't wait here, |
| 10627 | // then the injected touches won't cause the focused event to get dropped. |
| 10628 | // The dispatcher only checks for whether the queue should be pruned upon queueing. |
| 10629 | // If we inject the touch right away and the ANR timer hasn't started, the touch event would |
| 10630 | // simply be added to the queue without 'shouldPruneInboundQueueLocked' returning 'true'. |
| 10631 | // For this test, it means that the key would get delivered to the window once it becomes |
| 10632 | // focused. |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 10633 | std::this_thread::sleep_for(100ms); |
Siarhei Vishniakou | f56b269 | 2020-09-08 19:43:33 -0500 | [diff] [blame] | 10634 | |
| 10635 | // Touch unfocused window. This should force the pending key to get dropped. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10636 | mDispatcher->notifyMotion( |
| 10637 | generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, |
| 10638 | ui::LogicalDisplayId::DEFAULT, {UNFOCUSED_WINDOW_LOCATION})); |
Siarhei Vishniakou | f56b269 | 2020-09-08 19:43:33 -0500 | [diff] [blame] | 10639 | |
| 10640 | // We do not consume the motion right away, because that would require dispatcher to first |
| 10641 | // process (== drop) the key event, and by that time, ANR will be raised. |
| 10642 | // Set the focused window first. |
| 10643 | mFocusedWindow->setFocusable(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 10644 | mDispatcher->onWindowInfosChanged( |
| 10645 | {{*mFocusedWindow->getInfo(), *mUnfocusedWindow->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | f56b269 | 2020-09-08 19:43:33 -0500 | [diff] [blame] | 10646 | setFocusedWindow(mFocusedWindow); |
| 10647 | mFocusedWindow->consumeFocusEvent(true); |
| 10648 | // We do not call "setFocusedApplication" here, even though the newly focused window belongs |
| 10649 | // to another application. This could be a bug / behaviour in the policy. |
| 10650 | |
| 10651 | mUnfocusedWindow->consumeMotionDown(); |
| 10652 | |
| 10653 | ASSERT_TRUE(mDispatcher->waitForIdle()); |
| 10654 | // Should not ANR because we actually have a focused window. It was just added too slowly. |
| 10655 | ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertNotifyAnrWasNotCalled()); |
| 10656 | } |
| 10657 | |
Siarhei Vishniakou | 99e407b | 2023-12-26 18:09:32 -0800 | [diff] [blame] | 10658 | /** |
| 10659 | * If we are pruning input queue, we should never drop pointer events. Otherwise, we risk having |
| 10660 | * an inconsistent event stream inside the dispatcher. In this test, we make sure that the |
| 10661 | * dispatcher doesn't prune pointer events incorrectly. |
| 10662 | * |
| 10663 | * This test reproduces a crash in InputDispatcher. |
| 10664 | * To reproduce the crash, we need to simulate the conditions for "pruning input queue" to occur. |
| 10665 | * |
| 10666 | * Keep the currently focused application (mApplication), and have no focused window. |
| 10667 | * We set up two additional windows: |
| 10668 | * 1) The navigation bar window. This simulates the system "NavigationBar", which is used in the |
| 10669 | * 3-button navigation mode. This window injects a BACK button when it's touched. 2) The application |
| 10670 | * window. This window is not focusable, but is touchable. |
| 10671 | * |
| 10672 | * We first touch the navigation bar, which causes it to inject a key. Since there's no focused |
| 10673 | * window, the dispatcher doesn't process this key, and all other events inside dispatcher are now |
| 10674 | * blocked. The dispatcher is waiting for 'mApplication' to add a focused window. |
| 10675 | * |
| 10676 | * Now, we touch "Another window". This window is owned by a different application than |
| 10677 | * 'mApplication'. This causes the dispatcher to stop waiting for 'mApplication' to add a focused |
| 10678 | * window. Now, the "pruning input queue" behaviour should kick in, and the dispatcher should start |
| 10679 | * dropping the events from its queue. Ensure that no crash occurs. |
| 10680 | * |
| 10681 | * In this test, we are setting long timeouts to prevent ANRs and events dropped due to being stale. |
| 10682 | * This does not affect the test running time. |
| 10683 | */ |
| 10684 | TEST_F(InputDispatcherMultiWindowAnr, PruningInputQueueShouldNotDropPointerEvents) { |
| 10685 | std::shared_ptr<FakeApplicationHandle> systemUiApplication = |
| 10686 | std::make_shared<FakeApplicationHandle>(); |
| 10687 | systemUiApplication->setDispatchingTimeout(3000ms); |
| 10688 | mFakePolicy->setStaleEventTimeout(3000ms); |
| 10689 | sp<FakeWindowHandle> navigationBar = |
| 10690 | sp<FakeWindowHandle>::make(systemUiApplication, mDispatcher, "NavigationBar", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10691 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 99e407b | 2023-12-26 18:09:32 -0800 | [diff] [blame] | 10692 | navigationBar->setFocusable(false); |
| 10693 | navigationBar->setWatchOutsideTouch(true); |
| 10694 | navigationBar->setFrame(Rect(0, 0, 100, 100)); |
| 10695 | |
| 10696 | mApplication->setDispatchingTimeout(3000ms); |
| 10697 | // 'mApplication' is already focused, but we call it again here to make it explicit. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10698 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, mApplication); |
Siarhei Vishniakou | 99e407b | 2023-12-26 18:09:32 -0800 | [diff] [blame] | 10699 | |
| 10700 | std::shared_ptr<FakeApplicationHandle> anotherApplication = |
| 10701 | std::make_shared<FakeApplicationHandle>(); |
| 10702 | sp<FakeWindowHandle> appWindow = |
| 10703 | sp<FakeWindowHandle>::make(anotherApplication, mDispatcher, "Another window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10704 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | 99e407b | 2023-12-26 18:09:32 -0800 | [diff] [blame] | 10705 | appWindow->setFocusable(false); |
| 10706 | appWindow->setFrame(Rect(100, 100, 200, 200)); |
| 10707 | |
| 10708 | mDispatcher->onWindowInfosChanged( |
| 10709 | {{*navigationBar->getInfo(), *appWindow->getInfo()}, {}, 0, 0}); |
| 10710 | // 'mFocusedWindow' is no longer in the dispatcher window list, and therefore loses focus |
| 10711 | mFocusedWindow->consumeFocusEvent(false); |
| 10712 | |
| 10713 | // Touch down the navigation bar. It consumes the touch and injects a key into the dispatcher |
| 10714 | // in response. |
| 10715 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 10716 | .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) |
| 10717 | .build()); |
| 10718 | navigationBar->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); |
| 10719 | |
| 10720 | // Key will not be sent anywhere because we have no focused window. It will remain pending. |
| 10721 | // Pretend we are injecting KEYCODE_BACK, but it doesn't actually matter what key it is. |
| 10722 | InputEventInjectionResult result = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10723 | injectKey(*mDispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, |
| 10724 | ui::LogicalDisplayId::DEFAULT, InputEventInjectionSync::NONE, |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 10725 | /*injectionTimeout=*/100ms, |
Siarhei Vishniakou | 99e407b | 2023-12-26 18:09:32 -0800 | [diff] [blame] | 10726 | /*allowKeyRepeat=*/false); |
| 10727 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, result); |
| 10728 | |
| 10729 | // Finish the gesture - lift up finger and inject ACTION_UP key event |
| 10730 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN) |
| 10731 | .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) |
| 10732 | .build()); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10733 | result = injectKey(*mDispatcher, AKEY_EVENT_ACTION_UP, /*repeatCount=*/0, |
| 10734 | ui::LogicalDisplayId::DEFAULT, InputEventInjectionSync::NONE, |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 10735 | /*injectionTimeout=*/100ms, |
Siarhei Vishniakou | 99e407b | 2023-12-26 18:09:32 -0800 | [diff] [blame] | 10736 | /*allowKeyRepeat=*/false); |
| 10737 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, result); |
| 10738 | // The key that was injected is blocking the dispatcher, so the navigation bar shouldn't be |
| 10739 | // getting any events yet. |
| 10740 | navigationBar->assertNoEvents(); |
| 10741 | |
| 10742 | // Now touch "Another window". This touch is going to a different application than the one we |
| 10743 | // are waiting for (which is 'mApplication'). |
| 10744 | // This should cause the dispatcher to drop the pending focus-dispatched events (like the key |
| 10745 | // trying to be injected) and to continue processing the rest of the events in the original |
| 10746 | // order. |
| 10747 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 10748 | .pointer(PointerBuilder(0, ToolType::FINGER).x(150).y(150)) |
| 10749 | .build()); |
| 10750 | navigationBar->consumeMotionEvent(WithMotionAction(ACTION_UP)); |
| 10751 | navigationBar->consumeMotionEvent(WithMotionAction(ACTION_OUTSIDE)); |
| 10752 | appWindow->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); |
| 10753 | |
| 10754 | appWindow->assertNoEvents(); |
| 10755 | navigationBar->assertNoEvents(); |
| 10756 | } |
| 10757 | |
Siarhei Vishniakou | a2862a0 | 2020-07-20 16:36:46 -0500 | [diff] [blame] | 10758 | // These tests ensure we cannot send touch events to a window that's positioned behind a window |
| 10759 | // that has feature NO_INPUT_CHANNEL. |
| 10760 | // Layout: |
| 10761 | // Top (closest to user) |
| 10762 | // mNoInputWindow (above all windows) |
| 10763 | // mBottomWindow |
| 10764 | // Bottom (furthest from user) |
| 10765 | class InputDispatcherMultiWindowOcclusionTests : public InputDispatcherTest { |
| 10766 | virtual void SetUp() override { |
| 10767 | InputDispatcherTest::SetUp(); |
| 10768 | |
| 10769 | mApplication = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10770 | mNoInputWindow = sp<FakeWindowHandle>::make(mApplication, mDispatcher, |
| 10771 | "Window without input channel", |
| 10772 | ui::LogicalDisplayId::DEFAULT, |
| 10773 | /*createInputChannel=*/false); |
Prabir Pradhan | 51e7db0 | 2022-02-07 06:02:57 -0800 | [diff] [blame] | 10774 | mNoInputWindow->setNoInputChannel(true); |
Siarhei Vishniakou | a2862a0 | 2020-07-20 16:36:46 -0500 | [diff] [blame] | 10775 | mNoInputWindow->setFrame(Rect(0, 0, 100, 100)); |
| 10776 | // It's perfectly valid for this window to not have an associated input channel |
| 10777 | |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 10778 | mBottomWindow = sp<FakeWindowHandle>::make(mApplication, mDispatcher, "Bottom window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10779 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | a2862a0 | 2020-07-20 16:36:46 -0500 | [diff] [blame] | 10780 | mBottomWindow->setFrame(Rect(0, 0, 100, 100)); |
| 10781 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 10782 | mDispatcher->onWindowInfosChanged( |
| 10783 | {{*mNoInputWindow->getInfo(), *mBottomWindow->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | a2862a0 | 2020-07-20 16:36:46 -0500 | [diff] [blame] | 10784 | } |
| 10785 | |
| 10786 | protected: |
| 10787 | std::shared_ptr<FakeApplicationHandle> mApplication; |
| 10788 | sp<FakeWindowHandle> mNoInputWindow; |
| 10789 | sp<FakeWindowHandle> mBottomWindow; |
| 10790 | }; |
| 10791 | |
| 10792 | TEST_F(InputDispatcherMultiWindowOcclusionTests, NoInputChannelFeature_DropsTouches) { |
| 10793 | PointF touchedPoint = {10, 10}; |
| 10794 | |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 10795 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10796 | AINPUT_SOURCE_TOUCHSCREEN, |
| 10797 | ui::LogicalDisplayId::DEFAULT, {touchedPoint})); |
Siarhei Vishniakou | a2862a0 | 2020-07-20 16:36:46 -0500 | [diff] [blame] | 10798 | |
| 10799 | mNoInputWindow->assertNoEvents(); |
| 10800 | // Even though the window 'mNoInputWindow' positioned above 'mBottomWindow' does not have |
| 10801 | // an input channel, it is not marked as FLAG_NOT_TOUCHABLE, |
| 10802 | // and therefore should prevent mBottomWindow from receiving touches |
| 10803 | mBottomWindow->assertNoEvents(); |
| 10804 | } |
| 10805 | |
| 10806 | /** |
| 10807 | * If a window has feature NO_INPUT_CHANNEL, and somehow (by mistake) still has an input channel, |
| 10808 | * ensure that this window does not receive any touches, and blocks touches to windows underneath. |
| 10809 | */ |
| 10810 | TEST_F(InputDispatcherMultiWindowOcclusionTests, |
| 10811 | NoInputChannelFeature_DropsTouchesWithValidChannel) { |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 10812 | mNoInputWindow = sp<FakeWindowHandle>::make(mApplication, mDispatcher, |
| 10813 | "Window with input channel and NO_INPUT_CHANNEL", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10814 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | a2862a0 | 2020-07-20 16:36:46 -0500 | [diff] [blame] | 10815 | |
Prabir Pradhan | 51e7db0 | 2022-02-07 06:02:57 -0800 | [diff] [blame] | 10816 | mNoInputWindow->setNoInputChannel(true); |
Siarhei Vishniakou | a2862a0 | 2020-07-20 16:36:46 -0500 | [diff] [blame] | 10817 | mNoInputWindow->setFrame(Rect(0, 0, 100, 100)); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 10818 | mDispatcher->onWindowInfosChanged( |
| 10819 | {{*mNoInputWindow->getInfo(), *mBottomWindow->getInfo()}, {}, 0, 0}); |
Siarhei Vishniakou | a2862a0 | 2020-07-20 16:36:46 -0500 | [diff] [blame] | 10820 | |
| 10821 | PointF touchedPoint = {10, 10}; |
| 10822 | |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 10823 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10824 | AINPUT_SOURCE_TOUCHSCREEN, |
| 10825 | ui::LogicalDisplayId::DEFAULT, {touchedPoint})); |
Siarhei Vishniakou | a2862a0 | 2020-07-20 16:36:46 -0500 | [diff] [blame] | 10826 | |
| 10827 | mNoInputWindow->assertNoEvents(); |
| 10828 | mBottomWindow->assertNoEvents(); |
| 10829 | } |
| 10830 | |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 10831 | class InputDispatcherMirrorWindowFocusTests : public InputDispatcherTest { |
| 10832 | protected: |
| 10833 | std::shared_ptr<FakeApplicationHandle> mApp; |
| 10834 | sp<FakeWindowHandle> mWindow; |
| 10835 | sp<FakeWindowHandle> mMirror; |
| 10836 | |
| 10837 | virtual void SetUp() override { |
| 10838 | InputDispatcherTest::SetUp(); |
| 10839 | mApp = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10840 | mWindow = sp<FakeWindowHandle>::make(mApp, mDispatcher, "TestWindow", |
| 10841 | ui::LogicalDisplayId::DEFAULT); |
| 10842 | mMirror = mWindow->clone(ui::LogicalDisplayId::DEFAULT); |
| 10843 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, mApp); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 10844 | mWindow->setFocusable(true); |
| 10845 | mMirror->setFocusable(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 10846 | mDispatcher->onWindowInfosChanged({{*mWindow->getInfo(), *mMirror->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 10847 | } |
| 10848 | }; |
| 10849 | |
| 10850 | TEST_F(InputDispatcherMirrorWindowFocusTests, CanGetFocus) { |
| 10851 | // Request focus on a mirrored window |
| 10852 | setFocusedWindow(mMirror); |
| 10853 | |
| 10854 | // window gets focused |
| 10855 | mWindow->consumeFocusEvent(true); |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 10856 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(*mDispatcher)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 10857 | << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10858 | mWindow->consumeKeyDown(ui::LogicalDisplayId::INVALID); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 10859 | } |
| 10860 | |
| 10861 | // A focused & mirrored window remains focused only if the window and its mirror are both |
| 10862 | // focusable. |
| 10863 | TEST_F(InputDispatcherMirrorWindowFocusTests, FocusedIfAllWindowsFocusable) { |
| 10864 | setFocusedWindow(mMirror); |
| 10865 | |
Prabir Pradhan | bb3f1c0 | 2024-01-04 20:17:14 +0000 | [diff] [blame] | 10866 | // window gets focused because it is above the mirror |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 10867 | mWindow->consumeFocusEvent(true); |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 10868 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(*mDispatcher)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 10869 | << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10870 | mWindow->consumeKeyDown(ui::LogicalDisplayId::INVALID); |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 10871 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyUp(*mDispatcher)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 10872 | << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10873 | mWindow->consumeKeyUp(ui::LogicalDisplayId::INVALID); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 10874 | |
| 10875 | mMirror->setFocusable(false); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 10876 | mDispatcher->onWindowInfosChanged({{*mWindow->getInfo(), *mMirror->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 10877 | |
| 10878 | // window loses focus since one of the windows associated with the token in not focusable |
| 10879 | mWindow->consumeFocusEvent(false); |
| 10880 | |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 10881 | ASSERT_EQ(InputEventInjectionResult::TIMED_OUT, injectKeyDown(*mDispatcher)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 10882 | << "Inject key event should return InputEventInjectionResult::TIMED_OUT"; |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 10883 | mWindow->assertNoEvents(); |
| 10884 | } |
| 10885 | |
| 10886 | // A focused & mirrored window remains focused until the window and its mirror both become |
| 10887 | // invisible. |
| 10888 | TEST_F(InputDispatcherMirrorWindowFocusTests, FocusedIfAnyWindowVisible) { |
| 10889 | setFocusedWindow(mMirror); |
| 10890 | |
| 10891 | // window gets focused |
| 10892 | mWindow->consumeFocusEvent(true); |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 10893 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(*mDispatcher)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 10894 | << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10895 | mWindow->consumeKeyDown(ui::LogicalDisplayId::INVALID); |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 10896 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyUp(*mDispatcher)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 10897 | << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10898 | mWindow->consumeKeyUp(ui::LogicalDisplayId::INVALID); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 10899 | |
| 10900 | mMirror->setVisible(false); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 10901 | mDispatcher->onWindowInfosChanged({{*mWindow->getInfo(), *mMirror->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 10902 | |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 10903 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(*mDispatcher)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 10904 | << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10905 | mWindow->consumeKeyDown(ui::LogicalDisplayId::INVALID); |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 10906 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyUp(*mDispatcher)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 10907 | << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10908 | mWindow->consumeKeyUp(ui::LogicalDisplayId::INVALID); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 10909 | |
| 10910 | mWindow->setVisible(false); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 10911 | mDispatcher->onWindowInfosChanged({{*mWindow->getInfo(), *mMirror->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 10912 | |
| 10913 | // window loses focus only after all windows associated with the token become invisible. |
| 10914 | mWindow->consumeFocusEvent(false); |
| 10915 | |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 10916 | ASSERT_EQ(InputEventInjectionResult::TIMED_OUT, injectKeyDown(*mDispatcher)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 10917 | << "Inject key event should return InputEventInjectionResult::TIMED_OUT"; |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 10918 | mWindow->assertNoEvents(); |
| 10919 | } |
| 10920 | |
| 10921 | // A focused & mirrored window remains focused until both windows are removed. |
| 10922 | TEST_F(InputDispatcherMirrorWindowFocusTests, FocusedWhileWindowsAlive) { |
| 10923 | setFocusedWindow(mMirror); |
| 10924 | |
| 10925 | // window gets focused |
| 10926 | mWindow->consumeFocusEvent(true); |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 10927 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(*mDispatcher)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 10928 | << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10929 | mWindow->consumeKeyDown(ui::LogicalDisplayId::INVALID); |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 10930 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyUp(*mDispatcher)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 10931 | << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10932 | mWindow->consumeKeyUp(ui::LogicalDisplayId::INVALID); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 10933 | |
| 10934 | // single window is removed but the window token remains focused |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 10935 | mDispatcher->onWindowInfosChanged({{*mMirror->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 10936 | |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 10937 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(*mDispatcher)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 10938 | << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10939 | mMirror->consumeKeyDown(ui::LogicalDisplayId::INVALID); |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 10940 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyUp(*mDispatcher)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 10941 | << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10942 | mMirror->consumeKeyUp(ui::LogicalDisplayId::INVALID); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 10943 | |
| 10944 | // Both windows are removed |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 10945 | mDispatcher->onWindowInfosChanged({{}, {}, 0, 0}); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 10946 | mWindow->consumeFocusEvent(false); |
| 10947 | |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 10948 | ASSERT_EQ(InputEventInjectionResult::TIMED_OUT, injectKeyDown(*mDispatcher)) |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 10949 | << "Inject key event should return InputEventInjectionResult::TIMED_OUT"; |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 10950 | mWindow->assertNoEvents(); |
| 10951 | } |
| 10952 | |
| 10953 | // Focus request can be pending until one window becomes visible. |
| 10954 | TEST_F(InputDispatcherMirrorWindowFocusTests, DeferFocusWhenInvisible) { |
| 10955 | // Request focus on an invisible mirror. |
| 10956 | mWindow->setVisible(false); |
| 10957 | mMirror->setVisible(false); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 10958 | mDispatcher->onWindowInfosChanged({{*mWindow->getInfo(), *mMirror->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 10959 | setFocusedWindow(mMirror); |
| 10960 | |
| 10961 | // Injected key goes to pending queue. |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 10962 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 10963 | injectKey(*mDispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10964 | ui::LogicalDisplayId::DEFAULT, InputEventInjectionSync::NONE)); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 10965 | |
| 10966 | mMirror->setVisible(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 10967 | mDispatcher->onWindowInfosChanged({{*mWindow->getInfo(), *mMirror->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 10968 | |
| 10969 | // window gets focused |
| 10970 | mWindow->consumeFocusEvent(true); |
| 10971 | // window gets the pending key event |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10972 | mWindow->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 10973 | } |
Prabir Pradhan | 9998771 | 2020-11-10 18:43:05 -0800 | [diff] [blame] | 10974 | |
| 10975 | class InputDispatcherPointerCaptureTests : public InputDispatcherTest { |
| 10976 | protected: |
| 10977 | std::shared_ptr<FakeApplicationHandle> mApp; |
| 10978 | sp<FakeWindowHandle> mWindow; |
| 10979 | sp<FakeWindowHandle> mSecondWindow; |
| 10980 | |
| 10981 | void SetUp() override { |
| 10982 | InputDispatcherTest::SetUp(); |
| 10983 | mApp = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10984 | mWindow = sp<FakeWindowHandle>::make(mApp, mDispatcher, "TestWindow", |
| 10985 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 9998771 | 2020-11-10 18:43:05 -0800 | [diff] [blame] | 10986 | mWindow->setFocusable(true); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10987 | mSecondWindow = sp<FakeWindowHandle>::make(mApp, mDispatcher, "TestWindow2", |
| 10988 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 9998771 | 2020-11-10 18:43:05 -0800 | [diff] [blame] | 10989 | mSecondWindow->setFocusable(true); |
| 10990 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 10991 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, mApp); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 10992 | mDispatcher->onWindowInfosChanged( |
| 10993 | {{*mWindow->getInfo(), *mSecondWindow->getInfo()}, {}, 0, 0}); |
Prabir Pradhan | 9998771 | 2020-11-10 18:43:05 -0800 | [diff] [blame] | 10994 | |
| 10995 | setFocusedWindow(mWindow); |
| 10996 | mWindow->consumeFocusEvent(true); |
| 10997 | } |
| 10998 | |
Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 10999 | void notifyPointerCaptureChanged(const PointerCaptureRequest& request) { |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 11000 | mDispatcher->notifyPointerCaptureChanged(generatePointerCaptureChangedArgs(request)); |
Prabir Pradhan | 9998771 | 2020-11-10 18:43:05 -0800 | [diff] [blame] | 11001 | } |
| 11002 | |
Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 11003 | PointerCaptureRequest requestAndVerifyPointerCapture(const sp<FakeWindowHandle>& window, |
| 11004 | bool enabled) { |
Prabir Pradhan | 9998771 | 2020-11-10 18:43:05 -0800 | [diff] [blame] | 11005 | mDispatcher->requestPointerCapture(window->getToken(), enabled); |
Hiroki Sato | 2504023 | 2024-02-22 17:21:22 +0900 | [diff] [blame] | 11006 | auto request = mFakePolicy->assertSetPointerCaptureCalled(window, enabled); |
Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 11007 | notifyPointerCaptureChanged(request); |
Prabir Pradhan | 9998771 | 2020-11-10 18:43:05 -0800 | [diff] [blame] | 11008 | window->consumeCaptureEvent(enabled); |
Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 11009 | return request; |
Prabir Pradhan | 9998771 | 2020-11-10 18:43:05 -0800 | [diff] [blame] | 11010 | } |
| 11011 | }; |
| 11012 | |
| 11013 | TEST_F(InputDispatcherPointerCaptureTests, EnablePointerCaptureWhenFocused) { |
| 11014 | // Ensure that capture cannot be obtained for unfocused windows. |
| 11015 | mDispatcher->requestPointerCapture(mSecondWindow->getToken(), true); |
| 11016 | mFakePolicy->assertSetPointerCaptureNotCalled(); |
| 11017 | mSecondWindow->assertNoEvents(); |
| 11018 | |
| 11019 | // Ensure that capture can be enabled from the focus window. |
| 11020 | requestAndVerifyPointerCapture(mWindow, true); |
| 11021 | |
| 11022 | // Ensure that capture cannot be disabled from a window that does not have capture. |
| 11023 | mDispatcher->requestPointerCapture(mSecondWindow->getToken(), false); |
| 11024 | mFakePolicy->assertSetPointerCaptureNotCalled(); |
| 11025 | |
| 11026 | // Ensure that capture can be disabled from the window with capture. |
| 11027 | requestAndVerifyPointerCapture(mWindow, false); |
| 11028 | } |
| 11029 | |
| 11030 | TEST_F(InputDispatcherPointerCaptureTests, DisablesPointerCaptureAfterWindowLosesFocus) { |
Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 11031 | auto request = requestAndVerifyPointerCapture(mWindow, true); |
Prabir Pradhan | 9998771 | 2020-11-10 18:43:05 -0800 | [diff] [blame] | 11032 | |
| 11033 | setFocusedWindow(mSecondWindow); |
| 11034 | |
| 11035 | // Ensure that the capture disabled event was sent first. |
| 11036 | mWindow->consumeCaptureEvent(false); |
| 11037 | mWindow->consumeFocusEvent(false); |
| 11038 | mSecondWindow->consumeFocusEvent(true); |
Hiroki Sato | 2504023 | 2024-02-22 17:21:22 +0900 | [diff] [blame] | 11039 | mFakePolicy->assertSetPointerCaptureCalled(mWindow, false); |
Prabir Pradhan | 9998771 | 2020-11-10 18:43:05 -0800 | [diff] [blame] | 11040 | |
| 11041 | // Ensure that additional state changes from InputReader are not sent to the window. |
Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 11042 | notifyPointerCaptureChanged({}); |
| 11043 | notifyPointerCaptureChanged(request); |
| 11044 | notifyPointerCaptureChanged({}); |
Prabir Pradhan | 9998771 | 2020-11-10 18:43:05 -0800 | [diff] [blame] | 11045 | mWindow->assertNoEvents(); |
| 11046 | mSecondWindow->assertNoEvents(); |
| 11047 | mFakePolicy->assertSetPointerCaptureNotCalled(); |
| 11048 | } |
| 11049 | |
| 11050 | TEST_F(InputDispatcherPointerCaptureTests, UnexpectedStateChangeDisablesPointerCapture) { |
Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 11051 | auto request = requestAndVerifyPointerCapture(mWindow, true); |
Prabir Pradhan | 9998771 | 2020-11-10 18:43:05 -0800 | [diff] [blame] | 11052 | |
| 11053 | // InputReader unexpectedly disables and enables pointer capture. |
Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 11054 | notifyPointerCaptureChanged({}); |
| 11055 | notifyPointerCaptureChanged(request); |
Prabir Pradhan | 9998771 | 2020-11-10 18:43:05 -0800 | [diff] [blame] | 11056 | |
| 11057 | // Ensure that Pointer Capture is disabled. |
Hiroki Sato | 2504023 | 2024-02-22 17:21:22 +0900 | [diff] [blame] | 11058 | mFakePolicy->assertSetPointerCaptureCalled(mWindow, false); |
Prabir Pradhan | 9998771 | 2020-11-10 18:43:05 -0800 | [diff] [blame] | 11059 | mWindow->consumeCaptureEvent(false); |
| 11060 | mWindow->assertNoEvents(); |
| 11061 | } |
| 11062 | |
Prabir Pradhan | 167e6d9 | 2021-02-04 16:18:17 -0800 | [diff] [blame] | 11063 | TEST_F(InputDispatcherPointerCaptureTests, OutOfOrderRequests) { |
| 11064 | requestAndVerifyPointerCapture(mWindow, true); |
| 11065 | |
| 11066 | // The first window loses focus. |
| 11067 | setFocusedWindow(mSecondWindow); |
Hiroki Sato | 2504023 | 2024-02-22 17:21:22 +0900 | [diff] [blame] | 11068 | mFakePolicy->assertSetPointerCaptureCalled(mWindow, false); |
Prabir Pradhan | 167e6d9 | 2021-02-04 16:18:17 -0800 | [diff] [blame] | 11069 | mWindow->consumeCaptureEvent(false); |
| 11070 | |
| 11071 | // Request Pointer Capture from the second window before the notification from InputReader |
| 11072 | // arrives. |
| 11073 | mDispatcher->requestPointerCapture(mSecondWindow->getToken(), true); |
Hiroki Sato | 2504023 | 2024-02-22 17:21:22 +0900 | [diff] [blame] | 11074 | auto request = mFakePolicy->assertSetPointerCaptureCalled(mSecondWindow, true); |
Prabir Pradhan | 167e6d9 | 2021-02-04 16:18:17 -0800 | [diff] [blame] | 11075 | |
| 11076 | // InputReader notifies Pointer Capture was disabled (because of the focus change). |
Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 11077 | notifyPointerCaptureChanged({}); |
Prabir Pradhan | 167e6d9 | 2021-02-04 16:18:17 -0800 | [diff] [blame] | 11078 | |
| 11079 | // InputReader notifies Pointer Capture was enabled (because of mSecondWindow's request). |
Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 11080 | notifyPointerCaptureChanged(request); |
Prabir Pradhan | 167e6d9 | 2021-02-04 16:18:17 -0800 | [diff] [blame] | 11081 | |
| 11082 | mSecondWindow->consumeFocusEvent(true); |
| 11083 | mSecondWindow->consumeCaptureEvent(true); |
| 11084 | } |
| 11085 | |
Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 11086 | TEST_F(InputDispatcherPointerCaptureTests, EnableRequestFollowsSequenceNumbers) { |
| 11087 | // App repeatedly enables and disables capture. |
| 11088 | mDispatcher->requestPointerCapture(mWindow->getToken(), true); |
Hiroki Sato | 2504023 | 2024-02-22 17:21:22 +0900 | [diff] [blame] | 11089 | auto firstRequest = mFakePolicy->assertSetPointerCaptureCalled(mWindow, true); |
Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 11090 | mDispatcher->requestPointerCapture(mWindow->getToken(), false); |
Hiroki Sato | 2504023 | 2024-02-22 17:21:22 +0900 | [diff] [blame] | 11091 | mFakePolicy->assertSetPointerCaptureCalled(mWindow, false); |
Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 11092 | mDispatcher->requestPointerCapture(mWindow->getToken(), true); |
Hiroki Sato | 2504023 | 2024-02-22 17:21:22 +0900 | [diff] [blame] | 11093 | auto secondRequest = mFakePolicy->assertSetPointerCaptureCalled(mWindow, true); |
Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 11094 | |
| 11095 | // InputReader notifies that PointerCapture has been enabled for the first request. Since the |
| 11096 | // first request is now stale, this should do nothing. |
| 11097 | notifyPointerCaptureChanged(firstRequest); |
| 11098 | mWindow->assertNoEvents(); |
| 11099 | |
| 11100 | // InputReader notifies that the second request was enabled. |
| 11101 | notifyPointerCaptureChanged(secondRequest); |
| 11102 | mWindow->consumeCaptureEvent(true); |
| 11103 | } |
| 11104 | |
Prabir Pradhan | 7092e26 | 2022-05-03 16:51:09 +0000 | [diff] [blame] | 11105 | TEST_F(InputDispatcherPointerCaptureTests, RapidToggleRequests) { |
| 11106 | requestAndVerifyPointerCapture(mWindow, true); |
| 11107 | |
| 11108 | // App toggles pointer capture off and on. |
| 11109 | mDispatcher->requestPointerCapture(mWindow->getToken(), false); |
Hiroki Sato | 2504023 | 2024-02-22 17:21:22 +0900 | [diff] [blame] | 11110 | mFakePolicy->assertSetPointerCaptureCalled(mWindow, false); |
Prabir Pradhan | 7092e26 | 2022-05-03 16:51:09 +0000 | [diff] [blame] | 11111 | |
| 11112 | mDispatcher->requestPointerCapture(mWindow->getToken(), true); |
Hiroki Sato | 2504023 | 2024-02-22 17:21:22 +0900 | [diff] [blame] | 11113 | auto enableRequest = mFakePolicy->assertSetPointerCaptureCalled(mWindow, true); |
Prabir Pradhan | 7092e26 | 2022-05-03 16:51:09 +0000 | [diff] [blame] | 11114 | |
| 11115 | // InputReader notifies that the latest "enable" request was processed, while skipping over the |
| 11116 | // preceding "disable" request. |
| 11117 | notifyPointerCaptureChanged(enableRequest); |
| 11118 | |
| 11119 | // Since pointer capture was never disabled during the rapid toggle, the window does not receive |
| 11120 | // any notifications. |
| 11121 | mWindow->assertNoEvents(); |
| 11122 | } |
| 11123 | |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 11124 | /** |
| 11125 | * One window. Hover mouse in the window, and then start capture. Make sure that the relative |
| 11126 | * mouse movements don't affect the previous mouse hovering state. |
| 11127 | * When pointer capture is enabled, the incoming events are always ACTION_MOVE (there are no |
| 11128 | * HOVER_MOVE events). |
| 11129 | */ |
| 11130 | TEST_F(InputDispatcherPointerCaptureTests, MouseHoverAndPointerCapture) { |
| 11131 | // Mouse hover on the window |
| 11132 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE) |
| 11133 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(110)) |
| 11134 | .build()); |
| 11135 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) |
| 11136 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(110)) |
| 11137 | .build()); |
| 11138 | |
| 11139 | mWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_HOVER_ENTER))); |
| 11140 | mWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_HOVER_MOVE))); |
| 11141 | |
| 11142 | // Start pointer capture |
| 11143 | requestAndVerifyPointerCapture(mWindow, true); |
| 11144 | |
| 11145 | // Send some relative mouse movements and receive them in the window. |
| 11146 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_MOUSE_RELATIVE) |
| 11147 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(10).y(11)) |
| 11148 | .build()); |
| 11149 | mWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithCoords(10, 11), |
| 11150 | WithSource(AINPUT_SOURCE_MOUSE_RELATIVE))); |
| 11151 | |
| 11152 | // Stop pointer capture |
| 11153 | requestAndVerifyPointerCapture(mWindow, false); |
| 11154 | |
| 11155 | // Continue hovering on the window |
| 11156 | mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) |
| 11157 | .pointer(PointerBuilder(0, ToolType::MOUSE).x(105).y(115)) |
| 11158 | .build()); |
| 11159 | mWindow->consumeMotionEvent( |
| 11160 | AllOf(WithMotionAction(ACTION_HOVER_MOVE), WithSource(AINPUT_SOURCE_MOUSE))); |
| 11161 | |
| 11162 | mWindow->assertNoEvents(); |
| 11163 | } |
| 11164 | |
Prabir Pradhan | 9d3d561 | 2024-06-06 20:34:26 +0000 | [diff] [blame] | 11165 | TEST_F(InputDispatcherPointerCaptureTests, MultiDisplayPointerCapture) { |
| 11166 | // The default display is the focused display to begin with. |
| 11167 | requestAndVerifyPointerCapture(mWindow, true); |
| 11168 | |
| 11169 | // Move the second window to a second display, make it the focused window on that display. |
| 11170 | mSecondWindow->editInfo()->displayId = SECOND_DISPLAY_ID; |
| 11171 | mDispatcher->onWindowInfosChanged({{*mWindow->getInfo(), *mSecondWindow->getInfo()}, {}, 0, 0}); |
| 11172 | setFocusedWindow(mSecondWindow); |
| 11173 | mSecondWindow->consumeFocusEvent(true); |
| 11174 | |
| 11175 | mWindow->assertNoEvents(); |
| 11176 | |
| 11177 | // The second window cannot gain capture because it is not on the focused display. |
| 11178 | mDispatcher->requestPointerCapture(mSecondWindow->getToken(), true); |
| 11179 | mFakePolicy->assertSetPointerCaptureNotCalled(); |
| 11180 | mSecondWindow->assertNoEvents(); |
| 11181 | |
| 11182 | // Make the second display the focused display. |
| 11183 | mDispatcher->setFocusedDisplay(SECOND_DISPLAY_ID); |
Arpit Singh | b65e2bd | 2024-06-03 09:48:16 +0000 | [diff] [blame] | 11184 | mFakePolicy->assertFocusedDisplayNotified(SECOND_DISPLAY_ID); |
Prabir Pradhan | 9d3d561 | 2024-06-06 20:34:26 +0000 | [diff] [blame] | 11185 | |
| 11186 | // This causes the first window to lose pointer capture, and it's unable to request capture. |
| 11187 | mWindow->consumeCaptureEvent(false); |
| 11188 | mFakePolicy->assertSetPointerCaptureCalled(mWindow, false); |
| 11189 | |
| 11190 | mDispatcher->requestPointerCapture(mWindow->getToken(), true); |
| 11191 | mFakePolicy->assertSetPointerCaptureNotCalled(); |
| 11192 | |
| 11193 | // The second window is now able to gain pointer capture successfully. |
| 11194 | requestAndVerifyPointerCapture(mSecondWindow, true); |
| 11195 | } |
| 11196 | |
Hiroki Sato | 2504023 | 2024-02-22 17:21:22 +0900 | [diff] [blame] | 11197 | using InputDispatcherPointerCaptureDeathTest = InputDispatcherPointerCaptureTests; |
| 11198 | |
| 11199 | TEST_F(InputDispatcherPointerCaptureDeathTest, |
| 11200 | NotifyPointerCaptureChangedWithWrongTokenAbortsDispatcher) { |
| 11201 | testing::GTEST_FLAG(death_test_style) = "threadsafe"; |
| 11202 | ScopedSilentDeath _silentDeath; |
| 11203 | |
| 11204 | mDispatcher->requestPointerCapture(mWindow->getToken(), true); |
| 11205 | auto request = mFakePolicy->assertSetPointerCaptureCalled(mWindow, true); |
| 11206 | |
| 11207 | // Dispatch a pointer changed event with a wrong token. |
| 11208 | request.window = mSecondWindow->getToken(); |
| 11209 | ASSERT_DEATH( |
| 11210 | { |
| 11211 | notifyPointerCaptureChanged(request); |
| 11212 | mSecondWindow->consumeCaptureEvent(true); |
| 11213 | }, |
| 11214 | "Unexpected requested window for Pointer Capture."); |
| 11215 | } |
| 11216 | |
Bernardo Rufino | c3b7b8c | 2021-01-29 17:38:07 +0000 | [diff] [blame] | 11217 | class InputDispatcherUntrustedTouchesTest : public InputDispatcherTest { |
| 11218 | protected: |
| 11219 | constexpr static const float MAXIMUM_OBSCURING_OPACITY = 0.8; |
Bernardo Rufino | 7393d17 | 2021-02-26 13:56:11 +0000 | [diff] [blame] | 11220 | |
| 11221 | constexpr static const float OPACITY_ABOVE_THRESHOLD = 0.9; |
| 11222 | static_assert(OPACITY_ABOVE_THRESHOLD > MAXIMUM_OBSCURING_OPACITY); |
| 11223 | |
| 11224 | constexpr static const float OPACITY_BELOW_THRESHOLD = 0.7; |
| 11225 | static_assert(OPACITY_BELOW_THRESHOLD < MAXIMUM_OBSCURING_OPACITY); |
| 11226 | |
| 11227 | // When combined twice, ie 1 - (1 - 0.5)*(1 - 0.5) = 0.75 < 8, is still below the threshold |
| 11228 | constexpr static const float OPACITY_FAR_BELOW_THRESHOLD = 0.5; |
| 11229 | static_assert(OPACITY_FAR_BELOW_THRESHOLD < MAXIMUM_OBSCURING_OPACITY); |
| 11230 | static_assert(1 - (1 - OPACITY_FAR_BELOW_THRESHOLD) * (1 - OPACITY_FAR_BELOW_THRESHOLD) < |
| 11231 | MAXIMUM_OBSCURING_OPACITY); |
| 11232 | |
Prabir Pradhan | 8a5c41d | 2023-06-08 19:13:46 +0000 | [diff] [blame] | 11233 | static constexpr gui::Uid TOUCHED_APP_UID{10001}; |
| 11234 | static constexpr gui::Uid APP_B_UID{10002}; |
| 11235 | static constexpr gui::Uid APP_C_UID{10003}; |
Bernardo Rufino | c3b7b8c | 2021-01-29 17:38:07 +0000 | [diff] [blame] | 11236 | |
| 11237 | sp<FakeWindowHandle> mTouchWindow; |
| 11238 | |
| 11239 | virtual void SetUp() override { |
| 11240 | InputDispatcherTest::SetUp(); |
Bernardo Rufino | 6d52e54 | 2021-02-15 18:38:10 +0000 | [diff] [blame] | 11241 | mTouchWindow = getWindow(TOUCHED_APP_UID, "Touched"); |
Bernardo Rufino | c3b7b8c | 2021-01-29 17:38:07 +0000 | [diff] [blame] | 11242 | mDispatcher->setMaximumObscuringOpacityForTouch(MAXIMUM_OBSCURING_OPACITY); |
| 11243 | } |
| 11244 | |
| 11245 | virtual void TearDown() override { |
| 11246 | InputDispatcherTest::TearDown(); |
| 11247 | mTouchWindow.clear(); |
| 11248 | } |
| 11249 | |
Prabir Pradhan | 8a5c41d | 2023-06-08 19:13:46 +0000 | [diff] [blame] | 11250 | sp<FakeWindowHandle> getOccludingWindow(gui::Uid uid, std::string name, TouchOcclusionMode mode, |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 11251 | float alpha = 1.0f) { |
Bernardo Rufino | c3b7b8c | 2021-01-29 17:38:07 +0000 | [diff] [blame] | 11252 | sp<FakeWindowHandle> window = getWindow(uid, name); |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 11253 | window->setTouchable(false); |
Bernardo Rufino | c3b7b8c | 2021-01-29 17:38:07 +0000 | [diff] [blame] | 11254 | window->setTouchOcclusionMode(mode); |
Bernardo Rufino | 1d0d1f2 | 2021-02-12 15:08:43 +0000 | [diff] [blame] | 11255 | window->setAlpha(alpha); |
Bernardo Rufino | c3b7b8c | 2021-01-29 17:38:07 +0000 | [diff] [blame] | 11256 | return window; |
| 11257 | } |
| 11258 | |
Prabir Pradhan | 8a5c41d | 2023-06-08 19:13:46 +0000 | [diff] [blame] | 11259 | sp<FakeWindowHandle> getWindow(gui::Uid uid, std::string name) { |
Bernardo Rufino | c3b7b8c | 2021-01-29 17:38:07 +0000 | [diff] [blame] | 11260 | std::shared_ptr<FakeApplicationHandle> app = std::make_shared<FakeApplicationHandle>(); |
| 11261 | sp<FakeWindowHandle> window = |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11262 | sp<FakeWindowHandle>::make(app, mDispatcher, name, ui::LogicalDisplayId::DEFAULT); |
Bernardo Rufino | c3b7b8c | 2021-01-29 17:38:07 +0000 | [diff] [blame] | 11263 | // Generate an arbitrary PID based on the UID |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 11264 | window->setOwnerInfo(gui::Pid{static_cast<pid_t>(1777 + (uid.val() % 10000))}, uid); |
Bernardo Rufino | c3b7b8c | 2021-01-29 17:38:07 +0000 | [diff] [blame] | 11265 | return window; |
| 11266 | } |
| 11267 | |
| 11268 | void touch(const std::vector<PointF>& points = {PointF{100, 200}}) { |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 11269 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11270 | AINPUT_SOURCE_TOUCHSCREEN, |
| 11271 | ui::LogicalDisplayId::DEFAULT, points)); |
Bernardo Rufino | c3b7b8c | 2021-01-29 17:38:07 +0000 | [diff] [blame] | 11272 | } |
| 11273 | }; |
| 11274 | |
| 11275 | TEST_F(InputDispatcherUntrustedTouchesTest, WindowWithBlockUntrustedOcclusionMode_BlocksTouch) { |
Bernardo Rufino | 1d0d1f2 | 2021-02-12 15:08:43 +0000 | [diff] [blame] | 11276 | const sp<FakeWindowHandle>& w = |
Bernardo Rufino | c3b7b8c | 2021-01-29 17:38:07 +0000 | [diff] [blame] | 11277 | getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::BLOCK_UNTRUSTED); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 11278 | mDispatcher->onWindowInfosChanged({{*w->getInfo(), *mTouchWindow->getInfo()}, {}, 0, 0}); |
Bernardo Rufino | c3b7b8c | 2021-01-29 17:38:07 +0000 | [diff] [blame] | 11279 | |
| 11280 | touch(); |
| 11281 | |
| 11282 | mTouchWindow->assertNoEvents(); |
| 11283 | } |
| 11284 | |
Bernardo Rufino | a43a5a4 | 2021-02-17 12:21:14 +0000 | [diff] [blame] | 11285 | TEST_F(InputDispatcherUntrustedTouchesTest, |
Bernardo Rufino | 7393d17 | 2021-02-26 13:56:11 +0000 | [diff] [blame] | 11286 | WindowWithBlockUntrustedOcclusionModeWithOpacityBelowThreshold_BlocksTouch) { |
| 11287 | const sp<FakeWindowHandle>& w = |
| 11288 | getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::BLOCK_UNTRUSTED, 0.7f); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 11289 | mDispatcher->onWindowInfosChanged({{*w->getInfo(), *mTouchWindow->getInfo()}, {}, 0, 0}); |
Bernardo Rufino | 7393d17 | 2021-02-26 13:56:11 +0000 | [diff] [blame] | 11290 | |
| 11291 | touch(); |
| 11292 | |
| 11293 | mTouchWindow->assertNoEvents(); |
| 11294 | } |
| 11295 | |
| 11296 | TEST_F(InputDispatcherUntrustedTouchesTest, |
Bernardo Rufino | a43a5a4 | 2021-02-17 12:21:14 +0000 | [diff] [blame] | 11297 | WindowWithBlockUntrustedOcclusionMode_DoesNotReceiveTouch) { |
| 11298 | const sp<FakeWindowHandle>& w = |
| 11299 | getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::BLOCK_UNTRUSTED); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 11300 | mDispatcher->onWindowInfosChanged({{*w->getInfo(), *mTouchWindow->getInfo()}, {}, 0, 0}); |
Bernardo Rufino | a43a5a4 | 2021-02-17 12:21:14 +0000 | [diff] [blame] | 11301 | |
| 11302 | touch(); |
| 11303 | |
| 11304 | w->assertNoEvents(); |
| 11305 | } |
| 11306 | |
Bernardo Rufino | c3b7b8c | 2021-01-29 17:38:07 +0000 | [diff] [blame] | 11307 | TEST_F(InputDispatcherUntrustedTouchesTest, WindowWithAllowOcclusionMode_AllowsTouch) { |
Bernardo Rufino | 1d0d1f2 | 2021-02-12 15:08:43 +0000 | [diff] [blame] | 11308 | const sp<FakeWindowHandle>& w = getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::ALLOW); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 11309 | mDispatcher->onWindowInfosChanged({{*w->getInfo(), *mTouchWindow->getInfo()}, {}, 0, 0}); |
Bernardo Rufino | c3b7b8c | 2021-01-29 17:38:07 +0000 | [diff] [blame] | 11310 | |
| 11311 | touch(); |
| 11312 | |
| 11313 | mTouchWindow->consumeAnyMotionDown(); |
| 11314 | } |
| 11315 | |
| 11316 | TEST_F(InputDispatcherUntrustedTouchesTest, TouchOutsideOccludingWindow_AllowsTouch) { |
Bernardo Rufino | 1d0d1f2 | 2021-02-12 15:08:43 +0000 | [diff] [blame] | 11317 | const sp<FakeWindowHandle>& w = |
Bernardo Rufino | c3b7b8c | 2021-01-29 17:38:07 +0000 | [diff] [blame] | 11318 | getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::BLOCK_UNTRUSTED); |
Bernardo Rufino | 1d0d1f2 | 2021-02-12 15:08:43 +0000 | [diff] [blame] | 11319 | w->setFrame(Rect(0, 0, 50, 50)); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 11320 | mDispatcher->onWindowInfosChanged({{*w->getInfo(), *mTouchWindow->getInfo()}, {}, 0, 0}); |
Bernardo Rufino | c3b7b8c | 2021-01-29 17:38:07 +0000 | [diff] [blame] | 11321 | |
| 11322 | touch({PointF{100, 100}}); |
| 11323 | |
| 11324 | mTouchWindow->consumeAnyMotionDown(); |
| 11325 | } |
| 11326 | |
| 11327 | TEST_F(InputDispatcherUntrustedTouchesTest, WindowFromSameUid_AllowsTouch) { |
Bernardo Rufino | 1d0d1f2 | 2021-02-12 15:08:43 +0000 | [diff] [blame] | 11328 | const sp<FakeWindowHandle>& w = |
Bernardo Rufino | 6d52e54 | 2021-02-15 18:38:10 +0000 | [diff] [blame] | 11329 | getOccludingWindow(TOUCHED_APP_UID, "A", TouchOcclusionMode::BLOCK_UNTRUSTED); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 11330 | mDispatcher->onWindowInfosChanged({{*w->getInfo(), *mTouchWindow->getInfo()}, {}, 0, 0}); |
Bernardo Rufino | 1d0d1f2 | 2021-02-12 15:08:43 +0000 | [diff] [blame] | 11331 | |
| 11332 | touch(); |
| 11333 | |
| 11334 | mTouchWindow->consumeAnyMotionDown(); |
| 11335 | } |
| 11336 | |
| 11337 | TEST_F(InputDispatcherUntrustedTouchesTest, WindowWithZeroOpacity_AllowsTouch) { |
| 11338 | const sp<FakeWindowHandle>& w = |
| 11339 | getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::BLOCK_UNTRUSTED, 0.0f); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 11340 | mDispatcher->onWindowInfosChanged({{*w->getInfo(), *mTouchWindow->getInfo()}, {}, 0, 0}); |
Bernardo Rufino | c3b7b8c | 2021-01-29 17:38:07 +0000 | [diff] [blame] | 11341 | |
| 11342 | touch(); |
| 11343 | |
| 11344 | mTouchWindow->consumeAnyMotionDown(); |
| 11345 | } |
| 11346 | |
Bernardo Rufino | a43a5a4 | 2021-02-17 12:21:14 +0000 | [diff] [blame] | 11347 | TEST_F(InputDispatcherUntrustedTouchesTest, WindowWithZeroOpacity_DoesNotReceiveTouch) { |
| 11348 | const sp<FakeWindowHandle>& w = |
| 11349 | getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::BLOCK_UNTRUSTED, 0.0f); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 11350 | mDispatcher->onWindowInfosChanged({{*w->getInfo(), *mTouchWindow->getInfo()}, {}, 0, 0}); |
Bernardo Rufino | a43a5a4 | 2021-02-17 12:21:14 +0000 | [diff] [blame] | 11351 | |
| 11352 | touch(); |
| 11353 | |
| 11354 | w->assertNoEvents(); |
| 11355 | } |
| 11356 | |
| 11357 | /** |
| 11358 | * This is important to make sure apps can't indirectly learn the position of touches (outside vs |
| 11359 | * inside) while letting them pass-through. Note that even though touch passes through the occluding |
| 11360 | * window, the occluding window will still receive ACTION_OUTSIDE event. |
| 11361 | */ |
| 11362 | TEST_F(InputDispatcherUntrustedTouchesTest, |
| 11363 | WindowWithZeroOpacityAndWatchOutside_ReceivesOutsideEvent) { |
| 11364 | const sp<FakeWindowHandle>& w = |
| 11365 | getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::BLOCK_UNTRUSTED, 0.0f); |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 11366 | w->setWatchOutsideTouch(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 11367 | mDispatcher->onWindowInfosChanged({{*w->getInfo(), *mTouchWindow->getInfo()}, {}, 0, 0}); |
Bernardo Rufino | a43a5a4 | 2021-02-17 12:21:14 +0000 | [diff] [blame] | 11368 | |
| 11369 | touch(); |
| 11370 | |
| 11371 | w->consumeMotionOutside(); |
| 11372 | } |
| 11373 | |
| 11374 | TEST_F(InputDispatcherUntrustedTouchesTest, OutsideEvent_HasZeroCoordinates) { |
| 11375 | const sp<FakeWindowHandle>& w = |
| 11376 | getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::BLOCK_UNTRUSTED, 0.0f); |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 11377 | w->setWatchOutsideTouch(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 11378 | mDispatcher->onWindowInfosChanged({{*w->getInfo(), *mTouchWindow->getInfo()}, {}, 0, 0}); |
Bernardo Rufino | a43a5a4 | 2021-02-17 12:21:14 +0000 | [diff] [blame] | 11379 | |
| 11380 | touch(); |
| 11381 | |
Prabir Pradhan | dfabf8a | 2022-01-21 08:19:30 -0800 | [diff] [blame] | 11382 | w->consumeMotionOutsideWithZeroedCoords(); |
Bernardo Rufino | a43a5a4 | 2021-02-17 12:21:14 +0000 | [diff] [blame] | 11383 | } |
| 11384 | |
Bernardo Rufino | c3b7b8c | 2021-01-29 17:38:07 +0000 | [diff] [blame] | 11385 | TEST_F(InputDispatcherUntrustedTouchesTest, WindowWithOpacityBelowThreshold_AllowsTouch) { |
Bernardo Rufino | 1d0d1f2 | 2021-02-12 15:08:43 +0000 | [diff] [blame] | 11386 | const sp<FakeWindowHandle>& w = |
Bernardo Rufino | 7393d17 | 2021-02-26 13:56:11 +0000 | [diff] [blame] | 11387 | getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::USE_OPACITY, |
| 11388 | OPACITY_BELOW_THRESHOLD); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 11389 | mDispatcher->onWindowInfosChanged({{*w->getInfo(), *mTouchWindow->getInfo()}, {}, 0, 0}); |
Bernardo Rufino | 1d0d1f2 | 2021-02-12 15:08:43 +0000 | [diff] [blame] | 11390 | |
| 11391 | touch(); |
| 11392 | |
| 11393 | mTouchWindow->consumeAnyMotionDown(); |
| 11394 | } |
| 11395 | |
| 11396 | TEST_F(InputDispatcherUntrustedTouchesTest, WindowWithOpacityAtThreshold_AllowsTouch) { |
| 11397 | const sp<FakeWindowHandle>& w = |
| 11398 | getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::USE_OPACITY, |
| 11399 | MAXIMUM_OBSCURING_OPACITY); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 11400 | mDispatcher->onWindowInfosChanged({{*w->getInfo(), *mTouchWindow->getInfo()}, {}, 0, 0}); |
Bernardo Rufino | c3b7b8c | 2021-01-29 17:38:07 +0000 | [diff] [blame] | 11401 | |
| 11402 | touch(); |
| 11403 | |
| 11404 | mTouchWindow->consumeAnyMotionDown(); |
| 11405 | } |
| 11406 | |
| 11407 | TEST_F(InputDispatcherUntrustedTouchesTest, WindowWithOpacityAboveThreshold_BlocksTouch) { |
Bernardo Rufino | 1d0d1f2 | 2021-02-12 15:08:43 +0000 | [diff] [blame] | 11408 | const sp<FakeWindowHandle>& w = |
Bernardo Rufino | 7393d17 | 2021-02-26 13:56:11 +0000 | [diff] [blame] | 11409 | getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::USE_OPACITY, |
| 11410 | OPACITY_ABOVE_THRESHOLD); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 11411 | mDispatcher->onWindowInfosChanged({{*w->getInfo(), *mTouchWindow->getInfo()}, {}, 0, 0}); |
Bernardo Rufino | 1d0d1f2 | 2021-02-12 15:08:43 +0000 | [diff] [blame] | 11412 | |
| 11413 | touch(); |
| 11414 | |
| 11415 | mTouchWindow->assertNoEvents(); |
| 11416 | } |
| 11417 | |
| 11418 | TEST_F(InputDispatcherUntrustedTouchesTest, WindowsWithCombinedOpacityAboveThreshold_BlocksTouch) { |
| 11419 | // Resulting opacity = 1 - (1 - 0.7)*(1 - 0.7) = .91 |
| 11420 | const sp<FakeWindowHandle>& w1 = |
Bernardo Rufino | 7393d17 | 2021-02-26 13:56:11 +0000 | [diff] [blame] | 11421 | getOccludingWindow(APP_B_UID, "B1", TouchOcclusionMode::USE_OPACITY, |
| 11422 | OPACITY_BELOW_THRESHOLD); |
Bernardo Rufino | 1d0d1f2 | 2021-02-12 15:08:43 +0000 | [diff] [blame] | 11423 | const sp<FakeWindowHandle>& w2 = |
Bernardo Rufino | 7393d17 | 2021-02-26 13:56:11 +0000 | [diff] [blame] | 11424 | getOccludingWindow(APP_B_UID, "B2", TouchOcclusionMode::USE_OPACITY, |
| 11425 | OPACITY_BELOW_THRESHOLD); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 11426 | mDispatcher->onWindowInfosChanged( |
| 11427 | {{*w1->getInfo(), *w2->getInfo(), *mTouchWindow->getInfo()}, {}, 0, 0}); |
Bernardo Rufino | 1d0d1f2 | 2021-02-12 15:08:43 +0000 | [diff] [blame] | 11428 | |
| 11429 | touch(); |
| 11430 | |
| 11431 | mTouchWindow->assertNoEvents(); |
| 11432 | } |
| 11433 | |
| 11434 | TEST_F(InputDispatcherUntrustedTouchesTest, WindowsWithCombinedOpacityBelowThreshold_AllowsTouch) { |
| 11435 | // Resulting opacity = 1 - (1 - 0.5)*(1 - 0.5) = .75 |
| 11436 | const sp<FakeWindowHandle>& w1 = |
Bernardo Rufino | 7393d17 | 2021-02-26 13:56:11 +0000 | [diff] [blame] | 11437 | getOccludingWindow(APP_B_UID, "B1", TouchOcclusionMode::USE_OPACITY, |
| 11438 | OPACITY_FAR_BELOW_THRESHOLD); |
Bernardo Rufino | 1d0d1f2 | 2021-02-12 15:08:43 +0000 | [diff] [blame] | 11439 | const sp<FakeWindowHandle>& w2 = |
Bernardo Rufino | 7393d17 | 2021-02-26 13:56:11 +0000 | [diff] [blame] | 11440 | getOccludingWindow(APP_B_UID, "B2", TouchOcclusionMode::USE_OPACITY, |
| 11441 | OPACITY_FAR_BELOW_THRESHOLD); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 11442 | mDispatcher->onWindowInfosChanged( |
| 11443 | {{*w1->getInfo(), *w2->getInfo(), *mTouchWindow->getInfo()}, {}, 0, 0}); |
Bernardo Rufino | 1d0d1f2 | 2021-02-12 15:08:43 +0000 | [diff] [blame] | 11444 | |
| 11445 | touch(); |
| 11446 | |
| 11447 | mTouchWindow->consumeAnyMotionDown(); |
| 11448 | } |
| 11449 | |
| 11450 | TEST_F(InputDispatcherUntrustedTouchesTest, |
| 11451 | WindowsFromDifferentAppsEachBelowThreshold_AllowsTouch) { |
| 11452 | const sp<FakeWindowHandle>& wB = |
Bernardo Rufino | 7393d17 | 2021-02-26 13:56:11 +0000 | [diff] [blame] | 11453 | getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::USE_OPACITY, |
| 11454 | OPACITY_BELOW_THRESHOLD); |
Bernardo Rufino | 1d0d1f2 | 2021-02-12 15:08:43 +0000 | [diff] [blame] | 11455 | const sp<FakeWindowHandle>& wC = |
Bernardo Rufino | 7393d17 | 2021-02-26 13:56:11 +0000 | [diff] [blame] | 11456 | getOccludingWindow(APP_C_UID, "C", TouchOcclusionMode::USE_OPACITY, |
| 11457 | OPACITY_BELOW_THRESHOLD); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 11458 | mDispatcher->onWindowInfosChanged( |
| 11459 | {{*wB->getInfo(), *wC->getInfo(), *mTouchWindow->getInfo()}, {}, 0, 0}); |
Bernardo Rufino | 1d0d1f2 | 2021-02-12 15:08:43 +0000 | [diff] [blame] | 11460 | |
| 11461 | touch(); |
| 11462 | |
| 11463 | mTouchWindow->consumeAnyMotionDown(); |
| 11464 | } |
| 11465 | |
| 11466 | TEST_F(InputDispatcherUntrustedTouchesTest, WindowsFromDifferentAppsOneAboveThreshold_BlocksTouch) { |
| 11467 | const sp<FakeWindowHandle>& wB = |
Bernardo Rufino | 7393d17 | 2021-02-26 13:56:11 +0000 | [diff] [blame] | 11468 | getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::USE_OPACITY, |
| 11469 | OPACITY_BELOW_THRESHOLD); |
Bernardo Rufino | 1d0d1f2 | 2021-02-12 15:08:43 +0000 | [diff] [blame] | 11470 | const sp<FakeWindowHandle>& wC = |
Bernardo Rufino | 7393d17 | 2021-02-26 13:56:11 +0000 | [diff] [blame] | 11471 | getOccludingWindow(APP_C_UID, "C", TouchOcclusionMode::USE_OPACITY, |
| 11472 | OPACITY_ABOVE_THRESHOLD); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 11473 | mDispatcher->onWindowInfosChanged( |
| 11474 | {{*wB->getInfo(), *wC->getInfo(), *mTouchWindow->getInfo()}, {}, 0, 0}); |
Bernardo Rufino | c3b7b8c | 2021-01-29 17:38:07 +0000 | [diff] [blame] | 11475 | |
| 11476 | touch(); |
| 11477 | |
| 11478 | mTouchWindow->assertNoEvents(); |
| 11479 | } |
| 11480 | |
Bernardo Rufino | 6d52e54 | 2021-02-15 18:38:10 +0000 | [diff] [blame] | 11481 | TEST_F(InputDispatcherUntrustedTouchesTest, |
| 11482 | WindowWithOpacityAboveThresholdAndSelfWindow_BlocksTouch) { |
| 11483 | const sp<FakeWindowHandle>& wA = |
Bernardo Rufino | 7393d17 | 2021-02-26 13:56:11 +0000 | [diff] [blame] | 11484 | getOccludingWindow(TOUCHED_APP_UID, "T", TouchOcclusionMode::USE_OPACITY, |
| 11485 | OPACITY_BELOW_THRESHOLD); |
Bernardo Rufino | 6d52e54 | 2021-02-15 18:38:10 +0000 | [diff] [blame] | 11486 | const sp<FakeWindowHandle>& wB = |
Bernardo Rufino | 7393d17 | 2021-02-26 13:56:11 +0000 | [diff] [blame] | 11487 | getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::USE_OPACITY, |
| 11488 | OPACITY_ABOVE_THRESHOLD); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 11489 | mDispatcher->onWindowInfosChanged( |
| 11490 | {{*wA->getInfo(), *wB->getInfo(), *mTouchWindow->getInfo()}, {}, 0, 0}); |
Bernardo Rufino | 6d52e54 | 2021-02-15 18:38:10 +0000 | [diff] [blame] | 11491 | |
| 11492 | touch(); |
| 11493 | |
| 11494 | mTouchWindow->assertNoEvents(); |
| 11495 | } |
| 11496 | |
| 11497 | TEST_F(InputDispatcherUntrustedTouchesTest, |
| 11498 | WindowWithOpacityBelowThresholdAndSelfWindow_AllowsTouch) { |
| 11499 | const sp<FakeWindowHandle>& wA = |
Bernardo Rufino | 7393d17 | 2021-02-26 13:56:11 +0000 | [diff] [blame] | 11500 | getOccludingWindow(TOUCHED_APP_UID, "T", TouchOcclusionMode::USE_OPACITY, |
| 11501 | OPACITY_ABOVE_THRESHOLD); |
Bernardo Rufino | 6d52e54 | 2021-02-15 18:38:10 +0000 | [diff] [blame] | 11502 | const sp<FakeWindowHandle>& wB = |
Bernardo Rufino | 7393d17 | 2021-02-26 13:56:11 +0000 | [diff] [blame] | 11503 | getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::USE_OPACITY, |
| 11504 | OPACITY_BELOW_THRESHOLD); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 11505 | mDispatcher->onWindowInfosChanged( |
| 11506 | {{*wA->getInfo(), *wB->getInfo(), *mTouchWindow->getInfo()}, {}, 0, 0}); |
Bernardo Rufino | 6d52e54 | 2021-02-15 18:38:10 +0000 | [diff] [blame] | 11507 | |
| 11508 | touch(); |
| 11509 | |
| 11510 | mTouchWindow->consumeAnyMotionDown(); |
| 11511 | } |
| 11512 | |
| 11513 | TEST_F(InputDispatcherUntrustedTouchesTest, SelfWindowWithOpacityAboveThreshold_AllowsTouch) { |
| 11514 | const sp<FakeWindowHandle>& w = |
Bernardo Rufino | 7393d17 | 2021-02-26 13:56:11 +0000 | [diff] [blame] | 11515 | getOccludingWindow(TOUCHED_APP_UID, "T", TouchOcclusionMode::USE_OPACITY, |
| 11516 | OPACITY_ABOVE_THRESHOLD); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 11517 | mDispatcher->onWindowInfosChanged({{*w->getInfo(), *mTouchWindow->getInfo()}, {}, 0, 0}); |
Bernardo Rufino | 6d52e54 | 2021-02-15 18:38:10 +0000 | [diff] [blame] | 11518 | |
| 11519 | touch(); |
| 11520 | |
| 11521 | mTouchWindow->consumeAnyMotionDown(); |
| 11522 | } |
| 11523 | |
| 11524 | TEST_F(InputDispatcherUntrustedTouchesTest, SelfWindowWithBlockUntrustedMode_AllowsTouch) { |
| 11525 | const sp<FakeWindowHandle>& w = |
| 11526 | getOccludingWindow(TOUCHED_APP_UID, "T", TouchOcclusionMode::BLOCK_UNTRUSTED); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 11527 | mDispatcher->onWindowInfosChanged({{*w->getInfo(), *mTouchWindow->getInfo()}, {}, 0, 0}); |
Bernardo Rufino | 6d52e54 | 2021-02-15 18:38:10 +0000 | [diff] [blame] | 11528 | |
| 11529 | touch(); |
| 11530 | |
| 11531 | mTouchWindow->consumeAnyMotionDown(); |
| 11532 | } |
| 11533 | |
Bernardo Rufino | ccd3dd6 | 2021-02-15 18:47:42 +0000 | [diff] [blame] | 11534 | TEST_F(InputDispatcherUntrustedTouchesTest, |
| 11535 | OpacityThresholdIs0AndWindowAboveThreshold_BlocksTouch) { |
| 11536 | mDispatcher->setMaximumObscuringOpacityForTouch(0.0f); |
| 11537 | const sp<FakeWindowHandle>& w = |
| 11538 | getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::USE_OPACITY, 0.1f); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 11539 | mDispatcher->onWindowInfosChanged({{*w->getInfo(), *mTouchWindow->getInfo()}, {}, 0, 0}); |
Bernardo Rufino | ccd3dd6 | 2021-02-15 18:47:42 +0000 | [diff] [blame] | 11540 | |
| 11541 | touch(); |
| 11542 | |
| 11543 | mTouchWindow->assertNoEvents(); |
| 11544 | } |
| 11545 | |
| 11546 | TEST_F(InputDispatcherUntrustedTouchesTest, OpacityThresholdIs0AndWindowAtThreshold_AllowsTouch) { |
| 11547 | mDispatcher->setMaximumObscuringOpacityForTouch(0.0f); |
| 11548 | const sp<FakeWindowHandle>& w = |
| 11549 | getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::USE_OPACITY, 0.0f); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 11550 | mDispatcher->onWindowInfosChanged({{*w->getInfo(), *mTouchWindow->getInfo()}, {}, 0, 0}); |
Bernardo Rufino | ccd3dd6 | 2021-02-15 18:47:42 +0000 | [diff] [blame] | 11551 | |
| 11552 | touch(); |
| 11553 | |
| 11554 | mTouchWindow->consumeAnyMotionDown(); |
| 11555 | } |
| 11556 | |
| 11557 | TEST_F(InputDispatcherUntrustedTouchesTest, |
| 11558 | OpacityThresholdIs1AndWindowBelowThreshold_AllowsTouch) { |
| 11559 | mDispatcher->setMaximumObscuringOpacityForTouch(1.0f); |
| 11560 | const sp<FakeWindowHandle>& w = |
Bernardo Rufino | 7393d17 | 2021-02-26 13:56:11 +0000 | [diff] [blame] | 11561 | getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::USE_OPACITY, |
| 11562 | OPACITY_ABOVE_THRESHOLD); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 11563 | mDispatcher->onWindowInfosChanged({{*w->getInfo(), *mTouchWindow->getInfo()}, {}, 0, 0}); |
Bernardo Rufino | 7393d17 | 2021-02-26 13:56:11 +0000 | [diff] [blame] | 11564 | |
| 11565 | touch(); |
| 11566 | |
| 11567 | mTouchWindow->consumeAnyMotionDown(); |
| 11568 | } |
| 11569 | |
| 11570 | TEST_F(InputDispatcherUntrustedTouchesTest, |
| 11571 | WindowWithBlockUntrustedModeAndWindowWithOpacityBelowFromSameApp_BlocksTouch) { |
| 11572 | const sp<FakeWindowHandle>& w1 = |
| 11573 | getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::BLOCK_UNTRUSTED, |
| 11574 | OPACITY_BELOW_THRESHOLD); |
| 11575 | const sp<FakeWindowHandle>& w2 = |
| 11576 | getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::USE_OPACITY, |
| 11577 | OPACITY_BELOW_THRESHOLD); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 11578 | mDispatcher->onWindowInfosChanged( |
| 11579 | {{*w1->getInfo(), *w2->getInfo(), *mTouchWindow->getInfo()}, {}, 0, 0}); |
Bernardo Rufino | 7393d17 | 2021-02-26 13:56:11 +0000 | [diff] [blame] | 11580 | |
| 11581 | touch(); |
| 11582 | |
| 11583 | mTouchWindow->assertNoEvents(); |
| 11584 | } |
| 11585 | |
| 11586 | /** |
| 11587 | * Window B of BLOCK_UNTRUSTED occlusion mode is enough to block the touch, we're testing that the |
| 11588 | * addition of another window (C) of USE_OPACITY occlusion mode and opacity below the threshold |
| 11589 | * (which alone would result in allowing touches) does not affect the blocking behavior. |
| 11590 | */ |
| 11591 | TEST_F(InputDispatcherUntrustedTouchesTest, |
| 11592 | WindowWithBlockUntrustedModeAndWindowWithOpacityBelowFromDifferentApps_BlocksTouch) { |
| 11593 | const sp<FakeWindowHandle>& wB = |
| 11594 | getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::BLOCK_UNTRUSTED, |
| 11595 | OPACITY_BELOW_THRESHOLD); |
| 11596 | const sp<FakeWindowHandle>& wC = |
| 11597 | getOccludingWindow(APP_C_UID, "C", TouchOcclusionMode::USE_OPACITY, |
| 11598 | OPACITY_BELOW_THRESHOLD); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 11599 | mDispatcher->onWindowInfosChanged( |
| 11600 | {{*wB->getInfo(), *wC->getInfo(), *mTouchWindow->getInfo()}, {}, 0, 0}); |
Bernardo Rufino | 7393d17 | 2021-02-26 13:56:11 +0000 | [diff] [blame] | 11601 | |
| 11602 | touch(); |
| 11603 | |
| 11604 | mTouchWindow->assertNoEvents(); |
| 11605 | } |
| 11606 | |
| 11607 | /** |
| 11608 | * This test is testing that a window from a different UID but with same application token doesn't |
| 11609 | * block the touch. Apps can share the application token for close UI collaboration for example. |
| 11610 | */ |
| 11611 | TEST_F(InputDispatcherUntrustedTouchesTest, |
| 11612 | WindowWithSameApplicationTokenFromDifferentApp_AllowsTouch) { |
| 11613 | const sp<FakeWindowHandle>& w = |
| 11614 | getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::BLOCK_UNTRUSTED); |
| 11615 | w->setApplicationToken(mTouchWindow->getApplicationToken()); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 11616 | mDispatcher->onWindowInfosChanged({{*w->getInfo(), *mTouchWindow->getInfo()}, {}, 0, 0}); |
Bernardo Rufino | ccd3dd6 | 2021-02-15 18:47:42 +0000 | [diff] [blame] | 11617 | |
| 11618 | touch(); |
| 11619 | |
| 11620 | mTouchWindow->consumeAnyMotionDown(); |
| 11621 | } |
| 11622 | |
arthurhung | b89ccb0 | 2020-12-30 16:19:01 +0800 | [diff] [blame] | 11623 | class InputDispatcherDragTests : public InputDispatcherTest { |
| 11624 | protected: |
| 11625 | std::shared_ptr<FakeApplicationHandle> mApp; |
| 11626 | sp<FakeWindowHandle> mWindow; |
| 11627 | sp<FakeWindowHandle> mSecondWindow; |
| 11628 | sp<FakeWindowHandle> mDragWindow; |
Vaibhav Devmurari | 6abcf8f | 2022-06-06 10:08:05 +0000 | [diff] [blame] | 11629 | sp<FakeWindowHandle> mSpyWindow; |
Arthur Hung | b75c2aa | 2022-07-15 09:35:36 +0000 | [diff] [blame] | 11630 | // Mouse would force no-split, set the id as non-zero to verify if drag state could track it. |
| 11631 | static constexpr int32_t MOUSE_POINTER_ID = 1; |
arthurhung | b89ccb0 | 2020-12-30 16:19:01 +0800 | [diff] [blame] | 11632 | |
| 11633 | void SetUp() override { |
| 11634 | InputDispatcherTest::SetUp(); |
| 11635 | mApp = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11636 | mWindow = sp<FakeWindowHandle>::make(mApp, mDispatcher, "TestWindow", |
| 11637 | ui::LogicalDisplayId::DEFAULT); |
arthurhung | b89ccb0 | 2020-12-30 16:19:01 +0800 | [diff] [blame] | 11638 | mWindow->setFrame(Rect(0, 0, 100, 100)); |
arthurhung | b89ccb0 | 2020-12-30 16:19:01 +0800 | [diff] [blame] | 11639 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11640 | mSecondWindow = sp<FakeWindowHandle>::make(mApp, mDispatcher, "TestWindow2", |
| 11641 | ui::LogicalDisplayId::DEFAULT); |
arthurhung | b89ccb0 | 2020-12-30 16:19:01 +0800 | [diff] [blame] | 11642 | mSecondWindow->setFrame(Rect(100, 0, 200, 100)); |
arthurhung | b89ccb0 | 2020-12-30 16:19:01 +0800 | [diff] [blame] | 11643 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11644 | mSpyWindow = sp<FakeWindowHandle>::make(mApp, mDispatcher, "SpyWindow", |
| 11645 | ui::LogicalDisplayId::DEFAULT); |
Vaibhav Devmurari | 6abcf8f | 2022-06-06 10:08:05 +0000 | [diff] [blame] | 11646 | mSpyWindow->setSpy(true); |
| 11647 | mSpyWindow->setTrustedOverlay(true); |
| 11648 | mSpyWindow->setFrame(Rect(0, 0, 200, 100)); |
| 11649 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11650 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, mApp); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 11651 | mDispatcher->onWindowInfosChanged( |
| 11652 | {{*mSpyWindow->getInfo(), *mWindow->getInfo(), *mSecondWindow->getInfo()}, |
| 11653 | {}, |
| 11654 | 0, |
| 11655 | 0}); |
arthurhung | b89ccb0 | 2020-12-30 16:19:01 +0800 | [diff] [blame] | 11656 | } |
| 11657 | |
Arthur Hung | b75c2aa | 2022-07-15 09:35:36 +0000 | [diff] [blame] | 11658 | void injectDown(int fromSource = AINPUT_SOURCE_TOUCHSCREEN) { |
| 11659 | switch (fromSource) { |
| 11660 | case AINPUT_SOURCE_TOUCHSCREEN: |
| 11661 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 11662 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11663 | ui::LogicalDisplayId::DEFAULT, {50, 50})) |
Arthur Hung | b75c2aa | 2022-07-15 09:35:36 +0000 | [diff] [blame] | 11664 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 11665 | break; |
| 11666 | case AINPUT_SOURCE_STYLUS: |
| 11667 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 11668 | injectMotionEvent(*mDispatcher, |
| 11669 | MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, |
| 11670 | AINPUT_SOURCE_STYLUS) |
| 11671 | .buttonState( |
| 11672 | AMOTION_EVENT_BUTTON_STYLUS_PRIMARY) |
| 11673 | .pointer(PointerBuilder(0, ToolType::STYLUS) |
| 11674 | .x(50) |
| 11675 | .y(50)) |
| 11676 | .build())); |
Arthur Hung | b75c2aa | 2022-07-15 09:35:36 +0000 | [diff] [blame] | 11677 | break; |
| 11678 | case AINPUT_SOURCE_MOUSE: |
| 11679 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 11680 | injectMotionEvent(*mDispatcher, |
| 11681 | MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, |
| 11682 | AINPUT_SOURCE_MOUSE) |
| 11683 | .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) |
| 11684 | .pointer(PointerBuilder(MOUSE_POINTER_ID, |
| 11685 | ToolType::MOUSE) |
| 11686 | .x(50) |
| 11687 | .y(50)) |
| 11688 | .build())); |
Arthur Hung | b75c2aa | 2022-07-15 09:35:36 +0000 | [diff] [blame] | 11689 | break; |
| 11690 | default: |
| 11691 | FAIL() << "Source " << fromSource << " doesn't support drag and drop"; |
| 11692 | } |
arthurhung | b89ccb0 | 2020-12-30 16:19:01 +0800 | [diff] [blame] | 11693 | |
| 11694 | // Window should receive motion event. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11695 | mWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Vaibhav Devmurari | 6abcf8f | 2022-06-06 10:08:05 +0000 | [diff] [blame] | 11696 | // Spy window should also receive motion event |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11697 | mSpyWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | 5474565 | 2022-04-20 07:17:41 +0000 | [diff] [blame] | 11698 | } |
| 11699 | |
| 11700 | // Start performing drag, we will create a drag window and transfer touch to it. |
| 11701 | // @param sendDown : if true, send a motion down on first window before perform drag and drop. |
| 11702 | // Returns true on success. |
Arthur Hung | b75c2aa | 2022-07-15 09:35:36 +0000 | [diff] [blame] | 11703 | bool startDrag(bool sendDown = true, int fromSource = AINPUT_SOURCE_TOUCHSCREEN) { |
Arthur Hung | 5474565 | 2022-04-20 07:17:41 +0000 | [diff] [blame] | 11704 | if (sendDown) { |
Arthur Hung | b75c2aa | 2022-07-15 09:35:36 +0000 | [diff] [blame] | 11705 | injectDown(fromSource); |
Arthur Hung | 5474565 | 2022-04-20 07:17:41 +0000 | [diff] [blame] | 11706 | } |
arthurhung | b89ccb0 | 2020-12-30 16:19:01 +0800 | [diff] [blame] | 11707 | |
| 11708 | // The drag window covers the entire display |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11709 | mDragWindow = sp<FakeWindowHandle>::make(mApp, mDispatcher, "DragWindow", |
| 11710 | ui::LogicalDisplayId::DEFAULT); |
Vaibhav Devmurari | 6abcf8f | 2022-06-06 10:08:05 +0000 | [diff] [blame] | 11711 | mDragWindow->setTouchableRegion(Region{{0, 0, 0, 0}}); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 11712 | mDispatcher->onWindowInfosChanged({{*mDragWindow->getInfo(), *mSpyWindow->getInfo(), |
| 11713 | *mWindow->getInfo(), *mSecondWindow->getInfo()}, |
| 11714 | {}, |
| 11715 | 0, |
| 11716 | 0}); |
arthurhung | b89ccb0 | 2020-12-30 16:19:01 +0800 | [diff] [blame] | 11717 | |
| 11718 | // Transfer touch focus to the drag window |
Arthur Hung | 5474565 | 2022-04-20 07:17:41 +0000 | [diff] [blame] | 11719 | bool transferred = |
Prabir Pradhan | 367f343 | 2024-02-13 23:05:58 +0000 | [diff] [blame] | 11720 | mDispatcher->transferTouchGesture(mWindow->getToken(), mDragWindow->getToken(), |
| 11721 | /*isDragDrop=*/true); |
Arthur Hung | 5474565 | 2022-04-20 07:17:41 +0000 | [diff] [blame] | 11722 | if (transferred) { |
| 11723 | mWindow->consumeMotionCancel(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11724 | mDragWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, |
| 11725 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
Arthur Hung | 5474565 | 2022-04-20 07:17:41 +0000 | [diff] [blame] | 11726 | } |
| 11727 | return transferred; |
arthurhung | b89ccb0 | 2020-12-30 16:19:01 +0800 | [diff] [blame] | 11728 | } |
| 11729 | }; |
| 11730 | |
| 11731 | TEST_F(InputDispatcherDragTests, DragEnterAndDragExit) { |
Arthur Hung | b75c2aa | 2022-07-15 09:35:36 +0000 | [diff] [blame] | 11732 | startDrag(); |
arthurhung | b89ccb0 | 2020-12-30 16:19:01 +0800 | [diff] [blame] | 11733 | |
| 11734 | // Move on window. |
| 11735 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 11736 | injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11737 | ui::LogicalDisplayId::DEFAULT, {50, 50})) |
arthurhung | b89ccb0 | 2020-12-30 16:19:01 +0800 | [diff] [blame] | 11738 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11739 | mDragWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, |
| 11740 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
arthurhung | b89ccb0 | 2020-12-30 16:19:01 +0800 | [diff] [blame] | 11741 | mWindow->consumeDragEvent(false, 50, 50); |
| 11742 | mSecondWindow->assertNoEvents(); |
| 11743 | |
| 11744 | // Move to another window. |
| 11745 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 11746 | injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11747 | ui::LogicalDisplayId::DEFAULT, {150, 50})) |
arthurhung | b89ccb0 | 2020-12-30 16:19:01 +0800 | [diff] [blame] | 11748 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11749 | mDragWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, |
| 11750 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
arthurhung | b89ccb0 | 2020-12-30 16:19:01 +0800 | [diff] [blame] | 11751 | mWindow->consumeDragEvent(true, 150, 50); |
| 11752 | mSecondWindow->consumeDragEvent(false, 50, 50); |
| 11753 | |
| 11754 | // Move back to original window. |
| 11755 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 11756 | injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11757 | ui::LogicalDisplayId::DEFAULT, {50, 50})) |
arthurhung | b89ccb0 | 2020-12-30 16:19:01 +0800 | [diff] [blame] | 11758 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11759 | mDragWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, |
| 11760 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
arthurhung | b89ccb0 | 2020-12-30 16:19:01 +0800 | [diff] [blame] | 11761 | mWindow->consumeDragEvent(false, 50, 50); |
| 11762 | mSecondWindow->consumeDragEvent(true, -50, 50); |
| 11763 | |
| 11764 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11765 | injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 11766 | {50, 50})) |
arthurhung | b89ccb0 | 2020-12-30 16:19:01 +0800 | [diff] [blame] | 11767 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11768 | mDragWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
arthurhung | b89ccb0 | 2020-12-30 16:19:01 +0800 | [diff] [blame] | 11769 | mWindow->assertNoEvents(); |
| 11770 | mSecondWindow->assertNoEvents(); |
| 11771 | } |
| 11772 | |
Vaibhav Devmurari | 6abcf8f | 2022-06-06 10:08:05 +0000 | [diff] [blame] | 11773 | TEST_F(InputDispatcherDragTests, DragEnterAndPointerDownPilfersPointers) { |
Arthur Hung | b75c2aa | 2022-07-15 09:35:36 +0000 | [diff] [blame] | 11774 | startDrag(); |
Vaibhav Devmurari | 6abcf8f | 2022-06-06 10:08:05 +0000 | [diff] [blame] | 11775 | |
| 11776 | // No cancel event after drag start |
| 11777 | mSpyWindow->assertNoEvents(); |
| 11778 | |
| 11779 | const MotionEvent secondFingerDownEvent = |
| 11780 | MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 11781 | .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 11782 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(50).y(50)) |
| 11783 | .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(60).y(60)) |
Vaibhav Devmurari | 6abcf8f | 2022-06-06 10:08:05 +0000 | [diff] [blame] | 11784 | .build(); |
| 11785 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 11786 | injectMotionEvent(*mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, |
Vaibhav Devmurari | 6abcf8f | 2022-06-06 10:08:05 +0000 | [diff] [blame] | 11787 | InputEventInjectionSync::WAIT_FOR_RESULT)) |
| 11788 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 11789 | |
| 11790 | // Receives cancel for first pointer after next pointer down |
| 11791 | mSpyWindow->consumeMotionCancel(); |
| 11792 | mSpyWindow->consumeMotionDown(); |
| 11793 | |
| 11794 | mSpyWindow->assertNoEvents(); |
| 11795 | } |
| 11796 | |
arthurhung | f452d0b | 2021-01-06 00:19:52 +0800 | [diff] [blame] | 11797 | TEST_F(InputDispatcherDragTests, DragAndDrop) { |
Arthur Hung | b75c2aa | 2022-07-15 09:35:36 +0000 | [diff] [blame] | 11798 | startDrag(); |
arthurhung | f452d0b | 2021-01-06 00:19:52 +0800 | [diff] [blame] | 11799 | |
| 11800 | // Move on window. |
| 11801 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 11802 | injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11803 | ui::LogicalDisplayId::DEFAULT, {50, 50})) |
arthurhung | f452d0b | 2021-01-06 00:19:52 +0800 | [diff] [blame] | 11804 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11805 | mDragWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, |
| 11806 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
arthurhung | f452d0b | 2021-01-06 00:19:52 +0800 | [diff] [blame] | 11807 | mWindow->consumeDragEvent(false, 50, 50); |
| 11808 | mSecondWindow->assertNoEvents(); |
| 11809 | |
| 11810 | // Move to another window. |
| 11811 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 11812 | injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11813 | ui::LogicalDisplayId::DEFAULT, {150, 50})) |
arthurhung | f452d0b | 2021-01-06 00:19:52 +0800 | [diff] [blame] | 11814 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11815 | mDragWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, |
| 11816 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
arthurhung | f452d0b | 2021-01-06 00:19:52 +0800 | [diff] [blame] | 11817 | mWindow->consumeDragEvent(true, 150, 50); |
| 11818 | mSecondWindow->consumeDragEvent(false, 50, 50); |
| 11819 | |
| 11820 | // drop to another window. |
| 11821 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11822 | injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, |
arthurhung | f452d0b | 2021-01-06 00:19:52 +0800 | [diff] [blame] | 11823 | {150, 50})) |
| 11824 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11825 | mDragWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
Siarhei Vishniakou | a66d65e | 2023-06-16 10:32:51 -0700 | [diff] [blame] | 11826 | mFakePolicy->assertDropTargetEquals(*mDispatcher, mSecondWindow->getToken()); |
arthurhung | f452d0b | 2021-01-06 00:19:52 +0800 | [diff] [blame] | 11827 | mWindow->assertNoEvents(); |
| 11828 | mSecondWindow->assertNoEvents(); |
| 11829 | } |
| 11830 | |
Vaibhav Devmurari | 110ba32 | 2023-11-17 10:47:16 +0000 | [diff] [blame] | 11831 | TEST_F(InputDispatcherDragTests, DragAndDropNotCancelledIfSomeOtherPointerIsPilfered) { |
| 11832 | startDrag(); |
| 11833 | |
| 11834 | // No cancel event after drag start |
| 11835 | mSpyWindow->assertNoEvents(); |
| 11836 | |
| 11837 | const MotionEvent secondFingerDownEvent = |
| 11838 | MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 11839 | .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) |
| 11840 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(50).y(50)) |
| 11841 | .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(60).y(60)) |
| 11842 | .build(); |
| 11843 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
| 11844 | injectMotionEvent(*mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, |
| 11845 | InputEventInjectionSync::WAIT_FOR_RESULT)) |
| 11846 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 11847 | |
| 11848 | // Receives cancel for first pointer after next pointer down |
| 11849 | mSpyWindow->consumeMotionEvent(WithMotionAction(ACTION_CANCEL)); |
Siarhei Vishniakou | 1ff00cc | 2023-12-13 16:12:13 -0800 | [diff] [blame] | 11850 | mSpyWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithPointerIds({1}))); |
Vaibhav Devmurari | 110ba32 | 2023-11-17 10:47:16 +0000 | [diff] [blame] | 11851 | mDragWindow->consumeMotionEvent(WithMotionAction(ACTION_MOVE)); |
| 11852 | |
| 11853 | mSpyWindow->assertNoEvents(); |
| 11854 | |
| 11855 | // Spy window calls pilfer pointers |
| 11856 | EXPECT_EQ(OK, mDispatcher->pilferPointers(mSpyWindow->getToken())); |
| 11857 | mDragWindow->assertNoEvents(); |
| 11858 | |
| 11859 | const MotionEvent firstFingerMoveEvent = |
Siarhei Vishniakou | 96a1557 | 2023-12-18 10:47:52 -0800 | [diff] [blame] | 11860 | MotionEventBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
Vaibhav Devmurari | 110ba32 | 2023-11-17 10:47:16 +0000 | [diff] [blame] | 11861 | .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) |
| 11862 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(60).y(60)) |
| 11863 | .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(60).y(60)) |
| 11864 | .build(); |
| 11865 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | 96a1557 | 2023-12-18 10:47:52 -0800 | [diff] [blame] | 11866 | injectMotionEvent(*mDispatcher, firstFingerMoveEvent, INJECT_EVENT_TIMEOUT, |
Vaibhav Devmurari | 110ba32 | 2023-11-17 10:47:16 +0000 | [diff] [blame] | 11867 | InputEventInjectionSync::WAIT_FOR_RESULT)) |
| 11868 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 11869 | |
| 11870 | // Drag window should still receive the new event |
Prabir Pradhan | 65455c7 | 2024-02-13 21:46:41 +0000 | [diff] [blame] | 11871 | mDragWindow->consumeMotionEvent( |
| 11872 | AllOf(WithMotionAction(ACTION_MOVE), WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))); |
Vaibhav Devmurari | 110ba32 | 2023-11-17 10:47:16 +0000 | [diff] [blame] | 11873 | mDragWindow->assertNoEvents(); |
| 11874 | } |
| 11875 | |
arthurhung | 6d4bed9 | 2021-03-17 11:59:33 +0800 | [diff] [blame] | 11876 | TEST_F(InputDispatcherDragTests, StylusDragAndDrop) { |
Arthur Hung | b75c2aa | 2022-07-15 09:35:36 +0000 | [diff] [blame] | 11877 | startDrag(true, AINPUT_SOURCE_STYLUS); |
arthurhung | 6d4bed9 | 2021-03-17 11:59:33 +0800 | [diff] [blame] | 11878 | |
| 11879 | // Move on window and keep button pressed. |
| 11880 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 11881 | injectMotionEvent(*mDispatcher, |
arthurhung | 6d4bed9 | 2021-03-17 11:59:33 +0800 | [diff] [blame] | 11882 | MotionEventBuilder(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_STYLUS) |
| 11883 | .buttonState(AMOTION_EVENT_BUTTON_STYLUS_PRIMARY) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 11884 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50)) |
arthurhung | 6d4bed9 | 2021-03-17 11:59:33 +0800 | [diff] [blame] | 11885 | .build())) |
| 11886 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11887 | mDragWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, |
| 11888 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
arthurhung | 6d4bed9 | 2021-03-17 11:59:33 +0800 | [diff] [blame] | 11889 | mWindow->consumeDragEvent(false, 50, 50); |
| 11890 | mSecondWindow->assertNoEvents(); |
| 11891 | |
| 11892 | // Move to another window and release button, expect to drop item. |
| 11893 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 11894 | injectMotionEvent(*mDispatcher, |
arthurhung | 6d4bed9 | 2021-03-17 11:59:33 +0800 | [diff] [blame] | 11895 | MotionEventBuilder(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_STYLUS) |
| 11896 | .buttonState(0) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 11897 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(150).y(50)) |
arthurhung | 6d4bed9 | 2021-03-17 11:59:33 +0800 | [diff] [blame] | 11898 | .build())) |
| 11899 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11900 | mDragWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, |
| 11901 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
arthurhung | 6d4bed9 | 2021-03-17 11:59:33 +0800 | [diff] [blame] | 11902 | mWindow->assertNoEvents(); |
| 11903 | mSecondWindow->assertNoEvents(); |
Siarhei Vishniakou | a66d65e | 2023-06-16 10:32:51 -0700 | [diff] [blame] | 11904 | mFakePolicy->assertDropTargetEquals(*mDispatcher, mSecondWindow->getToken()); |
arthurhung | 6d4bed9 | 2021-03-17 11:59:33 +0800 | [diff] [blame] | 11905 | |
| 11906 | // nothing to the window. |
| 11907 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 11908 | injectMotionEvent(*mDispatcher, |
arthurhung | 6d4bed9 | 2021-03-17 11:59:33 +0800 | [diff] [blame] | 11909 | MotionEventBuilder(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_STYLUS) |
| 11910 | .buttonState(0) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 11911 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(150).y(50)) |
arthurhung | 6d4bed9 | 2021-03-17 11:59:33 +0800 | [diff] [blame] | 11912 | .build())) |
| 11913 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11914 | mDragWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
arthurhung | 6d4bed9 | 2021-03-17 11:59:33 +0800 | [diff] [blame] | 11915 | mWindow->assertNoEvents(); |
| 11916 | mSecondWindow->assertNoEvents(); |
| 11917 | } |
| 11918 | |
Arthur Hung | 5474565 | 2022-04-20 07:17:41 +0000 | [diff] [blame] | 11919 | TEST_F(InputDispatcherDragTests, DragAndDropOnInvalidWindow) { |
Arthur Hung | b75c2aa | 2022-07-15 09:35:36 +0000 | [diff] [blame] | 11920 | startDrag(); |
Arthur Hung | 6d0571e | 2021-04-09 20:18:16 +0800 | [diff] [blame] | 11921 | |
| 11922 | // Set second window invisible. |
| 11923 | mSecondWindow->setVisible(false); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 11924 | mDispatcher->onWindowInfosChanged( |
| 11925 | {{*mDragWindow->getInfo(), *mWindow->getInfo(), *mSecondWindow->getInfo()}, {}, 0, 0}); |
Arthur Hung | 6d0571e | 2021-04-09 20:18:16 +0800 | [diff] [blame] | 11926 | |
| 11927 | // Move on window. |
| 11928 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 11929 | injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11930 | ui::LogicalDisplayId::DEFAULT, {50, 50})) |
Arthur Hung | 6d0571e | 2021-04-09 20:18:16 +0800 | [diff] [blame] | 11931 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11932 | mDragWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, |
| 11933 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
Arthur Hung | 6d0571e | 2021-04-09 20:18:16 +0800 | [diff] [blame] | 11934 | mWindow->consumeDragEvent(false, 50, 50); |
| 11935 | mSecondWindow->assertNoEvents(); |
| 11936 | |
| 11937 | // Move to another window. |
| 11938 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 11939 | injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11940 | ui::LogicalDisplayId::DEFAULT, {150, 50})) |
Arthur Hung | 6d0571e | 2021-04-09 20:18:16 +0800 | [diff] [blame] | 11941 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11942 | mDragWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, |
| 11943 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
Arthur Hung | 6d0571e | 2021-04-09 20:18:16 +0800 | [diff] [blame] | 11944 | mWindow->consumeDragEvent(true, 150, 50); |
| 11945 | mSecondWindow->assertNoEvents(); |
| 11946 | |
| 11947 | // drop to another window. |
| 11948 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11949 | injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, |
Arthur Hung | 6d0571e | 2021-04-09 20:18:16 +0800 | [diff] [blame] | 11950 | {150, 50})) |
| 11951 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11952 | mDragWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
Siarhei Vishniakou | a66d65e | 2023-06-16 10:32:51 -0700 | [diff] [blame] | 11953 | mFakePolicy->assertDropTargetEquals(*mDispatcher, nullptr); |
Arthur Hung | 6d0571e | 2021-04-09 20:18:16 +0800 | [diff] [blame] | 11954 | mWindow->assertNoEvents(); |
| 11955 | mSecondWindow->assertNoEvents(); |
| 11956 | } |
| 11957 | |
Arthur Hung | 5474565 | 2022-04-20 07:17:41 +0000 | [diff] [blame] | 11958 | TEST_F(InputDispatcherDragTests, NoDragAndDropWhenMultiFingers) { |
Arthur Hung | b75c2aa | 2022-07-15 09:35:36 +0000 | [diff] [blame] | 11959 | // Ensure window could track pointerIds if it didn't support split touch. |
| 11960 | mWindow->setPreventSplitting(true); |
| 11961 | |
Arthur Hung | 5474565 | 2022-04-20 07:17:41 +0000 | [diff] [blame] | 11962 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11963 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 11964 | ui::LogicalDisplayId::DEFAULT, {50, 50})) |
Arthur Hung | 5474565 | 2022-04-20 07:17:41 +0000 | [diff] [blame] | 11965 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11966 | mWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | 5474565 | 2022-04-20 07:17:41 +0000 | [diff] [blame] | 11967 | |
| 11968 | const MotionEvent secondFingerDownEvent = |
| 11969 | MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11970 | .displayId(ui::LogicalDisplayId::DEFAULT) |
Arthur Hung | 5474565 | 2022-04-20 07:17:41 +0000 | [diff] [blame] | 11971 | .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 11972 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(50).y(50)) |
| 11973 | .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(75).y(50)) |
Arthur Hung | 5474565 | 2022-04-20 07:17:41 +0000 | [diff] [blame] | 11974 | .build(); |
| 11975 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 11976 | injectMotionEvent(*mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, |
Arthur Hung | 5474565 | 2022-04-20 07:17:41 +0000 | [diff] [blame] | 11977 | InputEventInjectionSync::WAIT_FOR_RESULT)) |
| 11978 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 11979 | mWindow->consumeMotionPointerDown(/*pointerIndex=*/1); |
Arthur Hung | 5474565 | 2022-04-20 07:17:41 +0000 | [diff] [blame] | 11980 | |
| 11981 | // Should not perform drag and drop when window has multi fingers. |
Arthur Hung | b75c2aa | 2022-07-15 09:35:36 +0000 | [diff] [blame] | 11982 | ASSERT_FALSE(startDrag(false)); |
Arthur Hung | 5474565 | 2022-04-20 07:17:41 +0000 | [diff] [blame] | 11983 | } |
| 11984 | |
| 11985 | TEST_F(InputDispatcherDragTests, DragAndDropWhenSplitTouch) { |
| 11986 | // First down on second window. |
| 11987 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11988 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 11989 | ui::LogicalDisplayId::DEFAULT, {150, 50})) |
Arthur Hung | 5474565 | 2022-04-20 07:17:41 +0000 | [diff] [blame] | 11990 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 11991 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11992 | mSecondWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | 5474565 | 2022-04-20 07:17:41 +0000 | [diff] [blame] | 11993 | |
| 11994 | // Second down on first window. |
| 11995 | const MotionEvent secondFingerDownEvent = |
| 11996 | MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 11997 | .displayId(ui::LogicalDisplayId::DEFAULT) |
Arthur Hung | 5474565 | 2022-04-20 07:17:41 +0000 | [diff] [blame] | 11998 | .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 11999 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(150).y(50)) |
| 12000 | .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(50).y(50)) |
Arthur Hung | 5474565 | 2022-04-20 07:17:41 +0000 | [diff] [blame] | 12001 | .build(); |
| 12002 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 12003 | injectMotionEvent(*mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, |
Arthur Hung | 5474565 | 2022-04-20 07:17:41 +0000 | [diff] [blame] | 12004 | InputEventInjectionSync::WAIT_FOR_RESULT)) |
| 12005 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12006 | mWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
| 12007 | mSecondWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT); |
Arthur Hung | 5474565 | 2022-04-20 07:17:41 +0000 | [diff] [blame] | 12008 | |
| 12009 | // Perform drag and drop from first window. |
Arthur Hung | b75c2aa | 2022-07-15 09:35:36 +0000 | [diff] [blame] | 12010 | ASSERT_TRUE(startDrag(false)); |
Arthur Hung | 5474565 | 2022-04-20 07:17:41 +0000 | [diff] [blame] | 12011 | |
| 12012 | // Move on window. |
| 12013 | const MotionEvent secondFingerMoveEvent = |
| 12014 | MotionEventBuilder(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 12015 | .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 12016 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(150).y(50)) |
| 12017 | .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(50).y(50)) |
Arthur Hung | 5474565 | 2022-04-20 07:17:41 +0000 | [diff] [blame] | 12018 | .build(); |
| 12019 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 12020 | injectMotionEvent(*mDispatcher, secondFingerMoveEvent, INJECT_EVENT_TIMEOUT, |
Arthur Hung | 5474565 | 2022-04-20 07:17:41 +0000 | [diff] [blame] | 12021 | InputEventInjectionSync::WAIT_FOR_RESULT)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12022 | mDragWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, |
| 12023 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
Arthur Hung | 5474565 | 2022-04-20 07:17:41 +0000 | [diff] [blame] | 12024 | mWindow->consumeDragEvent(false, 50, 50); |
| 12025 | mSecondWindow->consumeMotionMove(); |
| 12026 | |
| 12027 | // Release the drag pointer should perform drop. |
| 12028 | const MotionEvent secondFingerUpEvent = |
| 12029 | MotionEventBuilder(POINTER_1_UP, AINPUT_SOURCE_TOUCHSCREEN) |
| 12030 | .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 12031 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(150).y(50)) |
| 12032 | .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(50).y(50)) |
Arthur Hung | 5474565 | 2022-04-20 07:17:41 +0000 | [diff] [blame] | 12033 | .build(); |
| 12034 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 12035 | injectMotionEvent(*mDispatcher, secondFingerUpEvent, INJECT_EVENT_TIMEOUT, |
Arthur Hung | 5474565 | 2022-04-20 07:17:41 +0000 | [diff] [blame] | 12036 | InputEventInjectionSync::WAIT_FOR_RESULT)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12037 | mDragWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
Siarhei Vishniakou | a66d65e | 2023-06-16 10:32:51 -0700 | [diff] [blame] | 12038 | mFakePolicy->assertDropTargetEquals(*mDispatcher, mWindow->getToken()); |
Arthur Hung | 5474565 | 2022-04-20 07:17:41 +0000 | [diff] [blame] | 12039 | mWindow->assertNoEvents(); |
| 12040 | mSecondWindow->consumeMotionMove(); |
| 12041 | } |
| 12042 | |
Arthur Hung | 3915c1f | 2022-05-31 07:17:17 +0000 | [diff] [blame] | 12043 | TEST_F(InputDispatcherDragTests, DragAndDropWhenMultiDisplays) { |
Arthur Hung | b75c2aa | 2022-07-15 09:35:36 +0000 | [diff] [blame] | 12044 | startDrag(); |
Arthur Hung | 3915c1f | 2022-05-31 07:17:17 +0000 | [diff] [blame] | 12045 | |
| 12046 | // Update window of second display. |
| 12047 | sp<FakeWindowHandle> windowInSecondary = |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 12048 | sp<FakeWindowHandle>::make(mApp, mDispatcher, "D_2", SECOND_DISPLAY_ID); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 12049 | mDispatcher->onWindowInfosChanged( |
| 12050 | {{*mDragWindow->getInfo(), *mSpyWindow->getInfo(), *mWindow->getInfo(), |
| 12051 | *mSecondWindow->getInfo(), *windowInSecondary->getInfo()}, |
| 12052 | {}, |
| 12053 | 0, |
| 12054 | 0}); |
Arthur Hung | 3915c1f | 2022-05-31 07:17:17 +0000 | [diff] [blame] | 12055 | |
| 12056 | // Let second display has a touch state. |
| 12057 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 12058 | injectMotionEvent(*mDispatcher, |
Arthur Hung | 3915c1f | 2022-05-31 07:17:17 +0000 | [diff] [blame] | 12059 | MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, |
| 12060 | AINPUT_SOURCE_TOUCHSCREEN) |
| 12061 | .displayId(SECOND_DISPLAY_ID) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 12062 | .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) |
Arthur Hung | 3915c1f | 2022-05-31 07:17:17 +0000 | [diff] [blame] | 12063 | .build())); |
Prabir Pradhan | 7662a8d | 2023-12-15 01:58:14 +0000 | [diff] [blame] | 12064 | windowInSecondary->consumeMotionDown(SECOND_DISPLAY_ID, /*expectedFlag=*/0); |
Arthur Hung | 3915c1f | 2022-05-31 07:17:17 +0000 | [diff] [blame] | 12065 | // Update window again. |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 12066 | mDispatcher->onWindowInfosChanged( |
| 12067 | {{*mDragWindow->getInfo(), *mSpyWindow->getInfo(), *mWindow->getInfo(), |
| 12068 | *mSecondWindow->getInfo(), *windowInSecondary->getInfo()}, |
| 12069 | {}, |
| 12070 | 0, |
| 12071 | 0}); |
Arthur Hung | 3915c1f | 2022-05-31 07:17:17 +0000 | [diff] [blame] | 12072 | |
| 12073 | // Move on window. |
| 12074 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 12075 | injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12076 | ui::LogicalDisplayId::DEFAULT, {50, 50})) |
Arthur Hung | 3915c1f | 2022-05-31 07:17:17 +0000 | [diff] [blame] | 12077 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12078 | mDragWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, |
| 12079 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
Arthur Hung | 3915c1f | 2022-05-31 07:17:17 +0000 | [diff] [blame] | 12080 | mWindow->consumeDragEvent(false, 50, 50); |
| 12081 | mSecondWindow->assertNoEvents(); |
| 12082 | |
| 12083 | // Move to another window. |
| 12084 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 12085 | injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12086 | ui::LogicalDisplayId::DEFAULT, {150, 50})) |
Arthur Hung | 3915c1f | 2022-05-31 07:17:17 +0000 | [diff] [blame] | 12087 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12088 | mDragWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, |
| 12089 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
Arthur Hung | 3915c1f | 2022-05-31 07:17:17 +0000 | [diff] [blame] | 12090 | mWindow->consumeDragEvent(true, 150, 50); |
| 12091 | mSecondWindow->consumeDragEvent(false, 50, 50); |
| 12092 | |
| 12093 | // drop to another window. |
| 12094 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12095 | injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, |
Arthur Hung | 3915c1f | 2022-05-31 07:17:17 +0000 | [diff] [blame] | 12096 | {150, 50})) |
| 12097 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12098 | mDragWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
Siarhei Vishniakou | a66d65e | 2023-06-16 10:32:51 -0700 | [diff] [blame] | 12099 | mFakePolicy->assertDropTargetEquals(*mDispatcher, mSecondWindow->getToken()); |
Arthur Hung | 3915c1f | 2022-05-31 07:17:17 +0000 | [diff] [blame] | 12100 | mWindow->assertNoEvents(); |
| 12101 | mSecondWindow->assertNoEvents(); |
| 12102 | } |
| 12103 | |
Arthur Hung | b75c2aa | 2022-07-15 09:35:36 +0000 | [diff] [blame] | 12104 | TEST_F(InputDispatcherDragTests, MouseDragAndDrop) { |
| 12105 | startDrag(true, AINPUT_SOURCE_MOUSE); |
| 12106 | // Move on window. |
| 12107 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 12108 | injectMotionEvent(*mDispatcher, |
Arthur Hung | b75c2aa | 2022-07-15 09:35:36 +0000 | [diff] [blame] | 12109 | MotionEventBuilder(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_MOUSE) |
| 12110 | .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 12111 | .pointer(PointerBuilder(MOUSE_POINTER_ID, ToolType::MOUSE) |
Arthur Hung | b75c2aa | 2022-07-15 09:35:36 +0000 | [diff] [blame] | 12112 | .x(50) |
| 12113 | .y(50)) |
| 12114 | .build())) |
| 12115 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12116 | mDragWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, |
| 12117 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
Arthur Hung | b75c2aa | 2022-07-15 09:35:36 +0000 | [diff] [blame] | 12118 | mWindow->consumeDragEvent(false, 50, 50); |
| 12119 | mSecondWindow->assertNoEvents(); |
| 12120 | |
| 12121 | // Move to another window. |
| 12122 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 12123 | injectMotionEvent(*mDispatcher, |
Arthur Hung | b75c2aa | 2022-07-15 09:35:36 +0000 | [diff] [blame] | 12124 | MotionEventBuilder(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_MOUSE) |
| 12125 | .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 12126 | .pointer(PointerBuilder(MOUSE_POINTER_ID, ToolType::MOUSE) |
Arthur Hung | b75c2aa | 2022-07-15 09:35:36 +0000 | [diff] [blame] | 12127 | .x(150) |
| 12128 | .y(50)) |
| 12129 | .build())) |
| 12130 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12131 | mDragWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, |
| 12132 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
Arthur Hung | b75c2aa | 2022-07-15 09:35:36 +0000 | [diff] [blame] | 12133 | mWindow->consumeDragEvent(true, 150, 50); |
| 12134 | mSecondWindow->consumeDragEvent(false, 50, 50); |
| 12135 | |
| 12136 | // drop to another window. |
| 12137 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 12138 | injectMotionEvent(*mDispatcher, |
Arthur Hung | b75c2aa | 2022-07-15 09:35:36 +0000 | [diff] [blame] | 12139 | MotionEventBuilder(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_MOUSE) |
| 12140 | .buttonState(0) |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 12141 | .pointer(PointerBuilder(MOUSE_POINTER_ID, ToolType::MOUSE) |
Arthur Hung | b75c2aa | 2022-07-15 09:35:36 +0000 | [diff] [blame] | 12142 | .x(150) |
| 12143 | .y(50)) |
| 12144 | .build())) |
| 12145 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12146 | mDragWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); |
Siarhei Vishniakou | a66d65e | 2023-06-16 10:32:51 -0700 | [diff] [blame] | 12147 | mFakePolicy->assertDropTargetEquals(*mDispatcher, mSecondWindow->getToken()); |
Arthur Hung | b75c2aa | 2022-07-15 09:35:36 +0000 | [diff] [blame] | 12148 | mWindow->assertNoEvents(); |
| 12149 | mSecondWindow->assertNoEvents(); |
| 12150 | } |
| 12151 | |
Linnan Li | 5af92f9 | 2023-07-14 14:36:22 +0800 | [diff] [blame] | 12152 | /** |
| 12153 | * Start drag and drop with a pointer whose id is not 0, cancel the current touch, and ensure drag |
| 12154 | * and drop is also canceled. Then inject a simple gesture, and ensure dispatcher does not crash. |
| 12155 | */ |
| 12156 | TEST_F(InputDispatcherDragTests, DragAndDropFinishedWhenCancelCurrentTouch) { |
| 12157 | // Down on second window |
| 12158 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12159 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 12160 | ui::LogicalDisplayId::DEFAULT, {150, 50})) |
Linnan Li | 5af92f9 | 2023-07-14 14:36:22 +0800 | [diff] [blame] | 12161 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 12162 | |
| 12163 | ASSERT_NO_FATAL_FAILURE(mSecondWindow->consumeMotionDown()); |
| 12164 | ASSERT_NO_FATAL_FAILURE(mSpyWindow->consumeMotionDown()); |
| 12165 | |
| 12166 | // Down on first window |
| 12167 | const MotionEvent secondFingerDownEvent = |
| 12168 | MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12169 | .displayId(ui::LogicalDisplayId::DEFAULT) |
Linnan Li | 5af92f9 | 2023-07-14 14:36:22 +0800 | [diff] [blame] | 12170 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(150).y(50)) |
| 12171 | .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(50).y(50)) |
| 12172 | .build(); |
| 12173 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
| 12174 | injectMotionEvent(*mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, |
| 12175 | InputEventInjectionSync::WAIT_FOR_RESULT)) |
| 12176 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 12177 | ASSERT_NO_FATAL_FAILURE(mWindow->consumeMotionDown()); |
| 12178 | ASSERT_NO_FATAL_FAILURE(mSecondWindow->consumeMotionMove()); |
| 12179 | ASSERT_NO_FATAL_FAILURE(mSpyWindow->consumeMotionPointerDown(1)); |
| 12180 | |
| 12181 | // Start drag on first window |
| 12182 | ASSERT_TRUE(startDrag(/*sendDown=*/false, AINPUT_SOURCE_TOUCHSCREEN)); |
| 12183 | |
| 12184 | // Trigger cancel |
| 12185 | mDispatcher->cancelCurrentTouch(); |
| 12186 | ASSERT_NO_FATAL_FAILURE(mSecondWindow->consumeMotionCancel()); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12187 | ASSERT_NO_FATAL_FAILURE(mDragWindow->consumeMotionCancel(ui::LogicalDisplayId::DEFAULT, |
Prabir Pradhan | 65455c7 | 2024-02-13 21:46:41 +0000 | [diff] [blame] | 12188 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE)); |
Linnan Li | 5af92f9 | 2023-07-14 14:36:22 +0800 | [diff] [blame] | 12189 | ASSERT_NO_FATAL_FAILURE(mSpyWindow->consumeMotionCancel()); |
| 12190 | |
| 12191 | ASSERT_TRUE(mDispatcher->waitForIdle()); |
| 12192 | // The D&D finished with nullptr |
| 12193 | mFakePolicy->assertDropTargetEquals(*mDispatcher, nullptr); |
| 12194 | |
| 12195 | // Remove drag window |
| 12196 | mDispatcher->onWindowInfosChanged({{*mWindow->getInfo(), *mSecondWindow->getInfo()}, {}, 0, 0}); |
| 12197 | |
| 12198 | // Inject a simple gesture, ensure dispatcher not crashed |
| 12199 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12200 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 12201 | ui::LogicalDisplayId::DEFAULT, PointF{50, 50})) |
Linnan Li | 5af92f9 | 2023-07-14 14:36:22 +0800 | [diff] [blame] | 12202 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 12203 | ASSERT_NO_FATAL_FAILURE(mWindow->consumeMotionDown()); |
| 12204 | |
| 12205 | const MotionEvent moveEvent = |
| 12206 | MotionEventBuilder(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12207 | .displayId(ui::LogicalDisplayId::DEFAULT) |
Linnan Li | 5af92f9 | 2023-07-14 14:36:22 +0800 | [diff] [blame] | 12208 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(50).y(50)) |
| 12209 | .build(); |
| 12210 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
| 12211 | injectMotionEvent(*mDispatcher, moveEvent, INJECT_EVENT_TIMEOUT, |
| 12212 | InputEventInjectionSync::WAIT_FOR_RESULT)) |
| 12213 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 12214 | ASSERT_NO_FATAL_FAILURE(mWindow->consumeMotionMove()); |
| 12215 | |
| 12216 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12217 | injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, |
Linnan Li | 5af92f9 | 2023-07-14 14:36:22 +0800 | [diff] [blame] | 12218 | {50, 50})) |
| 12219 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 12220 | ASSERT_NO_FATAL_FAILURE(mWindow->consumeMotionUp()); |
| 12221 | } |
| 12222 | |
Prabir Pradhan | 9cd9eb6 | 2023-11-22 17:58:06 +0000 | [diff] [blame] | 12223 | TEST_F(InputDispatcherDragTests, NoDragAndDropWithHoveringPointer) { |
| 12224 | // Start hovering over the window. |
| 12225 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
| 12226 | injectMotionEvent(*mDispatcher, ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12227 | ui::LogicalDisplayId::DEFAULT, {50, 50})); |
Prabir Pradhan | 9cd9eb6 | 2023-11-22 17:58:06 +0000 | [diff] [blame] | 12228 | |
| 12229 | ASSERT_NO_FATAL_FAILURE(mWindow->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER))); |
| 12230 | ASSERT_NO_FATAL_FAILURE(mSpyWindow->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER))); |
| 12231 | |
| 12232 | ASSERT_FALSE(startDrag(/*sendDown=*/false)) |
| 12233 | << "Drag and drop should not work with a hovering pointer"; |
| 12234 | } |
| 12235 | |
Vishnu Nair | 062a867 | 2021-09-03 16:07:44 -0700 | [diff] [blame] | 12236 | class InputDispatcherDropInputFeatureTest : public InputDispatcherTest {}; |
| 12237 | |
| 12238 | TEST_F(InputDispatcherDropInputFeatureTest, WindowDropsInput) { |
| 12239 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12240 | sp<FakeWindowHandle> window = |
| 12241 | sp<FakeWindowHandle>::make(application, mDispatcher, "Test window", |
| 12242 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 51e7db0 | 2022-02-07 06:02:57 -0800 | [diff] [blame] | 12243 | window->setDropInput(true); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12244 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); |
Vishnu Nair | 062a867 | 2021-09-03 16:07:44 -0700 | [diff] [blame] | 12245 | window->setFocusable(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 12246 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 062a867 | 2021-09-03 16:07:44 -0700 | [diff] [blame] | 12247 | setFocusedWindow(window); |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 12248 | window->consumeFocusEvent(/*hasFocus=*/true, /*inTouchMode=*/true); |
Vishnu Nair | 062a867 | 2021-09-03 16:07:44 -0700 | [diff] [blame] | 12249 | |
| 12250 | // With the flag set, window should not get any input |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12251 | mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ui::LogicalDisplayId::DEFAULT)); |
Vishnu Nair | 062a867 | 2021-09-03 16:07:44 -0700 | [diff] [blame] | 12252 | window->assertNoEvents(); |
| 12253 | |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 12254 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12255 | AINPUT_SOURCE_TOUCHSCREEN, |
| 12256 | ui::LogicalDisplayId::DEFAULT)); |
Siarhei Vishniakou | 5c02a71 | 2023-05-15 15:45:02 -0700 | [diff] [blame] | 12257 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12258 | ui::LogicalDisplayId::DEFAULT)); |
Siarhei Vishniakou | d908f5a | 2023-11-16 10:25:12 -0800 | [diff] [blame] | 12259 | mDispatcher->waitForIdle(); |
Vishnu Nair | 062a867 | 2021-09-03 16:07:44 -0700 | [diff] [blame] | 12260 | window->assertNoEvents(); |
| 12261 | |
| 12262 | // With the flag cleared, the window should get input |
Prabir Pradhan | 51e7db0 | 2022-02-07 06:02:57 -0800 | [diff] [blame] | 12263 | window->setDropInput(false); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 12264 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 062a867 | 2021-09-03 16:07:44 -0700 | [diff] [blame] | 12265 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12266 | mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_UP, ui::LogicalDisplayId::DEFAULT)); |
| 12267 | window->consumeKeyUp(ui::LogicalDisplayId::DEFAULT); |
Vishnu Nair | 062a867 | 2021-09-03 16:07:44 -0700 | [diff] [blame] | 12268 | |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 12269 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12270 | AINPUT_SOURCE_TOUCHSCREEN, |
| 12271 | ui::LogicalDisplayId::DEFAULT)); |
| 12272 | window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Vishnu Nair | 062a867 | 2021-09-03 16:07:44 -0700 | [diff] [blame] | 12273 | window->assertNoEvents(); |
| 12274 | } |
| 12275 | |
| 12276 | TEST_F(InputDispatcherDropInputFeatureTest, ObscuredWindowDropsInput) { |
| 12277 | std::shared_ptr<FakeApplicationHandle> obscuringApplication = |
| 12278 | std::make_shared<FakeApplicationHandle>(); |
| 12279 | sp<FakeWindowHandle> obscuringWindow = |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 12280 | sp<FakeWindowHandle>::make(obscuringApplication, mDispatcher, "obscuringWindow", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12281 | ui::LogicalDisplayId::DEFAULT); |
Vishnu Nair | 062a867 | 2021-09-03 16:07:44 -0700 | [diff] [blame] | 12282 | obscuringWindow->setFrame(Rect(0, 0, 50, 50)); |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 12283 | obscuringWindow->setOwnerInfo(gui::Pid{111}, gui::Uid{111}); |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 12284 | obscuringWindow->setTouchable(false); |
Vishnu Nair | 062a867 | 2021-09-03 16:07:44 -0700 | [diff] [blame] | 12285 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12286 | sp<FakeWindowHandle> window = |
| 12287 | sp<FakeWindowHandle>::make(application, mDispatcher, "Test window", |
| 12288 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 51e7db0 | 2022-02-07 06:02:57 -0800 | [diff] [blame] | 12289 | window->setDropInputIfObscured(true); |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 12290 | window->setOwnerInfo(gui::Pid{222}, gui::Uid{222}); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12291 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); |
Vishnu Nair | 062a867 | 2021-09-03 16:07:44 -0700 | [diff] [blame] | 12292 | window->setFocusable(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 12293 | mDispatcher->onWindowInfosChanged( |
| 12294 | {{*obscuringWindow->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 062a867 | 2021-09-03 16:07:44 -0700 | [diff] [blame] | 12295 | setFocusedWindow(window); |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 12296 | window->consumeFocusEvent(/*hasFocus=*/true, /*inTouchMode=*/true); |
Vishnu Nair | 062a867 | 2021-09-03 16:07:44 -0700 | [diff] [blame] | 12297 | |
| 12298 | // With the flag set, window should not get any input |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12299 | mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ui::LogicalDisplayId::DEFAULT)); |
Vishnu Nair | 062a867 | 2021-09-03 16:07:44 -0700 | [diff] [blame] | 12300 | window->assertNoEvents(); |
| 12301 | |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 12302 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12303 | AINPUT_SOURCE_TOUCHSCREEN, |
| 12304 | ui::LogicalDisplayId::DEFAULT)); |
Siarhei Vishniakou | 5c02a71 | 2023-05-15 15:45:02 -0700 | [diff] [blame] | 12305 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12306 | ui::LogicalDisplayId::DEFAULT)); |
Vishnu Nair | 062a867 | 2021-09-03 16:07:44 -0700 | [diff] [blame] | 12307 | window->assertNoEvents(); |
| 12308 | |
| 12309 | // With the flag cleared, the window should get input |
Prabir Pradhan | 51e7db0 | 2022-02-07 06:02:57 -0800 | [diff] [blame] | 12310 | window->setDropInputIfObscured(false); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 12311 | mDispatcher->onWindowInfosChanged( |
| 12312 | {{*obscuringWindow->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 062a867 | 2021-09-03 16:07:44 -0700 | [diff] [blame] | 12313 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12314 | mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_UP, ui::LogicalDisplayId::DEFAULT)); |
| 12315 | window->consumeKeyUp(ui::LogicalDisplayId::DEFAULT); |
Vishnu Nair | 062a867 | 2021-09-03 16:07:44 -0700 | [diff] [blame] | 12316 | |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 12317 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12318 | AINPUT_SOURCE_TOUCHSCREEN, |
| 12319 | ui::LogicalDisplayId::DEFAULT)); |
| 12320 | window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, |
| 12321 | AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED); |
Vishnu Nair | 062a867 | 2021-09-03 16:07:44 -0700 | [diff] [blame] | 12322 | window->assertNoEvents(); |
| 12323 | } |
| 12324 | |
| 12325 | TEST_F(InputDispatcherDropInputFeatureTest, UnobscuredWindowGetsInput) { |
| 12326 | std::shared_ptr<FakeApplicationHandle> obscuringApplication = |
| 12327 | std::make_shared<FakeApplicationHandle>(); |
| 12328 | sp<FakeWindowHandle> obscuringWindow = |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 12329 | sp<FakeWindowHandle>::make(obscuringApplication, mDispatcher, "obscuringWindow", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12330 | ui::LogicalDisplayId::DEFAULT); |
Vishnu Nair | 062a867 | 2021-09-03 16:07:44 -0700 | [diff] [blame] | 12331 | obscuringWindow->setFrame(Rect(0, 0, 50, 50)); |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 12332 | obscuringWindow->setOwnerInfo(gui::Pid{111}, gui::Uid{111}); |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 12333 | obscuringWindow->setTouchable(false); |
Vishnu Nair | 062a867 | 2021-09-03 16:07:44 -0700 | [diff] [blame] | 12334 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12335 | sp<FakeWindowHandle> window = |
| 12336 | sp<FakeWindowHandle>::make(application, mDispatcher, "Test window", |
| 12337 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 51e7db0 | 2022-02-07 06:02:57 -0800 | [diff] [blame] | 12338 | window->setDropInputIfObscured(true); |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 12339 | window->setOwnerInfo(gui::Pid{222}, gui::Uid{222}); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12340 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); |
Vishnu Nair | 062a867 | 2021-09-03 16:07:44 -0700 | [diff] [blame] | 12341 | window->setFocusable(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 12342 | mDispatcher->onWindowInfosChanged( |
| 12343 | {{*obscuringWindow->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 062a867 | 2021-09-03 16:07:44 -0700 | [diff] [blame] | 12344 | setFocusedWindow(window); |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 12345 | window->consumeFocusEvent(/*hasFocus=*/true, /*inTouchMode=*/true); |
Vishnu Nair | 062a867 | 2021-09-03 16:07:44 -0700 | [diff] [blame] | 12346 | |
| 12347 | // With the flag set, window should not get any input |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12348 | mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ui::LogicalDisplayId::DEFAULT)); |
Vishnu Nair | 062a867 | 2021-09-03 16:07:44 -0700 | [diff] [blame] | 12349 | window->assertNoEvents(); |
| 12350 | |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 12351 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12352 | AINPUT_SOURCE_TOUCHSCREEN, |
| 12353 | ui::LogicalDisplayId::DEFAULT)); |
Siarhei Vishniakou | 5c02a71 | 2023-05-15 15:45:02 -0700 | [diff] [blame] | 12354 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12355 | ui::LogicalDisplayId::DEFAULT)); |
Vishnu Nair | 062a867 | 2021-09-03 16:07:44 -0700 | [diff] [blame] | 12356 | window->assertNoEvents(); |
| 12357 | |
| 12358 | // When the window is no longer obscured because it went on top, it should get input |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 12359 | mDispatcher->onWindowInfosChanged( |
| 12360 | {{*window->getInfo(), *obscuringWindow->getInfo()}, {}, 0, 0}); |
Vishnu Nair | 062a867 | 2021-09-03 16:07:44 -0700 | [diff] [blame] | 12361 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12362 | mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_UP, ui::LogicalDisplayId::DEFAULT)); |
| 12363 | window->consumeKeyUp(ui::LogicalDisplayId::DEFAULT); |
Vishnu Nair | 062a867 | 2021-09-03 16:07:44 -0700 | [diff] [blame] | 12364 | |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 12365 | mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12366 | AINPUT_SOURCE_TOUCHSCREEN, |
| 12367 | ui::LogicalDisplayId::DEFAULT)); |
| 12368 | window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Vishnu Nair | 062a867 | 2021-09-03 16:07:44 -0700 | [diff] [blame] | 12369 | window->assertNoEvents(); |
| 12370 | } |
| 12371 | |
Antonio Kantek | f16f283 | 2021-09-28 04:39:20 +0000 | [diff] [blame] | 12372 | class InputDispatcherTouchModeChangedTests : public InputDispatcherTest { |
| 12373 | protected: |
| 12374 | std::shared_ptr<FakeApplicationHandle> mApp; |
Antonio Kantek | 15beb51 | 2022-06-13 22:35:41 +0000 | [diff] [blame] | 12375 | std::shared_ptr<FakeApplicationHandle> mSecondaryApp; |
Antonio Kantek | f16f283 | 2021-09-28 04:39:20 +0000 | [diff] [blame] | 12376 | sp<FakeWindowHandle> mWindow; |
| 12377 | sp<FakeWindowHandle> mSecondWindow; |
Antonio Kantek | 15beb51 | 2022-06-13 22:35:41 +0000 | [diff] [blame] | 12378 | sp<FakeWindowHandle> mThirdWindow; |
Antonio Kantek | f16f283 | 2021-09-28 04:39:20 +0000 | [diff] [blame] | 12379 | |
| 12380 | void SetUp() override { |
| 12381 | InputDispatcherTest::SetUp(); |
| 12382 | |
| 12383 | mApp = std::make_shared<FakeApplicationHandle>(); |
Antonio Kantek | 15beb51 | 2022-06-13 22:35:41 +0000 | [diff] [blame] | 12384 | mSecondaryApp = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12385 | mWindow = sp<FakeWindowHandle>::make(mApp, mDispatcher, "TestWindow", |
| 12386 | ui::LogicalDisplayId::DEFAULT); |
Antonio Kantek | f16f283 | 2021-09-28 04:39:20 +0000 | [diff] [blame] | 12387 | mWindow->setFocusable(true); |
Antonio Kantek | 26defcf | 2022-02-08 01:12:27 +0000 | [diff] [blame] | 12388 | setFocusedWindow(mWindow); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12389 | mSecondWindow = sp<FakeWindowHandle>::make(mApp, mDispatcher, "TestWindow2", |
| 12390 | ui::LogicalDisplayId::DEFAULT); |
Antonio Kantek | f16f283 | 2021-09-28 04:39:20 +0000 | [diff] [blame] | 12391 | mSecondWindow->setFocusable(true); |
Antonio Kantek | 15beb51 | 2022-06-13 22:35:41 +0000 | [diff] [blame] | 12392 | mThirdWindow = |
| 12393 | sp<FakeWindowHandle>::make(mSecondaryApp, mDispatcher, |
| 12394 | "TestWindow3_SecondaryDisplay", SECOND_DISPLAY_ID); |
| 12395 | mThirdWindow->setFocusable(true); |
Antonio Kantek | f16f283 | 2021-09-28 04:39:20 +0000 | [diff] [blame] | 12396 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12397 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, mApp); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 12398 | mDispatcher->onWindowInfosChanged( |
| 12399 | {{*mWindow->getInfo(), *mSecondWindow->getInfo(), *mThirdWindow->getInfo()}, |
| 12400 | {}, |
| 12401 | 0, |
| 12402 | 0}); |
Antonio Kantek | 15beb51 | 2022-06-13 22:35:41 +0000 | [diff] [blame] | 12403 | mThirdWindow->setOwnerInfo(SECONDARY_WINDOW_PID, SECONDARY_WINDOW_UID); |
Antonio Kantek | f16f283 | 2021-09-28 04:39:20 +0000 | [diff] [blame] | 12404 | mWindow->consumeFocusEvent(true); |
Antonio Kantek | 26defcf | 2022-02-08 01:12:27 +0000 | [diff] [blame] | 12405 | |
Antonio Kantek | 15beb51 | 2022-06-13 22:35:41 +0000 | [diff] [blame] | 12406 | // Set main display initial touch mode to InputDispatcher::kDefaultInTouchMode. |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 12407 | if (mDispatcher->setInTouchMode(InputDispatcher::kDefaultInTouchMode, WINDOW_PID, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12408 | WINDOW_UID, /*hasPermission=*/true, |
| 12409 | ui::LogicalDisplayId::DEFAULT)) { |
Antonio Kantek | 48710e4 | 2022-03-24 14:19:30 -0700 | [diff] [blame] | 12410 | mWindow->consumeTouchModeEvent(InputDispatcher::kDefaultInTouchMode); |
| 12411 | mSecondWindow->consumeTouchModeEvent(InputDispatcher::kDefaultInTouchMode); |
Antonio Kantek | 15beb51 | 2022-06-13 22:35:41 +0000 | [diff] [blame] | 12412 | mThirdWindow->assertNoEvents(); |
| 12413 | } |
| 12414 | |
| 12415 | // Set secondary display initial touch mode to InputDispatcher::kDefaultInTouchMode. |
| 12416 | if (mDispatcher->setInTouchMode(InputDispatcher::kDefaultInTouchMode, SECONDARY_WINDOW_PID, |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 12417 | SECONDARY_WINDOW_UID, /*hasPermission=*/true, |
Antonio Kantek | 15beb51 | 2022-06-13 22:35:41 +0000 | [diff] [blame] | 12418 | SECOND_DISPLAY_ID)) { |
| 12419 | mWindow->assertNoEvents(); |
| 12420 | mSecondWindow->assertNoEvents(); |
| 12421 | mThirdWindow->consumeTouchModeEvent(InputDispatcher::kDefaultInTouchMode); |
Antonio Kantek | 48710e4 | 2022-03-24 14:19:30 -0700 | [diff] [blame] | 12422 | } |
Antonio Kantek | f16f283 | 2021-09-28 04:39:20 +0000 | [diff] [blame] | 12423 | } |
| 12424 | |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 12425 | void changeAndVerifyTouchModeInMainDisplayOnly(bool inTouchMode, gui::Pid pid, gui::Uid uid, |
Antonio Kantek | 15beb51 | 2022-06-13 22:35:41 +0000 | [diff] [blame] | 12426 | bool hasPermission) { |
Antonio Kantek | a042c02 | 2022-07-06 16:51:07 -0700 | [diff] [blame] | 12427 | ASSERT_TRUE(mDispatcher->setInTouchMode(inTouchMode, pid, uid, hasPermission, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12428 | ui::LogicalDisplayId::DEFAULT)); |
Antonio Kantek | f16f283 | 2021-09-28 04:39:20 +0000 | [diff] [blame] | 12429 | mWindow->consumeTouchModeEvent(inTouchMode); |
| 12430 | mSecondWindow->consumeTouchModeEvent(inTouchMode); |
Antonio Kantek | 15beb51 | 2022-06-13 22:35:41 +0000 | [diff] [blame] | 12431 | mThirdWindow->assertNoEvents(); |
Antonio Kantek | f16f283 | 2021-09-28 04:39:20 +0000 | [diff] [blame] | 12432 | } |
| 12433 | }; |
| 12434 | |
Antonio Kantek | 26defcf | 2022-02-08 01:12:27 +0000 | [diff] [blame] | 12435 | TEST_F(InputDispatcherTouchModeChangedTests, FocusedWindowCanChangeTouchMode) { |
Antonio Kantek | ea47acb | 2021-12-23 12:41:25 -0800 | [diff] [blame] | 12436 | const WindowInfo& windowInfo = *mWindow->getInfo(); |
Antonio Kantek | 15beb51 | 2022-06-13 22:35:41 +0000 | [diff] [blame] | 12437 | changeAndVerifyTouchModeInMainDisplayOnly(!InputDispatcher::kDefaultInTouchMode, |
| 12438 | windowInfo.ownerPid, windowInfo.ownerUid, |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 12439 | /* hasPermission=*/false); |
Antonio Kantek | f16f283 | 2021-09-28 04:39:20 +0000 | [diff] [blame] | 12440 | } |
| 12441 | |
Antonio Kantek | 26defcf | 2022-02-08 01:12:27 +0000 | [diff] [blame] | 12442 | TEST_F(InputDispatcherTouchModeChangedTests, NonFocusedWindowOwnerCannotChangeTouchMode) { |
| 12443 | const WindowInfo& windowInfo = *mWindow->getInfo(); |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 12444 | gui::Pid ownerPid = windowInfo.ownerPid; |
Prabir Pradhan | 8a5c41d | 2023-06-08 19:13:46 +0000 | [diff] [blame] | 12445 | gui::Uid ownerUid = windowInfo.ownerUid; |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 12446 | mWindow->setOwnerInfo(gui::Pid::INVALID, gui::Uid::INVALID); |
Antonio Kantek | 26defcf | 2022-02-08 01:12:27 +0000 | [diff] [blame] | 12447 | ASSERT_FALSE(mDispatcher->setInTouchMode(InputDispatcher::kDefaultInTouchMode, ownerPid, |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 12448 | ownerUid, /*hasPermission=*/false, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12449 | ui::LogicalDisplayId::DEFAULT)); |
Antonio Kantek | 26defcf | 2022-02-08 01:12:27 +0000 | [diff] [blame] | 12450 | mWindow->assertNoEvents(); |
| 12451 | mSecondWindow->assertNoEvents(); |
| 12452 | } |
| 12453 | |
| 12454 | TEST_F(InputDispatcherTouchModeChangedTests, NonWindowOwnerMayChangeTouchModeOnPermissionGranted) { |
| 12455 | const WindowInfo& windowInfo = *mWindow->getInfo(); |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 12456 | gui::Pid ownerPid = windowInfo.ownerPid; |
Prabir Pradhan | 8a5c41d | 2023-06-08 19:13:46 +0000 | [diff] [blame] | 12457 | gui::Uid ownerUid = windowInfo.ownerUid; |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 12458 | mWindow->setOwnerInfo(gui::Pid::INVALID, gui::Uid::INVALID); |
Antonio Kantek | 15beb51 | 2022-06-13 22:35:41 +0000 | [diff] [blame] | 12459 | changeAndVerifyTouchModeInMainDisplayOnly(!InputDispatcher::kDefaultInTouchMode, ownerPid, |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 12460 | ownerUid, /*hasPermission=*/true); |
Antonio Kantek | 26defcf | 2022-02-08 01:12:27 +0000 | [diff] [blame] | 12461 | } |
| 12462 | |
Antonio Kantek | f16f283 | 2021-09-28 04:39:20 +0000 | [diff] [blame] | 12463 | TEST_F(InputDispatcherTouchModeChangedTests, EventIsNotGeneratedIfNotChangingTouchMode) { |
Antonio Kantek | ea47acb | 2021-12-23 12:41:25 -0800 | [diff] [blame] | 12464 | const WindowInfo& windowInfo = *mWindow->getInfo(); |
Antonio Kantek | 26defcf | 2022-02-08 01:12:27 +0000 | [diff] [blame] | 12465 | ASSERT_FALSE(mDispatcher->setInTouchMode(InputDispatcher::kDefaultInTouchMode, |
| 12466 | windowInfo.ownerPid, windowInfo.ownerUid, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12467 | /*hasPermission=*/true, |
| 12468 | ui::LogicalDisplayId::DEFAULT)); |
Antonio Kantek | f16f283 | 2021-09-28 04:39:20 +0000 | [diff] [blame] | 12469 | mWindow->assertNoEvents(); |
| 12470 | mSecondWindow->assertNoEvents(); |
| 12471 | } |
| 12472 | |
Antonio Kantek | 15beb51 | 2022-06-13 22:35:41 +0000 | [diff] [blame] | 12473 | TEST_F(InputDispatcherTouchModeChangedTests, ChangeTouchOnSecondaryDisplayOnly) { |
| 12474 | const WindowInfo& windowInfo = *mThirdWindow->getInfo(); |
| 12475 | ASSERT_TRUE(mDispatcher->setInTouchMode(!InputDispatcher::kDefaultInTouchMode, |
| 12476 | windowInfo.ownerPid, windowInfo.ownerUid, |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 12477 | /*hasPermission=*/true, SECOND_DISPLAY_ID)); |
Antonio Kantek | 15beb51 | 2022-06-13 22:35:41 +0000 | [diff] [blame] | 12478 | mWindow->assertNoEvents(); |
| 12479 | mSecondWindow->assertNoEvents(); |
| 12480 | mThirdWindow->consumeTouchModeEvent(!InputDispatcher::kDefaultInTouchMode); |
| 12481 | } |
| 12482 | |
Antonio Kantek | 48710e4 | 2022-03-24 14:19:30 -0700 | [diff] [blame] | 12483 | TEST_F(InputDispatcherTouchModeChangedTests, CanChangeTouchModeWhenOwningLastInteractedWindow) { |
| 12484 | // Interact with the window first. |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 12485 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12486 | injectKeyDown(*mDispatcher, ui::LogicalDisplayId::DEFAULT)) |
Antonio Kantek | 48710e4 | 2022-03-24 14:19:30 -0700 | [diff] [blame] | 12487 | << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12488 | mWindow->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); |
Antonio Kantek | 48710e4 | 2022-03-24 14:19:30 -0700 | [diff] [blame] | 12489 | |
| 12490 | // Then remove focus. |
| 12491 | mWindow->setFocusable(false); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 12492 | mDispatcher->onWindowInfosChanged({{*mWindow->getInfo()}, {}, 0, 0}); |
Antonio Kantek | 48710e4 | 2022-03-24 14:19:30 -0700 | [diff] [blame] | 12493 | |
| 12494 | // Assert that caller can switch touch mode by owning one of the last interacted window. |
| 12495 | const WindowInfo& windowInfo = *mWindow->getInfo(); |
| 12496 | ASSERT_TRUE(mDispatcher->setInTouchMode(!InputDispatcher::kDefaultInTouchMode, |
| 12497 | windowInfo.ownerPid, windowInfo.ownerUid, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12498 | /*hasPermission=*/false, |
| 12499 | ui::LogicalDisplayId::DEFAULT)); |
Antonio Kantek | 48710e4 | 2022-03-24 14:19:30 -0700 | [diff] [blame] | 12500 | } |
| 12501 | |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12502 | class InputDispatcherSpyWindowTest : public InputDispatcherTest { |
| 12503 | public: |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 12504 | sp<FakeWindowHandle> createSpy() { |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12505 | std::shared_ptr<FakeApplicationHandle> application = |
| 12506 | std::make_shared<FakeApplicationHandle>(); |
| 12507 | std::string name = "Fake Spy "; |
| 12508 | name += std::to_string(mSpyCount++); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12509 | sp<FakeWindowHandle> spy = |
| 12510 | sp<FakeWindowHandle>::make(application, mDispatcher, name.c_str(), |
| 12511 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 51e7db0 | 2022-02-07 06:02:57 -0800 | [diff] [blame] | 12512 | spy->setSpy(true); |
Prabir Pradhan | 5c85e05 | 2021-12-22 02:27:12 -0800 | [diff] [blame] | 12513 | spy->setTrustedOverlay(true); |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12514 | return spy; |
| 12515 | } |
| 12516 | |
| 12517 | sp<FakeWindowHandle> createForeground() { |
| 12518 | std::shared_ptr<FakeApplicationHandle> application = |
| 12519 | std::make_shared<FakeApplicationHandle>(); |
| 12520 | sp<FakeWindowHandle> window = |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 12521 | sp<FakeWindowHandle>::make(application, mDispatcher, "Fake Window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12522 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 12523 | window->setFocusable(true); |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12524 | return window; |
| 12525 | } |
| 12526 | |
| 12527 | private: |
| 12528 | int mSpyCount{0}; |
| 12529 | }; |
| 12530 | |
Prabir Pradhan | a3ab87a | 2022-01-27 10:00:21 -0800 | [diff] [blame] | 12531 | using InputDispatcherSpyWindowDeathTest = InputDispatcherSpyWindowTest; |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12532 | /** |
Prabir Pradhan | 5c85e05 | 2021-12-22 02:27:12 -0800 | [diff] [blame] | 12533 | * Adding a spy window that is not a trusted overlay causes Dispatcher to abort. |
| 12534 | */ |
Prabir Pradhan | a3ab87a | 2022-01-27 10:00:21 -0800 | [diff] [blame] | 12535 | TEST_F(InputDispatcherSpyWindowDeathTest, UntrustedSpy_AbortsDispatcher) { |
Siarhei Vishniakou | 21f77bd | 2023-07-18 17:51:35 -0700 | [diff] [blame] | 12536 | testing::GTEST_FLAG(death_test_style) = "threadsafe"; |
Prabir Pradhan | a3ab87a | 2022-01-27 10:00:21 -0800 | [diff] [blame] | 12537 | ScopedSilentDeath _silentDeath; |
| 12538 | |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 12539 | auto spy = createSpy(); |
Prabir Pradhan | 5c85e05 | 2021-12-22 02:27:12 -0800 | [diff] [blame] | 12540 | spy->setTrustedOverlay(false); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 12541 | ASSERT_DEATH(mDispatcher->onWindowInfosChanged({{*spy->getInfo()}, {}, 0, 0}), |
Prabir Pradhan | 5c85e05 | 2021-12-22 02:27:12 -0800 | [diff] [blame] | 12542 | ".* not a trusted overlay"); |
| 12543 | } |
| 12544 | |
| 12545 | /** |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12546 | * Input injection into a display with a spy window but no foreground windows should succeed. |
| 12547 | */ |
| 12548 | TEST_F(InputDispatcherSpyWindowTest, NoForegroundWindow) { |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 12549 | auto spy = createSpy(); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 12550 | mDispatcher->onWindowInfosChanged({{*spy->getInfo()}, {}, 0, 0}); |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12551 | |
| 12552 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12553 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 12554 | ui::LogicalDisplayId::DEFAULT)) |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12555 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12556 | spy->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12557 | } |
| 12558 | |
| 12559 | /** |
| 12560 | * Verify the order in which different input windows receive events. The touched foreground window |
| 12561 | * (if there is one) should always receive the event first. When there are multiple spy windows, the |
| 12562 | * spy windows will receive the event according to their Z-order, where the top-most spy window will |
| 12563 | * receive events before ones belows it. |
| 12564 | * |
| 12565 | * Here, we set up a scenario with four windows in the following Z order from the top: |
| 12566 | * spy1, spy2, window, spy3. |
| 12567 | * We then inject an event and verify that the foreground "window" receives it first, followed by |
| 12568 | * "spy1" and "spy2". The "spy3" does not receive the event because it is underneath the foreground |
| 12569 | * window. |
| 12570 | */ |
| 12571 | TEST_F(InputDispatcherSpyWindowTest, ReceivesInputInOrder) { |
| 12572 | auto window = createForeground(); |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 12573 | auto spy1 = createSpy(); |
| 12574 | auto spy2 = createSpy(); |
| 12575 | auto spy3 = createSpy(); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 12576 | mDispatcher->onWindowInfosChanged( |
| 12577 | {{*spy1->getInfo(), *spy2->getInfo(), *window->getInfo(), *spy3->getInfo()}, {}, 0, 0}); |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12578 | const std::vector<sp<FakeWindowHandle>> channels{spy1, spy2, window, spy3}; |
| 12579 | const size_t numChannels = channels.size(); |
| 12580 | |
Michael Wright | 8e9a856 | 2022-02-09 13:44:29 +0000 | [diff] [blame] | 12581 | base::unique_fd epollFd(epoll_create1(EPOLL_CLOEXEC)); |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12582 | if (!epollFd.ok()) { |
| 12583 | FAIL() << "Failed to create epoll fd"; |
| 12584 | } |
| 12585 | |
| 12586 | for (size_t i = 0; i < numChannels; i++) { |
| 12587 | struct epoll_event event = {.events = EPOLLIN, .data.u64 = i}; |
| 12588 | if (epoll_ctl(epollFd.get(), EPOLL_CTL_ADD, channels[i]->getChannelFd(), &event) < 0) { |
| 12589 | FAIL() << "Failed to add fd to epoll"; |
| 12590 | } |
| 12591 | } |
| 12592 | |
| 12593 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12594 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 12595 | ui::LogicalDisplayId::DEFAULT)) |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12596 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 12597 | |
| 12598 | std::vector<size_t> eventOrder; |
| 12599 | std::vector<struct epoll_event> events(numChannels); |
| 12600 | for (;;) { |
| 12601 | const int nFds = epoll_wait(epollFd.get(), events.data(), static_cast<int>(numChannels), |
| 12602 | (100ms).count()); |
| 12603 | if (nFds < 0) { |
| 12604 | FAIL() << "Failed to call epoll_wait"; |
| 12605 | } |
| 12606 | if (nFds == 0) { |
| 12607 | break; // epoll_wait timed out |
| 12608 | } |
| 12609 | for (int i = 0; i < nFds; i++) { |
Colin Cross | 5b79930 | 2022-10-18 21:52:41 -0700 | [diff] [blame] | 12610 | ASSERT_EQ(static_cast<uint32_t>(EPOLLIN), events[i].events); |
Siarhei Vishniakou | 3197718 | 2022-09-30 08:51:23 -0700 | [diff] [blame] | 12611 | eventOrder.push_back(static_cast<size_t>(events[i].data.u64)); |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12612 | channels[i]->consumeMotionDown(); |
| 12613 | } |
| 12614 | } |
| 12615 | |
| 12616 | // Verify the order in which the events were received. |
| 12617 | EXPECT_EQ(3u, eventOrder.size()); |
| 12618 | EXPECT_EQ(2u, eventOrder[0]); // index 2: window |
| 12619 | EXPECT_EQ(0u, eventOrder[1]); // index 0: spy1 |
| 12620 | EXPECT_EQ(1u, eventOrder[2]); // index 1: spy2 |
| 12621 | } |
| 12622 | |
| 12623 | /** |
| 12624 | * A spy window using the NOT_TOUCHABLE flag does not receive events. |
| 12625 | */ |
| 12626 | TEST_F(InputDispatcherSpyWindowTest, NotTouchable) { |
| 12627 | auto window = createForeground(); |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 12628 | auto spy = createSpy(); |
| 12629 | spy->setTouchable(false); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 12630 | mDispatcher->onWindowInfosChanged({{*spy->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12631 | |
| 12632 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12633 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 12634 | ui::LogicalDisplayId::DEFAULT)) |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12635 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12636 | window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12637 | spy->assertNoEvents(); |
| 12638 | } |
| 12639 | |
| 12640 | /** |
| 12641 | * A spy window will only receive gestures that originate within its touchable region. Gestures that |
| 12642 | * have their ACTION_DOWN outside of the touchable region of the spy window will not be dispatched |
| 12643 | * to the window. |
| 12644 | */ |
| 12645 | TEST_F(InputDispatcherSpyWindowTest, TouchableRegion) { |
| 12646 | auto window = createForeground(); |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 12647 | auto spy = createSpy(); |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12648 | spy->setTouchableRegion(Region{{0, 0, 20, 20}}); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 12649 | mDispatcher->onWindowInfosChanged({{*spy->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12650 | |
| 12651 | // Inject an event outside the spy window's touchable region. |
| 12652 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12653 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 12654 | ui::LogicalDisplayId::DEFAULT)) |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12655 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 12656 | window->consumeMotionDown(); |
| 12657 | spy->assertNoEvents(); |
| 12658 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12659 | injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 12660 | ui::LogicalDisplayId::DEFAULT)) |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12661 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 12662 | window->consumeMotionUp(); |
| 12663 | spy->assertNoEvents(); |
| 12664 | |
| 12665 | // Inject an event inside the spy window's touchable region. |
| 12666 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12667 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 12668 | ui::LogicalDisplayId::DEFAULT, {5, 10})) |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12669 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 12670 | window->consumeMotionDown(); |
| 12671 | spy->consumeMotionDown(); |
| 12672 | } |
| 12673 | |
| 12674 | /** |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12675 | * A spy window can listen for touches outside its touchable region using the WATCH_OUTSIDE_TOUCHES |
Prabir Pradhan | dfabf8a | 2022-01-21 08:19:30 -0800 | [diff] [blame] | 12676 | * flag, but it will get zero-ed out coordinates if the foreground has a different owner. |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12677 | */ |
| 12678 | TEST_F(InputDispatcherSpyWindowTest, WatchOutsideTouches) { |
| 12679 | auto window = createForeground(); |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 12680 | window->setOwnerInfo(gui::Pid{12}, gui::Uid{34}); |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 12681 | auto spy = createSpy(); |
| 12682 | spy->setWatchOutsideTouch(true); |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 12683 | spy->setOwnerInfo(gui::Pid{56}, gui::Uid{78}); |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12684 | spy->setFrame(Rect{0, 0, 20, 20}); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 12685 | mDispatcher->onWindowInfosChanged({{*spy->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12686 | |
| 12687 | // Inject an event outside the spy window's frame and touchable region. |
| 12688 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12689 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 12690 | ui::LogicalDisplayId::DEFAULT, {100, 200})) |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12691 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 12692 | window->consumeMotionDown(); |
Prabir Pradhan | dfabf8a | 2022-01-21 08:19:30 -0800 | [diff] [blame] | 12693 | spy->consumeMotionOutsideWithZeroedCoords(); |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12694 | } |
| 12695 | |
| 12696 | /** |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12697 | * Even when a spy window spans over multiple foreground windows, the spy should receive all |
| 12698 | * pointers that are down within its bounds. |
| 12699 | */ |
| 12700 | TEST_F(InputDispatcherSpyWindowTest, ReceivesMultiplePointers) { |
| 12701 | auto windowLeft = createForeground(); |
| 12702 | windowLeft->setFrame({0, 0, 100, 200}); |
| 12703 | auto windowRight = createForeground(); |
| 12704 | windowRight->setFrame({100, 0, 200, 200}); |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 12705 | auto spy = createSpy(); |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12706 | spy->setFrame({0, 0, 200, 200}); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 12707 | mDispatcher->onWindowInfosChanged( |
| 12708 | {{*spy->getInfo(), *windowLeft->getInfo(), *windowRight->getInfo()}, {}, 0, 0}); |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12709 | |
| 12710 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12711 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 12712 | ui::LogicalDisplayId::DEFAULT, {50, 50})) |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12713 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 12714 | windowLeft->consumeMotionDown(); |
| 12715 | spy->consumeMotionDown(); |
| 12716 | |
| 12717 | const MotionEvent secondFingerDownEvent = |
Siarhei Vishniakou | a16e3a2 | 2022-03-02 15:26:40 -0800 | [diff] [blame] | 12718 | MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12719 | .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 12720 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(50).y(50)) |
| 12721 | .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(150).y(50)) |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12722 | .build(); |
| 12723 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 12724 | injectMotionEvent(*mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12725 | InputEventInjectionSync::WAIT_FOR_RESULT)) |
| 12726 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 12727 | windowRight->consumeMotionDown(); |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 12728 | spy->consumeMotionPointerDown(/*pointerIndex=*/1); |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12729 | } |
| 12730 | |
| 12731 | /** |
| 12732 | * When the first pointer lands outside the spy window and the second pointer lands inside it, the |
| 12733 | * the spy should receive the second pointer with ACTION_DOWN. |
| 12734 | */ |
| 12735 | TEST_F(InputDispatcherSpyWindowTest, ReceivesSecondPointerAsDown) { |
| 12736 | auto window = createForeground(); |
| 12737 | window->setFrame({0, 0, 200, 200}); |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 12738 | auto spyRight = createSpy(); |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12739 | spyRight->setFrame({100, 0, 200, 200}); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 12740 | mDispatcher->onWindowInfosChanged({{*spyRight->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12741 | |
| 12742 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12743 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 12744 | ui::LogicalDisplayId::DEFAULT, {50, 50})) |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12745 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 12746 | window->consumeMotionDown(); |
| 12747 | spyRight->assertNoEvents(); |
| 12748 | |
| 12749 | const MotionEvent secondFingerDownEvent = |
Siarhei Vishniakou | a16e3a2 | 2022-03-02 15:26:40 -0800 | [diff] [blame] | 12750 | MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12751 | .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 12752 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(50).y(50)) |
| 12753 | .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(150).y(50)) |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12754 | .build(); |
| 12755 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 12756 | injectMotionEvent(*mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12757 | InputEventInjectionSync::WAIT_FOR_RESULT)) |
| 12758 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 12759 | window->consumeMotionPointerDown(/*pointerIndex=*/1); |
Prabir Pradhan | 07e05b6 | 2021-11-19 03:57:24 -0800 | [diff] [blame] | 12760 | spyRight->consumeMotionDown(); |
| 12761 | } |
| 12762 | |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 12763 | /** |
| 12764 | * The spy window should not be able to affect whether or not touches are split. Only the foreground |
| 12765 | * windows should be allowed to control split touch. |
| 12766 | */ |
| 12767 | TEST_F(InputDispatcherSpyWindowTest, SplitIfNoForegroundWindowTouched) { |
Prabir Pradhan | 76bdecb | 2022-01-31 11:14:15 -0800 | [diff] [blame] | 12768 | // This spy window prevents touch splitting. However, we still expect to split touches |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 12769 | // because a foreground window has not disabled splitting. |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 12770 | auto spy = createSpy(); |
Prabir Pradhan | 76bdecb | 2022-01-31 11:14:15 -0800 | [diff] [blame] | 12771 | spy->setPreventSplitting(true); |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 12772 | |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 12773 | auto window = createForeground(); |
| 12774 | window->setFrame(Rect(0, 0, 100, 100)); |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 12775 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 12776 | mDispatcher->onWindowInfosChanged({{*spy->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 12777 | |
| 12778 | // First finger down, no window touched. |
| 12779 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12780 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 12781 | ui::LogicalDisplayId::DEFAULT, {100, 200})) |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 12782 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12783 | spy->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 12784 | window->assertNoEvents(); |
| 12785 | |
| 12786 | // Second finger down on window, the window should receive touch down. |
| 12787 | const MotionEvent secondFingerDownEvent = |
Siarhei Vishniakou | a16e3a2 | 2022-03-02 15:26:40 -0800 | [diff] [blame] | 12788 | MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12789 | .displayId(ui::LogicalDisplayId::DEFAULT) |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 12790 | .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 12791 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(200)) |
| 12792 | .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(50).y(50)) |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 12793 | .build(); |
| 12794 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 12795 | injectMotionEvent(*mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 12796 | InputEventInjectionSync::WAIT_FOR_RESULT)) |
| 12797 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 12798 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12799 | window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 12800 | spy->consumeMotionPointerDown(/*pointerIndex=*/1); |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 12801 | } |
| 12802 | |
| 12803 | /** |
| 12804 | * A spy window will usually be implemented as an un-focusable window. Verify that these windows |
| 12805 | * do not receive key events. |
| 12806 | */ |
| 12807 | TEST_F(InputDispatcherSpyWindowTest, UnfocusableSpyDoesNotReceiveKeyEvents) { |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 12808 | auto spy = createSpy(); |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 12809 | spy->setFocusable(false); |
| 12810 | |
| 12811 | auto window = createForeground(); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 12812 | mDispatcher->onWindowInfosChanged({{*spy->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 12813 | setFocusedWindow(window); |
| 12814 | window->consumeFocusEvent(true); |
| 12815 | |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 12816 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(*mDispatcher)) |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 12817 | << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12818 | window->consumeKeyDown(ui::LogicalDisplayId::INVALID); |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 12819 | |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 12820 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyUp(*mDispatcher)) |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 12821 | << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12822 | window->consumeKeyUp(ui::LogicalDisplayId::INVALID); |
Prabir Pradhan | 1376fcd | 2022-01-21 09:56:35 -0800 | [diff] [blame] | 12823 | |
| 12824 | spy->assertNoEvents(); |
| 12825 | } |
| 12826 | |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 12827 | using InputDispatcherPilferPointersTest = InputDispatcherSpyWindowTest; |
| 12828 | |
| 12829 | /** |
| 12830 | * A spy window can pilfer pointers. When this happens, touch gestures used by the spy window that |
| 12831 | * are currently sent to any other windows - including other spy windows - will also be cancelled. |
| 12832 | */ |
| 12833 | TEST_F(InputDispatcherPilferPointersTest, PilferPointers) { |
| 12834 | auto window = createForeground(); |
| 12835 | auto spy1 = createSpy(); |
| 12836 | auto spy2 = createSpy(); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 12837 | mDispatcher->onWindowInfosChanged( |
| 12838 | {{*spy1->getInfo(), *spy2->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 12839 | |
| 12840 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12841 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 12842 | ui::LogicalDisplayId::DEFAULT)) |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 12843 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 12844 | window->consumeMotionDown(); |
| 12845 | spy1->consumeMotionDown(); |
| 12846 | spy2->consumeMotionDown(); |
| 12847 | |
| 12848 | // Pilfer pointers from the second spy window. |
| 12849 | EXPECT_EQ(OK, mDispatcher->pilferPointers(spy2->getToken())); |
| 12850 | spy2->assertNoEvents(); |
| 12851 | spy1->consumeMotionCancel(); |
| 12852 | window->consumeMotionCancel(); |
| 12853 | |
| 12854 | // The rest of the gesture should only be sent to the second spy window. |
| 12855 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 12856 | injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12857 | ui::LogicalDisplayId::DEFAULT)) |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 12858 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 12859 | spy2->consumeMotionMove(); |
| 12860 | spy1->assertNoEvents(); |
| 12861 | window->assertNoEvents(); |
| 12862 | } |
| 12863 | |
| 12864 | /** |
| 12865 | * A spy window can pilfer pointers for a gesture even after the foreground window has been removed |
| 12866 | * in the middle of the gesture. |
| 12867 | */ |
| 12868 | TEST_F(InputDispatcherPilferPointersTest, CanPilferAfterWindowIsRemovedMidStream) { |
| 12869 | auto window = createForeground(); |
| 12870 | auto spy = createSpy(); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 12871 | mDispatcher->onWindowInfosChanged({{*spy->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 12872 | |
| 12873 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12874 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 12875 | ui::LogicalDisplayId::DEFAULT)) |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 12876 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12877 | window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
| 12878 | spy->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 12879 | |
| 12880 | window->releaseChannel(); |
| 12881 | |
| 12882 | EXPECT_EQ(OK, mDispatcher->pilferPointers(spy->getToken())); |
| 12883 | |
| 12884 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12885 | injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 12886 | ui::LogicalDisplayId::DEFAULT)) |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 12887 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12888 | spy->consumeMotionUp(ui::LogicalDisplayId::DEFAULT); |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 12889 | } |
| 12890 | |
| 12891 | /** |
| 12892 | * After a spy window pilfers pointers, new pointers that go down in its bounds should be sent to |
| 12893 | * the spy, but not to any other windows. |
| 12894 | */ |
| 12895 | TEST_F(InputDispatcherPilferPointersTest, ContinuesToReceiveGestureAfterPilfer) { |
| 12896 | auto spy = createSpy(); |
| 12897 | auto window = createForeground(); |
| 12898 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 12899 | mDispatcher->onWindowInfosChanged({{*spy->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 12900 | |
| 12901 | // First finger down on the window and the spy. |
| 12902 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12903 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 12904 | ui::LogicalDisplayId::DEFAULT, {100, 200})) |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 12905 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 12906 | spy->consumeMotionDown(); |
| 12907 | window->consumeMotionDown(); |
| 12908 | |
| 12909 | // Spy window pilfers the pointers. |
| 12910 | EXPECT_EQ(OK, mDispatcher->pilferPointers(spy->getToken())); |
| 12911 | window->consumeMotionCancel(); |
| 12912 | |
| 12913 | // Second finger down on the window and spy, but the window should not receive the pointer down. |
| 12914 | const MotionEvent secondFingerDownEvent = |
| 12915 | MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12916 | .displayId(ui::LogicalDisplayId::DEFAULT) |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 12917 | .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 12918 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(200)) |
| 12919 | .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(50).y(50)) |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 12920 | .build(); |
| 12921 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 12922 | injectMotionEvent(*mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 12923 | InputEventInjectionSync::WAIT_FOR_RESULT)) |
| 12924 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 12925 | |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 12926 | spy->consumeMotionPointerDown(/*pointerIndex=*/1); |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 12927 | |
| 12928 | // Third finger goes down outside all windows, so injection should fail. |
| 12929 | const MotionEvent thirdFingerDownEvent = |
| 12930 | MotionEventBuilder(POINTER_2_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12931 | .displayId(ui::LogicalDisplayId::DEFAULT) |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 12932 | .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 12933 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(200)) |
| 12934 | .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(50).y(50)) |
| 12935 | .pointer(PointerBuilder(/*id=*/2, ToolType::FINGER).x(-5).y(-5)) |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 12936 | .build(); |
| 12937 | ASSERT_EQ(InputEventInjectionResult::FAILED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 12938 | injectMotionEvent(*mDispatcher, thirdFingerDownEvent, INJECT_EVENT_TIMEOUT, |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 12939 | InputEventInjectionSync::WAIT_FOR_RESULT)) |
Siarhei Vishniakou | 1ae72f1 | 2023-01-29 12:55:30 -0800 | [diff] [blame] | 12940 | << "Inject motion event should return InputEventInjectionResult::FAILED"; |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 12941 | |
| 12942 | spy->assertNoEvents(); |
| 12943 | window->assertNoEvents(); |
| 12944 | } |
| 12945 | |
| 12946 | /** |
| 12947 | * After a spy window pilfers pointers, only the pointers used by the spy should be canceled |
| 12948 | */ |
| 12949 | TEST_F(InputDispatcherPilferPointersTest, PartiallyPilferRequiredPointers) { |
| 12950 | auto spy = createSpy(); |
| 12951 | spy->setFrame(Rect(0, 0, 100, 100)); |
| 12952 | auto window = createForeground(); |
| 12953 | window->setFrame(Rect(0, 0, 200, 200)); |
| 12954 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 12955 | mDispatcher->onWindowInfosChanged({{*spy->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 12956 | |
| 12957 | // First finger down on the window only |
| 12958 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12959 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 12960 | ui::LogicalDisplayId::DEFAULT, {150, 150})) |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 12961 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 12962 | window->consumeMotionDown(); |
| 12963 | |
| 12964 | // Second finger down on the spy and window |
| 12965 | const MotionEvent secondFingerDownEvent = |
| 12966 | MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12967 | .displayId(ui::LogicalDisplayId::DEFAULT) |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 12968 | .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 12969 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(150).y(150)) |
| 12970 | .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(10).y(10)) |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 12971 | .build(); |
| 12972 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 12973 | injectMotionEvent(*mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 12974 | InputEventInjectionSync::WAIT_FOR_RESULT)) |
| 12975 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 12976 | spy->consumeMotionDown(); |
| 12977 | window->consumeMotionPointerDown(1); |
| 12978 | |
| 12979 | // Third finger down on the spy and window |
| 12980 | const MotionEvent thirdFingerDownEvent = |
| 12981 | MotionEventBuilder(POINTER_2_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 12982 | .displayId(ui::LogicalDisplayId::DEFAULT) |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 12983 | .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 12984 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(150).y(150)) |
| 12985 | .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(10).y(10)) |
| 12986 | .pointer(PointerBuilder(/*id=*/2, ToolType::FINGER).x(50).y(50)) |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 12987 | .build(); |
| 12988 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 12989 | injectMotionEvent(*mDispatcher, thirdFingerDownEvent, INJECT_EVENT_TIMEOUT, |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 12990 | InputEventInjectionSync::WAIT_FOR_RESULT)) |
| 12991 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 12992 | spy->consumeMotionPointerDown(1); |
| 12993 | window->consumeMotionPointerDown(2); |
| 12994 | |
| 12995 | // Spy window pilfers the pointers. |
| 12996 | EXPECT_EQ(OK, mDispatcher->pilferPointers(spy->getToken())); |
Prabir Pradhan | 33cfc6d | 2024-06-11 20:17:44 +0000 | [diff] [blame] | 12997 | window->consumeMotionPointerUp(/*pointerIdx=*/2, |
| 12998 | AllOf(WithDisplayId(ui::LogicalDisplayId::DEFAULT), |
| 12999 | WithFlags(AMOTION_EVENT_FLAG_CANCELED), |
| 13000 | WithPointerCount(3))); |
| 13001 | window->consumeMotionPointerUp(/*pointerIdx=*/1, |
| 13002 | AllOf(WithDisplayId(ui::LogicalDisplayId::DEFAULT), |
| 13003 | WithFlags(AMOTION_EVENT_FLAG_CANCELED), |
| 13004 | WithPointerCount(2))); |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 13005 | |
| 13006 | spy->assertNoEvents(); |
| 13007 | window->assertNoEvents(); |
| 13008 | } |
| 13009 | |
| 13010 | /** |
| 13011 | * After a spy window pilfers pointers, all pilfered pointers that have already been dispatched to |
| 13012 | * other windows should be canceled. If this results in the cancellation of all pointers for some |
| 13013 | * window, then that window should receive ACTION_CANCEL. |
| 13014 | */ |
| 13015 | TEST_F(InputDispatcherPilferPointersTest, PilferAllRequiredPointers) { |
| 13016 | auto spy = createSpy(); |
| 13017 | spy->setFrame(Rect(0, 0, 100, 100)); |
| 13018 | auto window = createForeground(); |
| 13019 | window->setFrame(Rect(0, 0, 200, 200)); |
| 13020 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 13021 | mDispatcher->onWindowInfosChanged({{*spy->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 13022 | |
| 13023 | // First finger down on both spy and window |
| 13024 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13025 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 13026 | ui::LogicalDisplayId::DEFAULT, {10, 10})) |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 13027 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 13028 | window->consumeMotionDown(); |
| 13029 | spy->consumeMotionDown(); |
| 13030 | |
| 13031 | // Second finger down on the spy and window |
| 13032 | const MotionEvent secondFingerDownEvent = |
| 13033 | MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13034 | .displayId(ui::LogicalDisplayId::DEFAULT) |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 13035 | .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 13036 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(10).y(10)) |
| 13037 | .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(50).y(50)) |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 13038 | .build(); |
| 13039 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 13040 | injectMotionEvent(*mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 13041 | InputEventInjectionSync::WAIT_FOR_RESULT)) |
| 13042 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 13043 | spy->consumeMotionPointerDown(1); |
| 13044 | window->consumeMotionPointerDown(1); |
| 13045 | |
| 13046 | // Spy window pilfers the pointers. |
| 13047 | EXPECT_EQ(OK, mDispatcher->pilferPointers(spy->getToken())); |
| 13048 | window->consumeMotionCancel(); |
| 13049 | |
| 13050 | spy->assertNoEvents(); |
| 13051 | window->assertNoEvents(); |
| 13052 | } |
| 13053 | |
| 13054 | /** |
| 13055 | * After a spy window pilfers pointers, new pointers that are not touching the spy window can still |
| 13056 | * be sent to other windows |
| 13057 | */ |
| 13058 | TEST_F(InputDispatcherPilferPointersTest, CanReceivePointersAfterPilfer) { |
| 13059 | auto spy = createSpy(); |
| 13060 | spy->setFrame(Rect(0, 0, 100, 100)); |
| 13061 | auto window = createForeground(); |
| 13062 | window->setFrame(Rect(0, 0, 200, 200)); |
| 13063 | |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 13064 | mDispatcher->onWindowInfosChanged({{*spy->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 13065 | |
| 13066 | // First finger down on both window and spy |
| 13067 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13068 | injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, |
| 13069 | ui::LogicalDisplayId::DEFAULT, {10, 10})) |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 13070 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 13071 | window->consumeMotionDown(); |
| 13072 | spy->consumeMotionDown(); |
| 13073 | |
| 13074 | // Spy window pilfers the pointers. |
| 13075 | EXPECT_EQ(OK, mDispatcher->pilferPointers(spy->getToken())); |
| 13076 | window->consumeMotionCancel(); |
| 13077 | |
| 13078 | // Second finger down on the window only |
| 13079 | const MotionEvent secondFingerDownEvent = |
| 13080 | MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13081 | .displayId(ui::LogicalDisplayId::DEFAULT) |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 13082 | .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 13083 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(10).y(10)) |
| 13084 | .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(150).y(150)) |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 13085 | .build(); |
| 13086 | ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 13087 | injectMotionEvent(*mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 13088 | InputEventInjectionSync::WAIT_FOR_RESULT)) |
| 13089 | << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; |
| 13090 | window->consumeMotionDown(); |
| 13091 | window->assertNoEvents(); |
| 13092 | |
| 13093 | // TODO(b/232530217): do not send the unnecessary MOVE event and delete the next line |
| 13094 | spy->consumeMotionMove(); |
| 13095 | spy->assertNoEvents(); |
| 13096 | } |
| 13097 | |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 13098 | /** |
| 13099 | * A window on the left and a window on the right. Also, a spy window that's above all of the |
| 13100 | * windows, and spanning both left and right windows. |
| 13101 | * Send simultaneous motion streams from two different devices, one to the left window, and another |
| 13102 | * to the right window. |
| 13103 | * Pilfer from spy window. |
| 13104 | * Check that the pilfering only affects the pointers that are actually being received by the spy. |
| 13105 | */ |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 13106 | TEST_F(InputDispatcherPilferPointersTest, MultiDevicePilfer_legacy) { |
| 13107 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 13108 | sp<FakeWindowHandle> spy = createSpy(); |
| 13109 | spy->setFrame(Rect(0, 0, 200, 200)); |
| 13110 | sp<FakeWindowHandle> leftWindow = createForeground(); |
| 13111 | leftWindow->setFrame(Rect(0, 0, 100, 100)); |
| 13112 | |
| 13113 | sp<FakeWindowHandle> rightWindow = createForeground(); |
| 13114 | rightWindow->setFrame(Rect(100, 0, 200, 100)); |
| 13115 | |
| 13116 | constexpr int32_t stylusDeviceId = 1; |
| 13117 | constexpr int32_t touchDeviceId = 2; |
| 13118 | |
| 13119 | mDispatcher->onWindowInfosChanged( |
| 13120 | {{*spy->getInfo(), *leftWindow->getInfo(), *rightWindow->getInfo()}, {}, 0, 0}); |
| 13121 | |
| 13122 | // Stylus down on left window and spy |
| 13123 | mDispatcher->notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_STYLUS) |
| 13124 | .deviceId(stylusDeviceId) |
| 13125 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50)) |
| 13126 | .build()); |
| 13127 | leftWindow->consumeMotionEvent( |
| 13128 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(stylusDeviceId))); |
| 13129 | spy->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(stylusDeviceId))); |
| 13130 | |
| 13131 | // Finger down on right window and spy - but spy already has stylus |
| 13132 | mDispatcher->notifyMotion( |
| 13133 | MotionArgsBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 13134 | .deviceId(touchDeviceId) |
| 13135 | .pointer(PointerBuilder(0, ToolType::FINGER).x(150).y(50)) |
| 13136 | .build()); |
| 13137 | rightWindow->consumeMotionEvent( |
| 13138 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(touchDeviceId))); |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 13139 | spy->assertNoEvents(); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 13140 | |
| 13141 | // Act: pilfer from spy. Spy is currently receiving touch events. |
| 13142 | EXPECT_EQ(OK, mDispatcher->pilferPointers(spy->getToken())); |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 13143 | leftWindow->consumeMotionEvent( |
| 13144 | AllOf(WithMotionAction(ACTION_CANCEL), WithDeviceId(stylusDeviceId))); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 13145 | rightWindow->consumeMotionEvent( |
| 13146 | AllOf(WithMotionAction(ACTION_CANCEL), WithDeviceId(touchDeviceId))); |
| 13147 | |
| 13148 | // Continue movements from both stylus and touch. Touch will be delivered to spy, but not stylus |
| 13149 | mDispatcher->notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_STYLUS) |
| 13150 | .deviceId(stylusDeviceId) |
| 13151 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(51).y(52)) |
| 13152 | .build()); |
| 13153 | mDispatcher->notifyMotion( |
| 13154 | MotionArgsBuilder(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 13155 | .deviceId(touchDeviceId) |
| 13156 | .pointer(PointerBuilder(0, ToolType::FINGER).x(151).y(52)) |
| 13157 | .build()); |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 13158 | spy->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(stylusDeviceId))); |
Siarhei Vishniakou | 0b251a3 | 2023-09-20 16:24:42 -0700 | [diff] [blame] | 13159 | |
| 13160 | spy->assertNoEvents(); |
| 13161 | leftWindow->assertNoEvents(); |
| 13162 | rightWindow->assertNoEvents(); |
| 13163 | } |
| 13164 | |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 13165 | /** |
| 13166 | * A window on the left and a window on the right. Also, a spy window that's above all of the |
| 13167 | * windows, and spanning both left and right windows. |
| 13168 | * Send simultaneous motion streams from two different devices, one to the left window, and another |
| 13169 | * to the right window. |
| 13170 | * Pilfer from spy window. |
| 13171 | * Check that the pilfering affects all of the pointers that are actually being received by the spy. |
| 13172 | * The spy should receive both the touch and the stylus events after pilfer. |
| 13173 | */ |
| 13174 | TEST_F(InputDispatcherPilferPointersTest, MultiDevicePilfer) { |
| 13175 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); |
| 13176 | sp<FakeWindowHandle> spy = createSpy(); |
| 13177 | spy->setFrame(Rect(0, 0, 200, 200)); |
| 13178 | sp<FakeWindowHandle> leftWindow = createForeground(); |
| 13179 | leftWindow->setFrame(Rect(0, 0, 100, 100)); |
| 13180 | |
| 13181 | sp<FakeWindowHandle> rightWindow = createForeground(); |
| 13182 | rightWindow->setFrame(Rect(100, 0, 200, 100)); |
| 13183 | |
| 13184 | constexpr int32_t stylusDeviceId = 1; |
| 13185 | constexpr int32_t touchDeviceId = 2; |
| 13186 | |
| 13187 | mDispatcher->onWindowInfosChanged( |
| 13188 | {{*spy->getInfo(), *leftWindow->getInfo(), *rightWindow->getInfo()}, {}, 0, 0}); |
| 13189 | |
| 13190 | // Stylus down on left window and spy |
| 13191 | mDispatcher->notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_STYLUS) |
| 13192 | .deviceId(stylusDeviceId) |
| 13193 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50)) |
| 13194 | .build()); |
| 13195 | leftWindow->consumeMotionEvent( |
| 13196 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(stylusDeviceId))); |
| 13197 | spy->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(stylusDeviceId))); |
| 13198 | |
| 13199 | // Finger down on right window and spy |
| 13200 | mDispatcher->notifyMotion( |
| 13201 | MotionArgsBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 13202 | .deviceId(touchDeviceId) |
| 13203 | .pointer(PointerBuilder(0, ToolType::FINGER).x(150).y(50)) |
| 13204 | .build()); |
| 13205 | rightWindow->consumeMotionEvent( |
| 13206 | AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(touchDeviceId))); |
| 13207 | spy->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(touchDeviceId))); |
| 13208 | |
| 13209 | // Act: pilfer from spy. Spy is currently receiving touch events. |
| 13210 | EXPECT_EQ(OK, mDispatcher->pilferPointers(spy->getToken())); |
| 13211 | leftWindow->consumeMotionEvent( |
| 13212 | AllOf(WithMotionAction(ACTION_CANCEL), WithDeviceId(stylusDeviceId))); |
| 13213 | rightWindow->consumeMotionEvent( |
| 13214 | AllOf(WithMotionAction(ACTION_CANCEL), WithDeviceId(touchDeviceId))); |
| 13215 | |
| 13216 | // Continue movements from both stylus and touch. Touch and stylus will be delivered to spy |
Siarhei Vishniakou | 92bca1c | 2024-04-01 14:06:59 -0700 | [diff] [blame] | 13217 | // Instead of sending the two MOVE events for each input device together, and then receiving |
| 13218 | // them both, process them one at at time. InputConsumer is always in the batching mode, which |
| 13219 | // means that the two MOVE events will be initially put into a batch. Once the events are |
| 13220 | // batched, the 'consume' call may result in any of the MOVE events to be sent first (depending |
| 13221 | // on the implementation of InputConsumer), which would mean that the order of the received |
| 13222 | // events could be different depending on whether there are 1 or 2 events pending in the |
| 13223 | // InputChannel at the time the test calls 'consume'. To make assertions simpler here, and to |
| 13224 | // avoid this confusing behaviour, send and receive each MOVE event separately. |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 13225 | mDispatcher->notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_STYLUS) |
| 13226 | .deviceId(stylusDeviceId) |
| 13227 | .pointer(PointerBuilder(0, ToolType::STYLUS).x(51).y(52)) |
| 13228 | .build()); |
Siarhei Vishniakou | 92bca1c | 2024-04-01 14:06:59 -0700 | [diff] [blame] | 13229 | spy->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(stylusDeviceId))); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 13230 | mDispatcher->notifyMotion( |
| 13231 | MotionArgsBuilder(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) |
| 13232 | .deviceId(touchDeviceId) |
| 13233 | .pointer(PointerBuilder(0, ToolType::FINGER).x(151).y(52)) |
| 13234 | .build()); |
Siarhei Vishniakou | 92bca1c | 2024-04-01 14:06:59 -0700 | [diff] [blame] | 13235 | spy->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(touchDeviceId))); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 13236 | |
| 13237 | spy->assertNoEvents(); |
| 13238 | leftWindow->assertNoEvents(); |
| 13239 | rightWindow->assertNoEvents(); |
| 13240 | } |
| 13241 | |
Prabir Pradhan | 9cd9eb6 | 2023-11-22 17:58:06 +0000 | [diff] [blame] | 13242 | TEST_F(InputDispatcherPilferPointersTest, NoPilferingWithHoveringPointers) { |
| 13243 | auto window = createForeground(); |
| 13244 | auto spy = createSpy(); |
| 13245 | mDispatcher->onWindowInfosChanged({{*spy->getInfo(), *window->getInfo()}, {}, 0, 0}); |
| 13246 | |
| 13247 | mDispatcher->notifyMotion( |
| 13248 | MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE) |
| 13249 | .deviceId(1) |
| 13250 | .pointer(PointerBuilder(/*id=*/0, ToolType::MOUSE).x(100).y(200)) |
| 13251 | .build()); |
| 13252 | window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); |
| 13253 | spy->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); |
| 13254 | |
| 13255 | // Pilfer pointers from the spy window should fail. |
| 13256 | EXPECT_NE(OK, mDispatcher->pilferPointers(spy->getToken())); |
| 13257 | spy->assertNoEvents(); |
| 13258 | window->assertNoEvents(); |
| 13259 | } |
| 13260 | |
Prabir Pradhan | d65552b | 2021-10-07 11:23:50 -0700 | [diff] [blame] | 13261 | class InputDispatcherStylusInterceptorTest : public InputDispatcherTest { |
| 13262 | public: |
| 13263 | std::pair<sp<FakeWindowHandle>, sp<FakeWindowHandle>> setupStylusOverlayScenario() { |
| 13264 | std::shared_ptr<FakeApplicationHandle> overlayApplication = |
| 13265 | std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13266 | sp<FakeWindowHandle> overlay = sp<FakeWindowHandle>::make(overlayApplication, mDispatcher, |
| 13267 | "Stylus interceptor window", |
| 13268 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | d65552b | 2021-10-07 11:23:50 -0700 | [diff] [blame] | 13269 | overlay->setFocusable(false); |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 13270 | overlay->setOwnerInfo(gui::Pid{111}, gui::Uid{111}); |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 13271 | overlay->setTouchable(false); |
Prabir Pradhan | 51e7db0 | 2022-02-07 06:02:57 -0800 | [diff] [blame] | 13272 | overlay->setInterceptsStylus(true); |
Prabir Pradhan | d65552b | 2021-10-07 11:23:50 -0700 | [diff] [blame] | 13273 | overlay->setTrustedOverlay(true); |
| 13274 | |
| 13275 | std::shared_ptr<FakeApplicationHandle> application = |
| 13276 | std::make_shared<FakeApplicationHandle>(); |
| 13277 | sp<FakeWindowHandle> window = |
Siarhei Vishniakou | aed7ad0 | 2022-08-03 15:04:33 -0700 | [diff] [blame] | 13278 | sp<FakeWindowHandle>::make(application, mDispatcher, "Application window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13279 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | d65552b | 2021-10-07 11:23:50 -0700 | [diff] [blame] | 13280 | window->setFocusable(true); |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 13281 | window->setOwnerInfo(gui::Pid{222}, gui::Uid{222}); |
Prabir Pradhan | d65552b | 2021-10-07 11:23:50 -0700 | [diff] [blame] | 13282 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13283 | mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 13284 | mDispatcher->onWindowInfosChanged({{*overlay->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Prabir Pradhan | d65552b | 2021-10-07 11:23:50 -0700 | [diff] [blame] | 13285 | setFocusedWindow(window); |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 13286 | window->consumeFocusEvent(/*hasFocus=*/true, /*inTouchMode=*/true); |
Prabir Pradhan | d65552b | 2021-10-07 11:23:50 -0700 | [diff] [blame] | 13287 | return {std::move(overlay), std::move(window)}; |
| 13288 | } |
| 13289 | |
| 13290 | void sendFingerEvent(int32_t action) { |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 13291 | mDispatcher->notifyMotion( |
Prabir Pradhan | d65552b | 2021-10-07 11:23:50 -0700 | [diff] [blame] | 13292 | generateMotionArgs(action, AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13293 | ui::LogicalDisplayId::DEFAULT, {PointF{20, 20}})); |
Prabir Pradhan | d65552b | 2021-10-07 11:23:50 -0700 | [diff] [blame] | 13294 | } |
| 13295 | |
| 13296 | void sendStylusEvent(int32_t action) { |
| 13297 | NotifyMotionArgs motionArgs = |
| 13298 | generateMotionArgs(action, AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13299 | ui::LogicalDisplayId::DEFAULT, {PointF{30, 40}}); |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 13300 | motionArgs.pointerProperties[0].toolType = ToolType::STYLUS; |
Prabir Pradhan | 678438e | 2023-04-13 19:32:51 +0000 | [diff] [blame] | 13301 | mDispatcher->notifyMotion(motionArgs); |
Prabir Pradhan | d65552b | 2021-10-07 11:23:50 -0700 | [diff] [blame] | 13302 | } |
| 13303 | }; |
| 13304 | |
Prabir Pradhan | a3ab87a | 2022-01-27 10:00:21 -0800 | [diff] [blame] | 13305 | using InputDispatcherStylusInterceptorDeathTest = InputDispatcherStylusInterceptorTest; |
| 13306 | |
| 13307 | TEST_F(InputDispatcherStylusInterceptorDeathTest, UntrustedOverlay_AbortsDispatcher) { |
Siarhei Vishniakou | ad3b682 | 2023-06-22 14:17:35 -0700 | [diff] [blame] | 13308 | testing::GTEST_FLAG(death_test_style) = "threadsafe"; |
Prabir Pradhan | a3ab87a | 2022-01-27 10:00:21 -0800 | [diff] [blame] | 13309 | ScopedSilentDeath _silentDeath; |
| 13310 | |
Prabir Pradhan | d65552b | 2021-10-07 11:23:50 -0700 | [diff] [blame] | 13311 | auto [overlay, window] = setupStylusOverlayScenario(); |
| 13312 | overlay->setTrustedOverlay(false); |
| 13313 | // Configuring an untrusted overlay as a stylus interceptor should cause Dispatcher to abort. |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 13314 | ASSERT_DEATH(mDispatcher->onWindowInfosChanged( |
| 13315 | {{*overlay->getInfo(), *window->getInfo()}, {}, 0, 0}), |
Prabir Pradhan | d65552b | 2021-10-07 11:23:50 -0700 | [diff] [blame] | 13316 | ".* not a trusted overlay"); |
| 13317 | } |
| 13318 | |
| 13319 | TEST_F(InputDispatcherStylusInterceptorTest, ConsmesOnlyStylusEvents) { |
| 13320 | auto [overlay, window] = setupStylusOverlayScenario(); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 13321 | mDispatcher->onWindowInfosChanged({{*overlay->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Prabir Pradhan | d65552b | 2021-10-07 11:23:50 -0700 | [diff] [blame] | 13322 | |
| 13323 | sendStylusEvent(AMOTION_EVENT_ACTION_DOWN); |
| 13324 | overlay->consumeMotionDown(); |
| 13325 | sendStylusEvent(AMOTION_EVENT_ACTION_UP); |
| 13326 | overlay->consumeMotionUp(); |
| 13327 | |
| 13328 | sendFingerEvent(AMOTION_EVENT_ACTION_DOWN); |
| 13329 | window->consumeMotionDown(); |
| 13330 | sendFingerEvent(AMOTION_EVENT_ACTION_UP); |
| 13331 | window->consumeMotionUp(); |
| 13332 | |
| 13333 | overlay->assertNoEvents(); |
| 13334 | window->assertNoEvents(); |
| 13335 | } |
| 13336 | |
| 13337 | TEST_F(InputDispatcherStylusInterceptorTest, SpyWindowStylusInterceptor) { |
| 13338 | auto [overlay, window] = setupStylusOverlayScenario(); |
Prabir Pradhan | 51e7db0 | 2022-02-07 06:02:57 -0800 | [diff] [blame] | 13339 | overlay->setSpy(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 13340 | mDispatcher->onWindowInfosChanged({{*overlay->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Prabir Pradhan | d65552b | 2021-10-07 11:23:50 -0700 | [diff] [blame] | 13341 | |
| 13342 | sendStylusEvent(AMOTION_EVENT_ACTION_DOWN); |
| 13343 | overlay->consumeMotionDown(); |
| 13344 | window->consumeMotionDown(); |
| 13345 | sendStylusEvent(AMOTION_EVENT_ACTION_UP); |
| 13346 | overlay->consumeMotionUp(); |
| 13347 | window->consumeMotionUp(); |
| 13348 | |
| 13349 | sendFingerEvent(AMOTION_EVENT_ACTION_DOWN); |
| 13350 | window->consumeMotionDown(); |
| 13351 | sendFingerEvent(AMOTION_EVENT_ACTION_UP); |
| 13352 | window->consumeMotionUp(); |
| 13353 | |
| 13354 | overlay->assertNoEvents(); |
| 13355 | window->assertNoEvents(); |
| 13356 | } |
| 13357 | |
Prabir Pradhan | 6dfbf26 | 2022-03-14 15:24:30 +0000 | [diff] [blame] | 13358 | /** |
| 13359 | * Set up a scenario to test the behavior used by the stylus handwriting detection feature. |
| 13360 | * The scenario is as follows: |
| 13361 | * - The stylus interceptor overlay is configured as a spy window. |
| 13362 | * - The stylus interceptor spy receives the start of a new stylus gesture. |
| 13363 | * - It pilfers pointers and then configures itself to no longer be a spy. |
| 13364 | * - The stylus interceptor continues to receive the rest of the gesture. |
| 13365 | */ |
| 13366 | TEST_F(InputDispatcherStylusInterceptorTest, StylusHandwritingScenario) { |
| 13367 | auto [overlay, window] = setupStylusOverlayScenario(); |
| 13368 | overlay->setSpy(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 13369 | mDispatcher->onWindowInfosChanged({{*overlay->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Prabir Pradhan | 6dfbf26 | 2022-03-14 15:24:30 +0000 | [diff] [blame] | 13370 | |
| 13371 | sendStylusEvent(AMOTION_EVENT_ACTION_DOWN); |
| 13372 | overlay->consumeMotionDown(); |
| 13373 | window->consumeMotionDown(); |
| 13374 | |
| 13375 | // The interceptor pilfers the pointers. |
| 13376 | EXPECT_EQ(OK, mDispatcher->pilferPointers(overlay->getToken())); |
| 13377 | window->consumeMotionCancel(); |
| 13378 | |
| 13379 | // The interceptor configures itself so that it is no longer a spy. |
| 13380 | overlay->setSpy(false); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 13381 | mDispatcher->onWindowInfosChanged({{*overlay->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Prabir Pradhan | 6dfbf26 | 2022-03-14 15:24:30 +0000 | [diff] [blame] | 13382 | |
| 13383 | // It continues to receive the rest of the stylus gesture. |
| 13384 | sendStylusEvent(AMOTION_EVENT_ACTION_MOVE); |
| 13385 | overlay->consumeMotionMove(); |
| 13386 | sendStylusEvent(AMOTION_EVENT_ACTION_UP); |
| 13387 | overlay->consumeMotionUp(); |
| 13388 | |
| 13389 | window->assertNoEvents(); |
| 13390 | } |
| 13391 | |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 13392 | struct User { |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 13393 | gui::Pid mPid; |
Prabir Pradhan | 8a5c41d | 2023-06-08 19:13:46 +0000 | [diff] [blame] | 13394 | gui::Uid mUid; |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 13395 | uint32_t mPolicyFlags{DEFAULT_POLICY_FLAGS}; |
| 13396 | std::unique_ptr<InputDispatcher>& mDispatcher; |
| 13397 | |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 13398 | User(std::unique_ptr<InputDispatcher>& dispatcher, gui::Pid pid, gui::Uid uid) |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 13399 | : mPid(pid), mUid(uid), mDispatcher(dispatcher) {} |
| 13400 | |
| 13401 | InputEventInjectionResult injectTargetedMotion(int32_t action) const { |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 13402 | return injectMotionEvent(*mDispatcher, action, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13403 | ui::LogicalDisplayId::DEFAULT, {100, 200}, |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 13404 | {AMOTION_EVENT_INVALID_CURSOR_POSITION, |
| 13405 | AMOTION_EVENT_INVALID_CURSOR_POSITION}, |
| 13406 | INJECT_EVENT_TIMEOUT, InputEventInjectionSync::WAIT_FOR_RESULT, |
| 13407 | systemTime(SYSTEM_TIME_MONOTONIC), {mUid}, mPolicyFlags); |
| 13408 | } |
| 13409 | |
| 13410 | InputEventInjectionResult injectTargetedKey(int32_t action) const { |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 13411 | return inputdispatcher::injectKey(*mDispatcher, action, /*repeatCount=*/0, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13412 | ui::LogicalDisplayId::INVALID, |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 13413 | InputEventInjectionSync::WAIT_FOR_RESULT, |
Harry Cutts | 3347623 | 2023-01-30 19:57:29 +0000 | [diff] [blame] | 13414 | INJECT_EVENT_TIMEOUT, /*allowKeyRepeat=*/false, {mUid}, |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 13415 | mPolicyFlags); |
| 13416 | } |
| 13417 | |
Siarhei Vishniakou | e3ce412 | 2023-08-23 10:26:46 -0700 | [diff] [blame] | 13418 | sp<FakeWindowHandle> createWindow(const char* name) const { |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 13419 | std::shared_ptr<FakeApplicationHandle> overlayApplication = |
| 13420 | std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13421 | sp<FakeWindowHandle> window = |
| 13422 | sp<FakeWindowHandle>::make(overlayApplication, mDispatcher, name, |
| 13423 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 13424 | window->setOwnerInfo(mPid, mUid); |
| 13425 | return window; |
| 13426 | } |
| 13427 | }; |
| 13428 | |
| 13429 | using InputDispatcherTargetedInjectionTest = InputDispatcherTest; |
| 13430 | |
| 13431 | TEST_F(InputDispatcherTargetedInjectionTest, CanInjectIntoOwnedWindow) { |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 13432 | auto owner = User(mDispatcher, gui::Pid{10}, gui::Uid{11}); |
Siarhei Vishniakou | e3ce412 | 2023-08-23 10:26:46 -0700 | [diff] [blame] | 13433 | auto window = owner.createWindow("Owned window"); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 13434 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 13435 | |
| 13436 | EXPECT_EQ(InputEventInjectionResult::SUCCEEDED, |
| 13437 | owner.injectTargetedMotion(AMOTION_EVENT_ACTION_DOWN)); |
| 13438 | window->consumeMotionDown(); |
| 13439 | |
| 13440 | setFocusedWindow(window); |
| 13441 | window->consumeFocusEvent(true); |
| 13442 | |
| 13443 | EXPECT_EQ(InputEventInjectionResult::SUCCEEDED, |
| 13444 | owner.injectTargetedKey(AKEY_EVENT_ACTION_DOWN)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13445 | window->consumeKeyDown(ui::LogicalDisplayId::INVALID); |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 13446 | } |
| 13447 | |
| 13448 | TEST_F(InputDispatcherTargetedInjectionTest, CannotInjectIntoUnownedWindow) { |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 13449 | auto owner = User(mDispatcher, gui::Pid{10}, gui::Uid{11}); |
Siarhei Vishniakou | e3ce412 | 2023-08-23 10:26:46 -0700 | [diff] [blame] | 13450 | auto window = owner.createWindow("Owned window"); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 13451 | mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 13452 | |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 13453 | auto rando = User(mDispatcher, gui::Pid{20}, gui::Uid{21}); |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 13454 | EXPECT_EQ(InputEventInjectionResult::TARGET_MISMATCH, |
| 13455 | rando.injectTargetedMotion(AMOTION_EVENT_ACTION_DOWN)); |
| 13456 | |
| 13457 | setFocusedWindow(window); |
| 13458 | window->consumeFocusEvent(true); |
| 13459 | |
| 13460 | EXPECT_EQ(InputEventInjectionResult::TARGET_MISMATCH, |
| 13461 | rando.injectTargetedKey(AKEY_EVENT_ACTION_DOWN)); |
| 13462 | window->assertNoEvents(); |
| 13463 | } |
| 13464 | |
| 13465 | TEST_F(InputDispatcherTargetedInjectionTest, CanInjectIntoOwnedSpyWindow) { |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 13466 | auto owner = User(mDispatcher, gui::Pid{10}, gui::Uid{11}); |
Siarhei Vishniakou | e3ce412 | 2023-08-23 10:26:46 -0700 | [diff] [blame] | 13467 | auto window = owner.createWindow("Owned window"); |
| 13468 | auto spy = owner.createWindow("Owned spy"); |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 13469 | spy->setSpy(true); |
| 13470 | spy->setTrustedOverlay(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 13471 | mDispatcher->onWindowInfosChanged({{*spy->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 13472 | |
| 13473 | EXPECT_EQ(InputEventInjectionResult::SUCCEEDED, |
| 13474 | owner.injectTargetedMotion(AMOTION_EVENT_ACTION_DOWN)); |
| 13475 | spy->consumeMotionDown(); |
| 13476 | window->consumeMotionDown(); |
| 13477 | } |
| 13478 | |
| 13479 | TEST_F(InputDispatcherTargetedInjectionTest, CannotInjectIntoUnownedSpyWindow) { |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 13480 | auto owner = User(mDispatcher, gui::Pid{10}, gui::Uid{11}); |
Siarhei Vishniakou | e3ce412 | 2023-08-23 10:26:46 -0700 | [diff] [blame] | 13481 | auto window = owner.createWindow("Owned window"); |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 13482 | |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 13483 | auto rando = User(mDispatcher, gui::Pid{20}, gui::Uid{21}); |
Siarhei Vishniakou | e3ce412 | 2023-08-23 10:26:46 -0700 | [diff] [blame] | 13484 | auto randosSpy = rando.createWindow("Rando's spy"); |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 13485 | randosSpy->setSpy(true); |
| 13486 | randosSpy->setTrustedOverlay(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 13487 | mDispatcher->onWindowInfosChanged({{*randosSpy->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 13488 | |
| 13489 | // The event is targeted at owner's window, so injection should succeed, but the spy should |
| 13490 | // not receive the event. |
| 13491 | EXPECT_EQ(InputEventInjectionResult::SUCCEEDED, |
| 13492 | owner.injectTargetedMotion(AMOTION_EVENT_ACTION_DOWN)); |
| 13493 | randosSpy->assertNoEvents(); |
| 13494 | window->consumeMotionDown(); |
| 13495 | } |
| 13496 | |
| 13497 | TEST_F(InputDispatcherTargetedInjectionTest, CanInjectIntoAnyWindowWhenNotTargeting) { |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 13498 | auto owner = User(mDispatcher, gui::Pid{10}, gui::Uid{11}); |
Siarhei Vishniakou | e3ce412 | 2023-08-23 10:26:46 -0700 | [diff] [blame] | 13499 | auto window = owner.createWindow("Owned window"); |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 13500 | |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 13501 | auto rando = User(mDispatcher, gui::Pid{20}, gui::Uid{21}); |
Siarhei Vishniakou | e3ce412 | 2023-08-23 10:26:46 -0700 | [diff] [blame] | 13502 | auto randosSpy = rando.createWindow("Rando's spy"); |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 13503 | randosSpy->setSpy(true); |
| 13504 | randosSpy->setTrustedOverlay(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 13505 | mDispatcher->onWindowInfosChanged({{*randosSpy->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 13506 | |
| 13507 | // A user that has injection permission can inject into any window. |
| 13508 | EXPECT_EQ(InputEventInjectionResult::SUCCEEDED, |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 13509 | injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13510 | ui::LogicalDisplayId::DEFAULT)); |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 13511 | randosSpy->consumeMotionDown(); |
| 13512 | window->consumeMotionDown(); |
| 13513 | |
| 13514 | setFocusedWindow(randosSpy); |
| 13515 | randosSpy->consumeFocusEvent(true); |
| 13516 | |
Siarhei Vishniakou | b237f9e | 2023-07-21 16:42:23 -0700 | [diff] [blame] | 13517 | EXPECT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(*mDispatcher)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13518 | randosSpy->consumeKeyDown(ui::LogicalDisplayId::INVALID); |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 13519 | window->assertNoEvents(); |
| 13520 | } |
| 13521 | |
Siarhei Vishniakou | 580fb3a | 2023-05-05 15:02:20 -0700 | [diff] [blame] | 13522 | TEST_F(InputDispatcherTargetedInjectionTest, CannotGenerateActionOutsideToOtherUids) { |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 13523 | auto owner = User(mDispatcher, gui::Pid{10}, gui::Uid{11}); |
Siarhei Vishniakou | e3ce412 | 2023-08-23 10:26:46 -0700 | [diff] [blame] | 13524 | auto window = owner.createWindow("Owned window"); |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 13525 | |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 13526 | auto rando = User(mDispatcher, gui::Pid{20}, gui::Uid{21}); |
Siarhei Vishniakou | e3ce412 | 2023-08-23 10:26:46 -0700 | [diff] [blame] | 13527 | auto randosWindow = rando.createWindow("Rando's window"); |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 13528 | randosWindow->setFrame(Rect{-10, -10, -5, -5}); |
| 13529 | randosWindow->setWatchOutsideTouch(true); |
Siarhei Vishniakou | c41de37 | 2023-07-20 13:14:26 -0700 | [diff] [blame] | 13530 | mDispatcher->onWindowInfosChanged({{*randosWindow->getInfo(), *window->getInfo()}, {}, 0, 0}); |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 13531 | |
Siarhei Vishniakou | 580fb3a | 2023-05-05 15:02:20 -0700 | [diff] [blame] | 13532 | // Do not allow generation of ACTION_OUTSIDE events into windows owned by different uids. |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 13533 | EXPECT_EQ(InputEventInjectionResult::SUCCEEDED, |
| 13534 | owner.injectTargetedMotion(AMOTION_EVENT_ACTION_DOWN)); |
| 13535 | window->consumeMotionDown(); |
Siarhei Vishniakou | 580fb3a | 2023-05-05 15:02:20 -0700 | [diff] [blame] | 13536 | randosWindow->assertNoEvents(); |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 13537 | } |
| 13538 | |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13539 | using InputDispatcherPointerInWindowTest = InputDispatcherTest; |
| 13540 | |
| 13541 | TEST_F(InputDispatcherPointerInWindowTest, PointerInWindowWhenHovering) { |
| 13542 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 13543 | |
| 13544 | sp<FakeWindowHandle> left = sp<FakeWindowHandle>::make(application, mDispatcher, "Left Window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13545 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13546 | left->setFrame(Rect(0, 0, 100, 100)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13547 | sp<FakeWindowHandle> right = |
| 13548 | sp<FakeWindowHandle>::make(application, mDispatcher, "Right Window", |
| 13549 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13550 | right->setFrame(Rect(100, 0, 200, 100)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13551 | sp<FakeWindowHandle> spy = sp<FakeWindowHandle>::make(application, mDispatcher, "Spy Window", |
| 13552 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13553 | spy->setFrame(Rect(0, 0, 200, 100)); |
| 13554 | spy->setTrustedOverlay(true); |
| 13555 | spy->setSpy(true); |
| 13556 | |
| 13557 | mDispatcher->onWindowInfosChanged( |
| 13558 | {{*spy->getInfo(), *left->getInfo(), *right->getInfo()}, {}, 0, 0}); |
| 13559 | |
| 13560 | // Hover into the left window. |
| 13561 | mDispatcher->notifyMotion( |
| 13562 | MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS) |
| 13563 | .pointer(PointerBuilder(/*id=*/0, ToolType::STYLUS).x(50).y(50)) |
| 13564 | .build()); |
| 13565 | |
| 13566 | left->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); |
| 13567 | spy->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); |
| 13568 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13569 | ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13570 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13571 | /*pointerId=*/0)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13572 | ASSERT_TRUE(mDispatcher->isPointerInWindow(spy->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13573 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13574 | /*pointerId=*/0)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13575 | ASSERT_FALSE(mDispatcher->isPointerInWindow(right->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13576 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13577 | /*pointerId=*/0)); |
| 13578 | |
| 13579 | // Hover move to the right window. |
| 13580 | mDispatcher->notifyMotion( |
| 13581 | MotionArgsBuilder(ACTION_HOVER_MOVE, AINPUT_SOURCE_STYLUS) |
| 13582 | .pointer(PointerBuilder(/*id=*/0, ToolType::STYLUS).x(150).y(50)) |
| 13583 | .build()); |
| 13584 | |
| 13585 | left->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); |
| 13586 | right->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); |
| 13587 | spy->consumeMotionEvent(WithMotionAction(ACTION_HOVER_MOVE)); |
| 13588 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13589 | ASSERT_FALSE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13590 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13591 | /*pointerId=*/0)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13592 | ASSERT_TRUE(mDispatcher->isPointerInWindow(spy->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13593 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13594 | /*pointerId=*/0)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13595 | ASSERT_TRUE(mDispatcher->isPointerInWindow(right->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13596 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13597 | /*pointerId=*/0)); |
| 13598 | |
| 13599 | // Stop hovering. |
| 13600 | mDispatcher->notifyMotion( |
| 13601 | MotionArgsBuilder(ACTION_HOVER_EXIT, AINPUT_SOURCE_STYLUS) |
| 13602 | .pointer(PointerBuilder(/*id=*/0, ToolType::STYLUS).x(150).y(50)) |
| 13603 | .build()); |
| 13604 | |
| 13605 | right->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); |
| 13606 | spy->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); |
| 13607 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13608 | ASSERT_FALSE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13609 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13610 | /*pointerId=*/0)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13611 | ASSERT_FALSE(mDispatcher->isPointerInWindow(spy->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13612 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13613 | /*pointerId=*/0)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13614 | ASSERT_FALSE(mDispatcher->isPointerInWindow(right->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13615 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13616 | /*pointerId=*/0)); |
| 13617 | } |
| 13618 | |
| 13619 | TEST_F(InputDispatcherPointerInWindowTest, PointerInWindowWithSplitTouch) { |
| 13620 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 13621 | |
| 13622 | sp<FakeWindowHandle> left = sp<FakeWindowHandle>::make(application, mDispatcher, "Left Window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13623 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13624 | left->setFrame(Rect(0, 0, 100, 100)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13625 | sp<FakeWindowHandle> right = |
| 13626 | sp<FakeWindowHandle>::make(application, mDispatcher, "Right Window", |
| 13627 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13628 | right->setFrame(Rect(100, 0, 200, 100)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13629 | sp<FakeWindowHandle> spy = sp<FakeWindowHandle>::make(application, mDispatcher, "Spy Window", |
| 13630 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13631 | spy->setFrame(Rect(0, 0, 200, 100)); |
| 13632 | spy->setTrustedOverlay(true); |
| 13633 | spy->setSpy(true); |
| 13634 | |
| 13635 | mDispatcher->onWindowInfosChanged( |
| 13636 | {{*spy->getInfo(), *left->getInfo(), *right->getInfo()}, {}, 0, 0}); |
| 13637 | |
| 13638 | // First pointer down on left window. |
| 13639 | mDispatcher->notifyMotion( |
| 13640 | MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 13641 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(50).y(50)) |
| 13642 | .build()); |
| 13643 | |
| 13644 | left->consumeMotionDown(); |
| 13645 | spy->consumeMotionDown(); |
| 13646 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13647 | ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13648 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13649 | /*pointerId=*/0)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13650 | ASSERT_TRUE(mDispatcher->isPointerInWindow(spy->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13651 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13652 | /*pointerId=*/0)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13653 | ASSERT_FALSE(mDispatcher->isPointerInWindow(right->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13654 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13655 | /*pointerId=*/0)); |
| 13656 | |
| 13657 | // Second pointer down on right window. |
| 13658 | mDispatcher->notifyMotion( |
| 13659 | MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) |
| 13660 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(50).y(50)) |
| 13661 | .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(150).y(50)) |
| 13662 | .build()); |
| 13663 | |
| 13664 | left->consumeMotionMove(); |
| 13665 | right->consumeMotionDown(); |
| 13666 | spy->consumeMotionEvent(WithMotionAction(POINTER_1_DOWN)); |
| 13667 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13668 | ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13669 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13670 | /*pointerId=*/0)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13671 | ASSERT_TRUE(mDispatcher->isPointerInWindow(spy->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13672 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13673 | /*pointerId=*/0)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13674 | ASSERT_FALSE(mDispatcher->isPointerInWindow(right->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13675 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13676 | /*pointerId=*/0)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13677 | ASSERT_FALSE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13678 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13679 | /*pointerId=*/1)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13680 | ASSERT_TRUE(mDispatcher->isPointerInWindow(spy->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13681 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13682 | /*pointerId=*/1)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13683 | ASSERT_TRUE(mDispatcher->isPointerInWindow(right->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13684 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13685 | /*pointerId=*/1)); |
| 13686 | |
| 13687 | // Second pointer up. |
| 13688 | mDispatcher->notifyMotion( |
| 13689 | MotionArgsBuilder(POINTER_1_UP, AINPUT_SOURCE_TOUCHSCREEN) |
| 13690 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(50).y(50)) |
| 13691 | .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(150).y(50)) |
| 13692 | .build()); |
| 13693 | |
| 13694 | left->consumeMotionMove(); |
| 13695 | right->consumeMotionUp(); |
| 13696 | spy->consumeMotionEvent(WithMotionAction(POINTER_1_UP)); |
| 13697 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13698 | ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13699 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13700 | /*pointerId=*/0)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13701 | ASSERT_TRUE(mDispatcher->isPointerInWindow(spy->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13702 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13703 | /*pointerId=*/0)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13704 | ASSERT_FALSE(mDispatcher->isPointerInWindow(right->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13705 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13706 | /*pointerId=*/0)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13707 | ASSERT_FALSE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13708 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13709 | /*pointerId=*/1)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13710 | ASSERT_FALSE(mDispatcher->isPointerInWindow(spy->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13711 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13712 | /*pointerId=*/1)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13713 | ASSERT_FALSE(mDispatcher->isPointerInWindow(right->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13714 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13715 | /*pointerId=*/1)); |
| 13716 | |
| 13717 | // First pointer up. |
| 13718 | mDispatcher->notifyMotion( |
| 13719 | MotionArgsBuilder(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN) |
| 13720 | .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(50).y(50)) |
| 13721 | .build()); |
| 13722 | |
| 13723 | left->consumeMotionUp(); |
| 13724 | spy->consumeMotionUp(); |
| 13725 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13726 | ASSERT_FALSE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13727 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13728 | /*pointerId=*/0)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13729 | ASSERT_FALSE(mDispatcher->isPointerInWindow(spy->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13730 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13731 | /*pointerId=*/0)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13732 | ASSERT_FALSE(mDispatcher->isPointerInWindow(right->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13733 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13734 | /*pointerId=*/0)); |
| 13735 | } |
| 13736 | |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 13737 | TEST_F(InputDispatcherPointerInWindowTest, MultipleDevicesControllingOneMouse_legacy) { |
| 13738 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13739 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 13740 | |
| 13741 | sp<FakeWindowHandle> left = sp<FakeWindowHandle>::make(application, mDispatcher, "Left Window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13742 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13743 | left->setFrame(Rect(0, 0, 100, 100)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13744 | sp<FakeWindowHandle> right = |
| 13745 | sp<FakeWindowHandle>::make(application, mDispatcher, "Right Window", |
| 13746 | ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13747 | right->setFrame(Rect(100, 0, 200, 100)); |
| 13748 | |
| 13749 | mDispatcher->onWindowInfosChanged({{*left->getInfo(), *right->getInfo()}, {}, 0, 0}); |
| 13750 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13751 | ASSERT_FALSE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13752 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13753 | /*pointerId=*/0)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13754 | ASSERT_FALSE(mDispatcher->isPointerInWindow(right->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13755 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13756 | /*pointerId=*/0)); |
| 13757 | |
| 13758 | // Hover move into the window. |
| 13759 | mDispatcher->notifyMotion( |
| 13760 | MotionArgsBuilder(ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) |
| 13761 | .pointer(PointerBuilder(/*id=*/0, ToolType::MOUSE).x(50).y(50)) |
| 13762 | .rawXCursorPosition(50) |
| 13763 | .rawYCursorPosition(50) |
| 13764 | .deviceId(DEVICE_ID) |
| 13765 | .build()); |
| 13766 | |
| 13767 | left->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); |
| 13768 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13769 | ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13770 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13771 | /*pointerId=*/0)); |
| 13772 | |
| 13773 | // Move the mouse with another device. This cancels the hovering pointer from the first device. |
| 13774 | mDispatcher->notifyMotion( |
| 13775 | MotionArgsBuilder(ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) |
| 13776 | .pointer(PointerBuilder(/*id=*/0, ToolType::MOUSE).x(51).y(50)) |
| 13777 | .rawXCursorPosition(51) |
| 13778 | .rawYCursorPosition(50) |
| 13779 | .deviceId(SECOND_DEVICE_ID) |
| 13780 | .build()); |
| 13781 | |
| 13782 | left->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); |
| 13783 | left->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); |
| 13784 | |
| 13785 | // TODO(b/313689709): InputDispatcher's touch state is not updated, even though the window gets |
| 13786 | // a HOVER_EXIT from the first device. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13787 | ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13788 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13789 | /*pointerId=*/0)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13790 | ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13791 | SECOND_DEVICE_ID, |
| 13792 | /*pointerId=*/0)); |
| 13793 | |
| 13794 | // Move the mouse outside the window. Document the current behavior, where the window does not |
| 13795 | // receive HOVER_EXIT even though the mouse left the window. |
| 13796 | mDispatcher->notifyMotion( |
| 13797 | MotionArgsBuilder(ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) |
| 13798 | .pointer(PointerBuilder(/*id=*/0, ToolType::MOUSE).x(150).y(50)) |
| 13799 | .rawXCursorPosition(150) |
| 13800 | .rawYCursorPosition(50) |
| 13801 | .deviceId(SECOND_DEVICE_ID) |
| 13802 | .build()); |
| 13803 | |
| 13804 | left->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); |
| 13805 | right->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13806 | ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13807 | DEVICE_ID, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13808 | /*pointerId=*/0)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13809 | ASSERT_FALSE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 13810 | SECOND_DEVICE_ID, |
| 13811 | /*pointerId=*/0)); |
| 13812 | } |
| 13813 | |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 13814 | /** |
| 13815 | * TODO(b/313689709) - correctly support multiple mouse devices, because they should be controlling |
| 13816 | * the same cursor, and therefore have a shared motion event stream. |
| 13817 | */ |
| 13818 | TEST_F(InputDispatcherPointerInWindowTest, MultipleDevicesControllingOneMouse) { |
| 13819 | SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); |
| 13820 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
| 13821 | |
| 13822 | sp<FakeWindowHandle> left = sp<FakeWindowHandle>::make(application, mDispatcher, "Left Window", |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13823 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 13824 | left->setFrame(Rect(0, 0, 100, 100)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13825 | sp<FakeWindowHandle> right = |
| 13826 | sp<FakeWindowHandle>::make(application, mDispatcher, "Right Window", |
| 13827 | ui::LogicalDisplayId::DEFAULT); |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 13828 | right->setFrame(Rect(100, 0, 200, 100)); |
| 13829 | |
| 13830 | mDispatcher->onWindowInfosChanged({{*left->getInfo(), *right->getInfo()}, {}, 0, 0}); |
| 13831 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13832 | ASSERT_FALSE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13833 | DEVICE_ID, |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 13834 | /*pointerId=*/0)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13835 | ASSERT_FALSE(mDispatcher->isPointerInWindow(right->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13836 | DEVICE_ID, |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 13837 | /*pointerId=*/0)); |
| 13838 | |
| 13839 | // Hover move into the window. |
| 13840 | mDispatcher->notifyMotion( |
| 13841 | MotionArgsBuilder(ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) |
| 13842 | .pointer(PointerBuilder(/*id=*/0, ToolType::MOUSE).x(50).y(50)) |
| 13843 | .rawXCursorPosition(50) |
| 13844 | .rawYCursorPosition(50) |
| 13845 | .deviceId(DEVICE_ID) |
| 13846 | .build()); |
| 13847 | |
| 13848 | left->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); |
| 13849 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13850 | ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13851 | DEVICE_ID, |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 13852 | /*pointerId=*/0)); |
| 13853 | |
| 13854 | // Move the mouse with another device |
| 13855 | mDispatcher->notifyMotion( |
| 13856 | MotionArgsBuilder(ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) |
| 13857 | .pointer(PointerBuilder(/*id=*/0, ToolType::MOUSE).x(51).y(50)) |
| 13858 | .rawXCursorPosition(51) |
| 13859 | .rawYCursorPosition(50) |
| 13860 | .deviceId(SECOND_DEVICE_ID) |
| 13861 | .build()); |
| 13862 | left->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); |
| 13863 | |
| 13864 | // TODO(b/313689709): InputDispatcher's touch state is not updated, even though the window gets |
| 13865 | // a HOVER_EXIT from the first device. |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13866 | ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13867 | DEVICE_ID, |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 13868 | /*pointerId=*/0)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13869 | ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 13870 | SECOND_DEVICE_ID, |
| 13871 | /*pointerId=*/0)); |
| 13872 | |
| 13873 | // Move the mouse outside the window. Document the current behavior, where the window does not |
| 13874 | // receive HOVER_EXIT even though the mouse left the window. |
| 13875 | mDispatcher->notifyMotion( |
| 13876 | MotionArgsBuilder(ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) |
| 13877 | .pointer(PointerBuilder(/*id=*/0, ToolType::MOUSE).x(150).y(50)) |
| 13878 | .rawXCursorPosition(150) |
| 13879 | .rawYCursorPosition(50) |
| 13880 | .deviceId(SECOND_DEVICE_ID) |
| 13881 | .build()); |
| 13882 | |
| 13883 | right->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13884 | ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, |
| 13885 | DEVICE_ID, |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 13886 | /*pointerId=*/0)); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 13887 | ASSERT_FALSE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, |
Siarhei Vishniakou | ed89cbb | 2023-10-13 10:42:44 -0700 | [diff] [blame] | 13888 | SECOND_DEVICE_ID, |
| 13889 | /*pointerId=*/0)); |
| 13890 | } |
| 13891 | |
Arpit Singh | b65e2bd | 2024-06-03 09:48:16 +0000 | [diff] [blame] | 13892 | TEST_F(InputDispatcherTest, FocusedDisplayChangeIsNotified) { |
| 13893 | mDispatcher->setFocusedDisplay(SECOND_DISPLAY_ID); |
| 13894 | mFakePolicy->assertFocusedDisplayNotified(SECOND_DISPLAY_ID); |
| 13895 | } |
| 13896 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 13897 | } // namespace android::inputdispatcher |