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_SUPPLIER_H 17 #define NET_SUPPLIER_H 18 19 #include <map> 20 #include <memory> 21 #include <set> 22 #include <string> 23 #include <vector> 24 25 #include "i_net_supplier_callback.h" 26 #include "i_net_conn_callback.h" 27 #include "http_proxy.h" 28 #include "network.h" 29 #include "net_caps.h" 30 #include "net_specifier.h" 31 #include "net_supplier_info.h" 32 33 namespace OHOS { 34 namespace NetManagerStandard { 35 enum CallbackType { 36 CALL_TYPE_UNKNOWN = 0, 37 CALL_TYPE_AVAILABLE = 1, 38 CALL_TYPE_LOSTING = 2, 39 CALL_TYPE_LOST = 3, 40 CALL_TYPE_UPDATE_CAP = 4, 41 CALL_TYPE_UPDATE_LINK = 5, 42 CALL_TYPE_UNAVAILABLE = 6, 43 CALL_TYPE_BLOCK_STATUS = 7, 44 }; 45 46 class NetSupplier : public virtual RefBase { 47 public: 48 NetSupplier(NetBearType bearerType, const std::string &netSupplierIdent, const std::set<NetCap> &netCaps); 49 ~NetSupplier() = default; 50 bool operator==(const NetSupplier &netSupplier) const; 51 void SetNetwork(const std::shared_ptr<Network> &network); 52 void UpdateNetSupplierInfo(const NetSupplierInfo &netSupplierInfo); 53 int32_t UpdateNetLinkInfo(const NetLinkInfo &netLinkInfo); 54 uint32_t GetSupplierId() const; 55 NetBearType GetNetSupplierType() const; 56 std::string GetNetSupplierIdent() const; 57 bool CompareNetCaps(const std::set<NetCap> caps) const; 58 bool HasNetCap(NetCap cap) const; 59 bool HasNetCaps(const std::set<NetCap> &caps) const; 60 const NetCaps &GetNetCaps() const; 61 NetAllCapabilities GetNetCapabilities() const; 62 bool GetRoaming() const; 63 int8_t GetStrength() const; 64 uint16_t GetFrequency() const; 65 int32_t GetSupplierUid() const; 66 std::shared_ptr<Network> GetNetwork() const; 67 int32_t GetNetId() const; 68 sptr<NetHandle> GetNetHandle() const; 69 void GetHttpProxy(HttpProxy &httpProxy); 70 void UpdateNetConnState(NetConnState netConnState); 71 bool IsConnecting() const; 72 bool IsConnected() const; 73 void SetNetValid(bool ifValid); 74 bool IsNetValidated(); 75 void SetNetScore(int32_t score); 76 int32_t GetNetScore() const; 77 void SetRealScore(int32_t score); 78 int32_t GetRealScore(); 79 bool SupplierConnection(const std::set<NetCap> &netCaps); 80 bool SupplierDisconnection(const std::set<NetCap> &netCaps); 81 void SetRestrictBackground(bool restrictBackground); 82 bool GetRestrictBackground() const; 83 bool RequestToConnect(uint32_t reqId); 84 int32_t SelectAsBestNetwork(uint32_t reqId); 85 void ReceiveBestScore(uint32_t reqId, int32_t bestScore, uint32_t supplierId); 86 int32_t CancelRequest(uint32_t reqId); 87 void RemoveBestRequest(uint32_t reqId); 88 std::set<uint32_t> &GetBestRequestList(); 89 void SetDefault(); 90 void ClearDefault(); 91 void RegisterSupplierCallback(const sptr<INetSupplierCallback> &callback); 92 93 private: 94 NetBearType netSupplierType_; 95 std::string netSupplierIdent_; 96 NetCaps netCaps_; 97 NetLinkInfo netLinkInfo_; 98 NetSupplierInfo netSupplierInfo_; 99 NetAllCapabilities netAllCapabilities_; 100 uint32_t supplierId_ = 0; 101 int32_t netScore_ = 0; 102 int32_t netRealScore_ = 0; 103 std::set<uint32_t> requestList_; 104 std::set<uint32_t> bestReqList_; 105 sptr<INetSupplierCallback> netController_ = nullptr; 106 std::shared_ptr<Network> network_ = nullptr; 107 sptr<NetHandle> netHandle_ = nullptr; 108 bool restrictBackground_ = true; 109 }; 110 } // namespace NetManagerStandard 111 } // namespace OHOS 112 #endif // NET_SUPPLIER_H 113