Apply Grpc Client to current VHal Implementation

Test: tested on Cuttlefish VM

 - Use virtualization HAL implementation, device/google/cuttlefish/shared/auto/device.mk, PRODUCT_PACKAGES:
      remove android.hardware.automotive.vehicle@2.0-service
      add:
        android.hardware.automotive.vehicle@2.0-virtualization-service
        android.hardware.automotive.vehicle@2.0-virtualization-grpc-server

 - configure the server CID and port, add the following device/google/cuttlefish/shared/config/init.vendor.rc:
        setprop ro.vendor.vehiclehal.server.cid 3
        setprop ro.vendor.vehiclehal.server.port 9210
 - Build and Launch cuttlefish VM
        m && acloud create --boot-timeout 3600 -vv --local-instance --local-image
 - VHAL should work as normal, see tests in ag/9693857

Bug: b/141493212

Change-Id: I97df02dd26b89f60d3d87b2c32c4f4f8919b1294
diff --git a/automotive/vehicle/2.0/default/VirtualizationGrpcServer.cpp b/automotive/vehicle/2.0/default/VirtualizationGrpcServer.cpp
new file mode 100644
index 0000000..cca65d9
--- /dev/null
+++ b/automotive/vehicle/2.0/default/VirtualizationGrpcServer.cpp
@@ -0,0 +1,49 @@
+#include <android-base/logging.h>
+#include <getopt.h>
+#include <unistd.h>
+
+#include "vhal_v2_0/virtualization/GrpcVehicleServer.h"
+#include "vhal_v2_0/virtualization/Utils.h"
+
+int main(int argc, char* argv[]) {
+    namespace vhal_impl = android::hardware::automotive::vehicle::V2_0::impl;
+
+    vhal_impl::VsockServerInfo serverInfo;
+
+    // unique values to identify the options
+    constexpr int OPT_VHAL_SERVER_CID = 1001;
+    constexpr int OPT_VHAL_SERVER_PORT_NUMBER = 1002;
+
+    struct option longOptions[] = {
+            {"server_cid", 1, 0, OPT_VHAL_SERVER_CID},
+            {"server_port", 1, 0, OPT_VHAL_SERVER_PORT_NUMBER},
+            {nullptr, 0, nullptr, 0},
+    };
+
+    int optValue;
+    while ((optValue = getopt_long_only(argc, argv, ":", longOptions, 0)) != -1) {
+        switch (optValue) {
+            case OPT_VHAL_SERVER_CID:
+                serverInfo.serverCid = std::atoi(optarg);
+                LOG(DEBUG) << "Vehicle HAL server CID: " << serverInfo.serverCid;
+                break;
+            case OPT_VHAL_SERVER_PORT_NUMBER:
+                serverInfo.serverPort = std::atoi(optarg);
+                LOG(DEBUG) << "Vehicle HAL server port: " << serverInfo.serverPort;
+                break;
+            default:
+                // ignore other options
+                break;
+        }
+    }
+
+    if (serverInfo.serverCid == 0 || serverInfo.serverPort == 0) {
+        LOG(FATAL) << "Invalid server information, CID: " << serverInfo.serverCid
+                   << "; port: " << serverInfo.serverPort;
+        // Will abort after logging
+    }
+
+    auto server = vhal_impl::makeGrpcVehicleServer(vhal_impl::getVsockUri(serverInfo));
+    server->Start();
+    return 0;
+}