# @ohos.enterprise.deviceSettings (Device Settings Management) The **deviceSettings** module provides APIs for setting enterprise devices, including obtaining the screen-off time of a device. > **NOTE** > > 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. > > The APIs of this module can be used only in the stage model. > > 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). ## Modules to Import ```js import deviceSettings from '@ohos.enterprise.deviceSettings'; ``` ## deviceSettings.getScreenOffTime getScreenOffTime(admin: Want, callback: AsyncCallback<number>): void Obtains the device screen-off time through the specified device administrator application. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.ENTERPRISE_GET_SETTINGS **System capability**: SystemCapability.Customization.EnterpriseDeviceManager **System API**: This is a system API. **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | ------------------------------- | | admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. | | callback | AsyncCallback<number> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the device screen-off time obtained. Otherwise, **err** is an error object. | **Error codes** For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). | ID| Error Message | | ------- | ---------------------------------------------------------------------------- | | 9200001 | the application is not an administrator of the device. | | 9200002 | the administrator application does not have permission to manage the device. | **Example** ```js let wantTemp = { bundleName: 'com.example.myapplication', abilityName: 'EntryAbility', }; deviceSettings.getScreenOffTime(wantTemp, (err, result) => { if (err) { console.error(`Failed to get screen off time. Code: ${err.code}, message: ${err.message}`); return; } console.info(`Succeeded in getting screen off time, result : ${result}`); }); ``` ## deviceSettings.getScreenOffTime getScreenOffTime(admin: Want): Promise<number> Obtains the device screen-off time through the specified device administrator application. This API uses a promise to return the result. **Required permissions**: ohos.permission.ENTERPRISE_GET_SETTINGS **System capability**: SystemCapability.Customization.EnterpriseDeviceManager **System API**: This is a system API. **Parameters** | Name | Type | Mandatory | Description | | ----- | ----------------------------------- | ---- | ------- | | admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| **Return value** | Type | Description | | --------------------- | ------------------------- | | Promise<number> | Promise used to return the device screen-off time. | **Error codes** For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). | ID| Error Message | | ------- | ---------------------------------------------------------------------------- | | 9200001 | the application is not an administrator of the device. | | 9200002 | the administrator application does not have permission to manage the device. | **Example** ```js let wantTemp = { bundleName: 'com.example.myapplication', abilityName: 'EntryAbility', }; deviceSettings.getScreenOffTime(wantTemp).then((result) => { console.info(`Succeeded in getting screen off time, result : ${result}`); }).catch((err) => { console.error(`Failed to get screen off time. Code: ${err.code}, message: ${err.message}`); }); ``` ## deviceSettings.installUserCertificate installUserCertificate(admin: Want, certificate: CertBlob, callback: AsyncCallback<string>): void Installs a user certificate through the specified device administrator application. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.ENTERPRISE_MANAGE_CERTIFICATE **System capability**: SystemCapability.Customization.EnterpriseDeviceManager **System API**: This is a system API. **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | ------------------------------- | | admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. | | certificate | [CertBlob](#certblob) | Yes | Information about the certificate to install. | | callback | AsyncCallback<string> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | **Error codes** For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). | ID| Error Message | | ------- | ---------------------------------------------------------------------------- | | 9200001 | the application is not an administrator of the device. | | 9200002 | the administrator application does not have permission to manage the device. | | 9201001 | manage certificate failed | **Example** ```js let wantTemp = { bundleName: 'com.example.myapplication', abilityName: 'EntryAbility', }; var certFileArray: Uint8Array; // The variable context needs to be initialized in MainAbility's onCreate callback function // test.cer needs to be placed in the rawfile directory await globalThis.context.resourceManager.getRawFileContent("test.cer") .then(value => { certFileArray = value }) .catch(error => { console.error(`Failed to get row file content. message: ${error.message}`); return }); new Promise((resolve, reject) => { deviceSettings.installUserCertificate(wantTemp, {inData: certFileArray, alias: "cert_alias_xts"}, (err, result) => { if (err) { console.error(`Failed to install user certificate. Code: ${err.code}, message: ${err.message}`); } else{ console.info(`Succeeded in installing user certificate, result : ${JSON.stringify(result)}`); } }); }); ``` ## deviceSettings.installUserCertificate installUserCertificate(admin: Want, certificate: CertBlob): Promise<string> Installs a user certificate through the specified device administrator application. This API uses a promise to return the result. **Required permissions**: ohos.permission.ENTERPRISE_MANAGE_CERTIFICATE **System capability**: SystemCapability.Customization.EnterpriseDeviceManager **System API**: This is a system API. **Parameters** | Name | Type | Mandatory | Description | | ----- | ----------------------------------- | ---- | ------- | | admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| | certificate | [CertBlob](#certblob) | Yes | Information about the certificate to install. | **Return value** | Type | Description | | --------------------- | ------------------------- | | Promise<string> | Promise used to return the URI of the installed certificate. This URI can be used to uninstall the certificate.| **Error codes** For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). | ID| Error Message | | ------- | ---------------------------------------------------------------------------- | | 9200001 | the application is not an administrator of the device. | | 9200002 | the administrator application does not have permission to manage the device. | | 9201001 | manage certificate failed | **Example** ```js let wantTemp = { bundleName: 'com.example.myapplication', abilityName: 'EntryAbility', }; var certFileArray: Uint8Array // The variable context needs to be initialized in MainAbility's onCreate callback function // test.cer needs to be placed in the rawfile directory await globalThis.context.resourceManager.getRawFileContent("test.cer") .then(data => { certFileArray = data }).catch(error => { console.log('getRawFileContent error' + error) return }) deviceSettings.installUserCertificate(wantTemp, { inData: certFileArray, alias: "cert_alias_xts" }) .then((result) => { console.info(`Succeeded in installing user certificate, result : ${JSON.stringify(result)}`); }).catch(err => { console.error(`Failed to install user certificate. Code: ${err.code}, message: ${err.message}`); }) ``` ## CertBlob Represents the certificate information. **System capability**: SystemCapability.Customization.EnterpriseDeviceManager **System API**: This is a system API. | Name | Type | Mandatory| Description | | ----------- | --------| ----- | ------------------------------- | | inData | Uint8Array | Yes| Binary content of the certificate.| | alias | string | Yes| Certificate alias.| ## deviceSettings.uninstallUserCertificate uninstallUserCertificate(admin: Want, certUri: string, callback: AsyncCallback<void>): void Uninstalls a user certificate through the specified device administrator application. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.ENTERPRISE_MANAGE_CERTIFICATE **System capability**: SystemCapability.Customization.EnterpriseDeviceManager **System API**: This is a system API. **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | ------------------------------- | | admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. | | certUri | string | Yes | Certificate URI, which is returned by **installUserCertificate()**. | | callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | **Error codes** For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). | ID| Error Message | | ------- | ---------------------------------------------------------------------------- | | 9200001 | the application is not an administrator of the device. | | 9200002 | the administrator application does not have permission to manage the device. | | 9201001 | manage certificate failed | **Example** ```js let wantTemp = { bundleName: 'com.example.myapplication', abilityName: 'EntryAbility', }; let aliasStr = "certName" deviceSettings.uninstallUserCertificate(wantTemp, aliasStr, (err) => { if (err) { console.error(`Failed to uninstall user certificate. Code: ${err.code}, message: ${err.message}`); return; } console.info(`Succeeded in uninstalling user certificate`); }); ``` ## deviceSettings.uninstallUserCertificate uninstallUserCertificate(admin: Want, certUri: string): Promise<void> Uninstalls a user certificate through the specified device administrator application. This API uses a promise to return the result. **Required permissions**: ohos.permission.ENTERPRISE_MANAGE_CERTIFICATE **System capability**: SystemCapability.Customization.EnterpriseDeviceManager **System API**: This is a system API. **Parameters** | Name | Type | Mandatory | Description | | ----- | ----------------------------------- | ---- | ------- | | admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| | certUri | string | Yes | Certificate URI, which is returned by **installUserCertificate()**. | **Return value** | Type | Description | | --------------------- | ------------------------- | | Promise<void> | Promise that returns no value. An error object will be thrown if the operation fails.| **Error codes** For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). | ID| Error Message | | ------- | ---------------------------------------------------------------------------- | | 9200001 | the application is not an administrator of the device. | | 9200002 | the administrator application does not have permission to manage the device. | | 9201001 | manage certificate failed | **Example** ```js let wantTemp = { bundleName: 'com.example.myapplication', abilityName: 'EntryAbility', }; let aliasStr = "certName" deviceSettings.uninstallUserCertificate(wantTemp, aliasStr).then(() => { console.info(`Succeeded in uninstalling user certificate`); }).catch((err) => { console.error(`Failed to uninstall user certificate. Code is ${err.code}, message is ${err.message}`); }); ```