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 '@ohos.app.ability.VpnExtensionAbility';
How to Use
You can obtain a VpnExtensionContext object through a VpnExtensionAbility child class instance.
import VpnExtensionAbility from '@ohos.app.ability.VpnExtensionAbility';
import Want from '@ohos.app.ability.Want';
import vpnExt from '@ohos.net.vpnExtension';
let VpnConnection: vpnExt.VpnConnection;
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) {
// this.context is VpnExtensionContext
VpnConnection = vpnExt.createVpnConnection(this.context);
}
}
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 | Mandatory | Description |
---|---|---|---|
context | VpnExtensionContext | Yes | Specified context. |
onCreate
onCreate(want: Want): void
Represents the callback triggered when the extended VPN is initialized.
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.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
want | Want | Yes | Want information. |