1/* 2 * Copyright (C) 2022-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 16import { AsyncCallback, Callback } from './@ohos.base'; 17import http from './@ohos.net.http'; 18import socket from './@ohos.net.socket'; 19 20/** 21 * Provides interfaces to manage and use data networks. 22 * @namespace connection 23 * @syscap SystemCapability.Communication.NetManager.Core 24 * @since 8 25 */ 26/** 27 * Provides interfaces to manage and use data networks. 28 * @namespace connection 29 * @syscap SystemCapability.Communication.NetManager.Core 30 * @crossplatform 31 * @since 10 32 */ 33declare namespace connection { 34 type HttpRequest = http.HttpRequest; 35 type TCPSocket = socket.TCPSocket; 36 type UDPSocket = socket.UDPSocket; 37 38 /** 39 * Create a network connection with optional netSpecifier and timeout. 40 * @param { NetSpecifier } netSpecifier Indicates the network specifier. See {@link NetSpecifier}. 41 * @param { number } timeout The time in milliseconds to attempt looking for a suitable network before 42 * {@link NetConnection#netUnavailable} is called. 43 * @returns { NetConnection } the NetConnection of the NetSpecifier. 44 * @syscap SystemCapability.Communication.NetManager.Core 45 * @since 8 46 */ 47 /** 48 * Create a network connection with optional netSpecifier and timeout. 49 * @param { NetSpecifier } netSpecifier Indicates the network specifier. See {@link NetSpecifier}. 50 * @param { number } timeout The time in milliseconds to attempt looking for a suitable network before 51 * {@link NetConnection#netUnavailable} is called. 52 * @returns { NetConnection } the NetConnection of the NetSpecifier. 53 * @syscap SystemCapability.Communication.NetManager.Core 54 * @crossplatform 55 * @since 10 56 */ 57 function createNetConnection(netSpecifier?: NetSpecifier, timeout?: number): NetConnection; 58 59 /** 60 * Obtains the data network that is activated by default. 61 * To call this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. 62 * @permission ohos.permission.GET_NETWORK_INFO 63 * @param { AsyncCallback<NetHandle> } callback Returns the {@link NetHandle} object; 64 * returns {@code null} if the default network is not activated. 65 * @throws { BusinessError } 201 - Permission denied. 66 * @throws { BusinessError } 401 - Parameter error. 67 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 68 * @throws { BusinessError } 2100003 - System internal error. 69 * @syscap SystemCapability.Communication.NetManager.Core 70 * @since 8 71 */ 72 function getDefaultNet(callback: AsyncCallback<NetHandle>): void; 73 74 /** 75 * Obtains the data network that is activated by default. 76 * To call this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. 77 * @permission ohos.permission.GET_NETWORK_INFO 78 * @returns { Promise<NetHandle> } The promise returned by the function. 79 * @throws { BusinessError } 201 - Permission denied. 80 * @throws { BusinessError } 401 - Parameter error. 81 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 82 * @throws { BusinessError } 2100003 - System internal error. 83 * @syscap SystemCapability.Communication.NetManager.Core 84 * @since 8 85 */ 86 function getDefaultNet(): Promise<NetHandle>; 87 88 /** 89 * Obtains the data network that is activated by default. 90 * To call this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. 91 * @permission ohos.permission.GET_NETWORK_INFO 92 * @returns { NetHandle } if the default network is not activated. 93 * @throws { BusinessError } 201 - Permission denied. 94 * @throws { BusinessError } 401 - Parameter error. 95 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 96 * @throws { BusinessError } 2100003 - System internal error. 97 * @syscap SystemCapability.Communication.NetManager.Core 98 * @since 9 99 */ 100 function getDefaultNetSync(): NetHandle; 101 102 /** 103 * Obtains the list of data networks that are activated. 104 * To invoke this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. 105 * @permission ohos.permission.GET_NETWORK_INFO 106 * @param { AsyncCallback<Array<NetHandle>> } callback Returns the {@link NetHandle} object; returns {@code null} if no network is activated. 107 * @throws { BusinessError } 201 - Permission denied. 108 * @throws { BusinessError } 401 - Parameter error. 109 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 110 * @throws { BusinessError } 2100003 - System internal error. 111 * @syscap SystemCapability.Communication.NetManager.Core 112 * @since 8 113 */ 114 function getAllNets(callback: AsyncCallback<Array<NetHandle>>): void; 115 116 /** 117 * Obtains the list of data networks that are activated. 118 * To invoke this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. 119 * @permission ohos.permission.GET_NETWORK_INFO 120 * @returns { Promise<Array<NetHandle>> } The promise returned by the function. 121 * @throws { BusinessError } 201 - Permission denied. 122 * @throws { BusinessError } 401 - Parameter error. 123 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 124 * @throws { BusinessError } 2100003 - System internal error. 125 * @syscap SystemCapability.Communication.NetManager.Core 126 * @since 8 127 */ 128 function getAllNets(): Promise<Array<NetHandle>>; 129 130 /** 131 * Queries the connection properties of a network. 132 * This method requires the {@code ohos.permission.GET_NETWORK_INFO} permission. 133 * @permission ohos.permission.GET_NETWORK_INFO 134 * @param { NetHandle } netHandle Indicates the network to be queried. 135 * @param { AsyncCallback<ConnectionProperties> } callback Returns the {@link ConnectionProperties} object. 136 * @throws { BusinessError } 201 - Permission denied. 137 * @throws { BusinessError } 401 - Parameter error. 138 * @throws { BusinessError } 2100001 - Invalid parameter value. 139 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 140 * @throws { BusinessError } 2100003 - System internal error. 141 * @syscap SystemCapability.Communication.NetManager.Core 142 * @since 8 143 */ 144 function getConnectionProperties(netHandle: NetHandle, callback: AsyncCallback<ConnectionProperties>): void; 145 146 /** 147 * Queries the connection properties of a network. 148 * This method requires the {@code ohos.permission.GET_NETWORK_INFO} permission. 149 * @permission ohos.permission.GET_NETWORK_INFO 150 * @param { NetHandle } netHandle Indicates the network to be queried. 151 * @returns { Promise<ConnectionProperties> } The promise returned by the function. 152 * @throws { BusinessError } 201 - Permission denied. 153 * @throws { BusinessError } 401 - Parameter error. 154 * @throws { BusinessError } 2100001 - Invalid parameter value. 155 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 156 * @throws { BusinessError } 2100003 - System internal error. 157 * @syscap SystemCapability.Communication.NetManager.Core 158 * @since 8 159 */ 160 function getConnectionProperties(netHandle: NetHandle): Promise<ConnectionProperties>; 161 162 /** 163 * Obtains {@link NetCapabilities} of a {@link NetHandle} object. 164 * To invoke this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. 165 * @permission ohos.permission.GET_NETWORK_INFO 166 * @param { NetHandle } netHandle Indicates the handle. See {@link NetHandle}. 167 * @param { AsyncCallback<NetCapabilities> } callback Returns {@link NetCapabilities}; returns {@code null} if {@code handle} is invalid. 168 * @throws { BusinessError } 201 - Permission denied. 169 * @throws { BusinessError } 401 - Parameter error. 170 * @throws { BusinessError } 2100001 - Invalid parameter value. 171 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 172 * @throws { BusinessError } 2100003 - System internal error. 173 * @syscap SystemCapability.Communication.NetManager.Core 174 * @since 8 175 */ 176 function getNetCapabilities(netHandle: NetHandle, callback: AsyncCallback<NetCapabilities>): void; 177 178 /** 179 * Obtains {@link NetCapabilities} of a {@link NetHandle} object. 180 * To invoke this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. 181 * @permission ohos.permission.GET_NETWORK_INFO 182 * @param { NetHandle } netHandle Indicates the handle. See {@link NetHandle}. 183 * @returns { Promise<NetCapabilities> } The promise returned by the function. 184 * @throws { BusinessError } 201 - Permission denied. 185 * @throws { BusinessError } 401 - Parameter error. 186 * @throws { BusinessError } 2100001 - Invalid parameter value. 187 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 188 * @throws { BusinessError } 2100003 - System internal error. 189 * @syscap SystemCapability.Communication.NetManager.Core 190 * @since 8 191 */ 192 function getNetCapabilities(netHandle: NetHandle): Promise<NetCapabilities>; 193 194 /** 195 * Checks whether data traffic usage on the current network is metered. 196 * @permission ohos.permission.GET_NETWORK_INFO 197 * @param { AsyncCallback<boolean> } callback Returns {@code true} if data traffic usage on the current network is metered; 198 * returns {@code false} otherwise. 199 * @throws { BusinessError } 201 - Permission denied. 200 * @throws { BusinessError } 401 - Parameter error. 201 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 202 * @throws { BusinessError } 2100003 - System internal error. 203 * @syscap SystemCapability.Communication.NetManager.Core 204 * @since 9 205 */ 206 function isDefaultNetMetered(callback: AsyncCallback<boolean>): void; 207 208 /** 209 * Checks whether data traffic usage on the current network is metered. 210 * @permission ohos.permission.GET_NETWORK_INFO 211 * @returns { Promise<boolean> } the promise returned by the function. 212 * @throws { BusinessError } 201 - Permission denied. 213 * @throws { BusinessError } 401 - Parameter error. 214 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 215 * @throws { BusinessError } 2100003 - System internal error. 216 * @syscap SystemCapability.Communication.NetManager.Core 217 * @since 9 218 */ 219 function isDefaultNetMetered(): Promise<boolean>; 220 221 /** 222 * Checks whether the default data network is activated. 223 * @permission ohos.permission.GET_NETWORK_INFO 224 * @param { AsyncCallback<boolean> } callback Returns {@code true} if the default data network is activated; 225 * returns {@code false} otherwise. 226 * @throws { BusinessError } 201 - Permission denied. 227 * @throws { BusinessError } 401 - Parameter error. 228 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 229 * @throws { BusinessError } 2100003 - System internal error. 230 * @syscap SystemCapability.Communication.NetManager.Core 231 * @since 8 232 */ 233 /** 234 * Checks whether the default data network is activated. 235 * @permission ohos.permission.GET_NETWORK_INFO 236 * @param { AsyncCallback<boolean> } callback Returns {@code true} if the default data network is activated; 237 * returns {@code false} otherwise. 238 * @throws { BusinessError } 201 - Permission denied. 239 * @throws { BusinessError } 401 - Parameter error. 240 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 241 * @throws { BusinessError } 2100003 - System internal error. 242 * @syscap SystemCapability.Communication.NetManager.Core 243 * @crossplatform 244 * @since 10 245 */ 246 function hasDefaultNet(callback: AsyncCallback<boolean>): void; 247 248 /** 249 * Checks whether the default data network is activated. 250 * @permission ohos.permission.GET_NETWORK_INFO 251 * @returns { Promise<boolean> } The promise returned by the function. 252 * @throws { BusinessError } 201 - Permission denied. 253 * @throws { BusinessError } 401 - Parameter error. 254 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 255 * @throws { BusinessError } 2100003 - System internal error. 256 * @syscap SystemCapability.Communication.NetManager.Core 257 * @since 8 258 */ 259 /** 260 * Checks whether the default data network is activated. 261 * @permission ohos.permission.GET_NETWORK_INFO 262 * @returns { Promise<boolean> } The promise returned by the function. 263 * @throws { BusinessError } 201 - Permission denied. 264 * @throws { BusinessError } 401 - Parameter error. 265 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 266 * @throws { BusinessError } 2100003 - System internal error. 267 * @syscap SystemCapability.Communication.NetManager.Core 268 * @crossplatform 269 * @since 10 270 */ 271 function hasDefaultNet(): Promise<boolean>; 272 273 /** 274 * Enables the airplane mode for a device. 275 * To invoke this method, you must have the {@code ohos.permission.CONNECTIVITY_INTERNAL} permission. 276 * @permission ohos.permission.CONNECTIVITY_INTERNAL 277 * @param { AsyncCallback<void> } callback - the callback of enableAirplaneMode. 278 * @throws { BusinessError } 201 - Permission denied. 279 * @throws { BusinessError } 202 - Non-system applications use system APIs. 280 * @throws { BusinessError } 401 - Parameter error. 281 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 282 * @throws { BusinessError } 2100003 - System internal error. 283 * @syscap SystemCapability.Communication.NetManager.Core 284 * @systemapi Hide this for inner system use. Only used for system app. 285 * @since 8 286 */ 287 function enableAirplaneMode(callback: AsyncCallback<void>): void; 288 289 /** 290 * Enables the airplane mode for a device. 291 * To invoke this method, you must have the {@code ohos.permission.CONNECTIVITY_INTERNAL} permission. 292 * @permission ohos.permission.CONNECTIVITY_INTERNAL 293 * @returns { Promise<void> } The promise returned by the function. 294 * @throws { BusinessError } 201 - Permission denied. 295 * @throws { BusinessError } 202 - Non-system applications use system APIs. 296 * @throws { BusinessError } 401 - Parameter error. 297 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 298 * @throws { BusinessError } 2100003 - System internal error. 299 * @syscap SystemCapability.Communication.NetManager.Core 300 * @systemapi Hide this for inner system use. Only used for system app. 301 * @since 8 302 */ 303 function enableAirplaneMode(): Promise<void>; 304 305 /** 306 * Disables the airplane mode for a device. 307 * To invoke this method, you must have the {@code ohos.permission.CONNECTIVITY_INTERNAL} permission. 308 * @permission ohos.permission.CONNECTIVITY_INTERNAL 309 * @param { AsyncCallback<void> } callback - the callback of disableAirplaneMode. 310 * @throws { BusinessError } 201 - Permission denied. 311 * @throws { BusinessError } 202 - Non-system applications use system APIs. 312 * @throws { BusinessError } 401 - Parameter error. 313 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 314 * @throws { BusinessError } 2100003 - System internal error. 315 * @syscap SystemCapability.Communication.NetManager.Core 316 * @systemapi Hide this for inner system use. Only used for system app. 317 * @since 8 318 */ 319 function disableAirplaneMode(callback: AsyncCallback<void>): void; 320 321 /** 322 * Disables the airplane mode for a device. 323 * To invoke this method, you must have the {@code ohos.permission.CONNECTIVITY_INTERNAL} permission. 324 * @permission ohos.permission.CONNECTIVITY_INTERNAL 325 * @returns { Promise<void> } The promise returned by the function. 326 * @throws { BusinessError } 201 - Permission denied. 327 * @throws { BusinessError } 202 - Non-system applications use system APIs. 328 * @throws { BusinessError } 401 - Parameter error. 329 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 330 * @throws { BusinessError } 2100003 - System internal error. 331 * @syscap SystemCapability.Communication.NetManager.Core 332 * @systemapi Hide this for inner system use. Only used for system app. 333 * @since 8 334 */ 335 function disableAirplaneMode(): Promise<void>; 336 337 /** 338 * Reports the network state is connected. 339 * @permission ohos.permission.GET_NETWORK_INFO and ohos.permission.INTERNET 340 * @param { NetHandle } netHandle Indicates the network whose state is to be reported. 341 * @param { AsyncCallback<void> } callback - the callback of reportNetConnected. 342 * @throws { BusinessError } 201 - Permission denied. 343 * @throws { BusinessError } 401 - Parameter error. 344 * @throws { BusinessError } 2100001 - Invalid parameter value. 345 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 346 * @throws { BusinessError } 2100003 - System internal error. 347 * @syscap SystemCapability.Communication.NetManager.Core 348 * @since 8 349 */ 350 function reportNetConnected(netHandle: NetHandle, callback: AsyncCallback<void>): void; 351 352 /** 353 * Reports the network state is connected. 354 * @permission ohos.permission.GET_NETWORK_INFO and ohos.permission.INTERNET 355 * @param { NetHandle } netHandle Indicates the network whose state is to be reported. 356 * @returns { Promise<void> } The promise returned by the function. 357 * @throws { BusinessError } 201 - Permission denied. 358 * @throws { BusinessError } 401 - Parameter error. 359 * @throws { BusinessError } 2100001 - Invalid parameter value. 360 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 361 * @throws { BusinessError } 2100003 - System internal error. 362 * @syscap SystemCapability.Communication.NetManager.Core 363 * @since 8 364 */ 365 function reportNetConnected(netHandle: NetHandle): Promise<void>; 366 367 /** 368 * Reports the network state is disconnected. 369 * @permission ohos.permission.GET_NETWORK_INFO and ohos.permission.INTERNET 370 * @param { NetHandle } netHandle Indicates the network whose state is to be reported. 371 * @param { AsyncCallback<void> } callback - the callback of reportNetDisconnected. 372 * @throws { BusinessError } 201 - Permission denied. 373 * @throws { BusinessError } 401 - Parameter error. 374 * @throws { BusinessError } 2100001 - Invalid parameter value. 375 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 376 * @throws { BusinessError } 2100003 - System internal error. 377 * @syscap SystemCapability.Communication.NetManager.Core 378 * @since 8 379 */ 380 function reportNetDisconnected(netHandle: NetHandle, callback: AsyncCallback<void>): void; 381 382 /** 383 * Reports the network state is disconnected. 384 * @permission ohos.permission.GET_NETWORK_INFO and ohos.permission.INTERNET 385 * @param { NetHandle } netHandle Indicates the network whose state is to be reported. 386 * @returns { Promise<void> } The promise returned by the function. 387 * @throws { BusinessError } 201 - Permission denied. 388 * @throws { BusinessError } 401 - Parameter error. 389 * @throws { BusinessError } 2100001 - Invalid parameter value. 390 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 391 * @throws { BusinessError } 2100003 - System internal error. 392 * @syscap SystemCapability.Communication.NetManager.Core 393 * @since 8 394 */ 395 function reportNetDisconnected(netHandle: NetHandle): Promise<void>; 396 397 /** 398 * Resolves the host name to obtain all IP addresses based on the default data network. 399 * @permission ohos.permission.INTERNET 400 * @param { string } host Indicates the host name or the domain. 401 * @param { AsyncCallback<Array<NetAddress>> } callback Returns the NetAddress list. 402 * @throws { BusinessError } 201 - Permission denied. 403 * @throws { BusinessError } 401 - Parameter error. 404 * @throws { BusinessError } 2100001 - Invalid parameter value. 405 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 406 * @throws { BusinessError } 2100003 - System internal error. 407 * @syscap SystemCapability.Communication.NetManager.Core 408 * @since 8 409 */ 410 function getAddressesByName(host: string, callback: AsyncCallback<Array<NetAddress>>): void; 411 412 /** 413 * Resolves the host name to obtain all IP addresses based on the default data network. 414 * @permission ohos.permission.INTERNET 415 * @param { string } host Indicates the host name or the domain. 416 * @returns { Promise<Array<NetAddress>> } The promise returned by the function. 417 * @throws { BusinessError } 201 - Permission denied. 418 * @throws { BusinessError } 401 - Parameter error. 419 * @throws { BusinessError } 2100001 - Invalid parameter value. 420 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 421 * @throws { BusinessError } 2100003 - System internal error. 422 * @syscap SystemCapability.Communication.NetManager.Core 423 * @since 8 424 */ 425 function getAddressesByName(host: string): Promise<Array<NetAddress>>; 426 427 /** 428 * Obtains the {@link NetHandle} bound to a process using {@link setAppNet}. 429 * @param { AsyncCallback<NetHandle> } callback Returns the {@link NetHandle} bound to the process; 430 * returns {@code null} if no {@link NetHandle} is bound to the process.For details, see {@link NetHandle}. 431 * @throws { BusinessError } 401 - Parameter error. 432 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 433 * @throws { BusinessError } 2100003 - System internal error. 434 * @syscap SystemCapability.Communication.NetManager.Core 435 * @since 9 436 */ 437 function getAppNet(callback: AsyncCallback<NetHandle>): void; 438 439 /** 440 * Obtains the {@link NetHandle} bound to a process using {@link setAppNet}. 441 * @returns { Promise<NetHandle> } the promise returned by the function. 442 * @throws { BusinessError } 401 - Parameter error. 443 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 444 * @throws { BusinessError } 2100003 - System internal error. 445 * @syscap SystemCapability.Communication.NetManager.Core 446 * @since 9 447 */ 448 function getAppNet(): Promise<NetHandle>; 449 450 /** 451 * Binds a process to {@code NetHandle}. 452 * <p>All the sockets created from the process will be bound to the {@code NetHandle}, 453 * and the resolution of all host names will be managed by the {@code NetHandle}.</p> 454 * @permission ohos.permission.INTERNET 455 * @param { NetHandle } netHandle Indicates the handle. For details, see {@link NetHandle}. 456 * @param { AsyncCallback<void> } callback Returns the callback of setAppNet. 457 * @throws { BusinessError } 201 - Permission denied. 458 * @throws { BusinessError } 401 - Parameter error. 459 * @throws { BusinessError } 2100001 - Invalid parameter value. 460 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 461 * @throws { BusinessError } 2100003 - System internal error. 462 * @syscap SystemCapability.Communication.NetManager.Core 463 * @since 9 464 */ 465 function setAppNet(netHandle: NetHandle, callback: AsyncCallback<void>): void; 466 467 /** 468 * Binds a process to {@code NetHandle}. 469 * <p>All the sockets created from the process will be bound to the {@code NetHandle}, 470 * and the resolution of all host names will be managed by the {@code NetHandle}.</p> 471 * @permission ohos.permission.INTERNET 472 * @param { NetHandle } netHandle Indicates the handle. For details, see {@link NetHandle}. 473 * @returns { Promise<void> } the promise returned by the function. 474 * @throws { BusinessError } 201 - Permission denied. 475 * @throws { BusinessError } 401 - Parameter error. 476 * @throws { BusinessError } 2100001 - Invalid parameter value. 477 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 478 * @throws { BusinessError } 2100003 - System internal error. 479 * @syscap SystemCapability.Communication.NetManager.Core 480 * @since 9 481 */ 482 function setAppNet(netHandle: NetHandle): Promise<void>; 483 484 /** 485 * Obtains the network independent global {@link HttpProxy} proxy settings. 486 * 487 * If a application level proxy is set, the application level proxy parameters are returned. 488 * If a global proxy is set, the global proxy parameters are returned. 489 * If the process is bound to a {@link NetHandle} using {@link setAppNet}, the {@link NetHandle} proxy settings are returned. 490 * In other cases, the proxy settings of default network are returned. 491 * 492 * @param { AsyncCallback<HttpProxy> } callback Returns the proxy settings. For details, see {@link HttpProxy}. 493 * @throws { BusinessError } 401 - Parameter error. 494 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 495 * @throws { BusinessError } 2100003 - System internal error. 496 * @syscap SystemCapability.Communication.NetManager.Core 497 * @systemapi Hide this for inner system use. 498 * @since 10 499 */ 500 function getGlobalHttpProxy(callback: AsyncCallback<HttpProxy>): void; 501 502 /** 503 * Obtains the network independent global {@link HttpProxy} proxy settings. 504 * 505 * If a application level proxy is set, the application level proxy parameters are returned. 506 * If a global proxy is set, the global proxy parameters are returned. 507 * If the process is bound to a {@link NetHandle} using {@link setAppNet}, the {@link NetHandle} proxy settings are returned. 508 * In other cases, the proxy settings of default network are returned. 509 * 510 * @returns { Promise<HttpProxy> } the promise returned by the function. 511 * @throws { BusinessError } 401 - Parameter error. 512 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 513 * @throws { BusinessError } 2100003 - System internal error. 514 * @syscap SystemCapability.Communication.NetManager.Core 515 * @systemapi Hide this for inner system use. 516 * @since 10 517 */ 518 function getGlobalHttpProxy(): Promise<HttpProxy>; 519 520 /** 521 * Set application level http proxy {@link HttpProxy}. 522 * @param { HttpProxy } httpProxy - Indicates the application level proxy settings. For details, see {@link HttpProxy}. 523 * @throws { BusinessError } 401 - Parameter error. 524 * @throws { BusinessError } 2100001 - Invalid http proxy. 525 * @syscap SystemCapability.Communication.NetManager.Core 526 * @since 11 527 */ 528 529 function setAppHttpProxy(httpProxy: HttpProxy): void; 530 531 /** 532 * Set a network independent global {@link HttpProxy} proxy settings. 533 * @permission ohos.permission.CONNECTIVITY_INTERNAL 534 * @param { HttpProxy } httpProxy Indicates the global proxy settings. For details, see {@link HttpProxy}. 535 * @param { AsyncCallback<void> } callback Returns the callback of setGlobalHttpProxy. 536 * @throws { BusinessError } 201 - Permission denied. 537 * @throws { BusinessError } 401 - Parameter error. 538 * @throws { BusinessError } 2100001 - Invalid parameter value. 539 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 540 * @throws { BusinessError } 2100003 - System internal error. 541 * @syscap SystemCapability.Communication.NetManager.Core 542 * @systemapi Hide this for inner system use. 543 * @since 10 544 */ 545 function setGlobalHttpProxy(httpProxy: HttpProxy, callback: AsyncCallback<void>): void; 546 547 /** 548 * Set a network independent global {@link HttpProxy} proxy settings. 549 * @permission ohos.permission.CONNECTIVITY_INTERNAL 550 * @param { HttpProxy } httpProxy Indicates the global proxy settings. For details, see {@link HttpProxy}. 551 * @returns { Promise<void> } the promise returned by the function. 552 * @throws { BusinessError } 201 - Permission denied. 553 * @throws { BusinessError } 401 - Parameter error. 554 * @throws { BusinessError } 2100001 - Invalid parameter value. 555 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 556 * @throws { BusinessError } 2100003 - System internal error. 557 * @syscap SystemCapability.Communication.NetManager.Core 558 * @systemapi Hide this for inner system use. 559 * @since 10 560 */ 561 function setGlobalHttpProxy(httpProxy: HttpProxy): Promise<void>; 562 563 /** 564 * Obtains the default {@link HttpProxy} proxy settings. 565 * 566 * If a global proxy is set, the global proxy parameters are returned. 567 * If the process is bound to a {@link NetHandle} using {@link setAppNet}, 568 * the {@link NetHandle} proxy settings are returned. 569 * In other cases, the proxy settings of default network are returned. 570 * 571 * @param { AsyncCallback<HttpProxy> } callback Returns the default {@link HttpProxy} settings. 572 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 573 * @throws { BusinessError } 2100003 - System internal error. 574 * @syscap SystemCapability.Communication.NetManager.Core 575 * @since 10 576 */ 577 function getDefaultHttpProxy(callback: AsyncCallback<HttpProxy>): void; 578 579 /** 580 * Obtains the default {@link HttpProxy} proxy settings. 581 * 582 * If a global proxy is set, the global proxy parameters are returned. 583 * If the process is bound to a {@link NetHandle} using {@link setAppNet}, 584 * the {@link NetHandle} proxy settings are returned. 585 * In other cases, the proxy settings of default network are returned. 586 * 587 * @returns { Promise<HttpProxy> } the promise returned by the function. 588 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 589 * @throws { BusinessError } 2100003 - System internal error. 590 * @syscap SystemCapability.Communication.NetManager.Core 591 * @since 10 592 */ 593 function getDefaultHttpProxy(): Promise<HttpProxy>; 594 595 /** 596 * Add a custom {@link host} and corresponding {@link ip} mapping. 597 * @permission ohos.permission.INTERNET 598 * @param { string } host - Indicates the host name or the domain. 599 * @param { Array<string> } ip - List of IP addresses mapped to the host name. 600 * @param { AsyncCallback<void> } callback - Returns the callback of addCustomDnsRule. 601 * @throws { BusinessError } 201 - Permission denied. 602 * @throws { BusinessError } 401 - Parameter error. 603 * @throws { BusinessError } 2100001 - Invalid parameter value. 604 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 605 * @throws { BusinessError } 2100003 - System internal error. 606 * @syscap SystemCapability.Communication.NetManager.Core 607 * @since 11 608 */ 609 function addCustomDnsRule(host: string, ip: Array<string>, callback: AsyncCallback<void>): void; 610 611 /** 612 * Add a custom {@link host} and corresponding {@link ip} mapping. 613 * @permission ohos.permission.INTERNET 614 * @param { string } host - Indicates the host name or the domain. 615 * @param { Array<string> } ip - List of IP addresses mapped to the host name. 616 * @returns { Promise<void> } the promise returned by the function. 617 * @throws { BusinessError } 201 - Permission denied. 618 * @throws { BusinessError } 401 - Parameter error. 619 * @throws { BusinessError } 2100001 - Invalid parameter value. 620 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 621 * @throws { BusinessError } 2100003 - System internal error. 622 * @syscap SystemCapability.Communication.NetManager.Core 623 * @since 11 624 */ 625 function addCustomDnsRule(host: string, ip: Array<string>): Promise<void>; 626 627 /** 628 * Remove the custom DNS rule of the {@link host}. 629 * @permission ohos.permission.INTERNET 630 * @param { string } host - Indicates the host name or the domain. 631 * @param { AsyncCallback<void> } callback - Returns the callback of removeCustomDnsRule. 632 * @throws { BusinessError } 201 - Permission denied. 633 * @throws { BusinessError } 401 - Parameter error. 634 * @throws { BusinessError } 2100001 - Invalid parameter value. 635 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 636 * @throws { BusinessError } 2100003 - System internal error. 637 * @syscap SystemCapability.Communication.NetManager.Core 638 * @since 11 639 */ 640 function removeCustomDnsRule(host: string, callback: AsyncCallback<void>): void; 641 642 /** 643 * Remove the custom DNS rule of the {@link host}. 644 * @permission ohos.permission.INTERNET 645 * @param { string } host - Indicates the host name or the domain. 646 * @returns { Promise<void> } the promise returned by the function. 647 * @throws { BusinessError } 201 - Permission denied. 648 * @throws { BusinessError } 401 - Parameter error. 649 * @throws { BusinessError } 2100001 - Invalid parameter value. 650 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 651 * @throws { BusinessError } 2100003 - System internal error. 652 * @syscap SystemCapability.Communication.NetManager.Core 653 * @since 11 654 */ 655 function removeCustomDnsRule(host: string): Promise<void>; 656 657 /** 658 * Clear all custom DNS rules. 659 * @permission ohos.permission.INTERNET 660 * @param { AsyncCallback<void> } callback - Returns the callback of clearCustomDnsRules. 661 * @throws { BusinessError } 201 - Permission denied. 662 * @throws { BusinessError } 401 - Parameter error. 663 * @throws { BusinessError } 2100001 - Invalid parameter value. 664 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 665 * @throws { BusinessError } 2100003 - System internal error. 666 * @syscap SystemCapability.Communication.NetManager.Core 667 * @since 11 668 */ 669 function clearCustomDnsRules(callback: AsyncCallback<void>): void; 670 671 /** 672 * Clear all custom DNS rules. 673 * @permission ohos.permission.INTERNET 674 * @returns { Promise<void> } the promise returned by the function. 675 * @throws { BusinessError } 201 - Permission denied. 676 * @throws { BusinessError } 401 - Parameter error. 677 * @throws { BusinessError } 2100001 - Invalid parameter value. 678 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 679 * @throws { BusinessError } 2100003 - System internal error. 680 * @syscap SystemCapability.Communication.NetManager.Core 681 * @since 11 682 */ 683 function clearCustomDnsRules(): Promise<void>; 684 685 /** 686 * factory reset network settings 687 * 688 * To invoke this method, you must have the {@code ohos.permission.CONNECTIVITY_INTERNAL} permission. 689 * @permission ohos.permission.CONNECTIVITY_INTERNAL 690 * @returns { Promise<void> } the promise returned by the function. 691 * @throws { BusinessError } 201 - Permission denied. 692 * @throws { BusinessError } 202 - Non-system applications use system APIs. 693 * @throws { BusinessError } 401 - Parameter error. 694 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 695 * @throws { BusinessError } 2100003 - System internal error. 696 * @syscap SystemCapability.Communication.NetManager.Core 697 * @systemapi Hide this for inner system use. Only used for system app. 698 * @since 11 699 */ 700 function factoryReset(): Promise<void>; 701 702 /** 703 * Represents the network connection handle. 704 * @interface NetConnection 705 * @syscap SystemCapability.Communication.NetManager.Core 706 * @since 8 707 */ 708 /** 709 * Represents the network connection handle. 710 * @interface NetConnection 711 * @syscap SystemCapability.Communication.NetManager.Core 712 * @crossplatform 713 * @since 10 714 */ 715 export interface NetConnection { 716 /** 717 * Registers a listener for netAvailable events. 718 * @param { 'netAvailable' } type Indicates Event name. 719 * @param { Callback<NetHandle> } callback - the callback of on. 720 * @syscap SystemCapability.Communication.NetManager.Core 721 * @since 8 722 */ 723 /** 724 * Registers a listener for netAvailable events. 725 * @param { 'netAvailable' } type Indicates Event name. 726 * @param { Callback<NetHandle> } callback - the callback of on. 727 * @syscap SystemCapability.Communication.NetManager.Core 728 * @crossplatform 729 * @since 10 730 */ 731 on(type: 'netAvailable', callback: Callback<NetHandle>): void; 732 733 /** 734 * Registers a listener for netBlockStatusChange events. 735 * @param { 'netBlockStatusChange' } type Indicates Event name. 736 * @param { Callback<{ netHandle: NetHandle, blocked: boolean }> } callback - the callback of on. 737 * @syscap SystemCapability.Communication.NetManager.Core 738 * @since 8 739 */ 740 on(type: 'netBlockStatusChange', callback: Callback<{ netHandle: NetHandle, blocked: boolean }>): void; 741 742 /** 743 * Registers a listener for **netCapabilitiesChange** events. 744 * @param { 'netCapabilitiesChange' } type Indicates Event name. 745 * @param { Callback<{ netHandle: NetHandle, netCap: NetCapabilities }> } callback - the callback of on. 746 * @syscap SystemCapability.Communication.NetManager.Core 747 * @since 8 748 */ 749 /** 750 * Registers a listener for **netCapabilitiesChange** events. 751 * @param { 'netCapabilitiesChange' } type Indicates Event name. 752 * @param { Callback<{ netHandle: NetHandle, netCap: NetCapabilities }> } callback - the callback of on. 753 * @syscap SystemCapability.Communication.NetManager.Core 754 * @crossplatform 755 * @since 10 756 */ 757 on(type: 'netCapabilitiesChange', callback: Callback<{ netHandle: NetHandle, netCap: NetCapabilities }>): void; 758 759 /** 760 * Registers a listener for netConnectionPropertiesChange events. 761 * @param { 'netConnectionPropertiesChange' } type Indicates Event name. 762 * @param { Callback<{ netHandle: NetHandle, connectionProperties: ConnectionProperties }> } callback - the callback of on. 763 * @syscap SystemCapability.Communication.NetManager.Core 764 * @since 8 765 */ 766 on(type: 'netConnectionPropertiesChange', callback: Callback<{ netHandle: NetHandle, connectionProperties: ConnectionProperties }>): void; 767 768 /** 769 * Registers a listener for **netLost** events. 770 * @param { 'netLost' } type Indicates Event name. 771 * @param { Callback<NetHandle> } callback - the callback of on. 772 * @syscap SystemCapability.Communication.NetManager.Core 773 * @since 8 774 */ 775 /** 776 * Registers a listener for **netLost** events. 777 * @param { 'netLost' } type Indicates Event name. 778 * @param { Callback<NetHandle> } callback - the callback of on. 779 * @syscap SystemCapability.Communication.NetManager.Core 780 * @crossplatform 781 * @since 10 782 */ 783 on(type: 'netLost', callback: Callback<NetHandle>): void; 784 785 /** 786 * Registers a listener for netUnavailable events. 787 * @param { 'netUnavailable' } type Indicates Event name. 788 * @param { Callback<void> } callback - the callback of on. 789 * @syscap SystemCapability.Communication.NetManager.Core 790 * @since 8 791 */ 792 /** 793 * Registers a listener for netUnavailable events. 794 * @param { 'netUnavailable' } type Indicates Event name. 795 * @param { Callback<void> } callback - the callback of on. 796 * @syscap SystemCapability.Communication.NetManager.Core 797 * @crossplatform 798 * @since 10 799 */ 800 on(type: 'netUnavailable', callback: Callback<void>): void; 801 802 /** 803 * Receives status change notifications of a specified network. 804 * @permission ohos.permission.GET_NETWORK_INFO 805 * @param { AsyncCallback<void> } callback - the callback of register. 806 * @throws { BusinessError } 201 - Permission denied. 807 * @throws { BusinessError } 401 - Parameter error. 808 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 809 * @throws { BusinessError } 2100003 - System internal error. 810 * @throws { BusinessError } 2101008 - The same callback exists. 811 * @throws { BusinessError } 2101022 - The number of requests exceeded the maximum. 812 * @syscap SystemCapability.Communication.NetManager.Core 813 * @since 8 814 */ 815 /** 816 * Receives status change notifications of a specified network. 817 * @permission ohos.permission.GET_NETWORK_INFO 818 * @param { AsyncCallback<void> } callback - the callback of register. 819 * @throws { BusinessError } 201 - Permission denied. 820 * @throws { BusinessError } 401 - Parameter error. 821 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 822 * @throws { BusinessError } 2100003 - System internal error. 823 * @throws { BusinessError } 2101008 - The same callback exists. 824 * @throws { BusinessError } 2101022 - The number of requests exceeded the maximum. 825 * @syscap SystemCapability.Communication.NetManager.Core 826 * @crossplatform 827 * @since 10 828 */ 829 register(callback: AsyncCallback<void>): void; 830 831 /** 832 * Cancels listening for network status changes. 833 * @param { AsyncCallback<void> } callback - the callback of unregister. 834 * @throws { BusinessError } 201 - Permission denied. 835 * @throws { BusinessError } 401 - Parameter error. 836 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 837 * @throws { BusinessError } 2100003 - System internal error. 838 * @throws { BusinessError } 2101007 - The callback is not exists. 839 * @syscap SystemCapability.Communication.NetManager.Core 840 * @since 8 841 */ 842 /** 843 * Cancels listening for network status changes. 844 * @param { AsyncCallback<void> } callback - the callback of unregister. 845 * @throws { BusinessError } 201 - Permission denied. 846 * @throws { BusinessError } 401 - Parameter error. 847 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 848 * @throws { BusinessError } 2100003 - System internal error. 849 * @throws { BusinessError } 2101007 - The callback is not exists. 850 * @syscap SystemCapability.Communication.NetManager.Core 851 * @crossplatform 852 * @since 10 853 */ 854 unregister(callback: AsyncCallback<void>): void; 855 } 856 857 /** 858 * Provides an instance that bear data network capabilities. 859 * @interface NetSpecifier 860 * @syscap SystemCapability.Communication.NetManager.Core 861 * @since 8 862 */ 863 export interface NetSpecifier { 864 /** 865 * The transmission capacity and support of the network's global proxy storage data network. 866 * @type {NetCapabilities} 867 * @syscap SystemCapability.Communication.NetManager.Core 868 * @since 8 869 */ 870 netCapabilities: NetCapabilities; 871 872 /** 873 * Network identifier, the identifier for Wi Fi networks is "wifi", and the identifier for cellular networks is "simId1" (corresponding to SIM card 1). 874 * @type {?string} 875 * @syscap SystemCapability.Communication.NetManager.Core 876 * @since 8 877 */ 878 bearerPrivateIdentifier?: string; 879 } 880 881 /** 882 * Defines the handle of the data network. 883 * @interface NetHandle 884 * @syscap SystemCapability.Communication.NetManager.Core 885 * @since 8 886 */ 887 /** 888 * Defines the handle of the data network. 889 * @interface NetHandle 890 * @syscap SystemCapability.Communication.NetManager.Core 891 * @crossplatform 892 * @since 10 893 */ 894 export interface NetHandle { 895 /** 896 * Network ID, a value of 0 means that there is no default network, and the other values must be greater than or equal to 100. 897 * @type {number} 898 * @syscap SystemCapability.Communication.NetManager.Core 899 * @since 8 900 */ 901 /** 902 * Network ID, a value of 0 means that there is no default network, and the other values must be greater than or equal to 100. 903 * @type {number} 904 * @syscap SystemCapability.Communication.NetManager.Core 905 * @crossplatform 906 * @since 10 907 */ 908 netId: number; 909 910 /** 911 * <p>Binds a TCPSocket or UDPSocket to the current network. All data flows from 912 * the socket will use this network, without being subject to {@link setAppNet}.</p> 913 * Before using this method, ensure that the socket is disconnected. 914 * @param { TCPSocket | UDPSocket } socketParam Indicates the TCPSocket or UDPSocket object. 915 * @param { AsyncCallback<void> } callback - the callback of bindSocket. 916 * @throws { BusinessError } 401 - Parameter error. 917 * @throws { BusinessError } 2100001 - Invalid parameter value. 918 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 919 * @throws { BusinessError } 2100003 - System internal error. 920 * @syscap SystemCapability.Communication.NetManager.Core 921 * @since 9 922 */ 923 bindSocket(socketParam: TCPSocket | UDPSocket, callback: AsyncCallback<void>): void; 924 925 /** 926 * <p>Binds a TCPSocket or UDPSocket to the current network. All data flows from 927 * the socket will use this network, without being subject to {@link setAppNet}.</p> 928 * Before using this method, ensure that the socket is disconnected. 929 * @param { TCPSocket | UDPSocket } socketParam Indicates the TCPSocket or UDPSocket object. 930 * @returns { Promise<void> } the promise returned by the function. 931 * @throws { BusinessError } 401 - Parameter error. 932 * @throws { BusinessError } 2100001 - Invalid parameter value. 933 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 934 * @throws { BusinessError } 2100003 - System internal error. 935 * @syscap SystemCapability.Communication.NetManager.Core 936 * @since 9 937 */ 938 bindSocket(socketParam: TCPSocket | UDPSocket): Promise<void>; 939 940 /** 941 * Resolves a host name to obtain all IP addresses based on the specified NetHandle. 942 * @permission ohos.permission.INTERNET 943 * @param { string } host Indicates the host name or the domain. 944 * @param { AsyncCallback<Array<NetAddress>> } callback Returns the NetAddress list. 945 * @throws { BusinessError } 201 - Permission denied. 946 * @throws { BusinessError } 401 - Parameter error. 947 * @throws { BusinessError } 2100001 - Invalid parameter value. 948 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 949 * @throws { BusinessError } 2100003 - System internal error. 950 * @syscap SystemCapability.Communication.NetManager.Core 951 * @since 8 952 */ 953 getAddressesByName(host: string, callback: AsyncCallback<Array<NetAddress>>): void; 954 955 /** 956 * Resolves a host name to obtain all IP addresses based on the specified NetHandle. 957 * @permission ohos.permission.INTERNET 958 * @param { string } host Indicates the host name or the domain. 959 * @returns { Promise<Array<NetAddress>> } The promise returned by the function. 960 * @throws { BusinessError } 201 - Permission denied. 961 * @throws { BusinessError } 401 - Parameter error. 962 * @throws { BusinessError } 2100001 - Invalid parameter value. 963 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 964 * @throws { BusinessError } 2100003 - System internal error. 965 * @syscap SystemCapability.Communication.NetManager.Core 966 * @since 8 967 */ 968 getAddressesByName(host: string): Promise<Array<NetAddress>>; 969 970 /** 971 * Resolves a host name to obtain the first IP address based on the specified NetHandle. 972 * @permission ohos.permission.INTERNET 973 * @param { string } host Indicates the host name or the domain. 974 * @param { AsyncCallback<NetAddress> } callback Returns the first NetAddress. 975 * @throws { BusinessError } 201 - Permission denied. 976 * @throws { BusinessError } 401 - Parameter error. 977 * @throws { BusinessError } 2100001 - Invalid parameter value. 978 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 979 * @throws { BusinessError } 2100003 - System internal error. 980 * @syscap SystemCapability.Communication.NetManager.Core 981 * @since 8 982 */ 983 getAddressByName(host: string, callback: AsyncCallback<NetAddress>): void; 984 985 /** 986 * Resolves a host name to obtain the first IP address based on the specified NetHandle. 987 * @permission ohos.permission.INTERNET 988 * @param { string } host Indicates the host name or the domain. 989 * @returns { Promise<NetAddress> } The promise returned by the function. 990 * @throws { BusinessError } 201 - Permission denied. 991 * @throws { BusinessError } 401 - Parameter error. 992 * @throws { BusinessError } 2100001 - Invalid parameter value. 993 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 994 * @throws { BusinessError } 2100003 - System internal error. 995 * @syscap SystemCapability.Communication.NetManager.Core 996 * @since 8 997 */ 998 getAddressByName(host: string): Promise<NetAddress>; 999 } 1000 1001 /** 1002 * Defines the network capability set. 1003 * @interface NetCapabilities 1004 * @syscap SystemCapability.Communication.NetManager.Core 1005 * @since 8 1006 */ 1007 /** 1008 * Defines the network capability set. 1009 * @interface NetCapabilities 1010 * @syscap SystemCapability.Communication.NetManager.Core 1011 * @crossplatform 1012 * @since 10 1013 */ 1014 export interface NetCapabilities { 1015 /** 1016 * Uplink (device-to-network) bandwidth. 1017 * @type {?number} 1018 * @syscap SystemCapability.Communication.NetManager.Core 1019 * @since 8 1020 */ 1021 linkUpBandwidthKbps?: number; 1022 1023 /** 1024 * Downstream (network-to-device) bandwidth. 1025 * @type {?number} 1026 * @syscap SystemCapability.Communication.NetManager.Core 1027 * @since 8 1028 */ 1029 linkDownBandwidthKbps?: number; 1030 1031 /** 1032 * Network-specific capabilities. 1033 * @type {?Array<NetCap>} 1034 * @syscap SystemCapability.Communication.NetManager.Core 1035 * @since 8 1036 */ 1037 networkCap?: Array<NetCap>; 1038 1039 /** 1040 * Network type. 1041 * @type {Array<NetBearType>} 1042 * @syscap SystemCapability.Communication.NetManager.Core 1043 * @since 8 1044 */ 1045 /** 1046 * Network type. 1047 * @type {Array<NetBearType>} 1048 * @syscap SystemCapability.Communication.NetManager.Core 1049 * @crossplatform 1050 * @since 10 1051 */ 1052 bearerTypes: Array<NetBearType>; 1053 } 1054 1055 /** 1056 * Defines the network capability. 1057 * @enum {number} 1058 * @syscap SystemCapability.Communication.NetManager.Core 1059 * @since 8 1060 */ 1061 export enum NetCap { 1062 /** 1063 * Indicates that the network can access the carrier's MMSC to send and receive multimedia messages. 1064 * @syscap SystemCapability.Communication.NetManager.Core 1065 * @since 8 1066 */ 1067 NET_CAPABILITY_MMS = 0, 1068 1069 /** 1070 * Indicates that the network traffic is not metered. 1071 * @syscap SystemCapability.Communication.NetManager.Core 1072 * @since 8 1073 */ 1074 NET_CAPABILITY_NOT_METERED = 11, 1075 1076 /** 1077 * Indicates that the network can access the Internet. 1078 * @syscap SystemCapability.Communication.NetManager.Core 1079 * @since 8 1080 */ 1081 NET_CAPABILITY_INTERNET = 12, 1082 1083 /** 1084 * Indicates that the network does not use a VPN. 1085 * @syscap SystemCapability.Communication.NetManager.Core 1086 * @since 8 1087 */ 1088 NET_CAPABILITY_NOT_VPN = 15, 1089 1090 /** 1091 * Indicates that the network is available. 1092 * @syscap SystemCapability.Communication.NetManager.Core 1093 * @since 8 1094 */ 1095 NET_CAPABILITY_VALIDATED = 16, 1096 } 1097 1098 /** 1099 * Enumerates network types. 1100 * @enum {number} 1101 * @syscap SystemCapability.Communication.NetManager.Core 1102 * @since 8 1103 */ 1104 /** 1105 * Enumerates network types. 1106 * @enum {number} 1107 * @syscap SystemCapability.Communication.NetManager.Core 1108 * @crossplatform 1109 * @since 10 1110 */ 1111 export enum NetBearType { 1112 /** 1113 * Indicates that the network is based on a cellular network. 1114 * @syscap SystemCapability.Communication.NetManager.Core 1115 * @since 8 1116 */ 1117 /** 1118 * Indicates that the network is based on a cellular network. 1119 * @syscap SystemCapability.Communication.NetManager.Core 1120 * @crossplatform 1121 * @since 10 1122 */ 1123 BEARER_CELLULAR = 0, 1124 1125 /** 1126 * Indicates that the network is based on a Wi-Fi network. 1127 * @syscap SystemCapability.Communication.NetManager.Core 1128 * @since 8 1129 */ 1130 /** 1131 * Indicates that the network is based on a Wi-Fi network. 1132 * @syscap SystemCapability.Communication.NetManager.Core 1133 * @crossplatform 1134 * @since 10 1135 */ 1136 BEARER_WIFI = 1, 1137 1138 /** 1139 * Indicates that the network is an Ethernet network. 1140 * @syscap SystemCapability.Communication.NetManager.Core 1141 * @since 8 1142 */ 1143 BEARER_ETHERNET = 3, 1144 } 1145 1146 /** 1147 * Defines the network connection properties. 1148 * @interface ConnectionProperties 1149 * @syscap SystemCapability.Communication.NetManager.Core 1150 * @since 8 1151 */ 1152 export interface ConnectionProperties { 1153 /** 1154 * Network card name. 1155 * @type {string} 1156 * @syscap SystemCapability.Communication.NetManager.Core 1157 * @since 8 1158 */ 1159 interfaceName: string; 1160 /** 1161 * Domain. The default value is "". 1162 * @type {string} 1163 * @syscap SystemCapability.Communication.NetManager.Core 1164 * @since 8 1165 */ 1166 domains: string; 1167 /** 1168 * Link information. 1169 * @type {Array<LinkAddress>} 1170 * @syscap SystemCapability.Communication.NetManager.Core 1171 * @since 8 1172 */ 1173 linkAddresses: Array<LinkAddress>; 1174 1175 /** 1176 * Network address, refer to [NetAddress]. 1177 * @type {Array<NetAddress>} 1178 * @syscap SystemCapability.Communication.NetManager.Core 1179 * @since 8 1180 */ 1181 dnses: Array<NetAddress>; 1182 1183 /** 1184 * Routing information. 1185 * @type {Array<RouteInfo>} 1186 * @syscap SystemCapability.Communication.NetManager.Core 1187 * @since 8 1188 */ 1189 routes: Array<RouteInfo>; 1190 1191 /** 1192 * Maximum transmission unit. 1193 * @type {number} 1194 * @syscap SystemCapability.Communication.NetManager.Core 1195 * @since 8 1196 */ 1197 mtu: number; 1198 } 1199 1200 /** 1201 * Defines network route information. 1202 * @interface RouteInfo 1203 * @syscap SystemCapability.Communication.NetManager.Core 1204 * @since 8 1205 */ 1206 export interface RouteInfo { 1207 /** 1208 * Network card name. 1209 * @type {string} 1210 * @syscap SystemCapability.Communication.NetManager.Core 1211 * @since 8 1212 */ 1213 interface: string; 1214 1215 /** 1216 * Destination Address 1217 * @type {LinkAddress} 1218 * @syscap SystemCapability.Communication.NetManager.Core 1219 * @since 8 1220 */ 1221 destination: LinkAddress; 1222 1223 /** 1224 * Gateway address. 1225 * @type {NetAddress} 1226 * @syscap SystemCapability.Communication.NetManager.Core 1227 * @since 8 1228 */ 1229 gateway: NetAddress; 1230 1231 /** 1232 * Whether a gateway is present. 1233 * @type {boolean} 1234 * @syscap SystemCapability.Communication.NetManager.Core 1235 * @since 8 1236 */ 1237 hasGateway: boolean; 1238 1239 /** 1240 * Whether the route is the default route. 1241 * @type {boolean} 1242 * @syscap SystemCapability.Communication.NetManager.Core 1243 * @since 8 1244 */ 1245 isDefaultRoute: boolean; 1246 } 1247 1248 /** 1249 * Defines network link information. 1250 * @interface LinkAddress 1251 * @syscap SystemCapability.Communication.NetManager.Core 1252 * @since 8 1253 */ 1254 export interface LinkAddress { 1255 /** 1256 * Link address. 1257 * @type {NetAddress} 1258 * @syscap SystemCapability.Communication.NetManager.Core 1259 * @since 8 1260 */ 1261 address: NetAddress; 1262 /** 1263 * The length of the link address prefix. 1264 * @type {number} 1265 * @syscap SystemCapability.Communication.NetManager.Core 1266 * @since 8 1267 */ 1268 prefixLength: number; 1269 } 1270 1271 /** 1272 * Defines a network address. 1273 * @interface NetAddress 1274 * @syscap SystemCapability.Communication.NetManager.Core 1275 * @since 8 1276 */ 1277 export interface NetAddress { 1278 /** 1279 * Network address. 1280 * @type {string} 1281 * @syscap SystemCapability.Communication.NetManager.Core 1282 * @since 8 1283 */ 1284 address: string; 1285 1286 /** 1287 * Address family identifier. The value is 1 for IPv4 and 2 for IPv6. The default value is 1. 1288 * @type {?number} 1289 * @syscap SystemCapability.Communication.NetManager.Core 1290 * @since 8 1291 */ 1292 family?: number; 1293 1294 /** 1295 * Port number. The value ranges from 0 to 65535. 1296 * @type {?number} 1297 * @syscap SystemCapability.Communication.NetManager.Core 1298 * @since 8 1299 */ 1300 port?: number; 1301 } 1302 1303 /** 1304 * Network Global Proxy Configuration Information. 1305 * @interface HttpProxy 1306 * @syscap SystemCapability.Communication.NetManager.Core 1307 * @since 10 1308 */ 1309 export interface HttpProxy { 1310 /** 1311 * Proxy server host name. 1312 * @type {string} 1313 * @syscap SystemCapability.Communication.NetManager.Core 1314 * @since 10 1315 */ 1316 host: string; 1317 1318 /** 1319 * Host port. 1320 * @type {number} 1321 * @syscap SystemCapability.Communication.NetManager.Core 1322 * @since 10 1323 */ 1324 port: number; 1325 1326 /** 1327 * Do not use a blocking list for proxy servers. 1328 * @type {Array<string>} 1329 * @syscap SystemCapability.Communication.NetManager.Core 1330 * @since 10 1331 */ 1332 exclusionList: Array<string>; 1333 } 1334} 1335 1336export default connection; 1337