harmony 鸿蒙@ohos.enterprise.wifiManager (Wi-Fi Management)

2023-06-24 浏览 (628)

@ohos.enterprise.wifiManager (Wi-Fi Management)

The wifiManager module provides APIs for Wi-Fi management of enterprise devices.

NOTE

  • 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.

  • The APIs of this module can be used only in the stage model.

  • The APIs provided by this module can be called only by a device administrator application that is enabled.

Modules to Import

import wifiManager from '@ohos.enterprise.wifiManager';

wifiManager.isWifiActive

isWifiActive(admin: Want, callback: AsyncCallback<boolean>): void

Checks whether Wi-Fi is active through the specified device administrator application. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.ENTERPRISE_SET_WIFI

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application.
callbackAsyncCallback<boolean>YesCallback 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.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes.

IDError Message
9200001the application is not an administrator of the device.
9200002the administrator application does not have permission to manage the device.

Example

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

wifiManager.isWifiActive(wantTemp, (err, result) => {
  if (err) {
    console.error(`Failed to query is wifi active or not. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info(`Succeeded in query is wifi active or not, result : ${result}`);
});

wifiManager.isWifiActive

isWifiActive(admin: Want): Promise<boolean>

Checks whether Wi-Fi is active through the specified device administrator application. This API uses a promise to return the result.

Required permissions: ohos.permission.ENTERPRISE_SET_WIFI

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application.

Return value

TypeDescription
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.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes.

IDError Message
9200001the application is not an administrator of the device.
9200002the administrator application does not have permission to manage the device.

Example

import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

wifiManager.isWifiActive(wantTemp).then((result) => {
  console.info(`Succeeded in query is wifi active or not, result : ${result}`);
}).catch((err: BusinessError) => {
  console.error(`Failed to query is wifi active or not. Code: ${err.code}, message: ${err.message}`);
});

wifiManager.setWifiProfile

setWifiProfile(admin: Want, profile: WifiProfile, callback: AsyncCallback<void>): void

Sets 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.

Required permissions: ohos.permission.ENTERPRISE_SET_WIFI

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application.
profileWifiProfileYesWi-Fi profile information.
callbackAsyncCallback<void>YesCallback invoked to return the result. If the operation is successful, err is null. Otherwise, err is an error object.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes.

IDError Message
9200001the application is not an administrator of the device.
9200002the administrator application does not have permission to manage the device.

Example

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let profile: wifiManager.WifiProfile = {
  'ssid': 'name',
  'preSharedKey': 'passwd',
  'securityType': wifiManager.WifiSecurityType.WIFI_SEC_TYPE_PSK
};

wifiManager.setWifiProfile(wantTemp, profile, (err) => {
  if (err) {
    console.error(`Failed to set wifi profile. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info('Succeeded in setting wifi profile');
});

wifiManager.setWifiProfile

setWifiProfile(admin: Want, profile: WifiProfile): Promise<void>

Sets 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.

Required permissions: ohos.permission.ENTERPRISE_SET_WIFI

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application.
profileWifiProfileYesWi-Fi profile information.

Return value

TypeDescription
Promise<void>Promise that returns no value. If the operation fails, an error object will be thrown.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes.

IDError Message
9200001the application is not an administrator of the device.
9200002the administrator application does not have permission to manage the device.

Example

import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let profile: wifiManager.WifiProfile = {
  'ssid': 'name',
  'preSharedKey': 'passwd',
  'securityType': wifiManager.WifiSecurityType.WIFI_SEC_TYPE_PSK
};

wifiManager.setWifiProfile(wantTemp, profile).then(() => {
  console.info('Succeeded in setting wifi profile');
}).catch((err: BusinessError) => {
  console.error(`Failed to set wifi profile. Code: ${err.code}, message: ${err.message}`);
});

WifiProfile

Represents the Wi-Fi profile information.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

NameTypeReadableWritableDescription
ssidstringYesNoService set identifier (SSID) of the hotspot, in UTF-8 format.
bssidstringYesNoBasic service set identifier (BSSID) of the hotspot.
preSharedKeystringYesNoPre-shared key (PSK) of the hotspot.
isHiddenSsidbooleanYesNoWhether the network is hidden.
securityTypeWifiSecurityTypeYesNoSecurity type.
creatorUidnumberYesNoID of the creator.
disableReasonnumberYesNoReason for disabling Wi-Fi.
netIdnumberYesNoNetwork ID allocated.
randomMacTypenumberYesNoType of the random MAC.
randomMacAddrstringYesNoRandom MAC address.
ipTypeIpTypeYesNoIP address type.
staticIpIpProfileYesNoStatic IP address information.
eapProfileWifiEapProfileYesNoExtensible Authentication Protocol (EAP) configuration.

WifiSecurityType

Enumerates the Wi-Fi security types.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

NameValueDescription
WIFI_SEC_TYPE_INVALID0Invalid security type.
WIFI_SEC_TYPE_OPEN1Open security type.
WIFI_SEC_TYPE_WEP2Wired Equivalent Privacy (WEP).
WIFI_SEC_TYPE_PSK3PSK.
WIFI_SEC_TYPE_SAE4Simultaneous Authentication of Equals (SAE).
WIFI_SEC_TYPE_EAP5EAP.
WIFI_SEC_TYPE_EAP_SUITE_B6Suite B 192-bit encryption.
WIFI_SEC_TYPE_OWE7Opportunistic Wireless Encryption (OWE).
WIFI_SEC_TYPE_WAPI_CERT8WLAN Authentication and Privacy Infrastructure (WAPI) in certificate-based mode (WAPI-CERT).
WIFI_SEC_TYPE_WAPI_PSK9WAPI-PSK.

IpType

Enumerates the IP address types.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

NameValueDescription
STATIC0Static IP address.
DHCP1IP address allocated by DHCP.
UNKNOWN2Not specified.

IpProfile

Represents IP configuration information.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

NameTypeReadableWritableDescription
ipAddressnumberYesNoIP address.
gatewaynumberYesNoGateway.
prefixLengthnumberYesNoSubnet mask.
dnsServersnumber[]YesNoDomain name server (DNS) information.
domainsArray<string>YesNoDomain information.

WifiEapProfile

Represents EAP profile (configuration) information.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

NameTypeReadableWritableDescription
eapMethodEapMethodYesNoEAP authentication method.
phase2MethodPhase2MethodYesNoPhase 2 authentication method.
identitystringYesNoIdentity Information.
anonymousIdentitystringYesNoAnonymous identity.
passwordstringYesNoPassword.
caCertAliasesstringYesNoCA certificate alias.
caPathstringYesNoCA certificate path.
clientCertAliasesstringYesNoClient certificate alias.
certEntryUint8ArrayYesYesCA certificate content.
certPasswordstringYesYesCA certificate password.
altSubjectMatchstringYesNoA string to match the alternate subject.
domainSuffixMatchstringYesNoA string to match the domain suffix.
realmstringYesNoRealm for the passpoint credential.
plmnstringYesNoPublic land mobile network (PLMN) of the passpoint credential provider.
eapSubIdnumberYesNoSub-ID of the SIM card.

EapMethod

Enumerates the EAP authentication methods.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

NameValueDescription
EAP_NONE0Not specified.
EAP_PEAP1PEAP.
EAP_TLS2TLS.
EAP_TTLS3TTLS.
EAP_PWD4Password.
EAP_SIM5SIM.
EAP_AKA6AKA.
EAP_AKA_PRIME7AKA Prime.
EAP_UNAUTH_TLS8UNAUTH TLS.

Phase2Method

Enumerates the Phase 2 authentication methods.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

NameValueDescription
PHASE2_NONE0Not specified.
PHASE2_PAP1PAP.
PHASE2_MSCHAP2MS-CHAP.
PHASE2_MSCHAPV23MS-CHAPv2.
PHASE2_GTC4GTC .
PHASE2_SIM5SIM.
PHASE2_AKA6AKA.
PHASE2_AKA_PRIME7AKA Prime.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/1d6274e1f71e498eb572a1c24d358f31