1# @ohos.distributedDeviceManager (Device Management) (System API) 2 3The **distributedDeviceManager** module provides APIs for distributed device management. 4 5Applications can call the APIs to: 6 7- Subscribe to or unsubscribe from device state changes. 8- Discover untrusted devices nearby. 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 13 14> **NOTE** 15> 16> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. 17> This topic describes only the system APIs provided by the module. For details about its public APIs, see [@ohos.distributedDeviceManager](js-apis-distributedDeviceManager.md). 18 19 20## Modules to Import 21 22```ts 23import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 24``` 25 26### replyUiAction 27 28replyUiAction(action: number, actionResult: string): void; 29 30Replies to the user's UI operation. This API can be used only by the PIN HAP of the **deviceManager**. 31 32**Required permissions**: ohos.permission.ACCESS_SERVICE_DM 33 34**System capability**: SystemCapability.DistributedHardware.DeviceManager 35 36**System API**: This is a system API. 37 38**Parameters** 39 40 | Name | Type | Mandatory | Description | 41 | ------------- | --------------- | ---- | ------------------- | 42 | action | number | Yes | User operation. | 43 | actionResult | string | Yes | Operation result. | 44 45**Error codes** 46 47For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 48 49| ID | Error Message | 50| -------- | --------------------------------------------------------------- | 51| 201 | Permission verification failed. The application does not have the permission required to call the API. | 52| 202 | Permission verification failed. A non-system application calls a system API. | 53| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed; 4. The size of specified actionResult is greater than 255. | 54 55**Example** 56 57For details about how to initialize **dmInstance** in the example, see [distributedDeviceManager.createDeviceManager](js-apis-distributedDeviceManager.md#distributeddevicemanagercreatedevicemanager). 58<!--code_no_check--> 59 ```ts 60 import { BusinessError } from '@kit.BasicServicesKit'; 61 62 try { 63 /* 64 action = 0 - Grant the permission. 65 action = 1 - Revoke the permission. 66 action = 2 - The user operation in the permission request dialog box times out. 67 action = 3 - Cancel the display of the PIN box. 68 action = 4 - Cancel the display of the PIN input box. 69 action = 5 - Confirm the input in the PIN input box. 70 */ 71 let operation = 0; 72 dmInstance.replyUiAction(operation, 'extra'); 73 } catch (err) { 74 let e: BusinessError = err as BusinessError; 75 console.error('replyUiAction errCode:' + e.code + ',errMessage:' + e.message); 76 } 77 ``` 78 79### on('replyResult') 80 81on(type: 'replyResult', callback: Callback<{ param: string;}>): void; 82 83Subscribes to the reply to the UI operation result. 84 85**Required permissions**: ohos.permission.ACCESS_SERVICE_DM 86 87**System capability**: SystemCapability.DistributedHardware.DeviceManager 88 89**System API**: This is a system API. 90 91**Parameters** 92 93 | Name | Type | Mandatory | Description | 94 | -------- | ------------------------------------ | ---- | ------------------------------ | 95 | type | string | Yes | Event type, which has a fixed value of **replyResult**. | 96 | callback | Callback<{ param: string;}> | Yes | Callback invoked to return the UI status change. | 97 98**Error codes** 99 100For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 101 102| ID | Error Message | 103| -------- | --------------------------------------------------------------- | 104| 202 | Permission verification failed. A non-system application calls a system API. | 105| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed; 4. The size of specified type is greater than 255. | 106 107**Example** 108 109For details about how to initialize **dmInstance** in the example, see [distributedDeviceManager.createDeviceManager](js-apis-distributedDeviceManager.md#distributeddevicemanagercreatedevicemanager). 110<!--code_no_check--> 111 ```ts 112 import { BusinessError } from '@kit.BasicServicesKit'; 113 114 class Data { 115 param: string = ''; 116 } 117 118 interface TmpStr { 119 verifyFailed: boolean; 120 } 121 122 try { 123 dmInstance.on('replyResult', (data: Data) => { 124 console.log('replyResult executed, dialog closed' + JSON.stringify(data)); 125 let tmpStr: TmpStr = JSON.parse(data.param); 126 let isShow = tmpStr.verifyFailed; 127 console.log('replyResult executed, dialog closed' + isShow); 128 }); 129 } catch (err) { 130 let e: BusinessError = err as BusinessError; 131 console.error('replyResult errCode:' + e.code + ',errMessage:' + e.message); 132 } 133 ``` 134 135### off('replyResult') 136 137off(type: 'replyResult', callback?: Callback<{ param: string;}>): void; 138 139Unsubscribes from the reply to the UI operation result. 140 141**Required permissions**: ohos.permission.ACCESS_SERVICE_DM 142 143**System capability**: SystemCapability.DistributedHardware.DeviceManager 144 145**System API**: This is a system API. 146 147**Parameters** 148 149 | Name | Type | Mandatory | Description | 150 | -------- | ------------------------------------- | ---- | ------------------------------ | 151 | type | string | Yes | Event type, which has a fixed value of **replyResult**. | 152 | callback | Callback<{ param: string;}> | No | Callback to unregister. | 153 154**Error codes** 155 156For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 157 158| ID | Error Message | 159| -------- | --------------------------------------------------------------- | 160| 202 | Permission verification failed. A non-system application calls a system API. | 161| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed; 4. The size of specified type is greater than 255. | 162 163**Example** 164 165For details about how to initialize **dmInstance** in the example, see [distributedDeviceManager.createDeviceManager](js-apis-distributedDeviceManager.md#distributeddevicemanagercreatedevicemanager). 166<!--code_no_check--> 167 ```ts 168 import { BusinessError } from '@kit.BasicServicesKit'; 169 170 try { 171 dmInstance.off('replyResult'); 172 } catch (err) { 173 let e: BusinessError = err as BusinessError; 174 console.error('replyResult errCode:' + e.code + ',errMessage:' + e.message); 175 } 176 ``` 177