• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.configPolicy (配置策略)
2
3配置策略提供按预先定义的定制配置层级获取对应定制配置目录和文件路径的能力。
4
5>  **说明:**
6>
7>  本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8>
9>  本模块接口均为系统接口。
10
11## 导入模块
12
13```ts
14import configPolicy from '@ohos.configPolicy';
15```
16
17## getOneCfgFile
18
19getOneCfgFile(relPath: string, callback: AsyncCallback<string>)
20
21使用callback形式返回指定文件名的最高优先级配置文件路径。
22例如,config.xml在设备中存在以下路径(优先级从低到高):/system/etc/config.xml/sys_pod/etc/config.xml,最终返回/sys_pod/etc/config.xml23
24**系统能力**:SystemCapability.Customization.ConfigPolicy
25
26**参数:**
27
28| 参数名      | 类型                          | 必填   | 说明                    |
29| -------- | --------------------------- | ---- | --------------------- |
30| relPath  | string                      | 是    | 配置文件名                 |
31| callback | AsyncCallback<string> | 是    | 异步回调,用于返回最高优先级配置文件的路径 |
32
33**示例:**
34  ```ts
35  import { BusinessError } from '@ohos.base';
36
37  configPolicy.getOneCfgFile('etc/config.xml', (error: BusinessError, value: string) => {
38      if (error == null) {
39          console.log("value is " + value);
40      } else {
41          console.log("error occurs "+ error);
42      }
43  });
44  ```
45
46
47## getOneCfgFile
48
49getOneCfgFile(relPath: string): Promise<string>
50
51使用Promise形式返回指定文件名的最高优先级配置文件路径。
52
53**系统能力**:SystemCapability.Customization.ConfigPolicy
54
55**参数:**
56
57| 参数名     | 类型     | 必填   | 说明    |
58| ------- | ------ | ---- | ----- |
59| relPath | string | 是    | 配置文件名 |
60
61**返回值:**
62
63| 类型                    | 说明           |
64| --------------------- | ------------ |
65| Promise<string> | 最高优先级配置文件的路径 |
66
67**示例:**
68  ```ts
69  import { BusinessError } from '@ohos.base';
70
71  configPolicy.getOneCfgFile('etc/config.xml').then((value: string) => {
72      console.log("value is " + value);
73  }).catch((error: BusinessError) => {
74      console.log("getOneCfgFile promise " + error);
75  });
76  ```
77
78
79## getCfgFiles
80
81getCfgFiles(relPath: string, callback: AsyncCallback<Array<string>>)
82
83按优先级从低到高,使用callback形式返回指定文件名所有的文件列表。
84例如,config.xml在设备中存在以下路径(优先级从低到高):/system/etc/config.xml/sys_pod/etc/config.xml,最终返回/system/etc/config.xml, /sys_pod/etc/config.xml85
86**系统能力**:SystemCapability.Customization.ConfigPolicy
87
88**参数:**
89
90| 参数名      | 类型                                       | 必填   | 说明            |
91| -------- | ---------------------------------------- | ---- | ------------- |
92| relPath  | string                                   | 是    | 配置文件名         |
93| callback | AsyncCallback<Array<string>> | 是    | 异步回调,用于返回文件列表 |
94
95**示例:**
96  ```ts
97  import { BusinessError } from '@ohos.base';
98
99  configPolicy.getCfgFiles('etc/config.xml', (error: BusinessError, value: Array<string>) => {
100      if (error == null) {
101          console.log("value is " + value);
102      } else {
103          console.log("error occurs "+ error);
104      }
105  });
106  ```
107
108
109## getCfgFiles
110
111getCfgFiles(relPath: string): Promise&lt;Array&lt;string&gt;&gt;
112
113按优先级从低到高,使用Promise形式返回指定文件名所有的文件列表。
114
115**系统能力**:SystemCapability.Customization.ConfigPolicy
116
117**参数:**
118
119| 参数名     | 类型     | 必填   | 说明    |
120| ------- | ------ | ---- | ----- |
121| relPath | string | 是    | 配置文件名 |
122
123**返回值:**
124
125| 类型                                 | 说明   |
126| ---------------------------------- | ---- |
127| Promise&lt;Array&lt;string&gt;&gt; | 文件列表 |
128
129**示例:**
130  ```ts
131  import { BusinessError } from '@ohos.base';
132
133  configPolicy.getCfgFiles('etc/config.xml').then((value: Array<string>) => {
134      console.log("value is " + value);
135  }).catch((error: BusinessError) => {
136      console.log("getCfgFiles promise " + error);
137  });
138  ```
139
140
141## getCfgDirList
142
143getCfgDirList(callback: AsyncCallback&lt;Array&lt;string&gt;&gt;)
144
145使用callback形式返回配置层级目录列表。
146
147**系统能力**:SystemCapability.Customization.ConfigPolicy
148
149**参数:**
150
151| 参数名      | 类型                                       | 必填   | 说明                |
152| -------- | ---------------------------------------- | ---- | ----------------- |
153| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | 是    | 异步回调,用于返回配置层级目录列表 |
154
155**示例:**
156  ```ts
157  import { BusinessError } from '@ohos.base';
158
159  configPolicy.getCfgDirList((error: BusinessError, value: Array<string>) => {
160      if (error == null) {
161          console.log("value is " + value);
162      } else {
163          console.log("error occurs "+ error);
164      }
165  });
166  ```
167
168
169## getCfgDirList
170
171getCfgDirList(): Promise&lt;Array&lt;string&gt;&gt;
172
173使用Promise形式返回配置层级目录列表。
174
175**系统能力**:SystemCapability.Customization.ConfigPolicy
176
177**返回值:**
178
179| 类型                                 | 说明       |
180| ---------------------------------- | -------- |
181| Promise&lt;Array&lt;string&gt;&gt; | 配置层级目录列表 |
182
183**示例:**
184  ```ts
185  import { BusinessError } from '@ohos.base';
186
187  configPolicy.getCfgDirList().then((value: Array<string>) => {
188      console.log("value is " + value);
189  }).catch((error: BusinessError) => {
190      console.log("getCfgDirList promise " + error);
191  });
192  ```
193
194