Files
bananarchy/overlay/rootfs/usr/bin/sxmo_soundmonitor.sh
T
Bantam ad3461babf Measurement-corrected battery optimization pass (DSDS + Wi-Fi)
Re-analyzed the running nokia-argon (a1105, 43 h uptime, DSDS + Wi-Fi on) and
implemented the corrected kernel/userspace optimization list. No sleep state
existed at all (/sys/power/state was 0 bytes) and cpuinfo_transition_latency
was UINT_MAX, while the CPU cores were already ~98% power-collapsed.

Kernel (K1-K14)
- Enable CONFIG_SUSPEND / SUSPEND_FREEZER / PM_WAKELOCKS / PM_AUTOSLEEP and
  build the zImage from the tuned config; ship it as overlay/rootfs/boot/vmlinuz
  plus config and System.map. Add wakeup-source to the WCNSS pronto remoteproc.
- Add clock-latency-ns to cpu-opp-table in all 5 device trees (fixes
  CPUFREQ_ETERNAL at its source instead of a userspace rate_limit_us override).
- New patch 0006: wcn36xx keep-alive 30s->120s, listen_interval=3, VM-BMS
  sample interval 10s->30s, power_supply_changed() only on real capacity
  changes, GPU devfreq polling_ms 50->100.
- Retune the config for idle (HZ=100, PREEMPT_VOLUNTARY, TEO cpuidle governor,
  no ftrace/perf/kprobes/BPF-JIT-always-on/debug options, no serial console,
  DRM_FBDEV_OVERALLOC=0, lz4 zram, ENERGY_MODEL) and drop earlycon /
  console=ttyMSM0 from every kernel cmdline.
- net.ipv6.conf.default.disable_ipv6=1 to stop ND/MLD multicast on new
  interfaces; keep NETFILTER/IPV6/CGROUPS and FRAMEBUFFER_CONSOLE for
  VPN/tethering, elogind and plymouth.

Userspace (U1-U14)
- Idle blanking without the passcode locker (bananarchy-idle-blank.sh +
  idle_locker resume hook, SXMO_UNLOCK_IDLE_TIME=60, sxmo.noidle opts out).
- Guarded deep standby (bananarchy-suspend.sh / -deep-standby.sh /
  sxmo_autosuspend.sh / sxmo_suspend.sh), AllowSuspend=yes, doas rule, no
  infinite wakelock, no sxmo.nosuspend. Shipped disabled via
  /etc/bananarchy-no-deep-standby until the new kernel is boot-tested; freeze
  is preferred, mem is opt-in.
- statusbar_periodics 60s->300s, no mmcli/nmcli/rfkill polls, xsetroot only on
  change; battery udev rule filtered and no 2 s recheck fork.
- On-demand QMI DPM port, longer DSDS/modemmonitor backoffs, chrony long polls,
  NM wifi.scan-interval=600, bluetooth AutoEnable=false, tmpfs on /tmp,
  zero-log superd, GPU devfreq governor on screen-off, longer SIP/Tox timers.
- Fix the cosmetic wpa_supplicant yesno typo; withdraw the disproven duplicate
  wpa_supplicant and soundmonitor 5 s loop items.

Rebuilt images/bananarchy-nokia-argon.img with --mkinitfs: boot.img contains
the new zImage + DTB byte-for-byte and no serial-console cmdline. Deployed the
userspace overlay to the connected phone and verified shell/Python syntax, the
idle-blank round trip, the statusbar hook and the deep-standby guard.
check-rebuild.sh and sync-prebuilt-overlay.sh --check both pass.

Docs: BATTERY-OPTIMIZATION-ANALYSIS.md (measurement-corrected, with
implementation status), CHANGELOG.md, MANUAL.md, README.md, AGENTS.md.
2026-11-07 17:03:12 +02:00

186 lines
5.9 KiB
Bash
Executable File

#!/bin/sh
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2023 Sxmo Contributors
# shellcheck source=scripts/core/sxmo_common.sh
. "$(dirname "$0")/sxmo_common.sh"
find_jack_event_dev() {
for sysname in /sys/class/input/event*/device/name; do
[ -r "$sysname" ] || continue
read -r dname < "$sysname" 2>/dev/null || continue
case "$dname" in
*[Jj]ack*|*[Hh]eadset*)
ev="${sysname%/device/name}"
ev="/dev/input/${ev##*/}"
if [ -c "$ev" ]; then
printf "%s\n" "$ev"
return 0
fi
;;
esac
done
return 1
}
is_hp_plugged() {
jdev="$1"
if [ -n "$jdev" ] && command -v evtest >/dev/null 2>&1; then
evtest --query "$jdev" EV_SW SW_HEADPHONE_INSERT >/dev/null 2>&1
rc=$?
[ "$rc" -eq 10 ] && return 0
fi
if command -v amixer >/dev/null 2>&1; then
amixer -c 0 cget "name='Headphone Jack'" 2>/dev/null | grep -q ": values=on" && return 0
fi
return 1
}
is_mic_plugged() {
jdev="$1"
if [ -n "$jdev" ] && command -v evtest >/dev/null 2>&1; then
evtest --query "$jdev" EV_SW SW_MICROPHONE_INSERT >/dev/null 2>&1
rc=$?
[ "$rc" -eq 10 ] && return 0
fi
if command -v amixer >/dev/null 2>&1; then
amixer -c 0 cget "name='Mic Jack'" 2>/dev/null | grep -q ": values=on" && return 0
fi
return 1
}
handle_jack_insert() {
jdev="$1"
cur_out="$(sxmo_audio.sh device get 2>/dev/null || printf "Speaker")"
if [ "$cur_out" != "Headphones" ]; then
printf "%s\n" "$cur_out" > /tmp/sxmo_prev_out_device 2>/dev/null || true
fi
printf "1\n" > /tmp/sxmo_jack_plugged 2>/dev/null || true
if is_mic_plugged "$jdev"; then
printf "Headset\n" > /tmp/sxmo_audio_in_device 2>/dev/null || true
sxmo_audio.sh device setinput Headset >/dev/null 2>&1 || true
else
printf "Mic1\n" > /tmp/sxmo_audio_in_device 2>/dev/null || true
fi
sxmo_audio.sh device set Headphones >/dev/null 2>&1 || true
sxmo_log "Wired headphones plugged in -> routed audio to Headphones"
}
handle_jack_remove() {
printf "0\n" > /tmp/sxmo_jack_plugged 2>/dev/null || true
printf "Mic1\n" > /tmp/sxmo_audio_in_device 2>/dev/null || true
sxmo_audio.sh device setinput Mic1 >/dev/null 2>&1 || true
target_out="Speaker"
if [ -r /tmp/sxmo_in_call ]; then
read -r incall < /tmp/sxmo_in_call 2>/dev/null || incall=0
if [ "$incall" = "1" ]; then
target_out="Earpiece"
fi
fi
sxmo_audio.sh device set "$target_out" >/dev/null 2>&1 || true
sxmo_log "Wired headphones unplugged -> routed audio to $target_out"
}
monitor_jack_events() {
while : ; do
jdev="$(find_jack_event_dev || true)"
if [ -z "$jdev" ] || ! command -v evtest >/dev/null 2>&1; then
sleep 5
continue
fi
if is_hp_plugged "$jdev"; then
handle_jack_insert "$jdev"
else
printf "0\n" > /tmp/sxmo_jack_plugged 2>/dev/null || true
if [ -n "$(pactl list short sinks 2>/dev/null | awk '$2 ~ /^bluez_output\./ { print $2; exit }')" ]; then
sxmo_audio.sh device set Bluetooth >/dev/null 2>&1 || true
else
sxmo_audio.sh device apply >/dev/null 2>&1 || true
fi
fi
evtest "$jdev" 2>/dev/null | while read -r line; do
case "$line" in
*SW_HEADPHONE_INSERT*value\ 1*)
sleep 0.1
handle_jack_insert "$jdev"
;;
*SW_HEADPHONE_INSERT*value\ 0*)
handle_jack_remove
;;
*SW_MICROPHONE_INSERT*value\ 1*)
sxmo_audio.sh device setinput Headset >/dev/null 2>&1 || true
;;
*SW_MICROPHONE_INSERT*value\ 0*)
sxmo_audio.sh device setinput Mic1 >/dev/null 2>&1 || true
;;
esac
done
sleep 2
done
}
handle_change() {
prev_bt_sink="$(pactl list short sinks 2>/dev/null | awk '$2 ~ /^bluez_output\./ { print $2; exit }')"
if [ -n "$prev_bt_sink" ]; then
cur_out="$(cat /tmp/sxmo_audio_out_device 2>/dev/null || true)"
if [ "$cur_out" != "Bluetooth" ]; then
sxmo_audio.sh device set Bluetooth >/dev/null 2>&1 || true
else
sxmo_audio.sh device apply >/dev/null 2>&1 || true
fi
fi
pactl subscribe 2>/dev/null | while read -r line; do
case "$line" in
*"Event 'new' on sink"*|*"Event 'new' on card"*|*"Event 'change' on card"*)
bt_sink="$(pactl list short sinks 2>/dev/null | awk '$2 ~ /^bluez_output\./ { print $2; exit }')"
if [ -n "$bt_sink" ] && [ "$bt_sink" != "$prev_bt_sink" ]; then
prev_bt_sink="$bt_sink"
sxmo_audio.sh device set Bluetooth >/dev/null 2>&1 || true
sxmo_log "Bluetooth sink $bt_sink detected -> routed audio to Bluetooth"
fi
sxmo_hook_statusbar.sh volume >/dev/null 2>&1 || true
;;
*"Event 'remove' on sink"*|*"Event 'remove' on card"*)
bt_sink="$(pactl list short sinks 2>/dev/null | awk '$2 ~ /^bluez_output\./ { print $2; exit }')"
if [ -z "$bt_sink" ] && [ -n "$prev_bt_sink" ]; then
prev_bt_sink=""
cur_out="$(cat /tmp/sxmo_audio_out_device 2>/dev/null || true)"
if [ "$cur_out" = "Bluetooth" ]; then
if [ "$(cat /tmp/sxmo_jack_plugged 2>/dev/null || true)" = "1" ]; then
sxmo_audio.sh device set Headphones >/dev/null 2>&1 || true
elif [ -r /tmp/sxmo_in_call ]; then
sxmo_audio.sh device set Earpiece >/dev/null 2>&1 || true
else
sxmo_audio.sh device set Speaker >/dev/null 2>&1 || true
fi
sxmo_log "Bluetooth sink removed -> restored local audio route"
fi
fi
sxmo_hook_statusbar.sh volume >/dev/null 2>&1 || true
;;
*"Event 'change' on sink"*|*"Event 'change' on source"*)
if [ ! -d /tmp/sxmo_volset.lock ]; then
sxmo_hook_statusbar.sh volume >/dev/null 2>&1 || true
fi
;;
esac
done
}
cleanup() {
kill 0 2>/dev/null || true
}
trap cleanup EXIT INT TERM
monitor_jack_events &
while : ; do
handle_change || true
# U10: pactl subscribe is event-driven; only back off after a failure.
sleep 10
done