#2023盲盒+码# hdc及shell命令进阶使用指南:锁屏、解锁、返回、屏幕常亮等实用操作 原创

westinyang
发布于 2023-8-25 01:57
浏览
1收藏

【本文正在参加 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

关机、重启、重启到BL

# 关机
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

查看UDID

hdc shell bm get -u

发送接收文件

hdc file send 电脑文件/文件夹路径 设备文件/文件夹路径
hdc file recv 设备文件/文件夹路径

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
已于2023-8-25 12:26:46修改
2
收藏 1
回复
举报
回复
    相关推荐