1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * @file 18 * @kit BasicServicesKit 19 */ 20 21/** 22 * This module provides the capability of manage USB device. 23 * 24 * @namespace usbManager 25 * @syscap SystemCapability.USB.USBManager 26 * @since 9 27 */ 28declare namespace usbManager { 29 /** 30 * Obtains the USB device list. 31 * 32 * @returns { Array<Readonly<USBDevice>> } USB device list. 33 * @syscap SystemCapability.USB.USBManager 34 * @since 9 35 */ 36 function getDevices(): Array<Readonly<USBDevice>>; 37 38 /** 39 * Connects to the USB device based on the device information returned by getDevices(). 40 * 41 * @param { USBDevice } device - USB device on the device list returned by getDevices(). It cannot be empty. 42 * @returns { Readonly<USBDevicePipe> } object for data transfer. 43 * @throws { BusinessError } 401 - Parameter error. Possible causes: 44 * <br>1.Mandatory parameters are left unspecified. 45 * <br>2.Incorrect parameter types. 46 * @throws { BusinessError } 14400001 - Permission denied. Call requestRight to get the permission first. 47 * @syscap SystemCapability.USB.USBManager 48 * @since 9 49 */ 50 function connectDevice(device: USBDevice): Readonly<USBDevicePipe>; 51 52 /** 53 * Checks whether the application has the permission to access the device. 54 * 55 * @param { string } deviceName - device name defined by USBDevice.name. It cannot be empty. 56 * @returns { boolean } indicates if the user has the permission to access the device. 57 * @throws { BusinessError } 401 - Parameter error. Possible causes: 58 * <br>1.Mandatory parameters are left unspecified. 59 * <br>2.Incorrect parameter types. 60 * @syscap SystemCapability.USB.USBManager 61 * @since 9 62 */ 63 function hasRight(deviceName: string): boolean; 64 65 /** 66 * Requests the permission for a given application to access the USB device. 67 * The system application has access to the device by default, and there is no need to call this interface to apply. 68 * 69 * @param { string } deviceName - device name defined by USBDevice.name. It cannot be empty. 70 * @returns { Promise<boolean> } indicates if the device access permissions are granted. 71 * @throws { BusinessError } 401 - Parameter error. Possible causes: 72 * <br>1.Mandatory parameters are left unspecified. 73 * <br>2.Incorrect parameter types. 74 * @syscap SystemCapability.USB.USBManager 75 * @since 9 76 */ 77 function requestRight(deviceName: string): Promise<boolean>; 78 79 /** 80 * Remove the permission for a given application to access the USB device. 81 * The system application has access to the device by default, and calling this interface will not have any impact. 82 * 83 * @param { string } deviceName - device name defined by USBDevice.name. It cannot be empty. 84 * @returns { boolean } indicates if the device access permissions are removed. 85 * @throws { BusinessError } 401 - Parameter error. Possible causes: 86 * <br>1.Mandatory parameters are left unspecified. 87 * <br>2.Incorrect parameter types. 88 * @syscap SystemCapability.USB.USBManager 89 * @since 9 90 */ 91 function removeRight(deviceName: string): boolean; 92 93 /** 94 * Add device access permission. 95 * The system application has access to the device by default, and calling this interface will not have any impact. 96 * 97 * @param { string } bundleName - refers to application that require access permissions. It cannot be empty. 98 * @param { string } deviceName - device name defined by USBDevice.name. It cannot be empty. 99 * @returns { boolean } value to indicate whether the permission is granted. 100 * @throws { BusinessError } 401 - Parameter error. Possible causes: 101 * <br>1.Mandatory parameters are left unspecified. 102 * <br>2.Incorrect parameter types. 103 * @syscap SystemCapability.USB.USBManager 104 * @systemapi 105 * @since 9 106 * @deprecated since 12 107 * @useinstead ohos.usbManager/usbManager#addDeviceAccessRight 108 */ 109 function addRight(bundleName: string, deviceName: string): boolean; 110 111 /** 112 * Converts the string descriptor of a given USB function list to a numeric mask combination. 113 * 114 * @param { string } funcs - descriptor of the supported function list. It cannot be empty. 115 * @returns { number } the numeric mask combination of the function list. 116 * @throws { BusinessError } 401 - Parameter error. Possible causes: 117 * <br>1.Mandatory parameters are left unspecified. 118 * <br>2.Incorrect parameter types. 119 * @syscap SystemCapability.USB.USBManager 120 * @systemapi 121 * @since 9 122 * @deprecated since 12 123 * @useinstead ohos.usbManager/usbManager#getFunctionsFromString 124 */ 125 function usbFunctionsFromString(funcs: string): number; 126 127 /** 128 * Converts the numeric mask combination of a given USB function list to a string descriptor. 129 * 130 * @param { FunctionType } funcs - numeric mask combination of the function list. The type of funcs must be number. It cannot be empty. 131 * @returns { string } - descriptor of the supported function list. 132 * @throws { BusinessError } 401 - Parameter error. Possible causes: 133 * <br>1.Mandatory parameters are left unspecified. 134 * <br>2.Incorrect parameter types. 135 * @syscap SystemCapability.USB.USBManager 136 * @systemapi 137 * @since 9 138 * @deprecated since 12 139 * @useinstead ohos.usbManager/usbManager#getStringFromFunctions 140 */ 141 function usbFunctionsToString(funcs: FunctionType): string; 142 143 /** 144 * Sets the current USB function list in Device mode. 145 * 146 * @param { FunctionType } funcs - numeric mask combination of the supported function list. It cannot be empty. 147 * @returns { Promise<void> } the promise returned by the function. 148 * @throws { BusinessError } 401 - Parameter error. Possible causes: 149 * <br>1.Mandatory parameters are left unspecified. 150 * <br>2.Incorrect parameter types. 151 * @throws { BusinessError } 14400002 - Permission denied. The HDC is disabled by the system. 152 * @syscap SystemCapability.USB.USBManager 153 * @systemapi 154 * @since 9 155 * @deprecated since 12 156 * @useinstead ohos.usbManager/usbManager#setDeviceFunctions 157 */ 158 function setCurrentFunctions(funcs: FunctionType): Promise<void>; 159 160 /** 161 * Obtains the numeric mask combination for the current USB function list in Device mode. 162 * 163 * @returns { FunctionType } the numeric mask combination for the current USB function list in FunctionType. 164 * @syscap SystemCapability.USB.USBManager 165 * @systemapi 166 * @since 9 167 * @deprecated since 12 168 * @useinstead ohos.usbManager/usbManager#getDeviceFunctions 169 */ 170 function getCurrentFunctions(): FunctionType; 171 172 /* usb port functions begin */ 173 /** 174 * Obtains the USBPort list. 175 * 176 * @returns { Array<USBPort> } the USBPort list. 177 * @syscap SystemCapability.USB.USBManager 178 * @systemapi 179 * @since 9 180 * @deprecated since 12 181 * @useinstead ohos.usbManager/usbManager#getPortList 182 */ 183 function getPorts(): Array<USBPort>; 184 185 /** 186 * Gets the mask combination for the supported mode list of the specified USBPort. 187 * 188 * @param { number } portId - unique ID of the port. It cannot be empty. 189 * @returns { PortModeType } the mask combination for the supported mode list in PortModeType. 190 * @throws { BusinessError } 401 - Parameter error. Possible causes: 191 * <br>1.Mandatory parameters are left unspecified. 192 * <br>2.Incorrect parameter types. 193 * @syscap SystemCapability.USB.USBManager 194 * @systemapi 195 * @since 9 196 * @deprecated since 12 197 * @useinstead ohos.usbManager/usbManager#getPortSupportModes 198 */ 199 function getSupportedModes(portId: number): PortModeType; 200 201 /** 202 * Sets the role types supported by the specified USBPort, which can be powerRole (for charging) and dataRole (for data transfer). 203 * 204 * @param { number } portId - unique ID of the port. It cannot be empty. 205 * @param { PowerRoleType } powerRole - charging role. It cannot be empty. 206 * @param { DataRoleType } dataRole - data role. It cannot be empty. 207 * @returns { Promise<void> } the promise returned by the function. 208 * @throws { BusinessError } 401 - Parameter error. Possible causes: 209 * <br>1.Mandatory parameters are left unspecified. 210 * <br>2.Incorrect parameter types. 211 * @syscap SystemCapability.USB.USBManager 212 * @systemapi 213 * @since 9 214 * @deprecated since 12 215 * @useinstead ohos.usbManager/usbManager#setPortRoleTypes 216 */ 217 function setPortRoles(portId: number, powerRole: PowerRoleType, dataRole: DataRoleType): Promise<void>; 218 219 /** 220 * Add USB device access right. 221 * The system application has access to the device by default, and calling this interface will not have any impact. 222 * 223 * @permission ohos.permission.MANAGE_USB_CONFIG 224 * @param { string } tokenId - refers to application that require access permissions. It cannot be empty. 225 * @param { string } deviceName - device name defined by USBDevice.name. It cannot be empty. 226 * @returns { boolean } value to indicate whether the permission is granted. 227 * @throws { BusinessError } 401 - Parameter error. Possible causes: 228 * <br>1.Mandatory parameters are left unspecified. 229 * <br>2.Incorrect parameter types. 230 * @throws { BusinessError } 202 - Permission denied. Normal application do not have permission to use system api. 231 * @syscap SystemCapability.USB.USBManager 232 * @systemapi 233 * @since 12 234 */ 235 function addDeviceAccessRight(tokenId: string, deviceName: string): boolean; 236 237 /** 238 * Converts the string descriptor of a given USB function list to a numeric mask combination. 239 * 240 * @permission ohos.permission.MANAGE_USB_CONFIG 241 * @param { string } funcs - descriptor of the supported function list. It cannot be empty. 242 * @returns { number } the numeric mask combination of the function list. 243 * @throws { BusinessError } 401 - Parameter error. Possible causes: 244 * <br>1.Mandatory parameters are left unspecified. 245 * <br>2.Incorrect parameter types. 246 * @throws { BusinessError } 202 - Permission denied. Normal application do not have permission to use system api. 247 * @syscap SystemCapability.USB.USBManager 248 * @systemapi 249 * @since 12 250 */ 251 function getFunctionsFromString(funcs: string): number; 252 253 /** 254 * Converts the numeric mask combination of a given USB function list to a string descriptor. 255 * 256 * @permission ohos.permission.MANAGE_USB_CONFIG 257 * @param { FunctionType } funcs - numeric mask combination of the function list. It cannot be empty. 258 * @returns { string } - descriptor of the supported function list. 259 * @throws { BusinessError } 401 - Parameter error. Possible causes: 260 * <br>1.Mandatory parameters are left unspecified. 261 * <br>2.Incorrect parameter types. 262 * @throws { BusinessError } 202 - Permission denied. Normal application do not have permission to use system api. 263 * @syscap SystemCapability.USB.USBManager 264 * @systemapi 265 * @since 12 266 */ 267 function getStringFromFunctions(funcs: FunctionType): string; 268 269 /** 270 * Sets the current USB function list in Device mode. 271 * 272 * @permission ohos.permission.MANAGE_USB_CONFIG 273 * @param { FunctionType } funcs - numeric mask combination of the supported function list. It cannot be empty. 274 * @returns { Promise<void> } the promise returned by the function. 275 * @throws { BusinessError } 401 - Parameter error. Possible causes: 276 * <br>1.Mandatory parameters are left unspecified. 277 * <br>2.Incorrect parameter types. 278 * @throws { BusinessError } 202 - Permission denied. Normal application do not have permission to use system api. 279 * @syscap SystemCapability.USB.USBManager 280 * @systemapi 281 * @since 12 282 */ 283 function setDeviceFunctions(funcs: FunctionType): Promise<void>; 284 285 /** 286 * Obtains the numeric mask combination for the current USB function list in Device mode. 287 * 288 * @permission ohos.permission.MANAGE_USB_CONFIG 289 * @returns { FunctionType } the numeric mask combination for the current USB function list in FunctionType. 290 * @throws { BusinessError } 202 - Permission denied. Normal application do not have permission to use system api. 291 * @syscap SystemCapability.USB.USBManager 292 * @systemapi 293 * @since 12 294 */ 295 function getDeviceFunctions(): FunctionType; 296 297 /* usb port functions begin */ 298 /** 299 * Obtains the USBPort list. 300 * 301 * @permission ohos.permission.MANAGE_USB_CONFIG 302 * @returns { Array<USBPort> } the USBPort list. 303 * @throws { BusinessError } 202 - Permission denied. Normal application do not have permission to use system api. 304 * @syscap SystemCapability.USB.USBManager 305 * @systemapi 306 * @since 12 307 */ 308 function getPortList(): Array<USBPort>; 309 310 /** 311 * Gets the mask combination for the supported mode list of the specified USBPort. 312 * 313 * @permission ohos.permission.MANAGE_USB_CONFIG 314 * @param { number } portId - unique ID of the port. It cannot be empty. 315 * @returns { PortModeType } the mask combination for the supported mode list in PortModeType. 316 * @throws { BusinessError } 401 - Parameter error. Possible causes: 317 * <br>1.Mandatory parameters are left unspecified. 318 * <br>2.Incorrect parameter types. 319 * @throws { BusinessError } 202 - Permission denied. Normal application do not have permission to use system api. 320 * @syscap SystemCapability.USB.USBManager 321 * @systemapi 322 * @since 12 323 */ 324 function getPortSupportModes(portId: number): PortModeType; 325 326 /** 327 * Sets the role types supported by the specified USBPort, which can be powerRole (for charging) and dataRole (for data transfer). 328 * 329 * @permission ohos.permission.MANAGE_USB_CONFIG 330 * @param { number } portId - unique ID of the port. It cannot be empty. 331 * @param { PowerRoleType } powerRole - charging role. It cannot be empty. 332 * @param { DataRoleType } dataRole - data role. It cannot be empty. 333 * @returns { Promise<void> } the promise returned by the function. 334 * @throws { BusinessError } 401 - Parameter error. Possible causes: 335 * <br>1.Mandatory parameters are left unspecified. 336 * <br>2.Incorrect parameter types. 337 * @throws { BusinessError } 202 - Permission denied. Normal application do not have permission to use system api. 338 * @throws { BusinessError } 14400003 - Unsupported operation. The current device does not support port role switching. 339 * @syscap SystemCapability.USB.USBManager 340 * @systemapi 341 * @since 12 342 */ 343 function setPortRoleTypes(portId: number, powerRole: PowerRoleType, dataRole: DataRoleType): Promise<void>; 344 345 /* usb pipe functions begin */ 346 /** 347 * Claims a USB interface. 348 * 349 * @param { USBDevicePipe } pipe - device pipe, which is used to determine the bus number and device address. It cannot be empty. 350 * @param { USBInterface } iface - USB interface, which is used to determine the interface to claim. It cannot be empty. 351 * @param { boolean } [force] - optional parameter that determines whether to forcibly claim the USB interface. 352 * @returns { number } returns **0** if the USB interface is successfully claimed; returns an error code otherwise. 353 * @throws { BusinessError } 401 - Parameter error. Possible causes: 354 * <br>1.Mandatory parameters are left unspecified. 355 * <br>2.Incorrect parameter types. 356 * @syscap SystemCapability.USB.USBManager 357 * @since 9 358 */ 359 function claimInterface(pipe: USBDevicePipe, iface: USBInterface, force?: boolean): number; 360 361 /** 362 * Releases a USB interface. 363 * 364 * @param { USBDevicePipe } pipe - device pipe, which is used to determine the bus number and device address. It cannot be empty. 365 * @param { USBInterface } iface - USB interface, which is used to determine the interface to release. It cannot be empty. 366 * @returns { number } returns **0** if the USB interface is successfully released; returns an error code otherwise. 367 * @throws { BusinessError } 401 - Parameter error. Possible causes: 368 * <br>1.Mandatory parameters are left unspecified. 369 * <br>2.Incorrect parameter types. 370 * @syscap SystemCapability.USB.USBManager 371 * @since 9 372 */ 373 function releaseInterface(pipe: USBDevicePipe, iface: USBInterface): number; 374 375 /** 376 * Sets the device configuration. 377 * 378 * @param { USBDevicePipe } pipe - device pipe, which is used to determine the bus number and device address. It cannot be empty. 379 * @param { USBConfiguration } config - device configuration. It cannot be empty. 380 * @returns { number } returns **0** if the device configuration is successfully set; returns an error code otherwise. 381 * @throws { BusinessError } 401 - Parameter error. Possible causes: 382 * <br>1.Mandatory parameters are left unspecified. 383 * <br>2.Incorrect parameter types. 384 * @syscap SystemCapability.USB.USBManager 385 * @since 9 386 */ 387 function setConfiguration(pipe: USBDevicePipe, config: USBConfiguration): number; 388 389 /** 390 * Sets a USB interface. 391 * 392 * @param { USBDevicePipe } pipe - device pipe, which is used to determine the bus number and device address. It cannot be empty. 393 * @param { USBInterface } iface - USB interface, which is used to determine the interface to set. It cannot be empty. 394 * @returns { number } returns **0** if the USB interface is successfully set; return an error code otherwise. 395 * @throws { BusinessError } 401 - Parameter error. Possible causes: 396 * <br>1.Mandatory parameters are left unspecified. 397 * <br>2.Incorrect parameter types. 398 * @syscap SystemCapability.USB.USBManager 399 * @since 9 400 */ 401 function setInterface(pipe: USBDevicePipe, iface: USBInterface): number; 402 403 /** 404 * Obtains the raw USB descriptor. 405 * 406 * @param { USBDevicePipe } pipe - device pipe, which is used to determine the bus number and device address. It cannot be empty. 407 * @returns { Uint8Array } returns the raw descriptor data. 408 * @throws { BusinessError } 401 - Parameter error. Possible causes: 409 * <br>1.Mandatory parameters are left unspecified. 410 * <br>2.Incorrect parameter types. 411 * @syscap SystemCapability.USB.USBManager 412 * @since 9 413 */ 414 function getRawDescriptor(pipe: USBDevicePipe): Uint8Array; 415 416 /** 417 * Obtains the file descriptor. 418 * 419 * @param { USBDevicePipe } pipe - device pipe, which is used to determine the USB device. It cannot be empty. 420 * @returns { number } returns the file descriptor of the USB device. 421 * @throws { BusinessError } 401 - Parameter error. Possible causes: 422 * <br>1.Mandatory parameters are left unspecified. 423 * <br>2.Incorrect parameter types. 424 * @syscap SystemCapability.USB.USBManager 425 * @since 9 426 */ 427 function getFileDescriptor(pipe: USBDevicePipe): number; 428 429 /** 430 * Performs control transfer. 431 * 432 * @param { USBDevicePipe } pipe - device pipe, which is used to determine the USB device. It cannot be empty. 433 * @param { USBControlParams } controlparam - control transfer parameters. It cannot be empty. 434 * @param { number } [timeout] - timeout duration. This parameter is optional. The default value is **0**, indicating no timeout. 435 * @returns { Promise<number> } returns the size of the transmitted or received data block if the control transfer is successful; 436 * return -1 if an exception occurs. 437 * @throws { BusinessError } 401 - Parameter error. Possible causes: 438 * <br>1.Mandatory parameters are left unspecified. 439 * <br>2.Incorrect parameter types. 440 * @syscap SystemCapability.USB.USBManager 441 * @since 9 442 * @deprecated since 12 443 * @useinstead ohos.usbManager/usbManager#usbControlTransfer 444 */ 445 function controlTransfer(pipe: USBDevicePipe, controlparam: USBControlParams, timeout?: number): Promise<number>; 446 447 /** 448 * Performs usb control transfer. 449 * 450 * @param { USBDevicePipe } pipe - device pipe, which is used to determine the USB device. It cannot be empty. 451 * @param { USBDeviceRequestParams } requestparam - control transfer parameters. It cannot be empty. 452 * @param { number } [timeout] - timeout duration. This parameter is optional. The default value is **0**, indicating no timeout. 453 * @returns { Promise<number> } returns the size of the transmitted or received data block if the control transfer is successful; 454 * return -1 if an exception occurs. 455 * @throws { BusinessError } 401 - Parameter error. Possible causes: 456 * <br>1.Mandatory parameters are left unspecified. 457 * <br>2.Incorrect parameter types. 458 * @syscap SystemCapability.USB.USBManager 459 * @since 12 460 */ 461 function usbControlTransfer(pipe: USBDevicePipe, requestparam: USBDeviceRequestParams, timeout?: number): Promise<number>; 462 463 /** 464 * Performs bulk transfer. 465 * 466 * @param { USBDevicePipe } pipe - device pipe, which is used to determine the USB device. It cannot be empty. 467 * @param { USBEndpoint } endpoint - USB endpoint, which is used to determine the USB port for data transfer. It cannot be empty. 468 * @param { Uint8Array } buffer - buffer for writing or reading data. It cannot be empty. 469 * @param { number } [timeout] - timeout duration. This parameter is optional. The default value is **0**, indicating no timeout. 470 * @returns { Promise<number> } the size of the transmitted or received data block if the control transfer is successful; 471 * return -1 if an exception occurs. 472 * @throws { BusinessError } 401 - Parameter error. Possible causes: 473 * <br>1.Mandatory parameters are left unspecified. 474 * <br>2.Incorrect parameter types. 475 * @syscap SystemCapability.USB.USBManager 476 * @since 9 477 */ 478 function bulkTransfer( 479 pipe: USBDevicePipe, 480 endpoint: USBEndpoint, 481 buffer: Uint8Array, 482 timeout?: number 483 ): Promise<number>; 484 485 /** 486 * Closes a USB device pipe. 487 * 488 * @param { USBDevicePipe } pipe - device pipe, which is used to determine the USB device. It cannot be empty. 489 * @returns { number } returns **0** if the USB device pipe is closed successfully; return an error code otherwise. 490 * @throws { BusinessError } 401 - Parameter error. Possible causes: 491 * <br>1.Mandatory parameters are left unspecified. 492 * <br>2.Incorrect parameter types. 493 * @syscap SystemCapability.USB.USBManager 494 * @since 9 495 */ 496 function closePipe(pipe: USBDevicePipe): number; 497 498 /** 499 * Represents the USB endpoint from which data is sent or received. You can obtain the USB endpoint through USBInterface. 500 * 501 * @typedef USBEndpoint 502 * @syscap SystemCapability.USB.USBManager 503 * @since 9 504 */ 505 interface USBEndpoint { 506 /** 507 * Endpoint address 508 * 509 * @type { number } 510 * @syscap SystemCapability.USB.USBManager 511 * @since 9 512 */ 513 address: number; 514 515 /** 516 * Endpoint attributes 517 * 518 * @type { number } 519 * @syscap SystemCapability.USB.USBManager 520 * @since 9 521 */ 522 attributes: number; 523 524 /** 525 * Endpoint interval 526 * 527 * @type { number } 528 * @syscap SystemCapability.USB.USBManager 529 * @since 9 530 */ 531 interval: number; 532 533 /** 534 * Maximum size of data packets on the endpoint 535 * 536 * @type { number } 537 * @syscap SystemCapability.USB.USBManager 538 * @since 9 539 */ 540 maxPacketSize: number; 541 542 /** 543 * Endpoint direction 544 * 545 * @type { USBRequestDirection } 546 * @syscap SystemCapability.USB.USBManager 547 * @since 9 548 */ 549 direction: USBRequestDirection; 550 551 /** 552 * Endpoint number 553 * 554 * @type { number } 555 * @syscap SystemCapability.USB.USBManager 556 * @since 9 557 */ 558 number: number; 559 560 /** 561 * Endpoint type 562 * 563 * @type { number } 564 * @syscap SystemCapability.USB.USBManager 565 * @since 9 566 */ 567 type: number; 568 569 /** 570 * Unique ID defined by USBInterface.id, which indicates the interface to which the endpoint belongs 571 * 572 * @type { number } 573 * @syscap SystemCapability.USB.USBManager 574 * @since 9 575 */ 576 interfaceId: number; 577 } 578 579 /** 580 * Represents a USB interface. One config can contain multiple **USBInterface** instances, each providing a specific function. 581 * 582 * @typedef USBInterface 583 * @syscap SystemCapability.USB.USBManager 584 * @since 9 585 */ 586 interface USBInterface { 587 /** 588 * Unique ID of the USB interface 589 * 590 * @type { number } 591 * @syscap SystemCapability.USB.USBManager 592 * @since 9 593 */ 594 id: number; 595 596 /** 597 * Interface protocol 598 * 599 * @type { number } 600 * @syscap SystemCapability.USB.USBManager 601 * @since 9 602 */ 603 protocol: number; 604 605 /** 606 * Device type 607 * 608 * @type { number } 609 * @syscap SystemCapability.USB.USBManager 610 * @since 9 611 */ 612 clazz: number; 613 614 /** 615 * Device subclass 616 * 617 * @type { number } 618 * @syscap SystemCapability.USB.USBManager 619 * @since 9 620 */ 621 subClass: number; 622 623 /** 624 * Alternation between descriptors of the same USB interface 625 * 626 * @type { number } 627 * @syscap SystemCapability.USB.USBManager 628 * @since 9 629 */ 630 alternateSetting: number; 631 632 /** 633 * Interface name 634 * 635 * @type { string } 636 * @syscap SystemCapability.USB.USBManager 637 * @since 9 638 */ 639 name: string; 640 641 /** 642 * USBEndpoint that belongs to the USB interface 643 * 644 * @type { Array<USBEndpoint> } 645 * @syscap SystemCapability.USB.USBManager 646 * @since 9 647 */ 648 endpoints: Array<USBEndpoint>; 649 } 650 651 /** 652 * USB configuration. One USBDevice can contain multiple USBConfiguration instances. 653 * 654 * @typedef USBConfiguration 655 * @syscap SystemCapability.USB.USBManager 656 * @since 9 657 */ 658 interface USBConfiguration { 659 /** 660 * Unique ID of the USB configuration 661 * 662 * @type { number } 663 * @syscap SystemCapability.USB.USBManager 664 * @since 9 665 */ 666 id: number; 667 668 /** 669 * Configuration attributes 670 * 671 * @type { number } 672 * @syscap SystemCapability.USB.USBManager 673 * @since 9 674 */ 675 attributes: number; 676 677 /** 678 * Maximum power consumption, in mA 679 * 680 * @type { number } 681 * @syscap SystemCapability.USB.USBManager 682 * @since 9 683 */ 684 maxPower: number; 685 686 /** 687 * Configuration name, which can be left empty 688 * 689 * @type { string } 690 * @syscap SystemCapability.USB.USBManager 691 * @since 9 692 */ 693 name: string; 694 695 /** 696 * Support for remote wakeup 697 * 698 * @type { boolean } 699 * @syscap SystemCapability.USB.USBManager 700 * @since 9 701 */ 702 isRemoteWakeup: boolean; 703 704 /** 705 * Support for independent power supplies 706 * 707 * @type { boolean } 708 * @syscap SystemCapability.USB.USBManager 709 * @since 9 710 */ 711 isSelfPowered: boolean; 712 713 /** 714 * Supported interface attributes 715 * 716 * @type { Array<USBInterface> } 717 * @syscap SystemCapability.USB.USBManager 718 * @since 9 719 */ 720 interfaces: Array<USBInterface>; 721 } 722 723 /** 724 * Represents a USB device. 725 * 726 * @typedef USBDevice 727 * @syscap SystemCapability.USB.USBManager 728 * @since 9 729 */ 730 interface USBDevice { 731 /** 732 * Bus address 733 * 734 * @type { number } 735 * @syscap SystemCapability.USB.USBManager 736 * @since 9 737 */ 738 busNum: number; 739 740 /** 741 * Device address 742 * 743 * @type { number } 744 * @syscap SystemCapability.USB.USBManager 745 * @since 9 746 */ 747 devAddress: number; 748 749 /** 750 * Device SN 751 * 752 * @type { string } 753 * @syscap SystemCapability.USB.USBManager 754 * @since 9 755 */ 756 serial: string; 757 758 /** 759 * Device name 760 * 761 * @type { string } 762 * @syscap SystemCapability.USB.USBManager 763 * @since 9 764 */ 765 name: string; 766 767 /** 768 * Device manufacturer 769 * 770 * @type { string } 771 * @syscap SystemCapability.USB.USBManager 772 * @since 9 773 */ 774 manufacturerName: string; 775 776 /** 777 * Product information 778 * 779 * @type { string } 780 * @syscap SystemCapability.USB.USBManager 781 * @since 9 782 */ 783 productName: string; 784 785 /** 786 * Product version 787 * 788 * @type { string } 789 * @syscap SystemCapability.USB.USBManager 790 * @since 9 791 */ 792 version: string; 793 794 /** 795 * Vendor ID 796 * 797 * @type { number } 798 * @syscap SystemCapability.USB.USBManager 799 * @since 9 800 */ 801 vendorId: number; 802 803 /** 804 * Product ID 805 * 806 * @type { number } 807 * @syscap SystemCapability.USB.USBManager 808 * @since 9 809 */ 810 productId: number; 811 812 /** 813 * Device class 814 * 815 * @type { number } 816 * @syscap SystemCapability.USB.USBManager 817 * @since 9 818 */ 819 clazz: number; 820 821 /** 822 * Device subclass 823 * 824 * @type { number } 825 * @syscap SystemCapability.USB.USBManager 826 * @since 9 827 */ 828 subClass: number; 829 830 /** 831 * Device protocol code 832 * 833 * @type { number } 834 * @syscap SystemCapability.USB.USBManager 835 * @since 9 836 */ 837 protocol: number; 838 839 /** 840 * Device configuration descriptor information 841 * 842 * @type { Array<USBConfiguration> } 843 * @syscap SystemCapability.USB.USBManager 844 * @since 9 845 */ 846 configs: Array<USBConfiguration>; 847 } 848 849 /** 850 * Represents a USB device pipe, which is used to determine the USB device. 851 * 852 * @typedef USBDevicePipe 853 * @syscap SystemCapability.USB.USBManager 854 * @since 9 855 */ 856 interface USBDevicePipe { 857 /** 858 * Bus address. 859 * 860 * @type { number } 861 * @syscap SystemCapability.USB.USBManager 862 * @since 9 863 */ 864 busNum: number; 865 866 /** 867 * Device address 868 * 869 * @type { number } 870 * @syscap SystemCapability.USB.USBManager 871 * @since 9 872 */ 873 devAddress: number; 874 } 875 876 /** 877 * Enumerates power role types. 878 * 879 * @enum { number } 880 * @syscap SystemCapability.USB.USBManager 881 * @systemapi 882 * @since 9 883 */ 884 export enum PowerRoleType { 885 /** 886 * None 887 * 888 * @syscap SystemCapability.USB.USBManager 889 * @systemapi 890 * @since 9 891 */ 892 NONE = 0, 893 894 /** 895 * External power supply 896 * 897 * @syscap SystemCapability.USB.USBManager 898 * @systemapi 899 * @since 9 900 */ 901 SOURCE = 1, 902 903 /** 904 * Internal power supply 905 * 906 * @syscap SystemCapability.USB.USBManager 907 * @systemapi 908 * @since 9 909 */ 910 SINK = 2 911 } 912 913 /** 914 * Enumerates data role types. 915 * 916 * @enum { number } 917 * @syscap SystemCapability.USB.USBManager 918 * @systemapi 919 * @since 9 920 */ 921 export enum DataRoleType { 922 /** 923 * None 924 * 925 * @syscap SystemCapability.USB.USBManager 926 * @systemapi 927 * @since 9 928 */ 929 NONE = 0, 930 931 /** 932 * Host mode 933 * 934 * @syscap SystemCapability.USB.USBManager 935 * @systemapi 936 * @since 9 937 */ 938 HOST = 1, 939 940 /** 941 * Device mode 942 * 943 * @syscap SystemCapability.USB.USBManager 944 * @systemapi 945 * @since 9 946 */ 947 DEVICE = 2 948 } 949 950 /** 951 * Enumerates port mode types 952 * 953 * @enum { number } 954 * @syscap SystemCapability.USB.USBManager 955 * @systemapi 956 * @since 9 957 */ 958 export enum PortModeType { 959 /** 960 * None 961 * 962 * @syscap SystemCapability.USB.USBManager 963 * @systemapi 964 * @since 9 965 */ 966 NONE = 0, 967 968 /** 969 * Upstream facing port, which functions as the sink of power supply 970 * 971 * @syscap SystemCapability.USB.USBManager 972 * @systemapi 973 * @since 9 974 */ 975 UFP = 1, 976 977 /** 978 * Downstream facing port, which functions as the source of power supply 979 * 980 * @syscap SystemCapability.USB.USBManager 981 * @systemapi 982 * @since 9 983 */ 984 DFP = 2, 985 986 /** 987 * Dynamic reconfiguration port (DRP), which can function as the DFP (host) or UFP (device). It is not supported currently. 988 * 989 * @syscap SystemCapability.USB.USBManager 990 * @systemapi 991 * @since 9 992 */ 993 DRP = 3, 994 995 /** 996 * Not supported currently 997 * 998 * @syscap SystemCapability.USB.USBManager 999 * @systemapi 1000 * @since 9 1001 */ 1002 NUM_MODES = 4 1003 } 1004 1005 /** 1006 * Enumerates USB device port roles. 1007 * 1008 * @typedef USBPortStatus 1009 * @syscap SystemCapability.USB.USBManager 1010 * @systemapi 1011 * @since 9 1012 */ 1013 interface USBPortStatus { 1014 /** 1015 * USB mode 1016 * 1017 * @type { number } 1018 * @syscap SystemCapability.USB.USBManager 1019 * @systemapi 1020 * @since 9 1021 */ 1022 currentMode: number; 1023 1024 /** 1025 * Power role 1026 * 1027 * @type { number } 1028 * @syscap SystemCapability.USB.USBManager 1029 * @systemapi 1030 * @since 9 1031 */ 1032 currentPowerRole: number; 1033 1034 /** 1035 * Data role 1036 * 1037 * @type { number } 1038 * @syscap SystemCapability.USB.USBManager 1039 * @systemapi 1040 * @since 9 1041 */ 1042 currentDataRole: number; 1043 } 1044 1045 /** 1046 * Represents a USB device port. 1047 * 1048 * @typedef USBPort 1049 * @syscap SystemCapability.USB.USBManager 1050 * @systemapi 1051 * @since 9 1052 */ 1053 interface USBPort { 1054 /** 1055 * Unique ID of the USB port 1056 * 1057 * @type { number } 1058 * @syscap SystemCapability.USB.USBManager 1059 * @systemapi 1060 * @since 9 1061 */ 1062 id: number; 1063 1064 /** 1065 * Mask combination for the supported mode list of the USB port 1066 * 1067 * @type { PortModeType } 1068 * @syscap SystemCapability.USB.USBManager 1069 * @systemapi 1070 * @since 9 1071 */ 1072 supportedModes: PortModeType; 1073 1074 /** 1075 * USB port role 1076 * 1077 * @type { USBPortStatus } 1078 * @syscap SystemCapability.USB.USBManager 1079 * @systemapi 1080 * @since 9 1081 */ 1082 status: USBPortStatus; 1083 } 1084 1085 /** 1086 * Represents control transfer parameters. 1087 * 1088 * @typedef USBControlParams 1089 * @syscap SystemCapability.USB.USBManager 1090 * @since 9 1091 */ 1092 interface USBControlParams { 1093 /** 1094 * Request type 1095 * 1096 * @type { number } 1097 * @syscap SystemCapability.USB.USBManager 1098 * @since 9 1099 */ 1100 request: number; 1101 1102 /** 1103 * Request target type 1104 * 1105 * @type { USBRequestTargetType } 1106 * @syscap SystemCapability.USB.USBManager 1107 * @since 9 1108 */ 1109 target: USBRequestTargetType; 1110 1111 /** 1112 * Control request type 1113 * 1114 * @type { USBControlRequestType } 1115 * @syscap SystemCapability.USB.USBManager 1116 * @since 9 1117 */ 1118 reqType: USBControlRequestType; 1119 1120 /** 1121 * Request parameter value 1122 * 1123 * @type { number } 1124 * @syscap SystemCapability.USB.USBManager 1125 * @since 9 1126 */ 1127 value: number; 1128 1129 /** 1130 * Index of the parameter value 1131 * 1132 * @type { number } 1133 * @syscap SystemCapability.USB.USBManager 1134 * @since 9 1135 */ 1136 index: number; 1137 1138 /** 1139 * Data written to or read from the buffer 1140 * 1141 * @type { Uint8Array } 1142 * @syscap SystemCapability.USB.USBManager 1143 * @since 9 1144 */ 1145 data: Uint8Array; 1146 } 1147 1148 /** 1149 * Represents control transfer parameters. 1150 * 1151 * @typedef USBDeviceRequestParams 1152 * @syscap SystemCapability.USB.USBManager 1153 * @since 12 1154 */ 1155 interface USBDeviceRequestParams { 1156 /** 1157 * Bit map request type 1158 * 1159 * @type { number } 1160 * @syscap SystemCapability.USB.USBManager 1161 * @since 12 1162 */ 1163 bmRequestType: number; 1164 1165 /** 1166 * Byte request 1167 * 1168 * @type { number } 1169 * @syscap SystemCapability.USB.USBManager 1170 * @since 12 1171 */ 1172 bRequest: number; 1173 1174 /** 1175 * Request parameter word value 1176 * 1177 * @type { number } 1178 * @syscap SystemCapability.USB.USBManager 1179 * @since 12 1180 */ 1181 wValue: number; 1182 1183 /** 1184 * Word index of the parameter value 1185 * 1186 * @type { number } 1187 * @syscap SystemCapability.USB.USBManager 1188 * @since 12 1189 */ 1190 wIndex: number; 1191 1192 /** 1193 * Word length of the parameter value 1194 * 1195 * @type { number } 1196 * @syscap SystemCapability.USB.USBManager 1197 * @since 12 1198 */ 1199 wLength: number; 1200 1201 /** 1202 * Data written to or read from the buffer 1203 * 1204 * @type { Uint8Array } 1205 * @syscap SystemCapability.USB.USBManager 1206 * @since 12 1207 */ 1208 data: Uint8Array; 1209 } 1210 1211 /** 1212 * Enumerates USB request target types. 1213 * 1214 * @enum { number } 1215 * @syscap SystemCapability.USB.USBManager 1216 * @since 9 1217 */ 1218 export enum USBRequestTargetType { 1219 /** 1220 * USB device 1221 * 1222 * @syscap SystemCapability.USB.USBManager 1223 * @since 9 1224 */ 1225 USB_REQUEST_TARGET_DEVICE = 0, 1226 1227 /** 1228 * USB interface 1229 * 1230 * @syscap SystemCapability.USB.USBManager 1231 * @since 9 1232 */ 1233 USB_REQUEST_TARGET_INTERFACE = 1, 1234 1235 /** 1236 * Endpoint 1237 * 1238 * @syscap SystemCapability.USB.USBManager 1239 * @since 9 1240 */ 1241 USB_REQUEST_TARGET_ENDPOINT = 2, 1242 1243 /** 1244 * Others 1245 * 1246 * @syscap SystemCapability.USB.USBManager 1247 * @since 9 1248 */ 1249 USB_REQUEST_TARGET_OTHER = 3 1250 } 1251 1252 /** 1253 * Enumerates control request types. 1254 * 1255 * @enum { number } 1256 * @syscap SystemCapability.USB.USBManager 1257 * @since 9 1258 */ 1259 export enum USBControlRequestType { 1260 /** 1261 * Standard 1262 * 1263 * @syscap SystemCapability.USB.USBManager 1264 * @since 9 1265 */ 1266 USB_REQUEST_TYPE_STANDARD = 0, 1267 1268 /** 1269 * Class 1270 * 1271 * @syscap SystemCapability.USB.USBManager 1272 * @since 9 1273 */ 1274 USB_REQUEST_TYPE_CLASS = 1, 1275 1276 /** 1277 * Vendor 1278 * 1279 * @syscap SystemCapability.USB.USBManager 1280 * @since 9 1281 */ 1282 USB_REQUEST_TYPE_VENDOR = 2 1283 } 1284 1285 /** 1286 * Enumerates request directions. 1287 * 1288 * @enum { number } 1289 * @syscap SystemCapability.USB.USBManager 1290 * @since 9 1291 */ 1292 export enum USBRequestDirection { 1293 /** 1294 * Request for writing data from the host to the device 1295 * 1296 * @syscap SystemCapability.USB.USBManager 1297 * @since 9 1298 */ 1299 USB_REQUEST_DIR_TO_DEVICE = 0, 1300 1301 /** 1302 * Request for reading data from the device to the host 1303 * 1304 * @syscap SystemCapability.USB.USBManager 1305 * @since 9 1306 */ 1307 USB_REQUEST_DIR_FROM_DEVICE = 0x80 1308 } 1309 1310 /** 1311 * Enumerates function modes. 1312 * 1313 * @enum { number } 1314 * @syscap SystemCapability.USB.USBManager 1315 * @systemapi 1316 * @since 9 1317 */ 1318 export enum FunctionType { 1319 /** 1320 * None 1321 * 1322 * @syscap SystemCapability.USB.USBManager 1323 * @systemapi 1324 * @since 9 1325 */ 1326 NONE = 0, 1327 1328 /** 1329 * Serial port device 1330 * 1331 * @syscap SystemCapability.USB.USBManager 1332 * @systemapi 1333 * @since 9 1334 */ 1335 ACM = 1, 1336 1337 /** 1338 * Ethernet port device 1339 * 1340 * @syscap SystemCapability.USB.USBManager 1341 * @systemapi 1342 * @since 9 1343 */ 1344 ECM = 2, 1345 1346 /** 1347 * HDC device 1348 * 1349 * @syscap SystemCapability.USB.USBManager 1350 * @systemapi 1351 * @since 9 1352 */ 1353 HDC = 4, 1354 1355 /** 1356 * MTP device 1357 * 1358 * @syscap SystemCapability.USB.USBManager 1359 * @systemapi 1360 * @since 9 1361 */ 1362 MTP = 8, 1363 1364 /** 1365 * PTP device 1366 * 1367 * @syscap SystemCapability.USB.USBManager 1368 * @systemapi 1369 * @since 9 1370 */ 1371 PTP = 16, 1372 1373 /** 1374 * RNDIS device 1375 * 1376 * @syscap SystemCapability.USB.USBManager 1377 * @systemapi 1378 * @since 9 1379 */ 1380 RNDIS = 32, 1381 1382 /** 1383 * MIDI device 1384 * 1385 * @syscap SystemCapability.USB.USBManager 1386 * @systemapi 1387 * @since 9 1388 */ 1389 MIDI = 64, 1390 1391 /** 1392 * Audio source device 1393 * 1394 * @syscap SystemCapability.USB.USBManager 1395 * @systemapi 1396 * @since 9 1397 */ 1398 AUDIO_SOURCE = 128, 1399 1400 /** 1401 * NCM device 1402 * 1403 * @syscap SystemCapability.USB.USBManager 1404 * @systemapi 1405 * @since 9 1406 */ 1407 NCM = 256 1408 } 1409} 1410 1411export default usbManager; 1412