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

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

Stop hiding the IME window when turning screen off

In [1] we introduced the IME Screenshot, a layer to be shown when
navigating away from an app that has the IME visible, to avoid flickers.
Later in [2] we started explicilty hiding the IME window when the screen
is turning off, as the IME Screenshot would be visible on top of it
anyway. In [3], we started allowing the IME screenshot for activities of
type home or recent (previously omitted as an optimization), to attempt
to prevent a flicker.

However, hiding the IME explicitly so early still causes flickers.
Moreover, when we capture the AppSnapshot before turning the screen off,
the IME might be previously visible, but marked hidden at the time of
the snapshot capture, which disallows skipping the next IME show
animation when unlocking the screen.

This removes the explicit hiding of the IME window, as well as the extra
case of allowing the IME Screenshot on home or recents activites in the
screen turning off scenario.

  [1]: I6bef36c779a28777408576f57e5d1c67d5d48e3f
  [2]: I2e1e4bc106fc14aa65825ee82dc09390422951c5
  [3]: I1132a78ba1154e777a9751ac70659cd6377fcb39

Flag: EXEMPT bugfix
Test: atest com.android.server.wm.flicker.ime.ShowImeOnUnlockScreenTest
Bug: 426546412
Bug: 426548274
Bug: 384853532
Change-Id: Ia68ed50247034553760b5b9ec794122ee4930777
parent d40f9b88
Loading
Loading
Loading
Loading
+8 −17
Original line number Diff line number Diff line
@@ -4605,10 +4605,10 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp

        /**
         * Attaches the screenshot of IME (a screenshot will be taken if there wasn't one) to the
         * IME target task and shows it. If the given {@param anyTargetTask} is true, the screenshot
         * won't be skipped by the activity type of IME target task.
         * IME target task and shows it. The screenshot will be skipped for activities of type home
         * or recents.
         */
        void attachAndShow(@NonNull Transaction t, boolean anyTargetTask) {
        void attachAndShow(@NonNull Transaction t) {
            final DisplayContent dc = mImeTarget.getDisplayContent();
            // Prepare IME screenshot for the target if it allows to attach into.
            final Task task = mImeTarget.getTask();
@@ -4618,7 +4618,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
                    || mSurface.getHeight() != dc.mInputMethodWindow.getFrame().height();
            // The exclusion of home/recents is an optimization for regular task switch because
            // home/recents won't appear in recents task.
            if (task != null && (anyTargetTask || !task.isActivityTypeHomeOrRecents())) {
            if (task != null && !task.isActivityTypeHomeOrRecents()) {
                final ScreenCaptureInternal.ScreenshotHardwareBuffer buffer =
                        renewSurface
                                ? dc.mWmService.mTaskSnapshotController
@@ -4665,27 +4665,18 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp

        // Prepare IME screenshot for the target if it allows to attach into.
        if (mInputMethodWindow != null && mInputMethodWindow.isVisible()) {
            attachImeScreenshotOnTarget(mImeLayeringTarget, false /* hideImeWindow */);
            attachImeScreenshotOnTarget(mImeLayeringTarget);
        }
    }

    private void attachImeScreenshotOnTarget(@NonNull WindowState imeTarget,
            boolean hideImeWindow) {
    private void attachImeScreenshotOnTarget(@NonNull WindowState imeTarget) {
        final SurfaceControl.Transaction t = getPendingTransaction();
        // Remove the old IME screenshot first in case the new screenshot happens to
        // override the current one before the transition finish and the surface never be
        // removed on the task.
        removeImeScreenshotImmediately();
        mImeScreenshot = new ImeScreenshot(imeTarget, mWmService.mSurfaceControlFactory.get());
        // If the caller requests to hide IME, then allow to show IME screenshot for any target
        // task. So IME won't look like it suddenly disappeared. It usually happens when turning
        // the screen off.
        mImeScreenshot.attachAndShow(t, hideImeWindow /* anyTargetTask */);
        if (mInputMethodWindow != null && hideImeWindow) {
            // Hide the IME window when deciding to show IME screenshot on demand.
            // InsetsController will make IME visible again before animating it.
            mInputMethodWindow.hide(false, false);
        }
        mImeScreenshot.attachAndShow(t);
    }

    /**
@@ -4703,7 +4694,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
     */
    @VisibleForTesting
    void showImeScreenshot(@NonNull WindowState imeTarget) {
        attachImeScreenshotOnTarget(imeTarget, true /* hideImeWindow */);
        attachImeScreenshotOnTarget(imeTarget);
    }

    /**