Feature: Support voice monitoring on Android hosts

The master's voice monitoring menu sends COMMAND_AUDIO; the client opens a
ConnAuth sub-connection with TOKEN_AUDIO_START, the server opens CAudioDlg
and answers COMMAND_NEXT, then audio flows both ways. The protocol matches
the Windows client, so the server needs no changes.

The server's ACM format was read from Audio.cpp and AudioDlg.cpp first:
WAVE_FORMAT_GSM610, 8000 Hz mono, 65-byte blocks of 320 samples (40 ms),
about 1625 B/s. libgsm 1.0.13 (AOSP external/libgsm mirror) is vendored
under cpp/gsm and built with -DSASR -DWAV49 so its MS-GSM packing is
byte-identical to ACM GSM610. Encode and decode use separate gsm states
because frame_index/frame_chain live in the state.

Uplink packets are always exactly 1000 bytes: CAudio::PlayBuffer copies
1000 bytes from the buffer start regardless of packet length, so a short
packet would over-read. Since 1000 is not a multiple of 65, blocks
straddle packets; the stream is continuous and codec state carries over.

AudioMonitor.kt owns AudioRecord (8 kHz/16-bit/mono, 320 samples a read)
and AudioTrack playback of decoded downlink PCM. RECORD_AUDIO is requested
with POST_NOTIFICATIONS before the projection dialog, and CaptureService
adds the microphone FGS type only when held, falling back on failure. An
8-second dialog wait or missing microphone reports a tip to the master
instead of failing silently.

Verified on an Android 15 emulator against the Debug server: dialog
opened, uplink started, server receive counter grew at ~1.6 KB/s.
Downlink playback was not exercised (the test machine has no recording
device); that path is code-reviewed only.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-11 21:58:54 +01:00
1 parent 3ab5154db1
commit 4aedca8ee0
31 files changed
+4979 -22

No files matched your search

+5 -1
View File
@@ -5,6 +5,10 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
<!-- 语音监听(COMMAND_AUDIO):AudioRecord 采集麦克风;后台采集要求前台服务带
microphone 类型(Android 11+),类型权限在上面的 FOREGROUND_SERVICE_MICROPHONE -->
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<!-- 在线升级:走 PackageInstaller 会话安装服务端下发的 APK,仍需系统安装器人工确认 -->
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<!-- 卸载主机(TOKEN_UNINSTALL):ACTION_DELETE 拉系统卸载确认框,缺这个权限
@@ -39,7 +43,7 @@
<service
android:name=".CaptureService"
android:foregroundServiceType="dataSync|mediaProjection"
android:foregroundServiceType="dataSync|mediaProjection|microphone"
android:exported="false" />
<service