Add Bluetooth audio/HID/discoverability/alias support, fix SD card hotplug & caller ID matching, and expand ReMEdy J2ME JSRs + 64MB GC

This commit is contained in:
Luxferre committed 2026-11-01 16:18:04 +02:00
1 parent 456d3fbc42
commit 471916424e
51 files changed
+2961 -305

No files matched your search

+1 -1
View File
@@ -1,2 +1,2 @@
#!/bin/sh
exec /usr/bin/X -nocursor -nolisten tcp "$@"
exec /usr/bin/X -nolisten tcp "$@"
+5
View File
@@ -0,0 +1,5 @@
[General]
IdleTimeout=0
UserspaceHID=true
ClassicBondedOnly=false
LEAutoSecurity=true
+17
View File
@@ -0,0 +1,17 @@
[General]
DiscoverableTimeout = 0
PairableTimeout = 0
ControllerMode = dual
MultiProfile = multiple
JustWorksRepairing = always
Experimental = true
[GATT]
Cache = always
[Policy]
ReconnectUUIDs=00001112-0000-1000-8000-00805f9b34fb,0000111f-0000-1000-8000-00805f9b34fb,0000110a-0000-1000-8000-00805f9b34fb,0000110b-0000-1000-8000-00805f9b34fb,00001108-0000-1000-8000-00805f9b34fb,0000111e-0000-1000-8000-00805f9b34fb,00001124-0000-1000-8000-00805f9b34fb,00001812-0000-1000-8000-00805f9b34fb
ReconnectAttempts=7
ReconnectIntervals=1,2,4,8,16,32,64
AutoEnable=true
ResumeDelay = 2
+2
View File
@@ -7,7 +7,9 @@ permit nopass :wheel as root cmd poweroff
permit nopass :wheel as root cmd reboot
permit nopass :wheel as root cmd /sbin/poweroff
permit nopass :wheel as root cmd /sbin/reboot
permit nopass :wheel as root cmd /usr/bin/sxmo_wifitoggle.sh
permit nopass :wheel as root cmd sxmo_wifitoggle.sh
permit nopass setenv { SXMO_OS } :wheel as root cmd /usr/bin/sxmo_bluetoothtoggle.sh
permit nopass setenv { SXMO_OS } :wheel as root cmd sxmo_bluetoothtoggle.sh
permit nopass :wheel as root cmd rc-service args bluetooth restart
permit nopass :wheel as root cmd systemctl args restart bluetooth
@@ -0,0 +1,9 @@
monitor.bluez.properties = {
bluez5.roles = [ a2dp_sink a2dp_source bap_sink bap_source hsp_hs hsp_ag hfp_hf hfp_ag ]
bluez5.codecs = [ sbc sbc_xq aac ldac aptx aptx_hd aptx_ll aptx_ll_duplex faststream faststream_duplex opus_05 opus_05_51 opus_05_71 opus_05_dup opus_05_pro lc3 ]
bluez5.enable-sbc-xq = true
bluez5.enable-msbc = true
bluez5.enable-hw-volume = true
bluez5.hfphsp-backend = "native"
bluez5.hfphsp-backend-native-modem = "any"
}
@@ -1,4 +1,4 @@
# Automatically mount and unmount removable microSD cards (mmcblk1) at /media/sdcard
SUBSYSTEM=="block", KERNEL=="mmcblk1p[1-9]*", ACTION=="add", RUN+="/usr/bin/sxmo_sdcard.sh automount add %k"
SUBSYSTEM=="block", KERNEL=="mmcblk1", ATTR{partition}!="1", ENV{ID_FS_USAGE}=="filesystem", ACTION=="add", RUN+="/usr/bin/sxmo_sdcard.sh automount add %k"
SUBSYSTEM=="block", KERNEL=="mmcblk1*", ACTION=="remove", RUN+="/usr/bin/sxmo_sdcard.sh automount remove %k"
# Bananarchy microSD card automount on insertion & cleanup on removal
ACTION=="add", SUBSYSTEM=="block", KERNEL=="mmcblk[1-9]p[1-9]", RUN+="/bin/sh -c '/usr/bin/sxmo_sdcard.sh automount add %k >/dev/null 2>&1 &'"
ACTION=="add", SUBSYSTEM=="block", KERNEL=="mmcblk[1-9]", ENV{DEVTYPE}=="disk", RUN+="/bin/sh -c 'sleep 1; /usr/bin/sxmo_sdcard.sh automount add %k >/dev/null 2>&1 &'"
ACTION=="remove", SUBSYSTEM=="block", KERNEL=="mmcblk[1-9]*", RUN+="/bin/sh -c '/usr/bin/sxmo_sdcard.sh automount remove %k >/dev/null 2>&1 &'"
@@ -0,0 +1,9 @@
monitor.bluez.properties = {
bluez5.roles = [ a2dp_sink a2dp_source bap_sink bap_source hsp_hs hsp_ag hfp_hf hfp_ag ]
bluez5.codecs = [ sbc sbc_xq aac ldac aptx aptx_hd aptx_ll aptx_ll_duplex faststream faststream_duplex opus_05 opus_05_51 opus_05_71 opus_05_dup opus_05_pro lc3 ]
bluez5.enable-sbc-xq = true
bluez5.enable-msbc = true
bluez5.enable-hw-volume = true
bluez5.hfphsp-backend = "native"
bluez5.hfphsp-backend-native-modem = "any"
}
@@ -0,0 +1,9 @@
monitor.bluez.properties = {
bluez5.roles = [ a2dp_sink a2dp_source bap_sink bap_source hsp_hs hsp_ag hfp_hf hfp_ag ]
bluez5.codecs = [ sbc sbc_xq aac ldac aptx aptx_hd aptx_ll aptx_ll_duplex faststream faststream_duplex opus_05 opus_05_51 opus_05_71 opus_05_dup opus_05_pro lc3 ]
bluez5.enable-sbc-xq = true
bluez5.enable-msbc = true
bluez5.enable-hw-volume = true
bluez5.hfphsp-backend = "native"
bluez5.hfphsp-backend-native-modem = "any"
}
+278 -6
View File
@@ -5,6 +5,8 @@
import os
import sys
import time
import fcntl
import select
import struct
import socket
import signal
@@ -60,15 +62,24 @@ def notify_networks_ui():
def notify_user(title, body):
try:
bus_addr = "unix:path=/run/user/10000/bus"
if os.path.exists("/run/user/10000/dbus.bus"):
try:
with open("/run/user/10000/dbus.bus", "r", encoding="utf-8") as bf:
line = bf.readline().strip()
if line:
bus_addr = line
except OSError:
pass
if os.geteuid() == 0:
subprocess.Popen([
"su", "-", "user", "-c",
f"DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/10000/bus notify-send { subprocess.list2cmdline([title, body]) }"
f"DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS={subprocess.list2cmdline([bus_addr])} notify-send {subprocess.list2cmdline([title, body])}"
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
else:
env = os.environ.copy()
env.setdefault("DISPLAY", ":0")
env.setdefault("DBUS_SESSION_BUS_ADDRESS", "unix:path=/run/user/10000/bus")
env.setdefault("DBUS_SESSION_BUS_ADDRESS", bus_addr)
subprocess.Popen(["notify-send", title, body],
env=env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
except Exception:
@@ -278,6 +289,239 @@ def handle_obex_rx_session(sock):
pass
def run_gamepad_uinput_bridge(is_running):
ev_fmt = "llHHi"
ev_size = struct.calcsize(ev_fmt)
ui_set_evbit = 0x40045564
ui_set_keybit = 0x40045565
ui_dev_create = 0x5501
ui_dev_destroy = 0x5502
eviocgbit_key = (2 << 30) | (96 << 16) | (0x45 << 8) | (0x20 + 0x01)
# Map Linux gamepad button codes to Bananarchy keypad/navigation keys:
# South(A)=Enter(OK), East(B)=8(GB B), West(X)=5(Fire/Turbo B), North(Y)=6(Turbo A)
# Start=2(GB Start), Select=3(GB Select), L1=F1(LSK), R1=F2(RSK), L2=*, R2=0, Mode=Esc
btn_map = {
0x130: 28, # BTN_SOUTH (A) -> KEY_ENTER
0x131: 9, # BTN_EAST (B) -> KEY_8
0x132: 8, # BTN_C -> KEY_7
0x133: 6, # BTN_WEST (X) -> KEY_5
0x134: 7, # BTN_NORTH (Y) -> KEY_6
0x135: 10, # BTN_Z -> KEY_9
0x136: 59, # BTN_TL (L1) -> KEY_F1 (Left Softkey)
0x137: 60, # BTN_TR (R1) -> KEY_F2 (Right Softkey)
0x138: 55, # BTN_TL2 (L2) -> KEY_KPASTERISK (*)
0x139: 11, # BTN_TR2 (R2) -> KEY_0
0x13a: 4, # BTN_SELECT -> KEY_3
0x13b: 3, # BTN_START -> KEY_2
0x13c: 1, # BTN_MODE -> KEY_ESC
0x120: 28, # BTN_TRIGGER -> KEY_ENTER
0x121: 9, # BTN_THUMB -> KEY_8
0x220: 103, # BTN_DPAD_UP -> KEY_UP
0x221: 108, # BTN_DPAD_DOWN -> KEY_DOWN
0x222: 105, # BTN_DPAD_LEFT -> KEY_LEFT
0x223: 106, # BTN_DPAD_RIGHT -> KEY_RIGHT
}
all_keys = sorted(set(btn_map.values()) | {103, 108, 105, 106})
uinput_fd = None
gamepads = {} # path -> {"fd": int, "hat_x": 0, "hat_y": 0, "lx": 0, "ly": 0, "ax": {}}
last_scan = 0.0
def ensure_uinput():
nonlocal uinput_fd
if uinput_fd is not None:
return True
try:
subprocess.run(["modprobe", "-q", "uinput"],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
fd = os.open("/dev/uinput", os.O_WRONLY | os.O_NONBLOCK)
fcntl.ioctl(fd, ui_set_evbit, 0x00) # EV_SYN
fcntl.ioctl(fd, ui_set_evbit, 0x01) # EV_KEY
for k in all_keys:
fcntl.ioctl(fd, ui_set_keybit, k)
name = b"Bananarchy BT Gamepad Bridge"
udev = struct.pack("80sHHHHi", name, 0x06, 0x1209, 0x8110, 1, 0) + (b"\x00" * (64 * 4 * 4))
os.write(fd, udev)
fcntl.ioctl(fd, ui_dev_create)
uinput_fd = fd
return True
except Exception:
return False
def emit_key(code, val):
if uinput_fd is None and not ensure_uinput():
return
try:
os.write(uinput_fd, struct.pack(ev_fmt, 0, 0, 0x01, code, val))
os.write(uinput_fd, struct.pack(ev_fmt, 0, 0, 0x00, 0, 0))
except OSError:
pass
def get_axis_dir(fd, axis, val, cache):
if axis not in cache:
try:
ioc = (2 << 30) | (24 << 16) | (0x45 << 8) | (0x40 + axis)
buf = fcntl.ioctl(fd, ioc, b"\x00" * 24)
_v, min_v, max_v, _fz, _fl, _rs = struct.unpack("6i", buf)
if max_v > min_v:
cache[axis] = (min_v, max_v)
else:
cache[axis] = (-32768, 32767)
except Exception:
cache[axis] = (-32768, 32767)
min_v, max_v = cache[axis]
mid = (min_v + max_v) / 2.0
span = (max_v - min_v) / 2.0
if span <= 0:
return 0
norm = (val - mid) / span
if norm < -0.40:
return -1
if norm > 0.40:
return 1
return 0
while is_running():
now = time.monotonic()
if now - last_scan >= 2.0:
last_scan = now
try:
for entry in os.listdir("/dev/input"):
if not entry.startswith("event"):
continue
dev_path = f"/dev/input/{entry}"
if dev_path in gamepads:
continue
sys_name_path = f"/sys/class/input/{entry}/device/name"
try:
with open(sys_name_path, "r", encoding="utf-8") as nf:
dname = nf.read().strip()
if "Bananarchy BT Gamepad Bridge" in dname:
continue
except OSError:
pass
try:
fd = os.open(dev_path, os.O_RDONLY | os.O_NONBLOCK)
buf = bytearray(96)
fcntl.ioctl(fd, eviocgbit_key, buf, True)
has_gamepad = bool((buf[0x130 // 8] >> (0x130 % 8)) & 1) or bool((buf[0x120 // 8] >> (0x120 % 8)) & 1)
if has_gamepad:
ensure_uinput()
gamepads[dev_path] = {
"fd": fd, "hat_x": 0, "hat_y": 0, "lx": 0, "ly": 0, "ax": {}
}
else:
os.close(fd)
except Exception:
pass
except OSError:
pass
if not gamepads:
time.sleep(1.5)
continue
fd_map = {info["fd"]: (path, info) for path, info in list(gamepads.items())}
try:
rlist, _, _ = select.select(list(fd_map.keys()), [], [], 1.0)
except Exception:
time.sleep(0.5)
continue
for rfd in rlist:
path, info = fd_map.get(rfd, (None, None))
if not path:
continue
try:
data = os.read(rfd, ev_size * 16)
if not data:
raise OSError("EOF")
except OSError:
try:
os.close(rfd)
except OSError:
pass
gamepads.pop(path, None)
continue
offset = 0
while offset + ev_size <= len(data):
_sec, _usec, ev_type, ev_code, ev_val = struct.unpack_from(ev_fmt, data, offset)
offset += ev_size
if ev_type == 0x01 and ev_code in btn_map:
if ev_val in (0, 1, 2):
emit_key(btn_map[ev_code], ev_val)
elif ev_type == 0x03:
if ev_code == 0x10: # ABS_HAT0X
new_dir = -1 if ev_val < 0 else (1 if ev_val > 0 else 0)
old_dir = info["hat_x"]
if new_dir != old_dir:
if old_dir == -1:
emit_key(105, 0)
elif old_dir == 1:
emit_key(106, 0)
if new_dir == -1:
emit_key(105, 1)
elif new_dir == 1:
emit_key(106, 1)
info["hat_x"] = new_dir
elif ev_code == 0x11: # ABS_HAT0Y
new_dir = -1 if ev_val < 0 else (1 if ev_val > 0 else 0)
old_dir = info["hat_y"]
if new_dir != old_dir:
if old_dir == -1:
emit_key(103, 0)
elif old_dir == 1:
emit_key(108, 0)
if new_dir == -1:
emit_key(103, 1)
elif new_dir == 1:
emit_key(108, 1)
info["hat_y"] = new_dir
elif ev_code == 0x00: # ABS_X (Left Stick X)
new_dir = get_axis_dir(rfd, 0x00, ev_val, info["ax"])
old_dir = info["lx"]
if new_dir != old_dir:
if old_dir == -1:
emit_key(105, 0)
elif old_dir == 1:
emit_key(106, 0)
if new_dir == -1:
emit_key(105, 1)
elif new_dir == 1:
emit_key(106, 1)
info["lx"] = new_dir
elif ev_code == 0x01: # ABS_Y (Left Stick Y)
new_dir = get_axis_dir(rfd, 0x01, ev_val, info["ax"])
old_dir = info["ly"]
if new_dir != old_dir:
if old_dir == -1:
emit_key(103, 0)
elif old_dir == 1:
emit_key(108, 0)
if new_dir == -1:
emit_key(103, 1)
elif new_dir == 1:
emit_key(108, 1)
info["ly"] = new_dir
for info in gamepads.values():
try:
os.close(info["fd"])
except OSError:
pass
if uinput_fd is not None:
try:
fcntl.ioctl(uinput_fd, ui_dev_destroy)
except Exception:
pass
try:
os.close(uinput_fd)
except OSError:
pass
def run_daemon():
from jeepney import DBusAddress, new_method_call, new_method_return, MessageType
from jeepney.io.blocking import open_dbus_connection
@@ -297,14 +541,42 @@ def run_daemon():
signal.signal(signal.SIGTERM, stop_handler)
signal.signal(signal.SIGINT, stop_handler)
# Make adapter discoverable and pairable when Bluetooth is ON so senders can see the phone
subprocess.run(["bluetoothctl", "discoverable-timeout", "0"],
bt_name = ""
try:
if os.path.exists("/home/user/.config/sxmo/bt_name"):
with open("/home/user/.config/sxmo/bt_name", "r", encoding="utf-8") as nf:
bt_name = nf.readline().strip()
except OSError:
pass
if not bt_name:
try:
bt_name = socket.gethostname().strip()
except Exception:
bt_name = "Bananarchy"
if bt_name:
subprocess.run(["timeout", "2", "bluetoothctl", "system-alias", bt_name],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
bt_disc = "1"
try:
if os.path.exists("/home/user/.config/sxmo/bt_discoverable"):
with open("/home/user/.config/sxmo/bt_discoverable", "r", encoding="utf-8") as df:
bt_disc = df.readline().strip() or "1"
except OSError:
pass
disc_on = bt_disc.lower() not in ("0", "off", "no", "false")
subprocess.run(["timeout", "2", "bluetoothctl", "discoverable-timeout", "0"],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
subprocess.run(["bluetoothctl", "discoverable", "on"],
subprocess.run(["timeout", "2", "bluetoothctl", "discoverable", "on" if disc_on else "off"],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
subprocess.run(["bluetoothctl", "pairable", "on"],
subprocess.run(["timeout", "2", "bluetoothctl", "pairable", "on"],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
gp_thread = threading.Thread(target=run_gamepad_uinput_bridge,
args=(lambda: running,), daemon=True)
gp_thread.start()
profile_path = "/org/bananarchy/obex_opp"
conn = None
try:
@@ -89,7 +89,7 @@ if pidof -s plymouthd >/dev/null 2>&1; then
fi
if ! pidof -s Xorg >/dev/null 2>&1; then
"$XORG_BIN" :0 -s 0 -dpms -nocursor -nolisten tcp -config "$XORG_CONFIG" -modulepath "$XORG_MODPATH" -logfile /tmp/Xorg.0.log >/dev/null 2>&1 </dev/null &
"$XORG_BIN" :0 -s 0 -dpms -nolisten tcp -config "$XORG_CONFIG" -modulepath "$XORG_MODPATH" -logfile /tmp/Xorg.0.log >/dev/null 2>&1 </dev/null &
i=0
while [ "$i" -lt 40 ]; do
if xset s off s noblank s 0 0 >/dev/null 2>&1; then
Binary file not shown.
Binary file not shown.
Binary file not shown.
+132 -27
View File
@@ -26,6 +26,7 @@ clamp_pct() {
normalize_out_dev() {
case "$1" in
*[Bb]luetooth*|*[Bb]luez*) printf "Bluetooth" ;;
*[Ee]arpiece*) printf "Earpiece" ;;
*[Hh]eadphone*|*[Hh]eadset*) printf "Headphones" ;;
*) printf "Speaker" ;;
@@ -34,14 +35,24 @@ normalize_out_dev() {
normalize_in_dev() {
case "$1" in
*[Bb]luetooth*|*[Bb]luez*) printf "Bluetooth" ;;
*[Hh]eadset*) printf "Headset" ;;
*) printf "Mic1" ;;
esac
}
find_bt_sink() {
pactl list short sinks 2>/dev/null | awk '$2 ~ /^bluez_output\./ { print $2; exit }'
}
find_bt_source() {
pactl list short sources 2>/dev/null | awk '$2 ~ /^bluez_input\./ { print $2; exit }'
}
vol_file_for_dev() {
dev="$(normalize_out_dev "$1")"
case "$dev" in
Bluetooth) printf "%s/bluetooth_vol" "$CFG_DIR" ;;
Earpiece) printf "%s/earpiece_vol" "$CFG_DIR" ;;
Headphones) printf "%s/headphones_vol" "$CFG_DIR" ;;
*) printf "%s/speaker_vol" "$CFG_DIR" ;;
@@ -51,7 +62,7 @@ vol_file_for_dev() {
default_vol_for_dev() {
dev="$(normalize_out_dev "$1")"
case "$dev" in
Headphones) printf "80" ;;
Bluetooth|Headphones) printf "80" ;;
*) printf "85" ;;
esac
}
@@ -104,11 +115,23 @@ pct_to_hw_adc() {
}
deviceget() {
sink="$(pactl get-default-sink 2>/dev/null || true)"
case "$sink" in
bluez_output.*)
printf "Bluetooth\n" > /tmp/sxmo_audio_out_device 2>/dev/null || true
printf "Bluetooth\n"
return 0
;;
esac
if [ -r /tmp/sxmo_audio_out_device ]; then
read -r dev < /tmp/sxmo_audio_out_device 2>/dev/null || dev=""
if [ -n "$dev" ]; then
normalize_out_dev "$dev"
printf "\n"
dev="$(normalize_out_dev "$dev")"
if [ "$dev" = "Bluetooth" ] && [ -z "$(find_bt_sink)" ]; then
dev="Speaker"
printf "%s\n" "$dev" > /tmp/sxmo_audio_out_device 2>/dev/null || true
fi
printf "%s\n" "$dev"
return 0
fi
fi
@@ -116,12 +139,14 @@ deviceget() {
read -r dev < "$CFG_DIR/audio_out_device" 2>/dev/null || dev=""
if [ -n "$dev" ]; then
dev="$(normalize_out_dev "$dev")"
if [ "$dev" = "Bluetooth" ] && [ -z "$(find_bt_sink)" ]; then
dev="Speaker"
fi
printf "%s\n" "$dev" > /tmp/sxmo_audio_out_device 2>/dev/null || true
printf "%s\n" "$dev"
return 0
fi
fi
sink="$(pactl get-default-sink 2>/dev/null || true)"
case "$sink" in
*Earpiece*) dev="Earpiece" ;;
*Headphones*) dev="Headphones" ;;
@@ -132,11 +157,23 @@ deviceget() {
}
devicegetinput() {
src="$(pactl get-default-source 2>/dev/null || true)"
case "$src" in
bluez_input.*)
printf "Bluetooth\n" > /tmp/sxmo_audio_in_device 2>/dev/null || true
printf "Bluetooth\n"
return 0
;;
esac
if [ -r /tmp/sxmo_audio_in_device ]; then
read -r in_dev < /tmp/sxmo_audio_in_device 2>/dev/null || in_dev=""
if [ -n "$in_dev" ]; then
normalize_in_dev "$in_dev"
printf "\n"
in_dev="$(normalize_in_dev "$in_dev")"
if [ "$in_dev" = "Bluetooth" ] && [ -z "$(find_bt_source)" ]; then
in_dev="Mic1"
printf "%s\n" "$in_dev" > /tmp/sxmo_audio_in_device 2>/dev/null || true
fi
printf "%s\n" "$in_dev"
return 0
fi
fi
@@ -144,12 +181,14 @@ devicegetinput() {
read -r in_dev < "$CFG_DIR/audio_in_device" 2>/dev/null || in_dev=""
if [ -n "$in_dev" ]; then
in_dev="$(normalize_in_dev "$in_dev")"
if [ "$in_dev" = "Bluetooth" ] && [ -z "$(find_bt_source)" ]; then
in_dev="Mic1"
fi
printf "%s\n" "$in_dev" > /tmp/sxmo_audio_in_device 2>/dev/null || true
printf "%s\n" "$in_dev"
return 0
fi
fi
src="$(pactl get-default-source 2>/dev/null || true)"
case "$src" in
*Headset*) in_dev="Headset" ;;
*) in_dev="Mic1" ;;
@@ -251,6 +290,18 @@ apply_alsa_out() {
amixer -c 0 cset "name='RX2 Digital Volume'" 0 >/dev/null 2>&1 || true
fi
;;
Bluetooth)
amixer -c 0 -q sset 'SPK DAC' off 2>/dev/null || amixer -c 0 cset "name='SPK DAC Switch'" 0 >/dev/null 2>&1 || true
amixer -c 0 cset "name='EAR_S'" 'ZERO' >/dev/null 2>&1 || true
amixer -c 0 cset "name='HPHL'" 'ZERO' >/dev/null 2>&1 || true
amixer -c 0 cset "name='HPHR'" 'ZERO' >/dev/null 2>&1 || true
amixer -c 0 cset "name='RX1 MIX1 INP1'" 'ZERO' >/dev/null 2>&1 || true
amixer -c 0 cset "name='RX2 MIX1 INP1'" 'ZERO' >/dev/null 2>&1 || true
amixer -c 0 cset "name='RX3 MIX1 INP1'" 'ZERO' >/dev/null 2>&1 || true
amixer -c 0 cset "name='RX1 Digital Volume'" 0 >/dev/null 2>&1 || true
amixer -c 0 cset "name='RX2 Digital Volume'" 0 >/dev/null 2>&1 || true
amixer -c 0 cset "name='RX3 Digital Volume'" 0 >/dev/null 2>&1 || true
;;
*)
amixer -c 0 cset "name='EAR_S'" 'ZERO' >/dev/null 2>&1 || true
amixer -c 0 cset "name='HPHL'" 'ZERO' >/dev/null 2>&1 || true
@@ -274,7 +325,11 @@ apply_alsa_out() {
if [ "$eff_pct" -gt 0 ]; then
wpctl set-mute @DEFAULT_AUDIO_SINK@ 0 >/dev/null 2>&1 || true
wpctl set-volume @DEFAULT_AUDIO_SINK@ 100% >/dev/null 2>&1 || true
if [ "$dev" = "Bluetooth" ]; then
wpctl set-volume @DEFAULT_AUDIO_SINK@ "${eff_pct}%" >/dev/null 2>&1 || true
else
wpctl set-volume @DEFAULT_AUDIO_SINK@ 100% >/dev/null 2>&1 || true
fi
else
wpctl set-mute @DEFAULT_AUDIO_SINK@ 1 >/dev/null 2>&1 || true
fi
@@ -324,7 +379,11 @@ apply_alsa_in() {
if [ "$eff_pct" -gt 0 ]; then
wpctl set-mute @DEFAULT_AUDIO_SOURCE@ 0 >/dev/null 2>&1 || true
wpctl set-volume @DEFAULT_AUDIO_SOURCE@ 100% >/dev/null 2>&1 || true
if [ "$in_dev" = "Bluetooth" ]; then
wpctl set-volume @DEFAULT_AUDIO_SOURCE@ "${eff_pct}%" >/dev/null 2>&1 || true
else
wpctl set-volume @DEFAULT_AUDIO_SOURCE@ 100% >/dev/null 2>&1 || true
fi
else
wpctl set-mute @DEFAULT_AUDIO_SOURCE@ 1 >/dev/null 2>&1 || true
fi
@@ -333,6 +392,8 @@ apply_alsa_in() {
profile_for_devices() {
out_dev="$(normalize_out_dev "$1")"
in_dev="$(normalize_in_dev "$2")"
[ "$out_dev" = "Bluetooth" ] && out_dev="Speaker"
[ "$in_dev" = "Bluetooth" ] && in_dev="Mic1"
case "${out_dev}:${in_dev}" in
Headphones:Headset) printf "HiFi (Headphones, Headset)" ;;
Headphones:Mic1) printf "HiFi (Headphones, Mic1)" ;;
@@ -349,10 +410,24 @@ sync_pipewire_profile() {
prof="$(profile_for_devices "$out_dev" "$in_dev")"
pactl set-card-profile alsa_card.comprC0 off >/dev/null 2>&1 || true
pactl set-card-profile "$ALSA_CARD" "$prof" >/dev/null 2>&1 || true
sink_name="alsa_output.platform-7702000.sound.HiFi__${out_dev}__sink"
src_name="alsa_input.platform-7702000.sound.HiFi__${in_dev}__source"
pactl set-default-sink "$sink_name" >/dev/null 2>&1 || true
pactl set-default-source "$src_name" >/dev/null 2>&1 || true
if [ "$out_dev" = "Bluetooth" ]; then
bt_sink="$(find_bt_sink)"
if [ -n "$bt_sink" ]; then
pactl set-default-sink "$bt_sink" >/dev/null 2>&1 || true
fi
else
sink_name="alsa_output.platform-7702000.sound.HiFi__${out_dev}__sink"
pactl set-default-sink "$sink_name" >/dev/null 2>&1 || true
fi
if [ "$in_dev" = "Bluetooth" ]; then
bt_src="$(find_bt_source)"
if [ -n "$bt_src" ]; then
pactl set-default-source "$bt_src" >/dev/null 2>&1 || true
fi
else
src_name="alsa_input.platform-7702000.sound.HiFi__${in_dev}__source"
pactl set-default-source "$src_name" >/dev/null 2>&1 || true
fi
}
notifyvol() {
@@ -523,28 +598,56 @@ devicesetinput() {
}
devicelist() {
printf "Speaker\nEarpiece\nHeadphones\n"
if [ -n "$(find_bt_sink)" ]; then
printf "Bluetooth\nSpeaker\nEarpiece\nHeadphones\n"
else
printf "Speaker\nEarpiece\nHeadphones\n"
fi
}
devicelistinput() {
printf "Mic1\nHeadset\n"
if [ -n "$(find_bt_source)" ]; then
printf "Bluetooth\nMic1\nHeadset\n"
else
printf "Mic1\nHeadset\n"
fi
}
devicecycle() {
dir="${1:-next}"
cur="$(deviceget)"
has_bt=0
[ -n "$(find_bt_sink)" ] && has_bt=1
if [ "$dir" = "prev" ]; then
case "$cur" in
Speaker) next="Headphones" ;;
Earpiece) next="Speaker" ;;
*) next="Earpiece" ;;
esac
if [ "$has_bt" = "1" ]; then
case "$cur" in
Bluetooth) next="Headphones" ;;
Speaker) next="Bluetooth" ;;
Earpiece) next="Speaker" ;;
*) next="Earpiece" ;;
esac
else
case "$cur" in
Speaker) next="Headphones" ;;
Earpiece) next="Speaker" ;;
*) next="Earpiece" ;;
esac
fi
else
case "$cur" in
Speaker) next="Earpiece" ;;
Earpiece) next="Headphones" ;;
*) next="Speaker" ;;
esac
if [ "$has_bt" = "1" ]; then
case "$cur" in
Bluetooth) next="Speaker" ;;
Speaker) next="Earpiece" ;;
Earpiece) next="Headphones" ;;
*) next="Bluetooth" ;;
esac
else
case "$cur" in
Speaker) next="Earpiece" ;;
Earpiece) next="Headphones" ;;
*) next="Speaker" ;;
esac
fi
fi
deviceset "$next"
printf "%s\n" "$next"
@@ -570,6 +673,7 @@ devicegetdefaultsource() {
sourceset() {
pactl set-default-source "$1" >/dev/null 2>&1 || true
case "$1" in
bluez_input.*|*Bluetooth*) devicesetinput Bluetooth ;;
*Headset*) devicesetinput Headset ;;
*) devicesetinput Mic1 ;;
esac
@@ -578,6 +682,7 @@ sourceset() {
sinkset() {
pactl set-default-sink "$1" >/dev/null 2>&1 || true
case "$1" in
bluez_output.*|*Bluetooth*) deviceset Bluetooth ;;
*Earpiece*) deviceset Earpiece ;;
*Headphones*) deviceset Headphones ;;
*) deviceset Speaker ;;
@@ -616,7 +721,7 @@ profileset() {
_outportssubmenu() {
active_out="$(deviceget)"
for dev in Speaker Earpiece Headphones; do
for dev in $(devicelist); do
if [ "$active_out" = "$dev" ]; then
icon="$icon_ton"
else
@@ -629,7 +734,7 @@ _outportssubmenu() {
_inportssubmenu() {
active_in="$(devicegetinput)"
for dev in Mic1 Headset; do
for dev in $(devicelistinput); do
if [ "$active_in" = "$dev" ]; then
icon="$icon_ton"
else
+41 -4
View File
@@ -2,12 +2,15 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2022 Sxmo Contributors
# Must be run as root
if [ "$(id -u)" != "0" ]; then
exec doas -n /usr/bin/sxmo_bluetoothtoggle.sh "$@"
fi
. sxmo_common.sh
on() {
rfkill unblock bluetooth
modprobe -q uhid hidp uinput rfcomm bnep xpad 2>/dev/null || true
if [ -d /run/systemd/system ]; then
systemctl start bluetooth
@@ -17,7 +20,34 @@ on() {
rc-update add bluetooth
fi
sleep 0.4
bluetoothctl power on >/dev/null 2>&1 || true
timeout 2 bluetoothctl power on >/dev/null 2>&1 || true
bt_name=""
if [ -r /home/user/.config/sxmo/bt_name ]; then
IFS= read -r bt_name < /home/user/.config/sxmo/bt_name 2>/dev/null || true
fi
if [ -z "$bt_name" ]; then
bt_name="$(hostname 2>/dev/null || cat /etc/hostname 2>/dev/null || printf "Bananarchy")"
fi
if [ -n "$bt_name" ]; then
timeout 2 bluetoothctl system-alias "$bt_name" >/dev/null 2>&1 || true
fi
bt_disc="1"
if [ -r /home/user/.config/sxmo/bt_discoverable ]; then
IFS= read -r bt_disc < /home/user/.config/sxmo/bt_discoverable 2>/dev/null || true
fi
timeout 2 bluetoothctl discoverable-timeout 0 >/dev/null 2>&1 || true
timeout 2 bluetoothctl pairable on >/dev/null 2>&1 || true
case "$bt_disc" in
0|off|OFF|no|NO|false|FALSE)
timeout 2 bluetoothctl discoverable off >/dev/null 2>&1 || true
;;
*)
timeout 2 bluetoothctl discoverable on >/dev/null 2>&1 || true
;;
esac
/usr/bin/bananarchy-bt-obex start >/dev/null 2>&1 &
}
@@ -33,15 +63,22 @@ off() {
rfkill block bluetooth
}
case "$1" in
case "${1:-toggle}" in
on)
on
;;
off)
off
;;
status)
if rfkill list bluetooth -no ID,SOFT,HARD | grep -vq " blocked" && pidof -s bluetoothd >/dev/null 2>&1; then
echo "on"
else
echo "off"
fi
;;
*) # toggle
if rfkill list bluetooth -no ID,SOFT,HARD | grep -vq " blocked"; then
if rfkill list bluetooth -no ID,SOFT,HARD | grep -vq " blocked" && pidof -s bluetoothd >/dev/null 2>&1; then
off
else
on
+5
View File
@@ -28,6 +28,11 @@ export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
export XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
export XDG_STATE_HOME="${XDG_STATE_HOME:-$HOME/.local/state}"
export SXMO_CONTACTFILE="${SXMO_CONTACTFILE:-$XDG_CONFIG_HOME/sxmo/contacts.tsv}"
export SXMO_BLOCKFILE="${SXMO_BLOCKFILE:-$XDG_CONFIG_HOME/sxmo/block.tsv}"
export SXMO_BLOCKDIR="${SXMO_BLOCKDIR:-$XDG_DATA_HOME/sxmo/block}"
export SXMO_LOGDIR="${SXMO_LOGDIR:-$XDG_DATA_HOME/sxmo/modem}"
export SXMO_NOTIFDIR="${SXMO_NOTIFDIR:-$XDG_DATA_HOME/sxmo/notifications}"
export LANG="${LANG:-C.UTF-8}"
export LC_ALL="${LC_ALL:-C.UTF-8}"
export XMODIFIERS="${XMODIFIERS:-@im=fcitx}"
+143
View File
@@ -0,0 +1,143 @@
#!/bin/sh
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2022 Sxmo Contributors
# This script prints in reverse chronological order unique entries from the
# modem log merged with contact names defined in contacts file tsv.
# Wherein $SXMO_CONTACTFILE is tsv with two fields: number\tcontact name
# Wherein $LOGFILE is *sorted* tsv with three fields: date\tevt\tnumber
#
# Most normal numbers should be a full phone number starting with + and the country number
# Some special numbers (ie. 2222, "CR AGRICOLE") can ignore this pattern
#
# Prints in output format: "number: contact"
# include common definitions
# shellcheck source=scripts/core/sxmo_common.sh
. sxmo_common.sh
LOGFILE="$SXMO_LOGDIR"/modemlog.tsv
prepare_contacts_list() {
cut -f3 |
tac |
awk '!($0 in a){a[$0]; print}' |
sed '/^[[:space:]]*$/d' |
awk -F '\t' -v SXMO_CONTACTFILE="$SXMO_CONTACTFILE" '
function join(array, sep) {
result = ""
cs = ""
for (i in array) {
if (length(result)) cs = sep;
result = result cs array[i]
}
return result
}
function name_for_num(num) {
if (!a[num]) a[num] = "???";
return a[num]
}
FILENAME == SXMO_CONTACTFILE {
if (!length()) next;
a[$1] = $2;
next
}
# Multiple numbers, unknown group name
/(\+[^+]+){2,}/ && !a[$1] {
split("", names) # empty the names array
split($1, nums, "+")
for (i in nums) {
num = nums[i]
if (length(num) == 0) continue;
names[i] = name_for_num("+" num)
}
print join(names, ", ") ": " $0
next
}
{
print name_for_num($1) ": " $0
}
' "$SXMO_CONTACTFILE" -
}
contacts() {
prepare_contacts_list < "$LOGFILE"
}
texted_contacts() {
grep "\(recv\|sent\)_\(txt\|mms\|vvm\)" "$LOGFILE" | prepare_contacts_list
}
called_contacts() {
grep "call_\(pickup\|start\)" "$LOGFILE" | prepare_contacts_list
}
all_contacts() {
awk -F'\t' '{
print $2 ": " $1
}' "$SXMO_CONTACTFILE" | sort -f -k 1
}
unknown_contacts() {
contacts \
| grep "^???" \
| cut -d: -f2 \
| grep "^ +[0-9]\{9,14\}" \
| sed 's/^ //'
}
[ -f "$SXMO_CONTACTFILE" ] || touch "$SXMO_CONTACTFILE"
if [ "$1" = "--all" ]; then
if [ "$2" = "--no-groups" ]; then
all_contacts | grep -v '+.*+'
else
all_contacts
fi
elif [ "$1" = "--no-groups" ]; then
contacts | grep -v '+.*+'
elif [ "$1" = "--unknown" ]; then
unknown_contacts
elif [ "$1" = "--texted" ]; then
texted_contacts
elif [ "$1" = "--called" ]; then
called_contacts
elif [ "$1" = "--me" ]; then
all_contacts \
| grep "^Me: " \
| sed 's|^Me: ||'
elif [ "$1" = "--name-or-number" ]; then
if [ -z "$2" ]; then
printf "???\n"
else
contact="$(sxmo_contacts.sh --name "$2")"
if [ "$contact" = "???" ] || [ -z "$contact" ]; then
contact="$2"
fi
printf %s "$contact"
fi
elif [ "$1" = "--name" ]; then
if [ -z "$2" ]; then
printf "???\n"
else
awk -F'\t' -v num="$2" '
$1 == num { name = $2 }
END {
gsub(/^[ \t]+|[ \t]+$/, "", name)
print (length(name) ? name : "???")
}
' "$SXMO_CONTACTFILE"
fi
elif [ -n "$*" ]; then
all_contacts | grep -i -F "$*"
else
contacts
fi
+1 -1
View File
@@ -62,7 +62,7 @@ make_attachments_arg() {
}
if ! echo "$NUMBER" | grep -q '^+'; then
ACTUAL_NUMBER="$(sxmo_contacts.sh --all | grep "^$NUMBER:" | cut -d':' -f2 | sed 's/^ //')"
ACTUAL_NUMBER="$(sxmo_contacts.sh --all | awk -F': ' -v n="$NUMBER" '$1 == n {print $2; exit}')"
if [ -z "$ACTUAL_NUMBER" ]; then
info "WARNING: $NUMBER does not look like a phone number or a contact."
else
+28 -25
View File
@@ -12,10 +12,15 @@ notify_user() {
title="$1"
body="$2"
if command -v notify-send >/dev/null 2>&1; then
bus_addr="unix:path=/run/user/10000/bus"
if [ -r /run/user/10000/dbus.bus ]; then
IFS= read -r bus_line < /run/user/10000/dbus.bus 2>/dev/null || true
[ -n "$bus_line" ] && bus_addr="$bus_line"
fi
if [ "$(id -u)" -eq 0 ]; then
su - user -c "DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/10000/bus notify-send '$title' '$body'" >/dev/null 2>&1 &
su - user -c "DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=\"$bus_addr\" notify-send \"$title\" \"$body\"" >/dev/null 2>&1 &
else
DISPLAY="${DISPLAY:-:0}" notify-send "$title" "$body" >/dev/null 2>&1 &
DISPLAY="${DISPLAY:-:0}" DBUS_SESSION_BUS_ADDRESS="${DBUS_SESSION_BUS_ADDRESS:-$bus_addr}" notify-send "$title" "$body" >/dev/null 2>&1 &
fi
fi
}
@@ -79,26 +84,22 @@ probe_controller() {
if [ -f /tmp/bananarchy_duress_mode ]; then
return 1
fi
if [ -b /dev/mmcblk1 ]; then
return 0
fi
if [ -w /sys/bus/platform/drivers/sdhci_msm/unbind ]; then
if [ -e /sys/bus/platform/drivers/sdhci_msm/7864900.sdhci ]; then
find_sd_disk >/dev/null 2>&1 && return 0
if [ -w /sys/bus/platform/drivers/sdhci_msm/bind ]; then
if [ -e /sys/bus/platform/drivers/sdhci_msm/7864900.sdhci ] && [ -w /sys/bus/platform/drivers/sdhci_msm/unbind ]; then
printf "7864900.sdhci" > /sys/bus/platform/drivers/sdhci_msm/unbind 2>/dev/null || true
sleep 0.2
sleep 0.15
fi
printf "7864900.sdhci" > /sys/bus/platform/drivers/sdhci_msm/bind 2>/dev/null || true
printf "auto" > /sys/devices/platform/soc@0/7864900.sdhci/power/control 2>/dev/null || true
i=0
while [ "$i" -lt 12 ]; do
[ -b /dev/mmcblk1 ] && return 0
find_sd_disk >/dev/null 2>&1 && return 0
sleep 0.1
i="$(( i + 1 ))"
done
if [ ! -b /dev/mmcblk1 ]; then
printf "7864900.sdhci" > /sys/bus/platform/drivers/sdhci_msm/unbind 2>/dev/null || true
fi
fi
[ -b /dev/mmcblk1 ]
find_sd_disk >/dev/null 2>&1
}
do_mount() {
@@ -107,7 +108,7 @@ do_mount() {
return 1
fi
if [ "$(id -u)" -ne 0 ]; then
exec doas /usr/bin/sxmo_sdcard.sh mount "$@"
exec doas -n /usr/bin/sxmo_sdcard.sh mount "$@"
fi
if is_mounted; then
@@ -141,6 +142,7 @@ do_mount() {
fi
;;
exfat)
modprobe -q exfat 2>/dev/null || true
if mount -t exfat -o "rw,nosuid,nodev,noatime,uid=${USER_UID},gid=${USER_GID},fmask=0022,dmask=0022" "$part" "$MOUNT_POINT" 2>/dev/null || \
mount -o "rw,nosuid,nodev,noatime,uid=${USER_UID},gid=${USER_GID}" "$part" "$MOUNT_POINT" 2>/dev/null; then
mounted_ok=1
@@ -153,12 +155,15 @@ do_mount() {
fi
;;
ext4|ext3|ext2|f2fs|btrfs|xfs)
[ "$fstype" = "f2fs" ] && { modprobe -q f2fs 2>/dev/null || true; }
[ "$fstype" = "btrfs" ] && { modprobe -q btrfs 2>/dev/null || true; }
if mount -o "rw,nosuid,nodev,noatime" "$part" "$MOUNT_POINT" 2>/dev/null; then
mounted_ok=1
chown "${USER_UID}:${USER_GID}" "$MOUNT_POINT" 2>/dev/null || true
fi
;;
*)
modprobe -q exfat f2fs 2>/dev/null || true
if mount -o "rw,nosuid,nodev,noatime,uid=${USER_UID},gid=${USER_GID}" "$part" "$MOUNT_POINT" 2>/dev/null || \
mount -o "rw,nosuid,nodev,noatime" "$part" "$MOUNT_POINT" 2>/dev/null; then
mounted_ok=1
@@ -185,7 +190,7 @@ do_mount() {
do_unmount() {
if [ "$(id -u)" -ne 0 ]; then
exec doas /usr/bin/sxmo_sdcard.sh unmount "$@"
exec doas -n /usr/bin/sxmo_sdcard.sh unmount "$@"
fi
force_mode=0
@@ -226,7 +231,7 @@ do_rescan() {
return 1
fi
if [ "$(id -u)" -ne 0 ]; then
exec doas /usr/bin/sxmo_sdcard.sh rescan
exec doas -n /usr/bin/sxmo_sdcard.sh rescan
fi
probe_controller || true
if find_sd_part >/dev/null 2>&1; then
@@ -341,23 +346,21 @@ case "$cmd" in
if [ -f /tmp/bananarchy_duress_mode ]; then
exit 0
fi
if [ ! -e /sys/bus/platform/drivers/sdhci_msm/7864900.sdhci ] && [ -w /sys/bus/platform/drivers/sdhci_msm/bind ]; then
printf "7864900.sdhci" > /sys/bus/platform/drivers/sdhci_msm/bind 2>/dev/null || true
fi
printf "auto" > /sys/devices/platform/soc@0/7864900.sdhci/power/control 2>/dev/null || true
if [ -n "$kname" ]; then
do_mount "/dev/$kname" >/dev/null 2>&1 || true
else
if find_sd_part >/dev/null 2>&1; then
do_mount >/dev/null 2>&1 || true
elif [ -w /sys/bus/platform/drivers/sdhci_msm/unbind ]; then
printf "7864900.sdhci" > /sys/bus/platform/drivers/sdhci_msm/unbind 2>/dev/null || true
fi
elif find_sd_part >/dev/null 2>&1; then
do_mount >/dev/null 2>&1 || true
fi
;;
remove)
if [ "$(id -u)" -eq 0 ]; then
umount -l "$MOUNT_POINT" 2>/dev/null || true
rm -f "$STATE_FILE" 2>/dev/null || true
if [ -w /sys/bus/platform/drivers/sdhci_msm/unbind ]; then
printf "7864900.sdhci" > /sys/bus/platform/drivers/sdhci_msm/unbind 2>/dev/null || true
fi
printf "auto" > /sys/devices/platform/soc@0/7864900.sdhci/power/control 2>/dev/null || true
if [ ! -f /tmp/bananarchy_duress_mode ]; then
notify_user "SD Card" "SD card removed"
fi
+1 -1
View File
@@ -75,7 +75,7 @@ run_session_x() {
cmd_startx="$cmd_startx $arg"
done
cmd_startx="$cmd_startx -- -nocursor -nolisten tcp vt1 -keeptty"
cmd_startx="$cmd_startx -- -nolisten tcp vt1 -keeptty"
# shellcheck disable=SC2086
exec setpriv --ambient-caps '-all' $cmd_startx
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,9 @@
monitor.bluez.properties = {
bluez5.roles = [ a2dp_sink a2dp_source bap_sink bap_source hsp_hs hsp_ag hfp_hf hfp_ag ]
bluez5.codecs = [ sbc sbc_xq aac ldac aptx aptx_hd aptx_ll aptx_ll_duplex faststream faststream_duplex opus_05 opus_05_51 opus_05_71 opus_05_dup opus_05_pro lc3 ]
bluez5.enable-sbc-xq = true
bluez5.enable-msbc = true
bluez5.enable-hw-volume = true
bluez5.hfphsp-backend = "native"
bluez5.hfphsp-backend-native-modem = "any"
}