• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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. Need call requestRight to get permission.
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. No parameters are required.
244   * @throws { BusinessError } 202 - Permission denied. Normal application do not have permission to use system api.
245   * @syscap SystemCapability.USB.USBManager
246   * @systemapi
247   * @since 12
248   */
249  function getFunctionsFromString(funcs: string): number;
250
251  /**
252   * Converts the numeric mask combination of a given USB function list to a string descriptor.
253   *
254   * @permission ohos.permission.MANAGE_USB_CONFIG
255   * @param { FunctionType } funcs - numeric mask combination of the function list. It cannot be empty.
256   * @returns { string } - descriptor of the supported function list.
257   * @throws { BusinessError } 401 - Parameter error. Possible causes:
258   * <br>1.Mandatory parameters are left unspecified.
259   * <br>2.Incorrect parameter types.
260   * @throws { BusinessError } 202 - Permission denied. Normal application do not have permission to use system api.
261   * @syscap SystemCapability.USB.USBManager
262   * @systemapi
263   * @since 12
264   */
265  function getStringFromFunctions(funcs: FunctionType): string;
266
267  /**
268   * Sets the current USB function list in Device mode.
269   *
270   * @permission ohos.permission.MANAGE_USB_CONFIG
271   * @param { FunctionType } funcs - numeric mask combination of the supported function list. It cannot be empty.
272   * @returns { Promise<void> } the promise returned by the function.
273   * @throws { BusinessError } 401 - Parameter error. Possible causes:
274   * <br>1.Mandatory parameters are left unspecified.
275   * <br>2.Incorrect parameter types.
276   * @throws { BusinessError } 202 - Permission denied. Normal application do not have permission to use system api.
277   * @syscap SystemCapability.USB.USBManager
278   * @systemapi
279   * @since 12
280   */
281  function setDeviceFunctions(funcs: FunctionType): Promise<void>;
282
283  /**
284   * Obtains the numeric mask combination for the current USB function list in Device mode.
285   *
286   * @permission ohos.permission.MANAGE_USB_CONFIG
287   * @returns { FunctionType } the numeric mask combination for the current USB function list in FunctionType.
288   * @throws { BusinessError } 202 - Permission denied. Normal application do not have permission to use system api.
289   * @syscap SystemCapability.USB.USBManager
290   * @systemapi
291   * @since 12
292   */
293  function getDeviceFunctions(): FunctionType;
294
295  /* usb port functions begin */
296  /**
297   * Obtains the USBPort list.
298   *
299   * @permission ohos.permission.MANAGE_USB_CONFIG
300   * @returns { Array<USBPort> } the USBPort list.
301   * @throws { BusinessError } 202 - Permission denied. Normal application do not have permission to use system api.
302   * @syscap SystemCapability.USB.USBManager
303   * @systemapi
304   * @since 12
305   */
306  function getPortList(): Array<USBPort>;
307
308  /**
309   * Gets the mask combination for the supported mode list of the specified USBPort.
310   *
311   * @permission ohos.permission.MANAGE_USB_CONFIG
312   * @param { number } portId - unique ID of the port. It cannot be empty.
313   * @returns { PortModeType } the mask combination for the supported mode list in PortModeType.
314   * @throws { BusinessError } 401 - Parameter error. Possible causes:
315   * <br>1.Mandatory parameters are left unspecified.
316   * <br>2.Incorrect parameter types.
317   * @throws { BusinessError } 202 - Permission denied. Normal application do not have permission to use system api.
318   * @syscap SystemCapability.USB.USBManager
319   * @systemapi
320   * @since 12
321   */
322  function getPortSupportModes(portId: number): PortModeType;
323
324  /**
325   * Sets the role types supported by the specified USBPort, which can be powerRole (for charging) and dataRole (for data transfer).
326   *
327   * @permission ohos.permission.MANAGE_USB_CONFIG
328   * @param { number } portId - unique ID of the port. It cannot be empty.
329   * @param { PowerRoleType } powerRole - charging role. It cannot be empty.
330   * @param { DataRoleType } dataRole - data role. It cannot be empty.
331   * @returns { Promise<void> } the promise returned by the function.
332   * @throws { BusinessError } 401 - Parameter error. Possible causes:
333   * <br>1.Mandatory parameters are left unspecified.
334   * <br>2.Incorrect parameter types.
335   * @throws { BusinessError } 202 - Permission denied. Normal application do not have permission to use system api.
336   * @syscap SystemCapability.USB.USBManager
337   * @systemapi
338   * @since 12
339   */
340  function setPortRoleTypes(portId: number, powerRole: PowerRoleType, dataRole: DataRoleType): Promise<void>;
341
342  /* usb pipe functions begin */
343  /**
344   * Claims a USB interface.
345   *
346   * @param { USBDevicePipe } pipe - device pipe, which is used to determine the bus number and device address. It cannot be empty.
347   * @param { USBInterface } iface - USB interface, which is used to determine the interface to claim. It cannot be empty.
348   * @param { boolean } [force] - optional parameter that determines whether to forcibly claim the USB interface.
349   * @returns { number } returns **0** if the USB interface is successfully claimed; returns an error code otherwise.
350   * @throws { BusinessError } 401 - Parameter error. Possible causes:
351   * <br>1.Mandatory parameters are left unspecified.
352   * <br>2.Incorrect parameter types.
353   * @syscap SystemCapability.USB.USBManager
354   * @since 9
355   */
356  function claimInterface(pipe: USBDevicePipe, iface: USBInterface, force?: boolean): number;
357
358  /**
359   * Releases a USB interface.
360   *
361   * @param { USBDevicePipe } pipe - device pipe, which is used to determine the bus number and device address. It cannot be empty.
362   * @param { USBInterface } iface - USB interface, which is used to determine the interface to release. It cannot be empty.
363   * @returns { number } returns **0** if the USB interface is successfully released; returns an error code otherwise.
364   * @syscap SystemCapability.USB.USBManager
365   * @since 9
366   */
367  function releaseInterface(pipe: USBDevicePipe, iface: USBInterface): number;
368
369  /**
370   * Sets the device configuration.
371   *
372   * @param { USBDevicePipe } pipe - device pipe, which is used to determine the bus number and device address. It cannot be empty.
373   * @param { USBConfiguration } config - device configuration. It cannot be empty.
374   * @returns { number } returns **0** if the device configuration is successfully set; returns an error code otherwise.
375   * @throws { BusinessError } 401 - Parameter error. Possible causes:
376   * <br>1.Mandatory parameters are left unspecified.
377   * <br>2.Incorrect parameter types.
378   * @syscap SystemCapability.USB.USBManager
379   * @since 9
380   */
381  function setConfiguration(pipe: USBDevicePipe, config: USBConfiguration): number;
382
383  /**
384   * Sets a USB interface.
385   *
386   * @param { USBDevicePipe } pipe - device pipe, which is used to determine the bus number and device address. It cannot be empty.
387   * @param { USBInterface } iface - USB interface, which is used to determine the interface to set. It cannot be empty.
388   * @returns { number } returns **0** if the USB interface is successfully set; return an error code otherwise.
389   * @throws { BusinessError } 401 - Parameter error. Possible causes:
390   * <br>1.Mandatory parameters are left unspecified.
391   * <br>2.Incorrect parameter types.
392   * @syscap SystemCapability.USB.USBManager
393   * @since 9
394   */
395  function setInterface(pipe: USBDevicePipe, iface: USBInterface): number;
396
397  /**
398   * Obtains the raw USB descriptor.
399   *
400   * @param { USBDevicePipe } pipe - device pipe, which is used to determine the bus number and device address. It cannot be empty.
401   * @returns { Uint8Array } returns the raw descriptor data.
402   * @throws { BusinessError } 401 - Parameter error. Possible causes:
403   * <br>1.Mandatory parameters are left unspecified.
404   * <br>2.Incorrect parameter types.
405   * @syscap SystemCapability.USB.USBManager
406   * @since 9
407   */
408  function getRawDescriptor(pipe: USBDevicePipe): Uint8Array;
409
410  /**
411   * Obtains the file descriptor.
412   *
413   * @param { USBDevicePipe } pipe - device pipe, which is used to determine the USB device. It cannot be empty.
414   * @returns { number } returns the file descriptor of the USB device.
415   * @throws { BusinessError } 401 - Parameter error. Possible causes:
416   * <br>1.Mandatory parameters are left unspecified.
417   * <br>2.Incorrect parameter types.
418   * @syscap SystemCapability.USB.USBManager
419   * @since 9
420   */
421  function getFileDescriptor(pipe: USBDevicePipe): number;
422
423  /**
424   * Performs control transfer.
425   *
426   * @param { USBDevicePipe } pipe - device pipe, which is used to determine the USB device. It cannot be empty.
427   * @param { USBControlParams } controlparam - control transfer parameters. It cannot be empty.
428   * @param { number } [timeout] - timeout duration. This parameter is optional. The default value is **0**, indicating no timeout.
429   * @returns { Promise<number> } returns the size of the transmitted or received data block if the control transfer is successful;
430   * return -1 if an exception occurs.
431   * @throws { BusinessError } 401 - Parameter error. Possible causes:
432   * <br>1.Mandatory parameters are left unspecified.
433   * <br>2.Incorrect parameter types.
434   * @syscap SystemCapability.USB.USBManager
435   * @since 9
436   */
437  function controlTransfer(pipe: USBDevicePipe, controlparam: USBControlParams, timeout?: number): Promise<number>;
438
439  /**
440   * Performs bulk transfer.
441   *
442   * @param { USBDevicePipe } pipe - device pipe, which is used to determine the USB device. It cannot be empty.
443   * @param { USBEndpoint } endpoint - USB endpoint, which is used to determine the USB port for data transfer. It cannot be empty.
444   * @param { Uint8Array } buffer - buffer for writing or reading data. It cannot be empty.
445   * @param { number } [timeout] - timeout duration. This parameter is optional. The default value is **0**, indicating no timeout.
446   * @returns { Promise<number> } the size of the transmitted or received data block if the control transfer is successful;
447   * return -1 if an exception occurs.
448   * @throws { BusinessError } 401 - Parameter error. Possible causes:
449   * <br>1.Mandatory parameters are left unspecified.
450   * <br>2.Incorrect parameter types.
451   * @syscap SystemCapability.USB.USBManager
452   * @since 9
453   */
454  function bulkTransfer(
455    pipe: USBDevicePipe,
456    endpoint: USBEndpoint,
457    buffer: Uint8Array,
458    timeout?: number
459  ): Promise<number>;
460
461  /**
462   * Closes a USB device pipe.
463   *
464   * @param { USBDevicePipe } pipe - device pipe, which is used to determine the USB device. It cannot be empty.
465   * @returns { number } returns **0** if the USB device pipe is closed successfully; return an error code otherwise.
466   * @throws { BusinessError } 401 - Parameter error. Possible causes:
467   * <br>1.Mandatory parameters are left unspecified.
468   * <br>2.Incorrect parameter types.
469   * @syscap SystemCapability.USB.USBManager
470   * @since 9
471   */
472  function closePipe(pipe: USBDevicePipe): number;
473
474  /**
475   * Represents the USB endpoint from which data is sent or received. You can obtain the USB endpoint through USBInterface.
476   *
477   * @typedef USBEndpoint
478   * @syscap SystemCapability.USB.USBManager
479   * @since 9
480   */
481  interface USBEndpoint {
482    /**
483     * Endpoint address
484     *
485     * @syscap SystemCapability.USB.USBManager
486     * @since 9
487     */
488    address: number;
489
490    /**
491     * Endpoint attributes
492     *
493     * @syscap SystemCapability.USB.USBManager
494     * @since 9
495     */
496    attributes: number;
497
498    /**
499     * Endpoint interval
500     *
501     * @syscap SystemCapability.USB.USBManager
502     * @since 9
503     */
504    interval: number;
505
506    /**
507     * Maximum size of data packets on the endpoint
508     *
509     * @syscap SystemCapability.USB.USBManager
510     * @since 9
511     */
512    maxPacketSize: number;
513
514    /**
515     * Endpoint direction
516     *
517     * @syscap SystemCapability.USB.USBManager
518     * @since 9
519     */
520    direction: USBRequestDirection;
521
522    /**
523     * Endpoint number
524     *
525     * @syscap SystemCapability.USB.USBManager
526     * @since 9
527     */
528    number: number;
529
530    /**
531     * Endpoint type
532     *
533     * @syscap SystemCapability.USB.USBManager
534     * @since 9
535     */
536    type: number;
537
538    /**
539     * Unique ID defined by USBInterface.id, which indicates the interface to which the endpoint belongs
540     *
541     * @syscap SystemCapability.USB.USBManager
542     * @since 9
543     */
544    interfaceId: number;
545  }
546
547  /**
548   * Represents a USB interface. One config can contain multiple **USBInterface** instances, each providing a specific function.
549   *
550   * @typedef USBInterface
551   * @syscap SystemCapability.USB.USBManager
552   * @since 9
553   */
554  interface USBInterface {
555    /**
556     * Unique ID of the USB interface
557     *
558     * @syscap SystemCapability.USB.USBManager
559     * @since 9
560     */
561    id: number;
562
563    /**
564     * Interface protocol
565     *
566     * @syscap SystemCapability.USB.USBManager
567     * @since 9
568     */
569    protocol: number;
570
571    /**
572     * Device type
573     *
574     * @syscap SystemCapability.USB.USBManager
575     * @since 9
576     */
577    clazz: number;
578
579    /**
580     * Device subclass
581     *
582     * @syscap SystemCapability.USB.USBManager
583     * @since 9
584     */
585    subClass: number;
586
587    /**
588     * Alternation between descriptors of the same USB interface
589     *
590     * @syscap SystemCapability.USB.USBManager
591     * @since 9
592     */
593    alternateSetting: number;
594
595    /**
596     * Interface name
597     *
598     * @syscap SystemCapability.USB.USBManager
599     * @since 9
600     */
601    name: string;
602
603    /**
604     * USBEndpoint that belongs to the USB interface
605     *
606     * @syscap SystemCapability.USB.USBManager
607     * @since 9
608     */
609    endpoints: Array<USBEndpoint>;
610  }
611
612  /**
613   * USB configuration. One USBDevice can contain multiple USBConfiguration instances.
614   *
615   * @typedef USBConfiguration
616   * @syscap SystemCapability.USB.USBManager
617   * @since 9
618   */
619  interface USBConfiguration {
620    /**
621     * Unique ID of the USB configuration
622     *
623     * @syscap SystemCapability.USB.USBManager
624     * @since 9
625     */
626    id: number;
627
628    /**
629     * Configuration attributes
630     *
631     * @syscap SystemCapability.USB.USBManager
632     * @since 9
633     */
634    attributes: number;
635
636    /**
637     * Maximum power consumption, in mA
638     *
639     * @syscap SystemCapability.USB.USBManager
640     * @since 9
641     */
642    maxPower: number;
643
644    /**
645     * Configuration name, which can be left empty
646     *
647     * @syscap SystemCapability.USB.USBManager
648     * @since 9
649     */
650    name: string;
651
652    /**
653     * Support for remote wakeup
654     *
655     * @syscap SystemCapability.USB.USBManager
656     * @since 9
657     */
658    isRemoteWakeup: boolean;
659
660    /**
661     * Support for independent power supplies
662     *
663     * @syscap SystemCapability.USB.USBManager
664     * @since 9
665     */
666    isSelfPowered: boolean;
667
668    /**
669     * Supported interface attributes
670     *
671     * @syscap SystemCapability.USB.USBManager
672     * @since 9
673     */
674    interfaces: Array<USBInterface>;
675  }
676
677  /**
678   * Represents a USB device.
679   *
680   * @typedef USBDevice
681   * @syscap SystemCapability.USB.USBManager
682   * @since 9
683   */
684  interface USBDevice {
685    /**
686     * Bus address
687     *
688     * @syscap SystemCapability.USB.USBManager
689     * @since 9
690     */
691    busNum: number;
692
693    /**
694     * Device address
695     *
696     * @syscap SystemCapability.USB.USBManager
697     * @since 9
698     */
699    devAddress: number;
700
701    /**
702     * Device SN
703     *
704     * @syscap SystemCapability.USB.USBManager
705     * @since 9
706     */
707    serial: string;
708
709    /**
710     * Device name
711     *
712     * @syscap SystemCapability.USB.USBManager
713     * @since 9
714     */
715    name: string;
716
717    /**
718     * Device manufacturer
719     *
720     * @syscap SystemCapability.USB.USBManager
721     * @since 9
722     */
723    manufacturerName: string;
724
725    /**
726     * Product information
727     *
728     * @syscap SystemCapability.USB.USBManager
729     * @since 9
730     */
731    productName: string;
732
733    /**
734     * Product version
735     *
736     * @syscap SystemCapability.USB.USBManager
737     * @since 9
738     */
739    version: string;
740
741    /**
742     * Vendor ID
743     *
744     * @syscap SystemCapability.USB.USBManager
745     * @since 9
746     */
747    vendorId: number;
748
749    /**
750     * Product ID
751     *
752     * @syscap SystemCapability.USB.USBManager
753     * @since 9
754     */
755    productId: number;
756
757    /**
758     * Device class
759     *
760     * @syscap SystemCapability.USB.USBManager
761     * @since 9
762     */
763    clazz: number;
764
765    /**
766     * Device subclass
767     *
768     * @syscap SystemCapability.USB.USBManager
769     * @since 9
770     */
771    subClass: number;
772
773    /**
774     * Device protocol code
775     *
776     * @syscap SystemCapability.USB.USBManager
777     * @since 9
778     */
779    protocol: number;
780
781    /**
782     * Device configuration descriptor information
783     *
784     * @syscap SystemCapability.USB.USBManager
785     * @since 9
786     */
787    configs: Array<USBConfiguration>;
788  }
789
790  /**
791   * Represents a USB device pipe, which is used to determine the USB device.
792   *
793   * @typedef USBDevicePipe
794   * @syscap SystemCapability.USB.USBManager
795   * @since 9
796   */
797  interface USBDevicePipe {
798    /**
799     * Bus address.
800     *
801     * @syscap SystemCapability.USB.USBManager
802     * @since 9
803     */
804    busNum: number;
805
806    /**
807     * Device address
808     *
809     * @syscap SystemCapability.USB.USBManager
810     * @since 9
811     */
812    devAddress: number;
813  }
814
815  /**
816   * Enumerates power role types.
817   *
818   * @enum { number }
819   * @syscap SystemCapability.USB.USBManager
820   * @systemapi
821   * @since 9
822   */
823  export enum PowerRoleType {
824    /**
825     * None
826     *
827     * @syscap SystemCapability.USB.USBManager
828     * @systemapi
829     * @since 9
830     */
831    NONE = 0,
832
833    /**
834     * External power supply
835     *
836     * @syscap SystemCapability.USB.USBManager
837     * @systemapi
838     * @since 9
839     */
840    SOURCE = 1,
841
842    /**
843     * Internal power supply
844     *
845     * @syscap SystemCapability.USB.USBManager
846     * @systemapi
847     * @since 9
848     */
849    SINK = 2
850  }
851
852  /**
853   * Enumerates data role types.
854   *
855   * @enum { number }
856   * @syscap SystemCapability.USB.USBManager
857   * @systemapi
858   * @since 9
859   */
860  export enum DataRoleType {
861    /**
862     * None
863     *
864     * @syscap SystemCapability.USB.USBManager
865     * @systemapi
866     * @since 9
867     */
868    NONE = 0,
869
870    /**
871     * Host mode
872     *
873     * @syscap SystemCapability.USB.USBManager
874     * @systemapi
875     * @since 9
876     */
877    HOST = 1,
878
879    /**
880     * Device mode
881     *
882     * @syscap SystemCapability.USB.USBManager
883     * @systemapi
884     * @since 9
885     */
886    DEVICE = 2
887  }
888
889  /**
890   * Enumerates port mode types
891   *
892   * @enum { number }
893   * @syscap SystemCapability.USB.USBManager
894   * @systemapi
895   * @since 9
896   */
897  export enum PortModeType {
898    /**
899     * None
900     *
901     * @syscap SystemCapability.USB.USBManager
902     * @systemapi
903     * @since 9
904     */
905    NONE = 0,
906
907    /**
908     * Upstream facing port, which functions as the sink of power supply
909     *
910     * @syscap SystemCapability.USB.USBManager
911     * @systemapi
912     * @since 9
913     */
914    UFP = 1,
915
916    /**
917     * Downstream facing port, which functions as the source of power supply
918     *
919     * @syscap SystemCapability.USB.USBManager
920     * @systemapi
921     * @since 9
922     */
923    DFP = 2,
924
925    /**
926     * Dynamic reconfiguration port (DRP), which can function as the DFP (host) or UFP (device). It is not supported currently.
927     *
928     * @syscap SystemCapability.USB.USBManager
929     * @systemapi
930     * @since 9
931     */
932    DRP = 3,
933
934    /**
935     * Not supported currently
936     *
937     * @syscap SystemCapability.USB.USBManager
938     * @systemapi
939     * @since 9
940     */
941    NUM_MODES = 4
942  }
943
944  /**
945   * Enumerates USB device port roles.
946   *
947   * @typedef USBPortStatus
948   * @syscap SystemCapability.USB.USBManager
949   * @systemapi
950   * @since 9
951   */
952  interface USBPortStatus {
953    /**
954     * USB mode
955     *
956     * @syscap SystemCapability.USB.USBManager
957     * @systemapi
958     * @since 9
959     */
960    currentMode: number;
961
962    /**
963     * Power role
964     *
965     * @syscap SystemCapability.USB.USBManager
966     * @systemapi
967     * @since 9
968     */
969    currentPowerRole: number;
970
971    /**
972     * Data role
973     *
974     * @syscap SystemCapability.USB.USBManager
975     * @systemapi
976     * @since 9
977     */
978    currentDataRole: number;
979  }
980
981  /**
982   * Represents a USB device port.
983   *
984   * @typedef USBPort
985   * @syscap SystemCapability.USB.USBManager
986   * @systemapi
987   * @since 9
988   */
989  interface USBPort {
990    /**
991     * Unique ID of the USB port
992     *
993     * @syscap SystemCapability.USB.USBManager
994     * @systemapi
995     * @since 9
996     */
997    id: number;
998
999    /**
1000     * Mask combination for the supported mode list of the USB port
1001     *
1002     * @syscap SystemCapability.USB.USBManager
1003     * @systemapi
1004     * @since 9
1005     */
1006    supportedModes: PortModeType;
1007
1008    /**
1009     * USB port role
1010     *
1011     * @syscap SystemCapability.USB.USBManager
1012     * @systemapi
1013     * @since 9
1014     */
1015    status: USBPortStatus;
1016  }
1017
1018  /**
1019   * Represents control transfer parameters.
1020   *
1021   * @typedef USBControlParams
1022   * @syscap SystemCapability.USB.USBManager
1023   * @since 9
1024   */
1025  interface USBControlParams {
1026    /**
1027     * Request type
1028     *
1029     * @syscap SystemCapability.USB.USBManager
1030     * @since 9
1031     */
1032    request: number;
1033
1034    /**
1035     * Request target type
1036     *
1037     * @syscap SystemCapability.USB.USBManager
1038     * @since 9
1039     */
1040    target: USBRequestTargetType;
1041
1042    /**
1043     * Control request type
1044     *
1045     * @syscap SystemCapability.USB.USBManager
1046     * @since 9
1047     */
1048    reqType: USBControlRequestType;
1049
1050    /**
1051     * Request parameter value
1052     *
1053     * @syscap SystemCapability.USB.USBManager
1054     * @since 9
1055     */
1056    value: number;
1057
1058    /**
1059     * Index of the parameter value
1060     *
1061     * @syscap SystemCapability.USB.USBManager
1062     * @since 9
1063     */
1064    index: number;
1065
1066    /**
1067     * Data written to or read from the buffer
1068     *
1069     * @syscap SystemCapability.USB.USBManager
1070     * @since 9
1071     */
1072    data: Uint8Array;
1073  }
1074
1075  /**
1076   * Enumerates USB request target types.
1077   *
1078   * @enum { number }
1079   * @syscap SystemCapability.USB.USBManager
1080   * @since 9
1081   */
1082  export enum USBRequestTargetType {
1083    /**
1084     * USB device
1085     *
1086     * @syscap SystemCapability.USB.USBManager
1087     * @since 9
1088     */
1089    USB_REQUEST_TARGET_DEVICE = 0,
1090
1091    /**
1092     * USB interface
1093     *
1094     * @syscap SystemCapability.USB.USBManager
1095     * @since 9
1096     */
1097    USB_REQUEST_TARGET_INTERFACE = 1,
1098
1099    /**
1100     * Endpoint
1101     *
1102     * @syscap SystemCapability.USB.USBManager
1103     * @since 9
1104     */
1105    USB_REQUEST_TARGET_ENDPOINT = 2,
1106
1107    /**
1108     * Others
1109     *
1110     * @syscap SystemCapability.USB.USBManager
1111     * @since 9
1112     */
1113    USB_REQUEST_TARGET_OTHER = 3
1114  }
1115
1116  /**
1117   * Enumerates control request types.
1118   *
1119   * @enum { number }
1120   * @syscap SystemCapability.USB.USBManager
1121   * @since 9
1122   */
1123  export enum USBControlRequestType {
1124    /**
1125     * Standard
1126     *
1127     * @syscap SystemCapability.USB.USBManager
1128     * @since 9
1129     */
1130    USB_REQUEST_TYPE_STANDARD = 0,
1131
1132    /**
1133     * Class
1134     *
1135     * @syscap SystemCapability.USB.USBManager
1136     * @since 9
1137     */
1138    USB_REQUEST_TYPE_CLASS = 1,
1139
1140    /**
1141     * Vendor
1142     *
1143     * @syscap SystemCapability.USB.USBManager
1144     * @since 9
1145     */
1146    USB_REQUEST_TYPE_VENDOR = 2
1147  }
1148
1149  /**
1150   * Enumerates request directions.
1151   *
1152   * @enum { number }
1153   * @syscap SystemCapability.USB.USBManager
1154   * @since 9
1155   */
1156  export enum USBRequestDirection {
1157    /**
1158     * Request for writing data from the host to the device
1159     *
1160     * @syscap SystemCapability.USB.USBManager
1161     * @since 9
1162     */
1163    USB_REQUEST_DIR_TO_DEVICE = 0,
1164
1165    /**
1166     * Request for reading data from the device to the host
1167     *
1168     * @syscap SystemCapability.USB.USBManager
1169     * @since 9
1170     */
1171    USB_REQUEST_DIR_FROM_DEVICE = 0x80
1172  }
1173
1174  /**
1175   * Enumerates function modes.
1176   *
1177   * @enum { number }
1178   * @syscap SystemCapability.USB.USBManager
1179   * @systemapi
1180   * @since 9
1181   */
1182  export enum FunctionType {
1183    /**
1184     * None
1185     *
1186     * @syscap SystemCapability.USB.USBManager
1187     * @systemapi
1188     * @since 9
1189     */
1190    NONE = 0,
1191
1192    /**
1193     * Serial port device
1194     *
1195     * @syscap SystemCapability.USB.USBManager
1196     * @systemapi
1197     * @since 9
1198     */
1199    ACM = 1,
1200
1201    /**
1202     * Ethernet port device
1203     *
1204     * @syscap SystemCapability.USB.USBManager
1205     * @systemapi
1206     * @since 9
1207     */
1208    ECM = 2,
1209
1210    /**
1211     * HDC device
1212     *
1213     * @syscap SystemCapability.USB.USBManager
1214     * @systemapi
1215     * @since 9
1216     */
1217    HDC = 4,
1218
1219    /**
1220     * MTP device
1221     *
1222     * @syscap SystemCapability.USB.USBManager
1223     * @systemapi
1224     * @since 9
1225     */
1226    MTP = 8,
1227
1228    /**
1229     * PTP device
1230     *
1231     * @syscap SystemCapability.USB.USBManager
1232     * @systemapi
1233     * @since 9
1234     */
1235    PTP = 16,
1236
1237    /**
1238     * RNDIS device
1239     *
1240     * @syscap SystemCapability.USB.USBManager
1241     * @systemapi
1242     * @since 9
1243     */
1244    RNDIS = 32,
1245
1246    /**
1247     * MIDI device
1248     *
1249     * @syscap SystemCapability.USB.USBManager
1250     * @systemapi
1251     * @since 9
1252     */
1253    MIDI = 64,
1254
1255    /**
1256     * Audio source device
1257     *
1258     * @syscap SystemCapability.USB.USBManager
1259     * @systemapi
1260     * @since 9
1261     */
1262    AUDIO_SOURCE = 128,
1263
1264    /**
1265     * NCM device
1266     *
1267     * @syscap SystemCapability.USB.USBManager
1268     * @systemapi
1269     * @since 9
1270     */
1271    NCM = 256
1272  }
1273}
1274
1275export default usbManager;
1276