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