一、hdc

1、设备

hdc 帮助手册

> hdc -h

                         OpenHarmony device connector(HDC) ...

---------------------------------global commands:----------------------------------
 -h/help                               - Print hdc help
 -v/version                            - Print hdc version
 -l 0-5                                - Set runtime loglevel
 -t connectkey                         - Use device with given connect key
 checkserver                           - check client-server version
 checkdevice                           - check server-daemon version

---------------------------------component commands:-------------------------------
session commands(on server):
 discover                              - Discover devices listening on TCP via LAN broadcast
 list targets [-v]                     - List all devices status, -v for detail
 tconn key                             - Connect device via key, TCP use ip:port
                                         example:192.168.0.100:10178/192.168.0.100
                                         USB connect automatic, TCP need to connect manually

                                         UART connect need connect manually.
                                         Baud Rate can be specified with commas.
                                         key format: <Port Name>[,Baud Rate]
                                         example: tconn COM5,921600
                                         Default Baud Rate is 921600.

 start [-r]                            - Start server. If with '-r', will be restart server
 kill [-r]                             - Kill server. If with '-r', will be restart server
 -s [ip:]port                          - Set hdc server listen config

service commands(on daemon):
 target mount                          - Set /system /vendor partition read-write
 target boot [-bootloader|-recovery]   - Reboot the device or boot into bootloader\recovery.
 target boot [MODE]                    - Reboot the into MODE.
 smode [-r]                            - Restart daemon with root permissions, '-r' to cancel root
                                         permissions
 tmode usb                             - Reboot the device, listening on USB
 tmode port [port]                     - Reboot the device, listening on TCP port

---------------------------------task commands:-------------------------------------
file commands:
 file send [option] local remote       - Send file to device
 file recv [option] remote local       - Recv file from device
                                         option is -a|-s|-z
                                         -a: hold target file timestamp
                                         -sync: just update newer file
                                         -z: compress transfer
                                         -m: mode sync

forward commands:
 fport localnode remotenode            - Forward local traffic to remote device
 rport remotenode localnode            - Reserve remote traffic to local host
                                         node config name format 'schema:content'
                                         examples are below:
                                         tcp:<port>
                                         localfilesystem:<unix domain socket name>
                                         localreserved:<unix domain socket name>
                                         localabstract:<unix domain socket name>
                                         dev:<device name>
                                         jdwp:<pid> (remote only)
 fport ls                              - Display forward/reverse tasks
 fport rm taskstr                      - Remove forward/reverse task by taskstring

app commands:
 install [-r] src                      - Send package(s) to device and install them
                                         src examples: single or multiple packages and directories
                                         (.hap)
                                         -r: replace existing application
 uninstall [-k] package                - Remove application package from device
                                         -k: keep the data and cache directories

debug commands:
 hilog [-v]                            - Show device log, -v for detail
 shell [COMMAND...]                    - Run shell command (interactive shell if no command given)
 bugreport [PATH]                      - Return all information from the device, path will be save localpath
 jpid                                  - List pids of processes hosting a JDWP transport
 sideload [PATH]                       - Sideload the given full OTA package

security commands:
 keygen FILE                           - Generate public/private key; key stored in FILE and FILE.pub

---------------------------------flash commands:------------------------------------
flash commands:
 update packagename                    - Update system by package
 flash [-f] partition imagename        - Flash partition by image
 erase [-f] partition                  - Erase partition
 format [-f] partition

安装/卸载 APP

#安装HAP
hdc install [hap path] 

#卸载HAP
hdc uninstall [packageName]

#!!!注意,当卸载系统app时,可能出现以下报错,需要修改/system/etc/app/install_list.json
#源码位于vendor\hihope\rk3568\preinstall-config\install_list.json
hdc uninstall com.ohos.camera
[Info]App uninstall path:, queuesize:0, msg:error: failed to uninstall bundle. error: uninstall system app error.
AppMod finish

#修改/system/etc/app/install_list.json, 将removable改为true,使得camera可卸载
		...
        {
            "app_dir" : "/system/app/com.ohos.camera",
-           "removable" : false
+          "removable" : true
        },
        ...

查看当前连接设备

#查看当前连接所有设备,-v 显示详情
> hdc list targets (-v)
7001005458323933328a59612f4b3900		#设备为DAYU200 rk3568

重启设备

> hdc shell reboot	#串口命令下直接输入reboot即可

设置屏幕旋转

源码路径:

#foundation/window/window_manager/resources/config/${product}/display_manager_config.xml

#修改系统显示配置文件/system/etc/window/resources/display_manager_config.xml  buildInDefaultOrientation配置项,如下
    <!-- Indicates orientation of the built-in screen -->
    <!-- 0: Orientation::UNSPECIFIED -->	#未指明
    <!-- 1: Orientation::VERTICAL	# 竖屏        2: Orientation::HORIZONTAL-->	#横屏
    <!-- 3: Orientation::REVERSE_VERTICAL	#反竖屏 4: Orientation::REVERSE_HORIZONTAL -->	#反横屏
    <buildInDefaultOrientation>0</buildInDefaultOrientation>
#Step1、获取display_manager_config.xml配置文件到本地
> hdc file recv /system/etc/window/resources/display_manager_config.xml C:\Users\xxx\Desktop\hdcLog
#Step2、修改本地display_manager_config.xml buildInDefaultOrientation配置项
...
<buildInDefaultOrientation>3</buildInDefaultOrientation>	#由于DAYU200 DEBUG线、USB线与电脑连接原因,为了操作方便将屏幕设为反竖屏
...
#Step3、替换设备的display_manager_config.xml
> hdc shell mount -o remount,rw /
> hdc shell chmod 777 /system/etc/window/resources/display_manager_config.xml
> hdc file send C:\Users\xxx\Desktop\hdcLog\display_manager_config.xml /system/etc/window/resources/display_manager_config.xml
#Step4、重启设备
> hdc shell reboot

power-shell

>hdc shell power-shell
usage: power-shell
command list:
  setmode :    Set power mode.	#设置电源模式
  wakeup  :    Wakeup system and turn screen on.	#唤醒系统,点亮屏幕
  suspend :    Suspend system and turn screen off.	#系统待机,熄灭屏幕
  display :    Update or Override display brightness.	#更新或覆盖屏幕亮度
  timeout :    Override or Restore screen off time.	#覆盖或重置熄屏时间
  dump    :    Dump power info.	#查看电源信息
  help    :    Show this help menu.	#展示帮助菜单
设置电源模式/电源管理,例如屏幕常亮

方法一:命令设置电源性能模式,保持屏幕常亮

注意:重启后需要重新设置,源码修改见底部

#设置性能模式,屏幕常亮;	600:正常模式	601:省电模式	602:性能模式	603:极省电模式
> hdc shell power-shell setmode 602

方法二:修改设备电源管理配置文件power_mode_config.xml (原理可行,但实际无效,望大佬指点)

#Step1、获取power_mode_config.xml配置文件到本地
> hdc file recv /system/etc/power_config/power_mode_config.xml C:\Users\xxx\Desktop\hdcLog
#Step2、修改本地power_mode_config.xml 各个电源模式的DisplayOffTime 配置项设为-1,即功能关闭
<!--
    Power Mode Definitions:	#电源模式定义
    MODE_NORMAL = 600,	#正常模式
    MODE_POWER_SAVE = 601,	#省电模式
    MODE_PERFORMANCE = 602,	#性能模式
    MODE_EXTREME_POWER_SAVE = 603,	#极省电模式
-->
<!--
    Action Definitions:	#行为定义
    DisplayOffTime = 101,	#熄屏延时
    SystemAutoSleepTime = 102,	#系统自动休眠延时
    AutoAdjustBrightness = 103,	#自动调节亮度
    AutoWindowRotation = 107,	#自动横竖屏切换
    SystemBrightness = 115,	#系统默认亮度
    VibratorsState = 120,	#默认马达状态
-->
<switch_proxy version="1">
    <proxy id="600">
-       <switch id="101" value="30000" recover_flag="0"/>
+       <switch id="101" value="-1" recover_flag="0"/>
        <switch id="102" value="0" recover_flag="0"/>
        <switch id="103" value="-1" recover_flag="0"/>
        <switch id="107" value="1" recover_flag="0"/>
        <switch id="115" value="102" recover_flag="0"/>
        <switch id="120" value="1" recover_flag="0"/>
    </proxy>
    <proxy id="601">
-       <switch id="101" value="10000" recover_flag="0"/>
+       <switch id="101" value="-1" recover_flag="0"/>
        <switch id="102" value="5000" recover_flag="0"/>
        <switch id="103" value="-1" recover_flag="0"/>
        <switch id="107" value="-1" recover_flag="0"/>
        <switch id="115" value="50" recover_flag="0"/>
        <switch id="120" value="-1" recover_flag="0"/>
    </proxy>
    <proxy id="602">
        <switch id="101" value="-1" recover_flag="0"/>
        <switch id="102" value="-1" recover_flag="0"/>
        <switch id="103" value="-1" recover_flag="0"/>
        <switch id="107" value="1" recover_flag="0"/>
        <switch id="115" value="255" recover_flag="0"/>
        <switch id="120" value="1" recover_flag="0"/>
    </proxy>
    <proxy id="603">
-       <switch id="101" value="5000" recover_flag="0"/>
+       <switch id="101" value="-1" recover_flag="0"/>
        <switch id="102" value="1000" recover_flag="0"/>
        <switch id="103" value="-1" recover_flag="0"/>
        <switch id="107" value="-1" recover_flag="0"/>
        <switch id="115" value="25" recover_flag="0"/>
        <switch id="120" value="-1" recover_flag="0"/>
    </proxy>
</switch_proxy>
#Step3、替换设备的power_mode_config.xml
> hdc shell mount -o remount,rw /
> hdc shell chmod 777 /system/etc/power_config/power_mode_config.xml
> hdc file send C:\Users\xxx\Desktop\hdcLog\power_mode_config.xml /system/etc/power_config/power_mode_config.xml
#Step4、重启设备
> hdc shell reboot

如果想一劳永逸,可修改源码后编译即可。 源码路径:

base\powermgr\power_manager\services\native\profile\power_mode_config.xml

获取/设置设备param

查看param帮助手册

param --help
Command not found
Command list:
    param ls [-r] [name]                            --display system parameter			//显示某个或所有系统参数信息
    param get [name]                                --get system parameter				//获取某参数信息
    param set name value                            --set system parameter			//设置某参数值
    param wait name [value] [timeout]               --wait system parameter	//
    param dump [verbose]                            --dump system parameter
    param shell [name]                              --shell system parameter

////////////////////////////////////////////////////////////////////////////////////

//查看系统参数persist.sys.hilog.debug.on信息
# param ls -r persist.sys.hilog.debug.on
Parameter information:
selinux  : u:object_r:hilog_param:s0			//selinux权限信息
    dac  : shell(rww) log(rww) (r-w)			//(Discretionary Access Control)自主访问控制方式管理
    name : persist.sys.hilog.debug.on			//param名称
    value: false												//param当前值

//获取系统参数persist.sys.hilog.debug.on值
# param get persist.sys.hilog.debug.on
false

//设置系统参数persist.sys.hilog.debug.on值为true,并param get确认
# param set persist.sys.hilog.debug.on true
Set parameter persist.sys.hilog.debug.on true success
# param get persist.sys.hilog.debug.on
true

#查看系统运行bit模式
param get const.product.cpu.abilist
arm64-v8a

dac(Discretionary Access Control)

模拟操作

uinput用于输入模拟操作,其命令帮助手册为:

> hdc shell uinput --help
Usage: uinput <option> <command> <arg>...
The option are:
-M  --mouse			//模拟鼠标操作
commands for mouse:
-m <dx> <dy>              --move   <dx> <dy>  -move to relative position (dx,dy),		////模拟鼠标移动
   <dx1> <dy1> <dx2> <dy2> [soomth time] --trace -dx1 dy1 to dx2 dy2 smooth movement
-d <key>                  --down   key        -press down a button,	//模拟鼠标按键按下,0是左键,1是右键,2是中键
                                               0 is the left button, 1 is the right,
                                               2 is the middle
-u <key>                  --up     <key>      -release a button		//模拟鼠标按键弹起(松开)
-c <key>                  --click  <key>      -press the left button down,then raise	////模拟鼠标左键点击(按下并弹起)
-b <dx1> <dy1> <id> [press time] [click interval time]                --double click	//模拟左键鼠标双击
  [press time] the time range is more than 1ms but less than 300ms,
  [click interval time] the time range is more than 1ms but less than 450ms,
  Otherwise the operation result may produce error or invalid operation
 -press the left button down,then raise
   key value:0 - button left
   key value:1 - button right
   key value:2 - button middle
   key value:3 - button side
   key value:4 - button extra
   key value:5 - button forward
   key value:6 - button back
   key value:7 - button task
-s <key>                  --scroll <key>      -positive values are sliding backwards	//模拟鼠标滚轮按键,正值表示滚轮向后滑
-i <time>                 --interval <time>   -the program interval for the (time) milliseconds
                                               negative values are sliding forwards

-K  --keyboard			//模拟键盘按键操作
commands for keyboard:
-d <key>                   --down   <key>     -press down a key			//模拟按键按下
-u <key>                   --up     <key>     -release a key			//模拟按键弹起
-l <key> [long press time] --long_press <key> [long press time] -press and hold the key		//模拟按键长按
-i <time>                  --interval <time>  -the program interval for the (time) milliseconds		//设置按键操作间隔时长

-T  --touch			//模拟触摸操作
commands for touch:
-d <dx1> <dy1>             --down   <dx1> <dy1> -press down a position  dx1 dy1,		//模拟触摸按下
-u <dx1> <dy1>             --up     <dx1> <dy1> -release a position dx1 dy1,			//模拟触摸弹起
-m <dx1> <dy1> <dx2> <dy2> [smooth time]      --smooth movement		//模拟触摸滑动
   <dx1> <dy1> <dx2> <dy2> [smooth time]      -smooth movement,
                                              dx1 dy1 to dx2 dy2 smooth movement
-c <dx1> <dy1> [click interval]               -touch screen click dx1 dy1		//模拟触摸点击
-i <time>                  --interval <time>  -the program interval for the (time) milliseconds		//设置触摸操作延时
-g <dx1> <dy1> <dx2> <dy2> [press time] [total time]     -drag,
  [Press time] not less than 500ms and [total time] - [Press time] not less than 500ms
  Otherwise the operation result may produce error or invalid operation

-?  --help
模拟按键
//模拟back按键
> hdc shell uinput -K -d 2 -u 2		//按下和弹起键值为2的按键(即back键)
you raised the key 2

注意:使用时需按下(-d)和弹起(-u)成对 按键键值定义在@ohos.multimodalInput.keyCode包中,常用的按键如下:

Key

Keycode

KEYCODE_HOME

1

KEYCODE_BACK

2

KEYCODE_VOLUME_UP

16

KEYCODE_VOLUME_DOWN

17

KEYCODE_POWER

18

KEYCODE_VOLUME_MUTE

22

KEYCODE_DPAD_UP = 2012

2012

KEYCODE_DPAD_DOWN

2013

KEYCODE_DPAD_LEFT

2014

KEYCODE_DPAD_RIGHT

2015

KEYCODE_DPAD_CENTER

2016

调出输入法选择框

> hdc shell aa start ability -a InputMethod -b cn.openharmony.inputmethodchoosedialog

2、文件

获取文件到本地

> hdc file recv /system/etc/window/resources/display_manager_config.xml C:\Users\xxx\Desktop\hdcLog

发送文件到设备

#挂载系统根目录
> hdc shell mount -o remount,rw /
#若display_manager_config.xml文件只读,无权限操作,需更改其权限
> hdc shell chmod 777 /system/etc/window/resources/display_manager_config.xml
#替换设备display_manager_config.xml文件
> hdc file send C:\Users\xxx\Desktop\hdcLog\display_manager_config.xml /system/etc/window/resources/display_manager_config.xml

替换开机logo

开机logo文件源码路径: device\board\hihope\rk3568\kernel\logo.bmp device\board\hihope\rk3568\kernel\logo_kernel.bmp 由于替换后增量编译对应的img文件未更新,因此需要单独编译后更新或删除/out重新编译-打包-烧录

注意:开机logo图片对分辨率和文件格式要求未知,替换需谨慎

替换开机动画

开机动画文件源码路径: foundation/graphic/graphic_2d/frameworks/bootanimation/data/bootpic.zip

#挂载系统根目录
> hdc shell mount -o remount,rw /
#修改bootpic.zip权限
> hdc shell chmod 777 /system/etc/init/bootpic.zip
#替换设备开机动画
> hdc file send C:\Users\xxx\Desktop\hdcLog\bootpic.zip /system/etc/init/bootpic.zip

注意:bootpic.zip中的文件夹名称及图片名称格式需保持一致

二、Serial-COM

设置电源模式、电源管理,例如屏幕常亮

power-shell setmode 602

重启设备

reboot

三、其他

获取应用签名指纹

  • 通过keytool获取应用签名指纹

使用DevEco Studio 编译应用后,查打开Sdk\9\toolchains\lib\UnsgnedReleasedProfileTemplate.json 将"distribution-certificate"密钥内容删除换行符\n 转换前:

-----BEGIN CERTIFICATE-----\nMIICFTCCAZmgAwIBAgIEIjxLgjAMBggqhkjOPQQDAwUAMGMxCzAJBgNVBAYTAkNO\nMRQwEgYDVQQKEwtPcGVuSGFybW9ueTEZMBcGA1UECxMQT3Blbkh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5EzKd9FnKy4xovepdkGm9qfsdFlmyaMbsiR2A6nx8uOyIirtqeyo1Iw
UDAdBgNVHQ4EFgQU5URk13C3jroyBHJ9E963wvoqqmcwDgYDVR0PAQH/BAQDAgeA
MB8GA1UdIwQYMBaAFNuGtyIW1QuhS7fdJXu58QV9oi1HMAwGCCqGSM49BAMDBQAD
aAAwZQIxANm1j8izuUyepsAodFc3/LxrPksUPHr3UISOxZJslxM4KHRTDMJ08Cmo
lE5lyMctzAIwHxWvM/qS1uXPQm+AzDXkg3V8kP7vDJi1/9bCi0/HSHSvh4MqgZDr
Othrrw/zfJ+w
-----END CERTIFICATE-----

将转换后的密钥保存至profile.cer 使用keytool获取应用SHA256签名指纹

> keytool -printcert -file xxx\ohos_signtool\profile.cer
所有者: C=CN, O=Organization, OU=Unit, CN=ide_demo_app
发布者: CN=OpenHarmony Application CA, OU=OpenHarmony Team, O=OpenHarmony, C=CN
序列号: 223c4b82
生效时间: Thu Jun 29 10:47:07 CST 2023, 失效时间: Sun Jun 26 10:47:07 CST 2033
证书指纹:
         SHA1: 7A:FA:B6:D6:9F:39:14:FC:AA:3C:82:95:7A:FE:54:91:13:61:B2:F3
         SHA256: 26:C1:E5:3D:03:97:AD:24:D2:2E:B4:F1:01:59:B0:4E:0B:F8:14:AF:C2:A0:9B:47:AE:98:6A:04:82:CE:23:8C
签名算法名称: SHA384withECDSA
主体公共密钥算法: 256 位 EC 密钥
版本: 3

扩展:

#1: ObjectId: 2.5.29.35 Criticality=false
AuthorityKeyIdentifier [
KeyIdentifier [
0000: DB 86 B7 22 16 D5 0B A1   4B B7 DD 25 7B B9 F1 05  ..."....K..%....
0010: 7D A2 2D 47                                        ..-G
]
]

#2: ObjectId: 2.5.29.15 Criticality=true
KeyUsage [
  DigitalSignature
]

#3: ObjectId: 2.5.29.14 Criticality=false
SubjectKeyIdentifier [
KeyIdentifier [
0000: E5 44 64 D7 70 B7 8E BA   32 04 72 7D 13 DE B7 C2  .Dd.p...2.r.....
0010: FA 2A AA 67                                        .*.g
]
]
  • 通过hilog获取应用签名指纹 设置hilog等级为Debug
> hdc shell hilog -b D
Set global log level to D successfully

DevEco Studio安装hap时过滤finger,得到含有签名指纹的log如下

OpenHarmony常用调试命令_OpenHarmony