1# @ohos.configPolicy (Configuration Policy) (System API)
2
3The **configPolicy** module provides APIs for obtaining the custom configuration directory and file path based on the predefined configuration level.
4
5>  **NOTE**
6>
7>  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.
8>
9>  The APIs provided by this module are system APIs.
10
11## Modules to Import
12
13```ts
14import configPolicy from '@ohos.configPolicy';
15```
16
17## getOneCfgFile
18
19getOneCfgFile(relPath: string, callback: AsyncCallback<string>)
20
21Obtains the path of the configuration file with the highest priority based on the specified file name. This API uses an asynchronous callback to return the result.
22If there are two **config.xml** files, **/system/etc/config.xml** and **/sys_pod/etc/config.xml**, in ascending order of priority, **/sys_pod/etc/config.xml** is returned.
23
24**System capability**: SystemCapability.Customization.ConfigPolicy
25
26**Parameters**
27
28| Name  | Type                       | Mandatory| Description                                      |
29| -------- | --------------------------- | ---- | ------------------------------------------ |
30| relPath  | string                      | Yes  | Name of the configuration file.                                |
31| callback | AsyncCallback<string> | Yes  | Callback used to return the path of the configuration file.|
32
33**Error codes**
34
35For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
36
37| ID| Error Message                                                                      |
38| ------- | ---------------------------------------------------------------------------- |
39| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
40
41**Example**
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
66Obtains the path of the configuration file with the highest priority based on the specified file name. This API uses a promise to return the result.
67
68**System capability**: SystemCapability.Customization.ConfigPolicy
69
70**Parameters**
71
72| Name | Type  | Mandatory| Description      |
73| ------- | ------ | ---- | ---------- |
74| relPath | string | Yes  | Name of the configuration file.|
75
76**Error codes**
77
78For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
79
80| ID| Error Message                                                                      |
81| ------- | ---------------------------------------------------------------------------- |
82| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
83
84**Return value**
85
86| Type                  | Description                    |
87| ---------------------- | ------------------------ |
88| Promise<string>  | Promise used to return the path of the configuration file.|
89
90**Example**
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
113Obtains a list of configuration files with the specified name, sorted in ascending order of priority. This API uses an asynchronous callback to return the result.
114If there are two **config.xml** files, **/system/etc/config.xml** and **/sys_pod/etc/config.xml**, in ascending order of priority, **/system/etc/config.xml, /sys_pod/etc/config.xml** is returned.
115
116**System capability**: SystemCapability.Customization.ConfigPolicy
117
118**Parameters**
119
120| Name  | Type                                    | Mandatory| Description                      |
121| -------- | ---------------------------------------- | ---- | -------------------------- |
122| relPath  | string                                   | Yes  | Name of the configuration file.                |
123| callback | AsyncCallback<Array<string>> | Yes  | Callback used to return the file list.|
124
125**Error codes**
126
127For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
128
129| ID| Error Message                                                                      |
130| ------- | ---------------------------------------------------------------------------- |
131| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
132
133**Example**
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
157Obtains a list of configuration files with the specified name, sorted in ascending order of priority. This API uses a promise to return the result.
158
159**System capability**: SystemCapability.Customization.ConfigPolicy
160
161**Parameters**
162
163| Name | Type  | Mandatory| Description      |
164| ------- | ------ | ---- | ---------- |
165| relPath | string | Yes  | Name of the configuration file.|
166
167**Error codes**
168
169For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
170
171| ID| Error Message                                                                      |
172| ------- | ---------------------------------------------------------------------------- |
173| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
174
175**Return value**
176
177| Type                              | Description    |
178| ---------------------------------- | -------- |
179| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the file list.|
180
181**Example**
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
204Obtains the list of configuration level directories. This API uses an asynchronous callback to return the result.
205
206**System capability**: SystemCapability.Customization.ConfigPolicy
207
208**Parameters**
209
210| Name  | Type                                    | Mandatory| Description                              |
211| -------- | ---------------------------------------- | ---- | ---------------------------------- |
212| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes  | Callback used to return the configuration level directory list.|
213
214**Error codes**
215
216For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
217
218| ID| Error Message                                                                      |
219| ------- | ---------------------------------------------------------------------------- |
220| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
221
222**Example**
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
246Obtains the list of configuration level directories. This API uses a promise to return the result.
247
248**System capability**: SystemCapability.Customization.ConfigPolicy
249
250**Return value**
251
252| Type                              | Description            |
253| ---------------------------------- | ---------------- |
254| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the configuration level directory list.|
255
256**Example**
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
278Obtains the path of the configuration file with the highest priority based on the specified file name and follow mode. This API uses an asynchronous callback to return the result.
279For example, there are three **config.xml** files (in ascending order of priority): **/system/etc/config.xml**, **/sys_pod/etc/config.xml**, and **/sys_pod/etc/carrier/46060/etc/config.xml**. If the opkey of the default card is **46060** and the follow mode is **SIM_DEFAULT**, **/sys_pod/etc/carrier/46060/etc/config.xml** is returned.
280
281**System capability**: SystemCapability.Customization.ConfigPolicy
282
283**Parameters**
284
285| Name    | Type                         | Mandatory| Description                                      |
286| ---------- | ----------------------------- | ---- | ------------------------------------------ |
287| relPath    | string                        | Yes  | Name of the configuration file.                                |
288| followMode | [FollowXMode](#followxmode11) | Yes  | Follow mode.                                  |
289| callback   | AsyncCallback&lt;string&gt;   | Yes  | Callback used to return the path of the configuration file.|
290
291**Error codes**
292
293For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
294
295| ID| Error Message                                                                      |
296| ------- | ---------------------------------------------------------------------------- |
297| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
298
299**Example**
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
325Obtains the path of the configuration file with the highest priority based on the specified file name and custom follow rule. This API uses an asynchronous callback to return the result.
326For example, there are three **config.xml** files (in ascending order of priority): **/system/etc/config.xml**, **/sys_pod/etc/config.xml**, and **/sys_pod/etc/carrier/46060/etc/config.xml**. If the opkey of card 1 is **46060**, the follow mode is **USER_DEFINED**, and the custom follow rule is **etc/carrier/${telephony.sim.opkey0}**, **/sys_pod/etc/carrier/46060/etc/config.xml** is returned.
327
328**System capability**: SystemCapability.Customization.ConfigPolicy
329
330**Parameters**
331
332| Name    | Type                         | Mandatory| Description                                                  |
333| ---------- | ----------------------------- | ---- | ------------------------------------------------------ |
334| relPath    | string                        | Yes  | Name of the configuration file.                                            |
335| followMode | [FollowXMode](#followxmode11) | Yes  | Follow mode.                                              |
336| extra      | string                        | Yes  | Custom follow rule. This parameter is valid only when **followMode** is set to **USER_DEFINED**.|
337| callback   | AsyncCallback&lt;string&gt;   | Yes  | Callback used to return the path of the configuration file.            |
338
339**Error codes**
340
341For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
342
343| ID| Error Message                                                                      |
344| ------- | ---------------------------------------------------------------------------- |
345| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
346
347**Example**
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
374Obtains the path of the configuration file with the highest priority based on the specified file name and follow mode. This API uses a promise to return the result.
375
376**System capability**: SystemCapability.Customization.ConfigPolicy
377
378**Parameters**
379
380| Name    | Type                         | Mandatory| Description                                                  |
381| ---------- | ----------------------------- | ---- | ------------------------------------------------------ |
382| relPath    | string                        | Yes  | Name of the configuration file.                                            |
383| followMode | [FollowXMode](#followxmode11) | Yes  | Follow mode.                                              |
384| extra      | string                        | No  | Custom follow rule. This parameter is valid only when **followMode** is set to **USER_DEFINED**.|
385
386**Error codes**
387
388For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
389
390| ID| Error Message                                                                      |
391| ------- | ---------------------------------------------------------------------------- |
392| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3.Parameter verification failed.|
393
394**Return value**
395
396| Type                  | Description                    |
397| ---------------------- | ------------------------ |
398| Promise&lt;string&gt;  | Promise used to return the path of the configuration file.|
399
400**Example**
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
424Obtains the path of the configuration file with the highest priority based on the specified file name and follow mode. This API returns the result synchronously.
425
426**System capability**: SystemCapability.Customization.ConfigPolicy
427
428**Parameters**
429
430| Name    | Type                         | Mandatory| Description                                                |
431| ---------- | ----------------------------- | ---- | ----------------------------------------------------|
432| relPath    | string                        | Yes  | Name of the configuration file.                                          |
433| followMode | [FollowXMode](#followxmode11) | No  | Follow mode. The default value is **DEFAULT**.                   |
434| extra      | string                        | No  | Custom follow rule. This parameter is valid only when **followMode** is set to **USER_DEFINED**.|
435
436**Error codes**
437
438For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
439
440| ID| Error Message                                                                      |
441| ------- | ---------------------------------------------------------------------------- |
442| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3.Parameter verification failed.|
443
444**Return value**
445
446| Type  | Description                    |
447| ------ | ------------------------ |
448| string | Promise used to return the path of the configuration file.|
449
450
451**Example**
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
472Obtains a list of configuration files based on the specified file name and follow mode, sorted in ascending order of priority. This API uses an asynchronous callback to return the result.
473For example, there are three **config.xml** files (in ascending order of priority): **/system/etc/config.xml**, **/sys_pod/etc/config.xml**, and **/sys_pod/etc/carrier/46060/etc/config.xml**. If the opkey of the default card is **46060** and the follow mode is **SIM_DEFAULT**, **/system/etc/config.xml, /sys_pod/etc/config.xml, /sys_pod/etc/carrier/46060/etc/config.xml** is returned.
474
475**System capability**: SystemCapability.Customization.ConfigPolicy
476
477**Parameters**
478
479| Name    | Type                                    | Mandatory| Description                      |
480| ---------- | ---------------------------------------- | ---- | -------------------------- |
481| relPath    | string                                   | Yes  | Name of the configuration file.                |
482| followMode | [FollowXMode](#followxmode11)            | Yes  | Follow mode.                  |
483| callback   | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes  | Callback used to return the file list.|
484
485**Error codes**
486
487For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
488
489| ID| Error Message                                                                      |
490| ------- | ---------------------------------------------------------------------------- |
491| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
492
493**Example**
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
519Obtains a list of configuration files based on the specified file name and custom follow rule, sorted in ascending order of priority. This API uses an asynchronous callback to return the result.
520For example, there are three **config.xml** files (in ascending order of priority): **/system/etc/config.xml**, **/sys_pod/etc/config.xml**, and **/sys_pod/etc/carrier/46060/etc/config.xml**. If the opkey of card 1 is **46060**, the follow mode is **USER_DEFINED**, and the custom follow rule is **etc/carrier/${telephony.sim.opkey0}**, **/system/etc/config.xml, /sys_pod/etc/config.xml, /sys_pod/etc/carrier/46060/etc/config.xml** is returned.
521
522**System capability**: SystemCapability.Customization.ConfigPolicy
523
524**Parameters**
525
526| Name    | Type                                    | Mandatory| Description                                                  |
527| ---------- | ---------------------------------------- | ---- | ------------------------------------------------------ |
528| relPath    | string                                   | Yes  | Name of the configuration file.                                            |
529| followMode | [FollowXMode](#followxmode11)            | Yes  | Follow mode.                                              |
530| extra      | string                                   | Yes  | Custom follow rule. This parameter is valid only when **followMode** is set to **USER_DEFINED**.|
531| callback   | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes  | Callback used to return the file list.                            |
532
533**Error codes**
534
535For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
536
537| ID| Error Message                                                                      |
538| ------- | ---------------------------------------------------------------------------- |
539| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
540
541**Example**
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
568Obtains a list of configuration files based on the specified file name and follow mode, sorted in ascending order of priority. This API uses a promise to return the result.
569
570**System capability**: SystemCapability.Customization.ConfigPolicy
571
572**Parameters**
573
574| Name    | Type                         | Mandatory| Description                                                  |
575| ---------- | ----------------------------- | ---- | ------------------------------------------------------ |
576| relPath    | string                        | Yes  | Name of the configuration file.                                            |
577| followMode | [FollowXMode](#followxmode11) | Yes  | Follow mode.                                              |
578| extra      | string                        | No  | Custom follow rule. This parameter is valid only when **followMode** is set to **USER_DEFINED**.|
579
580**Error codes**
581
582For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
583
584| ID| Error Message                                                                      |
585| ------- | ---------------------------------------------------------------------------- |
586| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3.Parameter verification failed.|
587
588**Return value**
589
590| Type                              | Description    |
591| ---------------------------------- | -------- |
592| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the file list.|
593
594**Example**
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
618Obtains a list of configuration files based on the specified file name and follow mode, sorted in ascending order of priority. This API returns the result synchronously.
619
620**System capability**: SystemCapability.Customization.ConfigPolicy
621
622**Parameters**
623
624| Name    | Type                         | Mandatory| Description                                                  |
625| ---------- | ----------------------------- | ---- | ------------------------------------------------------ |
626| relPath    | string                        | Yes  | Name of the configuration file.                                            |
627| followMode | [FollowXMode](#followxmode11) | No  | Follow mode. The default value is **DEFAULT**.                   |
628| extra      | string                        | No  | Custom follow rule. This parameter is valid only when **followMode** is set to **USER_DEFINED**.|
629
630**Error codes**
631
632For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
633
634| ID| Error Message                                                                      |
635| ------- | ---------------------------------------------------------------------------- |
636| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3.Parameter verification failed.|
637
638**Return value**
639
640| Type               | Description    |
641| ------------------- | -------- |
642| Array&lt;string&gt; | Promise used to return the file list.|
643
644
645**Example**
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
666Obtains the list of configuration level directories. This API returns the result synchronously.
667
668**System capability**: SystemCapability.Customization.ConfigPolicy
669
670**Return value**
671
672| Type               | Description            |
673| ------------------- | ---------------- |
674| Array&lt;string&gt; | Promise used to return the configuration level directory list.|
675
676
677**Example**
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**System capability**: SystemCapability.Customization.ConfigPolicy
695
696| Name            | Value | Description                                                                                                                      |
697| ---------------- | --- | -------------------------------------------------------------------------------------------------------------------------- |
698| DEFAULT          | 0   | Files are searched based on the follow rules configured in the **followx_file_list.cfg** file at each configuration level.                               |
699| NO_RULE_FOLLOWED | 1   | No follow rule is used, even if the **followx_file_list.cfg** file exists.                                             |
700| SIM_DEFAULT      | 10  | Files are searched in **etc/carrier/${opkey}** file at each configuration level based on the opkey of the default card.                               |
701| SIM_1            | 11  | Files are searched in **etc/carrier/${opkey}** at each configuration level based on the opkey of card 1.                                     |
702| SIM_2            | 12  | Files are searched in **etc/carrier/${opkey}** at each configuration level based on the opkey of card 2.                                     |
703| USER_DEFINED     | 100 | Files are searched based on the follow rule passed in **extra**, rather than the **followx_file_list.cfg** file at each configuration level.|
704