it编程 > 前端脚本 > Powershell

Android adb shell dumpsys audio 信息查看分析详解

260人参与 2024-11-27 Powershell

android adb shell dumpsys audio 信息查看分析详解

一、前言

android 如果要分析当前设备的声音通道相关日志,
仅仅看audioservice的日志是看不到啥日志的,但是看整个audio关键字的日志又太多太乱了,
所以可以看一下系统提供的一个调试指令dumpsys audio 返回的信息进行定位分析,
里面主要包含了audioservice启动时间,当前设备的音频流指向,音频流的声音大小,音频外设的连接情况,音频播放记录,音频外设连接断开记录等等信息。

不同的android 系统使用 dumpsys audio 命令返回的日志信息可能会有差异,
因为打印返回的信息就是audioservice.java里面打印显示的,
本文的示例讲解是以mtk方案的android14日志信息进行讲解。
网上基本没有对dumpsys audio 日志信息进行分析的,有兴趣的可以收藏查看。

二、分析

1、简单示例和主要内容

本示例日志是设备连接蓝牙耳机后的dumpsys audio情况日志信息:

# dumpsys audio
[18:57:20]events log: audio services lifecycle
[18:57:20]11-22 18:54:07:681 audioservice() //(1)audioservice 启动时间,大概可以推测出开机时间
[18:57:20]mediafocuscontrol dump time: 6:57:22 pm //(2)执行dumpsys audio的时间
//(3)dumpsys audio最重要的内容,设备支持声音流情况
[18:57:20]stream volumes (device: index)
[18:57:20]- stream_voice_call (aliased to: stream_music):
。。。
[18:57:20]- stream_system (aliased to: stream_music):
。。。
[18:57:20]- stream_ring (aliased to: stream_music):
。。
//(4)基本是音频播放的情况,上面其他声音通道都是注释了以这个为标准
[18:57:20]- stream_music: 
[18:57:20]   muted: false
[18:57:20]   muted internally: false
[18:57:20]   min: 0  //声音范围
[18:57:20]   max: 15
[18:57:20]   streamvolume:7 //当前声音大小
[18:57:20]   current: 2 (speaker): 7, 80 (bt_a2dp): 7, 400 (hdmi): 7, 40000000 (default): 7
[18:57:20]   devices: bt_a2dp(80) //当前声音通道,蓝牙
[18:57:20]   volume group: music
[18:57:20]
[18:57:20]- stream_alarm (aliased to: stream_music):
[18:57:20]   muted: false
[18:57:20]   muted internally: false
[18:57:20]   min: 1
[18:57:20]   max: 7
[18:57:20]   streamvolume:4
[18:57:20]   current: 2 (speaker): 4, 80 (bt_a2dp): 4, 400 (hdmi): 4, 40000000 (default): 4
[18:57:20]   devices: speaker(2), bt_a2dp(80)
[18:57:20]   volume group: alarm
 //其他声音通道比较少实用,比如铃声,通知等情况
[18:57:20]- stream_notification (aliased to: stream_music):
[18:57:20]- stream_bluetooth_sco:
[18:57:20]- stream_system_enforced (aliased to: stream_music):
[18:57:20]- stream_dtmf (aliased to: stream_music):
[18:57:20]- stream_tts (aliased to: stream_music):
[18:57:20]- stream_accessibility (aliased to: stream_music):
[18:57:20]- stream_assistant (aliased to: stream_music):
。。。
//volume groups 不知道是干啥的,类型也是挺多的。
[18:57:20]volume groups (device: index)
[18:57:20]- volume group voice_call:
[18:57:20]   muted: false
[18:57:20]   min: 1
[18:57:20]   max: 7
[18:57:20]   current: 2 (speaker): 4, 80 (bt_a2dp): 7, 40000000 (default): 4
[18:57:20]   devices: bt_a2dp
[18:57:20]   streams: stream_voice_call 
[18:57:20]- volume group system:
[18:57:20]   muted: false
[18:57:20]   min: 0
[18:57:20]   max: 100
[18:57:20]   current: 2 (speaker): 47, 80 (bt_a2dp): 7, 40000000 (default): 47
[18:57:20]   devices: bt_a2dp
[18:57:20]   streams: stream_system 
[18:57:20]- volume group ring:
[18:57:20]- volume group music:
[18:57:20]- volume group alarm:
[18:57:20]- volume group alarm:
[18:57:20]- volume group bluetooth_sco:
[18:57:20]- volume group enforced_audible:
[18:57:20]- volume group dtmf:
[18:57:20]- volume group accessibility:
[18:57:20]- volume group assistant:
[18:57:20]- volume group audio_stream_rerouting:
[18:57:20]- volume group audio_stream_patch:
volume group类型的 streams属性值都是指向上面的stream volumes类型的。
[18:57:20]audio routes:
[18:57:20]  mmaintype=0x0
//(5)当前连接蓝牙的设备名称,如果未连接蓝牙为null
[18:57:20]  mbluetoothname=xiaodu portable speaker  
//(6)音频播放情况日志
[19:00:32]events log: playback activity as reported through playerbase
//开机铃声
[19:00:32]11-22 18:54:09:789 new player piid:71 uid/pid:1000/745 type:android.media.soundpool attr:audioattributes: usage=usage_assistance_sonification content=content_type_sonification flags=0x800 tags= bundle=null session:0
[19:00:33]11-22 18:54:10:837 new player piid:79 uid/pid:1000/1069 type:android.media.soundpool attr:audioattributes: usage=usage_media content=content_type_unknown flags=0x800 tags= bundle=null session:0
。。。
//音频文件播放+停止+播放+停止操作的日志
[19:00:33]11-22 18:58:37:956 player piid:103 event:started
[19:00:33]11-22 18:58:38:076 player piid:103 format update:formatinfo{isspatialized=false, channelmask=0x3, samplerate=44100}
[19:00:33]11-22 18:58:38:175 player piid:103 event:device updated deviceid:5
[19:00:33]11-22 18:58:38:190 player piid:103 event:device updated deviceid:5
[19:00:33]11-22 18:58:42:920 player piid:103 event:paused
[19:00:33]11-22 19:00:24:155 player piid:103 event:started
[19:00:33]11-22 19:00:24:169 player piid:103 format update:formatinfo{isspatialized=false, channelmask=0x3, samplerate=44100}
[19:00:33]11-22 19:00:24:204 player piid:103 event:device updated deviceid:5
[19:00:33]11-22 19:00:29:492 player piid:103 event:paused
//(7)当前连接的设备,这里是连接蓝牙耳机
[18:57:21]  connected devices:
[18:57:21]    [deviceinfo: type:0x80 (bt_a2dp) name:xiaodu portable speaker  addr:48:f3:f3:ed:78:ad codec: 1f000000 sensoruuid: 00000000-0000-0000-4254-48f3f3ed78ad disabled modes: {}]
[18:57:21]
//(8)如果是连接的usb有线耳机,另外一份日志拼过来的
[15:01:34]  connected devices:
[15:01:34]    [deviceinfo: type:0x4000000 (usb_headset) name:usb-audio - usb speaker phone addr:card=4;device=0 codec: 0 sensoruuid: null disabled modes: {}]
//(9)连接蓝牙耳机、有线耳机等外设音箱的日志
[18:57:21]events log: wired/a2dp/hearing aid device connection
。。。
[18:57:21]11-22 18:57:04:640 bt profile service: connecting hearing_aid profile
[18:57:21]11-22 18:57:04:666 bt profile service: connecting a2dp profile
[18:57:21]11-22 18:57:09:875 msg: onbluetoothactivedevicechange  state=2 addr=48:f3:f3:ed:78:ad prof=2 supprnoisy=true src=audioservice
[18:57:21]11-22 18:57:09:885 bt connected: addr=48:f3:f3:ed:78:ad profile=2 state=2 codec=audio_format_sbc
[18:57:21]11-22 18:57:10:074 a2dp device addr=48:f3:f3:ed:78:ad now available
//上面可以看到蓝牙连接的时间记录
//(10)声音通道占用的日志
[18:57:21]events log: force use (logged before setforceuse() is executed)
[18:57:21]11-22 18:54:07:774 setforceuse(for_dock, force_digital_dock) due to readdockaudiosettings
。。。
[18:57:21]11-22 18:54:08:521 setforceuse(for_vibrate_ringing, force_none) due to muteringermodestreams() from u/pid:1000/745
。。。
//从最后一行日志看,最后是设置为蓝牙通道的
[18:57:21]11-22 18:57:09:897 setforceuse(for_media, force_none) due to setbluetootha2dpon(true) from u/pid:1000/745 src:onsetbtactivedevice
//(11)声音变化和通道情况
[18:57:21]events log: volume changes (logged when command received by audioservice)
[18:57:21]11-22 18:57:09:885 volumestreamstate.muteinternally(stream:stream_music, muted)
[18:57:21]11-22 18:57:10:053 setdevicevolumebehavior: dev:bt_a2dp addr:48:f3:f3:ed:78:ad behavior:device_volume_behavior_variable pack:com.android.bluetooth
[18:57:21]11-22 18:57:10:156 avrcpsupportsabsolutevolume addr=48:f3:f3:ed:78:ad support=false
[18:57:21]11-22 18:57:10:323 volumestreamstate.muteinternally(stream:stream_music, unmuted)
//从上面日志看是蓝牙声音通道,stream_music 流
//(12)audiosystemadapter 不清楚是啥日志
[18:57:21]audiosystemadapter:
[18:57:21] last cache clear time: 11-22 18:57:10:110
[18:57:21] mdevicesforattrcache:
[18:57:21]        audioattributes: usage=usage_assistance_sonification content=content_type_unknown flags=0x800 tags= bundle=null forvolume: true stream: stream_system(1)
[18:57:21]                audiodeviceattributes: role:output type:bt_a2dp addr:48:f3:f3:ed:78:ad name: profiles:[] descriptors:[]
[18:57:21]        audioattributes: usage=usage_assistance_accessibility content=content_type_unknown flags=0x800 tags= bundle=null forvolume: true stream: stream_accessibility(10)
[18:57:21]                audiodeviceattributes: role:output type:bt_a2dp addr:48:f3:f3:ed:78:ad name: profiles:[] descriptors:[]
[18:57:21]        audioattributes: usage=usage_unknown content=content_type_unknown flags=0x801 tags= bundle=null forvolume: true stream: stream_system(1)
[18:57:21]                audiodeviceattributes: role:output type:speaker addr: name: profiles:[] descriptors:[]
[18:57:21]                audiodeviceattributes: role:output type:bt_a2dp addr:48:f3:f3:ed:78:ad name: profiles:[] descriptors:[]
。。。
百度查询到:audiosystemadapter可能会包含如下功能:
设备检测:检查设备是否支持特定音频特性(如蓝牙、耳机插孔等)。
音频路径管理:动态选择音频流的最佳路径,如扬声器、耳机或蓝牙设备。
音效处理:应用特定的音效效果,如均衡器设置或环绕声模式。
但是从上面日志看不出这些信息,可能信息比较隐蔽。

从上面的示例的主要日志信息,可以看到dumpsys主要包含当前音频流和外设的信息。

2、dumpsys audio日志的主要格式内容

# dumpsys audio //(1)执行命令
[18:57:20]events log: audio services lifecycle
//(2)audioservice 启动时间,大概可以推测出开机时间
[18:57:20]11-22 18:54:07:681 audioservice() 
//(3)dumpsys audio最重要的内容,设备支持声音流情况,正常看stream_music
[18:57:20]stream volumes (device: index)
[18:57:20]- stream_music: 
[18:57:20]   muted: false
[18:57:20]   muted internally: false
[18:57:20]   min: 0  //声音范围
[18:57:20]   max: 15
[18:57:20]   streamvolume:7 //当前声音大小
[18:57:20]   current: 2 (speaker): 7, 80 (bt_a2dp): 7, 400 (hdmi): 7, 40000000 (default): 7
[18:57:20]   devices: bt_a2dp(80) //当前声音通道,蓝牙
[18:57:20]   volume group: music
[18:57:20]
//(4)音频播放情况日志
[19:00:32]events log: playback activity as reported through
//(5)音频外设连接情况
[18:57:21]  connected devices:
//(6)声音通道占用的日志
[18:57:21]events log: force use (logged before setforceuse() is executed)
//(7)音频外设连接断开日志
[18:57:21]events log: wired/a2dp/hearing aid device connection
//(8)声音变化和通道情况
[18:57:21]events log: volume changes (logged when command received by audioservice)
//(9)audiosystemadapter 音频管理信息

这里只是根据一个实际的示例日志进行的讲解,
上面的讲解不一定完全正确和全面,仅供参考吧。

三、其他

1、dumpsys audio小结

dumpsys audio 主要能看到

当前设备音频流的指向情况,stream volumes (device: index)
当前系统音频外设连接情况,connected devices
声音通道占用情况记录,events log: force use
音频外设连接断开日志,events log: wired/a2dp/hearing aid device connection

dumpsys audio 最主要就是上面这几个声音相关信息。
更多的要看具体情况的日志了。

2、dumpsys audio 的源码

dumpsys audio 返回的打印信息,其实是java代码上打印的,具体源码如下:

framework/base/services/core/java/com/android/server/audio/audioservice.java

    @override
    protected void dump(filedescriptor fd, printwriter pw, string[] args) {
        if (!dumputils.checkdumppermission(mcontext, tag, pw)) return;
        slifecyclelogger.dump(pw);
        if (maudiohandler != null) {
            pw.println("\nmessage handler (watch for unhandled messages):");
            maudiohandler.dump(new printwriterprinter(pw), "  ");
        } else {
            pw.println("\nmessage handler is null");
        }
        ...
        pw.println("\naudio routes:");
        pw.print("  mmaintype=0x"); pw.println(integer.tohexstring(
                mdevicebroker.getcuraudioroutes().maintype));
        pw.print("  mbluetoothname="); pw.println(mdevicebroker.getcuraudioroutes().bluetoothname);
        ...
        pw.println("\n");
        pw.println("\nspatial audio:");
        pw.println("mhasspatializereffect:" + mhasspatializereffect + " (effect present)");
        pw.println("isspatializerenabled:" + isspatializerenabled() + " (routing dependent)");
        mspatializerhelper.dump(pw);
        sspatiallogger.dump(pw);
        maudiosystem.dump(pw);
    }

可以看到 dumpsys audio 命令返回的数据,都是在 audioservice.java 里面返回打印的;
audio相关数据很多,有兴趣的可以自己分析研究看看;
如果想要自定义添加一下额外的打印,可以在源码里面添加。

3、使用谷歌文件管理器 googlefile 播放音频文件日志:

logct | grep -e "audioservice|audiotrack"
//打开文件管理器后首次播放:
11-23 10:22:26.542   798  1614 i mediasessionstack: addsession to bottom of stack | record: com.google.android.apps.nbu.files/audioservice (userid=0)
11-23 10:22:26.938   798  1614 i audioservice.fadeoutmanager: unfadeoutuid() uid:10074
11-23 10:22:27.148   798   937 i mediasessionstack: onplaybackstatechanged - pushing session to top | record: com.google.android.apps.nbu.files/audioservice (userid=0)
11-23 10:22:27.635   798  1457 i activitymanager: background started fgs: allowed [callingpackage: com.google.android.apps.nbu.files; callinguid: 10074; uidstate: top ; uidbfsl: [bfsl]; intent: intent { cmp=com.google.android.apps.nbu.files/.mediaconsumption.audio.service.audioservice (has extras) }; code:proc_state_top; tempallowlistreason:<null>; targetsdkversion:34; callertargetsdkversion:34; startforegroundcount:0; bindfrompackage:null: isbindservice:true]
11-23 10:22:27.666   798   798 d mediasessionservice: media button session is changed to com.google.android.apps.nbu.files/audioservice (userid=0)
//停止后,再次点击播放
11-23 10:22:58.294  7108  7259 d audiotrack: gettimestamp_l(16): device stall time corrected using current time 2328289907108
11-23 10:22:58.339   798  1460 i mediasessionstack: onplaybackstatechanged - pushing session to top | record: com.google.android.apps.nbu.files/audioservice (userid=0)
11-23 10:22:58.344  7108  7259 d audiotrack: gettimestamp_l(16): stale timestamp time corrected, currenttimenanos: 2318205649000 < limitns: 2328189081941 < mstartns: 2328287081941
11-23 10:22:58.344  7108  7259 w audiotrack: gettimestamp_l(16): retrograde timestamp time corrected, 2328189081941 < 2328329633858

能看到一点日志,比如audiotrack播放时间,但是没有太多日志,比如用什么设备播放、播放音量等等信息。
所以dumpsys audio 还是可以看到当时比较有用的一些日志的。

4、android 的声音通道类型

其中streamtype定义如下:

stream_alarm:闹钟
stream_dtmf:双音多频,拨号键的声音
stream_music:音乐
stream_notification:通知
stream_ring:铃声
stream_system:系统
stream_voice_call:通话

android大概支持上面的声音通道类型,主要使用的是外放的 stream_music。

5、android–耳机插拔检测(framework篇)

上层到底层的一顿讲解

到此这篇关于android adb shell dumpsys audio 信息查看分析详解的文章就介绍到这了,更多相关android adb shell dumpsys audio 信息查看内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

您想发表意见!!点此发布评论

推荐阅读

Ubuntu如何搭建FTP服务器

11-18

Linux服务器升级GLIBC失败导致shell命令不可用的情况怎么处理

11-18

shell脚本批量执行ping和telnet测试网络方式

12-12

查看Windows监听端口占用的两种命令: Netstat或Powershell用法

11-05

微软 AI Shell 实测! Win11 命令行效率利器

12-30

接入混元AI大模型! 努比亚Watch GT智能手表发布: 599元

01-04

猜你喜欢

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论