Skip to content

Commit 005a9eb

Browse files
committed
bluetooth: disconnect MD after handshake
Replace stream.shutdown() which seems doing nothing with a device.disconnect() call. We need to do this since we now have profiles registered and not powering bluetooth adapter down. This should force MD connecting to HU for calls.
1 parent c92741a commit 005a9eb

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/bluetooth.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ impl Bluetooth {
294294
bt_timeout: Duration,
295295
state: AppState,
296296
stopped: bool,
297-
) -> Result<Stream> {
297+
) -> Result<(Address, Stream)> {
298298
info!("{} ⏳ Waiting for phone to connect via bluetooth...", NAME);
299299

300300
// try to connect to saved devices or provided one via command line
@@ -352,9 +352,10 @@ impl Bluetooth {
352352
NAME,
353353
req.device()
354354
);
355+
let addr = req.device().clone();
355356
let stream = req.accept()?;
356357

357-
Ok(stream)
358+
Ok((addr, stream))
358359
}
359360

360361
async fn cleanup_failed_bluetooth_connect(device: &Device) -> Result<()> {
@@ -561,7 +562,7 @@ impl Bluetooth {
561562
let mut started;
562563

563564
// Use the provided session and adapter instead of creating new ones
564-
let mut stream = self
565+
let (address, mut stream) = self
565566
.power_up_and_wait_for_connection(dongle_mode, connect, bt_timeout, state, stopped)
566567
.await?;
567568

@@ -597,7 +598,11 @@ impl Bluetooth {
597598
started = Instant::now();
598599
read_message(&mut stream, stage, MessageId::WifiConnectStatus, started).await?;
599600
tcp_start.notify_one();
600-
let _ = stream.shutdown().await?;
601+
602+
// handshake complete, now disconnect the device so it should
603+
// connect to real HU for calls
604+
let device = self.adapter.device(bluer::Address(*address))?;
605+
let _ = device.disconnect().await;
601606

602607
info!("{} 🚀 Bluetooth launch sequence completed", NAME);
603608

0 commit comments

Comments
 (0)