1/* 2 * Copyright (C) 2022-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { AsyncCallback, Callback } from './@ohos.base'; 17import http from './@ohos.net.http'; 18import socket from './@ohos.net.socket'; 19 20/** 21 * Provides interfaces to manage and use data networks. 22 * @namespace connection 23 * @syscap SystemCapability.Communication.NetManager.Core 24 * @since 8 25 */ 26/** 27 * Provides interfaces to manage and use data networks. 28 * @namespace connection 29 * @syscap SystemCapability.Communication.NetManager.Core 30 * @crossplatform 31 * @since 10 32 */ 33declare namespace connection { 34 type HttpRequest = http.HttpRequest; 35 type TCPSocket = socket.TCPSocket; 36 type UDPSocket = socket.UDPSocket; 37 38 /** 39 * Create a network connection with optional netSpecifier and timeout. 40 * @param { NetSpecifier } netSpecifier Indicates the network specifier. See {@link NetSpecifier}. 41 * @param { number } timeout The time in milliseconds to attempt looking for a suitable network before 42 * {@link NetConnection#netUnavailable} is called. 43 * @returns { NetConnection } the NetConnection of the NetSpecifier. 44 * @syscap SystemCapability.Communication.NetManager.Core 45 * @since 8 46 */ 47 /** 48 * Create a network connection with optional netSpecifier and timeout. 49 * @param { NetSpecifier } netSpecifier Indicates the network specifier. See {@link NetSpecifier}. 50 * @param { number } timeout The time in milliseconds to attempt looking for a suitable network before 51 * {@link NetConnection#netUnavailable} is called. 52 * @returns { NetConnection } the NetConnection of the NetSpecifier. 53 * @syscap SystemCapability.Communication.NetManager.Core 54 * @crossplatform 55 * @since 10 56 */ 57 function createNetConnection(netSpecifier?: NetSpecifier, timeout?: number): NetConnection; 58 59 /** 60 * Create a network interface object. 61 * @returns { NetInterface } the NetInterface object. 62 * @syscap SystemCapability.Communication.NetManager.Core 63 * @systemapi Hide this for inner system use. Only used for system app. 64 * @since 16 65 */ 66 function createNetInterface(): NetInterface; 67 68 /** 69 * Add route for a specefic net. 70 * @permission ohos.permission.CONNECTIVITY_INTERNAL 71 * @param { number } netId - the nethandle to add route. 72 * @param { RouteInfo } routeInfo - the route info to add. 73 * @throws { BusinessError } 201 - Permission denied. 74 * @throws { BusinessError } 202 - Non-system applications use system APIs. 75 * @throws { BusinessError } 401 - Parameter error. 76 * @throws { BusinessError } 2100003 - System internal error. 77 * @syscap SystemCapability.Communication.NetManager.Core 78 * @systemapi Hide this for inner system use. Only used for system app. 79 * @since 16 80 */ 81 function addNetworkRoute(netId: number, routeInfo: RouteInfo): void; 82 83 /** 84 * Get the config of the interface. 85 * @permission ohos.permission.CONNECTIVITY_INTERNAL 86 * @param { string } ifaceName - the name of the interface. 87 * @param { AsyncCallback<NetInterfaceConfiguration> } callback - the callback of getNetInterfaceConfiguration. 88 * @throws { BusinessError } 201 - Permission denied. 89 * @throws { BusinessError } 202 - Non-system applications use system APIs. 90 * @throws { BusinessError } 401 - Parameter error. 91 * @throws { BusinessError } 2100003 - System internal error. 92 * @syscap SystemCapability.Communication.NetManager.Core 93 * @systemapi Hide this for inner system use. Only used for system app. 94 * @since 16 95 */ 96 function getNetInterfaceConfiguration(ifaceName: string, callback: AsyncCallback<NetInterfaceConfiguration>): void; 97 98 /** 99 * Get the config of the interface. 100 * @permission ohos.permission.CONNECTIVITY_INTERNAL 101 * @param { string } ifaceName - the name of the interface. 102 * @throws { BusinessError } 201 - Permission denied. 103 * @throws { BusinessError } 202 - Non-system applications use system APIs. 104 * @throws { BusinessError } 401 - Parameter error. 105 * @throws { BusinessError } 2100003 - System internal error. 106 * @syscap SystemCapability.Communication.NetManager.Core 107 * @systemapi Hide this for inner system use. Only used for system app. 108 * @since 16 109 */ 110 function getNetInterfaceConfiguration(ifaceName: string): Promise<NetInterfaceConfiguration>; 111 112 /** 113 * Register a net supplier. 114 * @permission ohos.permission.CONNECTIVITY_INTERNAL 115 * @param { NetBearType } bearerType - the bearer type of the net. 116 * @param { string } ident - the id of the net. 117 * @param { Array<NetCap> } netCaps - the net capabilities of the net. 118 * @param { AsyncCallback<number> } callback - the callback of registerNetSupplier. 119 * @throws { BusinessError } 201 - Permission denied. 120 * @throws { BusinessError } 202 - Non-system applications use system APIs. 121 * @throws { BusinessError } 401 - Parameter error. 122 * @throws { BusinessError } 2100003 - System internal error. 123 * @syscap SystemCapability.Communication.NetManager.Core 124 * @systemapi Hide this for inner system use. Only used for system app. 125 * @since 16 126 */ 127 function registerNetSupplier(bearerType: NetBearType, ident: string, netCaps: Array<NetCap>, callback: AsyncCallback<number>): void; 128 129 /** 130 * Get the config of the interface. 131 * @permission ohos.permission.CONNECTIVITY_INTERNAL 132 * @param { string } ifaceName - the name of the interface. 133 * @throws { BusinessError } 201 - Permission denied. 134 * @throws { BusinessError } 202 - Non-system applications use system APIs. 135 * @throws { BusinessError } 401 - Parameter error. 136 * @throws { BusinessError } 2100003 - System internal error. 137 * @syscap SystemCapability.Communication.NetManager.Core 138 * @systemapi Hide this for inner system use. Only used for system app. 139 * @since 16 140 */ 141 function registerNetSupplier(bearerType: NetBearType, ident: string, netCaps: Array<NetCap>): Promise<number>; 142 143 /** 144 * Unregister a net supplier. 145 * @permission ohos.permission.CONNECTIVITY_INTERNAL 146 * @param { number } netId - the id of the net. 147 * @param { AsyncCallback<void> } callback - the callback of unregisterNetSupplier. 148 * @throws { BusinessError } 201 - Permission denied. 149 * @throws { BusinessError } 202 - Non-system applications use system APIs. 150 * @throws { BusinessError } 401 - Parameter error. 151 * @throws { BusinessError } 2100003 - System internal error. 152 * @syscap SystemCapability.Communication.NetManager.Core 153 * @systemapi Hide this for inner system use. Only used for system app. 154 * @since 16 155 */ 156 function unregisterNetSupplier(netId: number, callback: AsyncCallback<void>): void; 157 158 /** 159 * Unregister a net supplier. 160 * @permission ohos.permission.CONNECTIVITY_INTERNAL 161 * @param { number } netId - the id of the net. 162 * @throws { BusinessError } 201 - Permission denied. 163 * @throws { BusinessError } 202 - Non-system applications use system APIs. 164 * @throws { BusinessError } 401 - Parameter error. 165 * @throws { BusinessError } 2100003 - System internal error. 166 * @syscap SystemCapability.Communication.NetManager.Core 167 * @systemapi Hide this for inner system use. Only used for system app. 168 * @since 16 169 */ 170 function unregisterNetSupplier(netId: number): Promise<void>; 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 * @param { AsyncCallback<NetHandle> } callback Returns the {@link NetHandle} object; 177 * returns {@code null} if the default network is not activated. 178 * @throws { BusinessError } 201 - Permission denied. 179 * @throws { BusinessError } 401 - Parameter error. 180 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 181 * @throws { BusinessError } 2100003 - System internal error. 182 * @syscap SystemCapability.Communication.NetManager.Core 183 * @since 8 184 */ 185 function getDefaultNet(callback: AsyncCallback<NetHandle>): void; 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 { Promise<NetHandle> } The promise returned by the function. 192 * @throws { BusinessError } 201 - Permission denied. 193 * @throws { BusinessError } 401 - Parameter error. 194 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 195 * @throws { BusinessError } 2100003 - System internal error. 196 * @syscap SystemCapability.Communication.NetManager.Core 197 * @since 8 198 */ 199 function getDefaultNet(): Promise<NetHandle>; 200 201 /** 202 * Obtains the data network that is activated by default. 203 * To call this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. 204 * @permission ohos.permission.GET_NETWORK_INFO 205 * @returns { NetHandle } if the default network is not activated. 206 * @throws { BusinessError } 201 - Permission denied. 207 * @throws { BusinessError } 401 - Parameter error. 208 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 209 * @throws { BusinessError } 2100003 - System internal error. 210 * @syscap SystemCapability.Communication.NetManager.Core 211 * @since 9 212 */ 213 function getDefaultNetSync(): NetHandle; 214 215 /** 216 * Obtains the list of data networks that are activated. 217 * To invoke this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. 218 * @permission ohos.permission.GET_NETWORK_INFO 219 * @param { AsyncCallback<Array<NetHandle>> } callback Returns the {@link NetHandle} object; returns {@code null} if no network is activated. 220 * @throws { BusinessError } 201 - Permission denied. 221 * @throws { BusinessError } 401 - Parameter error. 222 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 223 * @throws { BusinessError } 2100003 - System internal error. 224 * @syscap SystemCapability.Communication.NetManager.Core 225 * @since 8 226 */ 227 function getAllNets(callback: AsyncCallback<Array<NetHandle>>): void; 228 229 /** 230 * Obtains the list of data networks that are activated. 231 * To invoke this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. 232 * @permission ohos.permission.GET_NETWORK_INFO 233 * @returns { Promise<Array<NetHandle>> } The promise returned by the function. 234 * @throws { BusinessError } 201 - Permission denied. 235 * @throws { BusinessError } 401 - Parameter error. 236 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 237 * @throws { BusinessError } 2100003 - System internal error. 238 * @syscap SystemCapability.Communication.NetManager.Core 239 * @since 8 240 */ 241 function getAllNets(): Promise<Array<NetHandle>>; 242 243 /** 244 * Queries the connection properties of a network. 245 * This method requires the {@code ohos.permission.GET_NETWORK_INFO} permission. 246 * @permission ohos.permission.GET_NETWORK_INFO 247 * @param { NetHandle } netHandle Indicates the network to be queried. 248 * @param { AsyncCallback<ConnectionProperties> } callback Returns the {@link ConnectionProperties} object. 249 * @throws { BusinessError } 201 - Permission denied. 250 * @throws { BusinessError } 401 - Parameter error. 251 * @throws { BusinessError } 2100001 - Invalid parameter value. 252 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 253 * @throws { BusinessError } 2100003 - System internal error. 254 * @syscap SystemCapability.Communication.NetManager.Core 255 * @since 8 256 */ 257 function getConnectionProperties(netHandle: NetHandle, callback: AsyncCallback<ConnectionProperties>): void; 258 259 /** 260 * Queries the connection properties of a network. 261 * This method requires the {@code ohos.permission.GET_NETWORK_INFO} permission. 262 * @permission ohos.permission.GET_NETWORK_INFO 263 * @param { NetHandle } netHandle Indicates the network to be queried. 264 * @returns { Promise<ConnectionProperties> } The promise returned by the function. 265 * @throws { BusinessError } 201 - Permission denied. 266 * @throws { BusinessError } 401 - Parameter error. 267 * @throws { BusinessError } 2100001 - Invalid parameter value. 268 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 269 * @throws { BusinessError } 2100003 - System internal error. 270 * @syscap SystemCapability.Communication.NetManager.Core 271 * @since 8 272 */ 273 function getConnectionProperties(netHandle: NetHandle): Promise<ConnectionProperties>; 274 275 /** 276 * Obtains {@link NetCapabilities} of a {@link NetHandle} object. 277 * To invoke this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. 278 * @permission ohos.permission.GET_NETWORK_INFO 279 * @param { NetHandle } netHandle Indicates the handle. See {@link NetHandle}. 280 * @param { AsyncCallback<NetCapabilities> } callback Returns {@link NetCapabilities}; returns {@code null} if {@code handle} is invalid. 281 * @throws { BusinessError } 201 - Permission denied. 282 * @throws { BusinessError } 401 - Parameter error. 283 * @throws { BusinessError } 2100001 - Invalid parameter value. 284 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 285 * @throws { BusinessError } 2100003 - System internal error. 286 * @syscap SystemCapability.Communication.NetManager.Core 287 * @since 8 288 */ 289 function getNetCapabilities(netHandle: NetHandle, callback: AsyncCallback<NetCapabilities>): void; 290 291 /** 292 * Obtains {@link NetCapabilities} of a {@link NetHandle} object. 293 * To invoke this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. 294 * @permission ohos.permission.GET_NETWORK_INFO 295 * @param { NetHandle } netHandle Indicates the handle. See {@link NetHandle}. 296 * @returns { Promise<NetCapabilities> } The promise returned by the function. 297 * @throws { BusinessError } 201 - Permission denied. 298 * @throws { BusinessError } 401 - Parameter error. 299 * @throws { BusinessError } 2100001 - Invalid parameter value. 300 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 301 * @throws { BusinessError } 2100003 - System internal error. 302 * @syscap SystemCapability.Communication.NetManager.Core 303 * @since 8 304 */ 305 function getNetCapabilities(netHandle: NetHandle): Promise<NetCapabilities>; 306 307 /** 308 * Checks whether data traffic usage on the current network is metered. 309 * @permission ohos.permission.GET_NETWORK_INFO 310 * @param { AsyncCallback<boolean> } callback Returns {@code true} if data traffic usage on the current network is metered; 311 * returns {@code false} otherwise. 312 * @throws { BusinessError } 201 - Permission denied. 313 * @throws { BusinessError } 401 - Parameter error. 314 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 315 * @throws { BusinessError } 2100003 - System internal error. 316 * @syscap SystemCapability.Communication.NetManager.Core 317 * @since 9 318 */ 319 function isDefaultNetMetered(callback: AsyncCallback<boolean>): void; 320 321 /** 322 * Checks whether data traffic usage on the current network is metered. 323 * @permission ohos.permission.GET_NETWORK_INFO 324 * @returns { Promise<boolean> } the promise returned by the function. 325 * @throws { BusinessError } 201 - Permission denied. 326 * @throws { BusinessError } 401 - Parameter error. 327 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 328 * @throws { BusinessError } 2100003 - System internal error. 329 * @syscap SystemCapability.Communication.NetManager.Core 330 * @since 9 331 */ 332 function isDefaultNetMetered(): Promise<boolean>; 333 334 /** 335 * Checks whether the default data network is activated. 336 * @permission ohos.permission.GET_NETWORK_INFO 337 * @param { AsyncCallback<boolean> } callback Returns {@code true} if the default data network is activated; 338 * returns {@code false} otherwise. 339 * @throws { BusinessError } 201 - Permission denied. 340 * @throws { BusinessError } 401 - Parameter error. 341 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 342 * @throws { BusinessError } 2100003 - System internal error. 343 * @syscap SystemCapability.Communication.NetManager.Core 344 * @since 8 345 */ 346 /** 347 * Checks whether the default data network is activated. 348 * @permission ohos.permission.GET_NETWORK_INFO 349 * @param { AsyncCallback<boolean> } callback Returns {@code true} if the default data network is activated; 350 * returns {@code false} otherwise. 351 * @throws { BusinessError } 201 - Permission denied. 352 * @throws { BusinessError } 401 - Parameter error. 353 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 354 * @throws { BusinessError } 2100003 - System internal error. 355 * @syscap SystemCapability.Communication.NetManager.Core 356 * @crossplatform 357 * @since 10 358 */ 359 function hasDefaultNet(callback: AsyncCallback<boolean>): void; 360 361 /** 362 * Checks whether the default data network is activated. 363 * @permission ohos.permission.GET_NETWORK_INFO 364 * @returns { Promise<boolean> } The promise returned by the function. 365 * @throws { BusinessError } 201 - Permission denied. 366 * @throws { BusinessError } 401 - Parameter error. 367 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 368 * @throws { BusinessError } 2100003 - System internal error. 369 * @syscap SystemCapability.Communication.NetManager.Core 370 * @since 8 371 */ 372 /** 373 * Checks whether the default data network is activated. 374 * @permission ohos.permission.GET_NETWORK_INFO 375 * @returns { Promise<boolean> } The promise returned by the function. 376 * @throws { BusinessError } 201 - Permission denied. 377 * @throws { BusinessError } 401 - Parameter error. 378 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 379 * @throws { BusinessError } 2100003 - System internal error. 380 * @syscap SystemCapability.Communication.NetManager.Core 381 * @crossplatform 382 * @since 10 383 */ 384 function hasDefaultNet(): Promise<boolean>; 385 386 /** 387 * Enables the airplane mode for a device. 388 * To invoke this method, you must have the {@code ohos.permission.CONNECTIVITY_INTERNAL} permission. 389 * @permission ohos.permission.CONNECTIVITY_INTERNAL 390 * @param { AsyncCallback<void> } callback - the callback of enableAirplaneMode. 391 * @throws { BusinessError } 201 - Permission denied. 392 * @throws { BusinessError } 202 - Non-system applications use system APIs. 393 * @throws { BusinessError } 401 - Parameter error. 394 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 395 * @throws { BusinessError } 2100003 - System internal error. 396 * @syscap SystemCapability.Communication.NetManager.Core 397 * @systemapi Hide this for inner system use. Only used for system app. 398 * @since 8 399 */ 400 function enableAirplaneMode(callback: AsyncCallback<void>): void; 401 402 /** 403 * Enables the airplane mode for a device. 404 * To invoke this method, you must have the {@code ohos.permission.CONNECTIVITY_INTERNAL} permission. 405 * @permission ohos.permission.CONNECTIVITY_INTERNAL 406 * @returns { Promise<void> } The promise returned by the function. 407 * @throws { BusinessError } 201 - Permission denied. 408 * @throws { BusinessError } 202 - Non-system applications use system APIs. 409 * @throws { BusinessError } 401 - Parameter error. 410 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 411 * @throws { BusinessError } 2100003 - System internal error. 412 * @syscap SystemCapability.Communication.NetManager.Core 413 * @systemapi Hide this for inner system use. Only used for system app. 414 * @since 8 415 */ 416 function enableAirplaneMode(): Promise<void>; 417 418 /** 419 * Disables the airplane mode for a device. 420 * To invoke this method, you must have the {@code ohos.permission.CONNECTIVITY_INTERNAL} permission. 421 * @permission ohos.permission.CONNECTIVITY_INTERNAL 422 * @param { AsyncCallback<void> } callback - the callback of disableAirplaneMode. 423 * @throws { BusinessError } 201 - Permission denied. 424 * @throws { BusinessError } 202 - Non-system applications use system APIs. 425 * @throws { BusinessError } 401 - Parameter error. 426 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 427 * @throws { BusinessError } 2100003 - System internal error. 428 * @syscap SystemCapability.Communication.NetManager.Core 429 * @systemapi Hide this for inner system use. Only used for system app. 430 * @since 8 431 */ 432 function disableAirplaneMode(callback: AsyncCallback<void>): void; 433 434 /** 435 * Disables the airplane mode for a device. 436 * To invoke this method, you must have the {@code ohos.permission.CONNECTIVITY_INTERNAL} permission. 437 * @permission ohos.permission.CONNECTIVITY_INTERNAL 438 * @returns { Promise<void> } The promise returned by the function. 439 * @throws { BusinessError } 201 - Permission denied. 440 * @throws { BusinessError } 202 - Non-system applications use system APIs. 441 * @throws { BusinessError } 401 - Parameter error. 442 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 443 * @throws { BusinessError } 2100003 - System internal error. 444 * @syscap SystemCapability.Communication.NetManager.Core 445 * @systemapi Hide this for inner system use. Only used for system app. 446 * @since 8 447 */ 448 function disableAirplaneMode(): Promise<void>; 449 450 /** 451 * Reports the network state is connected. 452 * @permission ohos.permission.GET_NETWORK_INFO and ohos.permission.INTERNET 453 * @param { NetHandle } netHandle Indicates the network whose state is to be reported. 454 * @param { AsyncCallback<void> } callback - the callback of reportNetConnected. 455 * @throws { BusinessError } 201 - Permission denied. 456 * @throws { BusinessError } 401 - Parameter error. 457 * @throws { BusinessError } 2100001 - Invalid parameter value. 458 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 459 * @throws { BusinessError } 2100003 - System internal error. 460 * @syscap SystemCapability.Communication.NetManager.Core 461 * @since 8 462 */ 463 function reportNetConnected(netHandle: NetHandle, callback: AsyncCallback<void>): void; 464 465 /** 466 * Reports the network state is connected. 467 * @permission ohos.permission.GET_NETWORK_INFO and ohos.permission.INTERNET 468 * @param { NetHandle } netHandle Indicates the network whose state is to be reported. 469 * @returns { Promise<void> } The promise returned by the function. 470 * @throws { BusinessError } 201 - Permission denied. 471 * @throws { BusinessError } 401 - Parameter error. 472 * @throws { BusinessError } 2100001 - Invalid parameter value. 473 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 474 * @throws { BusinessError } 2100003 - System internal error. 475 * @syscap SystemCapability.Communication.NetManager.Core 476 * @since 8 477 */ 478 function reportNetConnected(netHandle: NetHandle): Promise<void>; 479 480 /** 481 * Reports the network state is disconnected. 482 * @permission ohos.permission.GET_NETWORK_INFO and ohos.permission.INTERNET 483 * @param { NetHandle } netHandle Indicates the network whose state is to be reported. 484 * @param { AsyncCallback<void> } callback - the callback of reportNetDisconnected. 485 * @throws { BusinessError } 201 - Permission denied. 486 * @throws { BusinessError } 401 - Parameter error. 487 * @throws { BusinessError } 2100001 - Invalid parameter value. 488 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 489 * @throws { BusinessError } 2100003 - System internal error. 490 * @syscap SystemCapability.Communication.NetManager.Core 491 * @since 8 492 */ 493 function reportNetDisconnected(netHandle: NetHandle, callback: AsyncCallback<void>): void; 494 495 /** 496 * Reports the network state is disconnected. 497 * @permission ohos.permission.GET_NETWORK_INFO and ohos.permission.INTERNET 498 * @param { NetHandle } netHandle Indicates the network whose state is to be reported. 499 * @returns { Promise<void> } The promise returned by the function. 500 * @throws { BusinessError } 201 - Permission denied. 501 * @throws { BusinessError } 401 - Parameter error. 502 * @throws { BusinessError } 2100001 - Invalid parameter value. 503 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 504 * @throws { BusinessError } 2100003 - System internal error. 505 * @syscap SystemCapability.Communication.NetManager.Core 506 * @since 8 507 */ 508 function reportNetDisconnected(netHandle: NetHandle): Promise<void>; 509 510 /** 511 * Resolves the host name to obtain all IP addresses based on the default data network. 512 * @permission ohos.permission.INTERNET 513 * @param { string } host Indicates the host name or the domain. 514 * @param { AsyncCallback<Array<NetAddress>> } callback Returns the NetAddress list. 515 * @throws { BusinessError } 201 - Permission denied. 516 * @throws { BusinessError } 401 - Parameter error. 517 * @throws { BusinessError } 2100001 - Invalid parameter value. 518 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 519 * @throws { BusinessError } 2100003 - System internal error. 520 * @syscap SystemCapability.Communication.NetManager.Core 521 * @since 8 522 */ 523 function getAddressesByName(host: string, callback: AsyncCallback<Array<NetAddress>>): void; 524 525 /** 526 * Resolves the host name to obtain all IP addresses based on the default data network. 527 * @permission ohos.permission.INTERNET 528 * @param { string } host Indicates the host name or the domain. 529 * @returns { Promise<Array<NetAddress>> } The promise returned by the function. 530 * @throws { BusinessError } 201 - Permission denied. 531 * @throws { BusinessError } 401 - Parameter error. 532 * @throws { BusinessError } 2100001 - Invalid parameter value. 533 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 534 * @throws { BusinessError } 2100003 - System internal error. 535 * @syscap SystemCapability.Communication.NetManager.Core 536 * @since 8 537 */ 538 function getAddressesByName(host: string): Promise<Array<NetAddress>>; 539 540 /** 541 * Obtains the {@link NetHandle} bound to a process using {@link setAppNet}. 542 * @param { AsyncCallback<NetHandle> } callback Returns the {@link NetHandle} bound to the process; 543 * returns {@code null} if no {@link NetHandle} is bound to the process.For details, see {@link NetHandle}. 544 * @throws { BusinessError } 401 - Parameter error. 545 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 546 * @throws { BusinessError } 2100003 - System internal error. 547 * @syscap SystemCapability.Communication.NetManager.Core 548 * @since 9 549 */ 550 function getAppNet(callback: AsyncCallback<NetHandle>): void; 551 552 /** 553 * Obtains the {@link NetHandle} bound to a process using {@link setAppNet}. 554 * @returns { Promise<NetHandle> } the promise returned by the function. 555 * @throws { BusinessError } 401 - Parameter error. 556 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 557 * @throws { BusinessError } 2100003 - System internal error. 558 * @syscap SystemCapability.Communication.NetManager.Core 559 * @since 9 560 */ 561 function getAppNet(): Promise<NetHandle>; 562 563 /** 564 * Binds a process to {@code NetHandle}. 565 * <p>All the sockets created from the process will be bound to the {@code NetHandle}, 566 * and the resolution of all host names will be managed by the {@code NetHandle}.</p> 567 * @permission ohos.permission.INTERNET 568 * @param { NetHandle } netHandle Indicates the handle. For details, see {@link NetHandle}. 569 * @param { AsyncCallback<void> } callback Returns the callback of setAppNet. 570 * @throws { BusinessError } 201 - Permission denied. 571 * @throws { BusinessError } 401 - Parameter error. 572 * @throws { BusinessError } 2100001 - Invalid parameter value. 573 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 574 * @throws { BusinessError } 2100003 - System internal error. 575 * @syscap SystemCapability.Communication.NetManager.Core 576 * @since 9 577 */ 578 function setAppNet(netHandle: NetHandle, callback: AsyncCallback<void>): void; 579 580 /** 581 * Binds a process to {@code NetHandle}. 582 * <p>All the sockets created from the process will be bound to the {@code NetHandle}, 583 * and the resolution of all host names will be managed by the {@code NetHandle}.</p> 584 * @permission ohos.permission.INTERNET 585 * @param { NetHandle } netHandle Indicates the handle. For details, see {@link NetHandle}. 586 * @returns { Promise<void> } the promise returned by the function. 587 * @throws { BusinessError } 201 - Permission denied. 588 * @throws { BusinessError } 401 - Parameter error. 589 * @throws { BusinessError } 2100001 - Invalid parameter value. 590 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 591 * @throws { BusinessError } 2100003 - System internal error. 592 * @syscap SystemCapability.Communication.NetManager.Core 593 * @since 9 594 */ 595 function setAppNet(netHandle: NetHandle): Promise<void>; 596 597 /** 598 * Set a specific interface up. 599 * To invoke this method, you must have the {@code ohos.permission.CONNECTIVITY_INTERNAL} permission. 600 * @permission ohos.permission.CONNECTIVITY_INTERNAL 601 * @param { string } ifaceName - the name of the interface to set up. 602 * @param { AsyncCallback<void> } callback - the callback of setInterfaceUp. 603 * @throws { BusinessError } 201 - Permission denied. 604 * @throws { BusinessError } 202 - Non-system applications use system APIs. 605 * @throws { BusinessError } 401 - Parameter error. 606 * @throws { BusinessError } 2100003 - System internal error. 607 * @syscap SystemCapability.Communication.NetManager.Core 608 * @systemapi Hide this for inner system use. Only used for system app. 609 * @since 16 610 */ 611 function setInterfaceUp(ifaceName: string, callback: AsyncCallback<void>): void; 612 613 /** 614 * Set a specific interface up. 615 * @param { string } ifaceName - the name of the interface to set up. 616 * @throws { BusinessError } 201 - Permission denied. 617 * @throws { BusinessError } 202 - Non-system applications use system APIs. 618 * @throws { BusinessError } 401 - Parameter error. 619 * @throws { BusinessError } 2100003 - System internal error. 620 * @syscap SystemCapability.Communication.NetManager.Core 621 * @systemapi Hide this for inner system use. Only used for system app. 622 * @since 16 623 */ 624 function setInterfaceUp(ifaceName: string): Promise<void>; 625 626 /** 627 * Set ip address for a specific interface. 628 * To invoke this method, you must have the {@code ohos.permission.CONNECTIVITY_INTERNAL} permission. 629 * @permission ohos.permission.CONNECTIVITY_INTERNAL 630 * @param { string } ifaceName - the name of the interface. 631 * @param { string } ip - the ip address to set for the interface. 632 * @param { AsyncCallback<void> } callback - the callback of setNetInterfaceIpAddress. 633 * @throws { BusinessError } 201 - Permission denied. 634 * @throws { BusinessError } 202 - Non-system applications use system APIs. 635 * @throws { BusinessError } 401 - Parameter error. 636 * @throws { BusinessError } 2100003 - System internal error. 637 * @syscap SystemCapability.Communication.NetManager.Core 638 * @systemapi Hide this for inner system use. Only used for system app. 639 * @since 16 640 */ 641 function setNetInterfaceIpAddress(ifaceName: string, ip: string, callback: AsyncCallback<void>): void; 642 643 /** 644 * Set ip address for a specific interface. 645 * @param { string } ifaceName - the name of the interface. 646 * @param { string } ip - the ip address to set for the interface. 647 * @throws { BusinessError } 201 - Permission denied. 648 * @throws { BusinessError } 202 - Non-system applications use system APIs. 649 * @throws { BusinessError } 401 - Parameter error. 650 * @throws { BusinessError } 2100003 - System internal error. 651 * @syscap SystemCapability.Communication.NetManager.Core 652 * @systemapi Hide this for inner system use. Only used for system app. 653 * @since 16 654 */ 655 function setNetInterfaceIpAddress(ifaceName: string, ip: string): Promise<void>; 656 657 /** 658 * Obtains the network independent global {@link HttpProxy} proxy settings. 659 * 660 * If a application level proxy is set, the application level proxy parameters are returned. 661 * If a global proxy is set, the global proxy parameters are returned. 662 * If the process is bound to a {@link NetHandle} using {@link setAppNet}, the {@link NetHandle} proxy settings are returned. 663 * In other cases, the proxy settings of default network are returned. 664 * 665 * @param { AsyncCallback<HttpProxy> } callback Returns the proxy settings. For details, see {@link HttpProxy}. 666 * @throws { BusinessError } 401 - Parameter error. 667 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 668 * @throws { BusinessError } 2100003 - System internal error. 669 * @syscap SystemCapability.Communication.NetManager.Core 670 * @systemapi Hide this for inner system use. 671 * @since 10 672 */ 673 function getGlobalHttpProxy(callback: AsyncCallback<HttpProxy>): void; 674 675 /** 676 * Obtains the network independent global {@link HttpProxy} proxy settings. 677 * 678 * If a application level proxy is set, the application level proxy parameters are returned. 679 * If a global proxy is set, the global proxy parameters are returned. 680 * If the process is bound to a {@link NetHandle} using {@link setAppNet}, the {@link NetHandle} proxy settings are returned. 681 * In other cases, the proxy settings of default network are returned. 682 * 683 * @returns { Promise<HttpProxy> } the promise returned by the function. 684 * @throws { BusinessError } 401 - Parameter error. 685 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 686 * @throws { BusinessError } 2100003 - System internal error. 687 * @syscap SystemCapability.Communication.NetManager.Core 688 * @systemapi Hide this for inner system use. 689 * @since 10 690 */ 691 function getGlobalHttpProxy(): Promise<HttpProxy>; 692 693 /** 694 * Set application level http proxy {@link HttpProxy}. 695 * @param { HttpProxy } httpProxy - Indicates the application level proxy settings. For details, see {@link HttpProxy}. 696 * @throws { BusinessError } 401 - Parameter error. 697 * @throws { BusinessError } 2100001 - Invalid http proxy. 698 * @syscap SystemCapability.Communication.NetManager.Core 699 * @since 11 700 */ 701 702 function setAppHttpProxy(httpProxy: HttpProxy): void; 703 704 /** 705 * Set a network independent global {@link HttpProxy} proxy settings. 706 * @permission ohos.permission.CONNECTIVITY_INTERNAL 707 * @param { HttpProxy } httpProxy Indicates the global proxy settings. For details, see {@link HttpProxy}. 708 * @param { AsyncCallback<void> } callback Returns the callback of setGlobalHttpProxy. 709 * @throws { BusinessError } 201 - Permission denied. 710 * @throws { BusinessError } 401 - Parameter error. 711 * @throws { BusinessError } 2100001 - Invalid parameter value. 712 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 713 * @throws { BusinessError } 2100003 - System internal error. 714 * @syscap SystemCapability.Communication.NetManager.Core 715 * @systemapi Hide this for inner system use. 716 * @since 10 717 */ 718 function setGlobalHttpProxy(httpProxy: HttpProxy, callback: AsyncCallback<void>): void; 719 720 /** 721 * Set a network independent global {@link HttpProxy} proxy settings. 722 * @permission ohos.permission.CONNECTIVITY_INTERNAL 723 * @param { HttpProxy } httpProxy Indicates the global proxy settings. For details, see {@link HttpProxy}. 724 * @returns { Promise<void> } the promise returned by the function. 725 * @throws { BusinessError } 201 - Permission denied. 726 * @throws { BusinessError } 401 - Parameter error. 727 * @throws { BusinessError } 2100001 - Invalid parameter value. 728 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 729 * @throws { BusinessError } 2100003 - System internal error. 730 * @syscap SystemCapability.Communication.NetManager.Core 731 * @systemapi Hide this for inner system use. 732 * @since 10 733 */ 734 function setGlobalHttpProxy(httpProxy: HttpProxy): Promise<void>; 735 736 /** 737 * Obtains the default {@link HttpProxy} proxy settings. 738 * 739 * If a global proxy is set, the global proxy parameters are returned. 740 * If the process is bound to a {@link NetHandle} using {@link setAppNet}, 741 * the {@link NetHandle} proxy settings are returned. 742 * In other cases, the proxy settings of default network are returned. 743 * 744 * @param { AsyncCallback<HttpProxy> } callback Returns the default {@link HttpProxy} settings. 745 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 746 * @throws { BusinessError } 2100003 - System internal error. 747 * @syscap SystemCapability.Communication.NetManager.Core 748 * @since 10 749 */ 750 function getDefaultHttpProxy(callback: AsyncCallback<HttpProxy>): void; 751 752 /** 753 * Obtains the default {@link HttpProxy} proxy settings. 754 * 755 * If a global proxy is set, the global proxy parameters are returned. 756 * If the process is bound to a {@link NetHandle} using {@link setAppNet}, 757 * the {@link NetHandle} proxy settings are returned. 758 * In other cases, the proxy settings of default network are returned. 759 * 760 * @returns { Promise<HttpProxy> } the promise returned by the function. 761 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 762 * @throws { BusinessError } 2100003 - System internal error. 763 * @syscap SystemCapability.Communication.NetManager.Core 764 * @since 10 765 */ 766 function getDefaultHttpProxy(): Promise<HttpProxy>; 767 768 /** 769 * Add a custom {@link host} and corresponding {@link ip} mapping. 770 * @permission ohos.permission.INTERNET 771 * @param { string } host - Indicates the host name or the domain. 772 * @param { Array<string> } ip - List of IP addresses mapped to the host name. 773 * @param { AsyncCallback<void> } callback - Returns the callback of addCustomDnsRule. 774 * @throws { BusinessError } 201 - Permission denied. 775 * @throws { BusinessError } 401 - Parameter error. 776 * @throws { BusinessError } 2100001 - Invalid parameter value. 777 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 778 * @throws { BusinessError } 2100003 - System internal error. 779 * @syscap SystemCapability.Communication.NetManager.Core 780 * @since 11 781 */ 782 function addCustomDnsRule(host: string, ip: Array<string>, callback: AsyncCallback<void>): void; 783 784 /** 785 * Add a custom {@link host} and corresponding {@link ip} mapping. 786 * @permission ohos.permission.INTERNET 787 * @param { string } host - Indicates the host name or the domain. 788 * @param { Array<string> } ip - List of IP addresses mapped to the host name. 789 * @returns { Promise<void> } the promise returned by the function. 790 * @throws { BusinessError } 201 - Permission denied. 791 * @throws { BusinessError } 401 - Parameter error. 792 * @throws { BusinessError } 2100001 - Invalid parameter value. 793 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 794 * @throws { BusinessError } 2100003 - System internal error. 795 * @syscap SystemCapability.Communication.NetManager.Core 796 * @since 11 797 */ 798 function addCustomDnsRule(host: string, ip: Array<string>): Promise<void>; 799 800 /** 801 * Remove the custom DNS rule of the {@link host}. 802 * @permission ohos.permission.INTERNET 803 * @param { string } host - Indicates the host name or the domain. 804 * @param { AsyncCallback<void> } callback - Returns the callback of removeCustomDnsRule. 805 * @throws { BusinessError } 201 - Permission denied. 806 * @throws { BusinessError } 401 - Parameter error. 807 * @throws { BusinessError } 2100001 - Invalid parameter value. 808 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 809 * @throws { BusinessError } 2100003 - System internal error. 810 * @syscap SystemCapability.Communication.NetManager.Core 811 * @since 11 812 */ 813 function removeCustomDnsRule(host: string, callback: AsyncCallback<void>): void; 814 815 /** 816 * Remove the custom DNS rule of the {@link host}. 817 * @permission ohos.permission.INTERNET 818 * @param { string } host - Indicates the host name or the domain. 819 * @returns { Promise<void> } the promise returned by the function. 820 * @throws { BusinessError } 201 - Permission denied. 821 * @throws { BusinessError } 401 - Parameter error. 822 * @throws { BusinessError } 2100001 - Invalid parameter value. 823 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 824 * @throws { BusinessError } 2100003 - System internal error. 825 * @syscap SystemCapability.Communication.NetManager.Core 826 * @since 11 827 */ 828 function removeCustomDnsRule(host: string): Promise<void>; 829 830 /** 831 * Clear all custom DNS rules. 832 * @permission ohos.permission.INTERNET 833 * @param { AsyncCallback<void> } callback - Returns the callback of clearCustomDnsRules. 834 * @throws { BusinessError } 201 - Permission denied. 835 * @throws { BusinessError } 401 - Parameter error. 836 * @throws { BusinessError } 2100001 - Invalid parameter value. 837 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 838 * @throws { BusinessError } 2100003 - System internal error. 839 * @syscap SystemCapability.Communication.NetManager.Core 840 * @since 11 841 */ 842 function clearCustomDnsRules(callback: AsyncCallback<void>): void; 843 844 /** 845 * Clear all custom DNS rules. 846 * @permission ohos.permission.INTERNET 847 * @returns { Promise<void> } the promise returned by the function. 848 * @throws { BusinessError } 201 - Permission denied. 849 * @throws { BusinessError } 401 - Parameter error. 850 * @throws { BusinessError } 2100001 - Invalid parameter value. 851 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 852 * @throws { BusinessError } 2100003 - System internal error. 853 * @syscap SystemCapability.Communication.NetManager.Core 854 * @since 11 855 */ 856 function clearCustomDnsRules(): Promise<void>; 857 858 /** 859 * factory reset network settings 860 * 861 * To invoke this method, you must have the {@code ohos.permission.CONNECTIVITY_INTERNAL} permission. 862 * @permission ohos.permission.CONNECTIVITY_INTERNAL 863 * @returns { Promise<void> } the promise returned by the function. 864 * @throws { BusinessError } 201 - Permission denied. 865 * @throws { BusinessError } 202 - Non-system applications use system APIs. 866 * @throws { BusinessError } 401 - Parameter error. 867 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 868 * @throws { BusinessError } 2100003 - System internal error. 869 * @syscap SystemCapability.Communication.NetManager.Core 870 * @systemapi Hide this for inner system use. Only used for system app. 871 * @since 11 872 */ 873 function factoryReset(): Promise<void>; 874 875 /** 876 * Represents the network connection handle. 877 * @interface NetConnection 878 * @syscap SystemCapability.Communication.NetManager.Core 879 * @since 8 880 */ 881 /** 882 * Represents the network connection handle. 883 * @interface NetConnection 884 * @syscap SystemCapability.Communication.NetManager.Core 885 * @crossplatform 886 * @since 10 887 */ 888 export interface NetConnection { 889 /** 890 * Registers a listener for netAvailable events. 891 * @param { 'netAvailable' } type Indicates Event name. 892 * @param { Callback<NetHandle> } callback - the callback of on. 893 * @syscap SystemCapability.Communication.NetManager.Core 894 * @since 8 895 */ 896 /** 897 * Registers a listener for netAvailable events. 898 * @param { 'netAvailable' } type Indicates Event name. 899 * @param { Callback<NetHandle> } callback - the callback of on. 900 * @syscap SystemCapability.Communication.NetManager.Core 901 * @crossplatform 902 * @since 10 903 */ 904 on(type: 'netAvailable', callback: Callback<NetHandle>): void; 905 906 /** 907 * Registers a listener for netBlockStatusChange events. 908 * @param { 'netBlockStatusChange' } type Indicates Event name. 909 * @param { Callback<{ netHandle: NetHandle, blocked: boolean }> } callback - the callback of on. 910 * @syscap SystemCapability.Communication.NetManager.Core 911 * @since 8 912 */ 913 on(type: 'netBlockStatusChange', callback: Callback<{ netHandle: NetHandle, blocked: boolean }>): void; 914 915 /** 916 * Registers a listener for **netCapabilitiesChange** events. 917 * @param { 'netCapabilitiesChange' } type Indicates Event name. 918 * @param { Callback<{ netHandle: NetHandle, netCap: NetCapabilities }> } callback - the callback of on. 919 * @syscap SystemCapability.Communication.NetManager.Core 920 * @since 8 921 */ 922 /** 923 * Registers a listener for **netCapabilitiesChange** events. 924 * @param { 'netCapabilitiesChange' } type Indicates Event name. 925 * @param { Callback<{ netHandle: NetHandle, netCap: NetCapabilities }> } callback - the callback of on. 926 * @syscap SystemCapability.Communication.NetManager.Core 927 * @crossplatform 928 * @since 10 929 */ 930 on(type: 'netCapabilitiesChange', callback: Callback<{ netHandle: NetHandle, netCap: NetCapabilities }>): void; 931 932 /** 933 * Registers a listener for netConnectionPropertiesChange events. 934 * @param { 'netConnectionPropertiesChange' } type Indicates Event name. 935 * @param { Callback<{ netHandle: NetHandle, connectionProperties: ConnectionProperties }> } callback - the callback of on. 936 * @syscap SystemCapability.Communication.NetManager.Core 937 * @since 8 938 */ 939 on(type: 'netConnectionPropertiesChange', callback: Callback<{ netHandle: NetHandle, connectionProperties: ConnectionProperties }>): void; 940 941 /** 942 * Registers a listener for **netLost** events. 943 * @param { 'netLost' } type Indicates Event name. 944 * @param { Callback<NetHandle> } callback - the callback of on. 945 * @syscap SystemCapability.Communication.NetManager.Core 946 * @since 8 947 */ 948 /** 949 * Registers a listener for **netLost** events. 950 * @param { 'netLost' } type Indicates Event name. 951 * @param { Callback<NetHandle> } callback - the callback of on. 952 * @syscap SystemCapability.Communication.NetManager.Core 953 * @crossplatform 954 * @since 10 955 */ 956 on(type: 'netLost', callback: Callback<NetHandle>): void; 957 958 /** 959 * Registers a listener for netUnavailable events. 960 * @param { 'netUnavailable' } type Indicates Event name. 961 * @param { Callback<void> } callback - the callback of on. 962 * @syscap SystemCapability.Communication.NetManager.Core 963 * @since 8 964 */ 965 /** 966 * Registers a listener for netUnavailable events. 967 * @param { 'netUnavailable' } type Indicates Event name. 968 * @param { Callback<void> } callback - the callback of on. 969 * @syscap SystemCapability.Communication.NetManager.Core 970 * @crossplatform 971 * @since 10 972 */ 973 on(type: 'netUnavailable', callback: Callback<void>): void; 974 975 /** 976 * Receives status change notifications of a specified network. 977 * @permission ohos.permission.GET_NETWORK_INFO 978 * @param { AsyncCallback<void> } callback - the callback of register. 979 * @throws { BusinessError } 201 - Permission denied. 980 * @throws { BusinessError } 401 - Parameter error. 981 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 982 * @throws { BusinessError } 2100003 - System internal error. 983 * @throws { BusinessError } 2101008 - The same callback exists. 984 * @throws { BusinessError } 2101022 - The number of requests exceeded the maximum. 985 * @syscap SystemCapability.Communication.NetManager.Core 986 * @since 8 987 */ 988 /** 989 * Receives status change notifications of a specified network. 990 * @permission ohos.permission.GET_NETWORK_INFO 991 * @param { AsyncCallback<void> } callback - the callback of register. 992 * @throws { BusinessError } 201 - Permission denied. 993 * @throws { BusinessError } 401 - Parameter error. 994 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 995 * @throws { BusinessError } 2100003 - System internal error. 996 * @throws { BusinessError } 2101008 - The same callback exists. 997 * @throws { BusinessError } 2101022 - The number of requests exceeded the maximum. 998 * @syscap SystemCapability.Communication.NetManager.Core 999 * @crossplatform 1000 * @since 10 1001 */ 1002 register(callback: AsyncCallback<void>): void; 1003 1004 /** 1005 * Cancels listening for network status changes. 1006 * @param { AsyncCallback<void> } callback - the callback of unregister. 1007 * @throws { BusinessError } 201 - Permission denied. 1008 * @throws { BusinessError } 401 - Parameter error. 1009 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 1010 * @throws { BusinessError } 2100003 - System internal error. 1011 * @throws { BusinessError } 2101007 - The callback is not exists. 1012 * @syscap SystemCapability.Communication.NetManager.Core 1013 * @since 8 1014 */ 1015 /** 1016 * Cancels listening for network status changes. 1017 * @param { AsyncCallback<void> } callback - the callback of unregister. 1018 * @throws { BusinessError } 201 - Permission denied. 1019 * @throws { BusinessError } 401 - Parameter error. 1020 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 1021 * @throws { BusinessError } 2100003 - System internal error. 1022 * @throws { BusinessError } 2101007 - The callback is not exists. 1023 * @syscap SystemCapability.Communication.NetManager.Core 1024 * @crossplatform 1025 * @since 10 1026 */ 1027 unregister(callback: AsyncCallback<void>): void; 1028 } 1029 1030 /** 1031 * Represents the network interface. 1032 * @interface NetInterface 1033 * @syscap SystemCapability.Communication.NetManager.Core 1034 * @systemapi Hide this for inner system use. Only used for system app. 1035 * @since 16 1036 */ 1037 export interface NetInterface { 1038 /** 1039 * Registers a listener for interfaceAddressUpdated events. 1040 * @param { 'interfaceAddressUpdated' } type Indicates Event name. 1041 * @param { Callback<InterfaceInfo> } callback - the callback of on. 1042 * @syscap SystemCapability.Communication.NetManager.Core 1043 * @systemapi Hide this for inner system use. Only used for system app. 1044 * @since 16 1045 */ 1046 on(type: 'interfaceAddressUpdated', callback: Callback<InterfaceInfo>): void; 1047 /** 1048 * Registers a listener for interfaceAddressRemoved events. 1049 * @param { 'interfaceAddressRemoved' } type Indicates Event name. 1050 * @param { Callback<InterfaceInfo> } callback - the callback of on. 1051 * @syscap SystemCapability.Communication.NetManager.Core 1052 * @systemapi Hide this for inner system use. Only used for system app. 1053 * @since 16 1054 */ 1055 on(type: 'interfaceAddressRemoved', callback: Callback<InterfaceInfo>): void; 1056 /** 1057 * Registers a listener for interfaceAdded events. 1058 * @param { 'interfaceAdded' } type Indicates Event name. 1059 * @param { Callback<InterfaceInfo> } callback - the callback of on. 1060 * @syscap SystemCapability.Communication.NetManager.Core 1061 * @systemapi Hide this for inner system use. Only used for system app. 1062 * @since 16 1063 */ 1064 on(type: 'interfaceAdded', callback: Callback<InterfaceInfo>): void; 1065 /** 1066 * Registers a listener for interfaceRemoved events. 1067 * @param { 'interfaceRemoved' } type Indicates Event name. 1068 * @param { Callback<InterfaceInfo> } callback - the callback of on. 1069 * @syscap SystemCapability.Communication.NetManager.Core 1070 * @systemapi Hide this for inner system use. Only used for system app. 1071 * @since 16 1072 */ 1073 on(type: 'interfaceRemoved', callback: Callback<InterfaceInfo>): void; 1074 /** 1075 * Registers a listener for interfaceChanged events. 1076 * @param { 'interfaceChanged' } type Indicates Event name. 1077 * @param { Callback<InterfaceInfo> } callback - the callback of on. 1078 * @syscap SystemCapability.Communication.NetManager.Core 1079 * @systemapi Hide this for inner system use. Only used for system app. 1080 * @since 16 1081 */ 1082 on(type: 'interfaceChanged', callback: Callback<InterfaceInfo>): void; 1083 /** 1084 * Registers a listener for interfaceLinkStateChanged events. 1085 * @param { 'interfaceLinkStateChanged' } type Indicates Event name. 1086 * @param { Callback<InterfaceInfo> } callback - the callback of on. 1087 * @syscap SystemCapability.Communication.NetManager.Core 1088 * @systemapi Hide this for inner system use. Only used for system app. 1089 * @since 16 1090 */ 1091 on(type: 'interfaceLinkStateChanged', callback: Callback<InterfaceInfo>): void; 1092 /** 1093 * Registers a listener for routeChanged events. 1094 * @param { 'routeChanged' } type Indicates Event name. 1095 * @param { Callback<RouteChangeInfo> } callback - the callback of on. 1096 * @syscap SystemCapability.Communication.NetManager.Core 1097 * @systemapi Hide this for inner system use. Only used for system app. 1098 * @since 16 1099 */ 1100 on(type: 'routeChanged', callback: Callback<RouteChangeInfo>): void; 1101 1102 /** 1103 * Receives status change notifications of a specified interface. 1104 * @permission ohos.permission.CONNECTIVITY_INTERNAL 1105 * @param { AsyncCallback<void> } callback - the callback of register. 1106 * @throws { BusinessError } 201 - Permission denied. 1107 * @throws { BusinessError } 401 - Parameter error. 1108 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 1109 * @throws { BusinessError } 2100003 - System internal error. 1110 * @throws { BusinessError } 2101008 - The same callback exists. 1111 * @throws { BusinessError } 2101022 - The number of requests exceeded the maximum. 1112 * @syscap SystemCapability.Communication.NetManager.Core 1113 * @systemapi Hide this for inner system use. Only used for system app. 1114 * @since 16 1115 */ 1116 register(callback: AsyncCallback<void>): void; 1117 /** 1118 * Cancels listening for interface status changes. 1119 * @param { AsyncCallback<void> } callback - the callback of unregister. 1120 * @throws { BusinessError } 201 - Permission denied. 1121 * @throws { BusinessError } 401 - Parameter error. 1122 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 1123 * @throws { BusinessError } 2100003 - System internal error. 1124 * @throws { BusinessError } 2101007 - The callback is not exists. 1125 * @syscap SystemCapability.Communication.NetManager.Core 1126 * @systemapi Hide this for inner system use. Only used for system app. 1127 * @since 16 1128 */ 1129 unregister(callback: AsyncCallback<void>): void; 1130 } 1131 1132 /** 1133 * Provides an instance that bear data network capabilities. 1134 * @interface NetSpecifier 1135 * @syscap SystemCapability.Communication.NetManager.Core 1136 * @since 8 1137 */ 1138 export interface NetSpecifier { 1139 /** 1140 * The transmission capacity and support of the network's global proxy storage data network. 1141 * @type {NetCapabilities} 1142 * @syscap SystemCapability.Communication.NetManager.Core 1143 * @since 8 1144 */ 1145 netCapabilities: NetCapabilities; 1146 1147 /** 1148 * Network identifier, the identifier for Wi Fi networks is "wifi", and the identifier for cellular networks is "simId1" (corresponding to SIM card 1). 1149 * @type {?string} 1150 * @syscap SystemCapability.Communication.NetManager.Core 1151 * @since 8 1152 */ 1153 bearerPrivateIdentifier?: string; 1154 } 1155 1156 /** 1157 * Defines the handle of the data network. 1158 * @interface NetHandle 1159 * @syscap SystemCapability.Communication.NetManager.Core 1160 * @since 8 1161 */ 1162 /** 1163 * Defines the handle of the data network. 1164 * @interface NetHandle 1165 * @syscap SystemCapability.Communication.NetManager.Core 1166 * @crossplatform 1167 * @since 10 1168 */ 1169 export interface NetHandle { 1170 /** 1171 * 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. 1172 * @type {number} 1173 * @syscap SystemCapability.Communication.NetManager.Core 1174 * @since 8 1175 */ 1176 /** 1177 * 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. 1178 * @type {number} 1179 * @syscap SystemCapability.Communication.NetManager.Core 1180 * @crossplatform 1181 * @since 10 1182 */ 1183 netId: number; 1184 1185 /** 1186 * <p>Binds a TCPSocket or UDPSocket to the current network. All data flows from 1187 * the socket will use this network, without being subject to {@link setAppNet}.</p> 1188 * Before using this method, ensure that the socket is disconnected. 1189 * @param { TCPSocket | UDPSocket } socketParam Indicates the TCPSocket or UDPSocket object. 1190 * @param { AsyncCallback<void> } callback - the callback of bindSocket. 1191 * @throws { BusinessError } 401 - Parameter error. 1192 * @throws { BusinessError } 2100001 - Invalid parameter value. 1193 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 1194 * @throws { BusinessError } 2100003 - System internal error. 1195 * @syscap SystemCapability.Communication.NetManager.Core 1196 * @since 9 1197 */ 1198 bindSocket(socketParam: TCPSocket | UDPSocket, callback: AsyncCallback<void>): void; 1199 1200 /** 1201 * <p>Binds a TCPSocket or UDPSocket to the current network. All data flows from 1202 * the socket will use this network, without being subject to {@link setAppNet}.</p> 1203 * Before using this method, ensure that the socket is disconnected. 1204 * @param { TCPSocket | UDPSocket } socketParam Indicates the TCPSocket or UDPSocket object. 1205 * @returns { Promise<void> } the promise returned by the function. 1206 * @throws { BusinessError } 401 - Parameter error. 1207 * @throws { BusinessError } 2100001 - Invalid parameter value. 1208 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 1209 * @throws { BusinessError } 2100003 - System internal error. 1210 * @syscap SystemCapability.Communication.NetManager.Core 1211 * @since 9 1212 */ 1213 bindSocket(socketParam: TCPSocket | UDPSocket): Promise<void>; 1214 1215 /** 1216 * Resolves a host name to obtain all IP addresses based on the specified NetHandle. 1217 * @permission ohos.permission.INTERNET 1218 * @param { string } host Indicates the host name or the domain. 1219 * @param { AsyncCallback<Array<NetAddress>> } callback Returns the NetAddress list. 1220 * @throws { BusinessError } 201 - Permission denied. 1221 * @throws { BusinessError } 401 - Parameter error. 1222 * @throws { BusinessError } 2100001 - Invalid parameter value. 1223 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 1224 * @throws { BusinessError } 2100003 - System internal error. 1225 * @syscap SystemCapability.Communication.NetManager.Core 1226 * @since 8 1227 */ 1228 getAddressesByName(host: string, callback: AsyncCallback<Array<NetAddress>>): void; 1229 1230 /** 1231 * Resolves a host name to obtain all IP addresses based on the specified NetHandle. 1232 * @permission ohos.permission.INTERNET 1233 * @param { string } host Indicates the host name or the domain. 1234 * @returns { Promise<Array<NetAddress>> } The promise returned by the function. 1235 * @throws { BusinessError } 201 - Permission denied. 1236 * @throws { BusinessError } 401 - Parameter error. 1237 * @throws { BusinessError } 2100001 - Invalid parameter value. 1238 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 1239 * @throws { BusinessError } 2100003 - System internal error. 1240 * @syscap SystemCapability.Communication.NetManager.Core 1241 * @since 8 1242 */ 1243 getAddressesByName(host: string): Promise<Array<NetAddress>>; 1244 1245 /** 1246 * Resolves a host name to obtain the first IP address based on the specified NetHandle. 1247 * @permission ohos.permission.INTERNET 1248 * @param { string } host Indicates the host name or the domain. 1249 * @param { AsyncCallback<NetAddress> } callback Returns the first NetAddress. 1250 * @throws { BusinessError } 201 - Permission denied. 1251 * @throws { BusinessError } 401 - Parameter error. 1252 * @throws { BusinessError } 2100001 - Invalid parameter value. 1253 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 1254 * @throws { BusinessError } 2100003 - System internal error. 1255 * @syscap SystemCapability.Communication.NetManager.Core 1256 * @since 8 1257 */ 1258 getAddressByName(host: string, callback: AsyncCallback<NetAddress>): void; 1259 1260 /** 1261 * Resolves a host name to obtain the first IP address based on the specified NetHandle. 1262 * @permission ohos.permission.INTERNET 1263 * @param { string } host Indicates the host name or the domain. 1264 * @returns { Promise<NetAddress> } The promise returned by the function. 1265 * @throws { BusinessError } 201 - Permission denied. 1266 * @throws { BusinessError } 401 - Parameter error. 1267 * @throws { BusinessError } 2100001 - Invalid parameter value. 1268 * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. 1269 * @throws { BusinessError } 2100003 - System internal error. 1270 * @syscap SystemCapability.Communication.NetManager.Core 1271 * @since 8 1272 */ 1273 getAddressByName(host: string): Promise<NetAddress>; 1274 } 1275 1276 /** 1277 * Defines the network capability set. 1278 * @interface NetCapabilities 1279 * @syscap SystemCapability.Communication.NetManager.Core 1280 * @since 8 1281 */ 1282 /** 1283 * Defines the network capability set. 1284 * @interface NetCapabilities 1285 * @syscap SystemCapability.Communication.NetManager.Core 1286 * @crossplatform 1287 * @since 10 1288 */ 1289 export interface NetCapabilities { 1290 /** 1291 * Uplink (device-to-network) bandwidth. 1292 * @type {?number} 1293 * @syscap SystemCapability.Communication.NetManager.Core 1294 * @since 8 1295 */ 1296 linkUpBandwidthKbps?: number; 1297 1298 /** 1299 * Downstream (network-to-device) bandwidth. 1300 * @type {?number} 1301 * @syscap SystemCapability.Communication.NetManager.Core 1302 * @since 8 1303 */ 1304 linkDownBandwidthKbps?: number; 1305 1306 /** 1307 * Network-specific capabilities. 1308 * @type {?Array<NetCap>} 1309 * @syscap SystemCapability.Communication.NetManager.Core 1310 * @since 8 1311 */ 1312 networkCap?: Array<NetCap>; 1313 1314 /** 1315 * Network type. 1316 * @type {Array<NetBearType>} 1317 * @syscap SystemCapability.Communication.NetManager.Core 1318 * @since 8 1319 */ 1320 /** 1321 * Network type. 1322 * @type {Array<NetBearType>} 1323 * @syscap SystemCapability.Communication.NetManager.Core 1324 * @crossplatform 1325 * @since 10 1326 */ 1327 bearerTypes: Array<NetBearType>; 1328 } 1329 1330 /** 1331 * Defines the network capability. 1332 * @enum {number} 1333 * @syscap SystemCapability.Communication.NetManager.Core 1334 * @since 8 1335 */ 1336 export enum NetCap { 1337 /** 1338 * Indicates that the network can access the carrier's MMSC to send and receive multimedia messages. 1339 * @syscap SystemCapability.Communication.NetManager.Core 1340 * @since 8 1341 */ 1342 NET_CAPABILITY_MMS = 0, 1343 1344 /** 1345 * Indicates that the network traffic is not metered. 1346 * @syscap SystemCapability.Communication.NetManager.Core 1347 * @since 8 1348 */ 1349 NET_CAPABILITY_NOT_METERED = 11, 1350 1351 /** 1352 * Indicates that the network can access the Internet. 1353 * @syscap SystemCapability.Communication.NetManager.Core 1354 * @since 8 1355 */ 1356 NET_CAPABILITY_INTERNET = 12, 1357 1358 /** 1359 * Indicates that the network does not use a VPN. 1360 * @syscap SystemCapability.Communication.NetManager.Core 1361 * @since 8 1362 */ 1363 NET_CAPABILITY_NOT_VPN = 15, 1364 1365 /** 1366 * Indicates that the network is available. 1367 * @syscap SystemCapability.Communication.NetManager.Core 1368 * @since 8 1369 */ 1370 NET_CAPABILITY_VALIDATED = 16, 1371 } 1372 1373 /** 1374 * Enumerates network types. 1375 * @enum {number} 1376 * @syscap SystemCapability.Communication.NetManager.Core 1377 * @since 8 1378 */ 1379 /** 1380 * Enumerates network types. 1381 * @enum {number} 1382 * @syscap SystemCapability.Communication.NetManager.Core 1383 * @crossplatform 1384 * @since 10 1385 */ 1386 export enum NetBearType { 1387 /** 1388 * Indicates that the network is based on a cellular network. 1389 * @syscap SystemCapability.Communication.NetManager.Core 1390 * @since 8 1391 */ 1392 /** 1393 * Indicates that the network is based on a cellular network. 1394 * @syscap SystemCapability.Communication.NetManager.Core 1395 * @crossplatform 1396 * @since 10 1397 */ 1398 BEARER_CELLULAR = 0, 1399 1400 /** 1401 * Indicates that the network is based on a Wi-Fi network. 1402 * @syscap SystemCapability.Communication.NetManager.Core 1403 * @since 8 1404 */ 1405 /** 1406 * Indicates that the network is based on a Wi-Fi network. 1407 * @syscap SystemCapability.Communication.NetManager.Core 1408 * @crossplatform 1409 * @since 10 1410 */ 1411 BEARER_WIFI = 1, 1412 1413 /** 1414 * Indicates that the network is an Ethernet network. 1415 * @syscap SystemCapability.Communication.NetManager.Core 1416 * @since 8 1417 */ 1418 BEARER_ETHERNET = 3, 1419 } 1420 1421 /** 1422 * Defines the network connection properties. 1423 * @interface ConnectionProperties 1424 * @syscap SystemCapability.Communication.NetManager.Core 1425 * @since 8 1426 */ 1427 export interface ConnectionProperties { 1428 /** 1429 * Network card name. 1430 * @type {string} 1431 * @syscap SystemCapability.Communication.NetManager.Core 1432 * @since 8 1433 */ 1434 interfaceName: string; 1435 /** 1436 * Domain. The default value is "". 1437 * @type {string} 1438 * @syscap SystemCapability.Communication.NetManager.Core 1439 * @since 8 1440 */ 1441 domains: string; 1442 /** 1443 * Link information. 1444 * @type {Array<LinkAddress>} 1445 * @syscap SystemCapability.Communication.NetManager.Core 1446 * @since 8 1447 */ 1448 linkAddresses: Array<LinkAddress>; 1449 1450 /** 1451 * Network address, refer to [NetAddress]. 1452 * @type {Array<NetAddress>} 1453 * @syscap SystemCapability.Communication.NetManager.Core 1454 * @since 8 1455 */ 1456 dnses: Array<NetAddress>; 1457 1458 /** 1459 * Routing information. 1460 * @type {Array<RouteInfo>} 1461 * @syscap SystemCapability.Communication.NetManager.Core 1462 * @since 8 1463 */ 1464 routes: Array<RouteInfo>; 1465 1466 /** 1467 * Maximum transmission unit. 1468 * @type {number} 1469 * @syscap SystemCapability.Communication.NetManager.Core 1470 * @since 8 1471 */ 1472 mtu: number; 1473 } 1474 1475 /** 1476 * Defines network route information. 1477 * @interface RouteInfo 1478 * @syscap SystemCapability.Communication.NetManager.Core 1479 * @since 8 1480 */ 1481 export interface RouteInfo { 1482 /** 1483 * Network card name. 1484 * @type {string} 1485 * @syscap SystemCapability.Communication.NetManager.Core 1486 * @since 8 1487 */ 1488 interface: string; 1489 1490 /** 1491 * Destination Address 1492 * @type {LinkAddress} 1493 * @syscap SystemCapability.Communication.NetManager.Core 1494 * @since 8 1495 */ 1496 destination: LinkAddress; 1497 1498 /** 1499 * Gateway address. 1500 * @type {NetAddress} 1501 * @syscap SystemCapability.Communication.NetManager.Core 1502 * @since 8 1503 */ 1504 gateway: NetAddress; 1505 1506 /** 1507 * Whether a gateway is present. 1508 * @type {boolean} 1509 * @syscap SystemCapability.Communication.NetManager.Core 1510 * @since 8 1511 */ 1512 hasGateway: boolean; 1513 1514 /** 1515 * Whether the route is the default route. 1516 * @type {boolean} 1517 * @syscap SystemCapability.Communication.NetManager.Core 1518 * @since 8 1519 */ 1520 isDefaultRoute: boolean; 1521 } 1522 1523 /** 1524 * Defines network link information. 1525 * @interface LinkAddress 1526 * @syscap SystemCapability.Communication.NetManager.Core 1527 * @since 8 1528 */ 1529 export interface LinkAddress { 1530 /** 1531 * Link address. 1532 * @type {NetAddress} 1533 * @syscap SystemCapability.Communication.NetManager.Core 1534 * @since 8 1535 */ 1536 address: NetAddress; 1537 /** 1538 * The length of the link address prefix. 1539 * @type {number} 1540 * @syscap SystemCapability.Communication.NetManager.Core 1541 * @since 8 1542 */ 1543 prefixLength: number; 1544 } 1545 1546 /** 1547 * Defines a network address. 1548 * @interface NetAddress 1549 * @syscap SystemCapability.Communication.NetManager.Core 1550 * @since 8 1551 */ 1552 export interface NetAddress { 1553 /** 1554 * Network address. 1555 * @type {string} 1556 * @syscap SystemCapability.Communication.NetManager.Core 1557 * @since 8 1558 */ 1559 address: string; 1560 1561 /** 1562 * Address family identifier. The value is 1 for IPv4 and 2 for IPv6. The default value is 1. 1563 * @type {?number} 1564 * @syscap SystemCapability.Communication.NetManager.Core 1565 * @since 8 1566 */ 1567 family?: number; 1568 1569 /** 1570 * Port number. The value ranges from 0 to 65535. 1571 * @type {?number} 1572 * @syscap SystemCapability.Communication.NetManager.Core 1573 * @since 8 1574 */ 1575 port?: number; 1576 } 1577 1578 /** 1579 * Network Global Proxy Configuration Information. 1580 * @interface HttpProxy 1581 * @syscap SystemCapability.Communication.NetManager.Core 1582 * @since 10 1583 */ 1584 export interface HttpProxy { 1585 /** 1586 * Proxy server host name. 1587 * @type {string} 1588 * @syscap SystemCapability.Communication.NetManager.Core 1589 * @since 10 1590 */ 1591 host: string; 1592 1593 /** 1594 * Host port. 1595 * @type {number} 1596 * @syscap SystemCapability.Communication.NetManager.Core 1597 * @since 10 1598 */ 1599 port: number; 1600 1601 /** 1602 * Do not use a blocking list for proxy servers. 1603 * @type {Array<string>} 1604 * @syscap SystemCapability.Communication.NetManager.Core 1605 * @since 10 1606 */ 1607 exclusionList: Array<string>; 1608 } 1609 1610 /** 1611 * Network Interface Information. 1612 * @interface InterfaceInfo 1613 * @syscap SystemCapability.Communication.NetManager.Core 1614 * @systemapi Hide this for inner system use. 1615 * @since 16 1616 */ 1617 export interface InterfaceInfo { 1618 /** 1619 * Interface name. 1620 * @type {string} 1621 * @syscap SystemCapability.Communication.NetManager.Core 1622 * @systemapi Hide this for inner system use. 1623 * @since 16 1624 */ 1625 interfaceName: string; 1626 1627 /** 1628 * address of the interface. 1629 * @type {string} 1630 * @syscap SystemCapability.Communication.NetManager.Core 1631 * @systemapi Hide this for inner system use. 1632 * @since 16 1633 */ 1634 address?: string; 1635 1636 /** 1637 * Interface flags. 1638 * @type {number} 1639 * @syscap SystemCapability.Communication.NetManager.Core 1640 * @systemapi Hide this for inner system use. 1641 * @since 16 1642 */ 1643 flags?: number; 1644 1645 /** 1646 * Interface scope. 1647 * @type {number} 1648 * @syscap SystemCapability.Communication.NetManager.Core 1649 * @systemapi Hide this for inner system use. 1650 * @since 16 1651 */ 1652 scope?: number; 1653 1654 /** 1655 * if interface is up. 1656 * @type {boolean} 1657 * @syscap SystemCapability.Communication.NetManager.Core 1658 * @systemapi Hide this for inner system use. 1659 * @since 16 1660 */ 1661 up?: boolean; 1662 } 1663 1664 /** 1665 * Network Route Change Information. 1666 * @interface RouteChangeInfo 1667 * @syscap SystemCapability.Communication.NetManager.Core 1668 * @systemapi Hide this for inner system use. 1669 * @since 16 1670 */ 1671 export interface RouteChangeInfo { 1672 /** 1673 * Interface name. 1674 * @type {string} 1675 * @syscap SystemCapability.Communication.NetManager.Core 1676 * @systemapi Hide this for inner system use. 1677 * @since 16 1678 */ 1679 interfaceName: string; 1680 1681 /** 1682 * route of the interface. 1683 * @type {string} 1684 * @syscap SystemCapability.Communication.NetManager.Core 1685 * @systemapi Hide this for inner system use. 1686 * @since 16 1687 */ 1688 route: string; 1689 1690 /** 1691 * gateway of the interface. 1692 * @type {string} 1693 * @syscap SystemCapability.Communication.NetManager.Core 1694 * @systemapi Hide this for inner system use. 1695 * @since 16 1696 */ 1697 gateway: string; 1698 1699 /** 1700 * if the route info is updated. 1701 * @type {boolean} 1702 * @syscap SystemCapability.Communication.NetManager.Core 1703 * @systemapi Hide this for inner system use. 1704 * @since 16 1705 */ 1706 updated: boolean; 1707 } 1708 1709 /** 1710 * Network Interface Configuration Information. 1711 * @interface NetInterfaceConfiguration 1712 * @syscap SystemCapability.Communication.NetManager.Core 1713 * @systemapi Hide this for inner system use. 1714 * @since 16 1715 */ 1716 export interface NetInterfaceConfiguration { 1717 /** 1718 * Interface name. 1719 * @type {string} 1720 * @syscap SystemCapability.Communication.NetManager.Core 1721 * @systemapi Hide this for inner system use. 1722 * @since 16 1723 */ 1724 interfaceName: string; 1725 1726 /** 1727 * Interface hardware address. 1728 * @type {string} 1729 * @syscap SystemCapability.Communication.NetManager.Core 1730 * @systemapi Hide this for inner system use. 1731 * @since 16 1732 */ 1733 hwAddress: string; 1734 1735 /** 1736 * Interface ipv4 address. 1737 * @type {string} 1738 * @syscap SystemCapability.Communication.NetManager.Core 1739 * @systemapi Hide this for inner system use. 1740 * @since 16 1741 */ 1742 ipv4Address: string; 1743 1744 /** 1745 * Interface address prefixLength. 1746 * @type {number} 1747 * @syscap SystemCapability.Communication.NetManager.Core 1748 * @systemapi Hide this for inner system use. 1749 * @since 16 1750 */ 1751 prefixLength: number; 1752 1753 /** 1754 * Interface flags. 1755 * @type {Array<string>} 1756 * @syscap SystemCapability.Communication.NetManager.Core 1757 * @systemapi Hide this for inner system use. 1758 * @since 16 1759 */ 1760 flags: Array<string>; 1761 } 1762} 1763 1764export default connection; 1765