From b48979cf71b2dbff823ede2afbec2e760da4a67e Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Fri, 6 Nov 2026 14:04:01 -0700 Subject: [PATCH 1/7] omamobile-mmd: keep calls until release is confirmed Keep live calls visible until the modem reports termination, propagate hangup failures, and avoid duplicate release requests. Cover delayed replies and client deletion races. --- packages/omamobile-mmd/lib/bridge.py | 98 ++++++++-- packages/omamobile-mmd/test/conformance.py | 24 ++- packages/omamobile-mmd/test/test_bridge.py | 215 +++++++++++++++++++++ packages/omamobile-mmd/version | 2 +- 4 files changed, 315 insertions(+), 24 deletions(-) diff --git a/packages/omamobile-mmd/lib/bridge.py b/packages/omamobile-mmd/lib/bridge.py index 7ea950002..e0091bac0 100644 --- a/packages/omamobile-mmd/lib/bridge.py +++ b/packages/omamobile-mmd/lib/bridge.py @@ -157,6 +157,8 @@ def on_status(self, status): def on_lost(self): if self.modem is None: return + for path in list(self.calls): + self.finish_pending_delete(path, MMError('Failed', 'omamobile-sitd went away before call release')) for path in list(self.calls) + list(self.messages) + [self.sim, self.bearer]: if path: self.x.remove(path) @@ -315,6 +317,9 @@ def sync_calls(self): self.call_state(path, CALL_STATES.get(c['state'], mm.CALL_UNKNOWN), c.get('reason', '')) for sid, path in list(self.sitd_calls.items()): if sid not in seen and path in self.calls and self.calls[path]['seen']: + if self.calls[path]['releasing']: + self.finish_pending_delete(path, MMError('Failed', 'Call release was not confirmed')) + continue # sitd forgot it (another client deleted it): it has ended. self.call_state(path, mm.CALL_TERMINATED, '') self.forgotten &= seen @@ -324,7 +329,7 @@ def new_call(self, direction, number, state, sid=None): reason = (mm.REASON_INCOMING_NEW if direction == mm.DIRECTION_INCOMING and state != mm.CALL_UNKNOWN else mm.REASON_OUTGOING_STARTED if state != mm.CALL_UNKNOWN else mm.REASON_UNKNOWN) self.calls[path] = dict(sid=sid, direction=direction, number=number, state=state, busy=False, - seen=sid is not None) + seen=sid is not None, releasing=False, release_error=None, pending_delete=None) if sid: self.sitd_calls[sid] = path self.x.add(path, {mm.CALL: dict(State=state, StateReason=reason, Direction=direction, @@ -358,6 +363,24 @@ def call_state(self, path, state, sitd_reason): self.x.emit(path, mm.CALL, 'StateChanged', '(iiu)', (old, state, reason)) print(f'Call {path}: {CALL_STATE_NAMES.get(old, old)} -> {CALL_STATE_NAMES.get(state, state)}', flush=True) + if state == mm.CALL_TERMINATED: + self.finish_pending_delete(path) + + def finish_pending_delete(self, path, error=None): + call = self.calls.get(path) + pending = call and call.get('pending_delete') + if pending is None: + return + call['pending_delete'] = None + if pending['timer']: + GLib.source_remove(pending['timer']) + if error is not None: + pending['reply'].error(error) + else: + if call['sid']: + self.link.request('delete-call', lambda result, error: None, id=call['sid']) + self.delete_call(path) + pending['reply'].ok() def delete_call(self, path): call = self.calls.pop(path) @@ -536,31 +559,67 @@ def handle_voice(self, method, args, reply): if path not in self.calls: raise MMError('NotFound', 'No such call') call = self.calls[path] + if call['busy'] or call['pending_delete'] is not None: + raise MMError('InProgress', 'The call is being changed') + if call['sid'] and call['state'] not in (*LIVE, mm.CALL_TERMINATED): + raise MMError('WrongState', 'The call state is not known') if call['sid'] and call['state'] in LIVE: - # MM hangs up a call that is deleted while it lasts. + if call['release_error'] is not None: + return reply.error(call['release_error']) + # Keep the object until sitd reports that release completed. + pending = dict(reply=reply, timer=0) + call['pending_delete'] = pending + + def release_timeout(): + if path in self.calls and self.calls[path].get('pending_delete') is pending: + pending['timer'] = 0 + self.finish_pending_delete(path, MMError('Failed', 'Call release was not confirmed')) + return False + + pending['timer'] = GLib.timeout_add_seconds(20, release_timeout) + if call['releasing']: + return + call['releasing'] = True + def hung(result, error): - if path in self.calls: - self.delete_call(path) - reply.ok() + if error is not None and self.calls.get(path) is call: + call['release_error'] = sitd_error(error) + self.finish_pending_delete(path, call['release_error']) return self.link.request('hangup', hung, id=call['sid']) if call['sid']: self.link.request('delete-call', lambda result, error: None, id=call['sid']) self.delete_call(path) return reply.ok() if method == 'HangupAll': - live = [c['sid'] for c in self.calls.values() if c['sid'] and c['state'] in LIVE] + if any(c['busy'] for c in self.calls.values()): + raise MMError('InProgress', 'A call is being placed') + live = [(path, c) for path, c in self.calls.items() + if c['sid'] and c['state'] in LIVE and not c['releasing']] for path, c in self.calls.items(): if not c['sid'] and c['state'] == mm.CALL_UNKNOWN: self.call_state(path, mm.CALL_TERMINATED, 'terminated') - failures = [] - - def next_hangup(result=None, error=None): - if error is not None: - failures.append(error) - if live: - return self.link.request('hangup', next_hangup, id=live.pop(0)) + failures = [c['release_error'] for c in self.calls.values() + if c['sid'] and c['state'] in LIVE and c['release_error'] is not None] + + def next_hangup(): + while live: + path, call = live.pop(0) + if (self.calls.get(path) is not call or call['state'] not in LIVE + or call['releasing']): + continue + call['releasing'] = True + + def hung(result, error, path=path, call=call): + if error is not None: + failure = sitd_error(error) + failures.append(failure) + if self.calls.get(path) is call: + call['release_error'] = failure + self.finish_pending_delete(path, failure) + next_hangup() + return self.link.request('hangup', hung, id=call['sid']) if failures: - return reply.error(sitd_error(failures[0])) + return reply.error(failures[0]) reply.ok() return next_hangup() raise unsupported(method) @@ -604,7 +663,16 @@ def dialled(result, error): raise MMError('InProgress', 'The call is being placed') self.call_state(path, mm.CALL_TERMINATED, 'terminated') return reply.ok() - return self.link.request('hangup', self.answer(reply), id=call['sid']) + if call['releasing']: + raise MMError('InProgress', 'Call release is already in progress') + call['releasing'] = True + + def hung(result, error): + if error is not None and self.calls.get(path) is call: + call['release_error'] = sitd_error(error) + self.finish_pending_delete(path, call['release_error']) + self.answer(reply)(result, error) + return self.link.request('hangup', hung, id=call['sid']) if method == 'SendDtmf': keys = args[0] if not re.fullmatch(r'[0-9*#]{1,32}', keys or ''): diff --git a/packages/omamobile-mmd/test/conformance.py b/packages/omamobile-mmd/test/conformance.py index ada493a35..5e9cf7025 100644 --- a/packages/omamobile-mmd/test/conformance.py +++ b/packages/omamobile-mmd/test/conformance.py @@ -168,8 +168,16 @@ def calls_objects(): 'answered from Calls')), 'Calls answers through Call.Accept') calls_api(path, 'org.gnome.Calls.Call', 'SendDtmf', GLib.Variant('(s)', ('7',))) calls_api(path, 'org.gnome.Calls.Call', 'Hangup') - check(bool(wait_until(lambda: chain.client.prop(mm_call, mm.CALL, 'State') == mm.CALL_TERMINATED, 10, - 'hung up from Calls')), 'Calls hangs up through Call.Hangup') + # Calls may delete the object as soon as it ends. Check the recorded + # transition and the modem request, rather than polling a vanished object. + def terminated(call_path): + return any(s[0] == call_path and s[1] == mm.CALL and s[3][1] == mm.CALL_TERMINATED + for s in chain.client.named('StateChanged')) + + check(bool(wait_until(lambda: terminated(mm_call), 10, 'hung up from Calls')), + 'Calls reports the incoming call ended') + check(len([e for e in chain.entries() if e.get('type') == 'req' and e.get('id') == 0x0d03]) == 1, + 'Calls sends one incoming hangup to the modem') check([e.get('key') for e in chain.entries() if e.get('event') == 'dtmf'] == ['7'], 'Calls sends DTMF') subprocess.run(['gnome-calls', f'--dial={OTHER}'], env=dict(os.environ, DBUS_SESSION_BUS_ADDRESS=session_address), @@ -183,12 +191,12 @@ def calls_objects(): if not v['org.gnome.Calls.Call']['Inbound']], 10, 'outgoing in Calls')[0] calls_api(out_path, 'org.gnome.Calls.Call', 'Hangup') - def ended_or_deleted(): - # Calls deletes a call (Voice.DeleteCall) once it has ended. - if dialled[0] not in chain.client.prop(ROOT + '/Modem/0', mm.VOICE, 'Calls'): - return 'deleted' - return chain.client.prop(dialled[0], mm.CALL, 'State') == mm.CALL_TERMINATED - check(wait_until(ended_or_deleted, 10, 'ended') == 'deleted', 'Calls hangs up and deletes its call') + check(bool(wait_until(lambda: terminated(dialled[0]), 10, 'outgoing call ended')), + 'Calls reports the outgoing call ended') + check(bool(wait_until(lambda: dialled[0] not in chain.client.prop(ROOT + '/Modem/0', mm.VOICE, 'Calls'), + 10, 'outgoing call deleted')), 'Calls deletes its ended call') + check(len([e for e in chain.entries() if e.get('type') == 'req' and e.get('id') == 0x0d03]) == 2, + 'Calls sends one outgoing hangup to the modem') with open(log, errors='replace') as f: text = f.read() bad = [line for line in text.splitlines() if re.search(r'CRITICAL|Segmentation|dumped core', line)] diff --git a/packages/omamobile-mmd/test/test_bridge.py b/packages/omamobile-mmd/test/test_bridge.py index 0f9b18cd9..e25a8bbd9 100644 --- a/packages/omamobile-mmd/test/test_bridge.py +++ b/packages/omamobile-mmd/test/test_bridge.py @@ -7,6 +7,7 @@ registered_status, spin, tempdir, wait_until import os import re +import threading import unittest import bridge @@ -287,6 +288,220 @@ def dial(request): spin(.2) self.assertEqual(self.modem('Calls', mm.VOICE), [], 'a deleted call does not come back') + def test_delete_live_call_preserves_it_when_hangup_is_refused(self): + self.sitd.status['calls'] = [call('200', 'active')] + self.push() + path = wait_until(lambda: self.modem('Calls', mm.VOICE), 5, 'live call')[0] + + def refuse(request): + raise FakeRefusal('Hangup could not be confirmed') + + self.sitd.handlers['hangup'] = refuse + self.assertEqual(self.error_of(MODEM0, mm.VOICE, 'DeleteCall', 'o', (path,)), + mm.ERROR_PREFIX + 'Failed') + self.assertEqual(self.sitd.requests[-1], dict(action='hangup', id='200')) + self.assertEqual(self.modem('Calls', mm.VOICE), [path]) + self.assertEqual(self.client.prop(path, mm.CALL, 'State'), mm.CALL_ACTIVE) + self.push() + spin(.2) + self.assertEqual(self.modem('Calls', mm.VOICE), [path]) + self.assertEqual(self.error_of(path, mm.CALL, 'Hangup'), mm.ERROR_PREFIX + 'InProgress') + self.assertEqual(self.sitd.actions().count('hangup'), 1) + + def test_delete_live_call_waits_for_confirmed_release(self): + self.sitd.status['calls'] = [call('200', 'active')] + self.sitd.handlers['hangup'] = lambda request: {} + self.push() + path = wait_until(lambda: self.modem('Calls', mm.VOICE), 5, 'live call')[0] + result = self.client.call_async(MODEM0, mm.VOICE, 'DeleteCall', 'o', (path,)) + wait_until(lambda: self.sitd.actions().count('hangup') == 1, 5, 'hangup request') + spin(.2) + self.assertEqual(result, {}, 'the modem has not confirmed release') + self.assertEqual(self.modem('Calls', mm.VOICE), [path]) + self.assertEqual(self.error_of(MODEM0, mm.VOICE, 'DeleteCall', 'o', (path,)), + mm.ERROR_PREFIX + 'InProgress') + self.sitd.status['calls'] = [call('200', 'terminated', reason='terminated')] + self.push() + wait_until(lambda: result, 5, 'confirmed deletion') + self.assertEqual(result.get('result'), ()) + self.assertEqual(self.modem('Calls', mm.VOICE), []) + self.assertEqual(self.sitd.actions().count('hangup'), 1) + wait_until(lambda: self.sitd.actions().count('delete-call') == 1, 5, 'sitd call cleanup') + self.assertEqual(self.sitd.requests[-1], dict(action='delete-call', id='200')) + + def test_delete_after_hangup_does_not_send_a_second_hangup(self): + self.sitd.status['calls'] = [call('200', 'active')] + self.sitd.handlers['hangup'] = lambda request: {} + self.push() + path = wait_until(lambda: self.modem('Calls', mm.VOICE), 5, 'live call')[0] + self.client.call(path, mm.CALL, 'Hangup') + result = self.client.call_async(MODEM0, mm.VOICE, 'DeleteCall', 'o', (path,)) + spin(.2) + self.assertEqual(result, {}) + self.assertEqual(self.sitd.actions().count('hangup'), 1) + self.sitd.status['calls'] = [call('200', 'terminated', reason='terminated')] + self.push() + wait_until(lambda: result, 5, 'confirmed deletion') + self.assertEqual(result.get('result'), ()) + self.assertEqual(self.modem('Calls', mm.VOICE), []) + + def test_disappearing_live_call_does_not_confirm_release(self): + self.sitd.status['calls'] = [call('200', 'active')] + self.sitd.handlers['hangup'] = lambda request: {} + self.push() + path = wait_until(lambda: self.modem('Calls', mm.VOICE), 5, 'live call')[0] + result = self.client.call_async(MODEM0, mm.VOICE, 'DeleteCall', 'o', (path,)) + wait_until(lambda: self.sitd.actions().count('hangup') == 1, 5, 'hangup request') + self.sitd.status['calls'] = [] + self.push() + wait_until(lambda: result, 5, 'unconfirmed release refusal') + self.assertIn(mm.ERROR_PREFIX + 'Failed', result['error'].message) + self.assertEqual(self.modem('Calls', mm.VOICE), [path]) + self.assertEqual(self.client.prop(path, mm.CALL, 'State'), mm.CALL_ACTIVE) + self.push() + spin(.2) + self.assertEqual(self.client.prop(path, mm.CALL, 'State'), mm.CALL_ACTIVE) + + def test_release_confirmation_can_arrive_before_hangup_reply(self): + self.sitd.status['calls'] = [call('200', 'active')] + entered, proceed = threading.Event(), threading.Event() + self.addCleanup(proceed.set) + + def delayed(request): + entered.set() + if not proceed.wait(5): + raise FakeRefusal('test timed out') + return {} + + self.sitd.handlers['hangup'] = delayed + self.push() + path = wait_until(lambda: self.modem('Calls', mm.VOICE), 5, 'live call')[0] + result = self.client.call_async(MODEM0, mm.VOICE, 'DeleteCall', 'o', (path,)) + wait_until(entered.is_set, 5, 'hangup request') + self.sitd.status['calls'] = [call('200', 'terminated', reason='terminated')] + self.push() + wait_until(lambda: result, 5, 'confirmed deletion') + self.assertEqual(result.get('result'), ()) + proceed.set() + spin(.2) + self.assertEqual(self.modem('Calls', mm.VOICE), []) + + def test_service_loss_fails_pending_delete(self): + self.sitd.status['calls'] = [call('200', 'active')] + self.sitd.handlers['hangup'] = lambda request: {} + self.push() + path = wait_until(lambda: self.modem('Calls', mm.VOICE), 5, 'live call')[0] + result = self.client.call_async(MODEM0, mm.VOICE, 'DeleteCall', 'o', (path,)) + wait_until(lambda: self.sitd.actions().count('hangup') == 1, 5, 'hangup request') + self.sitd.stop() + wait_until(lambda: result, 5, 'service-loss refusal') + self.assertIn(mm.ERROR_PREFIX + 'Failed', result['error'].message) + + def test_delete_during_dial_is_refused(self): + entered, proceed = threading.Event(), threading.Event() + self.addCleanup(proceed.set) + + def delayed(request): + entered.set() + if not proceed.wait(5): + raise FakeRefusal('test timed out') + return dict(call='100', number=request['number']) + + self.sitd.handlers['dial'] = delayed + path = self.client.call(MODEM0, mm.VOICE, 'CreateCall', 'a{sv}', + ({'number': GLib.Variant('s', OTHER)},))[0] + started = self.client.call_async(path, mm.CALL, 'Start') + wait_until(entered.is_set, 5, 'dial request') + self.assertEqual(self.error_of(MODEM0, mm.VOICE, 'DeleteCall', 'o', (path,)), + mm.ERROR_PREFIX + 'InProgress') + self.assertEqual(self.error_of(MODEM0, mm.VOICE, 'HangupAll'), mm.ERROR_PREFIX + 'InProgress') + proceed.set() + wait_until(lambda: started, 5, 'dial reply') + self.assertEqual(started.get('result'), ()) + self.assertIn(path, self.modem('Calls', mm.VOICE)) + + def test_hangup_all_does_not_repeat_a_pending_release(self): + self.sitd.status['calls'] = [call('200', 'active')] + self.sitd.handlers['hangup'] = lambda request: {} + self.push() + path = wait_until(lambda: self.modem('Calls', mm.VOICE), 5, 'live call')[0] + self.client.call(path, mm.CALL, 'Hangup') + self.client.call(MODEM0, mm.VOICE, 'HangupAll') + self.assertEqual(self.sitd.actions().count('hangup'), 1) + + def test_delete_after_refused_hangup_reports_error_without_retry(self): + self.sitd.status['calls'] = [call('200', 'active')] + def refuse(request): + raise FakeRefusal('Hangup could not be confirmed') + self.sitd.handlers['hangup'] = refuse + self.push() + path = wait_until(lambda: self.modem('Calls', mm.VOICE), 5, 'live call')[0] + self.assertEqual(self.error_of(path, mm.CALL, 'Hangup'), mm.ERROR_PREFIX + 'Failed') + self.assertEqual(self.error_of(MODEM0, mm.VOICE, 'DeleteCall', 'o', (path,)), + mm.ERROR_PREFIX + 'Failed') + self.assertEqual(self.error_of(MODEM0, mm.VOICE, 'HangupAll'), mm.ERROR_PREFIX + 'Failed') + self.assertEqual(self.modem('Calls', mm.VOICE), [path]) + self.assertEqual(self.sitd.actions().count('hangup'), 1) + + def test_pending_delete_fails_when_prior_hangup_is_refused(self): + for method in ('Hangup', 'HangupAll'): + with self.subTest(method=method): + self.sitd.status['calls'] = [call('200', 'active')] + entered, proceed = threading.Event(), threading.Event() + self.addCleanup(proceed.set) + + def delayed_refusal(request): + entered.set() + if not proceed.wait(5): + raise FakeRefusal('test timed out') + raise FakeRefusal('Hangup could not be confirmed') + + self.sitd.handlers['hangup'] = delayed_refusal + self.push() + path = wait_until(lambda: self.modem('Calls', mm.VOICE), 5, 'live call')[0] + if method == 'Hangup': + hung = self.client.call_async(path, mm.CALL, method) + else: + hung = self.client.call_async(MODEM0, mm.VOICE, method) + wait_until(entered.is_set, 5, 'hangup request') + deleted = self.client.call_async(MODEM0, mm.VOICE, 'DeleteCall', 'o', (path,)) + spin(.2) + self.assertEqual(deleted, {}) + proceed.set() + wait_until(lambda: hung and deleted, 5, 'both errors') + self.assertIn(mm.ERROR_PREFIX + 'Failed', hung['error'].message) + self.assertIn(mm.ERROR_PREFIX + 'Failed', deleted['error'].message) + self.assertEqual(self.modem('Calls', mm.VOICE), [path]) + self.sitd.status['calls'] = [call('200', 'terminated', reason='terminated')] + self.push() + wait_until(lambda: self.client.prop(path, mm.CALL, 'State') == mm.CALL_TERMINATED, + 5, 'terminated') + self.client.call(MODEM0, mm.VOICE, 'DeleteCall', 'o', (path,)) + self.sitd.status['calls'] = [] + self.push() + spin(.2) + + def test_unconfirmed_release_times_out_without_deleting_or_retrying(self): + self.sitd.status['calls'] = [call('200', 'active')] + self.sitd.handlers['hangup'] = lambda request: {} + self.push() + path = wait_until(lambda: self.modem('Calls', mm.VOICE), 5, 'live call')[0] + result = self.client.call_async(MODEM0, mm.VOICE, 'DeleteCall', 'o', (path,)) + wait_until(lambda: result, 25, 'release confirmation timeout') + self.assertIn(mm.ERROR_PREFIX + 'Failed', result['error'].message) + self.assertEqual(self.modem('Calls', mm.VOICE), [path]) + self.assertEqual(self.client.prop(path, mm.CALL, 'State'), mm.CALL_ACTIVE) + self.assertEqual(self.sitd.actions().count('hangup'), 1) + + def test_delete_call_with_unknown_modem_state_is_refused(self): + self.sitd.status['calls'] = [call('200', 'unrecognized')] + self.push() + path = wait_until(lambda: self.modem('Calls', mm.VOICE), 5, 'unknown call')[0] + self.assertEqual(self.error_of(MODEM0, mm.VOICE, 'DeleteCall', 'o', (path,)), + mm.ERROR_PREFIX + 'WrongState') + self.assertEqual(self.modem('Calls', mm.VOICE), [path]) + self.assertEqual(self.sitd.actions(), []) + def test_incoming_call(self): self.sitd.handlers.update(accept=lambda r: {}) self.sitd.status['calls'] = [call('200', 'ringing-in')] diff --git a/packages/omamobile-mmd/version b/packages/omamobile-mmd/version index d917d3e26..b1e80bb24 100644 --- a/packages/omamobile-mmd/version +++ b/packages/omamobile-mmd/version @@ -1 +1 @@ -0.1.2 +0.1.3 From c5fa2f0e9169cccbfcb1c4638df7482b1a2a2e5a Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Fri, 6 Nov 2026 14:21:49 -0700 Subject: [PATCH 2/7] omamobile-mmd: wait for the private bus to listen Retry connection refusal while the test bus starts, and clean up the daemon when startup fails. Exercise delayed readiness and failure paths. --- packages/omamobile-mmd/test/all | 2 +- packages/omamobile-mmd/test/env.py | 34 +++++++++--- packages/omamobile-mmd/test/test_env.py | 70 +++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 8 deletions(-) create mode 100644 packages/omamobile-mmd/test/test_env.py diff --git a/packages/omamobile-mmd/test/all b/packages/omamobile-mmd/test/all index 3b555a4bb..6f05b1758 100755 --- a/packages/omamobile-mmd/test/all +++ b/packages/omamobile-mmd/test/all @@ -19,7 +19,7 @@ done pass "scripts parse" command -v dbus-daemon >/dev/null || fail "dbus-daemon (package dbus) is needed for the tests" -out=$(cd test && python3 -W ignore -m unittest -v test_api test_bridge test_libmm test_chain 2>&1) || { +out=$(cd test && python3 -W ignore -m unittest -v test_api test_env test_bridge test_libmm test_chain 2>&1) || { printf '%s\n' "$out" | grep -v -e Deprecat -e EventLoopPolicy | tail -40; fail "unit and bus tests"; } skips=$(printf '%s\n' "$out" | grep -c "skipped '" || true) pass "API, bridge, libmm-glib and chain tests$( ((skips)) && echo " (# SKIP $skips: $(printf '%s\n' "$out" | grep -o "skipped '[^']*'" | sort -u | tr '\n' ' '))")" diff --git a/packages/omamobile-mmd/test/env.py b/packages/omamobile-mmd/test/env.py index 831e70de4..20506a623 100644 --- a/packages/omamobile-mmd/test/env.py +++ b/packages/omamobile-mmd/test/env.py @@ -56,13 +56,33 @@ def __init__(self, directory): stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) self.address = 'unix:path=' + self.path deadline = time.monotonic() + 10 - while not os.path.exists(self.path): - if time.monotonic() > deadline or self.proc.poll() is not None: - raise RuntimeError('private dbus-daemon did not start') - time.sleep(.02) - self.connection = Gio.DBusConnection.new_for_address_sync( - self.address, Gio.DBusConnectionFlags.AUTHENTICATION_CLIENT | - Gio.DBusConnectionFlags.MESSAGE_BUS_CONNECTION, None, None) + try: + while not os.path.exists(self.path): + if time.monotonic() > deadline or self.proc.poll() is not None: + raise RuntimeError('private dbus-daemon did not start') + time.sleep(.02) + while True: + try: + self.connection = Gio.DBusConnection.new_for_address_sync( + self.address, Gio.DBusConnectionFlags.AUTHENTICATION_CLIENT | + Gio.DBusConnectionFlags.MESSAGE_BUS_CONNECTION, None, None) + break + except GLib.Error as error: + # bind() creates the socket before listen() accepts clients. + if not error.matches(Gio.io_error_quark(), Gio.IOErrorEnum.CONNECTION_REFUSED): + raise + if time.monotonic() > deadline or self.proc.poll() is not None: + raise RuntimeError('private dbus-daemon did not start') from error + time.sleep(.02) + except BaseException: + if self.proc.poll() is None: + self.proc.terminate() + try: + self.proc.wait(5) + except subprocess.TimeoutExpired: + self.proc.kill() + self.proc.wait() + raise def close(self): self.connection.close_sync(None) diff --git a/packages/omamobile-mmd/test/test_env.py b/packages/omamobile-mmd/test/test_env.py new file mode 100644 index 000000000..c25e8a53e --- /dev/null +++ b/packages/omamobile-mmd/test/test_env.py @@ -0,0 +1,70 @@ +# SPDX-License-Identifier: MIT +"""Private D-Bus startup must tolerate a socket that is not listening yet.""" +import os +from types import SimpleNamespace +import unittest +from unittest import mock + +import env +from env import Gio, GLib + + +class PrivateBusStartup(unittest.TestCase): + def setUp(self): + self.directory, cleanup = env.tempdir() + self.addCleanup(cleanup) + # bind() has created the path, but listen() has not necessarily run. + open(os.path.join(self.directory, 'bus'), 'w').close() + self.process = mock.Mock() + self.process.poll.return_value = None + self.connection = mock.Mock() + self.connect = mock.Mock() + self.gio = SimpleNamespace(DBusConnectionFlags=Gio.DBusConnectionFlags, + DBusConnection=SimpleNamespace(new_for_address_sync=self.connect), + io_error_quark=Gio.io_error_quark, IOErrorEnum=Gio.IOErrorEnum) + for patcher in (mock.patch.object(env, 'Gio', self.gio), + mock.patch.object(env.subprocess, 'Popen', return_value=self.process), + mock.patch.object(env.time, 'sleep')): + patcher.start() + self.addCleanup(patcher.stop) + + @staticmethod + def error(code): + return GLib.Error.new_literal(Gio.io_error_quark(), 'test error', code) + + def test_refused_connection_retries_until_bus_is_listening(self): + self.connect.side_effect = [self.error(Gio.IOErrorEnum.CONNECTION_REFUSED), self.connection] + bus = env.PrivateBus(self.directory) + self.assertIs(bus.connection, self.connection) + self.assertEqual(self.connect.call_count, 2) + bus.close() + self.process.terminate.assert_called_once() + self.process.wait.assert_called_once_with(5) + + def test_other_connection_error_stops_and_cleans_up(self): + self.connect.side_effect = self.error(Gio.IOErrorEnum.PERMISSION_DENIED) + with self.assertRaises(GLib.Error): + env.PrivateBus(self.directory) + self.connect.assert_called_once() + self.process.terminate.assert_called_once() + self.process.wait.assert_called_once_with(5) + + def test_refusal_timeout_stops_and_cleans_up(self): + self.connect.side_effect = self.error(Gio.IOErrorEnum.CONNECTION_REFUSED) + with mock.patch.object(env.time, 'monotonic', side_effect=[0, 11]): + with self.assertRaisesRegex(RuntimeError, 'did not start'): + env.PrivateBus(self.directory) + self.process.terminate.assert_called_once() + self.process.wait.assert_called_once_with(5) + + def test_daemon_exit_stops_retrying(self): + self.connect.side_effect = self.error(Gio.IOErrorEnum.CONNECTION_REFUSED) + self.process.poll.return_value = 1 + with self.assertRaisesRegex(RuntimeError, 'did not start'): + env.PrivateBus(self.directory) + self.connect.assert_called_once() + self.process.terminate.assert_not_called() + + +if __name__ == '__main__': + unittest.main() From fa87b08c610e490b6281325cc1dfdce10bf51e9a Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Sun, 8 Nov 2026 16:30:24 -0643 Subject: [PATCH 3/7] omamobile-mmd: a call sitd no longer lists is terminated, and its Delete completes sitd drops a call only after it has ended (delete-call needs terminated, and a restart restores live calls), so a call that disappears while a hangup is pending is over: mark it terminated and complete the client's Delete, instead of answering Failed and leaving the object Active until mmd restarts. --- packages/omamobile-mmd/lib/bridge.py | 8 ++++---- packages/omamobile-mmd/test/test_bridge.py | 15 ++++++--------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/packages/omamobile-mmd/lib/bridge.py b/packages/omamobile-mmd/lib/bridge.py index e0091bac0..1e41a9001 100644 --- a/packages/omamobile-mmd/lib/bridge.py +++ b/packages/omamobile-mmd/lib/bridge.py @@ -317,10 +317,10 @@ def sync_calls(self): self.call_state(path, CALL_STATES.get(c['state'], mm.CALL_UNKNOWN), c.get('reason', '')) for sid, path in list(self.sitd_calls.items()): if sid not in seen and path in self.calls and self.calls[path]['seen']: - if self.calls[path]['releasing']: - self.finish_pending_delete(path, MMError('Failed', 'Call release was not confirmed')) - continue - # sitd forgot it (another client deleted it): it has ended. + # sitd only drops a call after it has ended (delete-call needs + # terminated; a restart restores live calls), so a call it no + # longer lists is over, whether or not our hangup was what + # ended it: terminated, and a pending Delete completes. self.call_state(path, mm.CALL_TERMINATED, '') self.forgotten &= seen diff --git a/packages/omamobile-mmd/test/test_bridge.py b/packages/omamobile-mmd/test/test_bridge.py index e25a8bbd9..b3bfbb37f 100644 --- a/packages/omamobile-mmd/test/test_bridge.py +++ b/packages/omamobile-mmd/test/test_bridge.py @@ -345,23 +345,20 @@ def test_delete_after_hangup_does_not_send_a_second_hangup(self): self.assertEqual(result.get('result'), ()) self.assertEqual(self.modem('Calls', mm.VOICE), []) - def test_disappearing_live_call_does_not_confirm_release(self): + def test_disappearing_live_call_is_terminated_and_deleted(self): self.sitd.status['calls'] = [call('200', 'active')] self.sitd.handlers['hangup'] = lambda request: {} self.push() path = wait_until(lambda: self.modem('Calls', mm.VOICE), 5, 'live call')[0] result = self.client.call_async(MODEM0, mm.VOICE, 'DeleteCall', 'o', (path,)) wait_until(lambda: self.sitd.actions().count('hangup') == 1, 5, 'hangup request') + # sitd drops a call only once it has ended, so a call it no longer + # lists is over: terminated, and the pending Delete completes. self.sitd.status['calls'] = [] self.push() - wait_until(lambda: result, 5, 'unconfirmed release refusal') - self.assertIn(mm.ERROR_PREFIX + 'Failed', result['error'].message) - self.assertEqual(self.modem('Calls', mm.VOICE), [path]) - self.assertEqual(self.client.prop(path, mm.CALL, 'State'), mm.CALL_ACTIVE) - self.push() - spin(.2) - self.assertEqual(self.client.prop(path, mm.CALL, 'State'), mm.CALL_ACTIVE) - + wait_until(lambda: result, 5, 'the delete completes') + self.assertNotIn('error', result) + self.assertEqual(self.modem('Calls', mm.VOICE), []) def test_release_confirmation_can_arrive_before_hangup_reply(self): self.sitd.status['calls'] = [call('200', 'active')] entered, proceed = threading.Event(), threading.Event() From c9619cc31177036343bf44e9f867f3f6745cafb3 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Mon, 9 Nov 2026 09:05:55 -0643 Subject: [PATCH 4/7] omamobile-mmd: a refused or unconfirmed hang-up lets the user try again The releasing flag held for the rest of the call once a hang-up had failed or its confirmation had timed out, so a second press of the red button answered InProgress and the call ran on until the far end hung up. Now the flag clears when sitd answers the hang-up with an error and when the 20 s confirmation runs out, so each new Hangup, DeleteCall or HangupAll from the user is a new attempt, while the bridge still never retries on its own and still refuses a second hang-up while the first is outstanding. The cached error goes with it: the pending Delete gets its error directly. The tests say so, and the blank line before the confirmation-before-reply test is back. --- packages/omamobile-mmd/lib/bridge.py | 21 +++++++++++---------- packages/omamobile-mmd/test/test_bridge.py | 21 +++++++++++++++++---- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/packages/omamobile-mmd/lib/bridge.py b/packages/omamobile-mmd/lib/bridge.py index 1e41a9001..b9be0717b 100644 --- a/packages/omamobile-mmd/lib/bridge.py +++ b/packages/omamobile-mmd/lib/bridge.py @@ -329,7 +329,7 @@ def new_call(self, direction, number, state, sid=None): reason = (mm.REASON_INCOMING_NEW if direction == mm.DIRECTION_INCOMING and state != mm.CALL_UNKNOWN else mm.REASON_OUTGOING_STARTED if state != mm.CALL_UNKNOWN else mm.REASON_UNKNOWN) self.calls[path] = dict(sid=sid, direction=direction, number=number, state=state, busy=False, - seen=sid is not None, releasing=False, release_error=None, pending_delete=None) + seen=sid is not None, releasing=False, pending_delete=None) if sid: self.sitd_calls[sid] = path self.x.add(path, {mm.CALL: dict(State=state, StateReason=reason, Direction=direction, @@ -564,15 +564,17 @@ def handle_voice(self, method, args, reply): if call['sid'] and call['state'] not in (*LIVE, mm.CALL_TERMINATED): raise MMError('WrongState', 'The call state is not known') if call['sid'] and call['state'] in LIVE: - if call['release_error'] is not None: - return reply.error(call['release_error']) # Keep the object until sitd reports that release completed. + # A hang-up that sitd refused, or that was never confirmed, + # leaves no block: the next DeleteCall or Hangup from the user + # tries once more; the bridge never retries on its own. pending = dict(reply=reply, timer=0) call['pending_delete'] = pending def release_timeout(): if path in self.calls and self.calls[path].get('pending_delete') is pending: pending['timer'] = 0 + call['releasing'] = False self.finish_pending_delete(path, MMError('Failed', 'Call release was not confirmed')) return False @@ -583,8 +585,8 @@ def release_timeout(): def hung(result, error): if error is not None and self.calls.get(path) is call: - call['release_error'] = sitd_error(error) - self.finish_pending_delete(path, call['release_error']) + call['releasing'] = False + self.finish_pending_delete(path, sitd_error(error)) return self.link.request('hangup', hung, id=call['sid']) if call['sid']: self.link.request('delete-call', lambda result, error: None, id=call['sid']) @@ -598,8 +600,7 @@ def hung(result, error): for path, c in self.calls.items(): if not c['sid'] and c['state'] == mm.CALL_UNKNOWN: self.call_state(path, mm.CALL_TERMINATED, 'terminated') - failures = [c['release_error'] for c in self.calls.values() - if c['sid'] and c['state'] in LIVE and c['release_error'] is not None] + failures = [] def next_hangup(): while live: @@ -614,7 +615,7 @@ def hung(result, error, path=path, call=call): failure = sitd_error(error) failures.append(failure) if self.calls.get(path) is call: - call['release_error'] = failure + call['releasing'] = False self.finish_pending_delete(path, failure) next_hangup() return self.link.request('hangup', hung, id=call['sid']) @@ -669,8 +670,8 @@ def dialled(result, error): def hung(result, error): if error is not None and self.calls.get(path) is call: - call['release_error'] = sitd_error(error) - self.finish_pending_delete(path, call['release_error']) + call['releasing'] = False + self.finish_pending_delete(path, sitd_error(error)) self.answer(reply)(result, error) return self.link.request('hangup', hung, id=call['sid']) if method == 'SendDtmf': diff --git a/packages/omamobile-mmd/test/test_bridge.py b/packages/omamobile-mmd/test/test_bridge.py index b3bfbb37f..2f43dcd88 100644 --- a/packages/omamobile-mmd/test/test_bridge.py +++ b/packages/omamobile-mmd/test/test_bridge.py @@ -305,8 +305,9 @@ def refuse(request): self.push() spin(.2) self.assertEqual(self.modem('Calls', mm.VOICE), [path]) - self.assertEqual(self.error_of(path, mm.CALL, 'Hangup'), mm.ERROR_PREFIX + 'InProgress') - self.assertEqual(self.sitd.actions().count('hangup'), 1) + # the refused attempt is over, so a new Hangup is a new attempt + self.assertEqual(self.error_of(path, mm.CALL, 'Hangup'), mm.ERROR_PREFIX + 'Failed') + self.assertEqual(self.sitd.actions().count('hangup'), 2) def test_delete_live_call_waits_for_confirmed_release(self): self.sitd.status['calls'] = [call('200', 'active')] @@ -359,6 +360,7 @@ def test_disappearing_live_call_is_terminated_and_deleted(self): wait_until(lambda: result, 5, 'the delete completes') self.assertNotIn('error', result) self.assertEqual(self.modem('Calls', mm.VOICE), []) + def test_release_confirmation_can_arrive_before_hangup_reply(self): self.sitd.status['calls'] = [call('200', 'active')] entered, proceed = threading.Event(), threading.Event() @@ -426,7 +428,7 @@ def test_hangup_all_does_not_repeat_a_pending_release(self): self.client.call(MODEM0, mm.VOICE, 'HangupAll') self.assertEqual(self.sitd.actions().count('hangup'), 1) - def test_delete_after_refused_hangup_reports_error_without_retry(self): + def test_refused_hangup_reports_error_and_a_new_press_tries_again(self): self.sitd.status['calls'] = [call('200', 'active')] def refuse(request): raise FakeRefusal('Hangup could not be confirmed') @@ -434,11 +436,19 @@ def refuse(request): self.push() path = wait_until(lambda: self.modem('Calls', mm.VOICE), 5, 'live call')[0] self.assertEqual(self.error_of(path, mm.CALL, 'Hangup'), mm.ERROR_PREFIX + 'Failed') + self.assertEqual(self.sitd.actions().count('hangup'), 1) + # The bridge never retries on its own, but each new request from the + # user is a new attempt once the last one has failed self.assertEqual(self.error_of(MODEM0, mm.VOICE, 'DeleteCall', 'o', (path,)), mm.ERROR_PREFIX + 'Failed') + self.assertEqual(self.sitd.actions().count('hangup'), 2) self.assertEqual(self.error_of(MODEM0, mm.VOICE, 'HangupAll'), mm.ERROR_PREFIX + 'Failed') + self.assertEqual(self.sitd.actions().count('hangup'), 3) self.assertEqual(self.modem('Calls', mm.VOICE), [path]) - self.assertEqual(self.sitd.actions().count('hangup'), 1) + # and once sitd takes it, the call ends + self.sitd.handlers['hangup'] = lambda request: {} + self.client.call(path, mm.CALL, 'Hangup') + self.assertEqual(self.sitd.actions().count('hangup'), 4) def test_pending_delete_fails_when_prior_hangup_is_refused(self): for method in ('Hangup', 'HangupAll'): @@ -489,6 +499,9 @@ def test_unconfirmed_release_times_out_without_deleting_or_retrying(self): self.assertEqual(self.modem('Calls', mm.VOICE), [path]) self.assertEqual(self.client.prop(path, mm.CALL, 'State'), mm.CALL_ACTIVE) self.assertEqual(self.sitd.actions().count('hangup'), 1) + # after the timeout a new press from the user is a new attempt + self.client.call(path, mm.CALL, 'Hangup') + self.assertEqual(self.sitd.actions().count('hangup'), 2) def test_delete_call_with_unknown_modem_state_is_refused(self): self.sitd.status['calls'] = [call('200', 'unrecognized')] From 5359a6663038f98b0389374c214ac7dd0586343f Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Mon, 9 Nov 2026 13:16:27 -0643 Subject: [PATCH 5/7] omamobile-mmd: every hang-up gets the 20 s release window, and HangupAll says when it skipped one sitd answers a hang-up as soon as it has sent the release, and its own deadline then turns the radio off and keeps the call, so a release that was accepted but never completed left Call.Hangup blocked for the rest of the call. Now every hang-up, from Hangup, DeleteCall or HangupAll, holds the releasing flag for 20 s at most (one timer per call, ended by a reply, a terminated call or the call's deletion), after which a new press from the user is a new attempt; the bridge still never retries on its own. HangupAll answers InProgress instead of success for a call it skipped because its release is outstanding. The refusal test ends with the call terminated and gone, and a new test walks an accepted, unconfirmed hang-up through the window. --- packages/omamobile-mmd/lib/bridge.py | 41 ++++++++++++++++++---- packages/omamobile-mmd/test/test_bridge.py | 28 +++++++++++++-- 2 files changed, 60 insertions(+), 9 deletions(-) diff --git a/packages/omamobile-mmd/lib/bridge.py b/packages/omamobile-mmd/lib/bridge.py index b9be0717b..8ceadbfe9 100644 --- a/packages/omamobile-mmd/lib/bridge.py +++ b/packages/omamobile-mmd/lib/bridge.py @@ -366,6 +366,28 @@ def call_state(self, path, state, sitd_reason): if state == mm.CALL_TERMINATED: self.finish_pending_delete(path) + def start_release(self, call): + """One hang-up outstanding at a time, for 20 s at most: sitd answers + the request as soon as it has sent the release, and its own deadline + then turns the radio off and keeps the call, so a release that is + accepted but never completes must not block the user's next press. + The bridge never retries on its own.""" + call['releasing'] = True + if call.get('release_timer'): + GLib.source_remove(call['release_timer']) + + def expire(): + call['release_timer'] = 0 + call['releasing'] = False + return False + call['release_timer'] = GLib.timeout_add_seconds(20, expire) + + def end_release(self, call): + call['releasing'] = False + if call.get('release_timer'): + GLib.source_remove(call['release_timer']) + call['release_timer'] = 0 + def finish_pending_delete(self, path, error=None): call = self.calls.get(path) pending = call and call.get('pending_delete') @@ -383,6 +405,8 @@ def finish_pending_delete(self, path, error=None): pending['reply'].ok() def delete_call(self, path): + if path in self.calls: + self.end_release(self.calls[path]) call = self.calls.pop(path) if call['sid']: self.sitd_calls.pop(call['sid'], None) @@ -574,18 +598,17 @@ def handle_voice(self, method, args, reply): def release_timeout(): if path in self.calls and self.calls[path].get('pending_delete') is pending: pending['timer'] = 0 - call['releasing'] = False self.finish_pending_delete(path, MMError('Failed', 'Call release was not confirmed')) return False pending['timer'] = GLib.timeout_add_seconds(20, release_timeout) if call['releasing']: return - call['releasing'] = True + self.start_release(call) def hung(result, error): if error is not None and self.calls.get(path) is call: - call['releasing'] = False + self.end_release(call) self.finish_pending_delete(path, sitd_error(error)) return self.link.request('hangup', hung, id=call['sid']) if call['sid']: @@ -597,10 +620,14 @@ def hung(result, error): raise MMError('InProgress', 'A call is being placed') live = [(path, c) for path, c in self.calls.items() if c['sid'] and c['state'] in LIVE and not c['releasing']] + skipped = [path for path, c in self.calls.items() + if c['sid'] and c['state'] in LIVE and c['releasing']] for path, c in self.calls.items(): if not c['sid'] and c['state'] == mm.CALL_UNKNOWN: self.call_state(path, mm.CALL_TERMINATED, 'terminated') failures = [] + if skipped: + failures.append(MMError('InProgress', 'Call release is already in progress')) def next_hangup(): while live: @@ -608,14 +635,14 @@ def next_hangup(): if (self.calls.get(path) is not call or call['state'] not in LIVE or call['releasing']): continue - call['releasing'] = True + self.start_release(call) def hung(result, error, path=path, call=call): if error is not None: failure = sitd_error(error) failures.append(failure) if self.calls.get(path) is call: - call['releasing'] = False + self.end_release(call) self.finish_pending_delete(path, failure) next_hangup() return self.link.request('hangup', hung, id=call['sid']) @@ -666,11 +693,11 @@ def dialled(result, error): return reply.ok() if call['releasing']: raise MMError('InProgress', 'Call release is already in progress') - call['releasing'] = True + self.start_release(call) def hung(result, error): if error is not None and self.calls.get(path) is call: - call['releasing'] = False + self.end_release(call) self.finish_pending_delete(path, sitd_error(error)) self.answer(reply)(result, error) return self.link.request('hangup', hung, id=call['sid']) diff --git a/packages/omamobile-mmd/test/test_bridge.py b/packages/omamobile-mmd/test/test_bridge.py index 2f43dcd88..52d334985 100644 --- a/packages/omamobile-mmd/test/test_bridge.py +++ b/packages/omamobile-mmd/test/test_bridge.py @@ -425,7 +425,8 @@ def test_hangup_all_does_not_repeat_a_pending_release(self): self.push() path = wait_until(lambda: self.modem('Calls', mm.VOICE), 5, 'live call')[0] self.client.call(path, mm.CALL, 'Hangup') - self.client.call(MODEM0, mm.VOICE, 'HangupAll') + # a release is outstanding: HangupAll sends nothing and says so + self.assertEqual(self.error_of(MODEM0, mm.VOICE, 'HangupAll'), mm.ERROR_PREFIX + 'InProgress') self.assertEqual(self.sitd.actions().count('hangup'), 1) def test_refused_hangup_reports_error_and_a_new_press_tries_again(self): @@ -445,10 +446,33 @@ def refuse(request): self.assertEqual(self.error_of(MODEM0, mm.VOICE, 'HangupAll'), mm.ERROR_PREFIX + 'Failed') self.assertEqual(self.sitd.actions().count('hangup'), 3) self.assertEqual(self.modem('Calls', mm.VOICE), [path]) - # and once sitd takes it, the call ends + # and once sitd takes it, the call ends: sitd reports the release and the object goes self.sitd.handlers['hangup'] = lambda request: {} self.client.call(path, mm.CALL, 'Hangup') self.assertEqual(self.sitd.actions().count('hangup'), 4) + self.sitd.status['calls'] = [call('200', 'terminated', reason='terminated')] + self.push() + wait_until(lambda: self.client.prop(path, mm.CALL, 'State') == mm.CALL_TERMINATED, 5, 'terminated') + self.client.call(MODEM0, mm.VOICE, 'DeleteCall', 'o', (path,)) + self.sitd.status['calls'] = [] + self.push() + wait_until(lambda: self.modem('Calls', mm.VOICE) == [], 5, 'call gone') + + def test_unconfirmed_hangup_blocks_for_20_s_then_a_new_press_tries_again(self): + # sitd answers Hangup as soon as it has sent the release; if the call + # never ends, a second press is InProgress for 20 s, then a new attempt + self.sitd.status['calls'] = [call('200', 'active')] + self.sitd.handlers['hangup'] = lambda request: {} + self.push() + path = wait_until(lambda: self.modem('Calls', mm.VOICE), 5, 'live call')[0] + self.client.call(path, mm.CALL, 'Hangup') + self.assertEqual(self.error_of(path, mm.CALL, 'Hangup'), mm.ERROR_PREFIX + 'InProgress') + self.assertEqual(self.error_of(MODEM0, mm.VOICE, 'HangupAll'), mm.ERROR_PREFIX + 'InProgress') + self.assertEqual(self.sitd.actions().count('hangup'), 1) + spin(21) + self.client.call(path, mm.CALL, 'Hangup') + self.assertEqual(self.sitd.actions().count('hangup'), 2) + self.assertEqual(self.modem('Calls', mm.VOICE), [path]) def test_pending_delete_fails_when_prior_hangup_is_refused(self): for method in ('Hangup', 'HangupAll'): From a9d01a0e33bcc055d7cf3960ed3d169b5af672cd Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Mon, 9 Nov 2026 16:53:49 -0643 Subject: [PATCH 6/7] omamobile-mmd 0.1.4: a version past main's after the merge --- packages/omamobile-mmd/version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/omamobile-mmd/version b/packages/omamobile-mmd/version index b1e80bb24..845639eef 100644 --- a/packages/omamobile-mmd/version +++ b/packages/omamobile-mmd/version @@ -1 +1 @@ -0.1.3 +0.1.4 From 31be8e6e07822b8141028405867a913355755f1d Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Mon, 9 Nov 2026 18:56:39 -0643 Subject: [PATCH 7/7] omamobile-mmd: say what the release window meets with today's sitd, and test it With today's sitd a hang-up whose call never ends doesn't reach the bridge's 20 s window: sitd's own 12 s deadline turns the radio off and stops it for an attended reboot, the bridge withdraws the modem with its calls, and the next press finds no call object, so the modem never gets a second hang-up. The window is for a sitd that stays up. The comment and the two tests whose stand-in sitd stays up now say so, and a new test stops the stand-in after the first hang-up. --- packages/omamobile-mmd/lib/bridge.py | 13 +++++++---- packages/omamobile-mmd/test/test_bridge.py | 25 ++++++++++++++++++++-- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/packages/omamobile-mmd/lib/bridge.py b/packages/omamobile-mmd/lib/bridge.py index 8ceadbfe9..b02e80f3a 100644 --- a/packages/omamobile-mmd/lib/bridge.py +++ b/packages/omamobile-mmd/lib/bridge.py @@ -368,10 +368,15 @@ def call_state(self, path, state, sitd_reason): def start_release(self, call): """One hang-up outstanding at a time, for 20 s at most: sitd answers - the request as soon as it has sent the release, and its own deadline - then turns the radio off and keeps the call, so a release that is - accepted but never completes must not block the user's next press. - The bridge never retries on its own.""" + the request as soon as it has sent the release, so a release that is + accepted but never completes must not block the user's next press + for good. With today's sitd the window never runs out that way: when + the call is still there 12 s after the hang-up, sitd turns the radio + off and stops for an attended reboot (unconfirmed_release in + omamobile-modem-sit), the bridge withdraws the modem with its calls, + and the next press finds no call, an error rather than a second + hang-up at the modem. The window is for a sitd that stays up. The + bridge never retries on its own.""" call['releasing'] = True if call.get('release_timer'): GLib.source_remove(call['release_timer']) diff --git a/packages/omamobile-mmd/test/test_bridge.py b/packages/omamobile-mmd/test/test_bridge.py index 52d334985..70349e383 100644 --- a/packages/omamobile-mmd/test/test_bridge.py +++ b/packages/omamobile-mmd/test/test_bridge.py @@ -460,7 +460,9 @@ def refuse(request): def test_unconfirmed_hangup_blocks_for_20_s_then_a_new_press_tries_again(self): # sitd answers Hangup as soon as it has sent the release; if the call - # never ends, a second press is InProgress for 20 s, then a new attempt + # never ends and sitd stays up, a second press is InProgress for 20 s, + # then a new attempt. The stand-in sitd here stays up; today's real + # one stops at its own 12 s deadline (the next test). self.sitd.status['calls'] = [call('200', 'active')] self.sitd.handlers['hangup'] = lambda request: {} self.push() @@ -474,6 +476,24 @@ def test_unconfirmed_hangup_blocks_for_20_s_then_a_new_press_tries_again(self): self.assertEqual(self.sitd.actions().count('hangup'), 2) self.assertEqual(self.modem('Calls', mm.VOICE), [path]) + def test_unconfirmed_hangup_then_sitd_stops_takes_the_modem_and_the_call_away(self): + # What today's sitd does when the call never ends: at its own 12 s + # deadline it turns the radio off and stops for an attended reboot + # (unconfirmed_release in omamobile-modem-sit), before the bridge's + # 20 s window is over. The bridge then withdraws the modem with its + # calls, so the next press finds no call object: an error, not + # InProgress for good, and no second hang-up reaches the modem. + self.sitd.status['calls'] = [call('200', 'active')] + self.sitd.handlers['hangup'] = lambda request: {} + self.push() + path = wait_until(lambda: self.modem('Calls', mm.VOICE), 5, 'live call')[0] + self.client.call(path, mm.CALL, 'Hangup') + self.assertEqual(self.error_of(path, mm.CALL, 'Hangup'), mm.ERROR_PREFIX + 'InProgress') + self.sitd.stop() + wait_until(lambda: not self.client.objects(), 5, 'the modem withdrawn') + self.assertEqual(self.error_of(path, mm.CALL, 'Hangup'), 'org.freedesktop.DBus.Error.UnknownMethod') + self.assertEqual(self.sitd.actions().count('hangup'), 1) + def test_pending_delete_fails_when_prior_hangup_is_refused(self): for method in ('Hangup', 'HangupAll'): with self.subTest(method=method): @@ -523,7 +543,8 @@ def test_unconfirmed_release_times_out_without_deleting_or_retrying(self): self.assertEqual(self.modem('Calls', mm.VOICE), [path]) self.assertEqual(self.client.prop(path, mm.CALL, 'State'), mm.CALL_ACTIVE) self.assertEqual(self.sitd.actions().count('hangup'), 1) - # after the timeout a new press from the user is a new attempt + # after the timeout a new press from the user is a new attempt (with a + # sitd that is still up; today's has stopped by then) self.client.call(path, mm.CALL, 'Hangup') self.assertEqual(self.sitd.actions().count('hangup'), 2)