fix: workaround for android non-telecom path MODE_IN_COMMUNICATION reset edge-case - #2360
fix: workaround for android non-telecom path MODE_IN_COMMUNICATION reset edge-case#2360santhoshvai wants to merge 4 commits into
Conversation
📝 WalkthroughWalkthroughAdds an Android 11+ communication-mode keep-alive workaround with configuration and setter APIs. Integrates it with call audio lifecycle handling, diagnostics, compatibility fallbacks, and forwarding tests. ChangesCommunication mode workaround
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant CallManager
participant StreamInCallManagerModule
participant AudioDeviceManager
participant CommunicationModeKeepAlive
participant AudioTrack
CallManager->>StreamInCallManagerModule: Start communicator call with optional setting
StreamInCallManagerModule->>AudioDeviceManager: Configure workaround
AudioDeviceManager->>CommunicationModeKeepAlive: Start for eligible Android calls
CommunicationModeKeepAlive->>AudioTrack: Play silent voice-communication audio
AudioDeviceManager->>CommunicationModeKeepAlive: Stop before audio teardown
CommunicationModeKeepAlive->>AudioTrack: Release resources
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@packages/react-native-sdk/android/src/main/java/com/streamvideo/reactnative/audio/AudioDeviceManager.kt`:
- Around line 173-180: The stop flow in AudioDeviceManager.stop() currently
depends on currentActivity being available before releasing audio state.
Decouple teardown from the Activity-dependent block so audioManagerActivated is
reset and communicationWorkaround.stop() always runs, including when
currentActivity is null; keep only Activity-specific cleanup conditional on the
activity.
- Around line 301-305: Update AudioDeviceManager.close() to queue
communicationWorkaround disposal and all related audio cleanup on the same audio
executor used by start() and stop(), rather than performing it directly. Ensure
close() cannot race pending audio work or allow a queued start() to access
audioTrack or watchdog after cleanup, while preserving the existing callback
unregistration and proximityManager teardown behavior.
In
`@packages/react-native-sdk/android/src/main/java/com/streamvideo/reactnative/audio/CommunicationWorkaround.kt`:
- Around line 223-231: The watchdog repair in CommunicationWorkaround is still
able to run after stop() has restored MODE_NORMAL, so update the
AudioDeviceManager.runInAudioThread closure to check the active state before
touching AudioManager.mode. Keep the existing mode re-assertion logic in the
same watchdog block, but gate the read/write with the component’s current
running/active flag so stale queued work exits without setting
MODE_IN_COMMUNICATION after shutdown.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 31a96c71-a814-4394-a6a8-4ebfce921611
📒 Files selected for processing (7)
packages/react-native-sdk/__tests__/call-manager/CallManager.test.tspackages/react-native-sdk/android/src/main/java/com/streamvideo/reactnative/audio/AudioDeviceManager.ktpackages/react-native-sdk/android/src/main/java/com/streamvideo/reactnative/audio/CommunicationWorkaround.ktpackages/react-native-sdk/android/src/main/java/com/streamvideo/reactnative/callmanager/StreamInCallManagerModule.ktpackages/react-native-sdk/src/modules/call-manager/CallManager.tspackages/react-native-sdk/src/modules/call-manager/native-module.d.tspackages/react-native-sdk/src/modules/call-manager/types.ts
Bundle sizeBuilt package output. Sizes in KB; delta vs
|
💡 Overview
Fixes Android audio routing breaking mid-call on Android 11+. The OS resets
AudioManager.MODE_IN_COMMUNICATION~6s after it's set when the app has no activevoice-comm playback or recording — dropping the
call to the default media route and disabling AEC (https://issuetracker.google.com/issues/209493718).
This PR adds a workaround that plays a silent, looping voice-communication
AudioTrackfor theduration of a communicator-role call, so the OS always sees active playback and holds the
mode. Android-only; no-op below API 30 and for the
listenerrole / Telecom-managed calls.📝 Implementation notes
CommunicationModeKeepAlive.kt: plays a silent-AudioTrackto keep-alive; falls back to a periodicMODE_IN_COMMUNICATIONre-assert watchdog if the track can't be built.🎫 Ticket: https://linear.app/stream/issue/XYZ-123
📑 Docs: https://github.com/GetStream/docs-content/pull/
Summary by CodeRabbit