harmony 鸿蒙@ohos.configPolicy (Configuration Policy)

  • 2022-12-05
  • 浏览 (577)

@ohos.configPolicy (Configuration Policy)

The configPolicy module provides APIs for 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 provided by this module are system APIs.

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

  import { BusinessError } from '@ohos.base';

  configPolicy.getOneCfgFile('etc/config.xml', (error: BusinessError, value: string) => {
      if (error == null) {
          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

  import { BusinessError } from '@ohos.base';

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

getCfgFiles

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

Obtains a list of configuration files with the specified name, sorted 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 (in ascending order of priority), 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

  import { BusinessError } from '@ohos.base';

  configPolicy.getCfgFiles('etc/config.xml', (error: BusinessError, value: Array<string>) => {
      if (error == null) {
          console.log("value is " + value);
      } else {
          console.log("error occurs "+ error);
      }
  });

getCfgFiles

getCfgFiles(relPath: string): Promise&lt;Array&lt;string&gt;&gt;

Obtains a list of configuration files with the specified name, sorted 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&lt;Array&lt;string&gt;&gt; Promise used to return the file list.

Example

  import { BusinessError } from '@ohos.base';

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

getCfgDirList

getCfgDirList(callback: AsyncCallback&lt;Array&lt;string&gt;&gt;)

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

System capability: SystemCapability.Customization.ConfigPolicy

Parameters

Name Type Mandatory Description
callback AsyncCallback&lt;Array&lt;string&gt;&gt; Yes Callback used to return the configuration level directory list.

Example

  import { BusinessError } from '@ohos.base';

  configPolicy.getCfgDirList((error: BusinessError, value: Array<string>) => {
      if (error == null) {
          console.log("value is " + value);
      } else {
          console.log("error occurs "+ error);
      }
  });

getCfgDirList

getCfgDirList(): Promise&lt;Array&lt;string&gt;&gt;

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

System capability: SystemCapability.Customization.ConfigPolicy

Return value

Type Description
Promise&lt;Array&lt;string&gt;&gt; Promise used to return the configuration level directory list.

Example

  import { BusinessError } from '@ohos.base';

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

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

0  赞