summaryrefslogtreecommitdiff
path: root/libs/gui/tests/EndToEndNativeInputTest.cpp
diff options
context:
space:
mode:
authorchaviw <chaviw@google.com>2020-11-04 14:19:02 -0800
committerchaviw <chaviw@google.com>2020-11-06 16:41:21 -0800
commit39cfa2e03fc5e134eb62f2ebedbab91f56fefa22 (patch)
tree92b1b719371014cea6298e4891ede0280a80ee74 /libs/gui/tests/EndToEndNativeInputTest.cpp
parent5872c14d7f1217cfc86e9fe90bb01f0afc042ded (diff)
Crop bounds sent to input by screen bounds.
We want to the frame sent to input to be the layer bounds, including crop. This is because if the layer is cropped, we don't need to consider the cropped area on screen and therefore will not affect the touch area. Test: Minimized split has correct input frame Test: InputSurfacesTest.* Fixes: 170871385 Fixes: 171756624 Change-Id: I3d00f98044a68de6596265bc3e444d3ed2ea5896
Diffstat (limited to 'libs/gui/tests/EndToEndNativeInputTest.cpp')
-rw-r--r--libs/gui/tests/EndToEndNativeInputTest.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/libs/gui/tests/EndToEndNativeInputTest.cpp b/libs/gui/tests/EndToEndNativeInputTest.cpp
index 483f171564..c39b0b5ee6 100644
--- a/libs/gui/tests/EndToEndNativeInputTest.cpp
+++ b/libs/gui/tests/EndToEndNativeInputTest.cpp
@@ -153,6 +153,24 @@ public:
EXPECT_EQ(0, mev->getFlags() & VERIFIED_MOTION_EVENT_FLAGS);
}
+ void expectTapWithFlag(int x, int y, int32_t flags) {
+ InputEvent *ev = consumeEvent();
+ ASSERT_NE(ev, nullptr);
+ ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, ev->getType());
+ MotionEvent *mev = static_cast<MotionEvent *>(ev);
+ EXPECT_EQ(AMOTION_EVENT_ACTION_DOWN, mev->getAction());
+ EXPECT_EQ(x, mev->getX(0));
+ EXPECT_EQ(y, mev->getY(0));
+ EXPECT_EQ(flags, mev->getFlags() & flags);
+
+ ev = consumeEvent();
+ ASSERT_NE(ev, nullptr);
+ ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, ev->getType());
+ mev = static_cast<MotionEvent *>(ev);
+ EXPECT_EQ(AMOTION_EVENT_ACTION_UP, mev->getAction());
+ EXPECT_EQ(flags, mev->getFlags() & flags);
+ }
+
~InputSurface() { mInputFlinger->removeInputChannel(mClientChannel->getConnectionToken()); }
void doTransaction(std::function<void(SurfaceComposerClient::Transaction&,
@@ -602,4 +620,68 @@ TEST_F(InputSurfacesTest, rotate_surface_with_scale_and_insets) {
surface->expectTap(5, 10);
}
+TEST_F(InputSurfacesTest, touch_flag_obscured) {
+ std::unique_ptr<InputSurface> surface = makeSurface(100, 100);
+ surface->showAt(100, 100);
+
+ // Add non touchable window to fully cover touchable window. Window behind gets touch, but
+ // with flag AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED
+ std::unique_ptr<InputSurface> nonTouchableSurface = makeSurface(100, 100);
+ nonTouchableSurface->mInputInfo.flags = InputWindowInfo::Flag::NOT_TOUCHABLE;
+ nonTouchableSurface->mInputInfo.ownerUid = 22222;
+ nonTouchableSurface->showAt(100, 100);
+
+ injectTap(190, 199);
+ surface->expectTapWithFlag(90, 99, AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED);
+}
+
+TEST_F(InputSurfacesTest, touch_flag_partially_obscured_with_crop) {
+ std::unique_ptr<InputSurface> surface = makeSurface(100, 100);
+ surface->showAt(100, 100);
+
+ // Add non touchable window to cover touchable window, but parent is cropped to not cover area
+ // that will be tapped. Window behind gets touch, but with flag
+ // AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED
+ std::unique_ptr<InputSurface> parentSurface = makeSurface(100, 100);
+ std::unique_ptr<InputSurface> nonTouchableSurface = makeSurface(100, 100);
+ nonTouchableSurface->mInputInfo.flags = InputWindowInfo::Flag::NOT_TOUCHABLE;
+ parentSurface->mInputInfo.flags = InputWindowInfo::Flag::NOT_TOUCHABLE;
+ nonTouchableSurface->mInputInfo.ownerUid = 22222;
+ parentSurface->mInputInfo.ownerUid = 22222;
+ nonTouchableSurface->showAt(0, 0);
+ parentSurface->showAt(100, 100);
+
+ nonTouchableSurface->doTransaction([&](auto &t, auto &sc) {
+ t.setCrop_legacy(parentSurface->mSurfaceControl, Rect(0, 0, 50, 50));
+ t.reparent(sc, parentSurface->mSurfaceControl);
+ });
+
+ injectTap(190, 199);
+ surface->expectTapWithFlag(90, 99, AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED);
+}
+
+TEST_F(InputSurfacesTest, touch_not_obscured_with_crop) {
+ std::unique_ptr<InputSurface> surface = makeSurface(100, 100);
+ surface->showAt(100, 100);
+
+ // Add non touchable window to cover touchable window, but parent is cropped to avoid covering
+ // the touchable window. Window behind gets touch with no obscured flags.
+ std::unique_ptr<InputSurface> parentSurface = makeSurface(100, 100);
+ std::unique_ptr<InputSurface> nonTouchableSurface = makeSurface(100, 100);
+ nonTouchableSurface->mInputInfo.flags = InputWindowInfo::Flag::NOT_TOUCHABLE;
+ parentSurface->mInputInfo.flags = InputWindowInfo::Flag::NOT_TOUCHABLE;
+ nonTouchableSurface->mInputInfo.ownerUid = 22222;
+ parentSurface->mInputInfo.ownerUid = 22222;
+ nonTouchableSurface->showAt(0, 0);
+ parentSurface->showAt(50, 50);
+
+ nonTouchableSurface->doTransaction([&](auto &t, auto &sc) {
+ t.setCrop_legacy(parentSurface->mSurfaceControl, Rect(0, 0, 50, 50));
+ t.reparent(sc, parentSurface->mSurfaceControl);
+ });
+
+ injectTap(101, 110);
+ surface->expectTap(1, 10);
+}
+
} // namespace android::test