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

Commit ee42fdb4 authored by Vaibhav Devmurari's avatar Vaibhav Devmurari
Browse files

Remove Back shortcut processing in InputDispatcher

Test: manual
Bug: 290473497
Change-Id: Idfbf77d93f5bf190db9ba11c8132ccc804e2ceca
parent 994bf661
Loading
Loading
Loading
Loading
+0 −54
Original line number Diff line number Diff line
@@ -4186,45 +4186,6 @@ void InputDispatcher::notifyConfigurationChanged(const NotifyConfigurationChange
    }
}

/**
 * If one of the meta shortcuts is detected, process them here:
 *     Meta + Backspace; Meta + Grave; Meta + Left arrow -> generate BACK
 * Most System shortcuts are handled in PhoneWindowManager.java except 'Back' shortcuts. Unlike
 * Back, other shortcuts DO NOT need to be sent to applications and are fully handled by the system.
 * But for Back key and Back shortcuts, we need to send KEYCODE_BACK to applications which can
 * potentially handle the back key presses.
 * Note: We don't send any Meta based KeyEvents to applications, so we need to convert to a KeyEvent
 * where meta modifier is off before sending. Currently only use case is 'Back'.
 */
void InputDispatcher::accelerateMetaShortcuts(const int32_t deviceId, const int32_t action,
                                              int32_t& keyCode, int32_t& metaState) {
    if (metaState & AMETA_META_ON && action == AKEY_EVENT_ACTION_DOWN) {
        int32_t newKeyCode = AKEYCODE_UNKNOWN;
        if (keyCode == AKEYCODE_DEL || keyCode == AKEYCODE_GRAVE || keyCode == AKEYCODE_DPAD_LEFT) {
            newKeyCode = AKEYCODE_BACK;
        }
        if (newKeyCode != AKEYCODE_UNKNOWN) {
            std::scoped_lock _l(mLock);
            struct KeyReplacement replacement = {keyCode, deviceId};
            mReplacedKeys[replacement] = newKeyCode;
            keyCode = newKeyCode;
            metaState &= ~(AMETA_META_ON | AMETA_META_LEFT_ON | AMETA_META_RIGHT_ON);
        }
    } else if (action == AKEY_EVENT_ACTION_UP) {
        // In order to maintain a consistent stream of up and down events, check to see if the key
        // going up is one we've replaced in a down event and haven't yet replaced in an up event,
        // even if the modifier was released between the down and the up events.
        std::scoped_lock _l(mLock);
        struct KeyReplacement replacement = {keyCode, deviceId};
        auto replacementIt = mReplacedKeys.find(replacement);
        if (replacementIt != mReplacedKeys.end()) {
            keyCode = replacementIt->second;
            mReplacedKeys.erase(replacementIt);
            metaState &= ~(AMETA_META_ON | AMETA_META_LEFT_ON | AMETA_META_RIGHT_ON);
        }
    }
}

void InputDispatcher::notifyKey(const NotifyKeyArgs& args) {
    ALOGD_IF(debugInboundEventDetails(),
             "notifyKey - id=%" PRIx32 ", eventTime=%" PRId64
@@ -4257,8 +4218,6 @@ void InputDispatcher::notifyKey(const NotifyKeyArgs& args) {
    policyFlags |= POLICY_FLAG_TRUSTED;

    int32_t keyCode = args.keyCode;
    accelerateMetaShortcuts(args.deviceId, args.action, keyCode, metaState);

    KeyEvent event;
    event.initialize(args.id, args.deviceId, args.source, args.displayId, INVALID_HMAC, args.action,
                     flags, keyCode, args.scanCode, metaState, repeatCount, args.downTime,
@@ -4569,8 +4528,6 @@ InputEventInjectionResult InputDispatcher::injectInputEvent(const InputEvent* ev
            }
            int32_t keyCode = incomingKey.getKeyCode();
            int32_t metaState = incomingKey.getMetaState();
            accelerateMetaShortcuts(resolvedDeviceId, action,
                                    /*byref*/ keyCode, /*byref*/ metaState);
            KeyEvent keyEvent;
            keyEvent.initialize(incomingKey.getId(), resolvedDeviceId, incomingKey.getSource(),
                                incomingKey.getDisplayId(), INVALID_HMAC, action, flags, keyCode,
@@ -5558,7 +5515,6 @@ void InputDispatcher::resetAndDropEverythingLocked(const char* reason) {

    mAnrTracker.clear();
    mTouchStatesByDisplay.clear();
    mReplacedKeys.clear();
}

void InputDispatcher::logDispatchStateLocked() const {
@@ -5727,16 +5683,6 @@ void InputDispatcher::dumpDispatchStateLocked(std::string& dump) const {
        dump += INDENT "InboundQueue: <empty>\n";
    }

    if (!mReplacedKeys.empty()) {
        dump += INDENT "ReplacedKeys:\n";
        for (const auto& [replacement, newKeyCode] : mReplacedKeys) {
            dump += StringPrintf(INDENT2 "originalKeyCode=%d, deviceId=%d -> newKeyCode=%d\n",
                                 replacement.keyCode, replacement.deviceId, newKeyCode);
        }
    } else {
        dump += INDENT "ReplacedKeys: <empty>\n";
    }

    if (!mCommandQueue.empty()) {
        dump += StringPrintf(INDENT "CommandQueue: size=%zu\n", mCommandQueue.size());
    } else {
+0 −19
Original line number Diff line number Diff line
@@ -302,25 +302,6 @@ private:
    void resetKeyRepeatLocked() REQUIRES(mLock);
    std::shared_ptr<KeyEntry> synthesizeKeyRepeatLocked(nsecs_t currentTime) REQUIRES(mLock);

    // Key replacement tracking
    struct KeyReplacement {
        int32_t keyCode;
        int32_t deviceId;
        bool operator==(const KeyReplacement& rhs) const {
            return keyCode == rhs.keyCode && deviceId == rhs.deviceId;
        }
    };
    struct KeyReplacementHash {
        size_t operator()(const KeyReplacement& key) const {
            return std::hash<int32_t>()(key.keyCode) ^ (std::hash<int32_t>()(key.deviceId) << 1);
        }
    };
    // Maps the key code replaced, device id tuple to the key code it was replaced with
    std::unordered_map<KeyReplacement, int32_t, KeyReplacementHash> mReplacedKeys GUARDED_BY(mLock);
    // Process certain Meta + Key combinations
    void accelerateMetaShortcuts(const int32_t deviceId, const int32_t action, int32_t& keyCode,
                                 int32_t& metaState);

    // Deferred command processing.
    bool haveCommandsLocked() const REQUIRES(mLock);
    bool runCommandsLockedInterruptable() REQUIRES(mLock);