• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# hdc
2
3<!--Kit: Performance Analysis Kit-->
4<!--Subsystem: HiviewDFX-->
5<!--Owner: @kunsilva-->
6<!--Designer: @weimingjin-->
7<!--Tester: @gcw_KuLfPSbe-->
8<!--Adviser: @foryourself-->
9
10HarmonyOS Device Connector (hdc) is a command line tool used to interact with and debug devices, transmit data, view logs, and install applications. It can run on Windows, Linux, and MacOS to provide efficient and convenient device debugging capabilities.
11
12hdc consists of three parts:
13
14**client**: A process running on the PC. It starts when you run the hdc command and exits after the command is complete.
15
16**server**: A background service process running on the PC. It manages data interaction and device discovery between the client process and the daemon process on the device.
17
18**daemon**: A process running on the device for debugging. It is used to respond to requests sent by server.
19
20The following figure shows the relationship.
21
22![hdc_image_005](figures/hdc_image_005.PNG)
23
24> **NOTE**
25>
26> When the client starts, it checks whether the server is running by default. If not, a new hdc process is started as a server process and runs in the background.
27>
28> When the server is running, it listens for port 8710 on the computer by default. You can set the system environment variable **OHOS_HDC_SERVER_PORT** to listen for a port number ranging from 1 to 65535.
29
30## Environment Setup
31
32You can obtain hdc in any of the following ways:
33
341. SDK, which is embedded in [DevEco Studio](https://developer.huawei.com/consumer/en/deveco-studio/). No additional configuration is required. hdc is installed in **DevEco Studio/sdk/default/openharmony/toolchains** by default.
35
362. SDK directory of [Command Line Tools](https://developer.huawei.com/consumer/en/download/). hdc is installed in Command Line **Tools/sdk/default/openharmony/toolchains** by default.
37
38hdc supports both USB and wireless connections. You can enable or disable debugging in **Settings** > **System** > **Developer options** on the device. The setting takes effect immediately without restarting the device. If **Developer options** is not enabled, enable it by referring to [Developer Options](https://developer.huawei.com/consumer/en/doc/harmonyos-guides/ide-developer-mode#section530763213432). For details about the connection mode and procedure, see [USB Connection](#usb-connection) and [TCP Connection](#tcp-connection).
39
40### (Optional) Running hdc on CLI
41
42**Perform debugging in the installation directory**
43
44- You can run the hdc command in the **toolchains** subdirectory of the SDK to debug devices.
45
46- hdc can run independently. You can save the hdc executable file and **libusb_shared** dependency file in the **toolchains** subdirectory to a custom directory and run the hdc command in the custom directory to implement independent debugging.
47
48**Add hdc to the system environment variables**
49
50- On Windows:
51  1. Press the **Windows** key, enter **Settings** in the search box, and click to enter the **Settings** screen.
52  2. Search for **Advanced system settings**. In **Environment Variables** > **System Variables** > **Path**, click **Edit** to add the directory of **hdc.exe** to **Path**. After the environment variables are configured, restart the computer and run the hdc command in the CLI.
53
54- On Linux/macOS:
55  1. Start the terminal tool and run the following command:
56
57      ```shell
58      echo $SHELL
59      ```
60
61      1. If the command output is **bin/bash**, open the **.bashrc** file.
62
63          ```shell
64          vi ~/.bashrc
65          ```
66
67      2. If the command output is **/bin/zsh**, open the **.zshrc** file.
68
69          ```shell
70          vi ~/.zshrc
71          ```
72
73  2. Switch to the English input method and press **i** to enter the Insert mode.
74  3. Add the **PATH** information to the end of the file.
75
76      ```shell
77      PATH={DevEco Studio}/sdk/default/openharmony/toolchains:$PATH
78      ```
79
80      Replace **{DevEco Studio}** with the absolute path of the DevEco Studio installation directory, for example, **/home/DevEco-Studio**.
81  4. After the editing is complete, press **Esc** to exit the Insert mode, input **:wq**, and press **Enter** to save the file.
82  5. Run the following command for the environment variable to take effect.
83      1. If the **.bashrc** file is opened in **1**, run the following command:
84
85          ```shell
86          source ~/.bashrc
87          ```
88
89      2. If the **.zshrc** file is opened in **1**, run the following command:
90
91          ```shell
92          source ~/.zshrc
93          ```
94
95  6. After the environment variables are configured, restart the system.
96
97### (Optional) Configuring Server
98
99You can configure system environment variables to modify the listening port of the **server** process, logging level, or feature switch. For details, see [Options](#options).
100
101> **NOTE**
102>
103> After the environment variables are configured, restart the CLI or other software that uses HarmonyOS SDK for the new environment variable to take effect.
104
105## hdc Commands
106
107### Global Parameters
108
109Global parameters can be added between hdc and the command to be executed. For example, you can use the **-t** parameter to specify a device to run the command.
110
111```shell
112hdc -t connect-key shell echo "Hello world"
113```
114
115| Parameter| Description|
116| -------- | -------- |
117| [-t](#connecting-to-the-specified-target-device)| Connects to a specified target device based on the device ID. This parameter is optional when one device is connected and mandatory when multiple devices are connected.|
118| [-l](#server-logs) | (Optional) Specifies the log level when the device is running. The value ranges from 0 to 6. The default value is **3** (**LOG_INFO**).|
119| [-s](#remote-connection)| (Optional) Specifies the IP and port in **IP:port** format for listening when the client connects to the server.|
120| [-p](#quick-command-execution)| (Optional) Executes a client command without querying the server process.|
121| [-m](#starting-a-server-in-the-foreground)| (Optional) Starts the server process in the foreground.|
122| [-e](#creating-a-local-port-forwarding)| (Optional) Specifies the IP address for listening on the local host when TCP port forwarding is performed. The default value is **127.0.0.1**. This parameter must be used together with **-m**.<br>Note: This API is supported since API version 20.|
123
124### Commands
125
126| Command| Description|
127| -------- | -------- |
128| [list targets](#displaying-devices) | Displays all connected target devices.|
129| [wait](#waiting-for-device-connection)| Waits until the device is properly connected.|
130| [tmode usb](#switching-between-usb-debugging-and-wireless-debugging) | Since version 3.1.0e, this command is deprecated. You need to set the USB debugging on the device setting page.|
131| [tmode port](#enabling-the-network-connection-channel) | Enables the network connection channel of the device.|
132| [tmode port close](#disabling-the-network-connection-channel) | Disables the network connection channel of the device.|
133| [tconn](#connecting-to-a-device-over-tcp) | Specifies the device to connect based on **IP:port**.|
134| [shell](#running-interactive-commands)| Runs a command on the device, for example, **hdc shell ls**. If no command parameter is specified, you can run commands on the device terminal.|
135| [install](#installing-an-application) | Installs an application.|
136| [uninstall](#uninstalling-an-application)| Uninstalls a specified application.|
137| [file send](#sending-a-file-to-a-remote-device) | Sends a local file to a remote device.|
138| [file recv](#receiving-a-file-from-a-remote-device)| Receives a file from a remote device.|
139| [fport ls](#querying-the-port-forwarding-task-list)| Lists all port forwarding tasks.|
140| [fport](#creating-a-local-port-forwarding)| Sets up a local port forwarding, which forwards data from a local port to a remote port.|
141| [rport](#creating-a-remote-port-forwarding)| Sets up a remote port forwarding, which forwards data from a remote port to a local port.|
142| [fport rm](#deleting-a-port-forwarding-task)| Deletes a port forwarding task.|
143| [start](#starting-a-service) | Starts the hdc server process.|
144| [kill](#terminating-a-service) | Terminates the hdc server process.|
145| [hilog](#printing-device-logs)| Obtains device log information.|
146| [jpid](#displaying-pids-of-started-applications)| Displays the PIDs of started applications on the device.|
147| track-jpid [-a\|-p] | Displays the PIDs and names of started applications on the device in real time. Only applications with the **debug** tag can be debugged. If no parameter is specified, the PIDs of started applications are displayed. If the **-a** parameter is specified, the process tags of debug-type and release-type applications are displayed. If the **-p** parameter is specified, the process tags of debug-type and release-type applications are not displayed.|
148| [target boot](#restarting-the-target-device)| Restarts the target device.|
149| <!--DelRow--> [target mount](#mounting-the-system-partition-in-readwrite-mode) | Mounts the system partition in read/write mode. (This command is unavailable for non-root devices.)|
150| <!--DelRow--> [smode](#granting-root-permission-to-the-hdc-server) | Grants the root permission to the hdc server on the device. You can use the **-r** option to revoke the granted permission. (This command is unavailable for non-root devices.)|
151| [keygen](#security-commands) | Generates a new key pair.|
152| [version](#querying-the-hdc-version)| Displays the hdc version information. You can also run the **hdc -v** command to display the version information.|
153| [checkserver](#querying-the-client-and-server-versions)| Obtains the version information about the client process and server process.|
154
155## Basic Commands
156
157To use the USB debugging mode, enable the USB debugging functionality on the device and connect the device to the computer using a USB cable before running the command.
158
159### Displaying Connected Devices
160
161```shell
162hdc list targets
163```
164
165### Running the Shell command
166
167```shell
168hdc shell echo "Hello world"
169```
170
171### Obtaining the Help Information
172
173Display the hdc help information.
174
175```shell
176hdc -h [verbose]
177hdc help
178```
179
180| Name| Description|
181| -------- | -------- |
182| -h verbose | Displays the help information about the hdc command. The optional parameter **verbose** can be used to display detailed help information.|
183| help | Displays the help information about the hdc command.|
184
185**Return value**
186
187| Value| Description|
188| -------- | -------- |
189| OpenHarmony device connector(HDC) ...<br>---------------------------------global commands:----------------------------------<br>-h/help [verbose]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- Print hdc help, 'verbose' for more other cmds<br>... (Detailed information is omitted here.)| Help information for hdc commands.|
190
191> **NOTE**
192>
193> If an exception occurs, run the **hdc kill -r** command to terminate the process and restart the hdc service.
194>
195> If the **hdc list targets** command cannot obtain the device information, see [What should I do if the device cannot be identified](#what-should-i-do-if-the-device-cannot-be-identified).
196
197## Managing Device Connections
198
199### Displaying Devices
200
201```shell
202hdc list targets [-v]
203```
204
205**Parameters**
206
207| Name| Description|
208| -------- | -------- |
209| -v | Displays more details about the device.|
210
211**Return value**
212
213| Value| Description|
214| -------- | -------- |
215| Device ID list| List of IDs of connected devices.<br>You can add the **-v** parameter to the command to view the following information: device ID, connection mode (TCP/USB), connection status (**Unknown**/**Ready**/**Connected**/**Offline**/**Unauthorized**), device name, and hdc identifier.|
216| Device ID Unauthorized| The device is unauthorized.|
217| [Empty] | No device is found.|
218
219**Usage**
220
221```shell
222$ hdc list targets
223connect-key1
224...
225
226$ hdc list targets -v
227connect-key1            USB     Connected       localhost       hdc
228127.0.0.1:5555          TCP     Offline         localhost       hdc
229connect-key2            USB     Offline         localhost       hdc
230...
231```
232
233### Connecting to the Specified Target Device
234
235```shell
236hdc -t [connect-key] [command]
237```
238
239**Parameters**
240
241| Name| Description|
242| -------- | -------- |
243| -t | Connects to a specified target device based on the device ID.<br>This parameter is optional when one device is connected and mandatory when multiple devices are connected.|
244| command | Command to be executed.|
245
246> **NOTE**
247>
248> The *connect-key* uniquely identifies a device. If the device is connected through USB, the *connect-key* is the USB SN. If the device is connected over the network, the *connect-key* is *IP:port*.
249
250**Return value**
251
252| Value| Description|
253| -------- | -------- |
254| Normal command output. For details, see [Commands](#commands).| - |
255| [Fail]Not match target founded, check connect-key please. | The **-t** parameter is used to match the *connect-key* that does not exist. Check whether the *connect-key* is correct.|
256| [Fail]Device not founded or connected. | The device is not found or connected.|
257| [Fail]ExecuteCommand need connect-key? please confirm a device by help info. | Ensure that the device is connected and the debugging functionality is enabled.|
258| Unknown operation command... | The command is not supported.|
259
260> **NOTE**
261>
262> The error information is for reference only and may be optimized. Do not use the error information for logic judgment of automated scripts or programs. In practice, you are advised to use standard error codes provided by the system. For details, see [hdc Error Codes](#hdc-error-codes).
263
264**Usage**
265
266This option must be used with a command. The following uses the **shell** command as an example.
267
268```shell
269$ hdc list targets
270connect-key1
271...
272
273$ hdc -t connect-key1 shell echo "hello world!"
274hello world!
275```
276
277### Waiting for Device Connection
278
279```shell
280hdc wait # Wait for the device to connect.
281hdc -t [connect-key] wait # Wait for the specified device to connect. Replace connect-key with the specified device ID.
282```
283
284**Parameters**
285
286| Name| Description|
287| -------- | -------- |
288| -t connect-key | This parameter is added in version 3.1.0a.<br>When a single device is connected, it is optional.<br>When multiple devices are connected, it is mandatory.|
289
290**Return value**
291
292| Value| Description|
293| -------- | -------- |
294| None| The **hdc wait** command ends when a properly connected device is identified.|
295
296**Usage**
297
298```shell
299# If the device is properly connected, no information is displayed.
300$ hdc wait # Connect to a single device.
301$ hdc -t connect-key1 wait # Use -t to specify the device to be connected when there are multiple devices.
302```
303
304### USB Connection
305
306**Check the environment**
307
308| Item| Normal| Exception Handling|
309| -------- | -------- | -------- |
310| USB debugging| USB debugging is enabled.| If the USB debugging mode is not automatically enabled, restart the device.|
311| USB data cable connection| The PC used for debugging is connected to the device USB port using a USB cable.| If you use a USB cable with low bandwidth and no data communication function, the device may fail to be identified. You are advised to use an original charging cable.|
312| USB port| A USB port on the mainboard (USB port on the rear panel of a desktop computer or USB port on a laptop computer) is used.| If you use a conversion adapter, docking station, or USB port on the front panel of a desktop computer, issues such as low bandwidth and USB sync problems may occur, which results in frequent disconnections. Therefore, direct connection between the PC and the device is recommended.|
313| hdc environment variable| The help information is displayed after the **hdc -h** command is executed.| For details, see [Environment Setup](#environment-setup).|
314| Driver| After the device is connected via hdc, **HDC Device** or **HDC Interface** is displayed in **Device Manager**.| For details, see [What should I do if the device cannot be identified](#what-should-i-do-if-the-device-cannot-be-identified). |
315
316**Procedure**
317
3181. Connect to the device through a USB port.
319
3202. Run the following command to check the connected device:
321
322   ```shell
323   hdc list targets
324   ```
325
326   If the returned information contains the device ID, the USB connection is successful.
327
3283. After the device is found, run commands to interact with the device. If you want to perform hdc commands without the device ID, ensure that the device is not in TCP connection mode (the device information displayed by running the **hdc list targets** command does not contain **IP:port**) and directly connect to the device. For example:
329
330   ```shell
331   hdc shell
332   ```
333
334### TCP Connection
335
336> **NOTE**
337>
338> The TCP debugging mode is not stable. You are advised to use it only in the test environment.
339
340**Check the environment**
341
342| Item| Normal| Exception Handling|
343| -------- | -------- | -------- |
344| Network connection| The PC and the device are on the same network.| Connect the PC and device to the same Wi-Fi network.|
345| Network Status| Use **telnet IP:port** to check that the network connection between the PC and the device is normal.| Use a stable network.|
346| hdc environment variable| The help information is displayed after the **hdc -h** command is executed.| For details, see [Environment Setup](#environment-setup).|
347
348**Procedure**
349
3501. Go to **Settings** > **System** > **Developer options** and enable **Wireless debugging**.
351
3522. Record the IP address and port number displayed on the device in format **IP:port**.
353
3543. Connect to the device over TCP.
355
356   ```shell
357   hdc tconn IP:port
358   ```
359
360   If **Connect OK** is displayed, the connection is successful.
361
3624. Check the connection.
363
364   ```shell
365   hdc list targets
366   ```
367
368   The returned information is in format **IP:port**.
369
370   > **NOTE**
371   >
372   > To disable the TCP connection mode, disable **Wireless debugging** on the device or disconnect the network.
373
374### Remote Connection
375
376In a remote connection, the client (typically a local PC) connects over the network to the server (typically a server or development machine connected to the target device) to debug, control, and manage the target device remotely.
377
378![hdc_image_004](figures/hdc_image_004.PNG)
379
380Use the **-s** parameter to specify the IP address and port number of the server. The setting is valid only when the current command is executed.
381
382```shell
383hdc -s [IP:]port [command]
384```
385
386| Command| Description|
387| -------- | -------- |
388| -s | Specifies the IP address and port number of the current server process to listen for.|
389
390**Parameters**
391
392| Parameter| Description|
393| -------- | -------- |
394| IP | IP address to listen for. Both IPv4 and IPv6 addresses are supported. This parameter is optional. If no IP address is specified, the default IP address **127.0.0.1** is listened for.|
395| port | Port to listen for. The value ranges from 1 to 65535.|
396| command | Commands supported hdc. For details, see [hdc Commands](#hdc-commands).|
397
398**Return value**
399
400| Value| Description|
401| -------- | -------- |
402| Connect server failed. | Failed to connect to the server.|
403| -s content port incorrect. | The port number is out of range (1 to 65535).|
404
405**Usage**
406
407```shell
408# Run the command to obtain the device information in the server process of 127.0.0.1:8710:
409$ hdc -s 127.0.0.1:8710 list targets
410```
411
412**Procedure**
413
4141. Configure the server
415   After the server is connected to the corresponding hdc device through USB, run the following commands:
416
417   ```shell
418   $ hdc kill          # Terminate the local hdc service.
419   $ hdc -s IP:8710 -m # Enable the hdc service for network forwarding.
420                       # IP indicates the IP address of the server. To query the IP address, you can run the **ipconfig** command on Windows and run the **ifconfig** command on Unix.
421                       # 8710 is the default port number. You can also set it to another port number, for example, 18710.
422                       # After startup, the server prints logs.
423   ```
424
4252. Connect to the client
426   Ensure that the client can connect to the server IP address, and then run the following command:
427
428   ```shell
429   $ hdc -s IP:8710 [command] # IP indicates the IP address of the server, and 8710 indicates the port number set in step 1.
430                              # If the port number changes, change the port number accordingly.
431                              # command can be any available hdc command, for example, list targets.
432   ```
433
434> **NOTE**
435>
436> If the **-s** parameter is used to specify a server port, the system ignores the port set in the **OHOS_HDC_SERVER_PORT** environment variable. If the **-s** parameter is used to specify the server address, and the listening address is not the local loopback address (for example, **127.0.0.1**), pay attention to the access security.
437
438### Switching Between USB Debugging and Wireless Debugging
439
440The following table lists the commands for switching the connection mode.
441
442| Command| Description|
443| -------- | -------- |
444| tmode usb | This command is invalid and cannot be used to enable the USB connection channel. You need to enable it on the device setting page.|
445| tmode port [port-number] | Enables the network connection channel of the device. Then the daemon process on the device restarts, and the established connection is interrupted. You need to reconnect the device.|
446| tmode port close | Disables the network connection channel of the device. Then the daemon process on the device restarts, and the established connection is interrupted. You need to reconnect the device.|
447| tconn IP:port [-remove] | Connects to a specified device using **IP:port** and disconnects the device using the **-remove** parameter.|
448
449> **NOTE**
450>
451> You are advised to enable or disable the USB debugging and wireless debugging on the device.
452
453### Enabling the Network Connection Channel
454
455Run the following commands:
456
457```shell
458hdc tmode port [port-number]
459```
460
461**Parameters**
462
463| Parameter| Description|
464| -------- | -------- |
465| port-number | Port number of the connection. The value ranges from 1 to 65535.|
466
467**Return value**
468
469| Value| Description|
470| -------- | -------- |
471| Set device run mode successful. | The operation is successful.|
472| [Fail]ExecuteCommand need connect-key. | Failed to enable the network connection channel because no device exists in the list.|
473| [Fail]Incorrect port range. | The port number is out of range (1 to 65535).|
474
475**Usage**
476
477```shell
478$ hdc tmode port 65512
479Set device run mode successful.
480```
481
482> **NOTE**
483>
484> Before switching, ensure that the remote device and the local computer are on the same network. You can run the **ping** command to check the network connection.
485>
486> 1. On the local PC, run the **ping** command.
487>
488> 2. If the remote device returns response packets, the remote device and the local PC are on the same network.
489>
490> Otherwise, do not run this command.
491>
492> After the command is executed, the remote daemon exits and restarts. You need to reconnect to it.
493
494### Disabling the Network Connection Channel
495
496Run the following commands:
497
498```shell
499hdc tmode port close
500```
501
502**Return value**
503
504| Value| Description|
505| -------- | -------- |
506| [Fail]ExecuteCommand need connect-key. | The command cannot be executed because the device list is empty.|
507
508**Usage**
509
510```shell
511hdc tmode port close
512```
513
514> **NOTE**
515>
516> After the command is executed, the remote daemon exits and restarts. You need to reconnect to it.
517
518### Connecting to a Device over TCP
519
520Connect to the specified device over TCP.
521
522```shell
523hdc tconn IP:port [-remove]
524```
525
526**Parameters**
527
528| Parameter| Description|
529| -------- | -------- |
530| IP:port | IP address and port number of the device.|
531| -remove | An optional parameter used to disconnect a specified device.|
532
533**Return value**
534
535| Value| Description|
536| -------- | -------- |
537| Connect OK. | Device connected.|
538| [Info]Target is connected, repeat operation. | The device is already connected.|
539| [Fail]Connect failed. | Failed to connect the specified device.|
540
541**Usage**
542
543```shell
544$ hdc tconn 192.168.0.1:8888
545Connect OK
546
547# Disconnect from the specified device.
548$ hdc tconn 192.168.0.1:8888 -remove
549```
550
551## Running Interactive Commands
552
553```shell
554hdc shell [-b bundlename] [command]
555```
556
557**Parameters**
558
559| Parameter| Description|
560| -------- | -------- |
561| -b bundlename | This parameter is added in 3.1.0e. The bundle name of a debug application. The command is executed in non-interactive mode in the data directory of the debug application.<br>For details, [Accessing the App Sandbox in CLI Mode](https://developer.huawei.com/consumer/en/doc/harmonyos-guides/ide-device-file-explorer#section9381241102211)<br>Currently, this parameter can be used only in non-interactive mode, and the **command** parameter must be specified to enter an interactive shell session.<br>Otherwise, commands are executed in the system root directory by default.|
562| command | A single command to execute on the device. The command varies depending on the system type or version. You can run the **hdc shell ls /system/bin** command to obtain the supported command list. Currently, most commands are provided by [toybox](../tools/toybox.md). You can run the **hdc shell toybox --help** command to obtain the help information.<br>If this parameter is not specified, hdc starts an interactive shell session, in which you can enter commands such as **ls**, **cd**, and **pwd** at the command prompt.|
563
564> **NOTE**
565>
566> If the **[-b bundlename]** parameter is specified, the installed application corresponding to the bundle name must be signed using the debug certificate and started on the device. For details about how to request and use the debug certificate, see [Requesting a Debug Certificate](https://developer.huawei.com/consumer/en/doc/app/agc-help-add-debugcert-0000001914263178).
567
568**Return value**
569
570| Value| Description|
571| -------- | -------- |
572| Command execution result.| Execution result of the command. For details, see the corresponding command output.|
573| /bin/sh: XXX : inaccessible or not found. | The specified command is not supported.|
574| [Fail]Error information.| The execution fails. For details, see [hdc Error Codes](#hdc-error-codes).|
575
576**Usage**
577
578```shell
579# Enter the interactive mode to run a command.
580$ hdc shell
581$
582
583# Run the command in non-interactive mode.
584$ hdc shell "ps -ef | grep hdcd"
585shell         39491      1 1 14:40:58 ?     00:00:00 hdcd
586
587# Obtain the help information.
588$ hdc shell help -a
589---toybox---------------------------------------------------------------------
590
591usage: toybox [--long | --help | --version | [command] [arguments...]]
592
593With no arguments, shows available commands. First argument is
594name of a command to run, followed by any arguments to that command.
595
596--long  Show path to each command
597...
598
599# Specify the bundle name of an application to run the command in non-interactive mode in its data directory. The **touch**, **rm**, **ls**, **stat**, **cat** and **mkdir** commands are supported.
600$ hdc shell -b com.example.myapplication ls data/storage/el2/base/
601```
602
603**Common Debugging Tools**
604
605| Command| Description|
606| -------- | -------- |
607| [aa](../tools/aa-tool.md) | Application debugging tool|
608| [bm](../tools/bm-tool.md) | Bundle manager|
609| [cem](../tools/cem-tool.md) | Common event manager|
610| [anm](../tools/anm-tool.md) | Notification manager|
611| [edm](../tools/edm-tool.md) | Enterprise device manager|
612| [param](../tools/param-tool.md) | Operating system parameter manager|
613| [power-shell](../tools/power-shell.md) | Device power status conversion tool|
614| [atm](../tools/atm-tool.md) | Access token manager|
615| [hilog](./hilog.md) | Log manager|
616| [hidumper](./hidumper.md) | System information export tool|
617| [hitrace](./hitrace.md) | System logging and collection tool|
618| [hiperf](./hiperf.md) | Performance analysis tool|
619| [mediatool](../tools/mediatool.md) | Media resource library tool|
620| [devicedebug](../tools/devicedebug-tool.md) | Debugging application signal sending tool|
621| [rawheap-translator](../tools/rawheap-translator.md) | .rawheap file parsing tool|
622
623## Managing Applications
624
625| Command| Description|
626| -------- | -------- |
627| install src | Installs an application.|
628| uninstall bundlename | Uninstalls an application.|
629
630### Installing an Application
631
632Installs an application file.
633
634```shell
635hdc install [-r|-s] src
636```
637
638**Parameters**
639
640| Name| Description|
641| -------- | -------- |
642| src | Installation package name.|
643| -r | Replaces the existing application (.hap).|
644| -s | Install a shared package (.hsp).|
645
646**Return value**
647
648| Value| Description|
649| -------- | -------- |
650| [Info]App install path:XXX msg:install bundle successfully.<br>AppMod finish. | The installation is successful.|
651| Error information.| The installation fails.|
652
653**Usage**
654
655```shell
656# For example, install **example.hap**.
657$ hdc install E:\example.hap
658AppMod finish
659```
660
661### Uninstalling an Application
662
663Run the following commands:
664
665```shell
666hdc uninstall [-k|-s] bundlename
667```
668
669**Parameters**
670
671| Name| Description|
672| -------- | -------- |
673| bundlename | Application installation package.|
674| -k | Used to retain the **/data** and **/cache** directories after the application is uninstalled.|
675| -s | Used to uninstall a shared package.|
676
677**Return value**
678
679| Value| Description|
680| -------- | -------- |
681| [Info]App uninstall path: msg:uninstall bundle successfully.<br>AppMod finish. | The uninstallation is successful.|
682| Error information.| The uninstallation fails.|
683
684**Usage**
685
686```shell
687# For example, uninstall **com.example.hello**.
688$ hdc uninstall com.example.hello
689AppMod finish
690```
691
692## Transferring Files
693
694| Command| Description|
695| -------- | -------- |
696| file send SOURCE DEST | Sends a local file to a remote device.|
697| file recv DEST SOURCE | Receives a file from a remote device.|
698
699### Sending a File to a Remote Device
700
701Run the following commands:
702
703```shell
704hdc file send [-a|-sync|-z|-m|-b bundlename] SOURCE DEST
705```
706
707**Parameters**
708
709| Name| Description|
710| -------- | -------- |
711| SOURCE | Path of the file to send.|
712| DEST | Path of the target file.|
713| -a | Used to retain the file modification timestamp.|
714| -sync | Used to transfer only the files whose **mtime** is updated.<br>**mtime** (modified timestamp): timestamp after modification.|
715| -z | Used to compress and transmit files in LZ4 format. This parameter is unavailable.|
716| -m | Used to synchronize the DAC permission, UID, GID, and MAC permission during file transfer.<br>**DAC** (Discretionary Access Control): discretionary access control;<br>**uid** (User identifier): user identifier (or user ID);<br>**gid** (Group identifier): group identifier (or group ID);<br>**MAC** (Mandatory Access Control): mandatory access control (or non-discretionary access control).|
717| -b | Used to specify the bundle name of the debug-type application. This parameter is added in 3.1.0e (If this parameter is used in an earlier version, the message "[Fail]Unknown file option: -b" is displayed). <br>For details, see [Accessing the App Sandbox in CLI Mode](https://developer.huawei.com/consumer/en/doc/harmonyos-guides/ide-device-file-explorer#section9381241102211).|
718| bundlename | Bundle name of the debug-type application.|
719
720**Return value**
721
722A success message is returned if the file is sent successfully. Error information is displayed if the file fails to be sent.
723
724**Usage**
725
726```shell
727$ hdc file send test /test/
728FileTransfer finish, Size:10, File count = 1, time:0ms rate:100kB/s
729```
730
731### Receiving a File from a Remote Device
732
733Run the following commands:
734
735```shell
736hdc file recv [-a|-sync|-z|-m|-b bundlename] DEST SOURCE
737```
738
739**Parameters**
740
741| Name| Description|
742| -------- | -------- |
743| SOURCE | Destination path on the local device.|
744| DEST | Path of the file to send.|
745| -a | Used to retain the file modification timestamp.|
746| -sync | Used to transfer only the files whose **mtime** is updated.<br>**mtime** (modified timestamp): timestamp after modification.|
747| -z | Used to compress and transmit files in LZ4 format. This parameter is unavailable.|
748| -m | Used to synchronize the DAC permission, UID, GID, and MAC permission during file transfer.<br>**DAC** (Discretionary Access Control): discretionary access control;<br>**uid** (User identifier): user identifier (or user ID);<br>**gid** (Group identifier): group identifier (or group ID);<br>**MAC** (Mandatory Access Control): mandatory access control (or non-discretionary access control).|
749| -b | Used to send files in the data directory of a specified debug-type application process. This parameter is added in version 3.1.0e.<br>For details, see [Accessing the App Sandbox in CLI Mode](https://developer.huawei.com/consumer/en/doc/harmonyos-guides/ide-device-file-explorer#section9381241102211).|
750| bundlename | Bundle name of the debug application process.|
751
752**Return value**
753
754A success message is displayed if the file is received successfully. Error information is displayed if the file fails to be received.
755
756**Usage**
757
758```shell
759$ hdc file recv /test/test ./
760FileTransfer finish, Size:10, File count = 1, time:0ms rate:100kB/s
761```
762
763> **NOTE**
764>
765> To use the **\[-b bundlename]** parameter, ensure that the installed application is signed by a debug certificate and started. For details about how to request and use the debug certificate, see [Requesting a Debug Certificate](https://developer.huawei.com/consumer/en/doc/app/agc-help-add-debugcert-0000001914263178).
766>
767> **Version updates**: Since version 3.1.0a, Chinese characters can be used as file transfer command parameters, which facilitates the use in multi-language environments.
768
769## Port Forwarding
770
771| Command| Description|
772| -------- | -------- |
773| fport ls | Lists all port forwarding tasks.|
774| fport [IP:port] [IP:port] | Sets up a local port forwarding, which forwards data from a local port to a remote port. The port number ranges from 1 to 65535.|
775| rport [IP:port] [IP:port] | Sets up a remote port forwarding, which forwards data from a remote port to a local port. The port number ranges from 1024 to 65535.|
776| fport rm [IP:port] [IP:port] | Deletes a port forwarding task.|
777
778> **NOTE**
779>
780> Port forwarding type supported by the computer: TCP.
781>
782> Port forwarding type supported by the device: TCP, dev, localabstract, localfilesystem, jdwp, ark.
783
784### Querying the Port Forwarding Task List
785
786Run the following commands:
787
788```shell
789hdc fport ls
790```
791
792**Return value**
793
794| Value| Description|
795| -------- | -------- |
796| tcp:1234 tcp:1080 [Forward] | Local port forwarding.|
797| tcp:2080 tcp:2345 [Reverse] | Remote port forwarding.|
798| [Empty] | No port forwarding.|
799
800**Usage**
801
802```shell
803$ hdc fport ls
804[Empty]
805```
806
807### Creating a Local Port Forwarding
808
809Set up a local port forwarding, which forwards data from a local port to a remote port.
810
811```shell
812hdc fport [IP:port] [IP:port]
813```
814
815**Return value**
816
817| Value| Description|
818| -------- | -------- |
819| Forwardport result:OK. | The port forwarding is set up properly.|
820| [Fail]Incorrect forward command. | Failed to set up the port forwarding due to parameter errors.|
821| [Fail]TCP Port listen failed at XXXX. | Failed to set up the port forwarding because the local port is in use.|
822| [Fail]Forward parament failed. | The port forwarding format is incorrect, or the forwarding port protocol or port range is incorrect.|
823| [Fail]Not support forward-type. | The current platform does not support the forwarding port protocol used in the parameter.|
824
825**Usage**
826
827```shell
828$ hdc fport tcp:1234 tcp:1080
829Forwardport result:OK
830```
831> **NOTE**
832>
833> In the local port forwarding, if the local port uses TCP, the specified port is **port**, and the **-e** parameter is used when the service process is started, the local host listens for the port of the IP address specified by the **-e** parameter. If the **-e** parameter is not used when the server is started, the local host listens for **127.0.0.1:port**.
834
835
836### Creating a Remote Port Forwarding
837
838Set up a remote port forwarding, which forwards data from a remote port to a local port.
839
840```shell
841hdc rport [IP:port] [IP:port]
842```
843
844**Return value**
845
846| Value| Description|
847| -------- | -------- |
848| Forwardport result:OK. | The port forwarding is set up properly.|
849| [Fail]Incorrect forward command. | Failed to set up the port forwarding due to parameter errors.|
850| [Fail]TCP Port listen failed at XXXX. | Failed to set up the port forwarding because the local port is in use.|
851| [Fail]Forward parament failed. | The port forwarding format is incorrect, or the forwarding port protocol or port range is incorrect.|
852
853**Usage**
854
855```shell
856$ hdc rport tcp:1234 tcp:1080
857Forwardport result:OK
858```
859
860### Deleting a Port Forwarding Task
861
862Delete a specified port forwarding task.
863
864```shell
865hdc fport rm [IP:port][IP:port]
866```
867
868**Parameters**
869
870| Parameter| Description|
871| -------- | -------- |
872| IP:port | Port forwarding task, in the format of **tcp:XXXX tcp:XXXX**.|
873
874**Return value**
875
876| Value| Description|
877| -------- | -------- |
878| Remove forward ruler success, ruler:tcp:XXXX tcp:XXXX. | The port forwarding is removed successfully.|
879| [Fail]Remove forward ruler failed, ruler is not exist tcp:XXXX tcp:XXXX. | Failed to remove the port forwarding task because it does not exist.|
880
881**Usage**
882
883```shell
884$ hdc fport rm tcp:1234 tcp:1080
885Remove forward ruler success, ruler:tcp:1234 tcp:1080
886```
887
888## Managing Server Processes
889
890| Command| Description|
891| -------- | -------- |
892| start [-r] | Starts the hdc process. You can use the **-r** option to restart the process.|
893| kill [-r] | Terminates the hdc process. You can use the **-r** option to restart the process.|
894| -p | Executes a client command without querying the server process.|
895| -m | Starts a server process in the foreground.<br>Foreground startup mode (with the **-m** parameter): Service logs are printed to the client window in real time.<br>Background startup mode (without the **-m** parameter): The client does not print service logs. The log content is written to a local disk file. For details about the file storage path, see [Server Process Logs](#server-logs). |
896| -e |  Specifies the local listening IP address in TCP port forwarding. The default value is **127.0.0.1**. This parameter must be used together with **-m**.|
897
898### Starting a Service
899
900Start the hdc server.
901
902```shell
903hdc start [-r]
904```
905
906**Return value**
907
908| Value| Description|
909| -------- | -------- |
910| No returned information| The server is started successfully.|
911
912**Usage**
913
914```shell
915hdc start -r # Restart the server.
916```
917
918> **NOTE**
919>
920> When the hdc server is started and the system does not detect any running server, the log level setting priority is as follows: If the **-l** parameter and the **OHOS_HDC_LOG_LEVEL** environment variable are specified in the same command, the environment variable takes effect. If only the **-l** parameter is specified, the log level specified by it is used. If neither parameter is specified, the server is started at the default log level **LOG_INFO**.
921
922### Terminating a Service
923
924Run the following commands:
925
926```shell
927hdc kill [-r]
928```
929
930**Return value**
931
932| Value| Description|
933| -------- | -------- |
934| Kill server finish. | The server is terminated successfully.|
935| [Fail]Error information.| Failed to terminate the server.|
936
937**Usage**
938
939```shell
940$ hdc kill -r # Terminate and restart the server. You can run the hdc -l 5 kill -r command to view the detailed restart log.
941Kill server finish
942
943$ hdc kill # Terminate the server.
944Kill server finish
945```
946
947### Quick Command Execution
948
949Executes a client command without querying the server process. If the service is not started, running this command does not restart the service. Before using the parameter, ensure that the service has been started. Run the following commands:
950
951```shell
952hdc -p [command]
953```
954
955**Parameters**
956
957| Parameter| Description|
958| -------- | -------- |
959| command | Command to be executed.|
960
961**Return value**
962
963| Value| Description|
964| -------- | -------- |
965| Connect server failed. | Failed to connect to the server.|
966
967**Usage**
968
969```shell
970$ hdc start # Start the server.
971
972$ hdc -p list targets # Execute the command without checking.
973connect-key1
974connect-key2
975...
976```
977
978> **NOTE**
979>
980> When a command is executed without the **-p** parameter specified, the client first checks whether a server is running locally. If the system does not detect a running server process, the client automatically starts a server process and sets up a connection to transfer commands. If the system detects a running server process, the client directly connects to the server process and transfers commands.
981
982### Starting a Server in the Foreground
983
984Start the server process in the foreground.
985
986```shell
987hdc -m
988```
989
990**Return value**
991
992| Value| Description|
993| -------- | -------- |
994| Initial failed. | The server process fails to be initialized.|
995| [I][1970-01-01 00:00:00.000] Program running. Ver: X.X.Xx Pid:XXX.<br>... | Logs of the corresponding level are printed to display the activity status of the server.|
996
997**Usage**
998
999```shell
1000$ hdc -s 127.0.0.1:8710 -m # Specify the network listening parameters of the current server and start the server.
1001[I][1970-01-01 00:00:00.000] Program running. Ver: 3.1.0e Pid:8236
1002$ hdc -e 0.0.0.0 -m # Specify the local listening IP address 0.0.0.0 for port forwarding and start the server.
1003[I][1970-01-01 00:00:00.000] Program running. Ver: 3.1.0e Pid:8236
1004...
1005```
1006
1007> **NOTE**
1008>
1009> 1. In foreground startup mode, you can use the **-s** parameter to specify the network listening parameters of the server. If no IP address and port number are specified using the **-s** parameter and the environment variable **OHOS_HDC_SERVER_PORT** is not set, the system uses the default IP address and port number **127.0.0.1:8710**. You can also use the **-e** parameter to specify the IP address for which the local host should listen during port forwarding. If **-e** is omitted, it defaults to **127.0.0.1**.
1010>
1011> 2. If the server process is started in the foreground, the default log output level is **LOG_DEBUG**. To change the log level, use the **-l** parameter.
1012>
1013> 3. Only one server instance is allowed in the running environment. If a server is running, a new server instance cannot be started in the foreground.
1014
1015
1016## Operating the Device
1017
1018| Command| Description|
1019| -------- | -------- |
1020| hilog [-h] | Displays the log information of the device. You can run the **hdc hilog -h** command to obtain the supported parameters.|
1021| jpid | Displays the PIDs of started applications on the device.|
1022| track-jpid [-a\|-p] | Displays the PIDs and names of started applications on the device in real time. Only applications with the **debug** tag can be debugged. If no parameter is specified, the PIDs of debug-type applications are displayed. If the **-a** parameter is specified, the process tags of debug-type and release-type applications are displayed. If the **-p** parameter is specified, the process tags of debug-type and release-type applications are not displayed.|
1023| target boot [-bootloader\|-recovery] | Restarts the target device. You can use the **-bootloader** option to enter the fastboot mode and the **-recovery** option to enter the recovery mode.|
1024| target boot [MODE] | Restarts the target device. You can add a parameter to use the corresponding mode. **MODE** is a parameter supported by reboot in the **/bin/begetctl** command. You can run the **hdc shell "/bin/begetctl -h \ grep reboot"** command to check the restart mode.|  |
1025| <!--DelRow--> target mount | Mounts the system partition in read/write mode. (This command is supported after the device has required the root permission.)|
1026| <!--DelRow--> smode [-r] | Grants the root permission to the hdc background server process on the device. You can use the **-r** parameter to cancel the permission. (This command is supported after the device has required the root permission.)|
1027
1028### Printing Device Logs
1029
1030Run the following commands:
1031
1032```shell
1033hdc hilog [-h]
1034```
1035
1036**Parameters**
1037
1038| Parameter| Description|
1039| -------- | -------- |
1040| -h | Parameters supported by HiLog. You can run the **hdc hilog -h** command to obtain the parameter list.|
1041
1042**Return value**
1043
1044| Value| Description|
1045| -------- | -------- |
1046| Returned value| Log information obtained.|
1047
1048**Usage**
1049
1050```shell
1051$ hdc hilog -h
1052Usage:
1053-h --help
1054  Show all help information.
1055  Show single help information with option:
1056...
1057```
1058
1059### Displaying PIDs of Started Applications
1060
1061Run the following commands:
1062
1063```shell
1064hdc jpid
1065```
1066
1067**Return value**
1068
1069| Value| Description|
1070| -------- | -------- |
1071| PID list| PIDs of the applications that enable JDWP. |
1072| [Empty] | No process enables JDWP.|
1073
1074**Usage**
1075
1076```shell
1077$ hdc jpid
10781234
10791080
1080...
1081```
1082
1083### Displaying PIDs and Names of Started Applications in Real Time
1084
1085Display the PIDs and names of the started applications on the device in real time.
1086
1087```shell
1088hdc track-jpid [-a|-p]
1089```
1090
1091**Parameters**
1092
1093| Parameter| Description|
1094| -------- | -------- |
1095| Not specified| Used to display the PIDs of the started applications.|
1096| -a | Used to display the PIDs, bundle names, and process names of the debug-type and release-type applications, but does not display the **debug** and **release** tags.|
1097| -p | Used to display the PIDs, bundle names, and process names of the **debug** and **release** applications, but does not display the **debug** and **release** tags.|
1098
1099**Return value**
1100
1101| Value| Description|
1102| -------- | -------- |
1103| PID and bundle/process name list| If no parameter is specified, the processes of started applications are displayed. If the **-a** or **-p** parameter is specified, the started debug and release processes are displayed.|
1104| [Empty] | No JDWP-enabled application process is found.|
1105
1106**Usage**
1107
1108```shell
1109$ hdc track-jpid -a
11101234 com.example.hello release
1111...
1112
1113$ hdc track-jpid -p
11141234 com.example.hello
1115...
1116```
1117
1118### Restarting the Target Device
1119
1120Run the following commands:
1121
1122```shell
1123hdc target boot [-bootloader|-recovery]
1124hdc target boot [MODE]
1125```
1126
1127**Parameters**
1128
1129| Name| Description|
1130| -------- | -------- |
1131| Not specified| Used to restart a device.|
1132| -bootloader | Used to restart a device to enter the **fastboot** mode.|
1133| -recovery | Used to restart a device to enter the **recovery** mode.|
1134| MODE | Used to restart a device to enter the **MODE** mode. **MODE** is a parameter supported by **reboot** in the **/bin/begetctl** command.|
1135
1136**Usage**
1137
1138```shell
1139hdc target boot -bootloader  # Restart the device to enter the fastboot mode.
1140hdc target boot -recovery    # Restart the device to enter the recovery mode.
1141hdc target boot shutdown     # Shut down the device.
1142```
1143<!--Del-->
1144### Mounting the System Partition in Read/Write Mode
1145
1146Run the following commands:
1147
1148   ```shell
1149   hdc target mount
1150   ```
1151
1152   **Return value**
1153| Return Value| Description|
1154| -------- | -------- |
1155| Mount finish | Mounting succeeded.|
1156| [Fail]Mount failed | Mounting failed.|
1157
1158   **Usage**
1159
1160   ```shell
1161   hdc target mount
1162   ```
1163
1164   > **NOTE**
1165   >
1166   > This command is supported only after the device has required the root permission. Exercise caution when running this command.
1167
1168### Granting Root Permission to the hdc Server
1169
1170Run the following commands:
1171
1172   ```shell
1173   hdc smode [-r]
1174   ```
1175
1176   **Return value**
1177| Return Value| Description|
1178| -------- | -------- |
1179| No return value| Permission granted.|
1180| [Fail]Error information| Failed to grant the permission.|
1181
1182   **Usage**
1183
1184   ```shell
1185   hdc smode
1186   hdc smode -r  // Revoke the root permission.
1187   ```
1188
1189   > **NOTE**
1190   >
1191   > This command is supported only after the device has required the **root** permission.
1192<!--DelEnd-->
1193
1194## Security Commands
1195
1196| Command| Description|
1197| -------- | -------- |
1198| keygen FILE | Generates a new key pair and saves the private key and public key to **FILE** and **FILE.pub**, respectively. **FILE** indicates the custom file name.|
1199
1200Run the following commands:
1201
1202```shell
1203hdc keygen FILE
1204```
1205
1206**Parameters**
1207
1208| Parameter| Description|
1209| -------- | -------- |
1210| FILE | Custom file name.|
1211
1212**Usage**
1213
1214```shell
1215# Generate the **key** and **key.pub** files in the current directory.
1216$ hdc keygen key
1217```
1218
1219## Querying the hdc Version
1220
1221| Command| Description|
1222| -------- | -------- |
1223| -v | Prints the client version information.|
1224| version | Prints the server version information.|
1225| checkserver | Obtains the client and server process versions.|
1226
1227### Querying the Client Version
1228
1229Query the hdc client version.
1230
1231```shell
1232hdc -v
1233```
1234
1235**Return value**
1236
1237| Value| Description|
1238| -------- | -------- |
1239| Ver: X.X.Xx. | hdc (SDK) client version information.|
1240
1241**Usage**
1242
1243```shell
1244$ hdc -v
1245Ver: 3.1.0e
1246```
1247
1248### Querying the Server Version
1249
1250Query the server version.
1251
1252```shell
1253hdc version
1254```
1255
1256**Return value**
1257
1258| Value| Description|
1259| -------- | -------- |
1260| Ver: X.X.Xx. | hdc (SDK) server version information.|
1261
1262**Usage**
1263
1264```shell
1265$ hdc version
1266Ver: 3.1.0e
1267```
1268
1269### Querying the Client and Server Versions
1270
1271Run the following commands:
1272
1273```shell
1274hdc checkserver
1275```
1276
1277**Return value**
1278
1279| Value| Description|
1280| -------- | -------- |
1281| Client version: Ver: X.X.Xx, Server version: Ver: X.X.Xx. | The client and server versions.|
1282
1283**Usage**
1284
1285```shell
1286$ hdc checkserver
1287Client version: Ver: 3.1.0e, Server version: Ver: 3.1.0e
1288```
1289
1290## hdc Debugging Logs
1291
1292### Server Logs
1293
1294**Specify the log level at runtime**
1295
1296Specify the hdc log level. The default value is **LOG_INFO**.
1297
1298```shell
1299hdc -l [level] [command]
1300```
1301
1302**Parameters**
1303
1304| Parameter| Description|
1305| -------- | -------- |
1306| [level] | Used to specify the log level at runtime. The level increases with the number. When a log level is set, the current level and lower levels are enabled. For example, if the log level is set to 3, logs of levels 1 to 3 can be printed.<br>0: LOG_OFF<br>1: LOG_FATAL<br>2: LOG_WARN<br>3: LOG_INFO<br>4: LOG_DEBUG<br>5: LOG_ALL<br>6: LOG_LIBUSB|
1307| command | Command to be executed.|
1308
1309> **NOTE**
1310>
1311> 1. When the log level is set to **6** (**LOG_LIBUSB**), incremental logs related to libusb are generated. The incremental logs are detailed and contain a large amount of data, which helps accurately diagnose USB-related exceptions in server processes. You are advised to set the log level as required. USB-related operations are mainly performed by server processes. Therefore, incremental logs are available only for server processes. Accordingly, the client logs almost do not contain incremental log information.
1312>
1313> 2. You can change only the log levels of the current client and server.
1314
1315**Return value**
1316
1317| Value| Description|
1318| -------- | -------- |
1319| Log information.| Logs of the specified level.|
1320
1321**Usage**
1322
1323```shell
1324# Run the shell ls command to print logs of the LOG_DEBUG level and lower levels on the client.
1325$ hdc -l 5 shell ls
1326[D][1970-01-01 00:00:00.000][12dc][xxxx.xxx:123] Mallocchannel:1234567
1327...
1328
1329# Start the server in the foreground and specify the log level to LOG_LIBUSB.
1330$ hdc kill && hdc -l 6 -m
1331Kill server finish
1332[I][1970-01-01 00:00:00.000][4f28][xxxx.xxx:123] Program running. Ver: 3.1.0e Pid:12345
1333...
1334
1335# Start the server in the background and specify the log level to LOG_LIBUSB.
1336$ hdc kill && hdc -l 6 start
1337Kill server finish
1338[D][1970-01-01 00:00:00.000][12dc][xxxx.xxx:123] Mallocchannel:1234567
1339...
1340```
1341
1342> **NOTE**
1343>
1344> You can use the **-m** parameter to start the server in the foreground and view its log output directly. To exit the process, press **Ctrl+C**.
1345>
1346> If the server is started in the background, you can view the log output in **hdc.log**.
1347
1348**Obtain logs**
1349
1350Run the following command to enable the functionality of obtaining logs:
1351
1352```shell
1353hdc kill
1354hdc -l 5 start
1355```
1356
1357The collected logs are stored in the following path.
1358
1359| OS| Path| Remarks|
1360| -------- | -------- | -------- |
1361| Windows | %temp%\ | Example: **C:\\Users\Username\AppData\Local\Temp**.<br>Replace *Username* with the actual one.|
1362| Linux | /tmp/ |  |
1363| macOS| $TMPDIR/ | You can run the **echo $TMPDIR** command to view the actual path, and **cd $TMPDIR** to go to the corresponding directory.|
1364
1365The log file types are as follows.
1366
1367| Type| Name Format| Functionality| Remarks|
1368| -------- | -------- | -------- | -------- |
1369| Real-time log| hdc.log | Records server logs in real time.| Each time the hdc server is restarted, the original log is renamed and a new **hdc.log** is recorded.|
1370| Temporary historical log| hdc-%Y%m%d-%H%M%S.log | Dumps intermediate files generated during historical log archiving.| For example, if the time is 16:18:57.921 on September 19, 2024, the time format is **20240919-161857921**, and the name of the generated temporary log file is **hdc-20240919-161857921.log**.|
1371| Archived historical logs| hdc-%Y%m%d-%H%M%S.log.tgz | Compresses and stores historical logs.| The archive file is a compressed file of the **.tgz** type. You can use a decompression tool to obtain the file. For example, if the temporary name of a historical log file is **hdc-20240919-161857921.log**, the name of the corresponding archived historical log file is **hdc-20240919-161857921.log.tgz**. After the archived historical log file is generated, the corresponding temporary historical log file is automatically deleted.|
1372| Temporary real-time log| .hdc.cache.log | Records temporary caches generated by real-time logs.|  |
1373
1374### Device Logs
1375
1376Use HiLog to obtain the corresponding logs.
1377
1378```shell
1379hdc shell hilog -w start                              # Enable HiLog log flushing. (An error will be reported if HiLog is enabled again.)
1380hdc shell hilog -w stop                               # Disable HiLog log flushing. (An error will be reported if HiLog is disabled again.)
1381hdc shell ls /data/log/hilog                          # View the flushed HiLog logs.
1382hdc file recv /data/log/hilog {local_path}            # Obtain the flushed HiLog logs (including kernel logs). {local_path} varies according to the system. Replace it with the actual path.
1383```
1384
1385## Options
1386
1387### OHOS_HDC_SERVER_PORT
1388
1389
1390
1391Used to set the listening port number when the server is running. This port is used for data communication between the client and the server.
1392
1393When the server starts, it listens to port **8710** of the PC by default. The client uses TCP to connect to the server through this port. If port 8710 of the PC has been used or you want to use another port, you can add the environment variable **OHOS_HDC_SERVER_PORT** to the system environment variable to listen for any unoccupied port when the server starts. You can set the port number to a value ranging from 1 to 65535.
1394
1395For example, set **OHOS_HDC_SERVER_PORT** to **18710**.
1396
1397### OHOS_HDC_LOG_LEVEL
1398
1399
1400
1401Used to set the log level for the server. For details, see [Server Logs](#server-logs).
1402
1403### OHOS_HDC_HEARTBEAT
1404
1405
1406
1407Used to set whether to enable the heartbeat functionality for the server and daemon. This functionality is enabled by default.
1408
1409After the server and daemon are started, they send heartbeat packets to each other and record the heartbeat packets in hdc logs for checking the device connection status.
1410
1411When the environment variable OHOS_HDC_HEARTBEAT is set to **1** for the server, its heartbeat functionality is disabled. When the device is connected to the PC, the server notifies the daemon that the heartbeat functionality is disabled and does not send heartbeat packets to each other.
1412
1413When **OHOS_HDC_HEARTBEAT** is set to other values, the heartbeat functionality is enabled.
1414
1415### OHOS_HDC_CMD_RECORD
1416
1417
1418
1419Sets whether to enable the hdc command recording functionality. This functionality is enabled by default. This functionality records only the executed hdc commands but not the command execution results.
1420
1421When this parameter is set to **1**, the command recording functionality is enabled. When it is not set or set to any other number, the command recording functionality is disabled.
1422
1423This parameter is supported since API version 20.
1424
1425The recording log files are stored in the following paths:
1426
1427| OS| Path| Remarks|
1428| -------- | -------- | -------- |
1429| Windows | %temp%\hdc_cmd\ | Example: **C:\\Users\Username\AppData\Local\Temp\hdc_cmd\<br/>** (Replace the user name with the actual one.)|
1430| Linux | /tmp/hdc_cmd/ |  |
1431| macOS| $TMPDIR/hdc_cmd/ |  |
1432
1433### OHOS_HDC_ENCRYPT_CHANNEL
1434
1435
1436
1437Used to set the encryption functionality of the TCP connection channel between the server and the daemon. By default, the encryption functionality is disabled.
1438
1439If **OHOS_HDC_ENCRYPT_CHANNEL** is set to **1**, the channel encryption functionality is enabled; otherwise, it is disabled.
1440
1441This parameter is supported since API version 20.
1442
1443> **NOTE**
1444>
1445> When the server is running, it listens for port 8710 of the PC by default. You can customize the listening port by setting the system environment variable **OHOS_HDC_SERVER_PORT**.
1446
1447### Configuring Environment Variables
1448
1449The following example describes how to set environment variables by setting **OHOS_HDC_LOG_LEVEL** to 5. For details, see [Environment Setup](#environment-setup).
1450
1451| OS| Configuration Method|
1452| -------- | -------- |
1453| Windows | In **Settings**, search for **View advanced system settings**. In **Environment Variables** > **System Variables** > **Path**, click **Edit** to add the environment variable **OHOS_HDC_LOG_LEVEL** whose value is **5**. After the configuration is complete, click **OK**. Restart the CLI or other software that uses HarmonyOS SDK for the new environment variable to take effect.|
1454| Linux | Add **export OHOS_HDC_LOG_LEVEL=5** to the end of the **~/.bash_profile** file, save the file, and run the **source ~/.bash_profile** command for the current environment variable to take effect.|
1455| macOS| Add **export OHOS_HDC_LOG_LEVEL=5** to the end of the **~/.zshrc** file, save the file, and run the **source ~/.zshrc** command for the current environment variable to take effect. Restart the CLI or other software that uses HarmonyOS SDK for the new environment variable to take effect.|
1456
1457## hdc Version Mappings
1458
1459| hdc Version| API Version| New Features|
1460| -------- | -------- | -------- |
1461| 3.1.0a | 12 | The **wait** command supports the **-t** parameter. For details, see [Waiting for Device Connection](#waiting-for-device-connection).|
1462| 3.1.0e | 15 | - The **file send** command supports the **-b** parameter. For details, see [Transferring Files](#transferring-files).<br>- The **file recv** command supports the **-b** parameter. For details, see [Transferring Files](#transferring-files).<br>- The **shell** command supports the **-b** parameter. For details, see [Running Interactive Commands](#running-interactive-commands).|
1463
1464> **NOTE**
1465>
1466> If the current hdc version is too early, the compatibility of some functionalities may be affected. You can download the latest version based on the API version description.
1467
1468## FAQs
1469
1470### What should I do if the device cannot be identified
1471
1472**Symptom**
1473
1474After the **hdc list targets** command is executed, the command output is **[Empty]**.
1475
1476**Possible Causes and Solution**
1477
1478**Scenario 1**
1479
1480Check whether the target device is displayed in **Device Manager**.
1481
1482Windows:
1483
1484Check whether **HDC Device** (for a single-port device) or **HDC Interface** (for a composite-port device) exists under **Universal Serial Bus Controllers** in **Device Manager**.
1485
1486Linux:
1487
1488Run the **lsusb** command. Check whether **HDC Device** or **HDC Interface** is displayed in the command output.
1489
1490macOS:
1491
1492Check the system information or system overview of the USB device as follows:
1493
14941. Press and hold the **Option** key, and click the menu (usually in the upper left corner of the screen).
1495
14962. Choose **System Information** or **System Overview**.
1497
14983. Select **USB** on the left.
1499
15004. Check whether **HDC Device** or **HDC Interface** exists in the device tree.
1501
1502**Solution**
1503
1504If the hdc device is not displayed in the preceding environments, it is not correctly identified. You can try the following methods to solve the problem:
1505
15061. Use another physical USB port.
1507
15082. Change the USB cable.
1509
15103. Use another PC.
1511
15124. Enable USB debugging on the device.
1513
15145. When the authorization and trust dialog box is displayed, tap **Trust** or **Always trust**.
1515
15166. Restore the device to its factory settings.
1517
1518**Scenario 2**
1519
1520A USB device exists, but the driver is damaged. **HDC Device** with a warning icon in yellow is displayed.
1521
1522Symptom: This problem usually occurs in Windows. In **Device Manager/Universal Serial Bus Device**, **HDC Device** is displayed with a yellow warning icon, indicating that the device cannot work properly. To resolve the problem, reinstall the driver. If the problem persists, use another USB cable, docking station, or USB port.
1523
1524To reinstall the driver, perform the following steps:
1525
15261. Open **Device Manager**, and right-click the **HDC Device** with a warning icon.
1527
15282. In the displayed menu, choose **Update driver**.
1529
15303. In the first prompt window, click **Browse my computer for drivers**.
1531
15324. In the second prompt window, click **Let me pick from a list of available drivers on my computer**.
1533
15345. In the third prompt window, deselect **Show compatible hardware**, select **WinUsb Device** for **Manufacture** and **WinUsb Device** for **Model**, and click **Next**.
1535
1536**Scenario 3**
1537
1538If "[Fail]Failed to communicate with daemon" is displayed when the device is connected, the possible causes are:
1539
1540Symptom: After the hdc command is executed on the CLI, "[Fail]Failed to communicate with daemon" is returned.
1541
1542Possible causes are as follows:
1543
15441. The hdc or SDK does not match the device. If the device is the latest version, update the hdc or SDK tool to the latest version.
1545
15462. The port is occupied.
1547
1548When hdc and hdc_std use the same port simultaneously, the port set by **OHOS_HDC_SERVER_PORT** will cause a conflict. (If the variable is not set, the default port **8710** is used, resulting in the same conflict.) This problem also occurs when other software occupies the default hdc port.
1549
1550**Scenario 4**
1551
1552"Connect server failed" is displayed when the device is connected.
1553
1554The possible causes are as follows:
1555
1556**Port preemption**
1557
1558Solution:
1559
15601. Check the software processes that have the built-in hdc functionality.
1561   If the software (DevEco Studio or DevEco Testing) that has the built-in hdc functionality is running, stop these software processes and run hdc commands.
1562
15632. Check hdc port status.
1564   For example, if **OHOS_HDC_SERVER_PORT** is set to **8710**, run the following commands to check the port status.
1565
1566   Unix:
1567
1568   ```shell
1569   netstat -an |grep 8710
1570   ```
1571
1572   Windows:
1573
1574   ```shell
1575   netstat -an |findstr 8710
1576   ```
1577
1578   If the port is used by another software, stop the software process or change the **OHOS_HDC_SERVER_PORT** environment variable to another port number.
1579
15803. Make sure the server of any other version is stopped.
1581
1582   Windows:
1583
1584   Choose **Task Manager** > **Details**, right-click the **hdc.exe** process and choose **Open file location**. Check whether the location is the same as that configured in the environment variable. If not, stop the **hdc.exe** process by running the **hdc kill** command or terminating the process in **Task Manager**. Then, run the hdc command again. (After the server is stopped, running the hdc command will restart it.)
1585
1586   Unix:
1587
1588   Run the **ps -ef |grep hdc** command to query the hdc server and check whether the process startup location is the hdc file location set by the environment variable **Path**. If not, stop the hdc process by running the **hdc kill** or **kill -9 hdc** *PID* command, and run the hdc command again. (After the server is stopped, running the hdc command will restart it.)
1589
1590**Registry exception**
1591
1592Solution: Clear the registry. The procedure is as follows:
1593
15941. Press **Win+R** to open the **Run** dialog box, and enter **regedit** to open the registry.
1595
15962. Enter the following address in the address bar, and press **Enter** to access the registry of the USB device driver.
1597
1598   ```shell
1599   Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{88bae032-5a81-49f0-bc3d-a4ff138216d6}
1600   ```
1601
16023. Right-click **UpperFilters** and choose **Modify** from the shortcut menu. Back up and clear the value data in the file. If the fault persists, restore the data.
1603
16044. Refresh the **Device Manager**, remove and reconnect the USB cable to the USB port, or restart the PC.
1605
1606### What should I do if a non-root user cannot find the device when running the hdc command in Linux?
1607
1608**Symptom**
1609
1610After a non-root user connects the device to the PC through USB in Linux, the device cannot be found by running the **hdc list targets** command.
1611
1612**Possible Causes and Solution**
1613
1614By default, a non-root user does not have the permission to operate USB devices. To enable the permission, perform the following steps:
1615
1616- To temporarily grant the full operation permission on a USB device, run the following command:
1617
1618```shell
1619sudo chmod -R 777 /dev/bus/usb/
1620```
1621
1622- To permanently change the operation permission on a USB device, do as follows:
1623  1. Run the **lsusb** command to obtain the vendorID and productID of the USB device.
1624  2. Create an **udev** rule.
1625      Edit the **udev** loading rule and replace the default **idVendor** and **idProduct** values of the device with the values obtained in the previous step.
1626
1627      **MODE="0666"** indicates the permissions of **GROUP** (the user group) for the USB device. Ensure that the login user is in the user group.
1628
1629      ```shell
1630      $ sudo vim /etc/udev/rules.d/90-myusb.rules
1631        SUBSYSTEMS=="usb", ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", GROUP="users", MODE="0666"
1632      ```
1633
1634  3. Restart the computer or reload the **udev** rule.
1635
1636      ```shell
1637      sudo udevadm control --reload
1638      ```
1639
1640> **NOTE**
1641>
1642> Enabling the USB device operation permission for non-root users can solve the problem that the device cannot be found due to insufficient permission when hdc is used in Linux. However, granting the permission may cause potential security issues. You are advised to evaluate whether to enable the permission based on the application scenario.
1643
1644### What should I do if hdc cannot run?
1645
1646**Symptom**
1647
1648The hdc commands cannot be executed on the CLI.
1649
1650**Possible Causes and Solution**
1651
16521. The operating environment is abnormal.
1653   Linux: 64-bit Ubuntu 18.04 or later is recommended. If a libc++.so reference error occurs, run the **ldd** or **readelf** command to check the library reference.
1654
1655   macOS: macOS 11 or later is recommended.
1656
1657   Windows: Windows 10 or Windows 11 64-bit is recommended. If the WinUSB library or driver is missing in an earlier version, use [Zadig](https://github.com/pbatard/libwdi/releases) to update it. For devices that require driver installation, use Zadig to install the libusb-win32 driver. For details, see [Zadig](https://github.com/pbatard/libwdi/releases).
1658
16592. Improper running mode: Use the correct command to run the hdc tool instead of double-clicking the file.
1660
1661### What should I do if garbled characters are displayed when the hdc file send/recv command is used to transfer Chinese files?
1662
1663**Symptom**
1664
1665Garbled characters are displayed when the **hdc file send/recv** command is executed. For example, when the **file recv** command is used to send a file with a Chinese name from the device to the local host, the error message "[Fail]Error opening file: no such file or directory, path:XXXXX" is displayed, and the path contains garbled characters.
1666
1667![File transfer garbled text ](figures/file_transfer_garbled_text.png)
1668
1669**Possible Causes and Solution**
1670
1671Since 3.1.0a, the file transfer command supports Chinese characters in the parameter path. Update the version to the latest version.
1672
1673Run the **hdc checkserver** command to check the current version. If the version is earlier than 3.1.0a, upgrade the SDK to API version 12 or later.
1674
1675### What should I do if "Unauthorized" is displayed after the hdc list targets command is executed?
1676
1677**Symptom**
1678
1679When the **hdc list targets** command is executed to query the connected devices, "Unauthorized" is displayed next to the device ID.
1680
1681![Device not certified ](figures/device_not_certified.png)
1682
1683**Possible Causes and Solution**
1684
1685- If the device is not authorized upon the first connection, unlock the device after connecting to it. The "Trust this device?" dialog box is displayed. Click **Always trust** or **Trust** to complete the authorization.
1686
1687- If the authorization dialog box times out or you click **Don't trust**, restart debugging by going to **Settings** > **System** > **Developer options** > **USB debugging**/**Wireless debugging**, or run **hdc kill -r** to restart the server. Then the screen will display the "Trust this device?" dialog box again. Click **Always trust** or **Trust** to complete the authorization.
1688
1689### What should I do if "CryptAcquireContext second failed" is displayed when a hdc command is executed?
1690
1691**Symptom**
1692
1693When a hdc command is executed, the error message "CryptAcquireContext second failed XXX" is displayed?
1694
1695**Possible Causes and Solution**
1696
1697Modify the registry information in the PC as follows:
1698
16991. Press **Win+R** to open the **Run** dialog box, and enter **regedit** to open the registry.
1700
17012. Enter the following address in the address bar, and press **Enter**.
1702   **Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\Protect\Providers\df9d8cd0-1501-11d1-8c7a-00c04fc297eb**;
1703
17043. Right-click to create a DWORD (32-bit) value (D), set its name to **ProtectionPolicy** and value to **1** (hexadecimal), and click **OK**.
1705
17064. Restart the computer. The problem is solved.
1707
1708### What should I do if "Unknown USB Device (Device Descriptor Request Failed)" is displayed in Windows Device Manager?
1709
1710**Symptom**
1711
1712When a device is connected using USB, "Unknown USB Device (Device Descriptor Request Failed)" is displayed in **Universal Serial Bus controllers** of **Device Manager** on the PC.
1713
1714**Possible Causes and Solution**
1715
17161. Go to the Windows Service Management page (by inputting **services.msc**) and restart the **Plug and Play** service.
1717
17182. Uninstall the faulty USB device in Device Manager and remove the USB cable.
1719
17203. Restart the computer.
1721
1722If this problem persists after these steps or after you connect the device to another computer, the driver of the USB device may be faulty. In this case, replace the USB cable.
1723
1724### What should I do if the hdc command fails to be executed?
1725
1726**Symptom**
1727
1728If the hdc command output is not as expected, the possible causes are as follows:
1729
1730- Scenario 1: When the hdc command is executed, the message "Connect server failed" is displayed.
1731
1732- Scenario 2: When the hdc command is executed, the message "connect failed status:-4078" is displayed.
1733
1734- Scenario 3: No output is displayed after the hdc command is executed.
1735
1736**Possible Causes and Solution**
1737
1738To solve the port exception problem, perform the following steps:
1739
17401. Check the software processes that come with hdc, including software with built-in hdc, such as DevEco Studio and DevEco Testing. If such software exists, close it and then run the hdc commands.
1741
17422. Check hdc port status. For example, if **OHOS_HDC_SERVER_PORT** is set to **8710**, run the following command to check the port status.
1743   Unix:
1744
1745   ```shell
1746   netstat -an |grep 8710
1747   ```
1748
1749   Windows:
1750
1751   ```shell
1752   netstat -an |findstr 8710
1753   ```
1754
1755   If the port is used by another software, terminate the software process or change the **OHOS_HDC_SERVER_PORT** environment variable to another port number.
1756
17573. Make sure the server of any other version is stopped.
1758
1759   Windows: Choose **Task Manager** > **Details**, right-click the **hdc.exe** process and choose **Open file location**. Check whether the location is the same as that configured in the environment variable. If not, stop the **hdc.exe** process by running the **hdc kill** command or terminating the process in **Task Manager**. Then, run the hdc command again. (After the server is stopped, running the hdc command will restart it.)
1760
1761   Unix: Run the **ps -ef | grep hdc** command to query the hdc server process running in the background and check whether the process startup location is the hdc file location set by the environment variable **Path**. If not, stop the hdc process by running the **hdc kill** or **kill -9 hdc** *PID* command, and run the hdc command again. (After the server is stopped, running the hdc command will restart it.)
1762
1763### Common Procedure for Troubleshooting Other Problems
1764
17651. Run the **hdc list targets** command.
1766
17672. Check whether **HDC Device** exists in device management.
1768
17693. Run the **hdc kill** command to stop the server and run the **hdc -l5 start** command to collect logs. (The **hdc.log** file is stored in the **TEMP** directory on the execution end. The directory varies depending on the operating system. For details, see [Server Logs](#server-logs).)
1770
17714. Locate the problem based on the **hdc.log** file.
1772
1773> **NOTE**
1774>
1775> For more FAQs, see [FAQs](https://developer.huawei.com/consumer/en/doc/harmonyos-faqs/faqs-performance-analysis-kit).
1776
1777## hdc Error Codes
1778
1779### E000001 hdc Version Too Early
1780
1781**Error Message**
1782
1783The sdk hdc.exe version is too low, please upgrade to the latest version.
1784
1785**Symptom**
1786
1787The hdc version is too early. You need to update it to the latest version.
1788
1789**Possible Causes**
1790
1791If the client version is earlier than 3.0.0b, authorization is not supported and the client cannot access the system.
1792
1793**Solution**
1794
1795Update the hdc to the latest version by referring to [hdc Version Mappings](#hdc-version-mappings).
1796
1797### E000002 Unauthorized Device
1798
1799**Error Message**
1800
1801The device unauthorized.
1802
1803This server's public key is not set.
1804
1805Please check for a confirmation dialog on your device.
1806
1807Otherwise try 'hdc kill' if that seems wrong.
1808
1809**Symptom**
1810
1811The device is not authorized. Check whether the device has been authorized on the authorization dialog box. If the device has been authorized, run the **hdc kill** command and then run the debugging command again.
1812
1813**Possible Causes**
1814
1815- Scenario 1: When the device is connected for the first time, the debugging computer is not authorized on the device.
1816
1817- Scenario 2: If the authorization dialog box is displayed and you click **Trust** instead of **Always trust**, you need to authorize the device again after reconnecting to the device.
1818
1819**Solution**
1820
1821- Scenario 1: In the authorization dialog box displayed on the device, click **Trust**.
1822
1823- Scenario 2: Go to **Settings** > **System** > **Developer options**, reenable **Debugging**, and reconnect the device to authorize it. Alternatively, run the **hdc kill -r** command to restart hdc to trigger the authorization dialog box again, and click **Always trust**.
1824
1825### E000003 Unauthorized User on the Device
1826
1827**Error Message**
1828
1829The device unauthorized.
1830
1831The user denied the access for the device.
1832
1833Please execute 'hdc kill' and redo your command,
1834
1835then check for a confirmation dialog on your device.
1836
1837**Symptom**
1838
1839The device is not authorized. If the device rejects the debugging authorization, run the **hdc kill** command and run the debugging command again. Then check the authorization dialog box on the device.
1840
1841**Possible Causes**
1842
18431. The authorization dialog box on the device is automatically closed due to timeout, and the authorization is not confirmed.
1844
18452. You have clicked **Don't trust** to reject the authorization.
1846
1847**Solution**
1848
1849Go to **Settings** > **System** > **Developer options**, reenable **Debugging**, and reconnect the device to authorize it. Alternatively, run the **hdc kill -r** command to restart hdc to trigger the authorization dialog box again, and click **Always trust**.
1850
1851### E000004 Unstable Communication Connection
1852
1853**Error Message**
1854
1855The communication channel is being established.
1856
1857Please wait for several seconds and try again.
1858
1859**Symptom**
1860
1861It indicates that the communication channel is not established and asks you to try again after several seconds.
1862
1863**Possible Causes**
1864
1865The network or USB connection is not established or unstable.
1866
1867**Solution**
1868
1869After the device is connected, wait for about 10 seconds. After the connection is established, debug the device.
1870
1871### E001000 tmode Does Not Support USB Debugging
1872
1873**Error Message**
1874
1875For USB debugging, please set it on the device's Settings UI.
1876
1877**Symptom**
1878
1879The **hdc tmode** command cannot be used to set USB debugging.
1880
1881**Possible Causes**
1882
1883The **hdc tmode usb** command is deprecated. For details, see [Switching Between USB Debugging and Wireless Debugging](#switching-between-usb-debugging-and-wireless-debugging).
1884
1885**Solution**
1886
1887For details about the **tmode usb** command, see [Switching Between USB Debugging and Wireless Debugging](#switching-between-usb-debugging-and-wireless-debugging).
1888
1889### E001001 Unknown Command
1890
1891**Error Message**
1892
1893Unknown command.
1894
1895**Symptom**
1896
1897The **hdc tmode** command is incorrect.
1898
1899**Possible Causes**
1900
1901Parameters are missing or incorrect in the **hdc tmode** command.
1902
1903**Solution**
1904
1905Complete the command by referring to [Switching Between USB Debugging and Wireless Debugging](#switching-between-usb-debugging-and-wireless-debugging).
1906
1907### E001003 USB Connection Error
1908
1909**Error Message**
1910
1911USB communication abnormal, please check the USB communication link.
1912
1913**Symptom**
1914
1915The USB communication is abnormal. Check the USB communication link.
1916
1917**Possible Causes**
1918
1919- The USB cable is loose or disconnected.
1920
1921- After the **hdc shell reboot** command is executed, the device restarts and is disconnected. In this case, no action is required.
1922
1923- After the **hdc tmode port XXX** command is executed, the USB debugging mode is switched to the wireless debugging mode, and the device is disconnected. In this case, no action is required.
1924
1925**Solution**
1926
1927- Ensure that the USB cable is securely connected to the device and computer. If the connection is normal but the issue persists, change the USB cable or USB port.
1928
1929- Update the hdc to the latest version by referring to [hdc Version Mappings](#hdc-version-mappings).
1930
1931### E001104 Invalid IP Address in the tconn Command
1932
1933**Error Message**
1934
1935IP address incorrect.
1936
1937**Symptom**
1938
1939The IP address format is incorrect.
1940
1941**Possible Causes**
1942
1943When the **tconn** command is used for wireless debugging connection, the input IP address is not in IPv4 format.
1944
1945**Solution**
1946
1947Check whether the input IP address is valid by referring to the correct format **127.0.0.1:8888**. If invalid characters exist, correct the IP address and re-establish the connection.
1948
1949### E001005 Unknown or Disconnected Device
1950
1951**Error Message**
1952
1953Device not found or connected.
1954
1955**Symptom**
1956
1957No connected device is found or the device is not connected.
1958
1959**Possible Causes**
1960
1961The device is disconnected.
1962
1963**Solution**
1964
1965For details, see [What should I do if the device cannot be identified](#what-should-i-do-if-the-device-cannot-be-identified).
1966
1967### E001300 Emulator Does Not Support the tmode Command
1968
1969**Error Message**
1970
1971Not support tmode for Emulator.
1972
1973**Symptom**
1974
1975The Emulator does not support the **hdc tmode** command.
1976
1977**Possible Causes**
1978
1979The Emulator in DevEco Studio does not support the **hdc tmode** command.
1980
1981**Solution**
1982
1983To use tmode-related commands, connect to a physical device.
1984
1985### E002101 Failed to Terminate the Server
1986
1987**Error Message**
1988
1989Terminal hdc process failed, please terminal the hdc process in the task manager first.
1990
1991**Symptom**
1992
1993The server cannot be terminated.
1994
1995**Possible Causes**
1996
1997After the **.hdcserver.pid** file is deleted, the server cannot be terminated by the **hdc kill** command because the server PID cannot be obtained.
1998
1999**Solution**
2000
2001Terminate the hdc server in Task Manager.
2002
2003### E002105 Command Not Supported
2004
2005**Error Message**
2006
2007Unsupport command.
2008
2009**Symptom**
2010
2011The command is not supported.
2012
2013**Possible Causes**
2014
2015The device version is too early to support debugging commands.
2016
2017**Solution**
2018
2019Upgrade the device version or check whether the command is correct by referring to [hdc Commands](#hdc-commands).
2020
2021### E002106 Device Communication Exception
2022
2023**Error Message**
2024
2025Failed to communicate with daemon.
2026
2027**Symptom**
2028
2029The communication between the server and the daemon on the device is abnormal.
2030
2031**Possible Causes**
2032
2033- The USB is disconnected.
2034
2035- The network is unstable over TCP.
2036
2037**Solution**
2038
2039Check and ensure that the device is properly connected.
2040
2041Check the network status. After the network becomes stable, try again.
2042
2043### E003001 Invalid Bundle Name
2044
2045**Error Message**
2046
2047Invalid bundle name: bundlename.
2048
2049**Symptom**
2050
2051The **bundlename** specified in the **hdc shell [-b bundlename] [command]** command does not belong to an installed and started debug-type application, or the application directory does not exist.
2052
2053**Possible Causes**
2054
20551. Scenario 1: The specified application is not installed on the device.
2056
20572. Scenario 2: The specified application is not a debug-type application.
2058
20593. Scenario 3: The specified application is not started.
2060
2061**Solution**
2062
2063- Scenario 1: Ensure that the application specified in the command has been installed on the device.
2064  Run the **hdc shell "bm dump -a | grep bundlename"** command to check whether the application corresponding to the bundle name has been installed on the device. The expected result is **bundlename**.
2065
2066  For example, if the bundle name is **com.example.myapplication**, run the following command:
2067
2068  ```shell
2069  hdc shell "bm dump -a | grep com.example.myapplication"
2070  ```
2071
2072  If the bundle has been installed on the device, the following information is returned:
2073
2074  ```shell
2075  com.example.myapplication
2076  ```
2077
2078- Scenario 2: Check whether the application specified by the command is a debug-type application.
2079  1. Run the **hdc shell "bm dump -n bundlename | grep appProvisionType"** command. The expected result is **"appProvisionType": "debug"**.
2080      For example, run the following command to check the bundle name **com.example.myapplication**:
2081
2082      ```shell
2083      hdc shell "bm dump -n com.example.myapplication | grep appProvisionType"
2084      ```
2085
2086      If the application is a debug-type application, the following information is displayed:
2087
2088      ```shell
2089      "appProvisionType": "debug",
2090      ```
2091
2092  2. To build a debug-type application, you need to sign the application using a debug certificate. For details, see [Requesting a Debug Certificate](https://developer.huawei.com/consumer/en/doc/app/agc-help-add-debugcert-0000001914263178).
2093
2094- Scenario 3: Ensure that the bundle specified by the command has been started.
2095  1. After the application starts, the system mounts the corresponding resource directory. You can run the **hdc shell "mount |grep bundle name"** command to query the resource directory mounting status after the application starts.
2096      For example, to check the bundle name **com.example.myapplication**, run the following command:
2097
2098      ```shell
2099      hdc shell "mount |grep com.example.myapplication"
2100      ```
2101
2102      If the corresponding resource directory has been mounted, mounting information is expected to be returned. (The returned information varies according to the actual mounting status and is not displayed here.)
2103
2104      If the corresponding resource directory is not mounted, no information is returned.
2105  2. If the corresponding resource directory is not mounted, you can click the application or run the **aa** command to start the application.
2106      For example, to start the application whose name is **com.example.myapplication** and module name is **EntryAbility**, run the following command:
2107
2108      ```shell
2109      hdc shell aa start -b com.example.myapplication -a EntryAbility
2110      ```
2111
2112      For details, see [aa Commands](../tools/aa-tool.md).
2113
2114### E003002 Command Parameter Does Not Support the Interactive Mode
2115
2116**Error Message**
2117
2118Unsupport interactive shell command option.
2119
2120**Symptom**
2121
2122The **hdc shell [-b bundlename] [command]** command does not support the interactive option.
2123
2124**Possible Causes**
2125
2126The **command** parameter specified by **hdc shell [-b bundlename] [command]** cannot be empty.
2127
2128**Solution**
2129
2130Ensure that the **command** parameter is not empty. For details, see [Running Interactive Commands](#running-interactive-commands).
2131
2132### E003003 Interactive Command Parameters Not Supported
2133
2134**Error Message**
2135
2136Unsupport shell option: XXX.
2137
2138**Symptom**
2139
2140The **hdc shell [-b bundlename] [command]** command specifies unsupported command parameters, such as **-f** and **-B**.
2141
2142**Possible Causes**
2143
2144The parameters are case insensitive, or unsupported parameters are used.
2145
2146**Solution**
2147
2148Use the command parameters supported by the current version, for example, the **-b** parameter. For details, see [Running Interactive Commands](#running-interactive-commands).
2149
2150### E003004 Parameter Not Supported by the Device
2151
2152**Error Message**
2153
2154Device does not supported this shell command.
2155
2156**Symptom**
2157
2158The device does not support the **hdc shell [-b bundlename] [command]** command.
2159
2160**Possible Causes**
2161
2162The device version is too early to support new command parameters.
2163
2164**Solution**
2165
2166Upgrade the device OS to the latest version. For details, see [hdc Version Mappings](#hdc-version-mappings).
2167
2168### E003005 Incorrect Command Parameters
2169
2170**Error Message**
2171
2172The parameter is missing, correct your input by referring below: Usage...
2173
2174**Symptom**
2175
2176The** hdc shell xxx** command is not supported on the device.
2177
2178**Possible Causes**
2179
2180The system version of the device is too early to support the new command parameters.
2181
2182**Solution**
2183
2184Upgrade the device OS to the latest version. For details, see [hdc Version Mappings](#hdc-version-mappings).
2185
2186### E005003 Parameter Missing in File Transfer
2187
2188**Error Message**
2189
2190There is no bundle name.
2191
2192**Symptom**
2193
2194- Mandatory parameters are missing in the **hdc file send [-b bundlename][SOURCE][DEST]** command.
2195
2196- Mandatory parameters are missing in the **hdc file recv [-b bundlename][DEST][SOURCE]** command.
2197
2198**Possible Causes**
2199
2200When the **-b** parameter is specified, the **bundlename**, **SOURCE**, and **DEST** parameters are missing. For details about the command, see [Transferring Files](#transferring-files).
2201
2202**Solution**
2203
2204Ensure that the **bundlename**, **SOURCE**, and **DEST** parameters are not empty.
2205
2206### E005004 SDK or Device System Does Not Support the -b Parameter
2207
2208**Error Message**
2209
2210SDK/Device ROM doesn't support -b option.
2211
2212**Symptom**
2213
2214The **hdc file send/recv** command contains the **-b** option, but the hdc in SDK or device system version does not support this option.
2215
2216**Possible Causes**
2217
2218- Scenario 1: When the **hdc file send [-b bundlename] [SOURCE] [DEST]** command is executed, the device system does not support the **-b** option.
2219
2220- Scenario 2: When the **hdc file recv [-b bundlename] [DEST] [SOURCE]** command is executed, the hdc in SDK does not support the **-b** option.
2221
2222**Solution**
2223
2224- Scenario 1: Upgrade the system to the latest version. For details, see [hdc Version Mappings](#hdc-version-mappings).
2225
2226- Scenario 2: Upgrade the SDK to the latest version. For details, see [hdc Version Mappings](#hdc-version-mappings).
2227
2228### E005005 Failed to Create a Directory
2229
2230**Error Message**
2231
2232Error create directory: xxx, path: xxx.
2233
2234**Symptom**
2235
2236Failed to create a directory.
2237
2238**Possible Causes**
2239
2240When the **hdc file send** command is executed to send a file, the corresponding directory on the device is an unauthorized directory or a read-only system directory.
2241
2242**Solution**
2243
2244Change the target directory for sending files, and ensure that it has the write permission.
2245
2246### E005101 Invalid Bundle Name During File Transfer
2247
2248Same as the error code [E003001 Invalid Bundle Name](#e003001-invalid-bundle-name).
2249
2250### E005102 Invalid Remote Path
2251
2252**Error Message**
2253
2254Remote path: xxx is invalid, no such file/directory or it's out of the application directory.
2255
2256**Symptom**
2257
2258- The path specified by **DEST** in the **hdc file send [-b bundlename][SOURCE][DEST]** command does not exist or exceeds the application data directory.
2259
2260- The path specified by **DEST** in the **hdc file recv [-b bundlename][SOURCE][DEST]** command does not exist or exceeds the application data directory.
2261
2262**Possible Causes**
2263
2264- Scenario 1: The remote path does not exist.
2265
2266- Scenario 2: The **DEST** parameter contains the **..** redirection symbol. After the redirection, the directory exceeds the application data root directory.
2267
2268**Solution**
2269
2270Check whether the relative path of the application data directory specified by **DEST** exists.
2271
2272### E006001 Invalid Installation Package Path
2273
2274**Error Message**
2275
2276Not any installation package was found.
2277
2278**Symptom**
2279
2280No installation package is found.
2281
2282**Possible Causes**
2283
2284The installation package parameter is missing when the **hdc install** command is executed.
2285
2286**Solution**
2287
2288For details, see [Managing Applications](#managing-applications).
2289
2290### E007100 Unsupported Command
2291
2292**Error Message**
2293
2294Operate need running under debug mode.
2295
2296**Symptom**
2297
2298The command can be executed only in debug mode.
2299
2300**Possible Causes**
2301
2302The command is not supported.
2303
2304**Solution**
2305
2306No operation is required.
2307
2308### E005008 Unsupported File Transfer Operation
2309
2310**Error Message**
2311
2312Operation not allowed.
2313
2314**Symptom**
2315
2316The command operation is not allowed.
2317
2318**Possible Causes**
2319
2320Operations on sensitive files (such as system configuration files and log files) are not allowed.
2321
2322**Solution**
2323
2324No operation is required.
2325
2326### E001106 Incorrect IP Address Specified by -e
2327
2328**Error Message**
2329
2330-e content IP incorrect
2331
2332**Symptom**
2333
2334-The IP address specified by **-e** is incorrect.
2335
2336**Possible Causes**
2337
2338The IP address format is invalid.
2339
2340**Solution**
2341
2342Ensure that the entered IP address is valid and the IP address belongs to the local host.
2343