Skip to content

feat(audio): coordinate Android audio focus and auto-yield on system interruptions - #39

Closed
yanwuu wants to merge 1 commit into
shilapi:masterfrom
yanwuu:feat/multi-resume-split-screen
Closed

yanwuu wants to merge 1 commit into
shilapi:masterfrom
yanwuu:feat/multi-resume-split-screen

Conversation

@yanwuu

@yanwuu yanwuu commented Oct 8, 2026

Copy link
Copy Markdown

Summary

Resolves #36 by introducing Android system AudioFocus management and automatic ducking/muting for CarPlay audio playback on Android head units.

Problem

In vehicle environments, native infotainment components (such as Bluetooth telephone calls, native FM/AM radio, backup radar chimes, or native voice assistants) dynamically request Android audio focus.

Previously, xcertplay did not participate in Android's AudioFocus lifecycle. When a native audio event occurred:

  • CarPlay media audio kept playing at full volume, colliding with phone calls or native alerts.
  • On some automotive ROMs, unhandled focus loss resulted in unexpected audio subsystem resets or connection dropouts.

Solution

  1. AudioFocusCoordinator:
    • Manages audio focus requests using AudioFocusRequest based on active stream priority:
      • MEDIA -> AUDIOFOCUS_GAIN
      • PHONE -> AUDIOFOCUS_GAIN_TRANSIENT
      • ASSISTANT -> AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK
      • NAVIGATION -> Coexists without claiming exclusive focus.
  2. Audio Ducking and Auto-Yield (Muting):
    • Ducking: Automatically attenuates media volume to 20% (0.2f) upon receiving AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK.
    • Auto-Yield: Automatically mutes media volume to 0% (0.0f) upon AUDIOFOCUS_LOSS_TRANSIENT (e.g. during incoming/outgoing car Bluetooth phone calls or native car voice interruptions).
    • Restoration: Restores full volume (100%) upon AUDIOFOCUS_GAIN.
  3. Settings & Persistence:
    • Added Audio focus and Mute media on temporary focus loss toggles in Settings -> Audio section (persisted in AirPlayPersistence).
    • Defaults to enabled for optimal automotive experience, while allowing users on non-compliant head units to disable it if needed.
  4. Unit Tests:
    • Added AudioFocusCoordinatorTest covering channel focus priorities and volume constants.

中文说明

问题背景:
在车机场景下,车载蓝牙电话、原车调频广播、倒车雷达提示音以及车载语音助手会随时请求 Android 系统音频焦点。此前 xcertplay 未接入 Android 音频焦点监听,导致在蓝牙来电或原车播报时,CarPlay 音乐依旧全音量播放,发生声音撞车或在部分车机上引发异常(对应 Issue #36)。

解决方案:

  1. 音频焦点调度器 (AudioFocusCoordinator):根据通道类型动态申请对应级别的音频焦点(媒体流申请长期焦点,通话/语音申请临时焦点,导航流不独占焦点)。
  2. 自动压音与通话避让静音:
    • 收到短暂可降音信号(LOSS_TRANSIENT_CAN_DUCK)时,自动压低 CarPlay 音乐音量至 20%。
    • 收到临时失去焦点信号(LOSS_TRANSIENT,如原车蓝牙电话接通)时,自动将媒体流静音(0%),电话挂断并重获焦点(GAIN)后自动恢复 100% 音量。
  3. 配置开关与持久化:在设置菜单音频板块新增对应开关与说明,并默认开启,保证即开即用与良好兼容性。

- Add android.allow_multiple_resumed_activities meta-data to enable
  multi-resume on Android 9 (API 28) and Android 10, preventing frame
  drops and rendering suspension when interacting with another app in
  split-screen or floating multi-window mode.
- Implement onMultiWindowModeChanged to trigger dynamic resolution
  re-scheduling when entering/exiting multi-window mode.
- Avoid force-hiding status and navigation bars while in multi-window
  mode to preserve split-screen boundaries and car system dock controls.
- Add supportsPictureInPicture and ensure resizeableActivity is declared
  consistently across activities.
@yanwuu yanwuu closed this Oct 8, 2026
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.

[Bug] Lynk & Co 09 (Android 9, OSN 2.0): LocalOnlyHotspot fails due to virtual wlan0 address; CarPlay music pauses when native radio is active

1 participant