meefik / linuxdeploy

Install and run GNU/Linux on Android
https://meefik.github.io/linuxdeploy
GNU General Public License v3.0
5.25k stars 680 forks source link

Question: How to make a wrapper to keep a wakelock while child is running #125

Open ccaapton opened 10 years ago

ccaapton commented 10 years ago

The most annoy part of running linux commands on android is that they are not "wakelock-aware". When I need to run a python scripts that take 3 minutes, the job will often be paused when android goes to sleep.

I hope to have a wrapper script, some like "keepwake.sh". so I can execute my command like keepawake.sh mypythonscript.py. The script will acquire a wakelock at the beginning, then start the mypythonscript.py. After the job is done, the script release wakelock and terminate. Could you help me to figure out how to do it? Thanks a lot!

oczkers commented 7 years ago

Dunno if you need this anymore but simply: add (cpu) wakelock:

echo 'blabla_lock' > /sys/power/wake_lock

remove wakelock:

echo 'blabla_lock' > /sys/power/wake_unlock
twaik commented 6 years ago

You can use this script: https://gist.github.com/twaik/a4d62c256652818054548e4c62760050

albertcerdan commented 4 years ago

based on twaik script

#!/bin/bash
# android 9 wake lock admin script
case $1 in
    1) grep -q ld /sys/power/wake_lock || ( echo ld > /sys/power/wake_lock && echo "Wake Locked" );;
    0) grep -q ld /sys/power/wake_lock && echo ld > /sys/power/wake_unlock && echo "Wake Unlocked";;
    *) printf "usage: $0 [0|1]\nNeed to be root for make changes.\n\nActive Wake Locks:\n"; cat /sys/power/wake_lock;;
esac