• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.enterprise.wifiManager(WiFi管理)
2
3本模块提供企业设备WiFi管理能力,包括查询WiFi开启状态等。
4
5> **说明:**
6>
7> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8>
9> 本模块接口仅可在Stage模型下使用。
10>
11> 本模块接口仅对[设备管理应用](enterpriseDeviceManagement-overview.md#基本概念)开放,需将[设备管理应用激活](js-apis-enterprise-adminManager.md#adminmanagerenableadmin)后调用,实现相应功能。
12
13## 导入模块
14
15```ts
16import wifiManager from '@ohos.enterprise.wifiManager';
17```
18
19## wifiManager.isWifiActive
20
21isWifiActive(admin: Want, callback: AsyncCallback<boolean>): void
22
23指定设备管理应用查询wifi开启状态。使用callback异步回调。
24
25**需要权限:** ohos.permission.ENTERPRISE_SET_WIFI
26
27**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
28
29**系统API**: 此接口为系统接口。
30
31**参数:**
32
33| 参数名      | 类型                                       | 必填   | 说明                       |
34| -------- | ---------------------------------------- | ---- | ------------------------------- |
35| admin    | [Want](js-apis-app-ability-want.md)     | 是    | 设备管理应用。                  |
36| callback | AsyncCallback<boolean>            | 是    | 回调函数,当接口调用成功,err为null,data为boolean值,true表示wifi开启,false表示wifi关闭,否则err为错误对象。       |
37
38**错误码**:
39
40以下的错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
41
42| 错误码ID | 错误信息                                                                       |
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**示例:**
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
69指定设备管理应用获取wifi开启状态。使用Promise异步回调。
70
71**需要权限:** ohos.permission.ENTERPRISE_SET_WIFI
72
73**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
74
75**系统API**: 此接口为系统接口。
76
77**参数:**
78
79| 参数名   | 类型                                  | 必填   | 说明      |
80| ----- | ----------------------------------- | ---- | ------- |
81| admin | [Want](js-apis-app-ability-want.md) | 是    | 设备管理应用。 |
82
83**返回值:**
84
85| 类型                   | 说明                      |
86| --------------------- | ------------------------- |
87| Promise<boolean> | Promise结果,返回wifi开启状态,true表示wifi开启,false表示wifi关闭。  |
88
89**错误码**:
90
91以下的错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
92
93| 错误码ID | 错误信息                                                                     |
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**示例:**
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
119指定设备管理应用为设备配置wifi,使连接到指定网络。使用callback异步回调。
120
121**需要权限:** ohos.permission.ENTERPRISE_SET_WIFI
122
123**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
124
125**系统API**: 此接口为系统接口。
126
127**参数:**
128
129| 参数名      | 类型                                       | 必填   | 说明                       |
130| -------- | ---------------------------------------- | ---- | ------------------------------- |
131| admin    | [Want](js-apis-app-ability-want.md)     | 是    | 设备管理应用。                  |
132| profile    | [WifiProfile](#wifiprofile)     | 是    | WLAN配置信息。                  |
133| callback | AsyncCallback<void>            | 是    | 回调函数,当接口调用成功,err为null,否则为错误对象。      |
134
135**错误码**:
136
137以下的错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
138
139| 错误码ID | 错误信息                                                                       |
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**示例:**
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
171指定设备管理应用为设备配置wifi,使连接到指定网络。使用Promise异步回调。
172
173**需要权限:** ohos.permission.ENTERPRISE_SET_WIFI
174
175**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
176
177**系统API**: 此接口为系统接口。
178
179**参数:**
180
181| 参数名   | 类型                                  | 必填   | 说明      |
182| ----- | ----------------------------------- | ---- | ------- |
183| admin | [Want](js-apis-app-ability-want.md) | 是    | 设备管理应用。 |
184| profile    | [WifiProfile](#wifiprofile)     | 是    | WLAN配置信息。                  |
185
186**返回值:**
187
188| 类型                   | 说明                      |
189| --------------------- | ------------------------- |
190| Promise<void> | 无返回结果的Promise对象。当配置wifi连接到指定网络失败时会抛出错误对象。 |
191
192**错误码**:
193
194以下的错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
195
196| 错误码ID | 错误信息                                                                     |
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**示例:**
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
225WLAN配置信息
226
227**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
228
229**系统API**: 此接口为系统接口。
230
231| 名称         | 类型     | 可读 | 可写   | 说明                            |
232| ----------- | --------| ---- | ----- | ------------------------------- |
233| ssid | string | 是 | 否 | 热点的SSID,编码格式为UTF-8。 |
234| bssid | string | 是 | 否 | 热点的BSSID。 |
235| preSharedKey | string | 是 | 否 | 热点的密钥。 |
236| isHiddenSsid | boolean | 是 | 否 | 是否是隐藏网络。 |
237| securityType | [WifiSecurityType](#wifisecuritytype) | 是 | 否 | 加密类型。 |
238| creatorUid | number | 是 | 否 | 创建用户的ID。 |
239| disableReason | number | 是 | 否 | 禁用原因。 |
240| netId | number | 是 | 否 | 分配的网络ID。 |
241| randomMacType | number | 是 | 否 | 随机MAC类型 |
242| randomMacAddr | string | 是 | 否 | 随机MAC地址 |
243| ipType | [IpType](#iptype) | 是 | 否 | IP地址类型 |
244| staticIp | [IpProfile](#ipprofile) | 是 | 否 | 静态IP配置信息。 |
245| eapProfile | [WifiEapProfile](#wifieapprofile) | 是 | 否 | 可扩展身份验证协议配置。 |
246
247## WifiSecurityType
248
249表示加密类型的枚举。
250
251**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
252
253**系统API**: 此接口为系统接口。
254
255| 名称 | 值 | 说明 |
256| -------- | -------- | -------- |
257| WIFI_SEC_TYPE_INVALID | 0 | 无效加密类型。 |
258| WIFI_SEC_TYPE_OPEN | 1 | 开放加密类型。 |
259| WIFI_SEC_TYPE_WEP | 2 | Wired Equivalent Privacy (WEP)加密类型。 |
260| WIFI_SEC_TYPE_PSK | 3 | Pre-shared key (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位加密类型。 |
264| WIFI_SEC_TYPE_OWE | 7 | 机会性无线加密类型。 |
265| WIFI_SEC_TYPE_WAPI_CERT | 8 | WAPI-Cert加密类型。 |
266| WIFI_SEC_TYPE_WAPI_PSK | 9 | WAPI-PSK加密类型。 |
267
268## IpType
269
270表示IP类型的枚举。
271
272**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
273
274**系统API**: 此接口为系统接口。
275
276| 名称 | 值 | 说明 |
277| -------- | -------- | -------- |
278| STATIC | 0 | 静态IP。 |
279| DHCP | 1 | 通过DHCP获取。 |
280| UNKNOWN | 2 | 未指定。 |
281
282## IpProfile
283
284IP配置信息。
285
286**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
287
288**系统API**: 此接口为系统接口。
289
290| 名称 | 类型 | 可读 | 可写 | 说明 |
291| -------- | -------- | -------- | -------- | -------- |
292| ipAddress | number | 是 | 否 | IP地址。 |
293| gateway | number | 是 | 否 | 网关。 |
294| prefixLength | number | 是 | 否 | 掩码。 |
295| dnsServers | number[] | 是 | 否 | DNS服务器。 |
296| domains | Array<string> | 是 | 否 | 域信息。 |
297
298## WifiEapProfile
299
300可扩展身份验证协议配置信息。
301
302**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
303
304**系统API**: 此接口为系统接口。
305
306| **名称** | **类型** | **可读** | **可写** | **说明** |
307| -------- | -------- | -------- | -------- | -------- |
308| eapMethod | [EapMethod](#eapmethod) | 是 | 否 | EAP认证方式。 |
309| phase2Method | [Phase2Method](#phase2method) | 是 | 否 | 第二阶段认证方式。 |
310| identity | string | 是 | 否 | 身份信息。 |
311| anonymousIdentity | string | 是 | 否 | 匿名身份。 |
312| password | string | 是 | 否 | 密码。 |
313| caCertAliases | string | 是 | 否 | CA 证书别名。 |
314| caPath | string | 是 | 否 | CA 证书路径。 |
315| clientCertAliases | string | 是 | 否 | 客户端证书别名。 |
316| certEntry | Uint8Array | 是 | 是 | CA 证书内容。 |
317| certPassword | string | 是 | 是 | CA证书密码。 |
318| altSubjectMatch | string | 是 | 否 | 替代主题匹配。 |
319| domainSuffixMatch | string | 是 | 否 | 域后缀匹配。 |
320| realm | string | 是 | 否 | 通行证凭证的领域。 |
321| plmn | string | 是 | 否 | 公共陆地移动网的直通凭证提供商。 |
322| eapSubId | number | 是 | 否 | SIM卡的子ID。 |
323
324## EapMethod
325
326表示EAP认证方式的枚举。
327
328**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
329
330**系统API**: 此接口为系统接口。
331
332| 名称 | 值 | 说明 |
333| -------- | -------- | -------- |
334| EAP_NONE | 0 | 不指定。 |
335| EAP_PEAP | 1 | PEAP类型。 |
336| EAP_TLS | 2 | TLS类型。 |
337| EAP_TTLS | 3 | TTLS类型。 |
338| EAP_PWD | 4 | PWD类型。 |
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
347表示第二阶段认证方式的枚举。
348
349**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
350
351**系统API**: 此接口为系统接口。
352
353| 名称 | 值 | 说明 |
354| -------- | -------- | -------- |
355| PHASE2_NONE | 0 | 不指定。 |
356| PHASE2_PAP | 1 | PAP类型。 |
357| PHASE2_MSCHAP | 2 | MSCHAP类型。 |
358| PHASE2_MSCHAPV2 | 3 | MSCHAPV2类型。 |
359| PHASE2_GTC | 4 | GTC类型。 |
360| PHASE2_SIM | 5 | SIM类型。 |
361| PHASE2_AKA | 6 | AKA类型。 |
362| PHASE2_AKA_PRIME | 7 | AKA Prime类型。 |
363