您的位置:首页 > 移动开发 > Android开发

Android常用小工具的使用方法

2013-06-09 13:30 597 查看
1. input
input text <string>
输入字符串,可以不使用软键盘,更方便调试(包括写脚本测试)
input keyevent <event_code>
输入按键事件,支持全键盘按键,可以在没有输入设备时,操作系统。按键事件可以参考源文件:KeyEvent.java
e.g:

input keyevent 82 // unlock

input keyevent 1 // left softkey

input keyevent 2 // right softkey

input keyevent 3 // back idle

input keyevent 4 // back key

JellyBean上,可以支持更多的功能:
input keyevent <key codenumber or name>
Keyevent可以用名字表示,如:
input keyevent MENU (JellyBean)

input tap <x> <y>
可以发送一个点击事件。

input swipe <x1> <y1> <x2><y2>
可以发送一个滑动事件,如往右滑动:
input swipe 100 200 300 200

2. screencap
截屏工具
请求SurfaceFlinger重新renderSurface
>>surfaceFlinger通过openGL画到FBO中
>> 没有走hwcomposer及我们的DE最终显示
如果这个截图和最终屏幕显示可能不一致:
>> SurfaceFlinger有问题(framebuffer或hwcomposer)
>> 有overlay
>>我们的DE有两层, graphic(Android UI) 和overlay (video/camera的显示),目前只针对前者
截取framebuffer,可以通过sys文件接口实现
>> Cat/dev/graphics/fb0
使用方式:
usage: screencap [-hp] [FILENAME]
-h: this message
-p: save the file as a png.
If FILENAME ends with .png it will be saved asa png.
If FILENAME is not given, the results will beprinted to stdout.
#adb shell screencap –p /sdcard/screen1.png
#adb pull /sdcard/screen1.png .

3. monkey
Monkey是设备上的可执行程序,产生随机数如事件
>> Keyevent
>> Touch event
>> Guesture
>> System events
开发阶段作为压力测试使用
客户定制阶段可部分作为稳定性验证
可通过脚本实现一定的测试方法

命令格式
>> usage: monkey[options] COUNT
参数详解
>> Basicconfiguration options, such as setting the number of events toattempt.
>> Operationalconstraints, such as restricting the test to a singlepackage.
>> Event types andfrequencies.
>> Debugging options.
>>https://developer.android.com/tools/help/monkey.html
常用命令:
monkey 100 (基本命令)

monkey --ignore-crashes --ignore-timeouts99999 (无特定目的的压力测试)
monkey –p com.android.browser –pcom.android.launcher –v –v 999999 (仅测试lancher和browser,测试是输出最多的trace信息)

4. am
Android可以支持从命令行控制android的启动行为
在项目/硬件带起的初始阶段,很有帮助
usage: am [subcommand] [options]
e.g:

启动music:
am start -n com.android.music/com.android.music.MediaPlaybackActivity
拨打电话:
am start -a android.intent.action.CALL -dtel:10086
浏览网页:
am start -a android.intent.action.VIEW -d http://www.google.cn/ 性能测试:
am profile com.android.browser start /sdcard/dump.trace
am profile com.android.browser stop
结合traceview,可以很方便tracejava程序的性能问题。(目前的版本,traceview运行不起来(log 不配对))

5. pm
usage: pm [list|path|install|uninstall]
Android的包管理工具,功能强大
调试时会经常使用:安装、卸载、禁用等

6. bugreport
bugreport比较简单,主要是收集系统信息并输出到文件,以供开发人员分析
注意很多信息可能需要root权限才能获得
实际执行的就是dumpstate,获取的信息包括:
>>> Logcat
>>> Kernel message
>>> Dumpsys
>>> 其他系统信息

7. procrank
获得当前系统中各进程的内存使用快照,只有工程版本才带此工具。
使用方法:
Usage: procrank [ -W ] [ -v | -r | -p | -u| -h ]
-v Sort by VSS.
-r Sort by RSS.
-p Sort by PSS.
-u Sort by USS.
(Default sort order is PSS.)
-R Reverse sort order (default isdescending).
-w Display statistics for workingset only.
-W Reset working set of allprocesses.
-h Display this help screen.

VSS - Virtual Set Size 虚拟耗用内存(包含共享库占用的内存)

RSS - Resident Set Size 实际使用物理内存(包含共享库占用的内存)

PSS - Proportional Set Size 实际使用的物理内存(比例分配共享库占用的 内存)

USS - Unique Set Size 进程独自占用的物理内存(不包含共享库占用的内存)
Procrank在我们机器上统计的并不准确

8. toolbox
Android实现的shell命令少的可怜,功能简单,不够强大
工具参看 system/core/toolbox/Android.mk
我们的系统提供了更强大的busybox
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: