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/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 30 ConnectionType 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::kTypeWimax) { 36 return ConnectionType::kWimax; 37 } else if (type_str == shill::kTypeBluetooth) { 38 return ConnectionType::kBluetooth; 39 } else if (type_str == shill::kTypeCellular) { 40 return ConnectionType::kCellular; 41 } else if (type_str == kTypeDisconnected) { 42 return ConnectionType::kDisconnected; 43 } 44 return ConnectionType::kUnknown; 45 } 46 47 ConnectionTethering ParseConnectionTethering(const std::string& tethering_str) { 48 if (tethering_str == shill::kTetheringNotDetectedState) { 49 return ConnectionTethering::kNotDetected; 50 } else if (tethering_str == shill::kTetheringSuspectedState) { 51 return ConnectionTethering::kSuspected; 52 } else if (tethering_str == shill::kTetheringConfirmedState) { 53 return ConnectionTethering::kConfirmed; 54 } 55 return ConnectionTethering::kUnknown; 56 } 57 58 const char* StringForConnectionType(ConnectionType type) { 59 switch (type) { 60 case ConnectionType::kEthernet: 61 return shill::kTypeEthernet; 62 case ConnectionType::kWifi: 63 return shill::kTypeWifi; 64 case ConnectionType::kWimax: 65 return shill::kTypeWimax; 66 case ConnectionType::kBluetooth: 67 return shill::kTypeBluetooth; 68 case ConnectionType::kCellular: 69 return shill::kTypeCellular; 70 case ConnectionType::kDisconnected: 71 return kTypeDisconnected; 72 case ConnectionType::kUnknown: 73 return kTypeUnknown; 74 } 75 return kTypeUnknown; 76 } 77 78 } // namespace connection_utils 79 80 } // namespace chromeos_update_engine 81