1 /*
2  * Copyright (C) 2021 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 #include "host/libs/config/adb/adb.h"
17 
18 #include <algorithm>
19 #include <string>
20 
21 namespace cuttlefish {
22 
StringToAdbMode(const std::string & mode_cased)23 AdbMode StringToAdbMode(const std::string& mode_cased) {
24   std::string mode = mode_cased;
25   std::transform(mode.begin(), mode.end(), mode.begin(), ::tolower);
26   if (mode == "vsock_tunnel") {
27     return AdbMode::VsockTunnel;
28   } else if (mode == "vsock_half_tunnel") {
29     return AdbMode::VsockHalfTunnel;
30   } else if (mode == "native_vsock") {
31     return AdbMode::NativeVsock;
32   } else {
33     return AdbMode::Unknown;
34   }
35 }
36 
AdbModeToString(AdbMode mode)37 std::string AdbModeToString(AdbMode mode) {
38   switch (mode) {
39     case AdbMode::VsockTunnel:
40       return "vsock_tunnel";
41     case AdbMode::VsockHalfTunnel:
42       return "vsock_half_tunnel";
43     case AdbMode::NativeVsock:
44       return "native_vsock";
45     case AdbMode::Unknown:  // fall through
46     default:
47       return "unknown";
48   }
49 }
50 
51 }  // namespace cuttlefish
52