当前位置:   article > 正文

adb常用命令总结_adb shell dumpsys activity

adb shell dumpsys activity

1 前言

        ADB(Android Debug Bridge)即 Android 调试桥,采用监听 Socket TCP 端口的方式通讯。连接手机有2种方式:有线连接、无线连接。

        (1)有线连接

        使用数据线连接手机后,在【开发人员选项】中开启【USB 调试】,并在【选择 USB 配置】中选择【MTP (多媒体传输)】。

        (2)无线连接

adb connect ip

         注意事项:

  • 手机和 PC 需要连接同一个局域网
  • 需要开启【USB 调试】,并选择【MTP (多媒体传输)】

        若报如下错误:

cannot connect to 192.168.0.109:5555: 由于目标计算机积极拒绝,无法连接。 (10061)

         按照如下步骤可以连接上手机:

  • 使用数据线连接手机和 PC,执行命令:adb tcpip 5555
  • 拔掉数据线,开启【USB 调试】,并选择【MTP (多媒体传输)】
  • 执行命令:adb connect 192.168.0.109

2 常用命令

2.1 基础命令

  1. ::查看设备
  2. adb devices
  3. ::查看详细设备信息(含型号)
  4. adb devices -l
  5. ::查看手机信息(品牌、型号、版本等)
  6. adb shell cat /hw_product/etc/prop/local.prop | findstr product
  7. adb shell cat /system/build.prop | findstr product
  8. ::重启
  9. adb reboot
  10. ::查看日志
  11. adb logcat > log.txt
  12. adb logcat | findstr "matched_string"
  13. ::安装/卸载
  14. adb install xxx.apk
  15. adb uninstall package_name
  16. ::拉取/推送
  17. adb remount
  18. adb pull /sdcard/a.mp4 C:\Users\81518\Desktop\
  19. adb push C:\Users\81518\Desktop\a.mp4 /sdcard/
  20. ::查看当前界面运行的 activity 及其包名
  21. adb shell dumpsys window | findstr "mCurrentFocus"
  22. ::查看指定命令的参数
  23. adb command --help
  24. adb shell command --help

        打印方法调用堆栈:

android.util.Log.d("TAG", android.util.Log.getStackTraceString(new Throwable()));

2.2 截屏/录制

  1. ::截屏
  2. adb shell screencap -p /sdcard/1.png
  3. adb pull /sdcard/1.png C:\Users\81518\Desktop\
  4. ::录屏
  5. adb shell screenrecord /sdcard/1.mp4

        说明:截屏时,可以通过【-d】指定 display id,默认是 0

2.3 查看/修改系统参数

  1. ::查看系统参数值
  2. adb shell getprop system_prams
  3. ::设置系统参数值
  4. adb shell setprop system_prams params_value
  5. ::查看手机型号
  6. adb shell getprop ro.product.model
  7. ::查看手机固件构建时间
  8. adb shell getprop ro.build.date

2.4 模拟输入

  1. ::查看模拟输入命令
  2. adb shell input --help
  3. ::点击指定坐标位置
  4. adb shell input tap <x> <y>
  5. ::滑动
  6. adb shell input swipe <x1> <y1> <x2> <y2>
  7. ::按键事件
  8. adb shell input keyevent <keycode>

        说明:通过 -d 属性可以指定 displayId,应用如下:

  1. ::点击指定display的指定坐标位置
  2. adb shell input -d 1 tap 100 200

        常用<keycode>如下:

  1. 3 HOME 键
  2. 4 返回键
  3. 5 打开拨号应用
  4. 6 挂断电话
  5. 24 增加音量
  6. 25 降低音量
  7. 26 电源键
  8. 27 拍照(需要在相机应用里)
  9. 64 打开浏览器
  10. 82 菜单键
  11. 85 播放/暂停
  12. 86 停止播放
  13. 87 播放下一首
  14. 88 播放上一首
  15. 122 移动光标到行首或列表顶部
  16. 123 移动光标到行末或列表底部
  17. 126 恢复播放
  18. 127 暂停播放
  19. 164 静音
  20. 176 打开系统设置
  21. 187 切换应用
  22. 207 打开联系人
  23. 208 打开日历
  24. 209 打开音乐
  25. 210 打开计算器
  26. 220 降低屏幕亮度
  27. 221 提高屏幕亮度
  28. 223 系统休眠
  29. 224 点亮屏幕
  30. 231 打开语音助手
  31. 276 如果没有 wakelock 则让系统休眠

2.5  adb shell settings

        (1)查看属性

  1. ::查看系统/全局/安全属性
  2. adb shell settings list system
  3. adb shell settings list global
  4. adb shell settings list secure
  5. ::获取自动锁屏时间(单位:毫秒 ms)
  6. adb shell settings list system | findstr "screen_off_timeout"
  7. adb shell settings get system screen_off_timeout
  8. ::获取当前屏幕亮度
  9. adb shell settings get system screen_brightness
  10. ::获取默认输入法(com.baidu.input_huawei/.ImeService)
  11. adb shell settings get secure default_input_method

        (2)设置属性

  1. ::设置自动锁屏时间(单位:毫秒 ms,此处为:1天)
  2. adb shell settings put system screen_off_timeout 86400000
  3. ::设置当前屏幕亮度
  4. adb shell settings put system screen_brightness 100
  5. ::跳过开机导航
  6. adb shell settings put global device_provisioned 1 && adb reboot

2.6 adb shell am

        am 即 ActivityManager,主要用于启动 activity、service,发送 broadcast 等。

  1. ::打开记事本
  2. adb shell am start com.huawei.notepad
  3. ::关闭 QQ
  4. adb shell am force-stop com.tencent.mobileqq
  5. ::拉起服务
  6. adb shell am startservice -a com.example.test.DemoService
  7. ::发送广播
  8. adb shell am broadcast -a com.example.text.ACTION
  9. ::恢复出厂设置
  10. adb shell am broadcast -a android.intent.action.MASTER_CLEAR

2.7 adb shell wm

        wm 即 WindowManager,主要用于窗口管理。

  1. ::查看手机分辨率:Physical size: 1080x2340
  2. adb shell wm size
  3. ::查看物理密度:Physical density: 480
  4. adb shell wm density

2.8 adb shell pm

        pm 即 PackageManager,主要作用有:

  1. 安装、卸载应用
  2. 查询已安装应用
  3. 查询、增加、删除 permission
  4. 查询 Application 相关信息(application、activity、service、receiver、provider及相应属性等)
  5. 清除用户数据、缓存等 
  1. ::安装应用(安装包在手机上)
  2. adb shell pm install package_path
  3. ::卸载应用
  4. adb shell pm uninstall package_name
  5. ::查询已安装应用包名
  6. adb shell pm list packages [-s:系统包] [-3:三方包]
  7. ::获取指应用的apk路径
  8. adb shell pm path com.example.test
  9. ::获取指定应用的安装路径
  10. adb shell pm get-install-location
  11. ::授予权限
  12. adb shell pm grant com.example.test android.permission.READ_EXTERNAL_STORAGE
  13. ::撤销权限
  14. adb shell pm revoke com.example.test android.permission.WRITE_EXTERNAL_STORAGE
  15. ::列出所有用户
  16. adb shell pm list users
  17. ::创建用户
  18. adb shell pm create-user "user_name"
  19. ::删除有用户
  20. adb shell pm remove-user user_id
  21. ::清除指定应用的所有数据
  22. adb shell pm clear com.example.test

2.9 进程操作

  1. ::查看进程
  2. adb shell ps | findstr "com.tencent.mobileqq"
  3. ::kill进程
  4. adb shell kill pid
  5. adb shell am force-stop package_name
  6. ::关闭/启动 adb 服务
  7. adb kill-server
  8. adb start-server

2.10 adb shell uiautomator

        dump 布局

  1. adb shell uiautomator dump --compressed /data/local/tmp/uidump.xml
  2. adb pull /data/local/tmp/uidump.xml

        XML 在线格式化

2.11 dumpsys

        (1)adb shell dumpsys activity

  1. ::查看Activity组件信息
  2. adb shell dumpsys activity activities
  3. adb shell dumpsys activity activities | findstr /C:"* Hist"
  4. ::查看Service组件信息
  5. adb shell dumpsys activity services
  6. ::查看ContentProvider组件信息
  7. adb shell dumpsys activity providers
  8. ::查看BraodcastReceiver信息
  9. db shell dumpsys activity broadcasts
  10. ::查看Intent信息
  11. adb shell dumpsys activity intents
  12. ::查看进程信息
  13. adb shell dumpsys activity processes

        (2)adb shell dumpsys window

  1. ::查看窗口信息
  2. adb shell dumpsys window windows
  3. adb shell dumpsys window windows | findstr /C:"Window #"
  4. ::查看屏幕信息
  5. adb shell dumpsys window displays
  6. ::查看策略信息
  7. adb shell dumpsys window policy
  8. ::查看动画信息
  9. adb shell dumpsys window animator
  10. ::查看会话信息
  11. adb shell dumpsys window sessions
  12. ::查看 tokens 信息
  13. adb shell dumpsys window tokens
  14. ::查看 trace 信息
  15. adb shell dumpsys window trace

        (3)其他

  1. ::查看输入信息
  2. adb shell dumpsys input
  3. ::查看内存信息
  4. adb shell dumpsys meminfo
  5. ::查看电源管理信息
  6. adb shell dumpsys power
  7. ::查看电池信息,【即当前电量、电池状态、电池温度等】
  8. adb shell dumpsys battery
  9. ::查看渲染信息
  10. adb shell dumpsys SurfaceFlinger

3 拓展

        (1)批量 push

         有时需要批量 push 某文件夹下的带特定后缀的文件,这时可以使用如下脚本:

  1. set source_path=E:\android\jar\
  2. set target_path=/system/framework/
  3. cd %source_path%
  4. for %%s in (*.jar) do (
  5. adb push %%s %target_path%
  6. )
  7. pause

        注意:以上代码需放在 bat 脚本文件中,若在命令行中输入以上命令,则将  %%s 改为 %s。

        (2)追加属性

  1. adb pull hw_product/etc/prop/local.prop
  2. echo xxx_prop = true >> local.prop
  3. adb push local.prop hw_product/etc/prop/local.prop

        (3) 模拟点击

  1. @echo off
  2. setlocal EnableDelayedExpansion
  3. set /a loop_times=10
  4. adb remount
  5. for /l %%i in (1,1,!loop_times!) do (
  6. echo **********%%i**********
  7. call :loop
  8. )
  9. pause
  10. ::循环体
  11. :loop
  12. adb shell input tap 500 500
  13. :wait 3
  14. adb shell input swipe 500 1000 500 0
  15. :wait 3
  16. call :screenshot
  17. :wait 2
  18. goto:eof
  19. ::截屏
  20. :screenshot
  21. adb shell screencap -p /sdcard/1.png
  22. adb pull /sdcard/1.png 1.png
  23. set date_temp=%date:~0,10%
  24. set time_temp=%time:~0,12%
  25. set time_temp=%time_temp::=-%
  26. set time_temp=%time_temp:.=-%
  27. set t=%date_temp:/=-%_%time_temp: =0%
  28. echo %t%
  29. set filename=%t%.png
  30. ren 1.png %filename%
  31. goto:eof
  32. ::等待
  33. :wait
  34. choice /T %1 /C ync /CS /D y /n
  35. ::ping 127.0.0.1 -n 1 >nul
  36. goto:eof

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/56334
推荐阅读
相关标签
  

闽ICP备14008679号