diff options
3 files changed, 21 insertions, 6 deletions
diff --git a/core/java/android/inputmethodservice/IInputMethodWrapper.java b/core/java/android/inputmethodservice/IInputMethodWrapper.java index 05daf63fdd5d..df4dcce84a50 100644 --- a/core/java/android/inputmethodservice/IInputMethodWrapper.java +++ b/core/java/android/inputmethodservice/IInputMethodWrapper.java @@ -147,12 +147,16 @@ class IInputMethodWrapper extends IInputMethod.Stub @MainThread @Override public void executeMessage(Message msg) { - InputMethod inputMethod = mInputMethod.get(); + final InputMethod inputMethod = mInputMethod.get(); // Need a valid reference to the inputMethod for everything except a dump. if (inputMethod == null && msg.what != DO_DUMP) { Log.w(TAG, "Input method reference was null, ignoring message: " + msg.what); return; } + if (inputMethod != null && inputMethod.isServiceDestroyed() && msg.what != DO_DUMP) { + Log.w(TAG, "InputMethodService was destroyed, ignoring message: " + msg.what); + return; + } switch (msg.what) { case DO_DUMP: { diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java index 3a157d30d4c4..764bc2c41de0 100644 --- a/core/java/android/inputmethodservice/InputMethodService.java +++ b/core/java/android/inputmethodservice/InputMethodService.java @@ -700,11 +700,6 @@ public class InputMethodService extends AbstractInputMethodService { @MainThread @Override public final void initializeInternal(@NonNull IInputMethod.InitParams params) { - if (mDestroyed) { - Log.i(TAG, "The InputMethodService has already onDestroyed()." - + "Ignore the initialization."); - return; - } Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMS.initializeInternal"); mConfigTracker.onInitialize(params.configChanges); mPrivOps.set(params.privilegedOperations); @@ -1070,6 +1065,16 @@ public class InputMethodService extends AbstractInputMethodService { public void changeInputMethodSubtype(InputMethodSubtype subtype) { dispatchOnCurrentInputMethodSubtypeChanged(subtype); } + + /** + * {@inheritDoc} + * @hide + */ + @MainThread + @Override + public final boolean isServiceDestroyed() { + return mDestroyed; + } } /** diff --git a/core/java/android/view/inputmethod/InputMethod.java b/core/java/android/view/inputmethod/InputMethod.java index 978bfc7af60d..af7e59220fbd 100644 --- a/core/java/android/view/inputmethod/InputMethod.java +++ b/core/java/android/view/inputmethod/InputMethod.java @@ -417,4 +417,10 @@ public interface InputMethod { default void removeStylusHandwritingWindow() { // intentionally empty } + + /** + * Return {@code true} if the {@link InputMethodService} is destroyed. + * @hide + */ + boolean isServiceDestroyed(); } |