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