1# @ohos.usbManager (USB Manager) (System API)
2
3The **usbManager** module provides USB device management functions, including USB device list query, bulk data transfer, control transfer, and permission control on the host side as well as port management, and function switch and query on the device side.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8>
9> This topic describes only the system APIs provided by the module. For details about its public APIs, see [@ohos.usbManager (USB Manager)](js-apis-usbManager.md).
10
11## Modules to Import
12
13```ts
14import { usbManager } from '@kit.BasicServicesKit';
15```
16
17## addRight <sup>(deprecated)</sup>
18
19addRight(bundleName: string, deviceName: string): boolean
20
21Adds the device access permission for the application. System applications are granted the device access permission by default, and calling this API will not revoke the permission.
22
23**usbManager.requestRight** triggers a dialog box to request for user authorization, whereas **addRight** adds the access permission directly without displaying a dialog box. 
24
25> **NOTE**
26>
27> This API is supported since API version 9 and deprecated since API version 12. You are advised to use [addDeviceAccessRight](#adddeviceaccessright12).
28
29**System API**: This is a system API.
30
31**System capability**: SystemCapability.USB.USBManager
32
33**Parameters**
34
35| Name    | Type  | Mandatory| Description        |
36| ---------- | ------ | ---- | ------------ |
37| deviceName | string | Yes  | Device name.  |
38| bundleName | string | Yes  | Bundle name of the application.|
39
40**Error codes**
41
42For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
43
44| ID| Error Message                                                                                               |
45| -------- | ------------------------------------------------------------------------------------------------------- |
46| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
47| 202      | Permission denied. Normal application do not have permission to use system api.                         |
48
49**Return value**
50
51| Type   | Description                                                                     |
52| ------- | ------------------------------------------------------------------------- |
53| boolean | Permission addition result. The value **true** indicates that the access permission is added successfully; and the value **false** indicates the opposite.|
54
55**Example**
56
57```ts
58let devicesName: string = "1-1";
59let bundleName: string = "com.example.hello";
60if (usbManager.addRight(bundleName, devicesName)) {
61  console.log(`Succeed in adding right`);
62}
63```
64
65## usbFunctionsFromString<sup>(deprecated)</sup>
66
67usbFunctionsFromString(funcs: string): number
68
69Converts the USB function list in the string format to a numeric mask in Device mode.
70
71> **NOTE**
72>
73> This API is supported since API version 9 and deprecated since API version 12. You are advised to use [getFunctionsFromString](#getfunctionsfromstring12).
74
75**System API**: This is a system API.
76
77**System capability**: SystemCapability.USB.USBManager
78
79**Parameters**
80
81| Name| Type  | Mandatory| Description                  |
82| ------ | ------ | ---- | ---------------------- |
83| funcs  | string | Yes  | Function list in string format.|
84
85**Error codes**
86
87For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
88
89| ID| Error Message                                                                                               |
90| -------- | ------------------------------------------------------------------------------------------------------- |
91| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
92| 202      | Permission denied. Normal application do not have permission to use system api.                         |
93
94**Return value**
95
96| Type  | Description              |
97| ------ | ------------------ |
98| number | Function list in numeric mask format.|
99
100**Example**
101
102```ts
103let funcs: string = "acm";
104let ret: number = usbManager.usbFunctionsFromString(funcs);
105```
106
107## usbFunctionsToString<sup>(deprecated)</sup>
108
109usbFunctionsToString(funcs: FunctionType): string
110
111Converts the USB function list in the numeric mask format to a string in Device mode.
112
113> **NOTE**
114>
115> This API is supported since API version 9 and deprecated since API version 12. You are advised to use [getStringFromFunctions](#getstringfromfunctions12).
116
117**System API**: This is a system API.
118
119**System capability**: SystemCapability.USB.USBManager
120
121**Parameters**
122
123| Name| Type                         | Mandatory| Description             |
124| ------ | ----------------------------- | ---- | ----------------- |
125| funcs  | [FunctionType](#functiontype) | Yes  | USB function list in numeric mask format.|
126
127**Error codes**
128
129For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
130
131| ID| Error Message                                                                                               |
132| -------- | ------------------------------------------------------------------------------------------------------- |
133| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
134| 202      | Permission denied. Normal application do not have permission to use system api.                         |
135
136**Return value**
137
138| Type  | Description                          |
139| ------ | ------------------------------ |
140| string | Function list in string format.|
141
142**Example**
143
144```ts
145let funcs: number = usbManager.FunctionType.ACM | usb.FunctionType.ECM;
146let ret: string = usbManager.usbFunctionsToString(funcs);
147```
148
149## setCurrentFunctions<sup>(deprecated)</sup>
150
151setCurrentFunctions(funcs: FunctionType): Promise\<void\>
152
153Sets the current USB function list in Device mode.
154
155> **NOTE**
156>
157> This API is supported since API version 9 and deprecated since API version 12. You are advised to use [setDeviceFunctions](#setdevicefunctions12).
158
159**System API**: This is a system API.
160
161**System capability**: SystemCapability.USB.USBManager
162
163**Parameters**
164
165| Name| Type                         | Mandatory| Description             |
166| ------ | ----------------------------- | ---- | ----------------- |
167| funcs  | [FunctionType](#functiontype) | Yes  | USB function list in numeric mask format.|
168
169**Error codes**
170
171For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
172
173| ID| Error Message                                                                                               |
174| -------- | ------------------------------------------------------------------------------------------------------- |
175| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
176| 14400002 | Permission denied. The HDC is disabled by the system.                                                   |
177
178**Return value**
179
180| Type               | Description         |
181| ------------------- | ------------- |
182| Promise\<**void**\> | Promise used to return the result.|
183
184**Example**
185
186```ts
187import {BusinessError} from '@kit.BasicServicesKit';
188let funcs: number = usbManager.FunctionType.HDC;
189usbManager.setCurrentFunctions(funcs).then(() => {
190    console.info('usb setCurrentFunctions successfully.');
191}).catch((err: BusinessError) => {
192    console.error('usb setCurrentFunctions failed: ' + err.code + ' message: ' + err.message);
193});
194```
195
196## getCurrentFunctions<sup>(deprecated)</sup>
197
198getCurrentFunctions(): FunctionType
199
200Obtains the numeric mask combination for the USB function list in Device mode.
201
202> **NOTE**
203>
204> This API is supported since API version 9 and deprecated since API version 12. You are advised to use [getDeviceFunctions](#getdevicefunctions12).
205
206**System API**: This is a system API.
207
208**System capability**: SystemCapability.USB.USBManager
209
210**Error codes**
211
212For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
213
214| ID| Error Message                                                                       |
215| -------- | ------------------------------------------------------------------------------- |
216| 401      | Parameter error. No parameters are required.                                    |
217| 202      | Permission denied. Normal application do not have permission to use system api. |
218
219**Return value**
220
221| Type                         | Description                             |
222| ----------------------------- | --------------------------------- |
223| [FunctionType](#functiontype) | Numeric mask combination for the USB function list.|
224
225**Example**
226
227```ts
228let ret: number = usbManager.getCurrentFunctions();
229```
230
231## getPorts<sup>(deprecated)</sup>
232
233getPorts(): Array\<USBPort\>
234
235Obtains the list of all physical USB ports.
236
237> **NOTE**
238>
239> This API is supported since API version 9 and deprecated since API version 12. You are advised to use [getPortList](#getportlist12).
240
241**System API**: This is a system API.
242
243**System capability**: SystemCapability.USB.USBManager
244
245**Error codes**
246
247For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
248
249| ID| Error Message                                                                       |
250| -------- | ------------------------------------------------------------------------------- |
251| 401      | Parameter error. No parameters are required.                                    |
252| 202      | Permission denied. Normal application do not have permission to use system api. |
253
254**Return value**
255
256| Type                      | Description                 |
257| -------------------------- | --------------------- |
258| Array<[USBPort](#usbport)> | List of physical USB ports.|
259
260**Example**
261
262```ts
263let ret: Array<usbManager.USBPort> = usbManager.getPorts();
264```
265
266## getSupportedModes(deprecated)
267
268getSupportedModes(portId: number): PortModeType
269
270Obtains the mask combination for the supported mode list of a given USB port.
271
272> **NOTE**
273>
274> This API is supported since API version 9 and deprecated since API version 12. You are advised to use [getPortSupportModes](#getportlist12).
275
276**System API**: This is a system API.
277
278**System capability**: SystemCapability.USB.USBManager
279
280**Parameters**
281
282| Name| Type  | Mandatory| Description    |
283| ------ | ------ | ---- | -------- |
284| portId | number | Yes  | Port number.|
285
286**Error codes**
287
288For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
289
290| ID| Error Message                                                                                               |
291| -------- | ------------------------------------------------------------------------------------------------------- |
292| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
293| 202      | Permission denied. Normal application do not have permission to use system api.                         |
294
295**Return value**
296
297| Type                         | Description                      |
298| ----------------------------- | -------------------------- |
299| [PortModeType](#portmodetype) | Mask combination for the supported mode list.|
300
301**Example**
302
303```ts
304let ret: number = usbManager.getSupportedModes(0);
305```
306
307## setPortRoles<sup>(deprecated)</sup>
308
309setPortRoles(portId: number, powerRole: PowerRoleType, dataRole: DataRoleType): Promise\<void\>
310
311Sets the role types supported by a specified port, which can be **powerRole** (for charging) and **dataRole** (for data transfer).
312
313> **NOTE**
314>
315> This API is supported since API version 9 and deprecated since API version 12. You are advised to use [setPortRoleTypes](#setportroletypes12).
316
317**System API**: This is a system API.
318
319**System capability**: SystemCapability.USB.USBManager
320
321**Parameters**
322
323| Name   | Type                           | Mandatory| Description            |
324| --------- | ------------------------------- | ---- | ---------------- |
325| portId    | number                          | Yes  | Port number.        |
326| powerRole | [PowerRoleType](#powerroletype) | Yes  | Role for charging.    |
327| dataRole  | [DataRoleType](#dataroletype)   | Yes  | Role for data transfer.|
328
329**Error codes**
330
331For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
332
333| ID| Error Message                                                                                               |
334| -------- | ------------------------------------------------------------------------------------------------------- |
335| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
336
337**Return value**
338
339| Type               | Description         |
340| ------------------- | ------------- |
341| Promise\<**void**\> | Promise used to return the result.|
342
343**Example**
344
345```ts
346import {BusinessError} from '@kit.BasicServicesKit';
347let portId: number = 1;
348usbManager.setPortRoles(portId, usbManager.PowerRoleType.SOURCE, ususbManagerb.DataRoleType.HOST).then(() => {
349    console.info('usb setPortRoles successfully.');
350}).catch((err: BusinessError) => {
351    console.error('usb setPortRoles failed: ' + err.code + ' message: ' + err.message);
352});
353```
354
355## addDeviceAccessRight<sup>12+</sup>
356
357addDeviceAccessRight(tokenId: string, deviceName: string): boolean
358
359Adds the device access permission for the application. System applications are granted the device access permission by default, and calling this API will not revoke the permission.
360
361**usbManager.requestRight** triggers a dialog box to request for user authorization, whereas **addDeviceAccessRight** adds the access permission directly without displaying a dialog box.
362
363> **NOTE**
364>
365> This API is supported since API version 12.
366
367**System API**: This is a system API.
368
369**Required permissions**: ohos.permission.MANAGE_USB_CONFIG
370
371**System capability**: SystemCapability.USB.USBManager
372
373**Parameters**
374
375| Name    | Type  | Mandatory| Description           |
376| ---------- | ------ | ---- | --------------- |
377| deviceName | string | Yes  | Device name.     |
378| tokenId    | string | Yes  | Token ID of the software package.|
379
380**Error codes**
381
382For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
383
384| ID| Error Message                                                                                               |
385| -------- | ------------------------------------------------------------------------------------------------------- |
386| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
387| 202      | Permission denied. Normal application do not have permission to use system api.                         |
388
389**Return value**
390
391| Type   | Description                                                                     |
392| ------- | ------------------------------------------------------------------------- |
393| boolean | Permission addition result. The value **true** indicates that the access permission is added successfully; and the value **false** indicates the opposite.|
394
395**Example**
396
397```ts
398import bundleManager from '@ohos.bundle.bundleManager';
399import { BusinessError } from '@kit.BasicServicesKit';
400let devicesName: string = "1-1";
401let tokenId: string = "";
402
403  try {
404    let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;
405    bundleManager.getBundleInfoForSelf(bundleFlags).then((bundleInfo) => {
406      console.info('testTag', 'getBundleInfoForSelf successfully. Data: %{public}s', JSON.stringify(bundleInfo));
407      let token = bundleInfo.appInfo.accessTokenId;
408      tokenId = token.toString();
409      if (usbManager.addDeviceAccessRight(tokenId, devicesName)) {
410        console.log(`Succeed in adding right`);
411      }
412    }).catch((err : BusinessError) => {
413      console.error('testTag getBundleInfoForSelf failed' );
414    });
415  } catch (err) {
416    console.error('testTag failed');
417  }
418```
419
420## getFunctionsFromString<sup>12+</sup>
421
422getFunctionsFromString(funcs: string): number
423
424Converts the USB function list in the string format to a numeric mask in Device mode.
425
426> **NOTE**
427>
428> This API is supported since API version 12.
429
430**System API**: This is a system API.
431
432**Required permissions**: ohos.permission.MANAGE_USB_CONFIG
433
434**System capability**: SystemCapability.USB.USBManager
435
436**Parameters**
437
438| Name| Type  | Mandatory| Description                  |
439| ------ | ------ | ---- | ---------------------- |
440| funcs  | string | Yes  | Function list in string format.|
441
442**Error codes**
443
444For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
445
446| ID| Error Message                                                                       |
447| -------- | ------------------------------------------------------------------------------- |
448| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
449| 202      | Permission denied. Normal application do not have permission to use system api. |
450
451**Return value**
452
453| Type  | Description              |
454| ------ | ------------------ |
455| number | Function list in numeric mask format.|
456
457**Example**
458
459```ts
460let funcs: string = "acm";
461let ret: number = usbManager.getFunctionsFromString(funcs);
462```
463
464## getStringFromFunctions<sup>12+</sup>
465
466getStringFromFunctions(funcs: FunctionType): string
467
468Converts the USB function list in the numeric mask format to a string in Device mode.
469
470> **NOTE**
471>
472> This API is supported since API version 12.
473
474**System API**: This is a system API.
475
476**Required permissions**: ohos.permission.MANAGE_USB_CONFIG
477
478**System capability**: SystemCapability.USB.USBManager
479
480**Parameters**
481
482| Name| Type                         | Mandatory| Description             |
483| ------ | ----------------------------- | ---- | ----------------- |
484| funcs  | [FunctionType](#functiontype) | Yes  | USB function list in numeric mask format.|
485
486**Error codes**
487
488For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
489
490| ID| Error Message                                                                                               |
491| -------- | ------------------------------------------------------------------------------------------------------- |
492| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
493| 202      | Permission denied. Normal application do not have permission to use system api.                         |
494
495**Return value**
496
497| Type  | Description                          |
498| ------ | ------------------------------ |
499| string | Function list in string format.|
500
501**Example**
502
503```ts
504let funcs: number = usbManager.FunctionType.ACM | usbManager.FunctionType.ECM;
505let ret: string = usbManager.getStringFromFunctions(funcs);
506```
507
508## setDeviceFunctions<sup>12+</sup>
509
510setDeviceFunctions(funcs: FunctionType): Promise\<void\>
511
512Sets the current USB function list in Device mode.
513
514> **NOTE**
515>
516> This API is supported since API version 12.
517
518**System API**: This is a system API.
519
520**Required permissions**: ohos.permission.MANAGE_USB_CONFIG
521
522**System capability**: SystemCapability.USB.USBManager
523
524**Parameters**
525
526| Name| Type                         | Mandatory| Description             |
527| ------ | ----------------------------- | ---- | ----------------- |
528| funcs  | [FunctionType](#functiontype) | Yes  | USB function list in numeric mask format.|
529
530**Error codes**
531
532For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
533
534| ID| Error Message                                                                                               |
535| -------- | ------------------------------------------------------------------------------------------------------- |
536| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
537| 202      | Permission denied. Normal application do not have permission to use system api.                         |
538
539**Return value**
540
541| Type               | Description         |
542| ------------------- | ------------- |
543| Promise\<**void**\> | Promise used to return the result.|
544
545**Example**
546
547```ts
548import { BusinessError } from '@kit.BasicServicesKit';
549let funcs: number = usbManager.FunctionType.HDC;
550usbManager.setDeviceFunctions(funcs).then(() => {
551    console.info('usb setDeviceFunctions successfully.');
552}).catch((err : BusinessError) => {
553    console.error('usb setDeviceFunctions failed: ' + err.code + ' message: ' + err.message);
554});
555```
556
557## getDeviceFunctions<sup>12+</sup>
558
559getDeviceFunctions(): FunctionType
560
561Obtains the numeric mask combination for the USB function list in Device mode.
562
563> **NOTE**
564>
565> This API is supported since API version 12.
566
567**System API**: This is a system API.
568
569**Required permissions**: ohos.permission.MANAGE_USB_CONFIG
570
571**System capability**: SystemCapability.USB.USBManager
572
573**Error codes**
574
575For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
576
577| ID| Error Message                                                                       |
578| -------- | ------------------------------------------------------------------------------- |
579| 401      | Parameter error. No parameters are required.                                    |
580| 202      | Permission denied. Normal application do not have permission to use system api. |
581
582**Return value**
583
584| Type                         | Description                             |
585| ----------------------------- | --------------------------------- |
586| [FunctionType](#functiontype) | Numeric mask combination for the USB function list.|
587
588**Example**
589
590```ts
591let ret: number = usbManager.getDeviceFunctions();
592```
593
594## getPortList<sup>12+</sup>
595
596getPortList(): Array\<USBPort\>
597
598Obtains the list of all physical USB ports.
599
600> **NOTE**
601>
602> This API is supported since API version 12.
603
604**System API**: This is a system API.
605
606**Required permissions**: ohos.permission.MANAGE_USB_CONFIG
607
608**System capability**: SystemCapability.USB.USBManager
609
610**Error codes**
611
612For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
613
614| ID| Error Message                                                                                               |
615| -------- | ------------------------------------------------------------------------------------------------------- |
616| 202      | Permission denied. Normal application do not have permission to use system api.                         |
617
618**Return value**
619
620| Type                      | Description                 |
621| -------------------------- | --------------------- |
622| Array<[USBPort](#usbport)> | List of physical USB ports.|
623
624**Example**
625
626```ts
627let ret: Array<usbManager.USBPort> = usbManager.getPortList();
628```
629
630## getPortSupportModes<sup>12+</sup>
631
632getPortSupportModes(portId: number): PortModeType
633
634Obtains the mask combination for the supported mode list of a given USB port.
635
636**System API**: This is a system API.
637
638**Required permissions**: ohos.permission.MANAGE_USB_CONFIG
639
640**System capability**: SystemCapability.USB.USBManager
641
642**Parameters**
643
644| Name| Type  | Mandatory| Description    |
645| ------ | ------ | ---- | -------- |
646| portId | number | Yes  | Port number.|
647
648**Error codes**
649
650For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
651
652| ID| Error Message                                                                                               |
653| -------- | ------------------------------------------------------------------------------------------------------- |
654| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
655| 202      | Permission denied. Normal application do not have permission to use system api.                         |
656
657**Return value**
658
659| Type                         | Description                      |
660| ----------------------------- | -------------------------- |
661| [PortModeType](#portmodetype) | Mask combination for the supported mode list.|
662
663**Example**
664
665```ts
666let ret: number = usbManager.getSupportedModes(0);
667```
668
669## setPortRoleTypes<sup>12+</sup>
670
671setPortRoleTypes(portId: number, powerRole: PowerRoleType, dataRole: DataRoleType): Promise\<void\>
672
673Sets the role types supported by a specified port, which can be **powerRole** (for charging) and **dataRole** (for data transfer).
674
675> **NOTE**
676>
677> This API is supported since API version 12.
678
679**System API**: This is a system API.
680
681**Required permissions**: ohos.permission.MANAGE_USB_CONFIG
682
683**System capability**: SystemCapability.USB.USBManager
684
685**Parameters**
686
687| Name   | Type                           | Mandatory| Description            |
688| --------- | ------------------------------- | ---- | ---------------- |
689| portId    | number                          | Yes  | Port number.        |
690| powerRole | [PowerRoleType](#powerroletype) | Yes  | Role for charging.    |
691| dataRole  | [DataRoleType](#dataroletype)   | Yes  | Role for data transfer.|
692
693**Error codes**
694
695For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
696
697| ID| Error Message                                                                                               |
698| -------- | ------------------------------------------------------------------------------------------------------- |
699| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
700| 202      | Permission denied. Normal application do not have permission to use system api.                         |
701| 14400003 | Unsupported operation. The current device does not support port role switching.                         |
702
703**Return value**
704
705| Type               | Description         |
706| ------------------- | ------------- |
707| Promise\<**void**\> | Promise used to return the result.|
708
709**Example**
710
711```ts
712import { BusinessError } from '@kit.BasicServicesKit';
713let portId: number = 1;
714usbManager.setPortRoleTypes(portId, usbManager.PowerRoleType.SOURCE, usbManager.DataRoleType.HOST).then(() => {
715  console.info('usb setPortRoleTypes successfully.');
716}).catch((err : BusinessError) => {
717  console.error('usb setPortRoleTypes failed: ' + err.code + ' message: ' + err.message);
718});
719```
720
721## USBPort
722
723Represents a USB port.
724
725**System API**: This is a system API.
726
727**System capability**: SystemCapability.USB.USBManager
728
729| Name          | Type                           | Mandatory| Description                               |
730| -------------- | ------------------------------- | ---- | ----------------------------------- |
731| id             | number                          | Yes  | Unique identifier of a USB port.                  |
732| supportedModes | [PortModeType](#portmodetype)   | Yes  | Numeric mask combination for the supported mode list.|
733| status         | [USBPortStatus](#usbportstatus) | Yes  | USB port role.                      |
734
735## USBPortStatus
736
737Enumerates USB port roles.
738
739**System API**: This is a system API.
740
741**System capability**: SystemCapability.USB.USBManager
742
743| Name            | Type  | Mandatory| Description                  |
744| ---------------- | ------ | ---- | ---------------------- |
745| currentMode      | number | Yes  | Current USB mode.       |
746| currentPowerRole | number | Yes  | Current power role.    |
747| currentDataRole  | number | Yes  | Current data role.|
748
749## FunctionType
750
751Enumerates USB device function types.
752
753**System API**: This is a system API.
754
755**System capability**: SystemCapability.USB.USBManager
756
757| Name        | Value | Description      |
758| ------------ | --- | ---------- |
759| NONE         | 0   | No function.|
760| ACM          | 1   | ACM function. |
761| ECM          | 2   | ECM function. |
762| HDC          | 4   | HDC function. |
763| MTP          | 8   | Media transmission.|
764| PTP          | 16  | Image transmission.|
765| RNDIS        | 32  | Network sharing.|
766| MIDI         | 64  | MIDI function.|
767| AUDIO_SOURCE | 128 | Audio function.|
768| NCM          | 256 | NCM transmission. |
769
770## PortModeType
771
772Enumerates USB port mode types.
773
774**System API**: This is a system API.
775
776**System capability**: SystemCapability.USB.USBManager
777
778| Name     | Value| Description                                                |
779| --------- | -- | ---------------------------------------------------- |
780| NONE      | 0  | None                                                |
781| UFP       | 1  | Upstream facing port, which functions as the sink of power supply.                            |
782| DFP       | 2  | Downstream facing port, which functions as the source of power supply.                            |
783| DRP       | 3  | Dynamic reconfiguration port (DRP), which can function as the DFP (host) or UFP (device). It is not supported currently.|
784| NUM_MODES | 4  | Not supported currently.                                        |
785
786## PowerRoleType
787
788Enumerates power role types.
789
790**System API**: This is a system API.
791
792**System capability**: SystemCapability.USB.USBManager
793
794| Name  | Value| Description      |
795| ------ | -- | ---------- |
796| NONE   | 0  | None      |
797| SOURCE | 1  | Power supply for external devices.|
798| SINK   | 2  | External power supply.|
799
800## DataRoleType
801
802Enumerates data role types.
803
804**System API**: This is a system API.
805
806**System capability**: SystemCapability.USB.USBManager
807
808| Name  | Value| Description        |
809| ------ | -- | ------------ |
810| NONE   | 0  | None        |
811| HOST   | 1  | USB host.|
812| DEVICE | 2  | USB device.|
813