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