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