aboutsummaryrefslogtreecommitdiff
path: root/host
diff options
context:
space:
mode:
authorYu Shan <shanyu@google.com>2024-06-05 20:08:04 +0000
committerYu Shan <shanyu@google.com>2024-06-05 13:41:27 -0700
commitb8fb31ab9c86c2e3bceea3a2393924636ad01e94 (patch)
tree74ed374fa60b23987a8d18a9eb38820e97f2e6eb /host
parentea4ec4200ca1edaaae92b6a52145b654f93f0faa (diff)
downloadcuttlefish-b8fb31ab9c86c2e3bceea3a2393924636ad01e94.tar.gz
Revert^2 "Add a VHAL host-side proxy server."
9f53f3bcac60035533b302a9996f5ae1dbf80a14 Reland the previous commit which was reverted due to breaking cf_wear builds. Compared to the previous commit, this CL removes the dependency on device/google/trout. Test: Local run Bug: 328316981 Change-Id: I5f79d3ae5d8069f93325d4f18b472dcc82958c4d
Diffstat (limited to 'host')
-rw-r--r--host/commands/vhal_proxy_server/Android.bp46
-rw-r--r--host/commands/vhal_proxy_server/VhalProxyServer.cpp50
-rw-r--r--host/commands/vhal_proxy_server/vsockinfo.h39
3 files changed, 135 insertions, 0 deletions
diff --git a/host/commands/vhal_proxy_server/Android.bp b/host/commands/vhal_proxy_server/Android.bp
new file mode 100644
index 000000000..3ef94fa0a
--- /dev/null
+++ b/host/commands/vhal_proxy_server/Android.bp
@@ -0,0 +1,46 @@
+//
+// Copyright (C) 2024 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: "vhal_proxy_server",
+ defaults: [
+ "cuttlefish_host",
+ "FakeVehicleHardwareDefaults",
+ "VehicleHalDefaults",
+ ],
+ srcs: [
+ "VhalProxyServer.cpp",
+ ],
+ required: [
+ "Host_Prebuilt_VehicleHalDefaultProperties_JSON",
+ "Host_Prebuilt_VehicleHalTestProperties_JSON",
+ "Host_Prebuilt_VehicleHalVendorClusterTestProperties_JSON",
+ ],
+ static_libs: [
+ "libc++fs",
+ "android.hardware.automotive.vehicle@default-grpc-server-lib",
+ "FakeVehicleHardware",
+ ],
+ shared_libs: [
+ "libbase",
+ "libcutils",
+ "libgrpc++",
+ "liblog",
+ "libprotobuf-cpp-full",
+ ],
+ cflags: [
+ "-Wno-unused-parameter",
+ ],
+}
diff --git a/host/commands/vhal_proxy_server/VhalProxyServer.cpp b/host/commands/vhal_proxy_server/VhalProxyServer.cpp
new file mode 100644
index 000000000..1de12c3f4
--- /dev/null
+++ b/host/commands/vhal_proxy_server/VhalProxyServer.cpp
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2024 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 "FakeVehicleHardware.h"
+#include "GRPCVehicleProxyServer.h"
+#include "vsockinfo.h"
+
+#include <android-base/logging.h>
+#include <cutils/properties.h>
+#include <linux/vm_sockets.h>
+#include <sys/socket.h>
+
+#include <memory>
+
+using ::android::hardware::automotive::utils::VsockConnectionInfo;
+using ::android::hardware::automotive::vehicle::fake::FakeVehicleHardware;
+using ::android::hardware::automotive::vehicle::virtualization::
+ GrpcVehicleProxyServer;
+
+// A GRPC server for VHAL running on the guest Android.
+// argv[1]: Config directory path containing property config file (e.g.
+// DefaultProperties.json).
+// argv[2]: The vsock port number used by this server.
+int main(int argc, char* argv[]) {
+ CHECK(argc >= 3) << "Not enough arguments, require at least 2: config file "
+ "path and vsock port";
+ VsockConnectionInfo vsock = {
+ .cid = VMADDR_CID_HOST, .port = static_cast<unsigned int>(atoi(argv[2]))};
+ LOG(INFO) << "VHAL Server is listening on " << vsock.str();
+
+ auto fakeHardware = std::make_unique<FakeVehicleHardware>(argv[1], "", false);
+ auto proxyServer = std::make_unique<GrpcVehicleProxyServer>(
+ vsock.str(), std::move(fakeHardware));
+
+ proxyServer->Start().Wait();
+ return 0;
+}
diff --git a/host/commands/vhal_proxy_server/vsockinfo.h b/host/commands/vhal_proxy_server/vsockinfo.h
new file mode 100644
index 000000000..fde879b00
--- /dev/null
+++ b/host/commands/vhal_proxy_server/vsockinfo.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2020 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 <array>
+#include <optional>
+#include <string>
+
+namespace android::hardware::automotive::utils {
+
+using PropertyList = std::initializer_list<std::string>;
+
+struct VsockConnectionInfo {
+ unsigned cid = 0;
+ unsigned port = 0;
+
+ std::string str() const {
+ std::stringstream ss;
+
+ ss << "vsock:" << cid << ":" << port;
+ return ss.str();
+ }
+};
+
+} // namespace android::hardware::automotive::utils