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