Loading include/input/InputConsumer.h +5 −0 Original line number Diff line number Diff line Loading @@ -111,6 +111,11 @@ private: std::shared_ptr<InputChannel> mChannel; // TODO(b/311142655): delete this temporary tracing after the ANR bug is fixed const std::string mProcessingTraceTag; const std::string mLifetimeTraceTag; const int32_t mLifetimeTraceCookie; // The current input message. InputMessage mMsg; Loading libs/gui/include/gui/WindowInfo.h +2 −0 Original line number Diff line number Diff line Loading @@ -178,6 +178,8 @@ struct WindowInfo : public Parcelable { static_cast<uint32_t>(os::InputConfig::CLONE), GLOBAL_STYLUS_BLOCKS_TOUCH = static_cast<uint32_t>(os::InputConfig::GLOBAL_STYLUS_BLOCKS_TOUCH), SENSITIVE_FOR_TRACING = static_cast<uint32_t>(os::InputConfig::SENSITIVE_FOR_TRACING), // clang-format on }; Loading libs/gui/tests/EndToEndNativeInputTest.cpp +26 −27 Original line number Diff line number Diff line Loading @@ -195,7 +195,7 @@ public: EXPECT_EQ(hasFocus, focusEvent->getHasFocus()); } void expectTap(int x, int y) { void expectTap(float x, float y) { InputEvent* ev = consumeEvent(); ASSERT_NE(ev, nullptr); ASSERT_EQ(InputEventType::MOTION, ev->getType()); Loading Loading @@ -268,6 +268,11 @@ public: EXPECT_EQ(0, keyEvent->getFlags() & VERIFIED_KEY_EVENT_FLAGS); } void assertNoEvent() { InputEvent* event = consumeEvent(/*timeout=*/100ms); ASSERT_EQ(event, nullptr) << "Expected no event, but got " << *event; } virtual ~InputSurface() { if (mClientChannel) { mInputFlinger->removeInputChannel(mClientChannel->getConnectionToken()); Loading Loading @@ -937,9 +942,7 @@ TEST_F(InputSurfacesTest, strict_unobscured_input_unobscured_window) { surface->showAt(100, 100); injectTap(101, 101); EXPECT_NE(surface->consumeEvent(), nullptr); EXPECT_NE(surface->consumeEvent(), nullptr); surface->expectTap(1, 1); surface->requestFocus(); surface->assertFocusChange(true); Loading @@ -956,9 +959,7 @@ TEST_F(InputSurfacesTest, strict_unobscured_input_scaled_without_crop_window) { surface->showAt(100, 100); injectTap(101, 101); EXPECT_NE(surface->consumeEvent(), nullptr); EXPECT_NE(surface->consumeEvent(), nullptr); surface->expectTap(.5, .5); surface->requestFocus(); surface->assertFocusChange(true); Loading @@ -977,12 +978,12 @@ TEST_F(InputSurfacesTest, strict_unobscured_input_obscured_window) { obscuringSurface->mInputInfo.ownerUid = gui::Uid{22222}; obscuringSurface->showAt(100, 100); injectTap(101, 101); EXPECT_EQ(surface->consumeEvent(/*timeout=*/100ms), nullptr); surface->assertNoEvent(); surface->requestFocus(); surface->assertFocusChange(true); injectKey(AKEYCODE_V); EXPECT_EQ(surface->consumeEvent(/*timeout=*/100ms), nullptr); surface->assertNoEvent(); } TEST_F(InputSurfacesTest, strict_unobscured_input_partially_obscured_window) { Loading @@ -998,12 +999,12 @@ TEST_F(InputSurfacesTest, strict_unobscured_input_partially_obscured_window) { injectTap(101, 101); EXPECT_EQ(surface->consumeEvent(/*timeout=*/100ms), nullptr); surface->assertNoEvent(); surface->requestFocus(); surface->assertFocusChange(true); injectKey(AKEYCODE_V); EXPECT_EQ(surface->consumeEvent(/*timeout=*/100ms), nullptr); surface->assertNoEvent(); } TEST_F(InputSurfacesTest, strict_unobscured_input_alpha_window) { Loading @@ -1020,12 +1021,12 @@ TEST_F(InputSurfacesTest, strict_unobscured_input_alpha_window) { injectTap(101, 101); EXPECT_EQ(surface->consumeEvent(/*timeout=*/100ms), nullptr); surface->assertNoEvent(); surface->requestFocus(); surface->assertFocusChange(true); injectKey(AKEYCODE_V); EXPECT_EQ(surface->consumeEvent(/*timeout=*/100ms), nullptr); surface->assertNoEvent(); } TEST_F(InputSurfacesTest, strict_unobscured_input_cropped_window) { Loading @@ -1042,12 +1043,12 @@ TEST_F(InputSurfacesTest, strict_unobscured_input_cropped_window) { injectTap(111, 111); EXPECT_EQ(surface->consumeEvent(/*timeout=*/100ms), nullptr); surface->assertNoEvent(); surface->requestFocus(); surface->assertFocusChange(true); injectKey(AKEYCODE_V); EXPECT_EQ(surface->consumeEvent(/*timeout=*/100ms), nullptr); surface->assertNoEvent(); } TEST_F(InputSurfacesTest, ignore_touch_region_with_zero_sized_blast) { Loading @@ -1071,13 +1072,12 @@ TEST_F(InputSurfacesTest, drop_input_policy) { surface->showAt(100, 100); injectTap(101, 101); EXPECT_EQ(surface->consumeEvent(/*timeout=*/100ms), nullptr); surface->assertNoEvent(); surface->requestFocus(); surface->assertFocusChange(true); injectKey(AKEYCODE_V); EXPECT_EQ(surface->consumeEvent(/*timeout=*/100ms), nullptr); surface->assertNoEvent(); } TEST_F(InputSurfacesTest, layer_with_valid_crop_can_be_focused) { Loading Loading @@ -1112,7 +1112,7 @@ TEST_F(InputSurfacesTest, cropped_container_replaces_touchable_region_with_null_ // Does not receive events outside its crop injectTap(26, 26); EXPECT_EQ(containerSurface->consumeEvent(/*timeout=*/100ms), nullptr); containerSurface->assertNoEvent(); } /** Loading @@ -1137,7 +1137,7 @@ TEST_F(InputSurfacesTest, uncropped_container_replaces_touchable_region_with_nul // Does not receive events outside parent bounds injectTap(31, 31); EXPECT_EQ(containerSurface->consumeEvent(/*timeout=*/100ms), nullptr); containerSurface->assertNoEvent(); } /** Loading @@ -1163,7 +1163,7 @@ TEST_F(InputSurfacesTest, replace_touchable_region_with_crop) { // Does not receive events outside crop layer bounds injectTap(21, 21); injectTap(71, 71); EXPECT_EQ(containerSurface->consumeEvent(/*timeout=*/100ms), nullptr); containerSurface->assertNoEvent(); } TEST_F(InputSurfacesTest, child_container_with_no_input_channel_blocks_parent) { Loading @@ -1180,7 +1180,7 @@ TEST_F(InputSurfacesTest, child_container_with_no_input_channel_blocks_parent) { [&](auto &t, auto &sc) { t.reparent(sc, parent->mSurfaceControl); }); injectTap(101, 101); EXPECT_EQ(parent->consumeEvent(/*timeout=*/100ms), nullptr); parent->assertNoEvent(); } class MultiDisplayTests : public InputSurfacesTest { Loading Loading @@ -1229,7 +1229,7 @@ TEST_F(MultiDisplayTests, drop_touch_if_layer_on_invalid_display) { // Touches should be dropped if the layer is on an invalid display. injectTapOnDisplay(101, 101, layerStack.id); EXPECT_EQ(surface->consumeEvent(/*timeout=*/100ms), nullptr); surface->assertNoEvent(); // However, we still let the window be focused and receive keys. surface->requestFocus(layerStack.id); Loading Loading @@ -1267,12 +1267,12 @@ TEST_F(MultiDisplayTests, drop_input_for_secure_layer_on_nonsecure_display) { injectTapOnDisplay(101, 101, layerStack.id); EXPECT_EQ(surface->consumeEvent(/*timeout=*/100ms), nullptr); surface->assertNoEvent(); surface->requestFocus(layerStack.id); surface->assertFocusChange(true); injectKeyOnDisplay(AKEYCODE_V, layerStack.id); EXPECT_EQ(surface->consumeEvent(/*timeout=*/100ms), nullptr); surface->assertNoEvent(); } TEST_F(MultiDisplayTests, dont_drop_input_for_secure_layer_on_secure_display) { Loading @@ -1292,8 +1292,7 @@ TEST_F(MultiDisplayTests, dont_drop_input_for_secure_layer_on_secure_display) { surface->showAt(100, 100); injectTapOnDisplay(101, 101, layerStack.id); EXPECT_NE(surface->consumeEvent(), nullptr); EXPECT_NE(surface->consumeEvent(), nullptr); surface->expectTap(1, 1); surface->requestFocus(layerStack.id); surface->assertFocusChange(true); Loading libs/input/InputConsumer.cpp +17 −4 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ * limitations under the License. */ #include <cstdint> #define LOG_TAG "InputTransport" #define ATRACE_TAG ATRACE_TAG_INPUT Loading Loading @@ -194,9 +195,21 @@ InputConsumer::InputConsumer(const std::shared_ptr<InputChannel>& channel) InputConsumer::InputConsumer(const std::shared_ptr<InputChannel>& channel, bool enableTouchResampling) : mResampleTouch(enableTouchResampling), mChannel(channel), mMsgDeferred(false) {} : mResampleTouch(enableTouchResampling), mChannel(channel), mProcessingTraceTag(StringPrintf("InputConsumer processing on %s (%p)", mChannel->getName().c_str(), this)), mLifetimeTraceTag(StringPrintf("InputConsumer lifetime on %s (%p)", mChannel->getName().c_str(), this)), mLifetimeTraceCookie( static_cast<int32_t>(reinterpret_cast<std::uintptr_t>(this) & 0xFFFFFFFF)), mMsgDeferred(false) { ATRACE_ASYNC_BEGIN(mLifetimeTraceTag.c_str(), /*cookie=*/mLifetimeTraceCookie); } InputConsumer::~InputConsumer() {} InputConsumer::~InputConsumer() { ATRACE_ASYNC_END(mLifetimeTraceTag.c_str(), /*cookie=*/mLifetimeTraceCookie); } bool InputConsumer::isTouchResamplingEnabled() { return property_get_bool(PROPERTY_RESAMPLING_ENABLED, true); Loading Loading @@ -228,7 +241,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, bool consum mMsg.header.seq); // Trace the event processing timeline - event was just read from the socket ATRACE_ASYNC_BEGIN("InputConsumer processing", /*cookie=*/mMsg.header.seq); ATRACE_ASYNC_BEGIN(mProcessingTraceTag.c_str(), /*cookie=*/mMsg.header.seq); } if (result) { // Consume the next batched event unless batches are being held for later. Loading Loading @@ -769,7 +782,7 @@ status_t InputConsumer::sendUnchainedFinishedSignal(uint32_t seq, bool handled) popConsumeTime(seq); // Trace the event processing timeline - event was just finished ATRACE_ASYNC_END("InputConsumer processing", /*cookie=*/seq); ATRACE_ASYNC_END(mProcessingTraceTag.c_str(), /*cookie=*/seq); } return result; } Loading libs/input/android/os/InputConfig.aidl +8 −0 Original line number Diff line number Diff line Loading @@ -157,4 +157,12 @@ enum InputConfig { * like StatusBar and TaskBar. */ GLOBAL_STYLUS_BLOCKS_TOUCH = 1 << 17, /** * InputConfig used to indicate that this window is sensitive for tracing. * This must be set on windows that use {@link WindowManager.LayoutParams#FLAG_SECURE}, * but it may also be set without setting FLAG_SECURE. The tracing configuration will * determine how these sensitive events are eventually traced. */ SENSITIVE_FOR_TRACING = 1 << 18, } Loading
include/input/InputConsumer.h +5 −0 Original line number Diff line number Diff line Loading @@ -111,6 +111,11 @@ private: std::shared_ptr<InputChannel> mChannel; // TODO(b/311142655): delete this temporary tracing after the ANR bug is fixed const std::string mProcessingTraceTag; const std::string mLifetimeTraceTag; const int32_t mLifetimeTraceCookie; // The current input message. InputMessage mMsg; Loading
libs/gui/include/gui/WindowInfo.h +2 −0 Original line number Diff line number Diff line Loading @@ -178,6 +178,8 @@ struct WindowInfo : public Parcelable { static_cast<uint32_t>(os::InputConfig::CLONE), GLOBAL_STYLUS_BLOCKS_TOUCH = static_cast<uint32_t>(os::InputConfig::GLOBAL_STYLUS_BLOCKS_TOUCH), SENSITIVE_FOR_TRACING = static_cast<uint32_t>(os::InputConfig::SENSITIVE_FOR_TRACING), // clang-format on }; Loading
libs/gui/tests/EndToEndNativeInputTest.cpp +26 −27 Original line number Diff line number Diff line Loading @@ -195,7 +195,7 @@ public: EXPECT_EQ(hasFocus, focusEvent->getHasFocus()); } void expectTap(int x, int y) { void expectTap(float x, float y) { InputEvent* ev = consumeEvent(); ASSERT_NE(ev, nullptr); ASSERT_EQ(InputEventType::MOTION, ev->getType()); Loading Loading @@ -268,6 +268,11 @@ public: EXPECT_EQ(0, keyEvent->getFlags() & VERIFIED_KEY_EVENT_FLAGS); } void assertNoEvent() { InputEvent* event = consumeEvent(/*timeout=*/100ms); ASSERT_EQ(event, nullptr) << "Expected no event, but got " << *event; } virtual ~InputSurface() { if (mClientChannel) { mInputFlinger->removeInputChannel(mClientChannel->getConnectionToken()); Loading Loading @@ -937,9 +942,7 @@ TEST_F(InputSurfacesTest, strict_unobscured_input_unobscured_window) { surface->showAt(100, 100); injectTap(101, 101); EXPECT_NE(surface->consumeEvent(), nullptr); EXPECT_NE(surface->consumeEvent(), nullptr); surface->expectTap(1, 1); surface->requestFocus(); surface->assertFocusChange(true); Loading @@ -956,9 +959,7 @@ TEST_F(InputSurfacesTest, strict_unobscured_input_scaled_without_crop_window) { surface->showAt(100, 100); injectTap(101, 101); EXPECT_NE(surface->consumeEvent(), nullptr); EXPECT_NE(surface->consumeEvent(), nullptr); surface->expectTap(.5, .5); surface->requestFocus(); surface->assertFocusChange(true); Loading @@ -977,12 +978,12 @@ TEST_F(InputSurfacesTest, strict_unobscured_input_obscured_window) { obscuringSurface->mInputInfo.ownerUid = gui::Uid{22222}; obscuringSurface->showAt(100, 100); injectTap(101, 101); EXPECT_EQ(surface->consumeEvent(/*timeout=*/100ms), nullptr); surface->assertNoEvent(); surface->requestFocus(); surface->assertFocusChange(true); injectKey(AKEYCODE_V); EXPECT_EQ(surface->consumeEvent(/*timeout=*/100ms), nullptr); surface->assertNoEvent(); } TEST_F(InputSurfacesTest, strict_unobscured_input_partially_obscured_window) { Loading @@ -998,12 +999,12 @@ TEST_F(InputSurfacesTest, strict_unobscured_input_partially_obscured_window) { injectTap(101, 101); EXPECT_EQ(surface->consumeEvent(/*timeout=*/100ms), nullptr); surface->assertNoEvent(); surface->requestFocus(); surface->assertFocusChange(true); injectKey(AKEYCODE_V); EXPECT_EQ(surface->consumeEvent(/*timeout=*/100ms), nullptr); surface->assertNoEvent(); } TEST_F(InputSurfacesTest, strict_unobscured_input_alpha_window) { Loading @@ -1020,12 +1021,12 @@ TEST_F(InputSurfacesTest, strict_unobscured_input_alpha_window) { injectTap(101, 101); EXPECT_EQ(surface->consumeEvent(/*timeout=*/100ms), nullptr); surface->assertNoEvent(); surface->requestFocus(); surface->assertFocusChange(true); injectKey(AKEYCODE_V); EXPECT_EQ(surface->consumeEvent(/*timeout=*/100ms), nullptr); surface->assertNoEvent(); } TEST_F(InputSurfacesTest, strict_unobscured_input_cropped_window) { Loading @@ -1042,12 +1043,12 @@ TEST_F(InputSurfacesTest, strict_unobscured_input_cropped_window) { injectTap(111, 111); EXPECT_EQ(surface->consumeEvent(/*timeout=*/100ms), nullptr); surface->assertNoEvent(); surface->requestFocus(); surface->assertFocusChange(true); injectKey(AKEYCODE_V); EXPECT_EQ(surface->consumeEvent(/*timeout=*/100ms), nullptr); surface->assertNoEvent(); } TEST_F(InputSurfacesTest, ignore_touch_region_with_zero_sized_blast) { Loading @@ -1071,13 +1072,12 @@ TEST_F(InputSurfacesTest, drop_input_policy) { surface->showAt(100, 100); injectTap(101, 101); EXPECT_EQ(surface->consumeEvent(/*timeout=*/100ms), nullptr); surface->assertNoEvent(); surface->requestFocus(); surface->assertFocusChange(true); injectKey(AKEYCODE_V); EXPECT_EQ(surface->consumeEvent(/*timeout=*/100ms), nullptr); surface->assertNoEvent(); } TEST_F(InputSurfacesTest, layer_with_valid_crop_can_be_focused) { Loading Loading @@ -1112,7 +1112,7 @@ TEST_F(InputSurfacesTest, cropped_container_replaces_touchable_region_with_null_ // Does not receive events outside its crop injectTap(26, 26); EXPECT_EQ(containerSurface->consumeEvent(/*timeout=*/100ms), nullptr); containerSurface->assertNoEvent(); } /** Loading @@ -1137,7 +1137,7 @@ TEST_F(InputSurfacesTest, uncropped_container_replaces_touchable_region_with_nul // Does not receive events outside parent bounds injectTap(31, 31); EXPECT_EQ(containerSurface->consumeEvent(/*timeout=*/100ms), nullptr); containerSurface->assertNoEvent(); } /** Loading @@ -1163,7 +1163,7 @@ TEST_F(InputSurfacesTest, replace_touchable_region_with_crop) { // Does not receive events outside crop layer bounds injectTap(21, 21); injectTap(71, 71); EXPECT_EQ(containerSurface->consumeEvent(/*timeout=*/100ms), nullptr); containerSurface->assertNoEvent(); } TEST_F(InputSurfacesTest, child_container_with_no_input_channel_blocks_parent) { Loading @@ -1180,7 +1180,7 @@ TEST_F(InputSurfacesTest, child_container_with_no_input_channel_blocks_parent) { [&](auto &t, auto &sc) { t.reparent(sc, parent->mSurfaceControl); }); injectTap(101, 101); EXPECT_EQ(parent->consumeEvent(/*timeout=*/100ms), nullptr); parent->assertNoEvent(); } class MultiDisplayTests : public InputSurfacesTest { Loading Loading @@ -1229,7 +1229,7 @@ TEST_F(MultiDisplayTests, drop_touch_if_layer_on_invalid_display) { // Touches should be dropped if the layer is on an invalid display. injectTapOnDisplay(101, 101, layerStack.id); EXPECT_EQ(surface->consumeEvent(/*timeout=*/100ms), nullptr); surface->assertNoEvent(); // However, we still let the window be focused and receive keys. surface->requestFocus(layerStack.id); Loading Loading @@ -1267,12 +1267,12 @@ TEST_F(MultiDisplayTests, drop_input_for_secure_layer_on_nonsecure_display) { injectTapOnDisplay(101, 101, layerStack.id); EXPECT_EQ(surface->consumeEvent(/*timeout=*/100ms), nullptr); surface->assertNoEvent(); surface->requestFocus(layerStack.id); surface->assertFocusChange(true); injectKeyOnDisplay(AKEYCODE_V, layerStack.id); EXPECT_EQ(surface->consumeEvent(/*timeout=*/100ms), nullptr); surface->assertNoEvent(); } TEST_F(MultiDisplayTests, dont_drop_input_for_secure_layer_on_secure_display) { Loading @@ -1292,8 +1292,7 @@ TEST_F(MultiDisplayTests, dont_drop_input_for_secure_layer_on_secure_display) { surface->showAt(100, 100); injectTapOnDisplay(101, 101, layerStack.id); EXPECT_NE(surface->consumeEvent(), nullptr); EXPECT_NE(surface->consumeEvent(), nullptr); surface->expectTap(1, 1); surface->requestFocus(layerStack.id); surface->assertFocusChange(true); Loading
libs/input/InputConsumer.cpp +17 −4 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ * limitations under the License. */ #include <cstdint> #define LOG_TAG "InputTransport" #define ATRACE_TAG ATRACE_TAG_INPUT Loading Loading @@ -194,9 +195,21 @@ InputConsumer::InputConsumer(const std::shared_ptr<InputChannel>& channel) InputConsumer::InputConsumer(const std::shared_ptr<InputChannel>& channel, bool enableTouchResampling) : mResampleTouch(enableTouchResampling), mChannel(channel), mMsgDeferred(false) {} : mResampleTouch(enableTouchResampling), mChannel(channel), mProcessingTraceTag(StringPrintf("InputConsumer processing on %s (%p)", mChannel->getName().c_str(), this)), mLifetimeTraceTag(StringPrintf("InputConsumer lifetime on %s (%p)", mChannel->getName().c_str(), this)), mLifetimeTraceCookie( static_cast<int32_t>(reinterpret_cast<std::uintptr_t>(this) & 0xFFFFFFFF)), mMsgDeferred(false) { ATRACE_ASYNC_BEGIN(mLifetimeTraceTag.c_str(), /*cookie=*/mLifetimeTraceCookie); } InputConsumer::~InputConsumer() {} InputConsumer::~InputConsumer() { ATRACE_ASYNC_END(mLifetimeTraceTag.c_str(), /*cookie=*/mLifetimeTraceCookie); } bool InputConsumer::isTouchResamplingEnabled() { return property_get_bool(PROPERTY_RESAMPLING_ENABLED, true); Loading Loading @@ -228,7 +241,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, bool consum mMsg.header.seq); // Trace the event processing timeline - event was just read from the socket ATRACE_ASYNC_BEGIN("InputConsumer processing", /*cookie=*/mMsg.header.seq); ATRACE_ASYNC_BEGIN(mProcessingTraceTag.c_str(), /*cookie=*/mMsg.header.seq); } if (result) { // Consume the next batched event unless batches are being held for later. Loading Loading @@ -769,7 +782,7 @@ status_t InputConsumer::sendUnchainedFinishedSignal(uint32_t seq, bool handled) popConsumeTime(seq); // Trace the event processing timeline - event was just finished ATRACE_ASYNC_END("InputConsumer processing", /*cookie=*/seq); ATRACE_ASYNC_END(mProcessingTraceTag.c_str(), /*cookie=*/seq); } return result; } Loading
libs/input/android/os/InputConfig.aidl +8 −0 Original line number Diff line number Diff line Loading @@ -157,4 +157,12 @@ enum InputConfig { * like StatusBar and TaskBar. */ GLOBAL_STYLUS_BLOCKS_TOUCH = 1 << 17, /** * InputConfig used to indicate that this window is sensitive for tracing. * This must be set on windows that use {@link WindowManager.LayoutParams#FLAG_SECURE}, * but it may also be set without setting FLAG_SECURE. The tracing configuration will * determine how these sensitive events are eventually traced. */ SENSITIVE_FOR_TRACING = 1 << 18, }