1/* 2 * Copyright (C) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * @file 18 * @kit NetworkKit 19 */ 20 21import type { AsyncCallback, Callback } from './@ohos.base'; 22import type connection from './@ohos.net.connection'; 23 24/** 25 * Provides interfaces to manage network policy rules. 26 * @namespace policy 27 * @syscap SystemCapability.Communication.NetManager.Core 28 * @since 10 29 */ 30declare namespace policy { 31 /** 32 * Get network bear type. 33 * @typedef { connection.NetBearType } 34 * @syscap SystemCapability.Communication.NetManager.Core 35 * @since 10 36 */ 37 type NetBearType = connection.NetBearType; 38 39 /** 40 * Control if applications can use data on background. 41 * @permission ohos.permission.MANAGE_NET_STRATEGY 42 * @param { boolean } isAllowed - Allow applications to use data on background. 43 * @param { AsyncCallback<void> } callback - the callback of setBackgroundAllowed. 44 * @throws { BusinessError } 201 - Permission denied. 45 * @throws { BusinessError } 202 - Non-system applications use system APIs. 46 * @throws { BusinessError } 401 - Parameter error. 47 * @throws { BusinessError } 2100001 - Invalid parameter value. 48 * @throws { BusinessError } 2100002 - Failed to connect to the service. 49 * @throws { BusinessError } 2100003 - System internal error. 50 * @syscap SystemCapability.Communication.NetManager.Core 51 * @systemapi Hide this for inner system use. 52 * @since 10 53 */ 54 function setBackgroundAllowed(isAllowed: boolean, callback: AsyncCallback<void>): void; 55 56 /** 57 * Control if applications can use data on background. 58 * @permission ohos.permission.MANAGE_NET_STRATEGY 59 * @param { boolean } isAllowed - Allow applications to use data on background. 60 * @returns { Promise<void> } The promise returned by the function. 61 * @throws { BusinessError } 201 - Permission denied. 62 * @throws { BusinessError } 202 - Non-system applications use system APIs. 63 * @throws { BusinessError } 401 - Parameter error. 64 * @throws { BusinessError } 2100001 - Invalid parameter value. 65 * @throws { BusinessError } 2100002 - Failed to connect to the service. 66 * @throws { BusinessError } 2100003 - System internal error. 67 * @syscap SystemCapability.Communication.NetManager.Core 68 * @systemapi Hide this for inner system use. 69 * @since 10 70 */ 71 function setBackgroundAllowed(isAllowed: boolean): Promise<void>; 72 73 /** 74 * Get the status if applications can use data on background. 75 * @permission ohos.permission.MANAGE_NET_STRATEGY 76 * @param { AsyncCallback<boolean> } callback - the callback of allowed or not to use data on background. 77 * @throws { BusinessError } 201 - Permission denied. 78 * @throws { BusinessError } 202 - Non-system applications use system APIs. 79 * @throws { BusinessError } 401 - Parameter error. 80 * @throws { BusinessError } 2100001 - Invalid parameter value. 81 * @throws { BusinessError } 2100002 - Failed to connect to the service. 82 * @throws { BusinessError } 2100003 - System internal error. 83 * @syscap SystemCapability.Communication.NetManager.Core 84 * @systemapi Hide this for inner system use. 85 * @since 10 86 */ 87 function isBackgroundAllowed(callback: AsyncCallback<boolean>): void; 88 89 /** 90 * Get the status if applications can use data on background. 91 * @permission ohos.permission.MANAGE_NET_STRATEGY 92 * @returns { Promise<boolean> } The promise returned by the function. 93 * @throws { BusinessError } 201 - Permission denied. 94 * @throws { BusinessError } 202 - Non-system applications use system APIs. 95 * @throws { BusinessError } 401 - Parameter error. 96 * @throws { BusinessError } 2100001 - Invalid parameter value. 97 * @throws { BusinessError } 2100002 - Failed to connect to the service. 98 * @throws { BusinessError } 2100003 - System internal error. 99 * @syscap SystemCapability.Communication.NetManager.Core 100 * @systemapi Hide this for inner system use. 101 * @since 10 102 */ 103 function isBackgroundAllowed(): Promise<boolean>; 104 105 /** 106 * Get the background network policy for the specified uid. 107 * @permission ohos.permission.MANAGE_NET_STRATEGY 108 * @param { number } uid - The specified UID of application. 109 * @param { AsyncCallback<NetBackgroundPolicy> } callback - the callback of getBackgroundPolicyByUid. 110 * @throws { BusinessError } 201 - Permission denied. 111 * @throws { BusinessError } 202 - Non-system applications use system APIs. 112 * @throws { BusinessError } 401 - Parameter error. 113 * @throws { BusinessError } 2100001 - Invalid parameter value. 114 * @throws { BusinessError } 2100002 - Failed to connect to the service. 115 * @throws { BusinessError } 2100003 - System internal error. 116 * @syscap SystemCapability.Communication.NetManager.Core 117 * @systemapi Hide this for inner system use. 118 * @since 10 119 */ 120 function getBackgroundPolicyByUid(uid: number, callback: AsyncCallback<NetBackgroundPolicy>): void; 121 122 /** 123 * Get the background network policy for the specified uid. 124 * @permission ohos.permission.MANAGE_NET_STRATEGY 125 * @param { number } uid - The specified UID of application. 126 * @returns { Promise<NetBackgroundPolicy> } The promise returned by the function. 127 * @throws { BusinessError } 201 - Permission denied. 128 * @throws { BusinessError } 202 - Non-system applications use system APIs. 129 * @throws { BusinessError } 401 - Parameter error. 130 * @throws { BusinessError } 2100001 - Invalid parameter value. 131 * @throws { BusinessError } 2100002 - Failed to connect to the service. 132 * @throws { BusinessError } 2100003 - System internal error. 133 * @syscap SystemCapability.Communication.NetManager.Core 134 * @systemapi Hide this for inner system use. 135 * @since 10 136 */ 137 function getBackgroundPolicyByUid(uid: number): Promise<NetBackgroundPolicy>; 138 139 /** 140 * Set the policy for the specified UID. 141 * @permission ohos.permission.MANAGE_NET_STRATEGY 142 * @param { number } uid - the specified UID of application. 143 * @param { NetUidPolicy } policy - the policy of the current UID of application.For details, see {@link NetUidPolicy}. 144 * @param { AsyncCallback<void> } callback - the callback of setPolicyByUid. 145 * @throws { BusinessError } 201 - Permission denied. 146 * @throws { BusinessError } 202 - Non-system applications use system APIs. 147 * @throws { BusinessError } 401 - Parameter error. 148 * @throws { BusinessError } 2100001 - Invalid parameter value. 149 * @throws { BusinessError } 2100002 - Failed to connect to the service. 150 * @throws { BusinessError } 2100003 - System internal error. 151 * @syscap SystemCapability.Communication.NetManager.Core 152 * @systemapi Hide this for inner system use. 153 * @since 10 154 */ 155 function setPolicyByUid(uid: number, policy: NetUidPolicy, callback: AsyncCallback<void>): void; 156 157 /** 158 * Set the policy for the specified UID. 159 * @permission ohos.permission.MANAGE_NET_STRATEGY 160 * @param { number } uid - the specified UID of application. 161 * @param { NetUidPolicy } policy - the policy of the current UID of application.For details, see {@link NetUidPolicy}. 162 * @returns { Promise<void> } The promise returned by the function. 163 * @throws { BusinessError } 201 - Permission denied. 164 * @throws { BusinessError } 202 - Non-system applications use system APIs. 165 * @throws { BusinessError } 401 - Parameter error. 166 * @throws { BusinessError } 2100001 - Invalid parameter value. 167 * @throws { BusinessError } 2100002 - Failed to connect to the service. 168 * @throws { BusinessError } 2100003 - System internal error. 169 * @syscap SystemCapability.Communication.NetManager.Core 170 * @systemapi Hide this for inner system use. 171 * @since 10 172 */ 173 function setPolicyByUid(uid: number, policy: NetUidPolicy): Promise<void>; 174 175 /** 176 * Query the policy of the specified UID. 177 * @permission ohos.permission.MANAGE_NET_STRATEGY 178 * @param { number } uid - the specified UID of application. 179 * @param { AsyncCallback<NetUidPolicy> } callback - the callback of getPolicyByUid. 180 * @throws { BusinessError } 201 - Permission denied. 181 * @throws { BusinessError } 202 - Non-system applications use system APIs. 182 * @throws { BusinessError } 401 - Parameter error. 183 * @throws { BusinessError } 2100001 - Invalid parameter value. 184 * @throws { BusinessError } 2100002 - Failed to connect to the service. 185 * @throws { BusinessError } 2100003 - System internal error. 186 * @syscap SystemCapability.Communication.NetManager.Core 187 * @systemapi Hide this for inner system use. 188 * @since 10 189 */ 190 function getPolicyByUid(uid: number, callback: AsyncCallback<NetUidPolicy>): void; 191 192 /** 193 * Query the policy of the specified UID. 194 * @permission ohos.permission.MANAGE_NET_STRATEGY 195 * @param { number } uid - the specified UID of application. 196 * @returns { Promise<NetUidPolicy> } The promise returned by the function. 197 * @throws { BusinessError } 201 - Permission denied. 198 * @throws { BusinessError } 202 - Non-system applications use system APIs. 199 * @throws { BusinessError } 401 - Parameter error. 200 * @throws { BusinessError } 2100001 - Invalid parameter value. 201 * @throws { BusinessError } 2100002 - Failed to connect to the service. 202 * @throws { BusinessError } 2100003 - System internal error. 203 * @syscap SystemCapability.Communication.NetManager.Core 204 * @systemapi Hide this for inner system use. 205 * @since 10 206 */ 207 function getPolicyByUid(uid: number): Promise<NetUidPolicy>; 208 209 /** 210 * Query the application UIDs of the specified policy. 211 * @permission ohos.permission.MANAGE_NET_STRATEGY 212 * @param { NetUidPolicy } policy - the policy of the current UID of application.For details, see {@link NetUidPolicy}. 213 * @param { AsyncCallback<Array<number>> } callback - the callback of getUidsByPolicy. 214 * @throws { BusinessError } 201 - Permission denied. 215 * @throws { BusinessError } 202 - Non-system applications use system APIs. 216 * @throws { BusinessError } 401 - Parameter error. 217 * @throws { BusinessError } 2100001 - Invalid parameter value. 218 * @throws { BusinessError } 2100002 - Failed to connect to the service. 219 * @throws { BusinessError } 2100003 - System internal error. 220 * @syscap SystemCapability.Communication.NetManager.Core 221 * @systemapi Hide this for inner system use. 222 * @since 10 223 */ 224 function getUidsByPolicy(policy: NetUidPolicy, callback: AsyncCallback<Array<number>>): void; 225 226 /** 227 * Query the application UIDs of the specified policy. 228 * @permission ohos.permission.MANAGE_NET_STRATEGY 229 * @param { NetUidPolicy } policy - the policy of the current UID of application.For details, see {@link NetUidPolicy}. 230 * @returns { Promise<Array<number>> } The promise returned by the function. 231 * @throws { BusinessError } 201 - Permission denied. 232 * @throws { BusinessError } 202 - Non-system applications use system APIs. 233 * @throws { BusinessError } 401 - Parameter error. 234 * @throws { BusinessError } 2100001 - Invalid parameter value. 235 * @throws { BusinessError } 2100002 - Failed to connect to the service. 236 * @throws { BusinessError } 2100003 - System internal error. 237 * @syscap SystemCapability.Communication.NetManager.Core 238 * @systemapi Hide this for inner system use. 239 * @since 10 240 */ 241 function getUidsByPolicy(policy: NetUidPolicy): Promise<Array<number>>; 242 243 /** 244 * Get the status whether the uid app can access the metered network or non-metered network. 245 * @permission ohos.permission.MANAGE_NET_STRATEGY 246 * @param { number } uid - The specified UID of application. 247 * @param { boolean } isMetered - Indicates metered network or non-metered network. 248 * @param { AsyncCallback<boolean> } callback - the callback of isUidNetAllowed. 249 * @throws { BusinessError } 201 - Permission denied. 250 * @throws { BusinessError } 202 - Non-system applications use system APIs. 251 * @throws { BusinessError } 401 - Parameter error. 252 * @throws { BusinessError } 2100001 - Invalid parameter value. 253 * @throws { BusinessError } 2100002 - Failed to connect to the service. 254 * @throws { BusinessError } 2100003 - System internal error. 255 * @syscap SystemCapability.Communication.NetManager.Core 256 * @systemapi Hide this for inner system use. 257 * @since 10 258 */ 259 function isUidNetAllowed(uid: number, isMetered: boolean, callback: AsyncCallback<boolean>): void; 260 261 /** 262 * Get the status whether the uid app can access the metered network or non-metered network. 263 * @permission ohos.permission.MANAGE_NET_STRATEGY 264 * @param { number } uid - The specified UID of application. 265 * @param { boolean } isMetered - Indicates metered network or non-metered network. 266 * @returns { Promise<boolean> } The promise returned by the function. 267 * @throws { BusinessError } 201 - Permission denied. 268 * @throws { BusinessError } 202 - Non-system applications use system APIs. 269 * @throws { BusinessError } 401 - Parameter error. 270 * @throws { BusinessError } 2100001 - Invalid parameter value. 271 * @throws { BusinessError } 2100002 - Failed to connect to the service. 272 * @throws { BusinessError } 2100003 - System internal error. 273 * @syscap SystemCapability.Communication.NetManager.Core 274 * @systemapi Hide this for inner system use. 275 * @since 10 276 */ 277 function isUidNetAllowed(uid: number, isMetered: boolean): Promise<boolean>; 278 279 /** 280 * Get the status of whether the specified uid can access the specified network. 281 * @permission ohos.permission.MANAGE_NET_STRATEGY 282 * @param { number } uid - The specified UID of application. 283 * @param { string } iface - The specified network interface name. 284 * @param { AsyncCallback<boolean> } callback - the callback of isUidNetAllowed. 285 * @throws { BusinessError } 201 - Permission denied. 286 * @throws { BusinessError } 202 - Non-system applications use system APIs. 287 * @throws { BusinessError } 401 - Parameter error. 288 * @throws { BusinessError } 2100001 - Invalid parameter value. 289 * @throws { BusinessError } 2100002 - Failed to connect to the service. 290 * @throws { BusinessError } 2100003 - System internal error. 291 * @syscap SystemCapability.Communication.NetManager.Core 292 * @systemapi Hide this for inner system use. 293 * @since 10 294 */ 295 function isUidNetAllowed(uid: number, iface: string, callback: AsyncCallback<boolean>): void; 296 297 /** 298 * Get the status of whether the specified uid can access the specified network. 299 * @permission ohos.permission.MANAGE_NET_STRATEGY 300 * @param { number } uid - The specified UID of application. 301 * @param { string } iface - The specified network interface name. 302 * @returns { Promise<boolean> } The promise returned by the function. 303 * @throws { BusinessError } 201 - Permission denied. 304 * @throws { BusinessError } 202 - Non-system applications use system APIs. 305 * @throws { BusinessError } 401 - Parameter error. 306 * @throws { BusinessError } 2100001 - Invalid parameter value. 307 * @throws { BusinessError } 2100002 - Failed to connect to the service. 308 * @throws { BusinessError } 2100003 - System internal error. 309 * @syscap SystemCapability.Communication.NetManager.Core 310 * @systemapi Hide this for inner system use. 311 * @since 10 312 */ 313 function isUidNetAllowed(uid: number, iface: string): Promise<boolean>; 314 315 /** 316 * Set metered network quota policies. 317 * @permission ohos.permission.MANAGE_NET_STRATEGY 318 * @param { Array<NetQuotaPolicy> } quotaPolicies - Indicates {@link NetQuotaPolicy}. 319 * @param { AsyncCallback<void> } callback - the callback of setNetQuotaPolicies. 320 * @throws { BusinessError } 201 - Permission denied. 321 * @throws { BusinessError } 202 - Non-system applications use system APIs. 322 * @throws { BusinessError } 401 - Parameter error. 323 * @throws { BusinessError } 2100001 - Invalid parameter value. 324 * @throws { BusinessError } 2100002 - Failed to connect to the service. 325 * @throws { BusinessError } 2100003 - System internal error. 326 * @syscap SystemCapability.Communication.NetManager.Core 327 * @systemapi Hide this for inner system use. 328 * @since 10 329 */ 330 function setNetQuotaPolicies(quotaPolicies: Array<NetQuotaPolicy>, callback: AsyncCallback<void>): void; 331 332 /** 333 * Set metered network quota policies. 334 * @permission ohos.permission.MANAGE_NET_STRATEGY 335 * @param { Array<NetQuotaPolicy> } quotaPolicies - Indicates {@link NetQuotaPolicy}. 336 * @returns { Promise<void> } The promise returned by the function. 337 * @throws { BusinessError } 201 - Permission denied. 338 * @throws { BusinessError } 202 - Non-system applications use system APIs. 339 * @throws { BusinessError } 401 - Parameter error. 340 * @throws { BusinessError } 2100001 - Invalid parameter value. 341 * @throws { BusinessError } 2100002 - Failed to connect to the service. 342 * @throws { BusinessError } 2100003 - System internal error. 343 * @syscap SystemCapability.Communication.NetManager.Core 344 * @systemapi Hide this for inner system use. 345 * @since 10 346 */ 347 function setNetQuotaPolicies(quotaPolicies: Array<NetQuotaPolicy>): Promise<void>; 348 349 /** 350 * Get metered network quota policies. 351 * @permission ohos.permission.MANAGE_NET_STRATEGY 352 * @param { AsyncCallback<Array<NetQuotaPolicy>> } callback - the callback of getNetQuotaPolicies. 353 * @throws { BusinessError } 201 - Permission denied. 354 * @throws { BusinessError } 202 - Non-system applications use system APIs. 355 * @throws { BusinessError } 401 - Parameter error. 356 * @throws { BusinessError } 2100001 - Invalid parameter value. 357 * @throws { BusinessError } 2100002 - Failed to connect to the service. 358 * @throws { BusinessError } 2100003 - System internal error. 359 * @syscap SystemCapability.Communication.NetManager.Core 360 * @systemapi Hide this for inner system use. 361 * @since 10 362 */ 363 function getNetQuotaPolicies(callback: AsyncCallback<Array<NetQuotaPolicy>>): void; 364 365 /** 366 * Get metered network quota policies. 367 * @permission ohos.permission.MANAGE_NET_STRATEGY 368 * @returns { Promise<Array<NetQuotaPolicy>> } The promise returned by the function. 369 * @throws { BusinessError } 201 - Permission denied. 370 * @throws { BusinessError } 202 - Non-system applications use system APIs. 371 * @throws { BusinessError } 401 - Parameter error. 372 * @throws { BusinessError } 2100002 - Failed to connect to the service. 373 * @throws { BusinessError } 2100003 - System internal error. 374 * @syscap SystemCapability.Communication.NetManager.Core 375 * @systemapi Hide this for inner system use. 376 * @since 10 377 */ 378 function getNetQuotaPolicies(): Promise<Array<NetQuotaPolicy>>; 379 380 /** 381 * Update the policy when the quota reaches the upper limit. 382 * @permission ohos.permission.MANAGE_NET_STRATEGY 383 * @param { NetBearType } netType - {@link NetBearType}. 384 * @param { string } simId - Specify the matched simId of quota policy when netType is cellular. 385 * @param { RemindType } remindType - {@link RemindType}. 386 * @param { AsyncCallback<void> } callback - the callback of updateRemindPolicy. 387 * @throws { BusinessError } 201 - Permission denied. 388 * @throws { BusinessError } 202 - Non-system applications use system APIs. 389 * @throws { BusinessError } 401 - Parameter error. 390 * @throws { BusinessError } 2100001 - Invalid parameter value. 391 * @throws { BusinessError } 2100002 - Failed to connect to the service. 392 * @throws { BusinessError } 2100003 - System internal error. 393 * @syscap SystemCapability.Communication.NetManager.Core 394 * @systemapi Hide this for inner system use. 395 * @since 10 396 */ 397 function updateRemindPolicy(netType: NetBearType, simId: string, remindType: RemindType, callback: AsyncCallback<void>): void; 398 399 /** 400 * Update the policy when the quota reaches the upper limit. 401 * @permission ohos.permission.MANAGE_NET_STRATEGY 402 * @param { NetBearType } netType - {@link NetBearType}. 403 * @param { string } simId - Specify the matched simId of quota policy when netType is cellular. 404 * @param { RemindType } remindType - {@link RemindType}. 405 * @returns { Promise<void> } The promise returned by the function. 406 * @throws { BusinessError } 201 - Permission denied. 407 * @throws { BusinessError } 202 - Non-system applications use system APIs. 408 * @throws { BusinessError } 401 - Parameter error. 409 * @throws { BusinessError } 2100001 - Invalid parameter value. 410 * @throws { BusinessError } 2100002 - Failed to connect to the service. 411 * @throws { BusinessError } 2100003 - System internal error. 412 * @syscap SystemCapability.Communication.NetManager.Core 413 * @systemapi Hide this for inner system use. 414 * @since 10 415 */ 416 function updateRemindPolicy(netType: NetBearType, simId: string, remindType: RemindType): Promise<void>; 417 418 /** 419 * Set the list of uids that are allowed to access the Internet in hibernation mode. 420 * @permission ohos.permission.MANAGE_NET_STRATEGY 421 * @param { Array<number> } uids - The specified uids of application. 422 * @param { boolean } isAllowed - Whether to allow Uids in the list to access the Internet. 423 * @param { AsyncCallback<void> } callback - the callback of setDeviceIdleTrustlist. 424 * @throws { BusinessError } 201 - Permission denied. 425 * @throws { BusinessError } 202 - Non-system applications use system APIs. 426 * @throws { BusinessError } 401 - Parameter error. 427 * @throws { BusinessError } 2100001 - Invalid parameter value. 428 * @throws { BusinessError } 2100002 - Failed to connect to the service. 429 * @throws { BusinessError } 2100003 - System internal error. 430 * @syscap SystemCapability.Communication.NetManager.Core 431 * @systemapi Hide this for inner system use. 432 * @since 10 433 */ 434 function setDeviceIdleTrustlist(uids: Array<number>, isAllowed: boolean, callback: AsyncCallback<void>): void; 435 436 /** 437 * Set the list of uids that are allowed to access the Internet in hibernation mode. 438 * @permission ohos.permission.MANAGE_NET_STRATEGY 439 * @param { Array<number> } uids - The specified uids of application. 440 * @param { boolean } isAllowed - Whether to allow Uids in the list to access the Internet. 441 * @returns { Promise<void> } The promise returned by the function. 442 * @throws { BusinessError } 201 - Permission denied. 443 * @throws { BusinessError } 202 - Non-system applications use system APIs. 444 * @throws { BusinessError } 401 - Parameter error. 445 * @throws { BusinessError } 2100001 - Invalid parameter value. 446 * @throws { BusinessError } 2100002 - Failed to connect to the service. 447 * @throws { BusinessError } 2100003 - System internal error. 448 * @syscap SystemCapability.Communication.NetManager.Core 449 * @systemapi Hide this for inner system use. 450 * @since 10 451 */ 452 function setDeviceIdleTrustlist(uids: Array<number>, isAllowed: boolean): Promise<void>; 453 454 /** 455 * Obtain the list of uids that are allowed to access the Internet in hibernation mode. 456 * @permission ohos.permission.MANAGE_NET_STRATEGY 457 * @param { AsyncCallback<Array<number>> } callback - the callback of getDeviceIdleTrustlist. 458 * @throws { BusinessError } 201 - Permission denied. 459 * @throws { BusinessError } 202 - Non-system applications use system APIs. 460 * @throws { BusinessError } 401 - Parameter error. 461 * @throws { BusinessError } 2100001 - Invalid parameter value. 462 * @throws { BusinessError } 2100002 - Failed to connect to the service. 463 * @throws { BusinessError } 2100003 - System internal error. 464 * @syscap SystemCapability.Communication.NetManager.Core 465 * @systemapi Hide this for inner system use. 466 * @since 10 467 */ 468 function getDeviceIdleTrustlist(callback: AsyncCallback<Array<number>>): void; 469 470 /** 471 * Obtain the list of uids that are allowed to access the Internet in hibernation mode. 472 * @permission ohos.permission.MANAGE_NET_STRATEGY 473 * @returns { Promise<Array<number>> } The promise returned by the function. 474 * @throws { BusinessError } 201 - Permission denied. 475 * @throws { BusinessError } 202 - Non-system applications use system APIs. 476 * @throws { BusinessError } 401 - Parameter error. 477 * @throws { BusinessError } 2100002 - Failed to connect to the service. 478 * @throws { BusinessError } 2100003 - System internal error. 479 * @syscap SystemCapability.Communication.NetManager.Core 480 * @systemapi Hide this for inner system use. 481 * @since 10 482 */ 483 function getDeviceIdleTrustlist(): Promise<Array<number>>; 484 485 /** 486 * Set the list of uids that are allowed to access the Internet in power saving mode. 487 * @permission ohos.permission.MANAGE_NET_STRATEGY 488 * @param { Array<number> } uids - The specified uids of application. 489 * @param { boolean } isAllowed - Whether to allow Uids in the list to access the Internet. 490 * @param { AsyncCallback<void> } callback - the callback of setPowerSaveTrustlist. 491 * @throws { BusinessError } 201 - Permission denied. 492 * @throws { BusinessError } 202 - Non-system applications use system APIs. 493 * @throws { BusinessError } 401 - Parameter error. 494 * @throws { BusinessError } 2100001 - Invalid parameter value. 495 * @throws { BusinessError } 2100002 - Failed to connect to the service. 496 * @throws { BusinessError } 2100003 - System internal error. 497 * @syscap SystemCapability.Communication.NetManager.Core 498 * @systemapi Hide this for inner system use. 499 * @since 10 500 */ 501 function setPowerSaveTrustlist(uids: Array<number>, isAllowed: boolean, callback: AsyncCallback<void>): void; 502 503 /** 504 * Set the list of uids that are allowed to access the Internet in power saving mode. 505 * @permission ohos.permission.MANAGE_NET_STRATEGY 506 * @param { Array<number> } uids - The specified uids of application. 507 * @param { boolean } isAllowed - Whether to allow Uids in the list to access the Internet. 508 * @returns { Promise<void> } The promise returned by the function. 509 * @throws { BusinessError } 201 - Permission denied. 510 * @throws { BusinessError } 202 - Non-system applications use system APIs. 511 * @throws { BusinessError } 401 - Parameter error. 512 * @throws { BusinessError } 2100001 - Invalid parameter value. 513 * @throws { BusinessError } 2100002 - Failed to connect to the service. 514 * @throws { BusinessError } 2100003 - System internal error. 515 * @syscap SystemCapability.Communication.NetManager.Core 516 * @systemapi Hide this for inner system use. 517 * @since 10 518 */ 519 function setPowerSaveTrustlist(uids: Array<number>, isAllowed: boolean): Promise<void>; 520 521 /** 522 * Obtain the list of uids that are allowed to access the Internet in power saving mode. 523 * @permission ohos.permission.MANAGE_NET_STRATEGY 524 * @param { AsyncCallback<Array<number>> } callback - the callback of UIDs list. 525 * @throws { BusinessError } 201 - Permission denied. 526 * @throws { BusinessError } 202 - Non-system applications use system APIs. 527 * @throws { BusinessError } 401 - Parameter error. 528 * @throws { BusinessError } 2100001 - Invalid parameter value. 529 * @throws { BusinessError } 2100002 - Failed to connect to the service. 530 * @throws { BusinessError } 2100003 - System internal error. 531 * @syscap SystemCapability.Communication.NetManager.Core 532 * @systemapi Hide this for inner system use. 533 * @since 10 534 */ 535 function getPowerSaveTrustlist(callback: AsyncCallback<Array<number>>): void; 536 537 /** 538 * Obtain the list of uids that are allowed to access the Internet in power saving mode. 539 * @permission ohos.permission.MANAGE_NET_STRATEGY 540 * @returns { Promise<Array<number>> } The promise returned by the function. 541 * @throws { BusinessError } 201 - Permission denied. 542 * @throws { BusinessError } 202 - Non-system applications use system APIs. 543 * @throws { BusinessError } 401 - Parameter error. 544 * @throws { BusinessError } 2100002 - Failed to connect to the service. 545 * @throws { BusinessError } 2100003 - System internal error. 546 * @syscap SystemCapability.Communication.NetManager.Core 547 * @systemapi Hide this for inner system use. 548 * @since 10 549 */ 550 function getPowerSaveTrustlist(): Promise<Array<number>>; 551 552 /** 553 * Reset network policies\rules\quota policies\firewall rules. 554 * @permission ohos.permission.MANAGE_NET_STRATEGY 555 * @param { string } simId - Specify the matched simId of quota policy. 556 * @param { AsyncCallback<void> } callback - the callback of resetPolicies. 557 * @throws { BusinessError } 201 - Permission denied. 558 * @throws { BusinessError } 202 - Non-system applications use system APIs. 559 * @throws { BusinessError } 401 - Parameter error. 560 * @throws { BusinessError } 2100001 - Invalid parameter value. 561 * @throws { BusinessError } 2100002 - Failed to connect to the service. 562 * @throws { BusinessError } 2100003 - System internal error. 563 * @syscap SystemCapability.Communication.NetManager.Core 564 * @systemapi Hide this for inner system use. 565 * @since 10 566 */ 567 function resetPolicies(simId: string, callback: AsyncCallback<void>): void; 568 569 /** 570 * Reset network policies\rules\quota policies\firewall rules. 571 * @permission ohos.permission.MANAGE_NET_STRATEGY 572 * @param { string } simId - Specify the matched simId of quota policy. 573 * @returns { Promise<void> } The promise returned by the function. 574 * @throws { BusinessError } 201 - Permission denied. 575 * @throws { BusinessError } 202 - Non-system applications use system APIs. 576 * @throws { BusinessError } 401 - Parameter error. 577 * @throws { BusinessError } 2100001 - Invalid parameter value. 578 * @throws { BusinessError } 2100002 - Failed to connect to the service. 579 * @throws { BusinessError } 2100003 - System internal error. 580 * @syscap SystemCapability.Communication.NetManager.Core 581 * @systemapi Hide this for inner system use. 582 * @since 10 583 */ 584 function resetPolicies(simId: string): Promise<void>; 585 586 /** 587 * Set the policy to access the network of the specified application. 588 * 589 * @permission ohos.permission.MANAGE_NET_STRATEGY 590 * @param { number } uid - The specified UID of application. 591 * @param { NetworkAccessPolicy } policy - The network access policy of application. For details, see {@link NetworkAccessPolicy}. 592 * @param { boolean } [isReconfirmed] - Whether this operation is reconfirmed by user or not. Default false. 593 * @returns { Promise<void> } The promise returned by the function. 594 * @throws { BusinessError } 201 - Permission denied. 595 * @throws { BusinessError } 202 - Non-system applications use system APIs. 596 * @throws { BusinessError } 401 - Parameter error. 597 * @throws { BusinessError } 2100001 - Invalid parameter value. 598 * @throws { BusinessError } 2100002 - Failed to connect to the service. 599 * @throws { BusinessError } 2100003 - System internal error. 600 * @syscap SystemCapability.Communication.NetManager.Core 601 * @systemapi Hide this for inner system use. 602 * @since 12 603 */ 604 function setNetworkAccessPolicy(uid: number, policy: NetworkAccessPolicy, isReconfirmed?: boolean): Promise<void>; 605 606 /** 607 * Query the network access policy of the specified application. 608 * 609 * @permission ohos.permission.MANAGE_NET_STRATEGY 610 * @param { number } uid - The specified UID of application. 611 * @returns { Promise<NetworkAccessPolicy> } Returns the network access policy of the application. For details, see {@link NetworkAccessPolicy}. 612 * @throws { BusinessError } 201 - Permission denied. 613 * @throws { BusinessError } 202 - Non-system applications use system APIs. 614 * @throws { BusinessError } 401 - Parameter error. 615 * @throws { BusinessError } 2100001 - Invalid parameter value. 616 * @throws { BusinessError } 2100002 - Failed to connect to the service. 617 * @throws { BusinessError } 2100003 - System internal error. 618 * @syscap SystemCapability.Communication.NetManager.Core 619 * @systemapi Hide this for inner system use. 620 * @since 12 621 */ 622 function getNetworkAccessPolicy(uid: number): Promise<NetworkAccessPolicy>; 623 624 /** 625 * Query the network access policy of all applications. 626 * @permission ohos.permission.MANAGE_NET_STRATEGY 627 * @returns { Promise<UidNetworkAccessPolicy> } the network access policy of all applications. 628 * @throws { BusinessError } 201 - Permission denied. 629 * @throws { BusinessError } 202 - Non-system applications use system APIs. 630 * @throws { BusinessError } 2100002 - Failed to connect to the service. 631 * @throws { BusinessError } 2100003 - System internal error. 632 * @syscap SystemCapability.Communication.NetManager.Core 633 * @systemapi Hide this for inner system use. 634 * @since 12 635 */ 636 function getNetworkAccessPolicy(): Promise<UidNetworkAccessPolicy>; 637 638 /** 639 * Register uid policy change listener. 640 * @permission ohos.permission.MANAGE_NET_STRATEGY 641 * @param { 'netUidPolicyChange' } type - Indicates Event name. 642 * @param { Callback<{ uid: number, policy: NetUidPolicy }> } callback - the callback of on. 643 * @throws { BusinessError } 201 - Permission denied. 644 * @throws { BusinessError } 202 - Non-system applications use system APIs. 645 * @throws { BusinessError } 401 - Parameter error. 646 * @throws { BusinessError } 2100001 - Invalid parameter value. 647 * @throws { BusinessError } 2100002 - Failed to connect to the service. 648 * @throws { BusinessError } 2100003 - System internal error. 649 * @syscap SystemCapability.Communication.NetManager.Core 650 * @systemapi Hide this for inner system use. 651 * @since 10 652 */ 653 /** 654 * Register uid policy change listener. 655 * @permission ohos.permission.MANAGE_NET_STRATEGY 656 * @param { 'netUidPolicyChange' } type - Indicates Event name. 657 * @param { Callback<NetUidPolicyInfo> } callback - the callback of on. 658 * @throws { BusinessError } 201 - Permission denied. 659 * @throws { BusinessError } 202 - Non-system applications use system APIs. 660 * @throws { BusinessError } 401 - Parameter error. 661 * @throws { BusinessError } 2100001 - Invalid parameter value. 662 * @throws { BusinessError } 2100002 - Failed to connect to the service. 663 * @throws { BusinessError } 2100003 - System internal error. 664 * @syscap SystemCapability.Communication.NetManager.Core 665 * @systemapi Hide this for inner system use. 666 * @since 11 667 */ 668 function on(type: 'netUidPolicyChange', callback: Callback<NetUidPolicyInfo>): void; 669 670 /** 671 * Unregister uid policy change listener. 672 * @permission ohos.permission.MANAGE_NET_STRATEGY 673 * @param { 'netUidPolicyChange' } type - Indicates Event name. 674 * @param { Callback<{ uid: number, policy: NetUidPolicy }> } callback - the callback of off. 675 * @throws { BusinessError } 201 - Permission denied. 676 * @throws { BusinessError } 202 - Non-system applications use system APIs. 677 * @throws { BusinessError } 401 - Parameter error. 678 * @throws { BusinessError } 2100001 - Invalid parameter value. 679 * @throws { BusinessError } 2100002 - Failed to connect to the service. 680 * @throws { BusinessError } 2100003 - System internal error. 681 * @syscap SystemCapability.Communication.NetManager.Core 682 * @systemapi Hide this for inner system use. 683 * @since 10 684 */ 685 /** 686 * Unregister uid policy change listener. 687 * @permission ohos.permission.MANAGE_NET_STRATEGY 688 * @param { 'netUidPolicyChange' } type - Indicates Event name. 689 * @param { Callback<NetUidPolicyInfo> } callback - the callback of off. 690 * @throws { BusinessError } 201 - Permission denied. 691 * @throws { BusinessError } 202 - Non-system applications use system APIs. 692 * @throws { BusinessError } 401 - Parameter error. 693 * @throws { BusinessError } 2100001 - Invalid parameter value. 694 * @throws { BusinessError } 2100002 - Failed to connect to the service. 695 * @throws { BusinessError } 2100003 - System internal error. 696 * @syscap SystemCapability.Communication.NetManager.Core 697 * @systemapi Hide this for inner system use. 698 * @since 11 699 */ 700 function off(type: 'netUidPolicyChange', callback?: Callback<NetUidPolicyInfo>): void; 701 702 /** 703 * Register uid rule change listener. 704 * @permission ohos.permission.MANAGE_NET_STRATEGY 705 * @param { 'netUidRuleChange' } type - Indicates Event name. 706 * @param { Callback<{ uid: number, rule: NetUidRule }> } callback - the callback of on. 707 * @throws { BusinessError } 201 - Permission denied. 708 * @throws { BusinessError } 202 - Non-system applications use system APIs. 709 * @throws { BusinessError } 401 - Parameter error. 710 * @throws { BusinessError } 2100001 - Invalid parameter value. 711 * @throws { BusinessError } 2100002 - Failed to connect to the service. 712 * @throws { BusinessError } 2100003 - System internal error. 713 * @syscap SystemCapability.Communication.NetManager.Core 714 * @systemapi Hide this for inner system use. 715 * @since 10 716 */ 717 /** 718 * Register uid rule change listener. 719 * @permission ohos.permission.MANAGE_NET_STRATEGY 720 * @param { 'netUidRuleChange' } type - Indicates Event name. 721 * @param { Callback<NetUidRuleInfo> } callback - the callback of on. 722 * @throws { BusinessError } 201 - Permission denied. 723 * @throws { BusinessError } 202 - Non-system applications use system APIs. 724 * @throws { BusinessError } 401 - Parameter error. 725 * @throws { BusinessError } 2100001 - Invalid parameter value. 726 * @throws { BusinessError } 2100002 - Failed to connect to the service. 727 * @throws { BusinessError } 2100003 - System internal error. 728 * @syscap SystemCapability.Communication.NetManager.Core 729 * @systemapi Hide this for inner system use. 730 * @since 11 731 */ 732 function on(type: 'netUidRuleChange', callback: Callback<NetUidRuleInfo>): void; 733 734 /** 735 * Unregister uid rule change listener. 736 * @permission ohos.permission.MANAGE_NET_STRATEGY 737 * @param { 'netUidRuleChange' } type - Indicates Event name. 738 * @param { Callback<{ uid: number, rule: NetUidRule }> } callback - the callback of off. 739 * @throws { BusinessError } 201 - Permission denied. 740 * @throws { BusinessError } 202 - Non-system applications use system APIs. 741 * @throws { BusinessError } 401 - Parameter error. 742 * @throws { BusinessError } 2100001 - Invalid parameter value. 743 * @throws { BusinessError } 2100002 - Failed to connect to the service. 744 * @throws { BusinessError } 2100003 - System internal error. 745 * @syscap SystemCapability.Communication.NetManager.Core 746 * @systemapi Hide this for inner system use. 747 * @since 10 748 */ 749 /** 750 * Unregister uid rule change listener. 751 * @permission ohos.permission.MANAGE_NET_STRATEGY 752 * @param { 'netUidRuleChange' } type - Indicates Event name. 753 * @param { Callback<NetUidRuleInfo> } callback - the callback of off. 754 * @throws { BusinessError } 201 - Permission denied. 755 * @throws { BusinessError } 202 - Non-system applications use system APIs. 756 * @throws { BusinessError } 401 - Parameter error. 757 * @throws { BusinessError } 2100001 - Invalid parameter value. 758 * @throws { BusinessError } 2100002 - Failed to connect to the service. 759 * @throws { BusinessError } 2100003 - System internal error. 760 * @syscap SystemCapability.Communication.NetManager.Core 761 * @systemapi Hide this for inner system use. 762 * @since 11 763 */ 764 function off(type: 'netUidRuleChange', callback?: Callback<NetUidRuleInfo>): void; 765 766 /** 767 * Register metered ifaces change listener. 768 * @permission ohos.permission.MANAGE_NET_STRATEGY 769 * @param { 'netMeteredIfacesChange' } type - Indicates Event name. 770 * @param { Callback<Array<string>> } callback - the callback of on. 771 * @throws { BusinessError } 201 - Permission denied. 772 * @throws { BusinessError } 202 - Non-system applications use system APIs. 773 * @throws { BusinessError } 401 - Parameter error. 774 * @throws { BusinessError } 2100001 - Invalid parameter value. 775 * @throws { BusinessError } 2100002 - Failed to connect to the service. 776 * @throws { BusinessError } 2100003 - System internal error. 777 * @syscap SystemCapability.Communication.NetManager.Core 778 * @systemapi Hide this for inner system use. 779 * @since 10 780 */ 781 function on(type: 'netMeteredIfacesChange', callback: Callback<Array<string>>): void; 782 783 /** 784 * Unregister metered ifaces change listener. 785 * @permission ohos.permission.MANAGE_NET_STRATEGY 786 * @param { 'netMeteredIfacesChange' } type - Indicates Event name. 787 * @param { Callback<Array<string>> } callback - the callback of off. 788 * @throws { BusinessError } 201 - Permission denied. 789 * @throws { BusinessError } 202 - Non-system applications use system APIs. 790 * @throws { BusinessError } 401 - Parameter error. 791 * @throws { BusinessError } 2100001 - Invalid parameter value. 792 * @throws { BusinessError } 2100002 - Failed to connect to the service. 793 * @throws { BusinessError } 2100003 - System internal error. 794 * @syscap SystemCapability.Communication.NetManager.Core 795 * @systemapi Hide this for inner system use. 796 * @since 10 797 */ 798 function off(type: 'netMeteredIfacesChange', callback?: Callback<Array<string>>): void; 799 800 /** 801 * Register quota policies change listener. 802 * @permission ohos.permission.MANAGE_NET_STRATEGY 803 * @param { 'netQuotaPolicyChange' } type - Indicates Event name. 804 * @param { Callback<Array<NetQuotaPolicy>> } callback the callback of on. 805 * @throws { BusinessError } 201 - Permission denied. 806 * @throws { BusinessError } 202 - Non-system applications use system APIs. 807 * @throws { BusinessError } 401 - Parameter error. 808 * @throws { BusinessError } 2100001 - Invalid parameter value. 809 * @throws { BusinessError } 2100002 - Failed to connect to the service. 810 * @throws { BusinessError } 2100003 - System internal error. 811 * @syscap SystemCapability.Communication.NetManager.Core 812 * @systemapi Hide this for inner system use. 813 * @since 10 814 */ 815 function on(type: 'netQuotaPolicyChange', callback: Callback<Array<NetQuotaPolicy>>): void; 816 817 /** 818 * Unregister quota policies change listener. 819 * @permission ohos.permission.MANAGE_NET_STRATEGY 820 * @param { 'netQuotaPolicyChange' } type - Indicates Event name. 821 * @param { Callback<Array<NetQuotaPolicy>> } callback - the callback of off. 822 * @throws { BusinessError } 201 - Permission denied. 823 * @throws { BusinessError } 202 - Non-system applications use system APIs. 824 * @throws { BusinessError } 401 - Parameter error. 825 * @throws { BusinessError } 2100001 - Invalid parameter value. 826 * @throws { BusinessError } 2100002 - Failed to connect to the service. 827 * @throws { BusinessError } 2100003 - System internal error. 828 * @syscap SystemCapability.Communication.NetManager.Core 829 * @systemapi Hide this for inner system use. 830 * @since 10 831 */ 832 function off(type: 'netQuotaPolicyChange', callback?: Callback<Array<NetQuotaPolicy>>): void; 833 834 /** 835 * Register network background policy change listener. 836 * @permission ohos.permission.MANAGE_NET_STRATEGY 837 * @param { 'netBackgroundPolicyChange' } type - Indicates Event name. 838 * @param { Callback<boolean> } callback - the callback of on. 839 * @throws { BusinessError } 201 - Permission denied. 840 * @throws { BusinessError } 202 - Non-system applications use system APIs. 841 * @throws { BusinessError } 401 - Parameter error. 842 * @throws { BusinessError } 2100001 - Invalid parameter value. 843 * @throws { BusinessError } 2100002 - Failed to connect to the service. 844 * @throws { BusinessError } 2100003 - System internal error. 845 * @syscap SystemCapability.Communication.NetManager.Core 846 * @systemapi Hide this for inner system use. 847 * @since 10 848 */ 849 function on(type: 'netBackgroundPolicyChange', callback: Callback<boolean>): void; 850 851 /** 852 * Unregister network background policy change listener. 853 * @permission ohos.permission.MANAGE_NET_STRATEGY 854 * @param { 'netBackgroundPolicyChange' } type - Indicates Event name. 855 * @param { Callback<boolean> } callback - the callback of off. 856 * @throws { BusinessError } 201 - Permission denied. 857 * @throws { BusinessError } 202 - Non-system applications use system APIs. 858 * @throws { BusinessError } 401 - Parameter error. 859 * @throws { BusinessError } 2100001 - Invalid parameter value. 860 * @throws { BusinessError } 2100002 - Failed to connect to the service. 861 * @throws { BusinessError } 2100003 - System internal error. 862 * @syscap SystemCapability.Communication.NetManager.Core 863 * @systemapi Hide this for inner system use. 864 * @since 10 865 */ 866 function off(type: 'netBackgroundPolicyChange', callback?: Callback<boolean>): void; 867 868 /** 869 * Indicate whether the application can use metered networks in background. 870 * @enum {number} 871 * @syscap SystemCapability.Communication.NetManager.Core 872 * @systemapi Hide this for inner system use. 873 * @since 10 874 */ 875 export enum NetBackgroundPolicy { 876 /** 877 * Default value. 878 * @syscap SystemCapability.Communication.NetManager.Core 879 * @systemapi Hide this for inner system use. 880 * @since 10 881 */ 882 NET_BACKGROUND_POLICY_NONE = 0, 883 884 /** 885 * Apps can use metered networks on background. 886 * @syscap SystemCapability.Communication.NetManager.Core 887 * @systemapi Hide this for inner system use. 888 * @since 10 889 */ 890 NET_BACKGROUND_POLICY_ENABLE = 1, 891 892 /** 893 * Apps can't use metered networks on background. 894 * @syscap SystemCapability.Communication.NetManager.Core 895 * @systemapi Hide this for inner system use. 896 * @since 10 897 */ 898 NET_BACKGROUND_POLICY_DISABLE = 2, 899 900 /** 901 * Only apps in trustlist can use metered networks on background. 902 * @syscap SystemCapability.Communication.NetManager.Core 903 * @systemapi Hide this for inner system use. 904 * @since 10 905 */ 906 NET_BACKGROUND_POLICY_TRUSTLIST = 3, 907 } 908 909 /** 910 * Net quota policies, including matching network rule usage periods, restrictions, and warnings. 911 * @interface NetQuotaPolicy 912 * @syscap SystemCapability.Communication.NetManager.Core 913 * @systemapi Hide this for inner system use. 914 * @since 10 915 */ 916 export interface NetQuotaPolicy { 917 /** 918 * The matching rules of network quota policies. 919 * @type {NetworkMatchRule} 920 * @syscap SystemCapability.Communication.NetManager.Core 921 * @systemapi Hide this for inner system use. 922 * @since 10 923 */ 924 networkMatchRule: NetworkMatchRule; 925 926 /** 927 * Policies that limit network quota. 928 * @type {QuotaPolicy} 929 * @syscap SystemCapability.Communication.NetManager.Core 930 * @systemapi Hide this for inner system use. 931 * @since 10 932 */ 933 quotaPolicy: QuotaPolicy; 934 } 935 936 /** 937 * Policies that limit network quota. 938 * @interface QuotaPolicy 939 * @syscap SystemCapability.Communication.NetManager.Core 940 * @systemapi Hide this for inner system use. 941 * @since 10 942 */ 943 export interface QuotaPolicy { 944 /** 945 * The period and the start time for quota policy, default: "M1" (Monthly cycle). 946 * @type {string} 947 * @syscap SystemCapability.Communication.NetManager.Core 948 * @systemapi Hide this for inner system use. 949 * @since 10 950 */ 951 periodDuration: string; 952 953 /** 954 * The warning threshold of traffic, default: DATA_USAGE_UNKNOWN. 955 * @type {number} 956 * @syscap SystemCapability.Communication.NetManager.Core 957 * @systemapi Hide this for inner system use. 958 * @since 10 959 */ 960 warningBytes: number; 961 962 /** 963 * The limit threshold of traffic, default: DATA_USAGE_UNKNOWN. 964 * @type {number} 965 * @syscap SystemCapability.Communication.NetManager.Core 966 * @systemapi Hide this for inner system use. 967 * @since 10 968 */ 969 limitBytes: number; 970 971 /** 972 * Is metered network or not. 973 * @type {boolean} 974 * @syscap SystemCapability.Communication.NetManager.Core 975 * @systemapi Hide this for inner system use. 976 * @since 10 977 */ 978 metered: boolean; 979 980 /** 981 * The action while the used bytes reach the limit, see {@link LimitAction}. 982 * @type {LimitAction} 983 * @syscap SystemCapability.Communication.NetManager.Core 984 * @systemapi Hide this for inner system use. 985 * @since 10 986 */ 987 limitAction: LimitAction; 988 989 /** 990 * The time of the last warning reminder. For notifying only, default: REMIND_NEVER. 991 * @type {?number} 992 * @syscap SystemCapability.Communication.NetManager.Core 993 * @systemapi Hide this for inner system use. 994 * @since 10 995 */ 996 lastWarningRemind?: number; 997 998 /** 999 * The time of the last limit reminder. For notifying only, default: REMIND_NEVER. 1000 * @type {?number} 1001 * @syscap SystemCapability.Communication.NetManager.Core 1002 * @systemapi Hide this for inner system use. 1003 * @since 10 1004 */ 1005 lastLimitRemind?: number; 1006 } 1007 1008 /** 1009 * The matching rules of network quota policies. 1010 * @interface NetworkMatchRule 1011 * @syscap SystemCapability.Communication.NetManager.Core 1012 * @systemapi Hide this for inner system use. 1013 * @since 10 1014 */ 1015 export interface NetworkMatchRule { 1016 /** 1017 * netType see {@link NetBearType}. 1018 * @type {NetBearType} 1019 * @syscap SystemCapability.Communication.NetManager.Core 1020 * @systemapi Hide this for inner system use. 1021 * @since 10 1022 */ 1023 netType: NetBearType; 1024 1025 /** 1026 * To specify the identity of network, such as different WLAN. 1027 * @type {string} 1028 * @syscap SystemCapability.Communication.NetManager.Core 1029 * @systemapi Hide this for inner system use. 1030 * @since 10 1031 */ 1032 identity: string; 1033 1034 /** 1035 * The ID of the target card, valid when netType is BEARER_CELLULAR. 1036 * @type {string} 1037 * @syscap SystemCapability.Communication.NetManager.Core 1038 * @systemapi Hide this for inner system use. 1039 * @since 10 1040 */ 1041 simId: string; 1042 } 1043 1044 /** 1045 * The interface is used to generate network unique identifiers. 1046 * @interface NetUidRuleInfo 1047 * @syscap SystemCapability.Communication.NetManager.Core 1048 * @systemapi Hide this for inner system use. 1049 * @since 11 1050 */ 1051 export interface NetUidRuleInfo { 1052 /** 1053 * The warning threshold of traffic, default: DATA_USAGE_UNKNOWN. 1054 * @type { number } 1055 * @syscap SystemCapability.Communication.NetManager.Core 1056 * @systemapi Hide this for inner system use. 1057 * @since 11 1058 */ 1059 uid: number; 1060 /** 1061 * Rules whether an uid can access to a metered or non-metered network. 1062 * @type { NetUidRule } 1063 * @syscap SystemCapability.Communication.NetManager.Core 1064 * @systemapi Hide this for inner system use. 1065 * @since 11 1066 */ 1067 rule: NetUidRule; 1068 } 1069 1070 /** 1071 * Callback function for registering network UID policy changes. 1072 * @interface NetUidPolicyInfo 1073 * @syscap SystemCapability.Communication.NetManager.Core 1074 * @systemapi Hide this for inner system use. 1075 * @since 11 1076 */ 1077 export interface NetUidPolicyInfo { 1078 /** 1079 * The warning threshold of traffic, default: DATA_USAGE_UNKNOWN. 1080 * @type { number } 1081 * @syscap SystemCapability.Communication.NetManager.Core 1082 * @systemapi Hide this for inner system use. 1083 * @since 11 1084 */ 1085 uid: number; 1086 /** 1087 * Uid Specifies the Internet access policy in background mode. 1088 * @type { NetUidPolicy } 1089 * @syscap SystemCapability.Communication.NetManager.Core 1090 * @systemapi Hide this for inner system use. 1091 * @since 11 1092 */ 1093 policy: NetUidPolicy; 1094 } 1095 1096 /** 1097 * The action when quota policy hit the limit. 1098 * @enum {number} 1099 * @syscap SystemCapability.Communication.NetManager.Core 1100 * @systemapi Hide this for inner system use. 1101 * @since 10 1102 */ 1103 export enum LimitAction { 1104 /** 1105 * Default action, do nothing. 1106 * @syscap SystemCapability.Communication.NetManager.Core 1107 * @systemapi Hide this for inner system use. 1108 * @since 10 1109 */ 1110 LIMIT_ACTION_NONE = -1, 1111 1112 /** 1113 * When the quota policy reaches the limit, the system prohibits users from accessing the network. 1114 * @syscap SystemCapability.Communication.NetManager.Core 1115 * @systemapi Hide this for inner system use. 1116 * @since 10 1117 */ 1118 LIMIT_ACTION_ACCESS_DISABLED = 0, 1119 1120 /** 1121 * When the quota policy reaches the upper limit, the system notifies the user. 1122 * @syscap SystemCapability.Communication.NetManager.Core 1123 * @systemapi Hide this for inner system use. 1124 * @since 10 1125 */ 1126 LIMIT_ACTION_ALERT_ONLY = 1, 1127 } 1128 1129 /** 1130 * Rules whether an uid can access to a metered or non-metered network. 1131 * @enum {number} 1132 * @syscap SystemCapability.Communication.NetManager.Core 1133 * @systemapi Hide this for inner system use. 1134 * @since 10 1135 */ 1136 export enum NetUidRule { 1137 /** 1138 * Default uid rule. 1139 * @syscap SystemCapability.Communication.NetManager.Core 1140 * @systemapi Hide this for inner system use. 1141 * @since 10 1142 */ 1143 NET_RULE_NONE = 0, 1144 1145 /** 1146 * Allow traffic on metered networks while app is foreground. 1147 * @syscap SystemCapability.Communication.NetManager.Core 1148 * @systemapi Hide this for inner system use. 1149 * @since 10 1150 */ 1151 NET_RULE_ALLOW_METERED_FOREGROUND = 1 << 0, 1152 1153 /** 1154 * Allow traffic on metered network. 1155 * @syscap SystemCapability.Communication.NetManager.Core 1156 * @systemapi Hide this for inner system use. 1157 * @since 10 1158 */ 1159 NET_RULE_ALLOW_METERED = 1 << 1, 1160 1161 /** 1162 * Reject traffic on metered network. 1163 * @syscap SystemCapability.Communication.NetManager.Core 1164 * @systemapi Hide this for inner system use. 1165 * @since 10 1166 */ 1167 NET_RULE_REJECT_METERED = 1 << 2, 1168 1169 /** 1170 * Allow traffic on all network (metered or non-metered). 1171 * @syscap SystemCapability.Communication.NetManager.Core 1172 * @systemapi Hide this for inner system use. 1173 * @since 10 1174 */ 1175 NET_RULE_ALLOW_ALL = 1 << 5, 1176 1177 /** 1178 * Reject traffic on all network. 1179 * @syscap SystemCapability.Communication.NetManager.Core 1180 * @systemapi Hide this for inner system use. 1181 * @since 10 1182 */ 1183 NET_RULE_REJECT_ALL = 1 << 6, 1184 } 1185 1186 /** 1187 * Specify the remind type, see {@link updateRemindPolicy}. 1188 * @enum {number} 1189 * @syscap SystemCapability.Communication.NetManager.Core 1190 * @systemapi Hide this for inner system use. 1191 * @since 10 1192 */ 1193 export enum RemindType { 1194 /** 1195 * Warning alerts when the limit is reached. 1196 * @syscap SystemCapability.Communication.NetManager.Core 1197 * @systemapi Hide this for inner system use. 1198 * @since 10 1199 */ 1200 REMIND_TYPE_WARNING = 1, 1201 1202 /** 1203 * Limit alerts when the limit is reached. 1204 * @syscap SystemCapability.Communication.NetManager.Core 1205 * @systemapi Hide this for inner system use. 1206 * @since 10 1207 */ 1208 REMIND_TYPE_LIMIT = 2, 1209 } 1210 1211 /** 1212 * Uid Specifies the Internet access policy in background mode. 1213 * @enum {number} 1214 * @syscap SystemCapability.Communication.NetManager.Core 1215 * @systemapi Hide this for inner system use. 1216 * @since 10 1217 */ 1218 export enum NetUidPolicy { 1219 /** 1220 * Default net policy. 1221 * @syscap SystemCapability.Communication.NetManager.Core 1222 * @systemapi Hide this for inner system use. 1223 * @since 10 1224 */ 1225 NET_POLICY_NONE = 0, 1226 1227 /** 1228 * Allow on metered networks when app in background. 1229 * @syscap SystemCapability.Communication.NetManager.Core 1230 * @systemapi Hide this for inner system use. 1231 * @since 10 1232 */ 1233 NET_POLICY_ALLOW_METERED_BACKGROUND = 1 << 0, 1234 1235 /** 1236 * Reject on metered networks when app in background. 1237 * @syscap SystemCapability.Communication.NetManager.Core 1238 * @systemapi Hide this for inner system use. 1239 * @since 10 1240 */ 1241 NET_POLICY_REJECT_METERED_BACKGROUND = 1 << 1, 1242 } 1243 1244 /** 1245 * Network policies that limit the specified UID of application to access the network. 1246 * @interface NetworkAccessPolicy 1247 * @syscap SystemCapability.Communication.NetManager.Core 1248 * @systemapi Hide this for inner system use. 1249 * @since 12 1250 */ 1251 export interface NetworkAccessPolicy { 1252 /** 1253 * Indicate whether the application can be allowed to access the network by wifi. 1254 * @type { ?boolean } 1255 * @syscap SystemCapability.Communication.NetManager.Core 1256 * @systemapi Hide this for inner system use. 1257 * @since 12 1258 */ 1259 allowWiFi?: boolean; 1260 /** 1261 * Indicate whether the application can be allowed to access the network by cellular. 1262 * @type { ?boolean } 1263 * @syscap SystemCapability.Communication.NetManager.Core 1264 * @systemapi Hide this for inner system use. 1265 * @since 12 1266 */ 1267 allowCellular?: boolean; 1268 /** 1269 * Indicate whether the application can be always allowed to access the network by wifi and users cannot set it. 1270 * @type { ?boolean } 1271 * @syscap SystemCapability.Communication.NetManager.Core 1272 * @systemapi Hide this for inner system use. 1273 * @since 18 1274 */ 1275 alwaysAllowWiFi?: boolean; 1276 /** 1277 * Indicate whether the application can be always allowed to access the network by cellular and users cannot set it. 1278 * @type { ?boolean } 1279 * @syscap SystemCapability.Communication.NetManager.Core 1280 * @systemapi Hide this for inner system use. 1281 * @since 18 1282 */ 1283 alwaysAllowCellular?: boolean; 1284 } 1285 1286 /** 1287 * Provides the container definition for network access policy key-value pairs. 1288 * @interface UidNetworkAccessPolicy 1289 * @syscap SystemCapability.Communication.NetManager.Core 1290 * @systemapi Hide this for inner system use. 1291 * @since 12 1292 */ 1293 export interface UidNetworkAccessPolicy { 1294 /** 1295 * @type key:value pair. Key indicates the specified UID of an application. For value, see @NetworkAccessPolicy. 1296 * @syscap SystemCapability.Communication.NetManager.Core 1297 * @systemapi Hide this for inner system use. 1298 * @since 12 1299 */ 1300 [uid: string]: NetworkAccessPolicy; 1301 } 1302} 1303 1304export default policy; 1305