1e41f4b71Sopenharmony_ci# @ohos.enterprise.deviceSettings (Device Settings) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **deviceSettings** module provides APIs for setting enterprise devices, including obtaining the screen-off time of a device. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 12. 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. 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci## Modules to Import 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci```ts 16e41f4b71Sopenharmony_ciimport { deviceSettings } from '@kit.MDMKit'; 17e41f4b71Sopenharmony_ci``` 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci## deviceSettings.setValue 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_cisetValue(admin: Want, item: string, value: string): void 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ciSets a device setting policy. 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_SETTINGS 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci**Parameters** 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 32e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 33e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 34e41f4b71Sopenharmony_ci| item | string | Yes | Type of the device setting policy to set.<br>- **screenOff**: device screen-off policy.<br>- **dateTime**: system time settings.<br>- **powerPolicy**: power policy of the device.| 35e41f4b71Sopenharmony_ci| value | string | Yes | Policy to set.<br>If **item** is **screenOff**, value is the screen-off time in ms.<br>If **item** is **dateTime**, **value** is the system time to be set in ms.<br>If **item** is **powerPolicy**, **value** is a JSON string in the {"delayTime":xx,"powerPolicyAction":xx} format. **delayTime** indicates the delay time in ms, and **powerPolicyAction** indicates the sleep policy.<br>The sleep policy can be any of the following:<br>- **0**: No action is performed.<br>- **1**: enter sleep mode automatically.<br>- **2**: forcibly enter sleep mode.<br>- **3**: enter sleep mode (not supported by the power subsystem currently)<br>- **4**: power off.| 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci**Error codes** 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci| ID| Error Message | 42e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 43e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 44e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 45e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 46e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ci**Example** 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci```ts 51e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 52e41f4b71Sopenharmony_cilet wantTemp: Want = { 53e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 54e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 55e41f4b71Sopenharmony_ci}; 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_citry { 58e41f4b71Sopenharmony_ci deviceSettings.setValue(wantTemp, 'screenOff', '3000'); 59e41f4b71Sopenharmony_ci console.info(`Succeeded in setting screen off time.`); 60e41f4b71Sopenharmony_ci} catch (err) { 61e41f4b71Sopenharmony_ci console.error(`Failed to set screen off time. Code: ${err.code}, message: ${err.message}`); 62e41f4b71Sopenharmony_ci} 63e41f4b71Sopenharmony_ci``` 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ci## deviceSettings.getValue 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_cigetValue(admin: Want, item: string): string 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ciObtains a device setting policy. 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_SETTINGS 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ci**Parameters** 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 78e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 79e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 80e41f4b71Sopenharmony_ci| item | string | Yes | Type of the device setting policy to obtain.<br>- **screenOff**: device screen-off policy.<br>- **dateTime**: system time settings.<br>- **powerPolicy**: power policy of the device.| 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ci**Return value** 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci| Type | Description | 85e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | 86e41f4b71Sopenharmony_ci| string | Policy obtained.<br>If **item** is **screenOff**, the screen-off time (in ms) is returned.<br>If **item** is **dateTime**, the system time (in ms) is returned.<br>If **item** is **powerPolicy**, a JSON string in the {"delayTime":xx,"powerPolicyAction":xx} format is returned. **delayTime** indicates the delay time in ms, and **powerPolicyAction** indicates the sleep policy.<br>The sleep policy can be any of the following:<br>- **0**: No action is performed.<br>- **1**: enter sleep mode automatically.<br>- **2**: forcibly enter sleep mode.<br>- **3**: enter sleep mode (not supported by the power subsystem currently).<br>- **4**: power off.| 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_ci**Error codes** 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci| ID| Error Message | 93e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 94e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 95e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 96e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 97e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ci**Example** 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci```ts 102e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 103e41f4b71Sopenharmony_cilet wantTemp: Want = { 104e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 105e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 106e41f4b71Sopenharmony_ci}; 107e41f4b71Sopenharmony_ci 108e41f4b71Sopenharmony_citry { 109e41f4b71Sopenharmony_ci let result: string = deviceSettings.getValue(wantTemp, 'screenOff'); 110e41f4b71Sopenharmony_ci console.info(`Succeeded in getting screen off time, result : ${result}`); 111e41f4b71Sopenharmony_ci} catch (err) { 112e41f4b71Sopenharmony_ci console.error(`Failed to get screen off time. Code: ${err.code}, message: ${err.message}`); 113e41f4b71Sopenharmony_ci} 114e41f4b71Sopenharmony_ci``` 115