- Default CPU_RPM_SLEEP=0, CPU_L2_SLEEP=0, and MODEM_DRX_MODE=0 across bananarchy-power-policy.conf, bananarchy-power-policy.sh, bananarchy-display-power-sync, and kernel patch 0010 so closed-flip incoming calls wake APSS promptly via smd-edge without AT port contention. - Serialize sxmo_modem.sh incoming/finished call checks, expire stale /tmp/sxmo_hangup_requested flags, re-verify live ModemManager call state before ringing/raising callscreen, guard idle/flip-open HANGUP_CLOSE paths in locker.so, callscreen.so, bananarchy-idle-lock.sh, and bananarchy-lid, preserve calls on flip-open (UNGRAB/RAISE), and add closed-flip cover call controls (bananarchy-cover-idle, bananarchy-cover-event.sh, bananarchy-volume-keys). - Propagate live network/manual timezone updates across statusbar, locker.so, bananarchy-cover-idle, bananarchy-dsds, callscreen.so, and bananarchy-run-aligned without reboot (scripts/test-time-timezone-sync.py), remove non-functional Logout from the Power menu, ignore post-call sxmo_calls markers, add scripts/build-dwm-plugins.sh, and update a1114 (carbonara) hashes and docs.
407 lines
13 KiB
Bash
Executable File
407 lines
13 KiB
Bash
Executable File
#!/bin/sh
|
|
# Bananarchy runtime power policy: Wi-Fi listen interval, modem DRX, DSDS.
|
|
# Runs as root; re-execs through doas -n when called from the X session.
|
|
set -u
|
|
|
|
CONF=/etc/bananarchy-power-policy.conf
|
|
MODPROBE=/etc/modprobe.d/10-bananarchy-power.conf
|
|
RUNDIR=/run/bananarchy-power-policy
|
|
PARKED="$RUNDIR/parked"
|
|
AIDFILE="$RUNDIR/secondary.aid"
|
|
SLOTFILE="$RUNDIR/secondary.slot"
|
|
TOKEN="$RUNDIR/token"
|
|
RAT_PARKED="$RUNDIR/rat_parked"
|
|
RAT_SAVED="$RUNDIR/saved_rat"
|
|
RAT_TOKEN="$RUNDIR/rat.token"
|
|
IPV6_RA_SAVED="$RUNDIR/wlan0_accept_ra"
|
|
BOOTTOKEN="$RUNDIR/boot.token"
|
|
READYSTAMP="$RUNDIR/modem_ready.stamp"
|
|
DRXLOCK="$RUNDIR/lock.drx"
|
|
ACCEPT_RA=/proc/sys/net/ipv6/conf/wlan0/accept_ra
|
|
SPM_PARAM_DIR=/sys/module/cpuidle_qcom_spm/parameters
|
|
QMI="timeout 8 qmicli --silent -pd qrtr://0"
|
|
|
|
if [ "$(id -u)" != "0" ]; then
|
|
exec doas -n "$0" "$@"
|
|
fi
|
|
|
|
WIFI_LISTEN_INTERVAL=5
|
|
MODEM_DRX_MODE=0
|
|
DSDS_SECONDARY_MODE=active
|
|
DSDS_PARK_DELAY=300
|
|
CPU_RPM_SLEEP=0
|
|
CPU_L2_SLEEP=0
|
|
WIFI_SCREEN_OFF_IPV6_MUTE=1
|
|
WIFI_STANDBY_RAT=keep
|
|
[ -r "$CONF" ] && . "$CONF"
|
|
|
|
mkdir -p "$RUNDIR" 2>/dev/null || true
|
|
|
|
log() {
|
|
printf 'bananarchy-power-policy: %s\n' "$*" >&2
|
|
}
|
|
|
|
write_modprobe() {
|
|
n="$WIFI_LISTEN_INTERVAL"
|
|
case "$n" in ''|*[!0-9]*) n=0 ;; esac
|
|
if [ "$n" -lt 1 ] || [ "$n" -gt 10 ]; then
|
|
n=0
|
|
fi
|
|
if [ "$n" = "0" ]; then
|
|
rm -f "$MODPROBE" 2>/dev/null || true
|
|
return 0
|
|
fi
|
|
mkdir -p "$(dirname "$MODPROBE")" 2>/dev/null || true
|
|
printf '# Generated by bananarchy-power-policy.sh from %s\n' "$CONF" > "$MODPROBE" || return 1
|
|
printf 'options wcn36xx listen_interval=%s\n' "$n" >> "$MODPROBE" || return 1
|
|
}
|
|
|
|
apply_modem_drx() {
|
|
force_drx="${1:-cached}"
|
|
case "$MODEM_DRX_MODE" in
|
|
0)
|
|
rm -f "$RUNDIR"/drx.wwan* 2>/dev/null || true
|
|
return 0
|
|
;;
|
|
6|7|8|9) ;;
|
|
*)
|
|
log "invalid MODEM_DRX_MODE=$MODEM_DRX_MODE (use 0 or 6-9)"
|
|
return 1
|
|
;;
|
|
esac
|
|
(
|
|
exec 9>"$DRXLOCK"
|
|
flock -w 10 9 || exit 1
|
|
if [ "$force_drx" = "force" ]; then
|
|
rm -f "$RUNDIR"/drx.wwan* 2>/dev/null || true
|
|
fi
|
|
found_port=0
|
|
failed_port=0
|
|
for dev in /dev/wwan0at*; do
|
|
[ -c "$dev" ] || continue
|
|
found_port=1
|
|
port_name="${dev#/dev/}"
|
|
dev_id="$(stat -c '%i' "$dev" 2>/dev/null || echo 0)"
|
|
cache_file="$RUNDIR/drx.$port_name"
|
|
want_key="$MODEM_DRX_MODE:$dev_id"
|
|
cur_key=""
|
|
if [ "$force_drx" != "force" ] && [ -r "$cache_file" ]; then
|
|
IFS= read -r cur_key < "$cache_file" 2>/dev/null || cur_key=""
|
|
if [ "$cur_key" = "$want_key" ]; then
|
|
continue
|
|
fi
|
|
fi
|
|
out="$(timeout 6 /usr/libexec/msm-modem-uim-selection at "$dev" "AT\$QCDRX=$MODEM_DRX_MODE" 2>/dev/null || true)"
|
|
case "$out" in
|
|
*OK*)
|
|
printf '%s\n' "$want_key" > "$cache_file" 2>/dev/null || true
|
|
;;
|
|
*)
|
|
rm -f "$cache_file" 2>/dev/null || true
|
|
failed_port=1
|
|
log "AT\$QCDRX=$MODEM_DRX_MODE on $port_name failed: $out"
|
|
;;
|
|
esac
|
|
done
|
|
if [ "$found_port" -eq 0 ]; then
|
|
[ "$force_drx" = "force" ] && log "no modem AT port"
|
|
exit 1
|
|
fi
|
|
[ "$failed_port" -eq 0 ]
|
|
)
|
|
}
|
|
|
|
secondary_aid() {
|
|
$QMI --uim-get-card-status 2>/dev/null | awk '
|
|
/Slot \[2\]/ { s=1; next }
|
|
s && /^Slot \[/ { exit }
|
|
s && /Application ID:/ { g=1; next }
|
|
s && g && NF { gsub(/^[ \t]+/, ""); print; exit }
|
|
'
|
|
}
|
|
|
|
secondary_slot() {
|
|
$QMI --uim-get-card-status 2>/dev/null | awk '
|
|
/Secondary GW: slot/ {
|
|
for (i = 1; i <= NF; i++)
|
|
if ($i == "slot") { gsub(/[^0-9]/, "", $(i+1)); print $(i+1); exit }
|
|
}
|
|
'
|
|
}
|
|
|
|
park() {
|
|
[ -f "$PARKED" ] && return 0
|
|
aid="$(secondary_aid)"
|
|
slot="$(secondary_slot)"
|
|
[ -n "$aid" ] && [ -n "$slot" ] || {
|
|
log "cannot read secondary SIM AID/slot"
|
|
return 1
|
|
}
|
|
if $QMI --uim-change-provisioning-session='activate=no,session-type=secondary-gw-provisioning' >/dev/null 2>&1; then
|
|
printf '%s\n' "$aid" > "$AIDFILE"
|
|
printf '%s\n' "$slot" > "$SLOTFILE"
|
|
: > "$PARKED"
|
|
log "secondary SIM (slot $slot) parked"
|
|
return 0
|
|
fi
|
|
log "failed to deactivate secondary GW session"
|
|
return 1
|
|
}
|
|
|
|
unpark() {
|
|
[ -f "$PARKED" ] || return 0
|
|
aid=""
|
|
slot=""
|
|
[ -r "$AIDFILE" ] && { read -r aid < "$AIDFILE" 2>/dev/null || aid=""; }
|
|
[ -r "$SLOTFILE" ] && { read -r slot < "$SLOTFILE" 2>/dev/null || slot=""; }
|
|
[ -z "$slot" ] && slot=2
|
|
if [ -n "$aid" ] && $QMI --uim-change-provisioning-session="slot=$slot,activate=yes,session-type=secondary-gw-provisioning,aid=$aid" >/dev/null 2>&1; then
|
|
log "secondary SIM (slot $slot) restored"
|
|
else
|
|
log "failed to reactivate secondary GW session"
|
|
fi
|
|
rm -f "$PARKED" "$AIDFILE" "$SLOTFILE" "$RUNDIR"/drx.wwan* 2>/dev/null || true
|
|
}
|
|
|
|
set_spm_bool() {
|
|
path="$1"
|
|
val="$2"
|
|
[ -w "$path" ] || return 0
|
|
case "$val" in
|
|
1|Y|y) want="Y" ;;
|
|
0|N|n) want="N" ;;
|
|
*) return 0 ;;
|
|
esac
|
|
printf '%s\n' "$want" > "$path" 2>/dev/null || true
|
|
}
|
|
|
|
apply_cpu_lpm() {
|
|
set_spm_bool "$SPM_PARAM_DIR/rpm_sleep" "$CPU_RPM_SLEEP"
|
|
set_spm_bool "$SPM_PARAM_DIR/l2_sleep" "$CPU_L2_SLEEP"
|
|
case "$CPU_RPM_SLEEP" in
|
|
1|Y|y) ;;
|
|
*) set_spm_bool "$SPM_PARAM_DIR/screen_off" 0 ;;
|
|
esac
|
|
}
|
|
|
|
mute_wifi_ipv6_ra() {
|
|
[ "$WIFI_SCREEN_OFF_IPV6_MUTE" = "1" ] || return 0
|
|
[ -w "$ACCEPT_RA" ] || return 0
|
|
ip -4 addr show dev wlan0 2>/dev/null | grep -q 'inet ' || return 0
|
|
if [ ! -f "$IPV6_RA_SAVED" ]; then
|
|
cur_ra=""
|
|
IFS= read -r cur_ra < "$ACCEPT_RA" 2>/dev/null || cur_ra=""
|
|
case "$cur_ra" in ''|*[!0-9]*) cur_ra=1 ;; esac
|
|
printf '%s\n' "$cur_ra" > "$IPV6_RA_SAVED" 2>/dev/null || true
|
|
fi
|
|
printf '0\n' > "$ACCEPT_RA" 2>/dev/null || true
|
|
}
|
|
|
|
restore_wifi_ipv6_ra() {
|
|
[ -f "$IPV6_RA_SAVED" ] || return 0
|
|
saved_ra=1
|
|
IFS= read -r saved_ra < "$IPV6_RA_SAVED" 2>/dev/null || saved_ra=1
|
|
case "$saved_ra" in ''|*[!0-9]*) saved_ra=1 ;; esac
|
|
[ -w "$ACCEPT_RA" ] && printf '%s\n' "$saved_ra" > "$ACCEPT_RA" 2>/dev/null || true
|
|
rm -f "$IPV6_RA_SAVED" 2>/dev/null || true
|
|
}
|
|
|
|
park_wifi_rat() {
|
|
[ "$WIFI_STANDBY_RAT" = "gsm" ] || return 0
|
|
[ -f "$RAT_PARKED" ] && return 0
|
|
oper=""
|
|
[ -r /sys/class/net/wlan0/operstate ] && { IFS= read -r oper < /sys/class/net/wlan0/operstate 2>/dev/null || oper=""; }
|
|
[ "$oper" = "up" ] || return 0
|
|
saved_rat="$($QMI --nas-get-system-selection-preference 2>/dev/null | awk -F"'" '
|
|
/Mode preference:/ { gsub(/[[:space:]]*,[[:space:]]*/, "|", $2); print $2; exit }
|
|
')"
|
|
[ -n "$saved_rat" ] || saved_rat="gsm|umts|lte"
|
|
[ "$saved_rat" = "gsm" ] && return 0
|
|
printf '%s\n' "$saved_rat" > "$RAT_SAVED" 2>/dev/null || true
|
|
if $QMI --nas-set-system-selection-preference='gsm' >/dev/null 2>&1; then
|
|
: > "$RAT_PARKED"
|
|
log "Wi-Fi standby RAT parked to gsm (saved: $saved_rat)"
|
|
return 0
|
|
fi
|
|
rm -f "$RAT_SAVED" 2>/dev/null || true
|
|
log "failed to park Wi-Fi standby RAT to gsm"
|
|
return 1
|
|
}
|
|
|
|
unpark_wifi_rat() {
|
|
[ -f "$RAT_PARKED" ] || return 0
|
|
saved_rat=""
|
|
[ -r "$RAT_SAVED" ] && { IFS= read -r saved_rat < "$RAT_SAVED" 2>/dev/null || saved_rat=""; }
|
|
[ -n "$saved_rat" ] || saved_rat="gsm|umts|lte"
|
|
if $QMI --nas-set-system-selection-preference="$saved_rat" >/dev/null 2>&1; then
|
|
log "Wi-Fi standby RAT restored ($saved_rat)"
|
|
else
|
|
log "failed to restore Wi-Fi standby RAT ($saved_rat)"
|
|
fi
|
|
rm -f "$RAT_PARKED" "$RAT_SAVED" 2>/dev/null || true
|
|
}
|
|
|
|
screenoff() {
|
|
apply_cpu_lpm
|
|
mute_wifi_ipv6_ra
|
|
apply_modem_drx cached || true
|
|
if [ "$WIFI_STANDBY_RAT" = "gsm" ]; then
|
|
rtok="$(date +%s)-$$"
|
|
printf '%s\n' "$rtok" > "$RAT_TOKEN"
|
|
(
|
|
sleep 30
|
|
cur=""
|
|
[ -r "$RAT_TOKEN" ] && { read -r cur < "$RAT_TOKEN" 2>/dev/null || cur=""; }
|
|
[ "$cur" = "$rtok" ] || exit 0
|
|
"$0" _park_rat >/dev/null 2>&1
|
|
) &
|
|
fi
|
|
[ "$DSDS_SECONDARY_MODE" = "eco" ] || return 0
|
|
token="$(date +%s)-$$"
|
|
printf '%s\n' "$token" > "$TOKEN"
|
|
(
|
|
sleep "$DSDS_PARK_DELAY"
|
|
cur=""
|
|
[ -r "$TOKEN" ] && { read -r cur < "$TOKEN" 2>/dev/null || cur=""; }
|
|
[ "$cur" = "$token" ] || exit 0
|
|
"$0" _park >/dev/null 2>&1
|
|
) &
|
|
}
|
|
|
|
screenon() {
|
|
rm -f "$TOKEN" "$RAT_TOKEN" 2>/dev/null || true
|
|
set_spm_bool "$SPM_PARAM_DIR/screen_off" 0
|
|
apply_cpu_lpm
|
|
restore_wifi_ipv6_ra
|
|
unpark_wifi_rat
|
|
unpark
|
|
apply_modem_drx cached || true
|
|
}
|
|
|
|
apply_now() {
|
|
rm -f "$BOOTTOKEN" "$READYSTAMP" "$RUNDIR"/drx.wwan* 2>/dev/null || true
|
|
write_modprobe || true
|
|
apply_cpu_lpm
|
|
[ "$WIFI_SCREEN_OFF_IPV6_MUTE" = "1" ] || restore_wifi_ipv6_ra
|
|
[ "$WIFI_STANDBY_RAT" = "gsm" ] || unpark_wifi_rat
|
|
apply_modem_drx force || true
|
|
}
|
|
|
|
modem_ready() {
|
|
now_ts=0
|
|
if [ -r /proc/uptime ]; then
|
|
IFS='. ' read -r now_ts _ < /proc/uptime 2>/dev/null || now_ts=0
|
|
fi
|
|
case "$now_ts" in ''|*[!0-9]*) now_ts=0 ;; esac
|
|
last_ts=0
|
|
[ -r "$READYSTAMP" ] && { read -r last_ts < "$READYSTAMP" 2>/dev/null || last_ts=0; }
|
|
case "$last_ts" in ''|*[!0-9]*) last_ts=0 ;; esac
|
|
if [ "$last_ts" -gt 0 ] && [ $((now_ts - last_ts)) -ge 0 ] && [ $((now_ts - last_ts)) -lt 5 ]; then
|
|
return 0
|
|
fi
|
|
printf '%s\n' "$now_ts" > "$READYSTAMP" 2>/dev/null || true
|
|
if apply_modem_drx force >/dev/null 2>&1; then
|
|
rm -f "$BOOTTOKEN" 2>/dev/null || true
|
|
fi
|
|
}
|
|
|
|
boot() {
|
|
rm -f "$TOKEN" "$RAT_TOKEN" "$PARKED" "$AIDFILE" "$SLOTFILE" "$RAT_PARKED" "$RAT_SAVED" "$IPV6_RA_SAVED" "$READYSTAMP" "$RUNDIR"/drx.wwan* 2>/dev/null || true
|
|
write_modprobe || true
|
|
apply_cpu_lpm
|
|
if [ "$MODEM_DRX_MODE" != "0" ]; then
|
|
btok="$$-$(cat /proc/uptime 2>/dev/null | awk '{print $1}' || echo 0)"
|
|
printf '%s\n' "$btok" > "$BOOTTOKEN"
|
|
(
|
|
# Let ModemManager finish its startup AT port probe (~5 s) so we do not
|
|
# compete with mm-port-probe on wwan_core's shared RX queue, then retry
|
|
# until all enumerated AT channels accept AT$QCDRX.
|
|
sleep 5
|
|
i=0
|
|
while [ "$i" -lt 12 ]; do
|
|
cur=""
|
|
[ -r "$BOOTTOKEN" ] && { read -r cur < "$BOOTTOKEN" 2>/dev/null || cur=""; }
|
|
[ "$cur" = "$btok" ] || exit 0
|
|
if [ -c /dev/wwan0at0 ] && { [ -c /dev/wwan0at1 ] || [ "$i" -ge 2 ]; }; then
|
|
if apply_modem_drx force >/dev/null 2>&1; then
|
|
exit 0
|
|
fi
|
|
fi
|
|
sleep 3
|
|
i=$((i + 1))
|
|
done
|
|
) >/dev/null 2>&1 &
|
|
fi
|
|
}
|
|
|
|
debugfs_summary() {
|
|
dir="$1"
|
|
[ -d "$dir" ] || { printf 'n/a'; return 0; }
|
|
out=""
|
|
for f in "$dir"/*; do
|
|
[ -r "$f" ] || continue
|
|
val="$(tr '\n\t' ' ' < "$f" 2>/dev/null | awk '{$1=$1; print}')"
|
|
[ -n "$val" ] && out="${out:+$out; }${f##*/}: $val"
|
|
done
|
|
printf '%s' "${out:-n/a}"
|
|
}
|
|
|
|
status() {
|
|
printf 'WIFI_LISTEN_INTERVAL=%s\n' "$WIFI_LISTEN_INTERVAL"
|
|
printf 'MODEM_DRX_MODE=%s\n' "$MODEM_DRX_MODE"
|
|
printf 'DSDS_SECONDARY_MODE=%s\n' "$DSDS_SECONDARY_MODE"
|
|
printf 'DSDS_PARK_DELAY=%s\n' "$DSDS_PARK_DELAY"
|
|
printf 'CPU_RPM_SLEEP=%s\n' "$CPU_RPM_SLEEP"
|
|
printf 'CPU_L2_SLEEP=%s\n' "$CPU_L2_SLEEP"
|
|
printf 'WIFI_SCREEN_OFF_IPV6_MUTE=%s\n' "$WIFI_SCREEN_OFF_IPV6_MUTE"
|
|
printf 'WIFI_STANDBY_RAT=%s\n' "$WIFI_STANDBY_RAT"
|
|
if [ -f "$PARKED" ]; then
|
|
printf 'secondary_parked=yes\n'
|
|
else
|
|
printf 'secondary_parked=no\n'
|
|
fi
|
|
if [ -f "$RAT_PARKED" ]; then
|
|
printf 'rat_parked=yes\n'
|
|
else
|
|
printf 'rat_parked=no\n'
|
|
fi
|
|
if [ -r "$MODPROBE" ]; then
|
|
printf 'modprobe_conf=%s (%s)\n' "$MODPROBE" "$(tail -n 1 "$MODPROBE")"
|
|
else
|
|
printf 'modprobe_conf=absent\n'
|
|
fi
|
|
printf 'wcn36xx_param=%s\n' "$(cat /sys/module/wcn36xx/parameters/listen_interval 2>/dev/null || echo n/a)"
|
|
printf 'wcn36xx_screen_off_offload=%s\n' "$(cat /sys/module/wcn36xx/parameters/screen_off_offload 2>/dev/null || echo n/a)"
|
|
printf 'cpuidle_rpm_sleep=%s\n' "$(cat "$SPM_PARAM_DIR/rpm_sleep" 2>/dev/null || echo n/a)"
|
|
printf 'cpuidle_l2_sleep=%s\n' "$(cat "$SPM_PARAM_DIR/l2_sleep" 2>/dev/null || echo n/a)"
|
|
printf 'cpuidle_screen_off=%s\n' "$(cat "$SPM_PARAM_DIR/screen_off" 2>/dev/null || echo n/a)"
|
|
printf 'cpuidle_rpm_sleep_count=%s\n' "$(cat "$SPM_PARAM_DIR/rpm_sleep_count" 2>/dev/null || echo n/a)"
|
|
printf 'cpuidle_l2_off_count=%s\n' "$(cat "$SPM_PARAM_DIR/l2_off_count" 2>/dev/null || echo n/a)"
|
|
printf 'wlan0_accept_ra=%s\n' "$(cat "$ACCEPT_RA" 2>/dev/null || echo n/a)"
|
|
printf 'qcom_stats=%s\n' "$(debugfs_summary /sys/kernel/debug/qcom_stats)"
|
|
printf 'qcom_rpm_master_stats=%s\n' "$(debugfs_summary /sys/kernel/debug/qcom_rpm_master_stats)"
|
|
drx_summary="$(timeout 8 /usr/libexec/msm-modem-uim-selection at all 'AT$QCDRX?' 2>/dev/null | awk '
|
|
/^\[wwan0at/ { gsub(/[\[\]]/, "", $0); p=$0; next }
|
|
/\$QCDRX:/ { gsub(/^[[:space:]]+|[[:space:]]+$/, "", $0); if (p != "") out = (out ? out " " : "") p ":" $0 }
|
|
END { print out }
|
|
')"
|
|
printf 'modem_drx_now=%s\n' "${drx_summary:-n/a}"
|
|
}
|
|
|
|
case "${1:-}" in
|
|
boot) boot ;;
|
|
apply) apply_now ;;
|
|
modem-ready) modem_ready ;;
|
|
screenoff) screenoff ;;
|
|
screenon) screenon ;;
|
|
_park) park ;;
|
|
_park_rat) park_wifi_rat ;;
|
|
unpark) restore_wifi_ipv6_ra; unpark_wifi_rat; unpark ;;
|
|
status) status ;;
|
|
*)
|
|
printf 'Usage: %s [boot|apply|modem-ready|screenoff|screenon|unpark|status]\n' "${0##*/}" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
exit 0
|