summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Bernardo Rufino <brufino@google.com> 2021-02-25 17:32:44 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2021-02-25 17:32:44 +0000
commit09c142e6660f4e7e866eab9fe2cfdc89cd82b48e (patch)
treeedcb8c5ac9cf5923f35c9cea1c8742757ce7d43e
parent96a824cecf22fdc1e961e6b48c8549aba4b87292 (diff)
parenta43a5a4be9d417948a2984af8c0cec2e26063b3f (diff)
Merge "Add InputDispatcher unit tests for untrusted touches [5/n]" into sc-dev
-rw-r--r--services/inputflinger/tests/InputDispatcher_test.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp
index 118a24f464..e027c5e376 100644
--- a/services/inputflinger/tests/InputDispatcher_test.cpp
+++ b/services/inputflinger/tests/InputDispatcher_test.cpp
@@ -908,6 +908,8 @@ public:
mInfo.addTouchableRegion(frame);
}
+ void addFlags(Flags<InputWindowInfo::Flag> flags) { mInfo.flags |= flags; }
+
void setFlags(Flags<InputWindowInfo::Flag> flags) { mInfo.flags = flags; }
void setInputFeatures(InputWindowInfo::Feature features) { mInfo.inputFeatures = features; }
@@ -4318,6 +4320,17 @@ TEST_F(InputDispatcherUntrustedTouchesTest, WindowWithBlockUntrustedOcclusionMod
mTouchWindow->assertNoEvents();
}
+TEST_F(InputDispatcherUntrustedTouchesTest,
+ WindowWithBlockUntrustedOcclusionMode_DoesNotReceiveTouch) {
+ const sp<FakeWindowHandle>& w =
+ getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::BLOCK_UNTRUSTED);
+ mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {w, mTouchWindow}}});
+
+ touch();
+
+ w->assertNoEvents();
+}
+
TEST_F(InputDispatcherUntrustedTouchesTest, WindowWithAllowOcclusionMode_AllowsTouch) {
const sp<FakeWindowHandle>& w = getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::ALLOW);
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {w, mTouchWindow}}});
@@ -4358,6 +4371,48 @@ TEST_F(InputDispatcherUntrustedTouchesTest, WindowWithZeroOpacity_AllowsTouch) {
mTouchWindow->consumeAnyMotionDown();
}
+TEST_F(InputDispatcherUntrustedTouchesTest, WindowWithZeroOpacity_DoesNotReceiveTouch) {
+ const sp<FakeWindowHandle>& w =
+ getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::BLOCK_UNTRUSTED, 0.0f);
+ mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {w, mTouchWindow}}});
+
+ touch();
+
+ w->assertNoEvents();
+}
+
+/**
+ * This is important to make sure apps can't indirectly learn the position of touches (outside vs
+ * inside) while letting them pass-through. Note that even though touch passes through the occluding
+ * window, the occluding window will still receive ACTION_OUTSIDE event.
+ */
+TEST_F(InputDispatcherUntrustedTouchesTest,
+ WindowWithZeroOpacityAndWatchOutside_ReceivesOutsideEvent) {
+ const sp<FakeWindowHandle>& w =
+ getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::BLOCK_UNTRUSTED, 0.0f);
+ w->addFlags(InputWindowInfo::Flag::WATCH_OUTSIDE_TOUCH);
+ mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {w, mTouchWindow}}});
+
+ touch();
+
+ w->consumeMotionOutside();
+}
+
+TEST_F(InputDispatcherUntrustedTouchesTest, OutsideEvent_HasZeroCoordinates) {
+ const sp<FakeWindowHandle>& w =
+ getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::BLOCK_UNTRUSTED, 0.0f);
+ w->addFlags(InputWindowInfo::Flag::WATCH_OUTSIDE_TOUCH);
+ mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {w, mTouchWindow}}});
+
+ touch();
+
+ InputEvent* event = w->consume();
+ ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, event->getType());
+ MotionEvent& motionEvent = static_cast<MotionEvent&>(*event);
+ EXPECT_EQ(0.0f, motionEvent.getRawPointerCoords(0)->getX());
+ EXPECT_EQ(0.0f, motionEvent.getRawPointerCoords(0)->getY());
+}
+
TEST_F(InputDispatcherUntrustedTouchesTest, WindowWithOpacityBelowThreshold_AllowsTouch) {
const sp<FakeWindowHandle>& w =
getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::USE_OPACITY, 0.7f);