Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | |
| 17 | #include <gtest/gtest.h> |
| 18 | #include <stdlib.h> |
| 19 | #include <unistd.h> |
| 20 | #include <sys/time.h> |
| 21 | #include <sys/types.h> |
| 22 | #include <stdio.h> |
| 23 | #include <poll.h> |
| 24 | |
| 25 | #include <memory> |
| 26 | |
Siarhei Vishniakou | bf98a57 | 2024-03-29 13:34:42 -0700 | [diff] [blame] | 27 | #include <android-base/thread_annotations.h> |
Patrick Williams | 0a4981a | 2023-07-28 15:08:52 -0500 | [diff] [blame] | 28 | #include <android/gui/BnWindowInfosReportedListener.h> |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 29 | #include <android/keycodes.h> |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 30 | #include <android/native_window.h> |
| 31 | |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 32 | #include <binder/Binder.h> |
| 33 | #include <binder/IServiceManager.h> |
| 34 | #include <binder/Parcel.h> |
| 35 | #include <binder/ProcessState.h> |
| 36 | |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 37 | #include <gui/ISurfaceComposer.h> |
| 38 | #include <gui/Surface.h> |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 39 | #include <gui/SurfaceComposerClient.h> |
| 40 | #include <gui/SurfaceControl.h> |
| 41 | |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 42 | #include <android/os/IInputFlinger.h> |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 43 | #include <gui/WindowInfo.h> |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 44 | #include <input/Input.h> |
Siarhei Vishniakou | 0438ca8 | 2024-03-12 14:27:25 -0700 | [diff] [blame] | 45 | #include <input/InputConsumer.h> |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 46 | #include <input/InputTransport.h> |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 47 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 48 | #include <ui/DisplayMode.h> |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 49 | #include <ui/Rect.h> |
| 50 | #include <ui/Region.h> |
| 51 | |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 52 | #include <private/android_filesystem_config.h> |
| 53 | |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 54 | using android::os::IInputFlinger; |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 55 | |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 56 | using android::hardware::graphics::common::V1_1::BufferUsage; |
| 57 | |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 58 | using android::gui::FocusRequest; |
| 59 | using android::gui::InputApplicationInfo; |
| 60 | using android::gui::TouchOcclusionMode; |
| 61 | using android::gui::WindowInfo; |
| 62 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 63 | namespace android { |
| 64 | namespace { |
| 65 | ui::LogicalDisplayId toDisplayId(ui::LayerStack layerStack) { |
| 66 | return ui::LogicalDisplayId{static_cast<int32_t>(layerStack.id)}; |
| 67 | } |
| 68 | } // namespace |
| 69 | namespace test { |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 70 | |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 71 | using Transaction = SurfaceComposerClient::Transaction; |
| 72 | |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 73 | sp<IInputFlinger> getInputFlinger() { |
Siarhei Vishniakou | 8d66013 | 2024-01-11 16:48:44 -0800 | [diff] [blame] | 74 | sp<IBinder> input(defaultServiceManager()->waitForService(String16("inputflinger"))); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 75 | if (input == nullptr) { |
| 76 | ALOGE("Failed to link to input service"); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 77 | } else { |
Harry Cutts | 917d6da | 2024-12-02 18:33:09 +0000 | [diff] [blame] | 78 | ALOGI("Linked to input"); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 79 | } |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 80 | return interface_cast<IInputFlinger>(input); |
| 81 | } |
| 82 | |
| 83 | // We use the top 10 layers as a way to haphazardly place ourselves above anything else. |
| 84 | static const int LAYER_BASE = INT32_MAX - 10; |
Chris Ye | 6c4243b | 2020-07-22 12:07:12 -0700 | [diff] [blame] | 85 | static constexpr std::chrono::nanoseconds DISPATCHING_TIMEOUT = 5s; |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 86 | |
Patrick Williams | 0a4981a | 2023-07-28 15:08:52 -0500 | [diff] [blame] | 87 | class SynchronousWindowInfosReportedListener : public gui::BnWindowInfosReportedListener { |
| 88 | public: |
| 89 | binder::Status onWindowInfosReported() override { |
Siarhei Vishniakou | bf98a57 | 2024-03-29 13:34:42 -0700 | [diff] [blame] | 90 | std::scoped_lock lock{mLock}; |
Patrick Williams | 0a4981a | 2023-07-28 15:08:52 -0500 | [diff] [blame] | 91 | mWindowInfosReported = true; |
| 92 | mConditionVariable.notify_one(); |
| 93 | return binder::Status::ok(); |
| 94 | } |
| 95 | |
| 96 | void wait() { |
Siarhei Vishniakou | bf98a57 | 2024-03-29 13:34:42 -0700 | [diff] [blame] | 97 | std::unique_lock lock{mLock}; |
| 98 | android::base::ScopedLockAssertion assumeLocked(mLock); |
| 99 | mConditionVariable.wait(lock, [&]() REQUIRES(mLock) { return mWindowInfosReported; }); |
Patrick Williams | 0a4981a | 2023-07-28 15:08:52 -0500 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | private: |
Siarhei Vishniakou | bf98a57 | 2024-03-29 13:34:42 -0700 | [diff] [blame] | 103 | std::mutex mLock; |
Patrick Williams | 0a4981a | 2023-07-28 15:08:52 -0500 | [diff] [blame] | 104 | std::condition_variable mConditionVariable; |
Siarhei Vishniakou | bf98a57 | 2024-03-29 13:34:42 -0700 | [diff] [blame] | 105 | bool mWindowInfosReported GUARDED_BY(mLock){false}; |
Patrick Williams | 0a4981a | 2023-07-28 15:08:52 -0500 | [diff] [blame] | 106 | }; |
| 107 | |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 108 | class InputSurface { |
| 109 | public: |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 110 | InputSurface(const sp<SurfaceControl>& sc, int width, int height, bool noInputChannel = false) { |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 111 | mSurfaceControl = sc; |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 112 | |
| 113 | mInputFlinger = getInputFlinger(); |
Linus Tufvesson | a185882 | 2022-03-04 09:32:07 +0000 | [diff] [blame] | 114 | if (noInputChannel) { |
Patrick Williams | 8760216 | 2024-11-05 10:13:19 -0600 | [diff] [blame] | 115 | mInputInfo->editInfo()->setInputConfig(WindowInfo::InputConfig::NO_INPUT_CHANNEL, true); |
Linus Tufvesson | a185882 | 2022-03-04 09:32:07 +0000 | [diff] [blame] | 116 | } else { |
Siarhei Vishniakou | 8d66013 | 2024-01-11 16:48:44 -0800 | [diff] [blame] | 117 | android::os::InputChannelCore tempChannel; |
| 118 | android::binder::Status result = |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 119 | mInputFlinger->createInputChannel(sc->getName() + " channel", &tempChannel); |
Siarhei Vishniakou | 8d66013 | 2024-01-11 16:48:44 -0800 | [diff] [blame] | 120 | if (!result.isOk()) { |
| 121 | ADD_FAILURE() << "binder call to createInputChannel failed"; |
| 122 | } |
| 123 | mClientChannel = InputChannel::create(std::move(tempChannel)); |
Patrick Williams | 8760216 | 2024-11-05 10:13:19 -0600 | [diff] [blame] | 124 | mInputInfo->editInfo()->token = mClientChannel->getConnectionToken(); |
Linus Tufvesson | a185882 | 2022-03-04 09:32:07 +0000 | [diff] [blame] | 125 | mInputConsumer = new InputConsumer(mClientChannel); |
| 126 | } |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 127 | |
Patrick Williams | 8760216 | 2024-11-05 10:13:19 -0600 | [diff] [blame] | 128 | mInputInfo->editInfo()->name = "Test info"; |
| 129 | mInputInfo->editInfo()->dispatchingTimeout = 5s; |
| 130 | mInputInfo->editInfo()->globalScaleFactor = 1.0; |
| 131 | mInputInfo->editInfo()->touchableRegion.orSelf(Rect(0, 0, width, height)); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 132 | |
Linus Tufvesson | a185882 | 2022-03-04 09:32:07 +0000 | [diff] [blame] | 133 | InputApplicationInfo aInfo; |
| 134 | aInfo.token = new BBinder(); |
| 135 | aInfo.name = "Test app info"; |
| 136 | aInfo.dispatchingTimeoutMillis = |
| 137 | std::chrono::duration_cast<std::chrono::milliseconds>(DISPATCHING_TIMEOUT).count(); |
Patrick Williams | 8760216 | 2024-11-05 10:13:19 -0600 | [diff] [blame] | 138 | mInputInfo->editInfo()->applicationInfo = aInfo; |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 141 | static std::unique_ptr<InputSurface> makeColorInputSurface(const sp<SurfaceComposerClient>& scc, |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 142 | int width, int height, |
| 143 | const std::string& name) { |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 144 | sp<SurfaceControl> surfaceControl = |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 145 | scc->createSurface(String8(name.c_str()), 0 /* bufHeight */, 0 /* bufWidth */, |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 146 | PIXEL_FORMAT_RGBA_8888, |
| 147 | ISurfaceComposerClient::eFXSurfaceEffect); |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 148 | return std::make_unique<InputSurface>(surfaceControl, width, height); |
| 149 | } |
| 150 | |
| 151 | static std::unique_ptr<InputSurface> makeBufferInputSurface( |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 152 | const sp<SurfaceComposerClient>& scc, int width, int height, |
| 153 | const std::string& name = "Test Buffer Surface") { |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 154 | sp<SurfaceControl> surfaceControl = |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 155 | scc->createSurface(String8(name.c_str()), width, height, PIXEL_FORMAT_RGBA_8888, |
| 156 | 0 /* flags */); |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 157 | return std::make_unique<InputSurface>(surfaceControl, width, height); |
| 158 | } |
| 159 | |
| 160 | static std::unique_ptr<InputSurface> makeContainerInputSurface( |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 161 | const sp<SurfaceComposerClient>& scc, int width, int height, |
| 162 | const std::string& name = "Test Container Surface") { |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 163 | sp<SurfaceControl> surfaceControl = |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 164 | scc->createSurface(String8(name.c_str()), 0 /* bufHeight */, 0 /* bufWidth */, |
| 165 | PIXEL_FORMAT_RGBA_8888, |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 166 | ISurfaceComposerClient::eFXSurfaceContainer); |
| 167 | return std::make_unique<InputSurface>(surfaceControl, width, height); |
| 168 | } |
| 169 | |
Linus Tufvesson | a185882 | 2022-03-04 09:32:07 +0000 | [diff] [blame] | 170 | static std::unique_ptr<InputSurface> makeContainerInputSurfaceNoInputChannel( |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 171 | const sp<SurfaceComposerClient>& scc, int width, int height, |
| 172 | const std::string& name = "Test Container Surface") { |
Linus Tufvesson | a185882 | 2022-03-04 09:32:07 +0000 | [diff] [blame] | 173 | sp<SurfaceControl> surfaceControl = |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 174 | scc->createSurface(String8(name.c_str()), 100 /* height */, 100 /* width */, |
| 175 | PIXEL_FORMAT_RGBA_8888, |
Linus Tufvesson | a185882 | 2022-03-04 09:32:07 +0000 | [diff] [blame] | 176 | ISurfaceComposerClient::eFXSurfaceContainer); |
| 177 | return std::make_unique<InputSurface>(surfaceControl, width, height, |
| 178 | true /* noInputChannel */); |
| 179 | } |
| 180 | |
arthurhung | b4a0f85 | 2020-06-16 11:02:50 +0800 | [diff] [blame] | 181 | static std::unique_ptr<InputSurface> makeCursorInputSurface( |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 182 | const sp<SurfaceComposerClient>& scc, int width, int height, |
| 183 | const std::string& name = "Test Cursor Surface") { |
arthurhung | b4a0f85 | 2020-06-16 11:02:50 +0800 | [diff] [blame] | 184 | sp<SurfaceControl> surfaceControl = |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 185 | scc->createSurface(String8(name.c_str()), 0 /* bufHeight */, 0 /* bufWidth */, |
| 186 | PIXEL_FORMAT_RGBA_8888, ISurfaceComposerClient::eCursorWindow); |
arthurhung | b4a0f85 | 2020-06-16 11:02:50 +0800 | [diff] [blame] | 187 | return std::make_unique<InputSurface>(surfaceControl, width, height); |
| 188 | } |
| 189 | |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 190 | void assertFocusChange(bool hasFocus) { |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 191 | InputEvent* ev = consumeEvent(); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 192 | ASSERT_NE(ev, nullptr); |
Siarhei Vishniakou | 63b6361 | 2023-04-12 11:00:23 -0700 | [diff] [blame] | 193 | ASSERT_EQ(InputEventType::FOCUS, ev->getType()); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 194 | FocusEvent* focusEvent = static_cast<FocusEvent*>(ev); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 195 | EXPECT_EQ(hasFocus, focusEvent->getHasFocus()); |
| 196 | } |
| 197 | |
Siarhei Vishniakou | 7b3fda3 | 2024-03-29 14:27:49 -0700 | [diff] [blame] | 198 | void expectTap(float x, float y) { |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 199 | InputEvent* ev = consumeEvent(); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 200 | ASSERT_NE(ev, nullptr); |
Siarhei Vishniakou | 63b6361 | 2023-04-12 11:00:23 -0700 | [diff] [blame] | 201 | ASSERT_EQ(InputEventType::MOTION, ev->getType()); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 202 | MotionEvent* mev = static_cast<MotionEvent*>(ev); |
| 203 | EXPECT_EQ(AMOTION_EVENT_ACTION_DOWN, mev->getAction()); |
| 204 | EXPECT_EQ(x, mev->getX(0)); |
| 205 | EXPECT_EQ(y, mev->getY(0)); |
arthurhung | b4a0f85 | 2020-06-16 11:02:50 +0800 | [diff] [blame] | 206 | EXPECT_EQ(0, mev->getFlags() & VERIFIED_MOTION_EVENT_FLAGS); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 207 | |
| 208 | ev = consumeEvent(); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 209 | ASSERT_NE(ev, nullptr); |
Siarhei Vishniakou | 63b6361 | 2023-04-12 11:00:23 -0700 | [diff] [blame] | 210 | ASSERT_EQ(InputEventType::MOTION, ev->getType()); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 211 | mev = static_cast<MotionEvent*>(ev); |
| 212 | EXPECT_EQ(AMOTION_EVENT_ACTION_UP, mev->getAction()); |
arthurhung | b4a0f85 | 2020-06-16 11:02:50 +0800 | [diff] [blame] | 213 | EXPECT_EQ(0, mev->getFlags() & VERIFIED_MOTION_EVENT_FLAGS); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 214 | } |
| 215 | |
chaviw | 39cfa2e | 2020-11-04 14:19:02 -0800 | [diff] [blame] | 216 | void expectTapWithFlag(int x, int y, int32_t flags) { |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 217 | InputEvent* ev = consumeEvent(); |
chaviw | 39cfa2e | 2020-11-04 14:19:02 -0800 | [diff] [blame] | 218 | ASSERT_NE(ev, nullptr); |
Siarhei Vishniakou | 63b6361 | 2023-04-12 11:00:23 -0700 | [diff] [blame] | 219 | ASSERT_EQ(InputEventType::MOTION, ev->getType()); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 220 | MotionEvent* mev = static_cast<MotionEvent*>(ev); |
chaviw | 39cfa2e | 2020-11-04 14:19:02 -0800 | [diff] [blame] | 221 | EXPECT_EQ(AMOTION_EVENT_ACTION_DOWN, mev->getAction()); |
| 222 | EXPECT_EQ(x, mev->getX(0)); |
| 223 | EXPECT_EQ(y, mev->getY(0)); |
| 224 | EXPECT_EQ(flags, mev->getFlags() & flags); |
| 225 | |
| 226 | ev = consumeEvent(); |
| 227 | ASSERT_NE(ev, nullptr); |
Siarhei Vishniakou | 63b6361 | 2023-04-12 11:00:23 -0700 | [diff] [blame] | 228 | ASSERT_EQ(InputEventType::MOTION, ev->getType()); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 229 | mev = static_cast<MotionEvent*>(ev); |
chaviw | 39cfa2e | 2020-11-04 14:19:02 -0800 | [diff] [blame] | 230 | EXPECT_EQ(AMOTION_EVENT_ACTION_UP, mev->getAction()); |
| 231 | EXPECT_EQ(flags, mev->getFlags() & flags); |
| 232 | } |
| 233 | |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 234 | void expectTapInDisplayCoordinates(int displayX, int displayY) { |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 235 | InputEvent* ev = consumeEvent(); |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 236 | ASSERT_NE(ev, nullptr); |
Siarhei Vishniakou | 63b6361 | 2023-04-12 11:00:23 -0700 | [diff] [blame] | 237 | ASSERT_EQ(InputEventType::MOTION, ev->getType()); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 238 | MotionEvent* mev = static_cast<MotionEvent*>(ev); |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 239 | EXPECT_EQ(AMOTION_EVENT_ACTION_DOWN, mev->getAction()); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 240 | const PointerCoords& coords = *mev->getRawPointerCoords(0 /*pointerIndex*/); |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 241 | EXPECT_EQ(displayX, coords.getX()); |
| 242 | EXPECT_EQ(displayY, coords.getY()); |
| 243 | EXPECT_EQ(0, mev->getFlags() & VERIFIED_MOTION_EVENT_FLAGS); |
| 244 | |
| 245 | ev = consumeEvent(); |
| 246 | ASSERT_NE(ev, nullptr); |
Siarhei Vishniakou | 63b6361 | 2023-04-12 11:00:23 -0700 | [diff] [blame] | 247 | ASSERT_EQ(InputEventType::MOTION, ev->getType()); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 248 | mev = static_cast<MotionEvent*>(ev); |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 249 | EXPECT_EQ(AMOTION_EVENT_ACTION_UP, mev->getAction()); |
| 250 | EXPECT_EQ(0, mev->getFlags() & VERIFIED_MOTION_EVENT_FLAGS); |
| 251 | } |
| 252 | |
Siarhei Vishniakou | bf98a57 | 2024-03-29 13:34:42 -0700 | [diff] [blame] | 253 | void expectKey(int32_t keycode) { |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 254 | InputEvent* ev = consumeEvent(); |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 255 | ASSERT_NE(ev, nullptr); |
Siarhei Vishniakou | 63b6361 | 2023-04-12 11:00:23 -0700 | [diff] [blame] | 256 | ASSERT_EQ(InputEventType::KEY, ev->getType()); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 257 | KeyEvent* keyEvent = static_cast<KeyEvent*>(ev); |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 258 | EXPECT_EQ(AMOTION_EVENT_ACTION_DOWN, keyEvent->getAction()); |
| 259 | EXPECT_EQ(keycode, keyEvent->getKeyCode()); |
| 260 | EXPECT_EQ(0, keyEvent->getFlags() & VERIFIED_KEY_EVENT_FLAGS); |
| 261 | |
| 262 | ev = consumeEvent(); |
| 263 | ASSERT_NE(ev, nullptr); |
Siarhei Vishniakou | 63b6361 | 2023-04-12 11:00:23 -0700 | [diff] [blame] | 264 | ASSERT_EQ(InputEventType::KEY, ev->getType()); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 265 | keyEvent = static_cast<KeyEvent*>(ev); |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 266 | EXPECT_EQ(AMOTION_EVENT_ACTION_UP, keyEvent->getAction()); |
| 267 | EXPECT_EQ(keycode, keyEvent->getKeyCode()); |
| 268 | EXPECT_EQ(0, keyEvent->getFlags() & VERIFIED_KEY_EVENT_FLAGS); |
| 269 | } |
| 270 | |
Siarhei Vishniakou | 7b3fda3 | 2024-03-29 14:27:49 -0700 | [diff] [blame] | 271 | void assertNoEvent() { |
| 272 | InputEvent* event = consumeEvent(/*timeout=*/100ms); |
| 273 | ASSERT_EQ(event, nullptr) << "Expected no event, but got " << *event; |
| 274 | } |
| 275 | |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 276 | virtual ~InputSurface() { |
Linus Tufvesson | a185882 | 2022-03-04 09:32:07 +0000 | [diff] [blame] | 277 | if (mClientChannel) { |
| 278 | mInputFlinger->removeInputChannel(mClientChannel->getConnectionToken()); |
| 279 | } |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 280 | } |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 281 | |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 282 | virtual void doTransaction( |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 283 | std::function<void(SurfaceComposerClient::Transaction&, const sp<SurfaceControl>&)> |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 284 | transactionBody) { |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 285 | SurfaceComposerClient::Transaction t; |
| 286 | transactionBody(t, mSurfaceControl); |
Prabir Pradhan | a97fd94 | 2024-10-28 21:21:53 +0000 | [diff] [blame] | 287 | t.apply(/*synchronously=*/true); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 288 | } |
| 289 | |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 290 | virtual void showAt(int x, int y, Rect crop = Rect(0, 0, 100, 100)) { |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 291 | SurfaceComposerClient::Transaction t; |
| 292 | t.show(mSurfaceControl); |
| 293 | t.setInputWindowInfo(mSurfaceControl, mInputInfo); |
| 294 | t.setLayer(mSurfaceControl, LAYER_BASE); |
| 295 | t.setPosition(mSurfaceControl, x, y); |
chaviw | 2571450 | 2021-02-11 10:01:08 -0800 | [diff] [blame] | 296 | t.setCrop(mSurfaceControl, crop); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 297 | t.setAlpha(mSurfaceControl, 1); |
Patrick Williams | 0a4981a | 2023-07-28 15:08:52 -0500 | [diff] [blame] | 298 | auto reportedListener = sp<SynchronousWindowInfosReportedListener>::make(); |
| 299 | t.addWindowInfosReportedListener(reportedListener); |
Prabir Pradhan | a97fd94 | 2024-10-28 21:21:53 +0000 | [diff] [blame] | 300 | t.apply(/*synchronously=*/true); |
Patrick Williams | 0a4981a | 2023-07-28 15:08:52 -0500 | [diff] [blame] | 301 | reportedListener->wait(); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 302 | } |
| 303 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 304 | void requestFocus(ui::LogicalDisplayId displayId = ui::LogicalDisplayId::DEFAULT) { |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 305 | SurfaceComposerClient::Transaction t; |
Vishnu Nair | 9ad0146 | 2021-01-15 12:55:14 -0800 | [diff] [blame] | 306 | FocusRequest request; |
Patrick Williams | 8760216 | 2024-11-05 10:13:19 -0600 | [diff] [blame] | 307 | request.token = mInputInfo->getInfo()->token; |
| 308 | request.windowName = mInputInfo->getInfo()->name; |
Vishnu Nair | 9ad0146 | 2021-01-15 12:55:14 -0800 | [diff] [blame] | 309 | request.timestamp = systemTime(SYSTEM_TIME_MONOTONIC); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 310 | request.displayId = displayId.val(); |
Vishnu Nair | 9ad0146 | 2021-01-15 12:55:14 -0800 | [diff] [blame] | 311 | t.setFocusedWindow(request); |
Prabir Pradhan | a97fd94 | 2024-10-28 21:21:53 +0000 | [diff] [blame] | 312 | t.apply(/*synchronously=*/true); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 313 | } |
| 314 | |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 315 | public: |
Siarhei Vishniakou | 1d038d4 | 2024-10-29 11:25:58 -0700 | [diff] [blame] | 316 | // But should be private |
Patrick Williams | 8760216 | 2024-11-05 10:13:19 -0600 | [diff] [blame] | 317 | sp<gui::WindowInfoHandle> mInputInfo = sp<gui::WindowInfoHandle>::make(); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 318 | sp<SurfaceControl> mSurfaceControl; |
Siarhei Vishniakou | 1d038d4 | 2024-10-29 11:25:58 -0700 | [diff] [blame] | 319 | |
| 320 | private: |
Siarhei Vishniakou | ce5ab08 | 2020-07-09 17:03:21 -0500 | [diff] [blame] | 321 | std::shared_ptr<InputChannel> mClientChannel; |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 322 | sp<IInputFlinger> mInputFlinger; |
| 323 | |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 324 | PreallocatedInputEventFactory mInputEventFactory; |
| 325 | InputConsumer* mInputConsumer; |
Siarhei Vishniakou | 1d038d4 | 2024-10-29 11:25:58 -0700 | [diff] [blame] | 326 | |
| 327 | InputEvent* consumeEvent(std::chrono::milliseconds timeout = 3000ms) { |
| 328 | mClientChannel->waitForMessage(timeout); |
| 329 | |
| 330 | InputEvent* ev; |
| 331 | uint32_t seqId; |
| 332 | status_t consumed = mInputConsumer->consume(&mInputEventFactory, true, -1, &seqId, &ev); |
| 333 | if (consumed != OK) { |
| 334 | return nullptr; |
| 335 | } |
| 336 | status_t status = mInputConsumer->sendFinishedSignal(seqId, true); |
| 337 | EXPECT_EQ(OK, status) << "Could not send finished signal"; |
| 338 | return ev; |
| 339 | } |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 340 | }; |
| 341 | |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 342 | class BlastInputSurface : public InputSurface { |
| 343 | public: |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 344 | BlastInputSurface(const sp<SurfaceControl>& sc, const sp<SurfaceControl>& parentSc, int width, |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 345 | int height) |
| 346 | : InputSurface(sc, width, height) { |
| 347 | mParentSurfaceControl = parentSc; |
| 348 | } |
| 349 | |
| 350 | ~BlastInputSurface() = default; |
| 351 | |
| 352 | static std::unique_ptr<BlastInputSurface> makeBlastInputSurface( |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 353 | const sp<SurfaceComposerClient>& scc, int width, int height) { |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 354 | sp<SurfaceControl> parentSc = |
| 355 | scc->createSurface(String8("Test Parent Surface"), 0 /* bufHeight */, |
| 356 | 0 /* bufWidth */, PIXEL_FORMAT_RGBA_8888, |
| 357 | ISurfaceComposerClient::eFXSurfaceContainer); |
| 358 | |
| 359 | sp<SurfaceControl> surfaceControl = |
| 360 | scc->createSurface(String8("Test Buffer Surface"), width, height, |
| 361 | PIXEL_FORMAT_RGBA_8888, |
| 362 | ISurfaceComposerClient::eFXSurfaceBufferState, |
| 363 | parentSc->getHandle()); |
| 364 | return std::make_unique<BlastInputSurface>(surfaceControl, parentSc, width, height); |
| 365 | } |
| 366 | |
| 367 | void doTransaction( |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 368 | std::function<void(SurfaceComposerClient::Transaction&, const sp<SurfaceControl>&)> |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 369 | transactionBody) override { |
| 370 | SurfaceComposerClient::Transaction t; |
| 371 | transactionBody(t, mParentSurfaceControl); |
Prabir Pradhan | a97fd94 | 2024-10-28 21:21:53 +0000 | [diff] [blame] | 372 | t.apply(/*synchronously=*/true); |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | void showAt(int x, int y, Rect crop = Rect(0, 0, 100, 100)) override { |
| 376 | SurfaceComposerClient::Transaction t; |
| 377 | t.show(mParentSurfaceControl); |
| 378 | t.setLayer(mParentSurfaceControl, LAYER_BASE); |
| 379 | t.setPosition(mParentSurfaceControl, x, y); |
| 380 | t.setCrop(mParentSurfaceControl, crop); |
| 381 | |
| 382 | t.show(mSurfaceControl); |
| 383 | t.setInputWindowInfo(mSurfaceControl, mInputInfo); |
| 384 | t.setCrop(mSurfaceControl, crop); |
| 385 | t.setAlpha(mSurfaceControl, 1); |
Prabir Pradhan | a97fd94 | 2024-10-28 21:21:53 +0000 | [diff] [blame] | 386 | t.apply(/*synchronously=*/true); |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | private: |
| 390 | sp<SurfaceControl> mParentSurfaceControl; |
| 391 | }; |
| 392 | |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 393 | class InputSurfacesTest : public ::testing::Test { |
| 394 | public: |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 395 | InputSurfacesTest() { ProcessState::self()->startThreadPool(); } |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 396 | |
| 397 | void SetUp() { |
| 398 | mComposerClient = new SurfaceComposerClient; |
| 399 | ASSERT_EQ(NO_ERROR, mComposerClient->initCheck()); |
Huihong Luo | 31b5ac2 | 2022-08-15 20:38:10 -0700 | [diff] [blame] | 400 | const auto ids = SurfaceComposerClient::getPhysicalDisplayIds(); |
| 401 | ASSERT_FALSE(ids.empty()); |
| 402 | // display 0 is picked for now, can extend to support all displays if needed |
| 403 | const auto display = SurfaceComposerClient::getPhysicalDisplayToken(ids.front()); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 404 | ASSERT_NE(display, nullptr); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 405 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 406 | ui::DisplayMode mode; |
| 407 | ASSERT_EQ(NO_ERROR, mComposerClient->getActiveDisplayMode(display, &mode)); |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 408 | |
| 409 | // After a new buffer is queued, SurfaceFlinger is notified and will |
| 410 | // latch the new buffer on next vsync. Let's heuristically wait for 3 |
| 411 | // vsyncs. |
Alec Mouri | 55e3103 | 2023-10-02 20:34:18 +0000 | [diff] [blame] | 412 | mBufferPostDelay = static_cast<int32_t>(1e6 / mode.peakRefreshRate) * 3; |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 413 | } |
| 414 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 415 | void TearDown() { mComposerClient->dispose(); } |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 416 | |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 417 | std::unique_ptr<InputSurface> makeSurface(int width, int height, |
| 418 | const std::string& name = "Test Surface") const { |
| 419 | return InputSurface::makeColorInputSurface(mComposerClient, width, height, name); |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 420 | } |
| 421 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 422 | void postBuffer(const sp<SurfaceControl>& layer, int32_t w, int32_t h) { |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 423 | int64_t usageFlags = BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 424 | BufferUsage::COMPOSER_OVERLAY | BufferUsage::GPU_TEXTURE; |
| 425 | sp<GraphicBuffer> buffer = |
| 426 | new GraphicBuffer(w, h, PIXEL_FORMAT_RGBA_8888, 1, usageFlags, "test"); |
Prabir Pradhan | a97fd94 | 2024-10-28 21:21:53 +0000 | [diff] [blame] | 427 | Transaction().setBuffer(layer, buffer).apply(/*synchronously=*/true); |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 428 | usleep(mBufferPostDelay); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | sp<SurfaceComposerClient> mComposerClient; |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 432 | int32_t mBufferPostDelay; |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 433 | }; |
| 434 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 435 | void injectTapOnDisplay(int x, int y, ui::LogicalDisplayId displayId) { |
Vishnu Nair | 16a938f | 2021-09-24 07:14:54 -0700 | [diff] [blame] | 436 | char *buf1, *buf2, *bufDisplayId; |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 437 | asprintf(&buf1, "%d", x); |
| 438 | asprintf(&buf2, "%d", y); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 439 | asprintf(&bufDisplayId, "%d", displayId.val()); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 440 | if (fork() == 0) { |
Vishnu Nair | 16a938f | 2021-09-24 07:14:54 -0700 | [diff] [blame] | 441 | execlp("input", "input", "-d", bufDisplayId, "tap", buf1, buf2, NULL); |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | void injectTap(int x, int y) { |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 446 | injectTapOnDisplay(x, y, ui::LogicalDisplayId::DEFAULT); |
Vishnu Nair | 16a938f | 2021-09-24 07:14:54 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 449 | void injectKeyOnDisplay(uint32_t keycode, ui::LogicalDisplayId displayId) { |
Vishnu Nair | 16a938f | 2021-09-24 07:14:54 -0700 | [diff] [blame] | 450 | char *buf1, *bufDisplayId; |
| 451 | asprintf(&buf1, "%d", keycode); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 452 | asprintf(&bufDisplayId, "%d", displayId.val()); |
Vishnu Nair | 16a938f | 2021-09-24 07:14:54 -0700 | [diff] [blame] | 453 | if (fork() == 0) { |
| 454 | execlp("input", "input", "-d", bufDisplayId, "keyevent", buf1, NULL); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 455 | } |
| 456 | } |
| 457 | |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 458 | void injectKey(uint32_t keycode) { |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 459 | injectKeyOnDisplay(keycode, ui::LogicalDisplayId::INVALID); |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 460 | } |
| 461 | |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 462 | TEST_F(InputSurfacesTest, can_receive_input) { |
| 463 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
| 464 | surface->showAt(100, 100); |
| 465 | |
| 466 | injectTap(101, 101); |
| 467 | |
Siarhei Vishniakou | 1d038d4 | 2024-10-29 11:25:58 -0700 | [diff] [blame] | 468 | surface->expectTap(1, 1); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 469 | } |
| 470 | |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 471 | /** |
| 472 | * Set up two surfaces side-by-side. Tap each surface. |
| 473 | * Next, swap the positions of the two surfaces. Inject tap into the two |
| 474 | * original locations. Ensure that the tap is received by the surfaces in the |
| 475 | * reverse order. |
| 476 | */ |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 477 | TEST_F(InputSurfacesTest, input_respects_positioning) { |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 478 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100, "Left Surface"); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 479 | surface->showAt(100, 100); |
| 480 | |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 481 | std::unique_ptr<InputSurface> surface2 = makeSurface(100, 100, "Right Surface"); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 482 | surface2->showAt(200, 200); |
| 483 | |
| 484 | injectTap(201, 201); |
| 485 | surface2->expectTap(1, 1); |
| 486 | |
| 487 | injectTap(101, 101); |
| 488 | surface->expectTap(1, 1); |
| 489 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 490 | surface2->doTransaction([](auto& t, auto& sc) { t.setPosition(sc, 100, 100); }); |
| 491 | surface->doTransaction([](auto& t, auto& sc) { t.setPosition(sc, 200, 200); }); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 492 | |
| 493 | injectTap(101, 101); |
| 494 | surface2->expectTap(1, 1); |
| 495 | |
| 496 | injectTap(201, 201); |
| 497 | surface->expectTap(1, 1); |
| 498 | } |
| 499 | |
| 500 | TEST_F(InputSurfacesTest, input_respects_layering) { |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 501 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100, "Test Surface 1"); |
| 502 | std::unique_ptr<InputSurface> surface2 = makeSurface(100, 100, "Test Surface 2"); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 503 | |
| 504 | surface->showAt(10, 10); |
| 505 | surface2->showAt(10, 10); |
| 506 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 507 | surface->doTransaction([](auto& t, auto& sc) { t.setLayer(sc, LAYER_BASE + 1); }); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 508 | |
| 509 | injectTap(11, 11); |
| 510 | surface->expectTap(1, 1); |
| 511 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 512 | surface2->doTransaction([](auto& t, auto& sc) { t.setLayer(sc, LAYER_BASE + 1); }); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 513 | |
| 514 | injectTap(11, 11); |
| 515 | surface2->expectTap(1, 1); |
| 516 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 517 | surface2->doTransaction([](auto& t, auto& sc) { t.hide(sc); }); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 518 | |
| 519 | injectTap(11, 11); |
| 520 | surface->expectTap(1, 1); |
| 521 | } |
| 522 | |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 523 | // Surface Insets are set to offset the client content and draw a border around the client surface |
| 524 | // (such as shadows in dialogs). Inputs sent to the client are offset such that 0,0 is the start |
| 525 | // of the client content. |
| 526 | TEST_F(InputSurfacesTest, input_respects_surface_insets) { |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 527 | std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100, "Background Surface"); |
| 528 | std::unique_ptr<InputSurface> fgSurface = makeSurface(100, 100, "Foreground Surface"); |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 529 | bgSurface->showAt(100, 100); |
| 530 | |
Patrick Williams | 8760216 | 2024-11-05 10:13:19 -0600 | [diff] [blame] | 531 | fgSurface->mInputInfo->editInfo()->surfaceInset = 5; |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 532 | fgSurface->showAt(100, 100); |
| 533 | |
| 534 | injectTap(106, 106); |
| 535 | fgSurface->expectTap(1, 1); |
| 536 | |
| 537 | injectTap(101, 101); |
| 538 | bgSurface->expectTap(1, 1); |
| 539 | } |
| 540 | |
Vishnu Nair | fed7c12 | 2023-03-18 01:54:43 +0000 | [diff] [blame] | 541 | TEST_F(InputSurfacesTest, input_respects_surface_insets_with_replaceTouchableRegionWithCrop) { |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 542 | std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100, "Background Surface"); |
| 543 | std::unique_ptr<InputSurface> fgSurface = makeSurface(100, 100, "Foreground Surface"); |
Vishnu Nair | fed7c12 | 2023-03-18 01:54:43 +0000 | [diff] [blame] | 544 | bgSurface->showAt(100, 100); |
| 545 | |
Patrick Williams | 8760216 | 2024-11-05 10:13:19 -0600 | [diff] [blame] | 546 | fgSurface->mInputInfo->editInfo()->surfaceInset = 5; |
| 547 | fgSurface->mInputInfo->editInfo()->replaceTouchableRegionWithCrop = true; |
Vishnu Nair | fed7c12 | 2023-03-18 01:54:43 +0000 | [diff] [blame] | 548 | fgSurface->showAt(100, 100); |
| 549 | |
| 550 | injectTap(106, 106); |
| 551 | fgSurface->expectTap(1, 1); |
| 552 | |
| 553 | injectTap(101, 101); |
| 554 | bgSurface->expectTap(1, 1); |
| 555 | } |
| 556 | |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 557 | // Ensure a surface whose insets are cropped, handles the touch offset correctly. ref:b/120413463 |
| 558 | TEST_F(InputSurfacesTest, input_respects_cropped_surface_insets) { |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 559 | std::unique_ptr<InputSurface> parentSurface = makeSurface(100, 100, "Parent Surface"); |
| 560 | std::unique_ptr<InputSurface> childSurface = makeSurface(100, 100, "Child Surface"); |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 561 | parentSurface->showAt(100, 100); |
| 562 | |
Patrick Williams | 8760216 | 2024-11-05 10:13:19 -0600 | [diff] [blame] | 563 | childSurface->mInputInfo->editInfo()->surfaceInset = 10; |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 564 | childSurface->showAt(100, 100); |
| 565 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 566 | childSurface->doTransaction([&](auto& t, auto& sc) { |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 567 | t.setPosition(sc, -5, -5); |
Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame] | 568 | t.reparent(sc, parentSurface->mSurfaceControl); |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 569 | }); |
| 570 | |
| 571 | injectTap(106, 106); |
| 572 | childSurface->expectTap(1, 1); |
| 573 | |
| 574 | injectTap(101, 101); |
| 575 | parentSurface->expectTap(1, 1); |
| 576 | } |
| 577 | |
Arthur Hung | 118b114 | 2019-05-08 21:25:59 +0800 | [diff] [blame] | 578 | // Ensure a surface whose insets are scaled, handles the touch offset correctly. |
| 579 | TEST_F(InputSurfacesTest, input_respects_scaled_surface_insets) { |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 580 | std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100, "Background Surface"); |
| 581 | std::unique_ptr<InputSurface> fgSurface = makeSurface(100, 100, "Foreground Surface"); |
Arthur Hung | 118b114 | 2019-05-08 21:25:59 +0800 | [diff] [blame] | 582 | bgSurface->showAt(100, 100); |
| 583 | |
Patrick Williams | 8760216 | 2024-11-05 10:13:19 -0600 | [diff] [blame] | 584 | fgSurface->mInputInfo->editInfo()->surfaceInset = 5; |
Arthur Hung | 118b114 | 2019-05-08 21:25:59 +0800 | [diff] [blame] | 585 | fgSurface->showAt(100, 100); |
| 586 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 587 | fgSurface->doTransaction([&](auto& t, auto& sc) { t.setMatrix(sc, 2.0, 0, 0, 4.0); }); |
Arthur Hung | 118b114 | 2019-05-08 21:25:59 +0800 | [diff] [blame] | 588 | |
| 589 | // expect = touch / scale - inset |
| 590 | injectTap(112, 124); |
| 591 | fgSurface->expectTap(1, 1); |
| 592 | |
| 593 | injectTap(101, 101); |
| 594 | bgSurface->expectTap(1, 1); |
| 595 | } |
| 596 | |
Ady Abraham | 282f1d7 | 2019-07-24 18:05:56 -0700 | [diff] [blame] | 597 | TEST_F(InputSurfacesTest, input_respects_scaled_surface_insets_overflow) { |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 598 | std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100, "Background Surface"); |
| 599 | std::unique_ptr<InputSurface> fgSurface = makeSurface(100, 100, "Foreground Surface"); |
Prabir Pradhan | c9589c1 | 2021-09-22 06:11:43 -0700 | [diff] [blame] | 600 | bgSurface->showAt(100, 100); |
| 601 | |
Ady Abraham | 282f1d7 | 2019-07-24 18:05:56 -0700 | [diff] [blame] | 602 | // In case we pass the very big inset without any checking. |
Patrick Williams | 8760216 | 2024-11-05 10:13:19 -0600 | [diff] [blame] | 603 | fgSurface->mInputInfo->editInfo()->surfaceInset = INT32_MAX; |
Ady Abraham | 282f1d7 | 2019-07-24 18:05:56 -0700 | [diff] [blame] | 604 | fgSurface->showAt(100, 100); |
| 605 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 606 | fgSurface->doTransaction([&](auto& t, auto& sc) { t.setMatrix(sc, 2.0, 0, 0, 2.0); }); |
Ady Abraham | 282f1d7 | 2019-07-24 18:05:56 -0700 | [diff] [blame] | 607 | |
| 608 | // expect no crash for overflow, and inset size to be clamped to surface size |
Prabir Pradhan | c9589c1 | 2021-09-22 06:11:43 -0700 | [diff] [blame] | 609 | injectTap(112, 124); |
| 610 | bgSurface->expectTap(12, 24); |
Ady Abraham | 282f1d7 | 2019-07-24 18:05:56 -0700 | [diff] [blame] | 611 | } |
| 612 | |
Prabir Pradhan | 33da946 | 2022-06-14 14:55:57 +0000 | [diff] [blame] | 613 | TEST_F(InputSurfacesTest, touchable_region) { |
| 614 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
| 615 | |
Patrick Williams | 8760216 | 2024-11-05 10:13:19 -0600 | [diff] [blame] | 616 | surface->mInputInfo->editInfo()->touchableRegion.set(Rect{19, 29, 21, 31}); |
Prabir Pradhan | 33da946 | 2022-06-14 14:55:57 +0000 | [diff] [blame] | 617 | |
| 618 | surface->showAt(11, 22); |
| 619 | |
| 620 | // A tap within the surface but outside the touchable region should not be sent to the surface. |
| 621 | injectTap(20, 30); |
Siarhei Vishniakou | 1d038d4 | 2024-10-29 11:25:58 -0700 | [diff] [blame] | 622 | surface->assertNoEvent(); |
Prabir Pradhan | 33da946 | 2022-06-14 14:55:57 +0000 | [diff] [blame] | 623 | |
| 624 | injectTap(31, 52); |
| 625 | surface->expectTap(20, 30); |
| 626 | } |
| 627 | |
| 628 | TEST_F(InputSurfacesTest, input_respects_touchable_region_offset_overflow) { |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 629 | std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100, "Background Surface"); |
| 630 | std::unique_ptr<InputSurface> fgSurface = makeSurface(100, 100, "Foreground Surface"); |
Prabir Pradhan | 33da946 | 2022-06-14 14:55:57 +0000 | [diff] [blame] | 631 | bgSurface->showAt(100, 100); |
| 632 | |
| 633 | // Set the touchable region to the values at the limit of its corresponding type. |
| 634 | // Since the surface is offset from the origin, the touchable region will be transformed into |
| 635 | // display space, which would trigger an overflow or an underflow. Ensure that we are protected |
| 636 | // against such a situation. |
Patrick Williams | 8760216 | 2024-11-05 10:13:19 -0600 | [diff] [blame] | 637 | fgSurface->mInputInfo->editInfo()->touchableRegion.orSelf( |
| 638 | Rect{INT32_MIN, INT32_MIN, INT32_MAX, INT32_MAX}); |
Prabir Pradhan | 33da946 | 2022-06-14 14:55:57 +0000 | [diff] [blame] | 639 | |
| 640 | fgSurface->showAt(100, 100); |
| 641 | |
| 642 | // Expect no crash for overflow. The overflowed touchable region is ignored, so the background |
| 643 | // surface receives touch. |
| 644 | injectTap(112, 124); |
| 645 | bgSurface->expectTap(12, 24); |
| 646 | } |
| 647 | |
| 648 | TEST_F(InputSurfacesTest, input_respects_scaled_touchable_region_overflow) { |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 649 | std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100, "Background Surface"); |
| 650 | std::unique_ptr<InputSurface> fgSurface = makeSurface(100, 100, "Foreground Surface"); |
Prabir Pradhan | 33da946 | 2022-06-14 14:55:57 +0000 | [diff] [blame] | 651 | bgSurface->showAt(0, 0); |
| 652 | |
Patrick Williams | 8760216 | 2024-11-05 10:13:19 -0600 | [diff] [blame] | 653 | fgSurface->mInputInfo->editInfo()->touchableRegion.orSelf( |
| 654 | Rect{INT32_MIN, INT32_MIN, INT32_MAX, INT32_MAX}); |
Prabir Pradhan | 33da946 | 2022-06-14 14:55:57 +0000 | [diff] [blame] | 655 | fgSurface->showAt(0, 0); |
| 656 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 657 | fgSurface->doTransaction([&](auto& t, auto& sc) { t.setMatrix(sc, 2.0, 0, 0, 2.0); }); |
Prabir Pradhan | 33da946 | 2022-06-14 14:55:57 +0000 | [diff] [blame] | 658 | |
| 659 | // Expect no crash for overflow. |
| 660 | injectTap(12, 24); |
Prabir Pradhan | a4c59bd | 2023-04-10 20:54:04 +0000 | [diff] [blame] | 661 | bgSurface->expectTap(12, 24); |
Prabir Pradhan | 33da946 | 2022-06-14 14:55:57 +0000 | [diff] [blame] | 662 | } |
| 663 | |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 664 | // Ensure we ignore transparent region when getting screen bounds when positioning input frame. |
| 665 | TEST_F(InputSurfacesTest, input_ignores_transparent_region) { |
| 666 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 667 | surface->doTransaction([](auto& t, auto& sc) { |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 668 | Region transparentRegion(Rect(0, 0, 10, 10)); |
| 669 | t.setTransparentRegionHint(sc, transparentRegion); |
| 670 | }); |
| 671 | surface->showAt(100, 100); |
| 672 | injectTap(101, 101); |
| 673 | surface->expectTap(1, 1); |
| 674 | } |
| 675 | |
Vishnu Nair | f8678ba | 2019-10-11 18:11:26 -0700 | [diff] [blame] | 676 | // TODO(b/139494112) update tests once we define expected behavior |
| 677 | // Ensure we still send input to the surface regardless of surface visibility changes due to the |
| 678 | // first buffer being submitted or alpha changes. |
| 679 | // Original bug ref: b/120839715 |
| 680 | TEST_F(InputSurfacesTest, input_ignores_buffer_layer_buffer) { |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 681 | std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100); |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 682 | std::unique_ptr<BlastInputSurface> bufferSurface = |
| 683 | BlastInputSurface::makeBlastInputSurface(mComposerClient, 100, 100); |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 684 | |
| 685 | bgSurface->showAt(10, 10); |
| 686 | bufferSurface->showAt(10, 10); |
| 687 | |
| 688 | injectTap(11, 11); |
Vishnu Nair | f8678ba | 2019-10-11 18:11:26 -0700 | [diff] [blame] | 689 | bufferSurface->expectTap(1, 1); |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 690 | |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 691 | postBuffer(bufferSurface->mSurfaceControl, 100, 100); |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 692 | injectTap(11, 11); |
| 693 | bufferSurface->expectTap(1, 1); |
| 694 | } |
| 695 | |
Arthur Hung | fb2ebce | 2021-10-04 14:08:48 +0000 | [diff] [blame] | 696 | TEST_F(InputSurfacesTest, input_respects_buffer_layer_alpha) { |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 697 | std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100); |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 698 | std::unique_ptr<BlastInputSurface> bufferSurface = |
| 699 | BlastInputSurface::makeBlastInputSurface(mComposerClient, 100, 100); |
| 700 | postBuffer(bufferSurface->mSurfaceControl, 100, 100); |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 701 | |
| 702 | bgSurface->showAt(10, 10); |
| 703 | bufferSurface->showAt(10, 10); |
| 704 | |
| 705 | injectTap(11, 11); |
| 706 | bufferSurface->expectTap(1, 1); |
| 707 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 708 | bufferSurface->doTransaction([](auto& t, auto& sc) { t.setAlpha(sc, 0.0); }); |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 709 | |
| 710 | injectTap(11, 11); |
Arthur Hung | fb2ebce | 2021-10-04 14:08:48 +0000 | [diff] [blame] | 711 | bgSurface->expectTap(1, 1); |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 712 | } |
| 713 | |
Vishnu Nair | f8678ba | 2019-10-11 18:11:26 -0700 | [diff] [blame] | 714 | TEST_F(InputSurfacesTest, input_ignores_color_layer_alpha) { |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 715 | std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100, "Background Surface"); |
| 716 | std::unique_ptr<InputSurface> fgSurface = makeSurface(100, 100, "Foreground Surface"); |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 717 | |
| 718 | bgSurface->showAt(10, 10); |
| 719 | fgSurface->showAt(10, 10); |
| 720 | |
| 721 | injectTap(11, 11); |
| 722 | fgSurface->expectTap(1, 1); |
| 723 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 724 | fgSurface->doTransaction([](auto& t, auto& sc) { t.setAlpha(sc, 0.0); }); |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 725 | |
| 726 | injectTap(11, 11); |
Vishnu Nair | f8678ba | 2019-10-11 18:11:26 -0700 | [diff] [blame] | 727 | fgSurface->expectTap(1, 1); |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | TEST_F(InputSurfacesTest, input_respects_container_layer_visiblity) { |
| 731 | std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100); |
| 732 | std::unique_ptr<InputSurface> containerSurface = |
| 733 | InputSurface::makeContainerInputSurface(mComposerClient, 100, 100); |
| 734 | |
| 735 | bgSurface->showAt(10, 10); |
| 736 | containerSurface->showAt(10, 10); |
| 737 | |
| 738 | injectTap(11, 11); |
| 739 | containerSurface->expectTap(1, 1); |
| 740 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 741 | containerSurface->doTransaction([](auto& t, auto& sc) { t.hide(sc); }); |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 742 | |
| 743 | injectTap(11, 11); |
| 744 | bgSurface->expectTap(1, 1); |
| 745 | } |
chaviw | fbe5d9c | 2018-12-26 12:23:37 -0800 | [diff] [blame] | 746 | |
Arthur Hung | d20b270 | 2019-01-14 18:16:16 +0800 | [diff] [blame] | 747 | TEST_F(InputSurfacesTest, input_respects_outscreen) { |
| 748 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
| 749 | surface->showAt(-1, -1); |
| 750 | |
| 751 | injectTap(0, 0); |
| 752 | surface->expectTap(1, 1); |
| 753 | } |
arthurhung | b4a0f85 | 2020-06-16 11:02:50 +0800 | [diff] [blame] | 754 | |
| 755 | TEST_F(InputSurfacesTest, input_ignores_cursor_layer) { |
| 756 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
| 757 | std::unique_ptr<InputSurface> cursorSurface = |
| 758 | InputSurface::makeCursorInputSurface(mComposerClient, 10, 10); |
| 759 | |
| 760 | surface->showAt(10, 10); |
arthurhung | b4a0f85 | 2020-06-16 11:02:50 +0800 | [diff] [blame] | 761 | cursorSurface->showAt(10, 10); |
| 762 | |
| 763 | injectTap(11, 11); |
| 764 | surface->expectTap(1, 1); |
| 765 | } |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 766 | |
| 767 | TEST_F(InputSurfacesTest, can_be_focused) { |
| 768 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
| 769 | surface->showAt(100, 100); |
| 770 | surface->requestFocus(); |
| 771 | |
| 772 | surface->assertFocusChange(true); |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 773 | |
| 774 | injectKey(AKEYCODE_V); |
| 775 | surface->expectKey(AKEYCODE_V); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 776 | } |
chaviw | 44a6d2b | 2020-09-08 17:14:16 -0700 | [diff] [blame] | 777 | |
| 778 | TEST_F(InputSurfacesTest, rotate_surface) { |
| 779 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
| 780 | surface->showAt(10, 10); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 781 | surface->doTransaction([](auto& t, auto& sc) { |
chaviw | 44a6d2b | 2020-09-08 17:14:16 -0700 | [diff] [blame] | 782 | t.setMatrix(sc, 0, 1, -1, 0); // 90 degrees |
| 783 | }); |
| 784 | injectTap(8, 11); |
| 785 | surface->expectTap(1, 2); |
| 786 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 787 | surface->doTransaction([](auto& t, auto& sc) { |
chaviw | 44a6d2b | 2020-09-08 17:14:16 -0700 | [diff] [blame] | 788 | t.setMatrix(sc, -1, 0, 0, -1); // 180 degrees |
| 789 | }); |
| 790 | injectTap(9, 8); |
| 791 | surface->expectTap(1, 2); |
| 792 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 793 | surface->doTransaction([](auto& t, auto& sc) { |
chaviw | 44a6d2b | 2020-09-08 17:14:16 -0700 | [diff] [blame] | 794 | t.setMatrix(sc, 0, -1, 1, 0); // 270 degrees |
| 795 | }); |
| 796 | injectTap(12, 9); |
| 797 | surface->expectTap(1, 2); |
| 798 | } |
| 799 | |
| 800 | TEST_F(InputSurfacesTest, rotate_surface_with_scale) { |
| 801 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
| 802 | surface->showAt(10, 10); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 803 | surface->doTransaction([](auto& t, auto& sc) { |
chaviw | 44a6d2b | 2020-09-08 17:14:16 -0700 | [diff] [blame] | 804 | t.setMatrix(sc, 0, 2, -4, 0); // 90 degrees |
| 805 | }); |
| 806 | injectTap(2, 12); |
| 807 | surface->expectTap(1, 2); |
| 808 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 809 | surface->doTransaction([](auto& t, auto& sc) { |
chaviw | 44a6d2b | 2020-09-08 17:14:16 -0700 | [diff] [blame] | 810 | t.setMatrix(sc, -2, 0, 0, -4); // 180 degrees |
| 811 | }); |
| 812 | injectTap(8, 2); |
| 813 | surface->expectTap(1, 2); |
| 814 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 815 | surface->doTransaction([](auto& t, auto& sc) { |
chaviw | 44a6d2b | 2020-09-08 17:14:16 -0700 | [diff] [blame] | 816 | t.setMatrix(sc, 0, -2, 4, 0); // 270 degrees |
| 817 | }); |
| 818 | injectTap(18, 8); |
| 819 | surface->expectTap(1, 2); |
| 820 | } |
| 821 | |
| 822 | TEST_F(InputSurfacesTest, rotate_surface_with_scale_and_insets) { |
| 823 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
Patrick Williams | 8760216 | 2024-11-05 10:13:19 -0600 | [diff] [blame] | 824 | surface->mInputInfo->editInfo()->surfaceInset = 5; |
chaviw | 44a6d2b | 2020-09-08 17:14:16 -0700 | [diff] [blame] | 825 | surface->showAt(100, 100); |
| 826 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 827 | surface->doTransaction([](auto& t, auto& sc) { |
chaviw | 44a6d2b | 2020-09-08 17:14:16 -0700 | [diff] [blame] | 828 | t.setMatrix(sc, 0, 2, -4, 0); // 90 degrees |
| 829 | }); |
| 830 | injectTap(40, 120); |
| 831 | surface->expectTap(5, 10); |
| 832 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 833 | surface->doTransaction([](auto& t, auto& sc) { |
chaviw | 44a6d2b | 2020-09-08 17:14:16 -0700 | [diff] [blame] | 834 | t.setMatrix(sc, -2, 0, 0, -4); // 180 degrees |
| 835 | }); |
| 836 | injectTap(80, 40); |
| 837 | surface->expectTap(5, 10); |
| 838 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 839 | surface->doTransaction([](auto& t, auto& sc) { |
chaviw | 44a6d2b | 2020-09-08 17:14:16 -0700 | [diff] [blame] | 840 | t.setMatrix(sc, 0, -2, 4, 0); // 270 degrees |
| 841 | }); |
| 842 | injectTap(160, 80); |
| 843 | surface->expectTap(5, 10); |
| 844 | } |
| 845 | |
chaviw | 39cfa2e | 2020-11-04 14:19:02 -0800 | [diff] [blame] | 846 | TEST_F(InputSurfacesTest, touch_flag_obscured) { |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 847 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100, "Touchable Surface"); |
chaviw | 39cfa2e | 2020-11-04 14:19:02 -0800 | [diff] [blame] | 848 | surface->showAt(100, 100); |
| 849 | |
| 850 | // Add non touchable window to fully cover touchable window. Window behind gets touch, but |
| 851 | // with flag AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 852 | std::unique_ptr<InputSurface> nonTouchableSurface = |
| 853 | makeSurface(100, 100, "Non-Touchable Surface"); |
Patrick Williams | 8760216 | 2024-11-05 10:13:19 -0600 | [diff] [blame] | 854 | nonTouchableSurface->mInputInfo->editInfo() |
| 855 | ->setInputConfig(WindowInfo::InputConfig::NOT_TOUCHABLE, true); |
| 856 | nonTouchableSurface->mInputInfo->editInfo()->ownerUid = gui::Uid{22222}; |
Bernardo Rufino | 602ef71 | 2020-12-21 11:02:18 +0000 | [diff] [blame] | 857 | // Overriding occlusion mode otherwise the touch would be discarded at InputDispatcher by |
| 858 | // the default obscured/untrusted touch filter introduced in S. |
Patrick Williams | 8760216 | 2024-11-05 10:13:19 -0600 | [diff] [blame] | 859 | nonTouchableSurface->mInputInfo->editInfo()->touchOcclusionMode = TouchOcclusionMode::ALLOW; |
chaviw | 39cfa2e | 2020-11-04 14:19:02 -0800 | [diff] [blame] | 860 | nonTouchableSurface->showAt(100, 100); |
| 861 | |
| 862 | injectTap(190, 199); |
| 863 | surface->expectTapWithFlag(90, 99, AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED); |
| 864 | } |
| 865 | |
| 866 | TEST_F(InputSurfacesTest, touch_flag_partially_obscured_with_crop) { |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 867 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100, "Test Surface"); |
chaviw | 39cfa2e | 2020-11-04 14:19:02 -0800 | [diff] [blame] | 868 | surface->showAt(100, 100); |
| 869 | |
| 870 | // Add non touchable window to cover touchable window, but parent is cropped to not cover area |
| 871 | // that will be tapped. Window behind gets touch, but with flag |
| 872 | // AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 873 | std::unique_ptr<InputSurface> parentSurface = makeSurface(100, 100, "Parent Surface"); |
| 874 | std::unique_ptr<InputSurface> nonTouchableSurface = |
| 875 | makeSurface(100, 100, "Non-Touchable Surface"); |
Patrick Williams | 8760216 | 2024-11-05 10:13:19 -0600 | [diff] [blame] | 876 | nonTouchableSurface->mInputInfo->editInfo() |
| 877 | ->setInputConfig(WindowInfo::InputConfig::NOT_TOUCHABLE, true); |
| 878 | parentSurface->mInputInfo->editInfo()->setInputConfig(WindowInfo::InputConfig::NOT_TOUCHABLE, |
| 879 | true); |
| 880 | nonTouchableSurface->mInputInfo->editInfo()->ownerUid = gui::Uid{22222}; |
| 881 | parentSurface->mInputInfo->editInfo()->ownerUid = gui::Uid{22222}; |
chaviw | 39cfa2e | 2020-11-04 14:19:02 -0800 | [diff] [blame] | 882 | nonTouchableSurface->showAt(0, 0); |
| 883 | parentSurface->showAt(100, 100); |
| 884 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 885 | nonTouchableSurface->doTransaction([&](auto& t, auto& sc) { |
chaviw | 2571450 | 2021-02-11 10:01:08 -0800 | [diff] [blame] | 886 | t.setCrop(parentSurface->mSurfaceControl, Rect(0, 0, 50, 50)); |
chaviw | 39cfa2e | 2020-11-04 14:19:02 -0800 | [diff] [blame] | 887 | t.reparent(sc, parentSurface->mSurfaceControl); |
| 888 | }); |
| 889 | |
| 890 | injectTap(190, 199); |
| 891 | surface->expectTapWithFlag(90, 99, AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED); |
| 892 | } |
| 893 | |
| 894 | TEST_F(InputSurfacesTest, touch_not_obscured_with_crop) { |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 895 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100, "Test Surface"); |
chaviw | 39cfa2e | 2020-11-04 14:19:02 -0800 | [diff] [blame] | 896 | surface->showAt(100, 100); |
| 897 | |
| 898 | // Add non touchable window to cover touchable window, but parent is cropped to avoid covering |
| 899 | // the touchable window. Window behind gets touch with no obscured flags. |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 900 | std::unique_ptr<InputSurface> parentSurface = makeSurface(100, 100, "Parent Surface"); |
| 901 | std::unique_ptr<InputSurface> nonTouchableSurface = |
| 902 | makeSurface(100, 100, "Non-Touchable Surface"); |
Patrick Williams | 8760216 | 2024-11-05 10:13:19 -0600 | [diff] [blame] | 903 | nonTouchableSurface->mInputInfo->editInfo() |
| 904 | ->setInputConfig(WindowInfo::InputConfig::NOT_TOUCHABLE, true); |
| 905 | parentSurface->mInputInfo->editInfo()->setInputConfig(WindowInfo::InputConfig::NOT_TOUCHABLE, |
| 906 | true); |
| 907 | nonTouchableSurface->mInputInfo->editInfo()->ownerUid = gui::Uid{22222}; |
| 908 | parentSurface->mInputInfo->editInfo()->ownerUid = gui::Uid{22222}; |
chaviw | 39cfa2e | 2020-11-04 14:19:02 -0800 | [diff] [blame] | 909 | nonTouchableSurface->showAt(0, 0); |
| 910 | parentSurface->showAt(50, 50); |
| 911 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 912 | nonTouchableSurface->doTransaction([&](auto& t, auto& sc) { |
chaviw | 2571450 | 2021-02-11 10:01:08 -0800 | [diff] [blame] | 913 | t.setCrop(parentSurface->mSurfaceControl, Rect(0, 0, 50, 50)); |
chaviw | 39cfa2e | 2020-11-04 14:19:02 -0800 | [diff] [blame] | 914 | t.reparent(sc, parentSurface->mSurfaceControl); |
| 915 | }); |
| 916 | |
| 917 | injectTap(101, 110); |
| 918 | surface->expectTap(1, 10); |
| 919 | } |
| 920 | |
chaviw | 7e72caf | 2020-12-02 16:50:43 -0800 | [diff] [blame] | 921 | TEST_F(InputSurfacesTest, touch_not_obscured_with_zero_sized_bql) { |
| 922 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
| 923 | |
| 924 | std::unique_ptr<InputSurface> bufferSurface = |
| 925 | InputSurface::makeBufferInputSurface(mComposerClient, 0, 0); |
Patrick Williams | 8760216 | 2024-11-05 10:13:19 -0600 | [diff] [blame] | 926 | bufferSurface->mInputInfo->editInfo()->setInputConfig(WindowInfo::InputConfig::NOT_TOUCHABLE, |
| 927 | true); |
| 928 | bufferSurface->mInputInfo->editInfo()->ownerUid = gui::Uid{22222}; |
chaviw | 7e72caf | 2020-12-02 16:50:43 -0800 | [diff] [blame] | 929 | |
| 930 | surface->showAt(10, 10); |
| 931 | bufferSurface->showAt(50, 50, Rect::EMPTY_RECT); |
| 932 | |
| 933 | injectTap(11, 11); |
| 934 | surface->expectTap(1, 1); |
| 935 | } |
| 936 | |
| 937 | TEST_F(InputSurfacesTest, touch_not_obscured_with_zero_sized_blast) { |
| 938 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
| 939 | |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 940 | std::unique_ptr<BlastInputSurface> bufferSurface = |
| 941 | BlastInputSurface::makeBlastInputSurface(mComposerClient, 0, 0); |
Patrick Williams | 8760216 | 2024-11-05 10:13:19 -0600 | [diff] [blame] | 942 | bufferSurface->mInputInfo->editInfo()->setInputConfig(WindowInfo::InputConfig::NOT_TOUCHABLE, |
| 943 | true); |
| 944 | bufferSurface->mInputInfo->editInfo()->ownerUid = gui::Uid{22222}; |
chaviw | 7e72caf | 2020-12-02 16:50:43 -0800 | [diff] [blame] | 945 | |
| 946 | surface->showAt(10, 10); |
| 947 | bufferSurface->showAt(50, 50, Rect::EMPTY_RECT); |
| 948 | |
| 949 | injectTap(11, 11); |
| 950 | surface->expectTap(1, 1); |
| 951 | } |
| 952 | |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 953 | TEST_F(InputSurfacesTest, strict_unobscured_input_unobscured_window) { |
| 954 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
| 955 | surface->doTransaction( |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 956 | [&](auto& t, auto& sc) { t.setDropInputMode(sc, gui::DropInputMode::OBSCURED); }); |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 957 | surface->showAt(100, 100); |
| 958 | |
| 959 | injectTap(101, 101); |
Siarhei Vishniakou | 7b3fda3 | 2024-03-29 14:27:49 -0700 | [diff] [blame] | 960 | surface->expectTap(1, 1); |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 961 | |
| 962 | surface->requestFocus(); |
| 963 | surface->assertFocusChange(true); |
| 964 | injectKey(AKEYCODE_V); |
| 965 | surface->expectKey(AKEYCODE_V); |
| 966 | } |
| 967 | |
| 968 | TEST_F(InputSurfacesTest, strict_unobscured_input_scaled_without_crop_window) { |
| 969 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 970 | surface->doTransaction([&](auto& t, auto& sc) { |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 971 | t.setDropInputMode(sc, gui::DropInputMode::OBSCURED); |
| 972 | t.setMatrix(sc, 2.0, 0, 0, 2.0); |
| 973 | }); |
| 974 | surface->showAt(100, 100); |
| 975 | |
| 976 | injectTap(101, 101); |
Siarhei Vishniakou | 7b3fda3 | 2024-03-29 14:27:49 -0700 | [diff] [blame] | 977 | surface->expectTap(.5, .5); |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 978 | |
| 979 | surface->requestFocus(); |
| 980 | surface->assertFocusChange(true); |
| 981 | injectKey(AKEYCODE_V); |
| 982 | surface->expectKey(AKEYCODE_V); |
| 983 | } |
| 984 | |
| 985 | TEST_F(InputSurfacesTest, strict_unobscured_input_obscured_window) { |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 986 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100, "Test Surface"); |
Patrick Williams | 8760216 | 2024-11-05 10:13:19 -0600 | [diff] [blame] | 987 | surface->mInputInfo->editInfo()->ownerUid = gui::Uid{11111}; |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 988 | surface->doTransaction( |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 989 | [&](auto& t, auto& sc) { t.setDropInputMode(sc, gui::DropInputMode::OBSCURED); }); |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 990 | surface->showAt(100, 100); |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 991 | std::unique_ptr<InputSurface> obscuringSurface = makeSurface(100, 100, "Obscuring Surface"); |
Patrick Williams | 8760216 | 2024-11-05 10:13:19 -0600 | [diff] [blame] | 992 | obscuringSurface->mInputInfo->editInfo()->setInputConfig(WindowInfo::InputConfig::NOT_TOUCHABLE, |
| 993 | true); |
| 994 | obscuringSurface->mInputInfo->editInfo()->ownerUid = gui::Uid{22222}; |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 995 | obscuringSurface->showAt(100, 100); |
| 996 | injectTap(101, 101); |
Siarhei Vishniakou | 7b3fda3 | 2024-03-29 14:27:49 -0700 | [diff] [blame] | 997 | surface->assertNoEvent(); |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 998 | |
| 999 | surface->requestFocus(); |
| 1000 | surface->assertFocusChange(true); |
| 1001 | injectKey(AKEYCODE_V); |
Siarhei Vishniakou | 7b3fda3 | 2024-03-29 14:27:49 -0700 | [diff] [blame] | 1002 | surface->assertNoEvent(); |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | TEST_F(InputSurfacesTest, strict_unobscured_input_partially_obscured_window) { |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 1006 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100, "Test Surface"); |
Patrick Williams | 8760216 | 2024-11-05 10:13:19 -0600 | [diff] [blame] | 1007 | surface->mInputInfo->editInfo()->ownerUid = gui::Uid{11111}; |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 1008 | surface->doTransaction( |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 1009 | [&](auto& t, auto& sc) { t.setDropInputMode(sc, gui::DropInputMode::OBSCURED); }); |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 1010 | surface->showAt(100, 100); |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 1011 | std::unique_ptr<InputSurface> obscuringSurface = makeSurface(100, 100, "Obscuring Surface"); |
Patrick Williams | 8760216 | 2024-11-05 10:13:19 -0600 | [diff] [blame] | 1012 | obscuringSurface->mInputInfo->editInfo()->setInputConfig(WindowInfo::InputConfig::NOT_TOUCHABLE, |
| 1013 | true); |
| 1014 | obscuringSurface->mInputInfo->editInfo()->ownerUid = gui::Uid{22222}; |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 1015 | obscuringSurface->showAt(190, 190); |
| 1016 | |
| 1017 | injectTap(101, 101); |
| 1018 | |
Siarhei Vishniakou | 7b3fda3 | 2024-03-29 14:27:49 -0700 | [diff] [blame] | 1019 | surface->assertNoEvent(); |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 1020 | |
| 1021 | surface->requestFocus(); |
| 1022 | surface->assertFocusChange(true); |
| 1023 | injectKey(AKEYCODE_V); |
Siarhei Vishniakou | 7b3fda3 | 2024-03-29 14:27:49 -0700 | [diff] [blame] | 1024 | surface->assertNoEvent(); |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | TEST_F(InputSurfacesTest, strict_unobscured_input_alpha_window) { |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 1028 | std::unique_ptr<InputSurface> parentSurface = makeSurface(300, 300, "Parent Surface"); |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 1029 | parentSurface->showAt(0, 0, Rect(0, 0, 300, 300)); |
| 1030 | |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 1031 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100, "Test Surface"); |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 1032 | surface->showAt(100, 100); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 1033 | surface->doTransaction([&](auto& t, auto& sc) { |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 1034 | t.setDropInputMode(sc, gui::DropInputMode::OBSCURED); |
| 1035 | t.reparent(sc, parentSurface->mSurfaceControl); |
| 1036 | t.setAlpha(parentSurface->mSurfaceControl, 0.9f); |
| 1037 | }); |
| 1038 | |
| 1039 | injectTap(101, 101); |
| 1040 | |
Siarhei Vishniakou | 7b3fda3 | 2024-03-29 14:27:49 -0700 | [diff] [blame] | 1041 | surface->assertNoEvent(); |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 1042 | |
| 1043 | surface->requestFocus(); |
| 1044 | surface->assertFocusChange(true); |
| 1045 | injectKey(AKEYCODE_V); |
Siarhei Vishniakou | 7b3fda3 | 2024-03-29 14:27:49 -0700 | [diff] [blame] | 1046 | surface->assertNoEvent(); |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | TEST_F(InputSurfacesTest, strict_unobscured_input_cropped_window) { |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 1050 | std::unique_ptr<InputSurface> parentSurface = makeSurface(300, 300, "Parent Surface"); |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 1051 | parentSurface->showAt(0, 0, Rect(0, 0, 300, 300)); |
| 1052 | |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 1053 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100, "Test Surface"); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 1054 | surface->doTransaction([&](auto& t, auto& sc) { |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 1055 | t.setDropInputMode(sc, gui::DropInputMode::OBSCURED); |
| 1056 | t.reparent(sc, parentSurface->mSurfaceControl); |
| 1057 | t.setCrop(parentSurface->mSurfaceControl, Rect(10, 10, 100, 100)); |
| 1058 | }); |
| 1059 | surface->showAt(100, 100); |
| 1060 | |
| 1061 | injectTap(111, 111); |
| 1062 | |
Siarhei Vishniakou | 7b3fda3 | 2024-03-29 14:27:49 -0700 | [diff] [blame] | 1063 | surface->assertNoEvent(); |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 1064 | |
| 1065 | surface->requestFocus(); |
| 1066 | surface->assertFocusChange(true); |
| 1067 | injectKey(AKEYCODE_V); |
Siarhei Vishniakou | 7b3fda3 | 2024-03-29 14:27:49 -0700 | [diff] [blame] | 1068 | surface->assertNoEvent(); |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 1069 | } |
| 1070 | |
Arthur Hung | 49d525a | 2021-11-19 15:11:51 +0000 | [diff] [blame] | 1071 | TEST_F(InputSurfacesTest, ignore_touch_region_with_zero_sized_blast) { |
| 1072 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
| 1073 | |
| 1074 | std::unique_ptr<BlastInputSurface> bufferSurface = |
| 1075 | BlastInputSurface::makeBlastInputSurface(mComposerClient, 0, 0); |
| 1076 | |
| 1077 | surface->showAt(100, 100); |
Patrick Williams | 8760216 | 2024-11-05 10:13:19 -0600 | [diff] [blame] | 1078 | bufferSurface->mInputInfo->editInfo()->touchableRegion.orSelf(Rect(0, 0, 200, 200)); |
Arthur Hung | 49d525a | 2021-11-19 15:11:51 +0000 | [diff] [blame] | 1079 | bufferSurface->showAt(100, 100, Rect::EMPTY_RECT); |
| 1080 | |
| 1081 | injectTap(101, 101); |
| 1082 | surface->expectTap(1, 1); |
| 1083 | } |
| 1084 | |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 1085 | TEST_F(InputSurfacesTest, drop_input_policy) { |
| 1086 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
| 1087 | surface->doTransaction( |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 1088 | [&](auto& t, auto& sc) { t.setDropInputMode(sc, gui::DropInputMode::ALL); }); |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 1089 | surface->showAt(100, 100); |
| 1090 | |
| 1091 | injectTap(101, 101); |
Siarhei Vishniakou | 7b3fda3 | 2024-03-29 14:27:49 -0700 | [diff] [blame] | 1092 | surface->assertNoEvent(); |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 1093 | |
| 1094 | surface->requestFocus(); |
| 1095 | surface->assertFocusChange(true); |
| 1096 | injectKey(AKEYCODE_V); |
Siarhei Vishniakou | 7b3fda3 | 2024-03-29 14:27:49 -0700 | [diff] [blame] | 1097 | surface->assertNoEvent(); |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 1098 | } |
Vishnu Nair | 16a938f | 2021-09-24 07:14:54 -0700 | [diff] [blame] | 1099 | |
Prabir Pradhan | 8c28598 | 2022-01-28 09:19:39 -0800 | [diff] [blame] | 1100 | TEST_F(InputSurfacesTest, layer_with_valid_crop_can_be_focused) { |
| 1101 | std::unique_ptr<InputSurface> bufferSurface = |
| 1102 | InputSurface::makeBufferInputSurface(mComposerClient, 100, 100); |
| 1103 | |
| 1104 | bufferSurface->showAt(50, 50, Rect{0, 0, 100, 100}); |
| 1105 | |
| 1106 | bufferSurface->requestFocus(); |
| 1107 | bufferSurface->assertFocusChange(true); |
| 1108 | } |
| 1109 | |
Prabir Pradhan | 6fa425a | 2021-12-16 07:16:04 -0800 | [diff] [blame] | 1110 | /** |
| 1111 | * If a cropped layer's touchable region is replaced with a null crop, it should receive input in |
| 1112 | * its own crop. |
| 1113 | */ |
| 1114 | TEST_F(InputSurfacesTest, cropped_container_replaces_touchable_region_with_null_crop) { |
| 1115 | std::unique_ptr<InputSurface> parentContainer = |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 1116 | InputSurface::makeContainerInputSurface(mComposerClient, 0, 0, |
| 1117 | "Parent Container Surface"); |
Prabir Pradhan | 6fa425a | 2021-12-16 07:16:04 -0800 | [diff] [blame] | 1118 | std::unique_ptr<InputSurface> containerSurface = |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 1119 | InputSurface::makeContainerInputSurface(mComposerClient, 100, 100, |
| 1120 | "Test Container Surface"); |
Prabir Pradhan | 6fa425a | 2021-12-16 07:16:04 -0800 | [diff] [blame] | 1121 | containerSurface->doTransaction( |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 1122 | [&](auto& t, auto& sc) { t.reparent(sc, parentContainer->mSurfaceControl); }); |
Patrick Williams | 8760216 | 2024-11-05 10:13:19 -0600 | [diff] [blame] | 1123 | containerSurface->mInputInfo->editInfo()->replaceTouchableRegionWithCrop = true; |
| 1124 | containerSurface->mInputInfo->editInfo()->touchableRegionCropHandle = nullptr; |
Prabir Pradhan | 6fa425a | 2021-12-16 07:16:04 -0800 | [diff] [blame] | 1125 | parentContainer->showAt(10, 10, Rect(0, 0, 20, 20)); |
| 1126 | containerSurface->showAt(10, 10, Rect(0, 0, 5, 5)); |
| 1127 | |
| 1128 | // Receives events inside its own crop |
| 1129 | injectTap(21, 21); |
| 1130 | containerSurface->expectTap(1, 1); // Event is in layer space |
| 1131 | |
| 1132 | // Does not receive events outside its crop |
| 1133 | injectTap(26, 26); |
Siarhei Vishniakou | 7b3fda3 | 2024-03-29 14:27:49 -0700 | [diff] [blame] | 1134 | containerSurface->assertNoEvent(); |
Prabir Pradhan | 6fa425a | 2021-12-16 07:16:04 -0800 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | /** |
| 1138 | * If an un-cropped layer's touchable region is replaced with a null crop, it should receive input |
| 1139 | * in its parent's touchable region. The input events should be in the layer's coordinate space. |
| 1140 | */ |
| 1141 | TEST_F(InputSurfacesTest, uncropped_container_replaces_touchable_region_with_null_crop) { |
Prabir Pradhan | 56d55bc | 2024-10-28 21:00:30 +0000 | [diff] [blame] | 1142 | std::unique_ptr<InputSurface> bgContainer = |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 1143 | InputSurface::makeContainerInputSurface(mComposerClient, 0, 0, |
| 1144 | "Background Container Surface"); |
Prabir Pradhan | 6fa425a | 2021-12-16 07:16:04 -0800 | [diff] [blame] | 1145 | std::unique_ptr<InputSurface> parentContainer = |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 1146 | InputSurface::makeContainerInputSurface(mComposerClient, 0, 0, |
| 1147 | "Parent Container Surface"); |
Prabir Pradhan | 6fa425a | 2021-12-16 07:16:04 -0800 | [diff] [blame] | 1148 | std::unique_ptr<InputSurface> containerSurface = |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 1149 | InputSurface::makeContainerInputSurface(mComposerClient, 100, 100, |
| 1150 | "Test Container Surface"); |
Prabir Pradhan | 6fa425a | 2021-12-16 07:16:04 -0800 | [diff] [blame] | 1151 | containerSurface->doTransaction( |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 1152 | [&](auto& t, auto& sc) { t.reparent(sc, parentContainer->mSurfaceControl); }); |
Patrick Williams | 8760216 | 2024-11-05 10:13:19 -0600 | [diff] [blame] | 1153 | containerSurface->mInputInfo->editInfo()->replaceTouchableRegionWithCrop = true; |
| 1154 | containerSurface->mInputInfo->editInfo()->touchableRegionCropHandle = nullptr; |
Prabir Pradhan | 56d55bc | 2024-10-28 21:00:30 +0000 | [diff] [blame] | 1155 | parentContainer->doTransaction( |
| 1156 | [&](auto& t, auto& sc) { t.reparent(sc, bgContainer->mSurfaceControl); }); |
| 1157 | bgContainer->showAt(0, 0, Rect(0, 0, 100, 100)); |
Prabir Pradhan | 6fa425a | 2021-12-16 07:16:04 -0800 | [diff] [blame] | 1158 | parentContainer->showAt(10, 10, Rect(0, 0, 20, 20)); |
| 1159 | containerSurface->showAt(10, 10, Rect::INVALID_RECT); |
| 1160 | |
| 1161 | // Receives events inside parent bounds |
| 1162 | injectTap(21, 21); |
| 1163 | containerSurface->expectTap(1, 1); // Event is in layer space |
| 1164 | |
| 1165 | // Does not receive events outside parent bounds |
| 1166 | injectTap(31, 31); |
Siarhei Vishniakou | 7b3fda3 | 2024-03-29 14:27:49 -0700 | [diff] [blame] | 1167 | containerSurface->assertNoEvent(); |
Prabir Pradhan | 6fa425a | 2021-12-16 07:16:04 -0800 | [diff] [blame] | 1168 | } |
| 1169 | |
| 1170 | /** |
| 1171 | * If a layer's touchable region is replaced with a layer crop, it should receive input in the crop |
| 1172 | * layer's bounds. The input events should be in the layer's coordinate space. |
| 1173 | */ |
| 1174 | TEST_F(InputSurfacesTest, replace_touchable_region_with_crop) { |
| 1175 | std::unique_ptr<InputSurface> cropLayer = |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 1176 | InputSurface::makeContainerInputSurface(mComposerClient, 0, 0, "Crop Layer Surface"); |
Prabir Pradhan | 6fa425a | 2021-12-16 07:16:04 -0800 | [diff] [blame] | 1177 | cropLayer->showAt(50, 50, Rect(0, 0, 20, 20)); |
| 1178 | |
| 1179 | std::unique_ptr<InputSurface> containerSurface = |
Arpit Singh | a9ec7d4 | 2024-12-04 14:34:05 +0000 | [diff] [blame^] | 1180 | InputSurface::makeContainerInputSurface(mComposerClient, 100, 100, "Container Surface"); |
Patrick Williams | 8760216 | 2024-11-05 10:13:19 -0600 | [diff] [blame] | 1181 | containerSurface->mInputInfo->editInfo()->replaceTouchableRegionWithCrop = true; |
| 1182 | containerSurface->mInputInfo->editInfo()->touchableRegionCropHandle = |
Prabir Pradhan | 6fa425a | 2021-12-16 07:16:04 -0800 | [diff] [blame] | 1183 | cropLayer->mSurfaceControl->getHandle(); |
| 1184 | containerSurface->showAt(10, 10, Rect::INVALID_RECT); |
| 1185 | |
| 1186 | // Receives events inside crop layer bounds |
| 1187 | injectTap(51, 51); |
| 1188 | containerSurface->expectTap(41, 41); // Event is in layer space |
| 1189 | |
| 1190 | // Does not receive events outside crop layer bounds |
| 1191 | injectTap(21, 21); |
| 1192 | injectTap(71, 71); |
Siarhei Vishniakou | 7b3fda3 | 2024-03-29 14:27:49 -0700 | [diff] [blame] | 1193 | containerSurface->assertNoEvent(); |
Prabir Pradhan | 6fa425a | 2021-12-16 07:16:04 -0800 | [diff] [blame] | 1194 | } |
| 1195 | |
Linus Tufvesson | a185882 | 2022-03-04 09:32:07 +0000 | [diff] [blame] | 1196 | TEST_F(InputSurfacesTest, child_container_with_no_input_channel_blocks_parent) { |
| 1197 | std::unique_ptr<InputSurface> parent = makeSurface(100, 100); |
| 1198 | |
| 1199 | parent->showAt(100, 100); |
| 1200 | injectTap(101, 101); |
| 1201 | parent->expectTap(1, 1); |
| 1202 | |
| 1203 | std::unique_ptr<InputSurface> childContainerSurface = |
| 1204 | InputSurface::makeContainerInputSurfaceNoInputChannel(mComposerClient, 100, 100); |
| 1205 | childContainerSurface->showAt(0, 0); |
| 1206 | childContainerSurface->doTransaction( |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 1207 | [&](auto& t, auto& sc) { t.reparent(sc, parent->mSurfaceControl); }); |
Linus Tufvesson | a185882 | 2022-03-04 09:32:07 +0000 | [diff] [blame] | 1208 | injectTap(101, 101); |
| 1209 | |
Siarhei Vishniakou | 7b3fda3 | 2024-03-29 14:27:49 -0700 | [diff] [blame] | 1210 | parent->assertNoEvent(); |
Linus Tufvesson | a185882 | 2022-03-04 09:32:07 +0000 | [diff] [blame] | 1211 | } |
| 1212 | |
Vishnu Nair | 16a938f | 2021-09-24 07:14:54 -0700 | [diff] [blame] | 1213 | class MultiDisplayTests : public InputSurfacesTest { |
| 1214 | public: |
| 1215 | MultiDisplayTests() : InputSurfacesTest() { ProcessState::self()->startThreadPool(); } |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 1216 | |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 1217 | void TearDown() override { |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 1218 | std::for_each(mVirtualDisplays.begin(), mVirtualDisplays.end(), |
| 1219 | SurfaceComposerClient::destroyVirtualDisplay); |
Vishnu Nair | 16a938f | 2021-09-24 07:14:54 -0700 | [diff] [blame] | 1220 | InputSurfacesTest::TearDown(); |
| 1221 | } |
| 1222 | |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 1223 | void createDisplay(int32_t width, int32_t height, bool isSecure, ui::LayerStack layerStack, |
| 1224 | bool receivesInput = true, int32_t offsetX = 0, int32_t offsetY = 0) { |
Vishnu Nair | 16a938f | 2021-09-24 07:14:54 -0700 | [diff] [blame] | 1225 | sp<IGraphicBufferConsumer> consumer; |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 1226 | sp<IGraphicBufferProducer> producer; |
| 1227 | BufferQueue::createBufferQueue(&producer, &consumer); |
Vishnu Nair | 16a938f | 2021-09-24 07:14:54 -0700 | [diff] [blame] | 1228 | consumer->setConsumerName(String8("Virtual disp consumer")); |
| 1229 | consumer->setDefaultBufferSize(width, height); |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 1230 | mProducers.push_back(producer); |
Vishnu Nair | 16a938f | 2021-09-24 07:14:54 -0700 | [diff] [blame] | 1231 | |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 1232 | std::string name = "VirtualDisplay"; |
| 1233 | name += std::to_string(mVirtualDisplays.size()); |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 1234 | sp<IBinder> token = SurfaceComposerClient::createVirtualDisplay(name, isSecure); |
Vishnu Nair | 16a938f | 2021-09-24 07:14:54 -0700 | [diff] [blame] | 1235 | SurfaceComposerClient::Transaction t; |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 1236 | t.setDisplaySurface(token, producer); |
| 1237 | t.setDisplayFlags(token, receivesInput ? 0x01 /* DisplayDevice::eReceivesInput */ : 0); |
| 1238 | t.setDisplayLayerStack(token, layerStack); |
| 1239 | t.setDisplayProjection(token, ui::ROTATION_0, {0, 0, width, height}, |
| 1240 | {offsetX, offsetY, offsetX + width, offsetY + height}); |
Prabir Pradhan | a97fd94 | 2024-10-28 21:21:53 +0000 | [diff] [blame] | 1241 | t.apply(/*synchronously=*/true); |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 1242 | |
| 1243 | mVirtualDisplays.push_back(token); |
Vishnu Nair | 16a938f | 2021-09-24 07:14:54 -0700 | [diff] [blame] | 1244 | } |
| 1245 | |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 1246 | std::vector<sp<IBinder>> mVirtualDisplays; |
| 1247 | std::vector<sp<IGraphicBufferProducer>> mProducers; |
Vishnu Nair | 16a938f | 2021-09-24 07:14:54 -0700 | [diff] [blame] | 1248 | }; |
| 1249 | |
Prabir Pradhan | da0f62c | 2022-07-22 19:53:04 +0000 | [diff] [blame] | 1250 | TEST_F(MultiDisplayTests, drop_touch_if_layer_on_invalid_display) { |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 1251 | ui::LayerStack layerStack = ui::LayerStack::fromValue(42); |
| 1252 | // Do not create a display associated with the LayerStack. |
| 1253 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 1254 | surface->doTransaction([&](auto& t, auto& sc) { t.setLayerStack(sc, layerStack); }); |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 1255 | surface->showAt(100, 100); |
| 1256 | |
Prabir Pradhan | da0f62c | 2022-07-22 19:53:04 +0000 | [diff] [blame] | 1257 | // Touches should be dropped if the layer is on an invalid display. |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 1258 | injectTapOnDisplay(101, 101, toDisplayId(layerStack)); |
Siarhei Vishniakou | 7b3fda3 | 2024-03-29 14:27:49 -0700 | [diff] [blame] | 1259 | surface->assertNoEvent(); |
Prabir Pradhan | da0f62c | 2022-07-22 19:53:04 +0000 | [diff] [blame] | 1260 | |
| 1261 | // However, we still let the window be focused and receive keys. |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 1262 | surface->requestFocus(toDisplayId(layerStack)); |
Prabir Pradhan | da0f62c | 2022-07-22 19:53:04 +0000 | [diff] [blame] | 1263 | surface->assertFocusChange(true); |
| 1264 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 1265 | injectKeyOnDisplay(AKEYCODE_V, toDisplayId(layerStack)); |
Prabir Pradhan | da0f62c | 2022-07-22 19:53:04 +0000 | [diff] [blame] | 1266 | surface->expectKey(AKEYCODE_V); |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | TEST_F(MultiDisplayTests, virtual_display_receives_input) { |
| 1270 | ui::LayerStack layerStack = ui::LayerStack::fromValue(42); |
| 1271 | createDisplay(1000, 1000, false /*isSecure*/, layerStack); |
| 1272 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 1273 | surface->doTransaction([&](auto& t, auto& sc) { t.setLayerStack(sc, layerStack); }); |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 1274 | surface->showAt(100, 100); |
| 1275 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 1276 | injectTapOnDisplay(101, 101, toDisplayId(layerStack)); |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 1277 | surface->expectTap(1, 1); |
| 1278 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 1279 | surface->requestFocus(toDisplayId(layerStack)); |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 1280 | surface->assertFocusChange(true); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 1281 | injectKeyOnDisplay(AKEYCODE_V, toDisplayId(layerStack)); |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 1282 | surface->expectKey(AKEYCODE_V); |
| 1283 | } |
| 1284 | |
Vishnu Nair | 16a938f | 2021-09-24 07:14:54 -0700 | [diff] [blame] | 1285 | TEST_F(MultiDisplayTests, drop_input_for_secure_layer_on_nonsecure_display) { |
| 1286 | ui::LayerStack layerStack = ui::LayerStack::fromValue(42); |
| 1287 | createDisplay(1000, 1000, false /*isSecure*/, layerStack); |
| 1288 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 1289 | surface->doTransaction([&](auto& t, auto& sc) { |
Vishnu Nair | 16a938f | 2021-09-24 07:14:54 -0700 | [diff] [blame] | 1290 | t.setFlags(sc, layer_state_t::eLayerSecure, layer_state_t::eLayerSecure); |
| 1291 | t.setLayerStack(sc, layerStack); |
| 1292 | }); |
| 1293 | surface->showAt(100, 100); |
| 1294 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 1295 | injectTapOnDisplay(101, 101, toDisplayId(layerStack)); |
Vishnu Nair | 16a938f | 2021-09-24 07:14:54 -0700 | [diff] [blame] | 1296 | |
Siarhei Vishniakou | 7b3fda3 | 2024-03-29 14:27:49 -0700 | [diff] [blame] | 1297 | surface->assertNoEvent(); |
Vishnu Nair | 16a938f | 2021-09-24 07:14:54 -0700 | [diff] [blame] | 1298 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 1299 | surface->requestFocus(toDisplayId(layerStack)); |
Vishnu Nair | 16a938f | 2021-09-24 07:14:54 -0700 | [diff] [blame] | 1300 | surface->assertFocusChange(true); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 1301 | injectKeyOnDisplay(AKEYCODE_V, toDisplayId(layerStack)); |
Siarhei Vishniakou | 7b3fda3 | 2024-03-29 14:27:49 -0700 | [diff] [blame] | 1302 | surface->assertNoEvent(); |
Vishnu Nair | 16a938f | 2021-09-24 07:14:54 -0700 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | TEST_F(MultiDisplayTests, dont_drop_input_for_secure_layer_on_secure_display) { |
| 1306 | ui::LayerStack layerStack = ui::LayerStack::fromValue(42); |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 1307 | |
| 1308 | // Create the secure display as system, because only certain users can create secure displays. |
| 1309 | seteuid(AID_SYSTEM); |
Vishnu Nair | 16a938f | 2021-09-24 07:14:54 -0700 | [diff] [blame] | 1310 | createDisplay(1000, 1000, true /*isSecure*/, layerStack); |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 1311 | // Change the uid back to root. |
| 1312 | seteuid(AID_ROOT); |
| 1313 | |
Vishnu Nair | 16a938f | 2021-09-24 07:14:54 -0700 | [diff] [blame] | 1314 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 1315 | surface->doTransaction([&](auto& t, auto& sc) { |
Vishnu Nair | 16a938f | 2021-09-24 07:14:54 -0700 | [diff] [blame] | 1316 | t.setFlags(sc, layer_state_t::eLayerSecure, layer_state_t::eLayerSecure); |
| 1317 | t.setLayerStack(sc, layerStack); |
| 1318 | }); |
| 1319 | surface->showAt(100, 100); |
| 1320 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 1321 | injectTapOnDisplay(101, 101, toDisplayId(layerStack)); |
Siarhei Vishniakou | 7b3fda3 | 2024-03-29 14:27:49 -0700 | [diff] [blame] | 1322 | surface->expectTap(1, 1); |
Vishnu Nair | 16a938f | 2021-09-24 07:14:54 -0700 | [diff] [blame] | 1323 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 1324 | surface->requestFocus(toDisplayId(layerStack)); |
Vishnu Nair | 16a938f | 2021-09-24 07:14:54 -0700 | [diff] [blame] | 1325 | surface->assertFocusChange(true); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 1326 | injectKeyOnDisplay(AKEYCODE_V, toDisplayId(layerStack)); |
Vishnu Nair | 16a938f | 2021-09-24 07:14:54 -0700 | [diff] [blame] | 1327 | |
| 1328 | surface->expectKey(AKEYCODE_V); |
| 1329 | } |
| 1330 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 1331 | } // namespace test |
| 1332 | } // namespace android |