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

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

Merge "Convert tool type to enum class" into udc-dev

parents fbf33a76 6d73f83c
Loading
Loading
Loading
Loading
+18 −6
Original line number Diff line number Diff line
@@ -216,7 +216,21 @@ std::string inputEventSourceToString(int32_t source);

bool isFromSource(uint32_t source, uint32_t test);

bool isStylusToolType(uint32_t toolType);
/**
 * The pointer tool type.
 */
enum class ToolType {
    UNKNOWN = AMOTION_EVENT_TOOL_TYPE_UNKNOWN,
    FINGER = AMOTION_EVENT_TOOL_TYPE_FINGER,
    STYLUS = AMOTION_EVENT_TOOL_TYPE_STYLUS,
    MOUSE = AMOTION_EVENT_TOOL_TYPE_MOUSE,
    ERASER = AMOTION_EVENT_TOOL_TYPE_ERASER,
    PALM = AMOTION_EVENT_TOOL_TYPE_PALM,
    ftl_first = UNKNOWN,
    ftl_last = PALM,
};

bool isStylusToolType(ToolType toolType);

/*
 * Flags that flow alongside events in the input dispatch system to help with certain
@@ -320,8 +334,6 @@ enum class MotionClassification : uint8_t {
 */
const char* motionClassificationToString(MotionClassification classification);

const char* motionToolTypeToString(int32_t toolType);

/**
 * Portion of FrameMetrics timeline of interest to input code.
 */
@@ -448,11 +460,11 @@ struct PointerProperties {
    int32_t id;

    // The pointer tool type.
    int32_t toolType;
    ToolType toolType;

    inline void clear() {
        id = -1;
        toolType = 0;
        toolType = ToolType::UNKNOWN;
    }

    bool operator==(const PointerProperties& other) const;
@@ -638,7 +650,7 @@ public:
        return mPointerProperties[pointerIndex].id;
    }

    inline int32_t getToolType(size_t pointerIndex) const {
    inline ToolType getToolType(size_t pointerIndex) const {
        return mPointerProperties[pointerIndex].toolType;
    }

+0 −1
Original line number Diff line number Diff line
@@ -669,7 +669,6 @@ private:
    static void addSample(MotionEvent* event, const InputMessage* msg);
    static bool canAddSample(const Batch& batch, const InputMessage* msg);
    static ssize_t findSampleNoLaterThan(const Batch& batch, nsecs_t time);
    static bool shouldResampleTool(int32_t toolType);

    static bool isTouchResamplingEnabled();
};
+7 −26
Original line number Diff line number Diff line
@@ -79,25 +79,6 @@ const char* motionClassificationToString(MotionClassification classification) {
    }
}

const char* motionToolTypeToString(int32_t toolType) {
    switch (toolType) {
        case AMOTION_EVENT_TOOL_TYPE_UNKNOWN:
            return "UNKNOWN";
        case AMOTION_EVENT_TOOL_TYPE_FINGER:
            return "FINGER";
        case AMOTION_EVENT_TOOL_TYPE_STYLUS:
            return "STYLUS";
        case AMOTION_EVENT_TOOL_TYPE_MOUSE:
            return "MOUSE";
        case AMOTION_EVENT_TOOL_TYPE_ERASER:
            return "ERASER";
        case AMOTION_EVENT_TOOL_TYPE_PALM:
            return "PALM";
        default:
            return "INVALID";
    }
}

// --- IdGenerator ---
#if defined(__ANDROID__)
[[maybe_unused]]
@@ -256,8 +237,8 @@ bool isFromSource(uint32_t source, uint32_t test) {
    return (source & test) == test;
}

bool isStylusToolType(uint32_t toolType) {
    return toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS || toolType == AMOTION_EVENT_TOOL_TYPE_ERASER;
bool isStylusToolType(ToolType toolType) {
    return toolType == ToolType::STYLUS || toolType == ToolType::ERASER;
}

VerifiedKeyEvent verifiedKeyEventFromKeyEvent(const KeyEvent& event) {
@@ -810,7 +791,7 @@ status_t MotionEvent::readFromParcel(Parcel* parcel) {
        mPointerProperties.push_back({});
        PointerProperties& properties = mPointerProperties.back();
        properties.id = parcel->readInt32();
        properties.toolType = parcel->readInt32();
        properties.toolType = static_cast<ToolType>(parcel->readInt32());
    }

    while (sampleCount > 0) {
@@ -866,7 +847,7 @@ status_t MotionEvent::writeToParcel(Parcel* parcel) const {
    for (size_t i = 0; i < pointerCount; i++) {
        const PointerProperties& properties = mPointerProperties[i];
        parcel->writeInt32(properties.id);
        parcel->writeInt32(properties.toolType);
        parcel->writeInt32(static_cast<int32_t>(properties.toolType));
    }

    const PointerCoords* pc = mSamplePointerCoords.data();
@@ -1030,9 +1011,9 @@ std::ostream& operator<<(std::ostream& out, const MotionEvent& event) {
            out << ", x[" << i << "]=" << x;
            out << ", y[" << i << "]=" << y;
        }
        int toolType = event.getToolType(i);
        if (toolType != AMOTION_EVENT_TOOL_TYPE_FINGER) {
            out << ", toolType[" << i << "]=" << toolType;
        ToolType toolType = event.getToolType(i);
        if (toolType != ToolType::FINGER) {
            out << ", toolType[" << i << "]=" << ftl::enum_string(toolType);
        }
    }
    if (event.getButtonState() != 0) {
+4 −5
Original line number Diff line number Diff line
@@ -145,6 +145,10 @@ inline static const char* toString(bool value) {
    return value ? "true" : "false";
}

static bool shouldResampleTool(ToolType toolType) {
    return toolType == ToolType::FINGER || toolType == ToolType::UNKNOWN;
}

// --- InputMessage ---

bool InputMessage::isValid(size_t actualSize) const {
@@ -1274,11 +1278,6 @@ void InputConsumer::resampleTouchState(nsecs_t sampleTime, MotionEvent* event,
    event->addSample(sampleTime, touchState.lastResample.pointers);
}

bool InputConsumer::shouldResampleTool(int32_t toolType) {
    return toolType == AMOTION_EVENT_TOOL_TYPE_FINGER
            || toolType == AMOTION_EVENT_TOOL_TYPE_UNKNOWN;
}

status_t InputConsumer::sendFinishedSignal(uint32_t seq, bool handled) {
    ALOGD_IF(DEBUG_TRANSPORT_CONSUMER,
             "channel '%s' consumer ~ sendFinishedSignal: seq=%u, handled=%s",
+4 −3
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@
#include <log/log.h>

#include <attestation/HmacKeyManager.h>
#include <ftl/enum.h>
#include <input/TfLiteMotionPredictor.h>

namespace android {
@@ -108,10 +109,10 @@ android::base::Result<void> MotionPredictor::record(const MotionEvent& event) {
        return {};
    }

    const int32_t toolType = event.getPointerProperties(0)->toolType;
    if (toolType != AMOTION_EVENT_TOOL_TYPE_STYLUS) {
    const ToolType toolType = event.getPointerProperties(0)->toolType;
    if (toolType != ToolType::STYLUS) {
        ALOGD_IF(isDebug(), "Prediction not supported for non-stylus tool: %s",
                 motionToolTypeToString(toolType));
                 ftl::enum_string(toolType).c_str());
        return {};
    }

Loading