首页 > 其他分享 >关于ADB命令工具

关于ADB命令工具

时间:2023-01-28 16:34:33浏览次数:62  
标签:shell settings -- 命令 ADB allow time adb 工具

android提供了不少命令行工具,方便我们调试和查看信息.下面是frameworks/base/cmds(android 6.0.1)中的命令.

$ tree cmds -L 1

cmds

am├── appops├── app_process├── appwidget├── backup├── bmgr├── bootanimation├── bu├── content

├── dpm├── hid├── idmap├── ime├── input├── interrupter├── media├── pm├── requestsync├── screencap

├── settings├── sm├── svc├── telecom├── uiautomator├── wm

上面每一个目录都是一个/一组命令.其中svc中包括power, data, wifi, usb, nfc这些开关.

这里只列举一些我平时可能用的到的命令(am, appops, ime, input, pm, screencap, settings, svc, uiautomator, wm)来演示.先从简单的开始.

 

ime

ime是和输入法相关的,可以通过它来启用/设置输入法,也可以列出手机中已有的输入法. 

$ adb shell ime list -s
com.sohu.inputmethod.sogou/.SogouIME
com.google.android.inputmethod.pinyin/.PinyinIME
com.sohu.inputmethod.sogou.xiaomi/.SogouIME

 

input

input命令可以模拟输入

比如我们想在输入框内输入123

adb shell input text 123

注意,要满足几点,首先要聚焦在输入框,另外最好使用原生输入法

 

我们也可以模拟系统按键,比如返回键

adb shell input keyevent KEYCODE_BACK

我们也可以模拟点击事件,比如点击x=900,y=150

$ adb shell input tap 900 150

 

wm

wm命令可以获得分辨率/屏幕密度等

$ adb shell wm size
Physical size: 1080x1920
$ adb shell wm density
Physical density: 480

还可以修改显示输入图像的比例,不过不知道有什么用,大家可以试试这个命令.

$ wm overscan 10,10,100,100
$ wm overscan reset

试过之后记得执行reset

 

screencap

screencap用来截屏

$ adb shell screencap -h
usage: screencap [-hp] [-d display-id] [FILENAME]
   -h: this message
   -p: save the file as a png.
   -d: specify the display id to capture, default 0.
If FILENAME ends with .png it will be saved as a png.
If FILENAME is not given, the results will be printed to stdout.

我们可以直接将截屏保存到电脑中

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

也可以将截图保存到sd卡中

$ adb shell 'cd sdcard; screencap -p screen.png'
$ adb shell ls -l sdcard/screen.png
-rw-rw---- root     sdcard_rw   197116 2016-06-21 11:49 screen.png

 

uiautomator

uiautomator可以用来做UI测试,也可以dump出当前UI结构.如果觉得hierarchy不好用,也可以试试这个命令.只不过结果是xml形式,信息也很全.

$ adb shell uiautomator 
Usage: uiautomator <subcommand> [options]

Available subcommands:

help: displays help message

runtest: executes UI automation tests
    runtest <class spec> [options]
    <class spec>: <JARS> < -c <CLASSES> | -e class <CLASSES> >
      <JARS>: a list of jar files containing test classes and dependencies. If
        the path is relative, it's assumed to be under /data/local/tmp. Use
        absolute path if the file is elsewhere. Multiple files can be
        specified, separated by space.
      <CLASSES>: a list of test class names to run, separated by comma. To
        a single method, use TestClass#testMethod format. The -e or -c option
        may be repeated. This option is not required and if not provided then
        all the tests in provided jars will be run automatically.
    options:
      --nohup: trap SIG_HUP, so test won't terminate even if parent process
               is terminated, e.g. USB is disconnected.
      -e debug [true|false]: wait for debugger to connect before starting.
      -e runner [CLASS]: use specified test runner class instead. If
        unspecified, framework default runner will be used.
      -e <NAME> <VALUE>: other name-value pairs to be passed to test classes.
        May be repeated.
      -e outputFormat simple | -s: enabled less verbose JUnit style output.

dump: creates an XML dump of current UI hierarchy
    dump [--verbose][file]
      [--compressed]: dumps compressed layout information.
      [file]: the location where the dumped XML should be stored, default is
      /sdcard/window_dump.xml

events: prints out accessibility events until terminated

dump当前UI结构

adb shell uiautomator dump sdcard/test.xml

 

settings

settings可以修改/获取系统设置信息

$ adb shell settings 
usage:  settings [--user NUM] get namespace key
        settings [--user NUM] put namespace key value
        settings [--user NUM] delete namespace key
        settings [--user NUM] list namespace

'namespace' is one of {system, secure, global}, case-insensitive
If '--user NUM' is not given, the operations are performed on the owner user.

比如我们想查看android_id

$ adb shell settings get secure android_id
1dbbe170f8995d89

查看wifi状态

$ adb shell settings get global wifi_on
1

查看日期是否是24小时制

$ adb shell settings get system time_12_24
24

 

svc

svc下面有一组命令,power, data, wifi, usb, nfc,可以控制其开关

例如:

$ svc wifi
svc wifi
Control the Wi-Fi manager
 
usage: svc wifi [enable|disable]
         Turn Wi-Fi on or off.

控制移动网络数据开关

$ adb shell svc data disable
$ adb shell svc data enable

 

appops

appops可以查看/修改权限相关信息

$ adb shell appops get com.android.phone 
VIBRATE: allow; time=+1d3h57m1s111ms ago; duration=+63ms
READ_CONTACTS: allow; time=+2h10m59s285ms ago
READ_SMS: allow; time=+2h10m49s858ms ago
WRITE_SMS: allow; time=+3m46s339ms ago
READ_ICC_SMS: allow; time=+2h10m49s859ms ago
WRITE_CLIPBOARD: allow; time=+10d2h24m17s819ms ago
WAKE_LOCK: allow; time=+5s122ms ago; duration=+14ms
READ_EXTERNAL_STORAGE: allow; time=+14h31m4s898ms ago
WRITE_EXTERNAL_STORAGE: allow; time=+14h31m4s898ms ago

$ adb shell appops get com.android.phone READ_CONTACTS
READ_CONTACTS: allow; time=+2h28m33s274ms ago

 

am和pm这两个命令应该算是最复杂也是最常用的了.我们可以通过am启动页面,发送广播等,可以通过pm列出手机中的app,启用禁用app等.当然有一些是需要root权限的.这里就不再介绍了.

android手机中的命令行工具不只这些,在frameworks/native/cmds中也有一些命令,比如我们常用的dumpsys

  • 查看电池所有相关信息
  • adb shell dumpsys battery
  • 模拟充电状态
  • adb shell dumpsys battery set status 2
  • 模拟非充电状态
  • adb shell dumpsys battery set status 1
  • 设置AC/USB/Wireless模式充电
  • adb shell dumpsys battery set ac/usb/wireless 1   -- 开启ac/usb/wireless充电
  • adb shell dumpsys battery set ac/usb/wireless 0   -- 关闭ac/usb/wireless充电
  • 模拟电池电量
  • adb shell dumpsys battery set level x   -- x表示电量 0-100之间取值
  • 模拟断开充电(Android6.0以上)
  • adb shell dumpsys battery unplug
  • 复位,恢复实际状态
  • adb shell dumpsys battery reset

 

标签:shell,settings,--,命令,ADB,allow,time,adb,工具
From: https://www.cnblogs.com/WoodHower/p/17063968.html

相关文章

  • U盘启动多系统工具Ventoy
    简单来说,Ventoy是一个制作可启动U盘的开源工具。有了Ventoy你就无需反复地格式化U盘,你只需要把ISO/WIM/IMG/VHD(x)/EFI等类型的文件直接拷贝到U盘里面就可以启动了,......
  • linux yum 命令错误常见记录
    [root@localhost~]#wget-O/etc/yum.repos.d/CentOS-Base.repohttps://mirrors.aliyun.com/repo/Centos-7.repo......
  • Go-24 golang命令行初始
    packagemainimport( "flag" "fmt" "os")//golang命令行初识;可以后面多多了解一下强大的命令行工具cobra//cobra工具推荐了解的地址:https://blog.csdn.net/qq......
  • 振弦采集模块配置工具VMTool的MODBUS 工具模块
    振弦采集模块配置工具VMTool的MODBUS工具模块(1)寄存器查看此功能模块提供标准的MODBUS协议寄存器显示及单个寄存器修改功能,通过点击扩展功能区的【MODBUS】标签切换......
  • redis集群之间数据迁移工具redis-migrate-tool测试
    1、学习背景,四川广电redis分布式缓存存在数据迁移,因此需要迁移对应的数据到新建集群;2、redis-migrate-tool特性1)快速,多线程2)支持异构迁移,支持twemproxy集群,rediscluste......
  • linux基本命令
    tail-1000fxx.out  实时查看文件catxx.out 查看文件more查看全部内容pwd 查看当前位置rm删除 rm-rf删除任何文件touch 创建文件grep过滤 参考:......
  • Anaconda3 安装和常用命令
    Anaconda3-2019.10-Windows-x86_64.exehttps://mirrors.bfsu.edu.cn/anaconda/archive/C:\Anaconda3>pythonPython3.7.4(default,Aug92019,18:34:13)[MSCv.1915......
  • 基于AbstractProcessor扩展MapStruct自动生成实体映射工具类
    作者:京东物流王北永姚再毅1背景日常开发过程中,尤其在DDD过程中,经常遇到VO/MODEL/PO等领域模型的相互转换。此时我们会一个字段一个字段进行set|get设置。要么使......
  • 基于AbstractProcessor扩展MapStruct自动生成实体映射工具类
    作者:京东物流王北永姚再毅1背景日常开发过程中,尤其在DDD过程中,经常遇到VO/MODEL/PO等领域模型的相互转换。此时我们会一个字段一个字段进行set|get设置。要么使用工具类......
  • Linux find 命令
    Linuxfind命令用来在指定目录下查找文件。任何位于参数之前的字符串都将被视为欲查找的目录名。如果使用该命令时,不设置任何参数,则find命令将在当前目录下查找子目录与......