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