Skip to content

DuckAi/Voice chat: Allow voice chat to run in background#8317

Open
karlenDimla wants to merge 2 commits intodevelopfrom
feature/karl/duckai/voicechat-bg
Open

DuckAi/Voice chat: Allow voice chat to run in background#8317
karlenDimla wants to merge 2 commits intodevelopfrom
feature/karl/duckai/voicechat-bg

Conversation

@karlenDimla
Copy link
Copy Markdown
Contributor

@karlenDimla karlenDimla commented Apr 17, 2026

Task/Issue URL: https://app.asana.com/1/137249556945/project/1208671677432066/task/1214087464606240?focus=true

Description

Enables Duck.ai voice mode to retain microphone access when the app is backgrounded.

Previously, Android would cut off microphone access as soon as the app left the foreground, interrupting any active voice session. This change introduces a foreground service (DuckChatVoiceMicrophoneService)
that is started when a voice session begins and stopped when it ends, signalling to Android that microphone use is intentional and keeping the process alive in the background.

Changes

  • DuckChatVoiceMicrophoneService — new foreground service that displays a persistent notification while a voice session is active, satisfying Android's background microphone requirements
  • VoiceSessionStateManager — new component that tracks the active voice session and its associated tab. Automatically ends the session (and stops the service) when:
    • The Duck.ai tab is closed
    • The app fully exits (swipe from recents)
    • The app is fresh-launched after a process kill
    • The Duck.ai frontend sends a voiceSessionEnded message
  • BrowserTabViewModel — passes tabId into processJsCallbackMessage so the session manager can correctly identify which tab owns the voice session and avoid ending the session when an unrelated tab is closed
  • AndroidManifest — adds FOREGROUND_SERVICE, FOREGROUND_SERVICE_MICROPHONE, and RECORD_AUDIO permissions, and registers the service with foregroundServiceType="microphone"

NOTE: This does not consider multiple duck.ai voice sessions.

Steps to test this PR

Prerequisites: Enable Search & Duck.Ai

Background app — microphone stays active

  • Open Duck.ai and start a voice session
  • Press the Home button to background the app
  • Expected: A persistent notification appears ("Duck.ai Voice" or similar). Voice continues picking up audio in the background.

Return from background — session intact

  • Complete step 1–2 above
  • Re-open the app from the Recent Apps switcher or tap the notification
  • Expected: The notification disappears. The voice session is still active in Duck.ai.

Swipe app away from recents — session ends

  • Open Duck.ai and start a voice session
  • Open the Recent Apps switcher and swipe the app away
  • Expected: The notification is dismissed. The foreground service stops.

Close the Duck.ai tab — session ends

  • Open Duck.ai and start a voice session
  • Close the Duck.ai tab (via the tab switcher)
  • Expected: The notification disappears immediately. The voice session ends.

Closing a different tab — session unaffected

  • Open Duck.ai and start a voice session, plus at least one other tab
  • Close any tab that is NOT the Duck.ai tab
  • Expected: The notification remains. The voice session continues.

Voice session ended by Duck.ai UI — service stops

  • Open Duck.ai and start a voice session
  • End the voice session within Duck.ai (e.g. tap stop/end)
  • Expected: The notification disappears.

Fresh app launch — no stale session

  • Force-stop the app while a voice session notification is visible
  • Re-launch the app
  • Expected: No notification appears. No stale session is active.

Note

Medium Risk
Introduces a new microphone foreground service and adds new audio/foreground-service permissions, which can impact runtime behavior and Play policy compliance; also changes session-lifecycle handling tied to tab removal and app exit.

Overview
Enables Duck.ai voice chat to keep microphone access while the app is backgrounded by starting a new foreground service (DuckChatVoiceMicrophoneService) with a persistent notification during active voice sessions.

Voice session tracking is expanded so VoiceSessionStateManager is started with a tabId, automatically ends the session (and stops the service) when the owning tab is closed or the app exits/fresh-launches, and BrowserTabViewModel now passes tabId into Duck.ai JS callbacks to support this. The duckchat-impl manifest adds microphone/foreground-service permissions and registers the new service, and tests are updated/added to cover the new tab-aware lifecycle behavior.

Reviewed by Cursor Bugbot for commit d57f881. Bugbot is set up for automated code reviews on this repo. Configure here.

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@karlenDimla karlenDimla force-pushed the feature/karl/duckai/voicechat-bg branch from af29658 to e67cfe3 Compare April 17, 2026 14:43
@karlenDimla karlenDimla force-pushed the feature/karl/duckai/voicechat-bg branch from e67cfe3 to 3706f37 Compare April 17, 2026 14:46
Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 67fc4e6. Configure here.

@karlenDimla karlenDimla force-pushed the feature/karl/duckai/voicechat-bg branch from 67fc4e6 to d57f881 Compare April 17, 2026 16:22
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.

2 participants