• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.enterprise.wifiManager (Wi-Fi Management)
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 provided by this module can be called only by a [device administrator application](enterpriseDeviceManagement-overview.md#basic-concepts) that is [enabled](js-apis-enterprise-adminManager.md#adminmanagerenableadmin).
12
13## Modules to Import
14
15```ts
16import wifiManager from '@ohos.enterprise.wifiManager';
17```
18
19## wifiManager.isWifiActive
20
21isWifiActive(admin: Want, callback: AsyncCallback<boolean>): void
22
23Checks whether Wi-Fi is active through the specified device administrator application. This API uses an asynchronous callback to return the result.
24
25**Required permissions**: ohos.permission.ENTERPRISE_SET_WIFI
26
27**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
28
29**System API**: This is a system API.
30
31**Parameters**
32
33| Name     | Type                                      | Mandatory  | Description                      |
34| -------- | ---------------------------------------- | ---- | ------------------------------- |
35| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
36| callback | AsyncCallback<boolean>            | Yes   | Callback invoked 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.      |
37
38**Error codes**
39
40For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
41
42| ID| Error Message                                                                      |
43| ------- | ---------------------------------------------------------------------------- |
44| 9200001 | the application is not an administrator of the device.                        |
45| 9200002 | the administrator application does not have permission to manage the device. |
46
47**Example**
48
49```ts
50import Want from '@ohos.app.ability.Want';
51let wantTemp: Want = {
52  bundleName: 'com.example.myapplication',
53  abilityName: 'EntryAbility',
54};
55
56wifiManager.isWifiActive(wantTemp, (err, result) => {
57  if (err) {
58    console.error(`Failed to query is wifi active or not. Code: ${err.code}, message: ${err.message}`);
59    return;
60  }
61  console.info(`Succeeded in query is wifi active or not, result : ${result}`);
62});
63```
64
65## wifiManager.isWifiActive
66
67isWifiActive(admin: Want): Promise<boolean>
68
69Checks whether Wi-Fi is active through the specified device administrator application. This API uses a promise to return the result.
70
71**Required permissions**: ohos.permission.ENTERPRISE_SET_WIFI
72
73**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
74
75**System API**: This is a system API.
76
77**Parameters**
78
79| Name  | Type                                 | Mandatory  | Description     |
80| ----- | ----------------------------------- | ---- | ------- |
81| admin | [Want](js-apis-app-ability-want.md) | Yes   | Device administrator application.|
82
83**Return value**
84
85| Type                  | Description                     |
86| --------------------- | ------------------------- |
87| 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. |
88
89**Error codes**
90
91For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
92
93| ID| Error Message                                                                    |
94| ------- | ---------------------------------------------------------------------------- |
95| 9200001 | the application is not an administrator of the device.                        |
96| 9200002 | the administrator application does not have permission to manage the device. |
97
98**Example**
99
100```ts
101import Want from '@ohos.app.ability.Want';
102import { BusinessError } from '@ohos.base';
103let wantTemp: Want = {
104  bundleName: 'com.example.myapplication',
105  abilityName: 'EntryAbility',
106};
107
108wifiManager.isWifiActive(wantTemp).then((result) => {
109  console.info(`Succeeded in query is wifi active or not, result : ${result}`);
110}).catch((err: BusinessError) => {
111  console.error(`Failed to query is wifi active or not. Code: ${err.code}, message: ${err.message}`);
112});
113```
114
115## wifiManager.setWifiProfile
116
117setWifiProfile(admin: Want, profile: WifiProfile, callback: AsyncCallback<void>): void
118
119Sets 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.
120
121**Required permissions**: ohos.permission.ENTERPRISE_SET_WIFI
122
123**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
124
125**System API**: This is a system API.
126
127**Parameters**
128
129| Name     | Type                                      | Mandatory  | Description                      |
130| -------- | ---------------------------------------- | ---- | ------------------------------- |
131| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
132| profile    | [WifiProfile](#wifiprofile)     | Yes   | Wi-Fi profile information.                 |
133| callback | AsyncCallback<void>            | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.     |
134
135**Error codes**
136
137For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
138
139| ID| Error Message                                                                      |
140| ------- | ---------------------------------------------------------------------------- |
141| 9200001 | the application is not an administrator of the device.                        |
142| 9200002 | the administrator application does not have permission to manage the device. |
143
144**Example**
145
146```ts
147import Want from '@ohos.app.ability.Want';
148let wantTemp: Want = {
149  bundleName: 'com.example.myapplication',
150  abilityName: 'EntryAbility',
151};
152let profile: wifiManager.WifiProfile = {
153  'ssid': 'name',
154  'preSharedKey': 'passwd',
155  'securityType': wifiManager.WifiSecurityType.WIFI_SEC_TYPE_PSK
156};
157
158wifiManager.setWifiProfile(wantTemp, profile, (err) => {
159  if (err) {
160    console.error(`Failed to set wifi profile. Code: ${err.code}, message: ${err.message}`);
161    return;
162  }
163  console.info('Succeeded in setting wifi profile');
164});
165```
166
167## wifiManager.setWifiProfile
168
169setWifiProfile(admin: Want, profile: WifiProfile): Promise<void>
170
171Sets 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.
172
173**Required permissions**: ohos.permission.ENTERPRISE_SET_WIFI
174
175**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
176
177**System API**: This is a system API.
178
179**Parameters**
180
181| Name  | Type                                 | Mandatory  | Description     |
182| ----- | ----------------------------------- | ---- | ------- |
183| admin | [Want](js-apis-app-ability-want.md) | Yes   | Device administrator application.|
184| profile    | [WifiProfile](#wifiprofile)     | Yes   | Wi-Fi profile information.                 |
185
186**Return value**
187
188| Type                  | Description                     |
189| --------------------- | ------------------------- |
190| Promise<void> | Promise that returns no value. If the operation fails, an error object will be thrown.|
191
192**Error codes**
193
194For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
195
196| ID| Error Message                                                                    |
197| ------- | ---------------------------------------------------------------------------- |
198| 9200001 | the application is not an administrator of the device.                        |
199| 9200002 | the administrator application does not have permission to manage the device. |
200
201**Example**
202
203```ts
204import Want from '@ohos.app.ability.Want';
205import { BusinessError } from '@ohos.base';
206let wantTemp: Want = {
207  bundleName: 'com.example.myapplication',
208  abilityName: 'EntryAbility',
209};
210let profile: wifiManager.WifiProfile = {
211  'ssid': 'name',
212  'preSharedKey': 'passwd',
213  'securityType': wifiManager.WifiSecurityType.WIFI_SEC_TYPE_PSK
214};
215
216wifiManager.setWifiProfile(wantTemp, profile).then(() => {
217  console.info('Succeeded in setting wifi profile');
218}).catch((err: BusinessError) => {
219  console.error(`Failed to set wifi profile. Code: ${err.code}, message: ${err.message}`);
220});
221```
222
223## WifiProfile
224
225Represents the Wi-Fi profile information.
226
227**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
228
229**System API**: This is a system API.
230
231| Name        | Type    | Mandatory|    Description                           |
232| ----------- | --------| ---- |  ------------------------------- |
233| ssid | string | Yes| Service set identifier (SSID) of the hotspot, in UTF-8 format.|
234| bssid | string | No| Basic service set identifier (BSSID) of the hotspot.|
235| preSharedKey | string | Yes| Pre-shared key (PSK) of the hotspot.|
236| isHiddenSsid | boolean | No| Whether the network is hidden.|
237| securityType | [WifiSecurityType](#wifisecuritytype) | Yes| Security type.|
238| creatorUid | number | No|ID of the creator.|
239| disableReason | number | No| Reason for disabling Wi-Fi.|
240| netId | number | No|Network ID allocated.|
241| randomMacType | number | No| Type of the random MAC.|
242| randomMacAddr | string | No|Random MAC address.|
243| ipType | [IpType](#iptype) | No|  IP address type.|
244| staticIp | [IpProfile](#ipprofile) | No|  Static IP address information.|
245| eapProfile | [WifiEapProfile](#wifieapprofile) | No|Extensible Authentication Protocol (EAP) configuration.|
246
247## WifiSecurityType
248
249Enumerates the Wi-Fi security types.
250
251**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
252
253**System API**: This is a system API.
254
255| Name| Value| Description|
256| -------- | -------- | -------- |
257| WIFI_SEC_TYPE_INVALID | 0 | Invalid security type.|
258| WIFI_SEC_TYPE_OPEN | 1 | Open security type.|
259| WIFI_SEC_TYPE_WEP | 2 | Wired Equivalent Privacy (WEP).|
260| WIFI_SEC_TYPE_PSK | 3 | PSK.|
261| WIFI_SEC_TYPE_SAE | 4 | Simultaneous Authentication of Equals (SAE).|
262| WIFI_SEC_TYPE_EAP | 5 | EAP.|
263| WIFI_SEC_TYPE_EAP_SUITE_B | 6 | Suite B 192-bit encryption.|
264| WIFI_SEC_TYPE_OWE | 7 | Opportunistic Wireless Encryption (OWE).|
265| WIFI_SEC_TYPE_WAPI_CERT | 8 | WLAN Authentication and Privacy Infrastructure (WAPI) in certificate-based mode (WAPI-CERT).|
266| WIFI_SEC_TYPE_WAPI_PSK | 9 | WAPI-PSK.|
267
268## IpType
269
270Enumerates the IP address types.
271
272**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
273
274**System API**: This is a system API.
275
276| Name| Value| Description|
277| -------- | -------- | -------- |
278| STATIC | 0 | Static IP address.|
279| DHCP | 1 | IP address allocated by DHCP.|
280| UNKNOWN | 2 | Not specified.|
281
282## IpProfile
283
284Represents IP configuration information.
285
286**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
287
288**System API**: This is a system API.
289
290| Name| Type| Mandatory| Description|
291| -------- | -------- | -------- |-------- |
292| ipAddress | number | Yes| IP address.|
293| gateway | number | Yes|Gateway.|
294| prefixLength | number | Yes| Subnet mask.|
295| dnsServers | number[] | Yes| Domain name server (DNS) information.|
296| domains | Array<string> | Yes|Domain information.|
297
298## WifiEapProfile
299
300Represents EAP profile (configuration) information.
301
302**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
303
304**System API**: This is a system API.
305
306| Name| Type| Mandatory| Description|
307| -------- | -------- | -------- | -------- |
308| eapMethod | [EapMethod](#eapmethod) | Yes|EAP authentication method.|
309| phase2Method | [Phase2Method](#phase2method) | Yes| Phase 2 authentication method.|
310| identity | string | Yes| Identity Information.|
311| anonymousIdentity | string | Yes|  Anonymous identity.|
312| password | string | Yes|  Password (string type).|
313| caCertAliases | string | Yes| CA certificate alias.|
314| caPath | string | Yes| CA certificate path.|
315| clientCertAliases | string | Yes| Client certificate alias.|
316| certEntry | Uint8Array | Yes| CA certificate content.|
317| certPassword | string | Yes|CA certificate password.|
318| altSubjectMatch | string | Yes| A string to match the alternate subject.|
319| domainSuffixMatch | string | Yes|A string to match the domain suffix.|
320| realm | string | Yes| Realm for the passpoint credential.|
321| plmn | string | Yes| Public land mobile network (PLMN) of the passpoint credential provider.|
322| eapSubId | number | Yes| Sub-ID of the SIM card.|
323
324## EapMethod
325
326Enumerates the EAP authentication methods.
327
328**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
329
330**System API**: This is a system API.
331
332| Name| Value| Description|
333| -------- | -------- | -------- |
334| EAP_NONE | 0 | Not specified.|
335| EAP_PEAP | 1 | PEAP.|
336| EAP_TLS | 2 | TLS.|
337| EAP_TTLS | 3 | TTLS.|
338| EAP_PWD | 4 | Password.|
339| EAP_SIM | 5 | SIM.|
340| EAP_AKA | 6 | AKA.|
341| EAP_AKA_PRIME | 7 | AKA Prime.|
342| EAP_UNAUTH_TLS | 8 | UNAUTH TLS.|
343
344
345## Phase2Method
346
347Enumerates the Phase 2 authentication methods.
348
349**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
350
351**System API**: This is a system API.
352
353| Name| Value| Description|
354| -------- | -------- | -------- |
355| PHASE2_NONE | 0 | Not specified.|
356| PHASE2_PAP | 1 | PAP.|
357| PHASE2_MSCHAP | 2 | MS-CHAP.|
358| PHASE2_MSCHAPV2 | 3 | MS-CHAPv2.|
359| PHASE2_GTC | 4 | GTC .|
360| PHASE2_SIM | 5 | SIM.|
361| PHASE2_AKA | 6 | AKA.|
362| PHASE2_AKA_PRIME | 7 | AKA Prime.|
363
364## wifiManager.isWifiDisabled<sup>11+</sup>
365
366isWifiDisabled(admin: Want): boolean
367
368Checks whether Wi-Fi is disabled through the specified device administrator application.
369
370**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_WIFI
371
372**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
373
374**System API**: This is a system API.
375
376**Parameters**
377
378| Name  | Type                                 | Mandatory  | Description     |
379| ----- | ----------------------------------- | ---- | ------- |
380| admin | [Want](js-apis-app-ability-want.md) | Yes   | Device administrator application.|
381
382**Return value**
383
384| Type                  | Description                     |
385| --------------------- | ------------------------- |
386| boolean | Returns **true** if Wi-Fi is disabled; returns **false** otherwise.|
387
388**Error codes**
389
390For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
391
392| ID| Error Message                                                                    |
393| ------- | ---------------------------------------------------------------------------- |
394| 9200001 | the application is not an administrator of the device.                        |
395| 9200002 | the administrator application does not have permission to manage the device. |
396
397**Example**
398
399```ts
400import Want from '@ohos.app.ability.Want';
401let wantTemp: Want = {
402  bundleName: 'com.example.myapplication',
403  abilityName: 'EntryAbility',
404};
405try {
406  let result: boolean = wifiManager.isWifiDisabled(wantTemp);
407  console.info(`Succeeded in query the wifi is disabled or not, result : ${result}`);
408} catch (err) {
409  console.error(`Failed to query the wifi is disabled or not. Code: ${err.code}, message: ${err.message}`);
410};
411```
412
413## wifiManager.setWifiDisabled<sup>11+</sup>
414
415setWifiDisabled(admin: Want, isDisabled: boolean): void
416
417Sets the Wi-Fi policy through the specified device administrator application.
418
419**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_WIFI
420
421**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
422
423**System API**: This is a system API.
424
425**Parameters**
426
427| Name    | Type                               | Mandatory| Description                                     |
428| ---------- | ----------------------------------- | ---- | ----------------------------------------- |
429| admin      | [Want](js-apis-app-ability-want.md) | Yes  | Device administrator application.                           |
430| isDisabled | boolean                             | Yes  | Wi-Fi policy to set. The value **true** means to disable Wi-Fi; the value **false** means the opposite.|
431
432**Error codes**
433
434For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
435
436| ID| Error Message                                                    |
437| -------- | ------------------------------------------------------------ |
438| 9200001  | the application is not an administrator of the device.       |
439| 9200002  | the administrator application does not have permission to manage the device. |
440
441**Example**
442
443```ts
444import Want from '@ohos.app.ability.Want';
445let wantTemp: Want = {
446  bundleName: 'com.example.myapplication',
447  abilityName: 'EntryAbility',
448};
449
450try {
451  wifiManager.setWifiDisabled(wantTemp, true);
452  console.info('Succeeded in set the wifi disabled');
453} catch (err) {
454  console.error(`Failed to set the wifi disabled. Code: ${err.code}, message: ${err.message}`);
455};
456```
457