#!/bin/sh # SPDX-License-Identifier: AGPL-3.0-only # Copyright 2022 Sxmo Contributors # include common definitions # shellcheck source=scripts/core/sxmo_common.sh . sxmo_common.sh set -e dial_number() { # on pinephone if you attempt to make a call while in a call, modem crashes if sxmo_modemcall.sh list_active_calls | grep -q .; then sxmo_notify_user.sh "Cannot make call while in a call (for now)." return 0 fi NUMBER="$(printf "%s" "$1" | tr -cd '+0-9*#')" if [ -z "$NUMBER" ]; then return 1 fi mm_state="$(mmcli -m any -K 2>/dev/null | awk -F':[[:space:]]*' '{gsub(/[[:space:]]+$/, "", $1); if ($1 == "modem.generic.state") {print $2; exit}}')" if [ "$mm_state" = "disabled" ] || [ -z "$mm_state" ]; then mmcli -m any -e >/dev/null 2>&1 || true mmcli -m any --3gpp-register-home >/dev/null 2>&1 || true sleep 1 fi sxmo_log "Attempting to dial: $NUMBER" if command -v xcallscreen >/dev/null 2>&1; then xcallscreen outgoing "-" "$NUMBER" >/dev/null 2>&1 || true fi if ! CALLID="$( mmcli -m any --voice-create-call="number=$NUMBER" 2>/dev/null | grep -Eo "Call/[0-9]+" | grep -oE "[0-9]+" )"; then if command -v xcallscreen >/dev/null 2>&1; then xcallscreen ended >/dev/null 2>&1 || true fi sxmo_notify_user.sh --urgency=critical "We failed to initiate call" return 1 fi # cleanup all dangling event files, ignore errors rm "$XDG_RUNTIME_DIR/sxmo_calls/$CALLID."* 2>/dev/null || true sxmo_log "Starting call with CALLID: $CALLID" if command -v xcallscreen >/dev/null 2>&1; then xcallscreen outgoing "$CALLID" "$NUMBER" >/dev/null 2>&1 || true fi sxmo_log "Invoking dial hook" sxmo_hook_dial.sh if ! sxmo_modemaudio.sh setup_audio; then if command -v xcallscreen >/dev/null 2>&1; then xcallscreen ended >/dev/null 2>&1 || true fi sxmo_notify_user.sh --urgency=critical "We failed to setup call audio" mmcli -m any --voice-delete-call="$CALLID" return 1 fi if ! sxmo_modemcall.sh pickup "$CALLID"; then if command -v xcallscreen >/dev/null 2>&1; then xcallscreen ended >/dev/null 2>&1 || true fi sxmo_modemaudio.sh reset_audio mmcli -m any --voice-delete-call="$CALLID" return 1 fi sxmo_jobs.sh start proximity_lock sxmo_proximitylock.sh sxmo_hook_statusbar.sh state & sxmo_jobs.sh start incall_menu sxmo_modemcall.sh incall_menu } dial_ussd() { USSD="$1" sxmo_log "Dialling USSD: $USSD" OUTPUT="$(doas -n /usr/libexec/msm-modem-uim-selection ussd initiate "$USSD" 2>/dev/null || /usr/libexec/msm-modem-uim-selection ussd initiate "$USSD" 2>/dev/null || true)" if [ -z "$OUTPUT" ]; then DBUS_MODEM="$(mmcli -J -L 2>/dev/null | jq -r '."modem-list"[]' 2>/dev/null | head -n1)" MM_BUS="org.freedesktop.ModemManager1" USSD_IFACE="org.freedesktop.ModemManager1.Modem.Modem3gpp.Ussd" if [ -n "$DBUS_MODEM" ]; then OUTPUT="$(busctl --json=short call "$MM_BUS" "$DBUS_MODEM" "$USSD_IFACE" Initiate "s" "$USSD" 2>/dev/null | jq -r '.data[]' 2>/dev/null || true)" fi fi if [ -n "$OUTPUT" ]; then sxmo_notify_user.sh "USSD ($USSD): $OUTPUT" else sxmo_notify_user.sh --urgency=critical "USSD request failed ($USSD)" fi } dial_menu() { if [ -n "${DISPLAY:-}" ] && command -v xdialer >/dev/null 2>&1; then exec xdialer fi # Initial menu with recently contacted people NUMBER="$( grep . <