From 1de53e5369f85f67f9e6ead2239dbd5c41f62869 Mon Sep 17 00:00:00 2001 From: Wilson Wu Date: Thu, 4 Mar 2021 17:29:45 +0800 Subject: [PATCH] Fix delayed hide soft input when switch user The user switch task may cost some time and delay to send the hide soft input action. It likely happended when system is busy(e.g. starting winscope trace). 1. Try to fix this by sending the hide soft input action before user switch task. 2. Remove the mSystemReady checking since user switch task should be always posted afterward. Bug: 176291101 Test: atest CtsInputMethodTestCases Change-Id: I1689e7a7a30ed717520e9d3c160e1727202ee15b --- .../InputMethodManagerService.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index 0754df0e6b9f5..09837208a9dde 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -1625,6 +1625,10 @@ public class InputMethodManagerService extends IInputMethodManager.Stub } mHandler.removeCallbacks(mUserSwitchHandlerTask); } + // Hide soft input before user switch task since switch task may block main handler a while + // and delayed the MSG_HIDE_SOFT_INPUT. + hideCurrentInputLocked( + mCurFocusedWindow, 0, null, SoftInputShowHideReason.HIDE_SWITCH_USER); final UserSwitchHandlerTask task = new UserSwitchHandlerTask(this, userId, clientToBeReset); mUserSwitchHandlerTask = task; @@ -1750,20 +1754,16 @@ public class InputMethodManagerService extends IInputMethodManager.Stub final boolean initialUserSwitch = TextUtils.isEmpty(defaultImiId); mLastSystemLocales = mRes.getConfiguration().getLocales(); - // TODO: Is it really possible that switchUserLocked() happens before system ready? - if (mSystemReady) { - hideCurrentInputLocked( - mCurFocusedWindow, 0, null, SoftInputShowHideReason.HIDE_SWITCH_USER); - - resetCurrentMethodAndClient(UnbindReason.SWITCH_USER); - buildInputMethodListLocked(initialUserSwitch); - if (TextUtils.isEmpty(mSettings.getSelectedInputMethod())) { - // This is the first time of the user switch and - // set the current ime to the proper one. - resetDefaultImeLocked(mContext); - } - updateFromSettingsLocked(true); + // The mSystemReady flag is set during boot phase, + // and user switch would not happen at that time. + resetCurrentMethodAndClient(UnbindReason.SWITCH_USER); + buildInputMethodListLocked(initialUserSwitch); + if (TextUtils.isEmpty(mSettings.getSelectedInputMethod())) { + // This is the first time of the user switch and + // set the current ime to the proper one. + resetDefaultImeLocked(mContext); } + updateFromSettingsLocked(true); if (initialUserSwitch) { InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(mIPackageManager,