1b1b8bc3fSopenharmony_ci/* 2b1b8bc3fSopenharmony_ci * Copyright (c) 2022-2023 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_ci#ifndef NET_POLICY_FIREWALL_H 17b1b8bc3fSopenharmony_ci#define NET_POLICY_FIREWALL_H 18b1b8bc3fSopenharmony_ci 19b1b8bc3fSopenharmony_ci#include "firewall_rule.h" 20b1b8bc3fSopenharmony_ci#include "net_policy_base.h" 21b1b8bc3fSopenharmony_ci#include "net_policy_file.h" 22b1b8bc3fSopenharmony_ci 23b1b8bc3fSopenharmony_cinamespace OHOS { 24b1b8bc3fSopenharmony_cinamespace NetManagerStandard { 25b1b8bc3fSopenharmony_ciclass NetPolicyFirewall : public NetPolicyBase { 26b1b8bc3fSopenharmony_cipublic: 27b1b8bc3fSopenharmony_ci NetPolicyFirewall() : deviceIdleMode_(false) {} 28b1b8bc3fSopenharmony_ci void Init(); 29b1b8bc3fSopenharmony_ci 30b1b8bc3fSopenharmony_ci /** 31b1b8bc3fSopenharmony_ci * Set the UID into device idle allow list. 32b1b8bc3fSopenharmony_ci * 33b1b8bc3fSopenharmony_ci * @param uid The specified UID of application. 34b1b8bc3fSopenharmony_ci * @param isAllowed The UID is into allow list or not. 35b1b8bc3fSopenharmony_ci * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 36b1b8bc3fSopenharmony_ci */ 37b1b8bc3fSopenharmony_ci int32_t SetDeviceIdleTrustlist(const std::vector<uint32_t> &uids, bool isAllowed); 38b1b8bc3fSopenharmony_ci 39b1b8bc3fSopenharmony_ci /** 40b1b8bc3fSopenharmony_ci * Get the allow list of UID in device idle mode. 41b1b8bc3fSopenharmony_ci * 42b1b8bc3fSopenharmony_ci * @param uids The list of UIDs 43b1b8bc3fSopenharmony_ci * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 44b1b8bc3fSopenharmony_ci */ 45b1b8bc3fSopenharmony_ci int32_t GetDeviceIdleTrustlist(std::vector<uint32_t> &uids); 46b1b8bc3fSopenharmony_ci 47b1b8bc3fSopenharmony_ci /** 48b1b8bc3fSopenharmony_ci * Process network policy in device idle mode. 49b1b8bc3fSopenharmony_ci * 50b1b8bc3fSopenharmony_ci * @param enable Device idle mode is open or not. 51b1b8bc3fSopenharmony_ci * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 52b1b8bc3fSopenharmony_ci */ 53b1b8bc3fSopenharmony_ci int32_t UpdateDeviceIdlePolicy(bool enable); 54b1b8bc3fSopenharmony_ci 55b1b8bc3fSopenharmony_ci /** 56b1b8bc3fSopenharmony_ci * Reset network firewall rules. 57b1b8bc3fSopenharmony_ci * 58b1b8bc3fSopenharmony_ci */ 59b1b8bc3fSopenharmony_ci void ResetPolicies(); 60b1b8bc3fSopenharmony_ci 61b1b8bc3fSopenharmony_ci /** 62b1b8bc3fSopenharmony_ci * Set the Power Save Allowed List object. 63b1b8bc3fSopenharmony_ci * 64b1b8bc3fSopenharmony_ci * @param uid The specified UID of application. 65b1b8bc3fSopenharmony_ci * @param isAllowed The UID is into allow list or not. 66b1b8bc3fSopenharmony_ci * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 67b1b8bc3fSopenharmony_ci */ 68b1b8bc3fSopenharmony_ci int32_t SetPowerSaveTrustlist(const std::vector<uint32_t> &uids, bool isAllowed); 69b1b8bc3fSopenharmony_ci 70b1b8bc3fSopenharmony_ci /** 71b1b8bc3fSopenharmony_ci * Get the Power Save Allowed List object. 72b1b8bc3fSopenharmony_ci * 73b1b8bc3fSopenharmony_ci * @param uids The list of UIDs. 74b1b8bc3fSopenharmony_ci * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 75b1b8bc3fSopenharmony_ci */ 76b1b8bc3fSopenharmony_ci int32_t GetPowerSaveTrustlist(std::vector<uint32_t> &uids); 77b1b8bc3fSopenharmony_ci 78b1b8bc3fSopenharmony_ci /** 79b1b8bc3fSopenharmony_ci * Process network policy in device idle mode. 80b1b8bc3fSopenharmony_ci * 81b1b8bc3fSopenharmony_ci * @param enable Power save mode is open or not. 82b1b8bc3fSopenharmony_ci * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 83b1b8bc3fSopenharmony_ci */ 84b1b8bc3fSopenharmony_ci int32_t UpdatePowerSavePolicy(bool enable); 85b1b8bc3fSopenharmony_ci 86b1b8bc3fSopenharmony_ci /** 87b1b8bc3fSopenharmony_ci * Handle the event from NetPolicyCore 88b1b8bc3fSopenharmony_ci * 89b1b8bc3fSopenharmony_ci * @param eventId The event id 90b1b8bc3fSopenharmony_ci * @param policyEvent The informations passed from other core 91b1b8bc3fSopenharmony_ci */ 92b1b8bc3fSopenharmony_ci void HandleEvent(int32_t eventId, const std::shared_ptr<PolicyEvent> &policyEvent); 93b1b8bc3fSopenharmony_ci 94b1b8bc3fSopenharmony_ciprivate: 95b1b8bc3fSopenharmony_ci void UpdateFirewallPolicyList(uint32_t chainType, const std::vector<uint32_t> &uids, bool isAllowed); 96b1b8bc3fSopenharmony_ci void DeleteUid(uint32_t uid); 97b1b8bc3fSopenharmony_ci 98b1b8bc3fSopenharmony_ciprivate: 99b1b8bc3fSopenharmony_ci std::shared_ptr<FirewallRule> deviceIdleFirewallRule_; 100b1b8bc3fSopenharmony_ci std::shared_ptr<FirewallRule> powerSaveFirewallRule_; 101b1b8bc3fSopenharmony_ci bool deviceIdleMode_ = false; 102b1b8bc3fSopenharmony_ci bool powerSaveMode_ = false; 103b1b8bc3fSopenharmony_ci std::set<uint32_t> deviceIdleAllowedList_; 104b1b8bc3fSopenharmony_ci std::set<uint32_t> deviceIdleDeniedList_; 105b1b8bc3fSopenharmony_ci std::set<uint32_t> powerSaveAllowedList_; 106b1b8bc3fSopenharmony_ci std::set<uint32_t> powerSaveDeniedList_; 107b1b8bc3fSopenharmony_ci}; 108b1b8bc3fSopenharmony_ci} // namespace NetManagerStandard 109b1b8bc3fSopenharmony_ci} // namespace OHOS 110b1b8bc3fSopenharmony_ci#endif // NET_POLICY_FIREWALL_H 111