Skip to content

Commit a82ba54

Browse files
author
Dianne Hackborn
committed
Part of fixing issue #6006757: Keyboard dismissal lags
This adjust various paths through InputMethodManager so that the flow in switching focus from one application to another is cleaner, resulting in less work being done, resulting in it being able to happen quicker. Some of the changes here avoid doing stuff when not needed, such as when we are told to unbind but are not currently the active input. A big part is also a change to the flow when a window receives input. Previously this would first do a checkFocus() which would tell the input method to switch focus to whatever view has focus in the window, followed by the windowGainedFocus() call telling it the window had gained focus. This would result in extra work because the input method service would first handle the focus switch, seeing the IME is currently displayed, so the IME would remain up and reset its focus to the new view. The app would immediately then tell it about the window, causing the service to find out the IME should be hidden and telling the IME, but the IME couldn't hide itself until it had first take care of switching its input. There is the definite potential of this breaking IME showing/hiding in cases depending on the order things may be relying on them to happen. I haven't seen any problems with a brief trip through the UI. Change-Id: I8494cbd6e19e2ab6db03f2463d9906680dda058b
1 parent ffc8989 commit a82ba54

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

core/java/android/view/inputmethod/InputMethodManager.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,10 @@ public void handleMessage(Message msg) {
355355
if (mServedView != null && mServedView.isFocused()) {
356356
mServedConnecting = true;
357357
}
358+
if (mActive) {
359+
startInputInner();
360+
}
358361
}
359-
startInputInner();
360362
}
361363
return;
362364
}
@@ -1127,43 +1129,49 @@ void scheduleCheckFocusLocked(View view) {
11271129
* @hide
11281130
*/
11291131
public void checkFocus() {
1132+
if (checkFocusNoStartInput()) {
1133+
startInputInner();
1134+
}
1135+
}
1136+
1137+
private boolean checkFocusNoStartInput() {
11301138
// This is called a lot, so short-circuit before locking.
11311139
if (mServedView == mNextServedView && !mNextServedNeedsStart) {
1132-
return;
1140+
return false;
11331141
}
11341142

11351143
InputConnection ic = null;
11361144
synchronized (mH) {
11371145
if (mServedView == mNextServedView && !mNextServedNeedsStart) {
1138-
return;
1146+
return false;
11391147
}
11401148
if (DEBUG) Log.v(TAG, "checkFocus: view=" + mServedView
11411149
+ " next=" + mNextServedView
11421150
+ " restart=" + mNextServedNeedsStart);
1143-
1151+
11441152
mNextServedNeedsStart = false;
11451153
if (mNextServedView == null) {
11461154
finishInputLocked();
11471155
// In this case, we used to have a focused view on the window,
11481156
// but no longer do. We should make sure the input method is
11491157
// no longer shown, since it serves no purpose.
11501158
closeCurrentInput();
1151-
return;
1159+
return false;
11521160
}
1153-
1161+
11541162
ic = mServedInputConnection;
1155-
1163+
11561164
mServedView = mNextServedView;
11571165
mCurrentTextBoxAttribute = null;
11581166
mCompletions = null;
11591167
mServedConnecting = true;
11601168
}
1161-
1169+
11621170
if (ic != null) {
11631171
ic.finishComposingText();
11641172
}
1165-
1166-
startInputInner();
1173+
1174+
return true;
11671175
}
11681176

11691177
void closeCurrentInput() {
@@ -1192,7 +1200,7 @@ public void onWindowFocus(View rootView, View focusedView, int softInputMode,
11921200
focusInLocked(focusedView != null ? focusedView : rootView);
11931201
}
11941202

1195-
checkFocus();
1203+
boolean startInput = checkFocusNoStartInput();
11961204

11971205
synchronized (mH) {
11981206
try {
@@ -1201,6 +1209,9 @@ public void onWindowFocus(View rootView, View focusedView, int softInputMode,
12011209
mService.windowGainedFocus(mClient, rootView.getWindowToken(),
12021210
focusedView != null, isTextEditor, softInputMode, first,
12031211
windowFlags);
1212+
if (startInput) {
1213+
startInputInner();
1214+
}
12041215
} catch (RemoteException e) {
12051216
}
12061217
}

0 commit comments

Comments
 (0)