使用adb shell dumpsys命令,该命令用于打印出当前系统信息,默认打印出设备中所有service的信息,可以在命令后面加指定的service name。
cmd adb shell dumpsys media.audio_policy
- Available output devices:
Device 1:
- id: 2
- tag name: Earpiece
- type: AUDIO_DEVICE_OUT_EARPIECE
- Profiles:
Profile 0:
- format:
- sampling rates:
- channel masks:
Device 2:
- id: 3
- tag name: Speaker
- type: AUDIO_DEVICE_OUT_SPEAKER
- Profiles:
Profile 0:
- format:
- sampling rates:
- channel masks:
Device 3:
- id: 4
- tag name: Dgtl Dock Headset //
- type: AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET
- Profiles:
Profile 0:
- format:
- sampling rates:
- channel masks:
Device 4:
- id: 5
- tag name: Telephony Tx //电话下行数据,用于传输路由到手机无线装置的音频
- type: AUDIO_DEVICE_OUT_TELEPHONY_TX
- Profiles:
Profile 0:
- format:
- sampling rates:
- channel masks:
- Available input devices:
Device 1:
- id: 2
- tag name: Built-In Mic
- type: AUDIO_DEVICE_IN_BUILTIN_MIC
- address: bottom
- Profiles:
- format:
- sampling rates:
- channel masks:
Device 2:
- id: 3
- tag name: Built-In Back Mic
- type: AUDIO_DEVICE_IN_BACK_MIC
- address: back
- Profiles:
Profile 0:
- format:
- sampling rates:
- channel masks:
Device 3:
- id: 4
- tag name: FM Tuner In //仅用于广播无线装置输入
- type: AUDIO_DEVICE_IN_FM_TUNER
- Profiles:
Profile 0:
- format:
- sampling rates:
- channel masks:
Device 4:
- id: 5
- tag name: Echo Ref In
- type: AUDIO_DEVICE_IN_ECHO_REFERENCE
- Profiles:
Profile 0:
- format:
- sampling rates:
- channel masks:
Device 5:
- id: 6
- tag name: Voice Call In
- type: AUDIO_DEVICE_IN_TELEPHONY_RX|AUDIO_DEVICE_IN_VOICE_CALL //电话上行数据,用于从移动网络电台接收到的与通话相关联的音频
- Profiles:
Profile 0:
- format:
- sampling rates:
- channel masks:
Device 6:
- id: 7
- tag name: Remote Submix In //表示被传输至远程接收设备的音频,这类音频数据流会被重定向至远程输出而非在本地扬声器或耳机播放。
- type: AUDIO_DEVICE_IN_REMOTE_SUBMIX
- address: 0
- Profiles:
Profile 0:
- format:
- sampling rates:
- channel masks:
四种输出设备:
- Earpiece 听筒
- Speaker 扬声器
- Dgtl Dock Headset
- Telephony Tx
四种输入设备:
- Built-In Mic
- Built-In Back Mic
- Telephony Rx
1.设备参数从何而来
在 native 层构造 AudioPolicyManager 对象的时候,会调用函数来解析 audio_policy_configuration.xml 配置文件,而这个 xml 文件中就包含着前述执行 dumpsys 命令后输出的内容:
file /system/etc/audio_policy_configuration.xml
<!-- Primary Audio HAL -->
<module name="primary" halVersion="3.0">
<attachedDevices>
<item>Earpiece</item>
<item>Speaker</item>
<item>Telephony Tx</item>
<item>Built-In Mic</item>
<item>Built-In Back Mic</item>
<item>Telephony Rx</item>
<item>Dgtl Dock Headset</item>
</attachedDevices>
<defaultOutputDevice>Speaker</defaultOutputDevice>
audio_policy将设备分为三类:听筒(EARPIECE)、耳机(HEADSET)、扬声器(SPEAKER)。
设备分类(getDeviceCategory):
Device | 功能 | Catalog |
AUDIO_DEVICE_OUT_EARPIECE | 听筒 | EARPIECE |
AUDIO_DEVICE_OUT_SPEAKER | 扬声器 | SPEAKER |
WIRED_HEADSET | 线控耳机,可以通过耳机控制远端播放、暂停、音量调节 | HEADSET |
WIRED_HEADPHONE | 普通耳机,只能听,不能操控播放 | |
BLUETOOTH_SCO | 蓝牙SCO,用于语音通话 | |
BLUETOOTH_SCO_HEADSET | 蓝牙SCO耳机 | |
BLUETOOTH_SCO_CARKIT | 蓝牙SCO车载 | SPEAKER |
BLUETOOTH_A2DP | 蓝牙高保真设备 | HEADSET |
BLUETOOTH_A2DP_HEADPHONES | 蓝牙高保真耳机 | |
BLUETOOTH_A2DP_SPEAKER | 蓝牙高保真扬声器 | SPEAKER |
AUX_DIGITAL | 辅助数字输出,HDMI | |
ANLG_DOCK_HEADSET | 模拟底座 | |
DGTL_DOCK_HEADSET | 数字底座 | |
USB_ACCESSORY | ||
USB_DEVICE | ||
REMOTE_SUBMIX | 远端播放 |