Skip to content

Disable BT audio devices for Element Call on Android < 12 #4876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

jmartinesp
Copy link
Member

Content

  • Disable audio devices on Android devices with an OS version < 12 - using some legacy audio APIs.
  • When this happens, mute the audio from the call, display a dialog and unmute the call once a different audio device is selected.
  • Also add a workaround for an issue where some devices weren't able to easily leave the call after hanging up.

Motivation and context

After trying several strategies to make BT audio devices play nice with the embedded Element Call instance on Android versions using the legacy audio APIs - Android 11 and lower - and it failing in several ways - wrong audio device being used when switching, audio just dying until the app is force closed or the app crashing with a native OS error and no stacktrace - we had to make a difficult decision of preventing using these devices at all.

This change makes it so when selecting a BT audio device or when it's selected by default by the OS, we notify the user about the device not being usable, and mute the audio to prevent it from being streamed through some other audio device. Once a new device is selected, the audio is enabled again and that device can be used normally.

Screenshots / GIFs

image

Tests

With an Android device using Android 11 or lower:

  • Open a call with a BT audio device connected. You should see the error dialog and be able to switch to another device and have the audio working properly with those.
  • When selecting the BT audio device again you should see the same result.
  • Everything else related to audio in calls should still work as before.

Tested devices

  • Physical
  • Emulator
  • OS version(s): 10

Checklist

  • Changes have been tested on an Android device or Android emulator with API 24
  • UI change has been tested on both light and dark themes
  • Accessibility has been taken into account. See https://github.com/element-hq/element-x-android/blob/develop/CONTRIBUTING.md#accessibility
  • Pull request is based on the develop branch
  • Pull request title will be used in the release note, it clearly define what will change for the user
  • Pull request includes screenshots or videos if containing UI changes
  • You've made a self review of your PR

@jmartinesp jmartinesp added the PR-Misc For other changes label Jun 13, 2025
After trying several strategies to make BT audio devices play nice with the embedded Element Call instance on Android versions using the legacy audio APIs - Android 11 and lower - and it failing in several ways - wrong audio device being used when switching, audio just dying until the app is force closed or the app crashing with a native OS error and no stacktrace - we had to make a difficult decision of preventing using these devices at all.

This change makes it so when selecting a BT audio device or when it's selected by default by the OS, we notify the user about the device not being usable, and mute the audio to prevent it from being streamed through some other audio device. Once a new device is selected, the audio is enabled again and that device can be used normally.
…n when tapping on the button inside the WebView

This change makes it so that if you go back when you already tried to hang up, it'll wait for the confirmation for a couple of seconds and if it doesn't arrive it'll leave the call screen anyway.
@jmartinesp jmartinesp force-pushed the misc/disable-bt-audio-devices-for-element-call-on-android-11-and-lower branch from 87fd3b1 to 993eec5 Compare June 13, 2025 10:55
Copy link
Contributor

github-actions bot commented Jun 13, 2025

📱 Scan the QR code below to install the build (arm64 only) for this PR.
QR code
If you can't scan the QR code you can install the build via this link: https://i.diawi.com/tp2WNt

@jmartinesp jmartinesp added the Record-Screenshots Runs the 'Record Screenshots' CI job and adds a commit with any new screenshots found. label Jun 13, 2025
@github-actions github-actions bot removed the Record-Screenshots Runs the 'Record Screenshots' CI job and adds a commit with any new screenshots found. label Jun 13, 2025
@jmartinesp jmartinesp added the Record-Screenshots Runs the 'Record Screenshots' CI job and adds a commit with any new screenshots found. label Jun 13, 2025
@github-actions github-actions bot removed the Record-Screenshots Runs the 'Record Screenshots' CI job and adds a commit with any new screenshots found. label Jun 13, 2025
@jmartinesp jmartinesp marked this pull request as ready for review June 13, 2025 11:19
@jmartinesp jmartinesp requested a review from a team as a code owner June 13, 2025 11:19
@jmartinesp jmartinesp requested review from bmarty and removed request for a team June 13, 2025 11:19
Comment on lines 180 to 182
InvalidAudioDeviceReason.BT_AUDIO_DEVICE_DISABLED -> {
// TODO: use a string resource when available
"Element Call does not support using Bluetooth audio devices in this Android version. Please select a different audio device."
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is replaced by the actual string in a following commit.

Copy link

Copy link

codecov bot commented Jun 13, 2025

Codecov Report

Attention: Patch coverage is 38.23529% with 21 lines in your changes missing coverage. Please review.

Project coverage is 80.25%. Comparing base (148b3d9) to head (58fda70).
Report is 9 commits behind head on develop.

Files with missing lines Patch % Lines
...id/features/call/impl/utils/WebViewAudioManager.kt 16.66% 14 Missing and 1 partial ⚠️
...nt/android/features/call/impl/ui/CallScreenView.kt 66.66% 5 Missing ⚠️
...droid/features/call/impl/ui/CallScreenPresenter.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4876      +/-   ##
===========================================
- Coverage    80.27%   80.25%   -0.02%     
===========================================
  Files         2140     2140              
  Lines        56909    56938      +29     
  Branches      7164     7168       +4     
===========================================
+ Hits         45686    45698      +12     
- Misses        8789     8805      +16     
- Partials      2434     2435       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. LGTM.

Sadly I'll have to update again #4863, but that's my fault, it's still a draft PR.

@jmartinesp jmartinesp merged commit c598b06 into develop Jun 13, 2025
28 of 31 checks passed
@jmartinesp jmartinesp deleted the misc/disable-bt-audio-devices-for-element-call-on-android-11-and-lower branch June 13, 2025 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR-Misc For other changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants