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

Commit 97d754f7 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Use const reference when not modifying objects"

parents e6f5520a d2770049
Loading
Loading
Loading
Loading
+123 −123

File changed.

Preview size limit exceeded, changes collapsed.

+13 −13
Original line number Diff line number Diff line
@@ -144,7 +144,7 @@ private:
    bool enqueueInboundEventLocked(EventEntry* entry) REQUIRES(mLock);

    // Cleans up input state when dropping an inbound event.
    void dropInboundEventLocked(EventEntry* entry, DropReason dropReason) REQUIRES(mLock);
    void dropInboundEventLocked(const EventEntry& entry, DropReason dropReason) REQUIRES(mLock);

    // Adds an event to a queue of recent events for debugging purposes.
    void addRecentEventLocked(EventEntry* entry) REQUIRES(mLock);
@@ -153,12 +153,12 @@ private:
    bool mAppSwitchSawKeyDown GUARDED_BY(mLock);
    nsecs_t mAppSwitchDueTime GUARDED_BY(mLock);

    bool isAppSwitchKeyEvent(KeyEntry* keyEntry);
    bool isAppSwitchKeyEvent(const KeyEntry& keyEntry);
    bool isAppSwitchPendingLocked() REQUIRES(mLock);
    void resetPendingAppSwitchLocked(bool handled) REQUIRES(mLock);

    // Stale event latency optimization.
    static bool isStaleEvent(nsecs_t currentTime, EventEntry* entry);
    static bool isStaleEvent(nsecs_t currentTime, const EventEntry& entry);

    // Blocked event latency optimization.  Drops old events when the user intends
    // to transfer focus to a new application.
@@ -293,8 +293,8 @@ private:
    void dispatchEventLocked(nsecs_t currentTime, EventEntry* entry,
                             const std::vector<InputTarget>& inputTargets) REQUIRES(mLock);

    void logOutboundKeyDetails(const char* prefix, const KeyEntry* entry);
    void logOutboundMotionDetails(const char* prefix, const MotionEntry* entry);
    void logOutboundKeyDetails(const char* prefix, const KeyEntry& entry);
    void logOutboundMotionDetails(const char* prefix, const MotionEntry& entry);

    // Keeping track of ANR timeouts.
    enum InputTargetWaitCause {
@@ -313,7 +313,7 @@ private:
    sp<InputWindowHandle> mLastHoverWindowHandle GUARDED_BY(mLock);

    // Finding targets for input events.
    int32_t handleTargetsNotReadyLocked(nsecs_t currentTime, const EventEntry* entry,
    int32_t handleTargetsNotReadyLocked(nsecs_t currentTime, const EventEntry& entry,
                                        const sp<InputApplicationHandle>& applicationHandle,
                                        const sp<InputWindowHandle>& windowHandle,
                                        nsecs_t* nextWakeupTime, const char* reason)
@@ -327,11 +327,11 @@ private:
    nsecs_t getTimeSpentWaitingForApplicationLocked(nsecs_t currentTime) REQUIRES(mLock);
    void resetANRTimeoutsLocked() REQUIRES(mLock);

    int32_t getTargetDisplayId(const EventEntry* entry);
    int32_t findFocusedWindowTargetsLocked(nsecs_t currentTime, const EventEntry* entry,
    int32_t getTargetDisplayId(const EventEntry& entry);
    int32_t findFocusedWindowTargetsLocked(nsecs_t currentTime, const EventEntry& entry,
                                           std::vector<InputTarget>& inputTargets,
                                           nsecs_t* nextWakeupTime) REQUIRES(mLock);
    int32_t findTouchedWindowTargetsLocked(nsecs_t currentTime, const MotionEntry* entry,
    int32_t findTouchedWindowTargetsLocked(nsecs_t currentTime, const MotionEntry& entry,
                                           std::vector<InputTarget>& inputTargets,
                                           nsecs_t* nextWakeupTime,
                                           bool* outConflictingPointerActions) REQUIRES(mLock);
@@ -350,7 +350,7 @@ private:
    void addGlobalMonitoringTargetsLocked(std::vector<InputTarget>& inputTargets, int32_t displayId,
                                          float xOffset = 0, float yOffset = 0) REQUIRES(mLock);

    void pokeUserActivityLocked(const EventEntry* eventEntry) REQUIRES(mLock);
    void pokeUserActivityLocked(const EventEntry& eventEntry) REQUIRES(mLock);
    bool checkInjectionPermission(const sp<InputWindowHandle>& windowHandle,
                                  const InjectionState* injectionState);
    bool isWindowObscuredAtPointLocked(const sp<InputWindowHandle>& windowHandle, int32_t x,
@@ -361,7 +361,7 @@ private:

    std::string checkWindowReadyForMoreInputLocked(nsecs_t currentTime,
                                                   const sp<InputWindowHandle>& windowHandle,
                                                   const EventEntry* eventEntry,
                                                   const EventEntry& eventEntry,
                                                   const char* targetType) REQUIRES(mLock);

    // Manage the dispatch cycle for a single connection.
@@ -405,7 +405,7 @@ private:
            REQUIRES(mLock);

    // Splitting motion events across windows.
    MotionEntry* splitMotionEvent(const MotionEntry* originalMotionEntry, BitSet32 pointerIds);
    MotionEntry* splitMotionEvent(const MotionEntry& originalMotionEntry, BitSet32 pointerIds);

    // Reset and drop everything the dispatcher is doing.
    void resetAndDropEverythingLocked(const char* reason) REQUIRES(mLock);
@@ -458,7 +458,7 @@ private:
    LatencyStatistics mTouchStatistics{TOUCH_STATS_REPORT_PERIOD};

    void reportTouchEventForStatistics(const MotionEntry& entry);
    void updateDispatchStatistics(nsecs_t currentTime, const EventEntry* entry,
    void updateDispatchStatistics(nsecs_t currentTime, const EventEntry& entry,
                                  int32_t injectionResult, nsecs_t timeSpentWaitingForApplication);
    void traceInboundQueueLengthLocked() REQUIRES(mLock);
    void traceOutboundQueueLength(const sp<Connection>& connection);
+43 −43
Original line number Diff line number Diff line
@@ -36,12 +36,12 @@ bool InputState::isHovering(int32_t deviceId, uint32_t source, int32_t displayId
    return false;
}

bool InputState::trackKey(const KeyEntry* entry, int32_t action, int32_t flags) {
bool InputState::trackKey(const KeyEntry& entry, int32_t action, int32_t flags) {
    switch (action) {
        case AKEY_EVENT_ACTION_UP: {
            if (entry->flags & AKEY_EVENT_FLAG_FALLBACK) {
            if (entry.flags & AKEY_EVENT_FLAG_FALLBACK) {
                for (size_t i = 0; i < mFallbackKeys.size();) {
                    if (mFallbackKeys.valueAt(i) == entry->keyCode) {
                    if (mFallbackKeys.valueAt(i) == entry.keyCode) {
                        mFallbackKeys.removeItemsAt(i);
                    } else {
                        i += 1;
@@ -65,7 +65,7 @@ bool InputState::trackKey(const KeyEntry* entry, int32_t action, int32_t flags)
    #if DEBUG_OUTBOUND_EVENT_DETAILS
            ALOGD("Dropping inconsistent key up event: deviceId=%d, source=%08x, "
                    "keyCode=%d, scanCode=%d",
                    entry->deviceId, entry->source, entry->keyCode, entry->scanCode);
                    entry.deviceId, entry.source, entry.keyCode, entry.scanCode);
    #endif
            return false;
            */
@@ -86,7 +86,7 @@ bool InputState::trackKey(const KeyEntry* entry, int32_t action, int32_t flags)
    }
}

bool InputState::trackMotion(const MotionEntry* entry, int32_t action, int32_t flags) {
bool InputState::trackMotion(const MotionEntry& entry, int32_t action, int32_t flags) {
    int32_t actionMasked = action & AMOTION_EVENT_ACTION_MASK;
    switch (actionMasked) {
        case AMOTION_EVENT_ACTION_UP:
@@ -99,7 +99,7 @@ bool InputState::trackMotion(const MotionEntry* entry, int32_t action, int32_t f
#if DEBUG_OUTBOUND_EVENT_DETAILS
            ALOGD("Dropping inconsistent motion up or cancel event: deviceId=%d, source=%08x, "
                  "displayId=%" PRId32 ", actionMasked=%d",
                  entry->deviceId, entry->source, entry->displayId, actionMasked);
                  entry.deviceId, entry.source, entry.displayId, actionMasked);
#endif
            return false;
        }
@@ -116,7 +116,7 @@ bool InputState::trackMotion(const MotionEntry* entry, int32_t action, int32_t f
        case AMOTION_EVENT_ACTION_POINTER_UP:
        case AMOTION_EVENT_ACTION_POINTER_DOWN:
        case AMOTION_EVENT_ACTION_MOVE: {
            if (entry->source & AINPUT_SOURCE_CLASS_NAVIGATION) {
            if (entry.source & AINPUT_SOURCE_CLASS_NAVIGATION) {
                // Trackballs can send MOVE events with a corresponding DOWN or UP. There's no need
                // to generate cancellation events for these since they're based in relative rather
                // than absolute units.
@@ -125,20 +125,20 @@ bool InputState::trackMotion(const MotionEntry* entry, int32_t action, int32_t f

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

            if (entry->source & AINPUT_SOURCE_CLASS_JOYSTICK) {
            if (entry.source & AINPUT_SOURCE_CLASS_JOYSTICK) {
                // Joysticks can send MOVE events without a corresponding DOWN or UP. Since all
                // joystick axes are normalized to [-1, 1] we can trust that 0 means it's neutral.
                // Any other value and we need to track the motion so we can send cancellation
                // events for anything generating fallback events (e.g. DPad keys for joystick
                // movements).
                if (index >= 0) {
                    if (entry->pointerCoords[0].isEmpty()) {
                    if (entry.pointerCoords[0].isEmpty()) {
                        mMotionMementos.erase(mMotionMementos.begin() + index);
                    } else {
                        MotionMemento& memento = mMotionMementos[index];
                        memento.setPointers(entry);
                    }
                } else if (!entry->pointerCoords[0].isEmpty()) {
                } else if (!entry.pointerCoords[0].isEmpty()) {
                    addMotionMemento(entry, flags, false /*hovering*/);
                }

@@ -153,7 +153,7 @@ bool InputState::trackMotion(const MotionEntry* entry, int32_t action, int32_t f
#if DEBUG_OUTBOUND_EVENT_DETAILS
            ALOGD("Dropping inconsistent motion pointer up/down or move event: "
                  "deviceId=%d, source=%08x, displayId=%" PRId32 ", actionMasked=%d",
                  entry->deviceId, entry->source, entry->displayId, actionMasked);
                  entry.deviceId, entry.source, entry.displayId, actionMasked);
#endif
            return false;
        }
@@ -167,7 +167,7 @@ bool InputState::trackMotion(const MotionEntry* entry, int32_t action, int32_t f
#if DEBUG_OUTBOUND_EVENT_DETAILS
            ALOGD("Dropping inconsistent motion hover exit event: deviceId=%d, source=%08x, "
                  "displayId=%" PRId32,
                  entry->deviceId, entry->source, entry->displayId);
                  entry.deviceId, entry.source, entry.displayId);
#endif
            return false;
        }
@@ -187,65 +187,65 @@ bool InputState::trackMotion(const MotionEntry* entry, int32_t action, int32_t f
    }
}

ssize_t InputState::findKeyMemento(const KeyEntry* entry) const {
ssize_t InputState::findKeyMemento(const KeyEntry& entry) const {
    for (size_t i = 0; i < mKeyMementos.size(); i++) {
        const KeyMemento& memento = mKeyMementos[i];
        if (memento.deviceId == entry->deviceId && memento.source == entry->source &&
            memento.displayId == entry->displayId && memento.keyCode == entry->keyCode &&
            memento.scanCode == entry->scanCode) {
        if (memento.deviceId == entry.deviceId && memento.source == entry.source &&
            memento.displayId == entry.displayId && memento.keyCode == entry.keyCode &&
            memento.scanCode == entry.scanCode) {
            return i;
        }
    }
    return -1;
}

ssize_t InputState::findMotionMemento(const MotionEntry* entry, bool hovering) const {
ssize_t InputState::findMotionMemento(const MotionEntry& entry, bool hovering) const {
    for (size_t i = 0; i < mMotionMementos.size(); i++) {
        const MotionMemento& memento = mMotionMementos[i];
        if (memento.deviceId == entry->deviceId && memento.source == entry->source &&
            memento.displayId == entry->displayId && memento.hovering == hovering) {
        if (memento.deviceId == entry.deviceId && memento.source == entry.source &&
            memento.displayId == entry.displayId && memento.hovering == hovering) {
            return i;
        }
    }
    return -1;
}

void InputState::addKeyMemento(const KeyEntry* entry, int32_t flags) {
void InputState::addKeyMemento(const KeyEntry& entry, int32_t flags) {
    KeyMemento memento;
    memento.deviceId = entry->deviceId;
    memento.source = entry->source;
    memento.displayId = entry->displayId;
    memento.keyCode = entry->keyCode;
    memento.scanCode = entry->scanCode;
    memento.metaState = entry->metaState;
    memento.deviceId = entry.deviceId;
    memento.source = entry.source;
    memento.displayId = entry.displayId;
    memento.keyCode = entry.keyCode;
    memento.scanCode = entry.scanCode;
    memento.metaState = entry.metaState;
    memento.flags = flags;
    memento.downTime = entry->downTime;
    memento.policyFlags = entry->policyFlags;
    memento.downTime = entry.downTime;
    memento.policyFlags = entry.policyFlags;
    mKeyMementos.push_back(memento);
}

void InputState::addMotionMemento(const MotionEntry* entry, int32_t flags, bool hovering) {
void InputState::addMotionMemento(const MotionEntry& entry, int32_t flags, bool hovering) {
    MotionMemento memento;
    memento.deviceId = entry->deviceId;
    memento.source = entry->source;
    memento.displayId = entry->displayId;
    memento.deviceId = entry.deviceId;
    memento.source = entry.source;
    memento.displayId = entry.displayId;
    memento.flags = flags;
    memento.xPrecision = entry->xPrecision;
    memento.yPrecision = entry->yPrecision;
    memento.xCursorPosition = entry->xCursorPosition;
    memento.yCursorPosition = entry->yCursorPosition;
    memento.downTime = entry->downTime;
    memento.xPrecision = entry.xPrecision;
    memento.yPrecision = entry.yPrecision;
    memento.xCursorPosition = entry.xCursorPosition;
    memento.yCursorPosition = entry.yCursorPosition;
    memento.downTime = entry.downTime;
    memento.setPointers(entry);
    memento.hovering = hovering;
    memento.policyFlags = entry->policyFlags;
    memento.policyFlags = entry.policyFlags;
    mMotionMementos.push_back(memento);
}

void InputState::MotionMemento::setPointers(const MotionEntry* entry) {
    pointerCount = entry->pointerCount;
    for (uint32_t i = 0; i < entry->pointerCount; i++) {
        pointerProperties[i].copyFrom(entry->pointerProperties[i]);
        pointerCoords[i].copyFrom(entry->pointerCoords[i]);
void InputState::MotionMemento::setPointers(const MotionEntry& entry) {
    pointerCount = entry.pointerCount;
    for (uint32_t i = 0; i < entry.pointerCount; i++) {
        pointerProperties[i].copyFrom(entry.pointerProperties[i]);
        pointerCoords[i].copyFrom(entry.pointerCoords[i]);
    }
}

+7 −7
Original line number Diff line number Diff line
@@ -41,12 +41,12 @@ public:
    // Records tracking information for a key event that has just been published.
    // Returns true if the event should be delivered, false if it is inconsistent
    // and should be skipped.
    bool trackKey(const KeyEntry* entry, int32_t action, int32_t flags);
    bool trackKey(const KeyEntry& entry, int32_t action, int32_t flags);

    // Records tracking information for a motion event that has just been published.
    // Returns true if the event should be delivered, false if it is inconsistent
    // and should be skipped.
    bool trackMotion(const MotionEntry* entry, int32_t action, int32_t flags);
    bool trackMotion(const MotionEntry& entry, int32_t action, int32_t flags);

    // Synthesizes cancelation events for the current state and resets the tracked state.
    void synthesizeCancelationEvents(nsecs_t currentTime, std::vector<EventEntry*>& outEvents,
@@ -100,18 +100,18 @@ private:
        bool hovering;
        uint32_t policyFlags;

        void setPointers(const MotionEntry* entry);
        void setPointers(const MotionEntry& entry);
    };

    std::vector<KeyMemento> mKeyMementos;
    std::vector<MotionMemento> mMotionMementos;
    KeyedVector<int32_t, int32_t> mFallbackKeys;

    ssize_t findKeyMemento(const KeyEntry* entry) const;
    ssize_t findMotionMemento(const MotionEntry* entry, bool hovering) const;
    ssize_t findKeyMemento(const KeyEntry& entry) const;
    ssize_t findMotionMemento(const MotionEntry& entry, bool hovering) const;

    void addKeyMemento(const KeyEntry* entry, int32_t flags);
    void addMotionMemento(const MotionEntry* entry, int32_t flags, bool hovering);
    void addKeyMemento(const KeyEntry& entry, int32_t flags);
    void addMotionMemento(const MotionEntry& entry, int32_t flags, bool hovering);

    static bool shouldCancelKey(const KeyMemento& memento, const CancelationOptions& options);
    static bool shouldCancelMotion(const MotionMemento& memento, const CancelationOptions& options);