• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.configPolicy (Configuration Policy)
2
3The **configPolicy** module provides APIs for obtaining the custom configuration directory and file path based on the predefined custom 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 a configuration file with the specified name and highest priority. This API uses an asynchronous callback to return the result.
22For example, if the **config.xml** file is stored in **/system/etc/config.xml** and **/sys_pod/etc/config.xml** (in ascending order of priority), then **/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**Example**
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
51Obtains the path of a configuration file with the specified name and highest priority. This API uses a promise to return the result.
52
53**System capability**: SystemCapability.Customization.ConfigPolicy
54
55**Parameters**
56
57| Name    | Type    | Mandatory  | Description   |
58| ------- | ------ | ---- | ----- |
59| relPath | string | Yes   | Name of the configuration file.|
60
61**Return value**
62
63| Type                   | Description          |
64| --------------------- | ------------ |
65| Promise<string> | Promise used to return the path of the configuration file.|
66
67**Example**
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
83Obtains 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.
84For example, if the **config.xml** file is stored in **/system/etc/config.xml** and **/sys_pod/etc/config.xml** (in ascending order of priority), then **/system/etc/config.xml, /sys_pod/etc/config.xml** is returned.
85
86**System capability**: SystemCapability.Customization.ConfigPolicy
87
88**Parameters**
89
90| Name     | Type                                      | Mandatory  | Description           |
91| -------- | ---------------------------------------- | ---- | ------------- |
92| relPath  | string                                   | Yes   | Name of the configuration file.        |
93| callback | AsyncCallback<Array<string>> | Yes   | Callback used to return the file list.|
94
95**Example**
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
113Obtains a list of configuration files with the specified name, sorted in ascending order of priority. This API uses a promise to return the result.
114
115**System capability**: SystemCapability.Customization.ConfigPolicy
116
117**Parameters**
118
119| Name    | Type    | Mandatory  | Description   |
120| ------- | ------ | ---- | ----- |
121| relPath | string | Yes   | Name of the configuration file.|
122
123**Return value**
124
125| Type                                | Description  |
126| ---------------------------------- | ---- |
127| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the file list.|
128
129**Example**
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
145Obtains the list of configuration level directories. This API uses an asynchronous callback to return the result.
146
147**System capability**: SystemCapability.Customization.ConfigPolicy
148
149**Parameters**
150
151| Name     | Type                                      | Mandatory  | Description               |
152| -------- | ---------------------------------------- | ---- | ----------------- |
153| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes   | Callback used to return the configuration level directory list.|
154
155**Example**
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
173Obtains the list of configuration level directories. This API uses a promise to return the result.
174
175**System capability**: SystemCapability.Customization.ConfigPolicy
176
177**Return value**
178
179| Type                                | Description      |
180| ---------------------------------- | -------- |
181| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the configuration level directory list.|
182
183**Example**
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