Let SoftInputWindow handle BadTokenException
After several attempts [1][2], this is our latest attempt to
gracefully ignore BadTokenException an IME that is being destroyed is
still handling pending showSoftInput() requests.
The point is that SoftInputWindow is a hidden API. This means that
instead of adding a bunch of try/catch blocks around mWindow.show() in
InputMethodService we can always override SoftInputWindow#show() to
inject our own code around mWindow.show().
With this CL, we can now fully track the internal lifecycle of
SoftInputWindow in SoftInputWindow#mWindowState. It enables us to
easily sort out cases like double fault cases discussed
in Bug 113159114, where showSoftInput() requests were queued multiple
times and still IMEs crash because what mWindow.show() throws for
the 2nd failure is IllegaStateException not BadTokenException.
[1] Id1e5f236f48c8ef01b7f157ba3f6e7ab2c26b135
6fcbb5629019489a88a9748f278d40d554cc5cdc
[2] I2c21573cf972145ab08e66604cdb9344139a3f31
e4bbb1cc451c7ebdad9f92968732fc4f6c21a70c
Fix: 113159114
Test: Manually verified IME switching scenario as follows.
1. Build and flush aosp_taimen-userdebug
2. make -j SoftKeyboard
3. adb install -r $OUT/system/app/SoftKeyboard/SoftKeyboard.apk
4. adb shell ime enable com.example.android.softkeyboard/.SoftKeyboard
5. Open the Dialer app and tap the top edit field.
6. Make sure that AOSP Keyboard is shown.
7. Tap the globe button on AOSP Keyboard.
8. Make sure that AOSP Keyboard is dismissed and SoftKeybaord is
shown.
9. Tap the globe button on SoftKeybaord.
10. Make sure that SoftKeybaord. is dismissed and AOSP Keyboard is
shown again.
Test: atest CtsInputMethodTestCases CtsInputMethodServiceHostTestCases
Change-Id: I1f51ed29df6b22b003ca285698e06b8f3ee5106a
2 files changed