blob: 1a623e21dc131bafa303ef9ed17e59361a51e573 [file] [log] [blame]
Robert Carr1c4c5592018-09-24 13:18:43 -07001/*
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 Nairde19f852018-12-18 16:11:53 -080027#include <android/native_window.h>
28
Robert Carr1c4c5592018-09-24 13:18:43 -070029#include <binder/Binder.h>
30#include <binder/IServiceManager.h>
31#include <binder/Parcel.h>
32#include <binder/ProcessState.h>
33
Vishnu Nairde19f852018-12-18 16:11:53 -080034#include <gui/ISurfaceComposer.h>
35#include <gui/Surface.h>
Robert Carr1c4c5592018-09-24 13:18:43 -070036#include <gui/SurfaceComposerClient.h>
37#include <gui/SurfaceControl.h>
38
39#include <input/InputWindow.h>
40#include <input/IInputFlinger.h>
41#include <input/InputTransport.h>
42#include <input/Input.h>
43
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080044#include <ui/DisplayConfig.h>
Robert Carr1c4c5592018-09-24 13:18:43 -070045#include <ui/Rect.h>
46#include <ui/Region.h>
47
48
49namespace android {
50namespace test {
51
Vishnu Nairde19f852018-12-18 16:11:53 -080052using Transaction = SurfaceComposerClient::Transaction;
53
Robert Carr1c4c5592018-09-24 13:18:43 -070054sp<IInputFlinger> getInputFlinger() {
55 sp<IBinder> input(defaultServiceManager()->getService(
56 String16("inputflinger")));
57 if (input == nullptr) {
58 ALOGE("Failed to link to input service");
59 } else { ALOGE("Linked to input"); }
60 return interface_cast<IInputFlinger>(input);
61}
62
63// We use the top 10 layers as a way to haphazardly place ourselves above anything else.
64static const int LAYER_BASE = INT32_MAX - 10;
65
66class InputSurface {
67public:
Vishnu Nairde19f852018-12-18 16:11:53 -080068 InputSurface(const sp<SurfaceControl> &sc, int width, int height) {
69 mSurfaceControl = sc;
Robert Carr1c4c5592018-09-24 13:18:43 -070070
71 InputChannel::openInputChannelPair("testchannels", mServerChannel, mClientChannel);
Robert Carr1c4c5592018-09-24 13:18:43 -070072
73 mInputFlinger = getInputFlinger();
74 mInputFlinger->registerInputChannel(mServerChannel);
75
76 populateInputInfo(width, height);
77
78 mInputConsumer = new InputConsumer(mClientChannel);
79 }
80
Vishnu Nairde19f852018-12-18 16:11:53 -080081 static std::unique_ptr<InputSurface> makeColorInputSurface(const sp<SurfaceComposerClient> &scc,
82 int width, int height) {
83 sp<SurfaceControl> surfaceControl =
84 scc->createSurface(String8("Test Surface"), 0 /* bufHeight */, 0 /* bufWidth */,
85 PIXEL_FORMAT_RGBA_8888, ISurfaceComposerClient::eFXSurfaceColor);
86 return std::make_unique<InputSurface>(surfaceControl, width, height);
87 }
88
89 static std::unique_ptr<InputSurface> makeBufferInputSurface(
90 const sp<SurfaceComposerClient> &scc, int width, int height) {
91 sp<SurfaceControl> surfaceControl =
92 scc->createSurface(String8("Test Buffer Surface"), width, height,
93 PIXEL_FORMAT_RGBA_8888, 0 /* flags */);
94 return std::make_unique<InputSurface>(surfaceControl, width, height);
95 }
96
97 static std::unique_ptr<InputSurface> makeContainerInputSurface(
98 const sp<SurfaceComposerClient> &scc, int width, int height) {
99 sp<SurfaceControl> surfaceControl =
100 scc->createSurface(String8("Test Container Surface"), 0 /* bufHeight */,
101 0 /* bufWidth */, PIXEL_FORMAT_RGBA_8888,
102 ISurfaceComposerClient::eFXSurfaceContainer);
103 return std::make_unique<InputSurface>(surfaceControl, width, height);
104 }
105
Robert Carr1c4c5592018-09-24 13:18:43 -0700106 InputEvent* consumeEvent() {
107 waitForEventAvailable();
108
109 InputEvent *ev;
110 uint32_t seqId;
111 status_t consumed = mInputConsumer->consume(&mInputEventFactory, true, -1, &seqId, &ev);
112 if (consumed != OK) {
113 return nullptr;
114 }
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100115 status_t status = mInputConsumer->sendFinishedSignal(seqId, true);
116 EXPECT_EQ(OK, status) << "Could not send finished signal";
Robert Carr1c4c5592018-09-24 13:18:43 -0700117 return ev;
118 }
119
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100120 void assertFocusChange(bool hasFocus) {
121 InputEvent *ev = consumeEvent();
122 ASSERT_NE(ev, nullptr);
123 ASSERT_EQ(AINPUT_EVENT_TYPE_FOCUS, ev->getType());
124 FocusEvent *focusEvent = static_cast<FocusEvent *>(ev);
125 EXPECT_EQ(hasFocus, focusEvent->getHasFocus());
126 }
127
Robert Carr1c4c5592018-09-24 13:18:43 -0700128 void expectTap(int x, int y) {
129 InputEvent* ev = consumeEvent();
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100130 ASSERT_NE(ev, nullptr);
131 ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, ev->getType());
Robert Carr1c4c5592018-09-24 13:18:43 -0700132 MotionEvent* mev = static_cast<MotionEvent*>(ev);
133 EXPECT_EQ(AMOTION_EVENT_ACTION_DOWN, mev->getAction());
134 EXPECT_EQ(x, mev->getX(0));
135 EXPECT_EQ(y, mev->getY(0));
136
137 ev = consumeEvent();
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100138 ASSERT_NE(ev, nullptr);
139 ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, ev->getType());
Robert Carr1c4c5592018-09-24 13:18:43 -0700140 mev = static_cast<MotionEvent*>(ev);
141 EXPECT_EQ(AMOTION_EVENT_ACTION_UP, mev->getAction());
142 }
143
144 ~InputSurface() {
145 mInputFlinger->unregisterInputChannel(mServerChannel);
146 }
147
148 void doTransaction(std::function<void(SurfaceComposerClient::Transaction&,
149 const sp<SurfaceControl>&)> transactionBody) {
150 SurfaceComposerClient::Transaction t;
151 transactionBody(t, mSurfaceControl);
152 t.apply(true);
153 }
154
155 void showAt(int x, int y) {
156 SurfaceComposerClient::Transaction t;
157 t.show(mSurfaceControl);
158 t.setInputWindowInfo(mSurfaceControl, mInputInfo);
159 t.setLayer(mSurfaceControl, LAYER_BASE);
160 t.setPosition(mSurfaceControl, x, y);
161 t.setCrop_legacy(mSurfaceControl, Rect(0, 0, 100, 100));
162 t.setAlpha(mSurfaceControl, 1);
163 t.apply(true);
164 }
165
166private:
167 void waitForEventAvailable() {
168 struct pollfd fd;
169
170 fd.fd = mClientChannel->getFd();
171 fd.events = POLLIN;
172 poll(&fd, 1, 3000);
173 }
174
175 void populateInputInfo(int width, int height) {
Siarhei Vishniakou26d3cfb2019-10-15 17:02:32 -0700176 mInputInfo.token = mServerChannel->getConnectionToken();
Robert Carr1c4c5592018-09-24 13:18:43 -0700177 mInputInfo.name = "Test info";
178 mInputInfo.layoutParamsFlags = InputWindowInfo::FLAG_NOT_TOUCH_MODAL;
179 mInputInfo.layoutParamsType = InputWindowInfo::TYPE_BASE_APPLICATION;
180 mInputInfo.dispatchingTimeout = 100000;
Robert Carre07e1032018-11-26 12:55:53 -0800181 mInputInfo.globalScaleFactor = 1.0;
Robert Carr1c4c5592018-09-24 13:18:43 -0700182 mInputInfo.canReceiveKeys = true;
183 mInputInfo.hasFocus = true;
184 mInputInfo.hasWallpaper = false;
185 mInputInfo.paused = false;
186
187 mInputInfo.touchableRegion.orSelf(Rect(0, 0, width, height));
188
189 // TODO: Fill in from SF?
190 mInputInfo.ownerPid = 11111;
191 mInputInfo.ownerUid = 11111;
192 mInputInfo.inputFeatures = 0;
193 mInputInfo.displayId = 0;
Robert Carr740167f2018-10-11 19:03:41 -0700194
195 InputApplicationInfo aInfo;
196 aInfo.token = new BBinder();
197 aInfo.name = "Test app info";
198 aInfo.dispatchingTimeout = 100000;
199
200 mInputInfo.applicationInfo = aInfo;
Robert Carr1c4c5592018-09-24 13:18:43 -0700201 }
202public:
203 sp<SurfaceControl> mSurfaceControl;
204 sp<InputChannel> mServerChannel, mClientChannel;
205 sp<IInputFlinger> mInputFlinger;
206
207 InputWindowInfo mInputInfo;
208
209 PreallocatedInputEventFactory mInputEventFactory;
210 InputConsumer* mInputConsumer;
211};
212
213class InputSurfacesTest : public ::testing::Test {
214public:
215 InputSurfacesTest() {
216 ProcessState::self()->startThreadPool();
217 }
218
219 void SetUp() {
220 mComposerClient = new SurfaceComposerClient;
221 ASSERT_EQ(NO_ERROR, mComposerClient->initCheck());
Vishnu Nairde19f852018-12-18 16:11:53 -0800222
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800223 const auto display = mComposerClient->getInternalDisplayToken();
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100224 ASSERT_NE(display, nullptr);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800225
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800226 DisplayConfig config;
227 ASSERT_EQ(NO_ERROR, mComposerClient->getActiveDisplayConfig(display, &config));
Vishnu Nairde19f852018-12-18 16:11:53 -0800228
229 // After a new buffer is queued, SurfaceFlinger is notified and will
230 // latch the new buffer on next vsync. Let's heuristically wait for 3
231 // vsyncs.
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800232 mBufferPostDelay = static_cast<int32_t>(1e6 / config.refreshRate) * 3;
Robert Carr1c4c5592018-09-24 13:18:43 -0700233 }
234
235 void TearDown() {
236 mComposerClient->dispose();
237 }
238
239 std::unique_ptr<InputSurface> makeSurface(int width, int height) {
Vishnu Nairde19f852018-12-18 16:11:53 -0800240 return InputSurface::makeColorInputSurface(mComposerClient, width, height);
241 }
242
243 void postBuffer(const sp<SurfaceControl> &layer) {
244 // wait for previous transactions (such as setSize) to complete
245 Transaction().apply(true);
246 ANativeWindow_Buffer buffer = {};
247 EXPECT_EQ(NO_ERROR, layer->getSurface()->lock(&buffer, nullptr));
248 ASSERT_EQ(NO_ERROR, layer->getSurface()->unlockAndPost());
249 // Request an empty transaction to get applied synchronously to ensure the buffer is
250 // latched.
251 Transaction().apply(true);
252 usleep(mBufferPostDelay);
Robert Carr1c4c5592018-09-24 13:18:43 -0700253 }
254
255 sp<SurfaceComposerClient> mComposerClient;
Vishnu Nairde19f852018-12-18 16:11:53 -0800256 int32_t mBufferPostDelay;
Robert Carr1c4c5592018-09-24 13:18:43 -0700257};
258
259void injectTap(int x, int y) {
260 char *buf1, *buf2;
261 asprintf(&buf1, "%d", x);
262 asprintf(&buf2, "%d", y);
263 if (fork() == 0) {
264 execlp("input", "input", "tap", buf1, buf2, NULL);
265 }
266}
267
268TEST_F(InputSurfacesTest, can_receive_input) {
269 std::unique_ptr<InputSurface> surface = makeSurface(100, 100);
270 surface->showAt(100, 100);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100271 surface->assertFocusChange(true);
Robert Carr1c4c5592018-09-24 13:18:43 -0700272
273 injectTap(101, 101);
274
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100275 EXPECT_NE(surface->consumeEvent(), nullptr);
Robert Carr1c4c5592018-09-24 13:18:43 -0700276}
277
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100278/**
279 * Set up two surfaces side-by-side. Tap each surface.
280 * Next, swap the positions of the two surfaces. Inject tap into the two
281 * original locations. Ensure that the tap is received by the surfaces in the
282 * reverse order.
283 */
Robert Carr1c4c5592018-09-24 13:18:43 -0700284TEST_F(InputSurfacesTest, input_respects_positioning) {
285 std::unique_ptr<InputSurface> surface = makeSurface(100, 100);
286 surface->showAt(100, 100);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100287 surface->assertFocusChange(true);
Robert Carr1c4c5592018-09-24 13:18:43 -0700288
289 std::unique_ptr<InputSurface> surface2 = makeSurface(100, 100);
290 surface2->showAt(200, 200);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100291 surface->assertFocusChange(false);
292 surface2->assertFocusChange(true);
Robert Carr1c4c5592018-09-24 13:18:43 -0700293
294 injectTap(201, 201);
295 surface2->expectTap(1, 1);
296
297 injectTap(101, 101);
298 surface->expectTap(1, 1);
299
300 surface2->doTransaction([](auto &t, auto &sc) {
301 t.setPosition(sc, 100, 100);
302 });
303 surface->doTransaction([](auto &t, auto &sc) {
304 t.setPosition(sc, 200, 200);
305 });
306
307 injectTap(101, 101);
308 surface2->expectTap(1, 1);
309
310 injectTap(201, 201);
311 surface->expectTap(1, 1);
312}
313
314TEST_F(InputSurfacesTest, input_respects_layering) {
315 std::unique_ptr<InputSurface> surface = makeSurface(100, 100);
316 std::unique_ptr<InputSurface> surface2 = makeSurface(100, 100);
317
318 surface->showAt(10, 10);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100319 surface->assertFocusChange(true);
Robert Carr1c4c5592018-09-24 13:18:43 -0700320 surface2->showAt(10, 10);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100321 surface->assertFocusChange(false);
322 surface2->assertFocusChange(true);
Robert Carr1c4c5592018-09-24 13:18:43 -0700323
324 surface->doTransaction([](auto &t, auto &sc) {
325 t.setLayer(sc, LAYER_BASE + 1);
326 });
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100327 surface2->assertFocusChange(false);
328 surface->assertFocusChange(true);
Robert Carr1c4c5592018-09-24 13:18:43 -0700329
330 injectTap(11, 11);
331 surface->expectTap(1, 1);
332
333 surface2->doTransaction([](auto &t, auto &sc) {
334 t.setLayer(sc, LAYER_BASE + 1);
335 });
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100336 surface2->assertFocusChange(true);
337 surface->assertFocusChange(false);
Robert Carr1c4c5592018-09-24 13:18:43 -0700338
339 injectTap(11, 11);
340 surface2->expectTap(1, 1);
341
342 surface2->doTransaction([](auto &t, auto &sc) {
343 t.hide(sc);
344 });
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100345 surface2->assertFocusChange(false);
346 surface->assertFocusChange(true);
Robert Carr1c4c5592018-09-24 13:18:43 -0700347
348 injectTap(11, 11);
349 surface->expectTap(1, 1);
350}
351
Vishnu Nairde19f852018-12-18 16:11:53 -0800352// Surface Insets are set to offset the client content and draw a border around the client surface
353// (such as shadows in dialogs). Inputs sent to the client are offset such that 0,0 is the start
354// of the client content.
355TEST_F(InputSurfacesTest, input_respects_surface_insets) {
356 std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100);
357 std::unique_ptr<InputSurface> fgSurface = makeSurface(100, 100);
358 bgSurface->showAt(100, 100);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100359 bgSurface->assertFocusChange(true);
Vishnu Nairde19f852018-12-18 16:11:53 -0800360
361 fgSurface->mInputInfo.surfaceInset = 5;
362 fgSurface->showAt(100, 100);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100363 fgSurface->assertFocusChange(true);
364 bgSurface->assertFocusChange(false);
Vishnu Nairde19f852018-12-18 16:11:53 -0800365
366 injectTap(106, 106);
367 fgSurface->expectTap(1, 1);
368
369 injectTap(101, 101);
370 bgSurface->expectTap(1, 1);
371}
372
373// Ensure a surface whose insets are cropped, handles the touch offset correctly. ref:b/120413463
374TEST_F(InputSurfacesTest, input_respects_cropped_surface_insets) {
375 std::unique_ptr<InputSurface> parentSurface = makeSurface(100, 100);
376 std::unique_ptr<InputSurface> childSurface = makeSurface(100, 100);
377 parentSurface->showAt(100, 100);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100378 parentSurface->assertFocusChange(true);
Vishnu Nairde19f852018-12-18 16:11:53 -0800379
380 childSurface->mInputInfo.surfaceInset = 10;
381 childSurface->showAt(100, 100);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100382 childSurface->assertFocusChange(true);
383 parentSurface->assertFocusChange(false);
Vishnu Nairde19f852018-12-18 16:11:53 -0800384
385 childSurface->doTransaction([&](auto &t, auto &sc) {
386 t.setPosition(sc, -5, -5);
387 t.reparent(sc, parentSurface->mSurfaceControl->getHandle());
388 });
389
390 injectTap(106, 106);
391 childSurface->expectTap(1, 1);
392
393 injectTap(101, 101);
394 parentSurface->expectTap(1, 1);
395}
396
Arthur Hung118b1142019-05-08 21:25:59 +0800397// Ensure a surface whose insets are scaled, handles the touch offset correctly.
398TEST_F(InputSurfacesTest, input_respects_scaled_surface_insets) {
399 std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100);
400 std::unique_ptr<InputSurface> fgSurface = makeSurface(100, 100);
401 bgSurface->showAt(100, 100);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100402 bgSurface->assertFocusChange(true);
Arthur Hung118b1142019-05-08 21:25:59 +0800403
404 fgSurface->mInputInfo.surfaceInset = 5;
405 fgSurface->showAt(100, 100);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100406 bgSurface->assertFocusChange(false);
407 fgSurface->assertFocusChange(true);
Arthur Hung118b1142019-05-08 21:25:59 +0800408
409 fgSurface->doTransaction([&](auto &t, auto &sc) { t.setMatrix(sc, 2.0, 0, 0, 4.0); });
410
411 // expect = touch / scale - inset
412 injectTap(112, 124);
413 fgSurface->expectTap(1, 1);
414
415 injectTap(101, 101);
416 bgSurface->expectTap(1, 1);
417}
418
Ady Abraham282f1d72019-07-24 18:05:56 -0700419TEST_F(InputSurfacesTest, input_respects_scaled_surface_insets_overflow) {
420 std::unique_ptr<InputSurface> fgSurface = makeSurface(100, 100);
421 // In case we pass the very big inset without any checking.
422 fgSurface->mInputInfo.surfaceInset = INT32_MAX;
423 fgSurface->showAt(100, 100);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100424 fgSurface->assertFocusChange(true);
Ady Abraham282f1d72019-07-24 18:05:56 -0700425
426 fgSurface->doTransaction([&](auto &t, auto &sc) { t.setMatrix(sc, 2.0, 0, 0, 2.0); });
427
428 // expect no crash for overflow, and inset size to be clamped to surface size
429 injectTap(202, 202);
430 fgSurface->expectTap(1, 1);
431}
432
Vishnu Nairde19f852018-12-18 16:11:53 -0800433// Ensure we ignore transparent region when getting screen bounds when positioning input frame.
434TEST_F(InputSurfacesTest, input_ignores_transparent_region) {
435 std::unique_ptr<InputSurface> surface = makeSurface(100, 100);
436 surface->doTransaction([](auto &t, auto &sc) {
437 Region transparentRegion(Rect(0, 0, 10, 10));
438 t.setTransparentRegionHint(sc, transparentRegion);
439 });
440 surface->showAt(100, 100);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100441 surface->assertFocusChange(true);
Vishnu Nairde19f852018-12-18 16:11:53 -0800442 injectTap(101, 101);
443 surface->expectTap(1, 1);
444}
445
Vishnu Nairf8678ba2019-10-11 18:11:26 -0700446// TODO(b/139494112) update tests once we define expected behavior
447// Ensure we still send input to the surface regardless of surface visibility changes due to the
448// first buffer being submitted or alpha changes.
449// Original bug ref: b/120839715
450TEST_F(InputSurfacesTest, input_ignores_buffer_layer_buffer) {
Vishnu Nairde19f852018-12-18 16:11:53 -0800451 std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100);
452 std::unique_ptr<InputSurface> bufferSurface =
453 InputSurface::makeBufferInputSurface(mComposerClient, 100, 100);
454
455 bgSurface->showAt(10, 10);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100456 bgSurface->assertFocusChange(true);
Vishnu Nairde19f852018-12-18 16:11:53 -0800457 bufferSurface->showAt(10, 10);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100458 bgSurface->assertFocusChange(false);
459 bufferSurface->assertFocusChange(true);
Vishnu Nairde19f852018-12-18 16:11:53 -0800460
461 injectTap(11, 11);
Vishnu Nairf8678ba2019-10-11 18:11:26 -0700462 bufferSurface->expectTap(1, 1);
Vishnu Nairde19f852018-12-18 16:11:53 -0800463
464 postBuffer(bufferSurface->mSurfaceControl);
465 injectTap(11, 11);
466 bufferSurface->expectTap(1, 1);
467}
468
Vishnu Nairf8678ba2019-10-11 18:11:26 -0700469TEST_F(InputSurfacesTest, input_ignores_buffer_layer_alpha) {
Vishnu Nairde19f852018-12-18 16:11:53 -0800470 std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100);
471 std::unique_ptr<InputSurface> bufferSurface =
472 InputSurface::makeBufferInputSurface(mComposerClient, 100, 100);
473 postBuffer(bufferSurface->mSurfaceControl);
474
475 bgSurface->showAt(10, 10);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100476 bgSurface->assertFocusChange(true);
Vishnu Nairde19f852018-12-18 16:11:53 -0800477 bufferSurface->showAt(10, 10);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100478 bufferSurface->assertFocusChange(true);
479 bgSurface->assertFocusChange(false);
Vishnu Nairde19f852018-12-18 16:11:53 -0800480
481 injectTap(11, 11);
482 bufferSurface->expectTap(1, 1);
483
484 bufferSurface->doTransaction([](auto &t, auto &sc) { t.setAlpha(sc, 0.0); });
485
486 injectTap(11, 11);
Vishnu Nairf8678ba2019-10-11 18:11:26 -0700487 bufferSurface->expectTap(1, 1);
Vishnu Nairde19f852018-12-18 16:11:53 -0800488}
489
Vishnu Nairf8678ba2019-10-11 18:11:26 -0700490TEST_F(InputSurfacesTest, input_ignores_color_layer_alpha) {
Vishnu Nairde19f852018-12-18 16:11:53 -0800491 std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100);
492 std::unique_ptr<InputSurface> fgSurface = makeSurface(100, 100);
493
494 bgSurface->showAt(10, 10);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100495 bgSurface->assertFocusChange(true);
Vishnu Nairde19f852018-12-18 16:11:53 -0800496 fgSurface->showAt(10, 10);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100497 bgSurface->assertFocusChange(false);
498 fgSurface->assertFocusChange(true);
Vishnu Nairde19f852018-12-18 16:11:53 -0800499
500 injectTap(11, 11);
501 fgSurface->expectTap(1, 1);
502
503 fgSurface->doTransaction([](auto &t, auto &sc) { t.setAlpha(sc, 0.0); });
504
505 injectTap(11, 11);
Vishnu Nairf8678ba2019-10-11 18:11:26 -0700506 fgSurface->expectTap(1, 1);
Vishnu Nairde19f852018-12-18 16:11:53 -0800507}
508
509TEST_F(InputSurfacesTest, input_respects_container_layer_visiblity) {
510 std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100);
511 std::unique_ptr<InputSurface> containerSurface =
512 InputSurface::makeContainerInputSurface(mComposerClient, 100, 100);
513
514 bgSurface->showAt(10, 10);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100515 bgSurface->assertFocusChange(true);
Vishnu Nairde19f852018-12-18 16:11:53 -0800516 containerSurface->showAt(10, 10);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100517 bgSurface->assertFocusChange(false);
518 containerSurface->assertFocusChange(true);
Vishnu Nairde19f852018-12-18 16:11:53 -0800519
520 injectTap(11, 11);
521 containerSurface->expectTap(1, 1);
522
523 containerSurface->doTransaction([](auto &t, auto &sc) { t.hide(sc); });
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100524 containerSurface->assertFocusChange(false);
525 bgSurface->assertFocusChange(true);
Vishnu Nairde19f852018-12-18 16:11:53 -0800526
527 injectTap(11, 11);
528 bgSurface->expectTap(1, 1);
529}
chaviwfbe5d9c2018-12-26 12:23:37 -0800530
Arthur Hungd20b2702019-01-14 18:16:16 +0800531TEST_F(InputSurfacesTest, input_respects_outscreen) {
532 std::unique_ptr<InputSurface> surface = makeSurface(100, 100);
533 surface->showAt(-1, -1);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100534 surface->assertFocusChange(true);
Arthur Hungd20b2702019-01-14 18:16:16 +0800535
536 injectTap(0, 0);
537 surface->expectTap(1, 1);
538}
Robert Carr1c4c5592018-09-24 13:18:43 -0700539}
540}