Android中dumpsys命令用法简单介绍
在Android手机上,通过使用adbshell命令可以进入android系统的shell,该shell除支持一些常用的标准命令之外,还支持一些和android系统相关的其他命令,这些命令可以打印出系统当前的状态信息。dumpsys就是这样一个命令。
使用adbshell进入命令行,敲入dumpsys,打印出的信息超级多,在我的nexus5机器上,输出多达67000行。首先从打印信息的开始部分看起:
Currentlyrunningservices: SurfaceFlinger accessibility account activity alarm android.security.keystore appops appwidget assetatlas audio backup battery batterypropreg batterystats bluetooth_manager clipboard commontime_management connectivity consumer_ir content country_detector cpuinfo dbinfo device_policy devicestoragemonitor diskstats display display.qservice dreams drm.drmManager dropbox entropy gfxinfo hardware input input_method iphonesubinfo isms location lock_settings media.audio_flinger media.audio_policy media.camera media.player media_router meminfo mount netpolicy netstats network_management nfc notification package permission phone power print procstats samplingprofiler scheduling_policy search sensorservice serial servicediscovery simphonebook sip statusbar telephony.registry textservices uimode updatelock usagestats usb user vibrator wallpaper wifi wifip2p window
由此可知,该命令打印出的是系统当前的所有正在运行的服务的信息。从中可以看到我们常见的一些服务。activity表示的是ActivityManagerService,用于管理应用程序的四大组件,appops表示的是AppOpsManagerService,用于管理和配置权限。window表示的是WindowManagerService,用于管理系统中的窗口,account表示的是AccountManagerService,用于管理系统中的账户信息。
在输出信息中,紧接着的是每个服务当前的详细状态信息,每个服务的状态信息一般都比较多,下面列举一个信息较少的服务信息:
------------------------------------------------------------------------------- DUMPOFSERVICEaccessibility: ACCESSIBILITYMANAGER(dumpsysaccessibility) Userstate[attributes:{id=0,currentUser=true,accessibilityEnabled=false,touchExplorationEnabled=false,displayMagnificationEnabled=false} services:{}] -------------------------------------------------------------------------------
每个服务信息之间使用横线间隔。
在开发过程中,使用dumpsys的最常用的用途是查看ActivityManagerService服务的信息。下面重点分析ActivityManagerService。该服务的信息从下面一行开始:
------------------------------------------------------------------------------- DUMPOFSERVICEactivity:
我们知道android应用程序的四大组件中有三个是由intent来驱动的。所以在ActivityManagerService的信息中,专门有一部分来记录当前待处理的Intent,称为pendingintent。格式如下:
ACTIVITYMANAGERPENDINGINTENTS(dumpsysactivityintents) *PendingIntentRecord{65ced5f0com.baidu.BaiduMapbroadcastIntent} uid=10084packageName=com.baidu.BaiduMaptype=broadcastIntentflags=0x0 requestIntent=act=com.baidu.locTest.LocationServer4.1.8 sent=truecanceled=false *PendingIntentRecord{66412b40com.android.phonebroadcastIntent} uid=1001packageName=com.android.phonetype=broadcastIntentflags=0x0 requestIntent=act=com.android.phone.ACTION_CALL_BACK_FROM_NOTIFICATIONdat=tel:153%201571%209213cmp=com.android.phone/.PhoneGlobals$NotificationBroadcastReceiver
直接在shell中键入dumpsysactivityintents,会直接得到这些信息。每个待处理的intent在ActivityManagerService内部使用一个PendingIntentRecord对象表示,并且会显示出所在应用的包名,并且会指定该intent是用来发送广播,启动activity或是启动service。
下面的信息是系统中的broadcastreceiver的状态信息,从下面一行开始:
------------------------------------------------------------------------------- ACTIVITYMANAGERBROADCASTSTATE(dumpsysactivitybroadcasts)
直接在shell中键入umpsysactivitybroadcasts,会直接得到这部分信息。
首先会列出系统中所有注册的广播接收者,格式如下:
RegisteredReceivers: *ReceiverList{660f2e40857com.android.systemui/10012/u-1remote:660f2ca0} app=857:com.android.systemui/u0a12pid=857uid=10012user=-1 Filter#0:BroadcastFilter{660f2ea0} Action:"android.intent.action.SHOW_BRIGHTNESS_DIALOG" *ReceiverList{66045cf03867com.meitu.meiyancamera:pushservice/10091/u0remote:65e756c8} app=3867:com.meitu.meiyancamera:pushservice/u0a91pid=3867uid=10091user=0 Filter#0:BroadcastFilter{66045d50} Action:"android.net.conn.CONNECTIVITY_CHANGE"
之后列出的是位于前台的历史广播,格式如下:
Historicalbroadcasts[foreground]: HistoricalBroadcastforeground#0: BroadcastRecord{65610478u-1android.intent.action.TIME_TICK}touser-1 Intent{act=android.intent.action.TIME_TICKflg=0x50000014(hasextras)} extras:Bundle[{android.intent.extra.ALARM_COUNT=1}] caller=androidnullpid=-1uid=1000 dispatchClockTime=TueOct0710:53:00GMT+08:002014 dispatchTime=-14s534msfinishTime=-14s436ms resultTo=nullresultCode=0resultData=null resultAbort=falseordered=truesticky=falseinitialSticky=false nextReceiver=10receiver=null Receiver#0:BroadcastFilter{6568af00u0ReceiverList{65692db8748system/1000/u0local:65b2a730}} Receiver#1:BroadcastFilter{660c8768u0ReceiverList{660c81a8857com.android.systemui/10012/u0remote:660c78c0}} Receiver#2:BroadcastFilter{65d2d230u0ReceiverList{65d2cb20857com.android.systemui/10012/u0remote:65a8bb70}} Receiver#3:BroadcastFilter{65f042e8u0ReceiverList{65f04d90857com.android.systemui/10012/u0remote:65f9f2c0}} Receiver#4:BroadcastFilter{65a9d5f0u0ReceiverList{65affbc8857com.android.systemui/10012/u0remote:65b41d50}} Receiver#5:BroadcastFilter{6682be08u0ReceiverList{6682bda8857com.android.systemui/10012/u0remote:665c2478}} Receiver#6:BroadcastFilter{667a6c48u0ReceiverList{6671f128857com.android.systemui/10012/u0remote:662c4048}} Receiver#7:BroadcastFilter{66901318u0ReceiverList{6694987011260com.youku.phone:MMS/10080/u0remote:6695e528}} Receiver#8:BroadcastFilter{663a4b60u0ReceiverList{663a5148857com.android.systemui/10012/u0remote:663c3530}} Receiver#9:BroadcastFilter{6633df98u0ReceiverList{6633f628857com.android.systemui/10012/u0remote:66370860}}
然后是位于后台的历史广播,格式如下:
Historicalbroadcasts[background]: HistoricalBroadcastbackground#0: BroadcastRecord{66430db0u0cn.etouch.ecalendar_CN.ETOUCH.ECALENDAR.WEATHER_HAS_UPDATE}touser0 Intent{act=cn.etouch.ecalendar_CN.ETOUCH.ECALENDAR.WEATHER_HAS_UPDATEflg=0x10(hasextras)} extras:Bundle[mParcelledData.dataSize=44] caller=cn.etouch.ecalendar3036:cn.etouch.ecalendar:remote/u0a140pid=3036uid=10140 dispatchClockTime=TueOct0710:53:00GMT+08:002014 dispatchTime=-14s475msfinishTime=-14s400ms resultTo=nullresultCode=0resultData=null nextReceiver=5receiver=null Receiver#0:ResolveInfo{66335e40cn.etouch.ecalendar/.widget.myWidget_weatherp=1000m=0x108000} priority=1000preferredOrder=0match=0x108000specificIndex=-1isDefault=false ActivityInfo: name=cn.etouch.ecalendar.widget.myWidget_weather packageName=cn.etouch.ecalendar labelRes=0x7f06016cnonLocalizedLabel=nullicon=0x0 enabled=trueexported=trueprocessName=cn.etouch.ecalendar taskAffinity=cn.etouch.ecalendartargetActivity=null ApplicationInfo: packageName=cn.etouch.ecalendar labelRes=0x7f060042nonLocalizedLabel=nullicon=0x7f0200c5 className=cn.etouch.ecalendar.common.ApplicationManager processName=cn.etouch.ecalendar taskAffinity=cn.etouch.ecalendar uid=10140flags=0x88be44theme=0x7f0a0029 requiresSmallestWidthDp=0compatibleWidthLimitDp=0largestWidthLimitDp=0 sourceDir=/data/app/cn.etouch.ecalendar-1.apk seinfo=default dataDir=/data/data/cn.etouch.ecalendar enabled=truetargetSdkVersion=11 supportsRtl=false
下面是provider相关的信息,格式如下:
------------------------------------------------------------------------------- ACTIVITYMANAGERCONTENTPROVIDERS(dumpsysactivityproviders) Publishedsingle-usercontentproviders(byclass): *ContentProviderRecord{65cd5f60u0com.redbend.vdmc/com.redbend.others.NodeProvider} package=com.redbend.vdmcprocess=com.redbend.vdmc proc=ProcessRecord{65d540d81018:com.redbend.vdmc/1001} uid=1001provider=android.content.ContentProviderProxy@658b6690 singleton=true authority=com.lge.node *ContentProviderRecord{65d1b150u0com.android.phone/.IccProvider} package=com.android.phoneprocess=com.android.phone proc=ProcessRecord{65fe24881000:com.android.phone/1001} uid=1001provider=android.content.ContentProviderProxy@660cbf38 singleton=true authority=icc isSyncable=falsemultiprocess=trueinitOrder=0
直接在命令行键入dumpsysactivityproviders,可以直接得到provider相关的信息。由输出信息可知,在AtivityManagerService中,一个provider组件使用一个ContentProviderRecord对象表示。
服务(Service)相关的信息如下:
------------------------------------------------------------------------------- ACTIVITYMANAGERSERVICES(dumpsysactivityservices) User0activeservices: *ServiceRecord{660da0f0u0com.android.bluetooth/.hid.HidService} intent={act=android.bluetooth.IBluetoothInputDevicecmp=com.android.bluetooth/.hid.HidService} packageName=com.android.bluetooth processName=com.android.bluetooth baseDir=/system/app/Bluetooth.apk dataDir=/data/data/com.android.bluetooth app=null createTime=-1d16h27m16s523msstartingBgTimeout=-- lastActivity=-17h20m54s385msrestartTime=--createdFromFg=false Bindings: *IntentBindRecord{660da3e0}: intent={act=android.bluetooth.IBluetoothInputDevicecmp=com.android.bluetooth/.hid.HidService} binder=null requested=falsereceived=falsehasBound=falsedoRebind=false
在shell中直接键入dumpsysactivityservices命令,可以直接得到Service信息。
Activity相关的信息格式如下:
------------------------------------------------------------------------------- ACTIVITYMANAGERACTIVITIES(dumpsysactivityactivities) Stack#0: Taskid#1 *TaskRecord{65cc6860#1A=com.google.android.googlequicksearchboxU=0sz=1} numActivities=1rootWasReset=trueuserId=0mTaskType=1numFullscreen=1mOnTopOfHome=true affinity=com.google.android.googlequicksearchbox intent={act=android.intent.action.MAINcat=[android.intent.category.HOME]flg=0x10600000cmp=com.google.android.googlequicksearchbox/com.google.android.launcher.GEL} realActivity=com.google.android.googlequicksearchbox/com.google.android.launcher.GEL Activities=[ActivityRecord{66020ee8u0com.google.android.googlequicksearchbox/com.google.android.launcher.GELt1}] askedCompatMode=false lastThumbnail=android.graphics.Bitmap@6653bf90lastDescription=null lastActiveTime=144235207(inactivefor1424s) *Hist#0:ActivityRecord{66020ee8u0com.google.android.googlequicksearchbox/com.google.android.launcher.GELt1} packageName=com.google.android.googlequicksearchboxprocessName=com.google.android.googlequicksearchbox launchedFromUid=0launchedFromPackage=nulluserId=0 app=ProcessRecord{66105ac81058:com.google.android.googlequicksearchbox/u0a19} Intent{act=android.intent.action.MAINcat=[android.intent.category.HOME]flg=0x10000000cmp=com.google.android.googlequicksearchbox/com.google.android.launcher.GEL} frontOfTask=truetask=TaskRecord{65cc6860#1A=com.google.android.googlequicksearchboxU=0sz=1} taskAffinity=com.google.android.googlequicksearchbox realActivity=com.google.android.googlequicksearchbox/com.google.android.launcher.GEL baseDir=/system/priv-app/Velvet.apk dataDir=/data/user/0/com.google.android.googlequicksearchbox stateNotNeeded=truecomponentSpecified=falsemActivityType=1 compat={480dpi}labelRes=0x7f0a04c5icon=0x7f030002theme=0x7f0e000d config={1.0460mcc1mnczh_CNldltrsw360dpw360dph567dp480dpinrmlportfinger-keyb/v/h-nav/hs.11} launchFailed=falselaunchCount=0lastLaunchTime=-17h20m56s529ms haveState=trueicicle=Bundle[mParcelledData.dataSize=12720] state=STOPPEDstopped=truedelayedResume=falsefinishing=false keysPaused=falseinHistory=truevisible=falsesleeping=trueidle=true fullscreen=truenoDisplay=falseimmersive=falselaunchMode=2 frozenBeforeDestroy=falsethumbnailNeeded=falseforceNewConfig=false mActivityType=HOME_ACTIVITY_TYPE thumbHolder:65cc6860bm=android.graphics.Bitmap@6653bf90desc=null waitingVisible=falsenowVisible=falselastVisibleTime=-21m53s598ms Taskid#24 *TaskRecord{667de460#24A=com.android.systemuiU=0sz=1} numActivities=1rootWasReset=falseuserId=0mTaskType=2numFullscreen=1mOnTopOfHome=true affinity=com.android.systemui intent={act=com.android.systemui.recent.action.TOGGLE_RECENTSflg=0x10c00000cmp=com.android.systemui/.recent.RecentsActivity} realActivity=com.android.systemui/.recent.RecentsActivity Activities=[ActivityRecord{6561e970u0com.android.systemui/.recent.RecentsActivityt24}] askedCompatMode=false lastThumbnail=android.graphics.Bitmap@662b3118lastDescription=null lastActiveTime=87755110(inactivefor57904s) *Hist#0:ActivityRecord{6561e970u0com.android.systemui/.recent.RecentsActivityt24} packageName=com.android.systemuiprocessName=com.android.systemui launchedFromUid=10012launchedFromPackage=com.android.systemuiuserId=0 app=ProcessRecord{6602d698857:com.android.systemui/u0a12} Intent{act=com.android.systemui.recent.action.TOGGLE_RECENTSflg=0x10800000cmp=com.android.systemui/.recent.RecentsActivity} frontOfTask=truetask=TaskRecord{667de460#24A=com.android.systemuiU=0sz=1} taskAffinity=com.android.systemui realActivity=com.android.systemui/.recent.RecentsActivity baseDir=/system/priv-app/SystemUI.apk dataDir=/data/data/com.android.systemui stateNotNeeded=falsecomponentSpecified=truemActivityType=2 compat={480dpi}labelRes=0x7f0a0080icon=0x10804a5theme=0x7f0e0000 config={1.0460mcc1mnczh_CNldltrsw360dpw360dph567dp480dpinrmlportfinger-keyb/v/h-nav/hs.9} launchFailed=falselaunchCount=0lastLaunchTime=-9h59m21s658ms haveState=trueicicle=Bundle[mParcelledData.dataSize=44] state=STOPPEDstopped=truedelayedResume=falsefinishing=false keysPaused=falseinHistory=truevisible=falsesleeping=trueidle=true fullscreen=truenoDisplay=falseimmersive=falselaunchMode=3 frozenBeforeDestroy=falsethumbnailNeeded=falseforceNewConfig=false mActivityType=RECENTS_ACTIVITY_TYPE thumbHolder:667de460bm=android.graphics.Bitmap@662b3118desc=null waitingVisible=falsenowVisible=falselastVisibleTime=-7h8m31s600ms Runningactivities(mostrecentfirst): TaskRecord{65cc6860#1A=com.google.android.googlequicksearchboxU=0sz=1} Run#1:ActivityRecord{66020ee8u0com.google.android.googlequicksearchbox/com.google.android.launcher.GELt1} TaskRecord{667de460#24A=com.android.systemuiU=0sz=1} Run#0:ActivityRecord{6561e970u0com.android.systemui/.recent.RecentsActivityt24} mLastPausedActivity:ActivityRecord{66020ee8u0com.google.android.googlequicksearchbox/com.google.android.launcher.GELt1}
在shell中直接键入dumpsysactivityactivities,可以直接得到activity的相关信息。
和其他组件相比,Activity的管理比较特殊。Activity是以栈的形式管理的,每个栈中存在若干个任务(task),每个任务又由若干个Activity组成。
上面简单介绍了ActivityManagerService中的四大组件相关的信息。关于其他服务中的信息,由于信息量太大,无法一一介绍,请读者自行查看。
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!