Inhibit suspend on network activity

This commit is contained in:
Xavier Del Campo Romero 2023-03-20 03:05:34 +01:00
parent 23f56b50b1
commit e377bc87fd
Signed by: xavi
GPG Key ID: 84FF3612A9BF43F2
1 changed files with 32 additions and 1 deletions

View File

@ -7,6 +7,7 @@ SLEEP_MAX_SECS=600
WAKE_SECS=35
LOCK_DIR="/tmp/sleepwalk"
CPU_STATE=1
THRESHOLD="15.00"
set_cpu_offline() {
if [ $CPU_STATE -eq 1 ]; then
@ -107,8 +108,38 @@ is_screen_on() {
return "$(cat /sys/class/backlight/backlight/bl_power)"
}
network_activity() {
for n in $(seq 3)
do
for i in wwan0 wlan0
do
A=$(ifstat -i $i 1 1 | tail -n1)
RX=$(echo $A | awk '{print $1}')
TX=$(echo $A | awk '{print $2}')
if [ "$RX" = "n/a" ] || [ "$TX" = "n/a" ]
then
return 1
fi
for v in $RX $TX
do
C=$(echo $v $THRESHOLD |
awk '{if ($1 > $2) print "y"; else print "n"}')
if [ "$C" = "y" ]
then
return 0
fi
done
done
done
return 1
}
can_suspend() {
! ( is_inhibitor_active || is_screen_on || is_charging )
! ( is_inhibitor_active || is_screen_on || is_charging || network_activity )
}
led_sleep() {