Skip to content

fix: throw out all the defensive sleep logic#736

Open
frysee wants to merge 19 commits into
mainfrom
lean-suspend
Open

fix: throw out all the defensive sleep logic#736
frysee wants to merge 19 commits into
mainfrom
lean-suspend

Conversation

@frysee
Copy link
Copy Markdown
Member

@frysee frysee commented May 21, 2026

Maybe the BT reconnect fix is removing the hacks you added along the way?

@carroarmato0
Copy link
Copy Markdown

I noticed an issue when the bluetooth device was connected initially, and then disconnected during the sleep. When the device is woken up again, it thinks the BLE device is still connected.

Comment thread skeleton/SYSTEM/tg5050/bin/suspend Outdated
Comment thread skeleton/SYSTEM/tg5040/bin/suspend
Comment thread skeleton/SYSTEM/tg5040/bin/suspend Outdated
Comment thread skeleton/SYSTEM/tg5050/bin/suspend
Comment thread workspace/all/minarch/ma_audio.c Outdated

resetAudio = true;
SetAudioSink(device);
sleep(1); // give it a moment to apply before we reset the audio system, otherwise
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sentence stopped all of a sudden :D But I think I understand you want to wait for bluealsa readiness.
sleep(1) is a full 1second blocking. Wouldn't it be better to poll GetAudioDeviceName() in a short loop until a non-audiocodec device appears (or a timeout is hit)? That way it's fast on quick connections and still safe on slow ones, without always burning a full second.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this was more of a grasping-at-straws bandaid fix that worked after trying different things. One second is harsh, but it is on a background thread.

Comment thread workspace/all/audiomon/audiomon.cpp Outdated
Comment thread skeleton/SYSTEM/tg5050/bin/suspend Outdated

asound_state_dir=/tmp/asound-suspend

log_wakeup_sources() {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be removed before we merge.

Comment thread skeleton/SYSTEM/tg5040/bin/suspend Outdated
frysee and others added 19 commits May 27, 2026 00:56
…dsets

The XRadio BT controller firmware generates link keys with store_hint=0,
meaning BlueZ never persists the key to disk. This caused two symptoms:

1. Earbuds disconnect ~2s after pairing: after the BR/EDR bond completes,
   nothing initiates the A2DP audio profile connection. The earbuds time
   out waiting for the host to open the audio channel and disconnect
   (reason 2 = remote terminated). Fixed by calling `bluetoothctl connect`
   immediately after `bluetoothctl pair` in PLAT_bluetoothPair().

2. No sound after sleep/wake (fixes #467): bt_init.sh stop/start clears
   the controller's volatile key memory. On wake, earbuds try to reconnect
   but BlueZ rejects them (no stored key, JustWorksRepairing=never default).
   Fixed by patching main.conf to set JustWorksRepairing=always before
   bluetoothd starts, allowing earbuds to re-initiate the bond from their
   side without user interaction.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
tg5050 (TrimUI Smart Pro S) uses an AIC8800 BT chip, not XRadio.
Remove the chip-specific attribution from the comment so it accurately
describes the symptom rather than incorrectly referencing XRadio.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants