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

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

Merge "Dynamically add STYLUS source for multi-touch devices"

parents 498f157d f9a41281
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -200,8 +200,7 @@ void MultiTouchInputMapper::configureRawPointerAxes() {
}

bool MultiTouchInputMapper::hasStylus() const {
    return mMultiTouchMotionAccumulator.hasStylus() || mTouchButtonAccumulator.hasStylus() ||
            shouldSimulateStylusWithTouch();
    return mTouchButtonAccumulator.hasStylus() || shouldSimulateStylusWithTouch();
}

bool MultiTouchInputMapper::shouldSimulateStylusWithTouch() const {
+9 −0
Original line number Diff line number Diff line
@@ -3762,12 +3762,15 @@ NotifyMotionArgs TouchInputMapper::dispatchMotion(
    PointerCoords pointerCoords[MAX_POINTERS];
    PointerProperties pointerProperties[MAX_POINTERS];
    uint32_t pointerCount = 0;
    bool stylusToolFound = false;
    while (!idBits.isEmpty()) {
        uint32_t id = idBits.clearFirstMarkedBit();
        uint32_t index = idToIndex[id];
        pointerProperties[pointerCount].copyFrom(properties[index]);
        pointerCoords[pointerCount].copyFrom(coords[index]);

        stylusToolFound |= isStylusToolType(pointerProperties[pointerCount].toolType);

        if (changedId >= 0 && id == uint32_t(changedId)) {
            action |= pointerCount << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
        }
@@ -3799,6 +3802,12 @@ NotifyMotionArgs TouchInputMapper::dispatchMotion(
    if (mDeviceMode == DeviceMode::POINTER) {
        mPointerController->getPosition(&xCursorPosition, &yCursorPosition);
    }
    if (stylusToolFound) {
        // Dynamically add the stylus source when there's a stylus tool being used to cover the case
        // where we cannot reliably detect whether a multi-touch device will ever produce stylus
        // events when it is initially being configured.
        source |= AINPUT_SOURCE_STYLUS;
    }
    const int32_t displayId = getAssociatedDisplayId().value_or(ADISPLAY_ID_NONE);
    const int32_t deviceId = getDeviceId();
    std::vector<TouchVideoFrame> frames = getDeviceContext().getVideoFrames();
+1 −6
Original line number Diff line number Diff line
@@ -24,12 +24,11 @@ namespace android {
// --- MultiTouchMotionAccumulator ---

MultiTouchMotionAccumulator::MultiTouchMotionAccumulator()
      : mCurrentSlot(-1), mUsingSlotsProtocol(false), mHaveStylus(false) {}
      : mCurrentSlot(-1), mUsingSlotsProtocol(false) {}

void MultiTouchMotionAccumulator::configure(InputDeviceContext& deviceContext, size_t slotCount,
                                            bool usingSlotsProtocol) {
    mUsingSlotsProtocol = usingSlotsProtocol;
    mHaveStylus = deviceContext.hasAbsoluteAxis(ABS_MT_TOOL_TYPE);
    mSlots = std::vector<Slot>(slotCount);

    mCurrentSlot = -1;
@@ -146,10 +145,6 @@ void MultiTouchMotionAccumulator::finishSync() {
    }
}

bool MultiTouchMotionAccumulator::hasStylus() const {
    return mHaveStylus;
}

void MultiTouchMotionAccumulator::warnIfNotInUse(const RawEvent& event, const Slot& slot) {
    if (!slot.mInUse) {
        ALOGW("Received unexpected event (0x%0x, 0x%0x) for slot %i with tracking id %i",
+0 −2
Original line number Diff line number Diff line
@@ -75,7 +75,6 @@ public:
    void configure(InputDeviceContext& deviceContext, size_t slotCount, bool usingSlotsProtocol);
    void process(const RawEvent* rawEvent);
    void finishSync();
    bool hasStylus() const;

    inline size_t getSlotCount() const { return mSlots.size(); }
    inline const Slot& getSlot(size_t index) const {
@@ -87,7 +86,6 @@ private:
    int32_t mCurrentSlot;
    std::vector<Slot> mSlots;
    bool mUsingSlotsProtocol;
    bool mHaveStylus;

    void resetSlots();
    void warnIfNotInUse(const RawEvent& event, const Slot& slot);
+43 −0
Original line number Diff line number Diff line
@@ -2577,6 +2577,14 @@ protected:
    InputDeviceInfo mDeviceInfo;
};
TEST_F(TouchIntegrationTest, MultiTouchDeviceSource) {
    // 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
    // presses).
    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS | AINPUT_SOURCE_KEYBOARD,
              mDeviceInfo.getSources());
}
TEST_F(TouchIntegrationTest, InputEvent_ProcessSingleTouch) {
    NotifyMotionArgs args;
    const Point centerPoint = mDevice->getCenterPoint();
@@ -10780,6 +10788,41 @@ TEST_F(MultiTouchInputMapperTest, Reset_PreservesLastTouchState_NoPointersDown)
    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled());
}
TEST_F(MultiTouchInputMapperTest, ToolTypeSource) {
    addConfigurationProperty("touch.deviceType", "touchScreen");
    prepareDisplay(DISPLAY_ORIENTATION_0);
    prepareAxes(POSITION | ID | SLOT | PRESSURE | TOOL_TYPE);
    MultiTouchInputMapper& mapper = addMapperAndConfigure<MultiTouchInputMapper>();
    // Even if the device supports reporting the ABS_MT_TOOL_TYPE axis, which could give it the
    // ability to report MT_TOOL_PEN, we do not report the device as coming from a stylus source.
    // Due to limitations in the evdev protocol, we cannot say for certain that a device is capable
    // of reporting stylus events just because it supports ABS_MT_TOOL_TYPE.
    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, mapper.getSources());
    // However, if the device ever ends up reporting an event with MT_TOOL_PEN, it should be
    // reported with the stylus source, even through the device doesn't support the stylus source.
    processId(mapper, FIRST_TRACKING_ID);
    processToolType(mapper, MT_TOOL_PEN);
    processPosition(mapper, 100, 200);
    processPressure(mapper, RAW_PRESSURE_MAX);
    processSync(mapper);
    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(
            AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
                  WithSource(AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS),
                  WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS))));
    processId(mapper, INVALID_TRACKING_ID);
    processSync(mapper);
    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(
            AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
                  WithSource(AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS),
                  WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS))));
    // The mapper should still report only a touchscreen source.
    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, mapper.getSources());
}
// --- MultiTouchInputMapperTest_ExternalDevice ---
class MultiTouchInputMapperTest_ExternalDevice : public MultiTouchInputMapperTest {