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

Commit e562696c authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

Input: Add isStylusToolType() utility function

Using this utility function will ensure we don't forget to check for
both TOOL_TYPE_STYLUS and TOOL_TYPE_ERASER when we are looking to
identify a stylus.

This will cause a behavior change in UnwantedInteractionBlocker, where
TOOL_TYPE_ERASER was not previously considered a stylus tool.

Bug: None
Test: atest inputflinger_tests
Change-Id: I3dae9b5037d7ac08a5672c6e4d6e3b62ee2bd352
parent 3f7545f4
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -209,6 +209,8 @@ std::string inputEventSourceToString(int32_t source);

bool isFromSource(uint32_t source, uint32_t test);

bool isStylusToolType(uint32_t toolType);

/*
 * Flags that flow alongside events in the input dispatch system to help with certain
 * policy decisions such as waking from device sleep.
+4 −0
Original line number Diff line number Diff line
@@ -238,6 +238,10 @@ 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;
}

VerifiedKeyEvent verifiedKeyEventFromKeyEvent(const KeyEvent& event) {
    return {{VerifiedInputEvent::Type::KEY, event.getDeviceId(), event.getEventTime(),
             event.getSource(), event.getDisplayId()},
+1 −2
Original line number Diff line number Diff line
@@ -25,8 +25,7 @@ static std::pair<bool, bool> checkToolType(const NotifyMotionArgs& args) {
    for (size_t i = 0; i < args.pointerCount; i++) {
        // Make sure we are canceling stylus pointers
        const int32_t toolType = args.pointerProperties[i].toolType;
        if (toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS ||
            toolType == AMOTION_EVENT_TOOL_TYPE_ERASER) {
        if (isStylusToolType(toolType)) {
            hasStylus = true;
        }
        if (toolType == AMOTION_EVENT_TOOL_TYPE_FINGER) {
+11 −8
Original line number Diff line number Diff line
@@ -99,15 +99,18 @@ static bool isPalmRejectionEnabled() {
}

static int getLinuxToolCode(int toolType) {
    if (toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS) {
    switch (toolType) {
        case AMOTION_EVENT_TOOL_TYPE_STYLUS:
            return BTN_TOOL_PEN;
    }
    if (toolType == AMOTION_EVENT_TOOL_TYPE_FINGER) {
        case AMOTION_EVENT_TOOL_TYPE_ERASER:
            return BTN_TOOL_RUBBER;
        case AMOTION_EVENT_TOOL_TYPE_FINGER:
            return BTN_TOOL_FINGER;
    }
        default:
            ALOGW("Got tool type %" PRId32 ", converting to BTN_TOOL_FINGER", toolType);
            return BTN_TOOL_FINGER;
    }
}

static int32_t getActionUpForPointerId(const NotifyMotionArgs& args, int32_t pointerId) {
    for (size_t i = 0; i < args.pointerCount; i++) {
@@ -195,7 +198,7 @@ NotifyMotionArgs removePointerIds(const NotifyMotionArgs& args,
static std::optional<NotifyMotionArgs> removeStylusPointerIds(const NotifyMotionArgs& args) {
    std::set<int32_t> stylusPointerIds;
    for (uint32_t i = 0; i < args.pointerCount; i++) {
        if (args.pointerProperties[i].toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS) {
        if (isStylusToolType(args.pointerProperties[i].toolType)) {
            stylusPointerIds.insert(args.pointerProperties[i].id);
        }
    }
+1 −2
Original line number Diff line number Diff line
@@ -479,8 +479,7 @@ bool windowAcceptsTouchAt(const WindowInfo& windowInfo, int32_t displayId, int32

bool isPointerFromStylus(const MotionEntry& entry, int32_t pointerIndex) {
    return isFromSource(entry.source, AINPUT_SOURCE_STYLUS) &&
            (entry.pointerProperties[pointerIndex].toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS ||
             entry.pointerProperties[pointerIndex].toolType == AMOTION_EVENT_TOOL_TYPE_ERASER);
            isStylusToolType(entry.pointerProperties[pointerIndex].toolType);
}

// Determines if the given window can be targeted as InputTarget::FLAG_FOREGROUND.
Loading