diff options
| author | Charles Chen <charlesccchen@google.com> | 2022-01-10 22:37:37 +0800 |
|---|---|---|
| committer | Charles Chen <charlesccchen@google.com> | 2022-01-12 02:56:46 +0000 |
| commit | 07a7f23e36c3461268cbd28bb6779bdcf613d7ad (patch) | |
| tree | 24030f75df17dd3ea0610804a8276c7c7a997913 /core/java/android/inputmethodservice/InputMethodService.java | |
| parent | 13ab5f84ce9e8d65ab4a1d3c6b740b7577029cb5 (diff) | |
[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
Diffstat (limited to 'core/java/android/inputmethodservice/InputMethodService.java')
| -rw-r--r-- | core/java/android/inputmethodservice/InputMethodService.java | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java index afaa085c7cbd..f537a71cf01d 100644 --- a/core/java/android/inputmethodservice/InputMethodService.java +++ b/core/java/android/inputmethodservice/InputMethodService.java @@ -523,6 +523,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} @@ -599,6 +600,11 @@ public class InputMethodService extends AbstractInputMethodService { @Override public final void initializeInternal(@NonNull IBinder token, IInputMethodPrivilegedOperations privilegedOperations, int configChanges) { + 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); @@ -1435,6 +1441,7 @@ public class InputMethodService extends AbstractInputMethodService { } @Override public void onDestroy() { + mDestroyed = true; super.onDestroy(); mRootView.getViewTreeObserver().removeOnComputeInternalInsetsListener( mInsetsComputer); |
