未验证 提交 3f7a075b 编写于 作者: O openharmony_ci 提交者: Gitee

!2013 config_policy增加api说明

Merge pull request !2013 from huangke11/master
......@@ -114,4 +114,5 @@
- [非线性容器TreeSet](js-apis-treeset.md)
- [非线性容器LightWeightMap](js-apis-lightweightmap.md)
- [非线性容器LightWeightSet](js-apis-lightweightset.md)
- 定制管理
- [配置策略](js-apis-config-policy.md)
# 配置策略
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> - 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> - 本模块接口均为系统接口,三方应用不支持调用。
配置策略提供按预先定义的定制配置层级获取对应定制配置目录和文件路径的能力。
## 导入模块
```
import configPolicy from '@ohos.configPolicy';
```
## getOneCfgFile
getOneCfgFile(relPath: string, callback: AsyncCallback<string>): void
使用callback形式返回指定文件名的最高优先级配置文件路径。
例如,config.xml在设备中存在以下路径(优先级从低到高):/system/etc/config.xml、/sys-pod/etc/config.xml,最终返回/sys-pod/etc/config.xml。
**系统能力**:SystemCapability.Customization.ConfigPolicy
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| relPath | string | 是 | 配置文件名 |
| callback | AsyncCallback<string> | 是 | 异步回调,用于返回最高优先级配置文件的路径 |
**示例:**
```
configPolicy.getOneCfgFile('config.xml', (error, value) => {
if (error == undefined) {
console.log(value);
} else {
console.log(error);
}
});
```
## getOneCfgFile
getOneCfgFile(relPath: string): Promise<string>
使用Promise形式返回指定文件名的最高优先级配置文件路径。
**系统能力**:SystemCapability.Customization.ConfigPolicy
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| relPath | string | 是 | 配置文件名 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise<string> | 最高优先级配置文件的路径 |
**示例:**
```
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
按优先级从低到高,使用callback形式返回指定文件名所有的文件列表。例如,config.xml在设备中存在以下路径(优先级从低到高):/system/etc/config.xml、
/sys-pod/etc/config.xml,最终返回/system/etc/config.xml, /sys-pod/etc/config.xml。
**系统能力**:SystemCapability.Customization.ConfigPolicy
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| relPath | string | 是 | 配置文件名 |
| callback | AsyncCallback<Array<string>> | 是 | 异步回调,用于返回文件列表 |
**示例:**
```
configPolicy.getCfgFiles('config.xml', (error, value) => {
if (error == undefined) {
console.log(value);
} else {
console.log(error);
}
});
```
## getCfgFiles
getCfgFiles(relPath: string): Promise<Array<string>>
按优先级从低到高,使用Promise形式返回指定文件名所有的文件列表。
**系统能力**:SystemCapability.Customization.ConfigPolicy
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| relPath | string | 是 | 配置文件名 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise<Array<string>> | 文件列表 |
**示例:**
```
configPolicy.getCfgFiles('config.xml').then(value => {
console.log(value);
}).catch(error => {
console.log("getCfgFiles promise " + error);
});
```
## getCfgDirList
getCfgDirList(callback: AsyncCallback<Array<string>>): void
使用callback形式返回配置层级目录列表。
**系统能力**:SystemCapability.Customization.ConfigPolicy
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<Array<string>> | 是 | 异步回调,用于返回配置层级目录列表 |
**示例:**
```
configPolicy.getCfgDirList((error, value) => {
if (error == undefined) {
console.log(value);
} else {
console.log(error);
}
});
```
## getCfgDirList
getCfgDirList(): Promise<Array<string>>
使用Promise形式返回配置层级目录列表。
**系统能力**:SystemCapability.Customization.ConfigPolicy
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise<Array<string>> | 配置层级目录列表 |
**示例:**
```
configPolicy.getCfgDirList().then(value => {
console.log(value);
}).catch(error => {
console.log("getCfgDirList promise " + error);
});
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册