Skip to content

Draft: Bluetooth handoff

Summary

This feature adds Bluetooth Handoff to KDE Connect, which means it allows devices to coordinate connection of third-party bluetooth devices.

This is similar to how Apple devices can start playing audio on another device and the Airpods will automatically (and instantaneously) switch to the new device.

Here's a video demo (Youtube link):

Video

This initial patch adds three commands:

  • Device List (List of paired bluetooth devices, and an "is connected" bit for them)
  • Disconnect from device by MAC address
  • Connect to device by MAC address

It currently has a lot of code duplication and uses reflection for connect/disconnect (I haven't found another way that actually works), see "Shortcomings" section below.

The flows for each command begins by spawning a new thread (for doing blocking operations), and inside, iterating over each Bluetooth profile type (A2DP, HEADSET, HID_DEVICE, etc.).

In the "Device List" flow we then call getConnectedDevices which gives us the devices connected with this profile, and then merge it into a single "devices connected" list.

In the "Disconnect" flow we get the private disconnect method from the profile via reflection, then call it with the given device.

In the "Connect" flow we get the private connect method from the profile via reflection, then call it with the given device.

This shouldn't use a lot of battery since the PC should only query the device list when the dialog is open, and it doesn't trigger a Bluetooth scan anyway.

UI

Phone side is minimal right now, but can be implemented to mirror the desktop version

Phone UI

This is the desktop UI: (I use GNOME so screenshot is from GSConnect (Link to PR))

image

Test Plan

Installation

  • Install this branch on a phone using Android Studio or what have you.
  • Get a PC or VM with GNOME 40 (not 41 or 42, I don't have it yet so couldn't use GSConnect's master branch), I used an Ubuntu 21.10 based distro.
  • git clone git@github.com:Wazzaps/gnome-shell-extension-gsconnect.git -b feature/bluetooth-handoff && cd gnome-shell-extension-gsconnect
  • meson _build
  • ninja -C _build install-zip
  • Pair PC & Phone normally.
  • Pair a Bluetooth headset (or other device, though not tested) to the phone.
  • Open the "Bluetooth Devices" option in the menu:
    Screenshot_from_2022-04-22_16-09-47-2
  • The Bluetooth device should show up. Check the checkbox. The phone should disconnect, then the PC will start pairing (Not sure if a dialog will pop-up without blueman, try it)
    If it doesn't, pair the device with the PC too.
  • Now Unchecking the checkbox will disconnect it from the PC and connect it to the phone, and vice versa. Each switch may take from 3-10 seconds, depending on the device and the Bluetooth stacks on your host devices.

Shortcomings

  • No Desktop KDE implementation (Will try to find the time).
  • Need to check with more Bluetooth devices, currently only checked with Sony WH-1000XM3 and JBL LIVE300TWS.
  • Code duplication.
  • Uses reflection for connect/disconnect (Doesn't seem to be a way otherwise).
  • Need to add UI to control the connections to the Android side too.
  • Need to check older/newer Android versions (checked on Oxygen OS / Android 12).
  • Doesn't automatically happen. Perhaps we can integrate with the "Media Player Control" plugin.
  • Switching is pretty slow, though that might be Bluetooth's fault (Can we fix it anyway?).

Merge request reports