modem, callscreen, ring: fix DSDS incoming ring hangup/volume and add Primary/Secondary GW SIM swap UI
This commit is contained in:
1 parent
9a079e1068
commit
7927bacb67
18 files changed
+280
-84
No files matched your search
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user