1# @ohos.enterprise.deviceControl (Device Control) 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.md#adminmanagerenableadmin). 12 13## Modules to Import 14 15```ts 16import deviceControl from '@ohos.enterprise.deviceControl'; 17``` 18 19## deviceControl.resetFactory 20 21resetFactory(admin: Want, callback: AsyncCallback\<void>): void 22 23Restores device factory settings through the specified device administrator application. This API uses an asynchronous callback to return the result. 24 25**Required permissions**: ohos.permission.ENTERPRISE_RESET_DEVICE 26 27**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 28 29**System API**: This is a system API. 30 31**Parameters** 32 33| Name | Type | Mandatory | Description | 34| ----- | ----------------------------------- | ---- | ------- | 35| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 36| callback | AsyncCallback\<void> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 37 38**Error codes** 39 40For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 41 42| ID| Error Message | 43| ------- | ---------------------------------------------------------------------------- | 44| 9200001 | the application is not an administrator of the device. | 45| 9200002 | the administrator application does not have permission to manage the device. | 46 47**Example** 48 49```ts 50import Want from '@ohos.app.ability.Want'; 51let wantTemp: Want = { 52 bundleName: 'bundleName', 53 abilityName: 'abilityName', 54}; 55 56deviceControl.resetFactory(wantTemp, (err) => { 57 if (err) { 58 console.error(`Failed to reset factory. Code is ${err.code}, message is ${err.message}`); 59 return; 60 } 61 console.log('Succeeded in resetting factory'); 62}) 63``` 64 65## deviceControl.resetFactory 66 67resetFactory(admin: Want): Promise\<void> 68 69Restores device factory settings through the specified device administrator application. This API uses a promise to return the result. 70 71**Required permissions**: ohos.permission.ENTERPRISE_RESET_DEVICE 72 73**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 74 75**System API**: This is a system API. 76 77**Parameters** 78 79| Name | Type | Mandatory | Description | 80| ----- | ----------------------------------- | ---- | ------- | 81| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 82 83**Return value** 84 85| Type | Description | 86| ----- | ----------------------------------- | 87| Promise\<void> | Promise that returns no value. If the operation fails, an error object will be thrown.| 88 89**Error codes** 90 91For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 92 93| ID| Error Message | 94| ------- | ---------------------------------------------------------------------------- | 95| 9200001 | the application is not an administrator of the device. | 96| 9200002 | the administrator application does not have permission to manage the device. | 97 98**Example** 99 100```ts 101import Want from '@ohos.app.ability.Want'; 102import { BusinessError } from '@ohos.base'; 103let wantTemp: Want = { 104 bundleName: 'bundleName', 105 abilityName: 'abilityName', 106}; 107 108deviceControl.resetFactory(wantTemp).then(() => { 109}).catch((err: BusinessError) => { 110 console.error(`Failed to reset factory. Code is ${err.code}, message is ${err.message}`); 111}) 112``` 113