diff --git a/CHANGELOG.md b/CHANGELOG.md index 57a3e8a..d0b8c63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,7 +28,7 @@ Release versions follow the `
` format (where `2026` is `a`, - Added a persistent BlueZ `NoInputNoOutput` default pairing/authorization agent (`/org/bananarchy/bt_agent`) and D-Bus `connect`/`pair` handler inside `/usr/bin/bananarchy-bt-obex` (skipping redundant pre-connect inquiry scans for known BlueZ devices and automatically recovering from stale `[LinkKey]` `br-connection-key-missing` errors) for seamless BLE HOGP (`00001812`), Classic HID (`00001124`), and A2DP/HFP bonding and reconnection, an automatic `/dev/uinput` gamepad-to-keypad bridge (`Bananarchy BT Gamepad Bridge`, excluding QWERTY keyboards) so Bluetooth/USB gamepads (`D-Pad` / `Left Stick` -> `Up`/`Down`/`Left`/`Right`, `South/A` -> `Enter`, `East/B` -> `8`, `West/X` -> `5`, `North/Y` -> `6`, `Start` -> `2`, `Select` -> `3`, `L1`/`R1` -> `Left`/`Right softkey`, `L2`/`R2` -> `*`/`0`, `Mode` -> `Escape`) control all NeoUI apps and games (`snake`, `tetris`, `scoundrel`, `gambatte`, `remedy`) out of the box, automatic `[KBD]` external keyboard detection (`isExternalKeyboardActive()`) in `fcitx5-t9`, `libneoui.so`, and DWM plugins so connecting a Bluetooth/USB QWERTY keyboard automatically bypasses T9 multi-tap and preedit popups for all keys (`0-9`, `*`, `#`, `Shift+0-9`, and letters), and automatic `XFixes` cursor display in `dwm` (`dwm_has_external_mouse()`) whenever a Bluetooth/USB mouse is connected. - **Universal Power button (`dmenu power`) access, background call termination, lockscreen X11 grab preemption, ReMEdy `Call (green)` pause menu, JSR expansion, and 64 MB mark-and-sweep GC**: - Updated `dwm`, `dmenu`, `xdrawer`, `libneoui.so`, `sxmo_multikey.sh`, all standalone Xlib DWM plugins, and standalone games (`scoundrel`, `gambatte`, `remedy`) so pressing **End / Power (red)** (`XF86PowerOff`, keycode `124`) from any active window or menu immediately ends any incoming, outgoing, or active call (even when `xcallscreen` has been switched away from in the background) or opens the system **Power menu (`dmenu power`)** when no call is active, while mapped **Call (green)** (`XF86Phone` / `XF86PickupPhone`) and `500 ms` **Right softkey** hold in `remedy` open the **ReMEdy Pause Menu**. - - Updated `callscreen.so` (`xcallscreen`), `locker.so` (`xlocker`), `dwm` (`lock_phone_screenoff` on `SW_LID = 1`), `sxmo_hook_lock.sh`, `sxmo_modemcall.sh`, `sxmo_modemdial.sh`, and `msm-modem-uim-selection` so locking the screen or sliding the lid closed immediately hangs up any incoming, outgoing, or active cellular/VoIP call and closes `xcallscreen`, fixed DSDS QMI `call-dial` / `call-hangup all` / `dsds-daemon` state tracking so secondary-SIM calls are never orphaned when switching apps, and eliminated duplicate `xlocker` startup activations across `bananarchy-x11-session.sh`, `sxmo_hook_start.sh`, `sxmo_hook_lock.sh`, and `locker.so`. + - Updated `callscreen.so` (`xcallscreen`), `dialer.so` (`xdialer`), `contacts.so` (`xcontacts`), `calllog.so` (`xcalllog`), `sms.so` (`xsms`), `locker.so` (`xlocker`), `dwm` (`lock_phone_screenoff` on `SW_LID = 1`), `sxmo_hook_lock.sh`, `sxmo_modemcall.sh`, `sxmo_modemdial.sh`, `sxmo_modemaudio.sh`, `sxmo_modem.sh`, `sxmo_modemmonitor.sh`, and `msm-modem-uim-selection` so locking the screen, sliding the lid closed, or pressing Hangup immediately sends `QMI_VOICE_END_CALL` (`0x0021`) over `AF_QIPCRTR` (`sub=1` and `sub=0`) in `< 10 ms`, aborts any in-flight `sxmo_modemdial.sh` pipeline via `/tmp/sxmo_hangup_requested`, starts Primary GW (`mmcli`) calls immediately upon creation without duplicate audio setup or background `incall_menu` jobs, guards `dialer` and `callscreen` against stale post-hangup or mid-call window popups, serializes `sxmo_modemaudio.sh` call-audio teardown (`flock` on `/tmp/sxmo_modemaudio.lock`), and prevents `callscreen` from fighting `dunst` notifications on `VisibilityNotify`, while eliminating duplicate `xlocker` and `dsds-daemon` startup instances. - Upgraded **ReMEdy (`remedy` / `j2me`)** with a `64 MB` heap budget and mark-and-sweep garbage collector (`System.gc()` / `Runtime.gc()`, `freeSlots_` object reuse, and full heap/JAR release on MIDlet exit), synchronous `Canvas.serviceRepaints()`, `Thread.yield()` / `Thread.sleep()` background thread stepping, synthetic native static field storage (`System.out`, `System.err`, `List.SELECT_COMMAND`, `AlertType.*`, `Boolean.TRUE/FALSE`), exact `String` reference preservation in `List.getString()` and `ChoiceGroup.getString()` (for `MeBoy` / `GTA 2` GBC-to-J2ME cartridges), `java.io.InputStreamReader` / `OutputStreamWriter`, `java.lang.Float` / `Double` / `Character`, **JSR-75** (`FileSystemRegistry` / `FileConnection`), **JSR-82** (`javax.bluetooth.*`), **JSR-120** (`javax.wireless.messaging.*`), **JSR-135** (`MIDIControl`), full **Nokia `DirectGraphics`** (`drawPixels`, `getPixels`, `fillPolygon`, `drawPolygon`, `fillTriangle`, `drawTriangle`, `setARGBColor`), and automatic/configurable sub-QVGA (`128x128`, `128x160`, `176x208`, `176x220`) canvas scaling (`Asphalt 6: Adrenaline`). - **Kernel-to-userspace battery, charging, fuel-gauge, and idle power optimizations**: - Fixed PM8909/PM8916 linear battery charger (`pm8916_lbc.ko.zst`) hardware state-machine engagement by writing `MISC_BOOT_DONE` (`0x1642 = 0x80`), overriding the internal charger comparator (`0x10d0 = 0xa5`, `0x10ee = 0x02`), stopping the USB enumeration watchdog timer (`0x134e = 0x00`, `0x104e = 0x00`), clearing `USB_SUSP` (`0x1347 = 0x00`) and `CHG_FAILED` (`0x104a = 0x80`), enabling `BAT_IF` thermistor pull-ups (`0x1248`, `0x124a`), re-arming `CHG_CTRL = 0x81` on every `usb_vbus` plug event, and setting `qcom,fast-charge-safe-current = 540 mA` (`4.375 V`) across all 5 device trees (`nokia-argon`, `nokia-beatles`, `nokia-tough`, `nokia-sparkler`, `nokia-leo`) so USB charging engages `FAST_CHG_ON` (`0x1010 = 0x20`) instead of idling at `90 mA`. @@ -41,7 +41,7 @@ Release versions follow the `
` format (where `2026` is `a`, - Set the DSDS `msm-modem-uim-selection` `select()` timeout to infinite (`None`, pure `AF_QIPCRTR` event-driven wait) while the screen is locked and `600s` when unlocked, added `neoui_next_timeout_ms()` to `libneoui.so`, wired GLib `GMainContext` file descriptors and `"load-failed"` / `closeWindow()` load-stop handling into `webarchy.so` (along with `NO_AT_BRIDGE=1` and `GTK_A11Y=none`), added `inotify` directory watching to `sms.so`, and eliminated idle periodic `poll()` timers across `dialer.so`, `calllog.so`, `contacts.so`, `sms.so`, `xdrawer.so`, `locker.so`, `email.so`, `irc.so`, `smallweb.so`, `tox.so`, `sip.so`, and `webarchy.so` so visible and background plugins sleep at `0%` CPU unless a transient timer (`softkey` chord, multi-tap window, or toast expiry) is active. - Skipped `dwm` `drawbar()` Xorg/Glamor/SPI redraws and `sxmo_hook_statusbar.sh` process spawns whenever `bl_power != 0`, `brightness == 0`, or `/tmp/bananarchy_screen_locked` exists (with immediate bar refresh on wake/unlock), fast-exited `sxmo_hook_statusbar.sh periodics` before sourcing hooks while locked or screenoff, serialized `bananarchy-sync-dunst-theme` with `flock` without spawning duplicate unmanaged `dunst` instances under `superd` (preventing `dunst` respawn storms), disabled NetworkManager periodic connectivity polling (`[connectivity] enabled=false`), and wrapped background spawns in double-fork subshells `( ... & )` across `bananarchy-x11-session.sh`, `sxmo_modemmonitor.sh`, `sxmo_hook_start.sh`, `sxmo_hook_postwake.sh`, and `msm-modem-uim-selection` to eliminate zombie child accumulation. - Fixed spontaneous screen blanking after sliding the keypad lid open and eliminated passcode entry lag in `xlocker` (`locker.so`) and `dwm` by removing queued asynchronous `sxmo_state.sh set screenoff` shell spawns from `lock_phone_screenoff()`, adding a `60 ms` `SW_LID` close debounce (`EVIOCGSW`) with instant wake on open, resetting `locker.so` inactivity timer on every unblank transition (`wasScreenBlanked`), forwarding any `dwm`-intercepted key events while locked directly to `/tmp/dwm_plugin_locker.fifo` (`KEY `), caching `locker.so` battery/notification status with a `10s` TTL, debouncing multi-digit auto-verification by `220 ms`, and adding a per-session random-salted 64-bit fast verification cache invalidated automatically on `/etc/shadow` or `/etc/bananarchy_duress.hash` changes. - - Replaced the standalone `conky` process with native `dwm` desktop clock rendering (`m->clockwin` `ParentRelative` window at `Y = 29, H = 92`) using the exact same `Fira Code` fonts (`32pt` `%H:%M` at `Y = 43..73` and `14pt` `%a %d %b %Y` at `Y = 87..101`), white foreground, and 1px black drop shadow, eliminating the `conky` daemon, its periodic X11 wakeup timers, and all `pkill -STOP/-CONT conky` process spawns across lock/unlock, statusbar, and timezone transitions. + - Replaced the standalone `conky` process with native `dwm` desktop clock rendering (`m->clockwin` `ParentRelative` window at `Y = 29, H = 92`) using the exact same `Fira Code` fonts (`32pt` `%H:%M` at `Y = 43..73` and `14pt` `%a %d %b %Y` at `Y = 87..101`), white foreground, and 1px black drop shadow, caching rendered clock/softbar state (`drawclock` and `drawsoftbar`) so statusbar updates (`xsetroot -name`) never clear or flash `m->clockwin` or `m->softwin` unless exposed or changed, and eliminating the `conky` daemon, its periodic X11 wakeup timers, and all `pkill -STOP/-CONT conky` process spawns across lock/unlock, statusbar, and timezone transitions. - **Zero-log privacy default and Extended Logging feature setting (`engmenu.so` / `xengmenu`, `dmenu.so`, `bananarchy-engmenu-ctl`)**: - Disabled extended system and session logging by default (`OFF`) across `sxmo_log()` / `sxmo_debug()`, `superd` (`-l /dev/null` and `/tmp/superd_state/superd/logs/*.log -> /dev/null`), `Xorg` (`-logfile /dev/null -logverbose 0`), `dwm`, `fcitx5` (`--verbose="*=0"`), `tinydm` (`tinydm-run-session`), `NetworkManager` (`level=OFF`), `ModemManager` (`--log-level=ERR --log-file=/dev/null`), and kernel `printk` (`1 4 1 1`), purging persistent log files from `~/.local/state/` and `/var/log/` so idle mode produces zero log writes. - Added the **Extended Logging** toggle (`OFF` by default) to the **Engineering Menu (`*#0001#` / `xengmenu` -> `8: Extended Logging`)**, **Config Menu (`Config -> Extended Logging`)**, and `/usr/bin/bananarchy-engmenu-ctl logging [on|off|toggle|status]`, storing volatile diagnostic logs strictly in RAM (`/tmp/sxmo.log`, `/tmp/superd.log`, `/tmp/superd_state/superd/logs/*.log`) when enabled and purging them immediately when disabled. diff --git a/overlay/rootfs/usr/bin/dwm b/overlay/rootfs/usr/bin/dwm index 375f8b5..5ff1631 100755 Binary files a/overlay/rootfs/usr/bin/dwm and b/overlay/rootfs/usr/bin/dwm differ diff --git a/overlay/rootfs/usr/bin/sxmo_modem.sh b/overlay/rootfs/usr/bin/sxmo_modem.sh index f48db89..21fdcce 100755 --- a/overlay/rootfs/usr/bin/sxmo_modem.sh +++ b/overlay/rootfs/usr/bin/sxmo_modem.sh @@ -60,25 +60,21 @@ checkforfinishedcalls() { if [ -f "$XDG_RUNTIME_DIR/sxmo_calls/${FINISHEDCALLID}.discardedcall" ]; then #this call was discarded STATE=discarded - sxmo_notify_user.sh "Call with $CONTACT terminated" stderr "Discarded call from $FINISHEDNUMBER" printf %b "$TIME\tcall_finished\t$FINISHEDNUMBER\n" >> "$SXMO_LOGDIR/modemlog.tsv" elif [ -f "$XDG_RUNTIME_DIR/sxmo_calls/${FINISHEDCALLID}.pickedupcall" ]; then #this call was picked up STATE=pickedup - sxmo_notify_user.sh "Call with $CONTACT terminated" stderr "Finished call from $FINISHEDNUMBER" printf %b "$TIME\tcall_finished\t$FINISHEDNUMBER\n" >> "$SXMO_LOGDIR/modemlog.tsv" - elif [ -f "$XDG_RUNTIME_DIR/sxmo_calls/${FINISHEDCALLID}.hangedupcall" ]; then + elif [ -f "$XDG_RUNTIME_DIR/sxmo_calls/${FINISHEDCALLID}.hangedupcall" ] || [ -f /tmp/sxmo_hangup_requested ]; then #this call was hung up by the user STATE=wehangedup - sxmo_notify_user.sh "Call with $CONTACT terminated" stderr "Finished call from $FINISHEDNUMBER" printf %b "$TIME\tcall_finished\t$FINISHEDNUMBER\n" >> "$SXMO_LOGDIR/modemlog.tsv" elif [ -f "$XDG_RUNTIME_DIR/sxmo_calls/${FINISHEDCALLID}.initiatedcall" ]; then STATE=theyhangedup #this call was hung up by the contact - sxmo_notify_user.sh "Call with $CONTACT terminated" stderr "Finished call from $FINISHEDNUMBER" printf %b "$TIME\tcall_finished\t$FINISHEDNUMBER\n" >> "$SXMO_LOGDIR/modemlog.tsv" elif [ -f "$XDG_RUNTIME_DIR/sxmo_calls/${FINISHEDCALLID}.blockedcall" ]; then diff --git a/overlay/rootfs/usr/bin/sxmo_modemaudio.sh b/overlay/rootfs/usr/bin/sxmo_modemaudio.sh index 3c881ce..68609a7 100755 --- a/overlay/rootfs/usr/bin/sxmo_modemaudio.sh +++ b/overlay/rootfs/usr/bin/sxmo_modemaudio.sh @@ -41,6 +41,8 @@ switch_bt_card_a2dp() { } 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")" @@ -56,13 +58,15 @@ enable_call_audio_mode() { 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 cset "name='INT_BT_SCO_RX Audio Mixer MultiMedia1'" 0 >/dev/null 2>&1 || true - amixer -c 0 cset "name='MultiMedia2 Mixer INT_BT_SCO_TX'" 0 >/dev/null 2>&1 || true - amixer -c 0 cset "name='MultiMedia2 Mixer TERT_MI2S_TX'" 0 >/dev/null 2>&1 || true - amixer -c 0 cset "name='PRI_MI2S_RX Voice Mixer VoiceMMode1'" 0 >/dev/null 2>&1 || true - amixer -c 0 cset "name='VoiceMMode1 Capture Mixer TERT_MI2S_TX'" 0 >/dev/null 2>&1 || true - amixer -c 0 cset "name='INT_BT_SCO_RX Voice Mixer VoiceMMode1'" 1 >/dev/null 2>&1 || true - amixer -c 0 cset "name='VoiceMMode1 Capture Mixer INT_BT_SCO_TX'" 1 >/dev/null 2>&1 || true + 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 @@ -72,21 +76,28 @@ enable_call_audio_mode() { 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 cset "name='INT_BT_SCO_RX Voice Mixer VoiceMMode1'" 0 >/dev/null 2>&1 || true - amixer -c 0 cset "name='VoiceMMode1 Capture Mixer INT_BT_SCO_TX'" 0 >/dev/null 2>&1 || true - amixer -c 0 cset "name='PRI_MI2S_RX Voice Mixer VoiceMMode1'" 1 >/dev/null 2>&1 || true - amixer -c 0 cset "name='VoiceMMode1 Capture Mixer TERT_MI2S_TX'" 1 >/dev/null 2>&1 || true - amixer -c 0 cset "name='MultiMedia2 Mixer TERT_MI2S_TX'" 0 >/dev/null 2>&1 || true - amixer -c 0 cset "name='RX1 Mute Switch'" 0 >/dev/null 2>&1 || true + 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)." - sxmo_hook_statusbar.sh volume >/dev/null 2>&1 || true 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)" @@ -96,18 +107,26 @@ disable_call_audio_mode() { fi if command -v amixer >/dev/null 2>&1; then - amixer -c 0 cset "name='INT_BT_SCO_RX Voice Mixer VoiceMMode1'" 0 >/dev/null 2>&1 || true - amixer -c 0 cset "name='VoiceMMode1 Capture Mixer INT_BT_SCO_TX'" 0 >/dev/null 2>&1 || true - amixer -c 0 cset "name='PRI_MI2S_RX Voice Mixer VoiceMMode1'" 0 >/dev/null 2>&1 || true - amixer -c 0 cset "name='VoiceMMode1 Capture Mixer TERT_MI2S_TX'" 0 >/dev/null 2>&1 || true - amixer -c 0 cset "name='INT_BT_SCO_RX Audio Mixer MultiMedia1'" 0 >/dev/null 2>&1 || true - amixer -c 0 cset "name='MultiMedia2 Mixer INT_BT_SCO_TX'" 0 >/dev/null 2>&1 || true - amixer -c 0 cset "name='PRI_MI2S_RX Audio Mixer MultiMedia1'" 1 >/dev/null 2>&1 || true - amixer -c 0 cset "name='MultiMedia2 Mixer TERT_MI2S_TX'" 1 >/dev/null 2>&1 || true + 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 + pkill -TERM -f "pacat --playback --device=bluez_output" 2>/dev/null || true 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 @@ -122,7 +141,6 @@ disable_call_audio_mode() { fi sxmo_log "Disabled ALSA voice call audio mode ($target_out)." - sxmo_hook_statusbar.sh volume >/dev/null 2>&1 || true return 0 } diff --git a/overlay/rootfs/usr/bin/sxmo_modemcall.sh b/overlay/rootfs/usr/bin/sxmo_modemcall.sh index b346715..cefe161 100755 --- a/overlay/rootfs/usr/bin/sxmo_modemcall.sh +++ b/overlay/rootfs/usr/bin/sxmo_modemcall.sh @@ -132,13 +132,25 @@ pickup() { hangup() { CALLID="${1:-all}" + touch /tmp/sxmo_hangup_requested 2>/dev/null || true + pkill -TERM -f sxmo_modemdial.sh 2>/dev/null || true case "$CALLID" in ""|"-"|"all") - rm -f "$XDG_RUNTIME_DIR/sxmo_calls/"* /tmp/sxmo_call_ringing /tmp/sxmo_active_call 2>/dev/null || true - mmcli -m any --voice-hangup-all >/dev/null 2>&1 || true + for f in "$XDG_RUNTIME_DIR"/sxmo_calls/*.initiatedcall "$XDG_RUNTIME_DIR"/sxmo_calls/*.pickedupcall; do + [ -e "$f" ] || continue + base="${f%.*}" + rm -f "$f" 2>/dev/null || true + touch "${base}.hangedupcall" 2>/dev/null || true + done + rm -f "$XDG_RUNTIME_DIR"/sxmo_calls/sub1_* "$XDG_RUNTIME_DIR"/sxmo_calls/sub0_* /tmp/sxmo_call_ringing /tmp/sxmo_active_call 2>/dev/null || true doas -n /usr/libexec/msm-modem-uim-selection call-hangup all >/dev/null 2>&1 || \ /usr/libexec/msm-modem-uim-selection call-hangup all >/dev/null 2>&1 || true + mmcli -m any --voice-hangup-all >/dev/null 2>&1 || true + for cid in $(mmcli -m any --voice-list-calls 2>/dev/null | grep -oE 'Call/[0-9]+' | cut -d/ -f2); do + mmcli -m any -o "$cid" --hangup >/dev/null 2>&1 || true + mmcli -m any --voice-delete-call="$cid" >/dev/null 2>&1 || true + done doas -n dbus-send --system --type=signal / org.ofono.VoiceCallManager.CallRemoved >/dev/null 2>&1 || true sxmo_hook_hangup.sh || true return 0 @@ -176,6 +188,7 @@ hangup() { ! mmcli -m any --voice-hangup-all 2>/dev/null && \ ! doas -n /usr/libexec/msm-modem-uim-selection call-hangup "$CALLID" >/dev/null 2>&1 && \ ! doas -n /usr/libexec/msm-modem-uim-selection call-hangup all >/dev/null 2>&1; then + mmcli -m any --voice-delete-call="$CALLID" >/dev/null 2>&1 || true # we ignore already closed calls if list_active_calls | grep -q "/$CALLID "; then HANGUP_FAILED=1 @@ -203,6 +216,7 @@ list_active_calls() { mmcli -m any --voice-list-calls 2>/dev/null | \ awk '$1=$1' | \ grep -v terminated | \ + grep -v "(unknown)" | \ grep -v "No calls were found" | while read -r line; do CALLID="$(printf "%s\n" "$line" | awk '$1=$1' | cut -d" " -f1 | xargs basename)" if [ -e "$XDG_RUNTIME_DIR/sxmo_calls/${CALLID}.mutedring" ]; then @@ -242,8 +256,6 @@ incall_menu() { xcallscreen active "$CALLID" "$NUMBER" >/dev/null 2>&1 || true ;; esac - else - xcallscreen >/dev/null 2>&1 || true fi return 0 fi diff --git a/overlay/rootfs/usr/bin/sxmo_modemdial.sh b/overlay/rootfs/usr/bin/sxmo_modemdial.sh index 8f6260c..4914dd3 100755 --- a/overlay/rootfs/usr/bin/sxmo_modemdial.sh +++ b/overlay/rootfs/usr/bin/sxmo_modemdial.sh @@ -19,7 +19,13 @@ if [ "${1:-}" = "--sim" ] && [ -n "${2:-}" ]; then 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)" + UIM_ST="" + if [ -r /tmp/sxmo_sim_slots ]; then + UIM_ST="$(cat /tmp/sxmo_sim_slots 2>/dev/null || true)" + fi + if [ -z "$UIM_ST" ]; then + UIM_ST="$(doas -n /usr/libexec/msm-modem-uim-selection slots 2>/dev/null || /usr/libexec/msm-modem-uim-selection slots 2>/dev/null || true)" + fi 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}')" @@ -31,24 +37,29 @@ resolve_sim_state() { } 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 + rm -f /tmp/sxmo_hangup_requested 2>/dev/null || true + + # on pinephone if you attempt to make a call while in a call, modem crashes + if [ "$(cat /tmp/sxmo_active_call 2>/dev/null)" = "1" ] && 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 + resolve_sim_state + [ -f /tmp/sxmo_hangup_requested ] && return 0 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 + if [ -p "/tmp/dwm_plugin_callscreen.fifo" ]; then printf "PROMPT_SIM %s\n" "$NUMBER" > /tmp/dwm_plugin_callscreen.fifo 2>/dev/null || true + return 0 + elif command -v xcallscreen >/dev/null 2>&1; then xcallscreen >/dev/null 2>&1 || true return 0 fi @@ -65,39 +76,32 @@ dial_number() { 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 + if [ ! -f /tmp/sxmo_hangup_requested ]; 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 - sxmo_notify_user.sh --urgency=critical "We failed to initiate call on SIM $TARGET_SIM" - return 1 + return 0 + fi + if [ -f /tmp/sxmo_hangup_requested ]; then + doas -n /usr/libexec/msm-modem-uim-selection call-hangup "$CALLID" >/dev/null 2>&1 || true + return 0 fi rm -f "$XDG_RUNTIME_DIR/sxmo_calls/${CALLID}.terminated" \ "$XDG_RUNTIME_DIR/sxmo_calls/${CALLID}.hangedupcall" \ "$XDG_RUNTIME_DIR/sxmo_calls/${CALLID}.discardedcall" 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 + 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 + fi sxmo_hook_dial.sh || true sxmo_modemaudio.sh setup_audio || true - if [ -p "/tmp/dwm_plugin_callscreen.fifo" ]; then - if [ -f "$XDG_RUNTIME_DIR/sxmo_calls/${CALLID}.active" ]; then - printf "ACTIVE %s %s SIM%s\n" "$CALLID" "$NUMBER" "$TARGET_SIM" > /tmp/dwm_plugin_callscreen.fifo 2>/dev/null || true - else - printf "OUTGOING %s %s SIM%s\n" "$CALLID" "$NUMBER" "$TARGET_SIM" > /tmp/dwm_plugin_callscreen.fifo 2>/dev/null || true - fi - elif command -v xcallscreen >/dev/null 2>&1; then - xcallscreen outgoing "$CALLID" "$NUMBER" >/dev/null 2>&1 || true - fi 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 - mmcli -m any --3gpp-register-home >/dev/null 2>&1 || true - sleep 1 - fi - 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 @@ -105,20 +109,42 @@ dial_number() { xcallscreen outgoing "-" "$NUMBER" >/dev/null 2>&1 || true fi - if ! CALLID="$( + 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 + grep -oE "[0-9]+" || true + )" + if [ -z "$CALLID" ]; then + mmcli -m any -e >/dev/null 2>&1 || true + mmcli -m any --3gpp-register-home >/dev/null 2>&1 || true + sleep 1 + [ -f /tmp/sxmo_hangup_requested ] && return 0 + CALLID="$( + mmcli -m any --voice-create-call="number=$NUMBER" 2>/dev/null | + grep -Eo "Call/[0-9]+" | + grep -oE "[0-9]+" || true + )" + fi + if [ -z "$CALLID" ]; then + if [ ! -f /tmp/sxmo_hangup_requested ]; 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 - sxmo_notify_user.sh --urgency=critical "We failed to initiate call" - return 1 + return 0 + fi + + if [ -f /tmp/sxmo_hangup_requested ]; then + mmcli -m any -o "$CALLID" --hangup >/dev/null 2>&1 || true + mmcli -m any --voice-delete-call="$CALLID" >/dev/null 2>&1 || true + return 0 fi # cleanup all dangling event files, ignore errors - rm "$XDG_RUNTIME_DIR/sxmo_calls/$CALLID."* 2>/dev/null || true + rm -f "$XDG_RUNTIME_DIR/sxmo_calls/$CALLID."* 2>/dev/null || true + touch "$XDG_RUNTIME_DIR/sxmo_calls/${CALLID}.initiatedcall" sxmo_log "Starting call with CALLID: $CALLID" 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 @@ -126,30 +152,35 @@ dial_number() { xcallscreen outgoing "$CALLID" "$NUMBER" >/dev/null 2>&1 || true fi + if ! mmcli -m any -o "$CALLID" --start >/dev/null 2>&1; then + rm -f "$XDG_RUNTIME_DIR/sxmo_calls/$CALLID."* 2>/dev/null || true + mmcli -m any --voice-delete-call="$CALLID" >/dev/null 2>&1 || true + if [ ! -f /tmp/sxmo_hangup_requested ]; 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 start the call" + return 1 + fi + return 0 + fi + + if [ -f /tmp/sxmo_hangup_requested ]; then + mmcli -m any -o "$CALLID" --hangup >/dev/null 2>&1 || true + mmcli -m any --voice-delete-call="$CALLID" >/dev/null 2>&1 || true + rm -f "$XDG_RUNTIME_DIR/sxmo_calls/$CALLID."* 2>/dev/null || true + return 0 + fi + + { + mkdir -p "$SXMO_LOGDIR" && + printf "%s\tcall_start\t%s\t[SIM %s]\n" "$(date +%FT%H:%M:%S%z)" "$NUMBER" "$TARGET_SIM" >> "$SXMO_LOGDIR/modemlog.tsv" + } 2>/dev/null || true + 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_hook_dial.sh || true + sxmo_modemaudio.sh setup_audio || true sxmo_hook_statusbar.sh state & - - sxmo_jobs.sh start incall_menu sxmo_modemcall.sh incall_menu } dial_ussd() { diff --git a/overlay/rootfs/usr/bin/sxmo_modemmonitor.sh b/overlay/rootfs/usr/bin/sxmo_modemmonitor.sh index b748039..3d216bd 100755 --- a/overlay/rootfs/usr/bin/sxmo_modemmonitor.sh +++ b/overlay/rootfs/usr/bin/sxmo_modemmonitor.sh @@ -70,8 +70,11 @@ mainloop() { fi while : ; do if [ "$(cat /tmp/sxmo_dsds_active 2>/dev/null || echo 0)" = "1" ]; then - doas -n /usr/libexec/msm-modem-uim-selection dsds-daemon 2>/dev/null || \ + if command -v doas >/dev/null 2>&1; then + doas -n /usr/libexec/msm-modem-uim-selection dsds-daemon 2>/dev/null || true + else /usr/libexec/msm-modem-uim-selection dsds-daemon 2>/dev/null || true + fi sleep 10 else sleep 120 diff --git a/overlay/rootfs/usr/lib/dwm/plugins/calllog.so b/overlay/rootfs/usr/lib/dwm/plugins/calllog.so index 0a12464..0632966 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/calllog.so and b/overlay/rootfs/usr/lib/dwm/plugins/calllog.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/callscreen.so b/overlay/rootfs/usr/lib/dwm/plugins/callscreen.so index f83ab11..9291153 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/callscreen.so and b/overlay/rootfs/usr/lib/dwm/plugins/callscreen.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/contacts.so b/overlay/rootfs/usr/lib/dwm/plugins/contacts.so index 5a82be6..0ddab2f 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/contacts.so and b/overlay/rootfs/usr/lib/dwm/plugins/contacts.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/dialer.so b/overlay/rootfs/usr/lib/dwm/plugins/dialer.so index d760fe6..bf4a3c6 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/dialer.so and b/overlay/rootfs/usr/lib/dwm/plugins/dialer.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/sms.so b/overlay/rootfs/usr/lib/dwm/plugins/sms.so index 02d4556..e390330 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/sms.so and b/overlay/rootfs/usr/lib/dwm/plugins/sms.so differ diff --git a/overlay/rootfs/usr/libexec/msm-modem-uim-selection b/overlay/rootfs/usr/libexec/msm-modem-uim-selection index c0d0a11..c489f65 100755 --- a/overlay/rootfs/usr/libexec/msm-modem-uim-selection +++ b/overlay/rootfs/usr/libexec/msm-modem-uim-selection @@ -74,12 +74,12 @@ detect_qmicli_modem() { return 0 fi fi - if timeout 3 qmicli --silent -pd qrtr://0 --uim-noop >/dev/null 2>&1; then - QMICLI_MODEM="timeout 4 qmicli --silent -pd qrtr://0" - return 0 - elif timeout 3 qmicli --silent -d qrtr://0 --uim-noop >/dev/null 2>&1; then + if timeout 3 qmicli --silent -d qrtr://0 --uim-noop >/dev/null 2>&1; then QMICLI_MODEM="timeout 4 qmicli --silent -d qrtr://0" return 0 + elif timeout 3 qmicli --silent -pd qrtr://0 --uim-noop >/dev/null 2>&1; then + QMICLI_MODEM="timeout 4 qmicli --silent -pd qrtr://0" + return 0 elif [ -e "/dev/modem" ]; then if timeout 3 qmicli --silent -pd /dev/modem --uim-noop >/dev/null 2>&1; then QMICLI_MODEM="timeout 4 qmicli --silent -pd /dev/modem" @@ -938,7 +938,7 @@ PY fi SIM_WAIT_TIME=2 provision_slot "$target" 4 - pkill -f "msm-modem-uim-selection dsds-daemon" 2>/dev/null || true + pkill -f "dsds-daemon" 2>/dev/null || true if [ "${3:-}" = "--swap-gw" ]; then spawn_enable_and_register "$target" 2 else @@ -1929,22 +1929,108 @@ PY exit $? ;; + slots) + python3 - "$PREFERRED_SIM_SLOT" << 'PY' +import select, socket, struct, sys + +pref_slot = int(sys.argv[1]) if len(sys.argv) > 1 and sys.argv[1].isdigit() else 1 +prim_slot = pref_slot +sec_slot = 0 +slot1_present = 0 +slot2_present = 0 + +AF_QIPCRTR = 42 +QRTR_PORT_CTRL = 0xfffffffe +QRTR_TYPE_NEW_SERVER = 4 +QRTR_TYPE_NEW_LOOKUP = 10 +QMI_SERVICE_UIM = 11 + +try: + ls = socket.socket(AF_QIPCRTR, socket.SOCK_DGRAM) + node, _ = ls.getsockname() + ls.sendto(struct.pack("= 20: + cmd, srv, inst, srv_node, srv_port = struct.unpack("= 9: + gw_pri, _, gw_sec, _ = struct.unpack("> 8) & 0xFF) + 1 + if gw_sec != 0xFFFF: + sec_slot = ((gw_sec >> 8) & 0xFF) + 1 + num_slots = val[8] + off = 9 + for s in range(min(num_slots, 2)): + if off + 6 > len(val): + break + cstate = val[off] + if s == 0 and cstate == 1: + slot1_present = 1 + elif s == 1 and cstate == 1: + slot2_present = 1 + num_apps = val[off + 5] + off += 6 + for _ in range(num_apps): + if off + 7 > len(val): + break + aid_len = val[off + 6] + if off + 14 + aid_len > len(val): + break + off += 14 + aid_len + us.close() +except Exception: + pass + +dual_active = 1 if (slot1_present and slot2_present and prim_slot in (1, 2) and sec_slot in (1, 2)) else 0 +out = ( + f"PREFERRED_SLOT={pref_slot}\n" + f"PRIMARY_GW_SLOT={prim_slot}\n" + f"SECONDARY_GW_SLOT={sec_slot}\n" + f"SLOT1_PRESENT={slot1_present}\n" + f"SLOT2_PRESENT={slot2_present}\n" + f"DUAL_SIM_ACTIVE={dual_active}\n" +) +sys.stdout.write(out) +try: + with open("/tmp/sxmo_sim_slots", "w") as f: + f.write(out) +except Exception: + pass +PY + exit 0 + ;; + call-dial|call-accept|call-hangup|call-dtmf|call-list) sub_cmd="$cmd" arg1="${2:-}" arg2="${3:-}" prim_slot="$PREFERRED_SIM_SLOT" sec_slot="0" - if detect_qmicli_modem; then - QMI_CARDS="$($QMICLI_MODEM --uim-get-card-status 2>/dev/null || true)" - if [ -n "$QMI_CARDS" ]; then - eval "$(parse_uim_card_status "$QMI_CARDS" "$PREFERRED_SIM_SLOT")" - prim_slot="${PRIMARY_GW_SLOT:-$PREFERRED_SIM_SLOT}" - sec_slot="${SECONDARY_GW_SLOT:-0}" - fi - fi python3 - "$sub_cmd" "$arg1" "$arg2" "$prim_slot" "$sec_slot" << 'PY' -import os, select, socket, struct, sys +import os, select, socket, struct, sys, time sub_cmd = sys.argv[1] arg1 = sys.argv[2] @@ -1957,27 +2043,57 @@ QRTR_PORT_CTRL = 0xfffffffe QRTR_TYPE_NEW_SERVER = 4 QRTR_TYPE_NEW_LOOKUP = 10 QMI_SERVICE_VOICE = 9 +QMI_SERVICE_UIM = 11 -ls = socket.socket(AF_QIPCRTR, socket.SOCK_DGRAM) -node, _ = ls.getsockname() -ls.sendto(struct.pack("= 20: - cmd, srv, inst, srv_node, srv_port = struct.unpack("= 20: + cmd, srv, inst, srv_node, srv_port = struct.unpack("= 8: + gw_pri, _, gw_sec, _ = struct.unpack("> 8) & 0xFF) + 1 + if gw_sec != 0xFFFF: + sec_slot = ((gw_sec >> 8) & 0xFF) + 1 + us.close() + except Exception: + pass + def parse_tlvs(resp): res = {} pos = 7 @@ -2040,7 +2156,15 @@ STATE_MAP = { 10: "setup", } +def is_hangup_requested(): + try: + return (time.time() - os.path.getmtime("/tmp/sxmo_hangup_requested")) < 3.5 + except Exception: + return False + if sub_cmd == "call-dial": + if is_hangup_requested(): + sys.exit(1) req_slot = int(arg1) if arg1.isdigit() else prim_slot sub = 1 if (req_slot == sec_slot and sec_slot != 0) else 0 num = "".join(c for c in arg2 if c in "+0123456789*#").encode("ascii") @@ -2057,12 +2181,21 @@ if sub_cmd == "call-dial": s = socket.socket(AF_QIPCRTR, socket.SOCK_DGRAM) qmi_req(s, 1, 0x0044, struct.pack("= 4 and struct.unpack("= 4 and struct.unpack("= 4 and struct.unpack(" 0 else 1 target_cid = 0 for cid, c in calls.items(): if sub_cmd == "call-accept" and c["state"] in (2, 7): @@ -2135,6 +2277,8 @@ elif sub_cmd in ("call-accept", "call-hangup", "call-dtmf"): elif sub_cmd != "call-accept" and c["state"] not in (8, 9): target_cid = cid break + if target_cid == 0 and sub_cmd == "call-hangup": + target_cid = fallback_cid if target_cid == 0: s.close() sys.exit(1) @@ -2175,8 +2319,18 @@ PY ;; dsds-daemon) - exec python3 - << 'PY' -import datetime, os, select, socket, struct, subprocess, sys, time + exec python3 - dsds-daemon << 'PY' +import datetime, fcntl, os, select, socket, struct, subprocess, sys, time + +lock_fd = open("/tmp/dsds_daemon.lock", "w") +try: + fcntl.flock(lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB) +except Exception: + sys.exit(0) +try: + os.chmod("/tmp/dsds_daemon.lock", 0o666) +except Exception: + pass try: while os.waitpid(-1, os.WNOHANG)[0] > 0: @@ -2776,9 +2930,44 @@ def has_mm_call_files(): pass return False -def sync_sub1_calls(calls, sim_slot): +def is_hangup_requested(): + try: + return (time.time() - os.path.getmtime("/tmp/sxmo_hangup_requested")) < 3.5 + except Exception: + return False + +def query_sec_slot(uim_addr, fallback=2): + if not uim_addr: + return fallback + try: + us = socket.socket(AF_QIPCRTR, socket.SOCK_DGRAM) + ut = qmi_req(us, uim_addr, 1, 0x002F, timeout=0.08) + us.close() + st_val = ut.get(0x10, b"") + if len(st_val) >= 8: + _, _, sec_gw_idx, _ = struct.unpack("> 8) & 0xFF) + 1 + except Exception: + pass + return fallback + +def sync_sub1_calls(calls, sim_slot, vs=None, voice_addr=None): global active_calls now_str = datetime.datetime.now().astimezone().isoformat(timespec="seconds") + hangup_req = is_hangup_requested() + sent_ended = False + + if hangup_req: + for cid, c in list(calls.items()): + if c["state"] not in (8, 9): + if vs is not None and voice_addr is not None: + try: + qmi_req(vs, voice_addr, 55000 + (cid % 100), 0x0021, struct.pack("= 8: - _, _, sec_gw_idx, _ = struct.unpack("> 8) & 0xFF) + 1 + sec_slot = query_sec_slot(uim_addr, 2) ws = socket.socket(AF_QIPCRTR, socket.SOCK_DGRAM) vs = socket.socket(AF_QIPCRTR, socket.SOCK_DGRAM) @@ -2955,6 +3138,7 @@ while True: continue tlvs = parse_tlvs(pkt) if sock is ws and mid == 0x0001: + sec_slot = query_sec_slot(uim_addr, sec_slot) # WMSEventReport indication if 0x11 in tlvs and len(tlvs[0x11]) >= 8: # Transfer-route MT message: [ack_ind(1), txn_id(4), format(1), len(2), data...] @@ -2980,6 +3164,7 @@ while True: elif sock is vs and mid == 0x002E: # VoiceAllCallStatusIndication got_voice_ind = True + sec_slot = query_sec_slot(uim_addr, sec_slot) calls = parse_call_info(tlvs) if not any(c["num"] for c in calls.values()): full_tlvs = qmi_req(vs, voice_addr, v_txn, 0x002F) @@ -2988,17 +3173,18 @@ while True: for cid, fc in full_calls.items(): if cid in calls and fc["num"]: calls[cid]["num"] = fc["num"] - sync_sub1_calls(calls, sec_slot) + sync_sub1_calls(calls, sec_slot, vs, voice_addr) if multipart_buf: w_txn = poll_stored_sms(ws, wms_addr, w_txn, sec_slot) w_txn = flush_stale_multipart(ws, wms_addr, w_txn, sec_slot) if not got_voice_ind and (active_calls or has_sub1_call_files()): + sec_slot = query_sec_slot(uim_addr, sec_slot) full_tlvs = qmi_req(vs, voice_addr, v_txn, 0x002F) v_txn = (v_txn % 60000) + 1 if full_tlvs: - sync_sub1_calls(parse_call_info(full_tlvs), sec_slot) + sync_sub1_calls(parse_call_info(full_tlvs), sec_slot, vs, voice_addr) if not os.path.exists("/tmp/bananarchy_screen_locked") and time.time() - last_poll >= 600.0: w_txn = poll_stored_sms(ws, wms_addr, w_txn, sec_slot) diff --git a/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_after_call.sh b/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_after_call.sh index 1871100..8213e5f 100755 --- a/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_after_call.sh +++ b/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_after_call.sh @@ -3,8 +3,4 @@ # This script is executed after the last call finished -if command -v xcallscreen >/dev/null 2>&1; then - xcallscreen ended >/dev/null 2>&1 || true -fi - sxmo_playerctl.sh resume_all diff --git a/prebuilt/sxmo-x11/usr/bin/dwm b/prebuilt/sxmo-x11/usr/bin/dwm index 375f8b5..5ff1631 100755 Binary files a/prebuilt/sxmo-x11/usr/bin/dwm and b/prebuilt/sxmo-x11/usr/bin/dwm differ diff --git a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/calllog.so b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/calllog.so index 0a12464..0632966 100755 Binary files a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/calllog.so and b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/calllog.so differ diff --git a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/callscreen.so b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/callscreen.so index f83ab11..9291153 100755 Binary files a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/callscreen.so and b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/callscreen.so differ diff --git a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/contacts.so b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/contacts.so index 5a82be6..0ddab2f 100755 Binary files a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/contacts.so and b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/contacts.so differ diff --git a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/dialer.so b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/dialer.so index d760fe6..bf4a3c6 100755 Binary files a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/dialer.so and b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/dialer.so differ diff --git a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/sms.so b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/sms.so index 02d4556..e390330 100755 Binary files a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/sms.so and b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/sms.so differ diff --git a/src/dwm-plugins/calllog_plugin.cpp b/src/dwm-plugins/calllog_plugin.cpp index 46f9283..4658d2b 100644 --- a/src/dwm-plugins/calllog_plugin.cpp +++ b/src/dwm-plugins/calllog_plugin.cpp @@ -547,12 +547,12 @@ int calllog_run_main(int argc, char** argv) { if (!selNum.empty()) { mode = ViewMode::Log; writeSoftkeySuppress(nowMs() + 350); + placePhoneCall(selNum); XUngrabKeyboard(dpy, CurrentTime); XUnmapWindow(dpy, win); XFlush(dpy); ::unlink(activePidPath.c_str()); visible = false; - placePhoneCall(selNum); } break; } @@ -1007,8 +1007,8 @@ int calllog_run_main(int argc, char** argv) { selected < static_cast(filtered.size())) { std::string num = filtered[selected].number; writeSoftkeySuppress(nowMs() + 350); - hideWindow(true); placePhoneCall(num); + hideWindow(false); } else if (filtered.empty()) { if (filterTab == 4) { blockList.load(); diff --git a/src/dwm-plugins/callscreen_plugin.cpp b/src/dwm-plugins/callscreen_plugin.cpp index 81f8b3f..49b8f7a 100644 --- a/src/dwm-plugins/callscreen_plugin.cpp +++ b/src/dwm-plugins/callscreen_plugin.cpp @@ -484,6 +484,7 @@ int callscreen_run_main(int argc, char** argv) { int64_t callStartMs = 0; int64_t endedAtMs = 0; + int64_t lastHangupMs = 0; int lastFinalDurationSec = 0; int64_t lastModemPollMs = 0; @@ -860,7 +861,9 @@ int callscreen_run_main(int argc, char** argv) { if (callState == CallState::Incoming) { writeIntFile("/tmp/sxmo_call_ringing", 1); writeIntFile("/tmp/sxmo_active_call", 1); - } else if (callState == CallState::Outgoing || callState == CallState::Active) { + } else if (callState == CallState::SelectSim || + callState == CallState::Outgoing || + callState == CallState::Active) { ::unlink("/tmp/sxmo_call_ringing"); writeIntFile("/tmp/sxmo_active_call", 2); } else { @@ -1422,6 +1425,7 @@ int callscreen_run_main(int argc, char** argv) { } endReason = reason.empty() ? "CALL ENDED" : reason; callState = CallState::Ended; + callId.clear(); endedAtMs = nowMs(); dtmfMode = false; ringMuted = false; @@ -1465,7 +1469,168 @@ int callscreen_run_main(int argc, char** argv) { "sxmo_modemaudio.sh disable_call_audio_mode >/dev/null 2>&1"); }; + auto hangupQmiVoiceCallsNow = [&]() { + constexpr int kAfQipcrtr = 42; + constexpr uint32_t kQrtrPortCtrl = 0xfffffffeu; + constexpr uint32_t kQrtrTypeNewServer = 4; + constexpr uint32_t kQrtrTypeNewLookup = 10; + constexpr uint32_t kQmiServiceVoice = 9; + + struct SockAddrQrtr { + unsigned short sq_family; + uint32_t sq_node; + uint32_t sq_port; + }; + struct QrtrCtrlPkt { + uint32_t cmd; + uint32_t service; + uint32_t instance; + uint32_t node; + uint32_t port; + } __attribute__((packed)); + + int lfd = ::socket(kAfQipcrtr, SOCK_DGRAM | SOCK_CLOEXEC, 0); + if (lfd < 0) { + return; + } + SockAddrQrtr localSq {}; + socklen_t sl = sizeof(localSq); + if (::getsockname(lfd, reinterpret_cast(&localSq), &sl) < 0) { + ::close(lfd); + return; + } + SockAddrQrtr ctrlSq { kAfQipcrtr, localSq.sq_node, kQrtrPortCtrl }; + QrtrCtrlPkt lookup { kQrtrTypeNewLookup, kQmiServiceVoice, 0, 0, 0 }; + if (::sendto(lfd, &lookup, sizeof(lookup), 0, + reinterpret_cast(&ctrlSq), + sizeof(ctrlSq)) < 0) { + ::close(lfd); + return; + } + uint32_t vNode = 0, vPort = 0; + bool foundSrv = false; + for (int i = 0; i < 8; ++i) { + struct pollfd pfd { lfd, POLLIN, 0 }; + if (::poll(&pfd, 1, 30) <= 0) break; + QrtrCtrlPkt pkt {}; + ssize_t n = ::recv(lfd, &pkt, sizeof(pkt), 0); + if (n >= static_cast(sizeof(pkt)) && pkt.cmd == kQrtrTypeNewServer) { + if (pkt.service == kQmiServiceVoice && pkt.port != 0) { + vNode = pkt.node; + vPort = pkt.port; + foundSrv = true; + break; + } + if (pkt.service == 0 && pkt.node == 0 && pkt.port == 0) break; + } + } + ::close(lfd); + if (!foundSrv) { + return; + } + + SockAddrQrtr vSq { kAfQipcrtr, vNode, vPort }; + for (int sub : {1, 0}) { + int sfd = ::socket(kAfQipcrtr, SOCK_DGRAM | SOCK_CLOEXEC, 0); + if (sfd < 0) continue; + uint8_t bindReq[11] = { + 0x00, 0x01, 0x00, 0x44, 0x00, 0x04, 0x00, + 0x01, 0x01, 0x00, static_cast(sub) + }; + ::sendto(sfd, bindReq, sizeof(bindReq), 0, + reinterpret_cast(&vSq), sizeof(vSq)); + struct pollfd pfd { sfd, POLLIN, 0 }; + int64_t bindDeadline = nowMs() + 60; + while (nowMs() < bindDeadline) { + int waitMs = static_cast(std::max(2, bindDeadline - nowMs())); + if (::poll(&pfd, 1, waitMs) <= 0) break; + uint8_t tmp[512]; + ssize_t rlen = ::recv(sfd, tmp, sizeof(tmp), 0); + if (rlen >= 7 && tmp[0] == 0x02 && tmp[1] == 0x01 && tmp[2] == 0x00 && + tmp[3] == 0x44 && tmp[4] == 0x00) { + break; + } + } + + uint8_t infoReq[7] = { 0x00, 0x02, 0x00, 0x2F, 0x00, 0x00, 0x00 }; + ::sendto(sfd, infoReq, sizeof(infoReq), 0, + reinterpret_cast(&vSq), sizeof(vSq)); + std::vector cidsToHangup; + int64_t infoDeadline = nowMs() + 80; + while (nowMs() < infoDeadline) { + int waitMs = static_cast(std::max(2, infoDeadline - nowMs())); + if (::poll(&pfd, 1, waitMs) <= 0) break; + uint8_t buf[1024]; + ssize_t rlen = ::recv(sfd, buf, sizeof(buf), 0); + if (rlen >= 7 && buf[0] == 0x02 && buf[1] == 0x02 && buf[2] == 0x00 && + buf[3] == 0x2F && buf[4] == 0x00) { + const uint8_t* rawCi01 = nullptr; + uint16_t lenCi01 = 0; + const uint8_t* rawCi10 = nullptr; + uint16_t lenCi10 = 0; + size_t pos = 7; + while (pos + 3 <= static_cast(rlen)) { + uint8_t tt = buf[pos]; + uint16_t tl = static_cast(buf[pos + 1]) | + (static_cast(buf[pos + 2]) << 8); + pos += 3; + if (pos + tl > static_cast(rlen)) break; + if (tt == 0x01) { + rawCi01 = buf + pos; + lenCi01 = tl; + } else if (tt == 0x10) { + rawCi10 = buf + pos; + lenCi10 = tl; + } + pos += tl; + } + const uint8_t* rawCi = rawCi01 ? rawCi01 : rawCi10; + uint16_t lenCi = rawCi01 ? lenCi01 : lenCi10; + if (rawCi && lenCi >= 1) { + uint8_t cnt = rawCi[0]; + size_t off = 1; + for (uint8_t i = 0; i < cnt && off + 7 <= lenCi; ++i, off += 7) { + uint8_t cid = rawCi[off]; + uint8_t cstate = rawCi[off + 1]; + if (cstate != 8 && cstate != 9 && cid > 0) { + cidsToHangup.push_back(cid); + } + } + } + break; + } + } + if (cidsToHangup.empty()) { + cidsToHangup.push_back(1); + } + uint8_t txn = 3; + for (uint8_t cid : cidsToHangup) { + uint8_t endReq[11] = { + 0x00, txn, 0x00, 0x21, 0x00, 0x04, 0x00, + 0x01, 0x01, 0x00, cid + }; + ::sendto(sfd, endReq, sizeof(endReq), 0, + reinterpret_cast(&vSq), sizeof(vSq)); + int64_t endDeadline = nowMs() + 50; + while (nowMs() < endDeadline) { + int waitMs = static_cast(std::max(2, endDeadline - nowMs())); + if (::poll(&pfd, 1, waitMs) <= 0) break; + uint8_t tmp[512]; + ssize_t rlen = ::recv(sfd, tmp, sizeof(tmp), 0); + if (rlen >= 7 && tmp[0] == 0x02 && tmp[1] == txn && tmp[2] == 0x00 && + tmp[3] == 0x21 && tmp[4] == 0x00) { + break; + } + } + ++txn; + } + ::close(sfd); + } + }; + auto hangupCall = [&](bool closeImmediately = false) { + lastHangupMs = nowMs(); + writeIntFile("/tmp/sxmo_hangup_requested", 1); std::string cid = resolveActiveModemCallId(); bool wasIncoming = (callState == CallState::Incoming); stopRingingJobs(); @@ -1473,12 +1638,34 @@ int callscreen_run_main(int argc, char** argv) { sendPluginCommand("sip", "CALL_HANGUP " + cid); } else if (cid.rfind("tox:", 0) == 0 || activeSimSlot == 4) { sendPluginCommand("tox", "CALL_HANGUP " + cid); - } else if (!cid.empty() && cid != "-" && cid != "sim" && cid != "test") { - runAsyncArgv("sxmo_modemcall.sh", "hangup", cid.c_str()); } else { - runAsyncArgv("sxmo_modemcall.sh", "hangup", "all"); - sendPluginCommand("sip", "CALL_HANGUP"); - sendPluginCommand("tox", "CALL_HANGUP"); + hangupQmiVoiceCallsNow(); + std::string callsDir = getRuntimeFile("sxmo_calls"); + DIR* d = ::opendir(callsDir.c_str()); + if (d) { + struct dirent* ent; + while ((ent = ::readdir(d)) != nullptr) { + if (ent->d_name[0] != '.' && ent->d_name[0] != '\0') { + std::string fn(ent->d_name); + if (fn.rfind("sub", 0) == 0 || + fn.find(".ringing-in") != std::string::npos || + fn.find(".dialing") != std::string::npos || + fn.find(".ringing-out") != std::string::npos || + fn.find(".active") != std::string::npos) { + std::string fpPath = callsDir + "/" + fn; + ::unlink(fpPath.c_str()); + } + } + } + ::closedir(d); + } + if (!cid.empty() && cid != "-" && cid != "sim" && cid != "test") { + runAsyncArgv("sxmo_modemcall.sh", "hangup", cid.c_str()); + } else { + runAsyncArgv("sxmo_modemcall.sh", "hangup", "all"); + sendPluginCommand("sip", "CALL_HANGUP"); + sendPluginCommand("tox", "CALL_HANGUP"); + } } if (closeImmediately || !visible || callState == CallState::Idle || callState == CallState::SelectSim || callState == CallState::Ended) { @@ -1660,7 +1847,7 @@ int callscreen_run_main(int argc, char** argv) { else if (cstate == 6) st = "held"; if (!st.empty() && outId.empty()) { outId = (sub == 1) ? ("sub1_" + std::to_string(cid)) - : std::to_string(cid); + : ("sub0_" + std::to_string(cid)); outState = st; outDir = (cdir == 2) ? "incoming" : "outgoing"; if (rawNum && lenNum >= 1) { @@ -1693,13 +1880,17 @@ int callscreen_run_main(int argc, char** argv) { if (callId == "sim" || callId == "test" || isVoipCallId(callId)) { return; } + if (lastHangupMs > 0 && nowMs() - lastHangupMs < 4000 && + ::access("/tmp/sxmo_hangup_requested", F_OK) == 0) { + return; + } std::string foundId; std::string foundDir; std::string foundState; std::string foundNum; bool sawTerminated = false; - if (callId.rfind("sub", 0) != 0) { + if (callId.rfind("sub1_", 0) != 0) { FILE* fp = ::popen("mmcli -m any --voice-list-calls -a 2>/dev/null", "r"); if (fp) { char line[512]; @@ -1891,9 +2082,9 @@ int callscreen_run_main(int argc, char** argv) { if (line == "ENDED" || line.rfind("ENDED ", 0) == 0) { std::string reason = (line.size() > 6) ? trimStr(line.substr(6)) : "CALL ENDED"; sipZrtpSas.clear(); - if (callState != CallState::Idle) { + if (callState != CallState::Idle && callState != CallState::Ended) { transitionToEnded(reason); - } else { + } else if (callState == CallState::Idle) { hideWindow(false); } return; @@ -1904,13 +2095,46 @@ int callscreen_run_main(int argc, char** argv) { std::string verb, arg1, arg2, arg3; iss >> verb >> arg1 >> arg2 >> arg3; - if (verb == "PROMPT_SIM") { + if (verb == "DIAL" || verb == "PROMPT_SIM") { if (callState == CallState::Incoming || callState == CallState::Outgoing || callState == CallState::Active) { showWindow(); return; } - simInfo = queryDualSimInfo(true); + lastHangupMs = 0; + ::unlink("/tmp/sxmo_hangup_requested"); + if (!simInfo.slot1Present && !simInfo.slot2Present) { + simInfo = queryDualSimInfo(false); + } + if (verb == "DIAL" && !simInfo.dualSimActive) { + int slot = (simInfo.primaryGwSlot == 2) ? 2 : 1; + std::string simStr = std::to_string(slot); + std::string num = normalizePhone(arg1); + if (!num.empty()) { + callId.clear(); + callNumber.clear(); + contactName.clear(); + updateCallerDetails("-", num); + activeSimSlot = slot; + callState = CallState::Outgoing; + callStartMs = nowMs(); + lastModemPollMs = callStartMs; + missingModemPolls = 0; + ringMuted = false; + speakerOn = false; + btAudioOn = hasBtAudioCard(); + dtmfMode = false; + dtmfSent.clear(); + selectedRow = 0; + setSpeakerRoute(false, btAudioOn); + statusNotice.clear(); + statusNoticeUntilMs = 0; + writeActiveStateFiles(); + showWindow(); + runAsyncArgv("sxmo_modemdial.sh", "--sim", simStr.c_str(), num.c_str()); + } + return; + } callId = "-"; callNumber.clear(); contactName.clear(); @@ -1920,6 +2144,11 @@ int callscreen_run_main(int argc, char** argv) { activeSimSlot = 0; writeActiveStateFiles(); showWindow(); + if (simInfo.slot1Operator.empty() && simInfo.slot2Operator.empty()) { + simInfo = queryDualSimInfo(true); + selectedRow = (simInfo.preferredSlot == 2) ? 1 : 0; + render(); + } return; } @@ -1968,6 +2197,8 @@ int callscreen_run_main(int argc, char** argv) { }; if (verb == "INCOMING") { + lastHangupMs = 0; + ::unlink("/tmp/sxmo_hangup_requested"); callId.clear(); callNumber.clear(); contactName.clear(); @@ -1989,31 +2220,46 @@ int callscreen_run_main(int argc, char** argv) { writeActiveStateFiles(); showWindow(); } else if (verb == "OUTGOING") { - callId.clear(); - callNumber.clear(); - contactName.clear(); - recordFileName.clear(); - recordFilePath.clear(); - lastRecordedSec = 0; - recordedClipCount = 0; + if (lastHangupMs > 0 && nowMs() - lastHangupMs < 4000 && + ::access("/tmp/sxmo_hangup_requested", F_OK) == 0) { + return; + } + lastHangupMs = 0; + bool alreadyOutgoing = (callState == CallState::Outgoing); + if (!alreadyOutgoing) { + callId.clear(); + callNumber.clear(); + contactName.clear(); + recordFileName.clear(); + recordFilePath.clear(); + lastRecordedSec = 0; + recordedClipCount = 0; + } updateCallerDetails(arg1, arg2); parseSimTag(arg1, arg3); callState = CallState::Outgoing; - callStartMs = nowMs(); - lastModemPollMs = callStartMs; + if (!alreadyOutgoing) { + callStartMs = nowMs(); + ringMuted = false; + speakerOn = false; + btAudioOn = hasBtAudioCard(); + dtmfMode = false; + dtmfSent.clear(); + selectedRow = 0; + setSpeakerRoute(false, btAudioOn); + statusNotice.clear(); + statusNoticeUntilMs = 0; + } + lastModemPollMs = nowMs(); missingModemPolls = 0; - ringMuted = false; - speakerOn = false; - btAudioOn = hasBtAudioCard(); - dtmfMode = false; - dtmfSent.clear(); - selectedRow = 0; - setSpeakerRoute(false, btAudioOn); - statusNotice.clear(); - statusNoticeUntilMs = 0; writeActiveStateFiles(); showWindow(); } else if (verb == "ACTIVE") { + if (lastHangupMs > 0 && nowMs() - lastHangupMs < 4000 && + ::access("/tmp/sxmo_hangup_requested", F_OK) == 0) { + return; + } + lastHangupMs = 0; bool wasActive = (callState == CallState::Active); bool wasOutgoing = (callState == CallState::Outgoing); updateCallerDetails(arg1, arg2); @@ -2044,7 +2290,9 @@ int callscreen_run_main(int argc, char** argv) { if (callState == CallState::Idle || callState == CallState::Ended) { syncModemCalls(); } - showWindow(); + if (callState != CallState::Idle || !arg1.empty()) { + showWindow(); + } } }; @@ -2057,6 +2305,8 @@ int callscreen_run_main(int argc, char** argv) { if (num.empty()) { return; } + lastHangupMs = 0; + ::unlink("/tmp/sxmo_hangup_requested"); std::string simStr = (chosenSim == 2) ? "2" : "1"; handleFifoCommand("OUTGOING - " + num + " SIM" + simStr); runAsyncArgv("sxmo_modemdial.sh", "--sim", simStr.c_str(), num.c_str()); @@ -2120,10 +2370,6 @@ int callscreen_run_main(int argc, char** argv) { writeActiveStateFiles(); } hideWindow(false); - } else { - XRaiseWindow(dpy, win); - grabPluginKeyboard(dpy, win); - render(); } } else if (ev.type == KeyRelease) { KeySym sym = XLookupKeysym(&ev.xkey, 0); @@ -2374,16 +2620,22 @@ int callscreen_run_main(int argc, char** argv) { } } - if (visible && (callState != CallState::Idle || checkRecordingAlive())) { + static int64_t lastTimerRenderMs = 0; + bool hasLiveTimer = (callState == CallState::Outgoing || + callState == CallState::Active || + checkRecordingAlive()); + if (visible && hasLiveTimer && nowMs() - lastTimerRenderMs >= 250) { + lastTimerRenderMs = nowMs(); render(); } int timeoutMs = -1; - if (visible || callState != CallState::Idle || checkRecordingAlive()) { + if (softkeyDeadlineMs > 0) { + timeoutMs = static_cast(std::max(5, softkeyDeadlineMs - nowMs())); + } else if (callState == CallState::Ended && endedAtMs > 0) { + timeoutMs = static_cast(std::max(10, 1300 - (nowMs() - endedAtMs))); + } else if (hasLiveTimer || callState == CallState::Incoming) { timeoutMs = 250; - if (softkeyDeadlineMs > 0) { - timeoutMs = static_cast(std::max(5, softkeyDeadlineMs - nowMs())); - } } struct pollfd pfds[2] {}; diff --git a/src/dwm-plugins/contacts_plugin.cpp b/src/dwm-plugins/contacts_plugin.cpp index 1f8510f..382c894 100644 --- a/src/dwm-plugins/contacts_plugin.cpp +++ b/src/dwm-plugins/contacts_plugin.cpp @@ -1046,8 +1046,8 @@ int runContactsApp(int argc, char** argv) { switch (actIdx) { case 0: // Call Contact writeSoftkeySuppress(nowMs() + 350); - hideWindow(true); placePhoneCall(c.number); + hideWindow(false); break; case 1: // Send SMS writeSoftkeySuppress(nowMs() + 350); @@ -1304,8 +1304,8 @@ int runContactsApp(int argc, char** argv) { if (selected >= 0 && selected < static_cast(filtered.size())) { std::string target = filtered[selected].number; writeSoftkeySuppress(nowMs() + 350); - hideWindow(true); placePhoneCall(target); + hideWindow(false); } break; case XK_Return: @@ -1323,8 +1323,8 @@ int runContactsApp(int argc, char** argv) { selected < static_cast(filtered.size())) { std::string target = filtered[selected].number; writeSoftkeySuppress(nowMs() + 350); - hideWindow(true); placePhoneCall(target); + hideWindow(false); } break; } @@ -1769,6 +1769,9 @@ int contacts_on_idle_key(const DwmHostApi* host, KeySym keysym, if (!host || !host->is_idle_desktop || !host->is_idle_desktop() || state != 0) { return 0; } + if (isCallActiveOrRingingFast() || isAnotherPluginActive("contacts")) { + return 0; + } if (keysym == XF86XK_Back || keysym == XF86XK_KbdLcdMenu2 || keycode == 166) { if (host->spawn_plugin) { host->spawn_plugin("contacts", nullptr); diff --git a/src/dwm-plugins/dialer_plugin.cpp b/src/dwm-plugins/dialer_plugin.cpp index cb2a5b9..d2f606d 100644 --- a/src/dwm-plugins/dialer_plugin.cpp +++ b/src/dwm-plugins/dialer_plugin.cpp @@ -571,6 +571,10 @@ int dialer_run_main(int argc, char** argv) { }; auto showWindow = [&](const std::string& arg) { + if (!visible && (isCallActiveOrRingingFast() || + isPidFileAlive(getRuntimeFile("xcallscreen.pid")))) { + return; + } writeIntFile(activePidPath, static_cast(::getpid())); closeOtherPlugins("dialer"); modal = DialerModal::Inactive; @@ -939,8 +943,8 @@ int dialer_run_main(int argc, char** argv) { case XF86XK_Send: { if (isCallActiveOrRingingFast()) { writeSoftkeySuppress(nowMs() + 350); - hideWindow(false); placePhoneCall(""); + hideWindow(false); break; } std::string target = selectActiveNumber(); @@ -960,8 +964,8 @@ int dialer_run_main(int argc, char** argv) { executeUssd(target, false); } else { writeSoftkeySuppress(nowMs() + 350); - hideWindow(false); placePhoneCall(target); + hideWindow(false); } } break; @@ -1085,6 +1089,9 @@ int dialer_on_idle_key(const DwmHostApi* host, KeySym keysym, if (!host || !host->is_idle_desktop || !host->is_idle_desktop()) { return 0; } + if (isCallActiveOrRingingFast() || isAnotherPluginActive("dialer")) { + return 0; + } char ch = mapDialKey(keysym, keycode, state); if (ch == '\0') { return 0; diff --git a/src/dwm-plugins/phone_data.h b/src/dwm-plugins/phone_data.h index e21b5dd..69633ba 100644 --- a/src/dwm-plugins/phone_data.h +++ b/src/dwm-plugins/phone_data.h @@ -1568,7 +1568,8 @@ inline DualSimInfo queryDualSimInfo(bool forceRefresh = false) { static DualSimInfo cached; static int64_t lastQueryMs = 0; int64_t now = nowMs(); - if (!forceRefresh && lastQueryMs > 0 && (now - lastQueryMs) < 3000) { + int64_t ttlMs = (cached.slot1Present || cached.slot2Present) ? 60000 : 3000; + if (!forceRefresh && lastQueryMs > 0 && (now - lastQueryMs) < ttlMs) { return cached; } @@ -1890,7 +1891,12 @@ inline void placePhoneCall(const std::string& rawNumber, int simSlot = 0) { if (num.empty()) { return; } + ::unlink("/tmp/sxmo_hangup_requested"); + writeIntFile("/tmp/sxmo_active_call", 2); if (simSlot == 0) { + if (sendPluginCommand("callscreen", "DIAL " + num)) { + return; + } DualSimInfo dsi = queryDualSimInfo(); if (dsi.dualSimActive) { if (!sendPluginCommand("callscreen", "PROMPT_SIM " + num)) { diff --git a/src/dwm-plugins/sms_plugin.cpp b/src/dwm-plugins/sms_plugin.cpp index c825511..e3f0ff7 100644 --- a/src/dwm-plugins/sms_plugin.cpp +++ b/src/dwm-plugins/sms_plugin.cpp @@ -1137,8 +1137,8 @@ int runSmsApp(int argc, char** argv) { ? filteredThreads[selectedThread].number : ""); if (!target.empty()) { - hideWindow(); placePhoneCall(target); + hideWindow(); } } else if (optId == 5) { std::string target = (prevMode == ViewMode::ThreadView) @@ -1451,12 +1451,12 @@ int runSmsApp(int argc, char** argv) { startAsyncSendSms(composeRecipient, composeText); drawUI(); } else if (mode == ViewMode::ThreadView && !activeNumber.empty()) { - hideWindow(); placePhoneCall(activeNumber); + hideWindow(); } else if (mode == ViewMode::Threads && !filteredThreads.empty()) { std::string num = filteredThreads[selectedThread].number; - hideWindow(); placePhoneCall(num); + hideWindow(); } continue; } diff --git a/src/sxmo-dwm/dwm.c b/src/sxmo-dwm/dwm.c index 8817024..489b03b 100644 --- a/src/sxmo-dwm/dwm.c +++ b/src/sxmo-dwm/dwm.c @@ -1080,6 +1080,144 @@ dirtomon(int dir) return m; } +static void +drawsoftbar(Monitor *m, int force) +{ + static int last_has_sel = -1; + int has_sel; + + if (!m || !m->softwin || !drw || !drw->font || is_screen_off()) + return; + has_sel = (m->sel != NULL); + if (!force && has_sel == last_has_sel) + return; + last_has_sel = has_sel; + + XLowerWindow(dpy, m->softwin); + XClearWindow(dpy, m->softwin); + if (!has_sel) { + XftDraw *d = XftDrawCreate(dpy, m->softwin, + DefaultVisual(dpy, screen), DefaultColormap(dpy, screen)); + if (d) { + unsigned int ew = 0, eh = 0; + const char *left_txt = "Menu"; + const char *right_txt = "Names"; + int sh_bar = 26; + + drw_font_getexts(drw->font, left_txt, strlen(left_txt), &ew, &eh, False); + int ty = (sh_bar - (int)eh) / 2; + pango_layout_set_text(drw->font->layout, left_txt, strlen(left_txt)); + pango_xft_render_layout(d, &scheme[SchemeSel][ColFg], + drw->font->layout, 6 * PANGO_SCALE, ty * PANGO_SCALE); + + drw_font_getexts(drw->font, right_txt, strlen(right_txt), &ew, &eh, False); + ty = (sh_bar - (int)eh) / 2; + int rx = m->ww - (int)ew - 6; + pango_layout_set_text(drw->font->layout, right_txt, strlen(right_txt)); + pango_xft_render_layout(d, &scheme[SchemeSel][ColFg], + drw->font->layout, rx * PANGO_SCALE, ty * PANGO_SCALE); + + XftDrawDestroy(d); + } + } +} + +static void +drawclock(Monitor *m, int force) +{ + static XftFont *clk_font_big = NULL; + static XftFont *clk_font_small = NULL; + static XftColor clk_fg, clk_sh; + static int clk_colors_init = 0; + static char last_tzlink[256] = ""; + static int last_has_sel = -1; + static char last_tbuf[32] = ""; + static char last_dbuf[64] = ""; + char tzlink[256], tbuf[32], dbuf[64]; + ssize_t tzlen; + time_t now; + struct tm lt; + int has_sel; + + if (!m || !m->clockwin || is_screen_off()) + return; + has_sel = (m->sel != NULL); + if (has_sel) { + if (!force && last_has_sel == 1) + return; + last_has_sel = 1; + XLowerWindow(dpy, m->clockwin); + XClearWindow(dpy, m->clockwin); + return; + } + + tzlen = readlink("/etc/localtime", tzlink, sizeof(tzlink) - 1); + if (tzlen > 0) { + tzlink[tzlen] = '\0'; + if (strcmp(tzlink, last_tzlink) != 0) { + snprintf(last_tzlink, sizeof(last_tzlink), "%s", tzlink); + setenv("TZ", tzlink, 1); + tzset(); + force = 1; + } + } + now = time(NULL); + localtime_r(&now, <); + strftime(tbuf, sizeof(tbuf), "%H:%M", <); + strftime(dbuf, sizeof(dbuf), "%a %d %b %Y", <); + + if (!force && last_has_sel == 0 && + strcmp(tbuf, last_tbuf) == 0 && strcmp(dbuf, last_dbuf) == 0) + return; + + last_has_sel = 0; + snprintf(last_tbuf, sizeof(last_tbuf), "%s", tbuf); + snprintf(last_dbuf, sizeof(last_dbuf), "%s", dbuf); + + if (!clk_font_big) + clk_font_big = XftFontOpenName(dpy, screen, "Fira Code:size=32:style=Regular"); + if (!clk_font_small) + clk_font_small = XftFontOpenName(dpy, screen, "Fira Code:size=14:style=Regular"); + if (!clk_colors_init) { + XRenderColor rfg = { 0xffff, 0xffff, 0xffff, 0xffff }; + XRenderColor rsh = { 0x0000, 0x0000, 0x0000, 0xffff }; + XftColorAllocValue(dpy, DefaultVisual(dpy, screen), + DefaultColormap(dpy, screen), &rfg, &clk_fg); + XftColorAllocValue(dpy, DefaultVisual(dpy, screen), + DefaultColormap(dpy, screen), &rsh, &clk_sh); + clk_colors_init = 1; + } + + XLowerWindow(dpy, m->clockwin); + XClearWindow(dpy, m->clockwin); + XftDraw *cd = XftDrawCreate(dpy, m->clockwin, + DefaultVisual(dpy, screen), DefaultColormap(dpy, screen)); + if (cd) { + XGlyphInfo ext; + if (clk_font_big) { + size_t tlen = strlen(tbuf); + XftTextExtentsUtf8(dpy, clk_font_big, (const FcChar8 *)tbuf, tlen, &ext); + int tx = (m->ww - ext.xOff) / 2; + int ty = 45; + XftDrawStringUtf8(cd, &clk_sh, clk_font_big, tx + 1, ty + 1, + (const FcChar8 *)tbuf, tlen); + XftDrawStringUtf8(cd, &clk_fg, clk_font_big, tx, ty, + (const FcChar8 *)tbuf, tlen); + } + if (clk_font_small) { + size_t dlen = strlen(dbuf); + XftTextExtentsUtf8(dpy, clk_font_small, (const FcChar8 *)dbuf, dlen, &ext); + int dx = (m->ww - ext.xOff) / 2; + int dy = 73; + XftDrawStringUtf8(cd, &clk_sh, clk_font_small, dx + 1, dy + 1, + (const FcChar8 *)dbuf, dlen); + XftDrawStringUtf8(cd, &clk_fg, clk_font_small, dx, dy, + (const FcChar8 *)dbuf, dlen); + } + XftDrawDestroy(cd); + } +} + void drawbar(Monitor *m) { @@ -1135,105 +1273,8 @@ drawbar(Monitor *m) drw_text(drw, MAX(x, m->ww - sw), 0, sw, bh, 0, s, 0, True); } drw_map(drw, m->barwin, 0, 0, m->ww, bh); - if (m->softwin && drw && drw->font) { - XLowerWindow(dpy, m->softwin); - XClearWindow(dpy, m->softwin); - if (!m->sel) { - XftDraw *d = XftDrawCreate(dpy, m->softwin, - DefaultVisual(dpy, screen), DefaultColormap(dpy, screen)); - if (d) { - unsigned int ew = 0, eh = 0; - const char *left_txt = "Menu"; - const char *right_txt = "Names"; - int sh_bar = 26; - - drw_font_getexts(drw->font, left_txt, strlen(left_txt), &ew, &eh, False); - int ty = (sh_bar - (int)eh) / 2; - pango_layout_set_text(drw->font->layout, left_txt, strlen(left_txt)); - pango_xft_render_layout(d, &scheme[SchemeSel][ColFg], - drw->font->layout, 6 * PANGO_SCALE, ty * PANGO_SCALE); - - drw_font_getexts(drw->font, right_txt, strlen(right_txt), &ew, &eh, False); - ty = (sh_bar - (int)eh) / 2; - int rx = m->ww - (int)ew - 6; - pango_layout_set_text(drw->font->layout, right_txt, strlen(right_txt)); - pango_xft_render_layout(d, &scheme[SchemeSel][ColFg], - drw->font->layout, rx * PANGO_SCALE, ty * PANGO_SCALE); - - XftDrawDestroy(d); - } - } - } - if (m->clockwin) { - XLowerWindow(dpy, m->clockwin); - XClearWindow(dpy, m->clockwin); - if (!m->sel) { - static XftFont *clk_font_big = NULL; - static XftFont *clk_font_small = NULL; - static XftColor clk_fg, clk_sh; - static int clk_colors_init = 0; - static char last_tzlink[256] = ""; - char tzlink[256]; - ssize_t tzlen; - - if (!clk_font_big) - clk_font_big = XftFontOpenName(dpy, screen, "Fira Code:size=32:style=Regular"); - if (!clk_font_small) - clk_font_small = XftFontOpenName(dpy, screen, "Fira Code:size=14:style=Regular"); - if (!clk_colors_init) { - XRenderColor rfg = { 0xffff, 0xffff, 0xffff, 0xffff }; - XRenderColor rsh = { 0x0000, 0x0000, 0x0000, 0xffff }; - XftColorAllocValue(dpy, DefaultVisual(dpy, screen), - DefaultColormap(dpy, screen), &rfg, &clk_fg); - XftColorAllocValue(dpy, DefaultVisual(dpy, screen), - DefaultColormap(dpy, screen), &rsh, &clk_sh); - clk_colors_init = 1; - } - tzlen = readlink("/etc/localtime", tzlink, sizeof(tzlink) - 1); - if (tzlen > 0) { - tzlink[tzlen] = '\0'; - if (strcmp(tzlink, last_tzlink) != 0) { - snprintf(last_tzlink, sizeof(last_tzlink), "%s", tzlink); - setenv("TZ", tzlink, 1); - tzset(); - } - } - XftDraw *cd = XftDrawCreate(dpy, m->clockwin, - DefaultVisual(dpy, screen), DefaultColormap(dpy, screen)); - if (cd) { - time_t now = time(NULL); - struct tm lt; - char tbuf[32], dbuf[64]; - XGlyphInfo ext; - - localtime_r(&now, <); - strftime(tbuf, sizeof(tbuf), "%H:%M", <); - strftime(dbuf, sizeof(dbuf), "%a %d %b %Y", <); - - if (clk_font_big) { - size_t tlen = strlen(tbuf); - XftTextExtentsUtf8(dpy, clk_font_big, (const FcChar8 *)tbuf, tlen, &ext); - int tx = (m->ww - ext.xOff) / 2; - int ty = 45; - XftDrawStringUtf8(cd, &clk_sh, clk_font_big, tx + 1, ty + 1, - (const FcChar8 *)tbuf, tlen); - XftDrawStringUtf8(cd, &clk_fg, clk_font_big, tx, ty, - (const FcChar8 *)tbuf, tlen); - } - if (clk_font_small) { - size_t dlen = strlen(dbuf); - XftTextExtentsUtf8(dpy, clk_font_small, (const FcChar8 *)dbuf, dlen, &ext); - int dx = (m->ww - ext.xOff) / 2; - int dy = 73; - XftDrawStringUtf8(cd, &clk_sh, clk_font_small, dx + 1, dy + 1, - (const FcChar8 *)dbuf, dlen); - XftDrawStringUtf8(cd, &clk_fg, clk_font_small, dx, dy, - (const FcChar8 *)dbuf, dlen); - } - XftDrawDestroy(cd); - } - } - } + drawsoftbar(m, 0); + drawclock(m, 0); } void @@ -1270,8 +1311,14 @@ expose(XEvent *e) Monitor *m; XExposeEvent *ev = &e->xexpose; - if (ev->count == 0 && (m = wintomon(ev->window))) - drawbar(m); + if (ev->count == 0 && (m = wintomon(ev->window))) { + if (ev->window == m->softwin) + drawsoftbar(m, 1); + else if (ev->window == m->clockwin) + drawclock(m, 1); + else + drawbar(m); + } } static void @@ -4336,6 +4383,8 @@ reload_dwm_theme(void) else XSetWindowBorder(dpy, c->win, scheme[SchemeNorm][ColBorder].pixel); } + drawsoftbar(m, 1); + drawclock(m, 1); } drawbars(); }