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 "is_uid_net_allowed_context.h" 25 #include "net_quota_policy.h" 26 #include "restore_all_policies_context.h" 27 #include "set_bg_policy_context.h" 28 #include "set_net_quota_policies_context.h" 29 #include "set_policy_by_uid_context.h" 30 #include "set_power_save_allow_list_context.h" 31 #include "set_device_idle_allow_list_context.h" 32 #include "update_remind_policy_context.h" 33 34 namespace OHOS { 35 namespace NetManagerStandard { 36 class NetPolicyExec final { 37 public: 38 NetPolicyExec() = delete; 39 ~NetPolicyExec() = delete; 40 41 static bool ExecSetPolicyByUid(SetPolicyByUidContext *context); 42 static bool ExecGetPolicyByUid(GetPolicyByUidContext *context); 43 static bool ExecGetUidsByPolicy(GetUidsByPolicyContext *context); 44 static bool ExecSetBackgroundPolicy(SetBackgroundPolicyContext *context); 45 static bool ExecGetBackgroundPolicy(GetBackgroundPolicyContext *context); 46 static bool ExecGetNetQuotaPolicies(GetNetQuotaPoliciesContext *context); 47 static bool ExecSetNetQuotaPolicies(SetNetQuotaPoliciesContext *context); 48 static bool ExecRestoreAllPolicies(RestoreAllPoliciesContext *context); 49 static bool ExecIsUidNetAllowed(IsUidNetAllowedContext *context); 50 static bool ExecSetDeviceIdleTrustlist(SetDeviceIdleTrustlistContext *context); 51 static bool ExecGetDeviceIdleTrustlist(GetDeviceIdleTrustlistContext *context); 52 static bool ExecGetBackgroundPolicyByUid(GetBackgroundPolicyByUidContext *context); 53 static bool ExecResetPolicies(ResetPoliciesContext *context); 54 static bool ExecUpdateRemindPolicy(UpdateRemindPolicyContext *context); 55 static bool ExecSetPowerSaveTrustlist(SetPowerSaveTrustlistContext *context); 56 static bool ExecGetPowerSaveTrustlist(GetPowerSaveTrustlistContext *context); 57 58 static napi_value SetPolicyByUidCallback(SetPolicyByUidContext *context); 59 static napi_value GetPolicyByUidCallback(GetPolicyByUidContext *context); 60 static napi_value GetUidsByPolicyCallback(GetUidsByPolicyContext *context); 61 static napi_value SetBackgroundPolicyCallback(SetBackgroundPolicyContext *context); 62 static napi_value GetBackgroundPolicyCallback(GetBackgroundPolicyContext *context); 63 static napi_value GetNetQuotaPoliciesCallback(GetNetQuotaPoliciesContext *context); 64 static napi_value SetNetQuotaPoliciesCallback(SetNetQuotaPoliciesContext *context); 65 static napi_value RestoreAllPoliciesCallback(RestoreAllPoliciesContext *context); 66 static napi_value IsUidNetAllowedCallback(IsUidNetAllowedContext *context); 67 static napi_value SetDeviceIdleTrustlistCallback(SetDeviceIdleTrustlistContext *context); 68 static napi_value GetDeviceIdleTrustlistCallback(GetDeviceIdleTrustlistContext *context); 69 static napi_value GetBackgroundPolicyByUidCallback(GetBackgroundPolicyByUidContext *context); 70 static napi_value ResetPoliciesCallback(ResetPoliciesContext *context); 71 static napi_value UpdateRemindPolicyCallback(UpdateRemindPolicyContext *context); 72 static napi_value SetPowerSaveTrustlistCallback(SetPowerSaveTrustlistContext *context); 73 static napi_value GetPowerSaveTrustlistCallback(GetPowerSaveTrustlistContext *context); 74 75 static napi_value CreateNetQuotaPolicy(napi_env env, const NetQuotaPolicy &netQuotaPolicy); 76 static void FillNetWorkMatchRule(napi_env env, napi_value connectionProperties, 77 const NetQuotaPolicy &netQuotaPolicy); 78 static void FillQuotaPolicy(napi_env env, napi_value elementObject, const NetQuotaPolicy &netQuotaPolicy); 79 }; 80 } // namespace NetManagerStandard 81 } // namespace OHOS 82 #endif // COMMUNICATIONNETMANAGERBASE_POLICY_EXEC_H 83