1 /*
2  * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef COMMUNICATIONNETMANAGERBASE_POLICY_EXEC_H
17 #define COMMUNICATIONNETMANAGERBASE_POLICY_EXEC_H
18 
19 #include <napi/native_api.h>
20 
21 #include "get_policy_by_uid_context.h"
22 #include "get_uids_by_policy_context.h"
23 #include "get_net_quota_policies_context.h"
24 #include "get_network_access_policy_context.h"
25 #include "is_uid_net_allowed_context.h"
26 #include "net_quota_policy.h"
27 #include "restore_all_policies_context.h"
28 #include "set_bg_policy_context.h"
29 #include "set_net_quota_policies_context.h"
30 #include "set_policy_by_uid_context.h"
31 #include "set_power_save_allow_list_context.h"
32 #include "set_device_idle_allow_list_context.h"
33 #include "update_remind_policy_context.h"
34 #include "set_network_access_policy_context.h"
35 
36 namespace OHOS {
37 namespace NetManagerStandard {
38 class NetPolicyExec final {
39 public:
40     NetPolicyExec() = delete;
41     ~NetPolicyExec() = delete;
42 
43     static bool ExecSetPolicyByUid(SetPolicyByUidContext *context);
44     static bool ExecGetPolicyByUid(GetPolicyByUidContext *context);
45     static bool ExecGetUidsByPolicy(GetUidsByPolicyContext *context);
46     static bool ExecSetBackgroundPolicy(SetBackgroundPolicyContext *context);
47     static bool ExecGetBackgroundPolicy(GetBackgroundPolicyContext *context);
48     static bool ExecGetNetQuotaPolicies(GetNetQuotaPoliciesContext *context);
49     static bool ExecSetNetQuotaPolicies(SetNetQuotaPoliciesContext *context);
50     static bool ExecRestoreAllPolicies(RestoreAllPoliciesContext *context);
51     static bool ExecIsUidNetAllowed(IsUidNetAllowedContext *context);
52     static bool ExecSetDeviceIdleTrustlist(SetDeviceIdleTrustlistContext *context);
53     static bool ExecGetDeviceIdleTrustlist(GetDeviceIdleTrustlistContext *context);
54     static bool ExecGetBackgroundPolicyByUid(GetBackgroundPolicyByUidContext *context);
55     static bool ExecResetPolicies(ResetPoliciesContext *context);
56     static bool ExecUpdateRemindPolicy(UpdateRemindPolicyContext *context);
57     static bool ExecSetPowerSaveTrustlist(SetPowerSaveTrustlistContext *context);
58     static bool ExecGetPowerSaveTrustlist(GetPowerSaveTrustlistContext *context);
59     static bool ExecSetNetworkAccessPolicy(SetNetworkAccessPolicyContext *context);
60     static bool ExecGetNetworkAccessPolicy(GetNetworkAccessPolicyContext *context);
61 
62     static napi_value SetPolicyByUidCallback(SetPolicyByUidContext *context);
63     static napi_value GetPolicyByUidCallback(GetPolicyByUidContext *context);
64     static napi_value GetUidsByPolicyCallback(GetUidsByPolicyContext *context);
65     static napi_value SetBackgroundPolicyCallback(SetBackgroundPolicyContext *context);
66     static napi_value GetBackgroundPolicyCallback(GetBackgroundPolicyContext *context);
67     static napi_value GetNetQuotaPoliciesCallback(GetNetQuotaPoliciesContext *context);
68     static napi_value SetNetQuotaPoliciesCallback(SetNetQuotaPoliciesContext *context);
69     static napi_value RestoreAllPoliciesCallback(RestoreAllPoliciesContext *context);
70     static napi_value IsUidNetAllowedCallback(IsUidNetAllowedContext *context);
71     static napi_value SetDeviceIdleTrustlistCallback(SetDeviceIdleTrustlistContext *context);
72     static napi_value GetDeviceIdleTrustlistCallback(GetDeviceIdleTrustlistContext *context);
73     static napi_value GetBackgroundPolicyByUidCallback(GetBackgroundPolicyByUidContext *context);
74     static napi_value ResetPoliciesCallback(ResetPoliciesContext *context);
75     static napi_value UpdateRemindPolicyCallback(UpdateRemindPolicyContext *context);
76     static napi_value SetPowerSaveTrustlistCallback(SetPowerSaveTrustlistContext *context);
77     static napi_value GetPowerSaveTrustlistCallback(GetPowerSaveTrustlistContext *context);
78     static napi_value SetNetworkAccessPolicyCallback(SetNetworkAccessPolicyContext *context);
79     static napi_value GetNetworkAccessPolicyCallback(GetNetworkAccessPolicyContext *context);
80 
81     static napi_value CreateNetQuotaPolicy(napi_env env, const NetQuotaPolicy &netQuotaPolicy);
82     static void FillNetWorkMatchRule(napi_env env, napi_value connectionProperties,
83                                      const NetQuotaPolicy &netQuotaPolicy);
84     static void FillQuotaPolicy(napi_env env, napi_value elementObject, const NetQuotaPolicy &netQuotaPolicy);
85 };
86 } // namespace NetManagerStandard
87 } // namespace OHOS
88 #endif // COMMUNICATIONNETMANAGERBASE_POLICY_EXEC_H
89