一、概述 adb shell dumpsys 在Android开发中经常要用到,平时都是零碎的积累,用到什么的时候就 记录下来,最近看了一些资料,发现可以汇总所有的命令,当带某个参数的时候,就可以查看具体 的信息, 本篇文章
adb shell dumpsys 在Android开发中经常要用到,平时都是零碎的积累,用到什么的时候就
记录下来,最近看了一些资料,发现可以汇总所有的命令,当带某个参数的时候,就可以查看具体
的信息, 本篇文章中还讲解了如何去找命令的源码和源头,供参考!
列出系统所有支持的dumpsys命令的服务
adb shell dumpsys | grep -i "DUMP OF SERVICE"
支持dumpsys命令的服务
adb shell service list
Found 203 services:0DockObserver: []1SurfaceFlinger: [android.ui.ISurfaceComposer]2VideoCallEngineService: []3accessibility: [android.view.accessibility.IAccessibilityManager]4account: [android.accounts.IAccountManager]5activity: [android.app.IActivityManager]6activity_task: [android.app.IActivityTaskManager]7adb: [android.debug.IAdbManager]8alarm: [android.app.IAlarmManager]9android.hardware.light.ILights/default: []10android.hardware.power.IPower/default: []11android.hardware.rebootescrow.IRebootEscrow/default: []12android.hardware.vibrator.IVibrator/default: []13android.os.UpdateEngineService: []14android.security.identity: [android.security.identity.ICredentialStoreFactory]15android.security.keystore: [android.security.keystore.IKeystoreService]16android.service.gatekeeper.IGateKeeperService: []17app_binding: []18app_integrity: [android.content.integrity.IAppIntegrityManager]19appops: [com.android.internal.app.IAppOpsService]20appwidget: [com.android.internal.appwidget.IAppWidgetService]21audio: [android.media.IAudiOService]22auth: [android.hardware.biometrics.IAuthService]23autofill: [android.view.autofill.IAutoFillManager]24backup: [android.app.backup.IBackupManager]25battery: []26batteryproperties: [android.os.IBatteryPropertiesReGIStrar]27batterystats: [com.android.internal.app.IBatteryStats]28binder_calls_stats: []29biometric: [android.hardware.biometrics.IBiometricService]30blob_store: [android.app.blob.IBlobStoreManager]31bluetooth_manager: [android.bluetooth.IBluetoothManager]32broadcastradio: [android.hardware.radio.IRadioService]33bugreport: [android.os.IDumpstate]34cacheinfo: []35carrier_config: [com.android.internal.telephony.ICarrierConfigLoader]36clipboard: [android.content.IClipboard]37color_display: [android.hardware.display.IColorDisplayManager]38compaNIOndevice: [android.companion.ICompanionDeviceManager]39connectivity: [android.net.IConnectivityManager]40connmetrics: [android.net.IIpConnectivityMetrics]41consumer_ir: [android.hardware.IConsumerIrService]42content: [android.content.IContentService]43country_detector: [android.location.ICountryDetector]44cpuinfo: []45crossprofileapps: [android.content.pm.ICrossProfileApps]46dataloader_manager: [android.content.pm.IDataLoaderManager]47dbinfo: []48device_config: []49device_identifiers: [android.os.IDeviceIdentifiersPolicyService]50device_policy: [android.app.admin.IDevicePolicyManager]51deviceidle: [android.os.IDeviceIdleController]52devicestoragemonitor: []53Diskstats: []54display: [android.hardware.display.IDisplayManager]55dnsresolver: []56dreams: [android.service.dreams.IDreamManager]57drm.drmManager: [drm.IDrmManagerService]58dropbox: [com.android.internal.os.IDropBoxManagerService]59dynamic_system: [android.os.image.IDynamicSystemService]60emergency_affordance: []61ethernet: [android.net.IEthernetManager]62external_vibrator_service: [android.os.IExternalVibratorService]63face: [android.hardware.face.IFaceService]64file_integrity: [android.security.IFileIntegrityService]65fingerprint: [android.hardware.fingerprint.IFingerprintService]66gfxinfo: []67gpu: [android.graphicsenv.IGpuService]68graphiCSStats: [android.view.IGraphicsStats]69hardware_properties: [android.os.IHardwarePropertiesManager]70imms: [com.android.internal.telephony.IMms]71ims_doze_manager: [com.android.ims.internal.IImsDozeManager]72ims_ex: [com.android.ims.internal.IImsServiceEx]73ims_ut_ex: [com.android.ims.internal.IImsUtEx]74incident: []75incidentcompanion: [android.os.IIncidentCompanion]76incremental: [android.os.incremental.IIncrementalService]77input: [android.hardware.input.IInputManager]78input_method: [com.android.internal.view.IInputMethodManager]79inputflinger: [android.input.IInputFlinger]80installd: []81ions: [com.android.internal.telephony.IOns]82ions_ex: [com.android.unisoc.telephony.aidl.IOperatorNameHandler]83iphonesubinfo: [com.android.internal.telephony.IPhoneSubInfo]84ipsec: [android.net.IIpSecService]85irit: [com.android.unisoc.telephony.aidl.IRadioInteractor]86isms: [com.android.internal.telephony.ISms]87ismsEx: [com.android.internal.telephony.ISmsEx]88isub: [com.android.internal.telephony.ISub]89jobscheduler: [android.app.job.IJobScheduler]90launcherapps: [android.content.pm.ILauncherApps]91ledsrv: [android.os.ILedService]92lights: [android.hardware.lights.ILightsManager]93linkturbonative: []94location: [android.location.ILocationManager]95lock_settings: [com.android.internal.widget.ILockSettings]96looper_stats: []97manager: [android.os.IServiceManager]98media.audio_flinger: [android.media.IAudioFlinger]99media.audio_policy: [android.media.IAudioPolicyService]100media.camera: [android.hardware.ICameraService]101media.camera.proxy: [android.hardware.ICameraServiceProxy]102media.extractor: [android.IMediaExtractorService]103media.metrics: [android.media.IMediaMetricsService]104media.player: [android.media.IMediaPlayerService]105media.resource_manager: [android.media.IResourceManagerService]106media_projection: [android.media.projection.IMediaProjectionManager]107media_resource_monitor: [android.media.IMediaResourceMonitor]108media_router: [android.media.IMediaRouterService]109media_session: [android.media.session.ISessionManager]110meminfo: []111midi: [android.media.midi.IMidiManager]112mount: [android.os.storage.IStorageManager]113netd: []114netd_listener: [android.net.metrics.INetdEventListener]115netpolicy: [android.net.INetworkPolicyManager]116netstats: [android.net.INetworkStatsService]117network_adapter: [android.os.INetworkAdapterService]118network_management: [android.os.INetworkManagementService]119network_score: [android.net.INetworkScoreService]120network_stack: [android.net.INetworkStackConnector]121network_time_update_service: []122network_watchlist: [com.android.internal.net.INetworkWatchlistManager]123notification: [android.app.INotificationManager]124oem_lock: [android.service.oemlock.IOemLockService]125otadexopt: [android.content.pm.IOtaDexopt]126overlay: [android.content.om.IOverlayManager]127package: [android.content.pm.IPackageManager]128package_native: [android.content.pm.IPackageManagerNative]129perfORMance_fw: [android.app.IPerformanceManagerInternal]130performancemanager: []131permission: [android.os.IPermissionController]132permissionmgr: [android.permission.IPermissionManager]133persistent_data_block: [android.service.persistentdata.IPersistentDataBlockService]134phone: [com.android.internal.telephony.ITelephony]135pinner: []136platform_compat: [com.android.internal.compat.IPlatformCompat]137platform_compat_native: [com.android.internal.compat.IPlatformCompatNative]138power: [android.os.IPowerManager]139power_ex: [android.os.sprdpower.IPowerManagerEx]140powerguru: [android.app.sprdpower.IPowerGuru]141print: [android.print.IPrintManager]142processinfo: [android.os.IProcessInfoService]143procstats: [com.android.internal.app.procstats.IProcessStats]144recovery: [android.os.IRecoverySystem]145restrictions: [android.content.IRestrictionsManager]146role: [android.app.role.IRoleManager]147rollback: [android.content.rollback.IRollbackManager]148runtime: []149scheduling_policy: [android.os.ISchedulingPolicyService]150search: [android.app.ISearchManager]151sec_key_att_app_id_provider: [android.security.keymaster.IKeyAttestationApplicationIdProvider]152sensor_privacy: [android.hardware.ISensorPrivacyManager]153sensorservice: [android.gui.SensorServer]154serial: [android.hardware.ISerialManager]155servicediscovery: [android.net.nsd.INsdManager]156settings: []157shortcut: [android.content.pm.IShortcutService]158simphonebook: [com.android.internal.telephony.IIccPhoneBookEx]159slice: [android.app.slice.ISliceManager]160soundtrigger: [com.android.internal.app.ISoundTriggerService]161soundtrigger_middleware: [android.media.soundtrigger_middleware.ISoundTriggerMiddlewareService]162sprd_power: []163sprdssense: [android.os.sprdpower.ISSense]164stats: [android.os.IStatsd]165statscompanion: [android.os.IStatsCompanionService]166statsmanager: [android.os.IStatsManagerService]167statusbar: [com.android.internal.statusbar.IStatusBarService]168storaged: [android.os.IStoraged]169storaged_pri: [android.os.storaged.IStoragedPrivate]170storagestats: [android.app.usage.IStorageStatsManager]171suspend_control: []172system_config: [android.os.ISystemConfig]173system_update: [android.os.ISystemUpdateManager]174telecom: [com.android.internal.telecom.ITelecomService]175telephony.registry: [com.android.internal.telephony.ITelephonyRegistry]176telephony_ims: [android.telephony.ims.aidl.IImsRcsController]177testharness: []178tethering: [android.net.ITetherinGConnector]179textclassification: [android.service.textclassifier.ITextClassifierService]180textservices: [com.android.internal.textservice.ITextServicesManager]181thermalservice: [android.os.IThermalService]182time_detector: [android.app.timedetector.ITimeDetectorService]183time_zone_detector: [android.app.timezonedetector.ITimeZoneDetectorService]184trust: [android.app.trust.ITrustManager]185uimode: [android.app.IUiModeManager]186uni_carrierconfig: [com.android.internal.telephony.IUniCarrierConfigLoader]187uni_telephony: [com.android.internal.telephony.IUniTelephony]188updatelock: [android.os.IUpdateLock]189uri_grants: [android.app.IUriGrantsManager]190usagestats: [android.app.usage.IUsageStatsManager]191usb: [android.hardware.usb.IUsbManager]192user: [android.os.IUserManager]193vibrator: [android.os.IVibratorService]194voiceinteraction: [com.android.internal.app.IVoiceInteractionManagerService]195vold: []196wallpaper: [android.app.IWallpaperManager]197WEBviewupdate: [android.webkit.IWebViewUpdateService]198wifi: [android.net.wifi.IWifiManager]199wifinl80211: []200wifip2p: [android.net.wifi.p2p.IWifiP2pManager]201wifiscanner: [android.net.wifi.IWifiScanner]202window: [android.view.IWindowManager]
上面两条命令的结果相差不大,代表系统中可以通过adb shell dumpsys 服务名 去获取相应信息的命令
查看AMS中所有信息
adb shell dumpsys activity
查看内存信息
adb shell dumpsys meminfo
查看电池信息
adb shell dumpsys battery
显示alarm信息
adb shell dumpsys alarm
显示内存状态
adb shell dumpsys procstats
查看Window的相关信息
adb shell dumpsys window
查看CPU相关信息
adb shell dumpsys cpuinfo
有些服务还可以带参数,如果不是很清楚细节,就加上 -h 参数
比如:
home@ubuntu:~$ adb shell dumpsys activity -hActivity manager dump options: [-a] [-c] [-p PACKAGE] [-h] [WHAT] ... WHAT may be one of: a[ctivities]: activity stack state r[recents]: recent activities state b[roadcasts] [PACKAGE_NAME] [history [-s]]: broadcast state broadcast-stats [PACKAGE_NAME]: aggregated broadcast statistics i[ntents] [PACKAGE_NAME]: pending intent state p[rocesses] [PACKAGE_NAME]: process state o[om]: out of memory management perm[issions]: URI permission grant state prov[iders] [COMP_SPEC ...]: content provider state provider [COMP_SPEC]: provider client-side state s[ervices] [COMP_SPEC ...]: service state allowed-associations: current package association restrictions as[sociations]: tracked app associations exit-info [PACKAGE_NAME]: historical process exit information lmk: stats on low memory killer lru: raw LRU process list binder-proxies: stats on binder objects and IPCs settings: currently applied config settings service [COMP_SPEC]: service client-side state package [PACKAGE_NAME]: all state related to given package all: dump all activities top: dump the top activity WHAT may also be a COMP_SPEC to dump activities. COMP_SPEC may be a component name (com.foo/.myApp), a partial substring in a component name, a hex object identifier. -a: include all available server state. -c: include client state. -p: limit output to given package. --checkin: output checkin format, resetting data. --C: output checkin format, not resetting data. --proto: output dump in protocol buffer format. --autofill: dump just the autofill-related state of an activity
然后对照英文注释,带上不同的参数后,可以获取具体的信息:
adb shell dumpsys activity activities----------查看Activity组件信息adb shell dumpsys activity services-----------查看Service组件信息adb shell dumpsys activity providers----------产看ContentProvider组件信息adb shell dumpsys activity broadcasts--------查看BraodcastReceiver信息adb shell dumpsys activity intents--------------查看Intent信息adb shell dumpsys activity processes---------查看进程信息adb shell dumpsys activity intents -------- 查看 PendingIntentRecord 信息
上述的这些命令都涉及到adb shell 命令,我们看看系统源头类
public abstract class BasicShellCommandHandler { //两个重要的方法: public abstract int onCommand(String cmd); public abstract void onHelp();}
onCommand方法 就是各个系统服务 adb shell 直接操作的方法:
比如 AMS 中的 启动一个activity
adb shell am start -n com.DeviceTest/com.DeviceTest.VersionTestActivity
AMS 中的 启动一个service
adb shell am startservice -n com.tentent.mm/.plugin.acountsync.model.AcountAuthenticatorService
启动微信
AMS 中的 停止一个服务
adb shell am stopservice -n xxxx
AMS 发送一个广播:
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -n org.mazhuang.boottimemeasure/.BootCompletedReceiver
表示向 org.mazhuang.boottimemeasure/.BootCompletedReceiver 发送一个 BOOT_COMPLETED
各系统服务中的 onShellCommand 方法:
最终都会复写onCommand 方法,比如AMS 中的 onCommand
public int onCommand(String cmd) { if (cmd == null) { return handleDefaultCommands(cmd); } final PrintWriter pw = getOutPrintWriter(); try { switch (cmd) { case "start": case "start-activity": return runStartActivity(pw); case "startservice": case "start-service": return runStartService(pw, false); case "startforegroundservice": case "startfgservice": case "start-foreground-service": case "start-fg-service": return runStartService(pw, true); case "stopservice": case "stop-service": return runStopService(pw); case "broadcast": return runSendBroadcast(pw); case "instrument":
到这里,就知道上述 adb shell am 命令的是从哪里来的
我们在看看 PMS 相关的 命令:
adb shell pm uninstall com.example.MyApp // 卸载一个应用
adb shell pm path : 查询package的安装位置
adb shell pm enable :使package或component可用。(如:pm enable "package/class")
adb shell pm disable :使package或component不可用。(如:pm disable "package/class")
adb shell pm list packages : 查看所有应用列表
adb shell pm list packages -s : 查看系统应用(system)列表
adb shell pm list packages -3 : 查看第三方应用
adb shell pm clear 包名 : 清除应用数据与缓存
同理,先进去 PMS中 看看 onShellCommand 方法, 然后最后也会复写 onCommand 方法:
public int onCommand(String cmd) { if (cmd == null) { return handleDefaultCommands(cmd); } final PrintWriter pw = getOutPrintWriter(); try { switch (cmd) { case "path": return runPath(); case "validate": return runValidate(); case "dump": return runDump(); case "list": return runList(); case "resolve-activity": return runResolveActivity(); case "query-activities": return runQueryIntentActivities(); case "query-services": return runQueryIntentServices(); case "query-receivers": return runQueryIntentReceivers(); case "install": return runInstall();
这样子,就找到命令的出处了,如果想知道原理,就继续去看每个方法中的实现逻辑。
同理,dumpsys 命令相关的源头,同样也可以查看每个服务中的 onHelp() 方法:
【备注】:只有部分服务有帮助打印信息
比如 我们想看看 电池服务(BatteryService)相关的信息,通过adb shell service list
找到电池的服务名:battery
adb shell dumpsys battery -h 查看该命令的帮助信息:
Battery service (battery) commands: help Print this help text. set [-f] [ac|usb|wireless|status|level|temp|present|invalid] Force a battery property value, freezing battery state. -f: force a battery change broadcast be sent, prints new sequence. unplug [-f] Force battery unplugged, freezing battery state. -f: force a battery change broadcast be sent, prints new sequence. reset [-f] Unfreeze battery state, returning to current hardware values. -f: force a battery change broadcast be sent, prints new sequence.
然后我们去找 BatteryService.java 中的 onHelp() 方法,可以找到对应的源码,也就知道该命令的源头了,代码如下:
class Shell extends ShellCommand { @Override public int onCommand(String cmd) { return onShellCommand(this, cmd); } @Override public void onHelp() { PrintWriter pw = getOutPrintWriter(); dumpHelp(pw); } } static void dumpHelp(PrintWriter pw) { pw.println("Battery service (battery) commands:"); pw.println(" help"); pw.println(" Print this help text."); pw.println(" set [-f] [ac|usb|wireless|status|level|temp|present|invalid] "); pw.println(" Force a battery property value, freezing battery state."); pw.println(" -f: force a battery change broadcast be sent, prints new sequence."); pw.println(" unplug [-f]"); pw.println(" Force battery unplugged, freezing battery state."); pw.println(" -f: force a battery change broadcast be sent, prints new sequence."); pw.println(" reset [-f]"); pw.println(" Unfreeze battery state, returning to current hardware values."); pw.println(" -f: force a battery change broadcast be sent, prints new sequence."); }
来源地址:https://blog.csdn.net/u012514113/article/details/127669871
--结束END--
本文标题: adb shell dumpsys 使用命令和来源
本文链接: https://lsjlt.com/news/415523.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-01-21
2023-10-28
2023-10-28
2023-10-27
2023-10-27
2023-10-27
2023-10-27
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0