diff --git a/en/application-dev/reference/apis/Readme-EN.md b/en/application-dev/reference/apis/Readme-EN.md index e2e63510d2d33ffe895ae3c5320af8d6a7f18235..f9f0247e9fff7af42e5d4ba0e57bec7750d41fa5 100644 --- a/en/application-dev/reference/apis/Readme-EN.md +++ b/en/application-dev/reference/apis/Readme-EN.md @@ -110,4 +110,6 @@ - [Nonlinear Container TreeSet](js-apis-treeset.md) - [Nonlinear Container LightWeightMap](js-apis-lightweightmap.md) - [Nonlinear Container LightWeightSet](js-apis-lightweightset.md) +- Custom Management + - [Configuration Policy](js-apis-config-policy.md) diff --git a/en/application-dev/reference/apis/js-apis-config-policy.md b/en/application-dev/reference/apis/js-apis-config-policy.md new file mode 100644 index 0000000000000000000000000000000000000000..3991e4ab9dff7911220c98d4aa89b2c896cbb1fe --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-config-policy.md @@ -0,0 +1,170 @@ +# Configuration Policy + +> ![icon-note.gif](public_sys-resources/icon-note.gif) **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. + +The configuration policy provides the capability of obtaining the custom configuration directory and file path based on the predefined custom configuration level. + +## Modules to Import + +``` +import configPolicy from '@ohos.configPolicy'; +``` + +## getOneCfgFile + +getOneCfgFile(relPath: string, callback: AsyncCallback<string>): void + +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('config.xml', (error, value) => { + if (error == undefined) { + console.log(value); + } else { + console.log(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('config.xml').then(value => { + console.log(value); + }).catch(error => { + console.log("getOneCfgFile promise " + error); + }); + ``` + + +## getCfgFiles + +getCfgFiles(relPath: string, callback: AsyncCallback<Array<string>>): void + +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('config.xml', (error, value) => { + if (error == undefined) { + console.log(value); + } else { + console.log(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('config.xml').then(value => { + console.log(value); + }).catch(error => { + console.log("getCfgFiles promise " + error); + }); + ``` + + +## getCfgDirList + +getCfgDirList(callback: AsyncCallback<Array<string>>): void + +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); + } else { + console.log(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); + }).catch(error => { + console.log("getCfgDirList promise " + error); + }); + ```