From 73a2813d761a4a50aef6ebeae390824f455d9ab0 Mon Sep 17 00:00:00 2001 From: Stacy Harper Date: Sun, 13 Feb 2022 19:47:23 +0100 Subject: [PATCH] Rework calls We need the recent -S (status) command to probe the real state of callaudiod. - Lot of cleanup and refactorisation Most of the code has been moved to a better place. The call audio setups, the pickup action and the incall menu now are three different things we can call individually. - Handle failures individually Every important task as the mmcli command or volume settings should warn a urgent message to the user if they failed. If we failed to setup audio, or to pickup the call then we dont even try to open the incall menu. - Made the incall_menu closeable and re-opennable You can close the incoming call menu and the incall menu and re-open them from any menu. To make this possible I moved some of the responsibilities to the modem monitor that trigger action after modem manager signals. We then check at this point if it was the last call and do some cleanup if so. - Initial work for concurrent calls Added some code to the hooks and the modem checkfinished and checkincoming calls to handle those cased. If you are in a call and someone else try to call you, we refresh the incall menu and new entries will allow you to switch calls. - The incall menu isnt sticked to one call This menu itself doesnt need a CALLID argument. It allow us to manage every active call. We should be able to hold and hangup and switch calls as we want. --- .../default_hooks/sxmo_hook_missed_call.sh | 8 +- configs/default_hooks/sxmo_hook_pickup.sh | 8 +- configs/default_hooks/sxmo_hook_ring.sh | 15 + .../sxmo_hook_screenoff.sh | 5 +- scripts/core/sxmo_appmenu.sh | 37 ++- scripts/core/sxmo_keyboard.sh | 6 +- scripts/modem/sxmo_modem.sh | 62 ++-- scripts/modem/sxmo_modemaudio.sh | 94 ++++++ scripts/modem/sxmo_modemcall.sh | 291 ++++++++---------- scripts/modem/sxmo_modemdial.sh | 44 ++- scripts/modem/sxmo_modemtext.sh | 2 +- 11 files changed, 355 insertions(+), 217 deletions(-) create mode 100644 scripts/modem/sxmo_modemaudio.sh diff --git a/configs/default_hooks/sxmo_hook_missed_call.sh b/configs/default_hooks/sxmo_hook_missed_call.sh index 1d4bf0e..1287a99 100644 --- a/configs/default_hooks/sxmo_hook_missed_call.sh +++ b/configs/default_hooks/sxmo_hook_missed_call.sh @@ -9,6 +9,8 @@ # $1 = Contact Name or Number (if not in contacts) # kill existing ring playback -MPVID="$(cat "$XDG_RUNTIME_DIR/sxmo.ring.pid")" -kill $MPVID -rm "$XDG_RUNTIME_DIR/sxmo.ring.pid" +if [ -e "$XDG_RUNTIME_DIR/sxmo.ring.pid" ]; then + MPVID="$(cat "$XDG_RUNTIME_DIR/sxmo.ring.pid")" + kill "$MPVID" + rm "$XDG_RUNTIME_DIR/sxmo.ring.pid" +fi diff --git a/configs/default_hooks/sxmo_hook_pickup.sh b/configs/default_hooks/sxmo_hook_pickup.sh index 89b309d..cf7d19d 100644 --- a/configs/default_hooks/sxmo_hook_pickup.sh +++ b/configs/default_hooks/sxmo_hook_pickup.sh @@ -5,7 +5,9 @@ # This script is executed (asynchronously) when you pick up an incoming call # kill existing ring playback -MPVID="$(cat "$XDG_RUNTIME_DIR/sxmo.ring.pid")" -kill $MPVID -rm "$XDG_RUNTIME_DIR/sxmo.ring.pid" +if [ -e "$XDG_RUNTIME_DIR/sxmo.ring.pid" ]; then + MPVID="$(cat "$XDG_RUNTIME_DIR/sxmo.ring.pid")" + kill "$MPVID" + rm "$XDG_RUNTIME_DIR/sxmo.ring.pid" +fi diff --git a/configs/default_hooks/sxmo_hook_ring.sh b/configs/default_hooks/sxmo_hook_ring.sh index 5c7dbbf..3290923 100644 --- a/configs/default_hooks/sxmo_hook_ring.sh +++ b/configs/default_hooks/sxmo_hook_ring.sh @@ -7,6 +7,21 @@ # $1 = Contact Name or Number (if not in contacts) +# Only vibrate if you already got an active call +if sxmo_modemcall.sh list_active_calls \ + | grep -v ringing-in \ + | grep -q .; then + sxmo_vibrate 1500 + exit +fi + +# Shallow if you have more than one ringing call +if ! sxmo_modemcall.sh list_active_calls \ + | grep -c ringing-in \ + | grep -q 1; then + exit +fi + # Start the mpv ring until another hook kill it or the max (10) is reached mpv --quiet --no-video --loop=10 /usr/share/sxmo/ring.ogg & MPVID=$! diff --git a/configs/default_hooks/three_button_touchscreen/sxmo_hook_screenoff.sh b/configs/default_hooks/three_button_touchscreen/sxmo_hook_screenoff.sh index 95d0897..c1308dc 100644 --- a/configs/default_hooks/three_button_touchscreen/sxmo_hook_screenoff.sh +++ b/configs/default_hooks/three_button_touchscreen/sxmo_hook_screenoff.sh @@ -25,7 +25,10 @@ case "$SXMO_WM" in dwm) # dmenu will grab input focus (i.e. power button) so kill it before going to # screenoff unless proximity lock is running (i.e. there's a phone call). - sxmo_daemons.sh running proximity_lock -q || sxmo_dmenu.sh close + if ! (sxmo_daemons.sh running proximity_lock -q || \ + sxmo_daemons.sh running calling_proximity_lock -q); then + sxmo_dmenu.sh close + fi ;; esac diff --git a/scripts/core/sxmo_appmenu.sh b/scripts/core/sxmo_appmenu.sh index 5c1c70f..42fcbf3 100755 --- a/scripts/core/sxmo_appmenu.sh +++ b/scripts/core/sxmo_appmenu.sh @@ -35,6 +35,29 @@ sxmo_type() { sxmo_type.sh -s 200 "$@" # dunno why this is necessary but it sucks without } +call_entries() { + shown_incall_menu= + sxmo_modemcall.sh list_active_calls | while read -r line; do + case "$line" in + *"(ringing-in)") + CALLID="$(printf %s "$line" | cut -d" " -f1 | xargs basename)" + NUMBER="$(sxmo_modemcall.sh vid_to_number "$CALLID")" + CONTACT="$(sxmo_contacts.sh --name "$NUMBER")" + + printf "%s Incoming call %s ^ 0 ^ sxmo_daemons.sh start incall_menu sxmo_modemcall.sh incoming_call_menu %s\n" \ + "$icon_phn" "$CONTACT" "$CALLID" + ;; + *) + [ -n "$shown_incall_menu" ] && continue + shown_incall_menu=1 + printf "%s Incall Menu ^ 0 ^ sxmo_daemons.sh start incall_menu sxmo_modemcall.sh incall_menu\n" \ + "$icon_phn" + ;; + esac + done + +} + getprogchoices() { RES="$(sxmo_hook_contextmenu.sh "$1")" if [ -n "$RES" ]; then @@ -53,16 +76,10 @@ getprogchoices() { fi fi - #shellcheck disable=SC2044 - for NOTIFFILE in $(find "$SXMO_NOTIFDIR" -name 'incomingcall*_notification'); do - NOTIFACTION="$(head -n1 "$NOTIFFILE")" - MESSAGE="$(tail -1 "$NOTIFFILE")" - CHOICES=" - $icon_phn $MESSAGE ^ 0 ^ $NOTIFACTION - $CHOICES - " - break - done + CHOICES=" + $(call_entries) + $CHOICES + " # Decorate menu at bottom w/ system menu entry if not system menu echo "$WINNAME" | grep -qv Sys && CHOICES=" diff --git a/scripts/core/sxmo_keyboard.sh b/scripts/core/sxmo_keyboard.sh index 5d266da..1ea9b5f 100755 --- a/scripts/core/sxmo_keyboard.sh +++ b/scripts/core/sxmo_keyboard.sh @@ -23,14 +23,16 @@ open() { close() { if [ -n "$KEYBOARD" ]; then # avoid killing everything ! - pkill -f "$KEYBOARD" + pkill "$KEYBOARD" fi } if [ "$1" = "toggle" ]; then close || open elif [ "$1" = "close" ]; then - close + if isopen; then + close + fi elif [ "$1" = "isopen" ]; then isopen || exit 1 else diff --git a/scripts/modem/sxmo_modem.sh b/scripts/modem/sxmo_modem.sh index a4fd8e5..84ce595 100644 --- a/scripts/modem/sxmo_modem.sh +++ b/scripts/modem/sxmo_modem.sh @@ -27,14 +27,6 @@ cleanupnumber() { echo "$1" } -lookupnumberfromcallid() { - VOICECALLID=$1 - mmcli -m any --voice-list-calls -o "$VOICECALLID" -K | - grep call.properties.number | - cut -d ':' -f 2 | - tr -d ' ' -} - checkforfinishedcalls() { #find all finished calls for FINISHEDCALLID in $( @@ -43,32 +35,36 @@ checkforfinishedcalls() { grep -oE "Call\/[0-9]+" | cut -d'/' -f2 ); do - FINISHEDNUMBER="$(lookupnumberfromcallid "$FINISHEDCALLID")" + FINISHEDNUMBER="$(sxmo_modemcall.sh vid_to_number "$FINISHEDCALLID")" FINISHEDNUMBER="$(cleanupnumber "$FINISHEDNUMBER")" mmcli -m any --voice-delete-call "$FINISHEDCALLID" - rm -f "$SXMO_NOTIFDIR/incomingcall_${FINISHEDCALLID}_notification"* #there may be multiple actionable notification for one call rm -f "$XDG_RUNTIME_DIR/${FINISHEDCALLID}.monitoredcall" + CONTACT="$(sxmo_contacts.sh --name "$FINISHEDNUMBER")" + [ "$CONTACT" = "???" ] && CONTACT="$FINISHEDNUMBER" + TIME="$(date +%FT%H:%M:%S%z)" mkdir -p "$SXMO_LOGDIR" if [ -f "$XDG_RUNTIME_DIR/${FINISHEDCALLID}.discardedcall" ]; then #this call was discarded + sxmo_notify_user.sh "Call with $CONTACT terminated" stderr "Discarded call from $FINISHEDNUMBER" printf %b "$TIME\tcall_finished\t$FINISHEDNUMBER\n" >> "$SXMO_LOGDIR/modemlog.tsv" elif [ -f "$XDG_RUNTIME_DIR/${FINISHEDCALLID}.pickedupcall" ]; then #this call was picked up - pkill -f sxmo_modemcall.sh + sxmo_notify_user.sh "Call with $CONTACT terminated" sxmo_hook_statusbar.sh volume stderr "Finished call from $FINISHEDNUMBER" printf %b "$TIME\tcall_finished\t$FINISHEDNUMBER\n" >> "$SXMO_LOGDIR/modemlog.tsv" elif [ -f "$XDG_RUNTIME_DIR/${FINISHEDCALLID}.hangedupcall" ]; then #this call was hung up by the user + sxmo_notify_user.sh "Call with $CONTACT terminated" stderr "Finished call from $FINISHEDNUMBER" printf %b "$TIME\tcall_finished\t$FINISHEDNUMBER\n" >> "$SXMO_LOGDIR/modemlog.tsv" elif [ -f "$XDG_RUNTIME_DIR/${FINISHEDCALLID}.initiatedcall" ]; then #this call was hung up by the contact - pkill -f sxmo_modemcall.sh + sxmo_notify_user.sh "Call with $CONTACT terminated" sxmo_hook_statusbar.sh volume stderr "Finished call from $FINISHEDNUMBER" printf %b "$TIME\tcall_finished\t$FINISHEDNUMBER\n" >> "$SXMO_LOGDIR/modemlog.tsv" @@ -79,14 +75,11 @@ checkforfinishedcalls() { else #this is a missed call # Add a notification for every missed call - pkill -f sxmo_modemcall.sh sxmo_hook_statusbar.sh volume stderr "Missed call from $FINISHEDNUMBER" printf %b "$TIME\tcall_missed\t$FINISHEDNUMBER\n" >> "$SXMO_LOGDIR/modemlog.tsv" - CONTACT="$(sxmo_contacts.sh --name "$FINISHEDNUMBER")" stderr "Invoking missed call hook (async)" - [ "$CONTACT" = "???" ] && CONTACT="$FINISHEDNUMBER" sxmo_hook_missed_call.sh "$CONTACT" & sxmo_notificationwrite.sh \ @@ -95,6 +88,21 @@ checkforfinishedcalls() { none \ "Missed $icon_phn $CONTACT" fi + + # If it was the last call + if ! sxmo_modemcall.sh list_active_calls | grep -q .; then + # Cleanup + sxmo_vibrate 1000 & + sxmo_daemons.sh stop incall_menu + sxmo_daemons.sh stop calling_proximity_lock + if ! sxmo_modemaudio.sh reset_audio; then + sxmo_notify_user.sh --urgency=critical "We failed to reset call audio" + fi + setsid -f sh -c 'sleep 2; sxmo_hook_statusbar.sh call_duration' + else + # Or refresh the menu + sxmo_daemons.sh start incall_menu sxmo_modemcall.sh incall_menu + fi done } @@ -112,7 +120,7 @@ checkforincomingcalls() { # Determine the incoming phone number stderr "Incoming Call..." - INCOMINGNUMBER=$(lookupnumberfromcallid "$VOICECALLID") + INCOMINGNUMBER=$(sxmo_modemcall.sh vid_to_number "$VOICECALLID") INCOMINGNUMBER="$(cleanupnumber "$INCOMINGNUMBER")" CONTACTNAME=$(sxmo_contacts.sh --name "$INCOMINGNUMBER") @@ -121,7 +129,6 @@ checkforincomingcalls() { stderr "BLOCKED call from number: $VOICECALLID" sxmo_modemcall.sh mute "$VOICECALLID" printf %b "$TIME\tcall_ring\t$INCOMINGNUMBER\n" >> "$SXMO_BLOCKDIR/modemlog.tsv" - rm -f "$SXMO_NOTIFDIR/incomingcall_${VOICECALLID}_notification"* else stderr "Invoking ring hook (async)" [ "$CONTACTNAME" = "???" ] && CONTACTNAME="$INCOMINGNUMBER" @@ -130,12 +137,21 @@ checkforincomingcalls() { mkdir -p "$SXMO_LOGDIR" printf %b "$TIME\tcall_ring\t$INCOMINGNUMBER\n" >> "$SXMO_LOGDIR/modemlog.tsv" - sxmo_notificationwrite.sh \ - "$SXMO_NOTIFDIR/incomingcall_${VOICECALLID}_notification" \ - "sxmo_modemcall.sh incomingcallmenu '$VOICECALLID'" \ - none \ - "Incoming $icon_phn $CONTACTNAME" & - sxmo_modemcall.sh incomingcallmenu "$VOICECALLID" & + # do not duplicate proximity lock if already running + if ! (sxmo_daemons.sh running proximity_lock -q || sxmo_daemons.sh running calling_proximity_lock -q); then + sxmo_daemons.sh start calling_proximity_lock sxmo_proximitylock.sh + fi + + # If we already got an active call + if sxmo_modemcall.sh list_active_calls \ + | grep -v ringing-in \ + | grep -q .; then + # Refresh the incall menu + sxmo_daemons.sh start incall_menu sxmo_modemcall.sh incall_menu + else + # Or fire the incomming call menu + sxmo_daemons.sh start incall_menu sxmo_modemcall.sh incoming_call_menu "$VOICECALLID" + fi stderr "Call from number: $INCOMINGNUMBER (VOICECALLID: $VOICECALLID)" fi diff --git a/scripts/modem/sxmo_modemaudio.sh b/scripts/modem/sxmo_modemaudio.sh new file mode 100644 index 0000000..f0d0985 --- /dev/null +++ b/scripts/modem/sxmo_modemaudio.sh @@ -0,0 +1,94 @@ +#!/bin/sh + +# shellcheck source=scripts/core/sxmo_common.sh +. sxmo_common.sh + +setup_audio() { + unmute_mic + enable_call_audio_mode + disable_speaker + + i=0 + while (! is_unmuted_mic) || (! is_call_audio_mode) || (! is_disabled_speaker); do + i=$((i+1)) + if [ "$i" -gt 5 ]; then + return 1 + fi + + sleep 0.2 + + unmute_mic + enable_call_audio_mode + disable_speaker + done +} + +reset_audio() { + mute_mic + disable_call_audio_mode + enable_speaker + + i=0 + while (! is_muted_mic) || (! is_default_audio_mode) || (! is_enabled_speaker); do + i=$((i+1)) + if [ "$i" -gt 5 ]; then + return 1 + fi + + sleep 0.2 + + mute_mic + disable_call_audio_mode + enable_speaker + done +} + +is_muted_mic() { + callaudiocli -S | grep -q "Mic muted: CALL_AUDIO_MIC_ON" +} + +is_unmuted_mic() { + callaudiocli -S | grep -q "Mic muted: CALL_AUDIO_MIC_OFF" +} + +mute_mic() { + callaudiocli -u 0 +} + +unmute_mic() { + callaudiocli -u 1 +} + +is_call_audio_mode() { + callaudiocli -S | grep -q "Selected mode: CALL_AUDIO_MODE_CALL" +} + +is_default_audio_mode() { + callaudiocli -S | grep -q "Selected mode: CALL_AUDIO_MODE_DEFAULT" +} + +enable_call_audio_mode() { + callaudiocli -m 1 +} + +disable_call_audio_mode() { + callaudiocli -m 0 +} + +is_enabled_speaker() { + callaudiocli -S | grep -q "Speaker enabled: CALL_AUDIO_SPEAKER_ON" +} + +is_disabled_speaker() { + callaudiocli -S | grep -q "Speaker enabled: CALL_AUDIO_SPEAKER_OFF" +} + +enable_speaker() { + callaudiocli -s 1 +} + +disable_speaker() { + callaudiocli -s 0 +} + +"$@" diff --git a/scripts/modem/sxmo_modemcall.sh b/scripts/modem/sxmo_modemcall.sh index 3a46bb5..95d9c98 100644 --- a/scripts/modem/sxmo_modemcall.sh +++ b/scripts/modem/sxmo_modemcall.sh @@ -2,50 +2,13 @@ # SPDX-License-Identifier: AGPL-3.0-only # Copyright 2022 Sxmo Contributors -trap "gracefulexit" INT TERM - # include common definitions # shellcheck source=configs/default_hooks/sxmo_hook_icons.sh . sxmo_hook_icons.sh # shellcheck source=scripts/core/sxmo_common.sh -. "$(dirname "$0")/sxmo_common.sh" +. sxmo_common.sh -AUDIO_MODE= -ENABLED_SPEAKER= -MUTED_MIC= - -stderr() { - sxmo_log "$*" -} - -finish() { - sxmo_vibrate 1000 & - setsid -f sh -c 'sleep 2; sxmo_hook_statusbar.sh call_duration' - if [ -n "$1" ]; then - stderr "$1" - notify-send Call "$1" - fi - if [ -z "$LOCKALREADYRUNNING" ]; then - sxmo_daemons.sh stop proximity_lock - fi - sxmo_dmenu.sh close - exit 1 -} - -gracefulexit() { - kill "$MAINPID" - wait "$MAINPID" - finish "Call ended" -} - - -modem_cmd_errcheck() { - RES="$(mmcli "$@" 2>&1)" - OK="$?" - stderr "Command: mmcli $*" - if [ "$OK" != 0 ]; then finish "Problem executing mmcli command!\n$RES"; fi - echo "$RES" -} +set -e vid_to_number() { mmcli -m any -o "$1" -K | \ @@ -57,15 +20,17 @@ vid_to_number() { log_event() { EVT_HANDLE="$1" EVT_VID="$2" + NUM="$(vid_to_number "$EVT_VID")" TIME="$(date +%FT%H:%M:%S%z)" + mkdir -p "$SXMO_LOGDIR" printf %b "$TIME\t$EVT_HANDLE\t$NUM\n" >> "$SXMO_LOGDIR/modemlog.tsv" } -acceptcall() { +pickup() { CALLID="$1" - stderr "Attempting to initialize CALLID $CALLID" + DIRECTION="$( mmcli --voice-status -o "$CALLID" -K | grep call.properties.direction | @@ -74,133 +39,131 @@ acceptcall() { )" case "$DIRECTION" in outgoing) - modem_cmd_errcheck -m any -o "$CALLID" --start - touch "$XDG_RUNTIME_DIR/${CALLID}.initiatedcall" #this signals that we started this call + if ! mmcli -m any -o "$CALLID" --start; then + sxmo_notify_user.sh --urgency=critical "We failed to start the call" + return 1 + fi + + sxmo_notify_user.sh "Started call" + touch "$XDG_RUNTIME_DIR/${CALLID}.initiatedcall" log_event "call_start" "$CALLID" - stderr "Started call $CALLID" ;; incoming) - stderr "Invoking pickup hook (async)" + sxmo_log "Invoking pickup hook (async)" sxmo_hook_pickup.sh & - touch "$XDG_RUNTIME_DIR/${CALLID}.pickedupcall" #this signals that we picked this call up - #to other asynchronously running processes - modem_cmd_errcheck -m any -o "$CALLID" --accept + + if ! mmcli -m any -o "$CALLID" --accept; then + sxmo_notify_user.sh --urgency=critical "We failed to accept the call" + return 1 + fi + + sxmo_notify_user.sh "Picked up call" + touch "$XDG_RUNTIME_DIR/${CALLID}.pickedupcall" log_event "call_pickup" "$CALLID" - stderr "Picked up call $CALLID" ;; *) - finish "Couldn't initialize call with callid <$CALLID>; unknown direction <$DIRECTION>" + sxmo_notify_user.sh --urgency=critical "Couldn't initialize call with callid <$CALLID>; unknown direction <$DIRECTION>" ;; esac - - unmute_mic - enable_call_audio_mode - disable_speaker } hangup() { CALLID="$1" - disable_call_audio_mode - enable_speaker - if [ -f "$XDG_RUNTIME_DIR/${CALLID}.pickedupcall" ]; then rm -f "$XDG_RUNTIME_DIR/${CALLID}.pickedupcall" - touch "$XDG_RUNTIME_DIR/${CALLID}.hangedupcall" #this signals that we hanged up this call to other asynchronously running processes + touch "$XDG_RUNTIME_DIR/${CALLID}.hangedupcall" log_event "call_hangup" "$CALLID" else #this call was never picked up and hung up immediately, so it is a discarded call - touch "$XDG_RUNTIME_DIR/${CALLID}.discardedcall" #this signals that we discarded this call to other asynchronously running processes - stderr "sxmo_modemcall: Invoking discard hook (async)" - sxmo_hook_discard.sh & + touch "$XDG_RUNTIME_DIR/${CALLID}.discardedcall" log_event "call_discard" "$CALLID" + + sxmo_log "sxmo_modemcall: Invoking discard hook (async)" + sxmo_hook_discard.sh & + fi + + if ! mmcli -m any -o "$CALLID" --hangup; then + sxmo_notify_user.sh --urgency=critical "We failed to hangup the call" + return 1 fi - modem_cmd_errcheck -m any -o "$CALLID" --hangup - finish "Call with $NUMBER terminated" - exit 0 } -muted_mic() { - [ "$MUTED_MIC" -eq 1 ] +# We shallow muted/blocked and terminated calls +list_active_calls() { + mmcli -m any --voice-list-calls | \ + awk '$1=$1' | \ + grep -v terminated | \ + grep -v "No calls were found" | while read -r line; do + CALLID="$(printf "%s\n" "$line" | awk '$1=$1' | cut -d" " -f1 | xargs basename)" + if [ -e "$XDG_RUNTIME_DIR/${CALLID}.mutedring" ]; then + continue # we shallow muted calls + fi + printf "%s\n" "$line" + done } -mute_mic() { - callaudiocli -u 0 - MUTED_MIC=1 -} - -unmute_mic() { - callaudiocli -u 1 - MUTED_MIC=0 -} - -is_call_audio_mode() { - [ call = "$AUDIO_MODE" ] -} - -enable_call_audio_mode() { - callaudiocli -m 1 - AUDIO_MODE=call -} - -disable_call_audio_mode() { - callaudiocli -m 0 - AUDIO_MODE=default -} - -enabled_speaker() { - [ "$ENABLED_SPEAKER" -eq 1 ] -} - -enable_speaker() { - callaudiocli -s 1 - ENABLED_SPEAKER=1 -} - -disable_speaker() { - callaudiocli -s 0 - ENABLED_SPEAKER=0 -} - -incallmenuloop() { - DMENUIDX=0 - NUMBER="$(vid_to_number "$1")" - export AUDIO_BACKEND=alsa # We cant control volume with pulse - while : ; do +incall_menu() { + # We have an active call + while list_active_calls | grep -q . ; do CHOICES="$(cat </dev/null # we cleanup all dangling event files + sxmo_log "Starting call with CALLID: $CALLID" - exec sxmo_modemcall.sh pickup "$CALLID" + + if ! sxmo_modemaudio.sh setup_audio; then + sxmo_notify_user.sh --urgency=critical "We failed to setup call audio" + return 1 + fi + + if ! sxmo_modemcall.sh pickup "$CALLID"; then + sxmo_modemaudio.sh reset_audio + return 1 + fi + + # do not duplicate proximity lock if already running + if ! sxmo_daemons.sh running proximity_lock -q; then + sxmo_daemons.sh start calling_proximity_lock sxmo_proximitylock.sh + fi + + sxmo_daemons.sh start incall_menu sxmo_modemcall.sh incall_menu } -dialmenu() { +dial_menu() { # Initial menu with recently contacted people NUMBER="$( cat <