From 435565124b40429d0a7c284517b6e7567aaf6795 Mon Sep 17 00:00:00 2001 From: jyh926 Date: Tue, 20 Jun 2023 11:52:26 +0800 Subject: [PATCH 1/3] add net policy js api Signed-off-by: jyh926 --- api/@ohos.net.policy.d.ts | 1047 +++++++++++++++++ .../plugin/dictionaries_supplementary.txt | 1 + 2 files changed, 1048 insertions(+) create mode 100644 api/@ohos.net.policy.d.ts diff --git a/api/@ohos.net.policy.d.ts b/api/@ohos.net.policy.d.ts new file mode 100644 index 000000000..160ad44a1 --- /dev/null +++ b/api/@ohos.net.policy.d.ts @@ -0,0 +1,1047 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { AsyncCallback, Callback } from "./@ohos.base"; +import connection from './@ohos.net.connection'; + +/** + * Provides interfaces to manage network policy rules. + * @namespace policy + * @syscap SystemCapability.Communication.NetManager.Core + * @since 10 + */ +declare namespace policy { + type NetBearType = connection.NetBearType; + + /** + * Control if applications can use data on background. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { boolean } isAllowed - Allow applications to use data on background. + * @param { AsyncCallback } callback - the callback of setBackgroundAllowed. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function setBackgroundAllowed(isAllowed: boolean, callback: AsyncCallback): void; + + /** + * Control if applications can use data on background. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { boolean } isAllowed - Allow applications to use data on background. + * @returns { Promise } The promise returned by the function. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function setBackgroundAllowed(isAllowed: boolean): Promise; + + /** + * Get the status if applications can use data on background. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { AsyncCallback } callback - the callback of allowed or not to use data on background. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function isBackgroundAllowed(callback: AsyncCallback): void; + + /** + * Get the status if applications can use data on background. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @returns { Promise } The promise returned by the function. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function isBackgroundAllowed(): Promise; + + /** + * Get the background network policy for the specified uid. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { number } uid - The specified UID of application. + * @param { AsyncCallback } callback - the callback of getBackgroundPolicyByUid. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function getBackgroundPolicyByUid(uid: number, callback: AsyncCallback): void; + + /** + * Get the background network policy for the specified uid. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { number } uid - The specified UID of application. + * @returns { Promise } The promise returned by the function. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function getBackgroundPolicyByUid(uid: number): Promise; + + /** + * Set the policy for the specified UID. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { number } uid - the specified UID of application. + * @param { NetUidPolicy } policy - the policy of the current UID of application.For details, see {@link NetUidPolicy}. + * @param { AsyncCallback } callback - the callback of setPolicyByUid. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function setPolicyByUid(uid: number, policy: NetUidPolicy, callback: AsyncCallback): void; + + /** + * Set the policy for the specified UID. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { number } uid - the specified UID of application. + * @param { NetUidPolicy } policy - the policy of the current UID of application.For details, see {@link NetUidPolicy}. + * @returns { Promise } The promise returned by the function. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function setPolicyByUid(uid: number, policy: NetUidPolicy): Promise; + + /** + * Query the policy of the specified UID. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { number } uid - the specified UID of application. + * @param { AsyncCallback } callback - the callback of getPolicyByUid. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function getPolicyByUid(uid: number, callback: AsyncCallback): void; + + /** + * Query the policy of the specified UID. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { number } uid - the specified UID of application. + * @returns { Promise } The promise returned by the function. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function getPolicyByUid(uid: number): Promise; + + /** + * Query the application UIDs of the specified policy. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { NetUidPolicy } policy - the policy of the current UID of application.For details, see {@link NetUidPolicy}. + * @param { AsyncCallback> } callback - the callback of getUidsByPolicy. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function getUidsByPolicy(policy: NetUidPolicy, callback: AsyncCallback>): void; + + /** + * Query the application UIDs of the specified policy. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { NetUidPolicy } policy - the policy of the current UID of application.For details, see {@link NetUidPolicy}. + * @returns { Promise> } The promise returned by the function. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function getUidsByPolicy(policy: NetUidPolicy): Promise>; + + /** + * Get the status whether the uid app can access the metered network or non-metered network. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { number } uid - The specified UID of application. + * @param { boolean } isMetered - Indicates metered network or non-metered network. + * @param { AsyncCallback } callback - the callback of isUidNetAllowed. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function isUidNetAllowed(uid: number, isMetered: boolean, callback: AsyncCallback): void; + + /** + * Get the status whether the uid app can access the metered network or non-metered network. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { number } uid - The specified UID of application. + * @param { boolean } isMetered - Indicates metered network or non-metered network. + * @returns { Promise } The promise returned by the function. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function isUidNetAllowed(uid: number, isMetered: boolean): Promise; + + /** + * Get the status of whether the specified uid can access the specified network. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { number } uid - The specified UID of application. + * @param { string } iface - The specified network interface name. + * @param { AsyncCallback } callback - the callback of isUidNetAllowed. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function isUidNetAllowed(uid: number, iface: string, callback: AsyncCallback): void; + + /** + * Get the status of whether the specified uid can access the specified network. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { number } uid - The specified UID of application. + * @param { string } iface - The specified network interface name. + * @returns { Promise } The promise returned by the function. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function isUidNetAllowed(uid: number, iface: string): Promise; + + /** + * Set metered network quota policies. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { Array } quotaPolicies - Indicates {@link NetQuotaPolicy}. + * @param { AsyncCallback } callback - the callback of setNetQuotaPolicies. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function setNetQuotaPolicies(quotaPolicies: Array, callback: AsyncCallback): void; + + /** + * Set metered network quota policies. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { Array } quotaPolicies - Indicates {@link NetQuotaPolicy}. + * @returns { Promise } The promise returned by the function. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function setNetQuotaPolicies(quotaPolicies: Array): Promise; + + /** + * Get metered network quota policies. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { AsyncCallback> } callback - the callback of getNetQuotaPolicies. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function getNetQuotaPolicies(callback: AsyncCallback>): void; + + /** + * Get metered network quota policies. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @returns { Promise> } The promise returned by the function. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function getNetQuotaPolicies(): Promise>; + + /** + * Update the policy when the quota reaches the upper limit. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { NetBearType } netType - {@link NetBearType}. + * @param { string } simId - Specify the matched simId of quota policy when netType is cellular. + * @param { RemindType } remindType - {@link RemindType}. + * @param { AsyncCallback } callback - the callback of updateRemindPolicy. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function updateRemindPolicy(netType: NetBearType, simId: string, remindType: RemindType, callback: AsyncCallback): void; + + /** + * Update the policy when the quota reaches the upper limit. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { NetBearType } netType - {@link NetBearType}. + * @param { string } simId - Specify the matched simId of quota policy when netType is cellular. + * @param { RemindType } remindType - {@link RemindType}. + * @returns { Promise } The promise returned by the function. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function updateRemindPolicy(netType: NetBearType, simId: string, remindType: RemindType): Promise; + + /** + * Set the list of uids that are allowed to access the Internet in hibernation mode. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { Array } uids - The specified uids of application. + * @param { boolean } isAllowed - Whether to allow Uids in the list to access the Internet. + * @param { AsyncCallback } callback - the callback of setDeviceIdleTrustlist. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function setDeviceIdleTrustlist(uids: Array, isAllowed: boolean, callback: AsyncCallback): void; + + /** + * Set the list of uids that are allowed to access the Internet in hibernation mode. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { Array } uids - The specified uids of application. + * @param { boolean } isAllowed - Whether to allow Uids in the list to access the Internet. + * @returns { Promise } The promise returned by the function. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function setDeviceIdleTrustlist(uids: Array, isAllowed: boolean): Promise; + + /** + * Obtain the list of uids that are allowed to access the Internet in hibernation mode. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { AsyncCallback> } callback - the callback of getDeviceIdleTrustlist. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function getDeviceIdleTrustlist(callback: AsyncCallback>): void; + + /** + * Obtain the list of uids that are allowed to access the Internet in hibernation mode. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @returns { Promise> } The promise returned by the function. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function getDeviceIdleTrustlist(): Promise>; + + /** + * Set the list of uids that are allowed to access the Internet in power saving mode. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { Array } uids - The specified uids of application. + * @param { boolean } isAllowed - Whether to allow Uids in the list to access the Internet. + * @param { AsyncCallback } callback - the callback of setPowerSaveTrustlist. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function setPowerSaveTrustlist(uids: Array, isAllowed: boolean, callback: AsyncCallback): void; + + /** + * Set the list of uids that are allowed to access the Internet in power saving mode. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { Array } uids - The specified uids of application. + * @param { boolean } isAllowed - Whether to allow Uids in the list to access the Internet. + * @returns { Promise } The promise returned by the function. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function setPowerSaveTrustlist(uids: Array, isAllowed: boolean): Promise; + + /** + * Obtain the list of uids that are allowed to access the Internet in power saving mode. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { AsyncCallback> } callback - the callback of UIDs list. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function getPowerSaveTrustlist(callback: AsyncCallback>): void; + + /** + * Obtain the list of uids that are allowed to access the Internet in power saving mode. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @returns { Promise> } The promise returned by the function. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function getPowerSaveTrustlist(): Promise>; + + /** + * Reset network policies\rules\quota policies\firewall rules. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { string } simId - Specify the matched simId of quota policy. + * @param { AsyncCallback } callback - the callback of resetPolicies. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function resetPolicies(simId: string, callback: AsyncCallback): void; + + /** + * Reset network policies\rules\quota policies\firewall rules. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { string } simId - Specify the matched simId of quota policy. + * @returns { Promise } The promise returned by the function. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function resetPolicies(simId: string): Promise; + + /** + * Register uid policy change listener. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { 'netUidPolicyChange' } type - Indicates Event name. + * @param { Callback<{ uid: number, policy: NetUidPolicy }> } callback - the callback of on. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function on(type: 'netUidPolicyChange', callback: Callback<{ uid: number, policy: NetUidPolicy }>): void; + + /** + * Unregister uid policy change listener. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { 'netUidPolicyChange' } type - Indicates Event name. + * @param { Callback<{ uid: number, policy: NetUidPolicy }> } callback - the callback of off. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function off(type: 'netUidPolicyChange', callback?: Callback<{ uid: number, policy: NetUidPolicy }>): void; + + /** + * Register uid rule change listener. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { 'netUidRuleChange' } type - Indicates Event name. + * @param { Callback<{ uid: number, rule: NetUidRule }> } callback - the callback of on. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function on(type: 'netUidRuleChange', callback: Callback<{ uid: number, rule: NetUidRule }>): void; + + /** + * Unregister uid rule change listener. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { 'netUidRuleChange' } type - Indicates Event name. + * @param { Callback<{ uid: number, rule: NetUidRule }> } callback - the callback of off. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function off(type: 'netUidRuleChange', callback?: Callback<{ uid: number, rule: NetUidRule }>): void; + + /** + * Register metered ifaces change listener. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { 'netMeteredIfacesChange' } type - Indicates Event name. + * @param { Callback> } callback - the callback of on. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function on(type: 'netMeteredIfacesChange', callback: Callback>): void; + + /** + * Unregister metered ifaces change listener. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { 'netMeteredIfacesChange' } type - Indicates Event name. + * @param { Callback> } callback - the callback of off. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function off(type: 'netMeteredIfacesChange', callback?: Callback>): void; + + /** + * Register quota policies change listener. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { 'netQuotaPolicyChange' } type - Indicates Event name. + * @param { Callback> } callback the callback of on. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function on(type: 'netQuotaPolicyChange', callback: Callback>): void; + + /** + * Unregister quota policies change listener. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { 'netQuotaPolicyChange' } type - Indicates Event name. + * @param { Callback> } callback - the callback of off. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function off(type: 'netQuotaPolicyChange', callback?: Callback>): void; + + /** + * Register network background policy change listener. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { 'netBackgroundPolicyChange' } type - Indicates Event name. + * @param { Callback } callback - the callback of on. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function on(type: 'netBackgroundPolicyChange', callback: Callback): void; + + /** + * Unregister network background policy change listener. + * @permission ohos.permission.MANAGE_NET_STRATEGY + * @param { 'netBackgroundPolicyChange' } type - Indicates Event name. + * @param { Callback } callback - the callback of off. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Non-system applications use system APIs. + * @throws { BusinessError } 401 - Parameter error. + * @throws { BusinessError } 2100001 - Invalid parameter value. + * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service. + * @throws { BusinessError } 2100003 - System internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + function off(type: 'netBackgroundPolicyChange', callback?: Callback): void; + + /** + * Indicate whether the application can use metered networks in background. + * @enum {number} + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + export enum NetBackgroundPolicy { + /** + * Default value. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + NET_BACKGROUND_POLICY_NONE = 0, + + /** + * Apps can use metered networks on background. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + NET_BACKGROUND_POLICY_ENABLE = 1, + + /** + * Apps can't use metered networks on background. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + NET_BACKGROUND_POLICY_DISABLE = 2, + + /** + * Only apps in allow list can use metered networks on background. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + NET_BACKGROUND_POLICY_TRUSTLIST = 3, + } + + /** + * Net quota policies, including matching network rule usage periods, restrictions, and warnings. + * @interface NetQuotaPolicy + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + export interface NetQuotaPolicy { + /** + * The matching rules of network quota policies. + * @type {NetworkMatchRule} + * @systemapi Hide this for inner system use. + * @since 10 + */ + networkMatchRule: NetworkMatchRule; + + /** + * Policies that limit network quota. + * @type {QuotaPolicy} + * @systemapi Hide this for inner system use. + * @since 10 + */ + quotaPolicy: QuotaPolicy; + } + + /** + * Policies that limit network quota. + * @interface QuotaPolicy + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + export interface QuotaPolicy { + /** + * The period and the start time for quota policy, default: "M1" (Monthly cycle). + * @type {string} + * @systemapi Hide this for inner system use. + * @since 10 + */ + periodDuration: string; + + /** + * The warning threshold of traffic, default: DATA_USAGE_UNKNOWN. + * @type {number} + * @systemapi Hide this for inner system use. + * @since 10 + */ + warningBytes: number; + + /** + * The limit threshold of traffic, default: DATA_USAGE_UNKNOWN. + * @type {number} + * @systemapi Hide this for inner system use. + * @since 10 + */ + limitBytes: number; + + /** + * Is metered network or not. + * @type {number} + * @systemapi Hide this for inner system use. + * @since 10 + */ + metered: boolean; + + /** + * The action while the used bytes reach the limit, see {@link LimitAction}. + * @type {number} + * @systemapi Hide this for inner system use. + * @since 10 + */ + limitAction: LimitAction; + + /** + * The time of the last warning reminder. For notifying only, default: REMIND_NEVER. + * @type {number} + * @systemapi Hide this for inner system use. + * @since 10 + */ + lastWarningRemind?: number; + + /** + * The time of the last limit reminder. For notifying only, default: REMIND_NEVER. + * @type {number} + * @systemapi Hide this for inner system use. + * @since 10 + */ + lastLimitRemind?: number; + } + + /** + * The matching rules of network quota policies. + * @interface NetworkMatchRule + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + export interface NetworkMatchRule { + /** + * netType see {@link NetBearType}. + * @type {NetBearType} + * @systemapi Hide this for inner system use. + * @since 10 + */ + netType: NetBearType; + + /** + * To specify the identity of network, such as different WLAN. + * @type {string} + * @systemapi Hide this for inner system use. + * @since 10 + */ + identity: string; + + /** + * The ID of the target card, valid when netType is BEARER_CELLULAR. + * @type {string} + * @systemapi Hide this for inner system use. + * @since 10 + */ + simId: string; + } + + /** + * The action when quota policy hit the limit. + * @enum {number} + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + export enum LimitAction { + /** + * Default action, do nothing. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + LIMIT_ACTION_NONE = -1, + + /** + * When the quota policy reaches the limit, the system prohibits users from accessing the network. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + LIMIT_ACTION_ACCESS_DISABLED = 0, + + /** + * When the quota policy reaches the upper limit, the system notifies the user. + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + LIMIT_ACTION_ALERT_ONLY = 1, + } + + /** + * Rules whether an uid can access to a metered or non-metered network. + * @enum {number} + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + export enum NetUidRule { + /** + * Default uid rule. + * @systemapi Hide this for inner system use. + * @since 10 + */ + NET_RULE_NONE = 0, + + /** + * Allow traffic on metered networks while app is foreground. + * @systemapi Hide this for inner system use. + * @since 10 + */ + NET_RULE_ALLOW_METERED_FOREGROUND = 1 << 0, + + /** + * Allow traffic on metered network. + * @systemapi Hide this for inner system use. + * @since 10 + */ + NET_RULE_ALLOW_METERED = 1 << 1, + + /** + * Reject traffic on metered network. + * @systemapi Hide this for inner system use. + * @since 10 + */ + NET_RULE_REJECT_METERED = 1 << 2, + + /** + * Allow traffic on all network (metered or non-metered). + * @systemapi Hide this for inner system use. + * @since 10 + */ + NET_RULE_ALLOW_ALL = 1 << 5, + + /** + * Reject traffic on all network. + * @systemapi Hide this for inner system use. + * @since 10 + */ + NET_RULE_REJECT_ALL = 1 << 6, + } + + /** + * Specify the remind type, see {@link updateRemindPolicy}. + * @enum {number} + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + export enum RemindType { + /** + * Warning alerts when the limit is reached. + * @systemapi Hide this for inner system use. + * @since 10 + */ + REMIND_TYPE_WARNING = 1, + + /** + * Limit alerts when the limit is reached. + * @systemapi Hide this for inner system use. + * @since 10 + */ + REMIND_TYPE_LIMIT = 2, + } + + /** + * Uid Specifies the Internet access policy in background mode. + * @enum {number} + * @syscap SystemCapability.Communication.NetManager.Core + * @systemapi Hide this for inner system use. + * @since 10 + */ + export enum NetUidPolicy { + /** + * Default net policy. + * @systemapi Hide this for inner system use. + * @since 10 + */ + NET_POLICY_NONE = 0, + + /** + * Allow on metered networks when app in background. + * @systemapi Hide this for inner system use. + * @since 10 + */ + NET_POLICY_ALLOW_METERED_BACKGROUND = 1 << 0, + + /** + * Reject on metered networks when app in background. + * @systemapi Hide this for inner system use. + * @since 10 + */ + NET_POLICY_REJECT_METERED_BACKGROUND = 1 << 1, + } +} + +export default policy; \ No newline at end of file diff --git a/build-tools/api_check_plugin/plugin/dictionaries_supplementary.txt b/build-tools/api_check_plugin/plugin/dictionaries_supplementary.txt index 32c5fc982..ef2113a65 100644 --- a/build-tools/api_check_plugin/plugin/dictionaries_supplementary.txt +++ b/build-tools/api_check_plugin/plugin/dictionaries_supplementary.txt @@ -720,6 +720,7 @@ tsbundle ttls tunneled txpower +trustlist uarfcn ubset ucs From 0cd8adbd77c4b26ccc38dfd2a0d31713eb7fb9c8 Mon Sep 17 00:00:00 2001 From: jiayanhong-hw Date: Tue, 20 Jun 2023 03:56:27 +0000 Subject: [PATCH 2/3] update api/@ohos.net.policy.d.ts. Signed-off-by: jiayanhong-hw --- api/@ohos.net.policy.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/@ohos.net.policy.d.ts b/api/@ohos.net.policy.d.ts index 160ad44a1..e7e1ba370 100644 --- a/api/@ohos.net.policy.d.ts +++ b/api/@ohos.net.policy.d.ts @@ -13,7 +13,7 @@ * limitations under the License. */ -import { AsyncCallback, Callback } from "./@ohos.base"; +import { AsyncCallback, Callback } from './@ohos.base'; import connection from './@ohos.net.connection'; /** @@ -775,7 +775,7 @@ declare namespace policy { NET_BACKGROUND_POLICY_DISABLE = 2, /** - * Only apps in allow list can use metered networks on background. + * Only apps in trustlist can use metered networks on background. * @syscap SystemCapability.Communication.NetManager.Core * @systemapi Hide this for inner system use. * @since 10 From 5b8dcaa81cebe6c1673e775330679e2a03e4ee84 Mon Sep 17 00:00:00 2001 From: jiayanhong-hw Date: Tue, 20 Jun 2023 03:57:15 +0000 Subject: [PATCH 3/3] update build-tools/api_check_plugin/plugin/dictionaries_supplementary.txt. Signed-off-by: jiayanhong-hw --- .../api_check_plugin/plugin/dictionaries_supplementary.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-tools/api_check_plugin/plugin/dictionaries_supplementary.txt b/build-tools/api_check_plugin/plugin/dictionaries_supplementary.txt index ef2113a65..6a6bbe93b 100644 --- a/build-tools/api_check_plugin/plugin/dictionaries_supplementary.txt +++ b/build-tools/api_check_plugin/plugin/dictionaries_supplementary.txt @@ -716,11 +716,11 @@ trashed traversed traverses truncates +trustlist tsbundle ttls tunneled txpower -trustlist uarfcn ubset ucs