1# @ohos.distributedHardware.hardwareManager (Distributed Hardware Management) (System API) 2 3The **hardwareManager** module provides the capability of controlling distributed hardware, including pausing, resuming, and stopping the distributed hardware service on the controlled device. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 11. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> 9> The APIs provided by this module are system APIs. 10 11## Modules to Import 12 13```js 14import hardwareManager from '@ohos.distributedHardware.hardwareManager'; 15``` 16 17## HardwareDescriptor 18 19Represents the distributed hardware information. 20 21**System capability**: SystemCapability.DistributedHardware.DistributedHardwareFWK 22 23| Name | Type | Mandatory | Description | 24| ------------ | --------------------------------------------------- | ---- | ------------------------------------------------------------ | 25| type | [DistributedHardwareType](#distributedhardwaretype) | Yes | Type of the distributed hardware.<br>**Required permissions**: ohos.permission.ACCESS_DISTRIBUTED_HARDWARE | 26| srcNetworkId | string | No | Source device. If this parameter is not specified, it indicates all source devices.<br>**Required permissions**: ohos.permission.ACCESS_DISTRIBUTED_HARDWARE | 27 28## DistributedHardwareType 29 30Enumerates the types of the distributed hardware. 31 32**System capability**: SystemCapability.DistributedHardware.DistributedHardwareFWK 33 34| Name | Value | Description | 35| :------------ | ---- | ---------------------------- | 36| ALL | 0 | All distributed applications. | 37| CAMERA | 1 | Distributed camera. | 38| SCREEN | 8 | Distributed screen. | 39| MODEM_MIC | 256 | Distributed microphone for mobile calls. | 40| MODEM_SPEAKER | 512 | Distributed speaker for mobile calls. | 41| MIC | 1024 | Distributed microphone. | 42| SPEAKER | 2048 | Distributed speaker. | 43 44## DistributedHardwareErrorCode 45 46Enumerates the error codes used for the distributed hardware. 47 48**System capability**: SystemCapability.DistributedHardware.DistributedHardwareFWK 49 50| Name | Value | Description | 51| ----------------------------------------- | -------- | ---------------------- | 52| ERR_CODE_DISTRIBUTED_HARDWARE_NOT_STARTED | 24200101 | The distributed hardware is not started. | 53| ERR_CODE_DEVICE_NOT_CONNECTED | 24200102 | The source device is not connected. | 54 55## hardwareManager.pauseDistributedHardware 56 57pauseDistributedHardware(description: HardwareDescriptor): Promise<void> 58 59Pauses the distributed hardware service on the controlled device. This API uses a promise to return the result. 60 61**Required permissions**: ohos.permission.ACCESS_DISTRIBUTED_HARDWARE 62 63**System capability**: SystemCapability.DistributedHardware.DistributedHardwareFWK 64 65**Parameters** 66 67| Name | Type | Mandatory | Description | 68| --------- | ---------------------------------------- | ---- | -------- | 69| description | [HardwareDescriptor](#hardwaredescriptor) | Yes | Hardware information. | 70 71**Return value** 72 73| Type | Description | 74| ------------------- | ---------------- | 75| Promise<void> | Promise that returns no value. | 76 77**Error codes** 78 79| ID | Error Message | 80| -------- | ---------------------------------------------------- | 81| 201 | Permission verification failed. | 82| 202 | Permission denied, non-system app called system api. | 83| 401 | Input parameter error. | 84| 24200101 | The specified distributed hardware is not started. | 85| 24200102 | The specified source device is not connected. | 86 87**Example** 88 89 ```ts 90 import hardwareManager from '@ohos.distributedHardware.hardwareManager'; 91 import { BusinessError } from '@ohos.base'; 92 93 try { 94 let description: hardwareManager.HardwareDescriptor = { 95 type: 1, 96 srcNetworkId: '1111' 97 }; 98 hardwareManager.pauseDistributedHardware(description).then(() => { 99 console.log('pause distributed hardware successfully'); 100 }).catch((error: BusinessError) => { 101 console.error('pause distributed hardware failed, cause:' + error); 102 }) 103 console.log('pause distributed hardware successfully'); 104 } catch (error) { 105 console.error('pause distributed hardware failed:' + error); 106 } 107 ``` 108 109## hardwareManager.resumeDistributedHardware 110 111resumeDistributedHardware(description: HardwareDescriptor): Promise<void> 112 113Resumes the distributed hardware service on the controlled device. This API uses a promise to return the result. 114 115**Required permissions**: ohos.permission.ACCESS_DISTRIBUTED_HARDWARE 116 117**System capability**: SystemCapability.DistributedHardware.DistributedHardwareFWK 118 119**Parameters** 120 121| Name | Type | Mandatory | Description | 122| ----------- | ----------------------------------------- | ---- | -------------- | 123| description | [HardwareDescriptor](#hardwaredescriptor) | Yes | Hardware information. | 124 125**Return value** 126 127| Type | Description | 128| ------------------- | ------------------------- | 129| Promise<void> | Promise that returns no value. | 130 131**Error codes** 132 133| ID | Error Message | 134| -------- | ---------------------------------------------------- | 135| 201 | Permission verification failed. | 136| 202 | Permission denied, non-system app called system api. | 137| 401 | Input parameter error. | 138| 24200101 | The specified distributed hardware is not started. | 139| 24200102 | The specified source device is not connected. | 140 141**Example** 142 143 ```ts 144 import hardwareManager from '@ohos.distributedHardware.hardwareManager'; 145 import { BusinessError } from '@ohos.base'; 146 147 try { 148 let description: hardwareManager.HardwareDescriptor = { 149 type: 1, 150 srcNetworkId: '1111' 151 }; 152 hardwareManager.resumeDistributedHardware(description).then(() => { 153 console.log('resume distributed hardware successfully'); 154 }).catch((error: BusinessError) => { 155 console.error('resume distributed hardware failed, cause:' + error); 156 }) 157 console.log('resume distributed hardware successfully'); 158 } catch (error) { 159 console.error('resume distributed hardware failed:' + error); 160 } 161 162 163 ``` 164 165## hardwareManager.stopDistributedHardware 166 167stopDistributedHardware(description: HardwareDescriptor): Promise<void> 168 169Stops the distributed hardware service on the controlled device. This API uses a promise to return the result. 170 171**Required permissions**: ohos.permission.ACCESS_DISTRIBUTED_HARDWARE 172 173**System capability**: SystemCapability.DistributedHardware.DistributedHardwareFWK 174 175**Parameters** 176 177| Name | Type | Mandatory | Description | 178| ----------- | ----------------------------------------- | ---- | -------------- | 179| description | [HardwareDescriptor](#hardwaredescriptor) | Yes | Hardware information. | 180 181**Return value** 182 183| Type | Description | 184| ------------------- | ------------------------- | 185| Promise<void> | Promise that returns no value. | 186 187**Error codes** 188 189| ID | Error Message | 190| -------- | ---------------------------------------------------- | 191| 201 | Permission verification failed. | 192| 202 | Permission denied, non-system app called system api. | 193| 401 | Input parameter error. | 194| 24200101 | The specified distributed hardware is not started. | 195| 24200102 | The specified source device is not connected. | 196 197**Example** 198 199 ```ts 200 import hardwareManager from '@ohos.distributedHardware.hardwareManager'; 201 import { BusinessError } from '@ohos.base'; 202 203 try { 204 let description: hardwareManager.HardwareDescriptor = { 205 type: 1, 206 srcNetworkId: '1111' 207 }; 208 hardwareManager.stopDistributedHardware(description).then(() => { 209 console.log('stop distributed hardware successfully'); 210 }).catch((error: BusinessError) => { 211 console.error('stop distributed hardware failed, cause:' + error); 212 }) 213 console.log('stop distributed hardware successfully'); 214 } catch (error) { 215 console.error('stop distributed hardware failed:' + error); 216 } 217 ``` 218