Query information from Android device with ‘dumpsys’
There a simple tool called Dumpsys, that allows query various services in order to find some useful data. It lists all the stats & information about particular selected component in a simple text format.
Here is the list of all the components you can query about:
$ dumpsys -l Currently running services: DockObserver SurfaceFlinger accessibility account activity alarm android.security.keystore appops appwidget assetatlas audio backup battery batteryproperties batterystats bluetooth_manager carrier_config clipboard commontime_management connectivity consumer_ir content country_detector cpuinfo dbinfo device_policy deviceidle devicestoragemonitor diskstats display display.qservice dreams drm.drmManager dropbox ethernet fingerprint gfxinfo graphicsstats imms input input_method iphonesubinfo isms isub jobscheduler launcherapps location lock_settings media.audio_flinger media.audio_policy media.camera media.camera.proxy media.player media.radio media.resource_manager media.sound_trigger_hw media_projection media_router media_session meminfo midi mount netpolicy netstats network_management network_score nfc notification package permission phone power print processinfo procstats restrictions rttmanager samplingprofiler scheduling_policy search sensorservice serial servicediscovery simphonebook sip statusbar telecom telephony.registry textservices trust uimode updatelock usagestats usb user vibrator voiceinteraction wallpaper webviewupdate wifi wifip2p wifiscanner window
Some of the services/components can take additional arguments when querying or even be used to set states, to find out more use -h argument when calling:
$ dumpsys battery -h Dump current battery state, or: set [ac|usb|wireless|status|level|invalid] <value> unplug reset
Now, we can use mock scenario when a device is not charging with: dumpsys battery unplug (Android 6+). When you try this, you will notice that the battery icon in statusbar is changed and no longer indicates that device is being charged. This state is simply reversible with dumpsys battery reset.
And here is a simple example of getting battery stats
$ adb shell dumpsys battery Current Battery Service state: AC powered: false USB powered: true Wireless powered: false status: 2 health: 2 present: true level: 71 scale: 100 voltage: 3899 temperature: 0 technology: Li-ion
Dumpsys can also be a great source of all sort of details about installed packages, by typing dumpsys package <package name>
$ dumpsys package com.xanh.draftnotes Activity Resolver Table: Non-Data Actions: android.intent.action.MAIN: 2a93a48 com.xanh.draftnotes/.MainActivity Receiver Resolver Table: Non-Data Actions: com.google.android.gms.analytics.ANALYTICS_DISPATCH: 6909c8 com.xanh.draftnotes/com.google.android.gms.analytics.AnalyticsReceiver com.android.vending.INSTALL_REFERRER: bbe8904 com.xanh.draftnotes/com.google.android.gms.analytics.CampaignTrackingReceiver Key Set Manager: [com.xanh.draftnotes] Signing KeySets: 131 Packages: Package [com.xanh.draftnotes] (2936f2c): userId=10272 pkg=Package{cadedf5 com.xanh.draftnotes} codePath=/data/app/com.xanh.draftnotes-1 resourcePath=/data/app/com.xanh.draftnotes-1 legacyNativeLibraryDir=/data/app/com.xanh.draftnotes-1/lib primaryCpuAbi=null secondaryCpuAbi=null versionCode=21 targetSdk=25 versionName=1.6.1 splits=[base] applicationInfo=ApplicationInfo{2e29d5c com.xanh.draftnotes} flags=[ DEBUGGABLE HAS_CODE ALLOW_CLEAR_USER_DATA ALLOW_BACKUP KILL_AFTER_RESTORE ] dataDir=/data/user/0/com.xanh.draftnotes supportsScreens=[small, medium, large, xlarge, resizeable, anyDensity] timeStamp=2017-05-31 22:56:18 firstInstallTime=2017-05-31 22:46:29 lastUpdateTime=2017-05-31 22:56:24 signatures=PackageSignatures{50d278a [bba9985]} installPermissionsFixed=true installStatus=1 pkgFlags=[ DEBUGGABLE HAS_CODE ALLOW_CLEAR_USER_DATA ALLOW_BACKUP KILL_AFTER_RESTORE ] requested permissions: android.permission.ACCESS_NETWORK_STATE android.permission.INTERNET android.permission.WRITE_EXTERNAL_STORAGE android.permission.WAKE_LOCK android.permission.USE_FINGERPRINT android.permission.VIBRATE android.permission.READ_EXTERNAL_STORAGE install permissions: android.permission.INTERNET: granted=true android.permission.ACCESS_NETWORK_STATE: granted=true android.permission.USE_FINGERPRINT: granted=true android.permission.VIBRATE: granted=true android.permission.WAKE_LOCK: granted=true User 0: installed=true hidden=false stopped=false notLaunched=false enabled=0 gids=[3003] runtime permissions: