161847f8eSopenharmony_ci/*
261847f8eSopenharmony_ci * Copyright (C) 2023 Huawei Device Co., Ltd.
361847f8eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
461847f8eSopenharmony_ci * you may not use this file except in compliance with the License.
561847f8eSopenharmony_ci * You may obtain a copy of the License at
661847f8eSopenharmony_ci *
761847f8eSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
861847f8eSopenharmony_ci *
961847f8eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1061847f8eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1161847f8eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1261847f8eSopenharmony_ci * See the License for the specific language governing permissions and
1361847f8eSopenharmony_ci * limitations under the License.
1461847f8eSopenharmony_ci */
1561847f8eSopenharmony_ci
1661847f8eSopenharmony_ci/**
1761847f8eSopenharmony_ci * @file
1861847f8eSopenharmony_ci * @kit NetworkKit
1961847f8eSopenharmony_ci */
2061847f8eSopenharmony_ci
2161847f8eSopenharmony_ciimport type connection from './@ohos.net.connection';
2261847f8eSopenharmony_ciimport type _VpnExtensionContext from './application/VpnExtensionContext';
2361847f8eSopenharmony_ciimport type Want from './@ohos.app.ability.Want';
2461847f8eSopenharmony_ci
2561847f8eSopenharmony_ci/**
2661847f8eSopenharmony_ci * Provides VPN related interfaces.
2761847f8eSopenharmony_ci * @namespace vpnExtension
2861847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.Vpn
2961847f8eSopenharmony_ci * @since 11
3061847f8eSopenharmony_ci */
3161847f8eSopenharmony_cideclare namespace vpnExtension {
3261847f8eSopenharmony_ci  /**
3361847f8eSopenharmony_ci   * Get network link information.
3461847f8eSopenharmony_ci   * @typedef { connection.LinkAddress }
3561847f8eSopenharmony_ci   * @syscap SystemCapability.Communication.NetManager.Core
3661847f8eSopenharmony_ci   * @since 11
3761847f8eSopenharmony_ci   */
3861847f8eSopenharmony_ci  export type LinkAddress = connection.LinkAddress;
3961847f8eSopenharmony_ci
4061847f8eSopenharmony_ci  /**
4161847f8eSopenharmony_ci   * Get network route information.
4261847f8eSopenharmony_ci   * @typedef { connection.RouteInfo }
4361847f8eSopenharmony_ci   * @syscap SystemCapability.Communication.NetManager.Core
4461847f8eSopenharmony_ci   * @since 11
4561847f8eSopenharmony_ci   */
4661847f8eSopenharmony_ci  export type RouteInfo = connection.RouteInfo;
4761847f8eSopenharmony_ci
4861847f8eSopenharmony_ci  /**
4961847f8eSopenharmony_ci   * The context of vpn extension. It allows access to
5061847f8eSopenharmony_ci   * serviceExtension-specific resources.
5161847f8eSopenharmony_ci   * @typedef _VpnExtensionContext
5261847f8eSopenharmony_ci   * @syscap SystemCapability.Ability.AbilityRuntime.Core
5361847f8eSopenharmony_ci   * @since 11
5461847f8eSopenharmony_ci   */
5561847f8eSopenharmony_ci  export type VpnExtensionContext = _VpnExtensionContext;
5661847f8eSopenharmony_ci
5761847f8eSopenharmony_ci  /**
5861847f8eSopenharmony_ci   * Starts a new vpn extension ability.
5961847f8eSopenharmony_ci   *
6061847f8eSopenharmony_ci   * @param { Want } want - Indicates the want info to start.
6161847f8eSopenharmony_ci   * @returns { Promise<void> } The promise returned by the function.
6261847f8eSopenharmony_ci   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
6361847f8eSopenharmony_ci   * @throws { BusinessError } 16000001 - The specified ability does not exist.
6461847f8eSopenharmony_ci   * @throws { BusinessError } 16000002 - Incorrect ability type.
6561847f8eSopenharmony_ci   * @throws { BusinessError } 16000006 - Cross-user operations are not allowed.
6661847f8eSopenharmony_ci   * @throws { BusinessError } 16000008 - The crowdtesting application expires.
6761847f8eSopenharmony_ci   * @throws { BusinessError } 16000011 - The context does not exist.
6861847f8eSopenharmony_ci   * @throws { BusinessError } 16000050 - Internal error.
6961847f8eSopenharmony_ci   * @throws { BusinessError } 16200001 - The caller has been released.
7061847f8eSopenharmony_ci   * @syscap SystemCapability.Ability.AbilityRuntime.Core
7161847f8eSopenharmony_ci   * @stagemodelonly
7261847f8eSopenharmony_ci   * @since 11
7361847f8eSopenharmony_ci   */
7461847f8eSopenharmony_ci  function startVpnExtensionAbility(want: Want): Promise<void>;
7561847f8eSopenharmony_ci
7661847f8eSopenharmony_ci  /**
7761847f8eSopenharmony_ci   * Stops a service within the same application.
7861847f8eSopenharmony_ci   *
7961847f8eSopenharmony_ci   * @param { Want } want - Indicates the want info to start.
8061847f8eSopenharmony_ci   * @returns { Promise<void> } The promise returned by the function.
8161847f8eSopenharmony_ci   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
8261847f8eSopenharmony_ci   * @throws { BusinessError } 16000001 - The specified ability does not exist.
8361847f8eSopenharmony_ci   * @throws { BusinessError } 16000002 - Incorrect ability type.
8461847f8eSopenharmony_ci   * @throws { BusinessError } 16000006 - Cross-user operations are not allowed.
8561847f8eSopenharmony_ci   * @throws { BusinessError } 16000011 - The context does not exist.
8661847f8eSopenharmony_ci   * @throws { BusinessError } 16000050 - Internal error.
8761847f8eSopenharmony_ci   * @throws { BusinessError } 16200001 - The caller has been released.
8861847f8eSopenharmony_ci   * @syscap SystemCapability.Ability.AbilityRuntime.Core
8961847f8eSopenharmony_ci   * @stagemodelonly
9061847f8eSopenharmony_ci   * @since 11
9161847f8eSopenharmony_ci   */
9261847f8eSopenharmony_ci  function stopVpnExtensionAbility(want: Want): Promise<void>;
9361847f8eSopenharmony_ci
9461847f8eSopenharmony_ci  /**
9561847f8eSopenharmony_ci   * Set the Enable/Disable Always on VPN mode for a device.
9661847f8eSopenharmony_ci   * 
9761847f8eSopenharmony_ci   * @permission ohos.permission.MANAGE_VPN
9861847f8eSopenharmony_ci   * @param { boolean } enable - Always on enable or disable
9961847f8eSopenharmony_ci   * @param { string } bundleName - bundleName is used to set always on.
10061847f8eSopenharmony_ci   * @returns { Promise<void> } The promise returned by the function.
10161847f8eSopenharmony_ci   * @throws { BusinessError } 201 - Permission denied.
10261847f8eSopenharmony_ci   * @throws { BusinessError } 202 - Non-system applications use system APIs.
10361847f8eSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error.
10461847f8eSopenharmony_ci   * @syscap SystemCapability.Communication.NetManager.Vpn
10561847f8eSopenharmony_ci   * @systemapi Hide this for inner system use.
10661847f8eSopenharmony_ci   * @stagemodelonly
10761847f8eSopenharmony_ci   * @since 11
10861847f8eSopenharmony_ci   */
10961847f8eSopenharmony_ci  function setAlwaysOnVpnEnabled(enable: boolean, bundleName: string): Promise<void>;
11061847f8eSopenharmony_ci
11161847f8eSopenharmony_ci  /**
11261847f8eSopenharmony_ci   * Get the Always on VPN mode status for a device.
11361847f8eSopenharmony_ci   * 
11461847f8eSopenharmony_ci   * @permission ohos.permission.MANAGE_VPN
11561847f8eSopenharmony_ci   * @param { string } bundleName - bundleName is used to retrieve whether it has the always on.
11661847f8eSopenharmony_ci   * @returns { Promise<boolean>} return the mode for alway on vpn status
11761847f8eSopenharmony_ci   * @throws { BusinessError } 201 - Permission denied.
11861847f8eSopenharmony_ci   * @throws { BusinessError } 202 - Non-system applications use system APIs.
11961847f8eSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error.
12061847f8eSopenharmony_ci   * @syscap SystemCapability.Communication.NetManager.Vpn
12161847f8eSopenharmony_ci   * @systemapi Hide this for inner system use.
12261847f8eSopenharmony_ci   * @stagemodelonly
12361847f8eSopenharmony_ci   * @since 11
12461847f8eSopenharmony_ci   */
12561847f8eSopenharmony_ci  function isAlwaysOnVpnEnabled(bundleName: string): Promise<boolean>;
12661847f8eSopenharmony_ci
12761847f8eSopenharmony_ci  /**
12861847f8eSopenharmony_ci   * Update a VPN dialog authorize information
12961847f8eSopenharmony_ci   * 
13061847f8eSopenharmony_ci   * @permission ohos.permission.MANAGE_VPN
13161847f8eSopenharmony_ci   * @param { string } bundleName - authorize or not
13261847f8eSopenharmony_ci   * @returns { boolean } The promise returned by the function.
13361847f8eSopenharmony_ci   * @throws { BusinessError } 201 - Permission denied.
13461847f8eSopenharmony_ci   * @throws { BusinessError } 202 - Non-system applications use system APIs.
13561847f8eSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error.
13661847f8eSopenharmony_ci   * @syscap SystemCapability.Communication.NetManager.Vpn
13761847f8eSopenharmony_ci   * @systemapi Hide this for inner system use.
13861847f8eSopenharmony_ci   * @stagemodelonly
13961847f8eSopenharmony_ci   * @since 11
14061847f8eSopenharmony_ci   */
14161847f8eSopenharmony_ci  function updateVpnAuthorizedState(bundleName: string): boolean;
14261847f8eSopenharmony_ci  /**
14361847f8eSopenharmony_ci   * Create a VPN connection using the VpnExtensionContext.
14461847f8eSopenharmony_ci   * 
14561847f8eSopenharmony_ci   * @param { VpnExtensionContext } context - Indicates the context of application or capability.
14661847f8eSopenharmony_ci   * @returns { VpnConnection } the VpnConnection of the construct VpnConnection instance.
14761847f8eSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error.
14861847f8eSopenharmony_ci   * @syscap SystemCapability.Communication.NetManager.Vpn
14961847f8eSopenharmony_ci   * @stagemodelonly
15061847f8eSopenharmony_ci   * @since 11
15161847f8eSopenharmony_ci   */
15261847f8eSopenharmony_ci  function createVpnConnection(context: VpnExtensionContext): VpnConnection;
15361847f8eSopenharmony_ci
15461847f8eSopenharmony_ci  /**
15561847f8eSopenharmony_ci   * Defines a VPN connection.
15661847f8eSopenharmony_ci   * 
15761847f8eSopenharmony_ci   * @interface VpnConnection
15861847f8eSopenharmony_ci   * @syscap SystemCapability.Communication.NetManager.Vpn
15961847f8eSopenharmony_ci   * @since 11
16061847f8eSopenharmony_ci   */
16161847f8eSopenharmony_ci  export interface VpnConnection {
16261847f8eSopenharmony_ci 
16361847f8eSopenharmony_ci    /**
16461847f8eSopenharmony_ci     * Create a VPN network using the VpnConfig.
16561847f8eSopenharmony_ci     * 
16661847f8eSopenharmony_ci     * @param { VpnConfig } config - Indicates the {@link VpnConfig} configuration of the VPN network.
16761847f8eSopenharmony_ci     * @returns { Promise<number> } The promise returns file descriptor of VPN interface.
16861847f8eSopenharmony_ci     * @throws { BusinessError } 401 - Parameter error.
16961847f8eSopenharmony_ci     * @throws { BusinessError } 2200001 - Invalid parameter value.
17061847f8eSopenharmony_ci     * @throws { BusinessError } 2200002 - Operation failed. Cannot connect to service.
17161847f8eSopenharmony_ci     * @throws { BusinessError } 2200003 - System internal error.
17261847f8eSopenharmony_ci     * @throws { BusinessError } 2203001 - VPN creation denied, please check the user type.
17361847f8eSopenharmony_ci     * @throws { BusinessError } 2203002 - VPN exist already, please execute destroy first.
17461847f8eSopenharmony_ci     * @syscap SystemCapability.Communication.NetManager.Vpn
17561847f8eSopenharmony_ci     * @since 11
17661847f8eSopenharmony_ci     */
17761847f8eSopenharmony_ci    create(config: VpnConfig): Promise<number>;
17861847f8eSopenharmony_ci 
17961847f8eSopenharmony_ci    /**
18061847f8eSopenharmony_ci     * Protect a socket from VPN connections. After protecting, data sent through this socket will go directly to the
18161847f8eSopenharmony_ci     * underlying network so its traffic will not be forwarded through the VPN.
18261847f8eSopenharmony_ci     * 
18361847f8eSopenharmony_ci     * @param { number } socketFd - File descriptor of socket, this socket from @ohos.net.socket.
18461847f8eSopenharmony_ci     * @returns { Promise<void> } The promise returned by the function.
18561847f8eSopenharmony_ci     * @throws { BusinessError } 401 - Parameter error.
18661847f8eSopenharmony_ci     * @throws { BusinessError } 2200001 - Invalid parameter value.
18761847f8eSopenharmony_ci     * @throws { BusinessError } 2200002 - Operation failed. Cannot connect to service.
18861847f8eSopenharmony_ci     * @throws { BusinessError } 2200003 - System internal error.
18961847f8eSopenharmony_ci     * @throws { BusinessError } 2203004 - Invalid socket file descriptor.
19061847f8eSopenharmony_ci     * @syscap SystemCapability.Communication.NetManager.Vpn
19161847f8eSopenharmony_ci     * @since 11
19261847f8eSopenharmony_ci     */
19361847f8eSopenharmony_ci    protect(socketFd: number): Promise<void>;
19461847f8eSopenharmony_ci 
19561847f8eSopenharmony_ci    /**
19661847f8eSopenharmony_ci     * Destroy the VPN network.
19761847f8eSopenharmony_ci     * 
19861847f8eSopenharmony_ci     * @returns { Promise<void> } The promise returned by the function.
19961847f8eSopenharmony_ci     * @throws { BusinessError } 401 - Parameter error.
20061847f8eSopenharmony_ci     * @throws { BusinessError } 2200002 - Operation failed. Cannot connect to service.
20161847f8eSopenharmony_ci     * @throws { BusinessError } 2200003 - System internal error.
20261847f8eSopenharmony_ci     * @syscap SystemCapability.Communication.NetManager.Vpn
20361847f8eSopenharmony_ci     * @since 11
20461847f8eSopenharmony_ci     */
20561847f8eSopenharmony_ci    destroy(): Promise<void>;
20661847f8eSopenharmony_ci  }
20761847f8eSopenharmony_ci
20861847f8eSopenharmony_ci  /**
20961847f8eSopenharmony_ci   * Define configuration of the VPN network.
21061847f8eSopenharmony_ci   * 
21161847f8eSopenharmony_ci   * @interface VpnConfig
21261847f8eSopenharmony_ci   * @syscap SystemCapability.Communication.NetManager.Vpn
21361847f8eSopenharmony_ci   * @since 11
21461847f8eSopenharmony_ci   */
21561847f8eSopenharmony_ci  export interface VpnConfig {
21661847f8eSopenharmony_ci    /**
21761847f8eSopenharmony_ci     * The array of addresses for VPN interface.
21861847f8eSopenharmony_ci     * 
21961847f8eSopenharmony_ci     * @type {Array<LinkAddress>}
22061847f8eSopenharmony_ci     * @syscap SystemCapability.Communication.NetManager.Vpn
22161847f8eSopenharmony_ci     * @since 11
22261847f8eSopenharmony_ci     */
22361847f8eSopenharmony_ci    addresses: Array<LinkAddress>;
22461847f8eSopenharmony_ci 
22561847f8eSopenharmony_ci    /**
22661847f8eSopenharmony_ci     * The array of routes for VPN interface.
22761847f8eSopenharmony_ci     * 
22861847f8eSopenharmony_ci     * @type {?Array<RouteInfo>}
22961847f8eSopenharmony_ci     * @syscap SystemCapability.Communication.NetManager.Vpn
23061847f8eSopenharmony_ci     * @since 11
23161847f8eSopenharmony_ci     */
23261847f8eSopenharmony_ci    routes?: Array<RouteInfo>;
23361847f8eSopenharmony_ci
23461847f8eSopenharmony_ci    /**
23561847f8eSopenharmony_ci     * The array of DNS servers for the VPN network.
23661847f8eSopenharmony_ci     * 
23761847f8eSopenharmony_ci     * @type {?Array<string>}
23861847f8eSopenharmony_ci     * @syscap SystemCapability.Communication.NetManager.Vpn
23961847f8eSopenharmony_ci     * @since 11
24061847f8eSopenharmony_ci     */
24161847f8eSopenharmony_ci    dnsAddresses?: Array<string>;
24261847f8eSopenharmony_ci 
24361847f8eSopenharmony_ci    /**
24461847f8eSopenharmony_ci     * The array of search domains for the DNS resolver.
24561847f8eSopenharmony_ci     * 
24661847f8eSopenharmony_ci     * @type {?Array<string>}
24761847f8eSopenharmony_ci     * @syscap SystemCapability.Communication.NetManager.Vpn
24861847f8eSopenharmony_ci     * @since 11
24961847f8eSopenharmony_ci     */
25061847f8eSopenharmony_ci    searchDomains?: Array<string>;
25161847f8eSopenharmony_ci 
25261847f8eSopenharmony_ci    /**
25361847f8eSopenharmony_ci     * The maximum transmission unit (MTU) for the VPN interface.
25461847f8eSopenharmony_ci     * 
25561847f8eSopenharmony_ci     * @type {?number}
25661847f8eSopenharmony_ci     * @syscap SystemCapability.Communication.NetManager.Vpn
25761847f8eSopenharmony_ci     * @since 11
25861847f8eSopenharmony_ci     */
25961847f8eSopenharmony_ci    mtu?: number;
26061847f8eSopenharmony_ci 
26161847f8eSopenharmony_ci    /**
26261847f8eSopenharmony_ci     * Whether ipv4 is supported. The default value is true.
26361847f8eSopenharmony_ci     * 
26461847f8eSopenharmony_ci     * @type {?boolean}
26561847f8eSopenharmony_ci     * @syscap SystemCapability.Communication.NetManager.Vpn
26661847f8eSopenharmony_ci     * @since 11
26761847f8eSopenharmony_ci     */
26861847f8eSopenharmony_ci    isIPv4Accepted?: boolean;
26961847f8eSopenharmony_ci 
27061847f8eSopenharmony_ci    /**
27161847f8eSopenharmony_ci     * Whether ipv6 is supported. The default value is false.
27261847f8eSopenharmony_ci     * 
27361847f8eSopenharmony_ci     * @type {?boolean}
27461847f8eSopenharmony_ci     * @syscap SystemCapability.Communication.NetManager.Vpn
27561847f8eSopenharmony_ci     * @since 11
27661847f8eSopenharmony_ci     */
27761847f8eSopenharmony_ci    isIPv6Accepted?: boolean;
27861847f8eSopenharmony_ci 
27961847f8eSopenharmony_ci    /**
28061847f8eSopenharmony_ci     * Whether to use the built-in VPN. The default value is false.
28161847f8eSopenharmony_ci     * 
28261847f8eSopenharmony_ci     * @type {?boolean}
28361847f8eSopenharmony_ci     * @syscap SystemCapability.Communication.NetManager.Vpn
28461847f8eSopenharmony_ci     * @since 11
28561847f8eSopenharmony_ci     */
28661847f8eSopenharmony_ci    isInternal?: boolean;
28761847f8eSopenharmony_ci 
28861847f8eSopenharmony_ci    /**
28961847f8eSopenharmony_ci     * Whether the VPN interface's file descriptor is in blocking/non-blocking mode. The default value is false.
29061847f8eSopenharmony_ci     * 
29161847f8eSopenharmony_ci     * @type {?boolean}
29261847f8eSopenharmony_ci     * @syscap SystemCapability.Communication.NetManager.Vpn
29361847f8eSopenharmony_ci     * @since 11
29461847f8eSopenharmony_ci     */
29561847f8eSopenharmony_ci    isBlocking?: boolean;
29661847f8eSopenharmony_ci 
29761847f8eSopenharmony_ci    /**
29861847f8eSopenharmony_ci     * The array of trustlist for the VPN network. The string indicates package name.
29961847f8eSopenharmony_ci     * 
30061847f8eSopenharmony_ci     * @type {?Array<string>}
30161847f8eSopenharmony_ci     * @syscap SystemCapability.Communication.NetManager.Vpn
30261847f8eSopenharmony_ci     * @since 11
30361847f8eSopenharmony_ci     */
30461847f8eSopenharmony_ci    trustedApplications?: Array<string>;
30561847f8eSopenharmony_ci 
30661847f8eSopenharmony_ci    /**
30761847f8eSopenharmony_ci     * The array of blocklist for the VPN network. The string indicates package name.
30861847f8eSopenharmony_ci     * 
30961847f8eSopenharmony_ci     * @type {?Array<string>}
31061847f8eSopenharmony_ci     * @syscap SystemCapability.Communication.NetManager.Vpn
31161847f8eSopenharmony_ci     * @since 11
31261847f8eSopenharmony_ci     */
31361847f8eSopenharmony_ci    blockedApplications?: Array<string>;
31461847f8eSopenharmony_ci  }
31561847f8eSopenharmony_ci}
31661847f8eSopenharmony_ciexport default vpnExtension;
31761847f8eSopenharmony_ci 
318