Package Manage(PM)
pm list packages [FILTER] 查看已安装的应用包
-f   显示关联的apk文件
-s  只在系统应用中搜索Filter
-3  只在第三方应用中搜索Filter
-d  只在disabled package搜索Filter
-e  只在enabled package搜索Filter
-i  显示installer
-u  uninstalled package
--user USERID
pm list instrumentation [TARGET-PACKAGE] 查看已安装的测试包
-f  显示关联的apk文件
pm list features
pm list permission-groups
pm list permissions [GROUP]
-g  按组组织
-f  显示所有信息
-s  显示简述
-d  只显示危险权限
-u  只显示用户可见的
pm list users
pm uninstall   删除应用
-k  保留数据和缓存
pm clear   清除应用数据
--user USERID
pm path   查看某个应用的apk包路径
pm dump   显示与包相关的系统状态信息
pm install PATH
-l  FORWARD_LOCK
-r  重新安装,保留数据
-t  运行安装测试apk
-i  指定安装包名
-s  SDCard
-f  内部存储器
-d  允许版本降级
pm get-install-location  返回当前默认安装位置
返回值:
0  auto
1  内部存储
2  外部存储
pm set-install-location 0|1|2 修改默认安装位置
pm enable|disable|disable-user|disable-until-used|block|unblock  [--user USERID] PACKAGE_OR_COMPONENT
pm grant|revoke  PACKAGE PERMISSION  应用增减权限(必须在应用中已声明)
pm create-user USER_NAME
pm remove-user USER_ID
pm get-max-users
pm set-permission-enforced PERMISSION [true|false]
pm trim-caches DESIRED_FREE_SPACE
Activity Manage(AM)
通用选项
--user | current | all  以特定用户运行
am start [options]  启动Activity
-D  调试模式
-W  等待启动结束
--start-profilter 启动分析器,结果输出到文件
-P 启动分析器,输出结果到文件,应用空闲时停止分析
-R 反复启动Count次,每次重复前,结束最上层Activity
-S 启动后强制停止
--opengl-trace 启动OpenGL函数记录
--user | current  指定以哪个用户运行,默认为当前用户
am startservice   启动服务
am stopservice   停止服务
am force-stop    强行停止与包相关的所有东西
am kill   杀掉与包相关的进程
am kill-all  杀掉所有后台进程
am broadcast 
am instrument [options] 
-r  以原始形式输出测试结果。该选项通常是在性能测试时与-e perf true一起使用
-p 输出分析数据到文件
-w 等到instrumentation结束时才返回
--no-window-animation
--user | current
-e [,…]
就是
InstrumentationTestRunner可用flag:
flag
value
说明
package
执行某个java包里的测试
class
#methos_name
执行某个测试类
size
small|medium|large
运行@SmallTest,@MediumTest,@LargeTest标注的测试
android.test.annotation包里定义了@LargeTest,@MediumTest,@SmallTest,@Smoke,和@Suppress
perf
true
debug
true
调试模式执行测试
log
true
 specifications include these flags and arguments
[-a ] [-d ] [-t ]    android.intent.action.VIEW content://contacts/people/1  image/png
[-c [-c ] ...]  android.intent.category.APP_CONTACTS
[-e|--es ...]
[--esn ...]
[--ez ...]
[--ei ...]
[--el ...]
[--ef ...]
[--eu ...]
[--ecn ]
[--eia [,
[--ela [,
[--efa [,
[-n ] [-f ]
[--grant-read-uri-permission] [--grant-write-uri-permission]
[--debug-log-resolution] [--exclude-stopped-packages]
[--include-stopped-packages]
[--activity-brought-to-front] [--activity-clear-top]
[--activity-clear-when-task-reset] [--activity-exclude-from-recents]
[--activity-launched-from-history] [--activity-multiple-task]
[--activity-no-animation] [--activity-no-history]
[--activity-no-user-action] [--activity-previous-is-top]
[--activity-reorder-to-front] [--activity-reset-task-if-needed]
[--activity-single-top] [--activity-clear-task]
[--activity-task-on-home]
[--receiver-registered-only] [--receiver-replace-pending]
[--selector]
[ | | ]
dumpsys
查询系统服务,获取系统运行时状态信息
原理:调用ServiceManager服务的listServices来查询系统注册的所有服务,并且通过checkService接口来获取服务的Binder远程代理对象,使用每个服务的dump函数来打印该服务的相关信息。
dumpsys  不带任何参数时,列出所有服务,并依次显示所有服务状态信息
dumpsys | grep FILTER
service list  显示系统服务列表
dumpsys SERVICE [SERVICE_OPTIONS] 显示指定服务的状态信息
dumpsys SERVICE -h  某些服务可以查看能接受的参数
例如:
dumpsys battery
dumpsys wifi
dumpsys cpuinfo
dumpsys meminfo
dumpsys meminfo com.xracoon.wifisetter
dumpsys window w(indows) | grep mCurrentFocus
dumpsys window d(disply) | grep Display
Logcat
logcat命令格式与直接调用adb logcat相同,下面两条命令效果一样,可参考adb 命令一文中Logcat的说明。
adb shell logcat [options] [filter...]
adb logcat [options] [filter...]
调试测试相关命令
dumpstate
dmesg
monkey [options] 
screenrecord [options]   android4.4+
screencap -p 
input
input [] [...]
source:
trackball, joystick, touchnavigation, mouse, keyboard, gamepad, touchpad, dpad, stylus, touchscreen
command和   /默认source:
command
默认的source
text 
touchscreen
keyevent [--longpress] ...
keyboard
tap 
touchscreen
swipe   [duration_ms]
touchscreen
press
trackball
roll 
trackball