Loading services/inputflinger/tests/InputDispatcher_test.cpp +55 −0 Original line number Original line Diff line number Diff line Loading @@ -908,6 +908,8 @@ public: mInfo.addTouchableRegion(frame); mInfo.addTouchableRegion(frame); } } void addFlags(Flags<InputWindowInfo::Flag> flags) { mInfo.flags |= flags; } void setFlags(Flags<InputWindowInfo::Flag> flags) { mInfo.flags = flags; } void setFlags(Flags<InputWindowInfo::Flag> flags) { mInfo.flags = flags; } void setInputFeatures(InputWindowInfo::Feature features) { mInfo.inputFeatures = features; } void setInputFeatures(InputWindowInfo::Feature features) { mInfo.inputFeatures = features; } Loading Loading @@ -4318,6 +4320,17 @@ TEST_F(InputDispatcherUntrustedTouchesTest, WindowWithBlockUntrustedOcclusionMod mTouchWindow->assertNoEvents(); 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) { TEST_F(InputDispatcherUntrustedTouchesTest, WindowWithAllowOcclusionMode_AllowsTouch) { const sp<FakeWindowHandle>& w = getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::ALLOW); const sp<FakeWindowHandle>& w = getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::ALLOW); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {w, mTouchWindow}}}); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {w, mTouchWindow}}}); Loading Loading @@ -4358,6 +4371,48 @@ TEST_F(InputDispatcherUntrustedTouchesTest, WindowWithZeroOpacity_AllowsTouch) { mTouchWindow->consumeAnyMotionDown(); 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) { TEST_F(InputDispatcherUntrustedTouchesTest, WindowWithOpacityBelowThreshold_AllowsTouch) { const sp<FakeWindowHandle>& w = const sp<FakeWindowHandle>& w = getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::USE_OPACITY, 0.7f); getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::USE_OPACITY, 0.7f); Loading Loading
services/inputflinger/tests/InputDispatcher_test.cpp +55 −0 Original line number Original line Diff line number Diff line Loading @@ -908,6 +908,8 @@ public: mInfo.addTouchableRegion(frame); mInfo.addTouchableRegion(frame); } } void addFlags(Flags<InputWindowInfo::Flag> flags) { mInfo.flags |= flags; } void setFlags(Flags<InputWindowInfo::Flag> flags) { mInfo.flags = flags; } void setFlags(Flags<InputWindowInfo::Flag> flags) { mInfo.flags = flags; } void setInputFeatures(InputWindowInfo::Feature features) { mInfo.inputFeatures = features; } void setInputFeatures(InputWindowInfo::Feature features) { mInfo.inputFeatures = features; } Loading Loading @@ -4318,6 +4320,17 @@ TEST_F(InputDispatcherUntrustedTouchesTest, WindowWithBlockUntrustedOcclusionMod mTouchWindow->assertNoEvents(); 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) { TEST_F(InputDispatcherUntrustedTouchesTest, WindowWithAllowOcclusionMode_AllowsTouch) { const sp<FakeWindowHandle>& w = getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::ALLOW); const sp<FakeWindowHandle>& w = getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::ALLOW); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {w, mTouchWindow}}}); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {w, mTouchWindow}}}); Loading Loading @@ -4358,6 +4371,48 @@ TEST_F(InputDispatcherUntrustedTouchesTest, WindowWithZeroOpacity_AllowsTouch) { mTouchWindow->consumeAnyMotionDown(); 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) { TEST_F(InputDispatcherUntrustedTouchesTest, WindowWithOpacityBelowThreshold_AllowsTouch) { const sp<FakeWindowHandle>& w = const sp<FakeWindowHandle>& w = getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::USE_OPACITY, 0.7f); getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::USE_OPACITY, 0.7f); Loading