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