ADB Shell Command

来源:互联网 发布:淘宝如何找货源 编辑:程序博客网 时间:2024/05/22 02:44

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 unplugadb 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 1Adb shell am broadcast -a android.intent.action.AIRPLANE_MODE --ez state trueAdb shell am start -a android.settings.AIRPLANE_MODE_SETTINGSAdb shell settings get global airplane_mode_on

Device Admin

adb shell am start -S com.android.settings/.Settings\\$DeviceAdminSettingsActivityadb shell am start -S com.android.settings/.Settings\\$LocationSettingsActivityadb 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_SETTINGSadb shell am start -a android.settings.action.MANAGE_OVERLAY_PERMISSION -d package:<pkg_name>adb shell am start -S com.android.settings/.Settings\\$WirelessSettingsActivityadb shell am start -n com.android.settings/.SubSettings -e:settings:show_fragment com.android.settings.applications.ManageDefaultAppsadb shell am start -S com.android.settings/.Settings\\$DevelopmentSettingsActivityadb 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 batteryCurrent Battery Service state:AC powered: falseUSB powered: trueWireless powered: falsestatus: 2health: 2present: truelevel: 100scale: 100voltage: 4240temperature: 273technology: 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 0adb shell dumpsys battery set ac 0adb shell dumpsys battery set status 3adb shell dumpsys battery set level <Level>

Charge

adb shell dumpsys battery set ac 1adb shell dumpsys battery set usb 1adb shell dumpsys battery set status 2adb 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 activityAdb shell dumpsys windowadb shell dumpsys device_policyadb shell dumpsys wifiadb 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

原创粉丝点击