1 /*
2  * Copyright (c) 2021-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 NET_CONN_SERVICE_PROXY_H
17 #define NET_CONN_SERVICE_PROXY_H
18 
19 #include "iremote_proxy.h"
20 
21 #include "i_net_conn_service.h"
22 
23 namespace OHOS {
24 namespace NetManagerStandard {
25 class NetConnServiceProxy : public IRemoteProxy<INetConnService> {
26 public:
27     explicit NetConnServiceProxy(const sptr<IRemoteObject> &impl);
28     virtual ~NetConnServiceProxy();
29     int32_t SystemReady() override;
30     int32_t SetInternetPermission(uint32_t uid, uint8_t allow) override;
31     int32_t EnableVnicNetwork(const sptr<NetLinkInfo> &netLinkInfo, const std::set<int32_t> &uids) override;
32     int32_t DisableVnicNetwork() override;
33     int32_t RegisterNetSupplier(NetBearType bearerType, const std::string &ident, const std::set<NetCap> &netCaps,
34                                 uint32_t &supplierId) override;
35     int32_t UnregisterNetSupplier(uint32_t supplierId) override;
36     int32_t RegisterNetSupplierCallback(uint32_t supplierId, const sptr<INetSupplierCallback> &callback) override;
37     int32_t RegisterNetConnCallback(const sptr<INetConnCallback> callback) override;
38     int32_t RegisterNetConnCallback(const sptr<NetSpecifier> &netSpecifier, const sptr<INetConnCallback> callback,
39                                     const uint32_t &timeoutMS) override;
40     int32_t RequestNetConnection(const sptr<NetSpecifier> netSpecifier, const sptr<INetConnCallback> callback,
41                                     const uint32_t timeoutMS) override;
42     int32_t UnregisterNetConnCallback(const sptr<INetConnCallback> &callback) override;
43     int32_t UpdateNetStateForTest(const sptr<NetSpecifier> &netSpecifier, int32_t netState) override;
44     int32_t UpdateNetSupplierInfo(uint32_t supplierId, const sptr<NetSupplierInfo> &netSupplierInfo) override;
45     int32_t UpdateNetLinkInfo(uint32_t supplierId, const sptr<NetLinkInfo> &netLinkInfo) override;
46     int32_t GetDefaultNet(int32_t &netId) override;
47     int32_t HasDefaultNet(bool &flag) override;
48     int32_t GetIfaceNames(NetBearType bearerType, std::list<std::string> &ifaceNames) override;
49     int32_t GetIfaceNameByType(NetBearType bearerType, const std::string &ident, std::string &ifaceName) override;
50     int32_t GetIfaceNameIdentMaps(NetBearType bearerType,
51                                   SafeMap<std::string, std::string> &ifaceNameIdentMaps) override;
52     int32_t RegisterNetDetectionCallback(int32_t netId, const sptr<INetDetectionCallback> &callback) override;
53     int32_t UnRegisterNetDetectionCallback(int32_t netId, const sptr<INetDetectionCallback> &callback) override;
54     int32_t NetDetection(int32_t netId) override;
55     int32_t GetAddressesByName(const std::string &host, int32_t netId, std::vector<INetAddr> &addrList) override;
56     int32_t GetAddressByName(const std::string &host, int32_t netId, INetAddr &addr) override;
57     int32_t GetSpecificNet(NetBearType bearerType, std::list<int32_t> &netIdList) override;
58     int32_t GetAllNets(std::list<int32_t> &netIdList) override;
59     int32_t GetSpecificUidNet(int32_t uid, int32_t &netId) override;
60     int32_t GetConnectionProperties(int32_t netId, NetLinkInfo &info) override;
61     int32_t GetNetCapabilities(int32_t netId, NetAllCapabilities &netAllCap) override;
62     int32_t BindSocket(int32_t socketFd, int32_t netId) override;
63     int32_t SetAirplaneMode(bool state) override;
64     int32_t IsDefaultNetMetered(bool &isMetered) override;
65     int32_t SetGlobalHttpProxy(const HttpProxy &httpProxy) override;
66     int32_t GetGlobalHttpProxy(HttpProxy &httpProxy) override;
67     int32_t GetDefaultHttpProxy(int32_t bindNetId, HttpProxy &httpProxy) override;
68     int32_t GetNetIdByIdentifier(const std::string &ident, std::list<int32_t> &netIdList) override;
69     int32_t SetAppNet(int32_t netId) override;
70     int32_t RegisterNetInterfaceCallback(const sptr<INetInterfaceStateCallback> &callback) override;
71     int32_t GetNetInterfaceConfiguration(const std::string &iface, NetInterfaceConfiguration &config) override;
72     int32_t AddNetworkRoute(int32_t netId, const std::string &ifName, const std::string &destination,
73                             const std::string &nextHop) override;
74     int32_t RemoveNetworkRoute(int32_t netId, const std::string &ifName, const std::string &destination,
75                                const std::string &nextHop) override;
76     int32_t AddInterfaceAddress(const std::string &ifName, const std::string &ipAddr,
77                                 int32_t prefixLength) override;
78     int32_t DelInterfaceAddress(const std::string &ifName, const std::string &ipAddr,
79                                 int32_t prefixLength) override;
80     int32_t AddStaticArp(const std::string &ipAddr, const std::string &macAddr, const std::string &ifName) override;
81     int32_t DelStaticArp(const std::string &ipAddr, const std::string &macAddr, const std::string &ifName) override;
82     int32_t RegisterSlotType(uint32_t supplierId, int32_t type) override;
83     int32_t GetSlotType(std::string &type) override;
84     int32_t FactoryResetNetwork() override;
85     int32_t RegisterNetFactoryResetCallback(const sptr<INetFactoryResetCallback> &callback) override;
86     int32_t IsPreferCellularUrl(const std::string& url, bool& preferCellular) override;
87     int32_t RegisterPreAirplaneCallback(const sptr<IPreAirplaneCallback> callback) override;
88     int32_t UnregisterPreAirplaneCallback(const sptr<IPreAirplaneCallback> callback) override;
89     int32_t UpdateSupplierScore(NetBearType bearerType, uint32_t detectionStatus, uint32_t& supplierId) override;
90 
91 private:
92     bool WriteInterfaceToken(MessageParcel &data);
93     int32_t GetNetCapData(MessageParcel &reply, NetAllCapabilities &netAllCap);
94     int32_t RemoteSendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply);
95 
96 private:
97     static inline BrokerDelegator<NetConnServiceProxy> delegator_;
98 };
99 } // namespace NetManagerStandard
100 } // namespace OHOS
101 #endif // NET_CONN_SERVICE_PROXY_H
102