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 <VehicleUtils.h>
22 #include <aidl/android/hardware/automotive/vehicle/VehicleApPowerStateConfigFlag.h>
23 #include <android-base/logging.h>
24 #include <cutils/properties.h>
25
26 #include <memory>
27
28 namespace {
29
30 using ::aidl::android::hardware::automotive::vehicle::
31 VehicleApPowerStateConfigFlag;
32 using ::android::hardware::automotive::utils::VsockConnectionInfo;
33 using ::android::hardware::automotive::vehicle::toInt;
34 using ::android::hardware::automotive::vehicle::fake::FakeVehicleHardware;
35 using ::android::hardware::automotive::vehicle::virtualization::
36 GrpcVehicleProxyServer;
37
38 } // namespace
39
40 // A GRPC server for VHAL running on the guest Android.
41 // argv[1]: Config directory path containing property config file (e.g.
42 // DefaultProperties.json).
43 // argv[2]: The IP address for this server.
44 // argv[3]: The vsock address for this server.
main(int argc,char * argv[])45 int main(int argc, char* argv[]) {
46 CHECK(argc >= 4) << "Not enough arguments, require at least 3: config file "
47 "path, IP address, vsock address";
48
49 std::string eth_addr = argv[2];
50 std::string grpc_server_addr = argv[3];
51 std::vector<std::string> listen_addrs = {grpc_server_addr, eth_addr};
52
53 // For cuttlefish we support S2R and S2D.
54 int32_t s2rS2dConfig =
55 toInt(VehicleApPowerStateConfigFlag::ENABLE_DEEP_SLEEP_FLAG) |
56 toInt(VehicleApPowerStateConfigFlag::ENABLE_HIBERNATION_FLAG);
57 auto fake_hardware =
58 std::make_unique<FakeVehicleHardware>(argv[1], "", false, s2rS2dConfig);
59 auto proxy_server = std::make_unique<GrpcVehicleProxyServer>(
60 listen_addrs, std::move(fake_hardware));
61
62 LOG(INFO) << "VHAL Server is listening on " << grpc_server_addr << ", "
63 << eth_addr;
64
65 proxy_server->Start().Wait();
66 return 0;
67 }
68