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

Commit 440bf65f authored by Arpit Singh's avatar Arpit Singh
Browse files

Test display associations in TouchIntegrationTest

Added test for display linked via a input-port and via a unique id

Bug: 285478143
Test: atest inputflinger_tests

Change-Id: I12fb815eec20b345545899a20dc28110bfd321f0
parent 4232a0d8
Loading
Loading
Loading
Loading
+84 −27
Original line number Original line Diff line number Diff line
@@ -1343,20 +1343,8 @@ protected:
        mFakePolicy = sp<FakeInputReaderPolicy>::make();
        mFakePolicy = sp<FakeInputReaderPolicy>::make();
        mFakePointerController = std::make_shared<FakePointerController>();
        mFakePointerController = std::make_shared<FakePointerController>();
        mFakePolicy->setPointerController(mFakePointerController);
        mFakePolicy->setPointerController(mFakePointerController);
        mTestListener = std::make_unique<TestInputListener>(/*eventHappenedTimeout=*/2000ms,
                                                            /*eventDidNotHappenTimeout=*/30ms);
        mReader = std::make_unique<InputReader>(std::make_shared<EventHub>(), mFakePolicy,
                                                *mTestListener);
        ASSERT_EQ(mReader->start(), OK);
        // Since this test is run on a real device, all the input devices connected
        setupInputReader();
        // to the test device will show up in mReader. We wait for those input devices to
        // show up before beginning the tests.
        ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertInputDevicesChanged());
        ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyInputDevicesChangedWasCalled());
        ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyConfigurationChangedWasCalled());
        mTestListener->clearNotifyDeviceResetCalls();
    }
    }
    void TearDown() override {
    void TearDown() override {
@@ -1377,6 +1365,22 @@ protected:
                                      });
                                      });
        return it != inputDevices.end() ? std::make_optional(*it) : std::nullopt;
        return it != inputDevices.end() ? std::make_optional(*it) : std::nullopt;
    }
    }
    void setupInputReader() {
        mTestListener = std::make_unique<TestInputListener>(/*eventHappenedTimeout=*/2000ms,
                                                            /*eventDidNotHappenTimeout=*/30ms);
        mReader = std::make_unique<InputReader>(std::make_shared<EventHub>(), mFakePolicy,
                                                *mTestListener);
        ASSERT_EQ(mReader->start(), OK);
        // Since this test is run on a real device, all the input devices connected
        // to the test device will show up in mReader. We wait for those input devices to
        // show up before beginning the tests.
        ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertInputDevicesChanged());
        ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyInputDevicesChangedWasCalled());
        ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyConfigurationChangedWasCalled());
    }
};
};
TEST_F(InputReaderIntegrationTest, TestInvalidDevice) {
TEST_F(InputReaderIntegrationTest, TestInvalidDevice) {
@@ -1510,7 +1514,7 @@ TEST_F(InputReaderIntegrationTest, SendsGearDownAndUpToInputListener) {
// --- TouchIntegrationTest ---
// --- TouchIntegrationTest ---
class TouchIntegrationTest : public InputReaderIntegrationTest {
class BaseTouchIntegrationTest : public InputReaderIntegrationTest {
protected:
protected:
    const std::string UNIQUE_ID = "local:0";
    const std::string UNIQUE_ID = "local:0";
@@ -1555,7 +1559,55 @@ protected:
    InputDeviceInfo mDeviceInfo;
    InputDeviceInfo mDeviceInfo;
};
};
TEST_F(TouchIntegrationTest, MultiTouchDeviceSource) {
enum class TouchIntegrationTestDisplays { DISPLAY_INTERNAL, DISPLAY_INPUT_PORT, DISPLAY_UNIQUE_ID };
class TouchIntegrationTest : public BaseTouchIntegrationTest,
                             public testing::WithParamInterface<TouchIntegrationTestDisplays> {
protected:
    static constexpr std::optional<uint8_t> DISPLAY_PORT = 0;
    const std::string INPUT_PORT = "uinput_touch/input0";
    void SetUp() override {
#if !defined(__ANDROID__)
        GTEST_SKIP();
#endif
        if (GetParam() == TouchIntegrationTestDisplays::DISPLAY_INTERNAL) {
            BaseTouchIntegrationTest::SetUp();
            return;
        }
        // setup policy with a input-port or UniqueId association to the display
        bool isInputPortAssociation =
                GetParam() == TouchIntegrationTestDisplays::DISPLAY_INPUT_PORT;
        mFakePolicy = sp<FakeInputReaderPolicy>::make();
        if (isInputPortAssociation) {
            mFakePolicy->addInputPortAssociation(INPUT_PORT, DISPLAY_PORT.value());
        } else {
            mFakePolicy->addInputUniqueIdAssociation(INPUT_PORT, UNIQUE_ID);
        }
        mFakePointerController = std::make_shared<FakePointerController>();
        mFakePolicy->setPointerController(mFakePointerController);
        InputReaderIntegrationTest::setupInputReader();
        mDevice = createUinputDevice<UinputTouchScreen>(Rect(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT),
                                                        INPUT_PORT);
        ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertInputDevicesChanged());
        // Add a display linked to a physical port or UniqueId.
        setDisplayInfoAndReconfigure(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_0,
                                     UNIQUE_ID, isInputPortAssociation ? DISPLAY_PORT : NO_PORT,
                                     ViewportType::INTERNAL);
        ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertInputDevicesChanged());
        ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyConfigurationChangedWasCalled());
        const auto info = findDeviceByName(mDevice->getName());
        ASSERT_TRUE(info);
        mDeviceInfo = *info;
    }
};
TEST_P(TouchIntegrationTest, MultiTouchDeviceSource) {
    // The UinputTouchScreen is an MT device that supports MT_TOOL_TYPE and also supports stylus
    // The UinputTouchScreen is an MT device that supports MT_TOOL_TYPE and also supports stylus
    // buttons. It should show up as a touchscreen, stylus, and keyboard (for reporting button
    // buttons. It should show up as a touchscreen, stylus, and keyboard (for reporting button
    // presses).
    // presses).
@@ -1563,7 +1615,7 @@ TEST_F(TouchIntegrationTest, MultiTouchDeviceSource) {
              mDeviceInfo.getSources());
              mDeviceInfo.getSources());
}
}
TEST_F(TouchIntegrationTest, InputEvent_ProcessSingleTouch) {
TEST_P(TouchIntegrationTest, InputEvent_ProcessSingleTouch) {
    NotifyMotionArgs args;
    NotifyMotionArgs args;
    const Point centerPoint = mDevice->getCenterPoint();
    const Point centerPoint = mDevice->getCenterPoint();
@@ -1587,7 +1639,7 @@ TEST_F(TouchIntegrationTest, InputEvent_ProcessSingleTouch) {
    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, args.action);
    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, args.action);
}
}
TEST_F(TouchIntegrationTest, InputEvent_ProcessMultiTouch) {
TEST_P(TouchIntegrationTest, InputEvent_ProcessMultiTouch) {
    NotifyMotionArgs args;
    NotifyMotionArgs args;
    const Point centerPoint = mDevice->getCenterPoint();
    const Point centerPoint = mDevice->getCenterPoint();
@@ -1643,7 +1695,7 @@ TEST_F(TouchIntegrationTest, InputEvent_ProcessMultiTouch) {
 * palms, and wants to cancel Pointer 1, then it is safe to simply drop POINTER_1_UP event without
 * palms, and wants to cancel Pointer 1, then it is safe to simply drop POINTER_1_UP event without
 * losing information about non-palm pointers.
 * losing information about non-palm pointers.
 */
 */
TEST_F(TouchIntegrationTest, MultiTouch_PointerMoveAndSecondPointerUp) {
TEST_P(TouchIntegrationTest, MultiTouch_PointerMoveAndSecondPointerUp) {
    NotifyMotionArgs args;
    NotifyMotionArgs args;
    const Point centerPoint = mDevice->getCenterPoint();
    const Point centerPoint = mDevice->getCenterPoint();
@@ -1686,7 +1738,7 @@ TEST_F(TouchIntegrationTest, MultiTouch_PointerMoveAndSecondPointerUp) {
 * In this scenario, the movement of the second pointer just prior to liftoff is ignored, and never
 * In this scenario, the movement of the second pointer just prior to liftoff is ignored, and never
 * gets sent to the listener.
 * gets sent to the listener.
 */
 */
TEST_F(TouchIntegrationTest, MultiTouch_PointerMoveAndSecondPointerMoveAndUp) {
TEST_P(TouchIntegrationTest, MultiTouch_PointerMoveAndSecondPointerMoveAndUp) {
    NotifyMotionArgs args;
    NotifyMotionArgs args;
    const Point centerPoint = mDevice->getCenterPoint();
    const Point centerPoint = mDevice->getCenterPoint();
@@ -1726,7 +1778,7 @@ TEST_F(TouchIntegrationTest, MultiTouch_PointerMoveAndSecondPointerMoveAndUp) {
    assertReceivedMotion(AMOTION_EVENT_ACTION_MOVE, {centerPoint + Point(5, 5)});
    assertReceivedMotion(AMOTION_EVENT_ACTION_MOVE, {centerPoint + Point(5, 5)});
}
}
TEST_F(TouchIntegrationTest, InputEvent_ProcessPalm) {
TEST_P(TouchIntegrationTest, InputEvent_ProcessPalm) {
    NotifyMotionArgs args;
    NotifyMotionArgs args;
    const Point centerPoint = mDevice->getCenterPoint();
    const Point centerPoint = mDevice->getCenterPoint();
@@ -1777,7 +1829,7 @@ TEST_F(TouchIntegrationTest, InputEvent_ProcessPalm) {
    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, args.action);
    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, args.action);
}
}
TEST_F(TouchIntegrationTest, NotifiesPolicyWhenStylusGestureStarted) {
TEST_P(TouchIntegrationTest, NotifiesPolicyWhenStylusGestureStarted) {
    const Point centerPoint = mDevice->getCenterPoint();
    const Point centerPoint = mDevice->getCenterPoint();
    // Send down with the pen tool selected. The policy should be notified of the stylus presence.
    // Send down with the pen tool selected. The policy should be notified of the stylus presence.
@@ -1829,7 +1881,7 @@ TEST_F(TouchIntegrationTest, NotifiesPolicyWhenStylusGestureStarted) {
    ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertStylusGestureNotified(mDeviceInfo.getId()));
    ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertStylusGestureNotified(mDeviceInfo.getId()));
}
}
TEST_F(TouchIntegrationTest, ExternalStylusConnectedDuringTouchGesture) {
TEST_P(TouchIntegrationTest, ExternalStylusConnectedDuringTouchGesture) {
    const Point centerPoint = mDevice->getCenterPoint();
    const Point centerPoint = mDevice->getCenterPoint();
    // Down
    // Down
@@ -1874,19 +1926,24 @@ TEST_F(TouchIntegrationTest, ExternalStylusConnectedDuringTouchGesture) {
    ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasNotCalled());
    ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasNotCalled());
}
}
INSTANTIATE_TEST_SUITE_P(TouchIntegrationTestDisplayVariants, TouchIntegrationTest,
                         testing::Values(TouchIntegrationTestDisplays::DISPLAY_INTERNAL,
                                         TouchIntegrationTestDisplays::DISPLAY_INPUT_PORT,
                                         TouchIntegrationTestDisplays::DISPLAY_UNIQUE_ID));
// --- StylusButtonIntegrationTest ---
// --- StylusButtonIntegrationTest ---
// Verify the behavior of button presses reported by various kinds of styluses, including buttons
// Verify the behavior of button presses reported by various kinds of styluses, including buttons
// reported by the touchscreen's device, by a fused external stylus, and by an un-fused external
// reported by the touchscreen's device, by a fused external stylus, and by an un-fused external
// stylus.
// stylus.
template <typename UinputStylusDevice>
template <typename UinputStylusDevice>
class StylusButtonIntegrationTest : public TouchIntegrationTest {
class StylusButtonIntegrationTest : public BaseTouchIntegrationTest {
protected:
protected:
    void SetUp() override {
    void SetUp() override {
#if !defined(__ANDROID__)
#if !defined(__ANDROID__)
        GTEST_SKIP();
        GTEST_SKIP();
#endif
#endif
        TouchIntegrationTest::SetUp();
        BaseTouchIntegrationTest::SetUp();
        mTouchscreen = mDevice.get();
        mTouchscreen = mDevice.get();
        mTouchscreenInfo = mDeviceInfo;
        mTouchscreenInfo = mDeviceInfo;
@@ -1924,8 +1981,8 @@ private:
    std::unique_ptr<UinputStylusDevice> mStylusDeviceLifecycleTracker{};
    std::unique_ptr<UinputStylusDevice> mStylusDeviceLifecycleTracker{};
    // Hide the base class's device to expose it with a different name for readability.
    // Hide the base class's device to expose it with a different name for readability.
    using TouchIntegrationTest::mDevice;
    using BaseTouchIntegrationTest::mDevice;
    using TouchIntegrationTest::mDeviceInfo;
    using BaseTouchIntegrationTest::mDeviceInfo;
};
};
using StylusButtonIntegrationTestTypes =
using StylusButtonIntegrationTestTypes =
@@ -2177,7 +2234,7 @@ TYPED_TEST(StylusButtonIntegrationTest, StylusButtonMotionEventsDisabled) {
// Verify the behavior of an external stylus. An external stylus can report pressure or button
// Verify the behavior of an external stylus. An external stylus can report pressure or button
// data independently of the touchscreen, which is then sent as a MotionEvent as part of an
// data independently of the touchscreen, which is then sent as a MotionEvent as part of an
// ongoing stylus gesture that is being emitted by the touchscreen.
// ongoing stylus gesture that is being emitted by the touchscreen.
using ExternalStylusIntegrationTest = TouchIntegrationTest;
using ExternalStylusIntegrationTest = BaseTouchIntegrationTest;
TEST_F(ExternalStylusIntegrationTest, FusedExternalStylusPressureReported) {
TEST_F(ExternalStylusIntegrationTest, FusedExternalStylusPressureReported) {
    const Point centerPoint = mDevice->getCenterPoint();
    const Point centerPoint = mDevice->getCenterPoint();
+6 −2
Original line number Original line Diff line number Diff line
@@ -159,10 +159,11 @@ void UinputExternalStylusWithPressure::setPressure(int32_t pressure) {


// --- UinputTouchScreen ---
// --- UinputTouchScreen ---


UinputTouchScreen::UinputTouchScreen(const Rect& size)
UinputTouchScreen::UinputTouchScreen(const Rect& size, const std::string& physicalPort)
      : UinputKeyboard(DEVICE_NAME, PRODUCT_ID,
      : UinputKeyboard(DEVICE_NAME, PRODUCT_ID,
                       {BTN_TOUCH, BTN_TOOL_PEN, BTN_STYLUS, BTN_STYLUS2, BTN_STYLUS3}),
                       {BTN_TOUCH, BTN_TOOL_PEN, BTN_STYLUS, BTN_STYLUS2, BTN_STYLUS3}),
        mSize(size) {}
        mSize(size),
        mPhysicalPort(physicalPort) {}


void UinputTouchScreen::configureDevice(int fd, uinput_user_dev* device) {
void UinputTouchScreen::configureDevice(int fd, uinput_user_dev* device) {
    UinputKeyboard::configureDevice(fd, device);
    UinputKeyboard::configureDevice(fd, device);
@@ -177,6 +178,9 @@ void UinputTouchScreen::configureDevice(int fd, uinput_user_dev* device) {
    ioctl(fd, UI_SET_ABSBIT, ABS_MT_TRACKING_ID);
    ioctl(fd, UI_SET_ABSBIT, ABS_MT_TRACKING_ID);
    ioctl(fd, UI_SET_ABSBIT, ABS_MT_TOOL_TYPE);
    ioctl(fd, UI_SET_ABSBIT, ABS_MT_TOOL_TYPE);
    ioctl(fd, UI_SET_PROPBIT, INPUT_PROP_DIRECT);
    ioctl(fd, UI_SET_PROPBIT, INPUT_PROP_DIRECT);
    if (!mPhysicalPort.empty()) {
        ioctl(fd, UI_SET_PHYS, mPhysicalPort.c_str());
    }


    device->absmin[ABS_MT_SLOT] = RAW_SLOT_MIN;
    device->absmin[ABS_MT_SLOT] = RAW_SLOT_MIN;
    device->absmax[ABS_MT_SLOT] = RAW_SLOT_MAX;
    device->absmax[ABS_MT_SLOT] = RAW_SLOT_MAX;
+2 −1
Original line number Original line Diff line number Diff line
@@ -197,11 +197,12 @@ public:
    const Point getCenterPoint();
    const Point getCenterPoint();


protected:
protected:
    explicit UinputTouchScreen(const Rect& size);
    explicit UinputTouchScreen(const Rect& size, const std::string& physicalPort = "");


private:
private:
    void configureDevice(int fd, uinput_user_dev* device) override;
    void configureDevice(int fd, uinput_user_dev* device) override;
    const Rect mSize;
    const Rect mSize;
    const std::string mPhysicalPort;
};
};


} // namespace android
} // namespace android