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