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 16/** 17 * @file 18 * @kit NetworkKit 19 */ 20 21import type { AsyncCallback, Callback } from './@ohos.base'; 22 23/*** if arkts 1.1 */ 24import type http from './@ohos.net.http'; 25import type socket from './@ohos.net.socket'; 26/*** endif */ 27 28/** 29 * Provides interfaces to manage and use data networks. 30 * @namespace connection 31 * @syscap SystemCapability.Communication.NetManager.Core 32 * @since 8 33 */ 34/** 35 * Provides interfaces to manage and use data networks. 36 * @namespace connection 37 * @syscap SystemCapability.Communication.NetManager.Core 38 * @crossplatform 39 * @since 10 40 */ 41/** 42 * Provides interfaces to manage and use data networks. 43 * @namespace connection 44 * @syscap SystemCapability.Communication.NetManager.Core 45 * @crossplatform 46 * @atomicservice 47 * @since arkts {'1.1':'11','1.2':'20'} 48 * @arkts 1.1&1.2 49 */ 50declare namespace connection { 51 /** 52 * Get an HTTP request task. 53 * @syscap SystemCapability.Communication.NetStack 54 * @since 8 55 */ 56 /** 57 * Get an HTTP request task. 58 * @syscap SystemCapability.Communication.NetStack 59 * @crossplatform 60 * @since 10 61 */ 62 /** 63 * Get an HTTP request task. 64 * @typedef { http.HttpRequest } 65 * @syscap SystemCapability.Communication.NetStack 66 * @crossplatform 67 * @atomicservice 68 * @since 11 69 */ 70 type HttpRequest = http.HttpRequest; 71 72 /** 73 * Get a TCPSocket object. 74 * @syscap SystemCapability.Communication.NetStack 75 * @since 8 76 */ 77 /** 78 * Get a TCPSocket object. 79 * @typedef { socket.TCPSocket } 80 * @syscap SystemCapability.Communication.NetStack 81 * @crossplatform 82 * @since 10 83 */ 84 type TCPSocket = socket.TCPSocket; 85 86 /** 87 * Get a UDPSocket object. 88 * @syscap SystemCapability.Communication.NetStack 89 * @since 8 90 */ 91 /** 92 * Get a UDPSocket object. 93 * @typedef { socket.UDPSocket } 94 * @syscap SystemCapability.Communication.NetStack 95 * @crossplatform 96 * @since 10 97 */ 98 type UDPSocket = socket.UDPSocket; 99 100 /** 101 * Create a network connection with optional netSpecifier and timeout. 102 * @param { NetSpecifier } [netSpecifier] - Indicates the network specifier. See {@link NetSpecifier}. 103 * @param { number } [timeout] - The time in milliseconds to attempt looking for a suitable network before 104 * {@link NetConnection#netUnavailable} is called. 105 * @returns { NetConnection } the NetConnection of the NetSpecifier. 106 * @syscap SystemCapability.Communication.NetManager.Core 107 * @since 8 108 */ 109 /** 110 * Create a network connection with optional netSpecifier and timeout. 111 * @param { NetSpecifier } [netSpecifier] - Indicates the network specifier. See {@link NetSpecifier}. 112 * @param { number } [timeout] - The time in milliseconds to attempt looking for a suitable network before 113 * {@link NetConnection#netUnavailable} is called. 114 * @returns { NetConnection } the NetConnection of the NetSpecifier. 115 * @syscap SystemCapability.Communication.NetManager.Core 116 * @crossplatform 117 * @since 10 118 */ 119 /** 120 * Create a network connection with optional netSpecifier and timeout. 121 * @param { NetSpecifier } [netSpecifier] - Indicates the network specifier. See {@link NetSpecifier}. 122 * @param { number } [timeout] - The time in milliseconds to attempt looking for a suitable network before 123 * {@link NetConnection#netUnavailable} is called. 124 * @returns { NetConnection } the NetConnection of the NetSpecifier. 125 * @syscap SystemCapability.Communication.NetManager.Core 126 * @crossplatform 127 * @atomicservice 128 * @since 11 129 */ 130 function createNetConnection(netSpecifier?: NetSpecifier, timeout?: number): NetConnection; 131 132 /** 133 * Obtains the data network that is activated by default. 134 * To call this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. 135 * @permission ohos.permission.GET_NETWORK_INFO 136 * @param { AsyncCallback<NetHandle> } callback - the callback of getDefaultNet. 137 * @throws { BusinessError } 201 - Permission denied. 138 * @throws { BusinessError } 401 - Parameter error. 139 * @throws { BusinessError } 2100002 - Failed to connect to the service. 140 * @throws { BusinessError } 2100003 - System internal error. 141 * @syscap SystemCapability.Communication.NetManager.Core 142 * @since 8 143 */ 144 /** 145 * Obtains the data network that is activated by default. 146 * To call this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. 147 * @permission ohos.permission.GET_NETWORK_INFO 148 * @param { AsyncCallback<NetHandle> } callback - the callback of getDefaultNet. 149 * @throws { BusinessError } 201 - Permission denied. 150 * @throws { BusinessError } 401 - Parameter error. 151 * @throws { BusinessError } 2100002 - Failed to connect to the service. 152 * @throws { BusinessError } 2100003 - System internal error. 153 * @syscap SystemCapability.Communication.NetManager.Core 154 * @atomicservice 155 * @since arkts {'1.1':'11','1.2':'20'} 156 * @arkts 1.1&1.2 157 */ 158 function getDefaultNet(callback: AsyncCallback<NetHandle>): void; 159 160 /** 161 * Obtains the data network that is activated by default. 162 * To call this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. 163 * @permission ohos.permission.GET_NETWORK_INFO 164 * @returns { Promise<NetHandle> } The promise returned by the function. 165 * @throws { BusinessError } 201 - Permission denied. 166 * @throws { BusinessError } 401 - Parameter error. 167 * @throws { BusinessError } 2100002 - Failed to connect to the service. 168 * @throws { BusinessError } 2100003 - System internal error. 169 * @syscap SystemCapability.Communication.NetManager.Core 170 * @since 8 171 */ 172 /** 173 * Obtains the data network that is activated by default. 174 * To call this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. 175 * @permission ohos.permission.GET_NETWORK_INFO 176 * @returns { Promise<NetHandle> } The promise returned by the function. 177 * @throws { BusinessError } 201 - Permission denied. 178 * @throws { BusinessError } 2100002 - Failed to connect to the service. 179 * @throws { BusinessError } 2100003 - System internal error. 180 * @syscap SystemCapability.Communication.NetManager.Core 181 * @atomicservice 182 * @since arkts {'1.1':'11','1.2':'20'} 183 * @arkts 1.1&1.2 184 */ 185 function getDefaultNet(): Promise<NetHandle>; 186 187 /** 188 * Obtains the data network that is activated by default. 189 * To call this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. 190 * @permission ohos.permission.GET_NETWORK_INFO 191 * @returns { NetHandle } if the default network is not activated. 192 * @throws { BusinessError } 201 - Permission denied. 193 * @throws { BusinessError } 401 - Parameter error. 194 * @throws { BusinessError } 2100002 - Failed to connect to the service. 195 * @throws { BusinessError } 2100003 - System internal error. 196 * @syscap SystemCapability.Communication.NetManager.Core 197 * @since 9 198 */ 199 /** 200 * Obtains the data network that is activated by default. 201 * To call this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. 202 * @permission ohos.permission.GET_NETWORK_INFO 203 * @returns { NetHandle } if the default network is not activated. 204 * @throws { BusinessError } 201 - Permission denied. 205 * @throws { BusinessError } 2100002 - Failed to connect to the service. 206 * @throws { BusinessError } 2100003 - System internal error. 207 * @syscap SystemCapability.Communication.NetManager.Core 208 * @atomicservice 209 * @since arkts {'1.1':'11','1.2':'20'} 210 * @arkts 1.1&1.2 211 */ 212 function getDefaultNetSync(): NetHandle; 213 214 /** 215 * Obtains the list of data networks that are activated. 216 * To invoke this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. 217 * @permission ohos.permission.GET_NETWORK_INFO 218 * @param { AsyncCallback<Array<NetHandle>> } callback - the callback of getAllNets. 219 * @throws { BusinessError } 201 - Permission denied. 220 * @throws { BusinessError } 401 - Parameter error. 221 * @throws { BusinessError } 2100002 - Failed to connect to the service. 222 * @throws { BusinessError } 2100003 - System internal error. 223 * @syscap SystemCapability.Communication.NetManager.Core 224 * @since 8 225 */ 226 function getAllNets(callback: AsyncCallback<Array<NetHandle>>): void; 227 228 /** 229 * Obtains the list of data networks that are activated. 230 * To invoke this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. 231 * @permission ohos.permission.GET_NETWORK_INFO 232 * @returns { Promise<Array<NetHandle>> } The promise returned by the function. 233 * @throws { BusinessError } 201 - Permission denied. 234 * @throws { BusinessError } 2100002 - Failed to connect to the service. 235 * @throws { BusinessError } 2100003 - System internal error. 236 * @syscap SystemCapability.Communication.NetManager.Core 237 * @since 8 238 */ 239 function getAllNets(): Promise<Array<NetHandle>>; 240 241 /** 242 * Obtains the list of data networks that are activated. 243 * To call this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. 244 * @permission ohos.permission.GET_NETWORK_INFO 245 * @returns { Array<NetHandle> } Returns data networks that are activated. 246 * @throws { BusinessError } 201 - Permission denied. 247 * @throws { BusinessError } 2100002 - Failed to connect to the service. 248 * @throws { BusinessError } 2100003 - System internal error. 249 * @syscap SystemCapability.Communication.NetManager.Core 250 * @since 10 251 */ 252 function getAllNetsSync(): Array<NetHandle>; 253 254 /** 255 * Queries the connection properties of a network. 256 * This method requires the {@code ohos.permission.GET_NETWORK_INFO} permission. 257 * @permission ohos.permission.GET_NETWORK_INFO 258 * @param { NetHandle } netHandle - Indicates the network to be queried. 259 * @param { AsyncCallback<ConnectionProperties> } callback - the callback of getConnectionProperties.{@link ConnectionProperties}. 260 * @throws { BusinessError } 201 - Permission denied. 261 * @throws { BusinessError } 401 - Parameter error. 262 * @throws { BusinessError } 2100001 - Invalid parameter value. 263 * @throws { BusinessError } 2100002 - Failed to connect to the service. 264 * @throws { BusinessError } 2100003 - System internal error. 265 * @syscap SystemCapability.Communication.NetManager.Core 266 * @since 8 267 */ 268 function getConnectionProperties(netHandle: NetHandle, callback: AsyncCallback<ConnectionProperties>): void; 269 270 /** 271 * Queries the connection properties of a network. 272 * This method requires the {@code ohos.permission.GET_NETWORK_INFO} permission. 273 * @permission ohos.permission.GET_NETWORK_INFO 274 * @param { NetHandle } netHandle - Indicates the network to be queried. 275 * @returns { Promise<ConnectionProperties> } The promise returned by the function. 276 * @throws { BusinessError } 201 - Permission denied. 277 * @throws { BusinessError } 401 - Parameter error. 278 * @throws { BusinessError } 2100001 - Invalid parameter value. 279 * @throws { BusinessError } 2100002 - Failed to connect to the service. 280 * @throws { BusinessError } 2100003 - System internal error. 281 * @syscap SystemCapability.Communication.NetManager.Core 282 * @since 8 283 */ 284 function getConnectionProperties(netHandle: NetHandle): Promise<ConnectionProperties>; 285 286 /** 287 * Queries the connection properties of a network. 288 * This method requires the {@code ohos.permission.GET_NETWORK_INFO} permission. 289 * @permission ohos.permission.GET_NETWORK_INFO 290 * @param { NetHandle } netHandle - Indicates the network to be queried. 291 * @returns { ConnectionProperties } Returns the connection properties of a network. 292 * @throws { BusinessError } 201 - Permission denied. 293 * @throws { BusinessError } 401 - Parameter error. 294 * @throws { BusinessError } 2100001 - Invalid parameter value. 295 * @throws { BusinessError } 2100002 - Failed to connect to the service. 296 * @throws { BusinessError } 2100003 - System internal error. 297 * @syscap SystemCapability.Communication.NetManager.Core 298 * @since 10 299 */ 300 function getConnectionPropertiesSync(netHandle: NetHandle): ConnectionProperties; 301 302 /** 303 * Obtains {@link NetCapabilities} of a {@link NetHandle} object. 304 * To invoke this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. 305 * @permission ohos.permission.GET_NETWORK_INFO 306 * @param { NetHandle } netHandle - Indicates the handle. See {@link NetHandle}. 307 * @param { AsyncCallback<NetCapabilities> } callback - the callback of getNetCapabilities.{@link NetCapabilities}. 308 * @throws { BusinessError } 201 - Permission denied. 309 * @throws { BusinessError } 401 - Parameter error. 310 * @throws { BusinessError } 2100001 - Invalid parameter value. 311 * @throws { BusinessError } 2100002 - Failed to connect to the service. 312 * @throws { BusinessError } 2100003 - System internal error. 313 * @syscap SystemCapability.Communication.NetManager.Core 314 * @since 8 315 */ 316 /** 317 * Obtains {@link NetCapabilities} of a {@link NetHandle} object. 318 * To invoke this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. 319 * @permission ohos.permission.GET_NETWORK_INFO 320 * @param { NetHandle } netHandle - Indicates the handle. See {@link NetHandle}. 321 * @param { AsyncCallback<NetCapabilities> } callback - the callback of getNetCapabilities.{@link NetCapabilities}. 322 * @throws { BusinessError } 201 - Permission denied. 323 * @throws { BusinessError } 401 - Parameter error. 324 * @throws { BusinessError } 2100001 - Invalid parameter value. 325 * @throws { BusinessError } 2100002 - Failed to connect to the service. 326 * @throws { BusinessError } 2100003 - System internal error. 327 * @syscap SystemCapability.Communication.NetManager.Core 328 * @atomicservice 329 * @since 11 330 */ 331 function getNetCapabilities(netHandle: NetHandle, callback: AsyncCallback<NetCapabilities>): void; 332 333 /** 334 * Obtains {@link NetCapabilities} of a {@link NetHandle} object. 335 * To invoke this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. 336 * @permission ohos.permission.GET_NETWORK_INFO 337 * @param { NetHandle } netHandle - Indicates the handle. See {@link NetHandle}. 338 * @returns { Promise<NetCapabilities> } The promise returned by the function. 339 * @throws { BusinessError } 201 - Permission denied. 340 * @throws { BusinessError } 401 - Parameter error. 341 * @throws { BusinessError } 2100001 - Invalid parameter value. 342 * @throws { BusinessError } 2100002 - Failed to connect to the service. 343 * @throws { BusinessError } 2100003 - System internal error. 344 * @syscap SystemCapability.Communication.NetManager.Core 345 * @since 8 346 */ 347 /** 348 * Obtains {@link NetCapabilities} of a {@link NetHandle} object. 349 * To invoke this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. 350 * @permission ohos.permission.GET_NETWORK_INFO 351 * @param { NetHandle } netHandle - Indicates the handle. See {@link NetHandle}. 352 * @returns { Promise<NetCapabilities> } The promise returned by the function. 353 * @throws { BusinessError } 201 - Permission denied. 354 * @throws { BusinessError } 401 - Parameter error. 355 * @throws { BusinessError } 2100001 - Invalid parameter value. 356 * @throws { BusinessError } 2100002 - Failed to connect to the service. 357 * @throws { BusinessError } 2100003 - System internal error. 358 * @syscap SystemCapability.Communication.NetManager.Core 359 * @atomicservice 360 * @since 11 361 */ 362 function getNetCapabilities(netHandle: NetHandle): Promise<NetCapabilities>; 363 364 /** 365 * Obtains {@link NetCapabilities} of a {@link NetHandle} object. 366 * To invoke this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. 367 * @permission ohos.permission.GET_NETWORK_INFO 368 * @param { NetHandle } netHandle - Indicates the handle. See {@link NetHandle}. 369 * @returns { NetCapabilities } Returns the connection capabilities of a network. 370 * @throws { BusinessError } 201 - Permission denied. 371 * @throws { BusinessError } 401 - Parameter error. 372 * @throws { BusinessError } 2100001 - Invalid parameter value. 373 * @throws { BusinessError } 2100002 - Failed to connect to the service. 374 * @throws { BusinessError } 2100003 - System internal error. 375 * @syscap SystemCapability.Communication.NetManager.Core 376 * @since 10 377 */ 378 /** 379 * Obtains {@link NetCapabilities} of a {@link NetHandle} object. 380 * To invoke this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. 381 * @permission ohos.permission.GET_NETWORK_INFO 382 * @param { NetHandle } netHandle - Indicates the handle. See {@link NetHandle}. 383 * @returns { NetCapabilities } Returns the connection capabilities of a network. 384 * @throws { BusinessError } 201 - Permission denied. 385 * @throws { BusinessError } 401 - Parameter error. 386 * @throws { BusinessError } 2100001 - Invalid parameter value. 387 * @throws { BusinessError } 2100002 - Failed to connect to the service. 388 * @throws { BusinessError } 2100003 - System internal error. 389 * @syscap SystemCapability.Communication.NetManager.Core 390 * @atomicservice 391 * @since 11 392 */ 393 function getNetCapabilitiesSync(netHandle: NetHandle): NetCapabilities; 394 395 /** 396 * Set the network extended attribute for a {@link NetHandle} object. 397 * To invoke this method, you must have the {@code ohos.permission.SET_NET_EXT_ATTRIBUTE} permission. 398 * @permission ohos.permission.SET_NET_EXT_ATTRIBUTE 399 * @param { NetHandle } netHandle - Indicates the network to be set. See {@link NetHandle}. 400 * @param { string } netExtAttribute - Indicates the extended attribute of the network. 401 * @returns { Promise<void> } The promise returned by the function. 402 * @throws { BusinessError } 201 - Permission denied. 403 * @throws { BusinessError } 2100001 - Invalid parameter value. 404 * @throws { BusinessError } 2100002 - Failed to connect to the service. 405 * @throws { BusinessError } 2100003 - System internal error. 406 * @syscap SystemCapability.Communication.NetManager.Core 407 * @since 20 408 */ 409 function setNetExtAttribute(netHandle: NetHandle, netExtAttribute: string): Promise<void>; 410 411 /** 412 * Set the network extended attribute for a {@link NetHandle} object. 413 * To invoke this method, you must have the {@code ohos.permission.SET_NET_EXT_ATTRIBUTE} permission. 414 * @permission ohos.permission.SET_NET_EXT_ATTRIBUTE 415 * @param { NetHandle } netHandle - Indicates the network to be set. See {@link NetHandle}. 416 * @param { string } netExtAttribute - Indicates the extended attribute of the network. 417 * @throws { BusinessError } 201 - Permission denied. 418 * @throws { BusinessError } 2100001 - Invalid parameter value. 419 * @throws { BusinessError } 2100002 - Failed to connect to the service. 420 * @throws { BusinessError } 2100003 - System internal error. 421 * @syscap SystemCapability.Communication.NetManager.Core 422 * @since 20 423 */ 424 function setNetExtAttributeSync(netHandle: NetHandle, netExtAttribute: string): void; 425 426 /** 427 * Get the network extended attribute for a {@link NetHandle} object. 428 * To invoke this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. 429 * @permission ohos.permission.GET_NETWORK_INFO 430 * @param { NetHandle } netHandle - Indicates the network to be queried. See {@link NetHandle}. 431 * @returns { Promise<string> } The promise returned by the function. 432 * @throws { BusinessError } 201 - Permission denied. 433 * @throws { BusinessError } 2100001 - Invalid parameter value. 434 * @throws { BusinessError } 2100002 - Failed to connect to the service. 435 * @throws { BusinessError } 2100003 - System internal error. 436 * @syscap SystemCapability.Communication.NetManager.Core 437 * @since 20 438 */ 439 function getNetExtAttribute(netHandle: NetHandle): Promise<string>; 440 441 /** 442 * Get the network extended attribute for a {@link NetHandle} object. 443 * To invoke this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. 444 * @permission ohos.permission.GET_NETWORK_INFO 445 * @param { NetHandle } netHandle - Indicates the network to be queried. See {@link NetHandle}. 446 * @returns { string } The netExtAttribute string returned by the function. 447 * @throws { BusinessError } 201 - Permission denied. 448 * @throws { BusinessError } 2100001 - Invalid parameter value. 449 * @throws { BusinessError } 2100002 - Failed to connect to the service. 450 * @throws { BusinessError } 2100003 - System internal error. 451 * @syscap SystemCapability.Communication.NetManager.Core 452 * @since 20 453 */ 454 function getNetExtAttributeSync(netHandle: NetHandle): string; 455 456 /** 457 * Checks whether data traffic usage on the current network is metered. 458 * @permission ohos.permission.GET_NETWORK_INFO 459 * @param { AsyncCallback<boolean> } callback - Returns {@code true} if data traffic usage on the current network is metered; 460 * returns {@code false} otherwise. 461 * @throws { BusinessError } 201 - Permission denied. 462 * @throws { BusinessError } 401 - Parameter error. 463 * @throws { BusinessError } 2100002 - Failed to connect to the service. 464 * @throws { BusinessError } 2100003 - System internal error. 465 * @syscap SystemCapability.Communication.NetManager.Core 466 * @since 9 467 */ 468 function isDefaultNetMetered(callback: AsyncCallback<boolean>): void; 469 470 /** 471 * Checks whether data traffic usage on the current network is metered. 472 * @permission ohos.permission.GET_NETWORK_INFO 473 * @returns { Promise<boolean> } the promise returned by the function. 474 * @throws { BusinessError } 201 - Permission denied. 475 * @throws { BusinessError } 2100002 - Failed to connect to the service. 476 * @throws { BusinessError } 2100003 - System internal error. 477 * @syscap SystemCapability.Communication.NetManager.Core 478 * @since 9 479 */ 480 function isDefaultNetMetered(): Promise<boolean>; 481 482 /** 483 * Checks whether data traffic usage on the current network is metered. 484 * @permission ohos.permission.GET_NETWORK_INFO 485 * @returns { boolean } Returns true if the current network is metered, else returns false. 486 * @throws { BusinessError } 201 - Permission denied. 487 * @throws { BusinessError } 2100002 - Failed to connect to the service. 488 * @throws { BusinessError } 2100003 - System internal error. 489 * @syscap SystemCapability.Communication.NetManager.Core 490 * @since 10 491 */ 492 function isDefaultNetMeteredSync(): boolean; 493 494 /** 495 * Checks whether the default data network is activated. 496 * @permission ohos.permission.GET_NETWORK_INFO 497 * @param { AsyncCallback<boolean> } callback - Returns {@code true} if the default data network is activated; 498 * returns {@code false} otherwise. 499 * @throws { BusinessError } 201 - Permission denied. 500 * @throws { BusinessError } 401 - Parameter error. 501 * @throws { BusinessError } 2100002 - Failed to connect to the service. 502 * @throws { BusinessError } 2100003 - System internal error. 503 * @syscap SystemCapability.Communication.NetManager.Core 504 * @since 8 505 */ 506 /** 507 * Checks whether the default data network is activated. 508 * @permission ohos.permission.GET_NETWORK_INFO 509 * @param { AsyncCallback<boolean> } callback - Returns {@code true} if the default data network is activated; 510 * returns {@code false} otherwise. 511 * @throws { BusinessError } 201 - Permission denied. 512 * @throws { BusinessError } 401 - Parameter error. 513 * @throws { BusinessError } 2100002 - Failed to connect to the service. 514 * @throws { BusinessError } 2100003 - System internal error. 515 * @syscap SystemCapability.Communication.NetManager.Core 516 * @crossplatform 517 * @since 10 518 */ 519 function hasDefaultNet(callback: AsyncCallback<boolean>): void; 520 521 /** 522 * Checks whether the default data network is activated. 523 * @permission ohos.permission.GET_NETWORK_INFO 524 * @returns { Promise<boolean> } The promise returned by the function. 525 * @throws { BusinessError } 201 - Permission denied. 526 * @throws { BusinessError } 401 - Parameter error. 527 * @throws { BusinessError } 2100002 - Failed to connect to the service. 528 * @throws { BusinessError } 2100003 - System internal error. 529 * @syscap SystemCapability.Communication.NetManager.Core 530 * @since 8 531 */ 532 /** 533 * Checks whether the default data network is activated. 534 * @permission ohos.permission.GET_NETWORK_INFO 535 * @returns { Promise<boolean> } The promise returned by the function. 536 * @throws { BusinessError } 201 - Permission denied. 537 * @throws { BusinessError } 2100002 - Failed to connect to the service. 538 * @throws { BusinessError } 2100003 - System internal error. 539 * @syscap SystemCapability.Communication.NetManager.Core 540 * @crossplatform 541 * @since 10 542 */ 543 function hasDefaultNet(): Promise<boolean>; 544 545 /** 546 * Checks whether the default data network is activated. 547 * @permission ohos.permission.GET_NETWORK_INFO 548 * @returns { boolean } Returns true if the default data network is activated, else returns false. 549 * @throws { BusinessError } 201 - Permission denied. 550 * @throws { BusinessError } 2100002 - Failed to connect to the service. 551 * @throws { BusinessError } 2100003 - System internal error. 552 * @syscap SystemCapability.Communication.NetManager.Core 553 * @since 10 554 */ 555 function hasDefaultNetSync(): boolean; 556 557 /** 558 * Enables the airplane mode for a device. 559 * To invoke this method, you must have the {@code ohos.permission.CONNECTIVITY_INTERNAL} permission. 560 * @permission ohos.permission.CONNECTIVITY_INTERNAL 561 * @param { AsyncCallback<void> } callback - the callback of enableAirplaneMode. 562 * @throws { BusinessError } 201 - Permission denied. 563 * @throws { BusinessError } 202 - Non-system applications use system APIs. 564 * @throws { BusinessError } 401 - Parameter error. 565 * @throws { BusinessError } 2100002 - Failed to connect to the service. 566 * @throws { BusinessError } 2100003 - System internal error. 567 * @syscap SystemCapability.Communication.NetManager.Core 568 * @systemapi Hide this for inner system use. Only used for system app. 569 * @since 8 570 */ 571 function enableAirplaneMode(callback: AsyncCallback<void>): void; 572 573 /** 574 * Enables the airplane mode for a device. 575 * To invoke this method, you must have the {@code ohos.permission.CONNECTIVITY_INTERNAL} permission. 576 * @permission ohos.permission.CONNECTIVITY_INTERNAL 577 * @returns { Promise<void> } The promise returned by the function. 578 * @throws { BusinessError } 201 - Permission denied. 579 * @throws { BusinessError } 202 - Non-system applications use system APIs. 580 * @throws { BusinessError } 2100002 - Failed to connect to the service. 581 * @throws { BusinessError } 2100003 - System internal error. 582 * @syscap SystemCapability.Communication.NetManager.Core 583 * @systemapi Hide this for inner system use. Only used for system app. 584 * @since 8 585 */ 586 function enableAirplaneMode(): Promise<void>; 587 588 /** 589 * Disables the airplane mode for a device. 590 * To invoke this method, you must have the {@code ohos.permission.CONNECTIVITY_INTERNAL} permission. 591 * @permission ohos.permission.CONNECTIVITY_INTERNAL 592 * @param { AsyncCallback<void> } callback - the callback of disableAirplaneMode. 593 * @throws { BusinessError } 201 - Permission denied. 594 * @throws { BusinessError } 202 - Non-system applications use system APIs. 595 * @throws { BusinessError } 401 - Parameter error. 596 * @throws { BusinessError } 2100002 - Failed to connect to the service. 597 * @throws { BusinessError } 2100003 - System internal error. 598 * @syscap SystemCapability.Communication.NetManager.Core 599 * @systemapi Hide this for inner system use. Only used for system app. 600 * @since 8 601 */ 602 function disableAirplaneMode(callback: AsyncCallback<void>): void; 603 604 /** 605 * Disables the airplane mode for a device. 606 * To invoke this method, you must have the {@code ohos.permission.CONNECTIVITY_INTERNAL} permission. 607 * @permission ohos.permission.CONNECTIVITY_INTERNAL 608 * @returns { Promise<void> } The promise returned by the function. 609 * @throws { BusinessError } 201 - Permission denied. 610 * @throws { BusinessError } 202 - Non-system applications use system APIs. 611 * @throws { BusinessError } 2100002 - Failed to connect to the service. 612 * @throws { BusinessError } 2100003 - System internal error. 613 * @syscap SystemCapability.Communication.NetManager.Core 614 * @systemapi Hide this for inner system use. Only used for system app. 615 * @since 8 616 */ 617 function disableAirplaneMode(): Promise<void>; 618 619 /** 620 * Reports the network state is connected. 621 * @permission ohos.permission.GET_NETWORK_INFO and ohos.permission.INTERNET 622 * @param { NetHandle } netHandle - Indicates the network whose state is to be reported. 623 * @param { AsyncCallback<void> } callback - the callback of reportNetConnected. 624 * @throws { BusinessError } 201 - Permission denied. 625 * @throws { BusinessError } 401 - Parameter error. 626 * @throws { BusinessError } 2100001 - Invalid parameter value. 627 * @throws { BusinessError } 2100002 - Failed to connect to the service. 628 * @throws { BusinessError } 2100003 - System internal error. 629 * @syscap SystemCapability.Communication.NetManager.Core 630 * @since 8 631 */ 632 function reportNetConnected(netHandle: NetHandle, callback: AsyncCallback<void>): void; 633 634 /** 635 * Reports the network state is connected. 636 * @permission ohos.permission.GET_NETWORK_INFO and ohos.permission.INTERNET 637 * @param { NetHandle } netHandle - Indicates the network whose state is to be reported. 638 * @returns { Promise<void> } The promise returned by the function. 639 * @throws { BusinessError } 201 - Permission denied. 640 * @throws { BusinessError } 401 - Parameter error. 641 * @throws { BusinessError } 2100001 - Invalid parameter value. 642 * @throws { BusinessError } 2100002 - Failed to connect to the service. 643 * @throws { BusinessError } 2100003 - System internal error. 644 * @syscap SystemCapability.Communication.NetManager.Core 645 * @since 8 646 */ 647 function reportNetConnected(netHandle: NetHandle): Promise<void>; 648 649 /** 650 * Reports the network state is disconnected. 651 * @permission ohos.permission.GET_NETWORK_INFO and ohos.permission.INTERNET 652 * @param { NetHandle } netHandle - Indicates the network whose state is to be reported. 653 * @param { AsyncCallback<void> } callback - the callback of reportNetDisconnected. 654 * @throws { BusinessError } 201 - Permission denied. 655 * @throws { BusinessError } 401 - Parameter error. 656 * @throws { BusinessError } 2100001 - Invalid parameter value. 657 * @throws { BusinessError } 2100002 - Failed to connect to the service. 658 * @throws { BusinessError } 2100003 - System internal error. 659 * @syscap SystemCapability.Communication.NetManager.Core 660 * @since 8 661 */ 662 function reportNetDisconnected(netHandle: NetHandle, callback: AsyncCallback<void>): void; 663 664 /** 665 * Reports the network state is disconnected. 666 * @permission ohos.permission.GET_NETWORK_INFO and ohos.permission.INTERNET 667 * @param { NetHandle } netHandle - Indicates the network whose state is to be reported. 668 * @returns { Promise<void> } The promise returned by the function. 669 * @throws { BusinessError } 201 - Permission denied. 670 * @throws { BusinessError } 401 - Parameter error. 671 * @throws { BusinessError } 2100001 - Invalid parameter value. 672 * @throws { BusinessError } 2100002 - Failed to connect to the service. 673 * @throws { BusinessError } 2100003 - System internal error. 674 * @syscap SystemCapability.Communication.NetManager.Core 675 * @since 8 676 */ 677 function reportNetDisconnected(netHandle: NetHandle): Promise<void>; 678 679 /** 680 * Resolves the host name to obtain all IP addresses based on the default data network. 681 * @permission ohos.permission.INTERNET 682 * @param { string } host - Indicates the host name or the domain. 683 * @param { AsyncCallback<Array<NetAddress>> } callback - Returns the NetAddress list. 684 * @throws { BusinessError } 201 - Permission denied. 685 * @throws { BusinessError } 401 - Parameter error. 686 * @throws { BusinessError } 2100001 - Invalid parameter value. 687 * @throws { BusinessError } 2100002 - Failed to connect to the service. 688 * @throws { BusinessError } 2100003 - System internal error. 689 * @syscap SystemCapability.Communication.NetManager.Core 690 * @since 8 691 */ 692 function getAddressesByName(host: string, callback: AsyncCallback<Array<NetAddress>>): void; 693 694 /** 695 * Resolves the host name to obtain all IP addresses based on the default data network. 696 * @permission ohos.permission.INTERNET 697 * @param { string } host - Indicates the host name or the domain. 698 * @returns { Promise<Array<NetAddress>> } The promise returned by the function. 699 * @throws { BusinessError } 201 - Permission denied. 700 * @throws { BusinessError } 401 - Parameter error. 701 * @throws { BusinessError } 2100001 - Invalid parameter value. 702 * @throws { BusinessError } 2100002 - Failed to connect to the service. 703 * @throws { BusinessError } 2100003 - System internal error. 704 * @syscap SystemCapability.Communication.NetManager.Core 705 * @since 8 706 */ 707 function getAddressesByName(host: string): Promise<Array<NetAddress>>; 708 709 /** 710 * Obtains the {@link NetHandle} bound to a process using {@link setAppNet}. 711 * @param { AsyncCallback<NetHandle> } callback - Returns the {@link NetHandle} bound to the process; 712 * returns {@code null} if no {@link NetHandle} is bound to the process.For details, see {@link NetHandle}. 713 * @throws { BusinessError } 401 - Parameter error. 714 * @throws { BusinessError } 2100002 - Failed to connect to the service. 715 * @throws { BusinessError } 2100003 - System internal error. 716 * @syscap SystemCapability.Communication.NetManager.Core 717 * @since 9 718 */ 719 function getAppNet(callback: AsyncCallback<NetHandle>): void; 720 721 /** 722 * Obtains the {@link NetHandle} bound to a process using {@link setAppNet}. 723 * @returns { Promise<NetHandle> } the promise returned by the function. 724 * @throws { BusinessError } 2100002 - Failed to connect to the service. 725 * @throws { BusinessError } 2100003 - System internal error. 726 * @syscap SystemCapability.Communication.NetManager.Core 727 * @since 9 728 */ 729 function getAppNet(): Promise<NetHandle>; 730 731 /** 732 * Obtains the {@link NetHandle} bound to a process using {@link setAppNet}. 733 * @returns { NetHandle } Returns the {@link NetHandle} bound to a process using {@link setAppNet}. 734 * @throws { BusinessError } 2100002 - Failed to connect to the service. 735 * @throws { BusinessError } 2100003 - System internal error. 736 * @syscap SystemCapability.Communication.NetManager.Core 737 * @since 10 738 */ 739 function getAppNetSync(): NetHandle; 740 741 /** 742 * Binds a process to {@code NetHandle}. 743 * <p>All the sockets created from the process will be bound to the {@code NetHandle}, 744 * and the resolution of all host names will be managed by the {@code NetHandle}.</p> 745 * @permission ohos.permission.INTERNET 746 * @param { NetHandle } netHandle - Indicates the handle. For details, see {@link NetHandle}. 747 * @param { AsyncCallback<void> } callback - the callback of setAppNet. 748 * @throws { BusinessError } 201 - Permission denied. 749 * @throws { BusinessError } 401 - Parameter error. 750 * @throws { BusinessError } 2100001 - Invalid parameter value. 751 * @throws { BusinessError } 2100002 - Failed to connect to the service. 752 * @throws { BusinessError } 2100003 - System internal error. 753 * @syscap SystemCapability.Communication.NetManager.Core 754 * @since 9 755 */ 756 function setAppNet(netHandle: NetHandle, callback: AsyncCallback<void>): void; 757 758 /** 759 * Binds a process to {@code NetHandle}. 760 * <p>All the sockets created from the process will be bound to the {@code NetHandle}, 761 * and the resolution of all host names will be managed by the {@code NetHandle}.</p> 762 * @permission ohos.permission.INTERNET 763 * @param { NetHandle } netHandle - Indicates the handle. For details, see {@link NetHandle}. 764 * @returns { Promise<void> } the promise returned by the function. 765 * @throws { BusinessError } 201 - Permission denied. 766 * @throws { BusinessError } 401 - Parameter error. 767 * @throws { BusinessError } 2100001 - Invalid parameter value. 768 * @throws { BusinessError } 2100002 - Failed to connect to the service. 769 * @throws { BusinessError } 2100003 - System internal error. 770 * @syscap SystemCapability.Communication.NetManager.Core 771 * @since 9 772 */ 773 function setAppNet(netHandle: NetHandle): Promise<void>; 774 775 /** 776 * Obtains the default {@link HttpProxy} proxy settings. 777 * 778 * If an application level proxy is set, the application level proxy parameters are returned. 779 * If a global proxy is set, the global proxy parameters are returned. 780 * If the process is bound to a {@link NetHandle} using {@link setAppNet}, the {@link NetHandle} proxy settings are returned. 781 * In other cases, the proxy settings of default network are returned. 782 * 783 * @param { AsyncCallback<HttpProxy> } callback - Returns the default {@link HttpProxy} settings. 784 * @throws { BusinessError } 2100002 - Failed to connect to the service. 785 * @throws { BusinessError } 2100003 - System internal error. 786 * @syscap SystemCapability.Communication.NetManager.Core 787 * @since 10 788 */ 789 function getDefaultHttpProxy(callback: AsyncCallback<HttpProxy>): void; 790 791 /** 792 * Obtains the default {@link HttpProxy} proxy settings. 793 * 794 * If an application level proxy is set, the application level proxy parameters are returned. 795 * If a global proxy is set, the global proxy parameters are returned. 796 * If the process is bound to a {@link NetHandle} using {@link setAppNet}, the {@link NetHandle} proxy settings are returned. 797 * In other cases, the proxy settings of default network are returned. 798 * 799 * @returns { Promise<HttpProxy> } the promise returned by the function. 800 * @throws { BusinessError } 2100002 - Failed to connect to the service. 801 * @throws { BusinessError } 2100003 - System internal error. 802 * @syscap SystemCapability.Communication.NetManager.Core 803 * @since 10 804 */ 805 function getDefaultHttpProxy(): Promise<HttpProxy>; 806 807 /** 808 * Obtains the network independent global {@link HttpProxy} proxy settings. 809 * @param { AsyncCallback<HttpProxy> } callback - Returns the proxy settings. For details, see {@link HttpProxy}. 810 * @throws { BusinessError } 401 - Parameter error. 811 * @throws { BusinessError } 202 - Non-system applications use system APIs. 812 * @throws { BusinessError } 2100002 - Failed to connect to the service. 813 * @throws { BusinessError } 2100003 - System internal error. 814 * @syscap SystemCapability.Communication.NetManager.Core 815 * @systemapi Hide this for inner system use. 816 * @since 10 817 */ 818 function getGlobalHttpProxy(callback: AsyncCallback<HttpProxy>): void; 819 820 /** 821 * Obtains the network independent global {@link HttpProxy} proxy settings. 822 * @returns { Promise<HttpProxy> } the promise returned by the function. 823 * @throws { BusinessError } 202 - Non-system applications use system APIs. 824 * @throws { BusinessError } 2100002 - Failed to connect to the service. 825 * @throws { BusinessError } 2100003 - System internal error. 826 * @syscap SystemCapability.Communication.NetManager.Core 827 * @systemapi Hide this for inner system use. 828 * @since 10 829 */ 830 function getGlobalHttpProxy(): Promise<HttpProxy>; 831 832 /** 833 * Set application level http proxy {@link HttpProxy}. 834 * @param { HttpProxy } httpProxy - Indicates the application level proxy settings. For details, see {@link HttpProxy}. 835 * @throws { BusinessError } 401 - Parameter error. 836 * @throws { BusinessError } 2100001 - Invalid http proxy. 837 * @syscap SystemCapability.Communication.NetManager.Core 838 * @since 11 839 */ 840 function setAppHttpProxy(httpProxy: HttpProxy): void; 841 842 /** 843 * Set a network independent global {@link HttpProxy} proxy settings. 844 * @permission ohos.permission.CONNECTIVITY_INTERNAL 845 * @param { HttpProxy } httpProxy - Indicates the global proxy settings. For details, see {@link HttpProxy}. 846 * @param { AsyncCallback<void> } callback - the callback of setGlobalHttpProxy. 847 * @throws { BusinessError } 201 - Permission denied. 848 * @throws { BusinessError } 401 - Parameter error. 849 * @throws { BusinessError } 202 - Non-system applications use system APIs. 850 * @throws { BusinessError } 2100001 - Invalid parameter value. 851 * @throws { BusinessError } 2100002 - Failed to connect to the service. 852 * @throws { BusinessError } 2100003 - System internal error. 853 * @syscap SystemCapability.Communication.NetManager.Core 854 * @systemapi Hide this for inner system use. 855 * @since 10 856 */ 857 function setGlobalHttpProxy(httpProxy: HttpProxy, callback: AsyncCallback<void>): void; 858 859 /** 860 * Set a network independent global {@link HttpProxy} proxy settings. 861 * @permission ohos.permission.CONNECTIVITY_INTERNAL 862 * @param { HttpProxy } httpProxy - Indicates the global proxy settings. For details, see {@link HttpProxy}. 863 * @returns { Promise<void> } the promise returned by the function. 864 * @throws { BusinessError } 201 - Permission denied. 865 * @throws { BusinessError } 401 - Parameter error. 866 * @throws { BusinessError } 202 - Non-system applications use system APIs. 867 * @throws { BusinessError } 2100001 - Invalid parameter value. 868 * @throws { BusinessError } 2100002 - Failed to connect to the service. 869 * @throws { BusinessError } 2100003 - System internal error. 870 * @syscap SystemCapability.Communication.NetManager.Core 871 * @systemapi Hide this for inner system use. 872 * @since 10 873 */ 874 function setGlobalHttpProxy(httpProxy: HttpProxy): Promise<void>; 875 876 /** 877 * Set the URL {@link pacUrl} of the current PAC script. 878 * To invoke this method, you must have the {@code ohos.permission.SET_PAC_URL} permission. 879 * @permission ohos.permission.SET_PAC_URL 880 * @param { string } pacUrl - Indicates the URL of the current PAC script. 881 * @throws { BusinessError } 201 - Permission denied. 882 * @throws { BusinessError } 401 - Parameter error. 883 * @throws { BusinessError } 2100002 - Failed to connect to the service. 884 * @throws { BusinessError } 2100003 - System internal error. 885 * @syscap SystemCapability.Communication.NetManager.Core 886 * @since 15 887 */ 888 function setPacUrl(pacUrl: string): void; 889 890 /** 891 * Obtain the URL {@link pacUrl} of the current PAC script. 892 * @returns { string } Returns the URL of the current PAC script or empty string if there is no PAC script. 893 * @throws { BusinessError } 2100002 - Failed to connect to the service. 894 * @throws { BusinessError } 2100003 - System internal error. 895 * @syscap SystemCapability.Communication.NetManager.Core 896 * @since 15 897 */ 898 function getPacUrl(): string; 899 900 /** 901 * Set the URL {@link pacFileUrl} of the current PAC script. 902 * Proxy information can be obtained through parsing the script address. 903 * To invoke this method, you must have the {@code ohos.permission.SET_PAC_URL} permission. 904 * @permission ohos.permission.SET_PAC_URL 905 * @param { string } pacFileUrl - Indicates the URL of the current PAC script. 906 * @throws { BusinessError } 201 - Permission denied. 907 * @throws { BusinessError } 2100002 - Failed to connect to the service. 908 * @syscap SystemCapability.Communication.NetManager.Core 909 * @since 20 910 */ 911 function setPacFileUrl(pacFileUrl: string): void; 912 913 /** 914 * Obtain the URL {@link pacFileUrl} of the current PAC script. 915 * @returns { string } Returns the URL of the current PAC script or empty string if there is no PAC script. 916 * @throws { BusinessError } 2100002 - Failed to connect to the service. 917 * @syscap SystemCapability.Communication.NetManager.Core 918 * @since 20 919 */ 920 function getPacFileUrl(): string; 921 922 /** 923 * Find pac proxy info for the url. 924 * @param { string } url - the url. 925 * @returns { string } Returns the proxy infomation. 926 * @syscap SystemCapability.Communication.NetManager.Core 927 * @since 20 928 */ 929 function findProxyForUrl(url: string): string; 930 931 /** 932 * Set the proxy mode {@link ProxyMode}. 933 * @permission ohos.permission.CONNECTIVITY_INTERNAL 934 * @param { ProxyMode } mode - Indicates the proxy mode. 935 * @returns { Promise<void> } the promise returned by the function. 936 * @throws { BusinessError } 201 - Permission denied. 937 * @throws { BusinessError } 202 - Non-system applications use system APIs. 938 * @syscap SystemCapability.Communication.NetManager.Core 939 * @systemapi Hide this for inner system use. Only used for system app. 940 * @since 20 941 */ 942 function setProxyMode(mode: ProxyMode): Promise<void>; 943 944 /** 945 * Obtain the proxy mode {@link ProxyMode}. 946 * @permission ohos.permission.CONNECTIVITY_INTERNAL 947 * @returns { Promise<ProxyMode> } the promise returned by the function. 948 * @throws { BusinessError } 201 - Permission denied. 949 * @throws { BusinessError } 202 - Non-system applications use system APIs. 950 * @syscap SystemCapability.Communication.NetManager.Core 951 * @systemapi Hide this for inner system use. Only used for system app. 952 * @since 20 953 */ 954 function getProxyMode(): Promise<ProxyMode>; 955 956 /** 957 * Add a custom {@link host} and corresponding {@link ip} mapping for current application. 958 * @permission ohos.permission.INTERNET 959 * @param { string } host - Indicates the host name or the domain. 960 * @param { Array<string> } ip - List of IP addresses mapped to the host name. 961 * @param { AsyncCallback<void> } callback - Returns the callback of addCustomDnsRule. 962 * @throws { BusinessError } 201 - Permission denied. 963 * @throws { BusinessError } 401 - Parameter error. 964 * @throws { BusinessError } 2100001 - Invalid parameter value. 965 * @throws { BusinessError } 2100002 - Failed to connect to the service. 966 * @throws { BusinessError } 2100003 - System internal error. 967 * @syscap SystemCapability.Communication.NetManager.Core 968 * @since 11 969 */ 970 /** 971 * Add a custom {@link host} and corresponding {@link ip} mapping for current application. 972 * @permission ohos.permission.INTERNET 973 * @param { string } host - Indicates the host name or the domain. 974 * @param { Array<string> } ip - List of IP addresses mapped to the host name. 975 * @param { AsyncCallback<void> } callback - Returns the callback of addCustomDnsRule. 976 * @throws { BusinessError } 201 - Permission denied. 977 * @throws { BusinessError } 401 - Parameter error. 978 * @throws { BusinessError } 2100001 - Invalid parameter value. 979 * @throws { BusinessError } 2100002 - Failed to connect to the service. 980 * @throws { BusinessError } 2100003 - System internal error. 981 * @syscap SystemCapability.Communication.NetManager.Core 982 * @atomicservice 983 * @since 15 984 */ 985 function addCustomDnsRule(host: string, ip: Array<string>, callback: AsyncCallback<void>): void; 986 987 /** 988 * Add a custom {@link host} and corresponding {@link ip} mapping for current application. 989 * @permission ohos.permission.INTERNET 990 * @param { string } host - Indicates the host name or the domain. 991 * @param { Array<string> } ip - List of IP addresses mapped to the host name. 992 * @returns { Promise<void> } the promise returned by the function. 993 * @throws { BusinessError } 201 - Permission denied. 994 * @throws { BusinessError } 401 - Parameter error. 995 * @throws { BusinessError } 2100001 - Invalid parameter value. 996 * @throws { BusinessError } 2100002 - Failed to connect to the service. 997 * @throws { BusinessError } 2100003 - System internal error. 998 * @syscap SystemCapability.Communication.NetManager.Core 999 * @since 11 1000 */ 1001 /** 1002 * Add a custom {@link host} and corresponding {@link ip} mapping for current application. 1003 * @permission ohos.permission.INTERNET 1004 * @param { string } host - Indicates the host name or the domain. 1005 * @param { Array<string> } ip - List of IP addresses mapped to the host name. 1006 * @returns { Promise<void> } the promise returned by the function. 1007 * @throws { BusinessError } 201 - Permission denied. 1008 * @throws { BusinessError } 401 - Parameter error. 1009 * @throws { BusinessError } 2100001 - Invalid parameter value. 1010 * @throws { BusinessError } 2100002 - Failed to connect to the service. 1011 * @throws { BusinessError } 2100003 - System internal error. 1012 * @syscap SystemCapability.Communication.NetManager.Core 1013 * @atomicservice 1014 * @since 15 1015 */ 1016 function addCustomDnsRule(host: string, ip: Array<string>): Promise<void>; 1017 1018 /** 1019 * Remove the custom DNS rule of the {@link host} for current application. 1020 * @permission ohos.permission.INTERNET 1021 * @param { string } host - Indicates the host name or the domain. 1022 * @param { AsyncCallback<void> } callback - Returns the callback of removeCustomDnsRule. 1023 * @throws { BusinessError } 201 - Permission denied. 1024 * @throws { BusinessError } 401 - Parameter error. 1025 * @throws { BusinessError } 2100001 - Invalid parameter value. 1026 * @throws { BusinessError } 2100002 - Failed to connect to the service. 1027 * @throws { BusinessError } 2100003 - System internal error. 1028 * @syscap SystemCapability.Communication.NetManager.Core 1029 * @since 11 1030 */ 1031 /** 1032 * Remove the custom DNS rule of the {@link host} for current application. 1033 * @permission ohos.permission.INTERNET 1034 * @param { string } host - Indicates the host name or the domain. 1035 * @param { AsyncCallback<void> } callback - Returns the callback of removeCustomDnsRule. 1036 * @throws { BusinessError } 201 - Permission denied. 1037 * @throws { BusinessError } 401 - Parameter error. 1038 * @throws { BusinessError } 2100001 - Invalid parameter value. 1039 * @throws { BusinessError } 2100002 - Failed to connect to the service. 1040 * @throws { BusinessError } 2100003 - System internal error. 1041 * @syscap SystemCapability.Communication.NetManager.Core 1042 * @atomicservice 1043 * @since 15 1044 */ 1045 function removeCustomDnsRule(host: string, callback: AsyncCallback<void>): void; 1046 1047 /** 1048 * Remove the custom DNS rule of the {@link host} for current application. 1049 * @permission ohos.permission.INTERNET 1050 * @param { string } host - Indicates the host name or the domain. 1051 * @returns { Promise<void> } the promise returned by the function. 1052 * @throws { BusinessError } 201 - Permission denied. 1053 * @throws { BusinessError } 401 - Parameter error. 1054 * @throws { BusinessError } 2100001 - Invalid parameter value. 1055 * @throws { BusinessError } 2100002 - Failed to connect to the service. 1056 * @throws { BusinessError } 2100003 - System internal error. 1057 * @syscap SystemCapability.Communication.NetManager.Core 1058 * @since 11 1059 */ 1060 /** 1061 * Remove the custom DNS rule of the {@link host} for current application. 1062 * @permission ohos.permission.INTERNET 1063 * @param { string } host - Indicates the host name or the domain. 1064 * @returns { Promise<void> } the promise returned by the function. 1065 * @throws { BusinessError } 201 - Permission denied. 1066 * @throws { BusinessError } 401 - Parameter error. 1067 * @throws { BusinessError } 2100001 - Invalid parameter value. 1068 * @throws { BusinessError } 2100002 - Failed to connect to the service. 1069 * @throws { BusinessError } 2100003 - System internal error. 1070 * @syscap SystemCapability.Communication.NetManager.Core 1071 * @atomicservice 1072 * @since 15 1073 */ 1074 function removeCustomDnsRule(host: string): Promise<void>; 1075 1076 /** 1077 * Clear all custom DNS rules for current application. 1078 * @permission ohos.permission.INTERNET 1079 * @param { AsyncCallback<void> } callback - Returns the callback of clearCustomDnsRules. 1080 * @throws { BusinessError } 201 - Permission denied. 1081 * @throws { BusinessError } 401 - Parameter error. 1082 * @throws { BusinessError } 2100001 - Invalid parameter value. 1083 * @throws { BusinessError } 2100002 - Failed to connect to the service. 1084 * @throws { BusinessError } 2100003 - System internal error. 1085 * @syscap SystemCapability.Communication.NetManager.Core 1086 * @since 11 1087 */ 1088 function clearCustomDnsRules(callback: AsyncCallback<void>): void; 1089 1090 /** 1091 * Clear all custom DNS rules for current application. 1092 * @permission ohos.permission.INTERNET 1093 * @returns { Promise<void> } the promise returned by the function. 1094 * @throws { BusinessError } 201 - Permission denied. 1095 * @throws { BusinessError } 2100001 - Invalid parameter value. 1096 * @throws { BusinessError } 2100002 - Failed to connect to the service. 1097 * @throws { BusinessError } 2100003 - System internal error. 1098 * @syscap SystemCapability.Communication.NetManager.Core 1099 * @since 11 1100 */ 1101 function clearCustomDnsRules(): Promise<void>; 1102 1103 /** 1104 * factory reset network settings 1105 * 1106 * To invoke this method, you must have the {@code ohos.permission.CONNECTIVITY_INTERNAL} permission. 1107 * @permission ohos.permission.CONNECTIVITY_INTERNAL 1108 * @returns { Promise<void> } the promise returned by the function. 1109 * @throws { BusinessError } 201 - Permission denied. 1110 * @throws { BusinessError } 202 - Non-system applications use system APIs. 1111 * @throws { BusinessError } 2100002 - Failed to connect to the service. 1112 * @throws { BusinessError } 2100003 - System internal error. 1113 * @syscap SystemCapability.Communication.NetManager.Core 1114 * @systemapi Hide this for inner system use. Only used for system app. 1115 * @since 11 1116 */ 1117 function factoryReset(): Promise<void>; 1118 1119 /** 1120 * Represents the network connection handle. 1121 * @interface NetConnection 1122 * @syscap SystemCapability.Communication.NetManager.Core 1123 * @since 8 1124 */ 1125 /** 1126 * Represents the network connection handle. 1127 * @interface NetConnection 1128 * @syscap SystemCapability.Communication.NetManager.Core 1129 * @crossplatform 1130 * @since 10 1131 */ 1132 /** 1133 * Represents the network connection handle. 1134 * @interface NetConnection 1135 * @syscap SystemCapability.Communication.NetManager.Core 1136 * @crossplatform 1137 * @atomicservice 1138 * @since 11 1139 */ 1140 export interface NetConnection { 1141 /** 1142 * Registers a listener for netAvailable events. 1143 * @param { 'netAvailable' } type - Indicates Event name. 1144 * @param { Callback<NetHandle> } callback - the callback used to return the result. 1145 * @syscap SystemCapability.Communication.NetManager.Core 1146 * @since 8 1147 */ 1148 /** 1149 * Registers a listener for netAvailable events. 1150 * @param { 'netAvailable' } type - Indicates Event name. 1151 * @param { Callback<NetHandle> } callback - the callback used to return the result. 1152 * @syscap SystemCapability.Communication.NetManager.Core 1153 * @crossplatform 1154 * @since 10 1155 */ 1156 /** 1157 * Registers a listener for netAvailable events. 1158 * @param { 'netAvailable' } type - Indicates Event name. 1159 * @param { Callback<NetHandle> } callback - the callback used to return the result. 1160 * @syscap SystemCapability.Communication.NetManager.Core 1161 * @crossplatform 1162 * @atomicservice 1163 * @since 11 1164 */ 1165 on(type: 'netAvailable', callback: Callback<NetHandle>): void; 1166 1167 /** 1168 * Registers a listener for netBlockStatusChange events. 1169 * @param { 'netBlockStatusChange' } type - Indicates Event name. 1170 * @param { Callback<{ netHandle: NetHandle, blocked: boolean }> } callback - the callback used to return the result. 1171 * @syscap SystemCapability.Communication.NetManager.Core 1172 * @since 8 1173 */ 1174 /** 1175 * Registers a listener for netBlockStatusChange events. 1176 * @param { 'netBlockStatusChange' } type - Indicates Event name. 1177 * @param { Callback<NetBlockStatusInfo> } callback - the callback used to return the result. 1178 * @syscap SystemCapability.Communication.NetManager.Core 1179 * @since 11 1180 */ 1181 on(type: 'netBlockStatusChange', callback: Callback<NetBlockStatusInfo>): void; 1182 1183 /** 1184 * Registers a listener for **netCapabilitiesChange** events. 1185 * @param { 'netCapabilitiesChange' } type - Indicates Event name. 1186 * @param { Callback<NetCapabilityInfo> } callback - the callback used to return the result. 1187 * @syscap SystemCapability.Communication.NetManager.Core 1188 * @since 8 1189 */ 1190 /** 1191 * Registers a listener for **netCapabilitiesChange** events. 1192 * @param { 'netCapabilitiesChange' } type - Indicates Event name. 1193 * @param { Callback<NetCapabilityInfo> } callback - the callback used to return the result. 1194 * @syscap SystemCapability.Communication.NetManager.Core 1195 * @crossplatform 1196 * @since 10 1197 */ 1198 /** 1199 * Registers a listener for **netCapabilitiesChange** events. 1200 * @param { 'netCapabilitiesChange' } type - Indicates Event name. 1201 * @param { Callback<NetCapabilityInfo> } callback - the callback used to return the result. 1202 * @syscap SystemCapability.Communication.NetManager.Core 1203 * @crossplatform 1204 * @atomicservice 1205 * @since 11 1206 */ 1207 on(type: 'netCapabilitiesChange', callback: Callback<NetCapabilityInfo>): void; 1208 1209 /** 1210 * Registers a listener for netConnectionPropertiesChange events. 1211 * @param { 'netConnectionPropertiesChange' } type - Indicates Event name. 1212 * @param { Callback<{ netHandle: NetHandle, connectionProperties: ConnectionProperties }> } callback - the callback used to return the result. 1213 * @syscap SystemCapability.Communication.NetManager.Core 1214 * @since 8 1215 */ 1216 /** 1217 * Registers a listener for netConnectionPropertiesChange events. 1218 * @param { 'netConnectionPropertiesChange' } type - Indicates Event name. 1219 * @param { Callback<NetConnectionPropertyInfo> } callback - the callback used to return the result. 1220 * @syscap SystemCapability.Communication.NetManager.Core 1221 * @since 11 1222 */ 1223 on(type: 'netConnectionPropertiesChange', callback: Callback<NetConnectionPropertyInfo>): void; 1224 1225 /** 1226 * Registers a listener for **netLost** events. 1227 * @param { 'netLost' } type - Indicates Event name. 1228 * @param { Callback<NetHandle> } callback - the callback used to return the result. 1229 * @syscap SystemCapability.Communication.NetManager.Core 1230 * @since 8 1231 */ 1232 /** 1233 * Registers a listener for **netLost** events. 1234 * @param { 'netLost' } type - Indicates Event name. 1235 * @param { Callback<NetHandle> } callback - the callback used to return the result. 1236 * @syscap SystemCapability.Communication.NetManager.Core 1237 * @crossplatform 1238 * @since 10 1239 */ 1240 /** 1241 * Registers a listener for **netLost** events. 1242 * @param { 'netLost' } type - Indicates Event name. 1243 * @param { Callback<NetHandle> } callback - the callback used to return the result. 1244 * @syscap SystemCapability.Communication.NetManager.Core 1245 * @crossplatform 1246 * @atomicservice 1247 * @since 11 1248 */ 1249 on(type: 'netLost', callback: Callback<NetHandle>): void; 1250 1251 /** 1252 * Registers a listener for netUnavailable events. 1253 * @param { 'netUnavailable' } type - Indicates Event name. 1254 * @param { Callback<void> } callback - the callback used to return the result. 1255 * @syscap SystemCapability.Communication.NetManager.Core 1256 * @since 8 1257 */ 1258 /** 1259 * Registers a listener for netUnavailable events. 1260 * @param { 'netUnavailable' } type - Indicates Event name. 1261 * @param { Callback<void> } callback - the callback used to return the result. 1262 * @syscap SystemCapability.Communication.NetManager.Core 1263 * @crossplatform 1264 * @since 10 1265 */ 1266 /** 1267 * Registers a listener for netUnavailable events. 1268 * @param { 'netUnavailable' } type - Indicates Event name. 1269 * @param { Callback<void> } callback - the callback used to return the result. 1270 * @syscap SystemCapability.Communication.NetManager.Core 1271 * @crossplatform 1272 * @atomicservice 1273 * @since 11 1274 */ 1275 on(type: 'netUnavailable', callback: Callback<void>): void; 1276 1277 /** 1278 * Receives status change notifications of a specified network. 1279 * @permission ohos.permission.GET_NETWORK_INFO 1280 * @param { AsyncCallback<void> } callback - the callback of register. 1281 * @throws { BusinessError } 201 - Permission denied. 1282 * @throws { BusinessError } 401 - Parameter error. 1283 * @throws { BusinessError } 2100002 - Failed to connect to the service. 1284 * @throws { BusinessError } 2100003 - System internal error. 1285 * @throws { BusinessError } 2101008 - The callback already exists. 1286 * @throws { BusinessError } 2101022 - The number of requests exceeded the maximum allowed. 1287 * @syscap SystemCapability.Communication.NetManager.Core 1288 * @since 8 1289 */ 1290 /** 1291 * Receives status change notifications of a specified network. 1292 * @permission ohos.permission.GET_NETWORK_INFO 1293 * @param { AsyncCallback<void> } callback - the callback of register. 1294 * @throws { BusinessError } 201 - Permission denied. 1295 * @throws { BusinessError } 401 - Parameter error. 1296 * @throws { BusinessError } 2100002 - Failed to connect to the service. 1297 * @throws { BusinessError } 2100003 - System internal error. 1298 * @throws { BusinessError } 2101008 - The callback already exists. 1299 * @throws { BusinessError } 2101022 - The number of requests exceeded the maximum allowed. 1300 * @syscap SystemCapability.Communication.NetManager.Core 1301 * @crossplatform 1302 * @since 10 1303 */ 1304 /** 1305 * Receives status change notifications of a specified network. 1306 * @permission ohos.permission.GET_NETWORK_INFO 1307 * @param { AsyncCallback<void> } callback - the callback of register. 1308 * @throws { BusinessError } 201 - Permission denied. 1309 * @throws { BusinessError } 401 - Parameter error. 1310 * @throws { BusinessError } 2100002 - Failed to connect to the service. 1311 * @throws { BusinessError } 2100003 - System internal error. 1312 * @throws { BusinessError } 2101008 - The callback already exists. 1313 * @throws { BusinessError } 2101022 - The number of requests exceeded the maximum allowed. 1314 * @syscap SystemCapability.Communication.NetManager.Core 1315 * @crossplatform 1316 * @atomicservice 1317 * @since 11 1318 */ 1319 register(callback: AsyncCallback<void>): void; 1320 1321 /** 1322 * Cancels listening for network status changes. 1323 * @param { AsyncCallback<void> } callback - the callback of unregister. 1324 * @throws { BusinessError } 201 - Permission denied. 1325 * @throws { BusinessError } 401 - Parameter error. 1326 * @throws { BusinessError } 2100002 - Failed to connect to the service. 1327 * @throws { BusinessError } 2100003 - System internal error. 1328 * @throws { BusinessError } 2101007 - The callback does not exist. 1329 * @syscap SystemCapability.Communication.NetManager.Core 1330 * @since 8 1331 */ 1332 /** 1333 * Cancels listening for network status changes. 1334 * @param { AsyncCallback<void> } callback - the callback of unregister. 1335 * @throws { BusinessError } 201 - Permission denied. 1336 * @throws { BusinessError } 401 - Parameter error. 1337 * @throws { BusinessError } 2100002 - Failed to connect to the service. 1338 * @throws { BusinessError } 2100003 - System internal error. 1339 * @throws { BusinessError } 2101007 - The callback does not exist. 1340 * @syscap SystemCapability.Communication.NetManager.Core 1341 * @crossplatform 1342 * @since 10 1343 */ 1344 /** 1345 * Cancels listening for network status changes. 1346 * @param { AsyncCallback<void> } callback - the callback of unregister. 1347 * @throws { BusinessError } 201 - Permission denied. 1348 * @throws { BusinessError } 401 - Parameter error. 1349 * @throws { BusinessError } 2100002 - Failed to connect to the service. 1350 * @throws { BusinessError } 2100003 - System internal error. 1351 * @throws { BusinessError } 2101007 - The callback does not exist. 1352 * @syscap SystemCapability.Communication.NetManager.Core 1353 * @crossplatform 1354 * @atomicservice 1355 * @since 11 1356 */ 1357 /** 1358 * Cancels listening for network status changes. 1359 * @param { AsyncCallback<void> } callback - the callback of unregister. 1360 * @throws { BusinessError } 401 - Parameter error. 1361 * @throws { BusinessError } 2100002 - Failed to connect to the service. 1362 * @throws { BusinessError } 2100003 - System internal error. 1363 * @throws { BusinessError } 2101007 - The callback does not exist. 1364 * @syscap SystemCapability.Communication.NetManager.Core 1365 * @crossplatform 1366 * @atomicservice 1367 * @since 12 1368 */ 1369 unregister(callback: AsyncCallback<void>): void; 1370 } 1371 1372 /** 1373 * Provides an instance that bear data network capabilities. 1374 * @interface NetSpecifier 1375 * @syscap SystemCapability.Communication.NetManager.Core 1376 * @since 8 1377 */ 1378 /** 1379 * Provides an instance that bear data network capabilities. 1380 * @interface NetSpecifier 1381 * @syscap SystemCapability.Communication.NetManager.Core 1382 * @atomicservice 1383 * @since 11 1384 */ 1385 export interface NetSpecifier { 1386 /** 1387 * The transmission capacity and support of the network's global proxy storage data network. 1388 * @type {NetCapabilities} 1389 * @syscap SystemCapability.Communication.NetManager.Core 1390 * @since 8 1391 */ 1392 /** 1393 * The transmission capacity and support of the network's global proxy storage data network. 1394 * @type {NetCapabilities} 1395 * @syscap SystemCapability.Communication.NetManager.Core 1396 * @atomicservice 1397 * @since 11 1398 */ 1399 netCapabilities: NetCapabilities; 1400 1401 /** 1402 * Network identifier, the identifier for Wi Fi networks is "wifi", and the identifier for cellular networks is "simId1" (corresponding to SIM card 1). 1403 * @type {?string} 1404 * @syscap SystemCapability.Communication.NetManager.Core 1405 * @since 8 1406 */ 1407 /** 1408 * Network identifier, the identifier for Wi Fi networks is "wifi", and the identifier for cellular networks is "simId1" (corresponding to SIM card 1). 1409 * @type {?string} 1410 * @syscap SystemCapability.Communication.NetManager.Core 1411 * @atomicservice 1412 * @since 11 1413 */ 1414 bearerPrivateIdentifier?: string; 1415 } 1416 1417 /** 1418 * Receive information about changes in network capabilities. 1419 * @interface NetCapabilityInfo 1420 * @syscap SystemCapability.Communication.NetManager.Core 1421 * @crossplatform 1422 * @since 10 1423 */ 1424 /** 1425 * Receive information about changes in network capabilities. 1426 * @interface NetCapabilityInfo 1427 * @syscap SystemCapability.Communication.NetManager.Core 1428 * @crossplatform 1429 * @atomicservice 1430 * @since 11 1431 */ 1432 export interface NetCapabilityInfo { 1433 /** 1434 * Defines the handle of the data network. 1435 * @type { NetHandle } 1436 * @syscap SystemCapability.Communication.NetManager.Core 1437 * @crossplatform 1438 * @since 10 1439 */ 1440 /** 1441 * Defines the handle of the data network. 1442 * @type { NetHandle } 1443 * @syscap SystemCapability.Communication.NetManager.Core 1444 * @crossplatform 1445 * @atomicservice 1446 * @since 11 1447 */ 1448 netHandle: NetHandle; 1449 1450 /** 1451 * Defines the network capability set. 1452 * @type { NetCapabilities } 1453 * @syscap SystemCapability.Communication.NetManager.Core 1454 * @crossplatform 1455 * @since 10 1456 */ 1457 /** 1458 * Defines the network capability set. 1459 * @type { NetCapabilities } 1460 * @syscap SystemCapability.Communication.NetManager.Core 1461 * @crossplatform 1462 * @atomicservice 1463 * @since 11 1464 */ 1465 netCap: NetCapabilities; 1466 } 1467 1468 /** 1469 * Defines the handle of the data network. 1470 * @interface NetHandle 1471 * @syscap SystemCapability.Communication.NetManager.Core 1472 * @since 8 1473 */ 1474 /** 1475 * Defines the handle of the data network. 1476 * @interface NetHandle 1477 * @syscap SystemCapability.Communication.NetManager.Core 1478 * @crossplatform 1479 * @since 10 1480 */ 1481 /** 1482 * Defines the handle of the data network. 1483 * @interface NetHandle 1484 * @syscap SystemCapability.Communication.NetManager.Core 1485 * @crossplatform 1486 * @atomicservice 1487 * @since arkts {'1.1':'11','1.2':'20'} 1488 * @arkts 1.1&1.2 1489 */ 1490 export interface NetHandle { 1491 /** 1492 * 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. 1493 * @type {number} 1494 * @syscap SystemCapability.Communication.NetManager.Core 1495 * @since 8 1496 */ 1497 /** 1498 * 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. 1499 * @type {number} 1500 * @syscap SystemCapability.Communication.NetManager.Core 1501 * @crossplatform 1502 * @since 10 1503 */ 1504 /** 1505 * 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. 1506 * @type {number} 1507 * @syscap SystemCapability.Communication.NetManager.Core 1508 * @crossplatform 1509 * @atomicservice 1510 * @since arkts {'1.1':'11','1.2':'20'} 1511 * @arkts 1.1&1.2 1512 */ 1513 netId: number; 1514 1515 /** 1516 * <p>Binds a TCPSocket or UDPSocket to the current network. All data flows from 1517 * the socket will use this network, without being subject to {@link setAppNet}.</p> 1518 * Before using this method, ensure that the socket is disconnected. 1519 * @param { TCPSocket | UDPSocket } socketParam - Indicates the TCPSocket or UDPSocket object. 1520 * @param { AsyncCallback<void> } callback - the callback of bindSocket. 1521 * @throws { BusinessError } 401 - Parameter error. 1522 * @throws { BusinessError } 2100001 - Invalid parameter value. 1523 * @throws { BusinessError } 2100002 - Failed to connect to the service. 1524 * @throws { BusinessError } 2100003 - System internal error. 1525 * @syscap SystemCapability.Communication.NetManager.Core 1526 * @since 9 1527 */ 1528 bindSocket(socketParam: TCPSocket | UDPSocket, callback: AsyncCallback<void>): void; 1529 1530 /** 1531 * <p>Binds a TCPSocket or UDPSocket to the current network. All data flows from 1532 * the socket will use this network, without being subject to {@link setAppNet}.</p> 1533 * Before using this method, ensure that the socket is disconnected. 1534 * @param { TCPSocket | UDPSocket } socketParam - Indicates the TCPSocket or UDPSocket object. 1535 * @returns { Promise<void> } the promise returned by the function. 1536 * @throws { BusinessError } 401 - Parameter error. 1537 * @throws { BusinessError } 2100001 - Invalid parameter value. 1538 * @throws { BusinessError } 2100002 - Failed to connect to the service. 1539 * @throws { BusinessError } 2100003 - System internal error. 1540 * @syscap SystemCapability.Communication.NetManager.Core 1541 * @since 9 1542 */ 1543 bindSocket(socketParam: TCPSocket | UDPSocket): Promise<void>; 1544 1545 /** 1546 * Resolves a host name to obtain all IP addresses based on the specified NetHandle. 1547 * @permission ohos.permission.INTERNET 1548 * @param { string } host - Indicates the host name or the domain. 1549 * @param { AsyncCallback<Array<NetAddress>> } callback - the callback of getAddressesByName. 1550 * @throws { BusinessError } 201 - Permission denied. 1551 * @throws { BusinessError } 401 - Parameter error. 1552 * @throws { BusinessError } 2100001 - Invalid parameter value. 1553 * @throws { BusinessError } 2100002 - Failed to connect to the service. 1554 * @throws { BusinessError } 2100003 - System internal error. 1555 * @syscap SystemCapability.Communication.NetManager.Core 1556 * @since 8 1557 */ 1558 /** 1559 * Resolves a host name to obtain all IP addresses based on the specified NetHandle. 1560 * @permission ohos.permission.INTERNET 1561 * @param { string } host - Indicates the host name or the domain. 1562 * @param { AsyncCallback<Array<NetAddress>> } callback - the callback of getAddressesByName. 1563 * @throws { BusinessError } 201 - Permission denied. 1564 * @throws { BusinessError } 401 - Parameter error. 1565 * @throws { BusinessError } 2100001 - Invalid parameter value. 1566 * @throws { BusinessError } 2100002 - Failed to connect to the service. 1567 * @throws { BusinessError } 2100003 - System internal error. 1568 * @syscap SystemCapability.Communication.NetManager.Core 1569 * @atomicservice 1570 * @since 15 1571 */ 1572 getAddressesByName(host: string, callback: AsyncCallback<Array<NetAddress>>): void; 1573 1574 /** 1575 * Resolves a host name to obtain all IP addresses based on the specified NetHandle. 1576 * @permission ohos.permission.INTERNET 1577 * @param { string } host - Indicates the host name or the domain. 1578 * @returns { Promise<Array<NetAddress>> } The promise returned by the function. 1579 * @throws { BusinessError } 201 - Permission denied. 1580 * @throws { BusinessError } 401 - Parameter error. 1581 * @throws { BusinessError } 2100001 - Invalid parameter value. 1582 * @throws { BusinessError } 2100002 - Failed to connect to the service. 1583 * @throws { BusinessError } 2100003 - System internal error. 1584 * @syscap SystemCapability.Communication.NetManager.Core 1585 * @since 8 1586 */ 1587 /** 1588 * Resolves a host name to obtain all IP addresses based on the specified NetHandle. 1589 * @permission ohos.permission.INTERNET 1590 * @param { string } host - Indicates the host name or the domain. 1591 * @returns { Promise<Array<NetAddress>> } The promise returned by the function. 1592 * @throws { BusinessError } 201 - Permission denied. 1593 * @throws { BusinessError } 401 - Parameter error. 1594 * @throws { BusinessError } 2100001 - Invalid parameter value. 1595 * @throws { BusinessError } 2100002 - Failed to connect to the service. 1596 * @throws { BusinessError } 2100003 - System internal error. 1597 * @syscap SystemCapability.Communication.NetManager.Core 1598 * @atomicservice 1599 * @since 15 1600 */ 1601 getAddressesByName(host: string): Promise<Array<NetAddress>>; 1602 1603 /** 1604 * Resolves a host name to obtain the first IP address based on the specified NetHandle. 1605 * @permission ohos.permission.INTERNET 1606 * @param { string } host - Indicates the host name or the domain. 1607 * @param { AsyncCallback<NetAddress> } callback - the callback of getAddressByName. 1608 * @throws { BusinessError } 201 - Permission denied. 1609 * @throws { BusinessError } 401 - Parameter error. 1610 * @throws { BusinessError } 2100001 - Invalid parameter value. 1611 * @throws { BusinessError } 2100002 - Failed to connect to the service. 1612 * @throws { BusinessError } 2100003 - System internal error. 1613 * @syscap SystemCapability.Communication.NetManager.Core 1614 * @since 8 1615 */ 1616 getAddressByName(host: string, callback: AsyncCallback<NetAddress>): void; 1617 1618 /** 1619 * Resolves a host name to obtain the first IP address based on the specified NetHandle. 1620 * @permission ohos.permission.INTERNET 1621 * @param { string } host - Indicates the host name or the domain. 1622 * @returns { Promise<NetAddress> } The promise returned by the function. 1623 * @throws { BusinessError } 201 - Permission denied. 1624 * @throws { BusinessError } 401 - Parameter error. 1625 * @throws { BusinessError } 2100001 - Invalid parameter value. 1626 * @throws { BusinessError } 2100002 - Failed to connect to the service. 1627 * @throws { BusinessError } 2100003 - System internal error. 1628 * @syscap SystemCapability.Communication.NetManager.Core 1629 * @since 8 1630 */ 1631 getAddressByName(host: string): Promise<NetAddress>; 1632 } 1633 1634 /** 1635 * Defines the network capability set. 1636 * @interface NetCapabilities 1637 * @syscap SystemCapability.Communication.NetManager.Core 1638 * @since 8 1639 */ 1640 /** 1641 * Defines the network capability set. 1642 * @interface NetCapabilities 1643 * @syscap SystemCapability.Communication.NetManager.Core 1644 * @crossplatform 1645 * @since 10 1646 */ 1647 /** 1648 * Defines the network capability set. 1649 * @interface NetCapabilities 1650 * @syscap SystemCapability.Communication.NetManager.Core 1651 * @crossplatform 1652 * @atomicservice 1653 * @since 11 1654 */ 1655 export interface NetCapabilities { 1656 /** 1657 * Uplink (device-to-network) bandwidth. 1658 * @type {?number} 1659 * @syscap SystemCapability.Communication.NetManager.Core 1660 * @since 8 1661 */ 1662 linkUpBandwidthKbps?: number; 1663 1664 /** 1665 * Downstream (network-to-device) bandwidth. 1666 * @type {?number} 1667 * @syscap SystemCapability.Communication.NetManager.Core 1668 * @since 8 1669 */ 1670 linkDownBandwidthKbps?: number; 1671 1672 /** 1673 * Network-specific capabilities. 1674 * @type {?Array<NetCap>} 1675 * @syscap SystemCapability.Communication.NetManager.Core 1676 * @since 8 1677 */ 1678 /** 1679 * Network-specific capabilities. 1680 * @type {?Array<NetCap>} 1681 * @syscap SystemCapability.Communication.NetManager.Core 1682 * @atomicservice 1683 * @since 11 1684 */ 1685 networkCap?: Array<NetCap>; 1686 1687 /** 1688 * Network type. 1689 * @type {Array<NetBearType>} 1690 * @syscap SystemCapability.Communication.NetManager.Core 1691 * @since 8 1692 */ 1693 /** 1694 * Network type. 1695 * @type {Array<NetBearType>} 1696 * @syscap SystemCapability.Communication.NetManager.Core 1697 * @crossplatform 1698 * @since 10 1699 */ 1700 /** 1701 * Network type. 1702 * @type {Array<NetBearType>} 1703 * @syscap SystemCapability.Communication.NetManager.Core 1704 * @crossplatform 1705 * @atomicservice 1706 * @since 11 1707 */ 1708 bearerTypes: Array<NetBearType>; 1709 } 1710 1711 /** 1712 * Get information about network connections. 1713 * @interface NetConnectionPropertyInfo 1714 * @syscap SystemCapability.Communication.NetManager.Core 1715 * @since 11 1716 */ 1717 export interface NetConnectionPropertyInfo { 1718 /** 1719 * Defines the handle of the data network. 1720 * @type { NetHandle } 1721 * @syscap SystemCapability.Communication.NetManager.Core 1722 * @since 11 1723 */ 1724 netHandle: NetHandle; 1725 /** 1726 * Defines the network connection properties. 1727 * @type { ConnectionProperties } 1728 * @syscap SystemCapability.Communication.NetManager.Core 1729 * @since 11 1730 */ 1731 connectionProperties: ConnectionProperties; 1732 } 1733 1734 /** 1735 * Get network status information. 1736 * @interface NetBlockStatusInfo 1737 * @syscap SystemCapability.Communication.NetManager.Core 1738 * @since 11 1739 */ 1740 export interface NetBlockStatusInfo { 1741 /** 1742 * Defines the handle of the data network. 1743 * @type { NetHandle } 1744 * @syscap SystemCapability.Communication.NetManager.Core 1745 * @since 11 1746 */ 1747 netHandle: NetHandle; 1748 /** 1749 * Check whether the current state is blocked. 1750 * @type { boolean } 1751 * @syscap SystemCapability.Communication.NetManager.Core 1752 * @since 11 1753 */ 1754 blocked: boolean; 1755 } 1756 1757 /** 1758 * Defines the network capability. 1759 * @enum {number} 1760 * @syscap SystemCapability.Communication.NetManager.Core 1761 * @since 8 1762 */ 1763 /** 1764 * Defines the network capability. 1765 * @enum {number} 1766 * @syscap SystemCapability.Communication.NetManager.Core 1767 * @atomicservice 1768 * @since 11 1769 */ 1770 export enum NetCap { 1771 /** 1772 * Indicates that the network can access the carrier's MMSC to send and receive multimedia messages. 1773 * @syscap SystemCapability.Communication.NetManager.Core 1774 * @since 8 1775 */ 1776 /** 1777 * Indicates that the network can access the carrier's MMSC to send and receive multimedia messages. 1778 * @syscap SystemCapability.Communication.NetManager.Core 1779 * @atomicservice 1780 * @since 11 1781 */ 1782 NET_CAPABILITY_MMS = 0, 1783 1784 /** 1785 * Indicates that the network traffic is not metered. 1786 * @syscap SystemCapability.Communication.NetManager.Core 1787 * @since 8 1788 */ 1789 /** 1790 * Indicates that the network traffic is not metered. 1791 * @syscap SystemCapability.Communication.NetManager.Core 1792 * @atomicservice 1793 * @since 11 1794 */ 1795 NET_CAPABILITY_NOT_METERED = 11, 1796 1797 /** 1798 * Indicates that the network can access the Internet. 1799 * @syscap SystemCapability.Communication.NetManager.Core 1800 * @since 8 1801 */ 1802 /** 1803 * Indicates that the network can access the Internet. 1804 * @syscap SystemCapability.Communication.NetManager.Core 1805 * @atomicservice 1806 * @since 11 1807 */ 1808 NET_CAPABILITY_INTERNET = 12, 1809 1810 /** 1811 * Indicates that the network does not use a VPN. 1812 * @syscap SystemCapability.Communication.NetManager.Core 1813 * @since 8 1814 */ 1815 /** 1816 * Indicates that the network does not use a VPN. 1817 * @syscap SystemCapability.Communication.NetManager.Core 1818 * @atomicservice 1819 * @since 11 1820 */ 1821 NET_CAPABILITY_NOT_VPN = 15, 1822 1823 /** 1824 * Indicates that the network is available. 1825 * @syscap SystemCapability.Communication.NetManager.Core 1826 * @since 8 1827 */ 1828 /** 1829 * Indicates that the network is available. 1830 * @syscap SystemCapability.Communication.NetManager.Core 1831 * @atomicservice 1832 * @since 11 1833 */ 1834 NET_CAPABILITY_VALIDATED = 16, 1835 /** 1836 * Indicates that the network is portal. 1837 * @syscap SystemCapability.Communication.NetManager.Core 1838 * @atomicservice 1839 * @since 12 1840 */ 1841 NET_CAPABILITY_PORTAL = 17, 1842 1843 /** 1844 * Indicates that the network is checking connectivity. 1845 * @syscap SystemCapability.Communication.NetManager.Core 1846 * @atomicservice 1847 * @since 12 1848 */ 1849 NET_CAPABILITY_CHECKING_CONNECTIVITY = 31 1850 } 1851 1852 /** 1853 * Enumerates network types. 1854 * @enum {number} 1855 * @syscap SystemCapability.Communication.NetManager.Core 1856 * @since 8 1857 */ 1858 /** 1859 * Enumerates network types. 1860 * @enum {number} 1861 * @syscap SystemCapability.Communication.NetManager.Core 1862 * @crossplatform 1863 * @since 10 1864 */ 1865 /** 1866 * Enumerates network types. 1867 * @enum {number} 1868 * @syscap SystemCapability.Communication.NetManager.Core 1869 * @crossplatform 1870 * @atomicservice 1871 * @since 11 1872 */ 1873 export enum NetBearType { 1874 /** 1875 * Indicates that the network is based on a cellular network. 1876 * @syscap SystemCapability.Communication.NetManager.Core 1877 * @since 8 1878 */ 1879 /** 1880 * Indicates that the network is based on a cellular network. 1881 * @syscap SystemCapability.Communication.NetManager.Core 1882 * @crossplatform 1883 * @since 10 1884 */ 1885 /** 1886 * Indicates that the network is based on a cellular network. 1887 * @syscap SystemCapability.Communication.NetManager.Core 1888 * @crossplatform 1889 * @atomicservice 1890 * @since 11 1891 */ 1892 BEARER_CELLULAR = 0, 1893 1894 /** 1895 * Indicates that the network is based on a Wi-Fi network. 1896 * @syscap SystemCapability.Communication.NetManager.Core 1897 * @since 8 1898 */ 1899 /** 1900 * Indicates that the network is based on a Wi-Fi network. 1901 * @syscap SystemCapability.Communication.NetManager.Core 1902 * @crossplatform 1903 * @since 10 1904 */ 1905 /** 1906 * Indicates that the network is based on a Wi-Fi network. 1907 * @syscap SystemCapability.Communication.NetManager.Core 1908 * @crossplatform 1909 * @atomicservice 1910 * @since 11 1911 */ 1912 BEARER_WIFI = 1, 1913 1914 /** 1915 * Indicates that the network is based on a bluetooth network. 1916 * @syscap SystemCapability.Communication.NetManager.Core 1917 * @crossplatform 1918 * @atomicservice 1919 * @since 12 1920 */ 1921 BEARER_BLUETOOTH = 2, 1922 1923 /** 1924 * Indicates that the network is an Ethernet network. 1925 * @syscap SystemCapability.Communication.NetManager.Core 1926 * @since 8 1927 */ 1928 /** 1929 * Indicates that the network is an Ethernet network. 1930 * @syscap SystemCapability.Communication.NetManager.Core 1931 * @atomicservice 1932 * @since 11 1933 */ 1934 BEARER_ETHERNET = 3, 1935 1936 /** 1937 * Indicates that the network is based on a VPN network. 1938 * @syscap SystemCapability.Communication.NetManager.Core 1939 * @since 12 1940 */ 1941 BEARER_VPN = 4, 1942 } 1943 1944 /** 1945 * Enumerates proxy modes. 1946 * @enum {number} 1947 * @syscap SystemCapability.Communication.NetManager.Core 1948 * @systemapi Hide this for inner system use. Only used for system app. 1949 * @since 20 1950 */ 1951 export enum ProxyMode{ 1952 /** 1953 * Off proxy mode. 1954 * @syscap SystemCapability.Communication.NetManager.Core 1955 * @systemapi Hide this for inner system use. Only used for system app. 1956 * @since 20 1957 */ 1958 PROXY_MODE_OFF = 0, 1959 1960 /** 1961 * Auto proxy mode. 1962 * @syscap SystemCapability.Communication.NetManager.Core 1963 * @systemapi Hide this for inner system use. Only used for system app. 1964 * @since 20 1965 */ 1966 PROXY_MODE_AUTO = 1 1967 } 1968 1969 /** 1970 * Defines the network connection properties. 1971 * @interface ConnectionProperties 1972 * @syscap SystemCapability.Communication.NetManager.Core 1973 * @since 8 1974 */ 1975 export interface ConnectionProperties { 1976 /** 1977 * Network card name. 1978 * @type {string} 1979 * @syscap SystemCapability.Communication.NetManager.Core 1980 * @since 8 1981 */ 1982 interfaceName: string; 1983 /** 1984 * Domain. The default value is "". 1985 * @type {string} 1986 * @syscap SystemCapability.Communication.NetManager.Core 1987 * @since 8 1988 */ 1989 domains: string; 1990 /** 1991 * Link information. 1992 * @type {Array<LinkAddress>} 1993 * @syscap SystemCapability.Communication.NetManager.Core 1994 * @since 8 1995 */ 1996 linkAddresses: Array<LinkAddress>; 1997 1998 /** 1999 * Network address, refer to [NetAddress]. 2000 * @type {Array<NetAddress>} 2001 * @syscap SystemCapability.Communication.NetManager.Core 2002 * @since 8 2003 */ 2004 dnses: Array<NetAddress>; 2005 2006 /** 2007 * Routing information. 2008 * @type {Array<RouteInfo>} 2009 * @syscap SystemCapability.Communication.NetManager.Core 2010 * @since 8 2011 */ 2012 routes: Array<RouteInfo>; 2013 2014 /** 2015 * Maximum transmission unit. 2016 * @type {number} 2017 * @syscap SystemCapability.Communication.NetManager.Core 2018 * @since 8 2019 */ 2020 mtu: number; 2021 } 2022 2023 /** 2024 * Defines network route information. 2025 * @interface RouteInfo 2026 * @syscap SystemCapability.Communication.NetManager.Core 2027 * @since 8 2028 */ 2029 export interface RouteInfo { 2030 /** 2031 * Network card name. 2032 * @type {string} 2033 * @syscap SystemCapability.Communication.NetManager.Core 2034 * @since 8 2035 */ 2036 interface: string; 2037 2038 /** 2039 * Destination Address 2040 * @type {LinkAddress} 2041 * @syscap SystemCapability.Communication.NetManager.Core 2042 * @since 8 2043 */ 2044 destination: LinkAddress; 2045 2046 /** 2047 * Gateway address. 2048 * @type {NetAddress} 2049 * @syscap SystemCapability.Communication.NetManager.Core 2050 * @since 8 2051 */ 2052 gateway: NetAddress; 2053 2054 /** 2055 * Whether a gateway is present. 2056 * @type {boolean} 2057 * @syscap SystemCapability.Communication.NetManager.Core 2058 * @since 8 2059 */ 2060 hasGateway: boolean; 2061 2062 /** 2063 * Whether the route is the default route. 2064 * @type {boolean} 2065 * @syscap SystemCapability.Communication.NetManager.Core 2066 * @since 8 2067 */ 2068 isDefaultRoute: boolean; 2069 2070 /** 2071 * Whether the route is the excluded route. 2072 * @type { ?boolean} 2073 * @syscap SystemCapability.Communication.NetManager.Core 2074 * @since 20 2075 */ 2076 isExcludedRoute?: boolean; 2077 } 2078 2079 /** 2080 * Defines network link information. 2081 * @interface LinkAddress 2082 * @syscap SystemCapability.Communication.NetManager.Core 2083 * @since 8 2084 */ 2085 export interface LinkAddress { 2086 /** 2087 * Link address. 2088 * @type {NetAddress} 2089 * @syscap SystemCapability.Communication.NetManager.Core 2090 * @since 8 2091 */ 2092 address: NetAddress; 2093 /** 2094 * The length of the link address prefix. 2095 * @type {number} 2096 * @syscap SystemCapability.Communication.NetManager.Core 2097 * @since 8 2098 */ 2099 prefixLength: number; 2100 } 2101 2102 /** 2103 * Defines a network address. 2104 * @interface NetAddress 2105 * @syscap SystemCapability.Communication.NetManager.Core 2106 * @since 8 2107 */ 2108 /** 2109 * Defines a network address. 2110 * @interface NetAddress 2111 * @syscap SystemCapability.Communication.NetManager.Core 2112 * @atomicservice 2113 * @since 12 2114 */ 2115 export interface NetAddress { 2116 /** 2117 * Network address. 2118 * @type {string} 2119 * @syscap SystemCapability.Communication.NetManager.Core 2120 * @since 8 2121 */ 2122 /** 2123 * Network address. 2124 * @type {string} 2125 * @syscap SystemCapability.Communication.NetManager.Core 2126 * @atomicservice 2127 * @since 12 2128 */ 2129 address: string; 2130 2131 /** 2132 * Address family identifier. The value is 1 for IPv4 and 2 for IPv6. The default value is 1. 2133 * @type {?number} 2134 * @syscap SystemCapability.Communication.NetManager.Core 2135 * @since 8 2136 */ 2137 /** 2138 * Address family identifier. The value is 1 for IPv4 and 2 for IPv6. The default value is 1. 2139 * @type {?number} 2140 * @syscap SystemCapability.Communication.NetManager.Core 2141 * @atomicservice 2142 * @since 12 2143 */ 2144 family?: number; 2145 2146 /** 2147 * Port number. The value ranges from 0 to 65535. 2148 * @type {?number} 2149 * @syscap SystemCapability.Communication.NetManager.Core 2150 * @since 8 2151 */ 2152 /** 2153 * Port number. The value ranges from 0 to 65535. 2154 * @type {?number} 2155 * @syscap SystemCapability.Communication.NetManager.Core 2156 * @atomicservice 2157 * @since 12 2158 */ 2159 port?: number; 2160 } 2161 2162 /** 2163 * Network Global Proxy Configuration Information. 2164 * @interface HttpProxy 2165 * @syscap SystemCapability.Communication.NetManager.Core 2166 * @since 10 2167 */ 2168 /** 2169 * Network Global Proxy Configuration Information. 2170 * @interface HttpProxy 2171 * @syscap SystemCapability.Communication.NetManager.Core 2172 * @atomicservice 2173 * @since 11 2174 */ 2175 export interface HttpProxy { 2176 /** 2177 * Proxy server host name. 2178 * @type {string} 2179 * @syscap SystemCapability.Communication.NetManager.Core 2180 * @since 10 2181 */ 2182 /** 2183 * Proxy server host name. 2184 * @type {string} 2185 * @syscap SystemCapability.Communication.NetManager.Core 2186 * @atomicservice 2187 * @since 11 2188 */ 2189 host: string; 2190 2191 /** 2192 * Host port. 2193 * @type {number} 2194 * @syscap SystemCapability.Communication.NetManager.Core 2195 * @since 10 2196 */ 2197 /** 2198 * Host port. 2199 * @type {number} 2200 * @syscap SystemCapability.Communication.NetManager.Core 2201 * @atomicservice 2202 * @since 11 2203 */ 2204 port: number; 2205 2206 /** 2207 * Http proxy username. 2208 * @type {?string} 2209 * @syscap SystemCapability.Communication.NetManager.Core 2210 * @since 12 2211 */ 2212 username?: string; 2213 2214 /** 2215 * Http proxy password. 2216 * @type {?string} 2217 * @syscap SystemCapability.Communication.NetManager.Core 2218 * @since 12 2219 */ 2220 password?: string; 2221 2222 /** 2223 * Do not use a blocking list for proxy servers. 2224 * @type {Array<string>} 2225 * @syscap SystemCapability.Communication.NetManager.Core 2226 * @since 10 2227 */ 2228 /** 2229 * Do not use a blocking list for proxy servers. 2230 * @type {Array<string>} 2231 * @syscap SystemCapability.Communication.NetManager.Core 2232 * @atomicservice 2233 * @since 11 2234 */ 2235 exclusionList: Array<string>; 2236 } 2237} 2238 2239export default connection; 2240