Skip to content

fix(call): restore call audio mode after audio focus interruptions - #6546

Merged
mahibi merged 1 commit into
masterfrom
fix/audio-focus-interruption
Aug 24, 2026
Merged

fix(call): restore call audio mode after audio focus interruptions#6546
mahibi merged 1 commit into
masterfrom
fix/audio-focus-interruption

Conversation

@tareko

@tareko tareko commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

fix(call): restore call audio mode after audio focus interruptions

Fixes #6541

Description

The audio focus change listener in WebRtcAudioManager only logged changes (the "possibly extend support of handling audio-focus changes" TODO from the WebRTC sample was never implemented). A transient focus holder such as the telephony stack switches the global audio mode to MODE_IN_CALL and restores its own saved mode (typically MODE_NORMAL) on release, clobbering Talk's MODE_IN_COMMUNICATION. Since nothing re-asserted it, a Talk call interrupted by an incoming GSM call continued without hardware echo cancellation and proper VoIP routing — remote parties heard echo, very quiet audio, or nothing until the call was left and rejoined.

Changes:

  • New AudioFocusState tracks transient focus losses; when focus returns, MODE_IN_COMMUNICATION and the selected audio route are re-asserted (guarded by the RUNNING state so late callbacks after stop() are ignored)
  • Focus is now requested with AUDIOFOCUS_GAIN via AudioFocusRequest (voice-communication attributes, delayed gain accepted, no ducking) instead of the deprecated AUDIOFOCUS_GAIN_TRANSIENT hint meant for short-lived use
  • stop() abandons focus via abandonAudioFocusRequest

Steps to reproduce / How to test

  1. Join a Talk call (audio works both ways)
  2. Receive and answer a regular phone call
  3. Hang up the phone call and return to Talk
  4. Speak and ask the remote party what they hear

Without this PR: echo / very quiet audio / silence until the call is restarted.
With this PR: normal two-way audio resumes when the phone call ends.

Also test: music app playing before/after the call, headset unplug (ACTION_AUDIO_BECOMING_NOISY path), joining a call while a phone call is active (delayed focus gain).

  • ⛑️ Tests are included (WebRtcAudioManagerFocusTest: focus request config + restore state machine)
  • 🔖 Capability is checked or not needed
  • 🔙 Backport requests or not needed
  • 📅 Milestone is set
  • 🌸 PR title is meaningful

Note: This PR was developed with AI assistance (opencode / Kimi K3); see the Assisted-by commit trailer.

The audio focus change listener in WebRtcAudioManager only logged
changes. A transient focus holder such as the telephony stack switches
the global audio mode and restores its own saved mode on release,
clobbering MODE_IN_COMMUNICATION. After an incoming GSM call the Talk
call therefore continued without hardware echo cancellation and proper
VoIP routing: remote parties heard echo, quiet audio, or nothing until
the call was restarted.

- Re-assert MODE_IN_COMMUNICATION and the selected audio route when
  focus returns after a transient loss (new AudioFocusState tracks this)
- Request focus with AUDIOFOCUS_GAIN via AudioFocusRequest (voice
  communication attributes, delayed gain accepted) instead of the
  deprecated AUDIOFOCUS_GAIN_TRANSIENT hint meant for short use
- Abandon focus via abandonAudioFocusRequest on stop

Fixes #6541

Assisted-by: opencode:ox-alpha
Signed-off-by: Tarek Loubani <tarek@tarek.org>
@github-actions

Copy link
Copy Markdown
Contributor

APK file: https://github.com/nextcloud/talk-android/actions/runs/32604199571/artifacts/9483779211
To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.
qrcode (please click on link to get QR code displayed)

@AndyScherzinger AndyScherzinger added the 3. to review Waiting for reviews label Aug 23, 2026
@AndyScherzinger
AndyScherzinger requested review from mahibi and a lite review from Copilot August 23, 2026 06:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes an audio-routing regression during Talk calls after audio focus interruptions (e.g., answering/hanging up a GSM call) by re-asserting AudioManager.MODE_IN_COMMUNICATION and the selected audio route when focus is regained, ensuring proper VoIP routing and hardware AEC behavior.

Changes:

  • Implement audio focus change handling in WebRtcAudioManager to restore call audio mode/route after transient focus loss.
  • Switch audio focus acquisition to AudioFocusRequest with AUDIOFOCUS_GAIN and voice-communication AudioAttributes, and abandon focus via abandonAudioFocusRequest.
  • Add Robolectric unit tests covering the focus request configuration and the transient-loss restore state machine.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
app/src/main/java/com/nextcloud/talk/webrtc/WebRtcAudioManager.java Adds focus request/state tracking and re-applies MODE_IN_COMMUNICATION + routing on focus regain.
app/src/test/java/com/nextcloud/talk/webrtc/WebRtcAudioManagerFocusTest.kt Adds unit tests for the focus request config and restore-on-gain behavior after transient loss.
Suppressed comments (1)

app/src/main/java/com/nextcloud/talk/webrtc/WebRtcAudioManager.java:173

  • requestAudioFocus() can return AUDIOFOCUS_REQUEST_DELAYED when acceptsDelayedFocusGain is enabled. The current code treats any non-GRANTED result as an error, which will log a false failure in the delayed-focus scenario described in the PR and issue.
        if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
            Log.d(TAG, "Audio focus request granted for VOICE_CALL streams");
        } else {
            Log.e(TAG, "Audio focus request failed");
        }

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@mahibi
mahibi merged commit 2f7406a into master Aug 24, 2026
19 of 21 checks passed
@mahibi
mahibi deleted the fix/audio-focus-interruption branch August 24, 2026 18:11
@mahibi mahibi modified the milestones: 25.0.0, 25.1.0 Aug 24, 2026
@mahibi

mahibi commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

/backport to stable-25.0.x

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

Labels

3. to review Waiting for reviews AI assisted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Audio focus interruption (incoming GSM call) is never restored: echo / no audio until the Talk call is restarted

4 participants