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 #ifndef NET_CONNECT_ADAPTER_H 17 #define NET_CONNECT_ADAPTER_H 18 19 #include <memory> 20 #include <string> 21 #include <vector> 22 23 namespace OHOS::NWeb { 24 25 enum class NetConnectType : uint32_t { 26 CONNECTION_UNKNOWN = 0, 27 CONNECTION_ETHERNET = 1, 28 CONNECTION_WIFI = 2, 29 CONNECTION_2G = 3, 30 CONNECTION_3G = 4, 31 CONNECTION_4G = 5, 32 CONNECTION_NONE = 6, 33 CONNECTION_BLUETOOTH = 7, 34 CONNECTION_5G = 8, 35 CONNECTION_LAST = CONNECTION_5G 36 }; 37 38 enum class NetConnectSubtype : uint32_t { 39 SUBTYPE_UNKNOWN = 0, 40 SUBTYPE_NONE, 41 SUBTYPE_OTHER, 42 SUBTYPE_GSM, 43 SUBTYPE_IDEN, 44 SUBTYPE_CDMA, 45 SUBTYPE_1XRTT, 46 SUBTYPE_GPRS, 47 SUBTYPE_EDGE, 48 SUBTYPE_UMTS, 49 SUBTYPE_EVDO_REV_0, 50 SUBTYPE_EVDO_REV_A, 51 SUBTYPE_HSPA, 52 SUBTYPE_EVDO_REV_B, 53 SUBTYPE_HSDPA, 54 SUBTYPE_HSUPA, 55 SUBTYPE_EHRPD, 56 SUBTYPE_HSPAP, 57 SUBTYPE_LTE, 58 SUBTYPE_LTE_ADVANCED, 59 SUBTYPE_BLUETOOTH_1_2, 60 SUBTYPE_BLUETOOTH_2_1, 61 SUBTYPE_BLUETOOTH_3_0, 62 SUBTYPE_BLUETOOTH_4_0, 63 SUBTYPE_ETHERNET, 64 SUBTYPE_FAST_ETHERNET, 65 SUBTYPE_GIGABIT_ETHERNET, 66 SUBTYPE_10_GIGABIT_ETHERNET, 67 SUBTYPE_WIFI_B, 68 SUBTYPE_WIFI_G, 69 SUBTYPE_WIFI_N, 70 SUBTYPE_WIFI_AC, 71 SUBTYPE_WIFI_AD, 72 SUBTYPE_LAST = SUBTYPE_WIFI_AD 73 }; 74 75 class NetCapabilitiesAdapter { 76 public: 77 NetCapabilitiesAdapter() = default; 78 virtual ~NetCapabilitiesAdapter() = default; 79 80 virtual int32_t GetNetId() = 0; 81 virtual NetConnectType GetConnectType() = 0; 82 virtual NetConnectSubtype GetConnectSubtype() = 0; 83 }; 84 85 class NetConnectionPropertiesAdapter { 86 public: 87 NetConnectionPropertiesAdapter() = default; 88 virtual ~NetConnectionPropertiesAdapter() = default; 89 90 virtual int32_t GetNetId() = 0; 91 }; 92 93 class NetConnCallback { 94 public: 95 NetConnCallback() = default; 96 virtual ~NetConnCallback() = default; 97 98 virtual int32_t NetAvailable() = 0; 99 virtual int32_t NetCapabilitiesChange( 100 const NetConnectType& netConnectType, const NetConnectSubtype& netConnectSubtype) = 0; 101 virtual int32_t NetConnectionPropertiesChange() = 0; 102 virtual int32_t NetUnavailable() = 0; OnNetCapabilitiesChanged(const std::shared_ptr<NetCapabilitiesAdapter> capabilities)103 virtual int32_t OnNetCapabilitiesChanged( 104 const std::shared_ptr<NetCapabilitiesAdapter> capabilities) { return 0; } OnNetConnectionPropertiesChanged(const std::shared_ptr<NetConnectionPropertiesAdapter> properties)105 virtual int32_t OnNetConnectionPropertiesChanged( 106 const std::shared_ptr<NetConnectionPropertiesAdapter> properties) { return 0; } 107 }; 108 109 class NetConnectAdapter { 110 public: 111 NetConnectAdapter() = default; 112 113 virtual ~NetConnectAdapter() = default; 114 115 virtual int32_t RegisterNetConnCallback(std::shared_ptr<NetConnCallback> cb) = 0; 116 117 virtual int32_t UnregisterNetConnCallback(int32_t id) = 0; 118 119 virtual int32_t GetDefaultNetConnect(NetConnectType& type, NetConnectSubtype& netConnectSubtype) = 0; 120 121 virtual std::vector<std::string> GetDnsServers() = 0; 122 123 virtual std::vector<std::string> GetDnsServersByNetId(int32_t netId) = 0; 124 }; 125 126 } // namespace OHOS::NWeb 127 128 #endif // NET_CONNECT_ADAPTER_H 129