Created
October 7, 2017 14:17
-
-
Save nikp123/895019d0cc8f3a7374bc007eaa4245a8 to your computer and use it in GitHub Desktop.
A script that powers off your device when unplugged from the charger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/system/bin/sh | |
# Written by nikp123 2017 :D | |
# Powers off android when you unplug it from the charger | |
# Make sure busybox is installed in order this to work | |
while : | |
do | |
sleep 10 | |
a="$(dumpsys power | grep mIsPowered | cut -d'=' -f2)" | |
if [ "$a" == "false" ]; then | |
echo "Power loss [state=$a], checking in 5 seconds..." | |
sleep 5 | |
b="$(dumpsys power | grep mIsPowered | cut -d'=' -f2)" | |
if [ "$b" == "false" ]; then | |
echo "Second power loss [state=$b], powering off..." | |
# Give 30 seconds to power off device | |
busybox poweroff -d 30 -f | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment