diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index 4b2c41ddecec9..bb22b8e1b5b44 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -3374,6 +3374,14 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp mUpdateImeTarget = updateImeTarget; WindowState target = getWindow(mComputeImeTargetPredicate); + // Keeps the IME target with the last window while swiping up to recents to prevent + // flickering due to IME hide animation on top of recents. + // TODO(b/166736352): This logic should go away once we switch over target immediately + // and do the screenshot to preserve IME on disappearing target + if (target != null && curTarget != null && target.isActivityTypeHome() + && curTarget.getInsetsState().getSource(ITYPE_IME).isVisible()) { + return curTarget; + } // Yet more tricksyness! If this window is a "starting" window, we do actually want // to be on top of it, but it is not -really- where input will go. So look down below @@ -3546,7 +3554,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp ); } - private void updateImeParent() { + void updateImeParent() { final SurfaceControl newParent = computeImeParent(); if (newParent != null) { getPendingTransaction().reparent(mImeWindowsContainers.mSurfaceControl, newParent); diff --git a/services/core/java/com/android/server/wm/RecentsAnimationController.java b/services/core/java/com/android/server/wm/RecentsAnimationController.java index 38d20a8bd6856..a40b3104c5acf 100644 --- a/services/core/java/com/android/server/wm/RecentsAnimationController.java +++ b/services/core/java/com/android/server/wm/RecentsAnimationController.java @@ -283,6 +283,20 @@ public class RecentsAnimationController implements DeathRecipient { public void hideCurrentInputMethod() { final long token = Binder.clearCallingIdentity(); try { + synchronized (mService.getWindowManagerLock()) { + // Make sure to update the correct IME parent in case that the IME parent may + // be computed as display layer when re-layout window happens during rotation + // but there is intermediate state that the bounds of task and the IME + // target's activity is not the same during rotating. + mDisplayContent.updateImeParent(); + + // Ignore hiding IME if IME window is attached to app. + // Since we would like to snapshot Task with IME window while transitioning + // to recents. + if (mDisplayContent.isImeAttachedToApp()) { + return; + } + } final InputMethodManagerInternal inputMethodManagerInternal = LocalServices.getService(InputMethodManagerInternal.class); if (inputMethodManagerInternal != null) { diff --git a/services/core/java/com/android/server/wm/TaskSnapshotController.java b/services/core/java/com/android/server/wm/TaskSnapshotController.java index bc4f75276a950..87b470a54f77e 100644 --- a/services/core/java/com/android/server/wm/TaskSnapshotController.java +++ b/services/core/java/com/android/server/wm/TaskSnapshotController.java @@ -368,7 +368,8 @@ class TaskSnapshotController { SurfaceControl[] excludeLayers; final WindowState imeWindow = task.getDisplayContent().mInputMethodWindow; - if (imeWindow != null) { + // Exclude IME window snapshot when IME isn't proper to attach to app. + if (imeWindow != null && !task.getDisplayContent().isImeAttachedToApp()) { excludeLayers = new SurfaceControl[1]; excludeLayers[0] = imeWindow.getSurfaceControl(); } else {