• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 NET_POLICY_FIREWALL_H
17 #define NET_POLICY_FIREWALL_H
18 
19 #include "firewall_rule.h"
20 #include "net_policy_base.h"
21 #include "net_policy_file.h"
22 
23 namespace OHOS {
24 namespace NetManagerStandard {
25 class NetPolicyFirewall : public NetPolicyBase {
26 public:
NetPolicyFirewall()27     NetPolicyFirewall() : deviceIdleMode_(false) {}
28     void Init();
29 
30     /**
31      * Set the UID into device idle allow list.
32      *
33      * @param uid The specified UID of application.
34      * @param isAllowed The UID is into allow list or not.
35      * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}.
36      */
37     int32_t SetDeviceIdleAllowedList(uint32_t uid, bool isAllowed);
38 
39     /**
40      * Get the allow list of UID in device idle mode.
41      *
42      * @param uids The list of UIDs
43      * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}.
44      */
45     int32_t GetDeviceIdleAllowedList(std::vector<uint32_t> &uids);
46 
47     /**
48      * Process network policy in device idle mode.
49      *
50      * @param enable Device idle mode is open or not.
51      * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}.
52      */
53     int32_t UpdateDeviceIdlePolicy(bool enable);
54 
55     /**
56      * Reset network firewall rules.
57      *
58      */
59     void ResetPolicies();
60 
61     /**
62      * Handle the event from NetPolicyCore
63      *
64      * @param eventId The event id
65      * @param policyEvent The informations passed from other core
66      */
67     void HandleEvent(int32_t eventId, const std::shared_ptr<PolicyEvent> &policyEvent);
68 
69 private:
70     void DeleteUid(uint32_t uid);
71     std::shared_ptr<FirewallRule> deviceIdleFirewallRule_;
72     bool deviceIdleMode_;
73 };
74 } // namespace NetManagerStandard
75 } // namespace OHOS
76 #endif // NET_POLICY_FIREWALL_H
77