• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "net_manager_center.h"
17 
18 #include "net_manager_constants.h"
19 
20 namespace OHOS {
21 namespace NetManagerStandard {
GetInstance()22 NetManagerCenter &NetManagerCenter::GetInstance()
23 {
24     static NetManagerCenter gInstance;
25     return gInstance;
26 }
27 
GetIfaceNames(NetBearType bearerType,std::list<std::string> & ifaceNames)28 int32_t NetManagerCenter::GetIfaceNames(NetBearType bearerType, std::list<std::string> &ifaceNames)
29 {
30     if (connService_ == nullptr) {
31         return NETMANAGER_ERROR;
32     }
33     return connService_->GetIfaceNames(bearerType, ifaceNames);
34 }
35 
GetIfaceNameByType(NetBearType bearerType,const std::string & ident,std::string & ifaceName)36 int32_t NetManagerCenter::GetIfaceNameByType(NetBearType bearerType, const std::string &ident, std::string &ifaceName)
37 {
38     if (connService_ == nullptr) {
39         return NETMANAGER_ERROR;
40     }
41     return connService_->GetIfaceNameByType(bearerType, ident, ifaceName);
42 }
43 
RegisterNetSupplier(NetBearType bearerType,const std::string & ident,const std::set<NetCap> & netCaps,uint32_t & supplierId)44 int32_t NetManagerCenter::RegisterNetSupplier(NetBearType bearerType, const std::string &ident,
45                                               const std::set<NetCap> &netCaps, uint32_t &supplierId)
46 {
47     if (connService_ == nullptr) {
48         return NETMANAGER_ERROR;
49     }
50     return connService_->RegisterNetSupplier(bearerType, ident, netCaps, supplierId);
51 }
52 
UnregisterNetSupplier(uint32_t supplierId)53 int32_t NetManagerCenter::UnregisterNetSupplier(uint32_t supplierId)
54 {
55     if (connService_ == nullptr) {
56         return NETMANAGER_ERROR;
57     }
58     return connService_->UnregisterNetSupplier(supplierId);
59 }
60 
UpdateNetLinkInfo(uint32_t supplierId,const sptr<NetLinkInfo> & netLinkInfo)61 int32_t NetManagerCenter::UpdateNetLinkInfo(uint32_t supplierId, const sptr<NetLinkInfo> &netLinkInfo)
62 {
63     if (connService_ == nullptr) {
64         return NETMANAGER_ERROR;
65     }
66     return connService_->UpdateNetLinkInfo(supplierId, netLinkInfo);
67 }
68 
UpdateNetSupplierInfo(uint32_t supplierId,const sptr<NetSupplierInfo> & netSupplierInfo)69 int32_t NetManagerCenter::UpdateNetSupplierInfo(uint32_t supplierId, const sptr<NetSupplierInfo> &netSupplierInfo)
70 {
71     if (connService_ == nullptr) {
72         return NETMANAGER_ERROR;
73     }
74     return connService_->UpdateNetSupplierInfo(supplierId, netSupplierInfo);
75 }
76 
RegisterConnService(const sptr<NetConnBaseService> & service)77 void NetManagerCenter::RegisterConnService(const sptr<NetConnBaseService> &service)
78 {
79     connService_ = service;
80 }
81 
GetIfaceStatsDetail(const std::string & iface,uint32_t start,uint32_t end,NetStatsInfo & info)82 int32_t NetManagerCenter::GetIfaceStatsDetail(const std::string &iface, uint32_t start, uint32_t end,
83                                               NetStatsInfo &info)
84 {
85     if (statsService_ == nullptr) {
86         return NETMANAGER_ERROR;
87     }
88     return statsService_->GetIfaceStatsDetail(iface, start, end, info);
89 }
90 
ResetStatsFactory()91 int32_t NetManagerCenter::ResetStatsFactory()
92 {
93     if (statsService_ == nullptr) {
94         return NETMANAGER_ERROR;
95     }
96     return statsService_->ResetStatsFactory();
97 }
98 
RegisterStatsService(const sptr<NetStatsBaseService> & service)99 void NetManagerCenter::RegisterStatsService(const sptr<NetStatsBaseService> &service)
100 {
101     statsService_ = service;
102 }
103 
ResetPolicyFactory()104 int32_t NetManagerCenter::ResetPolicyFactory()
105 {
106     if (policyService_ == nullptr) {
107         return NETMANAGER_ERROR;
108     }
109     return ResetPolicies();
110 }
111 
ResetPolicies()112 int32_t NetManagerCenter::ResetPolicies()
113 {
114     if (policyService_ == nullptr) {
115         return NETMANAGER_ERROR;
116     }
117     return policyService_->ResetPolicies();
118 }
119 
RegisterPolicyService(const sptr<NetPolicyBaseService> & service)120 void NetManagerCenter::RegisterPolicyService(const sptr<NetPolicyBaseService> &service)
121 {
122     policyService_ = service;
123 }
124 
ResetEthernetFactory()125 int32_t NetManagerCenter::ResetEthernetFactory()
126 {
127     if (ethernetService_ == nullptr) {
128         return NETMANAGER_ERROR;
129     }
130     return ethernetService_->ResetEthernetFactory();
131 }
132 
RegisterEthernetService(const sptr<NetEthernetBaseService> & service)133 void NetManagerCenter::RegisterEthernetService(const sptr<NetEthernetBaseService> &service)
134 {
135     ethernetService_ = service;
136 }
137 
GetAddressesByName(const std::string & hostName,int32_t netId,std::vector<INetAddr> & addrInfo)138 int32_t NetManagerCenter::GetAddressesByName(const std::string &hostName, int32_t netId,
139                                              std::vector<INetAddr> &addrInfo)
140 {
141     if (dnsService_ == nullptr) {
142         return NETMANAGER_ERROR;
143     }
144     return dnsService_->GetAddressesByName(hostName, netId, addrInfo);
145 }
146 
RegisterDnsService(const sptr<DnsBaseService> & service)147 void NetManagerCenter::RegisterDnsService(const sptr<DnsBaseService> &service)
148 {
149     dnsService_ = service;
150 }
151 
RestrictBackgroundChanged(bool isRestrictBackground)152 int32_t NetManagerCenter::RestrictBackgroundChanged(bool isRestrictBackground)
153 {
154     if (connService_ == nullptr) {
155         return NETMANAGER_ERROR;
156     }
157     return connService_->RestrictBackgroundChanged(isRestrictBackground);
158 }
159 
IsUidNetAccess(uint32_t uid,bool metered)160 bool NetManagerCenter::IsUidNetAccess(uint32_t uid, bool metered)
161 {
162     if (policyService_ == nullptr) {
163         return NETMANAGER_ERROR;
164     }
165     return IsUidNetAllowed(uid, metered);
166 }
167 
IsUidNetAllowed(uint32_t uid,bool metered)168 bool NetManagerCenter::IsUidNetAllowed(uint32_t uid, bool metered)
169 {
170     if (policyService_ == nullptr) {
171         return NETMANAGER_ERROR;
172     }
173     return policyService_->IsUidNetAllowed(uid, metered);
174 }
175 } // namespace NetManagerStandard
176 } // namespace OHOS
177