目录

netQuality (Network Quality)

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, resolution, and other 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.

Since: 5.0.0(12)

Modules to Import

import { netQuality } from '@kit.NetworkBoostKit';

netQuality.on('netQosChange')

on(type: 'netQosChange', callback: Callback<Array<NetworkQos>>): void

Subscribes to network quality information.

Model restriction: This API can be used only in the stage model.

Required permission: ohos.permission.GET_NETWORK_INFO

Atomic service API: This API can be used in atomic services since API version 26.0.0.

System capability: SystemCapability.Communication.NetworkBoost.Core

Since: 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 used to return network QoS change details.

Error codes:

For details about the error codes, please refer to Universal Error Codes.

ID Error Message
201 Permission denied.
401 Invalid parameter.
801 Capability not supported.

Example:

import { BusinessError } from '@kit.BasicServicesKit';
import { netQuality } from '@kit.NetworkBoostKit';
try {
  netQuality.on('netQosChange', (list: Array<netQuality.NetworkQos>) => {
    if (list.length > 0) {
      list.forEach((qos) => {
        // Callback information processing.
        console.info('Succeeded receive netQosChange info qos=' + qos);
      });
    }
  });
} catch (err) {
  console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
}

netQuality.off('netQosChange')

off(type: 'netQosChange', callback?: Callback<Array<NetworkQos>>): void

Unsubscribes from network quality information.

Model restriction: This API can be used only in the stage model.

Required permission: ohos.permission.GET_NETWORK_INFO

Atomic service API: This API can be used in atomic services since API version 26.0.0.

System capability: SystemCapability.Communication.NetworkBoost.Core

Since: 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 to be unregistered, which must be the same as that passed upon subscription. If this parameter is not passed, all callbacks will be unregistered.

Error codes:

For details about the error codes, please refer to Universal Error Codes.

ID Error Message
201 Permission denied.
401 Invalid parameter.
801 Capability not supported.

Example:

import { BusinessError } from '@kit.BasicServicesKit';
import { netQuality } from '@kit.NetworkBoostKit';
try {
  netQuality.off('netQosChange');
} catch (err) {
  console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
}

netQuality.on('netSceneChange')

on(type: 'netSceneChange', callback: Callback<Array<NetworkScene>>): void

Subscribes to network scenario information.

Model restriction: This API can be used only in the stage model.

Required permission: ohos.permission.GET_NETWORK_INFO

Atomic service API: This API can be used in atomic services since API version 26.0.0.

System capability: SystemCapability.Communication.NetworkBoost.Core

Since: 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 used to return network scenario change details.

Error codes:

For details about the error codes, please refer to Universal Error Codes.

ID Error Message
201 Permission denied.
401 Invalid parameter.
801 Capability not supported.

Example:

import { BusinessError } from '@kit.BasicServicesKit';
import { netQuality } from '@kit.NetworkBoostKit';
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);
}

netQuality.off('netSceneChange')

off(type: 'netSceneChange', callback?: Callback<Array<NetworkScene>>): void

Unsubscribes from network scenario information.

Model restriction: This API can be used only in the stage model.

Required permission: ohos.permission.GET_NETWORK_INFO

Atomic service API: This API can be used in atomic services since API version 26.0.0.

System capability: SystemCapability.Communication.NetworkBoost.Core

Since: 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 to be unregistered, which must be the same as that passed upon subscription. If this parameter is not passed, all callbacks will be unregistered.

Error codes:

For details about the error codes, please refer to Universal Error Codes.

ID Error Message
201 Permission denied.
401 Invalid parameter.
801 Capability not supported.

Example:

import { BusinessError } from '@kit.BasicServicesKit';
import { netQuality } from '@kit.NetworkBoostKit';
try {
  netQuality.off('netSceneChange');
} catch (err) {
  console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
}

netQuality.reportQoe

reportQoe(appQoe: AppQoe): void

Reports app data transmission quality. If the reporting fails, the API will throw an exception.

Model restriction: This API can be used only in the stage model.

Required permission: ohos.permission.GET_NETWORK_INFO

Atomic service API: This API can be used in atomic services since API version 26.0.0.

System capability: SystemCapability.Communication.NetworkBoost.Core

Since: 5.0.0(12)

Parameters

Parameter Type Mandatory Description
appQoe AppQoe Yes Transmission quality data to be reported.

Error codes:

For details about the error codes, please refer to Universal Error Codes.

ID Error Message
201 Permission verify error.
401 Parameter error.
801 Capability not supported.

Example:

import { BusinessError } from '@kit.BasicServicesKit';
import { netQuality } from '@kit.NetworkBoostKit';
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);
}

AppQoe

Defines app data transmission quality information.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since API version 26.0.0.

System capability: SystemCapability.Communication.NetworkBoost.Core

Since: 5.0.0(12)

Name Type Read-Only Optional Description
serviceType ServiceType No No Service type of the app.
qoeType QoeType No No Network quality data type of the app.

NetworkQos

Defines network quality data that is returned.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since API version 26.0.0.

System capability: SystemCapability.Communication.NetworkBoost.Core

Since: 5.0.0(12)

Name Type Read-Only Optional Description
pathType PathType No No Type of the data path for which the network quality data needs to be returned.
linkUpBandwidth RateBps No No Uplink bandwidth, in bit/s.
linkDownBandwidth RateBps No No Downlink bandwidth, in bit/s.
linkUpRate RateBps No No Uplink rate, in bit/s.
linkDownRate RateBps No No Downlink rate, in bit/s.
rttMs number No No

RTT, which indicates the average RTT of all uplink and downlink TCP data packets on the data path corresponding to pathType in a statistical period. The value can be 0 or a positive number, in milliseconds.

If no response to a certain TCP request is received within the statistical period, the RTT of that request will not be included for calculating the average RTT. As a result, when the Internet is completely unreachable, the RTT returned is relatively small because no responses to TCP requests are received, creating a mismatch with the actual status. In such cases, you are advised to use the on('netCapabilitiesChange') method for comprehensive evaluation.

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

PathType

Defines the enumeration of data path types.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since API version 26.0.0.

System capability: SystemCapability.Communication.NetworkBoost.Core

Since: 5.0.0(12)

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

RateBps

type RateBps = number

Defines an abstract representation of the network bandwidth or rate.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since API version 26.0.0.

System capability: SystemCapability.Communication.NetworkBoost.Core

Since: 5.0.0(12)

Type Description
number Number. The value is a positive number in bit/s.

ServiceType

type ServiceType = 'default' | 'background' | 'realtimeVoice' | 'realtimeVideo' | 'callSignaling' | 'realtimeGame' | 'normalGame' | 'shortVideo' | 'longVideo' | 'livestreamingAnchor' | 'livestreamingWatcher' | 'download' | 'upload' | 'browser' | 'transaction' | 'shopping' | 'detection' | 'cloudService' | 'voiceConference' | 'videoConference' | 'audio' | 'navigation' | 'seckillService' | 'login'

Defines the enumeration of app service types.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since API version 26.0.0.

System capability: SystemCapability.Communication.NetworkBoost.Core

Since: 5.0.0(12)

Type Description
'default' Default service type, which is represented by the fixed character string 'default'.
'background' Background service, which is represented by the fixed character string 'background'.
'realtimeVoice' Real-time voice service, which is represented by the fixed character string 'realtimeVoice'.
'realtimeVideo' Real-time video service, which is represented by the fixed character string 'realtimeVideo'.
'callSignaling' Voice signaling service, which is represented by the fixed character string 'callSignaling'.
'realtimeGame' Real-time game service, which is represented by the fixed character string 'realtimeGame'.
'normalGame' Common game service, which is represented by the fixed character string 'normalGame'.
'shortVideo' Short video service, which is represented by the fixed character string 'shortVideo'.
'longVideo' Long video service, which is represented by the fixed character string 'longVideo'.
'livestreamingAnchor' Live streamer service, which is represented by the fixed character string 'livestreamingAnchor'.
'livestreamingWatcher' Live streaming viewer service, which is represented by the fixed character string 'livestreamingWatcher'.
'download' Download service, which is represented by the fixed character string 'download'.
'upload' Upload service, which is represented by the fixed character string 'upload'.
'browser' Web page browsing service, which is represented by the fixed character string 'browser'.
'transaction' Transaction payment or code scanning service, which is represented by the fixed character string 'transaction'. This service type is supported since API version 20.
'shopping' Shopping service, which is represented by the fixed character string 'shopping'. This service type is supported since API version 20.
'detection' Detection service, which is represented by the fixed character string 'detection'. This service type is supported since API version 20.
'cloudService' Cloud service/Cloud game, which is represented by the fixed character string 'cloudService'. This service type is supported since API version 20.
'voiceConference' Voice conference service, which is represented by the fixed character string 'voiceConference'. This service type is supported since API version 20.
'videoConference' Video conference service, which is represented by the fixed character string 'videoConference'. This service type is supported since API version 20.
'audio' Audio (such as music) service, which is represented by the fixed character string 'audio'. This service type is supported since API version 20.
'navigation' Navigation and location service, which is represented by the fixed character string 'navigation'. This service type is supported since API version 20.
'seckillService' Seckill service, such as ticket snatching, flash sale, order grabbing, and red envelope rush, which is represented by the fixed character string 'seckillService'. This service type is supported since API version 20.
'login' Sign-in (including one-tap sign-in) service, which is represented by the fixed character string 'login'. This service type is supported since API version 20.

QoeType

type QoeType = 'good' | BadQoeCause

Defines the enumeration of network quality data types of the app.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since API version 26.0.0.

System capability: SystemCapability.Communication.NetworkBoost.Core

Since: 5.0.0(12)

Type Description
'good' Good network quality, which is represented by the fixed character string 'good'.
BadQoeCause Bad network quality.

BadQoeCause

type BadQoeCause = 'unknown' | 'serverErr' | 'noData' | 'packetLost' | 'packetOutOfOrder' | 'highJitter' | 'highLatency'

Defines the enumeration of causes for bad network quality of the app.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since API version 26.0.0.

System capability: SystemCapability.Communication.NetworkBoost.Core

Since: 5.0.0(12)

Type Description
'unknown' Unknown cause, which is represented by the fixed character string 'unknown'.
'serverErr' Server error, which is represented by the fixed character string 'serverErr'.
'noData' No data, which is represented by the fixed character string 'noData'.
'packetLost' Packet loss, which is represented by the fixed character string 'packetLost'.
'packetOutOfOrder' Packets out of order, which is represented by the fixed character string 'packetOutOfOrder'.
'highJitter' High jitter, which is represented by the fixed character string 'highJitter'.
'highLatency' High latency, which is represented by the fixed character string 'highLatency'.

Network Rate/Bandwidth Level

Defines multiple constants that represent different network rate or bandwidth levels.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since API version 26.0.0.

System capability: SystemCapability.Communication.NetworkBoost.Core

Since: 5.0.0(12)

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

NetworkScene

Defines the network scenario change information that is returned.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since API version 26.0.0.

System capability: SystemCapability.Communication.NetworkBoost.Core

Since: 5.0.0(12)

Name Type Read-Only Optional Description
pathType PathType No No Type of the data path for which the network scenario data needs to be returned.
scene Scene No No Scenario status.
recommendedAction RecommendedAction No No Recommended data transmission policy.
weakSignalPrediction WeakSignalPrediction No Yes Weak signal prediction information.

WeakSignalPrediction

Defines weak signal prediction information.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since API version 26.0.0.

System capability: SystemCapability.Communication.NetworkBoost.Core

Since: 5.0.0(12)

Name 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 Predicted duration of the weak signal, in seconds. The value is a positive number. If the value is 0, the prediction result is invalid.

Scene

type Scene = 'normal' | 'congestion' | 'frequentHandover' | 'weakSignal'

Defines the enumeration of network scenario types.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since API version 26.0.0.

System capability: SystemCapability.Communication.NetworkBoost.Core

Since: 5.0.0(12)

Type Description
'normal' Normal scenario, which is represented by the fixed character string 'normal'.
'congestion' Congestion scenario, which is represented by the fixed character string 'congestion'.
'frequentHandover' Frequent cell handover scenario, which is represented by the fixed character string 'frequentHandover'.
'weakSignal' Weak signal scenario, which is represented by the fixed character string 'weakSignal'.

DataSpeedSimpleAction

type DataSpeedSimpleAction = 'suspendData' | 'decreaseData' | 'increaseData' | 'keepData'

Defines the enumeration of simple suggested packet transmission policies.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since API version 26.0.0.

System capability: SystemCapability.Communication.NetworkBoost.Core

Since: 5.0.0(12)

Type Description
'suspendData' Stop transmitting packets, which is represented by the fixed character string 'suspendData'.
'decreaseData' Decrease the packet transmission rate, which is represented by the fixed character string 'decreaseData'.
'increaseData' Increase the packet transmission rate, which is represented by the fixed character string 'increaseData'.
'keepData' Keep the current packet transmission rate, which is represented by the fixed character string 'keepData'.

RecommendedAction

type RecommendedAction = 'doCaching' | DataSpeedSimpleAction

Defines the enumeration of suggested data transmission policies.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since API version 26.0.0.

System capability: SystemCapability.Communication.NetworkBoost.Core

Since: 5.0.0(12)

Type Description
'doCaching' Caching data, which is represented by the fixed character string 'doCaching'.
DataSpeedSimpleAction Simple suggested packet transmission policy.