blob: 44e5128632db872a64490e959d4679277c0a0fcf [file] [log] [blame]
Sen Jiang255e22b2016-05-20 16:15:29 -07001//
2// Copyright (C) 2016 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
Amin Hassaniec7bc112020-10-29 16:47:58 -070017#include "update_engine/common/connection_utils.h"
Sen Jiang255e22b2016-05-20 16:15:29 -070018
19#include <shill/dbus-constants.h>
20
Colin Howesc9e98d62018-09-18 10:35:20 -070021namespace {
22// Not defined by shill since we don't use this outside of UE.
23constexpr char kTypeDisconnected[] = "Disconnected";
24constexpr char kTypeUnknown[] = "Unknown";
25} // namespace
26
Sen Jiang255e22b2016-05-20 16:15:29 -070027namespace chromeos_update_engine {
28namespace connection_utils {
29
30ConnectionType ParseConnectionType(const std::string& type_str) {
31 if (type_str == shill::kTypeEthernet) {
32 return ConnectionType::kEthernet;
33 } else if (type_str == shill::kTypeWifi) {
34 return ConnectionType::kWifi;
Sen Jiang255e22b2016-05-20 16:15:29 -070035 } else if (type_str == shill::kTypeCellular) {
36 return ConnectionType::kCellular;
Colin Howesc9e98d62018-09-18 10:35:20 -070037 } else if (type_str == kTypeDisconnected) {
38 return ConnectionType::kDisconnected;
Sen Jiang255e22b2016-05-20 16:15:29 -070039 }
40 return ConnectionType::kUnknown;
41}
42
43ConnectionTethering ParseConnectionTethering(const std::string& tethering_str) {
44 if (tethering_str == shill::kTetheringNotDetectedState) {
45 return ConnectionTethering::kNotDetected;
46 } else if (tethering_str == shill::kTetheringSuspectedState) {
47 return ConnectionTethering::kSuspected;
48 } else if (tethering_str == shill::kTetheringConfirmedState) {
49 return ConnectionTethering::kConfirmed;
50 }
51 return ConnectionTethering::kUnknown;
52}
53
54const char* StringForConnectionType(ConnectionType type) {
55 switch (type) {
56 case ConnectionType::kEthernet:
57 return shill::kTypeEthernet;
58 case ConnectionType::kWifi:
59 return shill::kTypeWifi;
Sen Jiang255e22b2016-05-20 16:15:29 -070060 case ConnectionType::kCellular:
61 return shill::kTypeCellular;
Colin Howesc9e98d62018-09-18 10:35:20 -070062 case ConnectionType::kDisconnected:
63 return kTypeDisconnected;
Sen Jiang255e22b2016-05-20 16:15:29 -070064 case ConnectionType::kUnknown:
Colin Howesc9e98d62018-09-18 10:35:20 -070065 return kTypeUnknown;
Sen Jiang255e22b2016-05-20 16:15:29 -070066 }
Colin Howesc9e98d62018-09-18 10:35:20 -070067 return kTypeUnknown;
Sen Jiang255e22b2016-05-20 16:15:29 -070068}
69
70} // namespace connection_utils
71
72} // namespace chromeos_update_engine