From fc7a1b5b34ad15bee492deab8123d7a548c8b8b3 Mon Sep 17 00:00:00 2001 From: Charles Chen Date: Wed, 16 Jun 2021 20:26:34 +0800 Subject: Migrate InputMethodService to WindowProviderService Also introduce IWindowManager#getDisplayIdToLaunchIme to make IMS be aware of the launched display to prevent extra onConfigurationChanged callback Bug: 149463653 Test: atest MultiDisplaySystemDecorationTests CtsInputMethodTestCases Test: atest ContextTest ContextIsUiContextTest Test: manual - moving IME between 2 displays and displayArea within display - config change received Test: manual - the app to show IME crashed and focus is set to the next task - no config change Change-Id: Ie565e30ed5dd3f2cfe27355a6dded76dc3adc14b --- core/java/android/inputmethodservice/InputMethodService.java | 3 +++ 1 file changed, 3 insertions(+) (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 881e0cfb58d7..18c6256dff80 100644 --- a/core/java/android/inputmethodservice/InputMethodService.java +++ b/core/java/android/inputmethodservice/InputMethodService.java @@ -629,10 +629,13 @@ public class InputMethodService extends AbstractInputMethodService { throw new IllegalStateException( "attachToken() must be called at most once. token=" + token); } + attachToWindowToken(token); mToken = token; mWindow.setToken(token); } + // TODO(b/149463653): remove updateInputMethodDisplay(int displayId) since we'll get the + // right display by attachToWindowToken /** * {@inheritDoc} * @hide -- cgit v1.2.3 From cbf1be8150c96c5ad66685a9394749eee065a78f Mon Sep 17 00:00:00 2001 From: Charles Chen Date: Tue, 22 Jun 2021 21:05:34 +0800 Subject: Remove updateImeDisplayId After InputMethodService migrated to WindowProviderService, the display is initialized by getInitialDisplayId(). Therefore, we don't need updateImeDisplayId() to initialize InputMethodService's Display anymore. Test: atest CtsInputMethodTestCases MultiDisplaySystemDecorationTests Bug: 149463653 Change-Id: Ia78139b5defc48c8b0354fc1e212eeb38fd71ba4 --- .../inputmethodservice/InputMethodService.java | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) (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 18c6256dff80..42fa9fbc7b94 100644 --- a/core/java/android/inputmethodservice/InputMethodService.java +++ b/core/java/android/inputmethodservice/InputMethodService.java @@ -589,7 +589,7 @@ public class InputMethodService extends AbstractInputMethodService { */ @MainThread @Override - public final void initializeInternal(@NonNull IBinder token, int displayId, + public final void initializeInternal(@NonNull IBinder token, IInputMethodPrivilegedOperations privilegedOperations, int configChanges) { if (InputMethodPrivilegedOperationsRegistry.isRegistered(token)) { Log.w(TAG, "The token has already registered, ignore this initialization."); @@ -599,7 +599,6 @@ public class InputMethodService extends AbstractInputMethodService { mConfigTracker.onInitialize(configChanges); mPrivOps.set(privilegedOperations); InputMethodPrivilegedOperationsRegistry.put(token, mPrivOps); - updateInputMethodDisplay(displayId); attachToken(token); Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); } @@ -634,25 +633,6 @@ public class InputMethodService extends AbstractInputMethodService { mWindow.setToken(token); } - // TODO(b/149463653): remove updateInputMethodDisplay(int displayId) since we'll get the - // right display by attachToWindowToken - /** - * {@inheritDoc} - * @hide - */ - @MainThread - @Override - public void updateInputMethodDisplay(int displayId) { - if (getDisplayId() == displayId) { - return; - } - // Update display for adding IME window to the right 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} * -- cgit v1.2.3 From fabbcd12476704e16c19a2f9b258f2270d5a4be5 Mon Sep 17 00:00:00 2001 From: Taran Singh Date: Wed, 18 Aug 2021 23:29:21 +0000 Subject: Fix NPE in IMS#onEvaluateFullscreenMode Fix NPE when EditorInfo is null Test: Manually using steps in bug Fix: 197078413 Bug: 197258697 Change-Id: I7437dec66f2cfe7769b9448916998c40745c3ebc --- core/java/android/inputmethodservice/InputMethodService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (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 42fa9fbc7b94..c0f008122b4f 100644 --- a/core/java/android/inputmethodservice/InputMethodService.java +++ b/core/java/android/inputmethodservice/InputMethodService.java @@ -1732,12 +1732,12 @@ public class InputMethodService extends AbstractInputMethodService { if (config.orientation != Configuration.ORIENTATION_LANDSCAPE) { return false; } - if ((mInputEditorInfo != null - && (mInputEditorInfo.imeOptions & EditorInfo.IME_FLAG_NO_FULLSCREEN) != 0) + if (mInputEditorInfo != null + && ((mInputEditorInfo.imeOptions & EditorInfo.IME_FLAG_NO_FULLSCREEN) != 0 // If app window has portrait orientation, regardless of what display orientation // is, IME shouldn't use fullscreen-mode. || (mInputEditorInfo.internalImeOptions - & EditorInfo.IME_INTERNAL_FLAG_APP_WINDOW_PORTRAIT) != 0) { + & EditorInfo.IME_INTERNAL_FLAG_APP_WINDOW_PORTRAIT) != 0)) { return false; } return true; -- cgit v1.2.3 From 70021e0f8a8872c9830dd424484bc785b0609bd6 Mon Sep 17 00:00:00 2001 From: Taran Singh Date: Mon, 11 Oct 2021 19:11:24 +0000 Subject: Remove binder tracing from IMS Binder tracing can be very expensive. In dogfood builds its triggered time to time and it should only be called manually when needed. Fix: 202721321 Test: atest CtsInputMethodtestCases tested with winscope trace. Change-Id: I0a4ee1b90e56ed1b20e44b5a0b42c17d565d05dd --- core/java/android/inputmethodservice/InputMethodService.java | 5 ----- 1 file changed, 5 deletions(-) (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 c0f008122b4f..9721279bcd24 100644 --- a/core/java/android/inputmethodservice/InputMethodService.java +++ b/core/java/android/inputmethodservice/InputMethodService.java @@ -790,11 +790,6 @@ public class InputMethodService extends AbstractInputMethodService { return; } - if (Trace.isEnabled()) { - Binder.enableTracing(); - } else { - Binder.disableTracing(); - } Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMS.showSoftInput"); ImeTracing.getInstance().triggerServiceDump( "InputMethodService.InputMethodImpl#showSoftInput", InputMethodService.this, -- cgit v1.2.3 From e51f699fa8632eac088782c1fbfe9d3d51552b84 Mon Sep 17 00:00:00 2001 From: Tony Wickham Date: Tue, 23 Nov 2021 17:34:25 +0000 Subject: Consider IME_VISIBLE_IMPERCEPTIBLE as shown for taskbar purposes IME_VISIBLE isn't set until the keyboard is "perceptibly" visible to the user (e.g. based on alpha). But we want to signal to taskbar as soon as we know IME will be visible. Test: tap an edit field to open keyboard, ensure taskbar reacts immediately instead of halfway through the transition Bug: 202511986 Change-Id: I39c15578ed3e5b729f4645ad76988b113f0b57a6 --- core/java/android/inputmethodservice/InputMethodService.java | 11 ++++++++++- 1 file changed, 10 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 9721279bcd24..e0324c0ded26 100644 --- a/core/java/android/inputmethodservice/InputMethodService.java +++ b/core/java/android/inputmethodservice/InputMethodService.java @@ -395,7 +395,7 @@ public class InputMethodService extends AbstractInputMethodService { /** * @hide - * The IME is visible. + * The IME is perceptibly visible to the user. */ public static final int IME_VISIBLE = 0x2; @@ -406,6 +406,15 @@ public class InputMethodService extends AbstractInputMethodService { */ public static final int IME_INVISIBLE = 0x4; + /** + * @hide + * The IME is visible, but not yet perceptible to the user (e.g. fading in) + * by {@link android.view.WindowInsetsController}. + * + * @see InputMethodManager#reportPerceptible + */ + public static final int IME_VISIBLE_IMPERCEPTIBLE = 0x8; + // Min and max values for back disposition. private static final int BACK_DISPOSITION_MIN = BACK_DISPOSITION_DEFAULT; private static final int BACK_DISPOSITION_MAX = BACK_DISPOSITION_ADJUST_NOTHING; -- cgit v1.2.3 From 468f72f0164f18e3da3a8b2d5fc7fbc8c55def65 Mon Sep 17 00:00:00 2001 From: Charles Chen Date: Mon, 10 Jan 2022 22:37:37 +0800 Subject: [RESTRICT AUTOMERGE] Attempt to fix exception in IMS IMS might throw IllegalStateException in WindowContextController#attachToWindowToken when #initializeInternal is called. A possible root cause may be #initializeInternal is called after onDestroy, which detach IMS from ImeContainer. This CL add a flag in #onDestroy to prevent #initializeInternal from being called after #onDestroy. Bug: 211062619 Test: presubmit Change-Id: Ie7814da801878a3487123fefdc9e71d0e1ed28d7 --- core/java/android/inputmethodservice/InputMethodService.java | 7 +++++++ 1 file changed, 7 insertions(+) (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 e0324c0ded26..9f798869e54a 100644 --- a/core/java/android/inputmethodservice/InputMethodService.java +++ b/core/java/android/inputmethodservice/InputMethodService.java @@ -524,6 +524,7 @@ public class InputMethodService extends AbstractInputMethodService { private Handler mHandler; private boolean mImeSurfaceScheduledForRemoval; private ImsConfigurationTracker mConfigTracker = new ImsConfigurationTracker(); + private boolean mDestroyed; /** * An opaque {@link Binder} token of window requesting {@link InputMethodImpl#showSoftInput} @@ -604,6 +605,11 @@ public class InputMethodService extends AbstractInputMethodService { Log.w(TAG, "The token has already registered, ignore this initialization."); return; } + if (mDestroyed) { + Log.i(TAG, "The InputMethodService has already onDestroyed()." + + "Ignore the initialization."); + return; + } Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMS.initializeInternal"); mConfigTracker.onInitialize(configChanges); mPrivOps.set(privilegedOperations); @@ -1403,6 +1409,7 @@ public class InputMethodService extends AbstractInputMethodService { } @Override public void onDestroy() { + mDestroyed = true; super.onDestroy(); mRootView.getViewTreeObserver().removeOnComputeInternalInsetsListener( mInsetsComputer); -- cgit v1.2.3