查看当前链接的机器列表

1
adb devices

结果:

1
2
List of devices attached
9TBQLN7DEUYXT4GU unauthorized

我这个电脑只连接了一个手机,9TBQLN7DEUYXT4GU 代表这个设备的 id,如果连接的设备数超过了一个,之后执行其它命令就需要指定设备 id 了;unauthorized 代表设备现在是未验证的状态,手机被连接之后会在手机上弹一个允许 USB 调试的弹窗,需要你的授权,接受之后这里会变成 device 状态。

查找栈顶 Activity

1
adb shell dumpsys activity top | grep ACTIVITY

结果:

1
2
3
ACTIVITY com.tencent.mobileqq/.activity.SplashActivity 161c7a6 pid=27178
ACTIVITY com.miui.home/.launcher.Launcher 7e33f27 pid=27891
ACTIVITY com.tencent.mm/.ui.LauncherUI 47a8f86 pid=10807

说明:

  1. 手机查出的 Activity 一般有多个。会包括手机桌面 Activity 什么的。
  2. grep 是 linux 下一个正则匹配工具,adb shell 自带。
  3. top 表示位于栈顶。
  4. 你要找对应应用的栈顶 Activity 只需要在结果里找对应包名的信息就好了

抓取日志

1
2
adb logcat -c
adb logcat > /Users/shaolongfei/Downloads/time.log

第一句话是清楚之前的日志的,第二句话会持续抓取日志保存到目标文件,此后再 control+C 可以结束抓取。

卸载 APK

1
adb uninstall com.liuyue.demo

安装 APK

1
adb install /Users/shaolongfei/Downloads/demo.apk

拷贝文件

从手机到电脑:

1
adb pull /sdcard/screen.png /Users/shaolongfei/Downloads/test.png

还有一种方式是 adb copy ,使用方式和 adb pull 一样

从电脑到手机:

1
adb push /Users/shaolongfei/Downloads/test.png /sdcard/screen.png

截屏

1
adb shell screencap /sdcard/screen.png

后面的路径必须是手机上的路径,之后可以使用 adb pull 命令拷贝拿到文件

录屏

1
adb shell screenrecord /sdcard/sceen_record.mp4

经测试连接方式在仅充电情况下无法完成录制,录出来的文件大小都是 0 ,需要修改连接方式为 MIDI 才可以成功。

计算某一个目录下的文件总大小

如果计算外部文件的大小可以直接使用

1
adb shell du -sk /sdcard/cache

说明:

- -sk 是 -s 和 -k 的缩写
- -s 表示 "summarize" 的缩写,它会显示目录的总文件大小
- -k 表示 "kilobytes" 的缩写,它会将文件大小显示为千字节(KB),如果你想用 MB 显示的话可以使用 `-m`

但如果是一些应用内的目录,如 /data/data/com.eyepetizer.android/files/dcr 的话,它会告诉你 Permission denied,这时候你可以用 com.eyepetizer.android 的身份去获取

1
2
3
adb shell
run-as com.eyepetizer.android
du -sk /data/data/com.eyepetizer.android/files/dcr

手机信息

1
2
3
4
5
6
adb shell getprop ro.product.name 查看当前产品的名称
adb shell getprop ro.build.version.release 查看当前系统版本
adb shell getprop ro.product.cpu.abi 查看当前产品cpu架构
adb shell getprop ro.product.brand 手机厂商名称
adb shell getprop ro.product.model 手机型号
adb shell getprop ro.build.type 版本

结果:

1
2
3
4
5
6
7
8
9
10
11
12
➜ ~ adb shell getprop ro.product.name
matisse
➜ ~ adb shell getprop ro.build.version.release
13
➜ ~ adb shell getprop ro.product.cpu.abi
arm64-v8a
➜ ~ adb shell getprop ro.product.brand
Redmi
➜ ~ adb shell getprop ro.product.model
22011211C
➜ ~ adb shell getprop ro.build.type
user

查看手机屏幕信息

1
adb shell dumpsys display | grep DisplayDeviceInfo

结果:

1
DisplayDeviceInfo{"内置屏幕": uniqueId="local:0", 1440 x 3200, modeId 2, defaultModeId 1, supportedModes [{id=1, width=1440, height=3200, fps=60.0, alternativeRefreshRates=[120.00001]}, {id=2, width=1440, height=3200, fps=120.00001, alternativeRefreshRates=[60.0]}, {id=3, width=1080, height=2400, fps=120.00001, alternativeRefreshRates=[60.0]}, {id=4, width=1080, height=2400, fps=60.0, alternativeRefreshRates=[120.00001]}], colorMode 0, supportedColorModes [0, 7, 9], hdrCapabilities HdrCapabilities{mSupportedHdrTypes=[1, 2, 3, 4], mMaxLuminance=500.0, mMaxAverageLuminance=500.0, mMinLuminance=0.0}, allmSupported false, gameContentTypeSupported false, density 560, 525.879 x 525.879 dpi, appVsyncOff 1199999, presDeadline 14800000, cutout DisplayCutout{insets=Rect(0, 104 - 0, 0) waterfall=Insets{left=0, top=0, right=0, bottom=0} boundingRect={Bounds=[Rect(0, 0 - 0, 0), Rect(680, 0 - 760, 104), Rect(0, 0 - 0, 0), Rect(0, 0 - 0, 0)]} cutoutPathParserInfo={CutoutPathParserInfo{displayWidth=1440 displayHeight=3200 physicalDisplayWidth=1440 physicalDisplayHeight=3200 density={3.5} cutoutSpec={M 0,0 H -40 V 104 H 40 V 0 H 0 Z} rotation={0} scale={1.0} physicalPixelDisplaySizeRatio={1.0}}}}, touch INTERNAL, rotation 0, type INTERNAL, address {port=0}, deviceProductInfo null, state OFF, frameRateOverride , brightnessMinimum 0.0, brightnessMaximum 1.0, brightnessDefault 0.07496032, roundedCorners RoundedCorners{[RoundedCorner{position=TopLeft, radius=132, center=Point(132, 132)}, RoundedCorner{position=TopRight, radius=132, center=Point(1308, 132)}, RoundedCorner{position=BottomRight, radius=132, center=Point(1308, 3068)}, RoundedCorner{position=BottomLeft, radius=132, center=Point(132, 3068)}]}, FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY, FLAG_ROTATES_WITH_CONTENT, FLAG_SECURE, FLAG_SUPPORTS_PROTECTED_BUFFERS, installOrientation 0}

从给的信息可以看到分辨率大小一共支持 4 种:

  • id=1, width=1440, height=3200, fps=60.0
  • id=2, width=1440, height=3200, fps=120.00001
  • id=3, width=1080, height=2400, fps=120.00001
  • id=4, width=1080, height=2400, fps=60.0

目前选的是 modeId 2 ,默认为 defaultModeId 1

colorMode 0, supportedColorModes [0, 7, 9] 说明当前选择的色彩模式为默认,支持 0、7、9三种颜色模式

  • 0 - 默认模式
  • 7 - RGB565 色彩模式,16 位色彩,支持 65535 种颜色
  • 9 - ARGB8888 色彩模式,32 位色彩,支持 1677216 种颜色

HdrCapabilities 内包含的是屏幕的 HDR 信息,mSupportedHdrTypes=[1, 2, 3, 4] 代表屏幕支持 4 种 HDR 类型:

  • 1 - HDR10 标准的,这是目前最常见和广泛支持的 HDR 类型。HDR10 可以提供更丰富的色彩深度和亮度,支持最高10倍的动态幅度。
  • 2 - Dolby Vision 标准的,Dolby 公司提出的专业 HDR 标准,可以比 HDR10 提供更好的映像质量和画面细节。但是支持性较低,主要限于 Dolby Vision 认证的设备和内容。
  • 3、4 不知道是什么类型

mMaxLuminance=500.0, mMaxAverageLuminance=500.0, mMinLuminance=0.0

  • mMaxLuminance - 最大亮度,表示这个设备支持的最高光亮值,该值是 500 nit
  • mMaxAverageLuminance - 最大平均亮度也是 500 nit,应该与上一个参数意义相同
  • mMinLuminance - 最低亮度是 0 nit,表示能够支持全黑显示

查看电池信息

1
adb shell dumpsys battery

结果:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Current Battery Service state:
AC powered: true
USB powered: false
Wireless powered: false
Max charging current: 0
Max charging voltage: 0
Charge counter: 2754000
status: 2
health: 2
present: true
level: 70
scale: 100
voltage: 4041
temperature: 306
technology: Li-poly

解释:

  • AC powered: 是否使用 AC(交流电) 电源充电
  • USB powered: 是否通过 USB 充电
  • Wireless powered:是否通过无线充电
  • Max charging current 和 Max charging voltage 应该是表示设备支持的最大充电电流和电压,但是不知道为啥这里是 0
  • Charge counter:设备电池的充放电总次数,感觉这个值也很不符合常理,而且重新获取的话这个值会变
  • Status:电池当前状态,2 表示电量在正常水平
  • Health:电池健康状态,2 表示处于正常健康状态
  • Present:是否有电池存在
  • Level:当前电量百分比
  • Scale:最大的电量值
  • Voltage:电池电压,4041mV
  • Temperature:电池温度,这里用的应该是 kelvin 单位,转换过来是 33°C
  • Technology:电池技术类型,Li-poly表示锂聚合物电池