• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Configuration Policy
2
3The configuration policy 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 of this module are system APIs and cannot be called by third-party applications.
10
11## Modules to Import
12
13```js
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| Name| Type| Mandatory| Description|
28| -------- | -------- | -------- | -------- |
29| relPath | string | Yes| Name of the configuration file.|
30| callback | AsyncCallback<string> | Yes| Callback used to return the path of the configuration file.|
31
32**Example**
33  ```js
34  configPolicy.getOneCfgFile('etc/config.xml', (error, value) => {
35      if (error == undefined) {
36          console.log("value is " + value);
37      } else {
38          console.log("error occurs "+ error);
39      }
40  });
41  ```
42
43
44## getOneCfgFile
45
46getOneCfgFile(relPath: string): Promise<string>
47
48Obtains the path of a configuration file with the specified name and highest priority. This API uses a promise to return the result.
49
50**System capability**: SystemCapability.Customization.ConfigPolicy
51
52**Parameters**
53| Name| Type| Mandatory| Description|
54| -------- | -------- | -------- | -------- |
55| relPath | string | Yes| Name of the configuration file.|
56
57**Return value**
58| Type| Description|
59| -------- | -------- |
60| Promise<string> | Promise used to return the path of the configuration file.|
61
62**Example**
63  ```js
64  configPolicy.getOneCfgFile('etc/config.xml').then(value => {
65      console.log("value is " + value);
66  }).catch(error => {
67      console.log("getOneCfgFile promise " + error);
68  });
69  ```
70
71
72## getCfgFiles
73
74getCfgFiles(relPath: string, callback: AsyncCallback<Array<string>>)
75
76Obtains all configuration files with the specified name and lists them in ascending order of priority. This API uses an asynchronous callback to return the result. For example, if the **config.xml** file is stored in **/system/etc/config.xml** and **/sys_pod/etc/config.xml**, then **/system/etc/config.xml, /sys_pod/etc/config.xml** is returned.
77
78**System capability**: SystemCapability.Customization.ConfigPolicy
79
80**Parameters**
81| Name| Type| Mandatory| Description|
82| -------- | -------- | -------- | -------- |
83| relPath | string | Yes| Name of the configuration file.|
84| callback | AsyncCallback<Array<string>> | Yes| Callback used to return the file list.|
85
86**Example**
87  ```js
88  configPolicy.getCfgFiles('etc/config.xml', (error, value) => {
89      if (error == undefined) {
90          console.log("value is " + value);
91      } else {
92          console.log("error occurs "+ error);
93      }
94  });
95  ```
96
97
98## getCfgFiles
99
100getCfgFiles(relPath: string): Promise<Array<string>>
101
102Obtains all configuration files with the specified name and lists them in ascending order of priority. This API uses a promise to return the result.
103
104**System capability**: SystemCapability.Customization.ConfigPolicy
105
106**Parameters**
107| Name| Type| Mandatory| Description|
108| -------- | -------- | -------- | -------- |
109| relPath | string | Yes| Name of the configuration file.|
110
111**Return value**
112| Type| Description|
113| -------- | -------- |
114| Promise<Array<string>> | Promise used to return the file list.|
115
116**Example**
117  ```js
118  configPolicy.getCfgFiles('etc/config.xml').then(value => {
119      console.log("value is " + value);
120  }).catch(error => {
121      console.log("getCfgFiles promise " + error);
122  });
123  ```
124
125
126## getCfgDirList
127
128getCfgDirList(callback: AsyncCallback<Array<string>>)
129
130Obtains the configuration level directory list. This API uses an asynchronous callback to return the result.
131
132**System capability**: SystemCapability.Customization.ConfigPolicy
133
134**Parameters**
135| Name| Type| Mandatory| Description|
136| -------- | -------- | -------- | -------- |
137| callback | AsyncCallback<Array<string>> | Yes| Callback used to return the configuration level directory list.|
138
139**Example**
140  ```js
141  configPolicy.getCfgDirList((error, value) => {
142      if (error == undefined) {
143          console.log("value is " + value);
144      } else {
145          console.log("error occurs "+ error);
146      }
147  });
148  ```
149
150
151## getCfgDirList
152
153getCfgDirList(): Promise<Array<string>>
154
155Obtains the configuration level directory list. This API uses a promise to return the result.
156
157**System capability**: SystemCapability.Customization.ConfigPolicy
158
159**Return value**
160| Type| Description|
161| -------- | -------- |
162| Promise<Array<string>> | Promise used to return the configuration level directory list.|
163
164**Example**
165  ```js
166  configPolicy.getCfgDirList().then(value => {
167      console.log("value is " + value);
168  }).catch(error => {
169      console.log("getCfgDirList promise " + error);
170  });
171  ```
172