[GUIDE] Proper Shutdown - Emulating long press power button

66 posts
Thanks Meter: 3
By Gogolo2, Member on 22nd August 2014, 08:42 AM
Post Reply Subscribe to Thread Email Thread

So you want to emulate the native android shutdown sequence. Broken power button? Car or fixed Nexus 7 installation? TV Stick? Here is the solution! (I advise you not to use one of the many shutdown apps because they shutdown without unmounting filesystem etc. and thus can damage your filesystem in the long run).

This should work on ANY Android device!

You can do it directly on your device, no adb needed. BUT: You have to be rooted!

How to:

1. Install Bash X from playstore (I'm not affiliated with them)
2. Start it and choose #root shell
3. Type: getevent -c 3
4. Push power button and release it (short, without the boot dialog)

5. Now you see something like this:

# getevent -c 3
add device 1: /dev/input/event0
name: "pmic8xxx_pwrkey"
add device 2: /dev/input/event1
name: "gk-keypad-8064"
add device 3: /dev/input/event4
name: "hs_detect"
add device 4: /dev/input/event3
name: "suspend_autotest_pwrkey"
could not get driver version for /dev/input/mice, Not a typewriter
add device 5: /dev/input/event2
name: "touch_mxt1188S"
/dev/input/event0: 0001 0074 00000001
/dev/input/event0: 0000 0000 00000000
/dev/input/event0: 0001 0074 00000000

add device output shows you the event numbers off your input devices. On my LG Pad the power key is assigned to /dev/input/event0. On your device it will be a other eventX number. On my Nexus 7 it is event2 (gpio).

Now we convert the hex strings of the events in dec (google a online converter). The last 3 lines then look like this:

/dev/input/event0: 1 116 1
/dev/input/event0: 0 0 0
/dev/input/event0: 1 116 0

1 116 1 means power key down
1 116 0 means power key release

6. Install Tasker. Set up a new profile with the profile you want to be the trigger for your action (shutdown). Under tasks choose script, start shell and paste our new script:

/dev/input/event0: 1 116 1;
/dev/input/event0: 0 0 0;
sleep 1;
/dev/input/event0: 1 116 0;

Now we need only some dpad keys for going down and right in the menu:

input keyevent 20;
input keyevent 66;
input keyevent 22;
input keyevent 66;

(Where 20 is down, 22 is right and 66 is enter. This works on stock and CM10)

The Tasker action finally looks like this:

/dev/input/event0: 1 116 1;
/dev/input/event0: 0 0 0;
/dev/input/event0: 1 116 0;
input keyevent 20;
input keyevent 66;
input keyevent 22;
input keyevent 66;

Don't forget to check "use root" in your action. Test it out!

Cool it is

I also thank the many people working on this question on other places.

edit: if you experience no proper shutdown (have to press 15sec power button for boot), its because tasker hangs on shutdown. Export a app from tasker and start it with automateit. Weird but it works
Last edited by Gogolo2; 29th August 2014 at 09:02 PM.
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes