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 | |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 27 | #include <android/native_window.h> |
| 28 | |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 29 | #include <binder/Binder.h> |
| 30 | #include <binder/IServiceManager.h> |
| 31 | #include <binder/Parcel.h> |
| 32 | #include <binder/ProcessState.h> |
| 33 | |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 34 | #include <gui/ISurfaceComposer.h> |
| 35 | #include <gui/Surface.h> |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 36 | #include <gui/SurfaceComposerClient.h> |
| 37 | #include <gui/SurfaceControl.h> |
| 38 | |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 39 | #include <android/os/IInputFlinger.h> |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 40 | #include <input/Input.h> |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 41 | #include <input/InputTransport.h> |
| 42 | #include <input/InputWindow.h> |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 43 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 44 | #include <ui/DisplayMode.h> |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 45 | #include <ui/Rect.h> |
| 46 | #include <ui/Region.h> |
| 47 | |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 48 | using android::os::IInputFlinger; |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 49 | |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 50 | using android::hardware::graphics::common::V1_1::BufferUsage; |
| 51 | |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 52 | namespace android::test { |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 53 | |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 54 | using Transaction = SurfaceComposerClient::Transaction; |
| 55 | |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 56 | sp<IInputFlinger> getInputFlinger() { |
| 57 | sp<IBinder> input(defaultServiceManager()->getService( |
| 58 | String16("inputflinger"))); |
| 59 | if (input == nullptr) { |
| 60 | ALOGE("Failed to link to input service"); |
| 61 | } else { ALOGE("Linked to input"); } |
| 62 | return interface_cast<IInputFlinger>(input); |
| 63 | } |
| 64 | |
| 65 | // We use the top 10 layers as a way to haphazardly place ourselves above anything else. |
| 66 | static const int LAYER_BASE = INT32_MAX - 10; |
Chris Ye | 6c4243b | 2020-07-22 12:07:12 -0700 | [diff] [blame] | 67 | static constexpr std::chrono::nanoseconds DISPATCHING_TIMEOUT = 5s; |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 68 | |
| 69 | class InputSurface { |
| 70 | public: |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 71 | InputSurface(const sp<SurfaceControl> &sc, int width, int height) { |
| 72 | mSurfaceControl = sc; |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 73 | |
| 74 | mInputFlinger = getInputFlinger(); |
Garfield Tan | 1560166 | 2020-09-22 15:32:38 -0700 | [diff] [blame] | 75 | mClientChannel = std::make_shared<InputChannel>(); |
| 76 | mInputFlinger->createInputChannel("testchannels", mClientChannel.get()); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 77 | |
| 78 | populateInputInfo(width, height); |
| 79 | |
| 80 | mInputConsumer = new InputConsumer(mClientChannel); |
| 81 | } |
| 82 | |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 83 | static std::unique_ptr<InputSurface> makeColorInputSurface(const sp<SurfaceComposerClient> &scc, |
| 84 | int width, int height) { |
| 85 | sp<SurfaceControl> surfaceControl = |
| 86 | scc->createSurface(String8("Test Surface"), 0 /* bufHeight */, 0 /* bufWidth */, |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 87 | PIXEL_FORMAT_RGBA_8888, |
| 88 | ISurfaceComposerClient::eFXSurfaceEffect); |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 89 | return std::make_unique<InputSurface>(surfaceControl, width, height); |
| 90 | } |
| 91 | |
| 92 | static std::unique_ptr<InputSurface> makeBufferInputSurface( |
| 93 | const sp<SurfaceComposerClient> &scc, int width, int height) { |
| 94 | sp<SurfaceControl> surfaceControl = |
| 95 | scc->createSurface(String8("Test Buffer Surface"), width, height, |
| 96 | PIXEL_FORMAT_RGBA_8888, 0 /* flags */); |
| 97 | return std::make_unique<InputSurface>(surfaceControl, width, height); |
| 98 | } |
| 99 | |
| 100 | static std::unique_ptr<InputSurface> makeContainerInputSurface( |
| 101 | const sp<SurfaceComposerClient> &scc, int width, int height) { |
| 102 | sp<SurfaceControl> surfaceControl = |
| 103 | scc->createSurface(String8("Test Container Surface"), 0 /* bufHeight */, |
| 104 | 0 /* bufWidth */, PIXEL_FORMAT_RGBA_8888, |
| 105 | ISurfaceComposerClient::eFXSurfaceContainer); |
| 106 | return std::make_unique<InputSurface>(surfaceControl, width, height); |
| 107 | } |
| 108 | |
arthurhung | b4a0f85 | 2020-06-16 11:02:50 +0800 | [diff] [blame] | 109 | static std::unique_ptr<InputSurface> makeCursorInputSurface( |
| 110 | const sp<SurfaceComposerClient> &scc, int width, int height) { |
| 111 | sp<SurfaceControl> surfaceControl = |
| 112 | scc->createSurface(String8("Test Cursor Surface"), 0 /* bufHeight */, |
| 113 | 0 /* bufWidth */, PIXEL_FORMAT_RGBA_8888, |
| 114 | ISurfaceComposerClient::eCursorWindow); |
| 115 | return std::make_unique<InputSurface>(surfaceControl, width, height); |
| 116 | } |
| 117 | |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 118 | InputEvent* consumeEvent() { |
| 119 | waitForEventAvailable(); |
| 120 | |
| 121 | InputEvent *ev; |
| 122 | uint32_t seqId; |
| 123 | status_t consumed = mInputConsumer->consume(&mInputEventFactory, true, -1, &seqId, &ev); |
| 124 | if (consumed != OK) { |
| 125 | return nullptr; |
| 126 | } |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 127 | status_t status = mInputConsumer->sendFinishedSignal(seqId, true); |
| 128 | EXPECT_EQ(OK, status) << "Could not send finished signal"; |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 129 | return ev; |
| 130 | } |
| 131 | |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 132 | void assertFocusChange(bool hasFocus) { |
| 133 | InputEvent *ev = consumeEvent(); |
| 134 | ASSERT_NE(ev, nullptr); |
| 135 | ASSERT_EQ(AINPUT_EVENT_TYPE_FOCUS, ev->getType()); |
| 136 | FocusEvent *focusEvent = static_cast<FocusEvent *>(ev); |
| 137 | EXPECT_EQ(hasFocus, focusEvent->getHasFocus()); |
| 138 | } |
| 139 | |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 140 | void expectTap(int x, int y) { |
| 141 | InputEvent* ev = consumeEvent(); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 142 | ASSERT_NE(ev, nullptr); |
| 143 | ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, ev->getType()); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 144 | MotionEvent* mev = static_cast<MotionEvent*>(ev); |
| 145 | EXPECT_EQ(AMOTION_EVENT_ACTION_DOWN, mev->getAction()); |
| 146 | EXPECT_EQ(x, mev->getX(0)); |
| 147 | EXPECT_EQ(y, mev->getY(0)); |
arthurhung | b4a0f85 | 2020-06-16 11:02:50 +0800 | [diff] [blame] | 148 | EXPECT_EQ(0, mev->getFlags() & VERIFIED_MOTION_EVENT_FLAGS); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 149 | |
| 150 | ev = consumeEvent(); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 151 | ASSERT_NE(ev, nullptr); |
| 152 | ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, ev->getType()); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 153 | mev = static_cast<MotionEvent*>(ev); |
| 154 | EXPECT_EQ(AMOTION_EVENT_ACTION_UP, mev->getAction()); |
arthurhung | b4a0f85 | 2020-06-16 11:02:50 +0800 | [diff] [blame] | 155 | EXPECT_EQ(0, mev->getFlags() & VERIFIED_MOTION_EVENT_FLAGS); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 156 | } |
| 157 | |
chaviw | 39cfa2e | 2020-11-04 14:19:02 -0800 | [diff] [blame] | 158 | void expectTapWithFlag(int x, int y, int32_t flags) { |
| 159 | InputEvent *ev = consumeEvent(); |
| 160 | ASSERT_NE(ev, nullptr); |
| 161 | ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, ev->getType()); |
| 162 | MotionEvent *mev = static_cast<MotionEvent *>(ev); |
| 163 | EXPECT_EQ(AMOTION_EVENT_ACTION_DOWN, mev->getAction()); |
| 164 | EXPECT_EQ(x, mev->getX(0)); |
| 165 | EXPECT_EQ(y, mev->getY(0)); |
| 166 | EXPECT_EQ(flags, mev->getFlags() & flags); |
| 167 | |
| 168 | ev = consumeEvent(); |
| 169 | ASSERT_NE(ev, nullptr); |
| 170 | ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, ev->getType()); |
| 171 | mev = static_cast<MotionEvent *>(ev); |
| 172 | EXPECT_EQ(AMOTION_EVENT_ACTION_UP, mev->getAction()); |
| 173 | EXPECT_EQ(flags, mev->getFlags() & flags); |
| 174 | } |
| 175 | |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 176 | virtual ~InputSurface() { |
| 177 | mInputFlinger->removeInputChannel(mClientChannel->getConnectionToken()); |
| 178 | } |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 179 | |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 180 | virtual void doTransaction( |
| 181 | std::function<void(SurfaceComposerClient::Transaction &, const sp<SurfaceControl> &)> |
| 182 | transactionBody) { |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 183 | SurfaceComposerClient::Transaction t; |
| 184 | transactionBody(t, mSurfaceControl); |
| 185 | t.apply(true); |
| 186 | } |
| 187 | |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 188 | 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] | 189 | SurfaceComposerClient::Transaction t; |
| 190 | t.show(mSurfaceControl); |
| 191 | t.setInputWindowInfo(mSurfaceControl, mInputInfo); |
| 192 | t.setLayer(mSurfaceControl, LAYER_BASE); |
| 193 | t.setPosition(mSurfaceControl, x, y); |
chaviw | 2571450 | 2021-02-11 10:01:08 -0800 | [diff] [blame] | 194 | t.setCrop(mSurfaceControl, crop); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 195 | t.setAlpha(mSurfaceControl, 1); |
| 196 | t.apply(true); |
| 197 | } |
| 198 | |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 199 | void requestFocus() { |
| 200 | SurfaceComposerClient::Transaction t; |
Vishnu Nair | 9ad0146 | 2021-01-15 12:55:14 -0800 | [diff] [blame] | 201 | FocusRequest request; |
| 202 | request.token = mInputInfo.token; |
| 203 | request.windowName = mInputInfo.name; |
| 204 | request.focusedToken = nullptr; |
| 205 | request.focusedWindowName = ""; |
| 206 | request.timestamp = systemTime(SYSTEM_TIME_MONOTONIC); |
| 207 | request.displayId = 0; |
| 208 | t.setFocusedWindow(request); |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 209 | t.apply(true); |
| 210 | } |
| 211 | |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 212 | private: |
| 213 | void waitForEventAvailable() { |
| 214 | struct pollfd fd; |
| 215 | |
| 216 | fd.fd = mClientChannel->getFd(); |
| 217 | fd.events = POLLIN; |
| 218 | poll(&fd, 1, 3000); |
| 219 | } |
| 220 | |
| 221 | void populateInputInfo(int width, int height) { |
Garfield Tan | 1560166 | 2020-09-22 15:32:38 -0700 | [diff] [blame] | 222 | mInputInfo.token = mClientChannel->getConnectionToken(); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 223 | mInputInfo.name = "Test info"; |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 224 | mInputInfo.flags = InputWindowInfo::Flag::NOT_TOUCH_MODAL; |
| 225 | mInputInfo.type = InputWindowInfo::Type::BASE_APPLICATION; |
Siarhei Vishniakou | c1ae556 | 2020-06-30 14:22:57 -0500 | [diff] [blame] | 226 | mInputInfo.dispatchingTimeout = 5s; |
Robert Carr | e07e103 | 2018-11-26 12:55:53 -0800 | [diff] [blame] | 227 | mInputInfo.globalScaleFactor = 1.0; |
Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 228 | mInputInfo.focusable = true; |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 229 | mInputInfo.hasWallpaper = false; |
| 230 | mInputInfo.paused = false; |
| 231 | |
| 232 | mInputInfo.touchableRegion.orSelf(Rect(0, 0, width, height)); |
| 233 | |
| 234 | // TODO: Fill in from SF? |
| 235 | mInputInfo.ownerPid = 11111; |
| 236 | mInputInfo.ownerUid = 11111; |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 237 | mInputInfo.displayId = 0; |
Robert Carr | 740167f | 2018-10-11 19:03:41 -0700 | [diff] [blame] | 238 | |
| 239 | InputApplicationInfo aInfo; |
| 240 | aInfo.token = new BBinder(); |
| 241 | aInfo.name = "Test app info"; |
Siarhei Vishniakou | 7062295 | 2020-07-30 11:17:23 -0500 | [diff] [blame] | 242 | aInfo.dispatchingTimeoutMillis = |
| 243 | std::chrono::duration_cast<std::chrono::milliseconds>(DISPATCHING_TIMEOUT).count(); |
Robert Carr | 740167f | 2018-10-11 19:03:41 -0700 | [diff] [blame] | 244 | |
| 245 | mInputInfo.applicationInfo = aInfo; |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 246 | } |
| 247 | public: |
| 248 | sp<SurfaceControl> mSurfaceControl; |
Siarhei Vishniakou | ce5ab08 | 2020-07-09 17:03:21 -0500 | [diff] [blame] | 249 | std::shared_ptr<InputChannel> mClientChannel; |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 250 | sp<IInputFlinger> mInputFlinger; |
| 251 | |
| 252 | InputWindowInfo mInputInfo; |
| 253 | |
| 254 | PreallocatedInputEventFactory mInputEventFactory; |
| 255 | InputConsumer* mInputConsumer; |
| 256 | }; |
| 257 | |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 258 | class BlastInputSurface : public InputSurface { |
| 259 | public: |
| 260 | BlastInputSurface(const sp<SurfaceControl> &sc, const sp<SurfaceControl> &parentSc, int width, |
| 261 | int height) |
| 262 | : InputSurface(sc, width, height) { |
| 263 | mParentSurfaceControl = parentSc; |
| 264 | } |
| 265 | |
| 266 | ~BlastInputSurface() = default; |
| 267 | |
| 268 | static std::unique_ptr<BlastInputSurface> makeBlastInputSurface( |
| 269 | const sp<SurfaceComposerClient> &scc, int width, int height) { |
| 270 | sp<SurfaceControl> parentSc = |
| 271 | scc->createSurface(String8("Test Parent Surface"), 0 /* bufHeight */, |
| 272 | 0 /* bufWidth */, PIXEL_FORMAT_RGBA_8888, |
| 273 | ISurfaceComposerClient::eFXSurfaceContainer); |
| 274 | |
| 275 | sp<SurfaceControl> surfaceControl = |
| 276 | scc->createSurface(String8("Test Buffer Surface"), width, height, |
| 277 | PIXEL_FORMAT_RGBA_8888, |
| 278 | ISurfaceComposerClient::eFXSurfaceBufferState, |
| 279 | parentSc->getHandle()); |
| 280 | return std::make_unique<BlastInputSurface>(surfaceControl, parentSc, width, height); |
| 281 | } |
| 282 | |
| 283 | void doTransaction( |
| 284 | std::function<void(SurfaceComposerClient::Transaction &, const sp<SurfaceControl> &)> |
| 285 | transactionBody) override { |
| 286 | SurfaceComposerClient::Transaction t; |
| 287 | transactionBody(t, mParentSurfaceControl); |
| 288 | t.apply(true); |
| 289 | } |
| 290 | |
| 291 | void showAt(int x, int y, Rect crop = Rect(0, 0, 100, 100)) override { |
| 292 | SurfaceComposerClient::Transaction t; |
| 293 | t.show(mParentSurfaceControl); |
| 294 | t.setLayer(mParentSurfaceControl, LAYER_BASE); |
| 295 | t.setPosition(mParentSurfaceControl, x, y); |
| 296 | t.setCrop(mParentSurfaceControl, crop); |
| 297 | |
| 298 | t.show(mSurfaceControl); |
| 299 | t.setInputWindowInfo(mSurfaceControl, mInputInfo); |
| 300 | t.setCrop(mSurfaceControl, crop); |
| 301 | t.setAlpha(mSurfaceControl, 1); |
| 302 | t.apply(true); |
| 303 | } |
| 304 | |
| 305 | private: |
| 306 | sp<SurfaceControl> mParentSurfaceControl; |
| 307 | }; |
| 308 | |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 309 | class InputSurfacesTest : public ::testing::Test { |
| 310 | public: |
| 311 | InputSurfacesTest() { |
| 312 | ProcessState::self()->startThreadPool(); |
| 313 | } |
| 314 | |
| 315 | void SetUp() { |
| 316 | mComposerClient = new SurfaceComposerClient; |
| 317 | ASSERT_EQ(NO_ERROR, mComposerClient->initCheck()); |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 318 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 319 | const auto display = mComposerClient->getInternalDisplayToken(); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 320 | ASSERT_NE(display, nullptr); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 321 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 322 | ui::DisplayMode mode; |
| 323 | ASSERT_EQ(NO_ERROR, mComposerClient->getActiveDisplayMode(display, &mode)); |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 324 | |
| 325 | // After a new buffer is queued, SurfaceFlinger is notified and will |
| 326 | // latch the new buffer on next vsync. Let's heuristically wait for 3 |
| 327 | // vsyncs. |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 328 | mBufferPostDelay = static_cast<int32_t>(1e6 / mode.refreshRate) * 3; |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | void TearDown() { |
| 332 | mComposerClient->dispose(); |
| 333 | } |
| 334 | |
| 335 | std::unique_ptr<InputSurface> makeSurface(int width, int height) { |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 336 | return InputSurface::makeColorInputSurface(mComposerClient, width, height); |
| 337 | } |
| 338 | |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 339 | void postBuffer(const sp<SurfaceControl> &layer, int32_t w, int32_t h) { |
| 340 | int64_t usageFlags = BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 341 | BufferUsage::COMPOSER_OVERLAY | BufferUsage::GPU_TEXTURE; |
| 342 | sp<GraphicBuffer> buffer = |
| 343 | new GraphicBuffer(w, h, PIXEL_FORMAT_RGBA_8888, 1, usageFlags, "test"); |
| 344 | Transaction().setBuffer(layer, buffer).apply(true); |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 345 | usleep(mBufferPostDelay); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | sp<SurfaceComposerClient> mComposerClient; |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 349 | int32_t mBufferPostDelay; |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 350 | }; |
| 351 | |
| 352 | void injectTap(int x, int y) { |
| 353 | char *buf1, *buf2; |
| 354 | asprintf(&buf1, "%d", x); |
| 355 | asprintf(&buf2, "%d", y); |
| 356 | if (fork() == 0) { |
| 357 | execlp("input", "input", "tap", buf1, buf2, NULL); |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | TEST_F(InputSurfacesTest, can_receive_input) { |
| 362 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
| 363 | surface->showAt(100, 100); |
| 364 | |
| 365 | injectTap(101, 101); |
| 366 | |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 367 | EXPECT_NE(surface->consumeEvent(), nullptr); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 368 | } |
| 369 | |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 370 | /** |
| 371 | * Set up two surfaces side-by-side. Tap each surface. |
| 372 | * Next, swap the positions of the two surfaces. Inject tap into the two |
| 373 | * original locations. Ensure that the tap is received by the surfaces in the |
| 374 | * reverse order. |
| 375 | */ |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 376 | TEST_F(InputSurfacesTest, input_respects_positioning) { |
| 377 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
| 378 | surface->showAt(100, 100); |
| 379 | |
| 380 | std::unique_ptr<InputSurface> surface2 = makeSurface(100, 100); |
| 381 | surface2->showAt(200, 200); |
| 382 | |
| 383 | injectTap(201, 201); |
| 384 | surface2->expectTap(1, 1); |
| 385 | |
| 386 | injectTap(101, 101); |
| 387 | surface->expectTap(1, 1); |
| 388 | |
| 389 | surface2->doTransaction([](auto &t, auto &sc) { |
| 390 | t.setPosition(sc, 100, 100); |
| 391 | }); |
| 392 | surface->doTransaction([](auto &t, auto &sc) { |
| 393 | t.setPosition(sc, 200, 200); |
| 394 | }); |
| 395 | |
| 396 | injectTap(101, 101); |
| 397 | surface2->expectTap(1, 1); |
| 398 | |
| 399 | injectTap(201, 201); |
| 400 | surface->expectTap(1, 1); |
| 401 | } |
| 402 | |
| 403 | TEST_F(InputSurfacesTest, input_respects_layering) { |
| 404 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
| 405 | std::unique_ptr<InputSurface> surface2 = makeSurface(100, 100); |
| 406 | |
| 407 | surface->showAt(10, 10); |
| 408 | surface2->showAt(10, 10); |
| 409 | |
| 410 | surface->doTransaction([](auto &t, auto &sc) { |
| 411 | t.setLayer(sc, LAYER_BASE + 1); |
| 412 | }); |
| 413 | |
| 414 | injectTap(11, 11); |
| 415 | surface->expectTap(1, 1); |
| 416 | |
| 417 | surface2->doTransaction([](auto &t, auto &sc) { |
| 418 | t.setLayer(sc, LAYER_BASE + 1); |
| 419 | }); |
| 420 | |
| 421 | injectTap(11, 11); |
| 422 | surface2->expectTap(1, 1); |
| 423 | |
| 424 | surface2->doTransaction([](auto &t, auto &sc) { |
| 425 | t.hide(sc); |
| 426 | }); |
| 427 | |
| 428 | injectTap(11, 11); |
| 429 | surface->expectTap(1, 1); |
| 430 | } |
| 431 | |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 432 | // Surface Insets are set to offset the client content and draw a border around the client surface |
| 433 | // (such as shadows in dialogs). Inputs sent to the client are offset such that 0,0 is the start |
| 434 | // of the client content. |
| 435 | TEST_F(InputSurfacesTest, input_respects_surface_insets) { |
| 436 | std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100); |
| 437 | std::unique_ptr<InputSurface> fgSurface = makeSurface(100, 100); |
| 438 | bgSurface->showAt(100, 100); |
| 439 | |
| 440 | fgSurface->mInputInfo.surfaceInset = 5; |
| 441 | fgSurface->showAt(100, 100); |
| 442 | |
| 443 | injectTap(106, 106); |
| 444 | fgSurface->expectTap(1, 1); |
| 445 | |
| 446 | injectTap(101, 101); |
| 447 | bgSurface->expectTap(1, 1); |
| 448 | } |
| 449 | |
| 450 | // Ensure a surface whose insets are cropped, handles the touch offset correctly. ref:b/120413463 |
| 451 | TEST_F(InputSurfacesTest, input_respects_cropped_surface_insets) { |
| 452 | std::unique_ptr<InputSurface> parentSurface = makeSurface(100, 100); |
| 453 | std::unique_ptr<InputSurface> childSurface = makeSurface(100, 100); |
| 454 | parentSurface->showAt(100, 100); |
| 455 | |
| 456 | childSurface->mInputInfo.surfaceInset = 10; |
| 457 | childSurface->showAt(100, 100); |
| 458 | |
| 459 | childSurface->doTransaction([&](auto &t, auto &sc) { |
| 460 | t.setPosition(sc, -5, -5); |
Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame] | 461 | t.reparent(sc, parentSurface->mSurfaceControl); |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 462 | }); |
| 463 | |
| 464 | injectTap(106, 106); |
| 465 | childSurface->expectTap(1, 1); |
| 466 | |
| 467 | injectTap(101, 101); |
| 468 | parentSurface->expectTap(1, 1); |
| 469 | } |
| 470 | |
Arthur Hung | 118b114 | 2019-05-08 21:25:59 +0800 | [diff] [blame] | 471 | // Ensure a surface whose insets are scaled, handles the touch offset correctly. |
| 472 | TEST_F(InputSurfacesTest, input_respects_scaled_surface_insets) { |
| 473 | std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100); |
| 474 | std::unique_ptr<InputSurface> fgSurface = makeSurface(100, 100); |
| 475 | bgSurface->showAt(100, 100); |
| 476 | |
| 477 | fgSurface->mInputInfo.surfaceInset = 5; |
| 478 | fgSurface->showAt(100, 100); |
| 479 | |
| 480 | fgSurface->doTransaction([&](auto &t, auto &sc) { t.setMatrix(sc, 2.0, 0, 0, 4.0); }); |
| 481 | |
| 482 | // expect = touch / scale - inset |
| 483 | injectTap(112, 124); |
| 484 | fgSurface->expectTap(1, 1); |
| 485 | |
| 486 | injectTap(101, 101); |
| 487 | bgSurface->expectTap(1, 1); |
| 488 | } |
| 489 | |
Ady Abraham | 282f1d7 | 2019-07-24 18:05:56 -0700 | [diff] [blame] | 490 | TEST_F(InputSurfacesTest, input_respects_scaled_surface_insets_overflow) { |
| 491 | std::unique_ptr<InputSurface> fgSurface = makeSurface(100, 100); |
| 492 | // In case we pass the very big inset without any checking. |
| 493 | fgSurface->mInputInfo.surfaceInset = INT32_MAX; |
| 494 | fgSurface->showAt(100, 100); |
| 495 | |
| 496 | fgSurface->doTransaction([&](auto &t, auto &sc) { t.setMatrix(sc, 2.0, 0, 0, 2.0); }); |
| 497 | |
| 498 | // expect no crash for overflow, and inset size to be clamped to surface size |
| 499 | injectTap(202, 202); |
| 500 | fgSurface->expectTap(1, 1); |
| 501 | } |
| 502 | |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 503 | // Ensure we ignore transparent region when getting screen bounds when positioning input frame. |
| 504 | TEST_F(InputSurfacesTest, input_ignores_transparent_region) { |
| 505 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
| 506 | surface->doTransaction([](auto &t, auto &sc) { |
| 507 | Region transparentRegion(Rect(0, 0, 10, 10)); |
| 508 | t.setTransparentRegionHint(sc, transparentRegion); |
| 509 | }); |
| 510 | surface->showAt(100, 100); |
| 511 | injectTap(101, 101); |
| 512 | surface->expectTap(1, 1); |
| 513 | } |
| 514 | |
Vishnu Nair | f8678ba | 2019-10-11 18:11:26 -0700 | [diff] [blame] | 515 | // TODO(b/139494112) update tests once we define expected behavior |
| 516 | // Ensure we still send input to the surface regardless of surface visibility changes due to the |
| 517 | // first buffer being submitted or alpha changes. |
| 518 | // Original bug ref: b/120839715 |
| 519 | TEST_F(InputSurfacesTest, input_ignores_buffer_layer_buffer) { |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 520 | std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100); |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 521 | std::unique_ptr<BlastInputSurface> bufferSurface = |
| 522 | BlastInputSurface::makeBlastInputSurface(mComposerClient, 100, 100); |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 523 | |
| 524 | bgSurface->showAt(10, 10); |
| 525 | bufferSurface->showAt(10, 10); |
| 526 | |
| 527 | injectTap(11, 11); |
Vishnu Nair | f8678ba | 2019-10-11 18:11:26 -0700 | [diff] [blame] | 528 | bufferSurface->expectTap(1, 1); |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 529 | |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 530 | postBuffer(bufferSurface->mSurfaceControl, 100, 100); |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 531 | injectTap(11, 11); |
| 532 | bufferSurface->expectTap(1, 1); |
| 533 | } |
| 534 | |
Vishnu Nair | f8678ba | 2019-10-11 18:11:26 -0700 | [diff] [blame] | 535 | TEST_F(InputSurfacesTest, input_ignores_buffer_layer_alpha) { |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 536 | std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100); |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 537 | std::unique_ptr<BlastInputSurface> bufferSurface = |
| 538 | BlastInputSurface::makeBlastInputSurface(mComposerClient, 100, 100); |
| 539 | postBuffer(bufferSurface->mSurfaceControl, 100, 100); |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 540 | |
| 541 | bgSurface->showAt(10, 10); |
| 542 | bufferSurface->showAt(10, 10); |
| 543 | |
| 544 | injectTap(11, 11); |
| 545 | bufferSurface->expectTap(1, 1); |
| 546 | |
| 547 | bufferSurface->doTransaction([](auto &t, auto &sc) { t.setAlpha(sc, 0.0); }); |
| 548 | |
| 549 | injectTap(11, 11); |
Vishnu Nair | f8678ba | 2019-10-11 18:11:26 -0700 | [diff] [blame] | 550 | bufferSurface->expectTap(1, 1); |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 551 | } |
| 552 | |
Vishnu Nair | f8678ba | 2019-10-11 18:11:26 -0700 | [diff] [blame] | 553 | TEST_F(InputSurfacesTest, input_ignores_color_layer_alpha) { |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 554 | std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100); |
| 555 | std::unique_ptr<InputSurface> fgSurface = makeSurface(100, 100); |
| 556 | |
| 557 | bgSurface->showAt(10, 10); |
| 558 | fgSurface->showAt(10, 10); |
| 559 | |
| 560 | injectTap(11, 11); |
| 561 | fgSurface->expectTap(1, 1); |
| 562 | |
| 563 | fgSurface->doTransaction([](auto &t, auto &sc) { t.setAlpha(sc, 0.0); }); |
| 564 | |
| 565 | injectTap(11, 11); |
Vishnu Nair | f8678ba | 2019-10-11 18:11:26 -0700 | [diff] [blame] | 566 | fgSurface->expectTap(1, 1); |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | TEST_F(InputSurfacesTest, input_respects_container_layer_visiblity) { |
| 570 | std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100); |
| 571 | std::unique_ptr<InputSurface> containerSurface = |
| 572 | InputSurface::makeContainerInputSurface(mComposerClient, 100, 100); |
| 573 | |
| 574 | bgSurface->showAt(10, 10); |
| 575 | containerSurface->showAt(10, 10); |
| 576 | |
| 577 | injectTap(11, 11); |
| 578 | containerSurface->expectTap(1, 1); |
| 579 | |
| 580 | containerSurface->doTransaction([](auto &t, auto &sc) { t.hide(sc); }); |
| 581 | |
| 582 | injectTap(11, 11); |
| 583 | bgSurface->expectTap(1, 1); |
| 584 | } |
chaviw | fbe5d9c | 2018-12-26 12:23:37 -0800 | [diff] [blame] | 585 | |
Arthur Hung | d20b270 | 2019-01-14 18:16:16 +0800 | [diff] [blame] | 586 | TEST_F(InputSurfacesTest, input_respects_outscreen) { |
| 587 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
| 588 | surface->showAt(-1, -1); |
| 589 | |
| 590 | injectTap(0, 0); |
| 591 | surface->expectTap(1, 1); |
| 592 | } |
arthurhung | b4a0f85 | 2020-06-16 11:02:50 +0800 | [diff] [blame] | 593 | |
| 594 | TEST_F(InputSurfacesTest, input_ignores_cursor_layer) { |
| 595 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
| 596 | std::unique_ptr<InputSurface> cursorSurface = |
| 597 | InputSurface::makeCursorInputSurface(mComposerClient, 10, 10); |
| 598 | |
| 599 | surface->showAt(10, 10); |
arthurhung | b4a0f85 | 2020-06-16 11:02:50 +0800 | [diff] [blame] | 600 | cursorSurface->showAt(10, 10); |
| 601 | |
| 602 | injectTap(11, 11); |
| 603 | surface->expectTap(1, 1); |
| 604 | } |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 605 | |
| 606 | TEST_F(InputSurfacesTest, can_be_focused) { |
| 607 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
| 608 | surface->showAt(100, 100); |
| 609 | surface->requestFocus(); |
| 610 | |
| 611 | surface->assertFocusChange(true); |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 612 | } |
chaviw | 44a6d2b | 2020-09-08 17:14:16 -0700 | [diff] [blame] | 613 | |
| 614 | TEST_F(InputSurfacesTest, rotate_surface) { |
| 615 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
| 616 | surface->showAt(10, 10); |
| 617 | surface->doTransaction([](auto &t, auto &sc) { |
| 618 | t.setMatrix(sc, 0, 1, -1, 0); // 90 degrees |
| 619 | }); |
| 620 | injectTap(8, 11); |
| 621 | surface->expectTap(1, 2); |
| 622 | |
| 623 | surface->doTransaction([](auto &t, auto &sc) { |
| 624 | t.setMatrix(sc, -1, 0, 0, -1); // 180 degrees |
| 625 | }); |
| 626 | injectTap(9, 8); |
| 627 | surface->expectTap(1, 2); |
| 628 | |
| 629 | surface->doTransaction([](auto &t, auto &sc) { |
| 630 | t.setMatrix(sc, 0, -1, 1, 0); // 270 degrees |
| 631 | }); |
| 632 | injectTap(12, 9); |
| 633 | surface->expectTap(1, 2); |
| 634 | } |
| 635 | |
| 636 | TEST_F(InputSurfacesTest, rotate_surface_with_scale) { |
| 637 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
| 638 | surface->showAt(10, 10); |
| 639 | surface->doTransaction([](auto &t, auto &sc) { |
| 640 | t.setMatrix(sc, 0, 2, -4, 0); // 90 degrees |
| 641 | }); |
| 642 | injectTap(2, 12); |
| 643 | surface->expectTap(1, 2); |
| 644 | |
| 645 | surface->doTransaction([](auto &t, auto &sc) { |
| 646 | t.setMatrix(sc, -2, 0, 0, -4); // 180 degrees |
| 647 | }); |
| 648 | injectTap(8, 2); |
| 649 | surface->expectTap(1, 2); |
| 650 | |
| 651 | surface->doTransaction([](auto &t, auto &sc) { |
| 652 | t.setMatrix(sc, 0, -2, 4, 0); // 270 degrees |
| 653 | }); |
| 654 | injectTap(18, 8); |
| 655 | surface->expectTap(1, 2); |
| 656 | } |
| 657 | |
| 658 | TEST_F(InputSurfacesTest, rotate_surface_with_scale_and_insets) { |
| 659 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
| 660 | surface->mInputInfo.surfaceInset = 5; |
| 661 | surface->showAt(100, 100); |
| 662 | |
| 663 | surface->doTransaction([](auto &t, auto &sc) { |
| 664 | t.setMatrix(sc, 0, 2, -4, 0); // 90 degrees |
| 665 | }); |
| 666 | injectTap(40, 120); |
| 667 | surface->expectTap(5, 10); |
| 668 | |
| 669 | surface->doTransaction([](auto &t, auto &sc) { |
| 670 | t.setMatrix(sc, -2, 0, 0, -4); // 180 degrees |
| 671 | }); |
| 672 | injectTap(80, 40); |
| 673 | surface->expectTap(5, 10); |
| 674 | |
| 675 | surface->doTransaction([](auto &t, auto &sc) { |
| 676 | t.setMatrix(sc, 0, -2, 4, 0); // 270 degrees |
| 677 | }); |
| 678 | injectTap(160, 80); |
| 679 | surface->expectTap(5, 10); |
| 680 | } |
| 681 | |
chaviw | 39cfa2e | 2020-11-04 14:19:02 -0800 | [diff] [blame] | 682 | TEST_F(InputSurfacesTest, touch_flag_obscured) { |
| 683 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
| 684 | surface->showAt(100, 100); |
| 685 | |
| 686 | // Add non touchable window to fully cover touchable window. Window behind gets touch, but |
| 687 | // with flag AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED |
| 688 | std::unique_ptr<InputSurface> nonTouchableSurface = makeSurface(100, 100); |
| 689 | nonTouchableSurface->mInputInfo.flags = InputWindowInfo::Flag::NOT_TOUCHABLE; |
| 690 | nonTouchableSurface->mInputInfo.ownerUid = 22222; |
Bernardo Rufino | 602ef71 | 2020-12-21 11:02:18 +0000 | [diff] [blame] | 691 | // Overriding occlusion mode otherwise the touch would be discarded at InputDispatcher by |
| 692 | // the default obscured/untrusted touch filter introduced in S. |
| 693 | nonTouchableSurface->mInputInfo.touchOcclusionMode = TouchOcclusionMode::ALLOW; |
chaviw | 39cfa2e | 2020-11-04 14:19:02 -0800 | [diff] [blame] | 694 | nonTouchableSurface->showAt(100, 100); |
| 695 | |
| 696 | injectTap(190, 199); |
| 697 | surface->expectTapWithFlag(90, 99, AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED); |
| 698 | } |
| 699 | |
| 700 | TEST_F(InputSurfacesTest, touch_flag_partially_obscured_with_crop) { |
| 701 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
| 702 | surface->showAt(100, 100); |
| 703 | |
| 704 | // Add non touchable window to cover touchable window, but parent is cropped to not cover area |
| 705 | // that will be tapped. Window behind gets touch, but with flag |
| 706 | // AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED |
| 707 | std::unique_ptr<InputSurface> parentSurface = makeSurface(100, 100); |
| 708 | std::unique_ptr<InputSurface> nonTouchableSurface = makeSurface(100, 100); |
| 709 | nonTouchableSurface->mInputInfo.flags = InputWindowInfo::Flag::NOT_TOUCHABLE; |
| 710 | parentSurface->mInputInfo.flags = InputWindowInfo::Flag::NOT_TOUCHABLE; |
| 711 | nonTouchableSurface->mInputInfo.ownerUid = 22222; |
| 712 | parentSurface->mInputInfo.ownerUid = 22222; |
| 713 | nonTouchableSurface->showAt(0, 0); |
| 714 | parentSurface->showAt(100, 100); |
| 715 | |
| 716 | nonTouchableSurface->doTransaction([&](auto &t, auto &sc) { |
chaviw | 2571450 | 2021-02-11 10:01:08 -0800 | [diff] [blame] | 717 | t.setCrop(parentSurface->mSurfaceControl, Rect(0, 0, 50, 50)); |
chaviw | 39cfa2e | 2020-11-04 14:19:02 -0800 | [diff] [blame] | 718 | t.reparent(sc, parentSurface->mSurfaceControl); |
| 719 | }); |
| 720 | |
| 721 | injectTap(190, 199); |
| 722 | surface->expectTapWithFlag(90, 99, AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED); |
| 723 | } |
| 724 | |
| 725 | TEST_F(InputSurfacesTest, touch_not_obscured_with_crop) { |
| 726 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
| 727 | surface->showAt(100, 100); |
| 728 | |
| 729 | // Add non touchable window to cover touchable window, but parent is cropped to avoid covering |
| 730 | // the touchable window. Window behind gets touch with no obscured flags. |
| 731 | std::unique_ptr<InputSurface> parentSurface = makeSurface(100, 100); |
| 732 | std::unique_ptr<InputSurface> nonTouchableSurface = makeSurface(100, 100); |
| 733 | nonTouchableSurface->mInputInfo.flags = InputWindowInfo::Flag::NOT_TOUCHABLE; |
| 734 | parentSurface->mInputInfo.flags = InputWindowInfo::Flag::NOT_TOUCHABLE; |
| 735 | nonTouchableSurface->mInputInfo.ownerUid = 22222; |
| 736 | parentSurface->mInputInfo.ownerUid = 22222; |
| 737 | nonTouchableSurface->showAt(0, 0); |
| 738 | parentSurface->showAt(50, 50); |
| 739 | |
| 740 | nonTouchableSurface->doTransaction([&](auto &t, auto &sc) { |
chaviw | 2571450 | 2021-02-11 10:01:08 -0800 | [diff] [blame] | 741 | t.setCrop(parentSurface->mSurfaceControl, Rect(0, 0, 50, 50)); |
chaviw | 39cfa2e | 2020-11-04 14:19:02 -0800 | [diff] [blame] | 742 | t.reparent(sc, parentSurface->mSurfaceControl); |
| 743 | }); |
| 744 | |
| 745 | injectTap(101, 110); |
| 746 | surface->expectTap(1, 10); |
| 747 | } |
| 748 | |
chaviw | 7e72caf | 2020-12-02 16:50:43 -0800 | [diff] [blame] | 749 | TEST_F(InputSurfacesTest, touch_not_obscured_with_zero_sized_bql) { |
| 750 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
| 751 | |
| 752 | std::unique_ptr<InputSurface> bufferSurface = |
| 753 | InputSurface::makeBufferInputSurface(mComposerClient, 0, 0); |
| 754 | bufferSurface->mInputInfo.flags = InputWindowInfo::Flag::NOT_TOUCHABLE; |
| 755 | bufferSurface->mInputInfo.ownerUid = 22222; |
| 756 | |
| 757 | surface->showAt(10, 10); |
| 758 | bufferSurface->showAt(50, 50, Rect::EMPTY_RECT); |
| 759 | |
| 760 | injectTap(11, 11); |
| 761 | surface->expectTap(1, 1); |
| 762 | } |
| 763 | |
| 764 | TEST_F(InputSurfacesTest, touch_not_obscured_with_zero_sized_blast) { |
| 765 | std::unique_ptr<InputSurface> surface = makeSurface(100, 100); |
| 766 | |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 767 | std::unique_ptr<BlastInputSurface> bufferSurface = |
| 768 | BlastInputSurface::makeBlastInputSurface(mComposerClient, 0, 0); |
chaviw | 7e72caf | 2020-12-02 16:50:43 -0800 | [diff] [blame] | 769 | bufferSurface->mInputInfo.flags = InputWindowInfo::Flag::NOT_TOUCHABLE; |
| 770 | bufferSurface->mInputInfo.ownerUid = 22222; |
| 771 | |
| 772 | surface->showAt(10, 10); |
| 773 | bufferSurface->showAt(50, 50, Rect::EMPTY_RECT); |
| 774 | |
| 775 | injectTap(11, 11); |
| 776 | surface->expectTap(1, 1); |
| 777 | } |
| 778 | |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 779 | } // namespace android::test |