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