androidandroid-buttonandroid-framework

How does Android OS listen for Power Button key short presses?


I'm looking for the implementation in the Android source on how the power button is mapped to turning the screen off. I am working on a custom ROM and am trying to find the relationship between the two events (short key press and screen turning off). I am finding that the screen state changes in frameworks/base/services/java/com/android/server/PowerManagerService.java, but I don't see anything related to the power button itself.

Thank you for your help.


Solution

  • Look in com.android.internal.policy.impl.WindowManagerPolicy.java. This handles dispatching of key events to the appropriate place and also provides custom handling of the power button.

    In particular, you might be interested in interceptKeyBeforeQueueing(), or just search for KEYCODE_POWER.