1b1b8bc3fSopenharmony_ci/*
2b1b8bc3fSopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd.
3b1b8bc3fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4b1b8bc3fSopenharmony_ci * you may not use this file except in compliance with the License.
5b1b8bc3fSopenharmony_ci * You may obtain a copy of the License at
6b1b8bc3fSopenharmony_ci *
7b1b8bc3fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8b1b8bc3fSopenharmony_ci *
9b1b8bc3fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10b1b8bc3fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11b1b8bc3fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12b1b8bc3fSopenharmony_ci * See the License for the specific language governing permissions and
13b1b8bc3fSopenharmony_ci * limitations under the License.
14b1b8bc3fSopenharmony_ci */
15b1b8bc3fSopenharmony_ci
16b1b8bc3fSopenharmony_ciimport { AsyncCallback, Callback } from './basic';
17b1b8bc3fSopenharmony_ciimport connection from './@ohos.net.connection';
18b1b8bc3fSopenharmony_ci
19b1b8bc3fSopenharmony_ci/**
20b1b8bc3fSopenharmony_ci * Provides interfaces to manage network policy rules.
21b1b8bc3fSopenharmony_ci *
22b1b8bc3fSopenharmony_ci * @since 9
23b1b8bc3fSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.Core
24b1b8bc3fSopenharmony_ci */
25b1b8bc3fSopenharmony_cideclare namespace policy {
26b1b8bc3fSopenharmony_ci  type NetBearType = connection.NetBearType;
27b1b8bc3fSopenharmony_ci
28b1b8bc3fSopenharmony_ci  /**
29b1b8bc3fSopenharmony_ci   * Control if applications can use data on background.
30b1b8bc3fSopenharmony_ci   *
31b1b8bc3fSopenharmony_ci   * @param isAllowed Allow applications to use data on background.
32b1b8bc3fSopenharmony_ci   * @permission ohos.permission.CONNECTIVITY_INTERNAL
33b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
34b1b8bc3fSopenharmony_ci   */
35b1b8bc3fSopenharmony_ci  function setBackgroundAllowed(isAllowed: boolean, callback: AsyncCallback<void>): void;
36b1b8bc3fSopenharmony_ci  function setBackgroundAllowed(isAllowed: boolean): Promise<void>;
37b1b8bc3fSopenharmony_ci
38b1b8bc3fSopenharmony_ci  /**
39b1b8bc3fSopenharmony_ci   * Get the status if applications can use data on background.
40b1b8bc3fSopenharmony_ci   *
41b1b8bc3fSopenharmony_ci   * @param callback Returns that it's allowed or not to use data on background.
42b1b8bc3fSopenharmony_ci   * @permission ohos.permission.CONNECTIVITY_INTERNAL
43b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
44b1b8bc3fSopenharmony_ci   */
45b1b8bc3fSopenharmony_ci  function isBackgroundAllowed(callback: AsyncCallback<boolean>): void;
46b1b8bc3fSopenharmony_ci  function isBackgroundAllowed(): Promise<boolean>;
47b1b8bc3fSopenharmony_ci
48b1b8bc3fSopenharmony_ci  /**
49b1b8bc3fSopenharmony_ci   * Set the policy for the specified UID.
50b1b8bc3fSopenharmony_ci   *
51b1b8bc3fSopenharmony_ci   * @param uid the specified UID of application.
52b1b8bc3fSopenharmony_ci   * @param policy the policy of the current UID of application.
53b1b8bc3fSopenharmony_ci   *      For details, see {@link NetUidPolicy}.
54b1b8bc3fSopenharmony_ci   * @permission ohos.permission.CONNECTIVITY_INTERNAL
55b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
56b1b8bc3fSopenharmony_ci   */
57b1b8bc3fSopenharmony_ci  function setPolicyByUid(uid: number, policy: NetUidPolicy, callback: AsyncCallback<void>): void;
58b1b8bc3fSopenharmony_ci  function setPolicyByUid(uid: number, policy: NetUidPolicy): Promise<void>;
59b1b8bc3fSopenharmony_ci
60b1b8bc3fSopenharmony_ci  /**
61b1b8bc3fSopenharmony_ci   * Query the policy of the specified UID.
62b1b8bc3fSopenharmony_ci   *
63b1b8bc3fSopenharmony_ci   * @param uid the specified UID of application.
64b1b8bc3fSopenharmony_ci   * @param callback Returns the policy of the current UID of application.
65b1b8bc3fSopenharmony_ci   *      For details, see {@link NetUidPolicy}.
66b1b8bc3fSopenharmony_ci   * @permission ohos.permission.CONNECTIVITY_INTERNAL
67b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
68b1b8bc3fSopenharmony_ci   */
69b1b8bc3fSopenharmony_ci  function getPolicyByUid(uid: number, callback: AsyncCallback<NetUidPolicy>): void;
70b1b8bc3fSopenharmony_ci  function getPolicyByUid(uid: number): Promise<NetUidPolicy>;
71b1b8bc3fSopenharmony_ci
72b1b8bc3fSopenharmony_ci  /**
73b1b8bc3fSopenharmony_ci   * Query the application UIDs of the specified policy.
74b1b8bc3fSopenharmony_ci   *
75b1b8bc3fSopenharmony_ci   * @param policy the policy of the current UID of application.
76b1b8bc3fSopenharmony_ci   *      For details, see {@link NetUidPolicy}.
77b1b8bc3fSopenharmony_ci   * @param callback Returns the UIDs of the specified policy.
78b1b8bc3fSopenharmony_ci   * @permission ohos.permission.CONNECTIVITY_INTERNAL
79b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
80b1b8bc3fSopenharmony_ci   */
81b1b8bc3fSopenharmony_ci  function getUidsByPolicy(policy: NetUidPolicy, callback: AsyncCallback<Array<number>>): void;
82b1b8bc3fSopenharmony_ci  function getUidsByPolicy(policy: NetUidPolicy): Promise<Array<number>>;
83b1b8bc3fSopenharmony_ci
84b1b8bc3fSopenharmony_ci  /**
85b1b8bc3fSopenharmony_ci   * Get network policies.
86b1b8bc3fSopenharmony_ci   *
87b1b8bc3fSopenharmony_ci   * @return See {@link NetQuotaPolicy}.
88b1b8bc3fSopenharmony_ci   * @permission ohos.permission.CONNECTIVITY_INTERNAL
89b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
90b1b8bc3fSopenharmony_ci   */
91b1b8bc3fSopenharmony_ci  function getNetQuotaPolicies(callback: AsyncCallback<Array<NetQuotaPolicy>>): void;
92b1b8bc3fSopenharmony_ci  function getNetQuotaPolicies(): Promise<Array<NetQuotaPolicy>>;
93b1b8bc3fSopenharmony_ci
94b1b8bc3fSopenharmony_ci  /**
95b1b8bc3fSopenharmony_ci   * Set network policies.
96b1b8bc3fSopenharmony_ci   *
97b1b8bc3fSopenharmony_ci   * @param quotaPolicies Indicates {@link NetQuotaPolicy}.
98b1b8bc3fSopenharmony_ci   * @permission ohos.permission.CONNECTIVITY_INTERNAL
99b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
100b1b8bc3fSopenharmony_ci   */
101b1b8bc3fSopenharmony_ci  function setNetQuotaPolicies(quotaPolicies: Array<NetQuotaPolicy>, callback: AsyncCallback<void>): void;
102b1b8bc3fSopenharmony_ci  function setNetQuotaPolicies(quotaPolicies: Array<NetQuotaPolicy>): Promise<void>;
103b1b8bc3fSopenharmony_ci
104b1b8bc3fSopenharmony_ci  /**
105b1b8bc3fSopenharmony_ci   * Reset the specified network management policy.
106b1b8bc3fSopenharmony_ci   *
107b1b8bc3fSopenharmony_ci   * @param iccid Indicates the specified sim that is valid when netType is cellular.
108b1b8bc3fSopenharmony_ci   * @permission ohos.permission.CONNECTIVITY_INTERNAL
109b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
110b1b8bc3fSopenharmony_ci   */
111b1b8bc3fSopenharmony_ci  function restoreAllPolicies(iccid: string, callback: AsyncCallback<void>): void;
112b1b8bc3fSopenharmony_ci  function restoreAllPolicies(iccid: string): Promise<void>;
113b1b8bc3fSopenharmony_ci
114b1b8bc3fSopenharmony_ci  /**
115b1b8bc3fSopenharmony_ci   * Get the status whether the specified uid app can access the metered network or non-metered network.
116b1b8bc3fSopenharmony_ci   *
117b1b8bc3fSopenharmony_ci   * @param uid The specified UID of application.
118b1b8bc3fSopenharmony_ci   * @param isMetered Indicates meterd network or non-metered network.
119b1b8bc3fSopenharmony_ci   * @permission ohos.permission.CONNECTIVITY_INTERNAL
120b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
121b1b8bc3fSopenharmony_ci   */
122b1b8bc3fSopenharmony_ci  function isUidNetAllowed(uid: number, isMetered: boolean, callback: AsyncCallback<boolean>): void;
123b1b8bc3fSopenharmony_ci  function isUidNetAllowed(uid: number, isMetered: boolean): Promise<boolean>;
124b1b8bc3fSopenharmony_ci
125b1b8bc3fSopenharmony_ci  /**
126b1b8bc3fSopenharmony_ci   * Get the status whether the specified uid app can access the specified iface network.
127b1b8bc3fSopenharmony_ci   *
128b1b8bc3fSopenharmony_ci   * @param uid The specified UID of application.
129b1b8bc3fSopenharmony_ci   * @param iface Iface name.
130b1b8bc3fSopenharmony_ci   * @permission ohos.permission.CONNECTIVITY_INTERNAL
131b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
132b1b8bc3fSopenharmony_ci   */
133b1b8bc3fSopenharmony_ci  function isUidNetAllowed(uid: number, iface: string, callback: AsyncCallback<boolean>): void;
134b1b8bc3fSopenharmony_ci  function isUidNetAllowed(uid: number, iface: string): Promise<boolean>;
135b1b8bc3fSopenharmony_ci
136b1b8bc3fSopenharmony_ci  /**
137b1b8bc3fSopenharmony_ci   * Set the UID into device idle allow list.
138b1b8bc3fSopenharmony_ci   *
139b1b8bc3fSopenharmony_ci   * @param uid The specified UID of application.
140b1b8bc3fSopenharmony_ci   * @param isAllowed The UID is into allow list or not.
141b1b8bc3fSopenharmony_ci   * @param callback
142b1b8bc3fSopenharmony_ci   * @permission ohos.permission.CONNECTIVITY_INTERNAL
143b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
144b1b8bc3fSopenharmony_ci   */
145b1b8bc3fSopenharmony_ci  function setDeviceIdleAllowList(uid: number, isAllowed: boolean, callback: AsyncCallback<void>): void;
146b1b8bc3fSopenharmony_ci  function setDeviceIdleAllowList(uid: number, isAllowed: boolean): Promise<void>;
147b1b8bc3fSopenharmony_ci
148b1b8bc3fSopenharmony_ci  /**
149b1b8bc3fSopenharmony_ci   * Get the allow list of in device idle mode.
150b1b8bc3fSopenharmony_ci   *
151b1b8bc3fSopenharmony_ci   * @param callback Returns the list of UIDs
152b1b8bc3fSopenharmony_ci   * @permission ohos.permission.CONNECTIVITY_INTERNAL
153b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
154b1b8bc3fSopenharmony_ci   */
155b1b8bc3fSopenharmony_ci  function getDeviceIdleAllowList(callback: AsyncCallback<Array<number>>): void;
156b1b8bc3fSopenharmony_ci  function getDeviceIdleAllowList(): Promise<Array<number>>;
157b1b8bc3fSopenharmony_ci
158b1b8bc3fSopenharmony_ci  /**
159b1b8bc3fSopenharmony_ci   * Get the background network restriction policy for the specified uid.
160b1b8bc3fSopenharmony_ci   *
161b1b8bc3fSopenharmony_ci   * @param uid The specified UID of application.
162b1b8bc3fSopenharmony_ci   * @param callback {@link NetBackgroundPolicy}.
163b1b8bc3fSopenharmony_ci   * @permission ohos.permission.CONNECTIVITY_INTERNAL
164b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
165b1b8bc3fSopenharmony_ci   */
166b1b8bc3fSopenharmony_ci  function getBackgroundPolicyByUid(uid: number, callback: AsyncCallback<NetBackgroundPolicy>): void;
167b1b8bc3fSopenharmony_ci  function getBackgroundPolicyByUid(uid: number): Promise<NetBackgroundPolicy>;
168b1b8bc3fSopenharmony_ci
169b1b8bc3fSopenharmony_ci  /**
170b1b8bc3fSopenharmony_ci   * Reset network policies\rules\quota policies\firewall rules.
171b1b8bc3fSopenharmony_ci   *
172b1b8bc3fSopenharmony_ci   * @param iccid Specify the matched iccid of quota policy.
173b1b8bc3fSopenharmony_ci   * @permission ohos.permission.CONNECTIVITY_INTERNAL
174b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
175b1b8bc3fSopenharmony_ci   */
176b1b8bc3fSopenharmony_ci  function resetPolicies(iccid: string, callback: AsyncCallback<void>): void;
177b1b8bc3fSopenharmony_ci  function resetPolicies(iccid: string): Promise<void>;
178b1b8bc3fSopenharmony_ci
179b1b8bc3fSopenharmony_ci  /**
180b1b8bc3fSopenharmony_ci   * Update the limit or warning remind time of quota policy.
181b1b8bc3fSopenharmony_ci   *
182b1b8bc3fSopenharmony_ci   * @param iccid Specify the matched iccid of quota policy when netType is cellular.
183b1b8bc3fSopenharmony_ci   * @param netType {@link NetBearType}.
184b1b8bc3fSopenharmony_ci   * @permission ohos.permission.CONNECTIVITY_INTERNAL
185b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
186b1b8bc3fSopenharmony_ci   */
187b1b8bc3fSopenharmony_ci  function updateRemindPolicy(netType: NetBearType, iccid: string, remindType: RemindType, callback: AsyncCallback<void>): void;
188b1b8bc3fSopenharmony_ci  function updateRemindPolicy(netType: NetBearType, iccid: string, remindType: RemindType): Promise<void>;
189b1b8bc3fSopenharmony_ci
190b1b8bc3fSopenharmony_ci  /**
191b1b8bc3fSopenharmony_ci   * Set the policy to access the network of the specified application.
192b1b8bc3fSopenharmony_ci   *
193b1b8bc3fSopenharmony_ci   * @permission ohos.permission.MANAGE_NET_STRATEGY
194b1b8bc3fSopenharmony_ci   * @param { number } uid - The specified UID of application.
195b1b8bc3fSopenharmony_ci   * @param { NetworkAccessPolicy } policy - The network access policy of application. For details, see {@link NetworkAccessPolicy}.
196b1b8bc3fSopenharmony_ci   * @param { boolean } [isReconfirmed] - Whether this operation is reconfirmed by user or not. Default false.
197b1b8bc3fSopenharmony_ci   * @throws { BusinessError } 201 - Permission denied.
198b1b8bc3fSopenharmony_ci   * @throws { BusinessError } 202 - Non-system applications use system APIs.
199b1b8bc3fSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error.
200b1b8bc3fSopenharmony_ci   * @throws { BusinessError } 2100001 - Invalid parameter value.
201b1b8bc3fSopenharmony_ci   * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service.
202b1b8bc3fSopenharmony_ci   * @throws { BusinessError } 2100003 - System internal error.
203b1b8bc3fSopenharmony_ci   * @syscap SystemCapability.Communication.NetManager.Core
204b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
205b1b8bc3fSopenharmony_ci   * @since 12
206b1b8bc3fSopenharmony_ci   */
207b1b8bc3fSopenharmony_ci  function setNetworkAccessPolicy(uid: number, policy: NetworkAccessPolicy, isReconfirmed?: boolean): Promise<void>;
208b1b8bc3fSopenharmony_ci
209b1b8bc3fSopenharmony_ci  /**
210b1b8bc3fSopenharmony_ci   * Query the network access policy of the specified application.
211b1b8bc3fSopenharmony_ci   *
212b1b8bc3fSopenharmony_ci   * @permission ohos.permission.MANAGE_NET_STRATEGY
213b1b8bc3fSopenharmony_ci   * @param { number } uid - The specified UID of application.
214b1b8bc3fSopenharmony_ci   * @returns { Promise<NetworkAccessPolicy> } Returns the network access policy of the application. For details, see {@link NetworkAccessPolicy}.
215b1b8bc3fSopenharmony_ci   * @throws { BusinessError } 201 - Permission denied.
216b1b8bc3fSopenharmony_ci   * @throws { BusinessError } 202 - Non-system applications use system APIs.
217b1b8bc3fSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error.
218b1b8bc3fSopenharmony_ci   * @throws { BusinessError } 2100001 - Invalid parameter value.
219b1b8bc3fSopenharmony_ci   * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service.
220b1b8bc3fSopenharmony_ci   * @throws { BusinessError } 2100003 - System internal error.
221b1b8bc3fSopenharmony_ci   * @syscap SystemCapability.Communication.NetManager.Core
222b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
223b1b8bc3fSopenharmony_ci   * @since 12
224b1b8bc3fSopenharmony_ci   */
225b1b8bc3fSopenharmony_ci  function getNetworkAccessPolicy(uid: number): Promise<NetworkAccessPolicy>;
226b1b8bc3fSopenharmony_ci
227b1b8bc3fSopenharmony_ci  /**
228b1b8bc3fSopenharmony_ci   * Query the network access policy of all applications.
229b1b8bc3fSopenharmony_ci   * @permission ohos.permission.MANAGE_NET_STRATEGY
230b1b8bc3fSopenharmony_ci   * @returns { Promise<UidNetworkAccessPolicy> } the network access policy of all applications.
231b1b8bc3fSopenharmony_ci   * @throws { BusinessError } 201 - Permission denied.
232b1b8bc3fSopenharmony_ci   * @throws { BusinessError } 202 - Non-system applications use system APIs.
233b1b8bc3fSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error.
234b1b8bc3fSopenharmony_ci   * @throws { BusinessError } 2100001 - Invalid parameter value.
235b1b8bc3fSopenharmony_ci   * @throws { BusinessError } 2100002 - Operation failed. Cannot connect to service.
236b1b8bc3fSopenharmony_ci   * @throws { BusinessError } 2100003 - System internal error.
237b1b8bc3fSopenharmony_ci   * @syscap SystemCapability.Communication.NetManager.Core
238b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
239b1b8bc3fSopenharmony_ci   * @since 12
240b1b8bc3fSopenharmony_ci   */
241b1b8bc3fSopenharmony_ci  function getNetworkAccessPolicy(): Promise<UidNetworkAccessPolicy>;
242b1b8bc3fSopenharmony_ci
243b1b8bc3fSopenharmony_ci  /**
244b1b8bc3fSopenharmony_ci   * Register uid policy change listener.
245b1b8bc3fSopenharmony_ci   *
246b1b8bc3fSopenharmony_ci   * @permission ohos.permission.CONNECTIVITY_INTERNAL
247b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
248b1b8bc3fSopenharmony_ci   */
249b1b8bc3fSopenharmony_ci  function on(type: "netUidPolicyChange", callback: Callback<{ uid: number, policy: NetUidPolicy }>): void;
250b1b8bc3fSopenharmony_ci
251b1b8bc3fSopenharmony_ci  /**
252b1b8bc3fSopenharmony_ci   * Unregister uid policy change listener.
253b1b8bc3fSopenharmony_ci   *
254b1b8bc3fSopenharmony_ci   * @permission ohos.permission.CONNECTIVITY_INTERNAL
255b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
256b1b8bc3fSopenharmony_ci   */
257b1b8bc3fSopenharmony_ci  function off(type: "netUidPolicyChange", callback?: Callback<{ uid: number, policy: NetUidPolicy }>): void;
258b1b8bc3fSopenharmony_ci
259b1b8bc3fSopenharmony_ci  /**
260b1b8bc3fSopenharmony_ci   * Register uid rule change listener.
261b1b8bc3fSopenharmony_ci   *
262b1b8bc3fSopenharmony_ci   * @permission ohos.permission.CONNECTIVITY_INTERNAL
263b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
264b1b8bc3fSopenharmony_ci   */
265b1b8bc3fSopenharmony_ci  function on(type: "netUidRuleChange", callback: Callback<{ uid: number, rule: NetUidRule }>): void;
266b1b8bc3fSopenharmony_ci
267b1b8bc3fSopenharmony_ci  /**
268b1b8bc3fSopenharmony_ci   * Unregister uid rule change listener.
269b1b8bc3fSopenharmony_ci   *
270b1b8bc3fSopenharmony_ci   * @permission ohos.permission.CONNECTIVITY_INTERNAL
271b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
272b1b8bc3fSopenharmony_ci   */
273b1b8bc3fSopenharmony_ci  function off(type: "netUidRuleChange", callback?: Callback<{ uid: number, rule: NetUidRule }>): void;
274b1b8bc3fSopenharmony_ci
275b1b8bc3fSopenharmony_ci  /**
276b1b8bc3fSopenharmony_ci   * Register metered ifaces change listener.
277b1b8bc3fSopenharmony_ci   *
278b1b8bc3fSopenharmony_ci   * @permission ohos.permission.CONNECTIVITY_INTERNAL
279b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
280b1b8bc3fSopenharmony_ci   */
281b1b8bc3fSopenharmony_ci  function on(type: "netMeteredIfacesChange", callback: Callback<Array<string>>): void;
282b1b8bc3fSopenharmony_ci
283b1b8bc3fSopenharmony_ci  /**
284b1b8bc3fSopenharmony_ci   * Unregister metered ifaces change listener.
285b1b8bc3fSopenharmony_ci   *
286b1b8bc3fSopenharmony_ci   * @permission ohos.permission.CONNECTIVITY_INTERNAL
287b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
288b1b8bc3fSopenharmony_ci   */
289b1b8bc3fSopenharmony_ci  function off(type: "netMeteredIfacesChange", callback?: Callback<Array<string>>): void;
290b1b8bc3fSopenharmony_ci
291b1b8bc3fSopenharmony_ci  /**
292b1b8bc3fSopenharmony_ci   * Register quota policies change listener.
293b1b8bc3fSopenharmony_ci   *
294b1b8bc3fSopenharmony_ci   * @permission ohos.permission.CONNECTIVITY_INTERNAL
295b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
296b1b8bc3fSopenharmony_ci   */
297b1b8bc3fSopenharmony_ci  function on(type: "netQuotaPolicyChange", callback: Callback<Array<NetQuotaPolicy>>): void;
298b1b8bc3fSopenharmony_ci
299b1b8bc3fSopenharmony_ci  /**
300b1b8bc3fSopenharmony_ci   * Unregister quota policies change listener.
301b1b8bc3fSopenharmony_ci   *
302b1b8bc3fSopenharmony_ci   * @permission ohos.permission.CONNECTIVITY_INTERNAL
303b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
304b1b8bc3fSopenharmony_ci   */
305b1b8bc3fSopenharmony_ci  function off(type: "netQuotaPolicyChange", callback?: Callback<Array<NetQuotaPolicy>>): void;
306b1b8bc3fSopenharmony_ci
307b1b8bc3fSopenharmony_ci  /**
308b1b8bc3fSopenharmony_ci   * Register network background policy change listener.
309b1b8bc3fSopenharmony_ci   *
310b1b8bc3fSopenharmony_ci   * @permission ohos.permission.CONNECTIVITY_INTERNAL
311b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
312b1b8bc3fSopenharmony_ci   */
313b1b8bc3fSopenharmony_ci  function on(type: "netBackgroundPolicyChange", callback: Callback<boolean>): void;
314b1b8bc3fSopenharmony_ci
315b1b8bc3fSopenharmony_ci  /**
316b1b8bc3fSopenharmony_ci   * Unregister network background policy change listener.
317b1b8bc3fSopenharmony_ci   *
318b1b8bc3fSopenharmony_ci   * @permission ohos.permission.CONNECTIVITY_INTERNAL
319b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
320b1b8bc3fSopenharmony_ci   */
321b1b8bc3fSopenharmony_ci  function off(type: "netBackgroundPolicyChange", callback?: Callback<boolean>): void;
322b1b8bc3fSopenharmony_ci
323b1b8bc3fSopenharmony_ci  /**
324b1b8bc3fSopenharmony_ci   * Indicate whether the application can use metered networks in background.
325b1b8bc3fSopenharmony_ci   *
326b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
327b1b8bc3fSopenharmony_ci   */
328b1b8bc3fSopenharmony_ci  export enum NetBackgroundPolicy {
329b1b8bc3fSopenharmony_ci    /* Default value. */
330b1b8bc3fSopenharmony_ci    NET_BACKGROUND_POLICY_NONE = 0,
331b1b8bc3fSopenharmony_ci    /* Apps can use metered networks on background. */
332b1b8bc3fSopenharmony_ci    NET_BACKGROUND_POLICY_ENABLE = 1,
333b1b8bc3fSopenharmony_ci    /* Apps can't use metered networks on background. */
334b1b8bc3fSopenharmony_ci    NET_BACKGROUND_POLICY_DISABLE = 2,
335b1b8bc3fSopenharmony_ci    /* Only apps in allow list can use metered networks on background. */
336b1b8bc3fSopenharmony_ci    NET_BACKGROUND_POLICY_ALLOW_LIST = 3,
337b1b8bc3fSopenharmony_ci  }
338b1b8bc3fSopenharmony_ci
339b1b8bc3fSopenharmony_ci  /**
340b1b8bc3fSopenharmony_ci   * Policy for net quota, includes usage period, limit and warning actions.
341b1b8bc3fSopenharmony_ci   *
342b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
343b1b8bc3fSopenharmony_ci   */
344b1b8bc3fSopenharmony_ci  export interface NetQuotaPolicy {
345b1b8bc3fSopenharmony_ci    /* netType see {@link NetBearType}. */
346b1b8bc3fSopenharmony_ci    netType: NetBearType;
347b1b8bc3fSopenharmony_ci    /* The ID of the target card, valid when netType is BEARER_CELLULAR. */
348b1b8bc3fSopenharmony_ci    iccid: string;
349b1b8bc3fSopenharmony_ci    /* To specify the identity of network, such as different WLAN. */
350b1b8bc3fSopenharmony_ci    ident: string;
351b1b8bc3fSopenharmony_ci    /* The period and the start time for quota policy, defalt: "M1". */
352b1b8bc3fSopenharmony_ci    periodDuration: string;
353b1b8bc3fSopenharmony_ci    /* The warning threshold of traffic, default:  DATA_USAGE_UNKNOWN. */
354b1b8bc3fSopenharmony_ci    warningBytes: number;
355b1b8bc3fSopenharmony_ci    /* The limit threshold of traffic, default: DATA_USAGE_UNKNOWN. */
356b1b8bc3fSopenharmony_ci    limitBytes: number;
357b1b8bc3fSopenharmony_ci    /* The updated wall time that last warning remind, default: REMIND_NEVER. */
358b1b8bc3fSopenharmony_ci    lastWarningRemind: number;
359b1b8bc3fSopenharmony_ci    /* The updated wall time that last limit remind, default: REMIND_NEVER. */
360b1b8bc3fSopenharmony_ci    lastLimitRemind: number;
361b1b8bc3fSopenharmony_ci    /* Is meterd network or not. */
362b1b8bc3fSopenharmony_ci    metered: boolean;
363b1b8bc3fSopenharmony_ci    /* The action while the used bytes reach the limit, see {@link LimitAction}. */
364b1b8bc3fSopenharmony_ci    limitAction: LimitAction;
365b1b8bc3fSopenharmony_ci  }
366b1b8bc3fSopenharmony_ci
367b1b8bc3fSopenharmony_ci  /**
368b1b8bc3fSopenharmony_ci   * The action when quota policy hit the limit.
369b1b8bc3fSopenharmony_ci   *
370b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
371b1b8bc3fSopenharmony_ci   */
372b1b8bc3fSopenharmony_ci  export enum LimitAction {
373b1b8bc3fSopenharmony_ci    /* Default action, do nothing. */
374b1b8bc3fSopenharmony_ci    LIMIT_ACTION_NONE = -1,
375b1b8bc3fSopenharmony_ci    /* Access is disabled, when quota policy hit the limit. */
376b1b8bc3fSopenharmony_ci    LIMIT_ACTION_DISABLE = 0,
377b1b8bc3fSopenharmony_ci    /* The user is billed automatically, when quota policy hit the limit. */
378b1b8bc3fSopenharmony_ci    LIMIT_ACTION_AUTO_BILL = 1,
379b1b8bc3fSopenharmony_ci  }
380b1b8bc3fSopenharmony_ci
381b1b8bc3fSopenharmony_ci  /**
382b1b8bc3fSopenharmony_ci   * Rules whether an uid can access to a metered or non-metered network.
383b1b8bc3fSopenharmony_ci   *
384b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
385b1b8bc3fSopenharmony_ci   */
386b1b8bc3fSopenharmony_ci  export enum NetUidRule {
387b1b8bc3fSopenharmony_ci    /* Default uid rule. */
388b1b8bc3fSopenharmony_ci    NET_RULE_NONE = 0,
389b1b8bc3fSopenharmony_ci    /* Allow traffic on metered networks while app is foreground. */
390b1b8bc3fSopenharmony_ci    NET_RULE_ALLOW_METERED_FOREGROUND = 1 << 0,
391b1b8bc3fSopenharmony_ci    /* Allow traffic on metered network. */
392b1b8bc3fSopenharmony_ci    NET_RULE_ALLOW_METERED = 1 << 1,
393b1b8bc3fSopenharmony_ci    /* Reject traffic on metered network. */
394b1b8bc3fSopenharmony_ci    NET_RULE_REJECT_METERED = 1 << 2,
395b1b8bc3fSopenharmony_ci    /* Allow traffic on all network (metered or non-metered). */
396b1b8bc3fSopenharmony_ci    NET_RULE_ALLOW_ALL = 1 << 5,
397b1b8bc3fSopenharmony_ci    /* Reject traffic on all network. */
398b1b8bc3fSopenharmony_ci    NET_RULE_REJECT_ALL = 1 << 6,
399b1b8bc3fSopenharmony_ci  }
400b1b8bc3fSopenharmony_ci
401b1b8bc3fSopenharmony_ci  /**
402b1b8bc3fSopenharmony_ci   * Specify the remind type, see {@link updateRemindPolicy}.
403b1b8bc3fSopenharmony_ci   *
404b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
405b1b8bc3fSopenharmony_ci   */
406b1b8bc3fSopenharmony_ci  export enum RemindType {
407b1b8bc3fSopenharmony_ci    /* Warning remind. */
408b1b8bc3fSopenharmony_ci    REMIND_TYPE_WARNING = 1,
409b1b8bc3fSopenharmony_ci    /* Limit remind. */
410b1b8bc3fSopenharmony_ci    REMIND_TYPE_LIMIT = 2,
411b1b8bc3fSopenharmony_ci  }
412b1b8bc3fSopenharmony_ci
413b1b8bc3fSopenharmony_ci  /**
414b1b8bc3fSopenharmony_ci   * Network policy for uid.
415b1b8bc3fSopenharmony_ci   *
416b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
417b1b8bc3fSopenharmony_ci   */
418b1b8bc3fSopenharmony_ci  export enum NetUidPolicy {
419b1b8bc3fSopenharmony_ci    /* Default net policy. */
420b1b8bc3fSopenharmony_ci    NET_POLICY_NONE = 0,
421b1b8bc3fSopenharmony_ci    /* Reject on metered networks when app in background. */
422b1b8bc3fSopenharmony_ci    NET_POLICY_ALLOW_METERED_BACKGROUND = 1 << 0,
423b1b8bc3fSopenharmony_ci    /* Allow on metered networks when app in background. */
424b1b8bc3fSopenharmony_ci    NET_POLICY_REJECT_METERED_BACKGROUND = 1 << 1,
425b1b8bc3fSopenharmony_ci  }
426b1b8bc3fSopenharmony_ci
427b1b8bc3fSopenharmony_ci  /**
428b1b8bc3fSopenharmony_ci   * Network policies that limit the specified UID of application to access the network.
429b1b8bc3fSopenharmony_ci   * @interface NetworkAccessPolicy
430b1b8bc3fSopenharmony_ci   * @syscap SystemCapability.Communication.NetManager.Core
431b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
432b1b8bc3fSopenharmony_ci   * @since 12
433b1b8bc3fSopenharmony_ci   */
434b1b8bc3fSopenharmony_ci  export interface NetworkAccessPolicy {
435b1b8bc3fSopenharmony_ci    /**
436b1b8bc3fSopenharmony_ci     * Indicate whether the application can be allowed to access the network by wifi.
437b1b8bc3fSopenharmony_ci     * @type { boolean }
438b1b8bc3fSopenharmony_ci     * @syscap SystemCapability.Communication.NetManager.Core
439b1b8bc3fSopenharmony_ci     * @systemapi Hide this for inner system use.
440b1b8bc3fSopenharmony_ci     * @since 12
441b1b8bc3fSopenharmony_ci     */
442b1b8bc3fSopenharmony_ci    allowWiFi?: boolean;
443b1b8bc3fSopenharmony_ci    /**
444b1b8bc3fSopenharmony_ci     * Indicate whether the application can be allowed to access the network by cellular.
445b1b8bc3fSopenharmony_ci     * @type { boolean }
446b1b8bc3fSopenharmony_ci     * @syscap SystemCapability.Communication.NetManager.Core
447b1b8bc3fSopenharmony_ci     * @systemapi Hide this for inner system use.
448b1b8bc3fSopenharmony_ci     * @since 12
449b1b8bc3fSopenharmony_ci     */
450b1b8bc3fSopenharmony_ci    allowCellular?: boolean;
451b1b8bc3fSopenharmony_ci  }
452b1b8bc3fSopenharmony_ci
453b1b8bc3fSopenharmony_ci  /**
454b1b8bc3fSopenharmony_ci   * Provides the container definition for network access policy key-value pairs.
455b1b8bc3fSopenharmony_ci   * @interface UidNetworkAccessPolicy
456b1b8bc3fSopenharmony_ci   * @syscap SystemCapability.Communication.NetManager.Core
457b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
458b1b8bc3fSopenharmony_ci   * @since 12
459b1b8bc3fSopenharmony_ci   */
460b1b8bc3fSopenharmony_ci  export interface UidNetworkAccessPolicy {
461b1b8bc3fSopenharmony_ci      /**
462b1b8bc3fSopenharmony_ci       * @type key:value pair. Key indicates the specified UID of an application. For value, see @NetworkAccessPolicy.
463b1b8bc3fSopenharmony_ci       * @syscap SystemCapability.Communication.NetManager.Core
464b1b8bc3fSopenharmony_ci       * @systemapi Hide this for inner system use.
465b1b8bc3fSopenharmony_ci       * @since 12
466b1b8bc3fSopenharmony_ci       */
467b1b8bc3fSopenharmony_ci      [uid: number]: NetworkAccessPolicy;
468b1b8bc3fSopenharmony_ci  }
469b1b8bc3fSopenharmony_ci}
470b1b8bc3fSopenharmony_ci
471b1b8bc3fSopenharmony_ciexport default policy;
472