1/* 2 * Copyright (c) 2020-2024 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 16import type { AsyncCallback, Callback } from './@ohos.base'; 17 18/** 19 * Providers interfaces to create a {@link deviceManager} instances. 20 * 21 * @since 7 22 * @Syscap SystemCapability.DISTRIBUTEDHARDWARE.deviceManager 23 * 24 */ 25declare namespace deviceManager { 26 /** 27 * DeviceInfo 28 * 29 * @systemapi this method can be used only by system applications. 30 */ 31 interface DeviceInfo { 32 /** 33 * DeviceId ID. 34 */ 35 deviceId: string; 36 37 /** 38 * Device name of the device. 39 */ 40 deviceName: string; 41 42 /** 43 * Device type of the device. 44 */ 45 deviceType: DeviceType; 46 47 /** 48 * NetworkId of the device. 49 * 50 * @since 8 51 */ 52 networkId: string; 53 54 /** 55 * @since 9 56 * The distance of dicovered device, in centimeters(cm). 57 */ 58 range: number; 59 60 /** 61 * Indicates the device's trusted type 62 * @syscap SystemCapability.DistributedHardware.DeviceManager 63 * @since 10 64 */ 65 authForm: AuthForm; 66 } 67 68 /** 69 * Device trusted type definitions 70 * @enum {number} 71 * @syscap SystemCapability.DistributedHardware.DeviceManager 72 * @systemapi this method can be used only by system applications. 73 * @since 10 74 */ 75 enum AuthForm { 76 /** 77 * Indicates invalid trusted device type. 78 * @syscap SystemCapability.DistributedHardware.DeviceManager 79 * @since 10 80 */ 81 INVALID_TYPE = -1, 82 83 /** 84 * Indicates peer to peer trusted device type without account. 85 * @syscap SystemCapability.DistributedHardware.DeviceManager 86 * @since 10 87 */ 88 PEER_TO_PEER = 0, 89 90 /** 91 * Indicates identical account trusted device type. 92 * @syscap SystemCapability.DistributedHardware.DeviceManager 93 * @since 10 94 */ 95 IDENTICAL_ACCOUNT = 1, 96 97 /** 98 * Indicates across account trusted device type. 99 * @syscap SystemCapability.DistributedHardware.DeviceManager 100 * @since 10 101 */ 102 ACROSS_ACCOUNT = 2 103 } 104 105 /** 106 * Device Type definitions 107 */ 108 enum DeviceType { 109 /** 110 * Indicates an unknown device type. 111 */ 112 UNKNOWN_TYPE = 0, 113 114 /** 115 * Indicates a speaker. 116 */ 117 SPEAKER = 0x0A, 118 119 /** 120 * Indicates a smartphone. 121 */ 122 PHONE = 0x0E, 123 124 /** 125 * Indicates a tablet. 126 */ 127 TABLET = 0x11, 128 129 /** 130 * Indicates a smart watch. 131 */ 132 WEARABLE = 0x6D, 133 134 /** 135 * Indicates a car. 136 */ 137 CAR = 0x83, 138 139 /** 140 * Indicates a smart TV. 141 */ 142 TV = 0x9C 143 } 144 145 /** 146 * Device state change event definition 147 * 148 * @systemapi this method can be used only by system applications. 149 */ 150 enum DeviceStateChangeAction { 151 /** 152 * device online action 153 */ 154 ONLINE = 0, 155 156 /** 157 * device ready action, the device information synchronization was completed. 158 */ 159 READY = 1, 160 161 /** 162 * device offline action 163 */ 164 OFFLINE = 2, 165 166 /** 167 * device change action 168 */ 169 CHANGE = 3 170 } 171 172 /** 173 * Service subscribe info for device discover 174 * 175 * @systemapi this method can be used only by system applications. 176 */ 177 interface SubscribeInfo { 178 /** 179 * Service subscribe ID, the value is in scope [0, 65535], should be unique for each discover process 180 */ 181 subscribeId: number; 182 183 /** 184 * Discovery mode for service subscription. 185 */ 186 mode: DiscoverMode; 187 188 /** 189 * Service subscription medium. 190 */ 191 medium: ExchangeMedium; 192 193 /** 194 * Service subscription frequency. 195 */ 196 freq: ExchangeFreq; 197 198 /** 199 * only find the device with the same account. 200 */ 201 isSameAccount: boolean; 202 203 /** 204 * find the sleeping devices. 205 */ 206 isWakeRemote: boolean; 207 208 /** 209 * Subscribe capability. 210 */ 211 capability: SubscribeCap; 212 } 213 214 /** 215 * Service publish info for device discover 216 * @since 9 217 * @systemapi this method can be used only by system applications. 218 */ 219 interface PublishInfo { 220 /** 221 * Service publish ID, the value is in scope [0, 65535], should be unique for each publish process 222 */ 223 publishId: number; 224 225 /** 226 * Discovery mode for service subscription. 227 */ 228 mode: DiscoverMode; 229 230 /** 231 * Service subscription frequency. 232 */ 233 freq: ExchangeFreq; 234 235 /** 236 * Whether the device should be ranged by discoverers. 237 */ 238 ranging: boolean; 239 } 240 241 /** 242 * device discover mode 243 * 244 * @systemapi this method can be used only by system applications. 245 */ 246 enum DiscoverMode { 247 /** 248 * when using this key at client side, it means discovering for available nearby devices by 249 * calling @startDeviceDiscovery function, while using this key at server side indicating that 250 * a device publication or advertisement by calling @publishDeviceDiscovery. 251 */ 252 DISCOVER_MODE_PASSIVE = 0x55, 253 254 /** 255 * when using this key at server side, it means discovering for available nearby devices by 256 * calling @startDeviceDiscovery function, while using this key at client side indicating that 257 * a device publication or advertisement by calling @publishDeviceDiscovery. 258 */ 259 DISCOVER_MODE_ACTIVE = 0xAA 260 } 261 262 /** 263 * device discover medium 264 * 265 * @systemapi this method can be used only by system applications. 266 */ 267 enum ExchangeMedium { 268 /** 269 * Automatic medium selection 270 */ 271 AUTO = 0, 272 273 /** 274 * Bluetooth 275 */ 276 BLE = 1, 277 278 /** 279 * Wi-Fi 280 */ 281 COAP = 2, 282 283 /** 284 * USB 285 */ 286 USB = 3 287 } 288 289 /** 290 * device discover freq 291 * 292 * @systemapi this method can be used only by system applications. 293 */ 294 enum ExchangeFreq { 295 /** 296 * Low 297 */ 298 LOW = 0, 299 300 /** 301 * Medium 302 */ 303 MID = 1, 304 305 /** 306 * High 307 */ 308 HIGH = 2, 309 310 /** 311 * Super-high 312 */ 313 SUPER_HIGH = 3 314 } 315 316 /** 317 * device discover capability 318 * 319 * @systemapi this method can be used only by system applications. 320 */ 321 enum SubscribeCap { 322 /** 323 * ddmpCapability, will be discarded later. Currently, it will be converted to OSD capability inner. 324 */ 325 SUBSCRIBE_CAPABILITY_DDMP = 0, 326 327 /** 328 * One Super Device Capability 329 */ 330 SUBSCRIBE_CAPABILITY_OSD = 1 331 } 332 333 /** 334 * Device Authentication param 335 * 336 * @systemapi this method can be used only by system applications 337 */ 338 interface AuthParam { 339 /** 340 * Authentication type, 1 for pin code. 341 */ 342 authType: number; 343 344 /** 345 * Authentication extra infos. 346 */ 347 extraInfo: { [key: string]: any }; 348 } 349 350 /** 351 * Device auth info. 352 * 353 * @systemapi this method can be used only by system applications 354 */ 355 interface AuthInfo { 356 /** 357 * Authentication type, 1 for pin code. 358 */ 359 authType: number; 360 361 /** 362 * the token used for this authentication. 363 */ 364 token: number; 365 366 /** 367 * Authentication extra infos. 368 */ 369 extraInfo: { [key: string]: any }; 370 } 371 372 /** 373 * Creates a {@code DeviceManager} instance. 374 * 375 * <p>To manage devices, you must first call this method to obtain a {@code DeviceManager} instance and then 376 * use this instance to call other device management methods. 377 * 378 * @param bundleName Indicates the bundle name of the application. 379 * @param callback Indicates the callback to be invoked upon {@code DeviceManager} instance creation. 380 * @systemapi this method can be used only by system applications. 381 */ 382 function createDeviceManager(bundleName: string, callback: AsyncCallback<DeviceManager>): void; 383 384 /** 385 * Provides methods for managing devices. 386 */ 387 interface DeviceManager { 388 /** 389 * Releases the {@code DeviceManager} instance after the methods for device management are no longer used. 390 * 391 * @systemapi this method can be used only by system applications. 392 */ 393 release(): void; 394 395 /** 396 * Obtains a list of trusted devices. 397 * 398 * @return Returns a list of trusted devices. 399 * @systemapi this method can be used only by system applications. 400 */ 401 getTrustedDeviceListSync(): Array<DeviceInfo>; 402 403 /** 404 * Obtains a list of trusted devices. 405 * 406 * @since 10 407 * @param isRefresh Quickly refresh the list, and make nearby devices with the same account go online. 408 * @return Returns a list of trusted devices. 409 * @systemapi this method can be used only by system applications. 410 */ 411 getTrustedDeviceListSync(isRefresh: boolean): Array<DeviceInfo>; 412 413 /** 414 * Obtains a list of trusted devices. 415 * 416 * @since 8 417 * @param callback Indicates the callback to be invoked upon getTrustedDeviceList 418 * @return Returns a list of trusted devices. 419 * @systemapi this method can be used only by system applications. 420 */ 421 getTrustedDeviceList(callback: AsyncCallback<Array<DeviceInfo>>): void; 422 423 /** 424 * Obtains a list of trusted devices. 425 * 426 * @since 8 427 * @return Returns a list of trusted devices. 428 * @systemapi this method can be used only by system applications. 429 */ 430 getTrustedDeviceList(): Promise<Array<DeviceInfo>>; 431 432 /** 433 * Obtains local device info 434 * 435 * @since 8 436 * @return Returns local device info. 437 * @systemapi this method can be used only by system applications. 438 */ 439 getLocalDeviceInfoSync(): DeviceInfo; 440 441 /** 442 * Obtains local device info 443 * 444 * @since 8 445 * @param callback Indicates the callback to be invoked upon getLocalDeviceInfo 446 * @return Returns local device info. 447 * @systemapi this method can be used only by system applications. 448 */ 449 getLocalDeviceInfo(callback: AsyncCallback<DeviceInfo>): void; 450 451 /** 452 * Obtains local device info 453 * 454 * @since 8 455 * @return Returns local device info. 456 * @systemapi this method can be used only by system applications. 457 */ 458 getLocalDeviceInfo(): Promise<DeviceInfo>; 459 460 /** 461 * Obtains device info 462 * 463 * @since 10 464 * @param networkId device network id. 465 * @param callback Indicates the callback to be invoked upon getDeviceInfo 466 * @throws {BusinessError} 401 - Parameter error. Possible causes: 467 * 1. Mandatory parameters are left unspecified; 468 * 2. Incorrect parameter type; 469 * 3. Parameter verification failed; 470 * 4. The size of specified networkId is greater than 255. 471 * @return Returns local device info. 472 * @systemapi this method can be used only by system applications. 473 */ 474 getDeviceInfo(networkId: string, callback: AsyncCallback<DeviceInfo>): void; 475 476 /** 477 * Obtains device info 478 * 479 * @since 10 480 * @param networkId device network id. 481 * @throws {BusinessError} 401 - Parameter error. Possible causes: 482 * 1. Mandatory parameters are left unspecified; 483 * 2. Incorrect parameter type; 484 * 3. Parameter verification failed; 485 * 4. The size of specified networkId is greater than 255. 486 * @return Returns local device info. 487 * @systemapi this method can be used only by system applications. 488 */ 489 getDeviceInfo(networkId: string): Promise<DeviceInfo>; 490 491 /** 492 * Start to discover device. 493 * 494 * @since 8 495 * @param subscribeInfo subscribe info to discovery device 496 * @systemapi this method can be used only by system applications. 497 */ 498 startDeviceDiscovery(subscribeInfo: SubscribeInfo): void; 499 500 /** 501 * Start to discover device. 502 * 503 * @since 9 504 * @param subscribeInfo subscribe info to discovery device 505 * @param filterOptions filterOptions to filter discovery device 506 * @systemapi this method can be used only by system applications. 507 */ 508 startDeviceDiscovery(subscribeInfo: SubscribeInfo, filterOptions?: string): void; 509 510 /** 511 * Stop to discover device. 512 * 513 * @param subscribeId Service subscribe ID 514 * @systemapi this method can be used only by system applications. 515 */ 516 stopDeviceDiscovery(subscribeId: number): void; 517 518 /** 519 * Publish discover device. 520 * @since 9 521 * @param publishInfo publish info to Publish discovery device 522 * @systemapi this method can be used only by system applications. 523 */ 524 publishDeviceDiscovery(publishInfo: PublishInfo): void; 525 526 /** 527 * UnPublish discover device. 528 * @since 9 529 * @param publishId Service publish ID, identify a publish operation, should be a unique id in package range 530 * @systemapi this method can be used only by system applications. 531 */ 532 unPublishDeviceDiscovery(publishId: number): void; 533 534 /** 535 * Request credential registerInfo. 536 * 537 * @since 10 538 * @param requestInfo Request credential params. 539 * @param callback Indicates the callback to be invoked upon requestCredential 540 * @throws {BusinessError} 401 - Parameter error. Possible causes: 541 * 1. Mandatory parameters are left unspecified; 542 * 2. Incorrect parameter type; 543 * 3. Parameter verification failed; 544 * 4. The size of specified requestInfo is greater than 255. 545 * @systemapi this method can be used only by system applications. 546 */ 547 requestCredentialRegisterInfo(requestInfo: string, callback: AsyncCallback<{ registerInfo: string }>): void; 548 549 /** 550 * Import credential information. 551 * 552 * @since 10 553 * @param credentialInfo Import credential params. 554 * @param callback Indicates the callback to be invoked upon importCredential 555 * @throws {BusinessError} 401 - Parameter error. Possible causes: 556 * 1. Mandatory parameters are left unspecified; 557 * 2. Incorrect parameter type; 558 * 3. Parameter verification failed; 559 * 4. The size of specified credentialInfo is greater than 5999. 560 * @systemapi this method can be used only by system applications. 561 */ 562 importCredential(credentialInfo: string, callback: AsyncCallback<{ resultInfo: string }>): void; 563 564 /** 565 * delete credential information. 566 * 567 * @since 10 568 * @param queryInfo delete credential params. 569 * @param callback Indicates the callback to be invoked upon deleteCredential 570 * @throws {BusinessError} 401 - Parameter error. Possible causes: 571 * 1. Mandatory parameters are left unspecified; 572 * 2. Incorrect parameter type; 573 * 3. Parameter verification failed; 574 * 4. The size of specified queryInfo is greater than 5999. 575 * @systemapi this method can be used only by system applications. 576 */ 577 deleteCredential(queryInfo: string, callback: AsyncCallback<{ resultInfo: string }>): void; 578 579 /** 580 * Authenticate the specified device. 581 * 582 * @param deviceInfo deviceInfo of device to authenticate 583 * @param authParam authParam of device to authenticate 584 * @param callback Indicates the callback to be invoked upon authenticateDevice 585 * @systemapi this method can be used only by system applications. 586 */ 587 authenticateDevice(deviceInfo: DeviceInfo, authParam: AuthParam, callback: AsyncCallback<{ deviceId: string, pinTone?: number }>): void; 588 589 /** 590 * unAuthenticate the specified device. 591 * 592 * @since 8 593 * @param deviceInfo deviceInfo of device to unAuthenticate 594 * @systemapi this method can be used only by system applications. 595 */ 596 unAuthenticateDevice(deviceInfo: DeviceInfo): void; 597 598 /** 599 * verify auth info, such as pin code. 600 * 601 * @param authInfo device auth info o verify 602 * @param callback Indicates the callback to be invoked upon verifyAuthInfo 603 * @systemapi this method can be used only by system applications. 604 */ 605 verifyAuthInfo(authInfo: AuthInfo, callback: AsyncCallback<{ deviceId: string, level: number }>): void; 606 607 /** 608 * Set user Operation from devicemanager ui, this interface can only be used by devicemanager ui. 609 * 610 * @since 9 611 * @param operateAction User Operation Actions. 612 * operateAction = 0 - allow authentication 613 * operateAction = 1 - cancel authentication 614 * operateAction = 2 - user operation timeout for authentication confirm 615 * operateAction = 3 - cancel pincode display 616 * operateAction = 4 - cancel pincode input 617 * operateAction = 5 - confirm pincode input 618 * @param params Indicates the input param of the user. 619 * @throws {BusinessError} 401 - Parameter error. Possible causes: 620 * 1. Mandatory parameters are left unspecified; 621 * 2. Incorrect parameter type; 622 * 3. Parameter verification failed; 623 * 4. The size of specified params is greater than 255. 624 * @systemapi this method can be used only by system applications. 625 */ 626 setUserOperation(operateAction: number, params: string): void; 627 628 /** 629 * Register a callback from deviceManager service so that the devicemanager ui can be notified when ui statue 630 * changes. 631 * 632 * @since 9 633 * @param callback Indicates the devicemanager ui state to register. 634 * @throws {BusinessError} 401 - Parameter error. Possible causes: 635 * 1. Mandatory parameters are left unspecified; 636 * 2. Incorrect parameter type; 637 * 3. Parameter verification failed; 638 * 4. The size of specified eventType is greater than 255. 639 * @systemapi this method can be used only by system applications. 640 */ 641 on(type: 'uiStateChange', callback: Callback<{ param: string }>): void; 642 643 /** 644 * Unregister uiStatueChange, this interface can only be used by devicemanager ui. 645 * 646 * @since 9 647 * @param callback Indicates the devicemanager ui state to unregister. 648 * @throws {BusinessError} 401 - Parameter error. Possible causes: 649 * 1. Mandatory parameters are left unspecified; 650 * 2. Incorrect parameter type; 651 * 3. Parameter verification failed; 652 * 4. The size of specified eventType is greater than 255. 653 * @systemapi this method can be used only by system applications. 654 */ 655 off(type: 'uiStateChange', callback?: Callback<{ param: string }>): void; 656 657 /** 658 * Register a device state callback so that the application can be notified upon device state changes based on 659 * the application bundle name. 660 * 661 * @param bundleName Indicates the bundle name of the application. 662 * @param callback Indicates the device state callback to register. 663 * @systemapi this method can be used only by system applications. 664 */ 665 on(type: 'deviceStateChange', callback: Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void; 666 667 /** 668 * UnRegister device state callback based on the application bundle name. 669 * 670 * @param bundleName Indicates the bundle name of the application. 671 * @param callback Indicates the device state callback to register. 672 * @systemapi this method can be used only by system applications. 673 */ 674 off(type: 'deviceStateChange', callback?: Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void; 675 676 /** 677 * Register a device found callback so that the application can be notified when the device was found 678 * 679 * @param callback Indicates the device found callback to register. 680 * @systemapi this method can be used only by system applications. 681 */ 682 on(type: 'deviceFound', callback: Callback<{ subscribeId: number, device: DeviceInfo }>): void; 683 684 /** 685 * UnRegister a device found callback so that the application can be notified when the device was found 686 * 687 * @param callback Indicates the device found callback to register. 688 * @systemapi this method can be used only by system applications. 689 */ 690 off(type: 'deviceFound', callback?: Callback<{ subscribeId: number, device: DeviceInfo }>): void; 691 692 /** 693 * Register a device found result callback so that the application can be notified when the device discover was failed 694 * 695 * @param callback Indicates the device found result callback to register. 696 * @systemapi this method can be used only by system applications. 697 */ 698 on(type: 'discoverFail', callback: Callback<{ subscribeId: number, reason: number }>): void; 699 700 /** 701 * UnRegister a device found result callback so that the application can be notified when the device discover was failed 702 * 703 * @param callback Indicates the device found result callback to register. 704 * @systemapi this method can be used only by system applications. 705 */ 706 off(type: 'discoverFail', callback?: Callback<{ subscribeId: number, reason: number }>): void; 707 708 /** 709 * Register a device publish result callback so that the application can be notified when the device publish success 710 * 711 * @since 9 712 * @param callback Indicates the device publish result callback to register. 713 * @systemapi this method can be used only by system applications. 714 */ 715 on(type: 'publishSuccess', callback: Callback<{ publishId: number }>): void; 716 717 /** 718 * UnRegister a device publish result callback so that the application can be notified when the device publish was failed 719 * 720 * @since 9 721 * @param callback Indicates the device publish result callback to register. 722 * @systemapi this method can be used only by system applications. 723 */ 724 off(type: 'publishSuccess', callback?: Callback<{ publishId: number }>): void; 725 726 /** 727 * Register a device publish result callback so that the application can be notified when the device publish was failed 728 * 729 * @since 9 730 * @param callback Indicates the device publish result callback to register. 731 * @systemapi this method can be used only by system applications. 732 */ 733 on(type: 'publishFail', callback: Callback<{ publishId: number, reason: number }>): void; 734 735 /** 736 * UnRegister a device publish result callback so that the application can be notified when the device publish was failed 737 * 738 * @since 9 739 * @param callback Indicates the device publish result callback to register. 740 * @systemapi this method can be used only by system applications. 741 */ 742 off(type: 'publishFail', callback?: Callback<{ publishId: number, reason: number }>): void; 743 744 /** 745 * Register a serviceError callback so that the application can be notified when devicemanager service died 746 * 747 * @param callback Indicates the service error callback to register. 748 * @systemapi this method can be used only by system applications. 749 */ 750 on(type: 'serviceDie', callback: () => void): void; 751 752 /** 753 * UnRegister a serviceError callback so that the application can be notified when devicemanager service died 754 * 755 * @param callback Indicates the service error callback to register. 756 * @systemapi this method can be used only by system applications. 757 */ 758 off(type: 'serviceDie', callback?: () => void): void; 759 } 760} 761 762export default deviceManager; 763