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 #include "netsys_policy_wrapper.h"
17
18 namespace OHOS {
19 namespace NetManagerStandard {
20 NetsysPolicyWrapper::NetsysPolicyWrapper() = default;
21
22 NetsysPolicyWrapper::~NetsysPolicyWrapper() = default;
23
RegisterNetsysCallback(sptr<NetsysControllerCallback> callback)24 int32_t NetsysPolicyWrapper::RegisterNetsysCallback(sptr<NetsysControllerCallback> callback)
25 {
26 auto netsysReturnValue = NetsysController::GetInstance().RegisterCallback(callback);
27 NETMGR_LOG_D("NetsysPolicyWrapper:RegisterNetsysObserver netsys return[%{public}d]", netsysReturnValue);
28 return netsysReturnValue;
29 }
30
BandwidthEnableDataSaver(bool enable)31 int32_t NetsysPolicyWrapper::BandwidthEnableDataSaver(bool enable)
32 {
33 auto netsysReturnValue = NetsysController::GetInstance().BandwidthEnableDataSaver(enable);
34 NETMGR_LOG_D("NetsysPolicyWrapper:EnableDataSaver enable[%{public}d] netsys return[%{public}d]", enable,
35 netsysReturnValue);
36 return netsysReturnValue;
37 }
38
BandwidthSetIfaceQuota(const std::string & iface,int64_t bytes)39 int32_t NetsysPolicyWrapper::BandwidthSetIfaceQuota(const std::string &iface, int64_t bytes)
40 {
41 auto netsysReturnValue = NetsysController::GetInstance().BandwidthSetIfaceQuota(iface, bytes);
42 NETMGR_LOG_D("NetsysPolicyWrapper:SetIfaceQuota iface[%{public}s] bytes[%{public}s] netsys return[%{public}d]",
43 iface.c_str(), std::to_string(bytes).c_str(), netsysReturnValue);
44 return netsysReturnValue;
45 }
46
BandwidthRemoveIfaceQuota(const std::string & iface)47 int32_t NetsysPolicyWrapper::BandwidthRemoveIfaceQuota(const std::string &iface)
48 {
49 auto netsysReturnValue = NetsysController::GetInstance().BandwidthRemoveIfaceQuota(iface);
50 NETMGR_LOG_D("NetsysPolicyWrapper:RemoveIfaceQuota iface[%{public}s] netsys return[%{public}d]", iface.c_str(),
51 netsysReturnValue);
52 return netsysReturnValue;
53 }
54
BandwidthAddDeniedList(uint32_t uid)55 int32_t NetsysPolicyWrapper::BandwidthAddDeniedList(uint32_t uid)
56 {
57 auto netsysReturnValue = NetsysController::GetInstance().BandwidthAddDeniedList(uid);
58 NETMGR_LOG_D("NetsysPolicyWrapper:AddDeniedList uid[%{public}u] netsys return[%{public}d]", uid, netsysReturnValue);
59 return netsysReturnValue;
60 }
61
BandwidthRemoveDeniedList(uint32_t uid)62 int32_t NetsysPolicyWrapper::BandwidthRemoveDeniedList(uint32_t uid)
63 {
64 auto netsysReturnValue = NetsysController::GetInstance().BandwidthRemoveDeniedList(uid);
65 NETMGR_LOG_D("NetsysPolicyWrapper:RemoveDeniedList uid[%{public}u] netsys return[%{public}d]", uid,
66 netsysReturnValue);
67 return netsysReturnValue;
68 }
69
BandwidthAddAllowedList(uint32_t uid)70 int32_t NetsysPolicyWrapper::BandwidthAddAllowedList(uint32_t uid)
71 {
72 auto netsysReturnValue = NetsysController::GetInstance().BandwidthAddAllowedList(uid);
73 NETMGR_LOG_D("NetsysPolicyWrapper:AddAllowedList uid[%{public}u] netsys return[%{public}d]", uid,
74 netsysReturnValue);
75 return netsysReturnValue;
76 }
77
BandwidthRemoveAllowedList(uint32_t uid)78 int32_t NetsysPolicyWrapper::BandwidthRemoveAllowedList(uint32_t uid)
79 {
80 auto netsysReturnValue = NetsysController::GetInstance().BandwidthRemoveAllowedList(uid);
81 NETMGR_LOG_D("NetsysPolicyWrapper:RemoveAllowedLists uid[%{public}u] netsys return[%{public}d]", uid,
82 netsysReturnValue);
83 return netsysReturnValue;
84 }
85
FirewallSetUidsAllowedListChain(uint32_t chain,const std::vector<uint32_t> & uids)86 int32_t NetsysPolicyWrapper::FirewallSetUidsAllowedListChain(uint32_t chain, const std::vector<uint32_t> &uids)
87 {
88 auto netsysReturnValue = NetsysController::GetInstance().FirewallSetUidsAllowedListChain(chain, uids);
89 NETMGR_LOG_D("SetUidsAllowedListChain chain[%{public}u] uids size[%{public}zu] netsys return[%{public}d]", chain,
90 uids.size(), netsysReturnValue);
91 return netsysReturnValue;
92 }
93
FirewallSetUidsDeniedListChain(uint32_t chain,const std::vector<uint32_t> & uids)94 int32_t NetsysPolicyWrapper::FirewallSetUidsDeniedListChain(uint32_t chain, const std::vector<uint32_t> &uids)
95 {
96 auto netsysReturnValue = NetsysController::GetInstance().FirewallSetUidsDeniedListChain(chain, uids);
97 NETMGR_LOG_D("SetUidsDeniedListChain chain[%{public}u] uids size[%{public}zu] netsys return[%{public}d]", chain,
98 uids.size(), netsysReturnValue);
99 return netsysReturnValue;
100 }
101
FirewallSetUidRule(uint32_t chain,uint32_t uid,uint32_t firewallRule)102 int32_t NetsysPolicyWrapper::FirewallSetUidRule(uint32_t chain, uint32_t uid, uint32_t firewallRule)
103 {
104 auto netsysReturnValue = NetsysController::GetInstance().FirewallSetUidRule(chain, uid, firewallRule);
105 NETMGR_LOG_D(
106 "NetsysPolicyWrapper:FirewallSetUidRule chain[%{public}u] uid[%{public}u] firewallRule[%{public}u] netsys "
107 "return[%{public}d]",
108 chain, uid, firewallRule, netsysReturnValue);
109 return netsysReturnValue;
110 }
111
FirewallEnableChain(uint32_t chain,bool enable)112 int32_t NetsysPolicyWrapper::FirewallEnableChain(uint32_t chain, bool enable)
113 {
114 auto netsysReturnValue = NetsysController::GetInstance().FirewallEnableChain(chain, enable);
115 NETMGR_LOG_D("FirewallEnableChain chain[%{public}u] enable[%{public}d] netsys return[%{public}d]", chain, enable,
116 netsysReturnValue);
117 return netsysReturnValue;
118 }
119 } // namespace NetManagerStandard
120 } // namespace OHOS
121