From 3756211c110b83ff4561e4a8adbfe6521638fde2 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Fri, 19 May 2023 22:49:09 +0800 Subject: [PATCH] Propagate last-ime-shown in the same task explicitly For example: Task [ top: Activity B with a focused EditText and IME is shown Activity A with a focused EditText ] The test expects that after B calls finish, the IME will show for A automatically. Previously, the ime-restore relied on a task snapshot when the activity is finishing. But the snapshot is unnecessary because there is no task switch. The logic worked accidentally by the heavy snapshot operation. Since shell transition should be able to centralize the timing to take snapshot to reduce duplicated snapshot in a cleaner way, it is more reasonable to propagate last-ime-shown directly. Bug: 283413681 Test: atest com.android.inputmethod.stresstest.AutoShowTest \ #autoShow_backwardWithKeyboardOn Change-Id: Ic58d1afd6e0e2f7db2136ac60818e3b46f338bc8 --- .../core/java/com/android/server/wm/ActivityRecord.java | 8 ++++++++ .../java/com/android/server/wm/WindowManagerService.java | 8 ++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index d84c013092865..3db031510317e 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -3570,6 +3570,14 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A // Tell window manager to prepare for this one to be removed. setVisibility(false); + // Propagate the last IME visibility in the same task, so the IME can show + // automatically if the next activity has a focused editable view. + if (mLastImeShown && mTransitionController.isShellTransitionsEnabled()) { + final ActivityRecord nextRunning = task.topRunningActivity(); + if (nextRunning != null) { + nextRunning.mLastImeShown = true; + } + } if (getTaskFragment().getPausingActivity() == null) { ProtoLog.v(WM_DEBUG_STATES, "Finish needs to pause: %s", this); diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 322c11a7cc4b3..e33c6f03c7208 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -9254,7 +9254,6 @@ public class WindowManagerService extends IWindowManager.Stub boolean shouldRestoreImeVisibility(IBinder imeTargetWindowToken) { final Task imeTargetWindowTask; - boolean hadRequestedShowIme = false; synchronized (mGlobalLock) { final WindowState imeTargetWindow = mWindowMap.get(imeTargetWindowToken); if (imeTargetWindow == null) { @@ -9264,14 +9263,15 @@ public class WindowManagerService extends IWindowManager.Stub if (imeTargetWindowTask == null) { return false; } - if (imeTargetWindow.mActivityRecord != null) { - hadRequestedShowIme = imeTargetWindow.mActivityRecord.mLastImeShown; + if (imeTargetWindow.mActivityRecord != null + && imeTargetWindow.mActivityRecord.mLastImeShown) { + return true; } } final TaskSnapshot snapshot = getTaskSnapshot(imeTargetWindowTask.mTaskId, imeTargetWindowTask.mUserId, false /* isLowResolution */, false /* restoreFromDisk */); - return snapshot != null && snapshot.hasImeSurface() || hadRequestedShowIme; + return snapshot != null && snapshot.hasImeSurface(); } @Override