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