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