Add Dual-SIM Dual Standby (DSDS), outgoing SIM selection, and instant charging icon update

This commit is contained in:
Luxferre committed 2026-10-27 11:36:00 +02:00
1 parent 5132deb4d8
commit 46f1255905
28 files changed
+2560 -280

No files matched your search

+54 -6
View File
@@ -14,17 +14,24 @@ mkdir -p "$XDG_RUNTIME_DIR/sxmo_calls"
set -e
vid_to_number() {
mmcli -m any -o "$1" -K | \
grep call.properties.number | \
cut -d ':' -f2 | \
tr -d ' '
case "$1" in
sub1_*|sub0_*)
doas -n /usr/libexec/msm-modem-uim-selection call-list 2>/dev/null | awk -F'\t' -v id="$1" '$1 == id {print $4; exit}'
;;
*)
mmcli -m any -o "$1" -K 2>/dev/null | \
grep call.properties.number | \
cut -d ':' -f2 | \
tr -d ' '
;;
esac
}
log_event() {
EVT_HANDLE="$1"
EVT_VID="$2"
NUM="$(vid_to_number "$EVT_VID")"
NUM="$(vid_to_number "$EVT_VID" 2>/dev/null || true)"
TIME="$(date +%FT%H:%M:%S%z)"
mkdir -p "$SXMO_LOGDIR"
@@ -35,6 +42,22 @@ pickup() {
CALLID="$1"
NUM="$(vid_to_number "$CALLID" 2>/dev/null || true)"
case "$CALLID" in
sub1_*|sub0_*)
sxmo_log "Invoking pickup hook for $CALLID"
sxmo_hook_pickup.sh || true
doas -n dbus-send --system --type=signal / org.ofono.VoiceCallManager.CallAdded >/dev/null 2>&1 || true
sxmo_modemaudio.sh setup_audio || true
doas -n /usr/libexec/msm-modem-uim-selection call-accept "$CALLID" >/dev/null 2>&1 || \
/usr/libexec/msm-modem-uim-selection call-accept "$CALLID" >/dev/null 2>&1 || true
touch "$XDG_RUNTIME_DIR/sxmo_calls/${CALLID}.pickedupcall"
if command -v xcallscreen >/dev/null 2>&1; then
xcallscreen active "$CALLID" "$NUM" >/dev/null 2>&1 || true
fi
return 0
;;
esac
DIRECTION="$(
(mmcli -m any -o "$CALLID" -K 2>/dev/null || mmcli -o "$CALLID" -K 2>/dev/null || mmcli --voice-status -o "$CALLID" -K 2>/dev/null) |
grep call.properties.direction |
@@ -99,6 +122,18 @@ pickup() {
hangup() {
CALLID="$1"
case "$CALLID" in
sub1_*|sub0_*)
rm -f "$XDG_RUNTIME_DIR/sxmo_calls/${CALLID}."* 2>/dev/null || true
touch "$XDG_RUNTIME_DIR/sxmo_calls/${CALLID}.hangedupcall"
doas -n /usr/libexec/msm-modem-uim-selection call-hangup "$CALLID" >/dev/null 2>&1 || \
/usr/libexec/msm-modem-uim-selection call-hangup "$CALLID" >/dev/null 2>&1 || true
doas -n dbus-send --system --type=signal / org.ofono.VoiceCallManager.CallRemoved >/dev/null 2>&1 || true
sxmo_hook_hangup.sh || true
return 0
;;
esac
if [ -f "$XDG_RUNTIME_DIR/sxmo_calls/${CALLID}.pickedupcall" ] || \
[ -f "$XDG_RUNTIME_DIR/sxmo_calls/${CALLID}.initiatedcall" ]; then
@@ -129,7 +164,7 @@ hangup() {
# We shallow muted/blocked and terminated calls
list_active_calls() {
mmcli -m any --voice-list-calls | \
mmcli -m any --voice-list-calls 2>/dev/null | \
awk '$1=$1' | \
grep -v terminated | \
grep -v "No calls were found" | while read -r line; do
@@ -139,6 +174,19 @@ list_active_calls() {
fi
printf "%s\n" "$line"
done
for f in "$XDG_RUNTIME_DIR"/sxmo_calls/sub1_*.*; do
[ -e "$f" ] || continue
base="${f##*/}"
cid="${base%%.*}"
st="${base#*.}"
case "$st" in
ringing-in|dialing|ringing-out|active|held|waiting)
if [ ! -e "$XDG_RUNTIME_DIR/sxmo_calls/${cid}.mutedring" ]; then
printf "/org/freedesktop/ModemManager1/Call/%s (%s)\n" "$cid" "$st"
fi
;;
esac
done
}
incall_menu() {
+76 -4
View File
@@ -8,8 +8,25 @@
set -e
dial_number() {
REQ_SIM_SLOT="${SXMO_SIM_SLOT:-}"
if [ "${1:-}" = "--sim" ] && [ -n "${2:-}" ]; then
REQ_SIM_SLOT="$2"
shift 2
fi
resolve_sim_state() {
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}')"
DUAL_ACTIVE="$(printf "%s\n" "$UIM_ST" | awk -F= '/^DUAL_SIM_ACTIVE=/ {print $2; exit}')"
[ -n "$PRIM_SLOT" ] || PRIM_SLOT="1"
[ -n "$SEC_SLOT" ] || SEC_SLOT="0"
[ -n "$PREF_SLOT" ] || PREF_SLOT="$PRIM_SLOT"
[ -n "$DUAL_ACTIVE" ] || DUAL_ACTIVE="0"
}
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)."
@@ -21,6 +38,51 @@ dial_number() {
return 1
fi
resolve_sim_state
TARGET_SIM="$REQ_SIM_SLOT"
# If 2 SIMs are active and no SIM was chosen yet, prompt via xcallscreen
if [ -z "$TARGET_SIM" ] && [ "$DUAL_ACTIVE" = "1" ]; then
if [ -p "/tmp/dwm_plugin_callscreen.fifo" ] && command -v xcallscreen >/dev/null 2>&1; then
printf "PROMPT_SIM %s\n" "$NUMBER" > /tmp/dwm_plugin_callscreen.fifo 2>/dev/null || true
xcallscreen >/dev/null 2>&1 || true
return 0
fi
TARGET_SIM="$PREF_SLOT"
fi
[ -n "$TARGET_SIM" ] || TARGET_SIM="$PRIM_SLOT"
# Secondary GW SIM call via QMI VOICE sub=1
if [ "$TARGET_SIM" = "$SEC_SLOT" ] && [ "$SEC_SLOT" != "0" ]; then
sxmo_log "Attempting to dial on Secondary GW (SIM $TARGET_SIM): $NUMBER"
if [ -p "/tmp/dwm_plugin_callscreen.fifo" ]; then
printf "OUTGOING - %s SIM%s\n" "$NUMBER" "$TARGET_SIM" > /tmp/dwm_plugin_callscreen.fifo 2>/dev/null || true
fi
if command -v xcallscreen >/dev/null 2>&1; then
xcallscreen outgoing "-" "$NUMBER" >/dev/null 2>&1 || true
fi
if ! CALLID="$(doas -n /usr/libexec/msm-modem-uim-selection call-dial "$TARGET_SIM" "$NUMBER" 2>/dev/null || /usr/libexec/msm-modem-uim-selection call-dial "$TARGET_SIM" "$NUMBER" 2>/dev/null)"; 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 on SIM $TARGET_SIM"
return 1
fi
rm "$XDG_RUNTIME_DIR/sxmo_calls/$CALLID."* 2>/dev/null || true
touch "$XDG_RUNTIME_DIR/sxmo_calls/${CALLID}.initiatedcall"
doas -n dbus-send --system --type=signal / org.ofono.VoiceCallManager.CallAdded >/dev/null 2>&1 || true
sxmo_hook_dial.sh || true
sxmo_modemaudio.sh setup_audio || true
if [ -p "/tmp/dwm_plugin_callscreen.fifo" ]; then
printf "OUTGOING %s %s SIM%s\n" "$CALLID" "$NUMBER" "$TARGET_SIM" > /tmp/dwm_plugin_callscreen.fifo 2>/dev/null || true
elif command -v xcallscreen >/dev/null 2>&1; then
xcallscreen outgoing "$CALLID" "$NUMBER" >/dev/null 2>&1 || true
fi
sxmo_jobs.sh start proximity_lock sxmo_proximitylock.sh
sxmo_hook_statusbar.sh state &
return 0
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
@@ -28,7 +90,10 @@ dial_number() {
sleep 1
fi
sxmo_log "Attempting to dial: $NUMBER"
sxmo_log "Attempting to dial (SIM $TARGET_SIM): $NUMBER"
if [ -p "/tmp/dwm_plugin_callscreen.fifo" ]; then
printf "OUTGOING - %s SIM%s\n" "$NUMBER" "$TARGET_SIM" > /tmp/dwm_plugin_callscreen.fifo 2>/dev/null || true
fi
if command -v xcallscreen >/dev/null 2>&1; then
xcallscreen outgoing "-" "$NUMBER" >/dev/null 2>&1 || true
fi
@@ -48,7 +113,9 @@ dial_number() {
# 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
if [ -p "/tmp/dwm_plugin_callscreen.fifo" ]; then
printf "OUTGOING %s %s SIM%s\n" "$CALLID" "$NUMBER" "$TARGET_SIM" > /tmp/dwm_plugin_callscreen.fifo 2>/dev/null || true
elif command -v xcallscreen >/dev/null 2>&1; then
xcallscreen outgoing "$CALLID" "$NUMBER" >/dev/null 2>&1 || true
fi
@@ -82,7 +149,12 @@ dial_number() {
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)"
SIM_ARG=""
if [ -n "$REQ_SIM_SLOT" ]; then
SIM_ARG="--sim $REQ_SIM_SLOT"
fi
# shellcheck disable=SC2086
OUTPUT="$(doas -n /usr/libexec/msm-modem-uim-selection ussd initiate $SIM_ARG "$USSD" 2>/dev/null || /usr/libexec/msm-modem-uim-selection ussd initiate $SIM_ARG "$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"
@@ -46,6 +46,8 @@ mainloop() {
elif printf "%s\n" "$uim_st" | grep -qE "SLOT[12]_STATE=present" && printf "%s\n" "$uim_st" | grep -q "^PRIMARY_GW_SLOT=0$"; then
doas -n /usr/libexec/msm-modem-uim-selection boot >/dev/null 2>&1 || true
newstate="$(mmcli -m any -K 2>/dev/null | grep "^modem.generic.state " | cut -d':' -f2 | sed 's/^ //')"
elif printf "%s\n" "$uim_st" | grep -q "^SLOT1_STATE=present$" && printf "%s\n" "$uim_st" | grep -q "^SLOT2_STATE=present$" && printf "%s\n" "$uim_st" | grep -q "^SECONDARY_GW_SLOT=0$"; then
doas -n /usr/libexec/msm-modem-uim-selection boot >/dev/null 2>&1 || true
fi
if [ -n "$newstate" ]; then
@@ -55,6 +57,18 @@ mainloop() {
fi
) &
# Monitor Secondary GW SIM calls and SMS in Dual-SIM Dual Standby (DSDS)
(
while : ; do
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)"
if printf "%s\n" "$uim_st" | grep -q "^DUAL_SIM_ACTIVE=1$"; then
doas -n /usr/libexec/msm-modem-uim-selection dsds-daemon 2>/dev/null || \
/usr/libexec/msm-modem-uim-selection dsds-daemon 2>/dev/null || true
fi
sleep 5
done
) &
# Monitor for incoming calls
dbus-monitor --system "interface='org.freedesktop.ModemManager1.Modem.Voice',type='signal',member='CallAdded'" |
while read -r line; do
+209
View File
@@ -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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large. Load diff
@@ -1,76 +1,119 @@
#!/bin/sh
# configversion: d031535bc22ba19d69704317b8d50560
export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/10000}"
export DISPLAY="${DISPLAY:-:0}"
export PATH="/usr/share/sxmo/default_hooks:/usr/bin:/bin:/usr/sbin:/sbin:$PATH"
SET_LED_PATH="$XDG_RUNTIME_DIR/sxmo_hook_battery_set_led"
object="${1:-/org/freedesktop/UPower/devices/battery_default}"
event="${2:-device changed}"
if [ "${1:-}" = "udev" ]; then
object="/org/freedesktop/UPower/devices/battery_default"
event="device changed"
if [ "${2:-}" != "recheck" ]; then
(sleep 2; "$0" udev recheck >/dev/null 2>&1) &
fi
else
object="${1:-/org/freedesktop/UPower/devices/battery_default}"
event="${2:-device changed}"
fi
case "$event" in
"device changed") ;;
*) exit 0 ;;
"device changed") ;;
*) exit 0 ;;
esac
case "$object" in
*/battery_*)
raw_name="${object##*/battery_}"
;;
*)
exit 0
;;
*/battery_*)
raw_name="${object##*/battery_}"
;;
*)
exit 0
;;
esac
sysfs_dir=""
if [ -d "/sys/class/power_supply/$raw_name" ]; then
sysfs_dir="/sys/class/power_supply/$raw_name"
name="$raw_name"
sysfs_dir="/sys/class/power_supply/$raw_name"
name="$raw_name"
else
for d in /sys/class/power_supply/*; do
[ -r "$d/type" ] || continue
read -r pstype < "$d/type" 2>/dev/null || continue
if [ "$pstype" = "Battery" ]; then
sysfs_dir="$d"
name="${d##*/}"
break
fi
done
for d in /sys/class/power_supply/*; do
[ -r "$d/type" ] || continue
read -r pstype < "$d/type" 2>/dev/null || continue
if [ "$pstype" = "Battery" ]; then
sysfs_dir="$d"
name="${d##*/}"
break
fi
done
fi
if [ -n "$sysfs_dir" ] && [ -r "$sysfs_dir/capacity" ] && [ -r "$sysfs_dir/status" ]; then
read -r percentage < "$sysfs_dir/capacity" 2>/dev/null || percentage=""
read -r raw_status < "$sysfs_dir/status" 2>/dev/null || raw_status=""
case "$raw_status" in
"Full"|"full") state="fully-charged" ;;
"Charging"|"charging") state="charging" ;;
"Discharging"|"discharging"|"Not charging"|"not charging") state="discharging" ;;
*) state="unknown" ;;
esac
read -r percentage < "$sysfs_dir/capacity" 2>/dev/null || percentage=""
read -r raw_status < "$sysfs_dir/status" 2>/dev/null || raw_status=""
case "$raw_status" in
"Full"|"full") state="fully-charged" ;;
"Charging"|"charging") state="charging" ;;
"Discharging"|"discharging"|"Not charging"|"not charging") state="discharging" ;;
*) state="unknown" ;;
esac
else
exit 0
exit 0
fi
chgr_online=""
if [ -r "/sys/class/power_supply/pm8916-lbc-chgr/online" ]; then
read -r chgr_online < "/sys/class/power_supply/pm8916-lbc-chgr/online" 2>/dev/null || chgr_online=""
else
for d in /sys/class/power_supply/*; do
[ -r "$d/type" ] && [ -r "$d/online" ] || continue
read -r pstype < "$d/type" 2>/dev/null || continue
case "$pstype" in
USB*|Mains)
read -r chgr_online < "$d/online" 2>/dev/null || chgr_online=""
[ -n "$chgr_online" ] && break
;;
esac
done
fi
if [ "$chgr_online" = "1" ] && [ "$state" = "discharging" ]; then
case "$percentage" in
''|*[!0-9]*) state="charging" ;;
*)
if [ "$percentage" -ge 99 ]; then
state="fully-charged"
else
state="charging"
fi
;;
esac
elif [ "$chgr_online" = "0" ] && { [ "$state" = "charging" ] || [ "$state" = "fully-charged" ]; }; then
state="discharging"
fi
if [ -z "$name" ] || [ -z "$state" ] || [ -z "$percentage" ] || [ "$state" = "unknown" ]; then
exit 0
exit 0
fi
if [ -z "$SXMO_DISABLE_LEDS" ]; then
if [ "$percentage" -lt 25 ] && [ ! -f "$SET_LED_PATH" ]; then
touch "$SET_LED_PATH"
sxmo_led.sh set red 100
elif [ -f "$SET_LED_PATH" ]; then
rm "$SET_LED_PATH"
sxmo_led.sh set red 0
fi
if [ "$percentage" -lt 25 ] && [ ! -f "$SET_LED_PATH" ]; then
touch "$SET_LED_PATH"
sxmo_led.sh set red 100
elif [ -f "$SET_LED_PATH" ]; then
rm "$SET_LED_PATH"
sxmo_led.sh set red 0
fi
fi
CACHE_FILE="${XDG_RUNTIME_DIR:-/tmp}/sxmo_bat_state_${name}"
ICON_FILE="${XDG_RUNTIME_DIR:-/run/user/10000}/sxmo_status/${SXMO_STATUS_NAME:-default}/040-battery-icon-${name}"
NEW_VAL="${state}:${percentage}"
if [ -r "$CACHE_FILE" ] && [ -f "$ICON_FILE" ]; then
read -r OLD_VAL < "$CACHE_FILE" 2>/dev/null || OLD_VAL=""
if [ "$OLD_VAL" = "$NEW_VAL" ]; then
exit 0
fi
read -r OLD_VAL < "$CACHE_FILE" 2>/dev/null || OLD_VAL=""
if [ "$OLD_VAL" = "$NEW_VAL" ]; then
exit 0
fi
fi
printf '%s\n' "$NEW_VAL" > "$CACHE_FILE"