1 /*
2  * Copyright (C) 2023 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 <sys/socket.h>
24 #include <linux/vm_sockets.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::GrpcVehicleProxyServer;
31 
main(int argc,char * argv[])32 int main(int argc, char* argv[]) {
33     auto vsock = VsockConnectionInfo::fromRoPropertyStore(
34             {
35                     "ro.boot.vendor.vehiclehal.server.cid",
36                     "ro.vendor.vehiclehal.server.cid",
37             },
38             {
39                     "ro.boot.vendor.vehiclehal.server.port",
40                     "ro.vendor.vehiclehal.server.port",
41             });
42     CHECK(vsock.has_value()) << "Cannot read VHAL server address.";
43     // For now we do not know where does the connection come from.
44     // If we do, change this to the expected client CID.
45     vsock->cid = VMADDR_CID_ANY;
46     LOG(INFO) << "VHAL Server is listening on " << vsock->str();
47 
48     auto fakeHardware = std::make_unique<FakeVehicleHardware>();
49     auto proxyServer =
50             std::make_unique<GrpcVehicleProxyServer>(vsock->str(), std::move(fakeHardware));
51 
52     proxyServer->Start().Wait();
53     return 0;
54 }
55