常用ADB指令总结

1.连接设备

adb connect host

2.查看设备

adb devices #查看设备信息 
adb version #设备版本 
adb help #帮助文档  
adb get-state #查看设备状态 device(正常连接),offline(连接异常),unknown(没有连接) 
adb get-serialno #获取序列号 
adb get-devpath #获取设备路径 
adb shell cat /system/build.prop #获取设备名称 

3.操作多个设备

adb —a 监听所有网络接口,而不仅仅是localhost 
-d 使用USB设备(如果多个设备连接错误) 
-e 使用TCP / IP设备(如果可用多个TCP / IP设备错误) 
-s 使用给定的序列号(覆盖ANDROID_SERIAL) 
-t 使用给定设备ID 
-h adb服务器主机名称(默认= localhost) 
-p adb服务器的端口(默认= 5037) 
-l 监听来自套接字的adb服务器(默认= tcp: localhost: 5037) 
例如:adb -s 127.0.0.1:62001 shell 

4.关机与重启

adb reboot #设备重启 
adb shutdown #设备关机 

5.刷机模式

adb reboot bootloader #重启到bootloader,即刷机模式 
adb reboot recovery #重启到recovery,即恢复模式 
adb sideload <path-to-update.zip>#更新系统 

6.查看应用

adb shell pm list packages #所有应用 
adb shell pm list package -f # 
adb shell pm list packages -s #系统应用 
adb shell pm list packages -3 #三方应用 
adb shell pm list packages | findstr bluetooth #过滤应用  管道符进行搜索,Linux下使用grep 

7.查看应用的activity信息

adb shell dumpsys package com.android.bluetooth #查看系统应用蓝牙的包名信息 
adb shell dumpsys activity activities #查看所有的活动程序包名 
adb shell dumpsys activity | findstr mFocusedActivity #查看当前重启的是哪个包 
adb shell dumpsys activity top | findstr activity #查找设备活动程序的父窗口 

8.清除应用数据和缓存

adb shell pm clear packagename

9.日志

adb logcat#查看日志 
adb logcat -v time #打印详情日志,会记录当前的所有操作行为以及产生的结果,默认持续监听,按下Ctrl+c即可结束 
adb logcat -v time >D:\log.txt #保存日志到电脑 
adb logcat -f /sdcard/1.txt    #保存日志到手机 
adb logcat | findstr com.android.bluetooth #保存指定包名的日志 
adb logcat -c  #清除之前的日志输出 
adb logcat | findstr ActivityManager  #查看当前正在运行的Activity 
adb logcat | findstr Displayed        #查看当前正在运行的Activity 
adb bugreport #查看bug报告 
adb logcat -b radio #无线通讯的日志 
adb shell dmesg #内核日志 

10.截屏录屏

adb shell screencap /sdcard/1.png #当前窗口截屏保存到手机 
adb shell /system/bin/screencap -p /sdcard/2.png 
adb exec-out screencap -p >1.png #截图保存到电脑 
adb shell screenrecord >1.mp4  #屏幕录像,Ctrl+c停止录制 
--size #视频大小 
--bit-rate #比特率 
--time-limit #持续时间 
--verbose #命令行显示log信息 
注:模拟器和安卓4.4以下版本不支持录屏 

11.设备相关信息

adb shell getprop ro.build.version.release #安卓系统版本 
adb shell getprop ro.product.model #查看设备型号 
adb shell cat /sys/class/net/wlan0/address #查看MAC地址 
adb shell wm size #设备屏幕分辨率 
adb shell wm size 400X654 #设置屏幕分辨率 
adb shell wm size reset #恢复原屏幕分辨率 
adb shell wm density #设备屏幕密度 
adb shell wm density 100 #修改屏幕密度为100dpi 
adb shell wm density reset #恢复原屏幕密度 
adb shell wm overscan 10,20,30,100 #显示区域 
adb shell wm overscan reset #恢复原显示区域 
adb shell dumpsys window displays #显示屏参数 
adb shell service list  #查看后台services信息 
adb shell settings put global adb_enabled 0 #关闭 USB 调试模式 
adb shell uiautomator dump   #获取当前界面的控件信息 
adb shell ime list -s  #设备上的输入法 

12.进程

adb shell ps #查看手机正在运行的进程 adb shell ps | findstr bluetooth  
adb shell ps -x pid #查看指定pid的进程状态信息 
adb shell kill pid #根据进程号杀进程 
adb shell procrank #杀进程  
adb shell start adbd #启动守护进程 
adb shell stop adbd  #关闭守护进程 

13.性能分析

adb shell cat /proc/cpuinfo #获取CPU序列号 
adb shell cat /proc/meminfo #查看当前内存占用 
adb shell cat /proc/iomem #查看IO内存分区 
adb remount #将system分区重新挂载为可读写分区 
adb shell dumpsys meminfo bluetooth #查看蓝牙占用的内存 
adb shell dumpsys cpuinfo | findstr bluetooth #获取CPU 
adb shell top #查看实时资源占用情况 
adb shell top -n 1 | findstr bluetooth #刷新一次内存信息,然后返回蓝牙内存占用 
adb shell top #查看设备cpu和内存占用情况 
adb shell top -m 6 #查看占用内存前6的app 
adb shell dumpsys gfxinfo bluetooth #获取流畅度相关 
adb shell netcfg #查看设备的网络连接情况 
adb shell ifconfig wlan0 #获取wlan0的IP地址和子网掩码 

14.文件操作

adb shell ls #列出目录下的文件和文件夹 
adb shell cd sys #切换当前目录为sys 
adb shell rename 旧文件名 新文件名 #重命名文件名 
adb shell rm /sys/1.apk #删除指定目录下的文件 
adb shell rm -r #删除指定目录下的文件夹及其子目录 
adb shell mv 旧文件名 新文件名 #移动文件 
adb shell chmod 777 1.jpg #设置文件权限 
adb shell mkdir 文件夹名 #新建文件夹 
adb shell cat 文件 #查看文件内容 
adb shell cat /data/misc/wifi/*.conf #查看WiFi密码 

15.按键

adb shell input keyevent 3 # HOME 键 
adb shell input keyevent 4 # 返回键 
adb shell input keyevent 5 # 拨号 
adb shell input keyevent 6 # 挂断 
adb shell input keyevent 24 # 音量+ 
adb shell input keyevent 25 # 音量- 
adb shell input keyevent 26 # 电源键 
adb shell input keyevent 27 # 拍照 
adb shell input keyevent 64 # 打开浏览器 
adb shell input keyevent 82 # 菜单键 
adb shell input keyevent 85 # 播放/暂停 
adb shell input keyevent 86 # 停止播放 
adb shell input keyevent 87 # 播放下一首 
adb shell input keyevent 88 # 播放上一首 
adb shell input keyevent 122 #移动光标到行首或列表顶部  
adb shell input keyevent 123 #移动光标到行尾或列表底部 
adb shell input keyevent 126 # 恢复播放 
adb shell input keyevent 127 # 暂停播放 
adb shell input keyevent 164 # 静音  
adb shell input keyevent 176 # 打开系统设置  
adb shell input keyevent 187 # 切换应用 
adb shell input keyevent 207 # 打开联系人  
adb shell input keyevent 208 # 打开日历 
adb shell input keyevent 209 # 打开音乐 
adb shell input keyevent 210 # 打开计算器  
adb shell input keyevent 220 # 降低屏幕亮度 
adb shell input keyevent 221 # 提高屏幕亮度 
adb shell input keyevent 223 # 休眠 
adb shell input keyevent 224 # 点亮屏幕 
adb shell input keyevent 231 # 打开语音助手 
adb shell input keyevent 276 # 如果没有 wakelock 则让系统休眠 

16.点击、滑动屏幕

adb shell input tap 100 300 #在(100,300)处点击 
adb shell input swipe 100 1200 100 200 #上滑 
adb shell input swipe 100 200 100 1200  #下滑 

17.输入

adb shell input text hello  #输入hello 

18.设备id

adb shell settings get secure android_id 

19.无线网络

adb shell svc wifi enable  #开启WiFi 
adb shell svc wifi disable #关闭WiFi 

20.以太网

获取root权限
adb root
adb remount
adb shell ifconfig eth0 up   打开
adb shell ifconfig eth0 down 关闭

21.Activity管理器

adb shell am start -n activity路径 #启动某一个activity 
adb shell am start -a android.intent.action.VIEW -d www.baidu.com#启动默认浏览器打开一个网页 
adb shell am start -n com.android.camera/.Camera #启动相机 
adb shell am start -a android.intent.action.CALL -d tel:10086#启动拨号10086 
adb shell am startservice -n 服务 #开启服务 
adb shell am stopservice  服务 #停止服务 
adb shell am force-stop bluetooth #杀死蓝牙进程 
adb shell am kill 进程号  #杀掉进程 
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED #向所有组件广播设备启动完毕 

22.调用软件包管理器

adb shell pm list permissions #查看权限 
adb shell pm list permission-groups #输出所有已知的权限组 
adb shell pm list permissions -d -g -f #查看系统危险权限并按组输出所有信息 
adb shell pm list instrumentation#列出所有测试软件包,-f列出测试软件包的APK文件 
adb shell pm path com.android.bluetooth #查看软件安装路径 
adb shell pm list features  #输出系统的所有功能 
adb shell pm list libraries #输出当前设备支持的所有库 
adb shell pm list users #输出系统中的所有用户 
adb shell pm enable ** #启用给定的软件包或组件(写为“package/class”) 
adb shell pm disable ** #停用给定的软件包或组件(写为“package/class”) 
adb shell pm get-max-users #输出设备支持的最大用户数 

23.隐藏状态栏

adb shell settings put global policy_control immersive.status=*

24.隐藏虚拟按钮

adb shell settings put global policy_control immersive.navigation=*

25.全屏模式

adb shell settings put global policy_control immersive.full=*

26.恢复正常模式

adb shell settings put global policy_control null
<think>我们正在讨论Monkey测试和ADB命令。用户的问题集中在Monkey测试的基本概念和ADB中的常用命令。根据提供的引用,我们可以总结如下: Monkey测试是Android平台的一种自动化测试手段,通过模拟用户的随机操作(如触摸、滑动、按键等)来对应用进行压力测试,以检测应用的稳定性和健壮性。常用ADB命令涉及Monkey测试的基本语法、参数设置以及日志记录等。我将按照以下结构组织回答:1.解释Monkey测试的基本概念和目的。2.介绍进行Monkey测试的前提条件(ADB连接设备)。 3.详细说明Monkey命令的基本格式和常用参数。4.提供几个典型的Monkey测试命令示例。 5.强调日志记录的重要性(-v参数的使用)。同时,根据系统指令,我们需要在回答中自然地添加引用标识,并在最后生成相关问题。注意:引用内容来自用户提供的三个引用片段,我们将在回答中适当引用。现在开始组织回答内容。</think>### Monkey测试基本概念及ADB常用命令 #### 一、Monkey测试基本概念 Monkey测试是Android平台的一种自动化压力测试手段,通过模拟用户随机操作(触摸屏幕、滑动、按键等)来检测应用的稳定性和健壮性[^2]。其核心特点包括: 1. **随机性**:生成伪随机事件流模拟用户操作 2. **压力测试**:验证应用在异常操作下的表现 3. **健壮性检测**:发现内存泄漏、ANR(应用无响应)和崩溃等问题 4. **无需脚本**:通过命令行参数配置测试场景 数学表达式示例: 设事件触发间隔为$\Delta t$毫秒,总测试时长$T$秒,则事件次数$N$满足: $$N = \frac{T \times 1000}{\Delta t}$$ #### 二、ADB连接准备 执行Monkey测试前需确保: ```bash # 检查设备连接 adb devices # 输出示例:List of devices attached # R58MC2CQTHM device ``` 若未识别设备,需开启手机的**开发者模式**和**USB调试**[^3]。 #### 三、Monkey常用命令语法 基本结构: ```bash adb shell monkey [选项] <事件次数> ``` ##### 核心参数说明: | 参数 | 作用 | 示例 | |------|------|------| | `-p <包名>` | 指定测试应用 | `-p com.tencent.mobileqq` | | `-v` | 日志详细度(可叠加) | `-v -v -v` | | `--throttle <毫秒>` | 事件间隔时间 | `--throttle 500` | | `-s <seed值>` | 重现随机序列 | `-s 1609090283475` | | `--ignore-crashes` | 忽略崩溃继续测试 | `--ignore-crashes` | | `--ignore-timeouts` | 忽略ANR继续测试 | `--ignore-timeouts` | #### 四、典型测试场景命令 1. **基础随机测试**(100次事件): ```bash adb shell monkey 100 ``` 2. **指定应用测试**(带500ms间隔): ```bash adb shell monkey -p com.example.app --throttle 500 200 ``` 3. **可复现测试**(固定seed值): ```bash adb shell monkey -s 12345 -v -v 300 ``` 4. **稳定性测试**(忽略崩溃/ANR): ```bash adb shell monkey --ignore-crashes --ignore-timeouts 500 ``` 5. **1分钟压力测试**(每秒1次操作): ```bash adb shell monkey --throttle 1000 60 # 60s = 60次操作 ``` #### 五、日志分析要点 - 使用`-v`等级控制输出: - `-v`:基础日志 - `-v -v`:详细事件流 - `-v -v -v`:完整的系统级信息 - 关键日志标识: ```log // 崩溃信息 CRASH: com.example.app (pid 12345) // ANR警告 ANR in com.example.app ``` > **注意**:命令中**事件次数必须放在最后**,日志参数`-v`需在次数前声明[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值