1/* 2 * Copyright (C) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * @file 18 * @kit NetworkKit 19 */ 20 21import type connection from './@ohos.net.connection'; 22import type _VpnExtensionContext from './application/VpnExtensionContext'; 23import type Want from './@ohos.app.ability.Want'; 24 25/** 26 * Provides VPN related interfaces. 27 * @namespace vpnExtension 28 * @syscap SystemCapability.Communication.NetManager.Vpn 29 * @since 11 30 */ 31declare namespace vpnExtension { 32 /** 33 * Get network link information. 34 * @syscap SystemCapability.Communication.NetManager.Core 35 * @since 11 36 */ 37 export type LinkAddress = connection.LinkAddress; 38 39 /** 40 * Get network route information. 41 * @syscap SystemCapability.Communication.NetManager.Core 42 * @since 11 43 */ 44 export type RouteInfo = connection.RouteInfo; 45 46 /** 47 * The context of vpn extension. It allows access to 48 * serviceExtension-specific resources. 49 * 50 * @syscap SystemCapability.Ability.AbilityRuntime.Core 51 * @since 11 52 */ 53 export type VpnExtensionContext = _VpnExtensionContext; 54 55 /** 56 * Starts a new vpn extension ability. 57 * 58 * @param { Want } want - Indicates the want info to start. 59 * @returns { Promise<void> } The promise returned by the function. 60 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 61 * @throws { BusinessError } 16000001 - The specified ability does not exist. 62 * @throws { BusinessError } 16000002 - Incorrect ability type. 63 * @throws { BusinessError } 16000006 - Cross-user operations are not allowed. 64 * @throws { BusinessError } 16000008 - The crowdtesting application expires. 65 * @throws { BusinessError } 16000011 - The context does not exist. 66 * @throws { BusinessError } 16000050 - Internal error. 67 * @throws { BusinessError } 16200001 - The caller has been released. 68 * @syscap SystemCapability.Ability.AbilityRuntime.Core 69 * @stagemodelonly 70 * @since 11 71 */ 72 function startVpnExtensionAbility(want: Want): Promise<void>; 73 74 /** 75 * Stops a service within the same application. 76 * 77 * @param { Want } want - Indicates the want info to start. 78 * @returns { Promise<void> } The promise returned by the function. 79 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 80 * @throws { BusinessError } 16000001 - The specified ability does not exist. 81 * @throws { BusinessError } 16000002 - Incorrect ability type. 82 * @throws { BusinessError } 16000006 - Cross-user operations are not allowed. 83 * @throws { BusinessError } 16000011 - The context does not exist. 84 * @throws { BusinessError } 16000050 - Internal error. 85 * @throws { BusinessError } 16200001 - The caller has been released. 86 * @syscap SystemCapability.Ability.AbilityRuntime.Core 87 * @stagemodelonly 88 * @since 11 89 */ 90 function stopVpnExtensionAbility(want: Want): Promise<void>; 91 92 /** 93 * Set the Enable/Disable Always on VPN mode for a device. 94 * 95 * @permission ohos.permission.MANAGE_VPN 96 * @param { boolean } enable - Always on enable or disable 97 * @param { string } bundleName - bundleName is used to set always on. 98 * @returns { Promise<void> } The promise returned by the function. 99 * @throws { BusinessError } 201 - Permission denied. 100 * @throws { BusinessError } 202 - Non-system applications use system APIs. 101 * @throws { BusinessError } 401 - Parameter error. 102 * @syscap SystemCapability.Communication.NetManager.Vpn 103 * @systemapi Hide this for inner system use. 104 * @stagemodelonly 105 * @since 11 106 */ 107 function setAlwaysOnVpnEnabled(enable: boolean, bundleName: string): Promise<void>; 108 109 /** 110 * Get the Always on VPN mode status for a device. 111 * 112 * @permission ohos.permission.MANAGE_VPN 113 * @param { string } bundleName - bundleName is used to retrieve whether it has the always on. 114 * @returns { Promise<boolean>} return the mode for alway on vpn status 115 * @throws { BusinessError } 201 - Permission denied. 116 * @throws { BusinessError } 202 - Non-system applications use system APIs. 117 * @throws { BusinessError } 401 - Parameter error. 118 * @syscap SystemCapability.Communication.NetManager.Vpn 119 * @systemapi Hide this for inner system use. 120 * @stagemodelonly 121 * @since 11 122 */ 123 function isAlwaysOnVpnEnabled(bundleName: string): Promise<boolean>; 124 125 /** 126 * Update a VPN dialog authorize information 127 * 128 * @permission ohos.permission.MANAGE_VPN 129 * @param { string } bundleName - authorize or not 130 * @returns { boolean } The promise returned by the function. 131 * @throws { BusinessError } 201 - Permission denied. 132 * @throws { BusinessError } 202 - Non-system applications use system APIs. 133 * @throws { BusinessError } 401 - Parameter error. 134 * @syscap SystemCapability.Communication.NetManager.Vpn 135 * @systemapi Hide this for inner system use. 136 * @stagemodelonly 137 * @since 11 138 */ 139 function updateVpnAuthorizedState(bundleName: string): boolean; 140 /** 141 * Create a VPN connection using the VpnExtensionContext. 142 * 143 * @param { VpnExtensionContext } context - Indicates the context of application or capability. 144 * @returns { VpnConnection } the VpnConnection of the construct VpnConnection instance. 145 * @throws { BusinessError } 401 - Parameter error. 146 * @syscap SystemCapability.Communication.NetManager.Vpn 147 * @stagemodelonly 148 * @since 11 149 */ 150 function createVpnConnection(context: VpnExtensionContext): VpnConnection; 151 152 /** 153 * Defines a VPN connection. 154 * 155 * @interface VpnConnection 156 * @syscap SystemCapability.Communication.NetManager.Vpn 157 * @since 11 158 */ 159 export interface VpnConnection { 160 161 /** 162 * Create a VPN network using the VpnConfig. 163 * 164 * @param { VpnConfig } config - Indicates the {@link VpnConfig} configuration of the VPN network. 165 * @returns { Promise<number> } The promise returns file descriptor of VPN interface. 166 * @throws { BusinessError } 401 - Parameter error. 167 * @throws { BusinessError } 2200001 - Invalid parameter value. 168 * @throws { BusinessError } 2200002 - Operation failed. Cannot connect to service. 169 * @throws { BusinessError } 2200003 - System internal error. 170 * @throws { BusinessError } 2203001 - VPN creation denied, please check the user type. 171 * @throws { BusinessError } 2203002 - VPN exist already, please execute destroy first. 172 * @syscap SystemCapability.Communication.NetManager.Vpn 173 * @since 11 174 */ 175 create(config: VpnConfig): Promise<number>; 176 177 /** 178 * Protect a socket from VPN connections. After protecting, data sent through this socket will go directly to the 179 * underlying network so its traffic will not be forwarded through the VPN. 180 * 181 * @param { number } socketFd - File descriptor of socket, this socket from @ohos.net.socket. 182 * @returns { Promise<void> } The promise returned by the function. 183 * @throws { BusinessError } 401 - Parameter error. 184 * @throws { BusinessError } 2200001 - Invalid parameter value. 185 * @throws { BusinessError } 2200002 - Operation failed. Cannot connect to service. 186 * @throws { BusinessError } 2200003 - System internal error. 187 * @throws { BusinessError } 2203004 - Invalid socket file descriptor. 188 * @syscap SystemCapability.Communication.NetManager.Vpn 189 * @since 11 190 */ 191 protect(socketFd: number): Promise<void>; 192 193 /** 194 * Destroy the VPN network. 195 * 196 * @returns { Promise<void> } The promise returned by the function. 197 * @throws { BusinessError } 401 - Parameter error. 198 * @throws { BusinessError } 2200002 - Operation failed. Cannot connect to service. 199 * @throws { BusinessError } 2200003 - System internal error. 200 * @syscap SystemCapability.Communication.NetManager.Vpn 201 * @since 11 202 */ 203 destroy(): Promise<void>; 204 } 205 206 /** 207 * Define configuration of the VPN network. 208 * 209 * @interface VpnConfig 210 * @syscap SystemCapability.Communication.NetManager.Vpn 211 * @since 11 212 */ 213 export interface VpnConfig { 214 /** 215 * The array of addresses for VPN interface. 216 * 217 * @type {Array<LinkAddress>} 218 * @syscap SystemCapability.Communication.NetManager.Vpn 219 * @since 11 220 */ 221 addresses: Array<LinkAddress>; 222 223 /** 224 * The array of routes for VPN interface. 225 * 226 * @type {?Array<RouteInfo>} 227 * @syscap SystemCapability.Communication.NetManager.Vpn 228 * @since 11 229 */ 230 routes?: Array<RouteInfo>; 231 232 /** 233 * The array of DNS servers for the VPN network. 234 * 235 * @type {?Array<string>} 236 * @syscap SystemCapability.Communication.NetManager.Vpn 237 * @since 11 238 */ 239 dnsAddresses?: Array<string>; 240 241 /** 242 * The array of search domains for the DNS resolver. 243 * 244 * @type {?Array<string>} 245 * @syscap SystemCapability.Communication.NetManager.Vpn 246 * @since 11 247 */ 248 searchDomains?: Array<string>; 249 250 /** 251 * The maximum transmission unit (MTU) for the VPN interface. 252 * 253 * @type {?number} 254 * @syscap SystemCapability.Communication.NetManager.Vpn 255 * @since 11 256 */ 257 mtu?: number; 258 259 /** 260 * Whether ipv4 is supported. The default value is true. 261 * 262 * @type {?boolean} 263 * @syscap SystemCapability.Communication.NetManager.Vpn 264 * @since 11 265 */ 266 isIPv4Accepted?: boolean; 267 268 /** 269 * Whether ipv6 is supported. The default value is false. 270 * 271 * @type {?boolean} 272 * @syscap SystemCapability.Communication.NetManager.Vpn 273 * @since 11 274 */ 275 isIPv6Accepted?: boolean; 276 277 /** 278 * Whether to use the built-in VPN. The default value is false. 279 * 280 * @type {?boolean} 281 * @syscap SystemCapability.Communication.NetManager.Vpn 282 * @since 11 283 */ 284 isInternal?: boolean; 285 286 /** 287 * Whether the VPN interface's file descriptor is in blocking/non-blocking mode. The default value is false. 288 * 289 * @type {?boolean} 290 * @syscap SystemCapability.Communication.NetManager.Vpn 291 * @since 11 292 */ 293 isBlocking?: boolean; 294 295 /** 296 * The array of trustlist for the VPN network. The string indicates package name. 297 * 298 * @type {?Array<string>} 299 * @syscap SystemCapability.Communication.NetManager.Vpn 300 * @since 11 301 */ 302 trustedApplications?: Array<string>; 303 304 /** 305 * The array of blocklist for the VPN network. The string indicates package name. 306 * 307 * @type {?Array<string>} 308 * @syscap SystemCapability.Communication.NetManager.Vpn 309 * @since 11 310 */ 311 blockedApplications?: Array<string>; 312 } 313} 314export default vpnExtension; 315 316