未验证 提交 53651ff5 编写于 作者: O openharmony_ci 提交者: Gitee

!6065 翻译完成:5794 config_policy接口资料优化

Merge pull request !6065 from wusongqing/TR5794
# Configuration Policy # 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. 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 ## Modules to Import
``` ```js
import configPolicy from '@ohos.configPolicy'; import configPolicy from '@ohos.configPolicy';
``` ```
## getOneCfgFile ## getOneCfgFile
getOneCfgFile(relPath: string, callback: AsyncCallback<string>): void 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. 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. 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 **System capability**: SystemCapability.Customization.ConfigPolicy
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | --------------------------- | ---- | --------------------- |
| relPath | string | Yes| Name of the configuration file.| | relPath | string | Yes | Name of the configuration file. |
| callback | AsyncCallback<string> | Yes| Callback used to return the path of the configuration file.| | callback | AsyncCallback<string> | Yes | Callback used to return the path of the configuration file.|
**Example** **Example**
``` ```js
configPolicy.getOneCfgFile('config.xml', (error, value) => { configPolicy.getOneCfgFile('etc/config.xml', (error, value) => {
if (error == undefined) { if (error == undefined) {
console.log(value); console.log("value is " + value);
} else { } else {
console.log(error); console.log("error occurs "+ error);
} }
}); });
``` ```
...@@ -48,19 +50,19 @@ Obtains the path of a configuration file with the specified name and highest pri ...@@ -48,19 +50,19 @@ Obtains the path of a configuration file with the specified name and highest pri
**System capability**: SystemCapability.Customization.ConfigPolicy **System capability**: SystemCapability.Customization.ConfigPolicy
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | ------- | ------ | ---- | ----- |
| relPath | string | Yes| Name of the configuration file.| | relPath | string | Yes | Name of the configuration file.|
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | --------------------- | ------------ |
| Promise<string> | Promise used to return the path of the configuration file.| | Promise<string> | Promise used to return the path of the configuration file.|
**Example** **Example**
``` ```js
configPolicy.getOneCfgFile('config.xml').then(value => { configPolicy.getOneCfgFile('etc/config.xml').then(value => {
console.log(value); console.log("value is " + value);
}).catch(error => { }).catch(error => {
console.log("getOneCfgFile promise " + error); console.log("getOneCfgFile promise " + error);
}); });
...@@ -69,26 +71,25 @@ Obtains the path of a configuration file with the specified name and highest pri ...@@ -69,26 +71,25 @@ Obtains the path of a configuration file with the specified name and highest pri
## getCfgFiles ## getCfgFiles
getCfgFiles(relPath: string, callback: AsyncCallback<Array<string>>): void 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** 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.
and **/sys-pod/etc/config.xml**, then **/system/etc/config.xml, /sys-pod/etc/config.xml** is returned.
**System capability**: SystemCapability.Customization.ConfigPolicy **System capability**: SystemCapability.Customization.ConfigPolicy
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | ---------------------------------------- | ---- | ------------- |
| relPath | string | Yes| Name of the configuration file.| | relPath | string | Yes | Name of the configuration file. |
| callback | AsyncCallback<Array<string>> | Yes| Callback used to return the file list.| | callback | AsyncCallback<Array<string>> | Yes | Callback used to return the file list.|
**Example** **Example**
``` ```js
configPolicy.getCfgFiles('config.xml', (error, value) => { configPolicy.getCfgFiles('etc/config.xml', (error, value) => {
if (error == undefined) { if (error == undefined) {
console.log(value); console.log("value is " + value);
} else { } else {
console.log(error); console.log("error occurs "+ error);
} }
}); });
``` ```
...@@ -103,19 +104,19 @@ Obtains all configuration files with the specified name and lists them in ascend ...@@ -103,19 +104,19 @@ Obtains all configuration files with the specified name and lists them in ascend
**System capability**: SystemCapability.Customization.ConfigPolicy **System capability**: SystemCapability.Customization.ConfigPolicy
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | ------- | ------ | ---- | ----- |
| relPath | string | Yes| Name of the configuration file.| | relPath | string | Yes | Name of the configuration file.|
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ---------------------------------- | ---- |
| Promise<Array<string>> | Promise used to return the file list.| | Promise<Array<string>> | Promise used to return the file list.|
**Example** **Example**
``` ```js
configPolicy.getCfgFiles('config.xml').then(value => { configPolicy.getCfgFiles('etc/config.xml').then(value => {
console.log(value); console.log("value is " + value);
}).catch(error => { }).catch(error => {
console.log("getCfgFiles promise " + error); console.log("getCfgFiles promise " + error);
}); });
...@@ -124,24 +125,24 @@ Obtains all configuration files with the specified name and lists them in ascend ...@@ -124,24 +125,24 @@ Obtains all configuration files with the specified name and lists them in ascend
## getCfgDirList ## getCfgDirList
getCfgDirList(callback: AsyncCallback<Array<string>>): void getCfgDirList(callback: AsyncCallback<Array<string>>)
Obtains the configuration level directory list. This API uses an asynchronous callback to return the result. Obtains the configuration level directory list. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Customization.ConfigPolicy **System capability**: SystemCapability.Customization.ConfigPolicy
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | ---------------------------------------- | ---- | ----------------- |
| callback | AsyncCallback<Array<string>> | Yes| Callback used to return the configuration level directory list.| | callback | AsyncCallback<Array<string>> | Yes | Callback used to return the configuration level directory list.|
**Example** **Example**
``` ```js
configPolicy.getCfgDirList((error, value) => { configPolicy.getCfgDirList((error, value) => {
if (error == undefined) { if (error == undefined) {
console.log(value); console.log("value is " + value);
} else { } else {
console.log(error); console.log("error occurs "+ error);
} }
}); });
``` ```
...@@ -156,14 +157,14 @@ Obtains the configuration level directory list. This API uses a promise to retur ...@@ -156,14 +157,14 @@ Obtains the configuration level directory list. This API uses a promise to retur
**System capability**: SystemCapability.Customization.ConfigPolicy **System capability**: SystemCapability.Customization.ConfigPolicy
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ---------------------------------- | -------- |
| Promise<Array<string>> | Promise used to return the configuration level directory list.| | Promise<Array<string>> | Promise used to return the configuration level directory list.|
**Example** **Example**
``` ```js
configPolicy.getCfgDirList().then(value => { configPolicy.getCfgDirList().then(value => {
console.log(value); console.log("value is " + value);
}).catch(error => { }).catch(error => {
console.log("getCfgDirList promise " + error); console.log("getCfgDirList promise " + error);
}); });
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册