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
35以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
36
37| 错误码ID | 错误信息                                                                       |
38| ------- | ---------------------------------------------------------------------------- |
39| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
40
41**示例:**
42
43  ```ts
44  import { BusinessError } from '@ohos.base';
45
46  try {
47    let relpath: string = 'etc/config.xml';
48    configPolicy.getOneCfgFile(relpath, (error: BusinessError, value: string) => {
49      if (error == null) {
50        console.log('value is ' + value);
51      } else {
52        console.log('error occurs ' + error);
53      }
54    });
55  } catch (error) {
56    let code = (error as BusinessError).code;
57    let message = (error as BusinessError).message;
58    console.log('error:' + code + ',' + message);
59  }
60  ```
61
62## getOneCfgFile
63
64getOneCfgFile(relPath: string): Promise<string>
65
66使用Promise形式返回指定文件名的最高优先级配置文件路径。
67
68**系统能力**:SystemCapability.Customization.ConfigPolicy
69
70**参数:**
71
72| 参数名  | 类型   | 必填 | 说明       |
73| ------- | ------ | ---- | ---------- |
74| relPath | string | 是   | 配置文件名 |
75
76**错误码**:
77
78以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
79
80| 错误码ID | 错误信息                                                                       |
81| ------- | ---------------------------------------------------------------------------- |
82| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
83
84**返回值:**
85
86| 类型                   | 说明                     |
87| ---------------------- | ------------------------ |
88| Promise<string>  | 最高优先级配置文件的路径 |
89
90**示例:**
91
92  ```ts
93  import { BusinessError } from '@ohos.base';
94
95  try {
96    let relpath: string = 'etc/config.xml';
97    configPolicy.getOneCfgFile(relpath).then((value: string) => {
98      console.log('value is ' + value);
99    }).catch((error: BusinessError) => {
100      console.log('getOneCfgFile promise ' + error);
101    });
102  } catch (error) {
103    let code = (error as BusinessError).code;
104    let message = (error as BusinessError).message;
105    console.log('error:' + code + ',' + message);
106  }
107  ```
108
109## getCfgFiles
110
111getCfgFiles(relPath: string, callback: AsyncCallback<Array<string>>)
112
113按优先级从低到高,使用callback形式返回指定文件名所有的文件列表。
114例如,config.xml在设备中存在以下路径(优先级从低到高):/system/etc/config.xml/sys_pod/etc/config.xml,最终返回/system/etc/config.xml, /sys_pod/etc/config.xml115
116**系统能力**:SystemCapability.Customization.ConfigPolicy
117
118**参数:**
119
120| 参数名   | 类型                                     | 必填 | 说明                       |
121| -------- | ---------------------------------------- | ---- | -------------------------- |
122| relPath  | string                                   | 是   | 配置文件名                 |
123| callback | AsyncCallback<Array<string>> | 是   | 异步回调,用于返回文件列表 |
124
125**错误码**:
126
127以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
128
129| 错误码ID | 错误信息                                                                       |
130| ------- | ---------------------------------------------------------------------------- |
131| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
132
133**示例:**
134
135  ```ts
136  import { BusinessError } from '@ohos.base';
137
138  try {
139    configPolicy.getCfgFiles('etc/config.xml', (error: BusinessError, value: Array<string>) => {
140      if (error == null) {
141        console.log('value is ' + value);
142      } else {
143        console.log('error occurs ' + error);
144      }
145    });
146  } catch (error) {
147    let code = (error as BusinessError).code;
148    let message = (error as BusinessError).message;
149    console.log('error:' + code + ',' + message);
150  }
151  ```
152
153## getCfgFiles
154
155getCfgFiles(relPath: string): Promise&lt;Array&lt;string&gt;&gt;
156
157按优先级从低到高,使用Promise形式返回指定文件名所有的文件列表。
158
159**系统能力**:SystemCapability.Customization.ConfigPolicy
160
161**参数:**
162
163| 参数名  | 类型   | 必填 | 说明       |
164| ------- | ------ | ---- | ---------- |
165| relPath | string | 是   | 配置文件名 |
166
167**错误码**:
168
169以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
170
171| 错误码ID | 错误信息                                                                       |
172| ------- | ---------------------------------------------------------------------------- |
173| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
174
175**返回值:**
176
177| 类型                               | 说明     |
178| ---------------------------------- | -------- |
179| Promise&lt;Array&lt;string&gt;&gt; | 文件列表 |
180
181**示例:**
182
183  ```ts
184  import { BusinessError } from '@ohos.base';
185
186  try {
187    let relpath: string = 'etc/config.xml';
188    configPolicy.getCfgFiles(relpath).then((value: Array<string>) => {
189      console.log('value is ' + value);
190    }).catch((error: BusinessError) => {
191      console.log('getCfgFiles promise ' + error);
192    });
193  } catch (error) {
194    let code = (error as BusinessError).code;
195    let message = (error as BusinessError).message;
196    console.log('error:' + code + ',' + message);
197  }
198  ```
199
200## getCfgDirList
201
202getCfgDirList(callback: AsyncCallback&lt;Array&lt;string&gt;&gt;)
203
204使用callback形式返回配置层级目录列表。
205
206**系统能力**:SystemCapability.Customization.ConfigPolicy
207
208**参数:**
209
210| 参数名   | 类型                                     | 必填 | 说明                               |
211| -------- | ---------------------------------------- | ---- | ---------------------------------- |
212| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | 是   | 异步回调,用于返回配置层级目录列表 |
213
214**错误码**:
215
216以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
217
218| 错误码ID | 错误信息                                                                       |
219| ------- | ---------------------------------------------------------------------------- |
220| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
221
222**示例:**
223
224  ```ts
225  import { BusinessError } from '@ohos.base';
226
227  try {
228    configPolicy.getCfgDirList((error: BusinessError, value: Array<string>) => {
229      if (error == null) {
230        console.log('value is ' + value);
231      } else {
232        console.log('error occurs ' + error);
233      }
234    });
235  } catch (error) {
236    let code = (error as BusinessError).code;
237    let message = (error as BusinessError).message;
238    console.log('error:' + code + ',' + message);
239  }
240  ```
241
242## getCfgDirList
243
244getCfgDirList(): Promise&lt;Array&lt;string&gt;&gt;
245
246使用Promise形式返回配置层级目录列表。
247
248**系统能力**:SystemCapability.Customization.ConfigPolicy
249
250**返回值:**
251
252| 类型                               | 说明             |
253| ---------------------------------- | ---------------- |
254| Promise&lt;Array&lt;string&gt;&gt; | 配置层级目录列表 |
255
256**示例:**
257
258  ```ts
259  import { BusinessError } from '@ohos.base';
260
261  try {
262    configPolicy.getCfgDirList().then((value: Array<string>) => {
263      console.log('value is ' + value);
264    }).catch((error: BusinessError) => {
265      console.log('getCfgDirList promise ' + error);
266    });
267  } catch (error) {
268    let code = (error as BusinessError).code;
269    let message = (error as BusinessError).message;
270    console.log('error:' + code + ',' + message);
271  }
272  ```
273
274## getOneCfgFile<sup>11+</sup>
275
276getOneCfgFile(relPath: string, followMode: FollowXMode, callback: AsyncCallback&lt;string&gt;)
277
278根据提供的跟随模式获取指定文件名的最高优先级配置文件路径,并使用callback形式返回。
279例如,config.xml在设备中存在以下路径(优先级从低到高):/system/etc/config.xml/sys_pod/etc/config.xml/sys_pod/etc/carrier/46060/etc/config.xml,且设备默认卡opkey为46060,设置的followMode为configPolicy.FollowXMode.SIM_DEFAULT,最终返回/sys_pod/etc/carrier/46060/etc/config.xml280
281**系统能力**:SystemCapability.Customization.ConfigPolicy
282
283**参数:**
284
285| 参数名     | 类型                          | 必填 | 说明                                       |
286| ---------- | ----------------------------- | ---- | ------------------------------------------ |
287| relPath    | string                        | 是   | 配置文件名                                 |
288| followMode | [FollowXMode](#followxmode11) | 是   | 跟随模式                                   |
289| callback   | AsyncCallback&lt;string&gt;   | 是   | 异步回调,用于返回最高优先级配置文件的路径 |
290
291**错误码**:
292
293以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
294
295| 错误码ID | 错误信息                                                                       |
296| ------- | ---------------------------------------------------------------------------- |
297| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
298
299**示例:**
300
301  ```ts
302  import { BusinessError } from '@ohos.base';
303
304  try {
305    let relpath: string = 'etc/config.xml';
306    configPolicy.getOneCfgFile(relpath, configPolicy.FollowXMode.SIM_DEFAULT,
307      (error: BusinessError, value: string) => {
308      if (error == null) {
309        console.log('value is ' + value);
310      } else {
311        console.log('error occurs ' + error);
312      }
313    });
314  } catch (error) {
315    let code = (error as BusinessError).code;
316    let message = (error as BusinessError).message;
317    console.log('error:' + code + ',' + message);
318  }
319  ```
320
321## getOneCfgFile<sup>11+</sup>
322
323getOneCfgFile(relPath: string, followMode: FollowXMode, extra: string, callback: AsyncCallback&lt;string&gt;)
324
325根据提供的跟随模式获取指定文件名的最高优先级配置文件路径,并使用callback形式返回。
326例如,config.xml在设备中存在以下路径(优先级从低到高):/system/etc/config.xml/sys_pod/etc/config.xml/sys_pod/etc/carrier/46060/etc/config.xml,且设备卡1的opkey为46060,设置的followMode为configPolicy.FollowXMode.USER_DEFINED,自定义跟随规则为"etc/carrier/${telephony.sim.opkey0}",最终返回/sys_pod/etc/carrier/46060/etc/config.xml327
328**系统能力**:SystemCapability.Customization.ConfigPolicy
329
330**参数:**
331
332| 参数名     | 类型                          | 必填 | 说明                                                   |
333| ---------- | ----------------------------- | ---- | ------------------------------------------------------ |
334| relPath    | string                        | 是   | 配置文件名                                             |
335| followMode | [FollowXMode](#followxmode11) | 是   | 跟随模式                                               |
336| extra      | string                        | 是   | 用户自定义跟随规则,仅在followMode为USER_DEFINED时有效 |
337| callback   | AsyncCallback&lt;string&gt;   | 是   | 异步回调,用于返回最高优先级配置文件的路径             |
338
339**错误码**:
340
341以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
342
343| 错误码ID | 错误信息                                                                       |
344| ------- | ---------------------------------------------------------------------------- |
345| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
346
347**示例:**
348
349  ```ts
350  import { BusinessError } from '@ohos.base';
351
352  try {
353    let relpath: string = 'etc/config.xml';
354    let extra: string = 'etc/carrier/${telephony.sim.opkey0}';
355    configPolicy.getOneCfgFile(relpath, configPolicy.FollowXMode.USER_DEFINED, extra,
356      (error: BusinessError, value: string) => {
357      if (error == null) {
358        console.log('value is ' + value);
359      } else {
360        console.log('error occurs ' + error);
361      }
362    });
363  } catch (error) {
364    let code = (error as BusinessError).code;
365    let message = (error as BusinessError).message;
366    console.log('error:' + code + ',' + message);
367  }
368  ```
369
370## getOneCfgFile<sup>11+</sup>
371
372getOneCfgFile(relPath: string, followMode: FollowXMode, extra?: string): Promise&lt;string&gt;
373
374根据提供的跟随模式获取指定文件名的最高优先级配置文件路径,并使用Promise形式返回。
375
376**系统能力**:SystemCapability.Customization.ConfigPolicy
377
378**参数:**
379
380| 参数名     | 类型                          | 必填 | 说明                                                   |
381| ---------- | ----------------------------- | ---- | ------------------------------------------------------ |
382| relPath    | string                        | 是   | 配置文件名                                             |
383| followMode | [FollowXMode](#followxmode11) | 是   | 跟随模式                                               |
384| extra      | string                        | 否   | 用户自定义跟随规则,仅在followMode为USER_DEFINED时必填 |
385
386**错误码**:
387
388以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
389
390| 错误码ID | 错误信息                                                                       |
391| ------- | ---------------------------------------------------------------------------- |
392| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3.Parameter verification failed.|
393
394**返回值:**
395
396| 类型                   | 说明                     |
397| ---------------------- | ------------------------ |
398| Promise&lt;string&gt;  | 最高优先级配置文件的路径 |
399
400**示例:**
401
402  ```ts
403  import { BusinessError } from '@ohos.base';
404
405  try {
406    let relpath: string = 'etc/config.xml';
407    let extra: string = 'etc/carrier/${telephony.sim.opkey0}';
408    configPolicy.getOneCfgFile(relpath, configPolicy.FollowXMode.SIM_DEFAULT, extra).then((value: string) => {
409      console.log('value is ' + value);
410    }).catch((error: BusinessError) => {
411      console.log('getOneCfgFile promise ' + error);
412    });
413  } catch (error) {
414    let code = (error as BusinessError).code;
415    let message = (error as BusinessError).message;
416    console.log('error:' + code + ',' + message);
417  }
418  ```
419
420## getOneCfgFileSync<sup>11+</sup>
421
422getOneCfgFileSync(relPath: string, followMode?: FollowXMode, extra?: string): string
423
424根据提供的跟随模式返回指定文件名的最高优先级配置文件路径。
425
426**系统能力**:SystemCapability.Customization.ConfigPolicy
427
428**参数:**
429
430| 参数名     | 类型                          | 必填 | 说明                                                 |
431| ---------- | ----------------------------- | ---- | ----------------------------------------------------|
432| relPath    | string                        | 是   | 配置文件名                                           |
433| followMode | [FollowXMode](#followxmode11) | 否   | 跟随模式,不设置时,默认使用DEFAULT                    |
434| extra      | string                        | 否   | 用户自定义跟随规则,仅在followMode为USER_DEFINED时必填 |
435
436**错误码**:
437
438以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
439
440| 错误码ID | 错误信息                                                                       |
441| ------- | ---------------------------------------------------------------------------- |
442| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3.Parameter verification failed.|
443
444**返回值:**
445
446| 类型   | 说明                     |
447| ------ | ------------------------ |
448| string | 最高优先级配置文件的路径 |
449
450
451**示例:**
452
453  ```ts
454  import { BusinessError } from '@ohos.base';
455
456  try {
457    let relpath: string = 'etc/config.xml';
458    let extra: string = 'etc/carrier/${telephony.sim.opkey0}';
459    let result: string = configPolicy.getOneCfgFileSync(relpath, configPolicy.FollowXMode.USER_DEFINED, extra);
460    console.log('result is ' + result);
461  } catch (error) {
462    let code = (error as BusinessError).code;
463    let message = (error as BusinessError).message;
464    console.log('error:' + code + ',' + message);
465  }
466  ```
467
468## getCfgFiles<sup>11+</sup>
469
470getCfgFiles(relPath: string, followMode: FollowXMode, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;)
471
472按优先级从低到高,根据提供的跟随模式获取指定文件名所有的文件列表,并使用callback形式返回。
473例如,config.xml在设备中存在以下路径(优先级从低到高):/system/etc/config.xml/sys_pod/etc/config.xml/sys_pod/etc/carrier/46060/etc/config.xml,且设备默认卡opkey为46060,设置的followMode为configPolicy.FollowXMode.SIM_DEFAULT,最终返回/system/etc/config.xml, /sys_pod/etc/config.xml, /sys_pod/etc/carrier/46060/etc/config.xml474
475**系统能力**:SystemCapability.Customization.ConfigPolicy
476
477**参数:**
478
479| 参数名     | 类型                                     | 必填 | 说明                       |
480| ---------- | ---------------------------------------- | ---- | -------------------------- |
481| relPath    | string                                   | 是   | 配置文件名                 |
482| followMode | [FollowXMode](#followxmode11)            | 是   | 跟随模式                   |
483| callback   | AsyncCallback&lt;Array&lt;string&gt;&gt; | 是   | 异步回调,用于返回文件列表 |
484
485**错误码**:
486
487以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
488
489| 错误码ID | 错误信息                                                                       |
490| ------- | ---------------------------------------------------------------------------- |
491| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
492
493**示例:**
494
495  ```ts
496  import { BusinessError } from '@ohos.base';
497
498  try {
499    let relpath: string = 'etc/config.xml';
500    configPolicy.getCfgFiles(relpath, configPolicy.FollowXMode.SIM_DEFAULT,
501      (error: BusinessError, value: Array<string>) => {
502      if (error == null) {
503        console.log('value is ' + value);
504      } else {
505        console.log('error occurs ' + error);
506      }
507    });
508  } catch (error) {
509    let code = (error as BusinessError).code;
510    let message = (error as BusinessError).message;
511    console.log('error:' + code + ',' + message);
512  }
513  ```
514
515## getCfgFiles<sup>11+</sup>
516
517getCfgFiles(relPath: string, followMode: FollowXMode, extra: string, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;)
518
519按优先级从低到高,根据提供的跟随模式获取指定文件名所有的文件列表,并使用callback形式返回。
520例如,config.xml在设备中存在以下路径(优先级从低到高):/system/etc/config.xml/sys_pod/etc/config.xml/sys_pod/etc/carrier/46060/etc/config.xml,且设备卡1的opkey为46060,设置的followMode为configPolicy.FollowXMode.USER_DEFINED,自定义跟随规则为"etc/carrier/${telephony.sim.opkey0}",最终返回/system/etc/config.xml, /sys_pod/etc/config.xml, /sys_pod/etc/carrier/46060/etc/config.xml521
522**系统能力**:SystemCapability.Customization.ConfigPolicy
523
524**参数:**
525
526| 参数名     | 类型                                     | 必填 | 说明                                                   |
527| ---------- | ---------------------------------------- | ---- | ------------------------------------------------------ |
528| relPath    | string                                   | 是   | 配置文件名                                             |
529| followMode | [FollowXMode](#followxmode11)            | 是   | 跟随模式                                               |
530| extra      | string                                   | 是   | 用户自定义跟随规则,仅在followMode为USER_DEFINED时有效 |
531| callback   | AsyncCallback&lt;Array&lt;string&gt;&gt; | 是   | 异步回调,用于返回文件列表                             |
532
533**错误码**:
534
535以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
536
537| 错误码ID | 错误信息                                                                       |
538| ------- | ---------------------------------------------------------------------------- |
539| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
540
541**示例:**
542
543  ```ts
544  import { BusinessError } from '@ohos.base';
545
546  try {
547    let relpath: string = 'etc/config.xml';
548    let extra: string = 'etc/carrier/${telephony.sim.opkey0}';
549    configPolicy.getCfgFiles(relpath, configPolicy.FollowXMode.SIM_DEFAULT, extra,
550      (error: BusinessError, value: Array<string>) => {
551      if (error == null) {
552        console.log('value is ' + value);
553      } else {
554        console.log('error occurs ' + error);
555      }
556    });
557  } catch (error) {
558    let code = (error as BusinessError).code;
559    let message = (error as BusinessError).message;
560    console.log('error:' + code + ',' + message);
561  }
562  ```
563
564## getCfgFiles<sup>11+</sup>
565
566getCfgFiles(relPath: string, followMode: FollowXMode, extra?: string): Promise&lt;Array&lt;string&gt;&gt;
567
568根据提供的跟随模式按优先级从低到高,获取指定文件名所有的文件列表,并使用Promise形式返回。
569
570**系统能力**:SystemCapability.Customization.ConfigPolicy
571
572**参数:**
573
574| 参数名     | 类型                          | 必填 | 说明                                                   |
575| ---------- | ----------------------------- | ---- | ------------------------------------------------------ |
576| relPath    | string                        | 是   | 配置文件名                                             |
577| followMode | [FollowXMode](#followxmode11) | 是   | 跟随模式                                               |
578| extra      | string                        | 否   | 用户自定义跟随规则,仅在followMode为USER_DEFINED时必填 |
579
580**错误码**:
581
582以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
583
584| 错误码ID | 错误信息                                                                       |
585| ------- | ---------------------------------------------------------------------------- |
586| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3.Parameter verification failed.|
587
588**返回值:**
589
590| 类型                               | 说明     |
591| ---------------------------------- | -------- |
592| Promise&lt;Array&lt;string&gt;&gt; | 文件列表 |
593
594**示例:**
595
596  ```ts
597  import { BusinessError } from '@ohos.base';
598
599  try {
600    let relpath: string = 'etc/config.xml';
601    let extra: string = 'etc/carrier/${telephony.sim.opkey0}';
602    configPolicy.getCfgFiles(relpath, configPolicy.FollowXMode.SIM_DEFAULT, extra).then((value: Array<string>) => {
603      console.log('value is ' + value);
604    }).catch((error: BusinessError) => {
605      console.log('getCfgFiles promise ' + error);
606    });
607  } catch (error) {
608    let code = (error as BusinessError).code;
609    let message = (error as BusinessError).message;
610    console.log('error:' + code + ',' + message);
611  }
612  ```
613
614## getCfgFilesSync<sup>11+</sup>
615
616getCfgFilesSync(relPath: string, followMode?: FollowXMode, extra?: string): Array&lt;string&gt;
617
618根据提供的跟随模式返回指定文件名所有的文件列表。
619
620**系统能力**:SystemCapability.Customization.ConfigPolicy
621
622**参数:**
623
624| 参数名     | 类型                          | 必填 | 说明                                                   |
625| ---------- | ----------------------------- | ---- | ------------------------------------------------------ |
626| relPath    | string                        | 是   | 配置文件名                                             |
627| followMode | [FollowXMode](#followxmode11) | 否   | 跟随模式,不设置时,默认使用DEFAULT                    |
628| extra      | string                        | 否   | 用户自定义跟随规则,仅在followMode为USER_DEFINED时必填 |
629
630**错误码**:
631
632以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
633
634| 错误码ID | 错误信息                                                                       |
635| ------- | ---------------------------------------------------------------------------- |
636| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3.Parameter verification failed.|
637
638**返回值:**
639
640| 类型                | 说明     |
641| ------------------- | -------- |
642| Array&lt;string&gt; | 文件列表 |
643
644
645**示例:**
646
647  ```ts
648  import { BusinessError } from '@ohos.base';
649
650  try {
651    let relpath: string = 'etc/config.xml';
652    let extra: string = 'etc/carrier/${telephony.sim.opkey0}';
653    let result: Array<string> = configPolicy.getCfgFilesSync(relpath, configPolicy.FollowXMode.USER_DEFINED, extra);
654    console.log('result is ' + result);
655  } catch (error) {
656    let code = (error as BusinessError).code;
657    let message = (error as BusinessError).message;
658    console.log('error:' + code + ',' + message);
659  }
660  ```
661
662## getCfgDirListSync<sup>11+</sup>
663
664getCfgDirListSync(): Array&lt;string&gt;
665
666返回配置层级目录列表。
667
668**系统能力**:SystemCapability.Customization.ConfigPolicy
669
670**返回值:**
671
672| 类型                | 说明             |
673| ------------------- | ---------------- |
674| Array&lt;string&gt; | 配置层级目录列表 |
675
676
677**示例:**
678
679  ```ts
680  import { BusinessError } from '@ohos.base';
681
682  try {
683    let result: Array<string> = configPolicy.getCfgDirListSync();
684    console.log('result is ' + result);
685  } catch (error) {
686    let code = (error as BusinessError).code;
687    let message = (error as BusinessError).message;
688    console.log('error:' + code + ',' + message);
689  }
690  ```
691
692## FollowXMode<sup>11+</sup>
693
694**系统能力:** SystemCapability.Customization.ConfigPolicy
695
696| 名称             | 值  | 说明                                                                                                                       |
697| ---------------- | --- | -------------------------------------------------------------------------------------------------------------------------- |
698| DEFAULT          | 0   | 默认模式,此模式下会根据各配置层级下的followx_file_list.cfg文件配置的跟随规则进行文件查找。                                |
699| NO_RULE_FOLLOWED | 1   | 不跟随模式,此模式下不会使用任何跟随规则,即使存在followx_file_list.cfg文件。                                              |
700| SIM_DEFAULT      | 10  | 跟随默认卡模式,此模式下会根据默认卡的opkey在各配置层级下的etc/carrier/${opkey}下查找文件。                                |
701| SIM_1            | 11  | 跟随卡1模式,此模式下会根据卡1的opkey在各配置层级下的etc/carrier/${opkey}下查找文件。                                      |
702| SIM_2            | 12  | 跟随卡2模式,此模式下会根据卡2的opkey在各配置层级下的etc/carrier/${opkey}下查找文件。                                      |
703| USER_DEFINED     | 100 | 用户自定义模式,此模式会根据入参extra提供的跟随规则进行配置文件获取。此模式会忽略各配置层级下的followx_file_list.cfg文件。 |
704