sxmo: simplify suspend hook and cap suspend time to just 5min

This commit is contained in:
Colin 2023-10-08 04:16:37 +00:00
parent 47e23c1ff3
commit 346ca57c93
2 changed files with 3 additions and 23 deletions

View File

@ -90,7 +90,7 @@ let
suspend = pkgs.static-nix-shell.mkBash {
pname = "sxmo_suspend.sh";
src = ./hooks;
pkgs = [ "coreutils" "util-linux" ];
pkgs = [ "util-linux" ];
};
};
in

View File

@ -1,5 +1,5 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p coreutils -p util-linux
#!nix-shell -i bash -p util-linux
# yeah, this isn't technically a hook, but the hook infrastructure isn't actually
# restricted to stuff that starts with sxmo_hook_ ...
@ -9,31 +9,11 @@
. sxmo_common.sh
sxmo_log "going to suspend to crust"
YEARS8_TO_SEC=268435455
suspend_time=99999999 # far away
mnc="$(sxmo_hook_mnc.sh)"
if [ -n "$mnc" ] && [ "$mnc" -gt 0 ] && [ "$mnc" -lt "$YEARS8_TO_SEC" ]; then
if [ "$mnc" -le 15 ]; then # cronjob imminent
sxmo_wakelock.sh lock sxmo_waiting_cronjob infinite
exit 1
else
suspend_time=$((mnc - 10))
fi
fi
suspend_time=300
sxmo_log "calling suspend with suspend_time <$suspend_time>"
start="$(date "+%s")"
rtcwake -m mem -s "$suspend_time" || exit 1
#We woke up again
time_spent="$(( $(date "+%s") - start ))"
if [ "$((time_spent + 15))" -ge "$suspend_time" ]; then
sxmo_wakelock.sh lock sxmo_waiting_cronjob infinite
fi
sxmo_hook_postwake.sh