1# @ohos.enterprise.wifiManager (Wi-Fi Management) (System API)
2
3The **wifiManager** module provides APIs for Wi-Fi management of enterprise devices.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8>
9> The APIs of this module can be used only in the stage model.
10>
11> The APIs of this module can be called only by a [device administrator application](../../mdm/mdm-kit-guide.md#introduction) that is [enabled](js-apis-enterprise-adminManager-sys.md#adminmanagerenableadmin).
12>
13> This topic describes only the system APIs provided by the module. For details about its public APIs, see [@ohos.enterprise.wifiManager](js-apis-enterprise-wifiManager.md).
14
15## Modules to Import
16
17```ts
18import { wifiManager } from '@kit.MDMKit';
19```
20
21## wifiManager.isWifiActive
22
23isWifiActive(admin: Want, callback: AsyncCallback<boolean>): void
24
25Checks whether Wi-Fi is active through the specified device administrator application. This API uses an asynchronous callback to return the result.
26
27**Required permissions**: ohos.permission.ENTERPRISE_SET_WIFI
28
29**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
30
31
32
33**Parameters**
34
35| Name     | Type                                      | Mandatory  | Description                      |
36| -------- | ---------------------------------------- | ---- | ------------------------------- |
37| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
38| callback | AsyncCallback<boolean>            | Yes   | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is a Boolean value (**true** indicates that Wi-Fi is active; and **false** indicates that Wi-Fi is inactive). If the operation fails, **err** is an error object.      |
39
40**Error codes**
41
42For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
43
44| ID| Error Message                                                                      |
45| ------- | ---------------------------------------------------------------------------- |
46| 9200001 | The application is not an administrator application of the device.            |
47| 9200002 | The administrator application does not have permission to manage the device. |
48| 201 | Permission verification failed. The application does not have the permission required to call the API. |
49| 202 | Permission verification failed. A non-system application calls a system API. |
50| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
51
52**Example**
53
54```ts
55import { Want } from '@kit.AbilityKit';
56let wantTemp: Want = {
57  bundleName: 'com.example.myapplication',
58  abilityName: 'EntryAbility',
59};
60
61wifiManager.isWifiActive(wantTemp, (err, result) => {
62  if (err) {
63    console.error(`Failed to query is wifi active or not. Code: ${err.code}, message: ${err.message}`);
64    return;
65  }
66  console.info(`Succeeded in query is wifi active or not, result : ${result}`);
67});
68```
69
70## wifiManager.isWifiActive
71
72isWifiActive(admin: Want): Promise<boolean>
73
74Checks whether Wi-Fi is active through the specified device administrator application. This API uses a promise to return the result.
75
76**Required permissions**: ohos.permission.ENTERPRISE_SET_WIFI
77
78**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
79
80
81
82**Parameters**
83
84| Name  | Type                                 | Mandatory  | Description     |
85| ----- | ----------------------------------- | ---- | ------- |
86| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes   | Device administrator application.|
87
88**Return value**
89
90| Type                  | Description                     |
91| --------------------- | ------------------------- |
92| Promise<boolean> | Promise used to return the result. The value **true** indicates that Wi-Fi is active, and the value **false** indicates that Wi-Fi is inactive. |
93
94**Error codes**
95
96For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
97
98| ID| Error Message                                                                    |
99| ------- | ---------------------------------------------------------------------------- |
100| 9200001 | The application is not an administrator application of the device.            |
101| 9200002 | The administrator application does not have permission to manage the device. |
102| 201 | Permission verification failed. The application does not have the permission required to call the API. |
103| 202 | Permission verification failed. A non-system application calls a system API. |
104| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
105
106**Example**
107
108```ts
109import { Want } from '@kit.AbilityKit';
110import { BusinessError } from '@kit.BasicServicesKit';
111let wantTemp: Want = {
112  bundleName: 'com.example.myapplication',
113  abilityName: 'EntryAbility',
114};
115
116wifiManager.isWifiActive(wantTemp).then((result) => {
117  console.info(`Succeeded in query is wifi active or not, result : ${result}`);
118}).catch((err: BusinessError) => {
119  console.error(`Failed to query is wifi active or not. Code: ${err.code}, message: ${err.message}`);
120});
121```
122
123## wifiManager.setWifiProfile
124
125setWifiProfile(admin: Want, profile: WifiProfile, callback: AsyncCallback<void>): void
126
127Sets Wi-Fi profile through the specified device administrator application to enable the device to connect to the specified network. This API uses an asynchronous callback to return the result.
128
129**Required permissions**: ohos.permission.ENTERPRISE_SET_WIFI
130
131**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
132
133
134
135**Parameters**
136
137| Name     | Type                                      | Mandatory  | Description                      |
138| -------- | ---------------------------------------- | ---- | ------------------------------- |
139| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
140| profile    | [WifiProfile](js-apis-enterprise-wifiManager.md#wifiprofile) | Yes   | Wi-Fi profile information.                 |
141| callback | AsyncCallback<void>            | Yes   | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.     |
142
143**Error codes**
144
145For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
146
147| ID| Error Message                                                                      |
148| ------- | ---------------------------------------------------------------------------- |
149| 9200001 | The application is not an administrator application of the device.            |
150| 9200002 | The administrator application does not have permission to manage the device. |
151| 201 | Permission verification failed. The application does not have the permission required to call the API. |
152| 202 | Permission verification failed. A non-system application calls a system API. |
153| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
154
155**Example**
156
157```ts
158import { Want } from '@kit.AbilityKit';
159let wantTemp: Want = {
160  bundleName: 'com.example.myapplication',
161  abilityName: 'EntryAbility',
162};
163let profile: wifiManager.WifiProfile = {
164  'ssid': 'name',
165  'preSharedKey': 'passwd',
166  'securityType': wifiManager.WifiSecurityType.WIFI_SEC_TYPE_PSK
167};
168
169wifiManager.setWifiProfile(wantTemp, profile, (err) => {
170  if (err) {
171    console.error(`Failed to set wifi profile. Code: ${err.code}, message: ${err.message}`);
172    return;
173  }
174  console.info('Succeeded in setting wifi profile');
175});
176```
177
178## wifiManager.setWifiProfile
179
180setWifiProfile(admin: Want, profile: WifiProfile): Promise<void>
181
182Sets Wi-Fi profile through the specified device administrator application to enable the device to connect to the specified network. This API uses a promise to return the result.
183
184**Required permissions**: ohos.permission.ENTERPRISE_SET_WIFI
185
186**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
187
188
189
190**Parameters**
191
192| Name  | Type                                 | Mandatory  | Description     |
193| ----- | ----------------------------------- | ---- | ------- |
194| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes   | Device administrator application.|
195| profile    | [WifiProfile](js-apis-enterprise-wifiManager.md#wifiprofile) | Yes   | Wi-Fi profile information.                 |
196
197**Return value**
198
199| Type                  | Description                     |
200| --------------------- | ------------------------- |
201| Promise<void> | Promise that returns no value. If the operation fails, an error object will be thrown.|
202
203**Error codes**
204
205For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
206
207| ID| Error Message                                                                    |
208| ------- | ---------------------------------------------------------------------------- |
209| 9200001 | The application is not an administrator application of the device.            |
210| 9200002 | The administrator application does not have permission to manage the device. |
211| 201 | Permission verification failed. The application does not have the permission required to call the API. |
212| 202 | Permission verification failed. A non-system application calls a system API. |
213| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
214
215**Example**
216
217```ts
218import { Want } from '@kit.AbilityKit';
219import { BusinessError } from '@kit.BasicServicesKit';
220let wantTemp: Want = {
221  bundleName: 'com.example.myapplication',
222  abilityName: 'EntryAbility',
223};
224let profile: wifiManager.WifiProfile = {
225  'ssid': 'name',
226  'preSharedKey': 'passwd',
227  'securityType': wifiManager.WifiSecurityType.WIFI_SEC_TYPE_PSK
228};
229
230wifiManager.setWifiProfile(wantTemp, profile).then(() => {
231  console.info('Succeeded in setting wifi profile');
232}).catch((err: BusinessError) => {
233  console.error(`Failed to set wifi profile. Code: ${err.code}, message: ${err.message}`);
234});
235```
236
237## wifiManager.isWifiDisabled<sup>11+</sup>
238
239isWifiDisabled(admin: Want): boolean
240
241Checks whether Wi-Fi is disabled through the specified device administrator application.
242
243**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_WIFI
244
245**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
246
247**System API**: This is a system API.
248
249**Parameters**
250
251| Name  | Type                                 | Mandatory  | Description     |
252| ----- | ----------------------------------- | ---- | ------- |
253| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes   | Device administrator application.|
254
255**Return value**
256
257| Type                  | Description                     |
258| --------------------- | ------------------------- |
259| boolean | Returns **true** if Wi-Fi is disabled; returns **false** otherwise.|
260
261**Error codes**
262
263For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
264
265| ID| Error Message                                                                    |
266| ------- | ---------------------------------------------------------------------------- |
267| 9200001 | The application is not an administrator application of the device.            |
268| 9200002 | The administrator application does not have permission to manage the device. |
269| 201 | Permission verification failed. The application does not have the permission required to call the API. |
270| 202 | Permission verification failed. A non-system application calls a system API. |
271| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
272
273**Example**
274
275```ts
276import { Want } from '@kit.AbilityKit';
277let wantTemp: Want = {
278  bundleName: 'com.example.myapplication',
279  abilityName: 'EntryAbility',
280};
281try {
282  let result: boolean = wifiManager.isWifiDisabled(wantTemp);
283  console.info(`Succeeded in query the wifi is disabled or not, result : ${result}`);
284} catch (err) {
285  console.error(`Failed to query the wifi is disabled or not. Code: ${err.code}, message: ${err.message}`);
286};
287```
288
289## wifiManager.setWifiDisabled<sup>11+</sup>
290
291setWifiDisabled(admin: Want, disabled: boolean): void
292
293Sets the Wi-Fi policy through the specified device administrator application.
294
295**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_WIFI
296
297**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
298
299**System API**: This is a system API.
300
301**Parameters**
302
303| Name    | Type                               | Mandatory| Description                                     |
304| ---------- | ----------------------------------- | ---- | ----------------------------------------- |
305| admin      | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes  | Device administrator application.                           |
306| disabled   | boolean                             | Yes  | Whether to disable Wi-Fi. The value **true** means to disable Wi-Fi; the value **false** means the opposite.|
307
308**Error codes**
309
310For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
311
312| ID| Error Message                                                    |
313| -------- | ------------------------------------------------------------ |
314| 9200001  | The application is not an administrator application of the device. |
315| 9200002  | The administrator application does not have permission to manage the device. |
316| 201      | Permission verification failed. The application does not have the permission required to call the API. |
317| 202      | Permission verification failed. A non-system application calls a system API. |
318| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
319
320**Example**
321
322```ts
323import { Want } from '@kit.AbilityKit';
324let wantTemp: Want = {
325  bundleName: 'com.example.myapplication',
326  abilityName: 'EntryAbility',
327};
328
329try {
330  wifiManager.setWifiDisabled(wantTemp, true);
331  console.info('Succeeded in set the wifi disabled');
332} catch (err) {
333  console.error(`Failed to set the wifi disabled. Code: ${err.code}, message: ${err.message}`);
334};
335```
336