| Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 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 |  | 
| Colin Howes | c9e98d6 | 2018-09-18 10:35:20 -0700 | [diff] [blame] | 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 |  | 
| Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 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; | 
| Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 35 | } else if (type_str == shill::kTypeCellular) { | 
|  | 36 | return ConnectionType::kCellular; | 
| Colin Howes | c9e98d6 | 2018-09-18 10:35:20 -0700 | [diff] [blame] | 37 | } else if (type_str == kTypeDisconnected) { | 
|  | 38 | return ConnectionType::kDisconnected; | 
| Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 39 | } | 
|  | 40 | return ConnectionType::kUnknown; | 
|  | 41 | } | 
|  | 42 |  | 
|  | 43 | ConnectionTethering 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 |  | 
|  | 54 | const char* StringForConnectionType(ConnectionType type) { | 
|  | 55 | switch (type) { | 
|  | 56 | case ConnectionType::kEthernet: | 
|  | 57 | return shill::kTypeEthernet; | 
|  | 58 | case ConnectionType::kWifi: | 
|  | 59 | return shill::kTypeWifi; | 
| Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 60 | case ConnectionType::kCellular: | 
|  | 61 | return shill::kTypeCellular; | 
| Colin Howes | c9e98d6 | 2018-09-18 10:35:20 -0700 | [diff] [blame] | 62 | case ConnectionType::kDisconnected: | 
|  | 63 | return kTypeDisconnected; | 
| Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 64 | case ConnectionType::kUnknown: | 
| Colin Howes | c9e98d6 | 2018-09-18 10:35:20 -0700 | [diff] [blame] | 65 | return kTypeUnknown; | 
| Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 66 | } | 
| Colin Howes | c9e98d6 | 2018-09-18 10:35:20 -0700 | [diff] [blame] | 67 | return kTypeUnknown; | 
| Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 68 | } | 
|  | 69 |  | 
|  | 70 | }  // namespace connection_utils | 
|  | 71 |  | 
|  | 72 | }  // namespace chromeos_update_engine |