1# @ohos.enterprise.deviceControl (Device Control) (System interface) 2 3The **deviceControl** module provides APIs for device control. 4 5> **NOTE** 6> 7> 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. 8> 9> The APIs of this module can be used only in the stage model. 10> 11> The APIs of this module can be called only by a [device administrator application](../../mdm/mdm-kit-guide.md#introduction) that is [enabled](js-apis-enterprise-adminManager-sys.md#adminmanagerenableadmin). 12> 13> This topic describes only the system APIs provided by the module. For details about its public APIs, see [@ohos.enterprise.deviceControl](js-apis-enterprise-deviceControl.md). 14 15## Modules to Import 16 17```ts 18import { deviceControl } from '@kit.MDMKit'; 19``` 20 21## deviceControl.resetFactory 22 23resetFactory(admin: Want, callback: AsyncCallback\<void>): void 24 25Restores device factory settings through the specified device administrator application. This API uses an asynchronous callback to return the result. 26 27**Required permissions**: ohos.permission.ENTERPRISE_RESET_DEVICE 28 29**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 30 31 32**Parameters** 33 34| Name | Type | Mandatory | Description | 35| ----- | ----------------------------------- | ---- | ------- | 36| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 37| callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 38 39**Error codes** 40 41For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 42 43| ID| Error Message | 44| ------- | ---------------------------------------------------------------------------- | 45| 9200001 | The application is not an administrator application of the device. | 46| 9200002 | The administrator application does not have permission to manage the device. | 47| 201 | Permission verification failed. The application does not have the permission required to call the API. | 48| 202 | Permission verification failed. A non-system application calls a system API. | 49| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 50 51**Example** 52 53```ts 54import { deviceControl } from '@kit.MDMKit'; 55import { Want } from '@kit.AbilityKit'; 56 57let wantTemp: Want = { 58 bundleName: 'com.example.myapplication', 59 abilityName: 'EntryAbility', 60}; 61 62deviceControl.resetFactory(wantTemp, (err) => { 63 if (err) { 64 console.error(`Failed to reset factory. Code is ${err.code}, message is ${err.message}`); 65 return; 66 } 67 console.log('Succeeded in resetting factory'); 68}) 69``` 70 71## deviceControl.resetFactory 72 73resetFactory(admin: Want): Promise\<void> 74 75Restores device factory settings through the specified device administrator application. This API uses a promise to return the result. 76 77**Required permissions**: ohos.permission.ENTERPRISE_RESET_DEVICE 78 79**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 80 81 82**Parameters** 83 84| Name | Type | Mandatory | Description | 85| ----- | ----------------------------------- | ---- | ------- | 86| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 87 88**Return value** 89 90| Type | Description | 91| ----- | ----------------------------------- | 92| Promise\<void> | Promise that returns no value. If the operation fails, an error object will be thrown.| 93 94**Error codes** 95 96For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 97 98| ID| Error Message | 99| ------- | ---------------------------------------------------------------------------- | 100| 9200001 | The application is not an administrator application of the device. | 101| 9200002 | The administrator application does not have permission to manage the device. | 102| 201 | Permission verification failed. The application does not have the permission required to call the API. | 103| 202 | Permission verification failed. A non-system application calls a system API. | 104| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 105 106**Example** 107 108```ts 109import { deviceControl } from '@kit.MDMKit'; 110import { Want } from '@kit.AbilityKit'; 111import { BusinessError } from '@kit.BasicServicesKit'; 112 113let wantTemp: Want = { 114 bundleName: 'com.example.myapplication', 115 abilityName: 'EntryAbility', 116}; 117 118deviceControl.resetFactory(wantTemp).then(() => { 119}).catch((err: BusinessError) => { 120 console.error(`Failed to reset factory. Code is ${err.code}, message is ${err.message}`); 121}) 122``` 123 124## deviceControl.shutdown<sup>11+</sup> 125 126shutdown(admin: Want): void 127 128Shuts down the device through the specified device administrator application. 129 130**Required permissions**: ohos.permission.ENTERPRISE_REBOOT 131 132**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 133 134 135**Parameters** 136 137| Name | Type | Mandatory | Description | 138| ----- | ----------------------------------- | ---- | ------- | 139| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 140 141**Error codes** 142 143For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 144 145| ID| Error Message | 146| ------- | ---------------------------------------------------------------------------- | 147| 9200001 | The application is not an administrator application of the device. | 148| 9200002 | The administrator application does not have permission to manage the device. | 149| 201 | Permission verification failed. The application does not have the permission required to call the API. | 150| 202 | Permission verification failed. A non-system application calls a system API. | 151| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 152 153**Example** 154 155```ts 156import { deviceControl } from '@kit.MDMKit'; 157import { Want } from '@kit.AbilityKit'; 158 159let wantTemp: Want = { 160 bundleName: 'com.example.myapplication', 161 abilityName: 'EntryAbility', 162}; 163 164try { 165 deviceControl.shutdown(wantTemp); 166} catch (err) { 167 console.error(`Failed to shutdown device. Code is ${err.code}, message is ${err.message}`); 168} 169``` 170 171## deviceControl.reboot<sup>11+</sup> 172 173reboot(admin: Want): void 174 175Reboots the device through the specified device administrator application. 176 177**Required permissions**: ohos.permission.ENTERPRISE_REBOOT 178 179**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 180 181 182**Parameters** 183 184| Name | Type | Mandatory | Description | 185| ----- | ----------------------------------- | ---- | ------- | 186| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 187 188**Error codes** 189 190For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 191 192| ID| Error Message | 193| ------- | ---------------------------------------------------------------------------- | 194| 9200001 | The application is not an administrator application of the device. | 195| 9200002 | The administrator application does not have permission to manage the device. | 196| 201 | Permission verification failed. The application does not have the permission required to call the API. | 197| 202 | Permission verification failed. A non-system application calls a system API. | 198| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 199 200**Example** 201 202```ts 203import { deviceControl } from '@kit.MDMKit'; 204import { Want } from '@kit.AbilityKit'; 205 206let wantTemp: Want = { 207 bundleName: 'com.example.myapplication', 208 abilityName: 'EntryAbility', 209}; 210 211try { 212 deviceControl.reboot(wantTemp); 213} catch (err) { 214 console.error(`Failed to reboot device. Code is ${err.code}, message is ${err.message}`); 215} 216``` 217 218## deviceControl.lockScreen<sup>11+</sup> 219 220lockScreen(admin: Want): void 221 222Locks the device screen through the specified device administrator application. 223 224**Required permissions**: ohos.permission.ENTERPRISE_LOCK_DEVICE 225 226**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 227 228 229**Parameters** 230 231| Name | Type | Mandatory | Description | 232| ----- | ----------------------------------- | ---- | ------- | 233| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 234 235**Error codes** 236 237For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 238 239| ID| Error Message | 240| ------- | ---------------------------------------------------------------------------- | 241| 9200001 | The application is not an administrator application of the device. | 242| 9200002 | The administrator application does not have permission to manage the device. | 243| 201 | Permission verification failed. The application does not have the permission required to call the API. | 244| 202 | Permission verification failed. A non-system application calls a system API. | 245| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 246 247**Example** 248 249```ts 250import { deviceControl } from '@kit.MDMKit'; 251import { Want } from '@kit.AbilityKit'; 252 253let wantTemp: Want = { 254 bundleName: 'com.example.myapplication', 255 abilityName: 'EntryAbility', 256}; 257 258try { 259 deviceControl.lockScreen(wantTemp); 260} catch (err) { 261 console.error(`Failed to lock screen. Code is ${err.code}, message is ${err.message}`); 262} 263``` 264