Add Dual-SIM Dual Standby (DSDS), outgoing SIM selection, and instant charging icon update
This commit is contained in:
1 parent
5132deb4d8
commit
46f1255905
28 files changed
+2560
-280
No files matched your search
Executable
+209
@@ -0,0 +1,209 @@
|
||||
#!/bin/sh
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
# Copyright 2022 Sxmo Contributors
|
||||
# shellcheck disable=SC3045
|
||||
|
||||
# include common definitions
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. sxmo_common.sh
|
||||
|
||||
info() {
|
||||
sxmo_log "$*"
|
||||
printf "%s\n" "$*"
|
||||
}
|
||||
|
||||
err() {
|
||||
info "$*"
|
||||
exit 1
|
||||
}
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s [--sim <1|2>] number|contact [-|message]\n" "$(basename "$0")"
|
||||
exit 1
|
||||
}
|
||||
|
||||
REQ_SIM_SLOT="${SXMO_SIM_SLOT:-}"
|
||||
if [ "${1:-}" = "--sim" ] && [ -n "${2:-}" ]; then
|
||||
REQ_SIM_SLOT="$2"
|
||||
shift 2
|
||||
fi
|
||||
|
||||
[ 0 -eq $# ] && usage
|
||||
NUMBER="$1"
|
||||
|
||||
make_attachments_arg() {
|
||||
LOGDIRNUM="$1"
|
||||
MAX_SIZE="$(grep "^TotalMaxAttachmentSize" "$MMS_BASE_DIR/mms" | cut -d'=' -f2)"
|
||||
MAX_NUMBER="$(grep "^MaxAttachments" "$MMS_BASE_DIR/mms" | cut -d'=' -f2)"
|
||||
[ -z "$MAX_NUMBER" ] && MAX_NUMBER="25"
|
||||
[ -z "$MAX_SIZE" ] && MAX_SIZE="1100000"
|
||||
|
||||
ATT_NUM=0
|
||||
TOTAL_SIZE=0
|
||||
while read -r ATTACHMENT; do
|
||||
[ -f "$ATTACHMENT" ] || err "Attachment ($ATTACHMENT) not found!"
|
||||
CTYPE=$(file -b --mime-type "$ATTACHMENT")
|
||||
case "$CTYPE" in
|
||||
"audio/mpegapplication/octet-stream")
|
||||
CTYPE="audio/mpeg"
|
||||
;;
|
||||
esac
|
||||
|
||||
ATT_NUM="$((ATT_NUM+1))"
|
||||
TOTAL_SIZE="$((TOTAL_SIZE+$(wc -c < "$ATTACHMENT")))"
|
||||
if [ "$ATT_NUM" -gt "$MAX_NUMBER" ]; then
|
||||
err "Number of attachments ($ATT_NUM) greater than MaxAttachments ($MAX_NUMBER)."
|
||||
fi
|
||||
if [ "$ATT_NUM" -ge 1 ] && [ "$TOTAL_SIZE" -gt "$MAX_SIZE" ]; then
|
||||
err "Total size of attachments ($TOTAL_SIZE) greater than TotalMaxAttachmentSize ($MAX_SIZE)."
|
||||
fi
|
||||
printf " %s '%s' -c '%s'" "-a" "$ATTACHMENT" "$CTYPE"
|
||||
done < "$SXMO_LOGDIR/$LOGDIRNUM/draft.attachments.txt"
|
||||
}
|
||||
|
||||
if ! echo "$NUMBER" | grep -q '^+'; then
|
||||
ACTUAL_NUMBER="$(sxmo_contacts.sh --all | grep "^$NUMBER:" | cut -d':' -f2 | sed 's/^ //')"
|
||||
if [ -z "$ACTUAL_NUMBER" ]; then
|
||||
info "WARNING: $NUMBER does not look like a phone number or a contact."
|
||||
else
|
||||
NUMBER="$ACTUAL_NUMBER"
|
||||
fi
|
||||
fi
|
||||
|
||||
finish() {
|
||||
if [ -n "$TMPFILE" ]; then
|
||||
rm "$TMPFILE"
|
||||
fi
|
||||
exit
|
||||
}
|
||||
trap 'finish' INT TERM EXIT
|
||||
|
||||
if [ "-" = "$2" ]; then
|
||||
TMPFILE="$(mktemp)"
|
||||
TEXTFILE="$TMPFILE"
|
||||
cat > "$TEXTFILE"
|
||||
elif [ "-f" = "$2" ]; then
|
||||
TMPFILE="$(mktemp)"
|
||||
awk 'NR > 1 { print prev } { prev=$0 } END { ORS=""; print }' "$3" > "$TMPFILE"
|
||||
TEXTFILE="$TMPFILE"
|
||||
else
|
||||
shift
|
||||
[ 0 -eq $# ] && usage
|
||||
|
||||
TMPFILE="$(mktemp)"
|
||||
TEXTFILE="$TMPFILE"
|
||||
printf "%s" "$*" > "$TEXTFILE"
|
||||
fi
|
||||
TEXT="$(cat "$TEXTFILE")"
|
||||
|
||||
# if multiple recipients or attachment, then send via mmsctl
|
||||
if [ "$(printf %s "$NUMBER" | xargs pnc find | wc -l)" -gt 1 ] || [ -f "$SXMO_LOGDIR/$NUMBER/draft.attachments.txt" ]; then
|
||||
|
||||
MMS_BASE_DIR="${SXMO_MMS_BASE_DIR:-"$HOME"/.mms/modemmanager}"
|
||||
[ -d "$MMS_BASE_DIR" ] || err "MMS not configured."
|
||||
|
||||
NUMBER="$(printf %s "$NUMBER" | xargs pnc find | sort -u | grep . | xargs printf %s)"
|
||||
[ -f "$SXMO_LOGDIR/$NUMBER/draft.attachments.txt" ] && ATTACHMENTS_ARG="$(make_attachments_arg "$NUMBER" | sed 's/^ //')"
|
||||
ATTACHMENTS_ARG="-a '$TEXTFILE' $ATTACHMENTS_ARG"
|
||||
RECIPIENTS_ARG="$(printf %s "$NUMBER" | sed 's/+/ -r +/g' | sed 's/^ //')"
|
||||
|
||||
info "mmsctl -S $RECIPIENTS_ARG $ATTACHMENTS_ARG"
|
||||
MMSCTL_RES="$(eval mmsctl -S "$RECIPIENTS_ARG" "$ATTACHMENTS_ARG")"
|
||||
MMSCTL_OK="$?"
|
||||
[ "$MMSCTL_OK" -ne 0 ] && err "mmsctl failed with \"$MMSCTL_RES\""
|
||||
|
||||
info "Waiting for mmsd-tng to send..."
|
||||
MMS_PIPE="$(mktemp -u)"
|
||||
mkfifo "$MMS_PIPE"
|
||||
timeout 60 dbus-monitor "interface='org.ofono.mms.Message',type='signal',member='PropertyChanged'" > "$MMS_PIPE" &
|
||||
MMS_PIPE_PID="$!"
|
||||
while read -r line; do
|
||||
if printf %s "$line" | grep -q 'member=PropertyChanged'; then
|
||||
MESSAGE_PATH="$(echo "$line" | cut -d'=' -f6 | cut -d';' -f1)"
|
||||
fi
|
||||
if printf %s "$line" | grep -q "string \"sent\""; then
|
||||
SENT_SUCCESS=1
|
||||
break
|
||||
fi
|
||||
done < "$MMS_PIPE"
|
||||
rm -f "$MMS_PIPE"
|
||||
kill "$MMS_PIPE_PID"
|
||||
|
||||
[ -z "$SENT_SUCCESS" ] && err "mmsd-tng did not send the draft."
|
||||
|
||||
[ -f "$SXMO_LOGDIR/$NUMBER/draft.attachments.txt" ] && rm -f "$SXMO_LOGDIR/$NUMBER/draft.attachments.txt"
|
||||
|
||||
sxmo_mms.sh processmms "$MESSAGE_PATH"
|
||||
|
||||
MMS_FILE="$(basename "$MESSAGE_PATH")"
|
||||
CONTACTNAME="$(sxmo_contacts.sh --name-or-number "$NUMBER")"
|
||||
sxmo_hook_sendsms.sh "$CONTACTNAME" "$TEXT" "$MMS_FILE" "$CONTACTNAME"
|
||||
|
||||
info "Sent mms text to $CONTACTNAME."
|
||||
else
|
||||
TEXTSIZE="${#TEXT}"
|
||||
UIM_ST="$(doas -n /usr/libexec/msm-modem-uim-selection status 2>/dev/null || /usr/libexec/msm-modem-uim-selection status 2>/dev/null || true)"
|
||||
PRIM_SLOT="$(printf "%s\n" "$UIM_ST" | awk -F= '/^PRIMARY_GW_SLOT=/ {print $2; exit}')"
|
||||
SEC_SLOT="$(printf "%s\n" "$UIM_ST" | awk -F= '/^SECONDARY_GW_SLOT=/ {print $2; exit}')"
|
||||
PREF_SLOT="$(printf "%s\n" "$UIM_ST" | awk -F= '/^PREFERRED_SLOT=/ {print $2; exit}')"
|
||||
[ -n "$PRIM_SLOT" ] || PRIM_SLOT="1"
|
||||
[ -n "$SEC_SLOT" ] || SEC_SLOT="0"
|
||||
[ -n "$PREF_SLOT" ] || PREF_SLOT="$PRIM_SLOT"
|
||||
|
||||
TARGET_SIM="$REQ_SIM_SLOT"
|
||||
[ -n "$TARGET_SIM" ] || TARGET_SIM="$PREF_SLOT"
|
||||
|
||||
SENT_VIA_QMI=0
|
||||
if [ "$TARGET_SIM" = "$SEC_SLOT" ] && [ "$SEC_SLOT" != "0" ]; then
|
||||
if doas -n /usr/libexec/msm-modem-uim-selection sms-send "$TARGET_SIM" "$NUMBER" "$TEXTFILE" >/dev/null 2>&1 || \
|
||||
/usr/libexec/msm-modem-uim-selection sms-send "$TARGET_SIM" "$NUMBER" "$TEXTFILE" >/dev/null 2>&1; then
|
||||
SENT_VIA_QMI=1
|
||||
else
|
||||
err "Couldn't send text message via SIM $TARGET_SIM"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$SENT_VIA_QMI" = "0" ]; then
|
||||
SMSNO="$(
|
||||
mmcli -m any --messaging-create-sms-with-text="$TEXTFILE" --messaging-create-sms="number=$NUMBER" 2>/dev/null |
|
||||
grep -o "[0-9]*$" || true
|
||||
)"
|
||||
SMS_OK=1
|
||||
SMS_RES=""
|
||||
if [ -n "$SMSNO" ]; then
|
||||
SMS_RES="$(mmcli -s "${SMSNO}" --send --timeout="${SXMO_MM_TIMEOUT:-"30"}" 2>&1)" && SMS_OK=0 || SMS_OK=$?
|
||||
fi
|
||||
|
||||
if [ "$SMS_OK" != 0 ]; then
|
||||
# Fallback to direct QMI WMS RawSend on TARGET_SIM
|
||||
if doas -n /usr/libexec/msm-modem-uim-selection sms-send "$TARGET_SIM" "$NUMBER" "$TEXTFILE" >/dev/null 2>&1 || \
|
||||
/usr/libexec/msm-modem-uim-selection sms-send "$TARGET_SIM" "$NUMBER" "$TEXTFILE" >/dev/null 2>&1; then
|
||||
SMS_OK=0
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$SMS_OK" != 0 ]; then
|
||||
if echo "$SMS_RES" | grep -q "Invalid number"; then
|
||||
for i in $(mmcli -m any --messaging-list-sms | grep " (unknown)" | cut -f5 -d' '); do
|
||||
mmcli -m any -s "$i" -K | grep -q "not requested" && mmcli -m any --messaging-delete-sms="$i" >/dev/null
|
||||
done
|
||||
err "Couldn't send text message: Invalid number."
|
||||
else
|
||||
err "Couldn't send text message ($SMS_RES)"
|
||||
fi
|
||||
fi
|
||||
|
||||
for i in $(mmcli -m any --messaging-list-sms 2>/dev/null | grep " (sent)" | cut -f5 -d' ') ; do
|
||||
mmcli -m any --messaging-delete-sms="$i" > /dev/null 2>&1 || true
|
||||
done
|
||||
fi
|
||||
|
||||
TIME="$(date +%FT%H:%M:%S%z)"
|
||||
mkdir -p "$SXMO_LOGDIR/$NUMBER"
|
||||
sxmo_hook_smslog.sh "sent" "$NUMBER" "$NUMBER" "$TIME" "$TEXT" >> "$SXMO_LOGDIR/$NUMBER/sms.txt"
|
||||
printf "%s\tsent_txt\t%s\t[SIM %s] %s chars\n" "$TIME" "$NUMBER" "$TARGET_SIM" "$TEXTSIZE" >> "$SXMO_LOGDIR/modemlog.tsv"
|
||||
|
||||
CONTACTNAME="$(sxmo_contacts.sh --name-or-number "$NUMBER")"
|
||||
sxmo_hook_sendsms.sh "$CONTACTNAME" "$TEXT"
|
||||
info "Sent sms text to $CONTACTNAME (SIM $TARGET_SIM)."
|
||||
fi
|
||||
Reference in new issue
Block a user