• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.distributedHardware.deviceManager (Device Management)
2
3The **deviceManager** module provides APIs for distributed device management.
4
5System applications can call the APIs to do the following:
6
7- Subscribe to or unsubscribe from device state changes.
8- Discover peripheral untrusted devices.
9- Authenticate or deauthenticate a device.
10- Query the trusted device list.
11- Query local device information, including the device name, type, and ID.
12- Publish device information for discovery purposes.
13
14> **NOTE**
15>
16> - The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
17> - The APIs of this module are system APIs and cannot be called by third-party applications.
18
19
20## Modules to Import
21
22```js
23import deviceManager from '@ohos.distributedHardware.deviceManager';
24```
25
26
27## deviceManager.createDeviceManager
28
29createDeviceManager(bundleName: string, callback: AsyncCallback<DeviceManager>): void
30
31Creates a **DeviceManager** instance.
32
33**System capability**: SystemCapability.DistributedHardware.DeviceManager
34
35**Parameters**
36
37| Name    | Type                                                | Mandatory| Description                                                       |
38| ---------- | ---------------------------------------------------- | ---- | ----------------------------------------------------------- |
39| bundleName | string                                               | Yes  | Bundle name of the application.                                 |
40| callback   | AsyncCallback<[DeviceManager](#devicemanager)> | Yes  | Callback used to return the **DeviceManager** instance created.|
41
42**Error codes**
43
44For details about the error codes, see [Device Management Error Codes](../errorcodes/errorcode-device-manager.md).
45
46| ID| Error Message                                                       |
47| -------- | --------------------------------------------------------------- |
48| 11600101 | Failed to execute the function.                                 |
49| 11600102 | Failed to obtain the service.                                   |
50
51**Example**
52
53  ```js
54  try {
55    deviceManager.createDeviceManager("ohos.samples.jshelloworld", (err, data) => {
56      if (err) {
57        console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message);
58        return;
59      }
60      console.info("createDeviceManager success");
61      let dmInstance = data;
62    });
63  } catch(err) {
64    console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message);
65  }
66  ```
67
68## DeviceInfo
69
70Defines device information.
71
72**System capability**: SystemCapability.DistributedHardware.DeviceManager
73
74| Name                    | Type                       | Mandatory  | Description      |
75| ---------------------- | ------------------------- | ---- | -------- |
76| deviceId               | string                    | Yes   | Unique identifier of a device.|
77| deviceName             | string                    | Yes   | Device name.   |
78| deviceType             | [DeviceType](#devicetype) | Yes   | Device type.   |
79| networkId<sup>8+</sup> | string                    | Yes   | Network ID of the device. |
80| range<sup>9+</sup>     | number                    | Yes   | Distance between the device (discovered device) and the device that initiates device discovery. |
81
82## DeviceType
83
84Enumerates the device types.
85
86**System capability**: SystemCapability.DistributedHardware.DeviceManager
87
88| Name          | Value | Description  |
89| ------------ | ---- | ---- |
90| SPEAKER      | 0x0A | Smart speaker.|
91| PHONE        | 0x0E | Phone.  |
92| TABLET       | 0x11 | Tablet.  |
93| WEARABLE     | 0x6D | Wearable.|
94| TV           | 0x9C | Smart TV. |
95| CAR          | 0x83 | Car.   |
96| UNKNOWN_TYPE | 0    | Unknown device type.|
97
98
99## DeviceStateChangeAction
100
101Enumerates the device states.
102
103**System capability**: SystemCapability.DistributedHardware.DeviceManager
104
105| Name     | Value | Description             |
106| ------- | ---- | --------------- |
107| ONLINE  | 0    | The device is physically online.          |
108| READY   | 1    | The information between devices has been synchronized in the Distributed Data Service (DDS) module, and the device is ready for running distributed services.|
109| OFFLINE | 2    | The device is physically offline.          |
110| CHANGE  | 3    | The device information is changed.        |
111
112## SubscribeInfo
113
114Defines subscription information.
115
116**System capability**: SystemCapability.DistributedHardware.DeviceManager
117
118| Name           | Type                               | Mandatory  | Description               |
119| ------------- | --------------------------------- | ---- | ----------------- |
120| subscribeId   | number                            | Yes   | Subscription ID, used to identify a device discovery period.|
121| mode          | [DiscoverMode ](#discovermode)    | No   | Device discovery mode.            |
122| medium        | [ExchangeMedium](#exchangemedium) | No   | Medium used for device discovery.            |
123| freq          | [ExchangeFreq](#exchangefreq)     | No   | Frequency of device discovery.            |
124| isSameAccount | boolean                           | No   | Whether the same account is used on the discovered device.           |
125| isWakeRemote  | boolean                           | No   | Whether to wake up the discovered device.          |
126| capability    | [SubscribeCap](#subscribecap)     | No   | Discovery capability.            |
127
128
129## DiscoverMode
130
131Enumerates the device discovery modes.
132
133**System capability**: SystemCapability.DistributedHardware.DeviceManager
134
135| Name                   | Value | Description   |
136| --------------------- | ---- | ----- |
137| DISCOVER_MODE_PASSIVE | 0x55 | Passive discovery.|
138| DISCOVER_MODE_ACTIVE  | 0xAA | Active discovery.|
139
140
141## ExchangeMedium
142
143Enumerates the media used for device discovery.
144
145**System capability**: SystemCapability.DistributedHardware.DeviceManager
146
147| Name  | Value | Description       |
148| ---- | ---- | --------- |
149| AUTO | 0    | Automatic.  |
150| BLE  | 1    | Bluetooth.  |
151| COAP | 2    | Wi-Fi.|
152| USB  | 3    | USB. |
153
154## ExchangeFreq
155
156Enumerates the device discovery frequencies.
157
158**System capability**: SystemCapability.DistributedHardware.DeviceManager
159
160| Name        | Value | Description   |
161| ---------- | ---- | ----- |
162| LOW        | 0    | Low frequency. |
163| MID        | 1    | Medium frequency. |
164| HIGH       | 2    | High frequency. |
165| SUPER_HIGH | 3    | Ultra-high frequency.|
166
167
168## SubscribeCap
169
170Enumerates the discovery capabilities.
171
172**System capability**: SystemCapability.DistributedHardware.DeviceManager
173
174| Name                       | Value | Description            |
175| ------------------------- | ---- | -------------- |
176| SUBSCRIBE_CAPABILITY_DDMP | 0    | DDMP capability. This will be deprecated later.|
177| SUBSCRIBE_CAPABILITY_OSD  | 1    | OSD capability.        |
178
179
180## AuthParam
181
182Defines the authentication parameters.
183
184**System capability**: SystemCapability.DistributedHardware.DeviceManager
185
186| Name       | Type                  | Mandatory  | Description        |
187| --------- | -------------------- | ---- | ---------- |
188| authType  | number               | Yes   | Authentication type.     |
189| extraInfo | {[key:string]&nbsp;:&nbsp;any} | No   | Extended field.|
190
191## AuthInfo
192
193Defines authentication information.
194
195**System capability**: SystemCapability.DistributedHardware.DeviceManager
196
197| Name       | Type                  | Mandatory  | Description        |
198| --------- | -------------------- | ---- | ---------- |
199| authType  | number               | Yes   | Authentication type.     |
200| token     | number               | Yes   | Authentication token.  |
201| extraInfo | {[key:string]&nbsp;:&nbsp;any} | No   | Extended field.|
202
203## PublishInfo<sup>9+</sup>
204
205Defines published device information.
206
207**System capability**: SystemCapability.DistributedHardware.DeviceManager
208
209| Name         | Type                             | Mandatory  | Description               |
210| ------------- | --------------------------------- | ---- | ----------------- |
211| publishId     | number                            | Yes   | ID used to identify a publication period.|
212| mode          | [DiscoverMode ](#discovermode)    | Yes   | Device discovery mode.            |
213| freq          | [ExchangeFreq](#exchangefreq)     | Yes   | Frequency of device discovery.            |
214| ranging       | boolean                           | Yes   | Whether the device supports distance reporting.            |
215
216## DeviceManager
217
218Provides APIs to obtain information about trusted devices and local devices. Before calling any API in **DeviceManager**, you must use **createDeviceManager** to create a **DeviceManager** instance, for example, **dmInstance**.
219
220### release
221
222release(): void
223
224Releases this **DeviceManager** instance when it is no longer used.
225
226**System capability**: SystemCapability.DistributedHardware.DeviceManager
227
228**Error codes**
229
230For details about the error codes, see [Device Management Error Codes](../errorcodes/errorcode-device-manager.md).
231
232| ID| Error Message                                                       |
233| -------- | --------------------------------------------------------------- |
234| 11600101 | Failed to execute the function.                                 |
235
236**Example**
237
238  ```js
239  try {
240    dmInstance.release();
241  } catch (err) {
242    console.error("release errCode:" + err.code + ",errMessage:" + err.message);
243  }
244  ```
245
246### getTrustedDeviceListSync
247
248getTrustedDeviceListSync(): Array&lt;DeviceInfo&gt;
249
250Obtains all trusted devices synchronously.
251
252**System capability**: SystemCapability.DistributedHardware.DeviceManager
253
254**Return value**
255
256  | Name                                    | Description       |
257  | -------------------------------------- | --------- |
258  | Array&lt;[DeviceInfo](#deviceinfo)&gt; | List of trusted devices obtained.|
259
260**Error codes**
261
262For details about the error codes, see [Device Management Error Codes](../errorcodes/errorcode-device-manager.md).
263
264| ID| Error Message                                                       |
265| -------- | --------------------------------------------------------------- |
266| 11600101 | Failed to execute the function.                                 |
267
268**Example**
269
270  ```js
271  try {
272    var deviceInfoList = dmInstance.getTrustedDeviceListSync();
273  } catch (err) {
274    console.error("getTrustedDeviceListSync errCode:" + err.code + ",errMessage:" + err.message);
275  }
276  ```
277
278### getTrustedDeviceList<sup>8+</sup>
279
280getTrustedDeviceList(callback:AsyncCallback&lt;Array&lt;DeviceInfo&gt;&gt;): void
281
282Obtains all trusted devices. This API uses an asynchronous callback to return the result.
283
284**System capability**: SystemCapability.DistributedHardware.DeviceManager
285
286**Parameters**
287
288  | Name      | Type                                    | Mandatory  | Description                   |
289  | -------- | ---------------------------------------- | ---- | --------------------- |
290  | callback | AsyncCallback&lt;Array&lt;[DeviceInfo](#deviceinfo)&gt;&gt; | Yes   | Callback used to return the list of trusted devices.|
291
292**Error codes**
293
294For details about the error codes, see [Device Management Error Codes](../errorcodes/errorcode-device-manager.md).
295
296| ID| Error Message                                                       |
297| -------- | --------------------------------------------------------------- |
298| 11600101 | Failed to execute the function.                                 |
299
300**Example**
301
302  ```js
303  try {
304    dmInstance.getTrustedDeviceList((err, data) => {
305      if (err) {
306        console.error("getTrustedDeviceList errCode:" + err.code + ",errMessage:" + err.message);
307        return;
308      }
309      console.log('get trusted device info: ' + JSON.stringify(data));
310    });
311  } catch (err) {
312    console.error("getTrustedDeviceList errCode:" + err.code + ",errMessage:" + err.message);
313  }
314  ```
315
316### getTrustedDeviceList<sup>8+</sup>
317
318getTrustedDeviceList(): Promise&lt;Array&lt;DeviceInfo&gt;&gt;
319
320Obtains all trusted devices. This API uses a promise to return the result.
321
322**System capability**: SystemCapability.DistributedHardware.DeviceManager
323
324**Return value**
325
326  | Type                                      | Description                   |
327  | ---------------------------------------- | --------------------- |
328  | Promise&lt;Array&lt;[DeviceInfo](#deviceinfo)&gt;&gt; | Promise used to return the list of trusted devices.|
329
330**Error codes**
331
332For details about the error codes, see [Device Management Error Codes](../errorcodes/errorcode-device-manager.md).
333
334| ID| Error Message                                                       |
335| -------- | --------------------------------------------------------------- |
336| 11600101 | Failed to execute the function.                                 |
337
338**Example**
339
340  ```js
341  dmInstance.getTrustedDeviceList().then((data) => {
342    console.log('get trusted device info: ' + JSON.stringify(data));
343    }).catch((err) => {
344      console.error("getTrustedDeviceList errCode:" + err.code + ",errMessage:" + err.message);
345  });
346  ```
347
348### getLocalDeviceInfoSync<sup>8+</sup>
349
350getLocalDeviceInfoSync(): [DeviceInfo](#deviceinfo)
351
352Obtains local device information synchronously.
353
354**System capability**: SystemCapability.DistributedHardware.DeviceManager
355
356**Return value**
357
358  | Name                     | Description             |
359  | ------------------------- | ---------------- |
360  | [DeviceInfo](#deviceinfo) | List of local devices obtained.|
361
362**Error codes**
363
364For details about the error codes, see [Device Management Error Codes](../errorcodes/errorcode-device-manager.md).
365
366| ID| Error Message                                                       |
367| -------- | --------------------------------------------------------------- |
368| 11600101 | Failed to execute the function.                                 |
369
370**Example**
371
372  ```js
373  try {
374    var deviceInfo = dmInstance.getLocalDeviceInfoSync();
375  } catch (err) {
376    console.error("getLocalDeviceInfoSync errCode:" + err.code + ",errMessage:" + err.message);
377  }
378  ```
379
380### getLocalDeviceInfo<sup>8+</sup>
381
382getLocalDeviceInfo(callback:AsyncCallback&lt;DeviceInfo&gt;): void
383
384Obtains local device information. This API uses an asynchronous callback to return the result.
385
386**System capability**: SystemCapability.DistributedHardware.DeviceManager
387
388**Parameters**
389
390  | Name      | Type                                    | Mandatory  | Description       |
391  | -------- | ---------------------------------------- | ---- | --------- |
392  | callback | AsyncCallback&lt;[DeviceInfo](#deviceinfo)&gt; | Yes   | Callback used to return the local device information.|
393
394**Error codes**
395
396For details about the error codes, see [Device Management Error Codes](../errorcodes/errorcode-device-manager.md).
397
398| ID| Error Message                                                       |
399| -------- | --------------------------------------------------------------- |
400| 11600101 | Failed to execute the function.                                 |
401
402**Example**
403
404  ```js
405  try {
406    dmInstance.getLocalDeviceInfo((err, data) => {
407    if (err) {
408      console.error("getLocalDeviceInfo errCode:" + err.code + ",errMessage:" + err.message);
409      return;
410    }
411      console.log('get local device info: ' + JSON.stringify(data));
412    });
413  } catch (err) {
414    console.error("getLocalDeviceInfo errCode:" + err.code + ",errMessage:" + err.message);
415  }
416  ```
417
418### getLocalDeviceInfo<sup>8+</sup>
419
420getLocalDeviceInfo(): Promise&lt;DeviceInfo&gt;
421
422Obtains local device information. This API uses a promise to return the result.
423
424**System capability**: SystemCapability.DistributedHardware.DeviceManager
425
426**Return value**
427
428  | Type                                      | Description                   |
429  | ---------------------------------------- | --------------------- |
430  | Promise&lt;[DeviceInfo](#deviceinfo)&gt; | Promise used to return the local device information.|
431
432**Error codes**
433
434For details about the error codes, see [Device Management Error Codes](../errorcodes/errorcode-device-manager.md).
435
436| ID| Error Message                                                       |
437| ------- | --------------------------------------------------------------- |
438| 11600101| Failed to execute the function.                                 |
439
440**Example**
441
442  ```js
443  dmInstance.getLocalDeviceInfo().then((data) => {
444    console.log('get local device info: ' + JSON.stringify(data));
445  }).catch((err) => {
446    console.error("getLocalDeviceInfo errCode:" + err.code + ",errMessage:" + err.message);
447  });
448  ```
449
450### startDeviceDiscovery<sup>8+</sup>
451
452startDeviceDiscovery(subscribeInfo: SubscribeInfo): void
453
454Starts to discover peripheral devices.
455
456**System capability**: SystemCapability.DistributedHardware.DeviceManager
457
458**Parameters**
459
460  | Name           | Type                      | Mandatory| Description   |
461  | ------------- | ------------------------------- | ---- | ----- |
462  | subscribeInfo | [SubscribeInfo](#subscribeinfo) | Yes  | Subscription information.|
463
464**Error codes**
465
466For details about the error codes, see [Device Management Error Codes](../errorcodes/errorcode-device-manager.md).
467
468| ID| Error Message                                                       |
469| -------- | --------------------------------------------------------------- |
470| 11600101 | Failed to execute the function.                                 |
471| 11600104 | Discovery invalid.                                              |
472
473**Example**
474
475  ```js
476  // Automatically generate a unique subscription ID.
477  var subscribeId = Math.floor(Math.random() * 10000 + 1000);
478  var subscribeInfo = {
479      "subscribeId": subscribeId,
480      "mode": 0xAA, // Active discovery
481      "medium": 0, // Automatic. Multiple media can be used for device discovery.
482      "freq": 2, // High frequency
483      "isSameAccount": false,
484      "isWakeRemote": false,
485      "capability": 1
486  };
487  try {
488    dmInstance.startDeviceDiscovery(subscribeInfo); // The deviceFound callback is invoked to notify the application when a device is discovered.
489  } catch (err) {
490    console.error("startDeviceDiscovery errCode:" + err.code + ",errMessage:" + err.message);
491  }
492  ```
493
494### startDeviceDiscovery<sup>9+</sup>
495
496startDeviceDiscovery(subscribeInfo: SubscribeInfo, filterOptions?: string): void
497
498Starts to discover peripheral devices and filters discovered devices.
499
500**System capability**: SystemCapability.DistributedHardware.DeviceManager
501
502**Parameters**
503
504  | Name           | Type                      | Mandatory  | Description   |
505  | ------------- | ------------------------------- | ---- | -----  |
506  | subscribeInfo | [SubscribeInfo](#subscribeinfo) | Yes  | Subscription information.|
507  | filterOptions | string                          | No  | Options for filtering discovered devices.|
508
509**Error codes**
510
511For details about the error codes, see [Device Management Error Codes](../errorcodes/errorcode-device-manager.md).
512
513| ID| Error Message                                                       |
514| -------- | --------------------------------------------------------------- |
515| 11600101 | Failed to execute the function.                                 |
516| 11600104 | Discovery invalid.                                              |
517
518**Example**
519
520  ```js
521  // Automatically generate a unique subscription ID.
522  var subscribeId = Math.floor(Math.random() * 10000 + 1000);
523  var subscribeInfo = {
524      "subscribeId": subscribeId,
525      "mode": 0xAA, // Active discovery
526      "medium": 0, // Automatic. Multiple media can be used for device discovery.
527      "freq": 2, // High frequency
528      "isSameAccount": false,
529      "isWakeRemote": false,
530      "capability": 1
531  };
532  var filterOptions = {
533    "filter_op": "OR", // Optional. The default value is OR.
534    "filters": [
535        {
536            "type": "range",
537            "value": 50 // Filter discovered devices based on the distance (in cm).
538        }
539    ]
540  };
541  try {
542    dmInstance.startDeviceDiscovery(subscribeInfo, JSON.stringify(filterOptions)); // The deviceFound callback is invoked to notify the application when a device is discovered.
543  } catch (err) {
544    console.error("startDeviceDiscovery errCode:" + err.code + ",errMessage:" + err.message);
545  }
546  ```
547
548### stopDeviceDiscovery
549
550stopDeviceDiscovery(subscribeId: number): void
551
552Stops device discovery.
553
554**System capability**: SystemCapability.DistributedHardware.DeviceManager
555
556**Parameters**
557
558  | Name         | Type  | Mandatory  | Description   |
559  | ----------- | ------ | ---- | ----- |
560  | subscribeId | number | Yes   | Subscription ID.|
561
562**Error codes**
563
564For details about the error codes, see [Device Management Error Codes](../errorcodes/errorcode-device-manager.md).
565
566| ID| Error Message                                                       |
567| -------- | --------------------------------------------------------------- |
568| 11600101 | Failed to execute the function.                                 |
569
570**Example**
571
572  ```js
573  try {
574    // stopDeviceDiscovery and startDeviceDiscovery must be used in pairs, and the input parameter **subscribeId** passed in them must be the same.
575    var subscribeId = 12345;
576    dmInstance.stopDeviceDiscovery(subscribeId);
577  } catch (err) {
578    console.error("stopDeviceDiscovery errCode:" + err.code + ",errMessage:" + err.message);
579  }
580  ```
581
582### publishDeviceDiscovery<sup>9+</sup>
583
584publishDeviceDiscovery(publishInfo: PublishInfo): void
585
586Publishes device information for discovery purposes.
587
588**System capability**: SystemCapability.DistributedHardware.DeviceManager
589
590**Parameters**
591
592  | Name         | Type                       | Mandatory| Description   |
593  | ------------- | ------------------------------- | ---- | ----- |
594  | publishInfo   | [PublishInfo](#publishinfo)     | Yes  | Device information to publish.|
595
596**Error codes**
597
598For details about the error codes, see [Device Management Error Codes](../errorcodes/errorcode-device-manager.md).
599
600| ID| Error Message                                                       |
601| -------- | --------------------------------------------------------------- |
602| 11600101 | Failed to execute the function.                                 |
603| 11600105 | Publish invalid.                                                |
604
605**Example**
606
607  ```js
608  // Automatically generate a unique subscription ID.
609  var publishId = Math.floor(Math.random() * 10000 + 1000);
610  var publishInfo = {
611      "publishId": publishId,
612      "mode": 0xAA, // Active discovery
613      "freq": 2, // High frequency
614      "ranging": true  // The device supports reporting the distance to the discovery initiator.
615  };
616  try {
617    dmInstance.publishDeviceDiscovery(publishInfo); // A callback is invoked to notify the application when the device information is published.
618  } catch (err) {
619    console.error("publishDeviceDiscovery errCode:" + err.code + ",errMessage:" + err.message);
620  }
621  ```
622
623### unPublishDeviceDiscovery<sup>9+</sup>
624
625unPublishDeviceDiscovery(publishId: number): void
626
627Stops publishing device information.
628
629**System capability**: SystemCapability.DistributedHardware.DeviceManager
630
631**Parameters**
632
633  | Name       | Type| Mandatory| Description |
634  | ----------- | -------- | ---- | ----- |
635  | publishId   | number   | Yes  | Publish ID.|
636
637**Error codes**
638
639For details about the error codes, see [Device Management Error Codes](../errorcodes/errorcode-device-manager.md).
640
641| ID| Error Message                                                       |
642| -------- | --------------------------------------------------------------- |
643| 11600101 | Failed to execute the function.                                 |
644
645**Example**
646
647  ```js
648  try {
649    // unPublishDeviceDiscovery and publishDeviceDiscovery must be used in pairs, and the input parameter **publishId** passed in them must be the same.
650    var publishId = 12345;
651    dmInstance.unPublishDeviceDiscovery(publishId);
652  } catch (err) {
653    console.error("unPublishDeviceDiscovery errCode:" + err.code + ",errMessage:" + err.message);
654  }
655  ```
656
657### authenticateDevice
658
659authenticateDevice(deviceInfo: DeviceInfo, authParam: AuthParam, callback: AsyncCallback&lt;{deviceId: string, pinToken ?: number}&gt;): void
660
661Authenticates a device.
662
663**System capability**: SystemCapability.DistributedHardware.DeviceManager
664
665**Parameters**
666
667  | Name        | Type                                    | Mandatory  | Description     |
668  | ---------- | ---------------------------------------- | ---- | ------- |
669  | deviceInfo | [DeviceInfo](#deviceinfo)                | Yes   | Device information.  |
670  | authParam  | [AuthParam](#authparam)                  | Yes   | Authentication parameter.  |
671  | callback   | AsyncCallback&lt;{deviceId:&nbsp;string,&nbsp;pinToken&nbsp;?:&nbsp;number}&gt; | Yes   | Callback used to return the authentication result.|
672
673**Error codes**
674
675For details about the error codes, see [Device Management Error Codes](../errorcodes/errorcode-device-manager.md).
676
677| ID| Error Message                                                       |
678| -------- | --------------------------------------------------------------- |
679| 11600101 | Failed to execute the function.                                 |
680| 11600103 | Authentication invalid.                                         |
681
682**Example**
683
684  ```js
685  // Information about the device to authenticate. The information can be obtained from the device discovery result.
686  var deviceInfo ={
687      "deviceId": "XXXXXXXX",
688      "deviceName": "",
689      "deviceType": 0x0E,
690      "networkId" : "xxxxxxx",
691      "range" : 0
692  };
693  let extraInfo = {
694          'targetPkgName': 'ohos.samples.xxx',
695          'appName': 'xxx',
696          'appDescription': 'xxx',
697          'business': '0'
698  }
699  let authParam = {
700      'authType': 1, // Authentication type. The value 1 means no account PIN authentication.
701      'extraInfo': extraInfo
702  }
703  try {
704    dmInstance.authenticateDevice(deviceInfo, authParam, (err, data) => {
705      if (err) {
706          console.error("authenticateDevice errCode:" + err.code + ",errMessage:" + err.message);
707          return;
708      }
709      console.info("authenticateDevice result:" + JSON.stringify(data));
710      let token = data.pinToken;
711    });
712  } catch (err) {
713    console.error("authenticateDevice errCode:" + err.code + ",errMessage:" + err.message);
714  }
715  ```
716
717### unAuthenticateDevice<sup>8+</sup>
718
719unAuthenticateDevice(deviceInfo: DeviceInfo): void
720
721Deauthenticates a device.
722
723**System capability**: SystemCapability.DistributedHardware.DeviceManager
724
725**Parameters**
726
727  | Name        | Type                     | Mandatory  | Description   |
728  | ---------- | ------------------------- | ---- | ----- |
729  | deviceInfo | [DeviceInfo](#deviceinfo) | Yes   | Device information.|
730
731**Error codes**
732
733For details about the error codes, see [Device Management Error Codes](../errorcodes/errorcode-device-manager.md).
734
735| ID| Error Message                                                       |
736| -------- | --------------------------------------------------------------- |
737| 11600101 | Failed to execute the function.                                 |
738
739**Example**
740
741  ```js
742  try {
743    var deviceInfo ={
744      "deviceId": "XXXXXXXX",
745      "deviceName": "",
746      "deviceType": 0x0E,
747      "networkId" : "xxxxxxx",
748      "range" : 0
749    };
750    dmInstance.unAuthenticateDevice(deviceInfo);
751  } catch (err) {
752    console.error("unAuthenticateDevice errCode:" + err.code + ",errMessage:" + err.message);
753  }
754  ```
755
756### verifyAuthInfo
757
758verifyAuthInfo(authInfo: AuthInfo, callback: AsyncCallback&lt;{deviceId: string, level: number}&gt;): void
759
760Verifies authentication information.
761
762**System capability**: SystemCapability.DistributedHardware.DeviceManager
763
764**Parameters**
765
766  | Name      | Type                                    | Mandatory  | Description     |
767  | -------- | ---------------------------------------- | ---- | ------- |
768  | authInfo | [AuthInfo](#authinfo)                    | Yes   | Authentication information.  |
769  | callback | AsyncCallback&lt;{deviceId:&nbsp;string,&nbsp;level:&nbsp;number}&gt; | Yes   | Callback used to return the verification result.|
770
771**Error codes**
772
773For details about the error codes, see [Device Management Error Codes](../errorcodes/errorcode-device-manager.md).
774
775| ID| Error Message                                                       |
776| -------- | --------------------------------------------------------------- |
777| 11600101 | Failed to execute the function.                                 |
778
779**Example**
780
781  ```js
782  let authInfo = {
783    "authType": 1,
784    "token": 123456,
785    "extraInfo": {}
786  }
787  try {
788    dmInstance.verifyAuthInfo(authInfo, (err, data) => {
789    if (err) {
790        console.error("verifyAuthInfo errCode:" + err.code + ",errMessage:" + err.message);
791        return;
792    }
793    console.info("verifyAuthInfo result:" + JSON.stringify(data));
794    });
795  } catch (err) {
796    console.error("verifyAuthInfo errCode:" + err.code + ",errMessage:" + err.message);
797  }
798  ```
799
800### setUserOperation<sup>9+</sup>
801
802setUserOperation(operateAction: number, params: string): void;
803
804Sets a user operation.
805
806**System capability**: SystemCapability.DistributedHardware.DeviceManager
807
808**Parameters**
809
810  | Name      | Type           | Mandatory | Description               |
811  | ------------- | --------------- | ---- | ------------------- |
812  | operateAction | number          | Yes   | User operation.      |
813  | params        | string          | Yes   | Input parameters of the user.|
814
815**Example**
816
817  ```js
818 try {
819    /*
820      operateAction = 0 - Grant the permission.
821      operateAction = 1 - Revoke the permission.
822      operateAction = 2 - The user operation in the permission request dialog box times out.
823      operateAction = 3 - Cancel the display of the PIN box.
824      operateAction = 4 - Cancel the display of the PIN input box.
825      operateAction = 5 - Confirm the input in the PIN input box.
826    */
827    let operation = 0;
828    dmInstance.setUserOperation(operation, "extra")
829    } catch (err) {
830      console.error("setUserOperation errCode:" + err.code + ",errMessage:" + err.message);
831  }
832  ```
833
834### on('uiStateChange')<sup>9+</sup>
835
836on(type: 'uiStateChange', callback: Callback&lt;{ param: string}&gt;): void;
837
838Subscribes to UI status changes.
839
840**System capability**: SystemCapability.DistributedHardware.DeviceManager
841
842**Parameters**
843
844  | Name     | Type                            | Mandatory| Description                           |
845  | -------- | ------------------------------------ | ---- | ------------------------------ |
846  | type     | string                                | Yes | Event type. The value **'uiStateChange'** indicates a UI status change event.|
847  | callback | Callback&lt;{&nbsp;param:&nbsp;string}&gt; | Yes | Callback used to return the UI status.       |
848
849**Example**
850
851  ```js
852  try {
853    dmInstance.on('uiStateChange', (data) => {
854    console.log("uiStateChange executed, dialog closed" + JSON.stringify(data))
855    var tmpStr = JSON.parse(data.param)
856    var isShow = tmpStr.verifyFailed
857    console.log("uiStateChange executed, dialog closed" + isShow)
858  });
859  } catch (err) {
860    console.error("uiStateChange errCode:" + err.code + ",errMessage:" + err.message);
861  }
862  ```
863
864### off('uiStateChange')<sup>9+</sup>
865
866off(type: 'uiStateChange', callback?: Callback&lt;{ param: string}&gt;): void;
867
868Unsubscribes from UI status changes.
869
870**System capability**: SystemCapability.DistributedHardware.DeviceManager
871
872**Parameters**
873
874  | Name     | Type                             | Mandatory| Description                           |
875  | -------- | ------------------------------------- | ---- | ------------------------------ |
876  | type     | string                                | Yes  | Event type. The value **'uiStateChange'** indicates a UI status change event.|
877  | callback | Callback&lt;{&nbsp;param:&nbsp;string}&gt; | No  | Callback used to return the UI status.|
878
879**Example**
880
881  ```js
882  try {
883    dmInstance.off('uiStateChange');
884  } catch (err) {
885    console.error("uiStateChange errCode:" + err.code + ",errMessage:" + err.message);
886  }
887  ```
888
889### on('deviceStateChange')
890
891on(type: 'deviceStateChange',  callback: Callback&lt;{ action: DeviceStateChangeAction, device: DeviceInfo }&gt;): void
892
893Subscribes to changes in the device state.
894
895**System capability**: SystemCapability.DistributedHardware.DeviceManager
896
897**Parameters**
898
899  | Name      | Type                                    | Mandatory  | Description                            |
900  | -------- | ---------------------------------------- | ---- | ------------------------------ |
901  | type     | string                                   | Yes   | Event type. The value **'deviceStateChange'** indicates a device state change event.|
902  | callback | Callback&lt;{ action: [DeviceStateChangeAction](#devicestatechangeaction), device: [DeviceInfo](#deviceinfo) }&gt; | Yes   | Callback used to return the device information and state.     |
903
904**Example**
905
906  ```js
907  try {
908    dmInstance.on('deviceStateChange', (data) => {
909      console.info("deviceStateChange on:" + JSON.stringify(data));
910    });
911  } catch (err) {
912    console.error("deviceStateChange errCode:" + err.code + ",errMessage:" + err.message);
913  }
914  ```
915
916### off('deviceStateChange')
917
918off(type: 'deviceStateChange', callback?: Callback&lt;{ action: DeviceStateChangeAction, device: DeviceInfo }&gt;): void
919
920Unsubscribes from changes in the device state.
921
922**System capability**: SystemCapability.DistributedHardware.DeviceManager
923
924**Parameters**
925
926  | Name      | Type                                    | Mandatory  | Description                         |
927  | -------- | ---------------------------------------- | ---- | --------------------------- |
928  | type     | string                                   | Yes   | Event type. The value **'deviceStateChange'** indicates a device state change event.       |
929  | callback | Callback&lt;{ action: [DeviceStateChangeAction](#devicestatechangeaction), device: [DeviceInfo](#deviceinfo) }&gt; | No   | Callback used to return the device information and state.|
930
931**Example**
932
933  ```js
934  try {
935    dmInstance.off('deviceStateChange', (data) => {
936      console.info('deviceStateChange' + JSON.stringify(data));
937    });
938  } catch (err) {
939    console.error("deviceStateChange errCode:" + err.code + ",errMessage:" + err.message);
940  }
941  ```
942
943### on('deviceFound')
944
945on(type: 'deviceFound', callback: Callback&lt;{ subscribeId: number, device: DeviceInfo }&gt;): void
946
947Subscribes to device discovery events.
948
949**System capability**: SystemCapability.DistributedHardware.DeviceManager
950
951**Parameters**
952
953  | Name      | Type                                    | Mandatory  | Description                        |
954  | -------- | ---------------------------------------- | ---- | -------------------------- |
955  | type     | string                                   | Yes   | Event type. The value **'deviceFound'** indicates an event reported when a device is discovered.|
956  | callback | Callback&lt;{&nbsp;subscribeId:&nbsp;number,&nbsp;device:&nbsp;[DeviceInfo](#deviceinfo)&nbsp;}&gt; | Yes   | Callback used for device discovery.              |
957
958**Example**
959
960  ```js
961  try {
962    dmInstance.on('deviceFound', (data) => {
963      console.info("deviceFound:" + JSON.stringify(data));
964    });
965  } catch (err) {
966    console.error("deviceFound errCode:" + err.code + ",errMessage:" + err.message);
967  }
968  ```
969
970### off('deviceFound')
971
972off(type: 'deviceFound', callback?: Callback&lt;{ subscribeId: number, device: DeviceInfo }&gt;): void
973
974Unsubscribes from device discovery events.
975
976**System capability**: SystemCapability.DistributedHardware.DeviceManager
977
978**Parameters**
979
980  | Name      | Type                                    | Mandatory  | Description                         |
981  | -------- | ---------------------------------------- | ---- | --------------------------- |
982  | type     | string                                   | Yes   | Event type. The value **'deviceFound'** indicates an event reported when a device is discovered.                |
983  | callback | Callback&lt;{&nbsp;subscribeId:&nbsp;number,&nbsp;device:&nbsp;[DeviceInfo](#deviceinfo)&nbsp;}&gt; | No   | Callback used to return the device information and state.|
984
985**Example**
986
987  ```js
988  try {
989    dmInstance.off('deviceFound', (data) => {
990      console.info('deviceFound' + JSON.stringify(data));
991    });
992  } catch (err) {
993    console.error("deviceFound errCode:" + err.code + ",errMessage:" + err.message);
994  }
995  ```
996
997### on('discoverFail')
998
999on(type: 'discoverFail', callback: Callback&lt;{ subscribeId: number, reason: number }&gt;): void
1000
1001Subscribes to device discovery failures.
1002
1003**System capability**: SystemCapability.DistributedHardware.DeviceManager
1004
1005**Parameters**
1006
1007  | Name      | Type                                    | Mandatory  | Description                            |
1008  | -------- | ---------------------------------------- | ---- | ------------------------------ |
1009  | type     | string                                   | Yes   | Event type. The event **'discoverFail'** indicates an event reported when device discovery fails.|
1010  | callback | Callback&lt;{&nbsp;subscribeId:&nbsp;number,&nbsp;reason:&nbsp;number&nbsp;}&gt; | Yes   | Callback used for the device discovery failure.                |
1011
1012**Example**
1013
1014  ```js
1015  try {
1016    dmInstance.on('discoverFail', (data) => {
1017        console.info("discoverFail on:" + JSON.stringify(data));
1018    });
1019  } catch (err) {
1020    console.error("discoverFail errCode:" + err.code + ",errMessage:" + err.message);
1021  }
1022  ```
1023
1024### off('discoverFail')
1025
1026off(type: 'discoverFail', callback?: Callback&lt;{ subscribeId: number, reason: number }&gt;): void
1027
1028Unsubscribes from device discovery failures.
1029
1030**System capability**: SystemCapability.DistributedHardware.DeviceManager
1031
1032**Parameters**
1033
1034  | Name      | Type                                    | Mandatory  | Description               |
1035  | -------- | ---------------------------------------- | ---- | ----------------- |
1036  | type     | string                                   | Yes   | Event type. The event **'discoverFail'** indicates an event reported when device discovery fails.    |
1037  | callback | Callback&lt;{&nbsp;subscribeId:&nbsp;number,&nbsp;reason:&nbsp;number&nbsp;}&gt; | No   | Callback used for the device discovery failure.|
1038
1039**Example**
1040
1041  ```js
1042  try {
1043    dmInstance.off('discoverFail', (data) => {
1044      console.info('discoverFail' + JSON.stringify(data));
1045    });
1046  } catch (err) {
1047    console.error("discoverFail errCode:" + err.code + ",errMessage:" + err.message);
1048  }
1049  ```
1050
1051### on('publishSuccess')<sup>9+</sup>
1052
1053on(type: 'publishSuccess', callback: Callback&lt;{ publishId: number }&gt;): void
1054
1055Subscribes to device information publication success events.
1056
1057**System capability**: SystemCapability.DistributedHardware.DeviceManager
1058
1059**Parameters**
1060
1061  | Name    | Type                                | Mandatory| Description                      |
1062  | -------- | ---------------------------------------- | ---- | -------------------------- |
1063  | type     | string                                   | Yes  | Event type. The value **'publishSuccess'** indicates an event reported when device information is published.|
1064  | callback | Callback&lt;{&nbsp;publishId:&nbsp;number&nbsp;}&gt;    | Yes  | Callback used to return the publish ID.              |
1065
1066
1067**Example**
1068
1069  ```js
1070  try {
1071    dmInstance.on('publishSuccess', (data) => {
1072      console.info("publishSuccess:" + JSON.stringify(data));
1073    });
1074  } catch (err) {
1075    console.error("publishSuccess errCode:" + err.code + ",errMessage:" + err.message);
1076  }
1077  ```
1078
1079### off('publishSuccess')<sup>9+</sup>
1080
1081off(type: 'publishSuccess', callback?: Callback&lt;{ publishId: number }&gt;): void
1082
1083Unsubscribes from device information publication success events.
1084
1085**System capability**: SystemCapability.DistributedHardware.DeviceManager
1086
1087**Parameters**
1088
1089  | Name    | Type                                | Mandatory| Description                         |
1090  | -------- | ---------------------------------------- | ---- | --------------------------- |
1091  | type     | string                                   | Yes  | Event type. The value **'publishSuccess'** indicates an event reported when device information is published.                |
1092  | callback | Callback&lt;{&nbsp;publishId:&nbsp;number&nbsp;}&gt;    | No  | Callback used to return the publish ID.|
1093
1094**Example**
1095
1096  ```js
1097  try {
1098    dmInstance.off('publishSuccess', (data) => {
1099      console.info('publishSuccess' + JSON.stringify(data));
1100    });
1101  } catch (err) {
1102    console.error("publishSuccess errCode:" + err.code + ",errMessage:" + err.message);
1103  }
1104  ```
1105
1106### on('publishFail')<sup>9+</sup>
1107
1108on(type: 'publishFail', callback: Callback&lt;{ publishId: number, reason: number }&gt;): void
1109
1110Subscribes to device information publication failures.
1111
1112**System capability**: SystemCapability.DistributedHardware.DeviceManager
1113
1114**Parameters**
1115
1116  | Name    | Type                                             | Mandatory| Description                            |
1117  | -------- | ----------------------------------------------------- | ---- | ------------------------------ |
1118  | type     | string                                                | Yes  | Event type. The event **'publishFail'** indicates an event reported when publishing device information fails.|
1119  | callback | Callback&lt;{&nbsp;publishId:&nbsp;number,&nbsp;reason:&nbsp;number&nbsp;}&gt; | Yes  | Callback used for the publication failure.                |
1120
1121**Example**
1122
1123  ```js
1124  try {
1125    dmInstance.on('publishFail', (data) => {
1126      console.info("publishFail on:" + JSON.stringify(data));
1127    });
1128  } catch (err) {
1129    console.error("publishFail errCode:" + err.code + ",errMessage:" + err.message);
1130  }
1131  ```
1132
1133### off('publishFail')<sup>9+</sup>
1134
1135off(type: 'publishFail', callback?: Callback&lt;{ publishId: number, reason: number }&gt;): void
1136
1137Unsubscribes from device information publication failures.
1138
1139**System capability**: SystemCapability.DistributedHardware.DeviceManager
1140
1141**Parameters**
1142
1143  | Name    | Type                                             | Mandatory| Description               |
1144  | -------- | ----------------------------------------------------- | ---- | ----------------- |
1145  | type     | string                                                | Yes  | Event type. The event **'publishFail'** indicates an event reported when publishing device information fails.    |
1146  | callback | Callback&lt;{&nbsp;publishId:&nbsp;number,&nbsp;reason:&nbsp;number&nbsp;}&gt; | No  | Callback used for the device discovery failure.|
1147
1148**Example**
1149
1150  ```js
1151  try {
1152    dmInstance.off('publishFail', (data) => {
1153      console.info('publishFail' + JSON.stringify(data));
1154    });
1155  } catch (err) {
1156    console.error("publishFail errCode:" + err.code + ",errMessage:" + err.message);
1157  }
1158  ```
1159
1160### on('serviceDie')
1161
1162on(type: 'serviceDie', callback: () =&gt; void): void
1163
1164Subscribes to dead events of the **DeviceManager** service.
1165
1166**System capability**: SystemCapability.DistributedHardware.DeviceManager
1167
1168**Parameters**
1169
1170  | Name      | Type                   | Mandatory  | Description                                      |
1171  | -------- | ----------------------- | ---- | ---------------------------------------- |
1172  | type     | string                  | Yes   | Event type. The value **'serviceDie'** indicates an event reported when the **DeviceManager** service is terminated unexpectedly.|
1173  | callback | ()&nbsp;=&gt;&nbsp;void | Yes   | Callback invoked when a dead event of the **DeviceManager** service occurs.                      |
1174
1175**Example**
1176
1177  ```js
1178  try {
1179    dmInstance.on("serviceDie", () => {
1180      console.info("serviceDie on");
1181    });
1182  } catch (err) {
1183    console.error("serviceDie errCode:" + err.code + ",errMessage:" + err.message);
1184  }
1185  ```
1186
1187### off('serviceDie')
1188
1189off(type: 'serviceDie', callback?: () =&gt; void): void
1190
1191Unsubscribes from dead events of the **DeviceManager** service.
1192
1193**System capability**: SystemCapability.DistributedHardware.DeviceManager
1194
1195**Parameters**
1196
1197  | Name      | Type                   | Mandatory  | Description                                      |
1198  | -------- | ----------------------- | ---- | ---------------------------------------- |
1199  | type     | string                  | Yes   | Event type. The value **'serviceDie'** indicates an event reported when the **DeviceManager** service is terminated unexpectedly.|
1200  | callback | ()&nbsp;=&gt;&nbsp;void | No   | Callback used to return the dead event of the **DeviceManager** service.                    |
1201
1202**Example**
1203
1204  ```js
1205  try {
1206    dmInstance.off("serviceDie", () => {
1207      console.info("serviceDie off");
1208    });
1209  } catch (err) {
1210    console.error("serviceDie errCode:" + err.code + ",errMessage:" + err.message);
1211  }
1212  ```
1213