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