/* * Copyright (C) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { AsyncCallback, Callback } from './basic'; /** * Provides methods to operate or manage Wi-Fi. * @namespace wifiManager * @since 9 */ declare namespace wifiManager { /** * Enable Wi-Fi. * * @since 9 * @throws {BusinessError} 201 - Permission denied. * @throws {BusinessError} 202 - System API is not allowed called by Non-system application. * @throws {BusinessError} 801 - Capability not supported. * @throws {BusinessError} 2501000 - Operation failed. * @throws {BusinessError} 2501003 - Failed for wifi is closing. * @syscap SystemCapability.Communication.WiFi.STA * @permission ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION * @systemapi Hide this for inner system use. */ function enableWifi(): void; /** * Disable Wi-Fi. * * @since 9 * @throws {BusinessError} 201 - Permission denied. * @throws {BusinessError} 202 - System API is not allowed called by Non-system application. * @throws {BusinessError} 801 - Capability not supported. * @throws {BusinessError} 2501000 - Operation failed. * @throws {BusinessError} 2501004 - Failed for wifi is opening. * @syscap SystemCapability.Communication.WiFi.STA * @permission ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION * @systemapi Hide this for inner system use. */ function disableWifi(): void; /** * Query the Wi-Fi status * * @returns Returns {@code true} if the Wi-Fi is active, returns {@code false} otherwise. * * @since 9 * @throws {BusinessError} 201 - Permission denied. * @throws {BusinessError} 801 - Capability not supported. * @throws {BusinessError} 2501000 - Operation failed. * @syscap SystemCapability.Communication.WiFi.STA * @permission ohos.permission.GET_WIFI_INFO */ function isWifiActive(): boolean; /** * Scan Wi-Fi hotspot. * *
This API works in asynchronous mode.
* * @since 9 * @throws {BusinessError} 201 - Permission denied. * @throws {BusinessError} 801 - Capability not supported. * @throws {BusinessError} 2501000 - Operation failed. * @syscap SystemCapability.Communication.WiFi.STA * @permission ohos.permission.SET_WIFI_INFO and ohos.permission.LOCATION */ function scan(): void; /** * Obtain the scanned sta list. * * @returns Returns information about scanned Wi-Fi hotspot if any. * * @since 9 * @throws {BusinessError} 201 - Permission denied. * @throws {BusinessError} 801 - Capability not supported. * @throws {BusinessError} 2501000 - Operation failed. * @syscap SystemCapability.Communication.WiFi.STA * @permission ohos.permission.GET_WIFI_INFO and (ohos.permission.GET_WIFI_PEERS_MAC or ohos.permission.LOCATION) */ function getScanResults(): PromiseThe configuration will be updated when the configuration is added.
* * @param config Indicates the device configuration for connection to the Wi-Fi network. * @returns Returns {@code networkId} if the configuration is added; returns {@code -1} otherwise. * * @since 9 * @throws {BusinessError} 201 - Permission denied. * @throws {BusinessError} 202 - System API is not allowed called by Non-system application. * @throws {BusinessError} 401 - Invalid parameters. * @throws {BusinessError} 801 - Capability not supported. * @throws {BusinessError} 2501000 - Operation failed. * @syscap SystemCapability.Communication.WiFi.STA * @permission ohos.permission.SET_WIFI_INFO and ohos.permission.SET_WIFI_CONFIG * @systemapi Hide this for inner system use. */ function addDeviceConfig(config: WifiDeviceConfig): PromiseThis method adds one configuration at a time. After this configuration is added,
* your device will determine whether to connect to the hotspot.
*
* @param config - candidate config.
* @returns Returns {@code networkId} if the configuration is added; returns {@code -1} otherwise.
*
* @since 9
* @throws {BusinessError} 201 - Permission denied.
* @throws {BusinessError} 401 - Invalid parameters.
* @throws {BusinessError} 801 - Capability not supported.
* @throws {BusinessError} 2501000 - Operation failed.
* @syscap SystemCapability.Communication.WiFi.STA
* @permission ohos.permission.SET_WIFI_INFO
*/
function addCandidateConfig(config: WifiDeviceConfig): Promise You can obtain only the Wi-Fi configurations you created on your own application.
*
* @returns Returns the list of all existed Wi-Fi configurations you created on your application.
*
* @since 9
* @throws {BusinessError} 201 - Permission denied.
* @throws {BusinessError} 801 - Capability not supported.
* @throws {BusinessError} 2501000 - Operation failed.
* @syscap SystemCapability.Communication.WiFi.STA
* @permission ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION
*/
function getCandidateConfigs(): Array This method connect to a configuration at a time.
*
* @param networkId - Network ID which will be connected.
* @since 9
* @throws {BusinessError} 201 - Permission denied.
* @throws {BusinessError} 401 - Invalid parameters.
* @throws {BusinessError} 801 - Capability not supported.
* @throws {BusinessError} 2501000 - Operation failed.
* @throws {BusinessError} 2501001 - Wifi is closed.
* @syscap SystemCapability.Communication.WiFi.STA
* @permission ohos.permission.SET_WIFI_INFO
*/
function connectToCandidateConfig(networkId: number): void;
/**
* Connect to Wi-Fi hotspot by networkId.
*
* @param networkId ID of the connected network.
*
* @since 9
* @throws {BusinessError} 201 - Permission denied.
* @throws {BusinessError} 202 - System API is not allowed called by Non-system application.
* @throws {BusinessError} 401 - Invalid parameters.
* @throws {BusinessError} 801 - Capability not supported.
* @throws {BusinessError} 2501000 - Operation failed.
* @throws {BusinessError} 2501001 - Wifi is closed.
* @syscap SystemCapability.Communication.WiFi.STA
* @permission ohos.permission.MANAGE_WIFI_CONNECTION
* @systemapi Hide this for inner system use.
*/
function connectToNetwork(networkId: number): void;
/**
* Connect to Wi-Fi hotspot by WifiDeviceConfig.
*
* @param config Indicates the device configuration for connection to the Wi-Fi hotspot.
*
* @since 9
* @throws {BusinessError} 201 - Permission denied.
* @throws {BusinessError} 202 - System API is not allowed called by Non-system application.
* @throws {BusinessError} 401 - Invalid parameters.
* @throws {BusinessError} 801 - Capability not supported.
* @throws {BusinessError} 2501000 - Operation failed.
* @throws {BusinessError} 2501001 - Wifi is closed.
* @syscap SystemCapability.Communication.WiFi.STA
* @permission ohos.permission.SET_WIFI_INFO and ohos.permission.SET_WIFI_CONFIG and
* ohos.permission.MANAGE_WIFI_CONNECTION
* @systemapi Hide this for inner system use.
*/
function connectToDevice(config: WifiDeviceConfig): void;
/**
* Disconnect connection between sta and Wi-Fi hotspot.
*
* @since 9
* @throws {BusinessError} 201 - Permission denied.
* @throws {BusinessError} 202 - System API is not allowed called by Non-system application.
* @throws {BusinessError} 801 - Capability not supported.
* @throws {BusinessError} 2501000 - Operation failed.
* @syscap SystemCapability.Communication.WiFi.STA
* @permission ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION
* @systemapi Hide this for inner system use.
*/
function disconnect(): void;
/**
* Calculate the Wi-Fi signal level based on the Wi-Fi RSSI and frequency band.
*
* @param rssi Indicates the Wi-Fi RSSI.
* @param band Indicates the Wi-Fi frequency band.
* @returns Returns Wi-Fi signal level ranging from 0 to 4.
*
* @since 9
* @throws {BusinessError} 201 - Permission denied.
* @throws {BusinessError} 401 - Invalid parameters.
* @throws {BusinessError} 801 - Capability not supported.
* @throws {BusinessError} 2501000 - Operation failed.
* @syscap SystemCapability.Communication.WiFi.STA
* @permission ohos.permission.GET_WIFI_INFO
*/
function getSignalLevel(rssi: number, band: number): number;
/**
* Obtain connection information about the Wi-Fi connection.
*
* @since 9
* @throws {BusinessError} 201 - Permission denied.
* @throws {BusinessError} 202 - System API is not allowed called by Non-system application.
* @throws {BusinessError} 801 - Capability not supported.
* @throws {BusinessError} 2501000 - Operation failed.
* @throws {BusinessError} 2501001 - Wifi is closed.
* @syscap SystemCapability.Communication.WiFi.STA
* @permission ohos.permission.GET_WIFI_INFO
*/
function getLinkedInfo(): Promise To check whether this device supports a specified feature.
*
* @returns Returns the features supported by this device.
* @since 9
* @throws {BusinessError} 201 - Permission denied.
* @throws {BusinessError} 202 - System API is not allowed called by Non-system application.
* @throws {BusinessError} 801 - Capability not supported.
* @throws {BusinessError} 2401000 - Operation failed.
* @syscap SystemCapability.Communication.WiFi.Core
* @permission ohos.permission.GET_WIFI_INFO
* @systemapi Hide this for inner system use.
*/
function getSupportedFeatures(): number;
/**
* Check whether the device supports a specified feature.
*
* @param featureId Indicates the ID of the feature.
* @returns Returns {@code true} if this device supports the specified feature, returns {@code false} otherwise.
* @since 9
* @throws {BusinessError} 201 - Permission denied.
* @throws {BusinessError} 401 - Invalid parameters.
* @throws {BusinessError} 801 - Capability not supported.
* @throws {BusinessError} 2401000 - Operation failed.
* @syscap SystemCapability.Communication.WiFi.Core
* @permission ohos.permission.GET_WIFI_INFO
*/
function isFeatureSupported(featureId: number): boolean;
/**
* Obtain the MAC address of a Wi-Fi device. Wi-Fi must be enabled.
*
* The MAC address is unique and cannot be changed.
*
* @returns Returns the MAC address of the Wi-Fi device.
* @since 9
* @throws {BusinessError} 201 - Permission denied.
* @throws {BusinessError} 202 - System API is not allowed called by Non-system application.
* @throws {BusinessError} 801 - Capability not supported.
* @throws {BusinessError} 2501000 - Operation failed.
* @throws {BusinessError} 2501001 - Wifi is closed.
* @syscap SystemCapability.Communication.WiFi.STA
* @permission ohos.permission.GET_WIFI_LOCAL_MAC and ohos.permission.GET_WIFI_INFO
* @systemapi Hide this for inner system use.
*/
function getDeviceMacAddress(): string[];
/**
* Obtain the IP information of the Wi-Fi connection.
*
* The IP information includes the host IP address, gateway address, and DNS information.
*
* @returns Returns the IP information of the Wi-Fi connection.
* @since 9
* @throws {BusinessError} 201 - Permission denied.
* @throws {BusinessError} 801 - Capability not supported.
* @throws {BusinessError} 2501000 - Operation failed.
* @syscap SystemCapability.Communication.WiFi.STA
* @permission ohos.permission.GET_WIFI_INFO
*/
function getIpInfo(): IpInfo;
/**
* Obtain the country code of the device.
*
* @returns Returns the country code of this device.
* @since 9
* @throws {BusinessError} 201 - Permission denied.
* @throws {BusinessError} 801 - Capability not supported.
* @throws {BusinessError} 2401000 - Operation failed.
* @syscap SystemCapability.Communication.WiFi.Core
* @permission ohos.permission.GET_WIFI_INFO
*/
function getCountryCode(): string;
/**
* Re-associate to current network.
*
* @since 9
* @throws {BusinessError} 201 - Permission denied.
* @throws {BusinessError} 202 - System API is not allowed called by Non-system application.
* @throws {BusinessError} 801 - Capability not supported.
* @throws {BusinessError} 2501000 - Operation failed.
* @throws {BusinessError} 2501001 - Wifi is closed.
* @syscap SystemCapability.Communication.WiFi.STA
* @permission ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION
* @systemapi Hide this for inner system use.
*/
function reassociate(): void;
/**
* Re-connect to current network.
*
* @since 9
* @throws {BusinessError} 201 - Permission denied.
* @throws {BusinessError} 202 - System API is not allowed called by Non-system application.
* @throws {BusinessError} 801 - Capability not supported.
* @throws {BusinessError} 2501000 - Operation failed.
* @throws {BusinessError} 2501001 - Wifi is closed.
* @syscap SystemCapability.Communication.WiFi.STA
* @permission ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION
* @systemapi Hide this for inner system use.
*/
function reconnect(): void;
/**
* Obtain the list of all existed Wi-Fi configurations.
*
* @returns Returns the list of all existing Wi-Fi configurations you created on your application.
* @since 9
* @throws {BusinessError} 201 - Permission denied.
* @throws {BusinessError} 202 - System API is not allowed called by Non-system application.
* @throws {BusinessError} 801 - Capability not supported.
* @throws {BusinessError} 2501000 - Operation failed.
* @syscap SystemCapability.Communication.WiFi.STA
* @permission ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION and ohos.permission.GET_WIFI_CONFIG
* @systemapi Hide this for inner system use.
*/
function getDeviceConfigs(): Array The disabled DeviceConfig will not be associated with again.
*
* @param networkId Identifies the network to disable.
* @since 9
* @throws {BusinessError} 201 - Permission denied.
* @throws {BusinessError} 202 - System API is not allowed called by Non-system application.
* @throws {BusinessError} 401 - Invalid parameters.
* @throws {BusinessError} 801 - Capability not supported.
* @throws {BusinessError} 2501000 - Operation failed.
* @syscap SystemCapability.Communication.WiFi.STA
* @permission ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION
* @systemapi Hide this for inner system use.
*/
function disableNetwork(netId: number): void;
/**
* Remove all the saved Wi-Fi configurations.
*
* @since 9
* @throws {BusinessError} 201 - Permission denied.
* @throws {BusinessError} 202 - System API is not allowed called by Non-system application.
* @throws {BusinessError} 801 - Capability not supported.
* @throws {BusinessError} 2501000 - Operation failed.
* @syscap SystemCapability.Communication.WiFi.STA
* @permission ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION
* @systemapi Hide this for inner system use.
*/
function removeAllNetwork(): void;
/**
* Remove a Wi-Fi DeviceConfig with networkId.
*
* After a Wi-Fi DeviceConfig is removed, its configuration will be deleted from the list of Wi-Fi configurations.
* If the Wi-Fi DeviceConfig is being connected, the connection will be interrupted.
* The application can only delete Wi-Fi DeviceConfig it has created.
*
* @param networkId indicate the ID of the Wi-Fi DeviceConfig,
* which can be obtained using the {@link #addDeviceConfig} or {@link #getLinkedInfo} method.
* @since 9
* @throws {BusinessError} 201 - Permission denied.
* @throws {BusinessError} 202 - System API is not allowed called by Non-system application.
* @throws {BusinessError} 401 - Invalid parameters.
* @throws {BusinessError} 801 - Capability not supported.
* @throws {BusinessError} 2501000 - Operation failed.
* @syscap SystemCapability.Communication.WiFi.STA
* @permission ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION
* @systemapi Hide this for inner system use.
*/
function removeDevice(id: number): void;
/**
* Enable Wi-Fi hotspot function.
*
* This method is asynchronous. After the Wi-Fi hotspot is enabled, Wi-Fi may be disabled.
*
* @since 9
* @throws {BusinessError} 201 - Permission denied.
* @throws {BusinessError} 202 - System API is not allowed called by Non-system application.
* @throws {BusinessError} 801 - Capability not supported.
* @throws {BusinessError} 2601000 - Operation failed.
* @syscap SystemCapability.Communication.WiFi.AP.Core
* @permission ohos.permission.MANAGE_WIFI_HOTSPOT
* @systemapi Hide this for inner system use.
*/
function enableHotspot(): void;
/**
* Disable Wi-Fi hotspot function.
*
* This method is asynchronous. If Wi-Fi is enabled after the Wi-Fi hotspot is disabled, Wi-Fi may be re-enabled.
*
* @returns Returns {@code true} if this method is called successfully, returns {@code false} otherwise.
* @since 9
* @throws {BusinessError} 201 - Permission denied.
* @throws {BusinessError} 202 - System API is not allowed called by Non-system application.
* @throws {BusinessError} 801 - Capability not supported.
* @throws {BusinessError} 2601000 - Operation failed.
* @syscap SystemCapability.Communication.WiFi.AP.Core
* @permission ohos.permission.MANAGE_WIFI_HOTSPOT
* @systemapi Hide this for inner system use.
*/
function disableHotspot(): void;
/**
* Check whether a device serving as a Wi-Fi hotspot supports both the 2.4 GHz and 5 GHz Wi-Fi.
*
* @returns Returns {@code true} if the method is called successfully, returns {@code false} otherwise.
* @since 9
* @throws {BusinessError} 201 - Permission denied.
* @throws {BusinessError} 202 - System API is not allowed called by Non-system application.
* @throws {BusinessError} 801 - Capability not supported.
* @throws {BusinessError} 2601000 - Operation failed.
* @syscap SystemCapability.Communication.WiFi.AP.Core
* @permission ohos.permission.GET_WIFI_INFO and ohos.permission.MANAGE_WIFI_HOTSPOT
* @systemapi Hide this for inner system use.
*/
function isHotspotDualBandSupported(): boolean;
/**
* Check whether Wi-Fi hotspot is active on a device.
*
* @returns Returns {@code true} if Wi-Fi hotspot is enabled, returns {@code false} otherwise.
* @since 9
* @throws {BusinessError} 201 - Permission denied.
* @throws {BusinessError} 202 - System API is not allowed called by Non-system application.
* @throws {BusinessError} 801 - Capability not supported.
* @throws {BusinessError} 2601000 - Operation failed.
* @syscap SystemCapability.Communication.WiFi.AP.Core
* @permission ohos.permission.GET_WIFI_INFO
* @systemapi Hide this for inner system use.
*/
function isHotspotActive(): boolean;
/**
* Set the hotspot configuration for the device.
*
* @param config Indicates the Wi-Fi hotspot configuration.
* The SSID and {@code securityType} must be available and correct.
* If {@code securityType} is not {@code open}, {@code preSharedKey} must be available and correct.
* @returns Returns {@code true} if the method is called successfully, returns {@code false} otherwise.
* @since 9
* @throws {BusinessError} 201 - Permission denied.
* @throws {BusinessError} 202 - System API is not allowed called by Non-system application.
* @throws {BusinessError} 401 - Invalid parameters.
* @throws {BusinessError} 801 - Capability not supported.
* @throws {BusinessError} 2601000 - Operation failed.
* @syscap SystemCapability.Communication.WiFi.AP.Core
* @permission ohos.permission.SET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG
* @systemapi Hide this for inner system use.
*/
function setHotspotConfig(config: HotspotConfig): void;
/**
* Obtain the Wi-Fi hotspot configuration.
*
* @returns Returns the configuration of an existed or enabled Wi-Fi hotspot.
* @since 9
* @throws {BusinessError} 201 - Permission denied.
* @throws {BusinessError} 202 - System API is not allowed called by Non-system application.
* @throws {BusinessError} 801 - Capability not supported.
* @throws {BusinessError} 2601000 - Operation failed.
* @syscap SystemCapability.Communication.WiFi.AP.Core
* @permission ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG
* @systemapi Hide this for inner system use.
*/
function getHotspotConfig(): HotspotConfig;
/**
* Obtain the list of stations that are connected to the Wi-Fi hotspot.
*
* This method can only be used on a device that serves as a Wi-Fi hotspot.
*
* @returns Returns the list of clients that are connected to the Wi-Fi hotspot.
* @since 9
* @throws {BusinessError} 201 - Permission denied.
* @throws {BusinessError} 202 - System API is not allowed called by Non-system application.
* @throws {BusinessError} 801 - Capability not supported.
* @throws {BusinessError} 2601000 - Operation failed.
* @syscap SystemCapability.Communication.WiFi.AP.Core
* @permission ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION and ohos.permission.MANAGE_WIFI_HOTSPOT
* @systemapi Hide this for inner system use.
*/
function getStations(): Array deviceAddress in the returned WifiP2pDevice will be set "00:00:00:00:00:00",
* if ohos.permission.GET_WIFI_LOCAL_MAC is not granted.
*
* @returns Returns the information about own device info.
* @since 9
* @throws {BusinessError} 201 - Permission denied.
* @throws {BusinessError} 801 - Capability not supported.
* @throws {BusinessError} 2801000 - Operation failed.
* @syscap SystemCapability.Communication.WiFi.P2P
* @permission ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG
*/
function getP2pLocalDevice(): Promise All callback functions will be deregistered If there is no specific callback parameter. All callback functions will be deregistered If there is no specific callback parameter. All callback functions will be deregistered If there is no specific callback parameter. All callback functions will be deregistered If there is no specific callback parameter. All callback functions will be deregistered If there is no specific callback parameter. All callback functions will be deregistered If there is no specific callback parameter. All callback functions will be deregistered If there is no specific callback parameter.