ADB Shell Command

本文详细介绍了如何使用ADB Shell命令来管理Android设备,包括列出已安装的包、获取系统信息、启动活动、模拟电池状态等。通过adb shell pm命令可以查看系统和第三方应用包,而adb dumpsys能提供系统信息、内存消耗、电池状态等详细数据。此外,还展示了如何模拟电池电量变化和调整设备时间。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

List Installed Package Names

Objective: List all the installed packages on an Android phone through an ADB shell.
Android package management is done by the pm command on the ADB shell. To list all the installed packages on an Android device, use the following syntax.

$ adb shell pm list packages

To list only the system packages, use the “-s” option.

$ adb shell pm list packages -s

To list only 3rd party (or non-system) packages, use the “-3” option.

$ adb shell pm list packages -3

To list the package names as well as the path to the installed APK files, use the “-f” option.

$ adb shell pm list packages -f

The “-f” option can be combined with the other options as well. For example, to list system package names with the installed package location, use the “-f -s” option.

$ adb shell pm list packages -f -s

To list all the disabled package names, use the “-d” option.

$ adb shell pm list packages -d

To list all the enabled package names, use the “-e” option.

$ adb shell pm list packages -e

adb shell am …
adb shell pm clear

Dump System Information

adb shell dumpsys battery set level XX (0-100)
adb shell dumpsys battery set status 3 (discharge)
adb shell dumpsys battery unplug
adb shell dumpsys battery reset

Getting system information (dumpsys)

adb shell dumpsys

The adb dumpsys command allows you to retain information about the Android system and the running applications.
To get currently memory consumption of an application you can use the following command.

adb shell dumpsys meminfo <package.name>

Memory consumption overview with dumpsys
The adb shell procrank lists you all application in the order of their memory consumption. This command does not work on real device. Use the adb shell dumpsys meminfo instead.
Information about scheduled tasks
To find which alarms are scheduled for your application, use the adb shell dumpsys alarm command and look for your package name. The output might be similar to the following:
RTC #6: Alarm{434a1234 type 1 com.example}
type=1 whenElapsed=608198149 when=+12m13s122ms window=-1 repeatInterval=0 count=0
operation=PendingIntent{430cf612: PendingIntentRecord{43bbf887 com.vogella startService}}
This shows the info that the alarm is scheduled for approx. 12 minutes.
To find out the information about the pending intent, run the adb shell dumpsys activity intents command and look for the ID of the PendingIntentRecord (in this example 43bbf887):
* PendingIntentRecord{43bbf887 com.vogella startService}
uid=10042 packageName=com.vogella type=startService flags=0x0
requestIntent=act=MY_ACTION cmp=com.vogella/.MyService (has extras)
Battery information tasks
As of Android 5.0 you can also get information about the battery consumption of an application.

adb shell dumpsys batterystats --charged <package-name>

Starting an activity

adb shell am start -n yourpackagename/.activityname

Go to System Setting

Wi-Fi

Adb shell am start -n com.android.settings/.wifi.WifiStatusTest

SIM

Adb shell am start -n com.android.settings/.Settings\\$SimSettingsActivity
Adb shell am start -n com.android.settings/.Settings\\$DataUsageSummaryActivity

Air plane mode

Adb shell settings put global airplane_mode_on 1
Adb shell am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true

Adb shell am start -a android.settings.AIRPLANE_MODE_SETTINGS
Adb shell settings get global airplane_mode_on

Device Admin

adb shell am start -S com.android.settings/.Settings\\$DeviceAdminSettingsActivity
adb shell am start -S com.android.settings/.Settings\\$LocationSettingsActivity

adb shell am start -a android.settings.APPLICATION_DETAILS_SETTINGS -d package:<pkg_name>
adb shell am start -a android.settings.action.MANAGE_WRITE_SETTINGS -d package:<pkg_name>
adb shell am start -a android.settings.APPLICATION_SETTINGS
adb shell am start -a android.settings.action.MANAGE_OVERLAY_PERMISSION -d package:<pkg_name>
adb shell am start -S com.android.settings/.Settings\\$WirelessSettingsActivity
adb shell am start -n com.android.settings/.SubSettings -e:settings:show_fragment com.android.settings.applications.ManageDefaultApps
adb shell am start -S com.android.settings/.Settings\\$DevelopmentSettingsActivity
adb shell am start -a android.settings.ACCESSIBILITY_SETTINGS

Mocking Battery Status

We’ll start with interacting with a system service responsible for providing information about device battery.
Using “dumpsys battery” we can get information about the device battery status.

$ adb shell dumpsys battery
Current Battery Service state:
AC powered: false
USB powered: true
Wireless powered: false
status: 2
health: 2
present: true
level: 100
scale: 100
voltage: 4240
temperature: 273
technology: Li-ion

First three lines show what charges are connected. To interpret the status and health values you can use corresponding constants in BatteryManager documentation. Here’s an extract from that doc. Values we got are highlighted.
Status Health
1 Unknown 1 Unknown
2 Charging 2 Good
3 Discharging 3 Overheat
4 Not charging 4 Dead
5 Full 5 Over voltage
6 Unspecified failure
7 Cold
“scale” is the maximum value of “level”. Divide “temperature” by 10 to get value in Celsius.
We can make the system think that charger is disconnected with a command

$ adb shell dumpsys battery set usb 0

In Android 6 a new “unplug” command is available. It’s an equivalent to setting all the chargers (usb, ac, wireless) to 0.

$ adb shell dumpsys battery unplug

If you want to change battery level value, use “set level” command:

$ adb shell dumpsys battery set level 5

Also let’s set battery status to “discharging”:

$ adb shell dumpsys battery set status 3

At this moment our battery is in discharging state with level 5.
The first time you invoke one of “set” commands, device stops getting information from real hardware. Hence, do not forget to finish your gambling with “reset” command in order to get our device back to earth.

$ adb shell dumpsys battery reset

Now you have a good instrument to test how your app behaves in low battery conditions. Good luck!

Discharge

adb shell dumpsys battery set usb 0
adb shell dumpsys battery set ac 0
adb shell dumpsys battery set status 3
adb shell dumpsys battery set level <Level>

Charge

adb shell dumpsys battery set ac 1
adb shell dumpsys battery set usb 1
adb shell dumpsys battery set status 2
adb shell dumpsys battery set level <Level>

Reset battery

adb shell dumpsys battery reset

Dump Window Information

We can get app launch activity information with the command. This is the way used by appium.

adb -s 04157df4654e6308 shell dumpsys window windows

Dump Power Information

Can check whether app wake the app.

adb -s 04157df4654e6308 shell dumpsys power

Others

Adb shell dumpsys activity
Adb shell dumpsys window
adb shell dumpsys device_policy
adb shell dumpsys wifi
adb shell dumpsys power

Get Prop – Device Information
Adb shell getprop ro.product.manufacturer
adb shell getprop ro.product.model
Adb shell getprop ro.build.version.sdk
Get Device Environment Variable
Adb shell echo $EXTERNAL_STORAGE
Adb Shell Cat
Adb shell cat /sys/class/power_supply/battery/capacity
Input Keyevent
adb shell input keyevent 24 – volumn up
adb shell input keyevent 25 – volumn down
adb shell input keyevent 82 – Context menu
adb shell input keyevent 26 – Toggle Display
Download app from market
Adb shell am start -a android.intent.action.VIEW -d market://details?id=
Set Device Time
setEmulatorTimeToPresent
adb shell settings put global auto_time 0
adb shell settings put global auto_time_zone 0
adb shell settings put system time_12_24 24
adb shell su 0 date –s
adb shell date –s
adb shell su 0 date -s %m%e%H%M%C%Y.%S
adb shell date -s %m%e%H%M%C%Y.%S
adb shell su 0 date
Unlock the device
adb shell am start -n io.appium.unlock/.Unlock

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值