Files
bananarchy/overlay/rootfs/usr/bin/sxmo_modemaudio.sh
T
Luxferre 36a5f8cb8a Fix Bluetooth 5.x/6.x headsets, Android OBEX prompts, and refresh a1120 images
- Scope WirePlumber 50-bluetooth.conf roles to [ a2dp_sink hsp_hs hfp_hf ], lock HFP to 8 kHz CVSD for QDSP6 INTERNAL_BT_SCO, enable dummy AVRCP player, and set LDAC ABR quality.
- Select BR/EDR bearer and ConnectProfile fallback for Classic Audio headsets while preserving LE bearer for HOGP devices, forward AVRCP media keys to music.so, bound discoverability to 60 s, fix SCO keepalive teardown/readiness and ATA call state sync, and suppress nokia-sparkler speaker haptic audio during BT SCO.
- Advertise Smartphone Class of Device (0x5a020c / btmgmt class 2 3), handle OBEX over both L2CAP SOCK_SEQPACKET and RFCOMM SOCK_STREAM via ObexPacketReader, and add NeoUI incoming file Accept/Reject dialog and configurable target folder picker in networks.so.
- Add scripts/test-bluetooth-headset.py and scripts/test-bluetooth-obex.py, and rebuild/pin verified a1120 (cocojamboo) images and release archives for nokia-argon, nokia-beatles, nokia-coconut, and nokia-sparkler.
2026-11-17 10:33:09 +02:00

168 lines
5.2 KiB
Bash
Executable File

#!/bin/sh
export PATH="${XDG_CONFIG_HOME:-$HOME/.config}/sxmo/hooks:/usr/share/sxmo/default_hooks:$PATH"
# shellcheck source=scripts/core/sxmo_common.sh
. sxmo_common.sh
CFG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/sxmo"
find_bt_card() {
pactl list short cards 2>/dev/null | awk '$2 ~ /^bluez_card\./ { print $2; exit }'
}
switch_bt_card_hfp() {
bt_card="$1"
[ -z "$bt_card" ] && return 1
pactl set-card-profile "$bt_card" headset-head-unit-cvsd >/dev/null 2>&1 || \
pactl set-card-profile "$bt_card" headset-head-unit >/dev/null 2>&1 || \
pactl set-card-profile "$bt_card" headset-head-unit-msbc >/dev/null 2>&1 || return 1
_w=0
while [ "$_w" -lt 15 ]; do
if pactl list short sinks 2>/dev/null | grep -q 'bluez_output\.'; then
break
fi
sleep 0.1
_w=$(( _w + 1 ))
done
return 0
}
switch_bt_card_a2dp() {
bt_card="$1"
[ -z "$bt_card" ] && return 1
if pactl set-card-profile "$bt_card" a2dp-sink >/dev/null 2>&1; then
return 0
fi
a2dp_prof="$(pactl list cards 2>/dev/null | awk -v c="$bt_card" '
$1 == "Name:" { in_card = ($2 == c); in_prof = 0 }
in_card && $1 == "Profiles:" { in_prof = 1; next }
in_card && in_prof && /^[[:space:]]*Active Profile:/ { in_prof = 0 }
in_card && in_prof && $1 ~ /^a2dp-sink/ && $0 !~ /available: no/ {
sub(/:$/, "", $1); print $1; exit
}
')"
if [ -n "$a2dp_prof" ]; then
pactl set-card-profile "$bt_card" "$a2dp_prof" >/dev/null 2>&1 && return 0
fi
return 1
}
enable_call_audio_mode() {
exec 9>/tmp/sxmo_modemaudio.lock
flock -x 9
printf "1\n" > /tmp/sxmo_in_call 2>/dev/null || true
cur_out="$(sxmo_audio.sh device get 2>/dev/null || printf "Speaker")"
bt_card="$(find_bt_card)"
jack_plugged=0
if [ -r /tmp/sxmo_jack_plugged ]; then
read -r jack_plugged < /tmp/sxmo_jack_plugged 2>/dev/null || jack_plugged=0
fi
if [ -n "$bt_card" ]; then
target_out="Bluetooth"
switch_bt_card_hfp "$bt_card" || true
sxmo_audio.sh device set Bluetooth >/dev/null 2>&1 || true
sxmo_audio.sh device setinput Bluetooth >/dev/null 2>&1 || true
if command -v amixer >/dev/null 2>&1; then
amixer -c 0 -s >/dev/null 2>&1 <<'EOF' || true
cset name='INT_BT_SCO_RX Audio Mixer MultiMedia1' 0
cset name='MultiMedia2 Mixer INT_BT_SCO_TX' 0
cset name='MultiMedia2 Mixer TERT_MI2S_TX' 0
cset name='PRI_MI2S_RX Voice Mixer VoiceMMode1' 0
cset name='VoiceMMode1 Capture Mixer TERT_MI2S_TX' 0
cset name='INT_BT_SCO_RX Voice Mixer VoiceMMode1' 1
cset name='VoiceMMode1 Capture Mixer INT_BT_SCO_TX' 1
EOF
fi
else
if [ "$jack_plugged" = "1" ] || [ "$cur_out" = "Headphones" ]; then
target_out="Headphones"
else
target_out="Earpiece"
fi
sxmo_audio.sh device set "$target_out" >/dev/null 2>&1 || true
if command -v amixer >/dev/null 2>&1; then
amixer -c 0 -s >/dev/null 2>&1 <<'EOF' || true
cset name='INT_BT_SCO_RX Voice Mixer VoiceMMode1' 0
cset name='VoiceMMode1 Capture Mixer INT_BT_SCO_TX' 0
cset name='PRI_MI2S_RX Voice Mixer VoiceMMode1' 1
cset name='VoiceMMode1 Capture Mixer TERT_MI2S_TX' 1
cset name='MultiMedia2 Mixer TERT_MI2S_TX' 0
cset name='RX1 Mute Switch' 0
EOF
fi
fi
sxmo_log "Enabled ALSA voice call audio mode ($target_out)."
return 0
}
disable_call_audio_mode() {
exec 9>/tmp/sxmo_modemaudio.lock
flock -x 9
if [ ! -e /tmp/sxmo_in_call ]; then
rm -f /tmp/sxmo_call_vol 2>/dev/null || true
return 0
fi
rm -f /tmp/sxmo_in_call /tmp/sxmo_call_vol 2>/dev/null || true
bt_card="$(find_bt_card)"
jack_plugged=0
if [ -r /tmp/sxmo_jack_plugged ]; then
read -r jack_plugged < /tmp/sxmo_jack_plugged 2>/dev/null || jack_plugged=0
fi
if command -v amixer >/dev/null 2>&1; then
amixer -c 0 -s >/dev/null 2>&1 <<'EOF' || true
cset name='INT_BT_SCO_RX Voice Mixer VoiceMMode1' 0
cset name='VoiceMMode1 Capture Mixer INT_BT_SCO_TX' 0
cset name='PRI_MI2S_RX Voice Mixer VoiceMMode1' 0
cset name='VoiceMMode1 Capture Mixer TERT_MI2S_TX' 0
cset name='INT_BT_SCO_RX Audio Mixer MultiMedia1' 0
cset name='MultiMedia2 Mixer INT_BT_SCO_TX' 0
cset name='PRI_MI2S_RX Audio Mixer MultiMedia1' 1
cset name='MultiMedia2 Mixer TERT_MI2S_TX' 1
EOF
fi
if [ -n "$bt_card" ]; then
target_out="Bluetooth"
if [ -r /tmp/sxmo_bt_sco_keepalive.pid ]; then
read -r kpid < /tmp/sxmo_bt_sco_keepalive.pid 2>/dev/null || kpid=""
rm -f /tmp/sxmo_bt_sco_keepalive.pid 2>/dev/null || true
[ -n "$kpid" ] && kill -TERM "$kpid" 2>/dev/null || true
fi
for _bpid in $(ps | awk '/pacat --playback --device=bluez_output/ && !/awk/ {print $1}' 2>/dev/null || true); do
kill -TERM "$_bpid" 2>/dev/null || true
done
switch_bt_card_a2dp "$bt_card" || true
sxmo_audio.sh device setinput Mic1 >/dev/null 2>&1 || true
sxmo_audio.sh device set Bluetooth >/dev/null 2>&1 || true
else
if [ "$jack_plugged" = "1" ]; then
target_out="Headphones"
else
target_out="Speaker"
fi
sxmo_audio.sh device setinput Mic1 >/dev/null 2>&1 || true
sxmo_audio.sh device set "$target_out" >/dev/null 2>&1 || true
fi
sxmo_log "Disabled ALSA voice call audio mode ($target_out)."
return 0
}
setup_audio() {
enable_call_audio_mode
return 0
}
reset_audio() {
disable_call_audio_mode
return 0
}
"$@"