Skip to content

Fix/bluetooth call routing - #6774

Merged
mahibi merged 9 commits into
masterfrom
fix/bluetooth-call-routing
Sep 25, 2026
Merged

mahibi merged 9 commits into
masterfrom
fix/bluetooth-call-routing

Conversation

@mahibi

@mahibi mahibi commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

continuing PR #6567 in Nextcloud repo. Kudos to @flake92

  • Prefer call-capable Bluetooth communication devices and preserve selection across reconnects.
  • On Android 12+, Bluetooth goes through the communication-device API instead of the deprecated SCO calls.
  • A Bluetooth choice now survives the headset disconnecting and reconnecting.
  • When leaving Bluetooth, the new output is selected first, so the working route stays if Android rejects the switch.
  • Bluetooth connection attempts are limited to 2, and late callbacks for old requests are ignored.
  • After audio focus returns, the Bluetooth route is selected again, or the call falls back to another output.
  • Ringback and remote audio wait for Android to confirm the route. After 10 s without confirmation, remote audio plays on the current route anyway.
  • Wired and USB headsets are detected with a device callback

馃弫 Checklist

  • 鉀戯笍 Tests (unit and/or integration) are included or not needed
  • 馃敄 Capability is checked or not needed
  • 馃敊 Backport requests are created or not needed: /backport to stable-xx.x
  • 馃搮 Milestone is set
  • 馃尭 PR title is meaningful (if it should be in the changelog: is it meaningful to users?)

馃 AI (if applicable)

  • The content of this PR was partly or fully generated using AI

@mahibi mahibi mentioned this pull request Sep 24, 2026
1 of 7 tasks
flake92 and others added 7 commits September 24, 2026 15:08
Prefer call-capable Bluetooth communication devices and preserve selection across reconnects.

Assisted-by: Codex:gpt-5
Signed-off-by: Oleg Cherry <80347136+flake92@users.noreply.github.com>
Assisted-by: Codex:gpt-5
Signed-off-by: Oleg Cherry <80347136+flake92@users.noreply.github.com>
Keep the working route when a device switch is rejected, preserve bounded retry state across focus changes, reject stale callbacks, and share wired-device detection. Convert the new policy and tests to Kotlin.

Assisted-by: Codex:gpt-5
Signed-off-by: flake92 <flake92@live.com>
Preserve the active route until a non-Bluetooth replacement is confirmed.

Keep automatic retry limits across focus recovery, reject stale callbacks, and reconcile wired and USB devices consistently.

Assisted-by: OpenAI Codex:gpt-5.6-sol
Signed-off-by: flake92 <flake92@live.com>
Extract modern Bluetooth focus recovery into a dedicated helper to keep the public dispatcher below the Codacy PMD NPath threshold without changing behavior.

Assisted-by: OpenAI Codex:gpt-5.6-sol
Signed-off-by: flake92 <flake92@live.com>
Delay ringback and remote audio playout until Android confirms the selected communication route. Keep reconnects silent and preserve the working privacy build behavior while retaining the hardened Bluetooth transition policy.

Assisted-by: OpenAI Codex:gpt-5.6-sol
Signed-off-by: flake92 <80347136+flake92@users.noreply.github.com>
Stop logging Bluetooth device names and hardware addresses; the adapter log
now only reports its state and the number of paired devices.

Only enumerate or select Bluetooth communication devices while the Bluetooth
permission (BLUETOOTH_CONNECT on Android 12+) is granted, and fall back to
another route otherwise.

Guard the remote audio playout flag and the registration of new peer
connection wrappers with one lock, so a wrapper created on the signaling
thread cannot pick up a stale "playout enabled" value after the audio route
was lost on the main thread.

Assisted-by: Claude:claude-opus-5
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KPHB1yxj4sVtsGoQhtbfCy
Signed-off-by: flake92 <80347136+flake92@users.noreply.github.com>
With speaker selected, the proximity sensor switched the route to the
earpiece directly. On Android 12+ that switch triggers the communication
device callback, which re-ran the route selection and switched straight back
to the speaker because it did not know about the proximity state.

Apply the proximity override inside the route selection so every route update
keeps the earpiece while the phone is near the ear.

Assisted-by: Claude Code:claude-opus-5
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
@mahibi
mahibi force-pushed the fix/bluetooth-call-routing branch from fecedc6 to ee36990 Compare September 24, 2026 14:26
@mahibi
mahibi marked this pull request as ready for review September 24, 2026 14:27
Remote audio waited for Android to confirm the selected communication route
without a limit. If a device never confirmed it, the call stayed silent.
After 10 seconds, play remote audio on the current route instead. The audio
manager's own Bluetooth fallback finishes before that.

Also drop the Bluetooth device name from the legacy headset log and correct
the comment on which Bluetooth permission the Android 12+ route needs.

Assisted-by: Claude Code:claude-opus-5
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
@mahibi

mahibi commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator Author

works fine for me.

One lesson learned (again): Testing with older bluetooth devices is a pain. Many issues are caused by the devices theirself, without that there is a bug in the talk code.
Example:
My "Marshall Major 3 Bluetooth" headphone lose the connection shortly after connecting during a call. This happens for all apps, so it's a device issue.

@mahibi

mahibi commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator Author

@rapterjet2004 if you approve if can be merged from my point of view

@github-actions

Copy link
Copy Markdown
Contributor

馃摫 QA build

Download app-qa-debug.apk
QR code Open the QR code for this download
Commit dff6fb3
Version 6774
Available until 7 days after this build

The QA build installs alongside a released Nextcloud app, so you can keep
using your existing install while testing.

Downloading the file requires a GitHub account, so open this link on the
device you want to test on, or transfer the APK to it.

@mahibi
mahibi merged commit 75a5792 into master Sep 25, 2026
14 of 18 checks passed
@mahibi
mahibi deleted the fix/bluetooth-call-routing branch September 25, 2026 09:43
@mahibi mahibi added this to the 25.1.0 milestone Sep 25, 2026
@mahibi

mahibi commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator Author

Thank you @flake92 馃憤 馃憤

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants