harmony(鸿蒙)Configuration Policy

  • 2022-08-09
  • 浏览 (654)

Configuration Policy

The configuration policy provides the capability of obtaining the custom configuration directory and file path based on the predefined custom configuration level.

NOTE

The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.

The APIs of this module are system APIs and cannot be called by third-party applications.

Modules to Import

import configPolicy from '@ohos.configPolicy';

getOneCfgFile

getOneCfgFile(relPath: string, callback: AsyncCallback<string>)

Obtains the path of a configuration file with the specified name and highest priority. This API uses an asynchronous callback to return the result. For example, if the config.xml file is stored in /system/etc/config.xml and /sys_pod/etc/config.xml (in ascending order of priority), then /sys_pod/etc/config.xml is returned.

System capability: SystemCapability.Customization.ConfigPolicy

Parameters |Name |Type |Mandatory|Description | |——–|—————————|—-|———————| |relPath|string |Yes |Name of the configuration file. | |callback|AsyncCallback<string>|Yes |Callback used to return the path of the configuration file.|

Example

  configPolicy.getOneCfgFile('etc/config.xml', (error, value) => {
      if (error == undefined) {
          console.log("value is " + value);
      } else {
          console.log("error occurs "+ error);
      }
  });

getOneCfgFile

getOneCfgFile(relPath: string): Promise<string>

Obtains the path of a configuration file with the specified name and highest priority. This API uses a promise to return the result.

System capability: SystemCapability.Customization.ConfigPolicy

Parameters |Name |Type |Mandatory|Description | |——-|——|—-|—–| |relPath|string|Yes |Name of the configuration file.|

Return value |Type |Description | |———————|————| |Promise<string>|Promise used to return the path of the configuration file.|

Example

  configPolicy.getOneCfgFile('etc/config.xml').then(value => {
      console.log("value is " + value);
  }).catch(error => {
      console.log("getOneCfgFile promise " + error);
  });

getCfgFiles

getCfgFiles(relPath: string, callback: AsyncCallback<Array<string>>)

Obtains all configuration files with the specified name and lists them in ascending order of priority. This API uses an asynchronous callback to return the result. For example, if the config.xml file is stored in /system/etc/config.xml and /sys_pod/etc/config.xml, then /system/etc/config.xml, /sys_pod/etc/config.xml is returned.

System capability: SystemCapability.Customization.ConfigPolicy

Parameters |Name |Type |Mandatory|Description | |——–|—————————————-|—-|————-| |relPath|string |Yes |Name of the configuration file. | |callback|AsyncCallback<Array<string>>|Yes |Callback used to return the file list.|

Example

  configPolicy.getCfgFiles('etc/config.xml', (error, value) => {
      if (error == undefined) {
          console.log("value is " + value);
      } else {
          console.log("error occurs "+ error);
      }
  });

getCfgFiles

getCfgFiles(relPath: string): Promise<Array<string>>

Obtains all configuration files with the specified name and lists them in ascending order of priority. This API uses a promise to return the result.

System capability: SystemCapability.Customization.ConfigPolicy

Parameters |Name |Type |Mandatory|Description | |——-|——|—-|—–| |relPath|string|Yes |Name of the configuration file.|

Return value |Type |Description| |———————————-|—-| |Promise<Array<string>>|Promise used to return the file list.|

Example

  configPolicy.getCfgFiles('etc/config.xml').then(value => {
      console.log("value is " + value);
  }).catch(error => {
      console.log("getCfgFiles promise " + error);
  });

getCfgDirList

getCfgDirList(callback: AsyncCallback<Array<string>>)

Obtains the configuration level directory list. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Customization.ConfigPolicy

Parameters |Name |Type |Mandatory|Description | |——–|—————————————-|—-|—————–| |callback|AsyncCallback<Array<string>>|Yes |Callback used to return the configuration level directory list.|

Example

  configPolicy.getCfgDirList((error, value) => {
      if (error == undefined) {
          console.log("value is " + value);
      } else {
          console.log("error occurs "+ error);
      }
  });

getCfgDirList

getCfgDirList(): Promise<Array<string>>

Obtains the configuration level directory list. This API uses a promise to return the result.

System capability: SystemCapability.Customization.ConfigPolicy

Return value |Type |Description | |———————————-|——–| |Promise<Array<string>>|Promise used to return the configuration level directory list.|

Example

  configPolicy.getCfgDirList().then(value => {
      console.log("value is " + value);
  }).catch(error => {
      console.log("getCfgDirList promise " + error);
  });

你可能感兴趣的鸿蒙文章

harmony(鸿蒙)APIs

harmony(鸿蒙)API Reference Document Description

harmony(鸿蒙)BundleStatusCallback

harmony(鸿蒙)innerBundleManager

harmony(鸿蒙)distributedBundle

harmony(鸿蒙)Bundle

harmony(鸿蒙)Context

harmony(鸿蒙)DataUriUtils

harmony(鸿蒙)EnterpriseAdminExtensionAbility

harmony(鸿蒙)Work Scheduler Callbacks

0  赞