1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "FakeVehicleHardware.h"
18 #include "GRPCVehicleProxyServer.h"
19 #include "vsockinfo.h"
20 
21 #include <android-base/logging.h>
22 #include <cutils/properties.h>
23 #include <linux/vm_sockets.h>
24 #include <sys/socket.h>
25 
26 #include <memory>
27 
28 using ::android::hardware::automotive::utils::VsockConnectionInfo;
29 using ::android::hardware::automotive::vehicle::fake::FakeVehicleHardware;
30 using ::android::hardware::automotive::vehicle::virtualization::
31     GrpcVehicleProxyServer;
32 
33 // A GRPC server for VHAL running on the guest Android.
34 // argv[1]: Config directory path containing property config file (e.g.
35 // DefaultProperties.json).
36 // argv[2]: The vsock port number used by this server.
main(int argc,char * argv[])37 int main(int argc, char* argv[]) {
38   CHECK(argc >= 3) << "Not enough arguments, require at least 2: config file "
39                       "path and vsock port";
40   VsockConnectionInfo vsock = {
41       .cid = VMADDR_CID_HOST, .port = static_cast<unsigned int>(atoi(argv[2]))};
42   LOG(INFO) << "VHAL Server is listening on " << vsock.str();
43 
44   auto fakeHardware = std::make_unique<FakeVehicleHardware>(argv[1], "", false);
45   auto proxyServer = std::make_unique<GrpcVehicleProxyServer>(
46       vsock.str(), std::move(fakeHardware));
47 
48   proxyServer->Start().Wait();
49   return 0;
50 }
51