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