This module provides capabilities including real-time network quality assessment, network scenario identification, and weak signal prediction. These capabilities enable your app to dynamically adjust cache, bit rate, frame rate, and resolution policies, ensuring a seamless experience even in challenging network environments. Your app can also call the transmission quality feedback API to report the network quality, so as to trigger network acceleration.
Start version: 5.0.0(12)
Subscribes to network quality information.
Required permission: ohos.permission.GET_NETWORK_INFO
System capability: SystemCapability.Communication.NetworkBoost.Core
Start version: 5.0.0(12)
Parameters:
Parameter | Type | Mandatory | Description |
|---|---|---|---|
type | string | Yes | Event type. The value is always netQosChange, indicating network quality change events. |
callback | Callback<Array<NetworkQos>> | Yes | Callback function, which is used to return network QoS change details. |
Error codes:
All error codes relevant to this kit are universal error codes. For details, please refer to Universal Error Codes.
Error Code | Description |
|---|---|
201 | Permission verification failed. |
401 | Parameter check failed. |
801 | The device does not support this API. |
Example:
import { BusinessError } from '@kit.BasicServicesKit';
try {
netQuality.on('netQosChange', (list: Array<netQuality.NetworkQos>) => {
if (list.length > 0) {
list.forEach((qos) => {
// Callback information processing.
console.info(`Succeeded receive netQosChange info`);
});
}
});
} catch (err) {
console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
} off(type: 'netQosChange', callback?: Callback<Array<NetworkQos>>): void
Unsubscribes from network quality information.
Required permission: ohos.permission.GET_NETWORK_INFO
System capability: SystemCapability.Communication.NetworkBoost.Core
Start version: 5.0.0(12)
Parameters:
Parameter | Type | Mandatory | Description |
|---|---|---|---|
type | string | Yes | Event type. The value is always netQosChange, indicating connection state change events. |
callback | Callback<Array<NetworkQos>> | No | Callback function to be unregistered, which must the same as that passed upon subscription. If this parameter is not passed, all callback functions are unregistered. |
Error codes:
All error codes relevant to this kit are universal error codes. For details, please refer to Universal Error Codes.
Error Code | Description |
|---|---|
201 | Permission verification failed. |
401 | Parameter check failed. |
801 | The device does not support this API. |
Example:
import { BusinessError } from '@kit.BasicServicesKit';
try {
netQuality.off('netQosChange');
} catch (err) {
console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
} on(type: 'netSceneChange', callback: Callback<Array<NetworkScene>>): void
Subscribes to network scenario information.
Required permission: ohos.permission.GET_NETWORK_INFO
System capability: SystemCapability.Communication.NetworkBoost.Core
Start version: 5.0.0(12)
Parameters:
Parameter | Type | Mandatory | Description |
|---|---|---|---|
type | string | Yes | Event type. The value is always netSceneChange, indicating network scenario change events. |
callback | Callback<Array<NetworkScene>> | Yes | Callback function, which is used to return network scenario change details. |
Error codes:
All error codes relevant to this kit are universal error codes. For details, please refer to Universal Error Codes.
Error Code | Description |
|---|---|
201 | Permission verification failed. |
401 | Parameter check failed. |
801 | The device does not support this API. |
Example:
import { BusinessError } from '@kit.BasicServicesKit';
try {
netQuality.on('netSceneChange', (list: Array<netQuality.NetworkScene>) => {
if (list.length > 0) {
list.forEach((scene) => {
// Callback information processing.
console.info(`Succeeded receive netSceneChange info`);
if (scene.weakSignalPrediction) {
// Weak signal prediction processing.
}
});
}
});
} catch (err) {
console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
} off(type: 'netSceneChange', callback?: Callback<Array<NetworkScene>>): void
Unsubscribes from network scenario information.
Required permission: ohos.permission.GET_NETWORK_INFO
System capability: SystemCapability.Communication.NetworkBoost.Core
Start version: 5.0.0(12)
Parameters:
Parameter | Type | Mandatory | Description |
|---|---|---|---|
type | string | Yes | Event type. The value is always netSceneChange, indicating network scenario change events. |
callback | Callback<Array<NetworkScene>> | No | Callback function to be unregistered, which must the same as that passed upon subscription. If this parameter is not passed, all callback functions are unregistered. |
Error codes:
All error codes relevant to this kit are universal error codes. For details, please refer to Universal Error Codes.
Error Code | Description |
|---|---|
201 | Permission verification failed. |
401 | Parameter check failed. |
801 | The device does not support this API. |
Example:
import { BusinessError } from '@kit.BasicServicesKit';
try {
netQuality.off('netSceneChange');
} catch (err) {
console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
} reportQoe(appQoe: AppQoe): void
Reports app data transmission quality. If the reporting fails, the API will throw an exception.
Required permission: ohos.permission.GET_NETWORK_INFO
System capability: SystemCapability.Communication.NetworkBoost.Core
Start version: 5.0.0(12)
Parameters:
Parameter | Type | Mandatory | Description |
|---|---|---|---|
appQoe | Yes | Transmission quality data to be reported. |
Error codes:
All error codes relevant to this kit are universal error codes. For details, please refer to Universal Error Codes.
Error Code | Description |
|---|---|
201 | Permission verification failed. |
401 | Parameter check failed. |
801 | The device does not support this API. |
Example:
import { BusinessError } from '@kit.BasicServicesKit';
try {
let serviceType: netQuality.ServiceType = 'shortVideo';
let qoeType: netQuality.BadQoeCause = 'serverErr';
let appQoe: netQuality.AppQoe = {
serviceType,
qoeType
};
netQuality.reportQoe(appQoe);
} catch (err) {
console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
} Defines app data transmission quality information.
System capability: SystemCapability.Communication.NetworkBoost.Core
Start version: 5.0.0(12)
Parameter | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
serviceType | No | No | Service type of the app. | |
qoeType | No | No | Network quality data type of the app. |
Defines network quality data that is returned.
System capability: SystemCapability.Communication.NetworkBoost.Core
Start version: 5.0.0(12)
Parameter | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
pathType | No | No | Type of the link for which the network quality data needs to be returned. | |
linkUpBandwidth | No | No | Uplink bandwidth information. | |
linkDownBandwidth | No | No | Downlink bandwidth information. | |
linkUpRate | No | No | Uplink rate. | |
linkDownRate | No | No | Downlink rate. | |
rttMs | number | No | No | RTT delay. The value is any positive number. |
linkUpBufferDelayMs | number | No | No | Uplink air interface buffer delay. The value is any positive number. |
linkUpBufferCongestionPercent | number | No | Yes | Percentage of the uplink air interface buffer delay to the total buffering time. The value range is [0, 100]. |
Defines the enumeration for the link type.
System capability: SystemCapability.Communication.NetworkBoost.Core
Start version: 5.0.0(12)
Parameter | Value | Description |
|---|---|---|
CELLULAR_PRIMARY | 0 | Primary SIM card. |
CELLULAR_SECONDARY | 1 | Secondary SIM card. |
WIFI_PRIMARY | 2 | Primary Wi-Fi. |
WIFI_SECONDARY | 3 | Secondary Wi-Fi. |
type RateBps = number
Defines an abstract representation of the network bandwidth or rate.
System capability: SystemCapability.Communication.NetworkBoost.Core
Start version: 5.0.0(12)
Type | Description |
|---|---|
number | Number. The value is any positive number in bit/s. |
Defines the options of the app service type.
System capability: SystemCapability.Communication.NetworkBoost.Core
Start version: 5.0.0(12)
Value Range | Description |
|---|---|
'default' | 'background' | 'realtimeVoice' | 'realtimeVideo' | 'callSignaling' | 'realtimeGame' | 'normalGame' | 'shortVideo' | 'longVideo' | 'livestreamingAnchor' | 'livestreamingWatcher' | 'download' | 'upload' | 'browser' | Character string that indicates the app service type. The options are as follows: default: default service type background: background service realtimeVoice: real-time voice service realtimeVideo: real-time video service callSignaling: voice signaling service realtimeGame: real-time game service normalGame: common game service shortVideo: short video service longVideo: long video service livestreamingAnchor: live streamer service livestreamingWatcher: live streaming viewer download: download service upload: upload service browser: web page browsing service |
Defines the options of the network quality data type of the app.
System capability: SystemCapability.Communication.NetworkBoost.Core
Start version: 5.0.0(12)
Value Range | Description |
|---|---|
'good' | BadQoeCause | Character string that represents the network quality data type. The options are good and BadQoeCause. good: good network quality |
Defines the cause options of bad network quality of the app.
System capability: SystemCapability.Communication.NetworkBoost.Core
Start version: 5.0.0(12)
Value Range | Description |
|---|---|
'unknown' | 'serverErr' | 'noData' | 'packetLost' | 'packetOutOfOrder' | 'highJitter' | 'highLatency' | Character string that represents the bad network quality type. The options are as follows: unknown: bad quality due to an unknown cause serverErr: server error noData: no data transmitted packetLost: packet loss packetOutOfOrder: packets out of order highJitter: high jitter highLatency: high latency |
Defines multiple constants that represent different network bandwidth or rate levels.
System capability: SystemCapability.Communication.NetworkBoost.Core
Start version: 5.0.0(12)
Parameter | Type | Value | Description |
|---|---|---|---|
BPS | number | 1 | 1 bit/s. |
KBPS | number | 1000 | 1 kbit/s. |
MBPS | number | 1000000 | 1 Mbit/s. |
GBPS | number | 1000000000 | 1 Gbit/s. |
TBPS | number | 1000000000000 | 1 Tbit/s. |
Defines the network scenario change information that is returned.
System capability: SystemCapability.Communication.NetworkBoost.Core
Start version: 5.0.0(12)
Parameter | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
pathType | No | No | Type of the link for which the network scenario data needs to be returned. | |
scene | No | No | Scenario status. | |
recommendedAction | No | No | Recommended data transmission policy. | |
weakSignalPrediction | No | Yes | Weak signal prediction information. |
Defines the weak signal prediction information.
System capability: SystemCapability.Communication.NetworkBoost.Core
Start version: 5.0.0(12)
Parameter | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
isLastPredictionValid | boolean | No | No | Indicates whether the latest weak signal prediction is still valid. The options are true (yes) and false (no). When the value is false, the startTime and duration parameters do not take effect. |
startTime | number | No | No | Predicted duration before the signal becomes weak, in seconds. The value is 0 or a positive number. |
duration | number | No | No | Estimated duration of the weak signal, in seconds. The value is a positive number. If the value is 0, the prediction result is invalid. |
Defines the options of the network scenario type.
System capability: SystemCapability.Communication.NetworkBoost.Core
Start version: 5.0.0(12)
Value Range | Description |
|---|---|
'normal' | 'congestion' | 'frequentHandover' | 'weakSignal' | Character string that represents the network scenario type. The options are as follows: normal: normal congestion: congestion frequentHandover: frequent handovers between cells weakSignal: weak signal |
Defines the options of the suggested packet transmission policy.
System capability: SystemCapability.Communication.NetworkBoost.Core
Start version: 5.0.0(12)
Value Range | Description |
|---|---|
'suspendData' | 'decreaseData' | 'increaseData' | 'keepData' | Character string that represents the suggested packet transmission policy. The options are as follows: suspendData: Stop transmitting packets. decreaseData: Decrease the packet transmission rate. increaseData: Increase the packet transmission rate. keepData: Keep the current packet transmission rate. |
Defines the options of the suggested data transmission policy.
System capability: SystemCapability.Communication.NetworkBoost.Core
Start version: 5.0.0(12)
Value Range | Description |
|---|---|
'doCaching' | DataSpeedSimpleAction | Character string that represents the suggested data transmission policy. The options are doCaching and DataSpeedSimpleAction. doCaching: Cache data. |