From 99cd3adf23084479989739935255b4ea6e14be57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Matczuk?= Date: Fri, 24 Jul 2026 14:04:25 +0200 Subject: [PATCH] linux-rust: release AACP state before playback takeover The listener only needs a snapshot of ear detection and connected devices, but kept the AACP mutex while activating audio and sending takeover packets. Copy those values and release the guard first so incoming events and queued control commands are not blocked by profile enumeration or restart delays. --- linux-rust/src/media_controller.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/linux-rust/src/media_controller.rs b/linux-rust/src/media_controller.rs index 5bd68b1a2..f7c29e610 100644 --- a/linux-rust/src/media_controller.rs +++ b/linux-rust/src/media_controller.rs @@ -138,11 +138,16 @@ impl MediaController { drop(state); if !was_playing && is_playing { - let aacp_state = aacp_manager.state.lock().await; - if !aacp_state - .ear_detection_status - .contains(&EarDetectionStatus::InEar) - { + let (bud_in_ear, connected_devices) = { + let aacp_state = aacp_manager.state.lock().await; + ( + aacp_state + .ear_detection_status + .contains(&EarDetectionStatus::InEar), + aacp_state.connected_devices.clone(), + ) + }; + if !bud_in_ear { info!("Media playback started but buds not in ear, skipping takeover"); continue; } @@ -155,7 +160,6 @@ impl MediaController { info!("already connected locally, hijacking connection by asking AirPods"); - let connected_devices = aacp_state.connected_devices.clone(); for device in connected_devices { if device.mac != local_mac { if let Err(e) = aacp_manager