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 DriverDevelopmentKit 19 */ 20 21import type { AsyncCallback } from './@ohos.base'; 22import type rpc from './@ohos.rpc'; 23 24/** 25 * This module provides the capability of manage external device. 26 * 27 * @namespace deviceManager 28 * @syscap SystemCapability.Driver.ExternalDevice 29 * @since 10 30 */ 31declare namespace deviceManager { 32 /** 33 * Query the external device list. 34 * 35 * @permission ohos.permission.ACCESS_EXTENSIONAL_DEVICE_DRIVER 36 * @param { number } busType - The bus type of device to be queried. 37 * @returns { Array<Readonly<Device>> } External device list. 38 * @throws { BusinessError } 401 - The parameter check failed. 39 * @throws { BusinessError } 22900001 - ExternalDeviceManager service exception. 40 * @syscap SystemCapability.Driver.ExternalDevice 41 * @since 10 42 */ 43 function queryDevices(busType?: number): Array<Readonly<Device>>; 44 45 /** 46 * Bind the device based on the device information returned by queryDevices(). 47 * 48 * @permission ohos.permission.ACCESS_EXTENSIONAL_DEVICE_DRIVER 49 * @param { number } deviceId - Device id on the device list returned by queryDevices(). 50 * @param { AsyncCallback<number> } onDisconnect - Callback is invoked when device is disconnected after bind 51 * success. 52 * @param { AsyncCallback<{deviceId: number, remote: rpc.IRemoteObject}> } callback - Indicates the bind result 53 * including device ID and remote object. 54 * @throws { BusinessError } 401 - The parameter check failed. 55 * @throws { BusinessError } 22900001 - ExternalDeviceManager service exception. 56 * @syscap SystemCapability.Driver.ExternalDevice 57 * @since 10 58 */ 59 function bindDevice(deviceId: number, onDisconnect: AsyncCallback<number>, 60 callback: AsyncCallback<{deviceId: number, remote: rpc.IRemoteObject}>): void; 61 62 /** 63 * Bind the device based on the device information returned by queryDevices(). 64 * 65 * @permission ohos.permission.ACCESS_EXTENSIONAL_DEVICE_DRIVER 66 * @param { number } deviceId - Device id on the device list returned by queryDevices(). 67 * @param { AsyncCallback<number> } onDisconnect - Callback is invoked when device is disconnected after bind 68 * success. 69 * @param { AsyncCallback<RemoteDeviceDriver> } callback - Indicates the bind result including device ID and 70 * remote object. 71 * @throws { BusinessError } 401 - The parameter check failed. 72 * @throws { BusinessError } 22900001 - ExternalDeviceManager service exception. 73 * @syscap SystemCapability.Driver.ExternalDevice 74 * @since 11 75 */ 76 function bindDeviceDriver(deviceId: number, onDisconnect: AsyncCallback<number>, 77 callback: AsyncCallback<RemoteDeviceDriver>): void; 78 79 /** 80 * Bind the device based on the device information returned by queryDevices(). 81 * 82 * @permission ohos.permission.ACCESS_EXTENSIONAL_DEVICE_DRIVER 83 * @param { number } deviceId - Device id on the device list returned by queryDevices(). 84 * @param { AsyncCallback<number> } onDisconnect - Callback is invoked when device is disconnected after bind 85 * success. 86 * @returns { Promise<{deviceId: number, remote: rpc.IRemoteObject}> } Indicates the bind result including device 87 * ID and remote object. 88 * @throws { BusinessError } 401 - The parameter check failed. 89 * @throws { BusinessError } 22900001 - ExternalDeviceManager service exception. 90 * @syscap SystemCapability.Driver.ExternalDevice 91 * @since 10 92 */ 93 function bindDevice(deviceId: number, onDisconnect: AsyncCallback<number>): Promise<{deviceId: number, 94 remote: rpc.IRemoteObject}>; 95 96 /** 97 * Bind the device based on the device information returned by queryDevices(). 98 * 99 * @permission ohos.permission.ACCESS_EXTENSIONAL_DEVICE_DRIVER 100 * @param { number } deviceId - Device id on the device list returned by queryDevices(). 101 * @param { AsyncCallback<number> } onDisconnect - Callback is invoked when device is disconnected after bind 102 * success. 103 * @returns { Promise<RemoteDeviceDriver> } Indicates the bind result including device ID and remote object. 104 * @throws { BusinessError } 401 - The parameter check failed. 105 * @throws { BusinessError } 22900001 - ExternalDeviceManager service exception. 106 * @syscap SystemCapability.Driver.ExternalDevice 107 * @since 11 108 */ 109 function bindDeviceDriver(deviceId: number, onDisconnect: AsyncCallback<number>): Promise<RemoteDeviceDriver>; 110 111 /** 112 * Unbind the device based on the device information returned by queryDevices(). 113 * 114 * @permission ohos.permission.ACCESS_EXTENSIONAL_DEVICE_DRIVER 115 * @param { number } deviceId - Device id on the device list returned by queryDevices(). 116 * @param { AsyncCallback<number> } callback - Indicates the unbind result invoked when unbind is finished. 117 * @throws { BusinessError } 401 - The parameter check failed. 118 * @throws { BusinessError } 22900001 - ExternalDeviceManager service exception. 119 * @syscap SystemCapability.Driver.ExternalDevice 120 * @since 10 121 */ 122 function unbindDevice(deviceId: number, callback: AsyncCallback<number>): void; 123 124 /** 125 * Unbind the device based on the device information returned by queryDevices(). 126 * 127 * @permission ohos.permission.ACCESS_EXTENSIONAL_DEVICE_DRIVER 128 * @param { number } deviceId - Device id on the device list returned by queryDevices(). 129 * @returns { Promise<number> } - Indicates the unbind result invoked when unbind is finished. 130 * @throws { BusinessError } 401 - The parameter check failed. 131 * @throws { BusinessError } 22900001 - ExternalDeviceManager service exception. 132 * @syscap SystemCapability.Driver.ExternalDevice 133 * @since 10 134 */ 135 function unbindDevice(deviceId: number): Promise<number>; 136 137 /** 138 * Queries external device information. 139 * 140 * @permission ohos.permission.ACCESS_EXTENSIONAL_DEVICE_DRIVER 141 * @param { number } deviceId - ID of device to query. 142 * @returns { Array<Readonly<DeviceInfo>> } Device information obtained. 143 * @throws { BusinessError } 201 - The permission check failed. 144 * @throws { BusinessError } 401 - The parameter check failed. 145 * @throws { BusinessError } 26300001 - ExternalDeviceManager service exception. 146 * @syscap SystemCapability.Driver.ExternalDevice 147 * @systemapi 148 * @since 12 149 */ 150 function queryDeviceInfo(deviceId?: number): Array<Readonly<DeviceInfo>>; 151 152 /** 153 * Queries driver information. 154 * 155 * @permission ohos.permission.ACCESS_EXTENSIONAL_DEVICE_DRIVER 156 * @param { string } driverUid - Unique identifier of driver query. 157 * @returns { Array<Readonly<DriverInfo>> } Driver information obtained. 158 * @throws { BusinessError } 201 - The permission check failed. 159 * @throws { BusinessError } 401 - The parameter check failed. 160 * @throws { BusinessError } 26300001 - ExternalDeviceManager service exception. 161 * @syscap SystemCapability.Driver.ExternalDevice 162 * @systemapi 163 * @since 12 164 */ 165 function queryDriverInfo(driverUid?: string): Array<Readonly<DriverInfo>>; 166 167 /** 168 * Enumerates the bus types. 169 * 170 * @enum { number } 171 * @syscap SystemCapability.Driver.ExternalDevice 172 * @since 10 173 */ 174 export enum BusType { 175 /** 176 * USB device type 177 * 178 * @syscap SystemCapability.Driver.ExternalDevice 179 * @since 10 180 */ 181 USB = 1, 182 } 183 184 /** 185 * Represents a device. 186 * 187 * @typedef Device 188 * @syscap SystemCapability.Driver.ExternalDevice 189 * @since 10 190 */ 191 interface Device { 192 /** 193 * Bus type of the device. 194 * 195 * @syscap SystemCapability.Driver.ExternalDevice 196 * @since 10 197 */ 198 busType: BusType; 199 200 /** 201 * Device ID. 202 * 203 * @syscap SystemCapability.Driver.ExternalDevice 204 * @since 10 205 */ 206 deviceId: number; 207 208 /** 209 * Description of the device. 210 * 211 * @syscap SystemCapability.Driver.ExternalDevice 212 * @since 10 213 */ 214 description: string; 215 } 216 217 /** 218 * Represents a USB device. 219 * 220 * @typedef USBDevice 221 * @syscap SystemCapability.Driver.ExternalDevice 222 * @since 10 223 */ 224 interface USBDevice extends Device { 225 /** 226 * Vendor ID. 227 * 228 * @syscap SystemCapability.Driver.ExternalDevice 229 * @since 10 230 */ 231 vendorId: number; 232 233 /** 234 * Product ID. 235 * 236 * @syscap SystemCapability.Driver.ExternalDevice 237 * @since 10 238 */ 239 productId: number; 240 } 241 242 /** 243 * Driver of the remote device bound with <b>deviceId</b>. 244 * 245 * @typedef RemoteDeviceDriver 246 * @syscap SystemCapability.Driver.ExternalDevice 247 * @since 11 248 */ 249 interface RemoteDeviceDriver { 250 /** 251 * Device ID. 252 * 253 * @syscap SystemCapability.Driver.ExternalDevice 254 * @since 11 255 */ 256 deviceId: number; 257 258 /** 259 * Remote driver object. 260 * 261 * @syscap SystemCapability.Driver.ExternalDevice 262 * @since 11 263 */ 264 remote: rpc.IRemoteObject; 265 } 266 267 /** 268 * Represents information about a device interface descriptor. 269 * 270 * @typedef USBInterfaceDesc 271 * @syscap SystemCapability.Driver.ExternalDevice 272 * @systemapi 273 * @since 12 274 */ 275 interface USBInterfaceDesc { 276 /** 277 * Interface number. 278 * 279 * @syscap SystemCapability.Driver.ExternalDevice 280 * @systemapi 281 * @since 12 282 */ 283 bInterfaceNumber: number; 284 285 /** 286 * Interface class code. 287 * 288 * @syscap SystemCapability.Driver.ExternalDevice 289 * @systemapi 290 * @since 12 291 */ 292 bClass: number; 293 294 /** 295 * Interface subclass code. 296 * 297 * @syscap SystemCapability.Driver.ExternalDevice 298 * @systemapi 299 * @since 12 300 */ 301 bSubClass: number; 302 303 /** 304 * Interface protocol. 305 * 306 * @syscap SystemCapability.Driver.ExternalDevice 307 * @systemapi 308 * @since 12 309 */ 310 bProtocol: number; 311 } 312 313 314 /** 315 * Represents the device information. 316 * 317 * @typedef DeviceInfo 318 * @syscap SystemCapability.Driver.ExternalDevice 319 * @systemapi 320 * @since 12 321 */ 322 interface DeviceInfo { 323 /** 324 * Device ID. 325 * 326 * @syscap SystemCapability.Driver.ExternalDevice 327 * @systemapi 328 * @since 12 329 */ 330 deviceId: number; 331 332 /** 333 * Whether the device has a matched driver. 334 * 335 * @syscap SystemCapability.Driver.ExternalDevice 336 * @systemapi 337 * @since 12 338 */ 339 isDriverMatched: boolean; 340 341 /** 342 * Unique identifier of the driver. 343 * 344 * @syscap SystemCapability.Driver.ExternalDevice 345 * @systemapi 346 * @since 12 347 */ 348 driverUid?: string; 349 } 350 351 /** 352 * Represents the USB device information. 353 * 354 * @typedef USBDeviceInfo 355 * @syscap SystemCapability.Driver.ExternalDevice 356 * @systemapi 357 * @since 12 358 */ 359 interface USBDeviceInfo extends DeviceInfo { 360 /** 361 * Vendor ID. 362 * 363 * @syscap SystemCapability.Driver.ExternalDevice 364 * @systemapi 365 * @since 12 366 */ 367 vendorId: number; 368 369 /** 370 * Product ID. 371 * 372 * @syscap SystemCapability.Driver.ExternalDevice 373 * @systemapi 374 * @since 12 375 */ 376 productId: number; 377 378 /** 379 * List of USB interface descriptors. 380 * 381 * @syscap SystemCapability.Driver.ExternalDevice 382 * @systemapi 383 * @since 12 384 */ 385 interfaceDescList: Array<Readonly<USBInterfaceDesc>>; 386 } 387 388 /** 389 * Represents the driver information. 390 * 391 * @typedef DriverInfo 392 * @syscap SystemCapability.Driver.ExternalDevice 393 * @systemapi 394 * @since 12 395 */ 396 interface DriverInfo { 397 /** 398 * Bus type of the device. 399 * 400 * @syscap SystemCapability.Driver.ExternalDevice 401 * @systemapi 402 * @since 12 403 */ 404 busType: BusType; 405 406 /** 407 * Unique identifier of the driver. 408 * 409 * @syscap SystemCapability.Driver.ExternalDevice 410 * @systemapi 411 * @since 12 412 */ 413 driverUid: string; 414 415 /** 416 * Driver name. 417 * 418 * @syscap SystemCapability.Driver.ExternalDevice 419 * @systemapi 420 * @since 12 421 */ 422 driverName: string; 423 424 /** 425 * Driver version. 426 * 427 * @syscap SystemCapability.Driver.ExternalDevice 428 * @systemapi 429 * @since 12 430 */ 431 driverVersion: string; 432 433 /** 434 * Driver size. 435 * 436 * @syscap SystemCapability.Driver.ExternalDevice 437 * @systemapi 438 * @since 12 439 */ 440 driverSize: string; 441 442 /** 443 * Driver description. 444 * 445 * @syscap SystemCapability.Driver.ExternalDevice 446 * @systemapi 447 * @since 12 448 */ 449 description: string; 450 } 451 452 /** 453 * Represents the USB driver information. 454 * 455 * @typedef USBDriverInfo 456 * @syscap SystemCapability.Driver.ExternalDevice 457 * @systemapi 458 * @since 12 459 */ 460 interface USBDriverInfo extends DriverInfo { 461 /** 462 * IDs of supported products. 463 * 464 * @syscap SystemCapability.Driver.ExternalDevice 465 * @systemapi 466 * @since 12 467 */ 468 productIdList: Array<number>; 469 470 /** 471 * IDs of supported vendors. 472 * 473 * @syscap SystemCapability.Driver.ExternalDevice 474 * @systemapi 475 * @since 12 476 */ 477 vendorIdList: Array<number>; 478 } 479} 480 481export default deviceManager; 482