Skip to content

feat(bluetooth): optionally drop the iPhone's Bluetooth links on disableBluetooth - #49

Open
code-new-bie wants to merge 1 commit into
shilapi:masterfrom
code-new-bie:pr/bluetooth-handoff
Open

code-new-bie wants to merge 1 commit into
shilapi:masterfrom
code-new-bie:pr/bluetooth-handoff

Conversation

@code-new-bie

Copy link
Copy Markdown

During wireless CarPlay the iPhone sends disableBluetooth to ask the
accessory to drop its classic Bluetooth links to it, so calls and media go
through CarPlay instead of the head unit's hands-free and Bluetooth audio.
The controller only used it to time the wireless handoff; the head unit kept
its HFP and A2DP links, so calls could ring on the head unit's own phone
screen and music could keep playing over Bluetooth.

Two new settings under Bluetooth, both off by default, turn off the iPhone's
hands-free (HFP client) and Bluetooth audio (A2DP sink) links when
disableBluetooth arrives:

  • Each link's connection priority is saved and set to off, so the head unit
    does not reconnect it, and the link is disconnected. A reconnect during the
    session is disconnected again, at most three times a minute.
  • The links are restored 15 s after the session ends unless CarPlay
    reconnects first, at once when the app exits, and on the next start if the
    process was killed before that (restored after 60 s unless CarPlay
    connects first).
  • Changing a setting applies at once, also during a session.

The profiles are hidden API and are called reflectively. On Android 10 and
earlier they need only BLUETOOTH_ADMIN; on later versions the head unit may
refuse, which is logged and leaves the links connected.

Verified in a BYD Song PLUS (Android 10): calls ring only in CarPlay and
music stays on CarPlay during the session, and both links come back after
it. BluetoothHandoffRestoreTest (Robolectric, so shared gains that test
dependency) covers holding, restoring, settings changes and the restore
after a killed process; BluetoothHandoffTest covers the reconnect limit and
address checks.

…bleBluetooth

During wireless CarPlay the iPhone sends disableBluetooth to ask the
accessory to drop its classic Bluetooth links to it, so calls and media go
through CarPlay instead of the head unit's hands-free and Bluetooth audio.
The controller only used it to time the wireless handoff; the head unit kept
its HFP and A2DP links, so calls could ring on the head unit's own phone
screen and music could keep playing over Bluetooth.

Two new settings under Bluetooth, both off by default, turn off the iPhone's
hands-free (HFP client) and Bluetooth audio (A2DP sink) links when
disableBluetooth arrives:

- Each link's connection priority is saved and set to off, so the head unit
  does not reconnect it, and the link is disconnected. A reconnect during the
  session is disconnected again, at most three times a minute.
- The links are restored 15 s after the session ends unless CarPlay
  reconnects first, at once when the app exits, and on the next start if the
  process was killed before that (restored after 60 s unless CarPlay
  connects first).
- Changing a setting applies at once, also during a session.

The profiles are hidden API and are called reflectively. On Android 10 and
earlier they need only BLUETOOTH_ADMIN; on later versions the head unit may
refuse, which is logged and leaves the links connected.

Verified in a BYD Song PLUS (Android 10): calls ring only in CarPlay and
music stays on CarPlay during the session, and both links come back after
it. BluetoothHandoffRestoreTest (Robolectric, so shared gains that test
dependency) covers holding, restoring, settings changes and the restore
after a killed process; BluetoothHandoffTest covers the reconnect limit and
address checks.
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.

1 participant