Fix background call hangup and end calls on screen lock or lid close

This commit is contained in:
Luxferre committed 2026-11-04 17:59:19 +02:00
1 parent c7cdde6734
commit 0c352f0a10
55 files changed
+391 -120

No files matched your search

@@ -2046,6 +2046,14 @@ if sub_cmd == "call-dial":
num = "".join(c for c in arg2 if c in "+0123456789*#").encode("ascii")
if not num:
sys.exit(1)
calls_dir = "/run/user/10000/sxmo_calls"
dial_marker = os.path.join(calls_dir, f"sub{sub}_dialing.initiatedcall")
try:
os.makedirs(calls_dir, exist_ok=True)
open(dial_marker, "w").close()
os.chown(dial_marker, 10000, 10000)
except Exception:
pass
s = socket.socket(AF_QIPCRTR, socket.SOCK_DGRAM)
qmi_req(s, 1, 0x0044, struct.pack("<BHB", 0x01, 1, sub))
tlvs = qmi_req(s, 2, 0x0020, struct.pack("<BH", 0x01, len(num)) + num, timeout=5.0)
@@ -2056,28 +2064,70 @@ if sub_cmd == "call-dial":
subprocess.run(["dbus-send", "--system", "--type=signal", "/", "org.ofono.VoiceCallManager.CallAdded"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
cid = tlvs.get(0x10, b"\x01")[0]
prefix = f"sub{sub}_"
try:
cid_marker = os.path.join(calls_dir, f"{prefix}{cid}.initiatedcall")
open(cid_marker, "w").close()
os.chown(cid_marker, 10000, 10000)
if os.path.exists(dial_marker):
os.remove(dial_marker)
except Exception:
pass
print(f"{prefix}{cid}")
sys.exit(0)
try:
if os.path.exists(dial_marker):
os.remove(dial_marker)
except Exception:
pass
sys.exit(1)
elif sub_cmd in ("call-accept", "call-hangup", "call-dtmf"):
import subprocess
if sub_cmd == "call-hangup" and arg1 in ("", "-", "all"):
any_ended = False
txn = 1
for sub in (1, 0):
s = socket.socket(AF_QIPCRTR, socket.SOCK_DGRAM)
qmi_req(s, txn, 0x0044, struct.pack("<BHB", 0x01, 1, sub))
txn += 1
calls = parse_call_info(qmi_req(s, txn, 0x002F))
txn += 1
for cid, c in calls.items():
if c["state"] not in (8, 9):
tlvs = qmi_req(s, txn, 0x0021, struct.pack("<BHB", 0x01, 1, cid))
txn += 1
res_tlv = tlvs.get(0x02, b"")
if len(res_tlv) >= 4 and struct.unpack("<HH", res_tlv[:4]) == (0, 0):
any_ended = True
s.close()
if any_ended:
subprocess.run(["dbus-send", "--system", "--type=signal", "/", "org.ofono.VoiceCallManager.CallRemoved"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
sys.exit(0)
sys.exit(1)
# Target sub=1 by default or parse sub1_<id>
target_sub = 1
target_cid = 0
if arg1.startswith("sub0_"):
target_sub = 0
target_cid = int(arg1.split("_", 1)[1])
try:
target_cid = int(arg1.split("_", 1)[1])
except Exception:
target_cid = 0
elif arg1.startswith("sub1_"):
target_sub = 1
target_cid = int(arg1.split("_", 1)[1])
try:
target_cid = int(arg1.split("_", 1)[1])
except Exception:
target_cid = 0
elif arg1.isdigit() and sub_cmd != "call-dtmf":
target_cid = int(arg1)
s = socket.socket(AF_QIPCRTR, socket.SOCK_DGRAM)
qmi_req(s, 1, 0x0044, struct.pack("<BHB", 0x01, 1, target_sub))
if target_cid == 0:
calls = parse_call_info(qmi_req(s, 2, 0x002F))
calls = parse_call_info(qmi_req(s, 2, 0x002F))
if target_cid == 0 or (sub_cmd == "call-hangup" and target_cid not in calls):
target_cid = 0
for cid, c in calls.items():
if sub_cmd == "call-accept" and c["state"] in (2, 7):
target_cid = cid
@@ -2094,6 +2144,11 @@ elif sub_cmd in ("call-accept", "call-hangup", "call-dtmf"):
tlvs = qmi_req(s, 3, 0x0022, struct.pack("<BHB", 0x01, 1, target_cid))
elif sub_cmd == "call-hangup":
tlvs = qmi_req(s, 3, 0x0021, struct.pack("<BHB", 0x01, 1, target_cid))
txn = 4
for cid, c in calls.items():
if cid != target_cid and c["state"] not in (8, 9):
qmi_req(s, txn, 0x0021, struct.pack("<BHB", 0x01, 1, cid))
txn += 1
subprocess.run(["dbus-send", "--system", "--type=signal", "/", "org.ofono.VoiceCallManager.CallRemoved"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
else:
ch = (arg1[-1] if arg1 else "0").encode("ascii")[:1]
@@ -2764,7 +2819,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}.") and not fn.endswith(".initiatedcall") and not fn.endswith(".pickedupcall") and not fn.endswith(".mutedring"):
if fn == "sub1_dialing.initiatedcall" or (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:
@@ -2942,7 +2997,8 @@ while True:
if not got_voice_ind and (active_calls or has_sub1_call_files()):
full_tlvs = qmi_req(vs, voice_addr, v_txn, 0x002F)
v_txn = (v_txn % 60000) + 1
sync_sub1_calls(parse_call_info(full_tlvs), sec_slot)
if full_tlvs:
sync_sub1_calls(parse_call_info(full_tlvs), sec_slot)
if not os.path.exists("/tmp/bananarchy_screen_locked") and time.time() - last_poll >= 600.0:
w_txn = poll_stored_sms(ws, wms_addr, w_txn, sec_slot)