diff options
-rw-r--r-- | services/inputflinger/dispatcher/TouchedWindow.cpp | 14 | ||||
-rw-r--r-- | services/inputflinger/dispatcher/TouchedWindow.h | 8 | ||||
-rw-r--r-- | services/inputflinger/tests/InputDispatcher_test.cpp | 32 |
3 files changed, 36 insertions, 18 deletions
diff --git a/services/inputflinger/dispatcher/TouchedWindow.cpp b/services/inputflinger/dispatcher/TouchedWindow.cpp index 536775100a..cd0500c872 100644 --- a/services/inputflinger/dispatcher/TouchedWindow.cpp +++ b/services/inputflinger/dispatcher/TouchedWindow.cpp @@ -128,20 +128,14 @@ void TouchedWindow::removeTouchingPointers(DeviceId deviceId, std::set<DeviceId> TouchedWindow::getTouchingDeviceIds() const { std::set<DeviceId> deviceIds; - for (const auto& [deviceId, _] : mDeviceStates) { - deviceIds.insert(deviceId); + for (const auto& [deviceId, deviceState] : mDeviceStates) { + if (deviceState.touchingPointerIds.any()) { + deviceIds.insert(deviceId); + } } return deviceIds; } -std::set<DeviceId> TouchedWindow::getActiveDeviceIds() const { - std::set<DeviceId> out; - for (const auto& [deviceId, _] : mDeviceStates) { - out.emplace(deviceId); - } - return out; -} - bool TouchedWindow::hasPilferingPointers(DeviceId deviceId) const { const auto stateIt = mDeviceStates.find(deviceId); if (stateIt == mDeviceStates.end()) { diff --git a/services/inputflinger/dispatcher/TouchedWindow.h b/services/inputflinger/dispatcher/TouchedWindow.h index 6d2283e0af..9a31678955 100644 --- a/services/inputflinger/dispatcher/TouchedWindow.h +++ b/services/inputflinger/dispatcher/TouchedWindow.h @@ -48,15 +48,7 @@ struct TouchedWindow { void addTouchingPointers(DeviceId deviceId, std::bitset<MAX_POINTER_ID + 1> pointers); void removeTouchingPointer(DeviceId deviceId, int32_t pointerId); void removeTouchingPointers(DeviceId deviceId, std::bitset<MAX_POINTER_ID + 1> pointers); - /** - * Get the currently active touching device id. If there isn't exactly 1 touching device, return - * nullopt. - */ std::set<DeviceId> getTouchingDeviceIds() const; - /** - * The ids of devices that are currently touching or hovering. - */ - std::set<DeviceId> getActiveDeviceIds() const; // Pilfering pointers bool hasPilferingPointers(DeviceId deviceId) const; diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp index 4d7a170088..0cedbf896d 100644 --- a/services/inputflinger/tests/InputDispatcher_test.cpp +++ b/services/inputflinger/tests/InputDispatcher_test.cpp @@ -9938,6 +9938,19 @@ TEST_F(InputDispatcherDragTests, DragAndDropFinishedWhenCancelCurrentTouch) { ASSERT_NO_FATAL_FAILURE(mWindow->consumeMotionUp()); } +TEST_F(InputDispatcherDragTests, NoDragAndDropWithHoveringPointer) { + // Start hovering over the window. + ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, + injectMotionEvent(*mDispatcher, ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE, + ADISPLAY_ID_DEFAULT, {50, 50})); + + ASSERT_NO_FATAL_FAILURE(mWindow->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER))); + ASSERT_NO_FATAL_FAILURE(mSpyWindow->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER))); + + ASSERT_FALSE(startDrag(/*sendDown=*/false)) + << "Drag and drop should not work with a hovering pointer"; +} + class InputDispatcherDropInputFeatureTest : public InputDispatcherTest {}; TEST_F(InputDispatcherDropInputFeatureTest, WindowDropsInput) { @@ -10836,6 +10849,25 @@ TEST_F(InputDispatcherPilferPointersTest, MultiDevicePilfer) { rightWindow->assertNoEvents(); } +TEST_F(InputDispatcherPilferPointersTest, NoPilferingWithHoveringPointers) { + auto window = createForeground(); + auto spy = createSpy(); + mDispatcher->onWindowInfosChanged({{*spy->getInfo(), *window->getInfo()}, {}, 0, 0}); + + mDispatcher->notifyMotion( + MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE) + .deviceId(1) + .pointer(PointerBuilder(/*id=*/0, ToolType::MOUSE).x(100).y(200)) + .build()); + window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); + spy->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); + + // Pilfer pointers from the spy window should fail. + EXPECT_NE(OK, mDispatcher->pilferPointers(spy->getToken())); + spy->assertNoEvents(); + window->assertNoEvents(); +} + class InputDispatcherStylusInterceptorTest : public InputDispatcherTest { public: std::pair<sp<FakeWindowHandle>, sp<FakeWindowHandle>> setupStylusOverlayScenario() { |