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

Commit 0b44f104 authored by Ming-Shin Lu's avatar Ming-Shin Lu
Browse files

Fix IME flickering when swiping out to home

When switching tasks between different users (i.e. primary and
work-profile user), if the source task has shown IME, when going to
the target task, IMMS will first unbind the current input method of
the current user and hide the soft-keyboard and the window token
by HIDE_SWITCH_USER reason, and then re-bind the input method of
the target user when focused to the target task.

If the hide soft-keyboard somehow being delayed and comes after the
target task has been focused and be the next IME target, user will
see the window removal transition on top of this IME target window.
(i.e. launching Google chat apps with IME shown from work-profile
 and then swiping out to home screen)

Even if we disable window animation in Activity#onDestory in IME
client side, the next relayout can come before that, so window exit
transition still happens.

To fix this timing issue, add animateExit parameter in
WindowManagerInternal#removeToken for IMMS not to perform window exit
animation and to hide the window surface permanentaly, so we can
avoid the window surface becoming visible again unexpectedly during
relayout.

Fix: 197494607
Fix: 195449326
Test: atest WindowTokenTests#\
        testRemoveWindowToken_noAnimateExitWhenSet
Test: manual as issue steps:
1. Enter Google chat
2. Start typing a message
3. Swipe home
4. Expect no IME surface flicker happens

Merged-In: I044257b5ac0d92dd06dae8eba996ea0ac6f1e659
Change-Id: I044257b5ac0d92dd06dae8eba996ea0ac6f1e659
parent 2415a31c
Loading
Loading
Loading
Loading
+5 −7
Original line number Diff line number Diff line
@@ -2582,14 +2582,12 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        }

        if (mCurToken != null) {
            try {
            if (DEBUG) {
                Slog.v(TAG, "Removing window token: " + mCurToken + " for display: "
                        + mCurTokenDisplayId);
            }
                mIWindowManager.removeWindowToken(mCurToken, mCurTokenDisplayId);
            } catch (RemoteException e) {
            }
            mWindowManagerInternal.removeWindowToken(mCurToken, false /* removeWindows */,
                    false /* animateExit */, mCurTokenDisplayId);
            // Set IME window status as invisible when unbind current method.
            mImeWindowVis = 0;
            mBackDisposition = InputMethodService.BACK_DISPOSITION_DEFAULT;
+3 −3
Original line number Diff line number Diff line
@@ -1165,10 +1165,10 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        }
    }

    WindowToken removeWindowToken(IBinder binder) {
    WindowToken removeWindowToken(IBinder binder, boolean animateExit) {
        final WindowToken token = mTokenMap.remove(binder);
        if (token != null && token.asActivityRecord() == null) {
            token.setExiting();
            token.setExiting(animateExit);
        }
        return token;
    }
@@ -1252,7 +1252,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
    }

    void removeAppToken(IBinder binder) {
        final WindowToken token = removeWindowToken(binder);
        final WindowToken token = removeWindowToken(binder, true /* animateExit */);
        if (token == null) {
            Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder);
            return;
+2 −2
Original line number Diff line number Diff line
@@ -66,8 +66,8 @@ class WallpaperWindowToken extends WindowToken {
    }

    @Override
    void setExiting() {
        super.setExiting();
    void setExiting(boolean animateExit) {
        super.setExiting(animateExit);
        mDisplayContent.mWallpaperController.removeWallpaperToken(this);
    }

+14 −1
Original line number Diff line number Diff line
@@ -445,8 +445,21 @@ public abstract class WindowManagerInternal {
     * @param removeWindows Whether to also remove the windows associated with the token.
     * @param displayId The display to remove the token from.
     */
    public final void removeWindowToken(android.os.IBinder token, boolean removeWindows,
            int displayId) {
        removeWindowToken(token, removeWindows, true /* animateExit */, displayId);
    }

    /**
     * Removes a window token.
     *
     * @param token The toke to remove.
     * @param removeWindows Whether to also remove the windows associated with the token.
     * @param animateExit Whether to play the windows exit animation after the token removal.
     * @param displayId The display to remove the token from.
     */
    public abstract void removeWindowToken(android.os.IBinder token, boolean removeWindows,
            int displayId);
            boolean animateExit, int displayId);

    /**
     * Registers a listener to be notified about app transition events.
+30 −39
Original line number Diff line number Diff line
@@ -2816,13 +2816,8 @@ public class WindowManagerService extends IWindowManager.Stub

    }

    @Override
    public void removeWindowToken(IBinder binder, int displayId) {
        if (!checkCallingPermission(MANAGE_APP_TOKENS, "removeWindowToken()")) {
            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
        }
        final long origId = Binder.clearCallingIdentity();
        try {
    void removeWindowToken(IBinder binder, boolean removeWindows, boolean animateExit,
            int displayId) {
        synchronized (mGlobalLock) {
            final DisplayContent dc = mRoot.getDisplayContent(displayId);

@@ -2831,15 +2826,29 @@ public class WindowManagerService extends IWindowManager.Stub
                        + " for non-exiting displayId=%d", binder, displayId);
                return;
            }
                final WindowToken token = dc.removeWindowToken(binder);
            final WindowToken token = dc.removeWindowToken(binder, animateExit);
            if (token == null) {
                ProtoLog.w(WM_ERROR,
                        "removeWindowToken: Attempted to remove non-existing token: %s",
                        binder);
                return;
            }

            if (removeWindows) {
                token.removeAllWindowsIfPossible();
            }
            dc.getInputMonitor().updateInputWindowsLw(true /* force */);
        }
    }

    @Override
    public void removeWindowToken(IBinder binder, int displayId) {
        if (!checkCallingPermission(MANAGE_APP_TOKENS, "removeWindowToken()")) {
            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
        }
        final long origId = Binder.clearCallingIdentity();
        try {
            removeWindowToken(binder, false /* removeWindows */, true /* animateExit */, displayId);
        } finally {
            Binder.restoreCallingIdentity(origId);
        }
@@ -7536,28 +7545,10 @@ public class WindowManagerService extends IWindowManager.Stub
        }

        @Override
        public void removeWindowToken(IBinder binder, boolean removeWindows, int displayId) {
            synchronized (mGlobalLock) {
                if (removeWindows) {
                    final DisplayContent dc = mRoot.getDisplayContent(displayId);
                    if (dc == null) {
                        ProtoLog.w(WM_ERROR, "removeWindowToken: Attempted to remove token: %s"
                                + " for non-exiting displayId=%d", binder, displayId);
                        return;
                    }

                    final WindowToken token = dc.removeWindowToken(binder);
                    if (token == null) {
                        ProtoLog.w(WM_ERROR,
                                "removeWindowToken: Attempted to remove non-existing token: %s",
                                binder);
                        return;
                    }

                    token.removeAllWindowsIfPossible();
                }
                WindowManagerService.this.removeWindowToken(binder, displayId);
            }
        public void removeWindowToken(IBinder binder, boolean removeWindows, boolean animateExit,
                int displayId) {
            WindowManagerService.this.removeWindowToken(binder, removeWindows, animateExit,
                    displayId);
        }

        @Override
Loading