Skip to content

Instantly share code, notes, and snippets.

@nikp123
Created October 7, 2017 14:17
Show Gist options
  • Save nikp123/895019d0cc8f3a7374bc007eaa4245a8 to your computer and use it in GitHub Desktop.
Save nikp123/895019d0cc8f3a7374bc007eaa4245a8 to your computer and use it in GitHub Desktop.
A script that powers off your device when unplugged from the charger
#!/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