1 // 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 17 #include "update_engine/common/connection_utils.h" 18 19 #include <shill/dbus-constants.h> 20 21 namespace { 22 // Not defined by shill since we don't use this outside of UE. 23 constexpr char kTypeDisconnected[] = "Disconnected"; 24 constexpr char kTypeUnknown[] = "Unknown"; 25 } // namespace 26 27 namespace chromeos_update_engine { 28 namespace connection_utils { 29 ParseConnectionType(const std::string & type_str)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; 35 } else if (type_str == shill::kTypeCellular) { 36 return ConnectionType::kCellular; 37 } else if (type_str == kTypeDisconnected) { 38 return ConnectionType::kDisconnected; 39 } 40 return ConnectionType::kUnknown; 41 } 42 ParseConnectionTethering(const std::string & tethering_str)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 StringForConnectionType(ConnectionType type)54const char* StringForConnectionType(ConnectionType type) { 55 switch (type) { 56 case ConnectionType::kEthernet: 57 return shill::kTypeEthernet; 58 case ConnectionType::kWifi: 59 return shill::kTypeWifi; 60 case ConnectionType::kCellular: 61 return shill::kTypeCellular; 62 case ConnectionType::kDisconnected: 63 return kTypeDisconnected; 64 case ConnectionType::kUnknown: 65 return kTypeUnknown; 66 } 67 return kTypeUnknown; 68 } 69 70 } // namespace connection_utils 71 72 } // namespace chromeos_update_engine 73