使用adb命令操控Android手机(adb命令)

1) 手机连接电脑之前

  • 首先,查看安卓手机是否已经连接上电脑
adb devices
  • 让adb一直查找安卓设备,找到后才停止
adb wait-for-device

2) 手机连接电脑后的操作

2.0) 基本命令

  • 连接多个安卓设备时,在adb命令后紧跟着使用 -s加序列号 来指定要操作的设备

建议每次只连接一个安卓设备进行操作!!!
建议每次只连接一个安卓设备进行操作!!!
建议每次只连接一个安卓设备进行操作!!!

$ adb devices
List of devices attached
FA6AX0301341    device
ce0217122b56b02604  device

$ adb -s FA6AX0301341 shell
sailfish:/ $

2.1) 锁定/解锁/重启/关机

  • 锁定/解锁手机
adb shell input keyevent 26 //锁定手机
adb shell input keyevent 82 //解锁手机(如果设置了密码,会提示输入密码)
  • 输入密码,并回车
adb shell input text 123456 && adb shell input keyevent 66
  • 重启/关机
adb reboot  //重启
adb shell reboot  //重启
adb shell reboot -p  //关机

2.2) 系统设置

  • 打开关闭蓝牙
adb shell service call bluetooth_manager 6 //打开蓝牙
adb shell service call bluetooth_manager 9 //关闭蓝牙
  • 打开关闭wifi
adb shell svc wifi enable  //打开wifi
adb shell svc wifi disable  //关闭wifi
  • 打开wifi设置界面
adb shell am start -a android.intent.action.MAIN -n com.android.settings/.wifi.WifiSettings
  • 连接时保持亮屏 设置
svc power stayon [true|false|usb|ac|wireless]

参数解释:
true: 任何情况下均保持亮屏
false:任何情况下均不保持亮屏(经过设定的时间后自动黑屏)
usb, ac, wireless:设置其中之一时,仅在这一种情况下才保持亮屏。

2.3) 模拟本机操作

  • 模拟按键操作
adb shell input keyevent 111 //关闭软键盘(其实是按下ESC,111=KEYCODE_ESCAPE)

更多按键代码,在这里
https://developer.android.com/reference/android/view/KeyEvent.html

  • 模拟滑动触屏操作
adb shell input touchscreen swipe 930 880 930 380 //向上滑
adb shell input touchscreen swipe 930 880 330 880 //向左滑
adb shell input touchscreen swipe 330 880 930 880 //向右滑
adb shell input touchscreen swipe 930 380 930 880 //向下滑
  • 模拟鼠标操作
adb shell input mouse tap 100 500

100是x,500是y。
原点在屏幕左上角。

2.4) 运行程序

  • 拨打电话
adb shell am start -a android.intent.action.CALL -d tel:10010
  • 打开网站
adb shell am start -a android.intent.action.VIEW -d  http://google.com
  • 启动APP
adb shell am start -n com.package.name/com.package.name.MainActivity
adb shell am start -n com.package.name/.MainActivity

$ adb shell monkey -p com.android.contacts -c android.intent.category.LAUNCHER 1
Events injected: 1
## Network stats: elapsed time=16ms (0ms mobile, 0ms wifi, 16ms not connected)

3) 硬件高级调节

3.0) 信息查看

  • 查看设备序列号
adb get-serialno

3.1) CPU相关

  • 查看CPU温度
    先查看有哪些温度区域thermal zone
$ adb shell ls sys/class/thermal/
cooling_device0
cooling_device1
cooling_device2
cooling_device3
cooling_device4
cooling_device5
thermal_zone0
thermal_zone1
thermal_zone2
thermal_zone3
thermal_zone4
thermal_zone5
thermal_zone6
thermal_zone7

查看某个CPU温度

$ cat /sys/class/thermal/thermal_zone0/temp                                                                                                
25800

温度是milliCelsius,所以这里是25.8度C。

  • CPU设置
    查看当前手机可用的governor
$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors                                                                     
userspace interactive performance
  • 锁定CPU为最大频率

参考:https://forum.xda-developers.com/showthread.php?t=1663809

设置CPU governor为performance。

echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

4) 刷机

  • 重启手机,进入recovery或bootloader模式
adb reboot recovery //恢复模式
adb reboot bootloader  //刷机模式。不同手机,命令不同,要试一下。
adb reboot-bootloader
adb reboot boot loader
  • 进入 fastboot 模式。
 adb  reboot  fastboot
    或
关机,然后同时按住 增加音量 和 电源 键开机

5) 调试

  • 抓取开机日志
adb wait-for-device && adb shell logcat -v threadtime | tee mybootup.log
  • 查看日志
adb logcat
  • 关闭/重启adb服务进程
adb kill-server
adb start-server
  • 从本地复制文件到设备,或者反之
adb push test.zip /sdcard/  //从本地复制文件到设备
adb pull /sdcard/abc.zip  ~/  //从设备复制文件到本地
  • 显示已经安装的APP的包名
adb shell pm list packages
  • 安装、删除APP
adb install abc.apk //第一次安装。如果手机上已经有此app,则会报错。
adb install -r abc.apk //如果已经安装过,保留原app的数据
adb -s 11223344 install abc.apk  //当多个安卓连接到电脑时,安装到指定一台安卓上
adb uninstall com.example.appname
  • 查看apk的版本(无需解压)
aapt dump badging abcd.apk |grep version
  • 捕获键盘操作
adb shell getevent -ltr 
  • 查看屏幕分辨率 dpi
wm density
wm size

设置:

wm density 240

立刻生效。



posted @ 2019-05-24 18:10  夏有凉风  阅读(25866)  评论(0编辑  收藏  举报