Use a std::set<std::string> for adb modes.
Validation is TODO, but this identifies the type as a list of strings.
Test: Run with -adb_mode=native_vsock,tunnel
Change-Id: I73ddc31258d93345a41ff005eb043a1f0eaca4ac
diff --git a/host/commands/launch/flags.cc b/host/commands/launch/flags.cc
index 49d34b3..db37fb3 100644
--- a/host/commands/launch/flags.cc
+++ b/host/commands/launch/flags.cc
@@ -5,6 +5,7 @@
#include <gflags/gflags.h>
#include <glog/logging.h>
+#include "common/libs/strings/str_split.h"
#include "common/libs/utils/environment.h"
#include "common/libs/utils/files.h"
#include "common/vsoc/lib/vsoc_memory.h"
@@ -254,7 +255,8 @@
tmp_config_obj.set_num_screen_buffers(FLAGS_num_screen_buffers);
tmp_config_obj.set_refresh_rate_hz(FLAGS_refresh_rate_hz);
tmp_config_obj.set_gdb_flag(FLAGS_qemu_gdb);
- tmp_config_obj.set_adb_mode(FLAGS_adb_mode);
+ std::vector<std::string> adb = cvd::StrSplit(FLAGS_adb_mode, ',');
+ tmp_config_obj.set_adb_mode(std::set<std::string>(adb.begin(), adb.end()));
tmp_config_obj.set_adb_ip_and_port("127.0.0.1:" + std::to_string(GetHostPort()));
tmp_config_obj.set_device_title(FLAGS_device_title);
diff --git a/host/commands/launch/launch.cc b/host/commands/launch/launch.cc
index 6af5b4f..8ef31c6 100644
--- a/host/commands/launch/launch.cc
+++ b/host/commands/launch/launch.cc
@@ -3,7 +3,6 @@
#include <glog/logging.h>
#include "common/libs/fs/shared_fd.h"
-#include "common/libs/strings/str_split.h"
#include "common/libs/utils/size_utils.h"
#include "common/vsoc/shm/screen_layout.h"
#include "host/commands/launch/launcher_defs.h"
@@ -46,8 +45,7 @@
}
bool AdbModeEnabled(const vsoc::CuttlefishConfig& config, const char* mode) {
- auto modes = cvd::StrSplit(config.adb_mode(), ',');
- return std::find(modes.begin(), modes.end(), mode) != modes.end();
+ return config.adb_mode().count(mode) > 0;
}
bool AdbTunnelEnabled(const vsoc::CuttlefishConfig& config) {
diff --git a/host/libs/config/cuttlefish_config.cpp b/host/libs/config/cuttlefish_config.cpp
index 1d18f56..82ac8e3 100644
--- a/host/libs/config/cuttlefish_config.cpp
+++ b/host/libs/config/cuttlefish_config.cpp
@@ -538,12 +538,20 @@
return (*dictionary_)[kCuttlefishEnvPath].asString();
}
-std::string CuttlefishConfig::adb_mode() const {
- return (*dictionary_)[kAdbMode].asString();
+std::set<std::string> CuttlefishConfig::adb_mode() const {
+ std::set<std::string> args_set;
+ for (auto& mode : (*dictionary_)[kAdbMode]) {
+ args_set.insert(mode.asString());
+ }
+ return args_set;
}
-void CuttlefishConfig::set_adb_mode(const std::string& mode) {
- (*dictionary_)[kAdbMode] = mode;
+void CuttlefishConfig::set_adb_mode(const std::set<std::string>& mode) {
+ Json::Value mode_json_obj(Json::arrayValue);
+ for (const auto& arg : mode) {
+ mode_json_obj.append(arg);
+ }
+ (*dictionary_)[kAdbMode] = mode_json_obj;
}
std::string CuttlefishConfig::adb_ip_and_port() const {
@@ -555,9 +563,14 @@
}
std::string CuttlefishConfig::adb_device_name() const {
- if (adb_mode().find("tunnel") != std::string::npos) {
+ // TODO(schuffelen): Deal with duplication between here and launch.cc
+ bool tunnelMode = adb_mode().count("tunnel") > 0;
+ bool vsockTunnel = adb_mode().count("vsock_tunnel") > 0;
+ bool vsockHalfProxy = adb_mode().count("vsock_half_proxy") > 0;
+ bool nativeVsock = adb_mode().count("native_vsock") > 0;
+ if (tunnelMode || vsockTunnel || vsockHalfProxy || nativeVsock) {
return adb_ip_and_port();
- } else if (adb_mode().find("usb") != std::string::npos) {
+ } else if (adb_mode().count("usb") > 0) {
return serial_number();
}
LOG(ERROR) << "no adb_mode found, returning bad device name";
diff --git a/host/libs/config/cuttlefish_config.h b/host/libs/config/cuttlefish_config.h
index f13a433..9f87399 100644
--- a/host/libs/config/cuttlefish_config.h
+++ b/host/libs/config/cuttlefish_config.h
@@ -215,8 +215,8 @@
void set_cuttlefish_env_path(const std::string& path);
std::string cuttlefish_env_path() const;
- void set_adb_mode(const std::string& mode);
- std::string adb_mode() const;
+ void set_adb_mode(const std::set<std::string>& modes);
+ std::set<std::string> adb_mode() const;
void set_adb_ip_and_port(const std::string& ip_port);
std::string adb_ip_and_port() const;