目录

netBoost (Network Acceleration)

This module provides APIs for app service scenario description, enabling the system to dynamically adjust service acceleration or low-power transmission policies based on the service scenario reported by your app and the real-time network status. In this way, users can enjoy fast and low-latency network experience.

Since: 6.0.0(20)

Modules to Import

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

netBoost.setSceneDesc

setSceneDesc(sceneDesc : SceneDesc): void

Sets the service scenario.

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

Required permission: ohos.permission.INTERNET

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

System capability: SystemCapability.Communication.NetworkBoost.Core

Since: 6.0.0(20)

Parameters

Parameter Type Mandatory Description
sceneDesc SceneDesc Yes Description information of a service scenario.

Error codes:

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

ID Error Message
201 Permission denied.
1013600001 Internal error.
1013600002 System service error.

Example:

import { BusinessError } from '@kit.BasicServicesKit';
import { netBoost } from '@kit.NetworkBoostKit';
try {
  let sceneDesc : netBoost.SceneDesc = {
    // scene: 'realtimeVoice' indicates the real-time voice service scenario, which can be configured based on service requirements. sceneEvent: SCENE_EVENT_ENTER indicates the event of entering a scenario.
    scene : 'realtimeVoice',
    sceneEvent : netBoost.SceneEvent.SCENE_EVENT_ENTER
  }
  netBoost.setSceneDesc(sceneDesc);
} catch (err) {
  console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
}

netBoost.setLowPowerMode

setLowPowerMode(isEnable : boolean): void

Sets the low power consumption mode.

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

Required permission: ohos.permission.INTERNET

System capability: SystemCapability.Communication.NetworkBoost.Core

Since: 6.1.1(24)

Parameters

Parameter Type Mandatory Description
isEnable boolean Yes

Switch that controls the low power consumption mode.

- true: enables the low power consumption mode.

- false: disables the low power consumption mode. The default value is false.

Error codes:

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

ID Error Message
201 Permission denied.
1013600001 Internal error.
1013600002 System service error.

Example:

import { BusinessError } from '@kit.BasicServicesKit';
import { netBoost } from '@kit.NetworkBoostKit';
try {
  let lowPower = true;
  netBoost.setLowPowerMode(lowPower);
} catch (err) {
  console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
}

netBoost.setDataFlowDesc

setDataFlowDesc(dataFlowDesc : DataFlowDesc): void

Sets the data flow description. Your app can report the data flow information, service scenario, scenario event, and expected network transmission quality of the data flow to the system. The system provides differentiated network transmission assurance for app data flows based on the data flow description.

Currently, the data flow description applies only to foreground apps. A maximum of two data flow descriptions can be set for each app.

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

Required permission: ohos.permission.INTERNET

System capability: SystemCapability.Communication.NetworkBoost.Core

Since: 26.0.0

Parameters

Parameter Type Mandatory Description
dataFlowDesc DataFlowDesc Yes Data flow description.

Error codes:

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

ID Error Message
201 Permission denied.
801 Capability not supported.
1013600001 Internal error.
1013600002 System service error.

Example:

import { BusinessError } from '@kit.BasicServicesKit';
import { netBoost } from '@kit.NetworkBoostKit';
try {
  let localAddr: netBoost.NetAddress = {
    address: "192.168.xx.xxx",  // Local IP address
    port: 1234,
  }
  let remoteAddr: netBoost.NetAddress = {
    address: "192.168.xx.xxx",  // Peer IP address
    port: 443,
  }
  let dataFlowInfo: netBoost.DataFlowInfo = {
    protocol: netBoost.ProtocolType.PROTOCOL_TCP,
    local: localAddr,
    remote: remoteAddr
  }
  let expectedDescription: netBoost.ExpectedDescription = {
    uplinkBandwidth: 2000,
    downlinkBandwidth: 4000,
    latency: 100,
    priority: netBoost.PriorityLevel.PRIO_HIGH
  }
  let dataFlowDesc: netBoost.DataFlowDesc = {
    dataFlowInfo: dataFlowInfo,
    scene: 'videoConference',
    sceneEvent: netBoost.SceneEvent.SCENE_EVENT_ENTER,
    expectations: expectedDescription
  }
  netBoost.setDataFlowDesc(dataFlowDesc);
} catch (err) {
  console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
}

SceneDesc

Defines the description information of a service scenario.

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: 6.0.0(20)

Parameters

Parameter Type Mandatory Description
scene netQuality.ServiceType Yes Service scenario type.
sceneEvent SceneEvent Yes Service scenario event.
startTime number No

Predicted duration before the sceneEvent is triggered, in milliseconds.

- The value 0 indicates that the sceneEvent occurs immediately. The default value is 0.

- A value greater than 0 indicates the predicted duration before the sceneEvent is triggered.

duration number No

Predicted duration of the SceneEvent, in milliseconds. The value 0 indicates an unknown duration, which ends when the SceneEvent ends.

For example, if a seckill promotion in an app is about to begin in 10 seconds and will last for 20 seconds, you can pass 'seckillService' for scene, and set sceneEvent to SCENE_EVENT_ENTER, startTime to 10000, and duration to 20000. You can set this parameter based on the actual service scenario type.

DataFlowDesc

Defines the data flow description information.

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

System capability: SystemCapability.Communication.NetworkBoost.Core

Since: 26.0.0

Parameters

Parameter Type Mandatory Description
dataFlowInfo DataFlowInfo | SocketFd Yes Data flow information, which uniquely identifies a data flow.
scene netQuality.ServiceType Yes Service scenario type.
sceneEvent SceneEvent Yes Service scenario event.
expectations ExpectedDescription No Expectation for a specific data flow.

DataFlowInfo

Defines the data flow information.

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

System capability: SystemCapability.Communication.NetworkBoost.Core

Since: 26.0.0

Parameters

Parameter Type Mandatory Description
protocol ProtocolType Yes Protocol type.
local NetAddress Yes Local network address and port number.
remote NetAddress Yes Peer network address and port number.

NetAddress

Defines the network address information.

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

System capability: SystemCapability.Communication.NetworkBoost.Core

Since: 26.0.0

Parameters

Parameter Type Mandatory Description
address string Yes IP address.
port number Yes Port number. The value ranges from 0 to 65535.

ExpectedDescription

Defines the description information about data flow expectations.

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

System capability: SystemCapability.Communication.NetworkBoost.Core

Since: 26.0.0

Parameters

Parameter Type Mandatory Description
uplinkBandwidth number No Expected uplink bandwidth, in kbit/s.
downlinkBandwidth number No Expected downlink bandwidth, in kbit/s.
latency number No Expected latency, in milliseconds.
objectSize number No Size of the requested or transmitted object.
priority PriorityLevel No Expected priority.
lowPowerMode boolean No

Low-power transmission.

- true: enables low-power transmission.

- false: disables low-power transmission. The default value is false.

If you set lowPowerMode, dataFlowInfo must be of the socketFd type.

If you do not set lowPowerMode, dataFlowInfo can be of any type.

SocketFd

type SocketFd = number

Specifies the socket file descriptor.

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

System capability: SystemCapability.Communication.NetworkBoost.Core

Since: 26.0.0

Type Description
number Socket file descriptor.

SceneEvent

Defines the enumeration of service scenario events.

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: 6.0.0(20)

Name Value Description
SCENE_EVENT_ENTER 0 The app enters a service scenario.
SCENE_EVENT_UPDATE 1 The last service scenario event information is updated.
SCENE_EVENT_LEAVE 2 The app leaves a service scenario.

ProtocolType

Defines the enumeration of network protocol types.

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

System capability: SystemCapability.Communication.NetworkBoost.Core

Since: 26.0.0

Name Value Description
PROTOCOL_UDP 0 UDP.
PROTOCOL_TCP 1 TCP.

PriorityLevel

Defines the enumeration of priorities.

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

System capability: SystemCapability.Communication.NetworkBoost.Core

Since: 26.0.0

Name Value Description
PRIO_NORMAL 0 Normal priority.
PRIO_HIGH 1 High priority.