Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2fa81001 authored by Prabir Pradhan's avatar Prabir Pradhan Committed by Android (Google) Code Review
Browse files

Merge "Ensure drag-and-drop and pilfering does not work with hovering pointers" into main

parents 566f1dcd 9cd9eb66
Loading
Loading
Loading
Loading
+4 −10
Original line number Diff line number Diff line
@@ -128,18 +128,12 @@ void TouchedWindow::removeTouchingPointers(DeviceId deviceId,

std::set<DeviceId> TouchedWindow::getTouchingDeviceIds() const {
    std::set<DeviceId> deviceIds;
    for (const auto& [deviceId, _] : mDeviceStates) {
    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;
    return deviceIds;
}

bool TouchedWindow::hasPilferingPointers(DeviceId deviceId) const {
+0 −8
Original line number Diff line number Diff line
@@ -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;
+32 −0
Original line number Diff line number Diff line
@@ -9997,6 +9997,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) {
@@ -10896,6 +10909,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() {