VpnExtensionContext

VpnExtensionContext represents the context of VpnExtensionAbility and is inherited from ExtensionContext.

This module provides the context required for APIs to access the resources of a VpnExtensionAbility object.

NOTE

The initial APIs of this module are supported since API version 11. 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.

Modules to Import

import { VpnExtensionAbility } from '@kit.NetworkKit';

How to Use

You can obtain a VpnExtensionContext object through a VpnExtensionAbility child class instance.

import { VpnExtensionAbility, vpnExtension } from '@kit.NetworkKit';
import { Want } from '@kit.AbilityKit';

export default class MyVpnExtAbility extends VpnExtensionAbility {
  private vpnServerIp: string = 'xxx.xxx.x.x';
  private tunIp: string = 'x.x.x.x';
  private blockedAppName: string = 'xxxx';

  onCreate(want: Want) {
    let VpnConnection: vpnExtension.VpnConnection = vpnExtension.createVpnConnection(this.context);
    console.info("vpn createVpnConnection: " + JSON.stringify(VpnConnection));
  }
}

VpnExtensionAbility

Represents the VPN extension capability.

System capability: SystemCapability.Ability.AbilityRuntime.Core.

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

Name Type Read-Only Optional Description
context VpnExtensionContext No No Specified context.

onCreate

onCreate(want: Want): void

Represents the callback triggered when the extended VPN is initialized.

NOTE

You are advised to call onDestroy to listen to the destruction of the extended VPN and clear resources in a timely manner.

System capability: SystemCapability.Ability.AbilityRuntime.Core.

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

Parameters

Name Type Mandatory Description
want Want Yes Want information.

onDestroy

onDestroy(): void

Represents the callback triggered when the extended VPN is destroyed.

System capability: SystemCapability.Ability.AbilityRuntime.Core.

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