modem, callscreen, ring: fix DSDS incoming ring hangup/volume and add Primary/Secondary GW SIM swap UI

This commit is contained in:
Luxferre committed 2026-10-27 13:02:14 +02:00
1 parent 9a079e1068
commit 7927bacb67
18 files changed
+280 -84

No files matched your search

+12 -1
View File
@@ -115,6 +115,10 @@ checkforfinishedcalls() {
if ! sxmo_modemcall.sh list_active_calls | grep -q .; then
# Cleanup
sxmo_jobs.sh stop ringing
pkill -TERM -f sxmo_hook_ring.sh 2>/dev/null || true
pkill -TERM -f "pw-play.*ring" 2>/dev/null || true
pkill -TERM -f "mpv.*ring" 2>/dev/null || true
pkill -TERM -x sxmo_vibrate 2>/dev/null || true
rm -f "$XDG_RUNTIME_DIR/sxmo_calls/"* 2>/dev/null || true
if [ "$STATE" != muted ] && [ ! -f "$XDG_CONFIG_HOME/sxmo/.novibrate" ]; then
sxmo_vibrate 600 &
@@ -133,6 +137,13 @@ checkforfinishedcalls() {
sxmo_hook_after_call.sh
else
# Or refresh the menu
if ! sxmo_modemcall.sh list_active_calls | grep -q "ringing-in"; then
sxmo_jobs.sh stop ringing
pkill -TERM -f sxmo_hook_ring.sh 2>/dev/null || true
pkill -TERM -f "pw-play.*ring" 2>/dev/null || true
pkill -TERM -f "mpv.*ring" 2>/dev/null || true
pkill -TERM -x sxmo_vibrate 2>/dev/null || true
fi
sxmo_jobs.sh start incall_menu sxmo_modemcall.sh incall_menu
fi
done
@@ -165,7 +176,7 @@ checkforincomingcalls() {
else
stderr "Invoking ring hook (async)"
CONTACTNAME=$(sxmo_contacts.sh --name-or-number "$INCOMINGNUMBER")
sxmo_jobs.sh start ringing sxmo_hook_ring.sh "$CONTACTNAME"
sxmo_jobs.sh start --group ringing sxmo_hook_ring.sh "$CONTACTNAME"
mkdir -p "$SXMO_LOGDIR"
printf %b "$TIME\tcall_ring\t$INCOMINGNUMBER\n" >> "$SXMO_LOGDIR/modemlog.tsv"
+4 -2
View File
@@ -93,7 +93,8 @@ pickup() {
return 1
fi
if ! mmcli -m any -o "$CALLID" --accept; then
if ! mmcli -m any -o "$CALLID" --accept 2>/dev/null && \
! doas -n /usr/libexec/msm-modem-uim-selection call-accept "$CALLID" >/dev/null 2>&1; then
sxmo_notify_user.sh --urgency=critical "We failed to accept the call"
return 1
fi
@@ -152,7 +153,8 @@ hangup() {
sxmo_hook_discard.sh
fi
if ! mmcli -m any -o "$CALLID" --hangup; then
if ! mmcli -m any -o "$CALLID" --hangup 2>/dev/null && \
! doas -n /usr/libexec/msm-modem-uim-selection call-hangup "$CALLID" >/dev/null 2>&1; then
# we ignore already closed calls
if list_active_calls | grep -q "/$CALLID "; then
sxmo_notify_user.sh --urgency=critical "We failed to hangup the call"
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -549,13 +549,14 @@ provision_slot() {
fi
if [ "$need_prim" = "1" ]; then
if [ "${SECONDARY_GW_SLOT:-0}" = "$chosen_slot" ]; then
if [ "${SECONDARY_GW_SLOT:-0}" != "0" ]; then
$QMICLI_MODEM --uim-change-provisioning-session='activate=no,session-type=secondary-gw-provisioning' >/dev/null 2>&1 || true
SECONDARY_GW_SLOT=0
fi
if [ "$PRIMARY_GW_SLOT" != "0" ]; then
$QMICLI_MODEM --uim-change-provisioning-session='activate=no,session-type=primary-gw-provisioning' >/dev/null 2>&1 || true
fi
sleep 0.2
if [ -n "$chosen_aid" ]; then
echo "Selecting AID $chosen_aid on slot $chosen_slot (primary-gw-provisioning)"
if ! $QMICLI_MODEM --uim-change-provisioning-session="slot=$chosen_slot,activate=yes,session-type=primary-gw-provisioning,aid=$chosen_aid" >/dev/null 2>&1; then
@@ -565,6 +566,7 @@ provision_slot() {
echo "Selecting slot $chosen_slot (primary-gw-provisioning)"
$QMICLI_MODEM --uim-change-provisioning-session="slot=$chosen_slot,activate=yes,session-type=primary-gw-provisioning" >/dev/null 2>&1 || true
fi
sleep 0.2
else
echo "Slot $chosen_slot already bound to primary-gw-provisioning ($chosen_app_state)."
fi
@@ -675,7 +677,7 @@ enable_and_register_modem() {
i=$((i + 1))
done
if [ -z "$mm_state" ] || [ "$mm_state" = "failed" ] || { [ "$force_unlock" = "1" ] && [ "$mm_state" = "locked" ]; }; then
if [ -z "$mm_state" ] || [ "$mm_state" = "failed" ] || [ "$force_unlock" = "2" ] || { [ "$force_unlock" = "1" ] && [ "$mm_state" = "locked" ]; }; then
restart_modemmanager_clean
i=0
mm_state=""
@@ -929,7 +931,12 @@ PY
fi
SIM_WAIT_TIME=2
provision_slot "$target" 4
spawn_enable_and_register "$target" 0
pkill -f "msm-modem-uim-selection dsds-daemon" 2>/dev/null || true
if [ "${3:-}" = "--swap-gw" ]; then
spawn_enable_and_register "$target" 2
else
spawn_enable_and_register "$target" 0
fi
exit 0
;;
@@ -1887,7 +1894,7 @@ STATE_MAP = {
7: "waiting",
8: "terminated",
9: "terminated",
10: "dialing",
10: "setup",
}
if sub_cmd == "call-dial":
@@ -2306,22 +2313,32 @@ STATE_MAP = {
7: "waiting",
8: "terminated",
9: "terminated",
10: "dialing",
10: "setup",
}
active_calls = {}
audio_opened = False
def stop_ringing_user():
run_user_cmd(
"rm -f /tmp/sxmo_call_ringing; "
"sxmo_jobs.sh stop ringing >/dev/null 2>&1; "
"pkill -TERM -f sxmo_hook_ring.sh 2>/dev/null; "
"pkill -TERM -f 'pw-play.*ring' 2>/dev/null; "
"pkill -TERM -f 'mpv.*ring' 2>/dev/null; "
"pkill -TERM -x sxmo_vibrate 2>/dev/null || true"
)
def set_q6voiced_audio(enable):
global audio_opened
if enable and not audio_opened:
audio_opened = True
subprocess.run(["dbus-send", "--system", "--type=signal", "/", "org.ofono.VoiceCallManager.CallAdded"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
run_user_cmd("sxmo_modemaudio.sh setup")
run_user_cmd("sxmo_modemaudio.sh setup_audio")
elif not enable and audio_opened:
audio_opened = False
subprocess.run(["dbus-send", "--system", "--type=signal", "/", "org.ofono.VoiceCallManager.CallRemoved"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
run_user_cmd("sxmo_modemaudio.sh teardown")
run_user_cmd("sxmo_modemaudio.sh reset_audio")
def has_sub1_call_files():
try:
@@ -2329,20 +2346,49 @@ def has_sub1_call_files():
except Exception:
return False
def has_mm_call_files():
try:
for fn in os.listdir(CALLS_DIR):
if fn and fn[0].isdigit():
return True
except Exception:
pass
return False
def sync_sub1_calls(calls, sim_slot):
global active_calls
now_str = datetime.datetime.now().astimezone().isoformat(timespec="seconds")
for old_cid, old_info in list(active_calls.items()):
if old_cid not in calls:
calls[old_cid] = {
"id": old_cid,
"state": 9,
"dir": old_info.get("dir", 1),
"num": old_info.get("num", ""),
}
if old_info.get("state") == "terminated":
del active_calls[old_cid]
else:
calls[old_cid] = {
"id": old_cid,
"state": 9,
"dir": old_info.get("dir", 1),
"num": old_info.get("num", ""),
}
for cid, c in calls.items():
for cid, c in list(calls.items()):
st = STATE_MAP.get(c["state"], "unknown")
if st == "setup":
if c["dir"] == 1 and has_sub1_call_files():
st = "dialing"
else:
continue
# Skip calls that are already managed by ModemManager / sxmo_modem.sh on Primary GW
if cid not in active_calls:
if st == "terminated":
continue
if c["dir"] == 1 and not has_sub1_call_files():
continue
if c["dir"] == 2:
time.sleep(0.35)
if has_mm_call_files():
continue
num = c["num"] or active_calls.get(cid, {}).get("num") or "Unknown"
if num and num != "Unknown" and not num.startswith("+") and len(num) >= 10:
num = "+" + num
@@ -2352,7 +2398,7 @@ def sync_sub1_calls(calls, sim_slot):
# Update /run/user/10000/sxmo_calls/sub1_<id>.<state>
for fn in os.listdir(CALLS_DIR):
if fn.startswith(f"{call_key}."):
if fn.startswith(f"{call_key}.") and not fn.endswith(".initiatedcall") and not fn.endswith(".pickedupcall") and not fn.endswith(".mutedring"):
try:
os.remove(os.path.join(CALLS_DIR, fn))
except Exception:
@@ -2362,16 +2408,26 @@ def sync_sub1_calls(calls, sim_slot):
open(os.path.join(CALLS_DIR, f"{call_key}.{st}"), "w").close()
except Exception:
pass
else:
for fn in os.listdir(CALLS_DIR):
if fn.startswith(f"{call_key}."):
try:
os.remove(os.path.join(CALLS_DIR, fn))
except Exception:
pass
if st == prev:
continue
active_calls[cid] = {"state": st, "num": num, "dir": c["dir"]}
if st == "ringing-in":
if has_mm_call_files():
del active_calls[cid]
continue
with open(os.path.join(LOG_DIR, "modemlog.tsv"), "a", encoding="utf-8") as f:
f.write(f"{now_str}\tcall_ring\t{num}\t[SIM {sim_slot}]\n")
send_fifo("/tmp/dwm_plugin_callscreen.fifo", f"INCOMING {call_key} {num} SIM{sim_slot}")
run_user_cmd(f"sxmo_hook_ring.sh '{num}'")
run_user_cmd(f"sxmo_jobs.sh start --group ringing sxmo_hook_ring.sh '{num}'")
elif st in ("dialing", "ringing-out"):
set_q6voiced_audio(True)
if prev not in ("dialing", "ringing-out"):
@@ -2379,18 +2435,17 @@ def sync_sub1_calls(calls, sim_slot):
f.write(f"{now_str}\tcall_dial\t{num}\t[SIM {sim_slot}]\n")
send_fifo("/tmp/dwm_plugin_callscreen.fifo", f"OUTGOING {call_key} {num} SIM{sim_slot}")
elif st == "active":
run_user_cmd("pkill -f sxmo_ring.sh || true; pkill -f mpv || true")
stop_ringing_user()
set_q6voiced_audio(True)
with open(os.path.join(LOG_DIR, "modemlog.tsv"), "a", encoding="utf-8") as f:
f.write(f"{now_str}\tcall_start\t{num}\t[SIM {sim_slot}]\n")
send_fifo("/tmp/dwm_plugin_callscreen.fifo", f"ACTIVE {call_key} {num} SIM{sim_slot}")
elif st == "terminated":
run_user_cmd("pkill -f sxmo_ring.sh || true")
stop_ringing_user()
evt = "call_missed" if prev == "ringing-in" else "call_hangup"
with open(os.path.join(LOG_DIR, "modemlog.tsv"), "a", encoding="utf-8") as f:
f.write(f"{now_str}\t{evt}\t{num}\t[SIM {sim_slot}]\n")
send_fifo("/tmp/dwm_plugin_callscreen.fifo", "ENDED CALL ENDED")
del active_calls[cid]
has_live = any(v["state"] in ("dialing", "ringing-out", "active", "held", "ringing-in", "waiting") for v in active_calls.values())
if not has_live:
@@ -2403,6 +2458,7 @@ def sync_sub1_calls(calls, sim_slot):
except Exception:
pass
if removed_stale:
stop_ringing_user()
send_fifo("/tmp/dwm_plugin_callscreen.fifo", "ENDED CALL ENDED")
if audio_opened:
set_q6voiced_audio(False)
@@ -8,6 +8,11 @@
# up the call).
# kill existing ring playback
rm -f /tmp/sxmo_call_ringing 2>/dev/null || true
sxmo_jobs.sh stop ringing
pkill -TERM -f sxmo_hook_ring.sh 2>/dev/null || true
pkill -TERM -f "pw-play.*ring" 2>/dev/null || true
pkill -TERM -f "mpv.*ring" 2>/dev/null || true
pkill -TERM -x sxmo_vibrate 2>/dev/null || true
sxmo_playerctl.sh resume_all
@@ -7,6 +7,11 @@
# incoming call, i.e., ignore the call ringing in.
# kill existing ring playback
rm -f /tmp/sxmo_call_ringing 2>/dev/null || true
sxmo_jobs.sh stop ringing
pkill -TERM -f sxmo_hook_ring.sh 2>/dev/null || true
pkill -TERM -f "pw-play.*ring" 2>/dev/null || true
pkill -TERM -f "mpv.*ring" 2>/dev/null || true
pkill -TERM -x sxmo_vibrate 2>/dev/null || true
sxmo_playerctl.sh resume_all
@@ -6,7 +6,12 @@
# This script is executed (asynchronously) when you pick up an incoming call
# kill existing ring playback
rm -f /tmp/sxmo_call_ringing 2>/dev/null || true
sxmo_jobs.sh stop ringing
pkill -TERM -f sxmo_hook_ring.sh 2>/dev/null || true
pkill -TERM -f "pw-play.*ring" 2>/dev/null || true
pkill -TERM -f "mpv.*ring" 2>/dev/null || true
pkill -TERM -x sxmo_vibrate 2>/dev/null || true
# Pause all player automatically
sxmo_playerctl.sh pause_all
@@ -83,6 +83,12 @@ if [ "$(cat /tmp/sxmo_active_call 2>/dev/null)" = "2" ]; then
exit 0
fi
# Prevent duplicate concurrent ringer instances
exec 9>"$XDG_RUNTIME_DIR/sxmo_ring.lock"
if ! flock -n 9; then
exit 0
fi
case "${SXMO_RINGVOL:-100}" in
''|*[!0-9]*) SXMO_RINGVOL=100 ;;
esac
@@ -93,10 +99,13 @@ if [ -r "$XDG_CONFIG_HOME/sxmo/speaker_vol" ]; then
read -r SAVED_SPK_VOL < "$XDG_CONFIG_HOME/sxmo/speaker_vol" 2>/dev/null || SAVED_SPK_VOL=85
fi
case "$SAVED_SPK_VOL" in ''|*[!0-9]*) SAVED_SPK_VOL=85 ;; esac
SAVED_RX3=$(( 60 + SAVED_SPK_VOL * 32 / 100 ))
SAVED_RX3=$(( 60 + SAVED_SPK_VOL * 24 / 100 ))
RING_PID=""
VIB_PID=""
WAIT_PID=""
SAW_RING_STATE=0
TICKS=0
is_call_picked_up() {
[ "$(cat /tmp/sxmo_active_call 2>/dev/null)" = "2" ] && return 0
@@ -106,13 +115,42 @@ is_call_picked_up() {
return 1
}
has_ringing_call_files() {
[ -e /tmp/sxmo_call_ringing ] && return 0
for f in "$XDG_RUNTIME_DIR"/sxmo_calls/*.monitoredcall "$XDG_RUNTIME_DIR"/sxmo_calls/*.ringing-in; do
[ -e "$f" ] && return 0
done
return 1
}
should_stop_ringing() {
is_call_picked_up && return 0
for f in "$XDG_RUNTIME_DIR"/sxmo_calls/*.mutedring \
"$XDG_RUNTIME_DIR"/sxmo_calls/*.discardedcall \
"$XDG_RUNTIME_DIR"/sxmo_calls/*.hangedupcall; do
[ -e "$f" ] && return 0
done
if [ "$SAW_RING_STATE" -eq 1 ] || [ "$TICKS" -ge 10 ]; then
if ! has_ringing_call_files; then
return 0
fi
fi
return 1
}
finish() {
trap - INT TERM EXIT
[ -n "$WAIT_PID" ] && kill -TERM "$WAIT_PID" 2>/dev/null || true
[ -n "$RING_PID" ] && pkill -TERM -P "$RING_PID" 2>/dev/null || true
[ -n "$VIB_PID" ] && pkill -TERM -P "$VIB_PID" 2>/dev/null || true
[ -n "$RING_PID" ] && kill -TERM "$RING_PID" 2>/dev/null || true
[ -n "$VIB_PID" ] && kill -TERM "$VIB_PID" 2>/dev/null || true
pkill -TERM -P "$$" 2>/dev/null || true
if [ -n "${SXMO_RINGTONE:-}" ]; then
pkill -TERM -f "pw-play.*$SXMO_RINGTONE" 2>/dev/null || true
pkill -TERM -f "mpv.*$SXMO_RINGTONE" 2>/dev/null || true
fi
pkill -TERM -x sxmo_vibrate 2>/dev/null || true
if ! is_call_picked_up; then
amixer -c 0 cset "name='RX3 Digital Volume'" "$SAVED_RX3" >/dev/null 2>&1 || true
wpctl set-volume @DEFAULT_AUDIO_SINK@ "${SAVED_SPK_VOL}%" >/dev/null 2>&1 || true
@@ -132,7 +170,7 @@ ring() {
if [ "${SXMO_RINGVOL:-100}" -le 0 ] || [ -z "${SXMO_RINGTONE:-}" ] || [ ! -f "$SXMO_RINGTONE" ]; then
return 0
fi
ring_rx3=$(( 60 + SXMO_RINGVOL * 34 / 100 ))
ring_rx3=$(( 60 + SXMO_RINGVOL * 24 / 100 ))
pw_vol="$(awk -v v="$SXMO_RINGVOL" 'BEGIN { printf "%.2f", v / 100.0 }')"
(
@@ -154,7 +192,7 @@ EOF
(
for d in 0.15 0.40; do
sleep "$d" || exit 0
is_call_picked_up && exit 0
should_stop_ringing && exit 0
amixer -c 0 -s >/dev/null 2>&1 <<EOF || true
cset "name='SPK DAC Switch'" 1
cset "name='RX3 MIX1 INP1'" 3
@@ -177,7 +215,9 @@ EOF
if [ "$use_pw" -eq 1 ]; then
i=0
while [ "$i" -lt "$loops" ]; do
is_call_picked_up && break
should_stop_ringing && break
amixer -c 0 cset "name='RX3 Digital Volume'" "$ring_rx3" >/dev/null 2>&1 || true
wpctl set-volume @DEFAULT_AUDIO_SINK@ "${SXMO_RINGVOL}%" >/dev/null 2>&1 || true
pw-play --volume="$pw_vol" "$SXMO_RINGTONE" >/dev/null 2>&1 &
rchild="$!"
wait "$rchild" 2>/dev/null
@@ -188,6 +228,7 @@ EOF
break
fi
i=$(( i + 1 ))
should_stop_ringing && break
sleep 0.2 &
rchild="$!"
wait "$rchild" 2>/dev/null || break
@@ -195,7 +236,7 @@ EOF
done
fi
if [ "$use_pw" -eq 0 ] && ! is_call_picked_up; then
if [ "$use_pw" -eq 0 ] && ! should_stop_ringing; then
mpv --no-config --no-terminal --no-resume-playback --quiet --vo=null --no-video \
--ao=pipewire,pulse,alsa --audio-channels=stereo --audio-samplerate=48000 \
--volume-max=150 --volume="$SXMO_RINGVOL" \
@@ -213,12 +254,13 @@ vibrate() {
vchild=""
trap '[ -n "$vchild" ] && kill -TERM "$vchild" 2>/dev/null; exit 0' INT TERM EXIT
while : ; do
is_call_picked_up && exit 0
should_stop_ringing && exit 0
sxmo_vibrate 1500 "$SXMO_VIBRATE_STRENGTH" &
vchild="$!"
wait "$vchild" 2>/dev/null || exit 0
vchild=""
should_stop_ringing && exit 0
sleep 0.5 &
vchild="$!"
wait "$vchild" 2>/dev/null || exit 0
@@ -230,6 +272,10 @@ vibrate() {
trap 'finish' INT TERM EXIT
if has_ringing_call_files; then
SAW_RING_STATE=1
fi
# RING & VIBRATE MODE (DEFAULT)
if [ ! -f "$XDG_CONFIG_HOME/sxmo/.noring" ] && [ ! -f "$XDG_CONFIG_HOME/sxmo/.novibrate" ]; then
sxmo_log "RING AND VIBRATE ($SXMO_RINGTONE, vol=${SXMO_RINGVOL}%, vib=${SXMO_VIBRATE_STRENGTH})"
@@ -249,6 +295,18 @@ elif [ ! -f "$XDG_CONFIG_HOME/sxmo/.novibrate" ] && [ -f "$XDG_CONFIG_HOME/sxmo/
vibrate
fi
sleep "${SXMO_RINGTIME:-20}" &
wait "$!"
MAX_TICKS=$(( ${SXMO_RINGTIME:-20} * 5 ))
while [ "$TICKS" -lt "$MAX_TICKS" ]; do
if [ "$SAW_RING_STATE" -eq 0 ] && has_ringing_call_files; then
SAW_RING_STATE=1
fi
if should_stop_ringing; then
break
fi
sleep 0.2 &
WAIT_PID="$!"
wait "$WAIT_PID" 2>/dev/null || break
WAIT_PID=""
TICKS=$(( TICKS + 1 ))
done
finish