1e41f4b71Sopenharmony_ci# @ohos.enterprise.deviceSettings (Device Settings) (System API) 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 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 system APIs provided by the module. For details about its public APIs, see [@ohos.enterprise.deviceSettings](js-apis-enterprise-deviceSettings.md). 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci## Modules to Import 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci```ts 18e41f4b71Sopenharmony_ciimport { deviceSettings } from '@kit.MDMKit'; 19e41f4b71Sopenharmony_ci``` 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci## deviceSettings.setScreenOffTime<sup>11+</sup> 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_cisetScreenOffTime(admin: Want, time: number): void 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ciSets the device screen-off time through the specified device administrator application. This API returns the result synchronously. If the operation is successful, **null** is returned. If the operation fails, an exception will be thrown. 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_SET_SCREENOFF_TIME 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci**Parameters** 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 34e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ------------------------------- | 35e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 36e41f4b71Sopenharmony_ci| time | number | Yes | Screen-off time to set, in milliseconds. You are advised to set this parameter to the device's optional screen-off time. | 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci**Error codes** 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci| ID| Error Message | 43e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- | 44e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 45e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 46e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 47e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 48e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci**Example** 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci```ts 53e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 54e41f4b71Sopenharmony_cilet wantTemp: Want = { 55e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 56e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 57e41f4b71Sopenharmony_ci}; 58e41f4b71Sopenharmony_citry { 59e41f4b71Sopenharmony_ci deviceSettings.setScreenOffTime(wantTemp, 30000); 60e41f4b71Sopenharmony_ci console.info(`Succeeded in setting screen off time`); 61e41f4b71Sopenharmony_ci} catch(err) { 62e41f4b71Sopenharmony_ci console.error(`Failed to set screen off time. Code: ${err.code}, message: ${err.message}`); 63e41f4b71Sopenharmony_ci} 64e41f4b71Sopenharmony_ci``` 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ci## deviceSettings.getScreenOffTime 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_cigetScreenOffTime(admin: Want, callback: AsyncCallback<number>): void 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ciObtains the device screen-off time through the specified device administrator application. This API uses an asynchronous callback to return the result. 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_GET_SETTINGS 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci**Parameters** 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 79e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ------------------------------- | 80e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 81e41f4b71Sopenharmony_ci| callback | AsyncCallback<number> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the screen-off time in ms. If the operation fails, **err** is an error object. | 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci**Error codes** 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci| ID| Error Message | 88e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- | 89e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 90e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 91e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 92e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 93e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci**Example** 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ci```ts 98e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 99e41f4b71Sopenharmony_cilet wantTemp: Want = { 100e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 101e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 102e41f4b71Sopenharmony_ci}; 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_cideviceSettings.getScreenOffTime(wantTemp, (err, result) => { 105e41f4b71Sopenharmony_ci if (err) { 106e41f4b71Sopenharmony_ci console.error(`Failed to get screen off time. Code: ${err.code}, message: ${err.message}`); 107e41f4b71Sopenharmony_ci return; 108e41f4b71Sopenharmony_ci } 109e41f4b71Sopenharmony_ci console.info(`Succeeded in getting screen off time, result : ${result}`); 110e41f4b71Sopenharmony_ci}); 111e41f4b71Sopenharmony_ci``` 112e41f4b71Sopenharmony_ci 113e41f4b71Sopenharmony_ci## deviceSettings.getScreenOffTime 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_cigetScreenOffTime(admin: Want): Promise<number> 116e41f4b71Sopenharmony_ci 117e41f4b71Sopenharmony_ciObtains the device screen-off time through the specified device administrator application. This API uses a promise to return the result. 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_GET_SETTINGS 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ci**Parameters** 124e41f4b71Sopenharmony_ci 125e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 126e41f4b71Sopenharmony_ci| ----- | ----------------------------------- | ---- | ------- | 127e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ci**Return value** 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci| Type | Description | 132e41f4b71Sopenharmony_ci| --------------------- | ------------------------- | 133e41f4b71Sopenharmony_ci| Promise<number> | Promise used to return the screen-off time, in ms. | 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ci**Error codes** 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ci| ID| Error Message | 140e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- | 141e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 142e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 143e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 144e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 145e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_ci**Example** 148e41f4b71Sopenharmony_ci 149e41f4b71Sopenharmony_ci```ts 150e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 151e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 152e41f4b71Sopenharmony_cilet wantTemp: Want = { 153e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 154e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 155e41f4b71Sopenharmony_ci}; 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_cideviceSettings.getScreenOffTime(wantTemp).then((result) => { 158e41f4b71Sopenharmony_ci console.info(`Succeeded in getting screen off time, result : ${result}`); 159e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 160e41f4b71Sopenharmony_ci console.error(`Failed to get screen off time. Code: ${err.code}, message: ${err.message}`); 161e41f4b71Sopenharmony_ci}); 162e41f4b71Sopenharmony_ci``` 163e41f4b71Sopenharmony_ci 164e41f4b71Sopenharmony_ci## deviceSettings.installUserCertificate 165e41f4b71Sopenharmony_ci 166e41f4b71Sopenharmony_ciinstallUserCertificate(admin: Want, certificate: CertBlob, callback: AsyncCallback<string>): void 167e41f4b71Sopenharmony_ci 168e41f4b71Sopenharmony_ciInstalls a user certificate through the specified device administrator application. This API uses an asynchronous callback to return the result. 169e41f4b71Sopenharmony_ci 170e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_CERTIFICATE 171e41f4b71Sopenharmony_ci 172e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_ci**Parameters** 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 177e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ------------------------------- | 178e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 179e41f4b71Sopenharmony_ci| certificate | [CertBlob](#certblob) | Yes | Information about the certificate to install. | 180e41f4b71Sopenharmony_ci| callback | AsyncCallback<string> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 181e41f4b71Sopenharmony_ci 182e41f4b71Sopenharmony_ci**Error codes** 183e41f4b71Sopenharmony_ci 184e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_ci| ID| Error Message | 187e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- | 188e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 189e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 190e41f4b71Sopenharmony_ci| 9201001 | Failed to manage the certificate. | 191e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 192e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 193e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 194e41f4b71Sopenharmony_ci 195e41f4b71Sopenharmony_ci**Example** 196e41f4b71Sopenharmony_ci 197e41f4b71Sopenharmony_ci```ts 198e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 199e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 200e41f4b71Sopenharmony_cilet wantTemp: Want = { 201e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 202e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 203e41f4b71Sopenharmony_ci}; 204e41f4b71Sopenharmony_cilet certFileArray: Uint8Array = new Uint8Array(); 205e41f4b71Sopenharmony_ci// The variable context needs to be initialized in MainAbility's onCreate callback function 206e41f4b71Sopenharmony_ci// test.cer needs to be placed in the rawfile directory 207e41f4b71Sopenharmony_cigetContext().resourceManager.getRawFileContent("test.cer").then((value) => { 208e41f4b71Sopenharmony_ci certFileArray = value; 209e41f4b71Sopenharmony_ci deviceSettings.installUserCertificate(wantTemp, { inData: certFileArray, alias: "cert_alias_xts" }, (err, result) => { 210e41f4b71Sopenharmony_ci if (err) { 211e41f4b71Sopenharmony_ci console.error(`Failed to install user certificate. Code: ${err.code}, message: ${err.message}`); 212e41f4b71Sopenharmony_ci } else { 213e41f4b71Sopenharmony_ci console.info(`Succeeded in installing user certificate, result : ${JSON.stringify(result)}`); 214e41f4b71Sopenharmony_ci } 215e41f4b71Sopenharmony_ci }); 216e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 217e41f4b71Sopenharmony_ci console.error(`Failed to get row file content. message: ${error.message}`); 218e41f4b71Sopenharmony_ci return 219e41f4b71Sopenharmony_ci}); 220e41f4b71Sopenharmony_ci``` 221e41f4b71Sopenharmony_ci 222e41f4b71Sopenharmony_ci## deviceSettings.installUserCertificate 223e41f4b71Sopenharmony_ci 224e41f4b71Sopenharmony_ciinstallUserCertificate(admin: Want, certificate: CertBlob): Promise<string> 225e41f4b71Sopenharmony_ci 226e41f4b71Sopenharmony_ciInstalls a user certificate through the specified device administrator application. This API uses a promise to return the result. 227e41f4b71Sopenharmony_ci 228e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_CERTIFICATE 229e41f4b71Sopenharmony_ci 230e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 231e41f4b71Sopenharmony_ci 232e41f4b71Sopenharmony_ci**Parameters** 233e41f4b71Sopenharmony_ci 234e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 235e41f4b71Sopenharmony_ci| ----- | ----------------------------------- | ---- | ------- | 236e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 237e41f4b71Sopenharmony_ci| certificate | [CertBlob](#certblob) | Yes | Information about the certificate to install. | 238e41f4b71Sopenharmony_ci 239e41f4b71Sopenharmony_ci**Return value** 240e41f4b71Sopenharmony_ci 241e41f4b71Sopenharmony_ci| Type | Description | 242e41f4b71Sopenharmony_ci| --------------------- | ------------------------- | 243e41f4b71Sopenharmony_ci| Promise<string> | Promise used to return the URI of the installed certificate. This URI can be used to uninstall the certificate.| 244e41f4b71Sopenharmony_ci 245e41f4b71Sopenharmony_ci**Error codes** 246e41f4b71Sopenharmony_ci 247e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 248e41f4b71Sopenharmony_ci 249e41f4b71Sopenharmony_ci| ID| Error Message | 250e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- | 251e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 252e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 253e41f4b71Sopenharmony_ci| 9201001 | Failed to manage the certificate. | 254e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 255e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 256e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 257e41f4b71Sopenharmony_ci 258e41f4b71Sopenharmony_ci**Example** 259e41f4b71Sopenharmony_ci 260e41f4b71Sopenharmony_ci```ts 261e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 262e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 263e41f4b71Sopenharmony_cilet wantTemp: Want = { 264e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 265e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 266e41f4b71Sopenharmony_ci}; 267e41f4b71Sopenharmony_cilet certFileArray: Uint8Array = new Uint8Array(); 268e41f4b71Sopenharmony_ci// The variable context needs to be initialized in MainAbility's onCreate callback function 269e41f4b71Sopenharmony_ci// test.cer needs to be placed in the rawfile directory 270e41f4b71Sopenharmony_cigetContext().resourceManager.getRawFileContent("test.cer").then((value) => { 271e41f4b71Sopenharmony_ci certFileArray = value 272e41f4b71Sopenharmony_ci deviceSettings.installUserCertificate(wantTemp, { inData: certFileArray, alias: "cert_alias_xts" }) 273e41f4b71Sopenharmony_ci .then((result) => { 274e41f4b71Sopenharmony_ci console.info(`Succeeded in installing user certificate, result : ${JSON.stringify(result)}`); 275e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 276e41f4b71Sopenharmony_ci console.error(`Failed to install user certificate. Code: ${err.code}, message: ${err.message}`); 277e41f4b71Sopenharmony_ci }) 278e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 279e41f4b71Sopenharmony_ci console.error(`Failed to get row file content. message: ${error.message}`); 280e41f4b71Sopenharmony_ci return 281e41f4b71Sopenharmony_ci}); 282e41f4b71Sopenharmony_ci``` 283e41f4b71Sopenharmony_ci 284e41f4b71Sopenharmony_ci## CertBlob 285e41f4b71Sopenharmony_ci 286e41f4b71Sopenharmony_ciRepresents the certificate information. 287e41f4b71Sopenharmony_ci 288e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 289e41f4b71Sopenharmony_ci 290e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 291e41f4b71Sopenharmony_ci| ----------- | --------| ----- | ------------------------------- | 292e41f4b71Sopenharmony_ci| inData | Uint8Array | Yes| Binary content of the certificate.| 293e41f4b71Sopenharmony_ci| alias | string | Yes| Certificate alias.| 294e41f4b71Sopenharmony_ci 295e41f4b71Sopenharmony_ci## deviceSettings.uninstallUserCertificate 296e41f4b71Sopenharmony_ci 297e41f4b71Sopenharmony_ciuninstallUserCertificate(admin: Want, certUri: string, callback: AsyncCallback<void>): void 298e41f4b71Sopenharmony_ci 299e41f4b71Sopenharmony_ciUninstalls a user certificate through the specified device administrator application. This API uses an asynchronous callback to return the result. 300e41f4b71Sopenharmony_ci 301e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_CERTIFICATE 302e41f4b71Sopenharmony_ci 303e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 304e41f4b71Sopenharmony_ci 305e41f4b71Sopenharmony_ci**Parameters** 306e41f4b71Sopenharmony_ci 307e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 308e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ------------------------------- | 309e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 310e41f4b71Sopenharmony_ci| certUri | string | Yes | Certificate URI, which is returned by **installUserCertificate()**. | 311e41f4b71Sopenharmony_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. | 312e41f4b71Sopenharmony_ci 313e41f4b71Sopenharmony_ci**Error codes** 314e41f4b71Sopenharmony_ci 315e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 316e41f4b71Sopenharmony_ci 317e41f4b71Sopenharmony_ci| ID| Error Message | 318e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- | 319e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 320e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 321e41f4b71Sopenharmony_ci| 9201001 | Failed to manage the certificate. | 322e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 323e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 324e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 325e41f4b71Sopenharmony_ci 326e41f4b71Sopenharmony_ci**Example** 327e41f4b71Sopenharmony_ci 328e41f4b71Sopenharmony_ci```ts 329e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 330e41f4b71Sopenharmony_cilet wantTemp: Want = { 331e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 332e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 333e41f4b71Sopenharmony_ci}; 334e41f4b71Sopenharmony_cilet aliasStr = "certName" 335e41f4b71Sopenharmony_cideviceSettings.uninstallUserCertificate(wantTemp, aliasStr, (err) => { 336e41f4b71Sopenharmony_ci if (err) { 337e41f4b71Sopenharmony_ci console.error(`Failed to uninstall user certificate. Code: ${err.code}, message: ${err.message}`); 338e41f4b71Sopenharmony_ci return; 339e41f4b71Sopenharmony_ci } 340e41f4b71Sopenharmony_ci console.info(`Succeeded in uninstalling user certificate`); 341e41f4b71Sopenharmony_ci}); 342e41f4b71Sopenharmony_ci``` 343e41f4b71Sopenharmony_ci 344e41f4b71Sopenharmony_ci## deviceSettings.uninstallUserCertificate 345e41f4b71Sopenharmony_ci 346e41f4b71Sopenharmony_ciuninstallUserCertificate(admin: Want, certUri: string): Promise<void> 347e41f4b71Sopenharmony_ci 348e41f4b71Sopenharmony_ciUninstalls a user certificate through the specified device administrator application. This API uses a promise to return the result. 349e41f4b71Sopenharmony_ci 350e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_CERTIFICATE 351e41f4b71Sopenharmony_ci 352e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 353e41f4b71Sopenharmony_ci 354e41f4b71Sopenharmony_ci**Parameters** 355e41f4b71Sopenharmony_ci 356e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 357e41f4b71Sopenharmony_ci| ----- | ----------------------------------- | ---- | ------- | 358e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 359e41f4b71Sopenharmony_ci| certUri | string | Yes | Certificate URI, which is returned by **installUserCertificate()**. | 360e41f4b71Sopenharmony_ci 361e41f4b71Sopenharmony_ci**Return value** 362e41f4b71Sopenharmony_ci 363e41f4b71Sopenharmony_ci| Type | Description | 364e41f4b71Sopenharmony_ci| --------------------- | ------------------------- | 365e41f4b71Sopenharmony_ci| Promise<void> | Promise that returns no value. An error object will be thrown if the operation fails.| 366e41f4b71Sopenharmony_ci 367e41f4b71Sopenharmony_ci**Error codes** 368e41f4b71Sopenharmony_ci 369e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 370e41f4b71Sopenharmony_ci 371e41f4b71Sopenharmony_ci| ID| Error Message | 372e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- | 373e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 374e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 375e41f4b71Sopenharmony_ci| 9201001 | Failed to manage the certificate. | 376e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 377e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 378e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 379e41f4b71Sopenharmony_ci 380e41f4b71Sopenharmony_ci**Example** 381e41f4b71Sopenharmony_ci 382e41f4b71Sopenharmony_ci```ts 383e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 384e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 385e41f4b71Sopenharmony_cilet wantTemp: Want = { 386e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 387e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 388e41f4b71Sopenharmony_ci}; 389e41f4b71Sopenharmony_cilet aliasStr = "certName" 390e41f4b71Sopenharmony_cideviceSettings.uninstallUserCertificate(wantTemp, aliasStr).then(() => { 391e41f4b71Sopenharmony_ci console.info(`Succeeded in uninstalling user certificate`); 392e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 393e41f4b71Sopenharmony_ci console.error(`Failed to uninstall user certificate. Code is ${err.code}, message is ${err.message}`); 394e41f4b71Sopenharmony_ci}); 395e41f4b71Sopenharmony_ci``` 396e41f4b71Sopenharmony_ci 397e41f4b71Sopenharmony_ci## deviceSettings.setPowerPolicy<sup>11+</sup> 398e41f4b71Sopenharmony_ci 399e41f4b71Sopenharmony_cisetPowerPolicy(admin: Want, powerScene: PowerScene, powerPolicy: PowerPolicy): void 400e41f4b71Sopenharmony_ci 401e41f4b71Sopenharmony_ciSets the device power policy through the specified device administrator application. This API returns the result synchronously. If the operation is successful, **null** is returned. If the operation fails, an exception will be thrown. 402e41f4b71Sopenharmony_ci 403e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_SETTINGS 404e41f4b71Sopenharmony_ci 405e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 406e41f4b71Sopenharmony_ci 407e41f4b71Sopenharmony_ci**Parameters** 408e41f4b71Sopenharmony_ci 409e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 410e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ------------------------------- | 411e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 412e41f4b71Sopenharmony_ci| powerScene | [PowerScene](#powerscene11) | Yes | Scenario to which the power policy applies. Currently, only the timeout scenario is supported. | 413e41f4b71Sopenharmony_ci| powerPolicy | [PowerPolicy](#powerpolicy11) | Yes | Power policy to set. | 414e41f4b71Sopenharmony_ci 415e41f4b71Sopenharmony_ci**Error codes** 416e41f4b71Sopenharmony_ci 417e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 418e41f4b71Sopenharmony_ci 419e41f4b71Sopenharmony_ci| ID| Error Message | 420e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- | 421e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 422e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 423e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 424e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 425e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 426e41f4b71Sopenharmony_ci 427e41f4b71Sopenharmony_ci**Example** 428e41f4b71Sopenharmony_ci 429e41f4b71Sopenharmony_ci```ts 430e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 431e41f4b71Sopenharmony_cilet wantTemp: Want = { 432e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 433e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 434e41f4b71Sopenharmony_ci}; 435e41f4b71Sopenharmony_citry { 436e41f4b71Sopenharmony_ci let delayTime = 0; 437e41f4b71Sopenharmony_ci let powerScene: deviceSettings.PowerScene = deviceSettings.PowerScene.TIME_OUT; 438e41f4b71Sopenharmony_ci let powerPolicyAction: deviceSettings.PowerPolicyAction = deviceSettings.PowerPolicyAction.AUTO_SUSPEND; 439e41f4b71Sopenharmony_ci let powerPolicy: deviceSettings.PowerPolicy = {powerPolicyAction, delayTime}; 440e41f4b71Sopenharmony_ci deviceSettings.setPowerPolicy(wantTemp, powerScene, powerPolicy); 441e41f4b71Sopenharmony_ci console.info(`Succeeded in setting power polilcy`); 442e41f4b71Sopenharmony_ci} catch (err) { 443e41f4b71Sopenharmony_ci console.error(`Failed to set power policy. Code: ${err.code}, message: ${err.message}`); 444e41f4b71Sopenharmony_ci} 445e41f4b71Sopenharmony_ci``` 446e41f4b71Sopenharmony_ci 447e41f4b71Sopenharmony_ci## deviceSettings.getPowerPolicy<sup>11+</sup> 448e41f4b71Sopenharmony_ci 449e41f4b71Sopenharmony_cigetPowerPolicy(admin: Want, powerScene: PowerScene): PowerPolicy 450e41f4b71Sopenharmony_ci 451e41f4b71Sopenharmony_ciObtains the device power policy through the specified device administrator application. This API returns the result synchronously. If the operation is successful, the power policy obtained is returned. If the operation fails, an exception will be thrown. 452e41f4b71Sopenharmony_ci 453e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_SETTINGS 454e41f4b71Sopenharmony_ci 455e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 456e41f4b71Sopenharmony_ci 457e41f4b71Sopenharmony_ci**Parameters** 458e41f4b71Sopenharmony_ci 459e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 460e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ------------------------------- | 461e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 462e41f4b71Sopenharmony_ci| powerScene | [PowerScene](#powerscene11) | Yes | Scenario to which the power policy applies. Currently, only the timeout scenario is supported. | 463e41f4b71Sopenharmony_ci 464e41f4b71Sopenharmony_ci**Return value** 465e41f4b71Sopenharmony_ci 466e41f4b71Sopenharmony_ci| Type | Description | Description | 467e41f4b71Sopenharmony_ci| ----- | ----------------------------------- |------------------------------- | 468e41f4b71Sopenharmony_ci| PowerPolicy | [PowerPolicy](#powerpolicy11) | Power policy obtained. | 469e41f4b71Sopenharmony_ci 470e41f4b71Sopenharmony_ci**Error codes** 471e41f4b71Sopenharmony_ci 472e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 473e41f4b71Sopenharmony_ci 474e41f4b71Sopenharmony_ci| ID| Error Message | 475e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- | 476e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 477e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 478e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 479e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 480e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 481e41f4b71Sopenharmony_ci 482e41f4b71Sopenharmony_ci**Example** 483e41f4b71Sopenharmony_ci 484e41f4b71Sopenharmony_ci```ts 485e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 486e41f4b71Sopenharmony_cilet wantTemp: Want = { 487e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 488e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 489e41f4b71Sopenharmony_ci}; 490e41f4b71Sopenharmony_citry { 491e41f4b71Sopenharmony_ci let powerScene: deviceSettings.PowerScene = deviceSettings.PowerScene.TIME_OUT; 492e41f4b71Sopenharmony_ci let powerPolicy: deviceSettings.PowerPolicy = deviceSettings.getPowerPolicy(wantTemp, powerScene); 493e41f4b71Sopenharmony_ci console.info(`Succeeded in getting power polilcy ${JSON.stringify(powerPolicy)}`); 494e41f4b71Sopenharmony_ci} catch (err) { 495e41f4b71Sopenharmony_ci console.error(`Failed to get power policy. Code: ${err.code}, message: ${err.message}`); 496e41f4b71Sopenharmony_ci} 497e41f4b71Sopenharmony_ci``` 498e41f4b71Sopenharmony_ci 499e41f4b71Sopenharmony_ci## PowerPolicy<sup>11+</sup> 500e41f4b71Sopenharmony_ci 501e41f4b71Sopenharmony_ciRepresents the power policy. 502e41f4b71Sopenharmony_ci 503e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 504e41f4b71Sopenharmony_ci 505e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 506e41f4b71Sopenharmony_ci| ----------- | --------| ----- | ------------------------------- | 507e41f4b71Sopenharmony_ci| powerPolicyAction | [PowerPolicyAction](#powerpolicyaction11) | Yes| Action to apply the power policy.| 508e41f4b71Sopenharmony_ci| delayTime | number | Yes| Delay time allowed.| 509e41f4b71Sopenharmony_ci 510e41f4b71Sopenharmony_ci## PowerScene<sup>11+</sup> 511e41f4b71Sopenharmony_ci 512e41f4b71Sopenharmony_ciDefines the scenario to which the power policy applies. 513e41f4b71Sopenharmony_ci 514e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 515e41f4b71Sopenharmony_ci 516e41f4b71Sopenharmony_ci| Name| Value| Description| 517e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 518e41f4b71Sopenharmony_ci| TIME_OUT | 0 | Timeout scenario.| 519e41f4b71Sopenharmony_ci 520e41f4b71Sopenharmony_ci## PowerPolicyAction<sup>11+</sup> 521e41f4b71Sopenharmony_ci 522e41f4b71Sopenharmony_ciEnumerates the actions that can be performed to apply the power policy. 523e41f4b71Sopenharmony_ci 524e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 525e41f4b71Sopenharmony_ci 526e41f4b71Sopenharmony_ci| Name| Value| Description| 527e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 528e41f4b71Sopenharmony_ci| NONE | 0 | No action is performed.| 529e41f4b71Sopenharmony_ci| AUTO_SUSPEND | 1 | Automatically enter the sleep mode.| 530e41f4b71Sopenharmony_ci| FORCE_SUSPEND | 2 | Forcibly enter the sleep mode.| 531e41f4b71Sopenharmony_ci| HIBERNATE | 3 | Enter the hibernation state. Currently, the power subsystem does not support this action.| 532e41f4b71Sopenharmony_ci| SHUTDOWN | 4 | Shut down the system.| 533