1

I'd like to understand if there's a way to trigger the power menu, as if the user had long-pressed the power button. I can be root / a system app, so normal security restrictions may not apply.

What I'm trying to do is prevent the screen from sleeping when power is pressed, but keep the long-press power menu. I was able to keep into the PREVENT_POWER_KEY permission, which allows you to catch the key event KEYCODE_POWER, but is also completely disables the normal power button behavior. That leads me to the original question: how to manually trigger the Android power menu.

I was able to track this down in the Android source: GlobalActions.java. if I'm reading things correctly, it looks like this code programmatically creates a GlobalActionsDialog. This class is not public. My assumption here is that I'm out of luck, but just checking if someone knows a workaround.

I appreciate one would not normally want to do this, but it is for a custom device + ROM.

halfer
  • 19,824
  • 17
  • 99
  • 186
Jeffrey Blattman
  • 22,176
  • 9
  • 79
  • 134
  • If you have root, figure out if there is a consistent hardware event for the power button (e.g., keypress), then there should be a way for root to simulate that key long-press. Particularly if it's for your own hardware, there should be little risk in the hardware event changing without your knowledge. – CommonsWare Jun 17 '13 at 17:46
  • http://stackoverflow.com/a/11338059/1109425 , check this – nandeesh Jun 17 '13 at 18:55
  • some updates on what i'm trying to actually accomplish. – Jeffrey Blattman Jun 17 '13 at 19:01

1 Answers1

0

I just took a look at the platform source code. I'm afraid it's not possible. The long press of the power key is handle by the WindowManagerService which is given the input directly by the Input Service. I even tried a cheeky way of using reflecting to get the Binder but no luck. You just can't get to what you need to, and to action it. Even faking input like Commonsware suggested is out of the mix because the is injected above this level.

Simon
  • 10,932
  • 50
  • 49