• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "net_connect_utils.h"
17 
18 namespace OHOS::NWeb {
ConvertToConnectTypeInner(const RadioTech & subtype)19 NetConnectType NetConnectUtils::ConvertToConnectTypeInner(const RadioTech &subtype)
20 {
21     switch (subtype) {
22         case RadioTech::RADIO_TECHNOLOGY_UNKNOWN:
23         case RadioTech::RADIO_TECHNOLOGY_IWLAN:
24             return NetConnectType::CONNECTION_UNKNOWN;
25         case RadioTech::RADIO_TECHNOLOGY_GSM:
26         case RadioTech::RADIO_TECHNOLOGY_1XRTT:
27             return NetConnectType::CONNECTION_2G;
28         case RadioTech::RADIO_TECHNOLOGY_WCDMA:
29         case RadioTech::RADIO_TECHNOLOGY_HSPA:
30         case RadioTech::RADIO_TECHNOLOGY_HSPAP:
31         case RadioTech::RADIO_TECHNOLOGY_TD_SCDMA:
32         case RadioTech::RADIO_TECHNOLOGY_EVDO:
33         case RadioTech::RADIO_TECHNOLOGY_EHRPD:
34             return NetConnectType::CONNECTION_3G;
35         case RadioTech::RADIO_TECHNOLOGY_LTE:
36         case RadioTech::RADIO_TECHNOLOGY_LTE_CA:
37             return NetConnectType::CONNECTION_4G;
38         case RadioTech::RADIO_TECHNOLOGY_NR:
39             return NetConnectType::CONNECTION_5G;
40         default:
41             return NetConnectType::CONNECTION_UNKNOWN;
42     }
43 }
44 
ConvertToConnectsubtype(const RadioTech & subtype)45 NetConnectSubtype NetConnectUtils::ConvertToConnectsubtype(const RadioTech &subtype)
46 {
47     switch (subtype) {
48         case RadioTech::RADIO_TECHNOLOGY_UNKNOWN:
49         case RadioTech::RADIO_TECHNOLOGY_IWLAN:
50         case RadioTech::RADIO_TECHNOLOGY_WCDMA:
51         case RadioTech::RADIO_TECHNOLOGY_TD_SCDMA:
52         case RadioTech::RADIO_TECHNOLOGY_EVDO:
53         case RadioTech::RADIO_TECHNOLOGY_NR:
54             return NetConnectSubtype::SUBTYPE_UNKNOWN;
55         case RadioTech::RADIO_TECHNOLOGY_GSM:
56             return NetConnectSubtype::SUBTYPE_GSM;
57         case RadioTech::RADIO_TECHNOLOGY_1XRTT:
58             return NetConnectSubtype::SUBTYPE_1XRTT;
59         case RadioTech::RADIO_TECHNOLOGY_HSPA:
60             return NetConnectSubtype::SUBTYPE_HSPA;
61         case RadioTech::RADIO_TECHNOLOGY_HSPAP:
62             return NetConnectSubtype::SUBTYPE_HSPAP;
63         case RadioTech::RADIO_TECHNOLOGY_EHRPD:
64             return NetConnectSubtype::SUBTYPE_EHRPD;
65         case RadioTech::RADIO_TECHNOLOGY_LTE:
66             return NetConnectSubtype::SUBTYPE_LTE;
67         case RadioTech::RADIO_TECHNOLOGY_LTE_CA:
68             return NetConnectSubtype::SUBTYPE_LTE_ADVANCED;
69         default:
70             return NetConnectSubtype::SUBTYPE_UNKNOWN;
71     }
72 }
73 
ConvertToConnectType(const NetBearType & netBearType,const RadioTech & subtype)74 NetConnectType NetConnectUtils::ConvertToConnectType(const NetBearType &netBearType, const RadioTech &subtype)
75 {
76     switch (netBearType) {
77         case BEARER_CELLULAR:
78             return ConvertToConnectTypeInner(subtype);
79         case BEARER_WIFI:
80             return NetConnectType::CONNECTION_WIFI;
81         case BEARER_BLUETOOTH:
82             return NetConnectType::CONNECTION_BLUETOOTH;
83         case BEARER_ETHERNET:
84             return NetConnectType::CONNECTION_ETHERNET;
85         case BEARER_VPN:
86         case BEARER_WIFI_AWARE:
87         case BEARER_DEFAULT:
88             return NetConnectType::CONNECTION_UNKNOWN;
89         default:
90             return NetConnectType::CONNECTION_UNKNOWN;
91     }
92 }
93 
ConnectTypeToString(const NetConnectType & type)94 std::string NetConnectUtils::ConnectTypeToString(const NetConnectType &type)
95 {
96     switch (type) {
97         case NetConnectType::CONNECTION_UNKNOWN:
98             return "unknown";
99         case NetConnectType::CONNECTION_ETHERNET:
100             return "ethernet";
101         case NetConnectType::CONNECTION_WIFI:
102             return "wifi";
103         case NetConnectType::CONNECTION_2G:
104             return "2g";
105         case NetConnectType::CONNECTION_3G:
106             return "3g";
107         case NetConnectType::CONNECTION_4G:
108             return "4g";
109         case NetConnectType::CONNECTION_NONE:
110             return "none";
111         case NetConnectType::CONNECTION_BLUETOOTH:
112             return "bluetooth";
113         case NetConnectType::CONNECTION_5G:
114             return "5g";
115     }
116 }
117 }  // namespace OHOS::NWeb