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