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

Commit a885f5e4 authored by Cosmin Băieș's avatar Cosmin Băieș
Browse files

Remove IME layering target update deferral

This was originally added in [1] to address the IME layering target
becoming the launcher home window, when transitioning from an app to
home by pressing the home key.

Later in [2], the logic was changed to maintain the IME layering target
until it is closing and not removed, to avoid changing the IME layering
target during a hide animation, when transitioning from an app that had
the IME shown, to one that didn't.

In [3], this was further tweaked to not maintain launcher home as the
IME layering target in this case, so that transitioning from home to an
app that had the IME shown will layer the IME on top of the app, instead
of on top of home (and below the app).

[4] added a new condition to also maintain the IME layering target if it
had the IME shown and the new proposed target is launcher home (or
recents).

In [5] we introduced the IME screenshot, to be kept on the previous IME
layering target, so we can safely move away from it, without any visual
inconsistencies. This allowed cleaning up the extra conditions mentioned
above, in [6]. This also modified when the IME surface parent is
updated, from whenever the IME layering target is updated, to whenever
the IME control target is updated.

However, this cleanup did not remove the logic for deferring IME
layering target updates during Task#moveTaskToFront. As we no longer
have (other) edge cases for maintaining the IME layering target, and as
the logic for whether a WindowState can be the IME layering target
improved to take into account extra states (in
isVisibleRequestedOrAdding), it should be safe to remove this deferral.

  [1]: Ia9b0cc913eeb76a4af20f9ac7b667c5a3d1eafc7
  [2]: I016c1e4549cf03c09cf1a30a91bd55fdb2587075
  [3]: Ib826b53415b1b1affde76e609d999e1b6f2d2b79
  [4]: Ib898bc2e3a5b063fe9eaf8b07d022231dd1326a3
  [5]: I6bef36c779a28777408576f57e5d1c67d5d48e3f
  [6]: Ia6722e1cbccd7adc8aed1828265f6fa4df78df63

Flag: EXEMPT cleanup
Bug: 399622420
Test: following cases
  1. show IME on app, swipe up to go home / press home key, observe IME
  does not animate, and the closing app snapshot has the IME
  2. show IME on app, open different app task (e.g. start composing an
  email on Gmail), observe IME remains on previous task, and then
  starts animating on the new task only after the transition
  3. show IME on app, swipe up to go to recents, observe IME does not
  animate and the app snapshot has the IME

Change-Id: I62c25360a2632e9a28628da467076caadd9587a6
parent 69d6bb8b
Loading
Loading
Loading
Loading
+0 −47
Original line number Diff line number Diff line
@@ -629,11 +629,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
     */
    int mLayoutSeq = 0;

    /** The number of deferrals of updating the IME layering target. */
    private int mUpdateImeLayeringTargetDeferCount;
    /** Whether the IME layering target was requested to be updated while being deferred. */
    private boolean mUpdateImeLayeringTargetRequestedWhileDeferred;

    private MagnificationSpec mMagnificationSpec;

    private InputMonitor mInputMonitor;
@@ -4168,14 +4163,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        }

        final WindowState curTarget = mImeLayeringTarget;
        if (!canUpdateImeLayeringTarget()) {
            if (DEBUG_INPUT_METHOD) {
                Slog.w(TAG_WM, "Defer updating IME layering target");
            }
            mUpdateImeLayeringTargetRequestedWhileDeferred = true;
            return curTarget;
        }

        // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the
        // same display. Or even when the current IME/target are not on the same screen as the next
        // IME/target. For now only look for input windows on the main screen.
@@ -5630,40 +5617,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        }
    }

    /**
     * Defers updating the IME layering target, tracking the number of deferrals in a counter. When
     * all of these are cleared through {@link #continueUpdateImeLayeringTarget} the update will
     * take place.
     */
    void deferUpdateImeLayeringTarget() {
        if (mUpdateImeLayeringTargetDeferCount == 0) {
            mUpdateImeLayeringTargetRequestedWhileDeferred = false;
        }
        mUpdateImeLayeringTargetDeferCount++;
    }

    /**
     * Attempts to continue updating the IME layering target by clearing one deferred update set
     * by {@link #deferUpdateImeLayeringTarget}. If no deferred updates remain, and the update
     * was requested while deferred, then this will trigger the update.
     */
    void continueUpdateImeLayeringTarget() {
        if (mUpdateImeLayeringTargetDeferCount == 0) {
            return;
        }

        mUpdateImeLayeringTargetDeferCount--;
        if (mUpdateImeLayeringTargetDeferCount == 0
                && mUpdateImeLayeringTargetRequestedWhileDeferred) {
            computeImeLayeringTarget(true /* update */);
        }
    }

    /** Checks whether the IME layering target can be updated, or is currently being deferred. */
    private boolean canUpdateImeLayeringTarget() {
        return mUpdateImeLayeringTargetDeferCount == 0;
    }

    InputMonitor getInputMonitor() {
        return mInputMonitor;
    }
+26 −38
Original line number Diff line number Diff line
@@ -5795,12 +5795,6 @@ class Task extends TaskFragment {
            tr.forAllActivities(a -> { a.appTimeTracker = timeTracker; });
        }

        try {
            // Defer updating the IME layering target since the it will try to get computed before
            // updating all closing and opening apps, which can cause it to get calculated
            // incorrectly.
            mDisplayContent.deferUpdateImeLayeringTarget();

        // Don't refocus if invisible to current user
        final ActivityRecord top = tr.getTopNonFinishingActivity();
        if (top == null || !top.showToCurrentUser()) {
@@ -5825,20 +5819,14 @@ class Task extends TaskFragment {
            updateTransitLocked(TRANSIT_TO_FRONT, options);
        }

            // If a new task is moved to the front, then mark the existing top activity as
            // supporting

            // picture-in-picture while paused only if the task would not be considered an oerlay
            // on top
            // of the current activity (eg. not fullscreen, or the assistant)
        // If a new task is moved to the front, then mark the existing top activity as supporting
        // picture-in-picture while paused only if the task would not be considered an overlay on
        // top of the current activity (eg. not fullscreen, or the assistant)
        enableEnterPipOnTaskSwitch(pipCandidate, tr, null /* toFrontActivity */, options);

        if (!deferResume) {
            mRootWindowContainer.resumeFocusedTasksTopActivities();
        }
        } finally {
            mDisplayContent.continueUpdateImeLayeringTarget();
        }
    }

    private boolean canMoveTaskToBack(Task task) {