OSDN Git Service

A new power button mode to hide the IME when shown
authorYohei Yukawa <yukawa@google.com>
Mon, 17 Apr 2017 17:35:27 +0000 (10:35 -0700)
committerYohei Yukawa <yukawa@google.com>
Mon, 17 Apr 2017 23:22:56 +0000 (23:22 +0000)
commitd6475a682d9651a651f60856baef9b17b4633b13
tree9fd236462073d1e383702c25dfd1a18d628c3b6c
parentd8837b6fca23847fcd4dd295ccbb33ef9d4edcec
A new power button mode to hide the IME when shown

As discussed in Bug 33038203 on certain platforms there is a demand
that the power button can change the behavior depending on whether an
IME window is shown on the screen or not.  The behavior requested here
can be summarized into two parts:

  * Hide the IME window if it is shown [1]
  * Go to the home screen if no IME window is shown

This CL implements the above request by introducing a new config mode
for config_shortPressOnPowerBehavior.  Note the definition of when an
IME is shown is often tricky than people would expect.  The way this
CL is implemented is to propagate IME window state from
InputMethodManagerService (IMMS) to PhoneWindowManager via
WindowManagerService regarding when the back button on the NavBar for
phones/tablets should be shown as an IME dismiss key [2].

 [1]: Even with this CL the IME still is allowed to ignore the request
      to hide the software keyboard. Currently there is no official
      protocol to forcefully hide the software keyboard.  How to deal
      with such a situation is a long standing TODO task.
 [2]: Internally this is controlled by the following IMMS fields:
       - InputMethodManagerService#mImeWindowVis
       - InputMethodManagerService#mBackDisposition
      Note that those fields rely on self-report from the IME.  To be
      precise, the base implementation of InputMethodService is
      responsible for report back its internal state to IMMS when
      necessary.  The important point is that, although this could
      allow a malicious IME to confuse the system UI to some extent,
      supporting malicious IMEs is not clearly a goal of Android.
      Anyway, the definition of when an IME is shown is a kind of
      hot topic in several system services recently.  Hopefully we
      can come up with better definition and reliable mechanism in
      a future release.

Fixes: 33824860
Test: Manually verified as follows
       1. Change config_shortPressOnPowerBehavior to "5"
       2. Rebuilt the OS image and flash it to the device
       3. Make sure that the power button works like a home button
          if software keyboard is not shown.
       4. Open dialer and focus in to the text field shown on top
       5. Make sure that the AOSP keyboard is shown.
       6. Run 'adb shell dumpsys input_method' to observe the
          following line:
            mImeWindowVis=Active|Visible
       7. Tap the power button to make sure that the AOSP keyboard
          gets dismissed.
       8. Tap the power button again to make sure that it works
          as if a home button.
Test: Manually tested as follows
       1. Open dialer and focus in to the text field to show an IME
       2. Run 'adb shell dumpsys window policy' to make sure
            mDismissImeOnBackKeyPressed=true
       3. Tap the back button to dismiss the IME
       4. Run 'adb shell dumpsys window policy' to make sure
            mDismissImeOnBackKeyPressed=false
Change-Id: I20721547c73360a70b5fc5cbe06824d577d1768a
core/java/android/view/WindowManagerInternal.java
core/java/android/view/WindowManagerPolicy.java
core/res/res/values/config.xml
services/core/java/com/android/server/InputMethodManagerService.java
services/core/java/com/android/server/policy/PhoneWindowManager.java
services/core/java/com/android/server/wm/WindowManagerService.java