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