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

Commit fdf6ab9e authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Remove app switch behaviour" into main

parents c0a0930b 6520a58f
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -48,3 +48,10 @@ flag {
  description: "Enable additional palm rejection on touchpad while typing"
  bug: "301055381"
}

flag {
  name: "remove_app_switch_drops"
  namespace: "input"
  description: "Remove the logic of dropping events due to pending app switch"
  bug: "284808102"
}
+45 −29
Original line number Diff line number Diff line
@@ -951,21 +951,26 @@ void InputDispatcher::dispatchOnceInnerLocked(nsecs_t* nextWakeupTime) {
    // Optimize latency of app switches.
    // Essentially we start a short timeout when an app switch key (HOME / ENDCALL) has
    // been pressed.  When it expires, we preempt dispatch and drop all other pending events.
    bool isAppSwitchDue = mAppSwitchDueTime <= currentTime;
    bool isAppSwitchDue;
    if (!input_flags::remove_app_switch_drops()) {
        isAppSwitchDue = mAppSwitchDueTime <= currentTime;
        if (mAppSwitchDueTime < *nextWakeupTime) {
            *nextWakeupTime = mAppSwitchDueTime;
        }
    }

    // Ready to start a new event.
    // If we don't already have a pending event, go grab one.
    if (!mPendingEvent) {
        if (mInboundQueue.empty()) {
            if (!input_flags::remove_app_switch_drops()) {
                if (isAppSwitchDue) {
                    // The inbound queue is empty so the app switch key we were waiting
                    // for will never arrive.  Stop waiting for it.
                    resetPendingAppSwitchLocked(false);
                    isAppSwitchDue = false;
                }
            }

            // Synthesize a key repeat if appropriate.
            if (mKeyRepeatState.lastKeyEntry) {
@@ -1062,6 +1067,7 @@ void InputDispatcher::dispatchOnceInnerLocked(nsecs_t* nextWakeupTime) {

        case EventEntry::Type::KEY: {
            std::shared_ptr<KeyEntry> keyEntry = std::static_pointer_cast<KeyEntry>(mPendingEvent);
            if (!input_flags::remove_app_switch_drops()) {
                if (isAppSwitchDue) {
                    if (isAppSwitchKeyEvent(*keyEntry)) {
                        resetPendingAppSwitchLocked(true);
@@ -1070,6 +1076,7 @@ void InputDispatcher::dispatchOnceInnerLocked(nsecs_t* nextWakeupTime) {
                        dropReason = DropReason::APP_SWITCH;
                    }
                }
            }
            if (dropReason == DropReason::NOT_DROPPED && isStaleEvent(currentTime, *keyEntry)) {
                dropReason = DropReason::STALE;
            }
@@ -1083,9 +1090,11 @@ void InputDispatcher::dispatchOnceInnerLocked(nsecs_t* nextWakeupTime) {
        case EventEntry::Type::MOTION: {
            std::shared_ptr<MotionEntry> motionEntry =
                    std::static_pointer_cast<MotionEntry>(mPendingEvent);
            if (!input_flags::remove_app_switch_drops()) {
                if (dropReason == DropReason::NOT_DROPPED && isAppSwitchDue) {
                    dropReason = DropReason::APP_SWITCH;
                }
            }
            if (dropReason == DropReason::NOT_DROPPED && isStaleEvent(currentTime, *motionEntry)) {
                dropReason = DropReason::STALE;
            }
@@ -1099,9 +1108,11 @@ void InputDispatcher::dispatchOnceInnerLocked(nsecs_t* nextWakeupTime) {
        case EventEntry::Type::SENSOR: {
            std::shared_ptr<SensorEntry> sensorEntry =
                    std::static_pointer_cast<SensorEntry>(mPendingEvent);
            if (!input_flags::remove_app_switch_drops()) {
                if (dropReason == DropReason::NOT_DROPPED && isAppSwitchDue) {
                    dropReason = DropReason::APP_SWITCH;
                }
            }
            //  Sensor timestamps use SYSTEM_TIME_BOOTTIME time base, so we can't use
            // 'currentTime' here, get SYSTEM_TIME_BOOTTIME instead.
            nsecs_t bootTime = systemTime(SYSTEM_TIME_BOOTTIME);
@@ -1202,6 +1213,8 @@ bool InputDispatcher::enqueueInboundEventLocked(std::unique_ptr<EventEntry> newE
            // If the application takes too long to catch up then we drop all events preceding
            // the app switch key.
            const KeyEntry& keyEntry = static_cast<const KeyEntry&>(entry);

            if (!input_flags::remove_app_switch_drops()) {
                if (isAppSwitchKeyEvent(keyEntry)) {
                    if (keyEntry.action == AKEY_EVENT_ACTION_DOWN) {
                        mAppSwitchSawKeyDown = true;
@@ -1216,7 +1229,7 @@ bool InputDispatcher::enqueueInboundEventLocked(std::unique_ptr<EventEntry> newE
                        }
                    }
                }

            }
            // If a new up event comes in, and the pending event with same key code has been asked
            // to try again later because of the policy. We have to reset the intercept key wake up
            // time for it may have been handled in the policy and could be dropped.
@@ -5802,6 +5815,9 @@ void InputDispatcher::dumpDispatchStateLocked(std::string& dump) const {
        dump += INDENT "Connections: <none>\n";
    }

    dump += "input_flags::remove_app_switch_drops() = ";
    dump += toString(input_flags::remove_app_switch_drops());
    dump += "\n";
    if (isAppSwitchPendingLocked()) {
        dump += StringPrintf(INDENT "AppSwitch: pending, due in %" PRId64 "ms\n",
                             ns2ms(mAppSwitchDueTime - now()));