zoukankan      html  css  js  c++  java
  • ADB高级应用

    ADB高级应用

    一、利用无线来查看adb shell

    > adb tcpip 5555

    连接:
    > adb connect IP:5555

    见后文《调试注意事项

    二、模拟按键

     > adb shell input keyevent "value"

    部分常见按键相应值:
    Key  | Constant Value
    Back 4
    Power 26
    Menu 82
    Home 3
    Search 84

    方向键:
    上 19
    下 20
    左 21
    右 22
    确认(类似单击):23

    三、adb shell下查看系统盘符

     > adb shell df
     

    四、adb shell下挂载系统

    > adb shell
    > busybox mount -o remount,rw /system


    五、adb shell 下移除USB设备

    > adb shell
    > vdc unshare /mnt/sdcard ums


    六、adb shell 下查看内核信息

    > cat /proc/kmsg &

    七、查看build配置的值(以heap为例)

    > adb shell getprop | grep heap

    八、通过sendevent 模拟按键以及鼠标


    直接用input实现:
    > adb shell input keyevent 3
    > adb shell input tap 250 250
    > adb shell input swipe 250 250 300 300


    九、查看屏幕显示的fps

    开启系统属性:debug.sf.fps=1
    然后直接logcat -s SurfaceFlinger -v time
    (看SurfaceFlinger里面打印出来时多少)


    十、查看当前执行程序栈


    > dumpsys window windows | busybox grep "Window #" 


    十一、查看当前设备DDR执行频率

    > cat /proc/clocks | busybox grep "ddr"

    十二:ADB logcat过滤

    adb logcat -s TAG_NAME
    adb logcat -s TAG_NAME_1 TAG_NAME_2
    adb logcat “*:PRIORITY”
    adb logcat -s TAG_NAME:PRIORITY
    adb logcat -s TAG_NAME_1:PRIORITY_1 TAG_NAME_2:PRIORITY

    优先级(PRIORITY)分为下面几种:

    V – Verbose
    D – Debug
    I – Info
    W – Warning
    E – Error
    F – Fatal
    S – Silent

    范例:
    > adb logcat *:E 查看异常信息
    > adb logcat -s "TAG"    过滤TAG

    十三:查看设备是否拥有su权限(4.2及之前版本号)

    > adb shell
    > ps
    # 会列出系统进程
    # 选一个u开头的 表示普通程序
    > su u0_a8
    #切换到u0_a8下 #号变 >
    > su
    #假设能够运行。>号为#号,则表示有su权限,假设提示权限问题。就没有su权限


    十四:查看应用引用

    adb 查看Android应用全部引用
     
    > adb shell
    > ps  (查看PID号)
    > cd /proc/PID号/fd
    > busybox ls -l
     
    也将文件拷贝出来
    > cat xxx > /sdcard/xxx

    十五:获取执行内存/CPU信息

    > adb shell
    > cat /proc/meminfo
    > cat /proc/cpuinfo

    十六:抓取Logcat信息及kmsg信息

     # cat proc/kmsg >/data/kmsg.txt & 
     # logcat -v time >/data/logcat.txt &

    十七:查看Android(手机平板开发板等)设备信息

    > adb shell dumpsys package > package.xml

           (此命令可显示手机(平板)可供应用查询到的library和feature)




    十八、输出全部已经安装的应用

    > adb shell pm list packages -f




    十九、查看预安apk


    > adb shell pm list packages -3

    二十:清除logcat缓冲区

    (用这个命令来清除一些反复出现的过时的日志)
    > adb logcat -c

    二十一、眼下觉得最牛的adb命令:截取屏幕图片

    截图直接保存到电脑

    $ adb shell screencap -p | sed 's/
    $//' > screen.png
    

    运行adb shell 将 转换 , 因此须要用sed删除多余的

    假设直接当命令用还能够用 alias 包裝装起來

    $ alias and-screencap="adb shell screencap -p | sed 's/
    $//'"
    $ and-screencap > screen.png 
    

    以后就能够方便的用and-screencap > 直接将截图保存到电脑上了




    其它入门级但也比較常见的adb命令

    1、查看全部已经连接上的设备

    adb devices 

    假设有多个设备连接到电脑,能够通过 adb -s DEVICE_ID 来指定用哪一个

    2、挂载system分区(当然须要设备支持)

    adb remount

    3、安装与卸载应用

    adb install <apk文件路径>
    adb install -r <apk文件路径>     通过install命令来安装apk文件,-r參数能够又一次安装某个应用并保留应用数据

    #举例
    adb install -r ~/chrome.apk

    卸载应用:
    adb uninstall <软件名>
    adb uninstall -k <软件名>         假设加 -k 參数,为卸载软件可是保留配置和缓存文件
    #举例
    adb uninstall com.android.chrome

    4、启动一个Activity

    adb shell am start 包名/.类名
    adb shell am start 包名/类的全名

    5、登录设备shell

    adb shell  --这个命令将登录设备的shell.
    adb shell <command命令>      后面加<command命令>将是直接执行设备命令, 相当于执行远程命令


    6. 从电脑上发送文件到设备

             --用push命令能够把本机电脑上的文件或者目录拷贝到设备(手机)

    adb remount     ## remount '/system'分区 as read-write

    adb push <本地路径> <远程路径>


    7. 从设备上下载文件到电脑

             --用pull命令能够把设备(手机)上的文件或者目录拷贝到本机电脑

    adb pull <远程路径> <本地路径> 


    8. 显示帮助信息(包含各种命令使用方法与含义) 

    adb help




    引用:

    其它引用:

    1.模拟功能按键
    命令格式:adb shell sendevent [device] [type] [code] [value]

    如: adb shell sendevent /dev/input/event0 1 229 1 代表按下按下menu键

    adb shell sendevent /dev/input/event0 1 229 0 代表按下松开menu键

    说明:上述的命令需组合使用

    另外所知道的命令例如以下:

    Key Name CODE

    MENU 229

    HOME 102

    BACK (back button) 158

    CALL (call button) 231

    END (end call button) 107


    2. 发送鼠标事件(Touch):

    命令格式:adb shell sendevent [device] [type] [code] [value]


    情况1:在某坐标点上touch

    如在屏幕的x坐标为40,y坐标为210的点上touch一下,命令例如以下

    adb shell sendevent /dev/input/event0 3 0 40

    adb shell sendevent /dev/input/event0 3 1 210

    adb shell sendevent /dev/input/event0 1 330 1 //touch

    adb shell sendevent /dev/input/event0 0 0 0 //it must have

    adb shell sendevent /dev/input/event0 1 330 0 //untouch

    adb shell sendevent /dev/input/event0 0 0 0 //it must have

    注:以上六组命令必须配合使用,缺一不可


    情况2:模拟滑动轨迹(可下载并採用aPaint软件进行试验)

    例如以下例是在aPaint软件上画出一条開始于(100,200),止于(108,200)的水平直线

    adb shell sendevent /dev/input/event0 3 0 100 //start from point (100,200)

    adb shell sendevent /dev/input/event0 3 1 200

    adb shell sendevent /dev/input/event0 1 330 1 //touch

    adb shell sendevent /dev/input/event0 0 0 0

    adb shell sendevent /dev/input/event0 3 0 101 //step to point (101,200)

    adb shell sendevent /dev/input/event0 0 0 0

    …………………… //must list each step, here just skip

    adb shell sendevent /dev/input/event0 3 0 108 //end point(108,200)

    adb shell sendevent /dev/input/event0 0 0 0

    adb shell sendevent /dev/input/event0 1 330 0 //untouch

    adb shell sendevent /dev/input/event0 0 0 0


    调试注意事项

    当调试那些使用了USB外设和主机特性的应用时,你非常有可能把你的USB硬件连接到你的Android设备上。这将阻止你通过USB建立adb到Android设备的连接。

    你通过网络仍能够訪问adb。

    通过网络连接adb:

    1. 通过USB将Android设备连接到电脑。
    2. 从SDK 的 platform-tools 文件夹,在命令行输入adb tcpip 5555
    3. 输入:adb connect <设备的IP地址>:5555 。你如今将被连接到Android设备并能像adb logcat一样发出通用的adb命令。
    4. 要设置你的设备监听USB,输入adb usb 。



  • 相关阅读:
    技术期刊 · 白日照耀开鸿蒙 | 深入鸿蒙 ACE UI 框架解析;无限循环的 useEffect 类型;用 Three.js 实现 3D 房间;图神经网络入门;超基础的机器学习入门-原理篇
    青岛敏捷之旅,来了!
    痞子衡嵌入式:借助Serial Plot软件测量i.MXRT系列FlexSPI驱动Flash页编程执行时间分布
    痞子衡嵌入式:超级下载算法RT-UFL v1.0在Segger Ozone下的使用
    痞子衡嵌入式:超级下载算法RT-UFL v1.0在Keil MDK下的使用
    痞子衡嵌入式:超级下载算法RT-UFL v1.0在IAR EW for Arm下的使用
    痞子衡嵌入式:超级下载算法RT-UFL v1.0在MCUXpresso IDE下的使用
    《痞子衡嵌入式半月刊》 第 42 期
    痞子衡嵌入式:i.MXRT全系列下FlexSPI外设AHB Master ID定义与AHB RX Buffer指定的异同
    CDP客户数据管理平台体系化搭建
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/5154046.html
Copyright © 2011-2022 走看看