From 90120a8b5b14d4d0830b3b5f478bb627a7ac06ea Mon Sep 17 00:00:00 2001 From: lumark Date: Wed, 15 Aug 2018 00:33:03 +0800 Subject: Support IME Window to show in secondary display. 1) Moving WMS.setInputMethodWindowLocked to DisplayContent, each display can have its own IME window. 2) Add getDisplayIdFromWindow in WindowManagerInternal, used for InputMethodManagerService to know which display for given IME window token. 3) Support add / remove IME window according displayId. 4) Modify WMS.inputMethodClientHasFocus to traverse all active display if inputMethodClient focused. 5) Add displayId parameter for IInputMethod.initializeInternal to update context display then client can addView to right display. Note: 1) There should be zero behavior difference as long as the target app is running on the default display. 2) The current implementation is not final and there are still chances that the current IME may not work well or even crash depending on how the IME is implemented. Bug: 111364446 Test: manual, use ActivityView & launch Messages in VirtualDisplay, tap search icon to see if soft input keyboard shown & app window size is adjusted by soft input. Change-Id: I8da315936caebdc8b2c16cff4e24192c06743251 --- .../inputmethodservice/InputMethodService.java | 23 +++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'core/java/android/inputmethodservice/InputMethodService.java') diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java index 2d12b867949a..34fa5b6b9842 100644 --- a/core/java/android/inputmethodservice/InputMethodService.java +++ b/core/java/android/inputmethodservice/InputMethodService.java @@ -16,6 +16,7 @@ package android.inputmethodservice; +import static android.view.Display.DEFAULT_DISPLAY; import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; import static android.view.WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; @@ -461,10 +462,11 @@ public class InputMethodService extends AbstractInputMethodService { */ @MainThread @Override - public final void initializeInternal(IBinder token, + public final void initializeInternal(IBinder token, int displayId, IInputMethodPrivilegedOperations privilegedOperations) { mPrivOps.set(privilegedOperations); mImm.registerInputMethodPrivOps(token, mPrivOps); + updateInputMethodDisplay(displayId); attachToken(token); } @@ -482,6 +484,22 @@ public class InputMethodService extends AbstractInputMethodService { mWindow.setToken(token); } + /** + * {@inheritDoc} + * @hide + */ + @MainThread + @Override + public void updateInputMethodDisplay(int displayId) { + // Update display for adding IME window to the right display. + if (displayId != DEFAULT_DISPLAY) { + // TODO(b/111364446) Need to address context lifecycle issue if need to re-create + // for update resources & configuration correctly when show soft input + // in non-default display. + updateDisplay(displayId); + } + } + /** * {@inheritDoc} * @@ -930,6 +948,9 @@ public class InputMethodService extends AbstractInputMethodService { // If the previous IME has occupied non-empty inset in the screen, we need to decide whether // we continue to use the same size of the inset or update it mShouldClearInsetOfPreviousIme = (mImm.getInputMethodWindowVisibleHeight() > 0); + // TODO(b/111364446) Need to address context lifecycle issue if need to re-create + // for update resources & configuration correctly when show soft input + // in non-default display. mInflater = (LayoutInflater)getSystemService( Context.LAYOUT_INFLATER_SERVICE); mWindow = new SoftInputWindow(this, "InputMethod", mTheme, null, null, mDispatcherState, -- cgit v1.2.3