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

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

Merge "Add a debug flag to convert all touch pointers to stylus"

parents 032ad49a f4d65b13
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ cc_defaults {
        "libstatslog",
        "libui",
        "libutils",
        "PlatformProperties",
    ],
    static_libs: [
        "libc++fs",
+15 −1
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@

#include "MultiTouchInputMapper.h"

#include <android/sysprop/InputProperties.sysprop.h>

namespace android {

// --- Constants ---
@@ -309,6 +311,10 @@ void MultiTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) {
                outPointer.toolType = AMOTION_EVENT_TOOL_TYPE_FINGER;
            }
        }
        if (shouldSimulateStylusWithTouch() &&
            outPointer.toolType == AMOTION_EVENT_TOOL_TYPE_FINGER) {
            outPointer.toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS;
        }

        bool isHovering = mTouchButtonAccumulator.getToolType() != AMOTION_EVENT_TOOL_TYPE_MOUSE &&
                (mTouchButtonAccumulator.isHovering() ||
@@ -385,7 +391,15 @@ void MultiTouchInputMapper::configureRawPointerAxes() {
}

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

bool MultiTouchInputMapper::shouldSimulateStylusWithTouch() const {
    static const bool SIMULATE_STYLUS_WITH_TOUCH =
            sysprop::InputProperties::simulate_stylus_with_touch().value_or(false);
    return SIMULATE_STYLUS_WITH_TOUCH &&
            mParameters.deviceType == Parameters::DeviceType::TOUCH_SCREEN;
}

} // namespace android
+8 −0
Original line number Diff line number Diff line
@@ -104,6 +104,14 @@ protected:
    bool hasStylus() const override;

private:
    // simulate_stylus_with_touch is a debug mode that converts all finger pointers reported by this
    // mapper's touchscreen into stylus pointers, and adds SOURCE_STYLUS to the input device.
    // It is used to simulate stylus events for debugging and testing on a device that does not
    // support styluses. It can be enabled using
    // "adb shell setprop persist.debug.input.simulate_stylus_with_touch true",
    // and requires a reboot to take effect.
    inline bool shouldSimulateStylusWithTouch() const;

    // If the slot is in use, return the bit id. Return std::nullopt otherwise.
    std::optional<int32_t> getActiveBitId(const MultiTouchMotionAccumulator::Slot& inSlot);
    MultiTouchMotionAccumulator mMultiTouchMotionAccumulator;