From e937216c330bfcaf523d9627fe315f89db00e36a Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Thu, 4 Jun 2015 17:46:27 +0900 Subject: Catch BadTokenException and continue in clearInsetofPreviousIme. This is a follow up CL for Ib04967f39b2529251e4835c42e9f99dba2cf43f2. As well explained in the I2c21573cf972145ab08e66604cdb9344139a3f31, the race condition here cannot be avoided without an unacceptable performance penalty. For now, we follow the same way. Bug: 21600287 Change-Id: I0ffdf8bf7e8a53cf8aba1339024b32da65d4f32d --- .../android/inputmethodservice/InputMethodService.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 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 81a65f8f38ea..a7afa91e3fae 100644 --- a/core/java/android/inputmethodservice/InputMethodService.java +++ b/core/java/android/inputmethodservice/InputMethodService.java @@ -1565,11 +1565,17 @@ public class InputMethodService extends AbstractInputMethodService { if (DEBUG) Log.v(TAG, "clearInsetOfPreviousIme() " + " mShouldClearInsetOfPreviousIme=" + mShouldClearInsetOfPreviousIme); if (!mShouldClearInsetOfPreviousIme || mWindow == null) return; - // We do not call onWindowShown() and onWindowHidden() so as not to make the IME author - // confused. - // TODO: Find out a better way which has less side-effect. - mWindow.show(); - mWindow.hide(); + try { + // We do not call onWindowShown() and onWindowHidden() so as not to make the IME author + // confused. + // TODO: Find out a better way which has less side-effect. + mWindow.show(); + mWindow.hide(); + } catch (WindowManager.BadTokenException e) { + if (DEBUG) Log.v(TAG, "clearInsetOfPreviousIme: BadTokenException: IME is done."); + mWindowVisible = false; + mWindowAdded = false; + } mShouldClearInsetOfPreviousIme = false; } -- cgit v1.2.3