
回复
【本文正在参加 2023「盲盒」+码有奖征文活动】 https://ost.51cto.com/posts/25284
@toc
本文提到的内容,适用于OpenHarmony3.2+
在官方文档中,有讲到hdc基本使用说明,aa/bm等工具的使用,以及有关系统、文件、网络相关的命令,但还是有一些命令未提及或者描述的不够详细,那本文讲到的一些hdc或shell命令使用技巧,是我在近半年探索研究过程中的一个汇总整理,作为一定的补充指导,希望能对你有所帮助~
# 锁屏
hdc shell power-shell suspend
# 亮屏
hdc shell power-shell wakeup
假如你的设备分辨率为:1080 * 2340,如果不是那请自行调整下,滑动距离仅供参考,当然你也可以写个脚本自动计算处理
540 = 1080 * 0.5
1755 = 2340 * 0.75
585 = 2340 * 0.25
# 参数说明:-m 起点x 起点y 终点x 终点y 时间
hdc shell uinput -T -m 540 1755 540 585 1
另外,此命令也可以用于其他场景的滑动测试或演示,理论上官方的 DevEco Testing 工具应该也是这样实现的~
相当于按下设备底部导航栏中的返回按钮,实际上 uinput 提供了 鼠标、键盘、触摸 等等操作,如果感兴趣的话可以自行进一步的研究~
hdc shell uinput -K -d 2 -u 2
# 安装(不能包含中文路径)
hdc app instal hap包完整路径
# 打开
hdc shell aa start -a 启动AbilityName -b 应用包名
# 关闭
hdc shell aa force-stop 应用包名
# 卸载
hdc app uninstall 应用包名
# 查看指定已安装应用的详细信息(非常实用)
hdc shell bm dump -n 应用包名
# 查看所有已安装应用的包名和启动AbilityName(非常实用)
hdc shell wukong appinfo
-s 参数为亮度值,取值范围:0~100
hdc shell power-shell display -s 0
# 设置电源模式为性能模式,屏幕常亮
hdc shell power-shell setmode 602
# 恢复为默认模式
hdc shell power-shell setmode 600
# 拉取截屏
hdc file recv /storage/media/100/local/files/Pictures/Screenshots
# 拉取录屏
hdc file recv /storage/media/100/local/files/Pictures/Videos
# 关机
hdc shell reboot shutdown
# 重启
hdc shell reboot
# 重启到BL
hdc shell reboot bootloader
hdc shell mount -o remount,rw /
hdc shell cat /system/etc/param/ohos_const/ohos.para
hdc shell cat /system/etc/param/ohos.para
输出示例
const.ohos.version.security_patch=2023/08/01
const.ohos.releasetype=Release
const.ohos.apiversion=9
const.ohos.fullname=OpenHarmony-3.2.14.6
...
hdc shell "snapshot_display -f /data/0.jpeg"
hdc file recv /data/0.jpeg
hdc shell bootanimation
hdc shell bm get -u
hdc file send 电脑文件/文件夹路径 设备文件/文件夹路径
hdc file recv 设备文件/文件夹路径