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

Commit b0ba2136 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 9546944 from bd6c28dd to udc-release

Change-Id: Ib6e65071e0d0ff284af59597abf5d2b9949ad0e0
parents a956178b bd6c28dd
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -64,6 +64,11 @@ public:
    // For main functions - dangerous for libraries to use
    status_t setThreadPoolMaxThreadCount(size_t maxThreads);
    status_t enableOnewaySpamDetection(bool enable);

    // Set the name of the current thread to look like a threadpool
    // thread. Typically this is called before joinThreadPool.
    //
    // TODO: remove this API, and automatically set it intelligently.
    void giveThreadPoolName();

    String8 getDriverName();
+1 −1
Original line number Diff line number Diff line
@@ -402,7 +402,7 @@ void InputProcessor::setMotionClassifierEnabled(bool enabled) {
            { // acquire lock
                std::scoped_lock threadLock(mLock);
                mHalDeathRecipient =
                        std::make_unique<ScopedDeathRecipient>(onBinderDied, this /*cookie*/);
                        std::make_unique<ScopedDeathRecipient>(onBinderDied, /*cookie=*/this);
                mHalDeathRecipient->linkToDeath(service->asBinder().get());
                setMotionClassifierLocked(MotionClassifier::create(std::move(service)));
            } // release lock
+4 −4
Original line number Diff line number Diff line
@@ -141,7 +141,7 @@ public:
                ALOGE("Waited too long for consumer to produce an event, giving up");
                break;
            }
            result = mConsumer->consume(&mEventFactory, true /*consumeBatches*/, -1, &consumeSeq,
            result = mConsumer->consume(&mEventFactory, /*consumeBatches=*/true, -1, &consumeSeq,
                                        &event);
        }
        if (result != OK) {
@@ -308,13 +308,13 @@ static void benchmarkInjectMotion(benchmark::State& state) {
    for (auto _ : state) {
        MotionEvent event = generateMotionEvent();
        // Send ACTION_DOWN
        dispatcher.injectInputEvent(&event, {} /*targetUid*/, InputEventInjectionSync::NONE,
        dispatcher.injectInputEvent(&event, /*targetUid=*/{}, InputEventInjectionSync::NONE,
                                    INJECT_EVENT_TIMEOUT,
                                    POLICY_FLAG_FILTERED | POLICY_FLAG_PASS_TO_USER);

        // Send ACTION_UP
        event.setAction(AMOTION_EVENT_ACTION_UP);
        dispatcher.injectInputEvent(&event, {} /*targetUid*/, InputEventInjectionSync::NONE,
        dispatcher.injectInputEvent(&event, /*targetUid=*/{}, InputEventInjectionSync::NONE,
                                    INJECT_EVENT_TIMEOUT,
                                    POLICY_FLAG_FILTERED | POLICY_FLAG_PASS_TO_USER);

@@ -344,7 +344,7 @@ static void benchmarkOnWindowInfosChanged(benchmark::State& state) {

    for (auto _ : state) {
        dispatcher.onWindowInfosChanged(windowInfos, displayInfos);
        dispatcher.onWindowInfosChanged({} /*windowInfos*/, {} /*displayInfos*/);
        dispatcher.onWindowInfosChanged(/*windowInfos=*/{}, /*displayInfos=*/{});
    }
    dispatcher.stop();
}
+49 −30
Original line number Diff line number Diff line
@@ -670,8 +670,7 @@ InputDispatcher::~InputDispatcher() {

    while (!mConnectionsByToken.empty()) {
        sp<Connection> connection = mConnectionsByToken.begin()->second;
        removeInputChannelLocked(connection->inputChannel->getConnectionToken(),
                                 false /* notify */);
        removeInputChannelLocked(connection->inputChannel->getConnectionToken(), /*notify=*/false);
    }
}

@@ -1023,7 +1022,7 @@ bool InputDispatcher::shouldPruneInboundQueueLocked(const MotionEntry& motionEnt
    if (isPointerDownEvent && mAwaitedFocusedApplication != nullptr) {
        const int32_t displayId = motionEntry.displayId;
        const auto [x, y] = resolveTouchedPosition(motionEntry);
        const bool isStylus = isPointerFromStylus(motionEntry, 0 /*pointerIndex*/);
        const bool isStylus = isPointerFromStylus(motionEntry, /*pointerIndex=*/0);

        auto [touchedWindowHandle, _] = findTouchedWindowAtLocked(displayId, x, y, isStylus);
        if (touchedWindowHandle != nullptr &&
@@ -2303,8 +2302,13 @@ std::vector<InputTarget> InputDispatcher::findTouchedWindowTargetsLocked(
                pointerIds.markBit(entry.pointerProperties[pointerIndex].id);
            }

            const bool isDownOrPointerDown = maskedAction == AMOTION_EVENT_ACTION_DOWN ||
                    maskedAction == AMOTION_EVENT_ACTION_POINTER_DOWN;

            tempTouchState.addOrUpdateWindow(windowHandle, targetFlags, pointerIds,
                                             entry.eventTime);
                                             isDownOrPointerDown
                                                     ? std::make_optional(entry.eventTime)
                                                     : std::nullopt);

            // If this is the pointer going down and the touched window has a wallpaper
            // then also add the touched wallpaper windows so they are locked in for the duration
@@ -2312,8 +2316,7 @@ std::vector<InputTarget> InputDispatcher::findTouchedWindowTargetsLocked(
            // We do not collect wallpapers during HOVER_MOVE or SCROLL because the wallpaper
            // engine only supports touch events.  We would need to add a mechanism similar
            // to View.onGenericMotionEvent to enable wallpapers to handle these events.
            if (maskedAction == AMOTION_EVENT_ACTION_DOWN ||
                maskedAction == AMOTION_EVENT_ACTION_POINTER_DOWN) {
            if (isDownOrPointerDown) {
                if (targetFlags.test(InputTarget::Flags::FOREGROUND) &&
                    windowHandle->getInfo()->inputConfig.test(
                            gui::WindowInfo::InputConfig::DUPLICATE_TOUCH_TO_WALLPAPER)) {
@@ -2333,14 +2336,22 @@ std::vector<InputTarget> InputDispatcher::findTouchedWindowTargetsLocked(
            }
        }

        // If any existing window is pilfering pointers from newly added window, remove it
        BitSet32 canceledPointers = BitSet32(0);
        for (const TouchedWindow& window : tempTouchState.windows) {
            if (window.isPilferingPointers) {
                canceledPointers |= window.pointerIds;
        // If a window is already pilfering some pointers, give it this new pointer as well and
        // make it pilfering. This will prevent other non-spy windows from getting this pointer,
        // which is a specific behaviour that we want.
        const int32_t pointerId = entry.pointerProperties[pointerIndex].id;
        for (TouchedWindow& touchedWindow : tempTouchState.windows) {
            if (touchedWindow.pointerIds.hasBit(pointerId) &&
                touchedWindow.pilferedPointerIds.count() > 0) {
                // This window is already pilfering some pointers, and this new pointer is also
                // going to it. Therefore, take over this pointer and don't give it to anyone
                // else.
                touchedWindow.pilferedPointerIds.set(pointerId);
            }
        }
        tempTouchState.cancelPointersForNonPilferingWindows(canceledPointers);

        // Restrict all pilfered pointers to the pilfering windows.
        tempTouchState.cancelPointersForNonPilferingWindows();
    } else {
        /* Case 2: Pointer move, up, cancel or non-splittable pointer down. */

@@ -2360,7 +2371,7 @@ std::vector<InputTarget> InputDispatcher::findTouchedWindowTargetsLocked(
        if (maskedAction == AMOTION_EVENT_ACTION_MOVE && entry.pointerCount == 1 &&
            tempTouchState.isSlippery()) {
            const auto [x, y] = resolveTouchedPosition(entry);
            const bool isStylus = isPointerFromStylus(entry, 0 /*pointerIndex*/);
            const bool isStylus = isPointerFromStylus(entry, /*pointerIndex=*/0);
            sp<WindowInfoHandle> oldTouchedWindowHandle =
                    tempTouchState.getFirstForegroundWindowHandle();
            auto [newTouchedWindowHandle, _] = findTouchedWindowAtLocked(displayId, x, y, isStylus);
@@ -2509,6 +2520,12 @@ std::vector<InputTarget> InputDispatcher::findTouchedWindowTargetsLocked(
    // Success!  Output targets from the touch state.
    tempTouchState.clearWindowsWithoutPointers();
    for (const TouchedWindow& touchedWindow : tempTouchState.windows) {
        if (touchedWindow.pointerIds.isEmpty() &&
            !touchedWindow.hasHoveringPointers(entry.deviceId)) {
            // Windows with hovering pointers are getting persisted inside TouchState.
            // Do not send this event to those windows.
            continue;
        }
        addWindowTargetLocked(touchedWindow.windowHandle, touchedWindow.targetFlags,
                              touchedWindow.pointerIds, touchedWindow.firstDownTimeInTarget,
                              targets);
@@ -2591,7 +2608,7 @@ void InputDispatcher::finishDragAndDrop(int32_t displayId, float x, float y) {
    constexpr bool isStylus = false;

    auto [dropWindow, _] =
            findTouchedWindowAtLocked(displayId, x, y, isStylus, true /*ignoreDragWindow*/);
            findTouchedWindowAtLocked(displayId, x, y, isStylus, /*ignoreDragWindow=*/true);
    if (dropWindow) {
        vec2 local = dropWindow->getInfo()->transform.transform(x, y);
        sendDropWindowCommandLocked(dropWindow->getToken(), local.x, local.y);
@@ -2648,19 +2665,19 @@ void InputDispatcher::addDragEventLocked(const MotionEntry& entry) {
            constexpr bool isStylus = false;

            auto [hoverWindowHandle, _] = findTouchedWindowAtLocked(entry.displayId, x, y, isStylus,
                                                                    true /*ignoreDragWindow*/);
                                                                    /*ignoreDragWindow=*/true);
            // enqueue drag exit if needed.
            if (hoverWindowHandle != mDragState->dragHoverWindowHandle &&
                !haveSameToken(hoverWindowHandle, mDragState->dragHoverWindowHandle)) {
                if (mDragState->dragHoverWindowHandle != nullptr) {
                    enqueueDragEventLocked(mDragState->dragHoverWindowHandle, true /*isExiting*/, x,
                    enqueueDragEventLocked(mDragState->dragHoverWindowHandle, /*isExiting=*/true, x,
                                           y);
                }
                mDragState->dragHoverWindowHandle = hoverWindowHandle;
            }
            // enqueue drag location if needed.
            if (hoverWindowHandle != nullptr) {
                enqueueDragEventLocked(hoverWindowHandle, false /*isExiting*/, x, y);
                enqueueDragEventLocked(hoverWindowHandle, /*isExiting=*/false, x, y);
            }
            break;
        }
@@ -3338,8 +3355,7 @@ status_t InputDispatcher::publishMotionEvent(Connection& connection,
                // Don't apply window scale here since we don't want scale to affect raw
                // coordinates. The scale will be sent back to the client and applied
                // later when requesting relative coordinates.
                scaledCoords[i].scale(globalScaleFactor, 1 /* windowXScale */,
                                      1 /* windowYScale */);
                scaledCoords[i].scale(globalScaleFactor, /*windowXScale=*/1, /*windowYScale=*/1);
            }
            usingCoords = scaledCoords;
        }
@@ -3475,7 +3491,7 @@ void InputDispatcher::startDispatchCycleLocked(nsecs_t currentTime,
                          "event to it, status=%s(%d)",
                          connection->getInputChannelName().c_str(), statusToString(status).c_str(),
                          status);
                    abortBrokenDispatchCycleLocked(currentTime, connection, true /*notify*/);
                    abortBrokenDispatchCycleLocked(currentTime, connection, /*notify=*/true);
                } else {
                    // Pipe is full and we are waiting for the app to finish process some events
                    // before sending more events to it.
@@ -3490,7 +3506,7 @@ void InputDispatcher::startDispatchCycleLocked(nsecs_t currentTime,
                      "status=%s(%d)",
                      connection->getInputChannelName().c_str(), statusToString(status).c_str(),
                      status);
                abortBrokenDispatchCycleLocked(currentTime, connection, true /*notify*/);
                abortBrokenDispatchCycleLocked(currentTime, connection, /*notify=*/true);
            }
            return;
        }
@@ -3942,8 +3958,8 @@ std::unique_ptr<MotionEntry> InputDispatcher::splitMotionEvent(
    if (action == AMOTION_EVENT_ACTION_DOWN) {
        LOG_ALWAYS_FATAL_IF(splitDownTime != originalMotionEntry.eventTime,
                            "Split motion event has mismatching downTime and eventTime for "
                            "ACTION_DOWN, motionEntry=%s, splitDownTime=%" PRId64 "ms",
                            originalMotionEntry.getDescription().c_str(), ns2ms(splitDownTime));
                            "ACTION_DOWN, motionEntry=%s, splitDownTime=%" PRId64,
                            originalMotionEntry.getDescription().c_str(), splitDownTime);
    }

    int32_t newId = mIdGenerator.nextId();
@@ -4227,7 +4243,7 @@ void InputDispatcher::notifySensor(const NotifySensorArgs* args) {
        // Just enqueue a new sensor event.
        std::unique_ptr<SensorEntry> newEntry =
                std::make_unique<SensorEntry>(args->id, args->eventTime, args->deviceId,
                                              args->source, 0 /* policyFlags*/, args->hwTimestamp,
                                              args->source, /* policyFlags=*/0, args->hwTimestamp,
                                              args->sensorType, args->accuracy,
                                              args->accuracyChanged, args->values);

@@ -5621,7 +5637,7 @@ Result<std::unique_ptr<InputChannel>> InputDispatcher::createInputChannel(const
        const sp<IBinder>& token = serverChannel->getConnectionToken();
        int fd = serverChannel->getFd();
        sp<Connection> connection =
                sp<Connection>::make(std::move(serverChannel), false /*monitor*/, mIdGenerator);
                sp<Connection>::make(std::move(serverChannel), /*monitor=*/false, mIdGenerator);

        if (mConnectionsByToken.find(token) != mConnectionsByToken.end()) {
            ALOGE("Created a new connection, but the token %p is already known", token.get());
@@ -5659,7 +5675,7 @@ Result<std::unique_ptr<InputChannel>> InputDispatcher::createInputMonitor(int32_
        }

        sp<Connection> connection =
                sp<Connection>::make(serverChannel, true /*monitor*/, mIdGenerator);
                sp<Connection>::make(serverChannel, /*monitor=*/true, mIdGenerator);
        const sp<IBinder>& token = serverChannel->getConnectionToken();
        const int fd = serverChannel->getFd();

@@ -5685,7 +5701,7 @@ status_t InputDispatcher::removeInputChannel(const sp<IBinder>& connectionToken)
    { // acquire lock
        std::scoped_lock _l(mLock);

        status_t status = removeInputChannelLocked(connectionToken, false /*notify*/);
        status_t status = removeInputChannelLocked(connectionToken, /*notify=*/false);
        if (status) {
            return status;
        }
@@ -5778,7 +5794,10 @@ status_t InputDispatcher::pilferPointersLocked(const sp<IBinder>& token) {

    // Prevent the gesture from being sent to any other windows.
    // This only blocks relevant pointers to be sent to other windows
    window.isPilferingPointers = true;
    for (BitSet32 idBits(window.pointerIds); !idBits.isEmpty();) {
        uint32_t id = idBits.clearFirstMarkedBit();
        window.pilferedPointerIds.set(id);
    }

    state.cancelPointersForWindowsExcept(window.pointerIds, token);
    return OK;
@@ -6390,11 +6409,11 @@ void InputDispatcher::onFocusChangedLocked(const FocusResolver::FocusChanges& ch
            CancelationOptions options(CancelationOptions::Mode::CANCEL_NON_POINTER_EVENTS,
                                       "focus left window");
            synthesizeCancelationEventsForInputChannelLocked(focusedInputChannel, options);
            enqueueFocusEventLocked(changes.oldFocus, false /*hasFocus*/, changes.reason);
            enqueueFocusEventLocked(changes.oldFocus, /*hasFocus=*/false, changes.reason);
        }
    }
    if (changes.newFocus) {
        enqueueFocusEventLocked(changes.newFocus, true /*hasFocus*/, changes.reason);
        enqueueFocusEventLocked(changes.newFocus, /*hasFocus=*/true, changes.reason);
    }

    // If a window has pointer capture, then it must have focus. We need to ensure that this
+17 −17
Original line number Diff line number Diff line
@@ -97,7 +97,7 @@ bool InputState::trackMotion(const MotionEntry& entry, int32_t action, int32_t f
    switch (actionMasked) {
        case AMOTION_EVENT_ACTION_UP:
        case AMOTION_EVENT_ACTION_CANCEL: {
            ssize_t index = findMotionMemento(entry, false /*hovering*/);
            ssize_t index = findMotionMemento(entry, /*hovering=*/false);
            if (index >= 0) {
                mMotionMementos.erase(mMotionMementos.begin() + index);
                return true;
@@ -111,11 +111,11 @@ bool InputState::trackMotion(const MotionEntry& entry, int32_t action, int32_t f
        }

        case AMOTION_EVENT_ACTION_DOWN: {
            ssize_t index = findMotionMemento(entry, false /*hovering*/);
            ssize_t index = findMotionMemento(entry, /*hovering=*/false);
            if (index >= 0) {
                mMotionMementos.erase(mMotionMementos.begin() + index);
            }
            addMotionMemento(entry, flags, false /*hovering*/);
            addMotionMemento(entry, flags, /*hovering=*/false);
            return true;
        }

@@ -129,7 +129,7 @@ bool InputState::trackMotion(const MotionEntry& entry, int32_t action, int32_t f
                return true;
            }

            ssize_t index = findMotionMemento(entry, false /*hovering*/);
            ssize_t index = findMotionMemento(entry, /*hovering=*/false);

            if (entry.source & AINPUT_SOURCE_CLASS_JOYSTICK) {
                // Joysticks can send MOVE events without a corresponding DOWN or UP. Since all
@@ -145,7 +145,7 @@ bool InputState::trackMotion(const MotionEntry& entry, int32_t action, int32_t f
                        memento.setPointers(entry);
                    }
                } else if (!entry.pointerCoords[0].isEmpty()) {
                    addMotionMemento(entry, flags, false /*hovering*/);
                    addMotionMemento(entry, flags, /*hovering=*/false);
                }

                // Joysticks and trackballs can send MOVE events without corresponding DOWN or UP.
@@ -168,7 +168,7 @@ bool InputState::trackMotion(const MotionEntry& entry, int32_t action, int32_t f
        }

        case AMOTION_EVENT_ACTION_HOVER_EXIT: {
            ssize_t index = findMotionMemento(entry, true /*hovering*/);
            ssize_t index = findMotionMemento(entry, /*hovering=*/true);
            if (index >= 0) {
                mMotionMementos.erase(mMotionMementos.begin() + index);
                return true;
@@ -183,11 +183,11 @@ bool InputState::trackMotion(const MotionEntry& entry, int32_t action, int32_t f

        case AMOTION_EVENT_ACTION_HOVER_ENTER:
        case AMOTION_EVENT_ACTION_HOVER_MOVE: {
            ssize_t index = findMotionMemento(entry, true /*hovering*/);
            ssize_t index = findMotionMemento(entry, /*hovering=*/true);
            if (index >= 0) {
                mMotionMementos.erase(mMotionMementos.begin() + index);
            }
            addMotionMemento(entry, flags, true /*hovering*/);
            addMotionMemento(entry, flags, /*hovering=*/true);
            return true;
        }

@@ -280,7 +280,7 @@ std::vector<std::unique_ptr<EventEntry>> InputState::synthesizeCancelationEvents
                                               memento.policyFlags, AKEY_EVENT_ACTION_UP,
                                               memento.flags | AKEY_EVENT_FLAG_CANCELED,
                                               memento.keyCode, memento.scanCode, memento.metaState,
                                               0 /*repeatCount*/, memento.downTime));
                                               /*repeatCount=*/0, memento.downTime));
        }
    }

@@ -297,8 +297,8 @@ std::vector<std::unique_ptr<EventEntry>> InputState::synthesizeCancelationEvents
                        std::make_unique<MotionEntry>(mIdGenerator.nextId(), currentTime,
                                                      memento.deviceId, memento.source,
                                                      memento.displayId, memento.policyFlags,
                                                      action, 0 /*actionButton*/, flags, AMETA_NONE,
                                                      0 /*buttonState*/, MotionClassification::NONE,
                                                      action, /*actionButton=*/0, flags, AMETA_NONE,
                                                      /*buttonState=*/0, MotionClassification::NONE,
                                                      AMOTION_EVENT_EDGE_FLAG_NONE,
                                                      memento.xPrecision, memento.yPrecision,
                                                      memento.xCursorPosition,
@@ -359,8 +359,8 @@ std::vector<std::unique_ptr<EventEntry>> InputState::synthesizePointerDownEvents
                    std::make_unique<MotionEntry>(mIdGenerator.nextId(), currentTime,
                                                  memento.deviceId, memento.source,
                                                  memento.displayId, memento.policyFlags, action,
                                                  0 /*actionButton*/, memento.flags, AMETA_NONE,
                                                  0 /*buttonState*/, MotionClassification::NONE,
                                                  /*actionButton=*/0, memento.flags, AMETA_NONE,
                                                  /*buttonState=*/0, MotionClassification::NONE,
                                                  AMOTION_EVENT_EDGE_FLAG_NONE, memento.xPrecision,
                                                  memento.yPrecision, memento.xCursorPosition,
                                                  memento.yCursorPosition, memento.downTime,
@@ -398,8 +398,8 @@ std::vector<std::unique_ptr<MotionEntry>> InputState::synthesizeCancelationEvent
        events.push_back(
                std::make_unique<MotionEntry>(mIdGenerator.nextId(), currentTime, memento.deviceId,
                                              memento.source, memento.displayId,
                                              memento.policyFlags, action, 0 /*actionButton*/,
                                              flags, AMETA_NONE, 0 /*buttonState*/,
                                              memento.policyFlags, action, /*actionButton=*/0,
                                              flags, AMETA_NONE, /*buttonState=*/0,
                                              MotionClassification::NONE,
                                              AMOTION_EVENT_EDGE_FLAG_NONE, memento.xPrecision,
                                              memento.yPrecision, memento.xCursorPosition,
@@ -425,9 +425,9 @@ std::vector<std::unique_ptr<MotionEntry>> InputState::synthesizeCancelationEvent
                    std::make_unique<MotionEntry>(mIdGenerator.nextId(), currentTime,
                                                  memento.deviceId, memento.source,
                                                  memento.displayId, memento.policyFlags, action,
                                                  0 /*actionButton*/,
                                                  /*actionButton=*/0,
                                                  memento.flags | AMOTION_EVENT_FLAG_CANCELED,
                                                  AMETA_NONE, 0 /*buttonState*/,
                                                  AMETA_NONE, /*buttonState=*/0,
                                                  MotionClassification::NONE,
                                                  AMOTION_EVENT_EDGE_FLAG_NONE, memento.xPrecision,
                                                  memento.yPrecision, memento.xCursorPosition,
Loading