Merge "Tee output of assemble_cvd and run_cvd to a log file"
diff --git a/OWNERS b/OWNERS
index 9594320..1944029 100644
--- a/OWNERS
+++ b/OWNERS
@@ -1,8 +1,11 @@
+# Current team members
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
+
+# Former team members
[email protected]
diff --git a/common/libs/device_config/guest_device_config.cpp b/common/libs/device_config/guest_device_config.cpp
index d5558b9..fc2c587 100644
--- a/common/libs/device_config/guest_device_config.cpp
+++ b/common/libs/device_config/guest_device_config.cpp
@@ -32,14 +32,15 @@
bool GetRawFromServer(DeviceConfig::RawData* data) {
auto port_property = "ro.boot.cuttlefish_config_server_port";
- auto port = property_get_int32(port_property, -1);
+ auto port = property_get_int64(port_property, -1);
if (port < 0) {
LOG(ERROR) << "Unable to get config server port from property: " <<
port_property;
return false;
}
auto config_server =
- cvd::SharedFD::VsockClient(2 /*host cid*/, port, SOCK_STREAM);
+ cvd::SharedFD::VsockClient(2 /*host cid*/,
+ static_cast<unsigned int>(port), SOCK_STREAM);
if (!config_server->IsOpen()) {
LOG(ERROR) << "Unable to connect to config server: "
<< config_server->StrError();
diff --git a/common/libs/fs/shared_fd.cpp b/common/libs/fs/shared_fd.cpp
index 2f6d100..b85cf7c 100644
--- a/common/libs/fs/shared_fd.cpp
+++ b/common/libs/fs/shared_fd.cpp
@@ -17,6 +17,8 @@
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/mman.h>
+#include <sys/syscall.h>
#include <cstddef>
#include <errno.h>
#include <fcntl.h>
@@ -52,6 +54,34 @@
}
}
}
+
+/*
+ * Android currently has host prebuilts of glibc 2.15 and 2.17, but
+ * memfd_create was only added in glibc 2.27. It was defined in Linux 3.17,
+ * so we consider it safe to use the low-level arbitrary syscall wrapper.
+ */
+#ifndef __NR_memfd_create
+# if defined(__x86_64__)
+# define __NR_memfd_create 319
+# elif defined(__i386__)
+# define __NR_memfd_create 356
+# elif defined(__aarch64__)
+# define __NR_memfd_create 279
+# else
+/* No interest in other architectures. */
+# error "Unknown architecture."
+# endif
+#endif
+
+int memfd_create_wrapper(const char* name, unsigned int flags) {
+#ifdef CUTTLEFISH_HOST
+ // TODO(schuffelen): Use memfd_create with a newer host libc.
+ return syscall(__NR_memfd_create, name, flags);
+#else
+ return memfd_create(name, flags);
+#endif
+}
+
} // namespace
namespace cvd {
@@ -256,6 +286,12 @@
return std::shared_ptr<FileInstance>(new FileInstance(fd, errno));
}
+SharedFD SharedFD::MemfdCreate(const char* name, unsigned int flags) {
+ int fd = memfd_create_wrapper(name, flags);
+ int error_num = errno;
+ return std::shared_ptr<FileInstance>(new FileInstance(fd, error_num));
+}
+
bool SharedFD::SocketPair(int domain, int type, int protocol,
SharedFD* fd0, SharedFD* fd1) {
int fds[2];
diff --git a/common/libs/fs/shared_fd.h b/common/libs/fs/shared_fd.h
index eec17b1..044c7cc 100644
--- a/common/libs/fs/shared_fd.h
+++ b/common/libs/fs/shared_fd.h
@@ -145,6 +145,7 @@
static bool Pipe(SharedFD* fd0, SharedFD* fd1);
static SharedFD Event(int initval = 0, int flags = 0);
static SharedFD Epoll(int flags = 0);
+ static SharedFD MemfdCreate(const char* name, unsigned int flags = 0);
static bool SocketPair(int domain, int type, int protocol, SharedFD* fd0,
SharedFD* fd1);
static SharedFD Socket(int domain, int socket_type, int protocol);
diff --git a/common/libs/utils/subprocess.cpp b/common/libs/utils/subprocess.cpp
index e83b487..aed28de 100644
--- a/common/libs/utils/subprocess.cpp
+++ b/common/libs/utils/subprocess.cpp
@@ -19,6 +19,7 @@
#include <errno.h>
#include <signal.h>
#include <stdlib.h>
+#include <sys/prctl.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
@@ -69,7 +70,8 @@
const char* const* command, const char* const* envp,
const std::map<cvd::Subprocess::StdIOChannel, int>& redirects,
const std::map<cvd::SharedFD, int>& inherited_fds, bool with_control_socket,
- cvd::SubprocessStopper stopper, bool in_group = false, bool verbose = false) {
+ cvd::SubprocessStopper stopper, bool in_group = false, bool verbose = false,
+ bool exit_with_parent = true) {
// The parent socket will get closed on the child on the call to exec, the
// child socket will be closed on the parent when this function returns and no
// references to the fd are left
@@ -91,6 +93,10 @@
pid_t pid = fork();
if (!pid) {
+ if (exit_with_parent) {
+ prctl(PR_SET_PDEATHSIG, SIGHUP); // Die when parent dies
+ }
+
do_redirects(redirects);
if (in_group) {
// This call should never fail (see SETPGID(2))
@@ -293,26 +299,34 @@
verbose_ = verbose;
}
-Subprocess Command::StartHelper(bool with_control_socket, bool in_group) const {
+void Command::SetExitWithParent(bool exit_with_parent) {
+ exit_with_parent_ = exit_with_parent;
+}
+
+void Command::SetWithControlSocket(bool with_control_socket) {
+ with_control_socket_ = with_control_socket;
+}
+
+Subprocess Command::StartHelper(bool in_group) const {
auto cmd = ToCharPointers(command_);
if (use_parent_env_) {
return subprocess_impl(cmd.data(), nullptr, redirects_, inherited_fds_,
- with_control_socket, subprocess_stopper_, in_group,
- verbose_);
+ with_control_socket_, subprocess_stopper_, in_group,
+ verbose_, exit_with_parent_);
} else {
auto envp = ToCharPointers(env_);
return subprocess_impl(cmd.data(), envp.data(), redirects_, inherited_fds_,
- with_control_socket, subprocess_stopper_, in_group,
- verbose_);
+ with_control_socket_, subprocess_stopper_, in_group,
+ verbose_, exit_with_parent_);
}
}
-Subprocess Command::Start(bool with_control_socket) const {
- return StartHelper(with_control_socket, false);
+Subprocess Command::Start() const {
+ return StartHelper(false);
}
-Subprocess Command::StartInGroup(bool with_control_socket) const {
- return StartHelper(with_control_socket, true);
+Subprocess Command::StartInGroup() const {
+ return StartHelper(true);
}
// A class that waits for threads to exit in its destructor.
diff --git a/common/libs/utils/subprocess.h b/common/libs/utils/subprocess.h
index 44976f9..67e5ae2 100644
--- a/common/libs/utils/subprocess.h
+++ b/common/libs/utils/subprocess.h
@@ -118,8 +118,10 @@
// optional subprocess stopper. When not provided, stopper defaults to sending
// SIGKILL to the subprocess.
Command(const std::string& executable,
- SubprocessStopper stopper = KillSubprocess)
- : subprocess_stopper_(stopper), verbose_(true) {
+ SubprocessStopper stopper = KillSubprocess,
+ bool exit_with_parent = true)
+ : subprocess_stopper_(stopper), verbose_(true),
+ exit_with_parent_(exit_with_parent), with_control_socket_(false) {
command_.push_back(executable);
}
Command(Command&&) = default;
@@ -159,15 +161,16 @@
Subprocess::StdIOChannel parent_channel);
void SetVerbose(bool verbose);
+ void SetExitWithParent(bool exit_with_parent);
+ // If with_control_socket is true the returned Subprocess instance will have a
+ // sharedFD that enables communication with the child process.
+ void SetWithControlSocket(bool with_control_socket);
// Starts execution of the command. This method can be called multiple times,
- // effectively staring multiple (possibly concurrent) instances. If
- // with_control_socket is true the returned Subprocess instance will have a
- // sharedFD that enables communication with the child process.
- Subprocess Start(bool with_control_socket = false) const;
- // Same as Start(bool), but the subprocess runs as head of its own process
- // group.
- Subprocess StartInGroup(bool with_control_socket = false) const;
+ // effectively staring multiple (possibly concurrent) instances.
+ Subprocess Start() const;
+ // Same as Start(), but the subprocess runs as head of its own process group.
+ Subprocess StartInGroup() const;
std::string GetShortName() const {
// This is safe because the constructor guarantees the name of the binary to
@@ -176,7 +179,7 @@
}
private:
- Subprocess StartHelper(bool with_control_socket, bool in_group) const;
+ Subprocess StartHelper(bool in_group) const;
std::vector<std::string> command_;
std::map<cvd::SharedFD, int> inherited_fds_{};
@@ -185,6 +188,8 @@
std::vector<std::string> env_{};
SubprocessStopper subprocess_stopper_;
bool verbose_;
+ bool exit_with_parent_;
+ bool with_control_socket_;
};
/*
diff --git a/guest/commands/vsock_logcat/main.cpp b/guest/commands/vsock_logcat/main.cpp
index 51d97e3..2abc20b 100644
--- a/guest/commands/vsock_logcat/main.cpp
+++ b/guest/commands/vsock_logcat/main.cpp
@@ -34,8 +34,10 @@
#include "common/libs/utils/files.h"
#include "common/libs/utils/subprocess.h"
-DEFINE_uint32(port, property_get_int32("ro.boot.vsock_logcat_port", 0),
- "VSOCK port to send logcat output to");
+DEFINE_uint32(
+ port,
+ static_cast<uint32_t>(property_get_int64("ro.boot.vsock_logcat_port", 0)),
+ "VSOCK port to send logcat output to");
DEFINE_uint32(cid, 2, "VSOCK CID to send logcat output to");
DEFINE_string(pipe_name, "/dev/cf_logcat_pipe",
"The path for the named pipe logcat will write to");
diff --git a/guest/hals/audio/audio_hw.c b/guest/hals/audio/audio_hw.c
index f0979a9..41a0543 100644
--- a/guest/hals/audio/audio_hw.c
+++ b/guest/hals/audio/audio_hw.c
@@ -34,6 +34,7 @@
#include <unistd.h>
#include <log/log.h>
+#include <cutils/list.h>
#include <cutils/str_parms.h>
#include <hardware/hardware.h>
@@ -52,10 +53,13 @@
#define IN_PERIOD_COUNT 4
struct generic_audio_device {
- struct audio_hw_device device; // Constant after init
+ struct audio_hw_device device; // Constant after init
pthread_mutex_t lock;
- bool mic_mute; // Proteced by this->lock
- struct mixer* mixer; // Proteced by this->lock
+ bool mic_mute; // Protected by this->lock
+ struct mixer* mixer; // Protected by this->lock
+ struct listnode out_streams; // Record for output streams, protected by this->lock
+ struct listnode in_streams; // Record for input streams, protected by this->lock
+ audio_patch_handle_t next_patch_handle; // Protected by this->lock
};
/* If not NULL, this is a pointer to the fallback module.
@@ -172,13 +176,14 @@
}
struct generic_stream_out {
- struct audio_stream_out stream; // Constant after init
+ struct audio_stream_out stream; // Constant after init
pthread_mutex_t lock;
- struct generic_audio_device *dev; // Constant after init
- audio_devices_t device; // Protected by this->lock
- struct audio_config req_config; // Constant after init
- struct pcm_config pcm_config; // Constant after init
- audio_vbuffer_t buffer; // Constant after init
+ struct generic_audio_device *dev; // Constant after init
+ uint32_t num_devices; // Protected by this->lock
+ audio_devices_t devices[AUDIO_PATCH_PORTS_MAX]; // Protected by this->lock
+ struct audio_config req_config; // Constant after init
+ struct pcm_config pcm_config; // Constant after init
+ audio_vbuffer_t buffer; // Constant after init
// Time & Position Keeping
bool standby; // Protected by this->lock
@@ -194,6 +199,11 @@
pthread_cond_t worker_wake; // Protected by this->lock
bool worker_standby; // Protected by this->lock
bool worker_exit; // Protected by this->lock
+
+ audio_io_handle_t handle; // Constant after init
+ audio_patch_handle_t patch_handle; // Protected by this->dev->lock
+
+ struct listnode stream_node; // Protected by this->dev->lock
};
struct generic_stream_in {
@@ -219,6 +229,11 @@
pthread_cond_t worker_wake; // Protected by this->lock
bool worker_standby; // Protected by this->lock
bool worker_exit; // Protected by this->lock
+
+ audio_io_handle_t handle; // Constant after init
+ audio_patch_handle_t patch_handle; // Protected by this->dev->lock
+
+ struct listnode stream_node; // Protected by this->dev->lock
};
static struct pcm_config pcm_config_out = {
@@ -290,29 +305,32 @@
"\t\tbuffer size: %zu\n"
"\t\tchannel mask: %08x\n"
"\t\tformat: %d\n"
- "\t\tdevice: %08x\n"
- "\t\taudio dev: %p\n\n",
+ "\t\tdevice(s): ",
out_get_sample_rate(stream),
out_get_buffer_size(stream),
out_get_channels(stream),
- out_get_format(stream),
- out->device,
- out->dev);
+ out_get_format(stream));
+ if (out->num_devices == 0) {
+ dprintf(fd, "%08x\n", AUDIO_DEVICE_NONE);
+ } else {
+ for (uint32_t i = 0; i < out->num_devices; i++) {
+ if (i != 0) {
+ dprintf(fd, ", ");
+ }
+ dprintf(fd, "%08x", out->devices[i]);
+ }
+ dprintf(fd, "\n");
+ }
+ dprintf(fd, "\t\taudio dev: %p\n\n", out->dev);
pthread_mutex_unlock(&out->lock);
return 0;
}
static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
{
- struct generic_stream_out *out = (struct generic_stream_out *)stream;
struct str_parms *parms;
char value[32];
- int ret = -EINVAL;
int success;
- long val;
- char *end;
- bool new_device_req = false;
- int new_device;
if (kvpairs == NULL || kvpairs[0] == 0) {
return 0;
@@ -320,28 +338,16 @@
parms = str_parms_create_str(kvpairs);
success = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING,
value, sizeof(value));
- if (success >= 0) {
- errno = 0;
- val = strtol(value, &end, 10);
- if ((errno == 0) && (end != NULL) && (*end == '\0') && ((int)val == val)) {
- new_device_req = true;
- new_device = (int)val;
- ret = 0;
- }
- }
- str_parms_destroy(parms);
- if (ret != 0) {
- ALOGD("%s: Unsupported parameter %s", __FUNCTION__, kvpairs);
- return ret;
- }
+ // As the hal version is 3.0, it must not use set parameters API to set audio devices.
+ // Instead, it should use create_audio_patch API.
+ assert(("Must not use set parameters API to set audio devices", success < 0));
- // Try applying change requests
- pthread_mutex_lock(&out->lock);
- if (new_device_req) {
- out->device = new_device;
- }
- pthread_mutex_unlock(&out->lock);
- return ret;
+ str_parms_destroy(parms);
+
+ ALOGW("%s(), unsupported parameter %s", __func__, kvpairs);
+ // There is not any key supported for set_parameters API.
+ // Return error when there is non-null value passed in.
+ return -EINVAL;
}
static char * out_get_parameters(const struct audio_stream *stream, const char *keys)
@@ -357,7 +363,11 @@
ret = str_parms_get_str(query, AUDIO_PARAMETER_STREAM_ROUTING, value, sizeof(value));
if (ret >= 0) {
pthread_mutex_lock(&out->lock);
- str_parms_add_int(reply, AUDIO_PARAMETER_STREAM_ROUTING, out->device);
+ audio_devices_t device = AUDIO_DEVICE_NONE;
+ for (uint32_t i = 0; i < out->num_devices; i++) {
+ device |= out->devices[i];
+ }
+ str_parms_add_int(reply, AUDIO_PARAMETER_STREAM_ROUTING, device);
pthread_mutex_unlock(&out->lock);
get = true;
}
@@ -377,7 +387,7 @@
}
if (get) {
- str = strdup(str_parms_to_str(reply));
+ str = str_parms_to_str(reply);
}
else {
ALOGD("%s Unsupported paramter: %s", __FUNCTION__, keys);
@@ -834,15 +844,9 @@
static int in_set_parameters(struct audio_stream *stream, const char *kvpairs)
{
- struct generic_stream_in *in = (struct generic_stream_in *)stream;
struct str_parms *parms;
char value[32];
- int ret = -EINVAL;
int success;
- long val;
- char *end;
- bool new_device_req = false;
- int new_device;
if (kvpairs == NULL || kvpairs[0] == 0) {
return 0;
@@ -850,28 +854,16 @@
parms = str_parms_create_str(kvpairs);
success = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING,
value, sizeof(value));
- if (success >= 0) {
- errno = 0;
- val = strtol(value, &end, 10);
- if ((errno == 0) && (end != NULL) && (*end == '\0') && ((int)val == val)) {
- new_device_req = true;
- new_device = (int)val;
- ret = 0;
- }
- }
- str_parms_destroy(parms);
- if (ret != 0) {
- ALOGD("%s: Unsupported parameter %s", __FUNCTION__, kvpairs);
- return ret;
- }
+ // As the hal version is 3.0, it must not use set parameters API to set audio device.
+ // Instead, it should use create_audio_patch API.
+ assert(("Must not use set parameters API to set audio devices", success < 0));
- // Try applying change requests
- pthread_mutex_lock(&in->lock);
- if (new_device_req) {
- in->device = new_device;
- }
- pthread_mutex_unlock(&in->lock);
- return ret;
+ str_parms_destroy(parms);
+
+ ALOGW("%s(), unsupported parameter %s", __func__, kvpairs);
+ // There is not any key supported for set_parameters API.
+ // Return error when there is non-null value passed in.
+ return -EINVAL;
}
static char * in_get_parameters(const struct audio_stream *stream,
@@ -906,7 +898,7 @@
}
if (get) {
- str = strdup(str_parms_to_str(reply));
+ str = str_parms_to_str(reply);
}
else {
ALOGD("%s Unsupported paramter: %s", __FUNCTION__, keys);
@@ -1222,9 +1214,13 @@
out->stream.get_presentation_position = out_get_presentation_position;
out->stream.get_next_write_timestamp = out_get_next_write_timestamp;
+ out->handle = handle;
+
pthread_mutex_init(&out->lock, (const pthread_mutexattr_t *) NULL);
out->dev = adev;
- out->device = devices;
+ // Only 1 device is expected despite the argument being named 'devices'
+ out->num_devices = 1;
+ out->devices[0] = devices;
memcpy(&out->req_config, config, sizeof(struct audio_config));
memcpy(&out->pcm_config, &pcm_config_out, sizeof(struct pcm_config));
out->pcm_config.rate = config->sample_rate;
@@ -1250,14 +1246,33 @@
pthread_create(&out->worker_thread, NULL, out_write_worker, out);
}
- *stream_out = &out->stream;
+ pthread_mutex_lock(&adev->lock);
+ list_add_tail(&adev->out_streams, &out->stream_node);
+ pthread_mutex_unlock(&adev->lock);
+
+ *stream_out = &out->stream;
error:
return ret;
}
+// This must be called with adev->lock held.
+struct generic_stream_out *get_stream_out_by_io_handle_l(
+ struct generic_audio_device *adev, audio_io_handle_t handle) {
+ struct listnode *node;
+
+ list_for_each(node, &adev->out_streams) {
+ struct generic_stream_out *out = node_to_item(
+ node, struct generic_stream_out, stream_node);
+ if (out->handle == handle) {
+ return out;
+ }
+ }
+ return NULL;
+}
+
static void adev_close_output_stream(struct audio_hw_device *dev,
struct audio_stream_out *stream)
{
@@ -1272,6 +1287,11 @@
pthread_join(out->worker_thread, NULL);
pthread_mutex_destroy(&out->lock);
audio_vbuffer_destroy(&out->buffer);
+
+ struct generic_audio_device *adev = (struct generic_audio_device *) dev;
+ pthread_mutex_lock(&adev->lock);
+ list_remove(&out->stream_node);
+ pthread_mutex_unlock(&adev->lock);
free(stream);
}
@@ -1348,6 +1368,20 @@
return get_input_buffer_size(config->sample_rate, config->format, config->channel_mask);
}
+// This must be called with adev->lock held.
+struct generic_stream_in *get_stream_in_by_io_handle_l(
+ struct generic_audio_device *adev, audio_io_handle_t handle) {
+ struct listnode *node;
+
+ list_for_each(node, &adev->in_streams) {
+ struct generic_stream_in *in = node_to_item(
+ node, struct generic_stream_in, stream_node);
+ if (in->handle == handle) {
+ return in;
+ }
+ }
+ return NULL;
+}
static void adev_close_input_stream(struct audio_hw_device *dev,
struct audio_stream_in *stream)
@@ -1368,6 +1402,11 @@
pthread_mutex_destroy(&in->lock);
audio_vbuffer_destroy(&in->buffer);
+
+ struct generic_audio_device *adev = (struct generic_audio_device *) dev;
+ pthread_mutex_lock(&adev->lock);
+ list_remove(&in->stream_node);
+ pthread_mutex_unlock(&adev->lock);
free(stream);
}
@@ -1442,6 +1481,11 @@
in->worker_exit = false;
pthread_create(&in->worker_thread, NULL, in_read_worker, in);
}
+ in->handle = handle;
+
+ pthread_mutex_lock(&adev->lock);
+ list_add_tail(&adev->in_streams, &in->stream_node);
+ pthread_mutex_unlock(&adev->lock);
*stream_in = &in->stream;
@@ -1497,6 +1541,159 @@
return 0;
}
+static int adev_create_audio_patch(struct audio_hw_device *dev,
+ unsigned int num_sources,
+ const struct audio_port_config *sources,
+ unsigned int num_sinks,
+ const struct audio_port_config *sinks,
+ audio_patch_handle_t *handle) {
+ if (num_sources != 1 || num_sinks == 0 || num_sinks > AUDIO_PATCH_PORTS_MAX) {
+ return -EINVAL;
+ }
+
+ if (sources[0].type == AUDIO_PORT_TYPE_DEVICE) {
+ // If source is a device, the number of sinks should be 1.
+ if (num_sinks != 1 || sinks[0].type != AUDIO_PORT_TYPE_MIX) {
+ return -EINVAL;
+ }
+ } else if (sources[0].type == AUDIO_PORT_TYPE_MIX) {
+ // If source is a mix, all sinks should be device.
+ for (unsigned int i = 0; i < num_sinks; i++) {
+ if (sinks[i].type != AUDIO_PORT_TYPE_DEVICE) {
+ ALOGE("%s() invalid sink type %#x for mix source", __func__, sinks[i].type);
+ return -EINVAL;
+ }
+ }
+ } else {
+ // All other cases are invalid.
+ return -EINVAL;
+ }
+
+ struct generic_audio_device* adev = (struct generic_audio_device*) dev;
+ int ret = 0;
+ bool generatedPatchHandle = false;
+ pthread_mutex_lock(&adev->lock);
+ if (*handle == AUDIO_PATCH_HANDLE_NONE) {
+ *handle = ++adev->next_patch_handle;
+ generatedPatchHandle = true;
+ }
+
+ // Only handle patches for mix->devices and device->mix case.
+ if (sources[0].type == AUDIO_PORT_TYPE_DEVICE) {
+ struct generic_stream_in *in =
+ get_stream_in_by_io_handle_l(adev, sinks[0].ext.mix.handle);
+ if (in == NULL) {
+ ALOGE("%s()can not find stream with handle(%d)", __func__, sources[0].ext.mix.handle);
+ ret = -EINVAL;
+ goto error;
+ }
+
+ // Check if the patch handle match the recorded one if a valid patch handle is passed.
+ if (!generatedPatchHandle && in->patch_handle != *handle) {
+ ALOGE("%s() the patch handle(%d) does not match recorded one(%d) for stream "
+ "with handle(%d) when creating audio patch for device->mix",
+ __func__, *handle, in->patch_handle, in->handle);
+ ret = -EINVAL;
+ goto error;
+ }
+ pthread_mutex_lock(&in->lock);
+ in->device = sources[0].ext.device.type;
+ pthread_mutex_unlock(&in->lock);
+ in->patch_handle = *handle;
+ } else {
+ struct generic_stream_out *out =
+ get_stream_out_by_io_handle_l(adev, sources[0].ext.mix.handle);
+ if (out == NULL) {
+ ALOGE("%s()can not find stream with handle(%d)", __func__, sources[0].ext.mix.handle);
+ ret = -EINVAL;
+ goto error;
+ }
+
+ // Check if the patch handle match the recorded one if a valid patch handle is passed.
+ if (!generatedPatchHandle && out->patch_handle != *handle) {
+ ALOGE("%s() the patch handle(%d) does not match recorded one(%d) for stream "
+ "with handle(%d) when creating audio patch for mix->device",
+ __func__, *handle, out->patch_handle, out->handle);
+ ret = -EINVAL;
+ pthread_mutex_unlock(&out->lock);
+ goto error;
+ }
+ pthread_mutex_lock(&out->lock);
+ for (out->num_devices = 0; out->num_devices < num_sinks; out->num_devices++) {
+ out->devices[out->num_devices] = sinks[out->num_devices].ext.device.type;
+ }
+ pthread_mutex_unlock(&out->lock);
+ out->patch_handle = *handle;
+ }
+
+error:
+ if (ret != 0 && generatedPatchHandle) {
+ *handle = AUDIO_PATCH_HANDLE_NONE;
+ }
+ pthread_mutex_unlock(&adev->lock);
+ return 0;
+}
+
+// This must be called with adev->lock held.
+struct generic_stream_out *get_stream_out_by_patch_handle_l(
+ struct generic_audio_device *adev, audio_patch_handle_t patch_handle) {
+ struct listnode *node;
+
+ list_for_each(node, &adev->out_streams) {
+ struct generic_stream_out *out = node_to_item(
+ node, struct generic_stream_out, stream_node);
+ if (out->patch_handle == patch_handle) {
+ return out;
+ }
+ }
+ return NULL;
+}
+
+// This must be called with adev->lock held.
+struct generic_stream_in *get_stream_in_by_patch_handle_l(
+ struct generic_audio_device *adev, audio_patch_handle_t patch_handle) {
+ struct listnode *node;
+
+ list_for_each(node, &adev->in_streams) {
+ struct generic_stream_in *in = node_to_item(
+ node, struct generic_stream_in, stream_node);
+ if (in->patch_handle == patch_handle) {
+ return in;
+ }
+ }
+ return NULL;
+}
+
+static int adev_release_audio_patch(struct audio_hw_device *dev,
+ audio_patch_handle_t patch_handle) {
+ struct generic_audio_device *adev = (struct generic_audio_device *) dev;
+
+ pthread_mutex_lock(&adev->lock);
+ struct generic_stream_out *out = get_stream_out_by_patch_handle_l(adev, patch_handle);
+ if (out != NULL) {
+ pthread_mutex_lock(&out->lock);
+ out->num_devices = 0;
+ memset(out->devices, 0, sizeof(out->devices));
+ pthread_mutex_unlock(&out->lock);
+ out->patch_handle = AUDIO_PATCH_HANDLE_NONE;
+ pthread_mutex_unlock(&adev->lock);
+ return 0;
+ }
+ struct generic_stream_in *in = get_stream_in_by_patch_handle_l(adev, patch_handle);
+ if (in != NULL) {
+ pthread_mutex_lock(&in->lock);
+ in->device = AUDIO_DEVICE_NONE;
+ pthread_mutex_unlock(&in->lock);
+ in->patch_handle = AUDIO_PATCH_HANDLE_NONE;
+ pthread_mutex_unlock(&adev->lock);
+ return 0;
+ }
+
+ pthread_mutex_unlock(&adev->lock);
+ ALOGW("%s() cannot find stream for patch handle: %d", __func__, patch_handle);
+ return -EINVAL;
+}
+
static int adev_close(hw_device_t *dev)
{
struct generic_audio_device *adev = (struct generic_audio_device *)dev;
@@ -1545,7 +1742,7 @@
pthread_mutex_init(&adev->lock, (const pthread_mutexattr_t *) NULL);
adev->device.common.tag = HARDWARE_DEVICE_TAG;
- adev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0;
+ adev->device.common.version = AUDIO_DEVICE_API_VERSION_3_0;
adev->device.common.module = (struct hw_module_t *) module;
adev->device.common.close = adev_close;
@@ -1567,9 +1764,15 @@
adev->device.close_input_stream = adev_close_input_stream;
adev->device.dump = adev_dump;
adev->device.get_microphones = adev_get_microphones;
+ adev->device.create_audio_patch = adev_create_audio_patch;
+ adev->device.release_audio_patch = adev_release_audio_patch;
*device = &adev->device.common;
+ adev->next_patch_handle = AUDIO_PATCH_HANDLE_NONE;
+ list_init(&adev->out_streams);
+ list_init(&adev->in_streams);
+
adev->mixer = mixer_open(PCM_CARD);
struct mixer_ctl *ctl;
diff --git a/guest/hals/hwcomposer/cutf_cvm/vsocket_screen_view.cpp b/guest/hals/hwcomposer/cutf_cvm/vsocket_screen_view.cpp
index 2e2683f..b67544c 100644
--- a/guest/hals/hwcomposer/cutf_cvm/vsocket_screen_view.cpp
+++ b/guest/hals/hwcomposer/cutf_cvm/vsocket_screen_view.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#define LOG_TAG "vsock_hwc"
+
#include "guest/hals/hwcomposer/cutf_cvm/vsocket_screen_view.h"
#include <cutils/properties.h>
@@ -54,17 +56,19 @@
y_res_ = device_config->screen_y_res();
dpi_ = device_config->screen_dpi();
refresh_rate_ = device_config->screen_refresh_rate();
+ ALOGI("Received screen parameters: res=%dx%d, dpi=%d, freq=%d", x_res_,
+ y_res_, dpi_, refresh_rate_);
}
bool VsocketScreenView::ConnectToScreenServer() {
- auto vsock_frames_port = property_get_int32("ro.boot.vsock_frames_port", -1);
+ auto vsock_frames_port = property_get_int64("ro.boot.vsock_frames_port", -1);
if (vsock_frames_port <= 0) {
ALOGI("No screen server configured, operating on headless mode");
return false;
}
- screen_server_ =
- cvd::SharedFD::VsockClient(2, vsock_frames_port, SOCK_STREAM);
+ screen_server_ = cvd::SharedFD::VsockClient(
+ 2, static_cast<unsigned int>(vsock_frames_port), SOCK_STREAM);
if (!screen_server_->IsOpen()) {
ALOGE("Unable to connect to screen server: %s", screen_server_->StrError());
return false;
diff --git a/guest/hals/ril/cuttlefish_ril.cpp b/guest/hals/ril/cuttlefish_ril.cpp
index 47cb5c5..40fc393 100644
--- a/guest/hals/ril/cuttlefish_ril.cpp
+++ b/guest/hals/ril/cuttlefish_ril.cpp
@@ -1241,13 +1241,6 @@
gce_ril_env->OnRequestComplete(t, RIL_E_SUCCESS, &areUiccApplicationsEnabled, sizeof(bool));
}
-static void request_can_toggle_uicc_applications_enablement(int /*request*/, void* /*data*/,
- size_t /*datalen*/, RIL_Token t) {
- ALOGV("Getting can toggle uicc applications enablement.");
-
- gce_ril_env->OnRequestComplete(t, RIL_E_SUCCESS, NULL, 0);
-}
-
static void request_cdma_set_subscription_source(int /*request*/, void* data,
size_t /*datalen*/,
RIL_Token t) {
@@ -2276,7 +2269,7 @@
return;
}
-// New functions after Q
+// New functions after Q.
static void request_set_signal_strength_reporting_criteria_1_5(int /*request*/, void* /*data*/,
size_t /*datalen*/, RIL_Token t) {
ALOGV("request_set_signal_strength_reporting_criteria_1_5 - void");
@@ -2296,6 +2289,12 @@
return;
}
+static void request_set_radio_power_1_5(RIL_Token t) {
+ ALOGV("request_set_radio_power_1_5");
+ gce_ril_env->OnRequestComplete(t, RIL_E_SUCCESS, NULL, 0);
+ return;
+}
+
static void gce_ril_on_request(int request, void* data, size_t datalen,
RIL_Token t) {
// Ignore all requests except RIL_REQUEST_GET_SIM_STATUS
@@ -2589,15 +2588,15 @@
case RIL_REQUEST_ARE_UICC_APPLICATIONS_ENABLED:
request_are_uicc_applications_enabled(request, data, datalen, t);
break;
- case RIL_REQUEST_CAN_TOGGLE_UICC_APPLICATIONS_ENABLEMENT:
- request_can_toggle_uicc_applications_enablement(request, data, datalen, t);
- break;
case RIL_REQUEST_SET_SYSTEM_SELECTION_CHANNELS_1_5:
request_set_system_selection_channels_1_5(request, t);
break;
case RIL_REQUEST_START_NETWORK_SCAN_1_5:
request_start_network_scan_1_5(t);
break;
+ case RIL_REQUEST_SET_RADIO_POWER_1_5:
+ request_set_radio_power_1_5(t);
+ break;
default:
ALOGE("Request %d not supported.", request);
gce_ril_env->OnRequestComplete(t, RIL_E_REQUEST_NOT_SUPPORTED, NULL, 0);
diff --git a/guest/hals/ril/libril/ril.cpp b/guest/hals/ril/libril/ril.cpp
index 8d3497e..03d469a 100644
--- a/guest/hals/ril/libril/ril.cpp
+++ b/guest/hals/ril/libril/ril.cpp
@@ -1173,6 +1173,7 @@
case RIL_REQUEST_GET_CARRIER_RESTRICTIONS_1_4: return "GET_CARRIER_RESTRICTIONS_1_4";
case RIL_REQUEST_SET_CARRIER_INFO_IMSI_ENCRYPTION: return "SET_CARRIER_INFO_IMSI_ENCRYPTION";
case RIL_REQUEST_SET_SIGNAL_STRENGTH_REPORTING_CRITERIA_1_5: return "SET_SIGNAL_STRENGTH_REPORTING_CRITERIA_1_5";
+ case RIL_REQUEST_SET_RADIO_POWER_1_5: return "SET_RADIO_POWER_1_5";
case RIL_RESPONSE_ACKNOWLEDGEMENT: return "RESPONSE_ACKNOWLEDGEMENT";
case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
diff --git a/guest/hals/ril/libril/ril.h b/guest/hals/ril/libril/ril.h
index 80394ea..32d5aa0 100644
--- a/guest/hals/ril/libril/ril.h
+++ b/guest/hals/ril/libril/ril.h
@@ -96,7 +96,6 @@
* RIL_REQUEST_SET_SYSTEM_SELECTION_CHANNELS
* RIL_REQUEST_ENABLE_UICC_APPLICATIONS
* RIL_REQUEST_ARE_UICC_APPLICATIONS_ENABLED
- * RIL_REQUEST_CAN_TOGGLE_UICC_APPLICATIONS_ENABLEMENT
*/
#define RIL_VERSION 12
#define LAST_IMPRECISE_RIL_VERSION 12 // Better self-documented name
@@ -2041,6 +2040,8 @@
RIL_APN_TYPE_EMERGENCY = 0x200, // APN type for Emergency PDN. This is not an IA apn,
// but is used for access to carrier services in an
// emergency call situation.
+ RIL_APN_TYPE_MCX = 0x400, // APN type for Mission Critical Service
+ RIL_APN_TYPE_XCAP = 0x800, // APN type for XCAP
RIL_APN_TYPE_ALL = 0xFFFFFFFF // All APN types
} RIL_ApnTypes;
@@ -6671,20 +6672,6 @@
#define RIL_REQUEST_ARE_UICC_APPLICATIONS_ENABLED 157
/**
- * RIL_REQUEST_CAN_TOGGLE_UICC_APPLICATIONS_ENABLEMENT
- *
- * Whether disabling / enabling uicc applications is supported
- *
- * Response: a boolean of whether it's supported.
- *
- * Valid errors:
- * SUCCESS
- * RADIO_NOT_AVAILABLE
- * INTERNAL_ERR
- */
-#define RIL_REQUEST_CAN_TOGGLE_UICC_APPLICATIONS_ENABLEMENT 158
-
-/**
* Specify which bands modem's background scan must act on.
* If specifyChannels is true, it only scans bands specified in specifiers.
* If specifyChannels is false, it scans all bands.
@@ -6699,7 +6686,7 @@
* INVALID_ARGUMENTS
*
*/
-#define RIL_REQUEST_SET_SYSTEM_SELECTION_CHANNELS_1_5 159
+#define RIL_REQUEST_SET_SYSTEM_SELECTION_CHANNELS_1_5 158
/**
* RIL_REQUEST_START_NETWORK_SCAN5
@@ -6721,7 +6708,22 @@
* INVALID_ARGUMENTS
*
*/
-#define RIL_REQUEST_START_NETWORK_SCAN_1_5 160
+#define RIL_REQUEST_START_NETWORK_SCAN_1_5 159
+
+
+/**
+ * RIL_REQUEST_SET_RADIO_POWER_1_5
+ *
+ * Turn on or off radio power. It can also specify whether turning on radio power is to place an
+ * emergency call and whether the call will be placed on this logical modem.
+ *
+ * Valid errors:
+ * SUCCESS
+ * INTERNAL_ERR
+ * INVALID_ARGUMENTS
+ *
+ */
+#define RIL_REQUEST_SET_RADIO_POWER_1_5 160
/***********************************************************************/
diff --git a/guest/hals/ril/libril/ril_commands.h b/guest/hals/ril/libril/ril_commands.h
index 17cb594..6cf94ba 100644
--- a/guest/hals/ril/libril/ril_commands.h
+++ b/guest/hals/ril/libril/ril_commands.h
@@ -172,6 +172,6 @@
{RIL_REQUEST_SET_SIGNAL_STRENGTH_REPORTING_CRITERIA_1_5, radio_1_5::setSignalStrengthReportingCriteriaResponse_1_5},
{RIL_REQUEST_ENABLE_UICC_APPLICATIONS, radio_1_5::enableUiccApplicationsResponse},
{RIL_REQUEST_ARE_UICC_APPLICATIONS_ENABLED, radio_1_5::areUiccApplicationsEnabledResponse},
- {RIL_REQUEST_CAN_TOGGLE_UICC_APPLICATIONS_ENABLEMENT, radio_1_5::canToggleUiccApplicationsEnablementResponse},
{RIL_REQUEST_SET_SYSTEM_SELECTION_CHANNELS_1_5, radio_1_5::setSystemSelectionChannelsResponse_1_5},
{RIL_REQUEST_START_NETWORK_SCAN_1_5, radio_1_5::startNetworkScanResponse_1_5},
+ {RIL_REQUEST_SET_RADIO_POWER_1_5, radio_1_5::setRadioPowerResponse_1_5},
diff --git a/guest/hals/ril/libril/ril_service.cpp b/guest/hals/ril/libril/ril_service.cpp
index b7b02a6..176b383 100755
--- a/guest/hals/ril/libril/ril_service.cpp
+++ b/guest/hals/ril/libril/ril_service.cpp
@@ -537,11 +537,21 @@
const ::android::hardware::radio::V1_5::AccessNetwork accessNetwork);
Return<void> enableUiccApplications(int32_t serial, bool detach);
Return<void> areUiccApplicationsEnabled(int32_t serial);
- Return<void> canToggleUiccApplicationsEnablement(int32_t serial);
Return<void> setSystemSelectionChannels_1_5(int32_t serial, bool specifyChannels,
const hidl_vec<::android::hardware::radio::V1_5::RadioAccessSpecifier>& specifiers);
Return<void> startNetworkScan_1_5(int32_t serial,
const ::android::hardware::radio::V1_5::NetworkScanRequest& request);
+ Return<void> setupDataCall_1_5(int32_t serial,
+ ::android::hardware::radio::V1_5::AccessNetwork accessNetwork,
+ const ::android::hardware::radio::V1_5::DataProfileInfo& dataProfileInfo,
+ bool roamingAllowed, ::android::hardware::radio::V1_2::DataRequestReason reason,
+ const hidl_vec<hidl_string>& addresses, const hidl_vec<hidl_string>& dnses);
+ Return<void> setInitialAttachApn_1_5(int32_t serial,
+ const ::android::hardware::radio::V1_5::DataProfileInfo& dataProfileInfo);
+ Return<void> setDataProfile_1_5(int32_t serial,
+ const hidl_vec<::android::hardware::radio::V1_5::DataProfileInfo>& profiles);
+ Return<void> setRadioPower_1_5(int32_t serial, bool powerOn, bool forEmergencyCall,
+ bool preferredForEmergencyCall);
};
struct OemHookImpl : public IOemHook {
@@ -3580,7 +3590,7 @@
return Void();
}
-// Methods from ::android::hardware::radio::IRadio::V1_5 follow.
+// Methods from ::android::hardware::radio::V1_5::IRadio follow.
Return<void> RadioImpl_1_5::setSignalStrengthReportingCriteria_1_5(int32_t /* serial */,
const ::android::hardware::radio::V1_5::SignalThresholdInfo& /* signalThresholdInfo */,
const ::android::hardware::radio::V1_5::AccessNetwork /* accessNetwork */) {
@@ -3599,6 +3609,16 @@
return Void();
}
+Return<void> RadioImpl_1_5::setRadioPower_1_5(int32_t serial, bool powerOn, bool forEmergencyCall,
+ bool preferredForEmergencyCall) {
+#if VDBG
+ RLOGD("setRadioPower_1_5: serial %d powerOn %d forEmergency %d preferredForEmergencyCall %d",
+ serial, powerOn, forEmergencyCall, preferredForEmergencyCall);
+#endif
+ dispatchVoid(serial, mSlotId, RIL_REQUEST_SET_RADIO_POWER_1_5);
+ return Void();
+}
+
Return<void> RadioImpl_1_5::areUiccApplicationsEnabled(int32_t serial) {
#if VDBG
RLOGD("areUiccApplicationsEnabled: serial %d", serial);
@@ -3607,14 +3627,6 @@
return Void();
}
-Return<void> RadioImpl_1_5::canToggleUiccApplicationsEnablement(int32_t serial) {
-#if VDBG
- RLOGD("canToggleUiccApplicationsEnablement: serial %d.", serial);
-#endif
- dispatchVoid(serial, mSlotId, RIL_REQUEST_CAN_TOGGLE_UICC_APPLICATIONS_ENABLEMENT);
- return Void();
-}
-
Return<void> RadioImpl_1_5::setSystemSelectionChannels_1_5(int32_t serial, bool /* specifyChannels */,
const hidl_vec<::android::hardware::radio::V1_5::RadioAccessSpecifier>& /* specifiers */) {
#if VDBG
@@ -3651,6 +3663,102 @@
return Void();
}
+Return<void> RadioImpl_1_5::setupDataCall_1_5(int32_t serial ,
+ ::android::hardware::radio::V1_5::AccessNetwork /* accessNetwork */,
+ const ::android::hardware::radio::V1_5::DataProfileInfo& dataProfileInfo,
+ bool roamingAllowed, ::android::hardware::radio::V1_2::DataRequestReason /* reason */,
+ const hidl_vec<hidl_string>& /* addresses */, const hidl_vec<hidl_string>& /* dnses */) {
+
+#if VDBG
+ RLOGD("setupDataCall_1_5: serial %d", serial);
+#endif
+
+ char *mvnoTypeStr = NULL;
+ if (!convertMvnoTypeToString(MvnoType::IMSI, mvnoTypeStr)) {
+ RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
+ RIL_REQUEST_SETUP_DATA_CALL);
+ if (pRI != NULL) {
+ sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
+ }
+ return Void();
+ }
+ dispatchStrings(serial, mSlotId, RIL_REQUEST_SETUP_DATA_CALL, true, 15,
+ std::to_string((int) RadioTechnology::UNKNOWN + 2).c_str(),
+ std::to_string((int) dataProfileInfo.base.profileId).c_str(),
+ dataProfileInfo.base.apn.c_str(),
+ dataProfileInfo.base.user.c_str(),
+ dataProfileInfo.base.password.c_str(),
+ std::to_string((int) dataProfileInfo.base.authType).c_str(),
+ getProtocolString(dataProfileInfo.base.protocol),
+ getProtocolString(dataProfileInfo.base.roamingProtocol),
+ std::to_string(dataProfileInfo.supportedApnTypesBitmap).c_str(),
+ std::to_string(dataProfileInfo.base.bearerBitmap).c_str(),
+ dataProfileInfo.base.persistent ? "1" : "0",
+ std::to_string(dataProfileInfo.base.mtu).c_str(),
+ mvnoTypeStr,
+ "302720x94",
+ roamingAllowed ? "1" : "0");
+ return Void();
+}
+
+Return<void> RadioImpl_1_5::setInitialAttachApn_1_5(int32_t serial ,
+ const ::android::hardware::radio::V1_5::DataProfileInfo& dataProfileInfo) {
+ RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
+ RIL_REQUEST_SET_INITIAL_ATTACH_APN);
+ if (pRI == NULL) {
+ return Void();
+ }
+
+ RadioResponseInfo responseInfo = {};
+ populateResponseInfo(responseInfo, serial, RESPONSE_SOLICITED, RIL_E_SUCCESS);
+
+ if (radioService[mSlotId]->mRadioResponseV1_5 != NULL) {
+ Return<void> retStatus
+ = radioService[mSlotId]->mRadioResponseV1_5->setInitialAttachApnResponse(responseInfo);
+ } else if (radioService[mSlotId]->mRadioResponseV1_4 != NULL) {
+ Return<void> retStatus
+ = radioService[mSlotId]->mRadioResponseV1_4->setInitialAttachApnResponse(responseInfo);
+ radioService[mSlotId]->checkReturnStatus(retStatus);
+ } else if (radioService[mSlotId]->mRadioResponse != NULL) {
+ Return<void> retStatus
+ = radioService[mSlotId]->mRadioResponse->setInitialAttachApnResponse(responseInfo);
+ radioService[mSlotId]->checkReturnStatus(retStatus);
+ } else {
+ RLOGE("setInitialAttachApnResponse: radioService[%d]->mRadioResponse == NULL", mSlotId);
+ }
+
+ return Void();
+}
+
+Return<void> RadioImpl_1_5::setDataProfile_1_5(int32_t serial ,
+ const hidl_vec<::android::hardware::radio::V1_5::DataProfileInfo>& /* profiles */) {
+ RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
+ RIL_REQUEST_SET_DATA_PROFILE);
+ if (pRI == NULL) {
+ return Void();
+ }
+
+ RadioResponseInfo responseInfo = {};
+ populateResponseInfo(responseInfo, serial, RESPONSE_SOLICITED, RIL_E_SUCCESS);
+
+ if (radioService[mSlotId]->mRadioResponseV1_5 != NULL) {
+ Return<void> retStatus
+ = radioService[mSlotId]->mRadioResponseV1_5->setDataProfileResponse(responseInfo);
+ } else if (radioService[mSlotId]->mRadioResponseV1_4 != NULL) {
+ Return<void> retStatus
+ = radioService[mSlotId]->mRadioResponseV1_4->setDataProfileResponse(responseInfo);
+ radioService[mSlotId]->checkReturnStatus(retStatus);
+ } else if (radioService[mSlotId]->mRadioResponse != NULL) {
+ Return<void> retStatus
+ = radioService[mSlotId]->mRadioResponse->setDataProfileResponse(responseInfo);
+ radioService[mSlotId]->checkReturnStatus(retStatus);
+ } else {
+ RLOGE("setDataProfileResponse: radioService[%d]->mRadioResponse == NULL", mSlotId);
+ }
+
+ return Void();
+}
+
// OEM hook methods:
Return<void> OemHookImpl::setResponseFunctions(
const ::android::sp<IOemHookResponse>& oemHookResponseParam,
@@ -4845,14 +4953,36 @@
#if VDBG
RLOGD("setupDataCallResponse: serial %d", serial);
#endif
-
- if (radioService[slotId]->mRadioResponseV1_4 != NULL) {
+ if (radioService[slotId]->mRadioResponseV1_5 != NULL) {
RadioResponseInfo responseInfo = {};
populateResponseInfo(responseInfo, serial, responseType, e);
::android::hardware::radio::V1_4::SetupDataCallResult result;
if (response == NULL || (responseLen % sizeof(RIL_Data_Call_Response_v11)) != 0) {
if (response != NULL) {
- RLOGE("setupDataCallResponse: Invalid response");
+ RLOGE("setupDataCallResponse_1_5: Invalid response");
+ if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
+ }
+ result.cause = ::android::hardware::radio::V1_4::DataCallFailCause::ERROR_UNSPECIFIED;
+ result.type = ::android::hardware::radio::V1_4::PdpProtocolType::UNKNOWN;
+ result.ifname = hidl_string();
+ result.addresses = hidl_vec<hidl_string>();
+ result.dnses = hidl_vec<hidl_string>();
+ result.gateways = hidl_vec<hidl_string>();
+ result.pcscf = hidl_vec<hidl_string>();
+ } else {
+ convertRilDataCallToHal((RIL_Data_Call_Response_v11 *) response, result);
+ }
+
+ Return<void> retStatus = radioService[slotId]->mRadioResponseV1_5->setupDataCallResponse_1_5(
+ responseInfo, result);
+ radioService[slotId]->checkReturnStatus(retStatus);
+ } else if (radioService[slotId]->mRadioResponseV1_4 != NULL) {
+ RadioResponseInfo responseInfo = {};
+ populateResponseInfo(responseInfo, serial, responseType, e);
+ ::android::hardware::radio::V1_4::SetupDataCallResult result;
+ if (response == NULL || (responseLen % sizeof(RIL_Data_Call_Response_v11)) != 0) {
+ if (response != NULL) {
+ RLOGE("setupDataCallResponse_1_4: Invalid response");
if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
}
result.cause = ::android::hardware::radio::V1_4::DataCallFailCause::ERROR_UNSPECIFIED;
@@ -6749,7 +6879,13 @@
RLOGD("setInitialAttachApnResponse: serial %d", serial);
#endif
- if (radioService[slotId]->mRadioResponse != NULL) {
+ if (radioService[slotId]->mRadioResponseV1_5 != NULL) {
+ RadioResponseInfo responseInfo = {};
+ populateResponseInfo(responseInfo, serial, responseType, e);
+ Return<void> retStatus
+ = radioService[slotId]->mRadioResponseV1_5->setInitialAttachApnResponse_1_5(
+ responseInfo);
+ } else if (radioService[slotId]->mRadioResponse != NULL) {
RadioResponseInfo responseInfo = {};
populateResponseInfo(responseInfo, serial, responseType, e);
Return<void> retStatus
@@ -7109,7 +7245,13 @@
RLOGD("setDataProfileResponse: serial %d", serial);
#endif
- if (radioService[slotId]->mRadioResponse != NULL) {
+ if (radioService[slotId]->mRadioResponseV1_5 != NULL) {
+ RadioResponseInfo responseInfo = {};
+ populateResponseInfo(responseInfo, serial, responseType, e);
+ Return<void> retStatus
+ = radioService[slotId]->mRadioResponseV1_5->setDataProfileResponse_1_5(
+ responseInfo);
+ } else if (radioService[slotId]->mRadioResponse != NULL) {
RadioResponseInfo responseInfo = {};
populateResponseInfo(responseInfo, serial, responseType, e);
Return<void> retStatus
@@ -7902,28 +8044,6 @@
return 0;
}
-int radio_1_5::canToggleUiccApplicationsEnablementResponse(int slotId, int responseType,
- int serial, RIL_Errno e,
- void *response, size_t responseLen) {
-#if VDBG
- RLOGD("%s(): %d", __FUNCTION__, serial);
-#endif
- RadioResponseInfo responseInfo = {};
- populateResponseInfo(responseInfo, serial, responseType, e);
-
- // If we don't have a radio service, there's nothing we can do
- if (radioService[slotId]->mRadioResponseV1_5 == NULL) {
- RLOGE("%s: radioService[%d]->mRadioResponseV1_5 == NULL", __FUNCTION__, slotId);
- return 0;
- }
-
- Return<void> retStatus =
- radioService[slotId]->mRadioResponseV1_5->canToggleUiccApplicationsEnablementResponse(
- responseInfo, true);
- radioService[slotId]->checkReturnStatus(retStatus);
- return 0;
-}
-
int radio_1_5::setSystemSelectionChannelsResponse_1_5(int slotId, int responseType, int serial,
RIL_Errno e, void* /* response */, size_t responseLen) {
#if VDBG
@@ -7962,6 +8082,27 @@
return 0;
}
+int radio_1_5::setRadioPowerResponse_1_5(int slotId, int responseType, int serial, RIL_Errno e,
+ void* /* response */, size_t responseLen) {
+#if VDBG
+ RLOGD("%s(): %d", __FUNCTION__, serial);
+#endif
+ RadioResponseInfo responseInfo = {};
+ populateResponseInfo(responseInfo, serial, responseType, e);
+
+ // If we don't have a radio service, there's nothing we can do
+ if (radioService[slotId]->mRadioResponseV1_5 == NULL) {
+ RLOGE("%s: radioService[%d]->mRadioResponseV1_5 == NULL", __FUNCTION__, slotId);
+ return 0;
+ }
+
+ Return<void> retStatus =
+ radioService[slotId]->mRadioResponseV1_5->setRadioPowerResponse_1_5(
+ responseInfo);
+ radioService[slotId]->checkReturnStatus(retStatus);
+ return 0;
+}
+
/***************************************************************************************************
* INDICATION FUNCTIONS
* The below function handle unsolicited messages coming from the Radio
diff --git a/guest/hals/ril/libril/ril_service.h b/guest/hals/ril/libril/ril_service.h
index 814768c..7bf86ba 100644
--- a/guest/hals/ril/libril/ril_service.h
+++ b/guest/hals/ril/libril/ril_service.h
@@ -798,9 +798,9 @@
int responseType, int serial, RIL_Errno e,
void *response, size_t responselen);
-int canToggleUiccApplicationsEnablementResponse(int slotId,
- int responseType, int serial, RIL_Errno e,
- void *response, size_t responselen);
+int setRadioPowerResponse_1_5(int slotId, int responseType, int serial, RIL_Errno e,
+ void *response, size_t responselen);
+
pthread_rwlock_t * getRadioServiceRwlock(int slotId);
diff --git a/guest/monitoring/tombstone_transmit/tombstone_transmit.cpp b/guest/monitoring/tombstone_transmit/tombstone_transmit.cpp
index 8fc3586..c2e07ee 100644
--- a/guest/monitoring/tombstone_transmit/tombstone_transmit.cpp
+++ b/guest/monitoring/tombstone_transmit/tombstone_transmit.cpp
@@ -82,7 +82,9 @@
return ret_value + i->name;
}
-DEFINE_uint32(port, property_get_int32("ro.boot.vsock_tombstone_port", 0),
+DEFINE_uint32(port,
+ static_cast<uint32_t>(
+ property_get_int64("ro.boot.vsock_tombstone_port", 0)),
"VSOCK port to send tombstones to");
DEFINE_uint32(cid, 2, "VSOCK CID to send logcat output to");
#define TOMBSTONE_BUFFER_SIZE (1024)
diff --git a/host/commands/assemble_cvd/flags.cc b/host/commands/assemble_cvd/flags.cc
index 2d6007e..400a686 100644
--- a/host/commands/assemble_cvd/flags.cc
+++ b/host/commands/assemble_cvd/flags.cc
@@ -43,15 +43,11 @@
DEFINE_int32(y_res, 1280, "Height of the screen in pixels");
DEFINE_int32(dpi, 160, "Pixels per inch for the screen");
DEFINE_int32(refresh_rate_hz, 60, "Screen refresh rate in Hertz");
-DEFINE_int32(num_screen_buffers, 3, "The number of screen buffers");
DEFINE_string(kernel_path, "",
"Path to the kernel. Overrides the one from the boot image");
DEFINE_string(initramfs_path, "", "Path to the initramfs");
DEFINE_bool(decompress_kernel, false,
"Whether to decompress the kernel image.");
-DEFINE_string(kernel_decompresser_executable,
- vsoc::DefaultHostArtifactsPath("bin/extract-vmlinux"),
- "Path to the extract-vmlinux executable.");
DEFINE_string(extra_kernel_cmdline, "",
"Additional flags to put on the kernel command line");
DEFINE_int32(loop_max_part, 7, "Maximum number of loop partitions");
@@ -99,39 +95,18 @@
" host kernel. This is only used during transition of our clients."
" Will be deprecated soon.");
DEFINE_bool(start_vnc_server, true, "Whether to start the vnc server process.");
-DEFINE_string(vnc_server_binary,
- vsoc::DefaultHostArtifactsPath("bin/vnc_server"),
- "Location of the vnc server binary.");
-DEFINE_string(virtual_usb_manager_binary,
- vsoc::DefaultHostArtifactsPath("bin/virtual_usb_manager"),
- "Location of the virtual usb manager binary.");
-DEFINE_string(kernel_log_monitor_binary,
- vsoc::DefaultHostArtifactsPath("bin/kernel_log_monitor"),
- "Location of the log monitor binary.");
DEFINE_int32(vnc_server_port, GetPerInstanceDefault(6444),
"The port on which the vnc server should listen");
-DEFINE_string(socket_forward_proxy_binary,
- vsoc::DefaultHostArtifactsPath("bin/socket_forward_proxy"),
- "Location of the socket_forward_proxy binary.");
-DEFINE_string(socket_vsock_proxy_binary,
- vsoc::DefaultHostArtifactsPath("bin/socket_vsock_proxy"),
- "Location of the socket_vsock_proxy binary.");
DEFINE_string(adb_mode, "vsock_half_tunnel",
- "Mode for ADB connection. Can be 'usb' for USB forwarding, "
- "'tunnel' for a TCP connection tunneled through VSoC, "
+ "Mode for ADB connection."
"'vsock_tunnel' for a TCP connection tunneled through vsock, "
"'native_vsock' for a direct connection to the guest ADB over "
"vsock, 'vsock_half_tunnel' for a TCP connection forwarded to "
"the guest ADB server, or a comma separated list of types as in "
- "'usb,tunnel'");
+ "'native_vsock,vsock_half_tunnel'");
DEFINE_bool(run_adb_connector, true,
"Maintain adb connection by sending 'adb connect' commands to the "
"server. Only relevant with -adb_mode=tunnel or vsock_tunnel");
-DEFINE_string(adb_connector_binary,
- vsoc::DefaultHostArtifactsPath("bin/adb_connector"),
- "Location of the adb_connector binary. Only relevant if "
- "-run_adb_connector is true");
-DEFINE_int32(vhci_port, GetPerInstanceDefault(0), "VHCI port to use for usb");
DEFINE_string(wifi_tap_name, GetPerInstanceDefault("cvd-wtap-"),
"The name of the tap interface to use for wifi");
DEFINE_int32(vsock_guest_cid,
@@ -155,35 +130,11 @@
DEFINE_string(crosvm_binary,
vsoc::DefaultHostArtifactsPath("bin/crosvm"),
"The Crosvm binary to use");
-DEFINE_string(console_forwarder_binary,
- vsoc::DefaultHostArtifactsPath("bin/console_forwarder"),
- "The Console Forwarder binary to use");
DEFINE_bool(restart_subprocesses, true, "Restart any crashed host process");
-DEFINE_string(logcat_receiver_binary,
- vsoc::DefaultHostArtifactsPath("bin/logcat_receiver"),
- "Binary for the logcat server");
DEFINE_string(logcat_mode, "", "How to send android's log messages from "
"guest to host. One of [serial, vsock]");
-DEFINE_int32(logcat_vsock_port, vsoc::GetPerInstanceDefault(5620),
- "The port for logcat over vsock");
-DEFINE_string(config_server_binary,
- vsoc::DefaultHostArtifactsPath("bin/config_server"),
- "Binary for the configuration server");
-DEFINE_int32(config_server_port, vsoc::GetPerInstanceDefault(4680),
- "The (vsock) port for the configuration server");
-DEFINE_int32(frames_vsock_port, vsoc::GetPerInstanceDefault(5580),
- "The vsock port to receive frames from the guest on");
DEFINE_bool(enable_tombstone_receiver, true, "Enables the tombstone logger on "
"both the guest and the host");
-DEFINE_string(tombstone_receiver_binary,
- vsoc::DefaultHostArtifactsPath("bin/tombstone_receiver"),
- "Binary for the tombstone server");
-DEFINE_int32(tombstone_receiver_port, vsoc::GetPerInstanceDefault(5630),
- "The vsock port for tombstones");
-DEFINE_int32(keyboard_server_port, GetPerInstanceDefault(5540),
- "The port on which the vsock keyboard server should listen");
-DEFINE_int32(touch_server_port, GetPerInstanceDefault(5640),
- "The port on which the vsock touch server should listen");
DEFINE_bool(use_bootloader, false, "Boots the device using a bootloader");
DEFINE_string(bootloader, "", "Bootloader binary path");
DEFINE_string(boot_slot, "", "Force booting into the given slot. If empty, "
@@ -280,7 +231,6 @@
tmp_config_obj.set_setupwizard_mode(FLAGS_setupwizard_mode);
tmp_config_obj.set_x_res(FLAGS_x_res);
tmp_config_obj.set_y_res(FLAGS_y_res);
- 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);
std::vector<std::string> adb = android::base::Split(FLAGS_adb_mode, ",");
@@ -339,27 +289,11 @@
}
}
- if (tmp_config_obj.adb_mode().count(vsoc::AdbMode::Usb) > 0) {
- tmp_config_obj.set_usb_v1_socket_name(
- tmp_config_obj.PerInstanceInternalPath("usb-v1"));
- tmp_config_obj.set_vhci_port(FLAGS_vhci_port);
- tmp_config_obj.set_usb_ip_socket_name(
- tmp_config_obj.PerInstanceInternalPath("usb-ip"));
- }
-
- tmp_config_obj.set_kernel_log_pipe_name(
- tmp_config_obj.PerInstanceInternalPath("kernel-log-pipe"));
- tmp_config_obj.set_console_pipe_name(
- tmp_config_obj.PerInstanceInternalPath("console-pipe"));
tmp_config_obj.set_deprecated_boot_completed(FLAGS_deprecated_boot_completed);
- tmp_config_obj.set_console_path(tmp_config_obj.PerInstancePath("console"));
- tmp_config_obj.set_logcat_path(tmp_config_obj.PerInstancePath("logcat"));
- tmp_config_obj.set_logcat_receiver_binary(FLAGS_logcat_receiver_binary);
- tmp_config_obj.set_config_server_binary(FLAGS_config_server_binary);
- tmp_config_obj.set_launcher_log_path(
- tmp_config_obj.PerInstancePath("launcher.log"));
- tmp_config_obj.set_launcher_monitor_socket_path(
- tmp_config_obj.PerInstancePath("launcher_monitor.sock"));
+ tmp_config_obj.set_logcat_receiver_binary(
+ vsoc::DefaultHostArtifactsPath("bin/logcat_receiver"));
+ tmp_config_obj.set_config_server_binary(
+ vsoc::DefaultHostArtifactsPath("bin/config_server"));
tmp_config_obj.set_mobile_bridge_name(FLAGS_mobile_interface);
tmp_config_obj.set_mobile_tap_name(FLAGS_mobile_tap_name);
@@ -372,42 +306,33 @@
tmp_config_obj.set_qemu_binary(FLAGS_qemu_binary);
tmp_config_obj.set_crosvm_binary(FLAGS_crosvm_binary);
- tmp_config_obj.set_console_forwarder_binary(FLAGS_console_forwarder_binary);
- tmp_config_obj.set_kernel_log_monitor_binary(FLAGS_kernel_log_monitor_binary);
+ tmp_config_obj.set_console_forwarder_binary(
+ vsoc::DefaultHostArtifactsPath("bin/console_forwarder"));
+ tmp_config_obj.set_kernel_log_monitor_binary(
+ vsoc::DefaultHostArtifactsPath("bin/kernel_log_monitor"));
tmp_config_obj.set_enable_vnc_server(FLAGS_start_vnc_server);
- tmp_config_obj.set_vnc_server_binary(FLAGS_vnc_server_binary);
+ tmp_config_obj.set_vnc_server_binary(
+ vsoc::DefaultHostArtifactsPath("bin/vnc_server"));
tmp_config_obj.set_vnc_server_port(FLAGS_vnc_server_port);
tmp_config_obj.set_restart_subprocesses(FLAGS_restart_subprocesses);
tmp_config_obj.set_run_adb_connector(FLAGS_run_adb_connector);
- tmp_config_obj.set_adb_connector_binary(FLAGS_adb_connector_binary);
- tmp_config_obj.set_virtual_usb_manager_binary(
- FLAGS_virtual_usb_manager_binary);
- tmp_config_obj.set_socket_forward_proxy_binary(
- FLAGS_socket_forward_proxy_binary);
- tmp_config_obj.set_socket_vsock_proxy_binary(FLAGS_socket_vsock_proxy_binary);
+ tmp_config_obj.set_adb_connector_binary(
+ vsoc::DefaultHostArtifactsPath("bin/adb_connector"));
+ tmp_config_obj.set_socket_vsock_proxy_binary(
+ vsoc::DefaultHostArtifactsPath("bin/socket_vsock_proxy"));
tmp_config_obj.set_run_as_daemon(FLAGS_daemon);
tmp_config_obj.set_data_policy(FLAGS_data_policy);
tmp_config_obj.set_blank_data_image_mb(FLAGS_blank_data_image_mb);
tmp_config_obj.set_blank_data_image_fmt(FLAGS_blank_data_image_fmt);
- if(tmp_config_obj.adb_mode().count(vsoc::AdbMode::Usb) == 0) {
- tmp_config_obj.disable_usb_adb();
- }
-
tmp_config_obj.set_logcat_mode(FLAGS_logcat_mode);
- tmp_config_obj.set_logcat_vsock_port(FLAGS_logcat_vsock_port);
- tmp_config_obj.set_config_server_port(FLAGS_config_server_port);
- tmp_config_obj.set_frames_vsock_port(FLAGS_frames_vsock_port);
tmp_config_obj.set_enable_tombstone_receiver(FLAGS_enable_tombstone_receiver);
- tmp_config_obj.set_tombstone_receiver_port(FLAGS_tombstone_receiver_port);
- tmp_config_obj.set_tombstone_receiver_binary(FLAGS_tombstone_receiver_binary);
-
- tmp_config_obj.set_touch_socket_port(FLAGS_touch_server_port);
- tmp_config_obj.set_keyboard_socket_port(FLAGS_keyboard_server_port);
+ tmp_config_obj.set_tombstone_receiver_binary(
+ vsoc::DefaultHostArtifactsPath("bin/tombstone_receiver"));
tmp_config_obj.set_use_bootloader(FLAGS_use_bootloader);
tmp_config_obj.set_bootloader(FLAGS_bootloader);
@@ -509,7 +434,7 @@
}
bool DecompressKernel(const std::string& src, const std::string& dst) {
- cvd::Command decomp_cmd(FLAGS_kernel_decompresser_executable);
+ cvd::Command decomp_cmd(vsoc::DefaultHostArtifactsPath("bin/extract-vmlinux"));
decomp_cmd.AddParameter(src);
auto output_file = cvd::SharedFD::Creat(dst.c_str(), 0666);
if (!output_file->IsOpen()) {
@@ -518,7 +443,7 @@
return false;
}
decomp_cmd.RedirectStdIO(cvd::Subprocess::StdIOChannel::kStdOut, output_file);
- auto decomp_proc = decomp_cmd.Start(false);
+ auto decomp_proc = decomp_cmd.Start();
return decomp_proc.Started() && decomp_proc.Wait() == 0;
}
diff --git a/host/commands/assemble_cvd/super_image_mixer.cc b/host/commands/assemble_cvd/super_image_mixer.cc
index 1960d41..9544670 100644
--- a/host/commands/assemble_cvd/super_image_mixer.cc
+++ b/host/commands/assemble_cvd/super_image_mixer.cc
@@ -44,8 +44,8 @@
if (file_info.source != source) {
continue;
}
- std::string expected_filename = "target_files-" + file_iter.second.build_id + ".zip";
- if (!android::base::EndsWith(file_path, expected_filename)) {
+ std::string expected_filename = "target_files-" + file_iter.second.build_id;
+ if (file_path.find(expected_filename) != std::string::npos) {
continue;
}
return file_path;;
diff --git a/host/commands/config_server/main.cpp b/host/commands/config_server/main.cpp
index 5970edf..6d1e7f8 100644
--- a/host/commands/config_server/main.cpp
+++ b/host/commands/config_server/main.cpp
@@ -23,25 +23,17 @@
DEFINE_int32(
server_fd, -1,
- "File descriptor to an already created vsock server. If negative a new "
- "server will be created at the port specified on the config file");
+ "File descriptor to an already created vsock server. Must be specified.");
int main(int argc, char** argv) {
::android::base::InitLogging(argv, android::base::StderrLogger);
google::ParseCommandLineFlags(&argc, &argv, true);
- auto config = vsoc::CuttlefishConfig::Get();
+ CHECK(vsoc::CuttlefishConfig::Get()) << "Could not open config";
- cvd::SharedFD server_fd;
- if (FLAGS_server_fd < 0) {
- unsigned int port = config->config_server_port();
- server_fd = cvd::SharedFD::VsockServer(port, SOCK_STREAM);
- } else {
- server_fd = cvd::SharedFD::Dup(FLAGS_server_fd);
- close(FLAGS_server_fd);
- }
+ cvd::SharedFD server_fd = cvd::SharedFD::Dup(FLAGS_server_fd);
- CHECK(server_fd->IsOpen()) << "Error creating or inheriting logcat server: "
+ CHECK(server_fd->IsOpen()) << "Inheriting logcat server: "
<< server_fd->StrError();
auto device_config = cvd::DeviceConfig::Get();
diff --git a/host/commands/fetcher/build_api.cc b/host/commands/fetcher/build_api.cc
index ff2b65e..fb685c7 100644
--- a/host/commands/fetcher/build_api.cc
+++ b/host/commands/fetcher/build_api.cc
@@ -15,13 +15,19 @@
#include "build_api.h"
+#include <dirent.h>
+#include <unistd.h>
+
#include <chrono>
#include <set>
#include <string>
#include <thread>
+#include <android-base/strings.h>
#include <glog/logging.h>
+#include "common/libs/utils/files.h"
+
namespace {
const std::string BUILD_API =
@@ -56,6 +62,16 @@
return out << "(id=\"" << build.id << "\", target=\"" << build.target << "\")";
}
+std::ostream& operator<<(std::ostream& out, const DirectoryBuild& build) {
+ auto paths = android::base::Join(build.paths, ":");
+ return out << "(paths=\"" << paths << "\", target=\"" << build.target << "\")";
+}
+
+std::ostream& operator<<(std::ostream& out, const Build& build) {
+ std::visit([&out](auto&& arg) { out << arg; }, build);
+ return out;
+}
+
BuildApi::BuildApi(std::unique_ptr<CredentialSource> credential_source)
: credential_source(std::move(credential_source)) {}
@@ -108,6 +124,26 @@
return artifacts;
}
+struct CloseDir {
+ void operator()(DIR* dir) {
+ closedir(dir);
+ }
+};
+
+using UniqueDir = std::unique_ptr<DIR, CloseDir>;
+
+std::vector<Artifact> BuildApi::Artifacts(const DirectoryBuild& build) {
+ std::vector<Artifact> artifacts;
+ for (const auto& path : build.paths) {
+ auto dir = UniqueDir(opendir(path.c_str()));
+ CHECK(dir != nullptr) << "Could not read files from \"" << path << "\"";
+ for (auto entity = readdir(dir.get()); entity != nullptr; entity = readdir(dir.get())) {
+ artifacts.emplace_back(std::string(entity->d_name));
+ }
+ }
+ return artifacts;
+}
+
bool BuildApi::ArtifactToFile(const DeviceBuild& build,
const std::string& artifact,
const std::string& path) {
@@ -116,9 +152,35 @@
return curl.DownloadToFile(url, path, Headers());
}
-DeviceBuild ArgumentToBuild(BuildApi* build_api, const std::string& arg,
- const std::string& default_build_target,
- const std::chrono::seconds& retry_period) {
+bool BuildApi::ArtifactToFile(const DirectoryBuild& build,
+ const std::string& artifact,
+ const std::string& destination) {
+ for (const auto& path : build.paths) {
+ auto source = path + "/" + artifact;
+ if (!cvd::FileExists(source)) {
+ continue;
+ }
+ unlink(destination.c_str());
+ if (symlink(source.c_str(), destination.c_str())) {
+ int error_num = errno;
+ LOG(ERROR) << "Could not create symlink from " << source << " to "
+ << destination << ": " << strerror(error_num);
+ return false;
+ }
+ return true;
+ }
+ return false;
+}
+
+Build ArgumentToBuild(BuildApi* build_api, const std::string& arg,
+ const std::string& default_build_target,
+ const std::chrono::seconds& retry_period) {
+ if (arg.find(":") != std::string::npos) {
+ std::vector<std::string> dirs = android::base::Split(arg, ":");
+ std::string id = dirs.back();
+ dirs.pop_back();
+ return DirectoryBuild(dirs, id);
+ }
size_t slash_pos = arg.find('/');
if (slash_pos != std::string::npos
&& arg.find('/', slash_pos + 1) != std::string::npos) {
diff --git a/host/commands/fetcher/build_api.h b/host/commands/fetcher/build_api.h
index bb89e81..54bbd72 100644
--- a/host/commands/fetcher/build_api.h
+++ b/host/commands/fetcher/build_api.h
@@ -20,6 +20,7 @@
#include <memory>
#include <ostream>
#include <string>
+#include <variant>
#include "credential_source.h"
#include "curl_wrapper.h"
@@ -35,6 +36,7 @@
unsigned int crc32;
public:
Artifact(const Json::Value&);
+ Artifact(const std::string& name) : name(name) {}
const std::string& Name() const { return name; }
size_t Size() const { return size; }
@@ -58,6 +60,23 @@
std::ostream& operator<<(std::ostream&, const DeviceBuild&);
+struct DirectoryBuild {
+ // TODO(schuffelen): Support local builds other than "eng"
+ DirectoryBuild(const std::vector<std::string>& paths,
+ const std::string& target)
+ : paths(paths), target(target), id("eng") {}
+
+ std::vector<std::string> paths;
+ std::string target;
+ std::string id;
+};
+
+std::ostream& operator<<(std::ostream&, const DirectoryBuild&);
+
+using Build = std::variant<DeviceBuild, DirectoryBuild>;
+
+std::ostream& operator<<(std::ostream&, const Build&);
+
class BuildApi {
CurlWrapper curl;
std::unique_ptr<CredentialSource> credential_source;
@@ -76,8 +95,24 @@
bool ArtifactToFile(const DeviceBuild& build, const std::string& artifact,
const std::string& path);
+
+ std::vector<Artifact> Artifacts(const DirectoryBuild&);
+
+ bool ArtifactToFile(const DirectoryBuild& build, const std::string& artifact,
+ const std::string& path);
+
+ std::vector<Artifact> Artifacts(const Build& build) {
+ return std::visit([this](auto&& arg) { return Artifacts(arg); }, build);
+ }
+
+ bool ArtifactToFile(const Build& build, const std::string& artifact,
+ const std::string& path) {
+ return std::visit([this, &artifact, &path](auto&& arg) {
+ return ArtifactToFile(arg, artifact, path);
+ }, build);
+ }
};
-DeviceBuild ArgumentToBuild(BuildApi* api, const std::string& arg,
- const std::string& default_build_target,
- const std::chrono::seconds& retry_period);
+Build ArgumentToBuild(BuildApi* api, const std::string& arg,
+ const std::string& default_build_target,
+ const std::chrono::seconds& retry_period);
diff --git a/host/commands/fetcher/fetch_cvd.cc b/host/commands/fetcher/fetch_cvd.cc
index 5e314c8..7532810 100644
--- a/host/commands/fetcher/fetch_cvd.cc
+++ b/host/commands/fetcher/fetch_cvd.cc
@@ -23,6 +23,7 @@
#include "gflags/gflags.h"
#include <glog/logging.h>
+#include "common/libs/fs/shared_fd.h"
#include "common/libs/utils/archive.h"
#include "common/libs/utils/files.h"
#include "common/libs/utils/subprocess.h"
@@ -68,28 +69,32 @@
* For example, for a target "aosp_cf_x86_phone-userdebug" at a build "5824130",
* the image zip file would be "aosp_cf_x86_phone-img-5824130.zip"
*/
-std::string target_build_zip(const DeviceBuild& build, const std::string& name) {
- std::string target = build.target;
+std::string TargetBuildZipFromArtifacts(
+ const Build& build, const std::string& name,
+ const std::vector<Artifact>& artifacts) {
+ std::string target = std::visit([](auto&& arg) { return arg.target; }, build);
size_t dash_pos = target.find("-");
if (dash_pos != std::string::npos) {
target.replace(dash_pos, target.size() - dash_pos, "");
}
- return target + "-" + name + "-" + build.id + ".zip";
+ auto id = std::visit([](auto&& arg) { return arg.id; }, build);
+ auto match = target + "-" + name + "-" + id;
+ for (const auto& artifact : artifacts) {
+ if (artifact.Name().find(match) != std::string::npos) {
+ return artifact.Name();
+ }
+ }
+ return "";
}
std::vector<std::string> download_images(BuildApi* build_api,
- const DeviceBuild& build,
+ const Build& build,
const std::string& target_directory,
const std::vector<std::string>& images) {
- std::string img_zip_name = target_build_zip(build, "img");
auto artifacts = build_api->Artifacts(build);
- bool has_image_zip = false;
- for (const auto& artifact : artifacts) {
- has_image_zip |= artifact.Name() == img_zip_name;
- }
- if (!has_image_zip) {
- LOG(FATAL) << "Target " << build.target << " at id " << build.id
- << " did not have " << img_zip_name;
+ std::string img_zip_name = TargetBuildZipFromArtifacts(build, "img", artifacts);
+ if (img_zip_name.size() == 0) {
+ LOG(FATAL) << "Target " << build << " did not have an img zip";
return {};
}
std::string local_path = target_directory + "/" + img_zip_name;
@@ -111,23 +116,18 @@
return files;
}
std::vector<std::string> download_images(BuildApi* build_api,
- const DeviceBuild& build,
+ const Build& build,
const std::string& target_directory) {
return download_images(build_api, build, target_directory, {});
}
std::vector<std::string> download_target_files(BuildApi* build_api,
- const DeviceBuild& build,
+ const Build& build,
const std::string& target_directory) {
- std::string target_zip = target_build_zip(build, "target_files");
auto artifacts = build_api->Artifacts(build);
- bool has_target_zip = false;
- for (const auto& artifact : artifacts) {
- has_target_zip |= artifact.Name() == target_zip;
- }
- if (!has_target_zip) {
- LOG(FATAL) << "Target " << build.target << " at id " << build.id
- << " did not have " << target_zip;
+ std::string target_zip = TargetBuildZipFromArtifacts(build, "target_files", artifacts);
+ if (target_zip.size() == 0) {
+ LOG(FATAL) << "Target " << build << " did not have a target files zip";
return {};
}
std::string local_path = target_directory + "/" + target_zip;
@@ -140,7 +140,7 @@
}
std::vector<std::string> download_host_package(BuildApi* build_api,
- const DeviceBuild& build,
+ const Build& build,
const std::string& target_directory) {
auto artifacts = build_api->Artifacts(build);
bool has_host_package = false;
@@ -148,8 +148,7 @@
has_host_package |= artifact.Name() == HOST_TOOLS;
}
if (!has_host_package) {
- LOG(FATAL) << "Target " << build.target << " at id " << build.id
- << " did not have " << HOST_TOOLS;
+ LOG(FATAL) << "Target " << build << " did not have " << HOST_TOOLS;
return {};
}
std::string local_path = target_directory + "/" + HOST_TOOLS;
@@ -192,7 +191,7 @@
}
std::vector<std::string> download_ota_tools(BuildApi* build_api,
- const DeviceBuild& build,
+ const Build& build,
const std::string& target_directory) {
auto artifacts = build_api->Artifacts(build);
bool has_host_package = false;
@@ -200,8 +199,7 @@
has_host_package |= artifact.Name() == OTA_TOOLS;
}
if (!has_host_package) {
- LOG(ERROR) << "Target " << build.target << " at id " << build.id
- << " did not have " << OTA_TOOLS;
+ LOG(ERROR) << "Target " << build << " did not have " << OTA_TOOLS;
return {};
}
std::string local_path = target_directory + "/" + OTA_TOOLS;
@@ -230,11 +228,14 @@
return files;
}
-void AddFilesToConfig(cvd::FileSource purpose, const DeviceBuild& build,
+void AddFilesToConfig(cvd::FileSource purpose, const Build& build,
const std::vector<std::string>& paths, cvd::FetcherConfig* config,
bool override_entry = false) {
for (const std::string& path : paths) {
- cvd::CvdFile file(purpose, build.id, build.target, path);
+ // TODO(schuffelen): Do better for local builds here.
+ auto id = std::visit([](auto&& arg) { return arg.id; }, build);
+ auto target = std::visit([](auto&& arg) { return arg.target; }, build);
+ cvd::CvdFile file(purpose, id, target, path);
bool added = config->add_cvd_file(file, override_entry);
if (!added) {
LOG(ERROR) << "Duplicate file " << file;
@@ -279,9 +280,9 @@
}
BuildApi build_api(std::move(credential_source));
- DeviceBuild default_build = ArgumentToBuild(&build_api, FLAGS_default_build,
- DEFAULT_BUILD_TARGET,
- retry_period);
+ auto default_build = ArgumentToBuild(&build_api, FLAGS_default_build,
+ DEFAULT_BUILD_TARGET,
+ retry_period);
std::vector<std::string> host_package_files =
download_host_package(&build_api, default_build, target_dir);
@@ -291,7 +292,7 @@
AddFilesToConfig(cvd::FileSource::DEFAULT_BUILD, default_build, host_package_files, &config);
if (FLAGS_system_build != "" || FLAGS_kernel_build != "" || FLAGS_otatools_build != "") {
- DeviceBuild ota_build = default_build;
+ auto ota_build = default_build;
if (FLAGS_otatools_build != "") {
ota_build = ArgumentToBuild(&build_api, FLAGS_otatools_build,
DEFAULT_BUILD_TARGET, retry_period);
@@ -313,8 +314,12 @@
AddFilesToConfig(cvd::FileSource::DEFAULT_BUILD, default_build, image_files, &config);
}
if (FLAGS_system_build != "" || FLAGS_download_target_files_zip) {
+ std::string default_target_dir = target_dir + "/default";
+ if (mkdir(default_target_dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0) {
+ LOG(FATAL) << "Could not create " << default_target_dir;
+ }
std::vector<std::string> target_files =
- download_target_files(&build_api, default_build, target_dir);
+ download_target_files(&build_api, default_build, default_target_dir);
if (target_files.empty()) {
LOG(FATAL) << "Could not download target files for " << default_build;
}
@@ -322,9 +327,9 @@
}
if (FLAGS_system_build != "") {
- DeviceBuild system_build = ArgumentToBuild(&build_api, FLAGS_system_build,
- DEFAULT_BUILD_TARGET,
- retry_period);
+ auto system_build = ArgumentToBuild(&build_api, FLAGS_system_build,
+ DEFAULT_BUILD_TARGET,
+ retry_period);
if (FLAGS_download_img_zip) {
std::vector<std::string> image_files =
download_images(&build_api, system_build, target_dir, {"system.img"});
@@ -337,8 +342,12 @@
&config, true);
}
}
+ std::string system_target_dir = target_dir + "/system";
+ if (mkdir(system_target_dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0) {
+ LOG(FATAL) << "Could not create " << system_target_dir;
+ }
std::vector<std::string> target_files =
- download_target_files(&build_api, system_build, target_dir);
+ download_target_files(&build_api, system_build, system_target_dir);
if (target_files.empty()) {
LOG(FATAL) << "Could not download target files for " << system_build;
}
@@ -346,8 +355,8 @@
}
if (FLAGS_kernel_build != "") {
- DeviceBuild kernel_build = ArgumentToBuild(&build_api, FLAGS_kernel_build,
- "kernel", retry_period);
+ auto kernel_build = ArgumentToBuild(&build_api, FLAGS_kernel_build,
+ "kernel", retry_period);
std::string local_path = target_dir + "/kernel";
if (build_api.ArtifactToFile(kernel_build, "bzImage", local_path)) {
@@ -390,15 +399,9 @@
return 0;
}
- if (chdir(target_dir.c_str()) != 0) {
- int error_num = errno;
- LOG(FATAL) << "Could not change directory to \"" << target_dir << "\"."
- << "errno was " << error_num << " \"" << strerror(error_num) << "\"";
- }
-
// Ignore return code. We want to make sure there is no running instance,
// and stop_cvd will exit with an error code if there is already no running instance.
- cvd::Command stop_cmd("bin/stop_cvd");
+ cvd::Command stop_cmd(target_dir + "/bin/stop_cvd");
stop_cmd.RedirectStdIO(cvd::Subprocess::StdIOChannel::kStdOut,
cvd::Subprocess::StdIOChannel::kStdErr);
stop_cmd.Start().Wait();
@@ -406,9 +409,35 @@
// gflags::ParseCommandLineFlags will remove fetch_cvd's flags from this.
// This depends the remove_flags argument (3rd) is "true".
+ auto filelist_fd = cvd::SharedFD::MemfdCreate("files_list");
+ if (!filelist_fd->IsOpen()) {
+ LOG(FATAL) << "Unable to create temp file to write file list. "
+ << filelist_fd->StrError() << " (" << filelist_fd->GetErrno() << ")";
+ }
+
+ for (const auto& file : config.get_cvd_files()) {
+ std::string file_entry = file.second.file_path + "\n";
+ auto chars_written = filelist_fd->Write(file_entry.c_str(), file_entry.size());
+ if (chars_written != file_entry.size()) {
+ LOG(FATAL) << "Unable to write entry to file list. Expected to write "
+ << file_entry.size() << " but wrote " << chars_written << ". "
+ << filelist_fd->StrError() << " (" << filelist_fd->GetErrno() << ")";
+ }
+ }
+ auto seek_result = filelist_fd->LSeek(0, SEEK_SET);
+ if (seek_result != 0) {
+ LOG(FATAL) << "Unable to seek on file list file. Expected 0, received " << seek_result
+ << filelist_fd->StrError() << " (" << filelist_fd->GetErrno() << ")";
+ }
+
+ if (filelist_fd->UNMANAGED_Dup2(0) == -1) {
+ LOG(FATAL) << "Unable to set file list to stdin. "
+ << filelist_fd->StrError() << " (" << filelist_fd->GetErrno() << ")";
+ }
+
// TODO(b/139199114): Go into assemble_cvd when the interface is stable and implemented.
- std::string next_stage = "bin/launch_cvd";
+ std::string next_stage = target_dir + "/bin/launch_cvd";
std::vector<const char*> next_stage_argv = {"launch_cvd"};
LOG(INFO) << "Running " << next_stage;
for (int i = 1; i < argc; i++) {
diff --git a/host/commands/fetcher/install_zip.cc b/host/commands/fetcher/install_zip.cc
index bd6294f..3ffd123 100644
--- a/host/commands/fetcher/install_zip.cc
+++ b/host/commands/fetcher/install_zip.cc
@@ -20,6 +20,7 @@
#include <string>
#include <vector>
+#include <android-base/strings.h>
#include <glog/logging.h>
#include "common/libs/utils/archive.h"
@@ -77,8 +78,14 @@
extraction_success = false;
}
}
- for (auto& file : files) {
- file = target_directory + "/" + file;
+ auto it = files.begin();
+ while (it != files.end()) {
+ if (*it == "" || android::base::EndsWith(*it, "/")) {
+ it = files.erase(it);
+ } else {
+ *it = target_directory + "/" + *it;
+ it++;
+ }
}
return extraction_success ? files : std::vector<std::string>{};
}
diff --git a/host/commands/logcat_receiver/main.cpp b/host/commands/logcat_receiver/main.cpp
index e9cbad2..25f95b6 100644
--- a/host/commands/logcat_receiver/main.cpp
+++ b/host/commands/logcat_receiver/main.cpp
@@ -22,8 +22,7 @@
DEFINE_int32(
server_fd, -1,
- "File descriptor to an already created vsock server. If negative a new "
- "server will be created at the port specified on the config file");
+ "File descriptor to an already created vsock server. Must be specified.");
int main(int argc, char** argv) {
::android::base::InitLogging(argv, android::base::StderrLogger);
@@ -37,14 +36,8 @@
CHECK(logcat_file->IsOpen())
<< "Unable to open logcat file: " << logcat_file->StrError();
- cvd::SharedFD server_fd;
- if (FLAGS_server_fd < 0) {
- unsigned int port = config->logcat_vsock_port();
- server_fd = cvd::SharedFD::VsockServer(port, SOCK_STREAM);
- } else {
- server_fd = cvd::SharedFD::Dup(FLAGS_server_fd);
- close(FLAGS_server_fd);
- }
+ cvd::SharedFD server_fd = cvd::SharedFD::Dup(FLAGS_server_fd);
+ close(FLAGS_server_fd);
CHECK(server_fd->IsOpen()) << "Error creating or inheriting logcat server: "
<< server_fd->StrError();
@@ -70,4 +63,4 @@
}
}
return 0;
-}
\ No newline at end of file
+}
diff --git a/host/commands/run_cvd/Android.bp b/host/commands/run_cvd/Android.bp
index a7893fe..c338f08 100644
--- a/host/commands/run_cvd/Android.bp
+++ b/host/commands/run_cvd/Android.bp
@@ -16,9 +16,10 @@
cc_binary_host {
name: "run_cvd",
srcs: [
+ "kernel_args.cc",
"launch.cc",
- "process_monitor.cc",
"main.cc",
+ "process_monitor.cc",
],
header_libs: [
"cuttlefish_glog",
diff --git a/host/commands/run_cvd/kernel_args.cc b/host/commands/run_cvd/kernel_args.cc
new file mode 100644
index 0000000..3f34c95
--- /dev/null
+++ b/host/commands/run_cvd/kernel_args.cc
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "host/commands/run_cvd/kernel_args.h"
+
+#include <string>
+#include <vector>
+
+#include "host/commands/run_cvd/launch.h"
+#include "host/commands/run_cvd/runner_defs.h"
+#include "host/libs/config/cuttlefish_config.h"
+#include "host/libs/vm_manager/vm_manager.h"
+
+template<typename T>
+static void AppendVector(std::vector<T>* destination, const std::vector<T>& source) {
+ destination->insert(destination->end(), source.begin(), source.end());
+}
+
+template<typename S, typename T>
+static std::string concat(const S& s, const T& t) {
+ std::ostringstream os;
+ os << s << t;
+ return os.str();
+}
+
+std::vector<std::string> KernelCommandLineFromConfig(const vsoc::CuttlefishConfig& config) {
+ std::vector<std::string> kernel_cmdline;
+
+ AppendVector(&kernel_cmdline, config.boot_image_kernel_cmdline());
+ AppendVector(&kernel_cmdline,
+ vm_manager::VmManager::ConfigureGpuMode(config.vm_manager(), config.gpu_mode()));
+ AppendVector(&kernel_cmdline, vm_manager::VmManager::ConfigureBootDevices(config.vm_manager()));
+
+ kernel_cmdline.push_back(concat("androidboot.serialno=", config.serial_number()));
+ kernel_cmdline.push_back(concat("androidboot.lcd_density=", config.dpi()));
+ if (config.logcat_mode() == cvd::kLogcatVsockMode) {
+ }
+ kernel_cmdline.push_back(concat(
+ "androidboot.setupwizard_mode=", config.setupwizard_mode()));
+ if (!config.use_bootloader()) {
+ std::string slot_suffix;
+ if (config.boot_slot().empty()) {
+ slot_suffix = "_a";
+ } else {
+ slot_suffix = "_" + config.boot_slot();
+ }
+ kernel_cmdline.push_back(concat("androidboot.slot_suffix=", slot_suffix));
+ }
+ kernel_cmdline.push_back(concat("loop.max_part=", config.loop_max_part()));
+ if (config.guest_enforce_security()) {
+ kernel_cmdline.push_back("enforcing=1");
+ } else {
+ kernel_cmdline.push_back("enforcing=0");
+ kernel_cmdline.push_back("androidboot.selinux=permissive");
+ }
+ if (config.guest_audit_security()) {
+ kernel_cmdline.push_back("audit=1");
+ } else {
+ kernel_cmdline.push_back("audit=0");
+ }
+
+ AppendVector(&kernel_cmdline, config.extra_kernel_cmdline());
+
+ return kernel_cmdline;
+}
+
+std::vector<std::string> KernelCommandLineFromVnc(const VncServerPorts& vnc_ports) {
+ std::vector<std::string> kernel_args;
+ if (vnc_ports.frames_server_vsock_port) {
+ kernel_args.push_back(concat("androidboot.vsock_frames_port=",
+ *vnc_ports.frames_server_vsock_port));
+ }
+ if (vnc_ports.touch_server_vsock_port) {
+ kernel_args.push_back(concat("androidboot.vsock_touch_port=",
+ *vnc_ports.touch_server_vsock_port));
+ }
+ if (vnc_ports.keyboard_server_vsock_port) {
+ kernel_args.push_back(concat("androidboot.vsock_keyboard_port=",
+ *vnc_ports.keyboard_server_vsock_port));
+ }
+ return kernel_args;
+}
+
+std::vector<std::string> KernelCommandLineFromTombstone(const TombstoneReceiverPorts& tombstone) {
+ if (!tombstone.server_vsock_port) {
+ return { "androidboot.tombstone_transmit=0" };
+ }
+ return {
+ "androidboot.tombstone_transmit=1",
+ concat("androidboot.vsock_tombstone_port=", *tombstone.server_vsock_port),
+ };
+}
+
+std::vector<std::string> KernelCommandLineFromConfigServer(const ConfigServerPorts& config_server) {
+ if (!config_server.server_vsock_port) {
+ return {};
+ }
+ return {
+ concat("androidboot.cuttlefish_config_server_port=", *config_server.server_vsock_port),
+ };
+}
+
+std::vector<std::string> KernelCommandLineFromLogcatServer(const LogcatServerPorts& logcat_server) {
+ if (!logcat_server.server_vsock_port) {
+ return {};
+ }
+ return {
+ concat("androidboot.vsock_logcat_port=", *logcat_server.server_vsock_port),
+ };
+}
diff --git a/host/commands/run_cvd/kernel_args.h b/host/commands/run_cvd/kernel_args.h
new file mode 100644
index 0000000..bce02ed
--- /dev/null
+++ b/host/commands/run_cvd/kernel_args.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <string>
+#include <vector>
+
+#include "host/commands/run_cvd/launch.h"
+#include "host/libs/config/cuttlefish_config.h"
+
+std::vector<std::string> KernelCommandLineFromConfig(const vsoc::CuttlefishConfig& config);
+std::vector<std::string> KernelCommandLineFromVnc(const VncServerPorts& vnc_config);
+std::vector<std::string> KernelCommandLineFromTombstone(const TombstoneReceiverPorts& tombstone);
+std::vector<std::string> KernelCommandLineFromConfigServer(const ConfigServerPorts& config_server);
+std::vector<std::string> KernelCommandLineFromLogcatServer(const LogcatServerPorts& config_server);
diff --git a/host/commands/run_cvd/launch.cc b/host/commands/run_cvd/launch.cc
index e4eb858..44e32fa 100644
--- a/host/commands/run_cvd/launch.cc
+++ b/host/commands/run_cvd/launch.cc
@@ -53,10 +53,6 @@
&& AdbModeEnabled(config, vsoc::AdbMode::NativeVsock);
}
-bool AdbUsbEnabled(const vsoc::CuttlefishConfig& config) {
- return AdbModeEnabled(config, vsoc::AdbMode::Usb);
-}
-
cvd::OnSocketReadyCb GetOnSubprocessExitCallback(
const vsoc::CuttlefishConfig& config) {
if (config.restart_subprocesses()) {
@@ -116,13 +112,12 @@
return ret;
}
-void LaunchLogcatReceiverIfEnabled(const vsoc::CuttlefishConfig& config,
- cvd::ProcessMonitor* process_monitor) {
+LogcatServerPorts LaunchLogcatReceiverIfEnabled(const vsoc::CuttlefishConfig& config,
+ cvd::ProcessMonitor* process_monitor) {
if (!LogcatReceiverEnabled(config)) {
- return;
+ return {};
}
- auto port = config.logcat_vsock_port();
- auto socket = cvd::SharedFD::VsockServer(port, SOCK_STREAM);
+ auto socket = cvd::SharedFD::VsockServer(SOCK_STREAM);
if (!socket->IsOpen()) {
LOG(ERROR) << "Unable to create logcat server socket: "
<< socket->StrError();
@@ -132,12 +127,12 @@
cmd.AddParameter("-server_fd=", socket);
process_monitor->StartSubprocess(std::move(cmd),
GetOnSubprocessExitCallback(config));
+ return { socket->VsockServerPort() };
}
-void LaunchConfigServer(const vsoc::CuttlefishConfig& config,
- cvd::ProcessMonitor* process_monitor) {
- auto port = config.config_server_port();
- auto socket = cvd::SharedFD::VsockServer(port, SOCK_STREAM);
+ConfigServerPorts LaunchConfigServer(const vsoc::CuttlefishConfig& config,
+ cvd::ProcessMonitor* process_monitor) {
+ auto socket = cvd::SharedFD::VsockServer(SOCK_STREAM);
if (!socket->IsOpen()) {
LOG(ERROR) << "Unable to create configuration server socket: "
<< socket->StrError();
@@ -147,12 +142,13 @@
cmd.AddParameter("-server_fd=", socket);
process_monitor->StartSubprocess(std::move(cmd),
GetOnSubprocessExitCallback(config));
+ return { socket->VsockServerPort() };
}
-void LaunchTombstoneReceiverIfEnabled(const vsoc::CuttlefishConfig& config,
- cvd::ProcessMonitor* process_monitor) {
+TombstoneReceiverPorts LaunchTombstoneReceiverIfEnabled(
+ const vsoc::CuttlefishConfig& config, cvd::ProcessMonitor* process_monitor) {
if (!config.enable_tombstone_receiver()) {
- return;
+ return {};
}
std::string tombstoneDir = config.PerInstancePath("tombstones");
@@ -163,15 +159,16 @@
LOG(ERROR) << "Failed to create tombstone directory: " << tombstoneDir
<< ". Error: " << errno;
exit(RunnerExitCodes::kTombstoneDirCreationError);
+ return {};
}
}
- auto port = config.tombstone_receiver_port();
- auto socket = cvd::SharedFD::VsockServer(port, SOCK_STREAM);
+ auto socket = cvd::SharedFD::VsockServer(SOCK_STREAM);
if (!socket->IsOpen()) {
LOG(ERROR) << "Unable to create tombstone server socket: "
<< socket->StrError();
std::exit(RunnerExitCodes::kTombstoneServerError);
+ return {};
}
cvd::Command cmd(config.tombstone_receiver_binary());
cmd.AddParameter("-server_fd=", socket);
@@ -179,25 +176,7 @@
process_monitor->StartSubprocess(std::move(cmd),
GetOnSubprocessExitCallback(config));
-}
-
-void LaunchUsbServerIfEnabled(const vsoc::CuttlefishConfig& config,
- cvd::ProcessMonitor* process_monitor) {
- if (!AdbUsbEnabled(config)) {
- return;
- }
- auto socket_name = config.usb_v1_socket_name();
- auto usb_v1_server = cvd::SharedFD::SocketLocalServer(
- socket_name.c_str(), false, SOCK_STREAM, 0666);
- if (!usb_v1_server->IsOpen()) {
- LOG(ERROR) << "Unable to create USB v1 server socket: "
- << usb_v1_server->StrError();
- std::exit(cvd::RunnerExitCodes::kUsbV1SocketError);
- }
- cvd::Command usb_server(config.virtual_usb_manager_binary());
- usb_server.AddParameter("-usb_v1_fd=", usb_v1_server);
- process_monitor->StartSubprocess(std::move(usb_server),
- GetOnSubprocessExitCallback(config));
+ return { socket->VsockServerPort() };
}
cvd::SharedFD CreateUnixVncInputServer(const std::string& path) {
@@ -210,60 +189,63 @@
return server;
}
-cvd::SharedFD CreateVsockVncInputServer(int port) {
- auto server = cvd::SharedFD::VsockServer(port, SOCK_STREAM);
- if (!server->IsOpen()) {
- LOG(ERROR) << "Unable to create vsock input server: "
- << server->StrError();
- return cvd::SharedFD();
+VncServerPorts LaunchVNCServerIfEnabled(
+ const vsoc::CuttlefishConfig& config,
+ cvd::ProcessMonitor* process_monitor,
+ std::function<bool(MonitorEntry*)> callback) {
+ VncServerPorts server_ret;
+ if (!config.enable_vnc_server()) {
+ return {};
}
- return server;
-}
-
-bool LaunchVNCServerIfEnabled(const vsoc::CuttlefishConfig& config,
- cvd::ProcessMonitor* process_monitor,
- std::function<bool(MonitorEntry*)> callback) {
- if (config.enable_vnc_server()) {
- // Launch the vnc server, don't wait for it to complete
- auto port_options = "-port=" + std::to_string(config.vnc_server_port());
- cvd::Command vnc_server(config.vnc_server_binary());
- vnc_server.AddParameter(port_options);
- if (config.vm_manager() == vm_manager::QemuManager::name()) {
- vnc_server.AddParameter("-write_virtio_input");
- }
- // When the ivserver is not enabled, the vnc touch_server needs to serve
- // on sockets and send input events to whoever connects to it (the VMM).
- auto touch_server =
- config.vm_manager() == vm_manager::CrosvmManager::name()
- ? CreateUnixVncInputServer(config.touch_socket_path())
- : CreateVsockVncInputServer(config.touch_socket_port());
- if (!touch_server->IsOpen()) {
- return false;
- }
- vnc_server.AddParameter("-touch_fd=", touch_server);
-
- auto keyboard_server =
- config.vm_manager() == vm_manager::CrosvmManager::name()
- ? CreateUnixVncInputServer(config.keyboard_socket_path())
- : CreateVsockVncInputServer(config.keyboard_socket_port());
- if (!keyboard_server->IsOpen()) {
- return false;
- }
- vnc_server.AddParameter("-keyboard_fd=", keyboard_server);
- // TODO(b/128852363): This should be handled through the wayland mock
- // instead.
- // Additionally it receives the frame updates from a virtual socket
- // instead
- auto frames_server =
- cvd::SharedFD::VsockServer(config.frames_vsock_port(), SOCK_STREAM);
- if (!frames_server->IsOpen()) {
- return false;
- }
- vnc_server.AddParameter("-frame_server_fd=", frames_server);
- process_monitor->StartSubprocess(std::move(vnc_server), callback);
- return true;
+ std::set<std::string> extra_kernel_args;
+ // Launch the vnc server, don't wait for it to complete
+ auto port_options = "-port=" + std::to_string(config.vnc_server_port());
+ cvd::Command vnc_server(config.vnc_server_binary());
+ vnc_server.AddParameter(port_options);
+ if (config.vm_manager() == vm_manager::QemuManager::name()) {
+ vnc_server.AddParameter("-write_virtio_input");
}
- return false;
+ // When the ivserver is not enabled, the vnc touch_server needs to serve
+ // on sockets and send input events to whoever connects to it (the VMM).
+ cvd::SharedFD touch_server;
+ if (config.vm_manager() == vm_manager::CrosvmManager::name()) {
+ touch_server = CreateUnixVncInputServer(config.touch_socket_path());
+ } else {
+ touch_server = cvd::SharedFD::VsockServer(SOCK_STREAM);
+ server_ret.touch_server_vsock_port = touch_server->VsockServerPort();
+ }
+ if (!touch_server->IsOpen()) {
+ LOG(ERROR) << "Could not open touch server: " << touch_server->StrError();
+ return {};
+ }
+ vnc_server.AddParameter("-touch_fd=", touch_server);
+
+ cvd::SharedFD keyboard_server;
+ if (config.vm_manager() == vm_manager::CrosvmManager::name()) {
+ keyboard_server = CreateUnixVncInputServer(config.keyboard_socket_path());
+ } else {
+ keyboard_server = cvd::SharedFD::VsockServer(SOCK_STREAM);
+ server_ret.keyboard_server_vsock_port = keyboard_server->VsockServerPort();
+ }
+ if (!keyboard_server->IsOpen()) {
+ LOG(ERROR) << "Could not open keyboard server: " << keyboard_server->StrError();
+ return {};
+ }
+ vnc_server.AddParameter("-keyboard_fd=", keyboard_server);
+ // TODO(b/128852363): This should be handled through the wayland mock
+ // instead.
+ // Additionally it receives the frame updates from a virtual socket
+ // instead
+ auto frames_server = cvd::SharedFD::VsockServer(SOCK_STREAM);
+ server_ret.frames_server_vsock_port = frames_server->VsockServerPort();
+ if (!frames_server->IsOpen()) {
+ LOG(ERROR) << "Could not open frames server: " << frames_server->StrError();
+ return {};
+ }
+ vnc_server.AddParameter("-frame_server_fd=", frames_server);
+ process_monitor->StartSubprocess(std::move(vnc_server), callback);
+
+ return server_ret;
}
void LaunchAdbConnectorIfEnabled(cvd::ProcessMonitor* process_monitor,
diff --git a/host/commands/run_cvd/launch.h b/host/commands/run_cvd/launch.h
index 4db6e12..e73ac1a 100644
--- a/host/commands/run_cvd/launch.h
+++ b/host/commands/run_cvd/launch.h
@@ -1,7 +1,10 @@
#pragma once
#include <functional>
+#include <set>
+#include <string>
+#include "common/libs/fs/shared_fd.h"
#include "common/libs/utils/subprocess.h"
#include "host/commands/run_cvd/process_monitor.h"
#include "host/libs/config/cuttlefish_config.h"
@@ -10,19 +13,36 @@
const vsoc::CuttlefishConfig& config,
cvd::ProcessMonitor* process_monitor,
unsigned int number_of_event_pipes);
-void LaunchLogcatReceiverIfEnabled(const vsoc::CuttlefishConfig& config,
- cvd::ProcessMonitor* process_monitor);
-void LaunchConfigServer(const vsoc::CuttlefishConfig& config,
- cvd::ProcessMonitor* process_monitor);
-void LaunchUsbServerIfEnabled(const vsoc::CuttlefishConfig& config,
- cvd::ProcessMonitor* process_monitor);
-bool LaunchVNCServerIfEnabled(const vsoc::CuttlefishConfig& config,
- cvd::ProcessMonitor* process_monitor,
- std::function<bool(cvd::MonitorEntry*)> callback);
void LaunchAdbConnectorIfEnabled(cvd::ProcessMonitor* process_monitor,
const vsoc::CuttlefishConfig& config,
cvd::SharedFD adbd_events_pipe);
void LaunchSocketVsockProxyIfEnabled(cvd::ProcessMonitor* process_monitor,
const vsoc::CuttlefishConfig& config);
-void LaunchTombstoneReceiverIfEnabled(const vsoc::CuttlefishConfig& config,
- cvd::ProcessMonitor* process_monitor);
+
+struct VncServerPorts {
+ std::optional<unsigned int> frames_server_vsock_port;
+ std::optional<unsigned int> touch_server_vsock_port;
+ std::optional<unsigned int> keyboard_server_vsock_port;
+};
+VncServerPorts LaunchVNCServerIfEnabled(
+ const vsoc::CuttlefishConfig& config,
+ cvd::ProcessMonitor* process_monitor,
+ std::function<bool(cvd::MonitorEntry*)> callback);
+
+struct TombstoneReceiverPorts {
+ std::optional<unsigned int> server_vsock_port;
+};
+TombstoneReceiverPorts LaunchTombstoneReceiverIfEnabled(
+ const vsoc::CuttlefishConfig& config, cvd::ProcessMonitor* process_monitor);
+
+struct ConfigServerPorts {
+ std::optional<unsigned int> server_vsock_port;
+};
+ConfigServerPorts LaunchConfigServer(const vsoc::CuttlefishConfig& config,
+ cvd::ProcessMonitor* process_monitor);
+
+struct LogcatServerPorts {
+ std::optional<unsigned int> server_vsock_port;
+};
+LogcatServerPorts LaunchLogcatReceiverIfEnabled(const vsoc::CuttlefishConfig& config,
+ cvd::ProcessMonitor* process_monitor);
diff --git a/host/commands/run_cvd/main.cc b/host/commands/run_cvd/main.cc
index 2ff5d10..c77e924 100644
--- a/host/commands/run_cvd/main.cc
+++ b/host/commands/run_cvd/main.cc
@@ -47,6 +47,7 @@
#include "common/libs/utils/files.h"
#include "common/libs/utils/subprocess.h"
#include "common/libs/utils/size_utils.h"
+#include "host/commands/run_cvd/kernel_args.h"
#include "host/commands/run_cvd/launch.h"
#include "host/commands/run_cvd/runner_defs.h"
#include "host/commands/run_cvd/process_monitor.h"
@@ -159,13 +160,7 @@
}
std::string config_env = "export CUTTLEFISH_PER_INSTANCE_PATH=\"" +
config.PerInstancePath(".") + "\"\n";
- config_env += "export ANDROID_SERIAL=";
- if (config.adb_mode().count(vsoc::AdbMode::Usb) > 0) {
- config_env += config.serial_number();
- } else {
- config_env += config.adb_ip_and_port();
- }
- config_env += "\n";
+ config_env += "export ANDROID_SERIAL=" + config.adb_ip_and_port() + "\n";
env->Write(config_env.c_str(), config_env.size());
return true;
}
@@ -278,80 +273,6 @@
return config.PerInstancePath("cuttlefish_config.json");
}
-template<typename T>
-void AppendVector(std::vector<T>* destination, const std::vector<T>& source) {
- destination->insert(destination->end(), source.begin(), source.end());
-}
-
-template<typename S, typename T>
-static std::string concat(const S& s, const T& t) {
- std::ostringstream os;
- os << s << t;
- return os.str();
-}
-
-std::vector<std::string> KernelCommandLineFromConfig(const vsoc::CuttlefishConfig& config) {
- std::vector<std::string> kernel_cmdline;
-
- AppendVector(&kernel_cmdline, config.boot_image_kernel_cmdline());
- AppendVector(&kernel_cmdline,
- vm_manager::VmManager::ConfigureGpuMode(config.vm_manager(), config.gpu_mode()));
- AppendVector(&kernel_cmdline, vm_manager::VmManager::ConfigureBootDevices(config.vm_manager()));
-
- kernel_cmdline.push_back(concat("androidboot.serialno=", config.serial_number()));
- kernel_cmdline.push_back(concat("androidboot.lcd_density=", config.dpi()));
- if (config.logcat_mode() == cvd::kLogcatVsockMode) {
- kernel_cmdline.push_back(concat("androidboot.vsock_logcat_port=", config.logcat_vsock_port()));
- }
- if (config.enable_vnc_server()) {
- kernel_cmdline.push_back(concat("androidboot.vsock_frames_port=", config.frames_vsock_port()));
- }
- if (config.enable_tombstone_receiver()) {
- kernel_cmdline.push_back("androidboot.tombstone_transmit=1");
- kernel_cmdline.push_back(concat(
- "androidboot.vsock_tombstone_port=",
- config.tombstone_receiver_port()));
- // TODO (b/128842613) populate a cid flag to read the host CID during
- // runtime
- } else {
- kernel_cmdline.push_back("androidboot.tombstone_transmit=0");
- }
- kernel_cmdline.push_back(concat(
- "androidboot.cuttlefish_config_server_port=", config.config_server_port()));
- kernel_cmdline.push_back(concat(
- "androidboot.setupwizard_mode=", config.setupwizard_mode()));
- if (!config.use_bootloader()) {
- std::string slot_suffix;
- if (config.boot_slot().empty()) {
- slot_suffix = "_a";
- } else {
- slot_suffix = "_" + config.boot_slot();
- }
- kernel_cmdline.push_back(concat("androidboot.slot_suffix=", slot_suffix));
- }
- if (config.vm_manager() == vm_manager::QemuManager::name()) {
- kernel_cmdline.push_back(concat("androidboot.vsock_touch_port=", config.touch_socket_port()));
- kernel_cmdline.push_back(concat(
- "androidboot.vsock_keyboard_port=", config.keyboard_socket_port()));
- }
- kernel_cmdline.push_back(concat("loop.max_part=", config.loop_max_part()));
- if (config.guest_enforce_security()) {
- kernel_cmdline.push_back("enforcing=1");
- } else {
- kernel_cmdline.push_back("enforcing=0");
- kernel_cmdline.push_back("androidboot.selinux=permissive");
- }
- if (config.guest_audit_security()) {
- kernel_cmdline.push_back("audit=1");
- } else {
- kernel_cmdline.push_back("audit=0");
- }
-
- AppendVector(&kernel_cmdline, config.extra_kernel_cmdline());
-
- return kernel_cmdline;
-}
-
} // namespace
int main(int argc, char** argv) {
@@ -478,26 +399,36 @@
cvd::SharedFD adbd_events_pipe = event_pipes[1];
event_pipes.clear();
+ std::set<std::string> extra_kernel_cmdline;
+
SetUpHandlingOfBootEvents(&process_monitor, boot_events_pipe,
boot_state_machine);
- LaunchLogcatReceiverIfEnabled(*config, &process_monitor);
+ auto logcat_server = LaunchLogcatReceiverIfEnabled(*config, &process_monitor);
+ auto logcat_server_args = KernelCommandLineFromLogcatServer(logcat_server);
- LaunchConfigServer(*config, &process_monitor);
+ auto config_server = LaunchConfigServer(*config, &process_monitor);
+ auto config_server_args = KernelCommandLineFromConfigServer(config_server);
- LaunchTombstoneReceiverIfEnabled(*config, &process_monitor);
-
- LaunchUsbServerIfEnabled(*config, &process_monitor);
+ auto tombstone_server = LaunchTombstoneReceiverIfEnabled(*config, &process_monitor);
+ auto tombstone_kernel_args = KernelCommandLineFromTombstone(tombstone_server);
// The vnc server needs to be launched after the ivserver because it connects
// to it when using qemu. It needs to launch before the VMM because it serves
// on several sockets (input devices, vsock frame server) when using crosvm.
- auto frontend_enabled = LaunchVNCServerIfEnabled(
+ auto vnc_server_config = LaunchVNCServerIfEnabled(
*config, &process_monitor, GetOnSubprocessExitCallback(*config));
+ auto vnc_kernel_args = KernelCommandLineFromVnc(vnc_server_config);
+
+ auto kernel_args = KernelCommandLineFromConfig(*config);
+ kernel_args.insert(kernel_args.end(), vnc_kernel_args.begin(), vnc_kernel_args.end());
+ kernel_args.insert(kernel_args.end(), tombstone_kernel_args.begin(),
+ tombstone_kernel_args.end());
+ kernel_args.insert(kernel_args.end(), config_server_args.begin(), config_server_args.end());
+ kernel_args.insert(kernel_args.end(), logcat_server_args.begin(), logcat_server_args.end());
// Start the guest VM
- vm_manager->WithFrontend(frontend_enabled);
- auto kernel_args = KernelCommandLineFromConfig(*config);
+ vm_manager->WithFrontend(vnc_kernel_args.size() > 0);
vm_manager->WithKernelCommandLine(android::base::Join(kernel_args, " "));
auto vmm_commands = vm_manager->StartCommands();
for (auto& vmm_cmd: vmm_commands) {
diff --git a/host/commands/run_cvd/process_monitor.cc b/host/commands/run_cvd/process_monitor.cc
index 8243306..f497ddb 100644
--- a/host/commands/run_cvd/process_monitor.cc
+++ b/host/commands/run_cvd/process_monitor.cc
@@ -68,7 +68,8 @@
}
void ProcessMonitor::StartSubprocess(Command cmd, OnSocketReadyCb callback) {
- auto proc = cmd.StartInGroup(true);
+ cmd.SetWithControlSocket(true);
+ auto proc = cmd.StartInGroup();
if (!proc.Started()) {
LOG(ERROR) << "Failed to start process";
return;
@@ -151,7 +152,7 @@
LOG(INFO) << "subprocess " << entry->cmd->GetShortName() << " (" << wait_ret
<< ") has exited for unknown reasons";
}
- entry->proc.reset(new Subprocess(entry->cmd->Start(true)));
+ entry->proc.reset(new Subprocess(entry->cmd->Start()));
return true;
}
diff --git a/host/commands/tombstone_receiver/Android.bp b/host/commands/tombstone_receiver/Android.bp
index bd32cae..66a353a 100644
--- a/host/commands/tombstone_receiver/Android.bp
+++ b/host/commands/tombstone_receiver/Android.bp
@@ -28,9 +28,7 @@
"libcuttlefish_utils",
],
static_libs: [
- "libcuttlefish_host_config",
"libgflags",
- "libjsoncpp",
],
defaults: ["cuttlefish_host_only"],
}
diff --git a/host/commands/tombstone_receiver/main.cpp b/host/commands/tombstone_receiver/main.cpp
index 7bea670..25da1a3 100644
--- a/host/commands/tombstone_receiver/main.cpp
+++ b/host/commands/tombstone_receiver/main.cpp
@@ -23,7 +23,6 @@
#include <sstream>
#include "common/libs/fs/shared_fd.h"
-#include "host/libs/config/cuttlefish_config.h"
DEFINE_int32(
server_fd, -1,
@@ -59,21 +58,13 @@
::android::base::InitLogging(argv, android::base::StderrLogger);
google::ParseCommandLineFlags(&argc, &argv, true);
- auto config = vsoc::CuttlefishConfig::Get();
- cvd::SharedFD server_fd;
+ cvd::SharedFD server_fd = cvd::SharedFD::Dup(FLAGS_server_fd);
+ close(FLAGS_server_fd);
- if (FLAGS_server_fd < 0) {
- unsigned int port = config->tombstone_receiver_port();
- server_fd = cvd::SharedFD::VsockServer(port, SOCK_STREAM);
- } else {
- server_fd = cvd::SharedFD::Dup(FLAGS_server_fd);
- close(FLAGS_server_fd);
- }
-
- CHECK(server_fd->IsOpen()) << "Error creating/inheriting tombstone server: "
+ CHECK(server_fd->IsOpen()) << "Error inheriting tombstone server: "
<< server_fd->StrError();
LOG(INFO) << "Host is starting server on port "
- << config->tombstone_receiver_port();
+ << server_fd->VsockServerPort();
// Server loop
while (true) {
diff --git a/host/commands/virtual_usb_manager/Android.bp b/host/commands/virtual_usb_manager/Android.bp
deleted file mode 100644
index 6669b8c..0000000
--- a/host/commands/virtual_usb_manager/Android.bp
+++ /dev/null
@@ -1,47 +0,0 @@
-//
-// Copyright (C) 2017 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-cc_binary_host {
- name: "virtual_usb_manager",
- srcs: [
- "main.cc",
- "vadb/usb_cmd_attach.cpp",
- "vadb/usb_cmd_control_transfer.cpp",
- "vadb/usb_cmd_data_transfer.cpp",
- "vadb/usb_cmd_device_list.cpp",
- "vadb/usb_cmd_heartbeat.cpp",
- "vadb/virtual_adb_client.cpp",
- "vadb/virtual_adb_server.cpp",
- "usbip/client.cpp",
- "usbip/device_pool.cpp",
- "usbip/messages.cpp",
- "usbip/server.cpp",
- "usbip/vhci_instrument.cpp",
- ],
- header_libs: [
- "cuttlefish_glog",
- ],
- shared_libs: [
- "libcuttlefish_fs",
- "libcuttlefish_utils",
- "libbase",
- ],
- static_libs: [
- "libcuttlefish_host_config",
- "libgflags",
- "libjsoncpp",
- ],
- defaults: ["cuttlefish_host_only"],
-}
diff --git a/host/commands/virtual_usb_manager/main.cc b/host/commands/virtual_usb_manager/main.cc
deleted file mode 100644
index 39fd556..0000000
--- a/host/commands/virtual_usb_manager/main.cc
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <string>
-#include <thread>
-
-#include <gflags/gflags.h>
-#include <glog/logging.h>
-
-#include "common/libs/fs/shared_fd.h"
-#include "common/libs/fs/shared_select.h"
-#include "host/libs/config/cuttlefish_config.h"
-#include "host/commands/virtual_usb_manager/usbip/server.h"
-#include "host/commands/virtual_usb_manager/vadb/virtual_adb_server.h"
-
-DEFINE_int32(
- usb_v1_fd, -1,
- "A file descriptor pointing to the USB v1 open socket or -1 to create it");
-
-int main(int argc, char** argv) {
- ::android::base::InitLogging(argv, android::base::StderrLogger);
- google::ParseCommandLineFlags(&argc, &argv, true);
-
- auto config = vsoc::CuttlefishConfig::Get();
- if (!config) {
- LOG(ERROR) << "Unable to get config object";
- return 1;
- }
-
- cvd::SharedFD usb_v1_server;
-
- if (FLAGS_usb_v1_fd < 0) {
- auto socket_name = config->usb_v1_socket_name();
- LOG(INFO) << "Starting server at " << socket_name;
- usb_v1_server = cvd::SharedFD::SocketLocalServer(socket_name.c_str(), false,
- SOCK_STREAM, 0666);
- } else {
- usb_v1_server = cvd::SharedFD::Dup(FLAGS_usb_v1_fd);
- }
-
- if (!usb_v1_server->IsOpen()) {
- LOG(ERROR) << "Error openning USB v1 server: " << usb_v1_server->StrError();
- return 2;
- }
-
- vadb::VirtualADBServer adb_{usb_v1_server, config->vhci_port(),
- config->usb_ip_socket_name()};
- vadb::usbip::Server usbip_{config->usb_ip_socket_name(), adb_.Pool()};
-
- CHECK(usbip_.Init()) << "Could not start USB/IP server";
-
- for (;;) {
- cvd::SharedFDSet fd_read;
- fd_read.Zero();
-
- adb_.BeforeSelect(&fd_read);
- usbip_.BeforeSelect(&fd_read);
-
- int ret = cvd::Select(&fd_read, nullptr, nullptr, nullptr);
- if (ret <= 0) continue;
-
- adb_.AfterSelect(fd_read);
- usbip_.AfterSelect(fd_read);
- }
-
- return 0;
-}
diff --git a/host/commands/virtual_usb_manager/usbip/Android.bp b/host/commands/virtual_usb_manager/usbip/Android.bp
deleted file mode 100644
index 8a52b90..0000000
--- a/host/commands/virtual_usb_manager/usbip/Android.bp
+++ /dev/null
@@ -1,36 +0,0 @@
-//
-// Copyright (C) 2017 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-cc_library_host_static {
- name: "libusbip",
- srcs: [
- "client.cpp",
- "device_pool.cpp",
- "messages.cpp",
- "server.cpp",
- "vhci_instrument.cpp",
- ],
- header_libs: [
- "cuttlefish_glog",
- ],
- shared_libs: [
- "libcuttlefish_fs",
- "libbase",
- ],
- static_libs: [
- "libgflags",
- ],
- defaults: ["cuttlefish_host_only"],
-}
diff --git a/host/commands/virtual_usb_manager/usbip/README.md b/host/commands/virtual_usb_manager/usbip/README.md
deleted file mode 100644
index e652352..0000000
--- a/host/commands/virtual_usb_manager/usbip/README.md
+++ /dev/null
@@ -1,36 +0,0 @@
-# USB/IP server library
-
-This folder contains set of classes and structures that constitute basic USB/IP
-server.
-
-Protocol used in this library is defined as part of
-[Linux kernel documentation](https://www.kernel.org/doc/Documentation/usb/usbip_protocol.txt).
-
-## Structure
-
-### [`vadb::usbip::Device`](./device.h)[](#Device)
-
-Structure describing individual device accessible over USB/IP protocol.
-
-### [`vadb::usbip::DevicePool`](./device_pool.h)[](#DevicePool)
-
-DevicePool holds a set of [Devices](#Device) that can be enumerated and
-accessed by clients of this Server.
-
-### [`vadb::usbip::Server`](./server.h)
-
-Purpose of this class is to start a new listening socket and accept incoming
-USB/IP connections & requests.
-
-### [`vadb::usbip::Client`](./client.h)
-
-Client class represents individual USB/IP connection. Client enables remote
-USB/IP client to enumerate and access devices registered in
-[DevicePool](#DevicePool).
-
-### [`USB/IP Messages`](./messages.h)
-
-This file contains structures and enum values defined by the USB/IP protocol.
-All definitions found there have been collected from
-[Linux kernel documentation](https://www.kernel.org/doc/Documentation/usb/usbip_protocol.txt)
-.
diff --git a/host/commands/virtual_usb_manager/usbip/client.cpp b/host/commands/virtual_usb_manager/usbip/client.cpp
deleted file mode 100644
index 50ea9f8..0000000
--- a/host/commands/virtual_usb_manager/usbip/client.cpp
+++ /dev/null
@@ -1,311 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "host/commands/virtual_usb_manager/usbip/client.h"
-
-#include <arpa/inet.h>
-
-#include <glog/logging.h>
-#include <iostream>
-
-#include "host/commands/virtual_usb_manager/usbip/device.h"
-#include "host/commands/virtual_usb_manager/usbip/messages.h"
-
-namespace vadb {
-namespace usbip {
-
-// NetToHost and HostToNet are used to reduce risk of copy/paste errors and to
-// provide uniform method of converting messages between different endian types.
-namespace {
-
-uint32_t NetToHost(uint32_t t) { return ntohl(t); }
-
-Command NetToHost(Command t) { return static_cast<Command>(ntohl(t)); }
-
-Direction NetToHost(Direction t) { return static_cast<Direction>(ntohl(t)); }
-
-uint32_t NetToHost(uint16_t t) { return ntohs(t); }
-
-CmdHeader NetToHost(const CmdHeader& t) {
- CmdHeader rval = t;
- rval.command = NetToHost(t.command);
- rval.seq_num = NetToHost(t.seq_num);
- rval.bus_num = NetToHost(t.bus_num);
- rval.dev_num = NetToHost(t.dev_num);
- rval.direction = NetToHost(t.direction);
- rval.endpoint = NetToHost(t.endpoint);
- return rval;
-}
-
-CmdReqSubmit NetToHost(const CmdReqSubmit& t) {
- CmdReqSubmit rval = t;
- rval.transfer_flags = NetToHost(t.transfer_flags);
- rval.transfer_buffer_length = NetToHost(t.transfer_buffer_length);
- rval.start_frame = NetToHost(t.start_frame);
- rval.number_of_packets = NetToHost(t.number_of_packets);
- rval.deadline_interval = NetToHost(t.deadline_interval);
- return rval;
-}
-
-CmdReqUnlink NetToHost(const CmdReqUnlink& t) {
- CmdReqUnlink rval = t;
- rval.seq_num = NetToHost(t.seq_num);
- return rval;
-}
-
-uint32_t HostToNet(uint32_t t) { return htonl(t); }
-
-Command HostToNet(const Command t) { return static_cast<Command>(htonl(t)); }
-
-Direction HostToNet(Direction t) { return static_cast<Direction>(htonl(t)); }
-
-uint16_t HostToNet(uint16_t t) { return htons(t); }
-
-CmdHeader HostToNet(const CmdHeader& t) {
- CmdHeader rval = t;
- rval.command = HostToNet(t.command);
- rval.seq_num = HostToNet(t.seq_num);
- rval.bus_num = HostToNet(t.bus_num);
- rval.dev_num = HostToNet(t.dev_num);
- rval.direction = HostToNet(t.direction);
- rval.endpoint = HostToNet(t.endpoint);
- return rval;
-}
-
-CmdRepSubmit HostToNet(const CmdRepSubmit& t) {
- CmdRepSubmit rval = t;
- rval.status = HostToNet(t.status);
- rval.actual_length = HostToNet(t.actual_length);
- rval.start_frame = HostToNet(t.start_frame);
- rval.number_of_packets = HostToNet(t.number_of_packets);
- rval.error_count = HostToNet(t.error_count);
- return rval;
-}
-
-CmdRepUnlink HostToNet(const CmdRepUnlink& t) {
- CmdRepUnlink rval = t;
- rval.status = HostToNet(t.status);
- return rval;
-}
-
-// Converts data to network order and sends it to the USB/IP client.
-// Returns true, if message was sent successfully.
-template <typename T>
-bool SendUSBIPMsg(const cvd::SharedFD& fd, const T& data) {
- T net = HostToNet(data);
- return fd->Send(&net, sizeof(T), MSG_NOSIGNAL) == sizeof(T);
-}
-
-// Receive message from USB/IP client.
-// After message is received, it's updated to match host endian.
-// Returns true, if message was received successfully.
-template <typename T>
-bool RecvUSBIPMsg(const cvd::SharedFD& fd, T* data) {
- T net;
- bool res = fd->Recv(&net, sizeof(T), MSG_NOSIGNAL) == sizeof(T);
- if (res) {
- *data = NetToHost(net);
- }
- return res;
-}
-
-} // namespace
-
-void Client::BeforeSelect(cvd::SharedFDSet* fd_read) const {
- fd_read->Set(fd_);
-}
-
-bool Client::AfterSelect(const cvd::SharedFDSet& fd_read) {
- if (fd_read.IsSet(fd_)) return HandleIncomingMessage();
- return true;
-}
-
-// Handle incoming COMMAND.
-//
-// Read next CMD from client channel.
-// Returns false, if connection should be dropped.
-bool Client::HandleIncomingMessage() {
- CmdHeader hdr;
- if (!RecvUSBIPMsg(fd_, &hdr)) {
- LOG(ERROR) << "Could not read command header: " << fd_->StrError();
- return false;
- }
-
- // And the protocol, again.
- switch (hdr.command) {
- case kUsbIpCmdReqSubmit:
- return HandleSubmitCmd(hdr);
-
- case kUsbIpCmdReqUnlink:
- return HandleUnlinkCmd(hdr);
-
- default:
- LOG(ERROR) << "Unsupported command requested: " << hdr.command;
- return false;
- }
-}
-
-// Handle incoming SUBMIT COMMAND.
-//
-// Execute command on specified USB device.
-// Returns false, if connection should be dropped.
-bool Client::HandleSubmitCmd(const CmdHeader& cmd) {
- CmdReqSubmit req;
- if (!RecvUSBIPMsg(fd_, &req)) {
- LOG(ERROR) << "Could not read submit command: " << fd_->StrError();
- return false;
- }
-
- uint32_t seq_num = cmd.seq_num;
-
- // Reserve buffer for data in or out.
- std::vector<uint8_t> payload;
- int payload_length = req.transfer_buffer_length;
- payload.resize(payload_length);
-
- bool is_host_to_device = cmd.direction == kUsbIpDirectionOut;
- // Control requests are quite easy to detect; if setup is all '0's, then we're
- // doing a data transfer, otherwise it's a control transfer.
- // We only check for cmd and type fields here, as combination 0/0 of these
- // fields is already invalid (cmd == GET_STATUS, type = WRITE).
- bool is_control_request = !(req.setup.cmd == 0 && req.setup.type == 0);
-
- // Find requested device and execute command.
- auto device = pool_.GetDevice({cmd.bus_num, cmd.dev_num});
- if (device) {
- // Read data to be sent to device, if specified.
- if (is_host_to_device && payload_length) {
- size_t got = 0;
- // Make sure we read everything.
- while (got < payload.size()) {
- auto read =
- fd_->Recv(&payload[got], payload.size() - got, MSG_NOSIGNAL);
- if (fd_->GetErrno() != 0) {
- LOG(ERROR) << "Client disconnected: " << fd_->StrError();
- return false;
- } else if (!read) {
- LOG(ERROR) << "Short read; client likely disconnected.";
- return false;
- }
- got += read;
- }
- }
-
- // If setup structure of request is initialized then we need to execute
- // control transfer. Otherwise, this is a plain data exchange.
- bool send_success = false;
- if (is_control_request) {
- send_success = device->handle_control_transfer(
- req.setup, req.deadline_interval, std::move(payload),
- [this, seq_num, is_host_to_device](bool is_success,
- std::vector<uint8_t> data) {
- HandleAsyncDataReady(seq_num, is_success, is_host_to_device,
- std::move(data));
- });
- } else {
- send_success = device->handle_data_transfer(
- cmd.endpoint, is_host_to_device, req.deadline_interval,
- std::move(payload),
- [this, seq_num, is_host_to_device](bool is_success,
- std::vector<uint8_t> data) {
- HandleAsyncDataReady(seq_num, is_success, is_host_to_device,
- std::move(data));
- });
- }
-
- // Simply fail if couldn't execute command.
- if (!send_success) {
- HandleAsyncDataReady(seq_num, false, is_host_to_device,
- std::vector<uint8_t>());
- }
- }
- return true;
-}
-
-void Client::HandleAsyncDataReady(uint32_t seq_num, bool is_success,
- bool is_host_to_device,
- std::vector<uint8_t> data) {
- // Response template.
- // - in header, host doesn't care about anything else except for command type
- // and sequence number.
- // - in body, report status == !OK unless we completed everything
- // successfully.
- CmdHeader rephdr{};
- rephdr.command = kUsbIpCmdRepSubmit;
- rephdr.seq_num = seq_num;
-
- CmdRepSubmit rep{};
- rep.status = is_success ? 0 : 1;
- rep.actual_length = data.size();
-
- // Data out.
- if (!SendUSBIPMsg(fd_, rephdr)) {
- LOG(ERROR) << "Failed to send response header: " << fd_->StrError();
- return;
- }
-
- if (!SendUSBIPMsg(fd_, rep)) {
- LOG(ERROR) << "Failed to send response body: " << fd_->StrError();
- return;
- }
-
- if (!is_host_to_device && data.size() > 0) {
- if (static_cast<size_t>(
- fd_->Send(data.data(), data.size(), MSG_NOSIGNAL)) != data.size()) {
- LOG(ERROR) << "Failed to send response payload: " << fd_->StrError();
- return;
- }
- }
-}
-
-// Handle incoming UNLINK COMMAND.
-//
-// Unlink removes command specified via seq_num from a list of commands to be
-// executed.
-// We don't schedule commands for execution, so technically every UNLINK will
-// come in late.
-// Returns false, if connection should be dropped.
-bool Client::HandleUnlinkCmd(const CmdHeader& cmd) {
- CmdReqUnlink req;
- if (!RecvUSBIPMsg(fd_, &req)) {
- LOG(ERROR) << "Could not read unlink command: " << fd_->StrError();
- return false;
- }
- LOG(INFO) << "Client requested to unlink previously submitted command: "
- << req.seq_num;
-
- CmdHeader rephdr{};
- rephdr.command = kUsbIpCmdRepUnlink;
- rephdr.seq_num = cmd.seq_num;
-
- // Technically we do not schedule commands for execution, so we cannot
- // de-queue commands, either. Indicate this by sending status != ok.
- CmdRepUnlink rep;
- rep.status = 1;
-
- if (!SendUSBIPMsg(fd_, rephdr)) {
- LOG(ERROR) << "Could not send unlink command header: " << fd_->StrError();
- return false;
- }
-
- if (!SendUSBIPMsg(fd_, rep)) {
- LOG(ERROR) << "Could not send unlink command data: " << fd_->StrError();
- return false;
- }
- return true;
-}
-
-} // namespace usbip
-} // namespace vadb
diff --git a/host/commands/virtual_usb_manager/usbip/client.h b/host/commands/virtual_usb_manager/usbip/client.h
deleted file mode 100644
index 5e48f21..0000000
--- a/host/commands/virtual_usb_manager/usbip/client.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-
-#include "common/libs/fs/shared_fd.h"
-#include "common/libs/fs/shared_select.h"
-#include "host/commands/virtual_usb_manager/usbip/device_pool.h"
-#include "host/commands/virtual_usb_manager/usbip/messages.h"
-
-namespace vadb {
-namespace usbip {
-
-// Represents USB/IP client, or individual connection to our USB/IP server.
-// Multiple clients are allowed, even if practically we anticipate only one
-// connection at the time.
-class Client final {
- public:
- Client(const DevicePool& pool, const cvd::SharedFD& fd)
- : pool_(pool), fd_(fd) {}
-
- ~Client() {}
-
- // BeforeSelect is Called right before Select() to populate interesting
- // SharedFDs.
- void BeforeSelect(cvd::SharedFDSet* fd_read) const;
-
- // AfterSelect is Called right after Select() to detect and respond to changes
- // on affected SharedFDs.
- // Return value indicates whether this client is still valid.
- bool AfterSelect(const cvd::SharedFDSet& fd_read);
-
- private:
- // Respond to message from remote client.
- // Returns false, if client violated protocol or disconnected, indicating,
- // that this instance should no longer be used.
- bool HandleIncomingMessage();
-
- // Execute command on USB device.
- // Returns false, if connection should be dropped.
- bool HandleSubmitCmd(const CmdHeader& hdr);
-
- // HandleAsyncDataReady is called asynchronously once previously submitted
- // data transfer (control or bulk) has completed (or failed).
- void HandleAsyncDataReady(uint32_t seq_num, bool is_success,
- bool is_host_to_device, std::vector<uint8_t> data);
-
- // Unlink previously submitted message from device queue.
- // Returns false, if connection should be dropped.
- bool HandleUnlinkCmd(const CmdHeader& hdr);
-
- const DevicePool& pool_;
- cvd::SharedFD fd_;
-
- Client(const Client&) = delete;
- Client& operator=(const Client&) = delete;
-};
-
-} // namespace usbip
-} // namespace vadb
diff --git a/host/commands/virtual_usb_manager/usbip/device.h b/host/commands/virtual_usb_manager/usbip/device.h
deleted file mode 100644
index 7af1ccc..0000000
--- a/host/commands/virtual_usb_manager/usbip/device.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-
-#include <cstdint>
-#include <functional>
-#include <map>
-#include <memory>
-#include <vector>
-
-#include "host/commands/virtual_usb_manager/usbip/messages.h"
-
-namespace vadb {
-namespace usbip {
-
-// The device descriptor of a USB device represents a USB device that is
-// available for import.
-class Device {
- public:
- // AsyncTransferReadyCB specifies a signature of a function that will be
- // called upon transfer completion (whether successful or failed). Parameters
- // supplied to the function are:
- // - operation status, indicated by boolean flag (true = success),
- // - vector containing transferred data (and actual size).
- using AsyncTransferReadyCB = std::function<void(bool, std::vector<uint8_t>)>;
-
- // Interface provides minimal description of device's interface.
- struct Interface {
- uint8_t iface_class;
- uint8_t iface_subclass;
- uint8_t iface_protocol;
- };
-
- // vendor_id and product_id identify device manufacturer and type.
- // dev_version describes device version (as BCD).
- uint16_t vendor_id;
- uint16_t product_id;
- uint16_t dev_version;
-
- // Class, Subclass and Protocol define device type.
- uint8_t dev_class;
- uint8_t dev_subclass;
- uint8_t dev_protocol;
-
- // Speed indicates device speed (see libusb_speed).
- uint8_t speed;
-
- // ConfigurationsCount and ConfigurationNumber describe total number of device
- // configurations and currently activated device configuration.
- size_t configurations_count;
- size_t configuration_number;
-
- // Interfaces returns a collection of device interfaces.
- std::vector<Interface> interfaces;
-
- // Attach request handler.
- std::function<bool()> handle_attach;
-
- // Device control request dispatcher.
- std::function<bool(const CmdRequest& request, uint32_t deadline,
- std::vector<uint8_t> data, AsyncTransferReadyCB callback)>
- handle_control_transfer;
-
- // Device data request dispatcher.
- std::function<bool(uint8_t endpoint, bool is_host_to_device,
- uint32_t deadline, std::vector<uint8_t> data,
- AsyncTransferReadyCB callback)>
- handle_data_transfer;
-};
-
-} // namespace usbip
-} // namespace vadb
diff --git a/host/commands/virtual_usb_manager/usbip/device_pool.cpp b/host/commands/virtual_usb_manager/usbip/device_pool.cpp
deleted file mode 100644
index ecd3e8e..0000000
--- a/host/commands/virtual_usb_manager/usbip/device_pool.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "host/commands/virtual_usb_manager/usbip/device_pool.h"
-
-#include <glog/logging.h>
-
-namespace vadb {
-namespace usbip {
-
-void DevicePool::AddDevice(BusDevNumber bdn, std::unique_ptr<Device> device) {
- devices_[bdn] = std::move(device);
-}
-
-Device* DevicePool::GetDevice(BusDevNumber bus_id) const {
- auto iter = devices_.find(bus_id);
- if (iter == devices_.end()) return nullptr;
- return iter->second.get();
-}
-
-} // namespace usbip
-} // namespace vadb
diff --git a/host/commands/virtual_usb_manager/usbip/device_pool.h b/host/commands/virtual_usb_manager/usbip/device_pool.h
deleted file mode 100644
index f6988c4..0000000
--- a/host/commands/virtual_usb_manager/usbip/device_pool.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-
-#include <map>
-#include <string>
-
-#include "host/commands/virtual_usb_manager/usbip/device.h"
-
-namespace vadb {
-namespace usbip {
-// Container for all virtual USB/IP devices.
-// Stores devices by virtual BUS ID.
-class DevicePool {
- public:
- // BusDevNumber is a pair uniquely identifying bus and device.
- struct BusDevNumber {
- uint16_t bus_number;
- uint16_t dev_number;
-
- bool operator<(BusDevNumber other) const {
- return (bus_number << 16 | dev_number) <
- (other.bus_number << 16 | other.dev_number);
- }
- };
-
- // Internal container type.
- using MapType = std::map<BusDevNumber, std::unique_ptr<Device>>;
-
- DevicePool() = default;
- virtual ~DevicePool() = default;
-
- // Add new device associated with virtual BUS ID.
- void AddDevice(BusDevNumber bus_id, std::unique_ptr<Device> device);
-
- // Get device associated with supplied virtual bus/device number.
- Device* GetDevice(BusDevNumber bus_dev_num) const;
-
- // Get total number of USB/IP devices.
- size_t Size() const { return devices_.size(); }
-
- MapType::const_iterator begin() const { return devices_.cbegin(); }
- MapType::const_iterator end() const { return devices_.cend(); }
-
- private:
- MapType devices_;
-
- DevicePool(const DevicePool&) = delete;
- DevicePool& operator=(const DevicePool&) = delete;
-};
-
-} // namespace usbip
-} // namespace vadb
diff --git a/host/commands/virtual_usb_manager/usbip/messages.cpp b/host/commands/virtual_usb_manager/usbip/messages.cpp
deleted file mode 100644
index 9de7c26..0000000
--- a/host/commands/virtual_usb_manager/usbip/messages.cpp
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "host/commands/virtual_usb_manager/usbip/messages.h"
-
-#include <netinet/in.h>
-#include <iostream>
-
-#include <glog/logging.h>
-
-namespace vadb {
-namespace usbip {
-namespace {
-// Basic sanity checking.
-// We're using CmdHeader + CmdReq/Rep in case any of the fields is moved between
-// structures.
-constexpr int kUsbIpCmdLength = 48;
-
-static_assert(sizeof(CmdHeader) + sizeof(CmdReqSubmit) == kUsbIpCmdLength,
- "USB/IP command + header must be exactly 48 bytes.");
-static_assert(sizeof(CmdHeader) + sizeof(CmdRepSubmit) == kUsbIpCmdLength,
- "USB/IP command + header must be exactly 48 bytes.");
-static_assert(sizeof(CmdHeader) + sizeof(CmdReqUnlink) == kUsbIpCmdLength,
- "USB/IP command + header must be exactly 48 bytes.");
-static_assert(sizeof(CmdHeader) + sizeof(CmdRepUnlink) == kUsbIpCmdLength,
- "USB/IP command + header must be exactly 48 bytes.");
-} // namespace
-
-std::ostream& operator<<(std::ostream& out, const CmdHeader& header) {
- out << "CmdHeader\n";
- out << "\t\tcmd:\t" << header.command << '\n';
- out << "\t\tseq#:\t" << header.seq_num << '\n';
- out << "\t\tbus#:\t0x" << header.bus_num << '\n';
- out << "\t\tdev#:\t0x" << header.dev_num << '\n';
- out << "\t\tdir:\t" << (header.direction ? "in" : "out") << '\n';
- out << "\t\tendpt:\t" << header.endpoint << "\n";
- return out;
-}
-
-std::ostream& operator<<(std::ostream& out, const CmdRequest& setup) {
- out << "Request\n";
- out << "\t\t\ttype:\t" << std::hex << int(setup.type) << '\n';
- out << "\t\t\treq:\t" << int(setup.cmd) << std::dec << '\n';
- out << "\t\t\tval:\t" << setup.value << '\n';
- out << "\t\t\tidx:\t" << setup.index << '\n';
- out << "\t\t\tlen:\t" << setup.length << '\n';
- return out;
-}
-
-std::ostream& operator<<(std::ostream& out, const CmdReqSubmit& submit) {
- out << "CmdReqSubmit\n";
- out << "\t\ttr_flg:\t" << std::hex << submit.transfer_flags << std::dec
- << '\n';
- out << "\t\ttr_len:\t" << submit.transfer_buffer_length << '\n';
- out << "\t\tstart:\t" << submit.start_frame << '\n';
- out << "\t\tpktcnt:\t" << submit.number_of_packets << '\n';
- out << "\t\tttl:\t" << submit.deadline_interval << '\n';
- out << "\t\tsetup:\t" << submit.setup << '\n';
- return out;
-}
-
-std::ostream& operator<<(std::ostream& out, const CmdRepSubmit& submit) {
- out << "CmdRepSubmit\n";
- out << "\t\tstatus:\t" << submit.status << '\n';
- out << "\t\tlen:\t" << submit.actual_length << '\n';
- out << "\t\tstart:\t" << submit.start_frame << '\n';
- out << "\t\tpktcnt:\t" << submit.number_of_packets << '\n';
- out << "\t\terrors:\t" << submit.error_count << '\n';
- out << "\t\tsetup:\t" << submit.setup << '\n';
- return out;
-}
-
-std::ostream& operator<<(std::ostream& out, const CmdReqUnlink& unlink) {
- out << "CmdReqUnlink\n";
- out << "\t\tseq#:\t" << unlink.seq_num << '\n';
- return out;
-}
-
-std::ostream& operator<<(std::ostream& out, const CmdRepUnlink& unlink) {
- out << "CmdRepUnlink\n";
- out << "\t\tstatus:\t" << unlink.status << '\n';
- return out;
-}
-
-} // namespace usbip
-} // namespace vadb
diff --git a/host/commands/virtual_usb_manager/usbip/messages.h b/host/commands/virtual_usb_manager/usbip/messages.h
deleted file mode 100644
index 8594465..0000000
--- a/host/commands/virtual_usb_manager/usbip/messages.h
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-
-#include <glog/logging.h>
-#include <stdint.h>
-
-#include "common/libs/fs/shared_fd.h"
-
-// Requests and constants below are defined in kernel documentation file:
-// https://www.kernel.org/doc/Documentation/usb/usbip_protocol.txt
-namespace vadb {
-namespace usbip {
-
-////////////////////////////////////////////////////////////////////////////////
-// COMMANDS
-////////////////////////////////////////////////////////////////////////////////
-
-// Command numbers. Commands are valid only once USB device is attached.
-enum Command : uint32_t {
- kUsbIpCmdReqSubmit = 1, // Submit request
- kUsbIpCmdReqUnlink = 2, // Unlink request
- kUsbIpCmdRepSubmit = 3, // Submit response
- kUsbIpCmdRepUnlink = 4, // Unlink response
-};
-
-// Direction of data flow.
-enum Direction : uint32_t {
- kUsbIpDirectionOut = 0,
- kUsbIpDirectionIn = 1,
-};
-
-// Setup structure is explained in great detail here:
-// - http://www.beyondlogic.org/usbnutshell/usb6.shtml
-// - http://www.usbmadesimple.co.uk/ums_4.htm
-struct CmdRequest {
- uint8_t type;
- uint8_t cmd;
- uint16_t value;
- uint16_t index;
- uint16_t length;
-} __attribute__((packed));
-
-// CmdHeader precedes any command request or response body.
-struct CmdHeader {
- Command command;
- uint32_t seq_num;
- uint16_t bus_num;
- uint16_t dev_num;
- Direction direction;
- uint32_t endpoint; // valid values: 0-15
-} __attribute__((packed));
-
-// Command data for submitting an USB request.
-struct CmdReqSubmit {
- uint32_t transfer_flags;
- uint32_t transfer_buffer_length;
- uint32_t start_frame;
- uint32_t number_of_packets;
- uint32_t deadline_interval;
- CmdRequest setup;
-} __attribute__((packed));
-
-// Command response for submitting an USB request.
-struct CmdRepSubmit {
- uint32_t status; // 0 = success.
- uint32_t actual_length;
- uint32_t start_frame;
- uint32_t number_of_packets;
- uint32_t error_count;
- CmdRequest setup;
-} __attribute__((packed));
-
-// Unlink USB request.
-struct CmdReqUnlink {
- uint32_t seq_num;
- uint32_t reserved[6];
-} __attribute__((packed));
-
-// Unlink USB response.
-struct CmdRepUnlink {
- uint32_t status;
- uint32_t reserved[6];
-} __attribute__((packed));
-
-// Diagnostics.
-std::ostream& operator<<(std::ostream& out, const CmdHeader& header);
-std::ostream& operator<<(std::ostream& out, const CmdReqSubmit& data);
-std::ostream& operator<<(std::ostream& out, const CmdRepSubmit& data);
-std::ostream& operator<<(std::ostream& out, const CmdReqUnlink& data);
-std::ostream& operator<<(std::ostream& out, const CmdRepUnlink& data);
-
-} // namespace usbip
-} // namespace vadb
diff --git a/host/commands/virtual_usb_manager/usbip/server.cpp b/host/commands/virtual_usb_manager/usbip/server.cpp
deleted file mode 100644
index ef71b72..0000000
--- a/host/commands/virtual_usb_manager/usbip/server.cpp
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "host/commands/virtual_usb_manager/usbip/server.h"
-
-#include <glog/logging.h>
-#include <netinet/in.h>
-#include "common/libs/fs/shared_select.h"
-
-using cvd::SharedFD;
-
-namespace vadb {
-namespace usbip {
-Server::Server(const std::string& name, const DevicePool& devices)
- : name_{name}, device_pool_{devices} {}
-
-bool Server::Init() { return CreateServerSocket(); }
-
-// Open new listening server socket.
-// Returns false, if listening socket could not be created.
-bool Server::CreateServerSocket() {
- LOG(INFO) << "Starting server socket: " << name_;
-
- server_ = SharedFD::SocketLocalServer(name_.c_str(), true, SOCK_STREAM, 0700);
- if (!server_->IsOpen()) {
- LOG(ERROR) << "Could not create socket: " << server_->StrError();
- return false;
- }
- return true;
-}
-
-void Server::BeforeSelect(cvd::SharedFDSet* fd_read) const {
- fd_read->Set(server_);
- for (const auto& client : clients_) client.BeforeSelect(fd_read);
-}
-
-void Server::AfterSelect(const cvd::SharedFDSet& fd_read) {
- if (fd_read.IsSet(server_)) HandleIncomingConnection();
-
- for (auto iter = clients_.begin(); iter != clients_.end();) {
- if (!iter->AfterSelect(fd_read)) {
- // If client conversation failed, hang up.
- iter = clients_.erase(iter);
- continue;
- }
- ++iter;
- }
-}
-
-// Accept new USB/IP connection. Add it to client pool.
-void Server::HandleIncomingConnection() {
- SharedFD client = SharedFD::Accept(*server_, nullptr, nullptr);
- if (!client->IsOpen()) {
- LOG(ERROR) << "Client connection failed: " << client->StrError();
- return;
- }
-
- clients_.emplace_back(device_pool_, client);
-}
-} // namespace usbip
-} // namespace vadb
diff --git a/host/commands/virtual_usb_manager/usbip/server.h b/host/commands/virtual_usb_manager/usbip/server.h
deleted file mode 100644
index 5c574f7..0000000
--- a/host/commands/virtual_usb_manager/usbip/server.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-
-#include <list>
-#include <string>
-
-#include "common/libs/fs/shared_fd.h"
-#include "host/commands/virtual_usb_manager/usbip/client.h"
-#include "host/commands/virtual_usb_manager/usbip/device_pool.h"
-
-namespace vadb {
-namespace usbip {
-
-class Server final {
- public:
- Server(const std::string& name, const DevicePool& device_pool);
- ~Server() = default;
-
- // Initialize this instance of Server.
- // Returns true, if initialization was successful.
- bool Init();
-
- // BeforeSelect is Called right before Select() to populate interesting
- // SharedFDs.
- void BeforeSelect(cvd::SharedFDSet* fd_read) const;
-
- // AfterSelect is Called right after Select() to detect and respond to changes
- // on affected SharedFDs.
- void AfterSelect(const cvd::SharedFDSet& fd_read);
-
- private:
- // Create USBIP server socket.
- // Returns true, if socket was successfully created.
- bool CreateServerSocket();
-
- // Handle new client connection.
- // New clients will be appended to clients_ list.
- void HandleIncomingConnection();
-
- std::string name_;
- cvd::SharedFD server_;
- std::list<Client> clients_;
-
- const DevicePool& device_pool_;
-
- Server(const Server&) = delete;
- Server& operator=(const Server&) = delete;
-};
-
-} // namespace usbip
-} // namespace vadb
diff --git a/host/commands/virtual_usb_manager/usbip/vhci_instrument.cpp b/host/commands/virtual_usb_manager/usbip/vhci_instrument.cpp
deleted file mode 100644
index 9df09ad..0000000
--- a/host/commands/virtual_usb_manager/usbip/vhci_instrument.cpp
+++ /dev/null
@@ -1,262 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <errno.h>
-#include <string.h>
-
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <sys/socket.h>
-
-#include <glog/logging.h>
-#include <fstream>
-#include <limits>
-#include <sstream>
-#include "common/libs/fs/shared_select.h"
-
-#include "common/libs/fs/shared_fd.h"
-#include "host/commands/virtual_usb_manager/usbip/vhci_instrument.h"
-
-namespace vadb {
-namespace usbip {
-namespace {
-// Device ID is specified as a concatenated pair of BUS and DEVICE id.
-// Since we only export one device and our server doesn't care much about
-// its number, we use the default value of BUS=1 and DEVICE=1.
-// This can be set to something else and should still work, as long as
-// numbers are valid in USB sense.
-constexpr uint32_t kDefaultDeviceID = (1 << 16) | 1;
-
-// Request Highspeed configuration. Superspeed isn't supported by vhci.
-// Supported configurations are:
-// 4 -> wireless
-// 3 -> highspeed
-// 2 -> full speed
-// 1 -> low speed
-// Please refer to the Kernel source tree in the following locations:
-// include/uapi/linux/usb/ch9.h
-// drivers/usb/usbip/vhci_sysfs.c
-constexpr uint32_t kDefaultDeviceSpeed = 3;
-
-// Subsystem and device type where VHCI driver is located.
-const char* const kVHCIPlatformPaths[] = {
- "/sys/devices/platform/vhci_hcd",
- "/sys/devices/platform/vhci_hcd.1",
-};
-
-// Control messages.
-// Attach tells thread to attach remote device.
-// Detach tells thread to detach remote device.
-using ControlMsgType = uint8_t;
-constexpr ControlMsgType kControlAttach = 'A';
-constexpr ControlMsgType kControlDetach = 'D';
-constexpr ControlMsgType kControlExit = 'E';
-
-// Used with EPOLL as epoll_data to determine event type.
-enum EpollEventType {
- kControlEvent,
- kVHCIEvent,
-};
-
-} // anonymous namespace
-
-VHCIInstrument::VHCIInstrument(int port, const std::string& name)
- : name_(name), port_{port} {}
-
-VHCIInstrument::~VHCIInstrument() {
- control_write_end_->Write(&kControlExit, sizeof(kControlExit));
- attach_thread_.join();
-}
-
-bool VHCIInstrument::Init() {
- cvd::SharedFD::Pipe(&control_read_end_, &control_write_end_);
-
- struct stat buf;
- for (const auto* path : kVHCIPlatformPaths) {
- if (stat(path, &buf) == 0) {
- syspath_ = path;
- break;
- }
- }
-
- if (syspath_.empty()) {
- LOG(ERROR) << "VHCI not available. Is the driver loaded?";
- LOG(ERROR) << "Try: sudo modprobe vhci_hcd";
- LOG(ERROR) << "The driver is part of linux-image-extra-`uname -r` package";
- return false;
- }
-
- if (!VerifyPortIsFree()) {
- LOG(ERROR) << "Trying to use VHCI port " << port_ << " but it is already in"
- << " use.";
- return false;
- }
-
- LOG(INFO) << "Using VHCI port " << port_;
- attach_thread_ = std::thread([this] { AttachThread(); });
- return true;
-}
-
-bool VHCIInstrument::VerifyPortIsFree() const {
- std::ifstream status_file(syspath_ + "/status");
-
- if (!status_file.good()) {
- LOG(ERROR) << "Could not open usb-ip status file.";
- return false;
- }
-
- // Skip past the header line.
- status_file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
-
- while (true) {
- // Port status values deducted from /sys/devices/platform/vhci_hcd/status
- // kVHCIPortFree indicates the port is not currently in use.
- constexpr static int kVHCIStatusPortFree = 4;
-
- int port{};
- int status{};
- status_file >> port >> status;
- if (!status_file.good()) {
- break;
- }
-
- status_file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
- if (port_ == port) {
- return status == kVHCIStatusPortFree;
- }
- }
- LOG(ERROR) << "Couldn't find status for VHCI port " << port_;
- return false;
-}
-
-void VHCIInstrument::TriggerAttach() {
- control_write_end_->Write(&kControlAttach, sizeof(kControlAttach));
-}
-
-void VHCIInstrument::TriggerDetach() {
- control_write_end_->Write(&kControlDetach, sizeof(kControlDetach));
-}
-
-void VHCIInstrument::AttachThread() {
- cvd::SharedFD epoll = cvd::SharedFD::Epoll();
- // Trigger attach upon start.
- bool want_attach = true;
- // Operation is pending on read.
- bool is_pending = false;
-
- epoll_event control_event;
- control_event.events = EPOLLIN;
- control_event.data.u64 = kControlEvent;
- epoll_event vhci_event;
- vhci_event.events = EPOLLRDHUP | EPOLLONESHOT;
- vhci_event.data.u64 = kVHCIEvent;
-
- epoll->EpollCtl(EPOLL_CTL_ADD, control_read_end_, &control_event);
- while (true) {
- if (vhci_socket_->IsOpen()) {
- epoll->EpollCtl(EPOLL_CTL_ADD, vhci_socket_, &vhci_event);
- }
-
- epoll_event found_event{};
- ControlMsgType request_type;
-
- if (epoll->EpollWait(&found_event, 1, 1000)) {
- switch (found_event.data.u64) {
- case kControlEvent:
- control_read_end_->Read(&request_type, sizeof(request_type));
- is_pending = true;
- want_attach = request_type == kControlAttach;
- LOG(INFO) << (want_attach ? "Attach" : "Detach") << " triggered.";
- break;
- case kVHCIEvent:
- vhci_socket_ = cvd::SharedFD();
- // Only re-establish VHCI if it was already established before.
- is_pending = want_attach;
- // Do not immediately fall into attach cycle. It will likely complete
- // before VHCI finishes deregistering this callback.
- continue;
- }
- }
-
- // Make an attempt to re-attach. If successful, clear pending attach flag.
- if (is_pending) {
- if (want_attach && Attach()) {
- is_pending = false;
- } else if (!want_attach && Detach()) {
- is_pending = false;
- } else {
- LOG(INFO) << (want_attach ? "Attach" : "Detach") << " unsuccessful. "
- << "Will re-try.";
- sleep(1);
- }
- }
- }
-}
-
-bool VHCIInstrument::Detach() {
- std::stringstream result;
- result << port_;
- std::ofstream detach(syspath_ + "/detach");
-
- if (!detach.is_open()) {
- LOG(WARNING) << "Could not open VHCI detach file.";
- return false;
- }
- detach << result.str();
- return detach.rdstate() == std::ios_base::goodbit;
-}
-
-bool VHCIInstrument::Attach() {
- if (!vhci_socket_->IsOpen()) {
- vhci_socket_ =
- cvd::SharedFD::SocketLocalClient(name_.c_str(), true, SOCK_STREAM);
- if (!vhci_socket_->IsOpen()) return false;
- }
-
- int sys_fd = vhci_socket_->UNMANAGED_Dup();
- bool success = false;
-
- {
- std::stringstream result;
- result << port_ << ' ' << sys_fd << ' ' << kDefaultDeviceID << ' '
- << kDefaultDeviceSpeed;
- std::string path = syspath_ + "/attach";
- std::ofstream attach(path);
-
- if (!attach.is_open()) {
- LOG(WARNING) << "Could not open VHCI attach file " << path << " ("
- << strerror(errno) << ")";
- close(sys_fd);
- return false;
- }
- attach << result.str();
-
- // It is unclear whether duplicate FD should remain open or not. There are
- // cases supporting both assumptions, likely related to kernel version.
- // Kernel 4.10 is having problems communicating with USB/IP server if the
- // socket is closed after it's passed to kernel. It is a clear indication
- // that the kernel requires the socket to be kept open.
- success = attach.rdstate() == std::ios_base::goodbit;
- // Make sure everything was written and flushed. This happens when we close
- // the ofstream attach.
- }
-
- close(sys_fd);
- return success;
-}
-
-} // namespace usbip
-} // namespace vadb
diff --git a/host/commands/virtual_usb_manager/usbip/vhci_instrument.h b/host/commands/virtual_usb_manager/usbip/vhci_instrument.h
deleted file mode 100644
index aa2f5d4..0000000
--- a/host/commands/virtual_usb_manager/usbip/vhci_instrument.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-
-#include <memory>
-#include <string>
-#include <thread>
-
-#include "common/libs/fs/shared_fd.h"
-
-namespace vadb {
-namespace usbip {
-// VHCIInstrument class configures VHCI-HCD on local kernel.
-class VHCIInstrument {
- public:
- VHCIInstrument(int port, const std::string& name);
- virtual ~VHCIInstrument();
-
- // Init opens vhci-hcd driver and allocates port to which remote USB device
- // will be attached.
- // Returns false, if vhci-hcd driver could not be opened, or if no free port
- // was found.
- bool Init();
-
- // TriggerAttach tells underlying thread to make attempt to re-attach USB
- // device.
- void TriggerAttach();
-
- // TriggerDetach tells underlying thread to disconnect remote USB device.
- void TriggerDetach();
-
- private:
- // Attach makes an attempt to configure VHCI to enable virtual USB device.
- // Returns true, if configuration attempt was successful.
- bool Attach();
-
- // Detach disconnects virtual USB device.
- // Returns true, if attempt was successful.
- bool Detach();
-
- // AttachThread is a background thread that responds to configuration
- // requests.
- void AttachThread();
- bool VerifyPortIsFree() const;
-
- private:
- std::string name_;
- std::thread attach_thread_;
- std::string syspath_;
- cvd::SharedFD control_write_end_;
- cvd::SharedFD control_read_end_;
- cvd::SharedFD vhci_socket_;
- int port_{};
-
- VHCIInstrument(const VHCIInstrument& other) = delete;
- VHCIInstrument& operator=(const VHCIInstrument& other) = delete;
-};
-} // namespace usbip
-} // namespace vadb
diff --git a/host/commands/virtual_usb_manager/vadb/usb_cmd.h b/host/commands/virtual_usb_manager/vadb/usb_cmd.h
deleted file mode 100644
index 7039fbe..0000000
--- a/host/commands/virtual_usb_manager/vadb/usb_cmd.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-
-#include "common/libs/fs/shared_fd.h"
-#include "common/libs/usbforward/protocol.h"
-
-namespace vadb {
-// USBCommand is an abstraction of a proxied USB command.
-// Instances of this object all share the following life cycle:
-// 1) A specific instance (COMMAND) is being created.
-// 2) Instance owner (OWNER) sends RequestHeader.
-// 3) OWNER calls COMMAND.OnRequest() to send any relevant, additional
-// information.
-// 4) OWNER queues COMMAND until response arrives.
-//
-// At this point instance owner can process next command in queue. Then,
-// eventually:
-//
-// 5) OWNER receives matching ResponseHeader.
-// 6) OWNER calls COMMAND.OnResponse(), supplying FD that carries additional
-// data.
-// 7) OWNER dequeues and deletes COMMAND.
-class USBCommand {
- public:
- USBCommand() = default;
- virtual ~USBCommand() = default;
-
- // Command returns a specific usbforward command ID associated with this
- // request.
- virtual usb_forward::Command Command() = 0;
-
- // OnRequest is called whenever additional data relevant to this command
- // (other than RequestHeader) should be sent.
- // Returns false, if communication with remote host failed (and should be
- // terminated).
- virtual bool OnRequest(const cvd::SharedFD& data) = 0;
-
- // OnResponse is called whenever additional data relevant to this command
- // (other than ResponseHeader) should be received.
- // Returns false, if communication with remote host failed (and should be
- // terminated).
- virtual bool OnResponse(bool is_success, const cvd::SharedFD& data) = 0;
-
- private:
- USBCommand(const USBCommand& other) = delete;
- USBCommand& operator=(const USBCommand& other) = delete;
-};
-
-} // namespace vadb
diff --git a/host/commands/virtual_usb_manager/vadb/usb_cmd_attach.cpp b/host/commands/virtual_usb_manager/vadb/usb_cmd_attach.cpp
deleted file mode 100644
index 8418236..0000000
--- a/host/commands/virtual_usb_manager/vadb/usb_cmd_attach.cpp
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include <glog/logging.h>
-
-#include "common/libs/usbforward/protocol.h"
-#include "host/commands/virtual_usb_manager/vadb/usb_cmd_attach.h"
-
-namespace vadb {
-bool USBCmdAttach::OnRequest(const cvd::SharedFD& fd) {
- if (fd->Write(&req_, sizeof(req_)) != sizeof(req_)) {
- LOG(ERROR) << "Short write: " << fd->StrError();
- return false;
- }
- return true;
-}
-
-bool USBCmdAttach::OnResponse(bool is_success, const cvd::SharedFD& /*data*/) {
- if (!is_success) return false;
- LOG(INFO) << "Attach successful.";
- return true;
-}
-
-USBCmdAttach::USBCmdAttach(uint8_t bus_id, uint8_t dev_id) {
- req_.bus_id = bus_id;
- req_.dev_id = dev_id;
-}
-} // namespace vadb
diff --git a/host/commands/virtual_usb_manager/vadb/usb_cmd_attach.h b/host/commands/virtual_usb_manager/vadb/usb_cmd_attach.h
deleted file mode 100644
index 368deca..0000000
--- a/host/commands/virtual_usb_manager/vadb/usb_cmd_attach.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-
-#include "host/commands/virtual_usb_manager/vadb/usb_cmd.h"
-
-namespace vadb {
-// Request remote device attach (~open).
-class USBCmdAttach : public USBCommand {
- public:
- USBCmdAttach(uint8_t bus_id, uint8_t dev_id);
- ~USBCmdAttach() override = default;
-
- // Return usbforward command this instance is executing.
- usb_forward::Command Command() override { return usb_forward::CmdAttach; }
-
- // Send request body to the server.
- // Return false, if communication failed.
- bool OnRequest(const cvd::SharedFD& data) override;
-
- // Receive response data from the server.
- // Return false, if communication failed.
- bool OnResponse(bool is_success, const cvd::SharedFD& data) override;
-
- private:
- usb_forward::AttachRequest req_;
-
- USBCmdAttach(const USBCmdAttach& other) = delete;
- USBCmdAttach& operator=(const USBCmdAttach& other) = delete;
-};
-} // namespace vadb
diff --git a/host/commands/virtual_usb_manager/vadb/usb_cmd_control_transfer.cpp b/host/commands/virtual_usb_manager/vadb/usb_cmd_control_transfer.cpp
deleted file mode 100644
index 16fec69..0000000
--- a/host/commands/virtual_usb_manager/vadb/usb_cmd_control_transfer.cpp
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include <glog/logging.h>
-
-#include "host/commands/virtual_usb_manager/vadb/usb_cmd_control_transfer.h"
-
-namespace vadb {
-USBCmdControlTransfer::USBCmdControlTransfer(
- uint8_t bus_id, uint8_t dev_id, uint8_t type, uint8_t request,
- uint16_t value, uint16_t index, uint32_t timeout, std::vector<uint8_t> data,
- usbip::Device::AsyncTransferReadyCB callback)
- : data_(std::move(data)), callback_(std::move(callback)) {
- req_.bus_id = bus_id;
- req_.dev_id = dev_id;
- req_.type = type;
- req_.cmd = request;
- req_.value = value;
- req_.index = index;
- req_.length = data_.size();
- req_.timeout = timeout;
-}
-
-bool USBCmdControlTransfer::OnRequest(const cvd::SharedFD& fd) {
- if (fd->Write(&req_, sizeof(req_)) != sizeof(req_)) {
- LOG(ERROR) << "Short write: " << fd->StrError();
- return false;
- }
-
- if ((req_.type & 0x80) == 0) {
- if (data_.size() > 0) {
- if (static_cast<size_t>(fd->Write(data_.data(), data_.size())) !=
- data_.size()) {
- LOG(ERROR) << "Short write: " << fd->StrError();
- return false;
- }
- }
- }
-
- return true;
-}
-
-bool USBCmdControlTransfer::OnResponse(bool is_success,
- const cvd::SharedFD& fd) {
- if (!is_success) {
- callback_(false, std::move(data_));
- return true;
- }
-
- if (req_.type & 0x80) {
- int32_t len;
- if (fd->Read(&len, sizeof(len)) != sizeof(len)) {
- LOG(ERROR) << "Short read: " << fd->StrError();
- callback_(false, std::move(data_));
- return false;
- }
-
- if (len > 0) {
- data_.resize(len);
- if (fd->Read(data_.data(), len) != len) {
- LOG(ERROR) << "Short read: " << fd->StrError();
- callback_(false, std::move(data_));
- return false;
- }
- }
- }
-
- callback_(true, std::move(data_));
- return true;
-}
-} // namespace vadb
diff --git a/host/commands/virtual_usb_manager/vadb/usb_cmd_control_transfer.h b/host/commands/virtual_usb_manager/vadb/usb_cmd_control_transfer.h
deleted file mode 100644
index 08aa159..0000000
--- a/host/commands/virtual_usb_manager/vadb/usb_cmd_control_transfer.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-
-#include <memory>
-
-#include <stdint.h>
-
-#include "common/libs/usbforward/protocol.h"
-#include "host/commands/virtual_usb_manager/vadb/usb_cmd.h"
-#include "host/commands/virtual_usb_manager/usbip/device.h"
-
-namespace vadb {
-// Execute control transfer.
-class USBCmdControlTransfer : public USBCommand {
- public:
- USBCmdControlTransfer(uint8_t bus_id, uint8_t dev_id, uint8_t type,
- uint8_t request, uint16_t value, uint16_t index,
- uint32_t timeout, std::vector<uint8_t> data,
- usbip::Device::AsyncTransferReadyCB callback);
-
- ~USBCmdControlTransfer() override = default;
-
- // Return usbforward command this instance is executing.
- usb_forward::Command Command() override {
- return usb_forward::CmdControlTransfer;
- }
-
- // Send request body to the server.
- // Return false, if communication failed.
- bool OnRequest(const cvd::SharedFD& data) override;
-
- // Receive response data from the server.
- // Return false, if communication failed.
- bool OnResponse(bool is_success, const cvd::SharedFD& data) override;
-
- private:
- usb_forward::ControlTransfer req_;
- std::vector<uint8_t> data_;
- usbip::Device::AsyncTransferReadyCB callback_;
-
- USBCmdControlTransfer(const USBCmdControlTransfer& other) = delete;
- USBCmdControlTransfer& operator=(const USBCmdControlTransfer& other) = delete;
-};
-} // namespace vadb
diff --git a/host/commands/virtual_usb_manager/vadb/usb_cmd_data_transfer.cpp b/host/commands/virtual_usb_manager/vadb/usb_cmd_data_transfer.cpp
deleted file mode 100644
index 8de468f..0000000
--- a/host/commands/virtual_usb_manager/vadb/usb_cmd_data_transfer.cpp
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include <glog/logging.h>
-
-#include "host/commands/virtual_usb_manager/vadb/usb_cmd_data_transfer.h"
-
-namespace vadb {
-USBCmdDataTransfer::USBCmdDataTransfer(
- uint8_t bus_id, uint8_t dev_id, uint8_t endpoint, bool is_host_to_device,
- uint32_t deadline, std::vector<uint8_t> data,
- usbip::Device::AsyncTransferReadyCB callback)
- : data_(std::move(data)), callback_(std::move(callback)) {
- req_.bus_id = bus_id;
- req_.dev_id = dev_id;
- req_.endpoint_id = endpoint;
- req_.is_host_to_device = is_host_to_device;
- req_.length = data_.size();
- req_.timeout = deadline;
-}
-
-bool USBCmdDataTransfer::OnRequest(const cvd::SharedFD& fd) {
- if (fd->Write(&req_, sizeof(req_)) != sizeof(req_)) {
- LOG(ERROR) << "Short write: " << fd->StrError();
- return false;
- }
-
- if (req_.is_host_to_device && data_.size() > 0) {
- if (static_cast<size_t>(fd->Write(data_.data(), data_.size())) !=
- data_.size()) {
- LOG(ERROR) << "Short write: " << fd->StrError();
- return false;
- }
- }
-
- return true;
-}
-
-bool USBCmdDataTransfer::OnResponse(bool is_success, const cvd::SharedFD& fd) {
- if (!is_success) {
- callback_(false, std::move(data_));
- return true;
- }
-
- if (!req_.is_host_to_device) {
- int32_t len;
- if (fd->Read(&len, sizeof(len)) != sizeof(len)) {
- LOG(ERROR) << "Short read: " << fd->StrError();
- callback_(false, std::move(data_));
- return false;
- }
-
- if (len > 0) {
- data_.resize(len);
- int32_t got = 0;
- // Virtio sends data in 32k packets. We may have to do a few reads.
- while (got < len) {
- auto packetsize = fd->Read(&data_[got], len - got);
- got += packetsize;
-
- if (fd->GetErrno() != 0) {
- // This could, technically, also be a disconnect.
- LOG(ERROR) << "Read failed: " << fd->StrError();
- return false;
- } else if (packetsize == 0) {
- LOG(ERROR) << "Short read; remote end disconnected.";
- return false;
- }
- }
- }
- }
-
- callback_(true, std::move(data_));
- return true;
-}
-} // namespace vadb
diff --git a/host/commands/virtual_usb_manager/vadb/usb_cmd_data_transfer.h b/host/commands/virtual_usb_manager/vadb/usb_cmd_data_transfer.h
deleted file mode 100644
index 3c4b64f..0000000
--- a/host/commands/virtual_usb_manager/vadb/usb_cmd_data_transfer.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-
-#include <memory>
-#include <stdint.h>
-
-#include "common/libs/usbforward/protocol.h"
-#include "host/commands/virtual_usb_manager/vadb/usb_cmd.h"
-#include "host/commands/virtual_usb_manager/usbip/device.h"
-
-namespace vadb {
-// Execute control transfer.
-class USBCmdDataTransfer : public USBCommand {
- public:
- USBCmdDataTransfer(uint8_t bus_id, uint8_t dev_id, uint8_t endpoint,
- bool is_host_to_device, uint32_t timeout,
- std::vector<uint8_t> data,
- usbip::Device::AsyncTransferReadyCB callback);
-
- ~USBCmdDataTransfer() override = default;
-
- // Return usbforward command this instance is executing.
- usb_forward::Command Command() override {
- return usb_forward::CmdDataTransfer;
- }
-
- // Send request body to the server.
- // Return false, if communication failed.
- bool OnRequest(const cvd::SharedFD& data) override;
-
- // Receive response data from the server.
- // Return false, if communication failed.
- bool OnResponse(bool is_success, const cvd::SharedFD& data) override;
-
- private:
- usb_forward::DataTransfer req_;
- std::vector<uint8_t> data_;
- usbip::Device::AsyncTransferReadyCB callback_;
-
- USBCmdDataTransfer(const USBCmdDataTransfer& other) = delete;
- USBCmdDataTransfer& operator=(const USBCmdDataTransfer& other) = delete;
-};
-} // namespace vadb
diff --git a/host/commands/virtual_usb_manager/vadb/usb_cmd_device_list.cpp b/host/commands/virtual_usb_manager/vadb/usb_cmd_device_list.cpp
deleted file mode 100644
index b74efdd..0000000
--- a/host/commands/virtual_usb_manager/vadb/usb_cmd_device_list.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include <glog/logging.h>
-
-#include "host/commands/virtual_usb_manager/vadb/usb_cmd_device_list.h"
-
-namespace vadb {
-bool USBCmdDeviceList::OnRequest(const cvd::SharedFD& /*data*/) {
- LOG(INFO) << "Requesting device list from Cuttlefish...";
- // No action required.
- return true;
-}
-
-bool USBCmdDeviceList::OnResponse(bool is_success, const cvd::SharedFD& fd) {
- // This should never happen. If this command fails, something is very wrong.
- if (!is_success) return false;
-
- int32_t count;
- if (fd->Read(&count, sizeof(count)) != sizeof(count)) {
- LOG(ERROR) << "Short read: " << fd->StrError();
- return false;
- }
-
- LOG(INFO) << "Device list completed with " << count << " devices.";
-
- while (count-- > 0) {
- usb_forward::DeviceInfo dev;
- std::vector<usb_forward::InterfaceInfo> ifaces;
-
- if (fd->Read(&dev, sizeof(dev)) != sizeof(dev)) {
- LOG(ERROR) << "Short read: " << fd->StrError();
- return false;
- }
-
- ifaces.resize(dev.num_interfaces);
- if (static_cast<size_t>(
- fd->Read(ifaces.data(),
- ifaces.size() * sizeof(usb_forward::InterfaceInfo))) !=
- ifaces.size() * sizeof(usb_forward::InterfaceInfo)) {
- LOG(ERROR) << "Short read: " << fd->StrError();
- return false;
- }
-
- LOG(INFO) << "Found remote device 0x" << std::hex << dev.vendor_id << ":"
- << dev.product_id;
-
- on_device_discovered_(dev, ifaces);
- }
-
- return true;
-}
-} // namespace vadb
diff --git a/host/commands/virtual_usb_manager/vadb/usb_cmd_device_list.h b/host/commands/virtual_usb_manager/vadb/usb_cmd_device_list.h
deleted file mode 100644
index 4d9ebbc..0000000
--- a/host/commands/virtual_usb_manager/vadb/usb_cmd_device_list.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-
-#include <functional>
-#include <vector>
-#include "common/libs/usbforward/protocol.h"
-#include "host/commands/virtual_usb_manager/vadb/usb_cmd.h"
-
-namespace vadb {
-// Request device list from remote host.
-class USBCmdDeviceList : public USBCommand {
- public:
- // DeviceDiscoveredCB is a callback function invoked for every new discovered
- // device.
- using DeviceDiscoveredCB =
- std::function<void(const usb_forward::DeviceInfo&,
- const std::vector<usb_forward::InterfaceInfo>&)>;
-
- USBCmdDeviceList(DeviceDiscoveredCB cb)
- : on_device_discovered_(std::move(cb)) {}
-
- ~USBCmdDeviceList() override = default;
-
- // Return usbforward command this instance is executing.
- usb_forward::Command Command() override { return usb_forward::CmdDeviceList; }
-
- // Send request body to the server.
- // Return false, if communication failed.
- bool OnRequest(const cvd::SharedFD& data) override;
-
- // Receive response data from the server.
- // Return false, if communication failed.
- bool OnResponse(bool is_success, const cvd::SharedFD& data) override;
-
- private:
- DeviceDiscoveredCB on_device_discovered_;
- USBCmdDeviceList(const USBCmdDeviceList& other) = delete;
- USBCmdDeviceList& operator=(const USBCmdDeviceList& other) = delete;
-};
-} // namespace vadb
diff --git a/host/commands/virtual_usb_manager/vadb/usb_cmd_heartbeat.cpp b/host/commands/virtual_usb_manager/vadb/usb_cmd_heartbeat.cpp
deleted file mode 100644
index cc80caa..0000000
--- a/host/commands/virtual_usb_manager/vadb/usb_cmd_heartbeat.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include <glog/logging.h>
-
-#include "common/libs/usbforward/protocol.h"
-#include "host/commands/virtual_usb_manager/vadb/usb_cmd_heartbeat.h"
-
-namespace vadb {
-bool USBCmdHeartbeat::OnRequest(const cvd::SharedFD& /*fd*/) { return true; }
-
-bool USBCmdHeartbeat::OnResponse(bool is_success,
- const cvd::SharedFD& /*data*/) {
- callback_(is_success);
- return true;
-}
-
-USBCmdHeartbeat::USBCmdHeartbeat(USBCmdHeartbeat::HeartbeatResultCB callback)
- : callback_(callback) {}
-} // namespace vadb
diff --git a/host/commands/virtual_usb_manager/vadb/usb_cmd_heartbeat.h b/host/commands/virtual_usb_manager/vadb/usb_cmd_heartbeat.h
deleted file mode 100644
index 552165b..0000000
--- a/host/commands/virtual_usb_manager/vadb/usb_cmd_heartbeat.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-
-#include "host/commands/virtual_usb_manager/vadb/usb_cmd.h"
-
-namespace vadb {
-// Request remote device attach (~open).
-class USBCmdHeartbeat : public USBCommand {
- public:
- // Heartbeat result callback receives a boolean argument indicating whether
- // remote device is ready to be attached.
- using HeartbeatResultCB = std::function<void(bool)>;
-
- USBCmdHeartbeat(HeartbeatResultCB callback);
- ~USBCmdHeartbeat() override = default;
-
- // Return usbforward command this instance is executing.
- usb_forward::Command Command() override { return usb_forward::CmdHeartbeat; }
-
- // Send request body to the server.
- // Return false, if communication failed.
- bool OnRequest(const cvd::SharedFD& data) override;
-
- // Receive response data from the server.
- // Return false, if communication failed.
- bool OnResponse(bool is_success, const cvd::SharedFD& data) override;
-
- private:
- HeartbeatResultCB callback_;
-
- USBCmdHeartbeat(const USBCmdHeartbeat& other) = delete;
- USBCmdHeartbeat& operator=(const USBCmdHeartbeat& other) = delete;
-};
-} // namespace vadb
diff --git a/host/commands/virtual_usb_manager/vadb/virtual_adb_client.cpp b/host/commands/virtual_usb_manager/vadb/virtual_adb_client.cpp
deleted file mode 100644
index 34ee5b4..0000000
--- a/host/commands/virtual_usb_manager/vadb/virtual_adb_client.cpp
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include <algorithm>
-#include <memory>
-#include <gflags/gflags.h>
-
-#include "common/libs/fs/shared_select.h"
-#include "host/commands/virtual_usb_manager/vadb/usb_cmd_attach.h"
-#include "host/commands/virtual_usb_manager/vadb/usb_cmd_control_transfer.h"
-#include "host/commands/virtual_usb_manager/vadb/usb_cmd_data_transfer.h"
-#include "host/commands/virtual_usb_manager/vadb/usb_cmd_device_list.h"
-#include "host/commands/virtual_usb_manager/vadb/usb_cmd_heartbeat.h"
-#include "host/commands/virtual_usb_manager/vadb/virtual_adb_client.h"
-
-DEFINE_bool(debug_adb_client, false, "Turn on verbose logging in the virtual_adb_client.cpp");
-
-#define VLOG(X) if (FLAGS_debug_adb_client) LOG(VERBOSE)
-
-namespace vadb {
-namespace {
-constexpr int kHeartbeatTimeoutSeconds = 3;
-} // namespace
-
-VirtualADBClient::VirtualADBClient(usbip::DevicePool* pool, cvd::SharedFD fd,
- int vhci_port,
- const std::string& usbip_socket_name)
- : pool_{pool}, fd_{fd}, vhci_{vhci_port, usbip_socket_name} {
- CHECK(vhci_.Init());
- timer_ = cvd::SharedFD::TimerFD(CLOCK_MONOTONIC, 0);
- SendHeartbeat();
-}
-
-void VirtualADBClient::RegisterDevice(
- const usb_forward::DeviceInfo& dev,
- const std::vector<usb_forward::InterfaceInfo>& ifaces) {
- auto d = std::unique_ptr<usbip::Device>(new usbip::Device);
- d->vendor_id = dev.vendor_id;
- d->product_id = dev.product_id;
- d->dev_version = dev.dev_version;
- d->dev_class = dev.dev_class;
- d->dev_subclass = dev.dev_subclass;
- d->dev_protocol = dev.dev_protocol;
- d->speed = dev.speed;
- d->configurations_count = dev.num_configurations;
- d->configuration_number = dev.cur_configuration;
-
- for (const auto& iface : ifaces) {
- d->interfaces.push_back(usbip::Device::Interface{
- iface.if_class, iface.if_subclass, iface.if_protocol});
- }
-
- uint8_t bus_id = dev.bus_id;
- uint8_t dev_id = dev.dev_id;
-
- d->handle_attach = [this, bus_id, dev_id]() -> bool {
- return HandleAttach(bus_id, dev_id);
- };
-
- d->handle_control_transfer =
- [this, bus_id, dev_id](
- const usbip::CmdRequest& r, uint32_t deadline,
- std::vector<uint8_t> data,
- usbip::Device::AsyncTransferReadyCB callback) -> bool {
- return HandleDeviceControlRequest(bus_id, dev_id, r, deadline,
- std::move(data), std::move(callback));
- };
-
- d->handle_data_transfer =
- [this, bus_id, dev_id](
- uint8_t endpoint, bool is_host_to_device, uint32_t deadline,
- std::vector<uint8_t> data,
- usbip::Device::AsyncTransferReadyCB callback) -> bool {
- return HandleDeviceDataRequest(bus_id, dev_id, endpoint, is_host_to_device,
- deadline, std::move(data),
- std::move(callback));
- };
-
- pool_->AddDevice(usbip::DevicePool::BusDevNumber{bus_id, dev_id},
- std::move(d));
-
- // Attach this device.
- HandleAttach(bus_id, dev_id);
-}
-
-bool VirtualADBClient::PopulateRemoteDevices() {
- return ExecuteCommand(std::unique_ptr<USBCommand>(new USBCmdDeviceList(
- [this](const usb_forward::DeviceInfo& info,
- const std::vector<usb_forward::InterfaceInfo>& ifaces) {
- RegisterDevice(info, ifaces);
- })));
-}
-
-bool VirtualADBClient::HandleDeviceControlRequest(
- uint8_t bus_id, uint8_t dev_id, const usbip::CmdRequest& r,
- uint32_t timeout, std::vector<uint8_t> data,
- usbip::Device::AsyncTransferReadyCB callback) {
- return ExecuteCommand(std::unique_ptr<USBCommand>(new USBCmdControlTransfer(
- bus_id, dev_id, r.type, r.cmd, r.value, r.index, timeout, std::move(data),
- std::move(callback))));
-}
-
-bool VirtualADBClient::HandleDeviceDataRequest(
- uint8_t bus_id, uint8_t dev_id, uint8_t endpoint, bool is_host_to_device,
- uint32_t deadline, std::vector<uint8_t> data,
- usbip::Device::AsyncTransferReadyCB callback) {
- return ExecuteCommand(std::unique_ptr<USBCommand>(
- new USBCmdDataTransfer(bus_id, dev_id, endpoint, is_host_to_device,
- deadline, std::move(data), std::move(callback))));
-}
-
-bool VirtualADBClient::HandleAttach(uint8_t bus_id, uint8_t dev_id) {
- return ExecuteCommand(
- std::unique_ptr<USBCommand>(new USBCmdAttach(bus_id, dev_id)));
-}
-
-bool VirtualADBClient::SendHeartbeat() {
- VLOG(1) << "Sending heartbeat...";
- struct itimerspec spec {};
- spec.it_value.tv_sec = kHeartbeatTimeoutSeconds;
- timer_->TimerSet(0, &spec, nullptr);
-
- heartbeat_tag_ = tag_;
-
- return ExecuteCommand(std::unique_ptr<USBCommand>(
- new USBCmdHeartbeat([this](bool success) { HandleHeartbeat(success); })));
-}
-
-void VirtualADBClient::HandleHeartbeat(bool is_ready) {
- VLOG(1) << "Remote server status: " << is_ready;
- if (is_ready && !is_remote_server_ready_) {
- LOG(INFO) << "Remote server is now ready.";
- PopulateRemoteDevices();
- vhci_.TriggerAttach();
- } else if (is_remote_server_ready_ && !is_ready) {
- vhci_.TriggerDetach();
- LOG(WARNING) << "Remote server connection lost.";
- // It makes perfect sense to cancel all outstanding USB requests, as device
- // is not going to answer any of these anyway.
- for (const auto& pair : commands_) {
- pair.second->OnResponse(false, fd_);
- }
- commands_.clear();
- }
- is_remote_server_ready_ = is_ready;
-}
-
-bool VirtualADBClient::HandleHeartbeatTimeout() {
- uint64_t timer_result;
- timer_->Read(&timer_result, sizeof(timer_result));
-
- auto iter = commands_.find(heartbeat_tag_);
- if (iter != commands_.end()) {
- // Make sure to erase the value from list of commands prior to running
- // callback. Particularly important for heartbeat, which cancels all
- // outstanding USB commands (including self, if found), if device goes
- // away (eg. reboots).
- auto command = std::move(iter->second);
- commands_.erase(iter);
- command->OnResponse(false, fd_);
- }
-
- return SendHeartbeat();
-}
-
-bool VirtualADBClient::ExecuteCommand(std::unique_ptr<USBCommand> cmd) {
- uint32_t this_tag = tag_;
- tag_++;
- usb_forward::RequestHeader hdr{cmd->Command(), this_tag};
- if (fd_->Write(&hdr, sizeof(hdr)) != sizeof(hdr)) {
- LOG(ERROR) << "Could not contact USB Forwarder: " << fd_->StrError();
- return false;
- }
-
- if (!cmd->OnRequest(fd_)) return false;
-
- commands_[this_tag] = std::move(cmd);
- return true;
-}
-
-// BeforeSelect is Called right before Select() to populate interesting
-// SharedFDs.
-void VirtualADBClient::BeforeSelect(cvd::SharedFDSet* fd_read) const {
- fd_read->Set(fd_);
- fd_read->Set(timer_);
-}
-
-// AfterSelect is Called right after Select() to detect and respond to changes
-// on affected SharedFDs.
-// Return value indicates whether this client is still valid.
-bool VirtualADBClient::AfterSelect(const cvd::SharedFDSet& fd_read) {
- if (fd_read.IsSet(timer_)) {
- HandleHeartbeatTimeout();
- }
- if (fd_read.IsSet(fd_)) {
- usb_forward::ResponseHeader rhdr;
- if (fd_->Read(&rhdr, sizeof(rhdr)) != sizeof(rhdr)) {
- LOG(ERROR) << "Could not read from USB Forwarder: " << fd_->StrError();
- // TODO(ender): it is very likely the connection has been dropped by QEmu.
- // Should we cancel all pending commands now?
- return false;
- }
-
- auto iter = commands_.find(rhdr.tag);
- if (iter == commands_.end()) {
- // This is likely a late heartbeat response, but could very well be any of
- // the remaining commands.
- LOG(INFO) << "Received response for discarded tag " << rhdr.tag;
- } else {
- // Make sure to erase the value from list of commands prior to running
- // callback. Particularly important for heartbeat, which cancels all
- // outstanding USB commands (including self, if found), if device goes
- // away (eg. reboots).
- auto command = std::move(iter->second);
- commands_.erase(iter);
- command->OnResponse(rhdr.status == usb_forward::StatusSuccess, fd_);
- }
- }
-
- return true;
-}
-
-} // namespace vadb
diff --git a/host/commands/virtual_usb_manager/vadb/virtual_adb_client.h b/host/commands/virtual_usb_manager/vadb/virtual_adb_client.h
deleted file mode 100644
index 9c503ab..0000000
--- a/host/commands/virtual_usb_manager/vadb/virtual_adb_client.h
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-
-#include <string>
-
-#include "common/libs/fs/shared_fd.h"
-#include "common/libs/fs/shared_select.h"
-#include "common/libs/usbforward/protocol.h"
-#include "host/commands/virtual_usb_manager/vadb/usb_cmd.h"
-#include "host/commands/virtual_usb_manager/usbip/device.h"
-#include "host/commands/virtual_usb_manager/usbip/device_pool.h"
-#include "host/commands/virtual_usb_manager/usbip/messages.h"
-#include "host/commands/virtual_usb_manager/usbip/vhci_instrument.h"
-
-namespace vadb {
-// VirtualADBClient is a companion class for USBForwarder, running on
-// Cuttlefish. VirtualADBClient collects list of available USB devices from
-// Cuttlefish and makes them available to USB/IP.
-//
-// Purpose of this class is to connect to USBForwarder and make access to
-// remote USB devices possible with help of USB/IP protocol.
-class VirtualADBClient {
- public:
- VirtualADBClient(usbip::DevicePool* pool, cvd::SharedFD fd, int vhci_port,
- const std::string& usbip_socket_name);
-
- virtual ~VirtualADBClient() = default;
-
- // Query remote server; populate available USB devices.
- bool PopulateRemoteDevices();
-
- // BeforeSelect is Called right before Select() to populate interesting
- // SharedFDs.
- void BeforeSelect(cvd::SharedFDSet* fd_read) const;
-
- // AfterSelect is Called right after Select() to detect and respond to changes
- // on affected SharedFDs.
- // Return value indicates whether this client is still valid.
- bool AfterSelect(const cvd::SharedFDSet& fd_read);
-
- private:
- // Register new device in a device pool.
- void RegisterDevice(const usb_forward::DeviceInfo& dev,
- const std::vector<usb_forward::InterfaceInfo>& ifaces);
-
- // Request attach remote USB device.
- bool HandleAttach(uint8_t bus_id, uint8_t dev_id);
-
- // Execute control request on remote device.
- bool HandleDeviceControlRequest(uint8_t bus_id, uint8_t dev_id,
- const usbip::CmdRequest& r, uint32_t deadline,
- std::vector<uint8_t> data,
- usbip::Device::AsyncTransferReadyCB callback);
-
- // Execute data request on remote device.
- bool HandleDeviceDataRequest(uint8_t bus_id, uint8_t dev_id, uint8_t endpoint,
- bool is_host_to_device, uint32_t deadline,
- std::vector<uint8_t> data,
- usbip::Device::AsyncTransferReadyCB callback);
-
- // Send new heartbeat request and arm the heartbeat timer.
- bool SendHeartbeat();
-
- // Heartbeat handler receives response to heartbeat request.
- // Supplied argument indicates, whether remote server is ready to export USB
- // gadget.
- void HandleHeartbeat(bool is_ready);
-
- // Heartbeat timeout detects situation where heartbeat did not receive
- // matching response. This could be a direct result of device reset.
- bool HandleHeartbeatTimeout();
-
- // ExecuteCommand creates command header and executes supplied USBCommand.
- // If execution was successful, command will be stored internally until
- // response arrives.
- bool ExecuteCommand(std::unique_ptr<USBCommand> cmd);
-
- usbip::DevicePool* pool_;
- cvd::SharedFD fd_;
- cvd::SharedFD timer_;
- usbip::VHCIInstrument vhci_;
- bool is_remote_server_ready_ = false;
-
- uint32_t tag_ = 0;
- // Assign an 'invalid' tag as previously sent heartbeat command. This will
- // prevent heartbeat timeout handler from finding a command if none was sent.
- uint32_t heartbeat_tag_ = ~0;
- std::map<uint32_t, std::unique_ptr<USBCommand>> commands_;
-
- VirtualADBClient(const VirtualADBClient& other) = delete;
- VirtualADBClient& operator=(const VirtualADBClient& other) = delete;
-};
-
-} // namespace vadb
diff --git a/host/commands/virtual_usb_manager/vadb/virtual_adb_server.cpp b/host/commands/virtual_usb_manager/vadb/virtual_adb_server.cpp
deleted file mode 100644
index 43dae75..0000000
--- a/host/commands/virtual_usb_manager/vadb/virtual_adb_server.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "host/commands/virtual_usb_manager/vadb/virtual_adb_server.h"
-
-namespace vadb {
-
-void VirtualADBServer::BeforeSelect(cvd::SharedFDSet* fd_read) const {
- fd_read->Set(server_);
- for (const auto& client : clients_) {
- client.BeforeSelect(fd_read);
- }
-}
-
-void VirtualADBServer::AfterSelect(const cvd::SharedFDSet& fd_read) {
- if (fd_read.IsSet(server_)) HandleIncomingConnection();
-
- for (auto iter = clients_.begin(); iter != clients_.end();) {
- if (!iter->AfterSelect(fd_read)) {
- // If client conversation failed, hang up.
- iter = clients_.erase(iter);
- continue;
- }
- ++iter;
- }
-}
-
-// Accept new QEmu connection. Add it to client pool.
-// Typically we will have no more than one QEmu connection, but the nature
-// of server requires proper handling nonetheless.
-void VirtualADBServer::HandleIncomingConnection() {
- cvd::SharedFD client = cvd::SharedFD::Accept(*server_, nullptr, nullptr);
- if (!client->IsOpen()) {
- LOG(ERROR) << "Client connection failed: " << client->StrError();
- return;
- }
-
- clients_.emplace_back(&pool_, client, vhci_port_, usbip_name_);
-}
-
-} // namespace vadb
diff --git a/host/commands/virtual_usb_manager/vadb/virtual_adb_server.h b/host/commands/virtual_usb_manager/vadb/virtual_adb_server.h
deleted file mode 100644
index d4aaf79..0000000
--- a/host/commands/virtual_usb_manager/vadb/virtual_adb_server.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-
-#include <list>
-#include <string>
-
-#include "common/libs/fs/shared_fd.h"
-#include "host/commands/virtual_usb_manager/usbip/device_pool.h"
-#include "host/commands/virtual_usb_manager/vadb/virtual_adb_client.h"
-
-namespace vadb {
-// VirtualADBServer manages incoming VirtualUSB/ADB connections from QEmu.
-class VirtualADBServer {
- public:
- VirtualADBServer(cvd::SharedFD usb_v1_socket, int vhci_port,
- const std::string& usbip_socket_name)
- : vhci_port_{vhci_port},
- usbip_name_(usbip_socket_name),
- server_(usb_v1_socket) {}
-
- ~VirtualADBServer() = default;
-
- // Pool of USB devices available to export.
- const usbip::DevicePool& Pool() const { return pool_; };
-
- // BeforeSelect is Called right before Select() to populate interesting
- // SharedFDs.
- void BeforeSelect(cvd::SharedFDSet* fd_read) const;
-
- // AfterSelect is Called right after Select() to detect and respond to changes
- // on affected SharedFDs.
- void AfterSelect(const cvd::SharedFDSet& fd_read);
-
- private:
- void HandleIncomingConnection();
-
- usbip::DevicePool pool_;
- int vhci_port_{};
- std::string usbip_name_;
- cvd::SharedFD server_;
- std::list<VirtualADBClient> clients_;
-
- VirtualADBServer(const VirtualADBServer&) = delete;
- VirtualADBServer& operator=(const VirtualADBServer&) = delete;
-};
-
-} // namespace vadb
diff --git a/host/libs/config/cuttlefish_config.cpp b/host/libs/config/cuttlefish_config.cpp
index 3b223d9..cdf75ff 100644
--- a/host/libs/config/cuttlefish_config.cpp
+++ b/host/libs/config/cuttlefish_config.cpp
@@ -80,7 +80,6 @@
const char* kDpi = "dpi";
const char* kXRes = "x_res";
const char* kYRes = "y_res";
-const char* kNumScreenBuffers = "num_screen_buffers";
const char* kRefreshRateHz = "refresh_rate_hz";
const char* kKernelImagePath = "kernel_image_path";
@@ -94,16 +93,7 @@
const char* kVendorRamdiskImagePath = "vendor_ramdisk_image_path";
const char* kVirtualDiskPaths = "virtual_disk_paths";
-const char* kUsbV1SocketName = "usb_v1_socket_name";
-const char* kVhciPort = "vhci_port";
-const char* kUsbIpSocketName = "usb_ip_socket_name";
-const char* kKernelLogPipeName = "kernel_log_pipe_name";
-const char* kConsolePipeName = "console_pipe_name";
const char* kDeprecatedBootCompleted = "deprecated_boot_completed";
-const char* kConsolePath = "console_path";
-const char* kLogcatPath = "logcat_path";
-const char* kLauncherLogPath = "launcher_log_path";
-const char* kLauncherMonitorPath = "launcher_monitor_socket";
const char* kMobileBridgeName = "mobile_bridge_name";
const char* kMobileTapName = "mobile_tap_name";
@@ -130,8 +120,6 @@
const char* kRestartSubprocesses = "restart_subprocesses";
const char* kRunAdbConnector = "run_adb_connector";
const char* kAdbConnectorBinary = "adb_connector_binary";
-const char* kVirtualUsbManagerBinary = "virtual_usb_manager_binary";
-const char* kSocketForwardProxyBinary = "socket_forward_proxy_binary";
const char* kSocketVsockProxyBinary = "socket_vsock_proxy_binary";
const char* kRunAsDaemon = "run_as_daemon";
@@ -141,14 +129,10 @@
const char* kBlankDataImageFmt = "blank_data_image_fmt";
const char* kLogcatMode = "logcat_mode";
-const char* kLogcatVsockPort = "logcat_vsock_port";
-const char* kConfigServerPort = "config_server_port";
-const char* kFramesVsockPort = "frames_vsock_port";
const char* kLogcatReceiverBinary = "logcat_receiver_binary";
const char* kConfigServerBinary = "config_server_binary";
const char* kRunTombstoneReceiver = "enable_tombstone_logger";
-const char* kTombstoneReceiverPort = "tombstone_logger_port";
const char* kTombstoneReceiverBinary = "tombstone_receiver_binary";
const char* kBootloader = "bootloader";
@@ -156,9 +140,6 @@
const char* kBootSlot = "boot_slot";
-const char* kTouchSocketPort = "touch_socket_port";
-const char* kKeyboardSocketPort = "keyboard_socket_port";
-
const char* kLoopMaxPart = "loop_max_part";
const char* kGuestEnforceSecurity = "guest_enforce_security";
const char* kGuestAuditSecurity = "guest_audit_security";
@@ -244,13 +225,6 @@
int CuttlefishConfig::y_res() const { return (*dictionary_)[kYRes].asInt(); }
void CuttlefishConfig::set_y_res(int y_res) { (*dictionary_)[kYRes] = y_res; }
-int CuttlefishConfig::num_screen_buffers() const {
- return (*dictionary_)[kNumScreenBuffers].asInt();
-}
-void CuttlefishConfig::set_num_screen_buffers(int num_screen_buffers) {
- (*dictionary_)[kNumScreenBuffers] = num_screen_buffers;
-}
-
int CuttlefishConfig::refresh_rate_hz() const {
return (*dictionary_)[kRefreshRateHz].asInt();
}
@@ -353,43 +327,12 @@
(*dictionary_)[kVirtualDiskPaths] = virtual_disks_json_obj;
}
-std::string CuttlefishConfig::usb_v1_socket_name() const {
- return (*dictionary_)[kUsbV1SocketName].asString();
-}
-void CuttlefishConfig::set_usb_v1_socket_name(
- const std::string& usb_v1_socket_name) {
- (*dictionary_)[kUsbV1SocketName] = usb_v1_socket_name;
-}
-
-int CuttlefishConfig::vhci_port() const {
- return (*dictionary_)[kVhciPort].asInt();
-}
-void CuttlefishConfig::set_vhci_port(int vhci_port) {
- (*dictionary_)[kVhciPort] = vhci_port;
-}
-
-std::string CuttlefishConfig::usb_ip_socket_name() const {
- return (*dictionary_)[kUsbIpSocketName].asString();
-}
-void CuttlefishConfig::set_usb_ip_socket_name(
- const std::string& usb_ip_socket_name) {
- (*dictionary_)[kUsbIpSocketName] = usb_ip_socket_name;
-}
-
std::string CuttlefishConfig::kernel_log_pipe_name() const {
- return (*dictionary_)[kKernelLogPipeName].asString();
-}
-void CuttlefishConfig::set_kernel_log_pipe_name(
- const std::string& kernel_log_pipe_name) {
- (*dictionary_)[kKernelLogPipeName] = kernel_log_pipe_name;
+ return cvd::AbsolutePath(PerInstanceInternalPath("kernel-log-pipe"));
}
std::string CuttlefishConfig::console_pipe_name() const {
- return (*dictionary_)[kConsolePipeName].asString();
-}
-void CuttlefishConfig::set_console_pipe_name(
- const std::string& console_pipe_name) {
- SetPath(kConsolePipeName, console_pipe_name);
+ return cvd::AbsolutePath(PerInstanceInternalPath("console-pipe"));
}
bool CuttlefishConfig::deprecated_boot_completed() const {
@@ -401,33 +344,19 @@
}
std::string CuttlefishConfig::console_path() const {
- return (*dictionary_)[kConsolePath].asString();
-}
-void CuttlefishConfig::set_console_path(const std::string& console_path) {
- SetPath(kConsolePath, console_path);
+ return cvd::AbsolutePath(PerInstancePath("console"));
}
std::string CuttlefishConfig::logcat_path() const {
- return (*dictionary_)[kLogcatPath].asString();
-}
-void CuttlefishConfig::set_logcat_path(const std::string& logcat_path) {
- SetPath(kLogcatPath, logcat_path);
+ return cvd::AbsolutePath(PerInstancePath("logcat"));
}
std::string CuttlefishConfig::launcher_monitor_socket_path() const {
- return (*dictionary_)[kLauncherMonitorPath].asString();
-}
-void CuttlefishConfig::set_launcher_monitor_socket_path(
- const std::string& launcher_monitor_path) {
- SetPath(kLauncherMonitorPath, launcher_monitor_path);
+ return cvd::AbsolutePath(PerInstancePath("launcher_monitor.sock"));
}
std::string CuttlefishConfig::launcher_log_path() const {
- return (*dictionary_)[kLauncherLogPath].asString();
-}
-void CuttlefishConfig::set_launcher_log_path(
- const std::string& launcher_log_path) {
- (*dictionary_)[kLauncherLogPath] = launcher_log_path;
+ return cvd::AbsolutePath(PerInstancePath("launcher.log"));
}
std::string CuttlefishConfig::mobile_bridge_name() const {
@@ -482,8 +411,6 @@
return AdbMode::VsockHalfTunnel;
} else if (mode == "native_vsock") {
return AdbMode::NativeVsock;
- } else if (mode == "usb") {
- return AdbMode::Usb;
} else {
return AdbMode::Unknown;
}
@@ -528,8 +455,6 @@
bool nativeVsock = adb_mode().count(AdbMode::NativeVsock) > 0;
if (vsockTunnel || vsockHalfProxy || nativeVsock) {
return adb_ip_and_port();
- } else if (adb_mode().count(AdbMode::Usb) > 0) {
- return serial_number();
}
LOG(ERROR) << "no adb_mode found, returning bad device name";
return "NO_ADB_MODE_SET_NO_VALID_DEVICE_NAME";
@@ -635,24 +560,6 @@
(*dictionary_)[kAdbConnectorBinary] = adb_connector_binary;
}
-std::string CuttlefishConfig::virtual_usb_manager_binary() const {
- return (*dictionary_)[kVirtualUsbManagerBinary].asString();
-}
-
-void CuttlefishConfig::set_virtual_usb_manager_binary(
- const std::string& virtual_usb_manager_binary) {
- (*dictionary_)[kVirtualUsbManagerBinary] = virtual_usb_manager_binary;
-}
-
-std::string CuttlefishConfig::socket_forward_proxy_binary() const {
- return (*dictionary_)[kSocketForwardProxyBinary].asString();
-}
-
-void CuttlefishConfig::set_socket_forward_proxy_binary(
- const std::string& socket_forward_proxy_binary) {
- (*dictionary_)[kSocketForwardProxyBinary] = socket_forward_proxy_binary;
-}
-
std::string CuttlefishConfig::socket_vsock_proxy_binary() const {
return (*dictionary_)[kSocketVsockProxyBinary].asString();
}
@@ -702,30 +609,6 @@
return (*dictionary_)[kLogcatMode].asString();
}
-void CuttlefishConfig::set_logcat_vsock_port(int port) {
- (*dictionary_)[kLogcatVsockPort] = port;
-}
-
-int CuttlefishConfig::logcat_vsock_port() const {
- return (*dictionary_)[kLogcatVsockPort].asInt();
-}
-
-void CuttlefishConfig::set_config_server_port(int port) {
- (*dictionary_)[kConfigServerPort] = port;
-}
-
-int CuttlefishConfig::config_server_port() const {
- return (*dictionary_)[kConfigServerPort].asInt();
-}
-
-void CuttlefishConfig::set_frames_vsock_port(int port) {
- (*dictionary_)[kFramesVsockPort] = port;
-}
-
-int CuttlefishConfig::frames_vsock_port() const {
- return (*dictionary_)[kFramesVsockPort].asInt();
-}
-
void CuttlefishConfig::set_logcat_receiver_binary(const std::string& binary) {
SetPath(kLogcatReceiverBinary, binary);
}
@@ -758,10 +641,6 @@
(*dictionary_)[kTombstoneReceiverBinary] = e2e_test_binary;
}
-void CuttlefishConfig::set_tombstone_receiver_port(int port) {
- (*dictionary_)[kTombstoneReceiverPort] = port;
-}
-
bool CuttlefishConfig::use_bootloader() const {
return (*dictionary_)[kUseBootloader].asBool();
}
@@ -786,10 +665,6 @@
return (*dictionary_)[kBootSlot].asString();
}
-int CuttlefishConfig::tombstone_receiver_port() const {
- return (*dictionary_)[kTombstoneReceiverPort].asInt();
-}
-
std::string CuttlefishConfig::touch_socket_path() const {
return PerInstanceInternalPath("touch.sock");
}
@@ -798,22 +673,6 @@
return PerInstanceInternalPath("keyboard.sock");
}
-void CuttlefishConfig::set_touch_socket_port(int port) {
- (*dictionary_)[kTouchSocketPort] = port;
-}
-
-int CuttlefishConfig::touch_socket_port() const {
- return (*dictionary_)[kTouchSocketPort].asInt();
-}
-
-void CuttlefishConfig::set_keyboard_socket_port(int port) {
- (*dictionary_)[kKeyboardSocketPort] = port;
-}
-
-int CuttlefishConfig::keyboard_socket_port() const {
- return (*dictionary_)[kKeyboardSocketPort].asInt();
-}
-
void CuttlefishConfig::set_loop_max_part(int loop_max_part) {
(*dictionary_)[kLoopMaxPart] = loop_max_part;
}
@@ -855,7 +714,7 @@
for (const auto& arg : android::base::Split(extra_cmdline, " ")) {
args_json_obj.append(arg);
}
- (*dictionary_)[kExtraKernelCmdline] = extra_cmdline;
+ (*dictionary_)[kExtraKernelCmdline] = args_json_obj;
}
std::vector<std::string> CuttlefishConfig::extra_kernel_cmdline() const {
std::vector<std::string> cmdline;
diff --git a/host/libs/config/cuttlefish_config.h b/host/libs/config/cuttlefish_config.h
index bf3d231..656f84f 100644
--- a/host/libs/config/cuttlefish_config.h
+++ b/host/libs/config/cuttlefish_config.h
@@ -42,7 +42,6 @@
VsockTunnel,
VsockHalfTunnel,
NativeVsock,
- Usb,
Unknown,
};
@@ -64,11 +63,6 @@
std::string instance_name() const;
- void disable_usb_adb() {
- // This seems to be the way usb is being disbled in the launcher
- set_usb_v1_socket_name("");
- }
-
std::string instance_dir() const;
void set_instance_dir(const std::string& instance_dir);
@@ -104,9 +98,6 @@
int y_res() const;
void set_y_res(int y_res);
- int num_screen_buffers() const;
- void set_num_screen_buffers(int num_screen_buffers);
-
int refresh_rate_hz() const;
void set_refresh_rate_hz(int refresh_rate_hz);
@@ -153,31 +144,16 @@
std::vector<std::string> virtual_disk_paths() const;
void set_virtual_disk_paths(const std::vector<std::string>& disk_paths);
- // The name of the socket that will be used to forward access to USB gadget.
- // This is for V1 of the USB bus.
- std::string usb_v1_socket_name() const;
- void set_usb_v1_socket_name(const std::string& usb_v1_socket_name);
-
- int vhci_port() const;
- void set_vhci_port(int vhci_port);
-
- std::string usb_ip_socket_name() const;
- void set_usb_ip_socket_name(const std::string& usb_ip_socket_name);
-
std::string kernel_log_pipe_name() const;
- void set_kernel_log_pipe_name(const std::string& kernel_log_pipe_name);
std::string console_pipe_name() const;
- void set_console_pipe_name(const std::string& console_pipe_name);
bool deprecated_boot_completed() const;
void set_deprecated_boot_completed(bool deprecated_boot_completed);
std::string console_path() const;
- void set_console_path(const std::string& console_path);
std::string logcat_path() const;
- void set_logcat_path(const std::string& logcat_path);
std::string logcat_receiver_binary() const;
void set_logcat_receiver_binary(const std::string& binary);
@@ -186,11 +162,8 @@
void set_config_server_binary(const std::string& binary);
std::string launcher_log_path() const;
- void set_launcher_log_path(const std::string& launcher_log_path);
std::string launcher_monitor_socket_path() const;
- void set_launcher_monitor_socket_path(
- const std::string& launhcer_monitor_path);
std::string mobile_bridge_name() const;
void set_mobile_bridge_name(const std::string& mobile_bridge_name);
@@ -258,12 +231,6 @@
void set_adb_connector_binary(const std::string& adb_connector_binary);
std::string adb_connector_binary() const;
- void set_virtual_usb_manager_binary(const std::string& binary);
- std::string virtual_usb_manager_binary() const;
-
- void set_socket_forward_proxy_binary(const std::string& binary);
- std::string socket_forward_proxy_binary() const;
-
void set_socket_vsock_proxy_binary(const std::string& binary);
std::string socket_vsock_proxy_binary() const;
@@ -282,24 +249,12 @@
void set_logcat_mode(const std::string& mode);
std::string logcat_mode() const;
- void set_logcat_vsock_port(int port);
- int logcat_vsock_port() const;
-
- void set_config_server_port(int port);
- int config_server_port() const;
-
- void set_frames_vsock_port(int port);
- int frames_vsock_port() const;
-
void set_enable_tombstone_receiver(bool enable_tombstone_receiver);
bool enable_tombstone_receiver() const;
void set_tombstone_receiver_binary(const std::string& binary);
std::string tombstone_receiver_binary() const;
- void set_tombstone_receiver_port(int port);
- int tombstone_receiver_port() const;
-
void set_use_bootloader(bool use_bootloader);
bool use_bootloader() const;
@@ -312,12 +267,6 @@
std::string touch_socket_path() const;
std::string keyboard_socket_path() const;
- void set_touch_socket_port(int touch_socket_port);
- int touch_socket_port() const;
-
- void set_keyboard_socket_port(int keyboard_socket_port);
- int keyboard_socket_port() const;
-
void set_loop_max_part(int loop_max_part);
int loop_max_part() const;
diff --git a/host/libs/vm_manager/cf_qemu.sh b/host/libs/vm_manager/cf_qemu.sh
index 969332d..5d88b3f 100755
--- a/host/libs/vm_manager/cf_qemu.sh
+++ b/host/libs/vm_manager/cf_qemu.sh
@@ -159,13 +159,6 @@
args+=(-initrd "${ramdisk_image_path}")
fi
-if [[ -n "${usb_v1_socket_name}" ]]; then
- args+=(
- -chardev "socket,id=charchannel1,path=${usb_v1_socket_name:-${default_internal_dir}/usb-v1}"
- -device "virtserialport,bus=virtio-serial0.0,nr=2,chardev=charchannel1,id=channel1,name=cf-gadget-usb-v1"
- )
-fi
-
if [[ ${vsock_guest_cid:-0} -gt 2 ]]; then
args+=(-device "vhost-vsock-pci,guest-cid=${vsock_guest_cid}")
fi
diff --git a/host/libs/vm_manager/qemu_manager.cpp b/host/libs/vm_manager/qemu_manager.cpp
index 45e3003..c5345c1 100644
--- a/host/libs/vm_manager/qemu_manager.cpp
+++ b/host/libs/vm_manager/qemu_manager.cpp
@@ -146,7 +146,6 @@
config_->kernel_log_pipe_name());
LogAndSetEnv("console_path", config_->console_path());
LogAndSetEnv("logcat_path", config_->logcat_path());
- LogAndSetEnv("usb_v1_socket_name", config_->usb_v1_socket_name());
LogAndSetEnv("vsock_guest_cid", std::to_string(config_->vsock_guest_cid()));
LogAndSetEnv("logcat_mode", config_->logcat_mode());
LogAndSetEnv("use_bootloader", config_->use_bootloader() ? "true" : "false");
diff --git a/host/libs/vm_manager/vm_manager.cpp b/host/libs/vm_manager/vm_manager.cpp
index 2ab4157..40fa828 100644
--- a/host/libs/vm_manager/vm_manager.cpp
+++ b/host/libs/vm_manager/vm_manager.cpp
@@ -44,32 +44,20 @@
{
QemuManager::name(),
{
- [](const vsoc::CuttlefishConfig* config) {
- return GetManagerSingleton<QemuManager>(config);
- },
- []() { return vsoc::HostSupportsQemuCli(); },
- [](const std::string& gpu_mode) {
- return QemuManager::ConfigureGpu(gpu_mode);
- },
- []() {
- return QemuManager::ConfigureBootDevices();
- }
+ GetManagerSingleton<QemuManager>,
+ vsoc::HostSupportsQemuCli,
+ QemuManager::ConfigureGpu,
+ QemuManager::ConfigureBootDevices,
},
},
{
CrosvmManager::name(),
{
- [](const vsoc::CuttlefishConfig* config) {
- return GetManagerSingleton<CrosvmManager>(config);
- },
+ GetManagerSingleton<CrosvmManager>,
// Same as Qemu for the time being
- []() { return vsoc::HostSupportsQemuCli(); },
- [](const std::string& gpu_mode) {
- return CrosvmManager::ConfigureGpu(gpu_mode);
- },
- []() {
- return CrosvmManager::ConfigureBootDevices();
- }
+ vsoc::HostSupportsQemuCli,
+ CrosvmManager::ConfigureGpu,
+ CrosvmManager::ConfigureBootDevices,
}
}
};
diff --git a/host_package.mk b/host_package.mk
index 1eac968..66246f2 100644
--- a/host_package.mk
+++ b/host_package.mk
@@ -27,7 +27,6 @@
vnc_server \
cf_qemu.sh \
cf_bpttool \
- virtual_usb_manager \
kernel_log_monitor \
extract-vmlinux \
crosvm \
diff --git a/shared/config/init.common.rc b/shared/config/init.common.rc
index 761b4e4..4833241 100644
--- a/shared/config/init.common.rc
+++ b/shared/config/init.common.rc
@@ -21,6 +21,32 @@
on init
# ZRAM setup
write /sys/block/zram0/comp_algorithm lz4
+ #
+ # EAS uclamp interfaces
+ #
+ mkdir /dev/cpuctl/foreground
+ mkdir /dev/cpuctl/background
+ mkdir /dev/cpuctl/top-app
+ mkdir /dev/cpuctl/rt
+ chown system system /dev/cpuctl
+ chown system system /dev/cpuctl/foreground
+ chown system system /dev/cpuctl/background
+ chown system system /dev/cpuctl/top-app
+ chown system system /dev/cpuctl/rt
+ chown system system /dev/cpuctl/tasks
+ chown system system /dev/cpuctl/foreground/tasks
+ chown system system /dev/cpuctl/background/tasks
+ chown system system /dev/cpuctl/top-app/tasks
+ chown system system /dev/cpuctl/rt/tasks
+ chmod 0664 /dev/cpuctl/tasks
+ chmod 0664 /dev/cpuctl/foreground/tasks
+ chmod 0664 /dev/cpuctl/background/tasks
+ chmod 0664 /dev/cpuctl/top-app/tasks
+ chmod 0664 /dev/cpuctl/rt/tasks
+ write /dev/cpuctl/foreground/cpu.rt_runtime_us 950000
+ write /dev/cpuctl/background/cpu.rt_runtime_us 950000
+ write /dev/cpuctl/top-app/cpu.rt_runtime_us 950000
+ write /dev/cpuctl/rt/cpu.rt_runtime_us 950000
on fs
diff --git a/shared/config/manifest.xml b/shared/config/manifest.xml
index 51887e5..d54570f 100644
--- a/shared/config/manifest.xml
+++ b/shared/config/manifest.xml
@@ -17,6 +17,7 @@
*/
-->
<manifest version="1.0" type="device" target-level="4">
+ <kernel target-level="5" />
<hal format="hidl">
<name>android.hardware.audio</name>
<transport>hwbinder</transport>
diff --git a/shared/device.mk b/shared/device.mk
index 8c6748a..3eaebd1 100644
--- a/shared/device.mk
+++ b/shared/device.mk
@@ -35,7 +35,7 @@
# Properties that are not vendor-specific. These will go in the product
# partition, instead of the vendor partition, and do not need vendor
# sepolicy
-PRODUCT_PRODUCT_PROPERTIES := \
+PRODUCT_PRODUCT_PROPERTIES += \
persist.adb.tcp.port=5555 \
persist.traced.enable=1 \
ro.com.google.locationfeatures=1 \
@@ -158,6 +158,7 @@
frameworks/native/data/etc/android.hardware.wifi.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.wifi.xml \
frameworks/native/data/etc/android.software.app_widgets.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.app_widgets.xml \
system/bt/vendor_libs/test_vendor_lib/data/controller_properties.json:vendor/etc/bluetooth/controller_properties.json \
+ device/google/cuttlefish/task_profiles.json:$(TARGET_COPY_OUT_VENDOR)/etc/task_profiles.json \
device/google/cuttlefish/shared/config/fstab:$(TARGET_COPY_OUT_RAMDISK)/fstab.cutf_ivsh \
device/google/cuttlefish/shared/config/fstab:$(TARGET_COPY_OUT_VENDOR)/etc/fstab.cutf_ivsh \
device/google/cuttlefish/shared/config/fstab:$(TARGET_COPY_OUT_RAMDISK)/fstab.cutf_cvm \
diff --git a/shared/sepolicy/vendor/bug_map b/shared/sepolicy/vendor/bug_map
index 372547e..81f8bf1 100644
--- a/shared/sepolicy/vendor/bug_map
+++ b/shared/sepolicy/vendor/bug_map
@@ -1,3 +1,4 @@
+gsid gsid capability b/146356992
init system_lib_file dir b/133444385
init system_lib_file file b/133444385
kernel kernel system b/130424539
diff --git a/shared/sepolicy/vendor/file.te b/shared/sepolicy/vendor/file.te
index a4d5d83..131c275 100644
--- a/shared/sepolicy/vendor/file.te
+++ b/shared/sepolicy/vendor/file.te
@@ -4,4 +4,5 @@
type tombstone_snapshot_file, file_type;
type var_run_system_file, file_type;
type sysfs_gpu, fs_type, sysfs_type;
+type sysfs_iio_devices, fs_type, sysfs_type;
type mediadrm_vendor_data_file, file_type, data_file_type;
diff --git a/shared/sepolicy/vendor/genfs_contexts b/shared/sepolicy/vendor/genfs_contexts
index 28f55bf..9250d73 100644
--- a/shared/sepolicy/vendor/genfs_contexts
+++ b/shared/sepolicy/vendor/genfs_contexts
@@ -1,7 +1,11 @@
+genfscon sysfs /bus/iio/devices u:object_r:sysfs_iio_devices:s0
genfscon sysfs /devices/pnp0/00:00/rtc u:object_r:sysfs_rtc:s0 # qemu virtual rtc
-genfscon sysfs /devices/platform/rtc-test.0/rtc u:object_r:sysfs_rtc:s0 # crosvm has no rtc, use kernel test driver
-genfscon sysfs /devices/platform/rtc-test.1/rtc u:object_r:sysfs_rtc:s0 # crosvm has no rtc, use kernel test driver
-genfscon sysfs /devices/platform/rtc-test.2/rtc u:object_r:sysfs_rtc:s0 # crosvm has no rtc, use kernel test driver
+genfscon sysfs /devices/platform/rtc-test.0/rtc/rtc0/hctosys u:object_r:sysfs_rtc:s0
+genfscon sysfs /devices/platform/rtc-test.1/rtc/rtc1/hctosys u:object_r:sysfs_rtc:s0
+genfscon sysfs /devices/platform/rtc-test.2/rtc/rtc2/hctosys u:object_r:sysfs_rtc:s0
+genfscon sysfs /devices/platform/rtc-test.1/rtc/rtc1/wakeup1 u:object_r:sysfs_wakeup:s0
+genfscon sysfs /devices/platform/rtc-test.1/wakeup/wakeup0 u:object_r:sysfs_wakeup:s0
+genfscon sysfs /devices/platform/rtc-test.2/wakeup/wakeup2 u:object_r:sysfs_wakeup:s0
genfscon sysfs /devices/pci0000:00/0000:00:04.0/virtio2/net u:object_r:sysfs_net:s0 # (new) qemu composite buried_eth0 & wlan0
genfscon sysfs /devices/pci0000:00/0000:00:05.0/virtio3/net u:object_r:sysfs_net:s0 # (new) qemu composite rmnet0
genfscon sysfs /devices/pci0000:00/0000:00:06.0/virtio5/net u:object_r:sysfs_net:s0 # (new) crosvm composite buried_eth0 & wlan0
diff --git a/shared/sepolicy/vendor/hal_power_stats_default.te b/shared/sepolicy/vendor/hal_power_stats_default.te
new file mode 100644
index 0000000..35c9275
--- /dev/null
+++ b/shared/sepolicy/vendor/hal_power_stats_default.te
@@ -0,0 +1 @@
+r_dir_file(hal_power_stats_default, sysfs_iio_devices) # Needed to traverse nonexistent iio devices tree
diff --git a/shared/sepolicy/vendor/priv_app.te b/shared/sepolicy/vendor/priv_app.te
index 7de36ab..05c9e47 100644
--- a/shared/sepolicy/vendor/priv_app.te
+++ b/shared/sepolicy/vendor/priv_app.te
@@ -1,6 +1 @@
gpu_access(priv_app)
-get_prop(priv_app, hal_camera_prop)
-# b/142672293: No other priv-app should need this allow rule now and GMS core runs in its own domain.
-userdebug_or_eng(`
- auditallow priv_app hal_camera_prop:file { getattr open read map };
-')
diff --git a/task_profiles.json b/task_profiles.json
new file mode 100644
index 0000000..29bcf30
--- /dev/null
+++ b/task_profiles.json
@@ -0,0 +1,533 @@
+{
+ "Attributes": [
+ {
+ "Name": "LowCapacityCPUs",
+ "Controller": "cpuset",
+ "File": "background/cpus"
+ },
+ {
+ "Name": "HighCapacityCPUs",
+ "Controller": "cpuset",
+ "File": "foreground/cpus"
+ },
+ {
+ "Name": "MaxCapacityCPUs",
+ "Controller": "cpuset",
+ "File": "top-app/cpus"
+ },
+ {
+ "Name": "MemLimit",
+ "Controller": "memory",
+ "File": "memory.limit_in_bytes"
+ },
+ {
+ "Name": "MemSoftLimit",
+ "Controller": "memory",
+ "File": "memory.soft_limit_in_bytes"
+ },
+ {
+ "Name": "MemSwappiness",
+ "Controller": "memory",
+ "File": "memory.swappiness"
+ },
+ {
+ "Name": "UClampMin",
+ "Controller": "cpu",
+ "File": "cpu.util.min"
+ },
+ {
+ "Name": "UClampMax",
+ "Controller": "cpu",
+ "File": "cpu.util.max"
+ }
+ ],
+
+ "Profiles": [
+ {
+ "Name": "HighEnergySaving",
+ "Actions": [
+ {
+ "Name": "JoinCgroup",
+ "Params":
+ {
+ "Controller": "cpu",
+ "Path": "background"
+ }
+ }
+ ]
+ },
+ {
+ "Name": "Frozen",
+ "Actions": [
+ {
+ "Name": "JoinCgroup",
+ "Params":
+ {
+ "Controller": "freezer",
+ "Path": "frozen"
+ }
+ }
+ ]
+ },
+ {
+ "Name": "Unfrozen",
+ "Actions": [
+ {
+ "Name": "JoinCgroup",
+ "Params":
+ {
+ "Controller": "freezer",
+ "Path": ""
+ }
+ }
+ ]
+ },
+ {
+ "Name": "NormalPerformance",
+ "Actions": [
+ {
+ "Name": "JoinCgroup",
+ "Params":
+ {
+ "Controller": "cpu",
+ "Path": ""
+ }
+ }
+ ]
+ },
+ {
+ "Name": "HighPerformance",
+ "Actions": [
+ {
+ "Name": "JoinCgroup",
+ "Params":
+ {
+ "Controller": "cpu",
+ "Path": "foreground"
+ }
+ }
+ ]
+ },
+ {
+ "Name": "MaxPerformance",
+ "Actions": [
+ {
+ "Name": "JoinCgroup",
+ "Params":
+ {
+ "Controller": "cpu",
+ "Path": "top-app"
+ }
+ }
+ ]
+ },
+ {
+ "Name": "RealtimePerformance",
+ "Actions": [
+ {
+ "Name": "JoinCgroup",
+ "Params":
+ {
+ "Controller": "cpu",
+ "Path": "rt"
+ }
+ }
+ ]
+ },
+
+ {
+ "Name": "VrKernelCapacity",
+ "Actions": [
+ {
+ "Name": "JoinCgroup",
+ "Params":
+ {
+ "Controller": "cpuset",
+ "Path": ""
+ }
+ }
+ ]
+ },
+ {
+ "Name": "VrServiceCapacityLow",
+ "Actions": [
+ {
+ "Name": "JoinCgroup",
+ "Params":
+ {
+ "Controller": "cpuset",
+ "Path": "system/background"
+ }
+ }
+ ]
+ },
+ {
+ "Name": "VrServiceCapacityNormal",
+ "Actions": [
+ {
+ "Name": "JoinCgroup",
+ "Params":
+ {
+ "Controller": "cpuset",
+ "Path": "system"
+ }
+ }
+ ]
+ },
+ {
+ "Name": "VrServiceCapacityHigh",
+ "Actions": [
+ {
+ "Name": "JoinCgroup",
+ "Params":
+ {
+ "Controller": "cpuset",
+ "Path": "system/performance"
+ }
+ }
+ ]
+ },
+ {
+ "Name": "VrProcessCapacityLow",
+ "Actions": [
+ {
+ "Name": "JoinCgroup",
+ "Params":
+ {
+ "Controller": "cpuset",
+ "Path": "application/background"
+ }
+ }
+ ]
+ },
+ {
+ "Name": "VrProcessCapacityNormal",
+ "Actions": [
+ {
+ "Name": "JoinCgroup",
+ "Params":
+ {
+ "Controller": "cpuset",
+ "Path": "application"
+ }
+ }
+ ]
+ },
+ {
+ "Name": "VrProcessCapacityHigh",
+ "Actions": [
+ {
+ "Name": "JoinCgroup",
+ "Params":
+ {
+ "Controller": "cpuset",
+ "Path": "application/performance"
+ }
+ }
+ ]
+ },
+
+ {
+ "Name": "ProcessCapacityLow",
+ "Actions": [
+ {
+ "Name": "JoinCgroup",
+ "Params":
+ {
+ "Controller": "cpuset",
+ "Path": "background"
+ }
+ }
+ ]
+ },
+ {
+ "Name": "ProcessCapacityNormal",
+ "Actions": [
+ {
+ "Name": "JoinCgroup",
+ "Params":
+ {
+ "Controller": "cpuset",
+ "Path": ""
+ }
+ }
+ ]
+ },
+ {
+ "Name": "ProcessCapacityHigh",
+ "Actions": [
+ {
+ "Name": "JoinCgroup",
+ "Params":
+ {
+ "Controller": "cpuset",
+ "Path": "foreground"
+ }
+ }
+ ]
+ },
+ {
+ "Name": "ProcessCapacityMax",
+ "Actions": [
+ {
+ "Name": "JoinCgroup",
+ "Params":
+ {
+ "Controller": "cpuset",
+ "Path": "top-app"
+ }
+ }
+ ]
+ },
+
+ {
+ "Name": "ServiceCapacityLow",
+ "Actions": [
+ {
+ "Name": "JoinCgroup",
+ "Params":
+ {
+ "Controller": "cpuset",
+ "Path": "system-background"
+ }
+ }
+ ]
+ },
+ {
+ "Name": "ServiceCapacityRestricted",
+ "Actions": [
+ {
+ "Name": "JoinCgroup",
+ "Params":
+ {
+ "Controller": "cpuset",
+ "Path": "restricted"
+ }
+ }
+ ]
+ },
+
+ {
+ "Name": "CameraServiceCapacity",
+ "Actions": [
+ {
+ "Name": "JoinCgroup",
+ "Params":
+ {
+ "Controller": "cpuset",
+ "Path": "camera-daemon"
+ }
+ }
+ ]
+ },
+
+ {
+ "Name": "LowIoPriority",
+ "Actions": [
+ {
+ "Name": "JoinCgroup",
+ "Params":
+ {
+ "Controller": "blkio",
+ "Path": "background"
+ }
+ }
+ ]
+ },
+ {
+ "Name": "NormalIoPriority",
+ "Actions": [
+ {
+ "Name": "JoinCgroup",
+ "Params":
+ {
+ "Controller": "blkio",
+ "Path": ""
+ }
+ }
+ ]
+ },
+ {
+ "Name": "HighIoPriority",
+ "Actions": [
+ {
+ "Name": "JoinCgroup",
+ "Params":
+ {
+ "Controller": "blkio",
+ "Path": ""
+ }
+ }
+ ]
+ },
+ {
+ "Name": "MaxIoPriority",
+ "Actions": [
+ {
+ "Name": "JoinCgroup",
+ "Params":
+ {
+ "Controller": "blkio",
+ "Path": ""
+ }
+ }
+ ]
+ },
+
+ {
+ "Name": "TimerSlackHigh",
+ "Actions": [
+ {
+ "Name": "SetTimerSlack",
+ "Params":
+ {
+ "Slack": "40000000"
+ }
+ }
+ ]
+ },
+ {
+ "Name": "TimerSlackNormal",
+ "Actions": [
+ {
+ "Name": "SetTimerSlack",
+ "Params":
+ {
+ "Slack": "50000"
+ }
+ }
+ ]
+ },
+
+ {
+ "Name": "PerfBoost",
+ "Actions": [
+ {
+ "Name": "SetClamps",
+ "Params":
+ {
+ "Boost": "50%",
+ "Clamp": "0"
+ }
+ }
+ ]
+ },
+ {
+ "Name": "PerfClamp",
+ "Actions": [
+ {
+ "Name": "SetClamps",
+ "Params":
+ {
+ "Boost": "0",
+ "Clamp": "30%"
+ }
+ }
+ ]
+ },
+
+ {
+ "Name": "LowMemoryUsage",
+ "Actions": [
+ {
+ "Name": "SetAttribute",
+ "Params":
+ {
+ "Name": "MemSoftLimit",
+ "Value": "16MB"
+ }
+ },
+ {
+ "Name": "SetAttribute",
+ "Params":
+ {
+ "Name": "MemSwappiness",
+ "Value": "150"
+
+ }
+ }
+ ]
+ },
+ {
+ "Name": "HighMemoryUsage",
+ "Actions": [
+ {
+ "Name": "SetAttribute",
+ "Params":
+ {
+ "Name": "MemSoftLimit",
+ "Value": "512MB"
+ }
+ },
+ {
+ "Name": "SetAttribute",
+ "Params":
+ {
+ "Name": "MemSwappiness",
+ "Value": "100"
+ }
+ }
+ ]
+ },
+ {
+ "Name": "SystemMemoryProcess",
+ "Actions": [
+ {
+ "Name": "JoinCgroup",
+ "Params":
+ {
+ "Controller": "memory",
+ "Path": "system"
+ }
+ }
+ ]
+ }
+ ],
+
+ "AggregateProfiles": [
+ {
+ "Name": "SCHED_SP_DEFAULT",
+ "Profiles": [ "TimerSlackNormal" ]
+ },
+ {
+ "Name": "SCHED_SP_BACKGROUND",
+ "Profiles": [ "HighEnergySaving", "LowIoPriority", "TimerSlackHigh" ]
+ },
+ {
+ "Name": "SCHED_SP_FOREGROUND",
+ "Profiles": [ "HighPerformance", "HighIoPriority", "TimerSlackNormal" ]
+ },
+ {
+ "Name": "SCHED_SP_TOP_APP",
+ "Profiles": [ "MaxPerformance", "MaxIoPriority", "TimerSlackNormal" ]
+ },
+ {
+ "Name": "SCHED_SP_RT_APP",
+ "Profiles": [ "RealtimePerformance", "MaxIoPriority", "TimerSlackNormal" ]
+ },
+ {
+ "Name": "CPUSET_SP_DEFAULT",
+ "Profiles": [ "TimerSlackNormal" ]
+ },
+ {
+ "Name": "CPUSET_SP_BACKGROUND",
+ "Profiles": [ "HighEnergySaving", "ProcessCapacityLow", "LowIoPriority", "TimerSlackHigh" ]
+ },
+ {
+ "Name": "CPUSET_SP_FOREGROUND",
+ "Profiles": [ "HighPerformance", "ProcessCapacityHigh", "HighIoPriority", "TimerSlackNormal" ]
+ },
+ {
+ "Name": "CPUSET_SP_TOP_APP",
+ "Profiles": [ "MaxPerformance", "ProcessCapacityMax", "MaxIoPriority", "TimerSlackNormal" ]
+ },
+ {
+ "Name": "CPUSET_SP_SYSTEM",
+ "Profiles": [ "ServiceCapacityLow", "TimerSlackNormal" ]
+ },
+ {
+ "Name": "CPUSET_SP_RESTRICTED",
+ "Profiles": [ "ServiceCapacityRestricted", "TimerSlackNormal" ]
+ }
+ ]
+}
diff --git a/vsoc_arm64/BoardConfig.mk b/vsoc_arm64/BoardConfig.mk
index 0668328..ac0ea3c 100644
--- a/vsoc_arm64/BoardConfig.mk
+++ b/vsoc_arm64/BoardConfig.mk
@@ -32,4 +32,4 @@
TARGET_2ND_CPU_VARIANT := cortex-a53
TARGET_TRANSLATE_2ND_ARCH := false
-BOARD_VENDOR_RAMDISK_KERNEL_MODULES += $(wildcard device/google/cuttlefish_kernel/4.19-arm64/*.ko)
+BOARD_VENDOR_RAMDISK_KERNEL_MODULES += $(wildcard device/google/cuttlefish_kernel/5.4-arm64/*.ko)
diff --git a/vsoc_arm64/device.mk b/vsoc_arm64/device.mk
index 6e0f910..ea7d2dc 100644
--- a/vsoc_arm64/device.mk
+++ b/vsoc_arm64/device.mk
@@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-PRODUCT_COPY_FILES += device/google/cuttlefish_kernel/4.19-arm64/kernel:kernel
+PRODUCT_COPY_FILES += device/google/cuttlefish_kernel/5.4-arm64/kernel:kernel
diff --git a/vsoc_x86/BoardConfig.mk b/vsoc_x86/BoardConfig.mk
index d4b1772..0a051c0 100644
--- a/vsoc_x86/BoardConfig.mk
+++ b/vsoc_x86/BoardConfig.mk
@@ -31,4 +31,4 @@
TARGET_NATIVE_BRIDGE_ABI := armeabi-v7a armeabi
BUILD_BROKEN_DUP_RULES := true
-BOARD_VENDOR_RAMDISK_KERNEL_MODULES += $(wildcard device/google/cuttlefish_kernel/4.19-x86_64/*.ko)
+BOARD_VENDOR_RAMDISK_KERNEL_MODULES += $(wildcard device/google/cuttlefish_kernel/5.4-x86_64/*.ko)
diff --git a/vsoc_x86/device.mk b/vsoc_x86/device.mk
index ead090e..784cfdc 100644
--- a/vsoc_x86/device.mk
+++ b/vsoc_x86/device.mk
@@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-PRODUCT_COPY_FILES += device/google/cuttlefish_kernel/4.19-x86_64/kernel:kernel
+PRODUCT_COPY_FILES += device/google/cuttlefish_kernel/5.4-x86_64/kernel:kernel
diff --git a/vsoc_x86_64/BoardConfig.mk b/vsoc_x86_64/BoardConfig.mk
index 90ab500..fb8c6f0 100644
--- a/vsoc_x86_64/BoardConfig.mk
+++ b/vsoc_x86_64/BoardConfig.mk
@@ -41,4 +41,4 @@
TARGET_NATIVE_BRIDGE_2ND_ABI := armeabi-v7a armeabi
BUILD_BROKEN_DUP_RULES := true
-BOARD_VENDOR_RAMDISK_KERNEL_MODULES += $(wildcard device/google/cuttlefish_kernel/4.19-x86_64/*.ko)
+BOARD_VENDOR_RAMDISK_KERNEL_MODULES += $(wildcard device/google/cuttlefish_kernel/5.4-x86_64/*.ko)
diff --git a/vsoc_x86_64/device.mk b/vsoc_x86_64/device.mk
index ead090e..784cfdc 100644
--- a/vsoc_x86_64/device.mk
+++ b/vsoc_x86_64/device.mk
@@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-PRODUCT_COPY_FILES += device/google/cuttlefish_kernel/4.19-x86_64/kernel:kernel
+PRODUCT_COPY_FILES += device/google/cuttlefish_kernel/5.4-x86_64/kernel:kernel
diff --git a/vsoc_x86_noapex/BoardConfig.mk b/vsoc_x86_noapex/BoardConfig.mk
index 906129e..109e567 100644
--- a/vsoc_x86_noapex/BoardConfig.mk
+++ b/vsoc_x86_noapex/BoardConfig.mk
@@ -21,4 +21,4 @@
include device/google/cuttlefish/vsoc_x86/BoardConfig.mk
TARGET_FLATTEN_APEX := true
-BOARD_VENDOR_RAMDISK_KERNEL_MODULES += $(wildcard device/google/cuttlefish_kernel/4.19-x86_64/*.ko)
+BOARD_VENDOR_RAMDISK_KERNEL_MODULES += $(wildcard device/google/cuttlefish_kernel/5.4-x86_64/*.ko)