From 5ae6910b7d966eaa238c41325588fa82c37a8a2a Mon Sep 17 00:00:00 2001 From: Nikolas Havrikov Date: Mon, 15 Nov 2021 13:46:27 +0100 Subject: [PATCH] Move and split removing window token Bug: 205676419 Test: make Change-Id: Ic3aa02925fe460d4530e9f0cede3aa3a98a109ec --- .../InputMethodBindingController.java | 23 +++++++++++++++---- .../InputMethodManagerService.java | 21 ++++++----------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java b/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java index b787b15a30e15..46887b6e91a52 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java @@ -50,6 +50,7 @@ import com.android.internal.inputmethod.InputBindResult; import com.android.internal.inputmethod.UnbindReason; import com.android.internal.view.IInputMethod; import com.android.server.inputmethod.InputMethodManagerService.ClientState; +import com.android.server.wm.WindowManagerInternal; /** * A controller managing the state of the input method binding. @@ -64,6 +65,7 @@ final class InputMethodBindingController { @NonNull private final InputMethodUtils.InputMethodSettings mSettings; @NonNull private final PackageManagerInternal mPackageManagerInternal; @NonNull private final IWindowManager mIWindowManager; + @NonNull private final WindowManagerInternal mWindowManagerInternal; @NonNull private final Resources mRes; private long mLastBindTime; @@ -120,6 +122,7 @@ final class InputMethodBindingController { mSettings = mService.mSettings; mPackageManagerInternal = mService.mPackageManagerInternal; mIWindowManager = mService.mIWindowManager; + mWindowManagerInternal = mService.mWindowManagerInternal; mRes = mService.mRes; // If configured, use low priority flags to make the IME killable by the lowmemorykiller @@ -193,10 +196,6 @@ final class InputMethodBindingController { return mCurToken; } - void setCurToken(IBinder curToken) { - mCurToken = curToken; - } - /** * The Intent used to connect to the current input method. */ @@ -368,13 +367,27 @@ final class InputMethodBindingController { } if (mCurToken != null) { - mService.removeCurrentTokenLocked(); + removeCurrentTokenLocked(); + mService.resetSystemUiLocked(); } mCurId = null; mService.clearCurMethodLocked(); } + @GuardedBy("mMethodMap") + private void removeCurrentTokenLocked() { + int curTokenDisplayId = mService.getCurTokenDisplayId(); + + if (DEBUG) { + Slog.v(TAG, + "Removing window token: " + mCurToken + " for display: " + curTokenDisplayId); + } + mWindowManagerInternal.removeWindowToken(mCurToken, false /* removeWindows */, + false /* animateExit */, curTokenDisplayId); + mCurToken = null; + } + @GuardedBy("mMethodMap") @NonNull InputBindResult bindCurrentMethodLocked(int displayIdToShowIme) { diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index b0e9ab7951c0f..05133e3f0f20f 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -593,17 +593,17 @@ public class InputMethodManagerService extends IInputMethodManager.Stub return mBindingController.getCurToken(); } - private void setCurToken(IBinder curToken) { - mBindingController.setCurToken(curToken); + /** + * The displayId of current active input method. + */ + int getCurTokenDisplayId() { + return mCurTokenDisplayId; } void setCurTokenDisplayId(int curTokenDisplayId) { mCurTokenDisplayId = curTokenDisplayId; } - /** - * The displayId of current active input method. - */ int mCurTokenDisplayId = INVALID_DISPLAY; /** @@ -2536,18 +2536,11 @@ public class InputMethodManagerService extends IInputMethodManager.Stub } @GuardedBy("mMethodMap") - void removeCurrentTokenLocked() { - IBinder token = getCurToken(); - if (DEBUG) { - Slog.v(TAG, "Removing window token: " + token + " for display: " + mCurTokenDisplayId); - } - mWindowManagerInternal.removeWindowToken(token, false /* removeWindows */, - false /* animateExit */, mCurTokenDisplayId); - // Set IME window status as invisible when unbind current method. + void resetSystemUiLocked() { + // Set IME window status as invisible when unbinding current method. mImeWindowVis = 0; mBackDisposition = InputMethodService.BACK_DISPOSITION_DEFAULT; updateSystemUiLocked(mImeWindowVis, mBackDisposition); - setCurToken(null); mCurTokenDisplayId = INVALID_DISPLAY; mCurHostInputToken = null; }