1 /* 2 * Copyright (c) 2021-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_CONN_MANAGER_H 17 #define NET_CONN_MANAGER_H 18 19 #include <string> 20 #include <map> 21 22 #include "parcel.h" 23 #include "singleton.h" 24 25 #include "i_net_conn_service.h" 26 #include "i_net_supplier_callback.h" 27 #include "net_supplier_callback_base.h" 28 #include "net_link_info.h" 29 #include "net_specifier.h" 30 #include "net_handle.h" 31 #include "http_proxy.h" 32 33 namespace OHOS { 34 namespace nmd { 35 class FwmarkClient; 36 } 37 namespace NetManagerStandard { 38 class NetConnClient { 39 DECLARE_DELAYED_SINGLETON(NetConnClient) 40 41 public: 42 int32_t SystemReady(); 43 int32_t RegisterNetSupplier(NetBearType bearerType, const std::string &ident, const std::set<NetCap> &netCaps, 44 uint32_t &supplierId); 45 int32_t UnregisterNetSupplier(uint32_t supplierId); 46 int32_t RegisterNetSupplierCallback(uint32_t supplierId, const sptr<NetSupplierCallbackBase> &callback); 47 int32_t UpdateNetSupplierInfo(uint32_t supplierId, const sptr<NetSupplierInfo> &netSupplierInfo); 48 int32_t UpdateNetLinkInfo(uint32_t supplierId, const sptr<NetLinkInfo> &netLinkInfo); 49 int32_t RegisterNetConnCallback(const sptr<INetConnCallback> &callback); 50 int32_t RegisterNetConnCallback(const sptr<NetSpecifier> &netSpecifier, const sptr<INetConnCallback> &callback, 51 const uint32_t &timeoutMS); 52 int32_t UnregisterNetConnCallback(const sptr<INetConnCallback> &callback); 53 int32_t GetDefaultNet(NetHandle &netHandle); 54 int32_t HasDefaultNet(bool &flag); 55 int32_t GetAllNets(std::list<sptr<NetHandle>> &netList); 56 int32_t GetConnectionProperties(const NetHandle &netHandle, NetLinkInfo &info); 57 int32_t GetNetCapabilities(const NetHandle &netHandle, NetAllCapabilities &netAllCap); 58 int32_t GetAddressesByName(const std::string &host, int32_t netId, std::vector<INetAddr> &addrList); 59 int32_t GetAddressByName(const std::string &host, int32_t netId, INetAddr &addr); 60 int32_t BindSocket(int32_t socket_fd, int32_t netId); 61 int32_t NetDetection(const NetHandle &netHandle); 62 int32_t SetAirplaneMode(bool state); 63 int32_t IsDefaultNetMetered(bool &isMetered); 64 int32_t SetGlobalHttpProxy(const HttpProxy &httpProxy); 65 int32_t GetGlobalHttpProxy(HttpProxy &httpProxy); 66 int32_t GetNetIdByIdentifier(const std::string &ident, int32_t &netId); 67 int32_t SetAppNet(int32_t netId); 68 int32_t GetAppNet(int32_t &netId); 69 70 private: 71 class NetConnDeathRecipient : public IRemoteObject::DeathRecipient { 72 public: NetConnDeathRecipient(NetConnClient & client)73 explicit NetConnDeathRecipient(NetConnClient &client) : client_(client) {} 74 ~NetConnDeathRecipient() override = default; OnRemoteDied(const wptr<IRemoteObject> & remote)75 void OnRemoteDied(const wptr<IRemoteObject> &remote) override 76 { 77 client_.OnRemoteDied(remote); 78 } 79 80 private: 81 NetConnClient &client_; 82 }; 83 84 private: 85 sptr<INetConnService> GetProxy(); 86 void OnRemoteDied(const wptr<IRemoteObject> &remote); 87 88 private: 89 std::mutex mutex_; 90 sptr<INetConnService> NetConnService_; 91 sptr<IRemoteObject::DeathRecipient> deathRecipient_; 92 std::map<uint32_t, sptr<INetSupplierCallback>> netSupplierCallback_; 93 }; 94 } // namespace NetManagerStandard 95 } // namespace OHOS 96 97 #endif // NET_CONN_MANAGER_H 98