Skip to content
Commit ee2a7ed3 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Allow setImeWindowStatus with null startInputToken

This is a follow up CL to my previous CL [1], which caused an unexpected
side effect that leads the current IME to crash due to a too strict
requiremnt.

It turns out that it was too early for us to start requiring non-null
StartInputToken in InputMethodManagerService#setImeWindowStatus()
because in many places we have assumed that an IME can show/hide its
software keyboard even before an IME target window is associated with
the IME.

There are two major cases that we missed:

 - InputMethodManager#showSoftInputFromInputMethod(IBinder, int):

   This method does not require that the calling IME is already bound
   to an IME target window.

 - InputMethodManager#showSoftInputUnchecked(int ,ResultReceiver):

   This @hide method allows the caller application to let current IME
   show the software keyboard with bypassing all the normal focus
   management tasks in InputMethodManager.  We should seriously
   consider to deprecate this @hide method, but to do that we have to
   clean up some internal components and SearchView in the support
   library that still rely on this method.

Bug 35395372 is triggered by the second scenario, but until we sort out
all the possible corner cases, we should allow null startInputToken as a
valid request, like we had have done so before the CL [1] introduced
such a validation.

 [1]: I9921b381e02106dbffff5e0b3d13f0a1245ce807
      6db3bfe3

Test: Made sure Bug 35395372 is no longer reproducible, that is,
      1. Flash a new image and complete the setup wizard on a
         direct-boot unaware device.
      2. Set a device password and require it upon each device boot.
      3. adb reboot
      4. Observe the default IME does not crash because of
         InvalidParameterException thrown by IMMS.
Test: Made sure IMM#showSoftInputFromInputMethod(IBinder, int) does
      not throw an InvalidParameterException even in an extreme case.
      1. Rebuild LatinIME with the following code in LatinIME.java
       @Override
       public AbstractInputMethodImpl onCreateInputMethodInterface() {
           return new InputMethodService.InputMethodImpl() {
               @Override
               public void attachToken(IBinder token) {
                   super.attachToken(token);

                   final InputMethodManager imm =
                       getSystemService(InputMethodManager.class);
                   final IBinder imeToken =
                       getWindow().getWindow().getAttributes().token;
                   imm.showSoftInputFromInputMethod(imeToken, 0);
               }
           };
       }
      2. adb install -r LatinIME.apk
      3. adb shell ime enable com.android.inputmethod.latin/.LatinIME
      4. adb shell ime set com.android.inputmethod.latin/.LatinIME
      5. Tap any text field.
      4. Observe LatinIME does not crash because of
         InvalidParameterException thrown by IMMS.
Bug: 34628091
Bug: 35079353
Fixes: 35395372
Change-Id: Ib9448c551d9a30776a999c27a5ff20f1a095633a
parent 040e425b
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment